mirror of
https://github.com/NoCheatPlus/NoCheatPlus.git
synced 2025-03-02 10:31:25 +01:00
spamcheck message/command whitelist
This commit is contained in:
parent
3fc80cbad2
commit
d917242683
@ -3,7 +3,7 @@ name: NoCheat
|
||||
author: Evenprime
|
||||
|
||||
main: cc.co.evenprime.bukkit.nocheat.NoCheat
|
||||
version: 2.11a
|
||||
version: 2.12
|
||||
|
||||
commands:
|
||||
nocheat:
|
||||
|
@ -8,8 +8,6 @@ import cc.co.evenprime.bukkit.nocheat.config.cache.ConfigurationCache;
|
||||
import cc.co.evenprime.bukkit.nocheat.data.BaseData;
|
||||
|
||||
/**
|
||||
*
|
||||
* @author Evenprime
|
||||
*
|
||||
*/
|
||||
public class ChatCheck {
|
||||
@ -29,6 +27,14 @@ public class ChatCheck {
|
||||
|
||||
if(spamCheck) {
|
||||
|
||||
// Maybe it's a command and on the whitelist
|
||||
for(String s : cc.chat.spamWhitelist) {
|
||||
if(message.startsWith(s)) {
|
||||
// It is
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
int time = plugin.getIngameSeconds();
|
||||
|
||||
BaseData data = plugin.getPlayerData(player);
|
||||
|
@ -89,6 +89,7 @@ public abstract class Configuration {
|
||||
|
||||
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);
|
||||
public final static OptionNode CHAT_SPAM_TIMEFRAME = new OptionNode("timeframe", CHAT_SPAM, DataType.INTEGER);
|
||||
public final static OptionNode CHAT_SPAM_LIMIT = new OptionNode("limit", CHAT_SPAM, DataType.INTEGER);
|
||||
public final static OptionNode CHAT_SPAM_ACTIONS = new OptionNode("actions", CHAT_SPAM, DataType.ACTIONLIST);
|
||||
|
@ -130,6 +130,7 @@ public class DefaultConfiguration extends Configuration {
|
||||
setValue(CHAT_CHECK, true);
|
||||
|
||||
setValue(CHAT_SPAM_CHECK, true);
|
||||
setValue(CHAT_SPAM_WHITELIST, "");
|
||||
setValue(CHAT_SPAM_TIMEFRAME, 5);
|
||||
setValue(CHAT_SPAM_LIMIT, 5);
|
||||
|
||||
|
@ -74,6 +74,7 @@ public class Explainations {
|
||||
set(Configuration.CHAT_CHECK, "If true, do various checks on PlayerChat events.");
|
||||
|
||||
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.");
|
||||
set(Configuration.CHAT_SPAM_LIMIT, "How many messages per timeframe may the player send without it counting as spamming?");
|
||||
set(Configuration.CHAT_SPAM_ACTIONS, "What should be done if a player is trying to spam the chat.\nUnit is number of chat messages above the limit you declared above.");
|
||||
|
@ -1,5 +1,8 @@
|
||||
package cc.co.evenprime.bukkit.nocheat.config.cache;
|
||||
|
||||
import java.util.LinkedList;
|
||||
import java.util.List;
|
||||
|
||||
import cc.co.evenprime.bukkit.nocheat.config.Configuration;
|
||||
import cc.co.evenprime.bukkit.nocheat.config.util.ActionList;
|
||||
|
||||
@ -7,6 +10,7 @@ public class CCChat {
|
||||
|
||||
public final boolean check;
|
||||
public final boolean spamCheck;
|
||||
public final String[] spamWhitelist;
|
||||
public final int spamTimeframe;
|
||||
public final int spamLimit;
|
||||
public final ActionList spamActions;
|
||||
@ -15,9 +19,24 @@ public class CCChat {
|
||||
|
||||
check = data.getBoolean(Configuration.CHAT_CHECK);
|
||||
spamCheck = data.getBoolean(Configuration.CHAT_SPAM_CHECK);
|
||||
spamWhitelist = splitWhitelist(data.getString(Configuration.CHAT_SPAM_WHITELIST));
|
||||
spamTimeframe = data.getInteger(Configuration.CHAT_SPAM_TIMEFRAME);
|
||||
spamLimit = data.getInteger(Configuration.CHAT_SPAM_LIMIT);
|
||||
spamActions = data.getActionList(Configuration.CHAT_SPAM_ACTIONS);
|
||||
|
||||
}
|
||||
|
||||
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()]);
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user