From 322f233ce0adc264e61eb07fd632e2f5dcd3a024 Mon Sep 17 00:00:00 2001 From: Jerom van der Sar Date: Tue, 18 Sep 2012 16:40:48 +0200 Subject: [PATCH] added permban feature --- .../Commands/Command_halt.java | 22 +++++- .../Commands/Command_permban.java | 78 +++++++++++++++++++ .../Listener/TFM_PlayerListener.java | 19 +++++ .../TotalFreedomMod/TFM_UserInfo.java | 2 +- .../TotalFreedomMod/TotalFreedomMod.java | 38 ++++++++- src/permban.yml | 10 +++ src/plugin.yml | 3 + 7 files changed, 169 insertions(+), 3 deletions(-) create mode 100644 src/me/StevenLawson/TotalFreedomMod/Commands/Command_permban.java create mode 100644 src/permban.yml diff --git a/src/me/StevenLawson/TotalFreedomMod/Commands/Command_halt.java b/src/me/StevenLawson/TotalFreedomMod/Commands/Command_halt.java index 9adcabb4..d80656e1 100644 --- a/src/me/StevenLawson/TotalFreedomMod/Commands/Command_halt.java +++ b/src/me/StevenLawson/TotalFreedomMod/Commands/Command_halt.java @@ -57,6 +57,27 @@ public class Command_halt extends TFM_Command return true; } + if(args[0].equalsIgnoreCase("list")) + { + TFM_Util.playerMsg(sender, "Halted players:"); + TFM_UserInfo info; + int count = 0; + for (Player hp : server.getOnlinePlayers()) + { + info = TFM_UserInfo.getPlayerData(hp); + if (info.isHalted()) + { + TFM_Util.playerMsg(sender, "- " + hp.getName()); + count++; + } + } + if (count == 0) + { + TFM_Util.playerMsg(sender, "- none"); + } + return true; + } + Player p; try { @@ -112,7 +133,6 @@ public class Command_halt extends TFM_Command playerdata.setFrozen(false); playerdata.setMuted(false); playerdata.setHalted(false); - TFM_Util.playerMsg(p, "You are no longer halted."); } } diff --git a/src/me/StevenLawson/TotalFreedomMod/Commands/Command_permban.java b/src/me/StevenLawson/TotalFreedomMod/Commands/Command_permban.java new file mode 100644 index 00000000..765419d3 --- /dev/null +++ b/src/me/StevenLawson/TotalFreedomMod/Commands/Command_permban.java @@ -0,0 +1,78 @@ +package me.StevenLawson.TotalFreedomMod.Commands; + +import me.StevenLawson.TotalFreedomMod.TFM_Util; +import me.StevenLawson.TotalFreedomMod.TotalFreedomMod; + +import org.bukkit.command.Command; +import org.bukkit.command.CommandSender; +import org.bukkit.entity.Player; + +public class Command_permban extends TFM_Command +{ + @Override + public boolean run(CommandSender sender, Player sender_p, Command cmd, String commandLabel, String[] args, boolean senderIsConsole) + { + if(!sender.isOp()) + { + sender.sendMessage(TotalFreedomMod.MSG_NO_PERMS); + return true; + } + + if(args.length != 1) + { + return false; + } + + if(args[0].equalsIgnoreCase("list")) + { + TFM_Util.playerMsg(sender, "Permanently banned players:"); + int count = 0; + for (String pbp : TotalFreedomMod.permbanned_players) + { + TFM_Util.playerMsg(sender, "- " + pbp); + count++; + } + if (count == 0) + { + TFM_Util.playerMsg(sender, "- none"); + } + else + { + TFM_Util.playerMsg(sender, "Total: " + count); + } + + count = 0; + TFM_Util.playerMsg(sender, "Permanently banned IPs:"); + for (String pbp : TotalFreedomMod.permbanned_ips) + { + TFM_Util.playerMsg(sender, "- " + pbp); + count++; + } + if (count == 0) + { + TFM_Util.playerMsg(sender, "- none"); + } + else + { + TFM_Util.playerMsg(sender, "Total: " + count); + } + + return true; + } + + if(!senderIsConsole) + { + sender.sendMessage(TotalFreedomMod.MSG_NO_PERMS); + return true; + } + + if(args[0].equalsIgnoreCase("reload")) + { + plugin.loadPermbanConfig(); + return true; + } + + // no command executed + return false; + } +} diff --git a/src/me/StevenLawson/TotalFreedomMod/Listener/TFM_PlayerListener.java b/src/me/StevenLawson/TotalFreedomMod/Listener/TFM_PlayerListener.java index 06f51471..bd879ad4 100644 --- a/src/me/StevenLawson/TotalFreedomMod/Listener/TFM_PlayerListener.java +++ b/src/me/StevenLawson/TotalFreedomMod/Listener/TFM_PlayerListener.java @@ -720,6 +720,25 @@ public class TFM_PlayerListener implements Listener return; } } + + for(String test_player : TotalFreedomMod.permbanned_players) + { + if(test_player.equalsIgnoreCase(player_name)) + { + event.disallow(PlayerLoginEvent.Result.KICK_BANNED, ChatColor.RED + "Your username is permanently banned from this server."); + return; + } + } + + for(String test_ip : TotalFreedomMod.permbanned_ips) + { + if(test_ip.equalsIgnoreCase(player_ip)) + { + event.disallow(PlayerLoginEvent.Result.KICK_BANNED, ChatColor.RED + "Your IP-address is permanently banned from this server."); + return; + } + } + } else { diff --git a/src/me/StevenLawson/TotalFreedomMod/TFM_UserInfo.java b/src/me/StevenLawson/TotalFreedomMod/TFM_UserInfo.java index 52f298f8..eba58aac 100644 --- a/src/me/StevenLawson/TotalFreedomMod/TFM_UserInfo.java +++ b/src/me/StevenLawson/TotalFreedomMod/TFM_UserInfo.java @@ -342,7 +342,7 @@ public class TFM_UserInfo public boolean isHalted() { - return this.is_halted; + return is_halted; } public void setHalted(boolean is_halted) diff --git a/src/me/StevenLawson/TotalFreedomMod/TotalFreedomMod.java b/src/me/StevenLawson/TotalFreedomMod/TotalFreedomMod.java index 12c9b101..5c2ccb9a 100644 --- a/src/me/StevenLawson/TotalFreedomMod/TotalFreedomMod.java +++ b/src/me/StevenLawson/TotalFreedomMod/TotalFreedomMod.java @@ -27,6 +27,7 @@ public class TotalFreedomMod extends JavaPlugin public static final long HEARTBEAT_RATE = 5L; //Seconds public static final String CONFIG_FILE = "config.yml"; public static final String SUPERADMIN_FILE = "superadmin.yml"; + public static final String PERMBAN_FILE = "permban.yml"; public static final String COMMAND_PATH = "me.StevenLawson.TotalFreedomMod.Commands"; public static final String COMMAND_PREFIX = "Command_"; @@ -54,9 +55,10 @@ public class TotalFreedomMod extends JavaPlugin TotalFreedomMod.pluginName = this.getDescription().getName(); setAppProperties(); - + loadMainConfig(); loadSuperadminConfig(); + loadPermbanConfig(); TFM_UserList.getInstance(this); @@ -231,6 +233,40 @@ public class TotalFreedomMod extends JavaPlugin } } } + + TFM_Log.info("Loaded " + superadmins.size() + " superadmins"); + TFM_Log.info("Loaded " + superadmin_ips.size() + " superadmin IPs"); + } + + public static List permbanned_players = new ArrayList(); + public static List permbanned_ips = new ArrayList(); + + public void loadPermbanConfig() + { + TFM_Util.createDefaultConfiguration(PERMBAN_FILE, getFile()); + + FileConfiguration config = YamlConfiguration.loadConfiguration(new File(getDataFolder(), PERMBAN_FILE)); + + permbanned_players = new ArrayList(); + permbanned_ips = new ArrayList(); + + for (String user : config.getKeys(false)) + { + permbanned_players.add(user.toLowerCase().trim()); + + List user_ips = (List) config.getStringList(user); + for (String ip : user_ips) + { + ip = ip.toLowerCase().trim(); + if (!permbanned_ips.contains(ip)) + { + permbanned_ips.add(ip); + } + } + } + + TFM_Log.info("Loaded " + permbanned_players.size() + " permanently banned players"); + TFM_Log.info("Loaded " + permbanned_ips.size() + " permanently banned IPs"); } private void registerEventHandlers() diff --git a/src/permban.yml b/src/permban.yml new file mode 100644 index 00000000..1c6cd0d1 --- /dev/null +++ b/src/permban.yml @@ -0,0 +1,10 @@ +# +# Permanent bans +# Only to be modified by markbyron +# + +badplayer1: + - 123.123.123.123 + - 321.321.321.321 +badplayer2: + - 111.111.111.111 \ No newline at end of file diff --git a/src/plugin.yml b/src/plugin.yml index e4911429..a2325820 100644 --- a/src/plugin.yml +++ b/src/plugin.yml @@ -125,6 +125,9 @@ commands: orbit: description: Superadmin command - POW!!! Right in the kisser! One of these days Alice, straight to the Moon! usage: / [power] + permban: + description: Manage permanently banned players and IPs + usage: / prelog: description: Superadmin command - Enable/disable the command prelogger. When this is on, logs will be filled with many duplicate messages. usage: /