Exemplo n.º 1
0
  public void onEnable() {
    plugin = this;
    this.getConfig().options().copyDefaults(true);
    this.saveConfig();
    tweetEnabled = this.getConfig().getBoolean("TwitterWhitelist.SendTweetAfterRegistration");
    mySQLHost = this.getConfig().getString("TwitterWhitelist.MySQL.Host");
    mySQLDB = this.getConfig().getString("TwitterWhitelist.MySQL.DB");
    mySQLPort = this.getConfig().getInt("TwitterWhitelist.MySQL.Port");
    mySQLUser = this.getConfig().getString("TwitterWhitelist.MySQL.User");
    mySQLPass = this.getConfig().getString("TwitterWhitelist.MySQL.Pass");
    twKey = this.getConfig().getString("TwitterWhitelist.Twitter.ConsumerKey");
    twSecret = this.getConfig().getString("TwitterWhitelist.Twitter.ConsumerSecret");
    mySQLURL = "jdbc:mysql://" + mySQLHost + ":" + mySQLPort + "/" + mySQLDB;
    try { // We use a try catch to avoid errors, hopefully we don't get any.
      Class.forName("com.mysql.jdbc.Driver"); // this accesses Driver in jdbc.
    } catch (ClassNotFoundException e) {
      // e.printStackTrace();
      this.getLogger().warning("Couldn't access jdbc driver: " + e.getMessage() + "\n");
    }
    try {
      connection = DriverManager.getConnection(mySQLURL, mySQLUser, mySQLPass);
    } catch (SQLException e) {
      // e.printStackTrace();
      this.getLogger().warning("Couldn't open MySQL Connection: " + e.getMessage() + "\n");
    }

    setUpMySQL();
    this.getServer().getPluginManager().registerEvents(this, this);

    plugin
        .getServer()
        .getScheduler()
        .scheduleSyncRepeatingTask(
            plugin,
            new Runnable() {
              public void run() {
                // do stuff
                TwitterAPI.keepMySQLAlive();
              }
            },
            1L,
            6000L);
  }
Exemplo n.º 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;
  }