summaryrefslogtreecommitdiffstats
path: root/EssentialsAntiCheat/src/com/earth2me/essentials/anticheat/checks/chat/ChatConfig.java
blob: 06ad5c9fcd7e057915efe3ef71dd6fcfd4286b2c (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
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()]);
	}
}