コード例 #1
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");
    }
  }
コード例 #2
0
  @Override
  public boolean onCommand(CommandSender sender, Command cmd, String label, String[] args) {
    // args[0] = commmand; args{1] is the first arg.....
    if (sender instanceof Player) {

      Player p = (Player) sender;
      if (cmd.getName().equalsIgnoreCase("tww")) {
        if (args.length < 1) {
          String tempMes;
          if (!p.hasPermission("TwitterWhitelist.Admin")) {
            // Kein Admin
            tempMes =
                "\n|------------------by derN3rd---------------------|\n"
                    + "| /tww r\n"
                    + "|  Verknüpft dein Twitteraccount\n"
                    + "| /tww confirm <Code>\n"
                    + "|  Bestätigt dein Acc mit einem Code\n"
                    + "| /twitter <Spielername>\n"
                    + "|  Gibt einen Link zum Twitter-Account aus\n"
                    + "|-------------------------------------------------|";
          } else {
            // Admin
            tempMes =
                "\n|-------------------------------------------------|\n"
                    + "| /tww r\n"
                    + "|  Verknüpft dein Twitteraccount\n"
                    + "| /tww confirm <Code>\n"
                    + "|  Bestätigt dein Acc mit einem Code\n"
                    + "| /twitter <Spielername>\n"
                    + "|  Gibt einen Link zum Twitter-Account aus\n"
                    + "| /tww reload\n"
                    + "|  Lädt die config.yml neu\n"
                    + "| /tww update\n"
                    + "|  Updatet alle Twitter-Accounts\n"
                    + "| /tww update <Playername>\n"
                    + "|  Updatet den speziefischen Player\n"
                    + "| /tww adm\n"
                    + "|  Gibt Infos über die DB aus\n"
                    + "| /tww adm rm <Playername>\n"
                    + "|  Entfernt das Twitter-Account des Spielers\n"
                    + "|-------------------------------------------------|";
          }
          p.sendMessage(
              (Object) ChatColor.DARK_RED + chatPrefix + (Object) ChatColor.RED + tempMes);
        } else {
          if (args[0].equalsIgnoreCase("r") || args[0].equalsIgnoreCase("register")) {
            // check if already confirmed before
            TwitterAPI.registerAccount(p);
          } else if (args[0].equalsIgnoreCase("confirm")) {
            // check if already confirmed before
            if (args.length > 1) {
              TwitterAPI.confirmAccount(args[1], p);
            } else {
              p.sendMessage(
                  (Object) ChatColor.DARK_RED
                      + chatPrefix
                      + (Object) ChatColor.RED
                      + "Bitte gebe den Code ein. /tww confirm <Code>");
            }
          } else if (args[0].equalsIgnoreCase("reload")) {
            if (!p.hasPermission("TwitterWhitelist.Admin")) {
              p.sendMessage(
                  (Object) ChatColor.DARK_RED
                      + chatPrefix
                      + (Object) ChatColor.RED
                      + "Das darfst du leider nicht :c");
            } else {
              this.reloadConfig();
              p.sendMessage(
                  (Object) ChatColor.DARK_RED
                      + chatPrefix
                      + (Object) ChatColor.GREEN
                      + "config.yml wurde neu geladen.");
            }
          } else if (args[0].equalsIgnoreCase("adm")) {
            if (args.length > 1 && args[1].equalsIgnoreCase("rm")) {
              if (!p.hasPermission("TwitterWhitelist.Admin")) {
                p.sendMessage(
                    (Object) ChatColor.DARK_RED
                        + chatPrefix
                        + (Object) ChatColor.RED
                        + "Das darfst du leider nicht :c");
              } else {
                if (args.length > 2) {
                  Player arguPlayer = plugin.getServer().getPlayer(args[2]);
                  if (arguPlayer == null) {
                    // Player not found
                    TwitterAPI.removeOfflineUser(args[2], p);
                  } else {
                    TwitterAPI.removeUser(arguPlayer, p);
                  }
                } else {
                  // no arg for rm given
                  p.sendMessage(
                      (Object) ChatColor.DARK_RED
                          + chatPrefix
                          + (Object) ChatColor.RED
                          + "/tww adm rm <Spielername>");
                }
              }
            } else if (args.length > 1 && args[1].equalsIgnoreCase("ban")) {
              if (!p.hasPermission("TwitterWhitelist.Admin")) {
                p.sendMessage(
                    (Object) ChatColor.DARK_RED
                        + chatPrefix
                        + (Object) ChatColor.RED
                        + "Das darfst du leider nicht :c");
              } else {
                if (args.length > 2) {
                  Player arguPlayer = plugin.getServer().getPlayer(args[2]);
                  if (arguPlayer == null) {
                    // Player not found
                    // TODO: Implement banning of offline players
                  } else {
                    TwitterAPI.banUser(p, arguPlayer);
                  }
                } else {
                  // no arg for rm given
                  p.sendMessage(
                      (Object) ChatColor.DARK_RED
                          + chatPrefix
                          + (Object) ChatColor.RED
                          + "/tww adm rm <Spielername>");
                }
              }
            } else { // Only /tww adm was typed
              TwitterAPI.getDBstats(p);
            }

          } else if (args[0].equalsIgnoreCase("update")) {
            if (!p.hasPermission("TwitterWhitelist.Admin")) {
              p.sendMessage(
                  (Object) ChatColor.DARK_RED
                      + chatPrefix
                      + (Object) ChatColor.RED
                      + "Das darfst du leider nicht :c");
            } else {
              if (args.length > 1) {
                // update specific user
                Player arguPlayer = plugin.getServer().getPlayer(args[1]);
                if (arguPlayer == null) {
                  p.sendMessage(
                      (Object) ChatColor.DARK_RED
                          + chatPrefix
                          + (Object) ChatColor.RED
                          + "Spieler nicht gefunden!");
                } else {
                  TwitterAPI.adminUpdateAccounts(p, arguPlayer);
                }
              } else {
                // update all
                p.sendMessage(
                    (Object) ChatColor.DARK_RED
                        + chatPrefix
                        + (Object) ChatColor.RED
                        + "Hier würden alle Player geupdatet werden, aber: Not implemented c:");
              }
            }
          }
        }
      } else if (cmd.getName().equalsIgnoreCase("twitter")) {
        if (!p.hasPermission("TwitterWhitelist.Lookup")) {
          p.sendMessage(
              (Object) ChatColor.DARK_RED
                  + chatPrefix
                  + (Object) ChatColor.RED
                  + "Das darfst du leider nicht :c");
        } else {
          if (args.length < 1) {
            p.sendMessage(
                (Object) ChatColor.DARK_RED
                    + chatPrefix
                    + (Object) ChatColor.RED
                    + "Bitte gib einen Spielernamen an."
                    + (Object) ChatColor.GOLD
                    + " /twitter <Spielername>");
          } else {
            Player player = plugin.getServer().getPlayer(args[0]);
            if (player == null) {
              p.sendMessage(
                  (Object) ChatColor.DARK_RED
                      + chatPrefix
                      + (Object) ChatColor.RED
                      + "Spieler "
                      + (Object) ChatColor.GOLD
                      + args[0]
                      + (Object) ChatColor.RED
                      + " nicht gefunden bzw. nicht online. Beginne Offline-Suche...");
              TwitterAPI.lookupOfflineUser(args[0], p);
            } else {
              TwitterAPI.lookupUser(player, p);
            }
          }
        }
      }
    }
    return false;
  }