Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import java.io.BufferedReader;
- import java.io.InputStreamReader;
- import java.io.OutputStreamWriter;
- import java.net.URL;
- import java.net.URLConnection;
- import java.net.URLEncoder;
- import java.util.Hashtable;
- import java.util.logging.Logger;
- import org.json.JSONObject;
- public class MCBan extends Plugin
- {
- private MCBan.Listener l = new MCBan.Listener(this);
- protected static final Logger log = Logger.getLogger("Minecraft");
- private String name = "MCBans";
- private PropertiesFile options = new PropertiesFile("mcban.properties");
- private PropertiesFile trustedlist = new PropertiesFile("mcban.trusted");
- public String line;
- public String playername;
- public String api_key = "meow";
- public String prefix = "[MCBans]";
- private Hashtable<String, String> ban_status = new Hashtable<String, String>();
- public String mod_grp = "";
- public Boolean allow_global_banned_read = Boolean.valueOf(false);
- public Boolean disable_global_ban = Boolean.valueOf(false);
- public Boolean offline_mode = Boolean.valueOf(false);
- public Boolean onconnect_msg = Boolean.valueOf(true);
- public String whitelist;
- public String ban_command;
- public String trusted_players;
- public String run_at_ban;
- private String version = "1.2.4";
- public void enable() {
- log.info(this.name + " " + this.version + " has been enabled");
- etc.getInstance().addCommand("/tempban", "MCBans temporary ban command");
- etc.getInstance().addCommand("/unban", "MCBans unban command");
- etc.getInstance().addCommand("/mcsay", "MCBans admin chat");
- }
- public void disable() {
- etc.getInstance().removeCommand(this.ban_command);
- etc.getInstance().removeCommand("/unban");
- etc.getInstance().removeCommand("/mcsay");
- etc.getInstance().removeCommand("/tempban");
- }
- public void initialize() {
- log.info(this.name + " " + this.version + " has been initialized");
- try {
- this.options.load();
- } catch (Exception localException) {
- }
- this.api_key = this.options.getString("api_key");
- this.allow_global_banned_read = Boolean.valueOf(this.options.getBoolean("api_key"));
- this.disable_global_ban = Boolean.valueOf(this.options.getBoolean("disable_global_ban"));
- this.whitelist = this.options.getString("whitelist");
- this.mod_grp = this.options.getString("mod_group");
- this.onconnect_msg = Boolean.valueOf(this.options.getBoolean("login_notify"));
- this.prefix = this.options.getString("prefix");
- this.ban_command = this.options.getString("ban_command");
- this.run_at_ban = this.options.getString("run_at_ban");
- this.trusted_players = this.trustedlist.getString("trusted_players");
- if (this.api_key.equalsIgnoreCase("")) {
- this.options.setString("api_key", "set_api_key_here");
- this.options.setBoolean("login_notify", this.onconnect_msg.booleanValue());
- this.options.setBoolean("allow_globally_banned_to_join_as_read_only", false);
- this.options.setBoolean("disable_global_ban", false);
- this.options.setString("whitelist", "[]");
- this.options.setString("run_at_ban", "");
- this.options.setString("prefix", this.prefix);
- this.options.setString("mod_group", "mod");
- this.options.setString("ban_command", "/ban");
- this.options.save();
- }
- if (this.trusted_players.equalsIgnoreCase("")) {
- this.trustedlist.setString("trusted_players", "[]");
- this.trustedlist.save();
- }
- if (this.whitelist.equalsIgnoreCase("")) {
- this.whitelist = "[]";
- }
- if (this.mod_grp.equalsIgnoreCase("")) {
- this.mod_grp = "mod";
- }
- if (this.trusted_players.equalsIgnoreCase("")) {
- this.trusted_players = "[]";
- }
- if (this.run_at_ban.equalsIgnoreCase("")) {
- this.run_at_ban = "";
- }
- if (this.ban_command.equalsIgnoreCase("")) {
- this.ban_command = "/ban";
- }
- l.save_settings();
- etc.getInstance().addCommand(this.ban_command, "MCBans ban command");
- if (l.request_from_api("exec=send_port&port=0").equalsIgnoreCase("")) {
- log.info("MCBans API [OFFLINE] resorting to backup list. (COMING SOON!)");
- offline_mode = Boolean.valueOf(true);
- } else {
- log.info("MCBans API [ONLINE]");
- }
- etc.getLoader().addListener(PluginLoader.Hook.COMMAND, this.l, this, PluginListener.Priority.MEDIUM);
- etc.getLoader().addListener(PluginLoader.Hook.SERVERCOMMAND, this.l, this, PluginListener.Priority.MEDIUM);
- etc.getLoader().addListener(PluginLoader.Hook.LOGIN, this.l, this, PluginListener.Priority.MEDIUM);
- etc.getLoader().addListener(PluginLoader.Hook.LOGINCHECK, this.l, this, PluginListener.Priority.MEDIUM);
- }
- public class Listener extends PluginListener {
- MCBan p;
- public Listener(MCBan plugin) {
- this.p = plugin;
- }
- private void save_settings()
- {
- MCBan.this.options.setString("api_key", MCBan.this.api_key);
- MCBan.this.options.setBoolean("login_notify", MCBan.this.onconnect_msg.booleanValue());
- MCBan.this.options.setBoolean("allow_globally_banned_to_join_as_read_only", MCBan.this.allow_global_banned_read.booleanValue());
- MCBan.this.options.setBoolean("disable_global_ban", MCBan.this.disable_global_ban.booleanValue());
- MCBan.this.options.setString("whitelist", MCBan.this.whitelist);
- MCBan.this.options.setString("run_at_ban", MCBan.this.run_at_ban);
- MCBan.this.options.setString("mod_group", MCBan.this.mod_grp);
- MCBan.this.options.setString("prefix", MCBan.this.prefix);
- MCBan.this.options.setString("ban_command", MCBan.this.ban_command);
- MCBan.this.options.save();
- }
- public String request_from_api(String data)
- {
- try
- {
- URL url = new URL("http://72.10.39.172/v2/" + this.p.api_key);
- URLConnection conn = url.openConnection();
- conn.setDoOutput(true);
- OutputStreamWriter wr = new OutputStreamWriter(conn.getOutputStream());
- wr.write(data);
- wr.flush();
- StringBuilder buf = new StringBuilder();
- BufferedReader rd = new BufferedReader(new InputStreamReader(conn.getInputStream()));
- while ((line = rd.readLine()) != null)
- {
- buf.append(line);
- }
- String result = buf.toString();
- wr.close();
- rd.close();
- try {
- if (result.equalsIgnoreCase("Server with that api key not found.")) {
- for (Player pi : etc.getServer().getPlayerList())
- if (pi.isAdmin())
- pi.sendMessage("§4" + MCBan.this.prefix + " api key is incorrect or your server is not setup!");
- }
- }
- catch (Exception localException1)
- {
- }
- return result; } catch (Exception e) {
- }
- return "";
- }
- public String onLoginChecks(String player)
- {
- try
- {
- String data = URLEncoder.encode("player", "UTF-8") + "=" + URLEncoder.encode(player, "UTF-8");
- data = data + "&" + URLEncoder.encode("version", "UTF-8") + "=" + URLEncoder.encode(this.p.version, "UTF-8");
- data = data + "&" + URLEncoder.encode("exec", "UTF-8") + "=" + URLEncoder.encode("user_connect", "UTF-8");
- String result = request_from_api(data);
- this.p.ban_status.put(player, result);
- JSONObject json = new JSONObject(result);
- if (json.getString("ban_status").equalsIgnoreCase("g")) {
- if ((!MCBan.this.disable_global_ban.booleanValue()) &&
- (!MCBan.this.allow_global_banned_read.booleanValue()))
- {
- return "You are globally banned, check mcbans.com";
- }
- }
- else {
- if (json.getString("ban_status").equalsIgnoreCase("l"))
- {
- return "You are banned from this server, check mcbans.com";
- }if (json.getString("ban_status").equalsIgnoreCase("t"))
- return ".:. Temporary Ban .:. Rejoin in " + json.getString("ban_remain");
- }
- } catch (Exception localException) {
- }
- return null;
- }
- public void onLogin(Player player)
- {
- try {
- String result = ((String)this.p.ban_status.get(player.getName())).toString();
- JSONObject json = new JSONObject(result);
- if (json.getString("owner").equalsIgnoreCase("y")) {
- player.sendMessage("§e" + MCBan.this.prefix + " Logged in as owner!");
- }
- if (json.getString("is_mcbans_mod").equalsIgnoreCase("y")) {
- player.sendMessage("§e" + MCBan.this.prefix + " Logged in as moderator!");
- }
- if (json.getString("ban_status").equalsIgnoreCase("g")) {
- if (MCBan.this.disable_global_ban.booleanValue()) {
- player.sendMessage("§4" + MCBan.this.prefix + " You are globally banned but are allowed in this server!");
- } else if (MCBan.this.allow_global_banned_read.booleanValue()) {
- player.sendMessage("§4" + MCBan.this.prefix + " Globally banned but allowed in the server as read only!");
- player.setCanModifyWorld(false);
- player.setIgnoreRestrictions(false);
- }
- } else if (json.getString("ban_status").equalsIgnoreCase("n"))
- {
- if (MCBan.this.onconnect_msg.booleanValue())
- player.sendMessage("§e" + MCBan.this.prefix + " Server secured by " + this.p.name + "!");
- }
- else if (json.getString("ban_status").equalsIgnoreCase("b")) {
- String ban_num = json.getString("ban_num");
- for (Player pi : etc.getServer().getPlayerList()) {
- if ((pi.isAdmin()) || (pi.isInGroup(MCBan.this.mod_grp)) || (player.canUseCommand("/ban"))) {
- pi.sendMessage("§4" + MCBan.this.prefix + player.getName() + " has " + ban_num + " ban(s) on record!");
- for (int v = 0; v < json.getJSONArray("ban_reasons").length(); v++) {
- pi.sendMessage("§4" + MCBan.this.prefix + (v + 1) + ". \"" + json.getJSONArray("ban_reasons").getString(v) + "\"");
- }
- }
- }
- player.sendMessage("§e" + MCBan.this.prefix + " You have bans on record, check mcbans.com!");
- }
- if ((json.getString("owner").equalsIgnoreCase("y")) && (json.getString("new_version").equalsIgnoreCase("y"))) {
- player.sendMessage("§e" + MCBan.this.prefix + " Your version of MCBans is out of date!");
- }
- if (json.getInt("disputes") != 0)
- player.sendMessage("§e" + MCBan.this.prefix + " " + json.getInt("disputes") + " Open Disputes!");
- } catch (Exception localException) {
- }
- }
- public boolean onCommand(Player player, String[] split) {
- if ((split[0].equalsIgnoreCase(MCBan.this.ban_command)) && (player.canUseCommand(MCBan.this.ban_command)))
- {
- try {
- if (split.length < 3) {
- player.sendMessage("§eusage = " + MCBan.this.ban_command + " <nick> <g(global)/l(local)> <reason>");
- return true;
- }
- if ((!split[2].equalsIgnoreCase("l")) && (!split[2].equalsIgnoreCase("local")) && (!split[2].equalsIgnoreCase("g")) && (!split[2].equalsIgnoreCase("global"))) {
- player.sendMessage("§eusage = " + MCBan.this.ban_command + " <nick> <g(global)/l(local)> <reason>");
- return true;
- }
- String reason = "";
- for (int x = 3; x < split.length; x++)
- if (reason.equalsIgnoreCase(""))
- reason = reason + split[x];
- else
- reason = reason + " " + split[x];
- try
- {
- playername = etc.getServer().matchPlayer(split[1]).getName();
- }
- catch (Exception e)
- {
- playername = split[1];
- }
- String data = URLEncoder.encode("player", "UTF-8") + "=" + URLEncoder.encode(playername, "UTF-8");
- data = data + "&" + URLEncoder.encode("reason", "UTF-8") + "=" + URLEncoder.encode(reason, "UTF-8");
- data = data + "&" + URLEncoder.encode("ban_admin", "UTF-8") + "=" + URLEncoder.encode(player.getName(), "UTF-8");
- data = data + "&" + URLEncoder.encode("duration", "UTF-8") + "=" + URLEncoder.encode("0", "UTF-8");
- if ((split[2].equalsIgnoreCase("l")) || (split[2].equalsIgnoreCase("local")))
- data = data + "&" + URLEncoder.encode("exec", "UTF-8") + "=" + URLEncoder.encode("ban_local_user", "UTF-8");
- else if ((split[2].equalsIgnoreCase("g")) || (split[2].equalsIgnoreCase("global"))) {
- data = data + "&" + URLEncoder.encode("exec", "UTF-8") + "=" + URLEncoder.encode("ban_user", "UTF-8");
- }
- String result = request_from_api(data);
- JSONObject json = new JSONObject(result);
- if (json.getString("result").equalsIgnoreCase("y"))
- {
- MCBan.log.info("Banned user: " + playername + " with the =Reason: " + reason + " =ADMIN: " + player.getName());
- for (Player pi : etc.getServer().getPlayerList()) {
- pi.sendMessage("§4" + MCBan.this.prefix + " " + playername + " was banned!");
- }
- try
- {
- etc.getServer().matchPlayer(split[1]).kick("You are banned from this server, check mcbans.com");
- }
- catch (Exception localException1)
- {
- }
- if (!MCBan.this.run_at_ban.equalsIgnoreCase(""))
- try {
- Runtime run = Runtime.getRuntime();
- Process pr = run.exec(MCBan.this.run_at_ban + " " + playername);
- pr.waitFor();
- } catch (Exception localException2) {
- }
- }
- else if (json.getString("result").equalsIgnoreCase("a")) {
- player.sendMessage("§4" + MCBan.this.prefix + " Player already banned from this server!");
- } else if (json.getString("result").equalsIgnoreCase("n")) {
- player.sendMessage("§4" + MCBan.this.prefix + " Could not ban the player with that name!");
- }
- } catch (Exception localException3) {
- }
- return true;
- }if ((split[0].equalsIgnoreCase("/unban")) && (player.canUseCommand("/unban"))) {
- try {
- if (split.length != 2) {
- player.sendMessage("§eusage = /unban <nick>");
- return true;
- }
- String data = URLEncoder.encode("player", "UTF-8") + "=" + URLEncoder.encode(split[1], "UTF-8");
- data = data + "&" + URLEncoder.encode("exec", "UTF-8") + "=" + URLEncoder.encode("unban_user", "UTF-8");
- String result = request_from_api(data);
- JSONObject json = new JSONObject(result);
- if (json.getString("result").equalsIgnoreCase("y")) {
- player.sendMessage("§2" + MCBan.this.prefix + " Unbanned the player with the name \"" + split[1] + "\"!");
- }
- else if (json.getString("result").equalsIgnoreCase("n"))
- player.sendMessage("§4" + MCBan.this.prefix + " Player with the name \"" + split[1] + "\" was not banned!");
- }
- catch (Exception localException4) {
- }
- return true;
- }if ((split[0].equalsIgnoreCase("/tempban")) && (player.canUseCommand("/tempban"))) {
- try {
- if (split.length != 4) {
- player.sendMessage("§eusage = /tempban <nick> <num> <m(minutes)/h(hours)/d(days)>");
- return true;
- }
- try {
- playername = etc.getServer().matchPlayer(split[1]).getName();
- }
- catch (Exception e)
- {
- playername = split[1];
- }
- String data = URLEncoder.encode("player", "UTF-8") + "=" + URLEncoder.encode(playername, "UTF-8");
- data = data + "&" + URLEncoder.encode("duration", "UTF-8") + "=" + URLEncoder.encode(split[2], "UTF-8");
- data = data + "&" + URLEncoder.encode("measure", "UTF-8") + "=" + URLEncoder.encode(split[3], "UTF-8");
- data = data + "&" + URLEncoder.encode("exec", "UTF-8") + "=" + URLEncoder.encode("tempban_user", "UTF-8");
- String result = request_from_api(data);
- JSONObject json = new JSONObject(result);
- if (json.getString("result").equalsIgnoreCase("y")) {
- player.sendMessage("§2" + MCBan.this.prefix + " Temporarily banned the player \"" + playername + "\"!");
- try {
- String measure = "";
- if ((split[3].equalsIgnoreCase("h")) || (split[3].equalsIgnoreCase("hours")))
- measure = "hour(s)";
- else if ((split[3].equalsIgnoreCase("m")) || (split[3].equalsIgnoreCase("minutes")))
- measure = "minute(s)";
- else if ((split[3].equalsIgnoreCase("d")) || (split[3].equalsIgnoreCase("days"))) {
- measure = "day(s)";
- }
- etc.getServer().matchPlayer(split[1]).kick("You are temporarily banned for " + split[2] + " " + measure);
- } catch (Exception localException5) {
- }
- } else if (json.getString("result").equalsIgnoreCase("n")) {
- player.sendMessage("§4" + MCBan.this.prefix + " Player with the name \"" + playername + "\" was not banned!");
- }
- } catch (Exception localException6) {
- }
- return true;
- }
- return false;
- }
- public boolean onConsoleCommand(String[] split) {
- if (split[0].equalsIgnoreCase(MCBan.this.ban_command.replace("/", "")))
- {
- try {
- if (split.length < 3) {
- MCBan.log.info("usage = " + MCBan.this.ban_command.replace("/", "") + " <nick> <g(global)/l(local)> <reason>");
- return true;
- }
- if ((!split[2].equalsIgnoreCase("l")) && (!split[2].equalsIgnoreCase("local")) && (!split[2].equalsIgnoreCase("g")) && (!split[2].equalsIgnoreCase("global"))) {
- MCBan.log.info("usage = " + MCBan.this.ban_command.replace("/", "") + " <nick> <g(global)/l(local)> <reason>");
- return true;
- }
- String reason = "";
- for (int x = 3; x < split.length; x++)
- if (reason.equalsIgnoreCase(""))
- reason = reason + split[x];
- else
- reason = reason + " " + split[x];
- try
- {
- playername = etc.getServer().matchPlayer(split[1]).getName();
- }
- catch (Exception e)
- {
- playername = split[1];
- }
- String data = URLEncoder.encode("player", "UTF-8") + "=" + URLEncoder.encode(playername, "UTF-8");
- data = data + "&" + URLEncoder.encode("reason", "UTF-8") + "=" + URLEncoder.encode(reason, "UTF-8");
- data = data + "&" + URLEncoder.encode("duration", "UTF-8") + "=" + URLEncoder.encode("0", "UTF-8");
- if ((split[2].equalsIgnoreCase("l")) || (split[2].equalsIgnoreCase("local")))
- data = data + "&" + URLEncoder.encode("exec", "UTF-8") + "=" + URLEncoder.encode("ban_local_user", "UTF-8");
- else if ((split[2].equalsIgnoreCase("g")) || (split[2].equalsIgnoreCase("global"))) {
- data = data + "&" + URLEncoder.encode("exec", "UTF-8") + "=" + URLEncoder.encode("ban_user", "UTF-8");
- }
- String result = request_from_api(data);
- JSONObject json = new JSONObject(result);
- if (json.getString("result").equalsIgnoreCase("y")) {
- try {
- etc.getLoader().callCustomHook("mcban_ban", new Object[] { "console", playername, reason });
- } catch (Exception e) {
- MCBan.log.info("failed? contact Firestar");
- }
- MCBan.log.info("Banned user: " + playername + " with the =Reason: " + reason);
- for (Player pi : etc.getServer().getPlayerList()) {
- pi.sendMessage("§4" + MCBan.this.prefix + " " + playername + " was banned!");
- }
- MCBan.log.info(MCBan.this.prefix + " " + playername + " was banned!");
- try
- {
- etc.getServer().matchPlayer(split[1]).kick("You are banned from this server, go to mcbans.com");
- }
- catch (Exception localException1)
- {
- }
- if (!MCBan.this.run_at_ban.equalsIgnoreCase(""))
- try {
- Runtime run = Runtime.getRuntime();
- Process pr = run.exec(MCBan.this.run_at_ban + " " + playername);
- pr.waitFor();
- } catch (Exception localException2) {
- }
- }
- else if (json.getString("result").equalsIgnoreCase("a")) {
- MCBan.log.info(MCBan.this.prefix + " Player is already banned!");
- } else if (json.getString("result").equalsIgnoreCase("n")) {
- MCBan.log.info(MCBan.this.prefix + " Could not ban the player with that name!");
- }
- } catch (Exception localException3) {
- }
- return true;
- }if (split[0].equalsIgnoreCase("unban")) {
- try {
- if (split.length != 2) {
- MCBan.log.info("usage = unban <nick>");
- return true;
- }
- String data = URLEncoder.encode("player", "UTF-8") + "=" + URLEncoder.encode(split[1], "UTF-8");
- data = data + "&" + URLEncoder.encode("exec", "UTF-8") + "=" + URLEncoder.encode("unban_user", "UTF-8");
- String result = request_from_api(data);
- JSONObject json = new JSONObject(result);
- if (json.getString("result").equalsIgnoreCase("y")) {
- MCBan.log.info(MCBan.this.prefix + " Unbanned the user \"" + split[1] + "\"!");
- }
- else if (json.getString("result").equalsIgnoreCase("n"))
- MCBan.log.info(MCBan.this.prefix + " Player with the name \"" + split[1] + "\" was not banned!");
- }
- catch (Exception localException4) {
- }
- return true;
- }if (split[0].equalsIgnoreCase("tempban")) {
- try {
- if (split.length != 4) {
- MCBan.log.info("usage = tempban <nick> <num> <m(minutes)/h(hours)/d(days)>");
- return true;
- }
- try {
- playername = etc.getServer().matchPlayer(split[1]).getName();
- }
- catch (Exception e)
- {
- playername = split[1];
- }
- String data = URLEncoder.encode("player", "UTF-8") + "=" + URLEncoder.encode(playername, "UTF-8");
- data = data + "&" + URLEncoder.encode("duration", "UTF-8") + "=" + URLEncoder.encode(split[2], "UTF-8");
- data = data + "&" + URLEncoder.encode("measure", "UTF-8") + "=" + URLEncoder.encode(split[3], "UTF-8");
- data = data + "&" + URLEncoder.encode("exec", "UTF-8") + "=" + URLEncoder.encode("tempban_user", "UTF-8");
- String result = request_from_api(data);
- JSONObject json = new JSONObject(result);
- MCBan.log.info("/Unban Response from server: " + result);
- if (json.getString("result").equalsIgnoreCase("y")) {
- MCBan.log.info(MCBan.this.prefix + " Temporarily banned the player \"" + playername + "\"!");
- try {
- String measure = "";
- if ((split[3].equalsIgnoreCase("h")) || (split[3].equalsIgnoreCase("hours")))
- measure = "hour(s)";
- else if ((split[3].equalsIgnoreCase("m")) || (split[3].equalsIgnoreCase("minutes")))
- measure = "minute(s)";
- else if ((split[3].equalsIgnoreCase("d")) || (split[3].equalsIgnoreCase("days"))) {
- measure = "day(s)";
- }
- etc.getServer().matchPlayer(split[1]).kick("You are temporarily banned for " + split[2] + " " + measure);
- } catch (Exception localException5) {
- }
- } else if (json.getString("result").equalsIgnoreCase("n")) {
- MCBan.log.info(MCBan.this.prefix + " Player with the name \"" + playername + "\" was not banned!");
- }
- } catch (Exception localException6) {
- }
- return true;
- }
- return false;
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment