diff options
Diffstat (limited to 'EssentialsAntiCheat/src/com/earth2me/essentials/anticheat/checks/chat/ChatConfig.java')
-rw-r--r-- | EssentialsAntiCheat/src/com/earth2me/essentials/anticheat/checks/chat/ChatConfig.java | 64 |
1 files changed, 64 insertions, 0 deletions
diff --git a/EssentialsAntiCheat/src/com/earth2me/essentials/anticheat/checks/chat/ChatConfig.java b/EssentialsAntiCheat/src/com/earth2me/essentials/anticheat/checks/chat/ChatConfig.java new file mode 100644 index 000000000..06ad5c9fc --- /dev/null +++ b/EssentialsAntiCheat/src/com/earth2me/essentials/anticheat/checks/chat/ChatConfig.java @@ -0,0 +1,64 @@ +package com.earth2me.essentials.anticheat.checks.chat; + +import java.util.LinkedList; +import java.util.List; +import com.earth2me.essentials.anticheat.ConfigItem; +import com.earth2me.essentials.anticheat.actions.types.ActionList; +import com.earth2me.essentials.anticheat.config.ConfPaths; +import com.earth2me.essentials.anticheat.config.NoCheatConfiguration; +import com.earth2me.essentials.anticheat.config.Permissions; + + +/** + * Configurations specific for the "Chat" checks Every world gets one of these assigned to it, or if a world doesn't get + * it's own, it will use the "global" version + * + */ +public class ChatConfig implements ConfigItem +{ + public final boolean spamCheck; + public final String[] spamWhitelist; + public final long spamTimeframe; + public final int spamMessageLimit; + public final int spamCommandLimit; + public final ActionList spamActions; + public final boolean colorCheck; + public final ActionList colorActions; + + public ChatConfig(NoCheatConfiguration data) + { + + spamCheck = data.getBoolean(ConfPaths.CHAT_SPAM_CHECK); + spamWhitelist = splitWhitelist(data.getString(ConfPaths.CHAT_SPAM_WHITELIST)); + spamTimeframe = data.getInt(ConfPaths.CHAT_SPAM_TIMEFRAME) * 1000L; + spamMessageLimit = data.getInt(ConfPaths.CHAT_SPAM_MESSAGELIMIT); + spamCommandLimit = data.getInt(ConfPaths.CHAT_SPAM_COMMANDLIMIT); + spamActions = data.getActionList(ConfPaths.CHAT_SPAM_ACTIONS, Permissions.CHAT_SPAM); + colorCheck = data.getBoolean(ConfPaths.CHAT_COLOR_CHECK); + colorActions = data.getActionList(ConfPaths.CHAT_COLOR_ACTIONS, Permissions.CHAT_COLOR); + } + + /** + * Convenience method to split a string into an array on every occurance of the "," character, removing all + * whitespaces before and after it too. + * + * @param string The string containing text seperated by "," + * @return An array of the seperate texts + */ + private String[] splitWhitelist(String string) + { + + List<String> strings = new LinkedList<String>(); + string = string.trim(); + + for (String s : string.split(",")) + { + if (s != null && s.trim().length() > 0) + { + strings.add(s.trim()); + } + } + + return strings.toArray(new String[strings.size()]); + } +} |