Ejemplo n.º 1
0
 private void setUpMySQL() {
   Statement statement1 = null;
   int results;
   try {
     statement1 = connection.createStatement();
     // FIXME: Lookup MySQl WIki if BOOLEAN is the right value for bools
     results =
         statement1.executeUpdate(
             "CREATE TABLE IF NOT EXISTS `twitterWhitelist` ( `UUID` VARCHAR(255) NOT NULL, `MCName` VARCHAR(255) NOT NULL , `twKey` VARCHAR(255) NOT NULL , `twSecret` VARCHAR(255) NOT NULL , `twName` VARCHAR(64) NOT NULL , `twID` BIGINT NOT NULL , `lastChange` TIMESTAMP on update CURRENT_TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP, `banned` BOOLEAN NOT NULL DEFAULT '0') ENGINE = MyISAM;");
   } catch (SQLException e) {
     // e.printStackTrace();
     plugin.getLogger().warning("Couldn't set up MySQL table for use: " + e.getMessage());
   } finally {
     try {
       if (statement1 != null) {
         statement1.close();
       }
     } catch (Exception e) {
     }
   }
 }
Ejemplo n.º 2
0
  @EventHandler(priority = EventPriority.NORMAL)
  public void onPlayerJoin(PlayerJoinEvent e) {
    PreparedStatement preparedStatement = null;
    ResultSet resultSet = null;
    Boolean iswhitelisted = null;

    try {
      preparedStatement =
          connection.prepareStatement(
              "SELECT UUID, twKey, twSecret, twName, twID from twitterWhitelist WHERE UUID=? LIMIT 1");
      preparedStatement.setString(1, e.getPlayer().getUniqueId().toString());
      resultSet = preparedStatement.executeQuery();

      if (resultSet.isBeforeFirst()) {
        iswhitelisted = true;
        plugin.getLogger().info("Player " + e.getPlayer().getName() + " is already in DB.");
        resultSet.next();
        if (resultSet.getString("UUID") != null) {
          TwitterAPI.updateAccount(
              resultSet.getString("twKey"), resultSet.getString("twSecret"), e.getPlayer());
          if (resultSet.getBoolean("banned")) {
            // ban the player
            // force the server to run ban command
            String commandLine = "ban " + e.getPlayer().getName() + " Multiaccount-Ban.";
            Bukkit.dispatchCommand(Bukkit.getConsoleSender(), commandLine);
          }
        }
      } else {
        // nicht gewhitelistet, also sperren und nur tww befehle erlauben.
        iswhitelisted = false;
      }
    } catch (SQLException err) {
      plugin.getLogger().warning("Couldn't fetch user from db: " + err.getMessage());
    } finally {
      try {
        if (preparedStatement != null) preparedStatement.close();
      } catch (SQLException e1) {
      }
    }

    if (iswhitelisted != null && !iswhitelisted) {
      plugin
          .getLogger()
          .info(
              "Player"
                  + e.getPlayer().getName()
                  + " is NOT whitelisted, sending message to player.");
      e.getPlayer()
          .sendMessage(
              (Object) ChatColor.DARK_RED
                  + chatPrefix
                  + (Object) ChatColor.WHITE
                  + "Um auf diesem Server spielen zu können, musst du dich mithilfe eines Twitter Accounts freischalten. Dies kannst du wie folgt tun:\n"
                  + (Object) ChatColor.GOLD
                  + "/tww r");
      e.getPlayer().setGameMode(GameMode.SPECTATOR);
      unwhitelisteds.add(e.getPlayer().getUniqueId());
    } else {
      plugin.getLogger().info("Player" + e.getPlayer().getName() + " is whitelisted");
    }
  }