diff --git a/plugin.yml b/plugin.yml index dff63e70..d3fbf6c3 100644 --- a/plugin.yml +++ b/plugin.yml @@ -11,6 +11,7 @@ main: cc.co.evenprime.bukkit.nocheat.NoCheat commands: nocheat: description: NoCheat command(s) + permission: nocheat.admin.commands usage: | / permlist player [permission] - to list the NoCheat relevant permissions of the player, optionally only those starting with [permission] / reload - to reload NoCheats configuration file(s), without reloading the plugin itself @@ -26,14 +27,8 @@ permissions: children: nocheat.admin.chatlog: description: Show log messages in the players chat - nocheat.admin.permlist: - description: allow use of the "nocheat permlist" command - nocheat.admin.reload: - description: allow use of the "nocheat reload" command - nocheat.admin.performance: - description: allow use of the "nocheat performance" command - nocheat.admin.playerinfo: - description: allow use of the "nocheat playerinfo" command + nocheat.admin.commands: + description: allow use of all of the "nocheat" commands nocheat.checks: description: Allow the player to bypass all checks children: @@ -73,6 +68,8 @@ permissions: children: nocheat.checks.chat.spam: description: Allow a player to send an infinite amount of chat messages + nocheat.checks.chat.color: + description: Allow a player to send colored chat messages nocheat.checks.chat.empty: description: Allow a player to send empty messages (normally not possible) nocheat.checks.fight: diff --git a/pom.xml b/pom.xml index a1fa899c..221a8cad 100644 --- a/pom.xml +++ b/pom.xml @@ -3,7 +3,7 @@ 4.0.0 cc.co.evenprime.bukkit NoCheat - 2.24b + 2.25 jar NoCheat diff --git a/src/cc/co/evenprime/bukkit/nocheat/checks/chat/CCChat.java b/src/cc/co/evenprime/bukkit/nocheat/checks/chat/CCChat.java index c7edc727..e4c07650 100644 --- a/src/cc/co/evenprime/bukkit/nocheat/checks/chat/CCChat.java +++ b/src/cc/co/evenprime/bukkit/nocheat/checks/chat/CCChat.java @@ -2,7 +2,6 @@ package cc.co.evenprime.bukkit.nocheat.checks.chat; import java.util.LinkedList; import java.util.List; - import cc.co.evenprime.bukkit.nocheat.ConfigItem; import cc.co.evenprime.bukkit.nocheat.config.Configuration; import cc.co.evenprime.bukkit.nocheat.config.util.ActionList; @@ -17,6 +16,8 @@ public class CCChat implements ConfigItem { public final ActionList spamActions; public final boolean emptyCheck; public final ActionList emptyActions; + public final boolean colorCheck; + public final ActionList colorActions; public CCChat(Configuration data) { @@ -28,6 +29,8 @@ public class CCChat implements ConfigItem { spamActions = data.getActionList(Configuration.CHAT_SPAM_ACTIONS); emptyCheck = data.getBoolean(Configuration.CHAT_EMPTY_CHECK); emptyActions = data.getActionList(Configuration.CHAT_EMPTY_ACTIONS); + colorCheck = data.getBoolean(Configuration.CHAT_COLOR_CHECK); + colorActions = data.getActionList(Configuration.CHAT_COLOR_ACTIONS); } diff --git a/src/cc/co/evenprime/bukkit/nocheat/checks/chat/ChatEventManager.java b/src/cc/co/evenprime/bukkit/nocheat/checks/chat/ChatEventManager.java index 75e5591d..04869753 100644 --- a/src/cc/co/evenprime/bukkit/nocheat/checks/chat/ChatEventManager.java +++ b/src/cc/co/evenprime/bukkit/nocheat/checks/chat/ChatEventManager.java @@ -3,12 +3,10 @@ package cc.co.evenprime.bukkit.nocheat.checks.chat; import java.util.ArrayList; import java.util.LinkedList; import java.util.List; - import org.bukkit.event.Event; import org.bukkit.event.Event.Priority; import org.bukkit.event.player.PlayerChatEvent; import org.bukkit.event.player.PlayerCommandPreprocessEvent; - import cc.co.evenprime.bukkit.nocheat.NoCheat; import cc.co.evenprime.bukkit.nocheat.NoCheatPlayer; import cc.co.evenprime.bukkit.nocheat.config.ConfigurationCacheStore; @@ -25,9 +23,10 @@ public class ChatEventManager extends EventManagerImpl { super(plugin); - this.checks = new ArrayList(2); + this.checks = new ArrayList(3); this.checks.add(new EmptyCheck(plugin)); this.checks.add(new SpamCheck(plugin)); + this.checks.add(new ColorCheck(plugin)); registerListener(Event.Type.PLAYER_CHAT, Priority.Lowest, true, plugin.getPerformance(EventType.CHAT)); registerListener(Event.Type.PLAYER_COMMAND_PREPROCESS, Priority.Lowest, true, plugin.getPerformance(EventType.CHAT)); @@ -63,7 +62,10 @@ public class ChatEventManager extends EventManagerImpl { if(cancelled) { event.setCancelled(cancelled); + } else { + event.setMessage(data.message); } + } public List getActiveChecks(ConfigurationCacheStore cc) { diff --git a/src/cc/co/evenprime/bukkit/nocheat/checks/chat/ColorCheck.java b/src/cc/co/evenprime/bukkit/nocheat/checks/chat/ColorCheck.java new file mode 100644 index 00000000..c18be915 --- /dev/null +++ b/src/cc/co/evenprime/bukkit/nocheat/checks/chat/ColorCheck.java @@ -0,0 +1,47 @@ +package cc.co.evenprime.bukkit.nocheat.checks.chat; + +import java.util.Locale; +import cc.co.evenprime.bukkit.nocheat.NoCheat; +import cc.co.evenprime.bukkit.nocheat.NoCheatPlayer; +import cc.co.evenprime.bukkit.nocheat.actions.ParameterName; +import cc.co.evenprime.bukkit.nocheat.config.Permissions; +import cc.co.evenprime.bukkit.nocheat.data.ChatData; + +public class ColorCheck extends ChatCheck { + + public ColorCheck(NoCheat plugin) { + super(plugin, "chat.color", Permissions.CHAT_COLOR); + } + + public boolean check(NoCheatPlayer player, ChatData data, CCChat cc) { + + if(data.message.matches(".*\247.*")) { + + data.colorVL += 1; + data.colorTotalVL += 1; + data.colorFailed++; + + boolean filter = executeActions(player, cc.colorActions.getActions(data.colorVL)); + + if(filter) { + // Remove color codes + data.message = data.message.replaceAll("\302\247", "").replaceAll("\247", ""); + } + } + + return false; + } + + @Override + public boolean isEnabled(CCChat cc) { + return cc.colorCheck; + } + + public String getParameter(ParameterName wildcard, NoCheatPlayer player) { + + if(wildcard == ParameterName.VIOLATIONS) + return String.format(Locale.US, "%d", (int) getData(player.getDataStore()).colorVL); + else + return super.getParameter(wildcard, player); + } +} diff --git a/src/cc/co/evenprime/bukkit/nocheat/command/CommandHandler.java b/src/cc/co/evenprime/bukkit/nocheat/command/CommandHandler.java index 3255cb91..7dd88f37 100644 --- a/src/cc/co/evenprime/bukkit/nocheat/command/CommandHandler.java +++ b/src/cc/co/evenprime/bukkit/nocheat/command/CommandHandler.java @@ -6,14 +6,11 @@ import java.util.LinkedList; import java.util.List; import java.util.Map; import java.util.Map.Entry; - import org.bukkit.command.Command; import org.bukkit.command.CommandSender; import org.bukkit.entity.Player; import org.bukkit.permissions.Permission; - import cc.co.evenprime.bukkit.nocheat.NoCheat; -import cc.co.evenprime.bukkit.nocheat.config.Permissions; import cc.co.evenprime.bukkit.nocheat.debug.Performance; import cc.co.evenprime.bukkit.nocheat.debug.PerformanceManager.EventType; @@ -23,11 +20,6 @@ public class CommandHandler { public static boolean handleCommand(NoCheat plugin, CommandSender sender, Command command, String label, String[] args) { - if(sender instanceof Player && !sender.hasPermission(Permissions.ADMIN_PLAYERINFO) && !sender.hasPermission(Permissions.ADMIN_PERMLIST) && !sender.hasPermission(Permissions.ADMIN_RELOAD) && !sender.hasPermission(Permissions.ADMIN_PERFORMANCE)) { - sender.sendMessage("Unknown command. Type \"help\" for help."); - return true; - } - boolean result = false; // Not our command if(!command.getName().equalsIgnoreCase("nocheat") || args.length == 0) { @@ -55,10 +47,6 @@ public class CommandHandler { } private static boolean handlePlayerInfoCommand(NoCheat plugin, CommandSender sender, String[] args) { - // Does the sender have permission? - if(sender instanceof Player && !sender.hasPermission(Permissions.ADMIN_PLAYERINFO)) { - return false; - } Map map = plugin.getPlayerData(args[1]); String filter = ""; @@ -77,10 +65,6 @@ public class CommandHandler { } private static boolean handlePermlistCommand(NoCheat plugin, CommandSender sender, String[] args) { - // Does the sender have permission to use it? - if(sender instanceof Player && !sender.hasPermission(Permissions.ADMIN_PERMLIST)) { - return false; - } // Get the player by name Player player = plugin.getServer().getPlayerExact(args[1]); @@ -132,10 +116,6 @@ public class CommandHandler { } private static boolean handleReloadCommand(NoCheat plugin, CommandSender sender) { - // Does the sender have permission? - if(sender instanceof Player && !sender.hasPermission(Permissions.ADMIN_RELOAD)) { - return false; - } sender.sendMessage("[NoCheat] Reloading configuration"); plugin.reloadConfiguration(); @@ -145,10 +125,6 @@ public class CommandHandler { } private static boolean handlePerformanceCommand(NoCheat plugin, CommandSender sender) { - // Does the sender have permission? - if(sender instanceof Player && !sender.hasPermission(Permissions.ADMIN_PERFORMANCE)) { - return false; - } sender.sendMessage("[NoCheat] Retrieving performance statistics"); diff --git a/src/cc/co/evenprime/bukkit/nocheat/config/Configuration.java b/src/cc/co/evenprime/bukkit/nocheat/config/Configuration.java index e1b3a694..31f7c213 100644 --- a/src/cc/co/evenprime/bukkit/nocheat/config/Configuration.java +++ b/src/cc/co/evenprime/bukkit/nocheat/config/Configuration.java @@ -2,7 +2,6 @@ package cc.co.evenprime.bukkit.nocheat.config; import java.util.HashMap; import java.util.Map; - import cc.co.evenprime.bukkit.nocheat.config.util.ActionList; import cc.co.evenprime.bukkit.nocheat.config.util.OptionNode; import cc.co.evenprime.bukkit.nocheat.config.util.OptionNode.DataType; @@ -106,6 +105,10 @@ public abstract class Configuration { private final static OptionNode CHAT = new OptionNode("chat", ROOT, DataType.PARENT); public final static OptionNode CHAT_CHECK = new OptionNode("check", CHAT, DataType.BOOLEAN); + private final static OptionNode CHAT_COLOR = new OptionNode("color", CHAT, DataType.PARENT); + public final static OptionNode CHAT_COLOR_CHECK = new OptionNode("check", CHAT_COLOR, DataType.BOOLEAN); + public final static OptionNode CHAT_COLOR_ACTIONS = new OptionNode("actions", CHAT_COLOR, DataType.ACTIONLIST); + private final static OptionNode CHAT_SPAM = new OptionNode("spam", CHAT, DataType.PARENT); public final static OptionNode CHAT_SPAM_CHECK = new OptionNode("check", CHAT_SPAM, DataType.BOOLEAN); public final static OptionNode CHAT_SPAM_WHITELIST = new OptionNode("whitelist", CHAT_SPAM, DataType.STRING); diff --git a/src/cc/co/evenprime/bukkit/nocheat/config/DefaultConfiguration.java b/src/cc/co/evenprime/bukkit/nocheat/config/DefaultConfiguration.java index 871bb65d..c82dbe74 100644 --- a/src/cc/co/evenprime/bukkit/nocheat/config/DefaultConfiguration.java +++ b/src/cc/co/evenprime/bukkit/nocheat/config/DefaultConfiguration.java @@ -4,7 +4,6 @@ import java.io.BufferedWriter; import java.io.File; import java.io.FileWriter; import java.io.IOException; - import cc.co.evenprime.bukkit.nocheat.config.util.ActionList; import cc.co.evenprime.bukkit.nocheat.config.util.ActionMapper; import cc.co.evenprime.bukkit.nocheat.log.LogLevel; @@ -153,6 +152,11 @@ public class DefaultConfiguration extends Configuration { { setValue(CHAT_CHECK, true); + setValue(CHAT_COLOR_CHECK, true); + ActionList colorActionList = new ActionList(); + colorActionList.setActions(0, action.getActions("colorLog chatCancel".split(" "))); + setValue(CHAT_COLOR_ACTIONS, colorActionList); + setValue(CHAT_SPAM_CHECK, true); setValue(CHAT_SPAM_WHITELIST, ""); setValue(CHAT_SPAM_TIMEFRAME, 5); @@ -269,6 +273,7 @@ public class DefaultConfiguration extends Configuration { w(w, "log nofallLog 0 5 med [player] failed [check]: tried to avoid fall damage for ~[falldistance] blocks. VL [violations]"); w(w, "log noswingLog 2 5 med [player] failed [check]: Didn't swing arm. VL [violations]"); w(w, "log emptyChatLog 0 5 med [player] failed [check]: Sent empty chat message. VL [violations]"); + w(w, "log colorLog 0 5 med [player] failed [check]: Sent colored chat message \"[text]\". VL [violations]"); w(w, "log dropLog 0 5 med [player] failed [check]: Tried to drop more items than allowed. VL [violations]"); w(w, ""); w(w, ""); diff --git a/src/cc/co/evenprime/bukkit/nocheat/config/Explainations.java b/src/cc/co/evenprime/bukkit/nocheat/config/Explainations.java index d4b706bc..1c5a88cc 100644 --- a/src/cc/co/evenprime/bukkit/nocheat/config/Explainations.java +++ b/src/cc/co/evenprime/bukkit/nocheat/config/Explainations.java @@ -2,7 +2,6 @@ package cc.co.evenprime.bukkit.nocheat.config; import java.util.HashMap; import java.util.Map; - import cc.co.evenprime.bukkit.nocheat.config.util.OptionNode; /** @@ -87,6 +86,8 @@ public class Explainations { set(Configuration.CHAT_CHECK, "If true, do various checks on PlayerChat events."); + set(Configuration.CHAT_COLOR_CHECK, "If true, check if a message sent by the player contains color codes."); + set(Configuration.CHAT_COLOR_ACTIONS, "What should be done if a player is trying to send colored messages.\n\"cancel\" means in this case that the color codes get removed from the message.\nUnit is number of colored chat messages sent by the player."); set(Configuration.CHAT_SPAM_CHECK, "If true, check if a player is spamming the chat."); set(Configuration.CHAT_SPAM_WHITELIST, "A list of messages that should be ignored by the spam check, seperated by ','. All messages/commands starting with one of these will be let through."); set(Configuration.CHAT_SPAM_TIMEFRAME, "Over what timeframe (in seconds) should the messages be counted?\nWhen the time is over, counting starts at 0 again."); diff --git a/src/cc/co/evenprime/bukkit/nocheat/config/Permissions.java b/src/cc/co/evenprime/bukkit/nocheat/config/Permissions.java index 5ece891a..adaf6064 100644 --- a/src/cc/co/evenprime/bukkit/nocheat/config/Permissions.java +++ b/src/cc/co/evenprime/bukkit/nocheat/config/Permissions.java @@ -30,6 +30,7 @@ public class Permissions { public final static String CHAT = CHECKS + ".chat"; public final static String CHAT_SPAM = CHAT + ".spam"; public static final String CHAT_EMPTY = CHAT + ".empty"; + public static final String CHAT_COLOR = CHAT + ".color"; public static final String FIGHT = CHECKS + ".fight"; public static final String FIGHT_DIRECTION = FIGHT + ".direction"; @@ -39,10 +40,7 @@ public class Permissions { public static final String TIMED_GODMODE = TIMED + ".godmode"; public final static String ADMIN_CHATLOG = ADMIN + ".chatlog"; - public static final String ADMIN_PERMLIST = ADMIN + ".permlist"; - public static final String ADMIN_RELOAD = ADMIN + ".reload"; - public static final String ADMIN_PERFORMANCE = ADMIN + ".performance"; - public static final String ADMIN_PLAYERINFO = ADMIN + ".playerinfo"; + public static final String ADMIN_COMMANDS = ADMIN + ".commands"; public static final String INVENTORY = CHECKS + ".inventory"; public static final String INVENTORY_DROP = INVENTORY + ".drop"; diff --git a/src/cc/co/evenprime/bukkit/nocheat/data/ChatData.java b/src/cc/co/evenprime/bukkit/nocheat/data/ChatData.java index 8812c7b1..2d7a10a4 100644 --- a/src/cc/co/evenprime/bukkit/nocheat/data/ChatData.java +++ b/src/cc/co/evenprime/bukkit/nocheat/data/ChatData.java @@ -1,7 +1,6 @@ package cc.co.evenprime.bukkit.nocheat.data; import java.util.Map; - import cc.co.evenprime.bukkit.nocheat.DataItem; /** @@ -15,6 +14,9 @@ public class ChatData implements DataItem { public int emptyVL; public int emptyTotalVL; public int emptyFailed; + public int colorVL; + public int colorTotalVL; + public int colorFailed; public int messageCount = 0; public long spamLastTime = 0; @@ -25,8 +27,10 @@ public class ChatData implements DataItem { public void collectData(Map map) { map.put("chat.spam.vl", (int) spamTotalVL); map.put("chat.empty.vl", (int) emptyTotalVL); + map.put("chat.color.vl", (int) colorTotalVL); map.put("chat.spam.failed", spamFailed); map.put("chat.empty.failed", emptyFailed); + map.put("chat.color.failed", colorFailed); } @Override