spenk

MCBan

Feb 15th, 2012
240
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 23.88 KB | None | 0 0
  1. import java.io.BufferedReader;
  2. import java.io.InputStreamReader;
  3. import java.io.OutputStreamWriter;
  4. import java.net.URL;
  5. import java.net.URLConnection;
  6. import java.net.URLEncoder;
  7. import java.util.Hashtable;
  8. import java.util.logging.Logger;
  9. import org.json.JSONObject;
  10.  
  11. public class MCBan extends Plugin
  12. {
  13.   private MCBan.Listener l = new MCBan.Listener(this);
  14.   protected static final Logger log = Logger.getLogger("Minecraft");
  15.   private String name = "MCBans";
  16.   private PropertiesFile options = new PropertiesFile("mcban.properties");
  17.   private PropertiesFile trustedlist = new PropertiesFile("mcban.trusted");
  18.   public String line;
  19.   public String playername;
  20.   public String api_key = "meow";
  21.   public String prefix = "[MCBans]";
  22.   private Hashtable<String, String> ban_status = new Hashtable<String, String>();
  23.   public String mod_grp = "";
  24.   public Boolean allow_global_banned_read = Boolean.valueOf(false);
  25.   public Boolean disable_global_ban = Boolean.valueOf(false);
  26.   public Boolean offline_mode = Boolean.valueOf(false);
  27.   public Boolean onconnect_msg = Boolean.valueOf(true);
  28.   public String whitelist;
  29.   public String ban_command;
  30.   public String trusted_players;
  31.   public String run_at_ban;
  32.   private String version = "1.2.4";
  33.  
  34.   public void enable() {
  35.     log.info(this.name + " " + this.version + " has been enabled");
  36.     etc.getInstance().addCommand("/tempban", "MCBans temporary ban command");
  37.     etc.getInstance().addCommand("/unban", "MCBans unban command");
  38.     etc.getInstance().addCommand("/mcsay", "MCBans admin chat");
  39.   }
  40.   public void disable() {
  41.     etc.getInstance().removeCommand(this.ban_command);
  42.     etc.getInstance().removeCommand("/unban");
  43.     etc.getInstance().removeCommand("/mcsay");
  44.     etc.getInstance().removeCommand("/tempban");
  45.   }
  46.  
  47.   public void initialize() {
  48.     log.info(this.name + " " + this.version + " has been initialized");
  49.     try {
  50.       this.options.load();
  51.     } catch (Exception localException) {
  52.     }
  53.     this.api_key = this.options.getString("api_key");
  54.     this.allow_global_banned_read = Boolean.valueOf(this.options.getBoolean("api_key"));
  55.     this.disable_global_ban = Boolean.valueOf(this.options.getBoolean("disable_global_ban"));
  56.     this.whitelist = this.options.getString("whitelist");
  57.     this.mod_grp = this.options.getString("mod_group");
  58.     this.onconnect_msg = Boolean.valueOf(this.options.getBoolean("login_notify"));
  59.     this.prefix = this.options.getString("prefix");
  60.     this.ban_command = this.options.getString("ban_command");
  61.     this.run_at_ban = this.options.getString("run_at_ban");
  62.     this.trusted_players = this.trustedlist.getString("trusted_players");
  63.     if (this.api_key.equalsIgnoreCase("")) {
  64.       this.options.setString("api_key", "set_api_key_here");
  65.       this.options.setBoolean("login_notify", this.onconnect_msg.booleanValue());
  66.       this.options.setBoolean("allow_globally_banned_to_join_as_read_only", false);
  67.       this.options.setBoolean("disable_global_ban", false);
  68.       this.options.setString("whitelist", "[]");
  69.       this.options.setString("run_at_ban", "");
  70.       this.options.setString("prefix", this.prefix);
  71.       this.options.setString("mod_group", "mod");
  72.       this.options.setString("ban_command", "/ban");
  73.       this.options.save();
  74.     }
  75.     if (this.trusted_players.equalsIgnoreCase("")) {
  76.       this.trustedlist.setString("trusted_players", "[]");
  77.       this.trustedlist.save();
  78.     }
  79.     if (this.whitelist.equalsIgnoreCase("")) {
  80.       this.whitelist = "[]";
  81.     }
  82.     if (this.mod_grp.equalsIgnoreCase("")) {
  83.       this.mod_grp = "mod";
  84.     }
  85.     if (this.trusted_players.equalsIgnoreCase("")) {
  86.       this.trusted_players = "[]";
  87.     }
  88.     if (this.run_at_ban.equalsIgnoreCase("")) {
  89.       this.run_at_ban = "";
  90.     }
  91.     if (this.ban_command.equalsIgnoreCase("")) {
  92.       this.ban_command = "/ban";
  93.     }
  94.     l.save_settings();
  95.     etc.getInstance().addCommand(this.ban_command, "MCBans ban command");
  96.     if (l.request_from_api("exec=send_port&port=0").equalsIgnoreCase("")) {
  97.       log.info("MCBans API [OFFLINE] resorting to backup list. (COMING SOON!)");
  98.       offline_mode = Boolean.valueOf(true);
  99.     } else {
  100.       log.info("MCBans API [ONLINE]");
  101.     }
  102.     etc.getLoader().addListener(PluginLoader.Hook.COMMAND, this.l, this, PluginListener.Priority.MEDIUM);
  103.     etc.getLoader().addListener(PluginLoader.Hook.SERVERCOMMAND, this.l, this, PluginListener.Priority.MEDIUM);
  104.     etc.getLoader().addListener(PluginLoader.Hook.LOGIN, this.l, this, PluginListener.Priority.MEDIUM);
  105.     etc.getLoader().addListener(PluginLoader.Hook.LOGINCHECK, this.l, this, PluginListener.Priority.MEDIUM);
  106.   }
  107.  
  108.   public class Listener extends PluginListener {
  109.     MCBan p;
  110.  
  111.     public Listener(MCBan plugin) {
  112.       this.p = plugin;
  113.     }
  114.  
  115.     private void save_settings()
  116.     {
  117.       MCBan.this.options.setString("api_key", MCBan.this.api_key);
  118.       MCBan.this.options.setBoolean("login_notify", MCBan.this.onconnect_msg.booleanValue());
  119.       MCBan.this.options.setBoolean("allow_globally_banned_to_join_as_read_only", MCBan.this.allow_global_banned_read.booleanValue());
  120.       MCBan.this.options.setBoolean("disable_global_ban", MCBan.this.disable_global_ban.booleanValue());
  121.       MCBan.this.options.setString("whitelist", MCBan.this.whitelist);
  122.       MCBan.this.options.setString("run_at_ban", MCBan.this.run_at_ban);
  123.       MCBan.this.options.setString("mod_group", MCBan.this.mod_grp);
  124.       MCBan.this.options.setString("prefix", MCBan.this.prefix);
  125.       MCBan.this.options.setString("ban_command", MCBan.this.ban_command);
  126.       MCBan.this.options.save();
  127.     }
  128.  
  129.     public String request_from_api(String data)
  130.     {
  131.       try
  132.       {
  133.         URL url = new URL("http://72.10.39.172/v2/" + this.p.api_key);
  134.         URLConnection conn = url.openConnection();
  135.         conn.setDoOutput(true);
  136.         OutputStreamWriter wr = new OutputStreamWriter(conn.getOutputStream());
  137.         wr.write(data);
  138.         wr.flush();
  139.         StringBuilder buf = new StringBuilder();
  140.         BufferedReader rd = new BufferedReader(new InputStreamReader(conn.getInputStream()));
  141.         while ((line = rd.readLine()) != null)
  142.         {
  143.           buf.append(line);
  144.         }
  145.         String result = buf.toString();
  146.         wr.close();
  147.         rd.close();
  148.         try {
  149.           if (result.equalsIgnoreCase("Server with that api key not found.")) {
  150.             for (Player pi : etc.getServer().getPlayerList())
  151.               if (pi.isAdmin())
  152.                 pi.sendMessage("§4" + MCBan.this.prefix + " api key is incorrect or your server is not setup!");
  153.           }
  154.         }
  155.         catch (Exception localException1)
  156.         {
  157.         }
  158.         return result; } catch (Exception e) {
  159.       }
  160.       return "";
  161.     }
  162.  
  163.     public String onLoginChecks(String player)
  164.     {
  165.       try
  166.       {
  167.         String data = URLEncoder.encode("player", "UTF-8") + "=" + URLEncoder.encode(player, "UTF-8");
  168.         data = data + "&" + URLEncoder.encode("version", "UTF-8") + "=" + URLEncoder.encode(this.p.version, "UTF-8");
  169.         data = data + "&" + URLEncoder.encode("exec", "UTF-8") + "=" + URLEncoder.encode("user_connect", "UTF-8");
  170.         String result = request_from_api(data);
  171.  
  172.         this.p.ban_status.put(player, result);
  173.         JSONObject json = new JSONObject(result);
  174.  
  175.         if (json.getString("ban_status").equalsIgnoreCase("g")) {
  176.           if ((!MCBan.this.disable_global_ban.booleanValue()) &&
  177.             (!MCBan.this.allow_global_banned_read.booleanValue()))
  178.           {
  179.             return "You are globally banned, check mcbans.com";
  180.           }
  181.         }
  182.         else {
  183.           if (json.getString("ban_status").equalsIgnoreCase("l"))
  184.           {
  185.             return "You are banned from this server, check mcbans.com";
  186.           }if (json.getString("ban_status").equalsIgnoreCase("t"))
  187.             return ".:. Temporary Ban .:. Rejoin in " + json.getString("ban_remain");
  188.         }
  189.       } catch (Exception localException) {
  190.       }
  191.       return null;
  192.     }
  193.  
  194.     public void onLogin(Player player)
  195.     {
  196.       try {
  197.         String result = ((String)this.p.ban_status.get(player.getName())).toString();
  198.         JSONObject json = new JSONObject(result);
  199.         if (json.getString("owner").equalsIgnoreCase("y")) {
  200.           player.sendMessage("§e" + MCBan.this.prefix + " Logged in as owner!");
  201.         }
  202.         if (json.getString("is_mcbans_mod").equalsIgnoreCase("y")) {
  203.           player.sendMessage("§e" + MCBan.this.prefix + " Logged in as moderator!");
  204.         }
  205.  
  206.         if (json.getString("ban_status").equalsIgnoreCase("g")) {
  207.           if (MCBan.this.disable_global_ban.booleanValue()) {
  208.             player.sendMessage("§4" + MCBan.this.prefix + " You are globally banned but are allowed in this server!");
  209.           } else if (MCBan.this.allow_global_banned_read.booleanValue()) {
  210.             player.sendMessage("§4" + MCBan.this.prefix + " Globally banned but allowed in the server as read only!");
  211.             player.setCanModifyWorld(false);
  212.             player.setIgnoreRestrictions(false);
  213.           }
  214.         } else if (json.getString("ban_status").equalsIgnoreCase("n"))
  215.         {
  216.           if (MCBan.this.onconnect_msg.booleanValue())
  217.             player.sendMessage("§e" + MCBan.this.prefix + " Server secured by " + this.p.name + "!");
  218.         }
  219.         else if (json.getString("ban_status").equalsIgnoreCase("b")) {
  220.           String ban_num = json.getString("ban_num");
  221.           for (Player pi : etc.getServer().getPlayerList()) {
  222.             if ((pi.isAdmin()) || (pi.isInGroup(MCBan.this.mod_grp)) || (player.canUseCommand("/ban"))) {
  223.               pi.sendMessage("§4" + MCBan.this.prefix + player.getName() + " has " + ban_num + " ban(s) on record!");
  224.               for (int v = 0; v < json.getJSONArray("ban_reasons").length(); v++) {
  225.                 pi.sendMessage("§4" + MCBan.this.prefix + (v + 1) + ". \"" + json.getJSONArray("ban_reasons").getString(v) + "\"");
  226.               }
  227.             }
  228.           }
  229.           player.sendMessage("§e" + MCBan.this.prefix + " You have bans on record, check mcbans.com!");
  230.         }
  231.         if ((json.getString("owner").equalsIgnoreCase("y")) && (json.getString("new_version").equalsIgnoreCase("y"))) {
  232.           player.sendMessage("§e" + MCBan.this.prefix + " Your version of MCBans is out of date!");
  233.         }
  234.         if (json.getInt("disputes") != 0)
  235.           player.sendMessage("§e" + MCBan.this.prefix + " " + json.getInt("disputes") + " Open Disputes!");
  236.       } catch (Exception localException) {
  237.       }
  238.     }
  239.  
  240.     public boolean onCommand(Player player, String[] split) {
  241.       if ((split[0].equalsIgnoreCase(MCBan.this.ban_command)) && (player.canUseCommand(MCBan.this.ban_command)))
  242.       {
  243.         try {
  244.           if (split.length < 3) {
  245.             player.sendMessage("§eusage = " + MCBan.this.ban_command + " <nick> <g(global)/l(local)> <reason>");
  246.             return true;
  247.           }
  248.           if ((!split[2].equalsIgnoreCase("l")) && (!split[2].equalsIgnoreCase("local")) && (!split[2].equalsIgnoreCase("g")) && (!split[2].equalsIgnoreCase("global"))) {
  249.             player.sendMessage("§eusage = " + MCBan.this.ban_command + " <nick> <g(global)/l(local)> <reason>");
  250.             return true;
  251.           }
  252.           String reason = "";
  253.           for (int x = 3; x < split.length; x++)
  254.             if (reason.equalsIgnoreCase(""))
  255.               reason = reason + split[x];
  256.             else
  257.               reason = reason + " " + split[x];
  258.           try
  259.           {
  260.             playername = etc.getServer().matchPlayer(split[1]).getName();
  261.           }
  262.           catch (Exception e)
  263.           {
  264.             playername = split[1];
  265.           }
  266.           String data = URLEncoder.encode("player", "UTF-8") + "=" + URLEncoder.encode(playername, "UTF-8");
  267.           data = data + "&" + URLEncoder.encode("reason", "UTF-8") + "=" + URLEncoder.encode(reason, "UTF-8");
  268.           data = data + "&" + URLEncoder.encode("ban_admin", "UTF-8") + "=" + URLEncoder.encode(player.getName(), "UTF-8");
  269.           data = data + "&" + URLEncoder.encode("duration", "UTF-8") + "=" + URLEncoder.encode("0", "UTF-8");
  270.           if ((split[2].equalsIgnoreCase("l")) || (split[2].equalsIgnoreCase("local")))
  271.             data = data + "&" + URLEncoder.encode("exec", "UTF-8") + "=" + URLEncoder.encode("ban_local_user", "UTF-8");
  272.           else if ((split[2].equalsIgnoreCase("g")) || (split[2].equalsIgnoreCase("global"))) {
  273.             data = data + "&" + URLEncoder.encode("exec", "UTF-8") + "=" + URLEncoder.encode("ban_user", "UTF-8");
  274.           }
  275.  
  276.           String result = request_from_api(data);
  277.  
  278.           JSONObject json = new JSONObject(result);
  279.  
  280.           if (json.getString("result").equalsIgnoreCase("y"))
  281.           {
  282.             MCBan.log.info("Banned user: " + playername + " with the =Reason: " + reason + " =ADMIN: " + player.getName());
  283.             for (Player pi : etc.getServer().getPlayerList()) {
  284.               pi.sendMessage("§4" + MCBan.this.prefix + " " + playername + " was banned!");
  285.             }
  286.  
  287.             try
  288.             {
  289.               etc.getServer().matchPlayer(split[1]).kick("You are banned from this server, check mcbans.com");
  290.             }
  291.             catch (Exception localException1)
  292.             {
  293.             }
  294.  
  295.             if (!MCBan.this.run_at_ban.equalsIgnoreCase(""))
  296.               try {
  297.                 Runtime run = Runtime.getRuntime();
  298.                 Process pr = run.exec(MCBan.this.run_at_ban + " " + playername);
  299.                 pr.waitFor();
  300.               } catch (Exception localException2) {
  301.               }
  302.           }
  303.           else if (json.getString("result").equalsIgnoreCase("a")) {
  304.             player.sendMessage("§4" + MCBan.this.prefix + " Player already banned from this server!");
  305.           } else if (json.getString("result").equalsIgnoreCase("n")) {
  306.             player.sendMessage("§4" + MCBan.this.prefix + " Could not ban the player with that name!");
  307.           }
  308.         } catch (Exception localException3) {
  309.         }
  310.         return true;
  311.       }if ((split[0].equalsIgnoreCase("/unban")) && (player.canUseCommand("/unban"))) {
  312.         try {
  313.           if (split.length != 2) {
  314.             player.sendMessage("§eusage = /unban <nick>");
  315.             return true;
  316.           }
  317.  
  318.           String data = URLEncoder.encode("player", "UTF-8") + "=" + URLEncoder.encode(split[1], "UTF-8");
  319.           data = data + "&" + URLEncoder.encode("exec", "UTF-8") + "=" + URLEncoder.encode("unban_user", "UTF-8");
  320.  
  321.           String result = request_from_api(data);
  322.  
  323.           JSONObject json = new JSONObject(result);
  324.  
  325.           if (json.getString("result").equalsIgnoreCase("y")) {
  326.             player.sendMessage("§2" + MCBan.this.prefix + " Unbanned the player with the name \"" + split[1] + "\"!");
  327.           }
  328.           else if (json.getString("result").equalsIgnoreCase("n"))
  329.             player.sendMessage("§4" + MCBan.this.prefix + " Player with the name \"" + split[1] + "\" was not banned!");
  330.         }
  331.         catch (Exception localException4) {
  332.         }
  333.         return true;
  334.       }if ((split[0].equalsIgnoreCase("/tempban")) && (player.canUseCommand("/tempban"))) {
  335.         try {
  336.           if (split.length != 4) {
  337.             player.sendMessage("§eusage = /tempban <nick> <num> <m(minutes)/h(hours)/d(days)>");
  338.             return true;
  339.           }
  340.           try {
  341.             playername = etc.getServer().matchPlayer(split[1]).getName();
  342.           }
  343.           catch (Exception e)
  344.           {
  345.             playername = split[1];
  346.           }
  347.  
  348.           String data = URLEncoder.encode("player", "UTF-8") + "=" + URLEncoder.encode(playername, "UTF-8");
  349.           data = data + "&" + URLEncoder.encode("duration", "UTF-8") + "=" + URLEncoder.encode(split[2], "UTF-8");
  350.           data = data + "&" + URLEncoder.encode("measure", "UTF-8") + "=" + URLEncoder.encode(split[3], "UTF-8");
  351.           data = data + "&" + URLEncoder.encode("exec", "UTF-8") + "=" + URLEncoder.encode("tempban_user", "UTF-8");
  352.  
  353.           String result = request_from_api(data);
  354.  
  355.           JSONObject json = new JSONObject(result);
  356.  
  357.           if (json.getString("result").equalsIgnoreCase("y")) {
  358.             player.sendMessage("§2" + MCBan.this.prefix + " Temporarily banned the player \"" + playername + "\"!");
  359.             try {
  360.               String measure = "";
  361.               if ((split[3].equalsIgnoreCase("h")) || (split[3].equalsIgnoreCase("hours")))
  362.                 measure = "hour(s)";
  363.               else if ((split[3].equalsIgnoreCase("m")) || (split[3].equalsIgnoreCase("minutes")))
  364.                 measure = "minute(s)";
  365.               else if ((split[3].equalsIgnoreCase("d")) || (split[3].equalsIgnoreCase("days"))) {
  366.                 measure = "day(s)";
  367.               }
  368.               etc.getServer().matchPlayer(split[1]).kick("You are temporarily banned for " + split[2] + " " + measure);
  369.             } catch (Exception localException5) {
  370.             }
  371.           } else if (json.getString("result").equalsIgnoreCase("n")) {
  372.             player.sendMessage("§4" + MCBan.this.prefix + " Player with the name \"" + playername + "\" was not banned!");
  373.           }
  374.         } catch (Exception localException6) {
  375.         }
  376.         return true;
  377.       }
  378.  
  379.       return false;
  380.     }
  381.     public boolean onConsoleCommand(String[] split) {
  382.       if (split[0].equalsIgnoreCase(MCBan.this.ban_command.replace("/", "")))
  383.       {
  384.         try {
  385.           if (split.length < 3) {
  386.             MCBan.log.info("usage = " + MCBan.this.ban_command.replace("/", "") + " <nick> <g(global)/l(local)> <reason>");
  387.             return true;
  388.           }
  389.           if ((!split[2].equalsIgnoreCase("l")) && (!split[2].equalsIgnoreCase("local")) && (!split[2].equalsIgnoreCase("g")) && (!split[2].equalsIgnoreCase("global"))) {
  390.             MCBan.log.info("usage = " + MCBan.this.ban_command.replace("/", "") + " <nick> <g(global)/l(local)> <reason>");
  391.             return true;
  392.           }
  393.           String reason = "";
  394.           for (int x = 3; x < split.length; x++)
  395.             if (reason.equalsIgnoreCase(""))
  396.               reason = reason + split[x];
  397.             else
  398.               reason = reason + " " + split[x];
  399.           try
  400.           {
  401.             playername = etc.getServer().matchPlayer(split[1]).getName();
  402.           }
  403.           catch (Exception e)
  404.           {
  405.             playername = split[1];
  406.           }
  407.           String data = URLEncoder.encode("player", "UTF-8") + "=" + URLEncoder.encode(playername, "UTF-8");
  408.           data = data + "&" + URLEncoder.encode("reason", "UTF-8") + "=" + URLEncoder.encode(reason, "UTF-8");
  409.           data = data + "&" + URLEncoder.encode("duration", "UTF-8") + "=" + URLEncoder.encode("0", "UTF-8");
  410.           if ((split[2].equalsIgnoreCase("l")) || (split[2].equalsIgnoreCase("local")))
  411.             data = data + "&" + URLEncoder.encode("exec", "UTF-8") + "=" + URLEncoder.encode("ban_local_user", "UTF-8");
  412.           else if ((split[2].equalsIgnoreCase("g")) || (split[2].equalsIgnoreCase("global"))) {
  413.             data = data + "&" + URLEncoder.encode("exec", "UTF-8") + "=" + URLEncoder.encode("ban_user", "UTF-8");
  414.           }
  415.  
  416.           String result = request_from_api(data);
  417.  
  418.           JSONObject json = new JSONObject(result);
  419.           if (json.getString("result").equalsIgnoreCase("y")) {
  420.             try {
  421.               etc.getLoader().callCustomHook("mcban_ban", new Object[] { "console", playername, reason });
  422.             } catch (Exception e) {
  423.               MCBan.log.info("failed? contact Firestar");
  424.             }
  425.             MCBan.log.info("Banned user: " + playername + " with the =Reason: " + reason);
  426.             for (Player pi : etc.getServer().getPlayerList()) {
  427.               pi.sendMessage("§4" + MCBan.this.prefix + " " + playername + " was banned!");
  428.             }
  429.             MCBan.log.info(MCBan.this.prefix + " " + playername + " was banned!");
  430.             try
  431.             {
  432.               etc.getServer().matchPlayer(split[1]).kick("You are banned from this server, go to mcbans.com");
  433.             }
  434.             catch (Exception localException1)
  435.             {
  436.             }
  437.  
  438.             if (!MCBan.this.run_at_ban.equalsIgnoreCase(""))
  439.               try {
  440.                 Runtime run = Runtime.getRuntime();
  441.                 Process pr = run.exec(MCBan.this.run_at_ban + " " + playername);
  442.                 pr.waitFor();
  443.               } catch (Exception localException2) {
  444.               }
  445.           }
  446.           else if (json.getString("result").equalsIgnoreCase("a")) {
  447.             MCBan.log.info(MCBan.this.prefix + " Player is already banned!");
  448.           } else if (json.getString("result").equalsIgnoreCase("n")) {
  449.             MCBan.log.info(MCBan.this.prefix + " Could not ban the player with that name!");
  450.           }
  451.         } catch (Exception localException3) {
  452.         }
  453.         return true;
  454.       }if (split[0].equalsIgnoreCase("unban")) {
  455.         try {
  456.           if (split.length != 2) {
  457.             MCBan.log.info("usage = unban <nick>");
  458.             return true;
  459.           }
  460.  
  461.           String data = URLEncoder.encode("player", "UTF-8") + "=" + URLEncoder.encode(split[1], "UTF-8");
  462.           data = data + "&" + URLEncoder.encode("exec", "UTF-8") + "=" + URLEncoder.encode("unban_user", "UTF-8");
  463.  
  464.           String result = request_from_api(data);
  465.  
  466.           JSONObject json = new JSONObject(result);
  467.  
  468.           if (json.getString("result").equalsIgnoreCase("y")) {
  469.             MCBan.log.info(MCBan.this.prefix + " Unbanned the user \"" + split[1] + "\"!");
  470.           }
  471.           else if (json.getString("result").equalsIgnoreCase("n"))
  472.             MCBan.log.info(MCBan.this.prefix + " Player with the name \"" + split[1] + "\" was not banned!");
  473.         }
  474.         catch (Exception localException4) {
  475.         }
  476.         return true;
  477.       }if (split[0].equalsIgnoreCase("tempban")) {
  478.         try {
  479.           if (split.length != 4) {
  480.             MCBan.log.info("usage = tempban <nick> <num> <m(minutes)/h(hours)/d(days)>");
  481.             return true;
  482.           }
  483.           try {
  484.             playername = etc.getServer().matchPlayer(split[1]).getName();
  485.           }
  486.           catch (Exception e)
  487.           {
  488.             playername = split[1];
  489.           }
  490.  
  491.           String data = URLEncoder.encode("player", "UTF-8") + "=" + URLEncoder.encode(playername, "UTF-8");
  492.           data = data + "&" + URLEncoder.encode("duration", "UTF-8") + "=" + URLEncoder.encode(split[2], "UTF-8");
  493.           data = data + "&" + URLEncoder.encode("measure", "UTF-8") + "=" + URLEncoder.encode(split[3], "UTF-8");
  494.           data = data + "&" + URLEncoder.encode("exec", "UTF-8") + "=" + URLEncoder.encode("tempban_user", "UTF-8");
  495.  
  496.           String result = request_from_api(data);
  497.  
  498.           JSONObject json = new JSONObject(result);
  499.           MCBan.log.info("/Unban Response from server: " + result);
  500.           if (json.getString("result").equalsIgnoreCase("y")) {
  501.             MCBan.log.info(MCBan.this.prefix + " Temporarily banned the player \"" + playername + "\"!");
  502.             try {
  503.               String measure = "";
  504.               if ((split[3].equalsIgnoreCase("h")) || (split[3].equalsIgnoreCase("hours")))
  505.                 measure = "hour(s)";
  506.               else if ((split[3].equalsIgnoreCase("m")) || (split[3].equalsIgnoreCase("minutes")))
  507.                 measure = "minute(s)";
  508.               else if ((split[3].equalsIgnoreCase("d")) || (split[3].equalsIgnoreCase("days"))) {
  509.                 measure = "day(s)";
  510.               }
  511.               etc.getServer().matchPlayer(split[1]).kick("You are temporarily banned for " + split[2] + " " + measure);
  512.             } catch (Exception localException5) {
  513.             }
  514.           } else if (json.getString("result").equalsIgnoreCase("n")) {
  515.             MCBan.log.info(MCBan.this.prefix + " Player with the name \"" + playername + "\" was not banned!");
  516.           }
  517.         } catch (Exception localException6) {
  518.         }
  519.         return true;
  520.       }
  521.  
  522.       return false;
  523.     }
  524.   }
  525. }
Advertisement
Add Comment
Please, Sign In to add comment