Add granular command spam exemption via permissions

This commit is contained in:
gravitylow committed 2013-12-11 14:55:39 -05:00
1 parent d6fbd7d5f3
commit c6d232d493
2 files changed
+8 -2

No files matched your search

@@ -45,7 +45,7 @@ public class PlayerListener extends EventListener {
@EventHandler(priority = EventPriority.HIGHEST, ignoreCancelled = true)
public void onPlayerCommandPreprocess(PlayerCommandPreprocessEvent event) {
Player player = event.getPlayer();
if (getCheckManager().willCheck(player, CheckType.COMMAND_SPAM)) {
if (getCheckManager().willCheck(player, CheckType.COMMAND_SPAM) && !Permission.getCommandExempt(player, event.getMessage().split(" ")[0])) {
CheckResult result = getBackend().checkCommandSpam(player, event.getMessage());
if (result.failed()) {
event.setCancelled(!silentMode());
@@ -64,9 +64,15 @@ public enum Permission {
SYSTEM_RELOAD;
private static final String PERMISSION_ALL = "anticheat.*";
private static final String PERMISSION_SPAM = "anticheat.check.spam";
public static boolean getCommandExempt(CommandSender cs, String commandLabel) {
// Check permission, base, and all will have already been checked
return cs.hasPermission(CHECK_COMMANDSPAM.toString() + commandLabel);
}
public boolean get(CommandSender cs) {
if ((this == CHECK_CHATSPAM || this == CHECK_COMMANDSPAM) && cs.hasPermission("anticheat.check.spam")) return true;
if ((this == CHECK_CHATSPAM || this == CHECK_COMMANDSPAM) && cs.hasPermission(PERMISSION_SPAM)) return true;
return cs.hasPermission(toString()) || cs.hasPermission(getBase()) || cs.hasPermission(PERMISSION_ALL);
}