From 1661e5cf99e66dd59da599eb655acddceec0a6dd Mon Sep 17 00:00:00 2001 From: j502647092 Date: Sun, 26 Jul 2015 18:02:17 +0800 Subject: [PATCH] complete spam class... Signed-off-by: j502647092 --- .../SimpleProtect/SimpleProtect.java | 3 +- .../citycraft/SimpleProtect/listen/Spam.java | 47 +++++++++---------- src/config.yml | 18 +++++-- src/plugin.yml | 6 ++- 4 files changed, 43 insertions(+), 31 deletions(-) diff --git a/src/cn/citycraft/SimpleProtect/SimpleProtect.java b/src/cn/citycraft/SimpleProtect/SimpleProtect.java index 2108a07..73afd72 100644 --- a/src/cn/citycraft/SimpleProtect/SimpleProtect.java +++ b/src/cn/citycraft/SimpleProtect/SimpleProtect.java @@ -92,7 +92,8 @@ public class SimpleProtect extends JavaPlugin { if (Config.getInstance().getBoolean("Spam.Enable", true)) { Spam spam = new Spam(this); Bukkit.getPluginManager().registerEvents(spam, this); - Bukkit.getScheduler().runTaskTimer(this, spam, 20, 20); + int resettime = Config.getInstance().getInt("Spam.MuteReset") * 20; + Bukkit.getScheduler().runTaskTimer(this, spam, resettime, resettime); getCommand("spam").setExecutor(spam); getLogger().info("防止玩家聊天刷屏已加载!"); } diff --git a/src/cn/citycraft/SimpleProtect/listen/Spam.java b/src/cn/citycraft/SimpleProtect/listen/Spam.java index b59c483..04d10cc 100644 --- a/src/cn/citycraft/SimpleProtect/listen/Spam.java +++ b/src/cn/citycraft/SimpleProtect/listen/Spam.java @@ -47,12 +47,12 @@ public class Spam implements Runnable, Listener, CommandExecutor { return false; } if (lt + plugin.getConfig().getLong("Spam.ChatWait", 1) > nt) { - AntiMsg = "请不要短时间内发送大量消息!"; + AntiMsg = plugin.getmessage("Spam.TooMuchChat"); return true; } if (lm.equals(s)) { if (lt + plugin.getConfig().getLong("Spam.SameChatWait", 5) > nt) { - AntiMsg = "请不要短时间内发送重复的消息!"; + AntiMsg = plugin.getmessage("Spam.TooMuchSameChat"); return true; } } @@ -71,12 +71,12 @@ public class Spam implements Runnable, Listener, CommandExecutor { return false; } if (lt + plugin.getConfig().getLong("Spam.CommandWait", 1) > nt) { - AntiMsg = "请不要短时间内发送大量命令"; + AntiMsg = plugin.getmessage("Spam.TooMuchCommand"); return true; } if (lm.equals(s)) { if (lt + plugin.getConfig().getLong("Spam.SameCommandWait", 3) > nt) { - AntiMsg = "请不要短时间内发送相同的命令"; + AntiMsg = plugin.getmessage("Spam.TooMuchSameCommand"); return true; } } @@ -86,40 +86,36 @@ public class Spam implements Runnable, Listener, CommandExecutor { @Override public boolean onCommand(CommandSender sender, Command command, String label, String[] args) { - if (command.getName().equalsIgnoreCase("spam")) { - if (!sender.hasPermission("spam.admin")) { - sender.sendMessage(plugin.servername + " " + plugin.getmessage("no-permission")); - return true; - } + if (command.getName().equalsIgnoreCase("sp")) { if (args.length == 2) { Player p = Bukkit.getPlayer(args[1]); if (args[0].equalsIgnoreCase("add")) { if (p != null) { cc.put(p, p); - sender.sendMessage(plugin.servername + " §c已禁止玩家 " + p.getDisplayName() - + " §c聊天!"); + sender.sendMessage(plugin.getfullmsg("Spam.MuteOn").replace("%player%", + p.getDisplayName())); } else { - sender.sendMessage(plugin.servername + " §c玩家不存在或不在线!"); + sender.sendMessage(plugin.getfullmsg("Spam.OffLine")); } } if (args[0].equalsIgnoreCase("del")) { if (p != null && cc.containsKey(p)) { cc.remove(p); - sender.sendMessage(plugin.servername + " §a已允许玩家 " + p.getDisplayName() - + " §a聊天!"); + sender.sendMessage(plugin.getfullmsg("Spam.MuteOff").replace("%player%", + p.getDisplayName())); } else { - sender.sendMessage(plugin.servername + " §c玩家未被禁言或不存在!"); + sender.sendMessage(plugin.getfullmsg("Spam.NotMute")); } } if (args[0].equalsIgnoreCase("admin")) { if (args[1].equalsIgnoreCase("on")) { adminchat = true; - sender.sendMessage(plugin.servername + " §a服务器已开启管理员聊天!"); + sender.sendMessage(plugin.getfullmsg("Spam.AdminChatOn")); return true; } if (args[1].equalsIgnoreCase("off")) { adminchat = false; - sender.sendMessage(plugin.servername + " §c服务器已关闭管理员聊天!"); + sender.sendMessage(plugin.getfullmsg("Spam.AdminChatOff")); return true; } } @@ -135,20 +131,20 @@ public class Spam implements Runnable, Listener, CommandExecutor { Player p = e.getPlayer(); String n = p.getName(); String s = e.getMessage(); - if (p.hasPermission("fcp.ignore.spam")) + if (p.hasPermission("sp.ignore.spam")) return; if (adminchat) { - p.sendMessage(plugin.servername + " §c服务器已开启管理员聊天!"); + p.sendMessage(plugin.getfullmsg("Spam.AdminChat")); e.setCancelled(true); return; } if (cc.containsKey(p)) { - p.sendMessage(plugin.servername + " §c您已被禁言,请联系管理员解禁!"); + p.sendMessage(plugin.getfullmsg("Spam.MuteMsg")); e.setCancelled(true); return; } if (AntiChat(n, s)) { - p.sendMessage(plugin.servername + "§6[§4刷屏检测§6] §c" + AntiMsg); + p.sendMessage(plugin.servername + plugin.pluginname + AntiMsg); e.setCancelled(true); put(p); } @@ -159,11 +155,10 @@ public class Spam implements Runnable, Listener, CommandExecutor { Player p = e.getPlayer(); String n = p.getName(); String s = e.getMessage(); - if (p.hasPermission("fcp.ignore.spam")) + if (p.hasPermission("sp.ignore.spam")) return; if (CommandWait(n, s)) { - put(p); - p.sendMessage(plugin.servername + "§6[§4命令检测§6] §c" + AntiMsg); + p.sendMessage(plugin.servername + plugin.pluginname + AntiMsg); e.setCancelled(true); } } @@ -171,8 +166,8 @@ public class Spam implements Runnable, Listener, CommandExecutor { public void put(Player p) { if (tc.containsKey(p)) { int t = tc.get(p); - if (t > plugin.getConfig().getLong("Spam.KickCheck", 3)) { - p.sendMessage(plugin.servername + " §c您由于多次刷屏已被禁言,请联系管理解禁!"); + if (t > plugin.getConfig().getLong("Spam.MuteCheck", 3)) { + p.sendMessage(plugin.getfullmsg("Spam.MuteMsg")); cc.put(p, p); } else { tc.put(p, t + 1); diff --git a/src/config.yml b/src/config.yml index c675c27..c4cd723 100644 --- a/src/config.yml +++ b/src/config.yml @@ -58,6 +58,18 @@ Spam: SameChatWait: 8 CommandWait: 2 SameCommandWait: 3 - KickCheck: 3 - KickReset: 10 - + MuteCheck: 3 + MuteReset: 3 + TooMuchChat: '请不要短时间内发送大量消息' + TooMuchSameChat: '请不要短时间内发送相同的信息' + TooMuchCommand: '请不要短时间内发送大量命令' + TooMuchSameCommand: '请不要短时间内发送相同的命令' + MuteOn: '&a已允许玩家 %player% &a聊天!' + MuteOff: '§c已禁止玩家 %player% §c聊天!' + OffLine: '&c玩家不存在或不在线!' + NotMute: '&c玩家未被禁言或不存在!' + AdminChatOn: '&a服务器已开启管理员聊天!' + AdminChatOff: '&c服务器已关闭管理员聊天!' + AdminChat: '&c服务器已开启管理员聊天!' + MuteMsg: '&c您由于多次刷屏已被禁言,请联系管理解禁!' + diff --git a/src/plugin.yml b/src/plugin.yml index 37f2b09..82087b2 100644 --- a/src/plugin.yml +++ b/src/plugin.yml @@ -25,9 +25,13 @@ permissions: children: sp.ignore.highredstone: true sp.ignore.nightvision: true + sp.ignore.spam: true sp.ignore.nightvision: description: 允许零亮度挖矿! default: op sp.ignore.highredstone: description: 允许忽略高频检测限制! - default: op \ No newline at end of file + default: op + sp.ignore.spam: + description: 允许忽略刷屏限制! + default: op \ No newline at end of file