summaryrefslogtreecommitdiffstats
path: root/EssentialsAntiCheat/src/com/earth2me/essentials/anticheat/checks/chat/ChatCheckListener.java
diff options
context:
space:
mode:
authormd_5 <md_5@bigpond.com>2012-03-12 10:39:36 +1100
committermd_5 <md_5@bigpond.com>2012-03-12 10:39:36 +1100
commit78f4820876f42f7b50bf88f64afd45bee939e4e4 (patch)
tree317cd3bcc63fc9e86a6efbcb5e13a50ed9efbaaf /EssentialsAntiCheat/src/com/earth2me/essentials/anticheat/checks/chat/ChatCheckListener.java
parent26409058467e9f34aa65a08df3c68a58129d22ba (diff)
downloadEssentials-78f4820876f42f7b50bf88f64afd45bee939e4e4.tar
Essentials-78f4820876f42f7b50bf88f64afd45bee939e4e4.tar.gz
Essentials-78f4820876f42f7b50bf88f64afd45bee939e4e4.tar.lz
Essentials-78f4820876f42f7b50bf88f64afd45bee939e4e4.tar.xz
Essentials-78f4820876f42f7b50bf88f64afd45bee939e4e4.zip
Initial formatted and slightly tweaked version of @evenprime 's NoCheat. Will be intergrated into the main Essentials as soon as possible
Diffstat (limited to 'EssentialsAntiCheat/src/com/earth2me/essentials/anticheat/checks/chat/ChatCheckListener.java')
-rw-r--r--EssentialsAntiCheat/src/com/earth2me/essentials/anticheat/checks/chat/ChatCheckListener.java108
1 files changed, 108 insertions, 0 deletions
diff --git a/EssentialsAntiCheat/src/com/earth2me/essentials/anticheat/checks/chat/ChatCheckListener.java b/EssentialsAntiCheat/src/com/earth2me/essentials/anticheat/checks/chat/ChatCheckListener.java
new file mode 100644
index 000000000..965a374aa
--- /dev/null
+++ b/EssentialsAntiCheat/src/com/earth2me/essentials/anticheat/checks/chat/ChatCheckListener.java
@@ -0,0 +1,108 @@
+package com.earth2me.essentials.anticheat.checks.chat;
+
+import com.earth2me.essentials.anticheat.EventManager;
+import com.earth2me.essentials.anticheat.NoCheat;
+import com.earth2me.essentials.anticheat.NoCheatPlayer;
+import com.earth2me.essentials.anticheat.config.ConfigurationCacheStore;
+import com.earth2me.essentials.anticheat.config.Permissions;
+import java.util.LinkedList;
+import java.util.List;
+import org.bukkit.event.EventHandler;
+import org.bukkit.event.EventPriority;
+import org.bukkit.event.Listener;
+import org.bukkit.event.player.PlayerChatEvent;
+import org.bukkit.event.player.PlayerCommandPreprocessEvent;
+
+
+/**
+ * Central location to listen to events that are relevant for the chat checks
+ *
+ */
+public class ChatCheckListener implements Listener, EventManager
+{
+ private final SpamCheck spamCheck;
+ private final ColorCheck colorCheck;
+ private final NoCheat plugin;
+
+ public ChatCheckListener(NoCheat plugin)
+ {
+
+ this.plugin = plugin;
+
+ spamCheck = new SpamCheck(plugin);
+ colorCheck = new ColorCheck(plugin);
+ }
+
+ /**
+ * We listen to PlayerCommandPreprocess events because commands can be used for spamming too.
+ *
+ * @param event The PlayerCommandPreprocess Event
+ */
+ @EventHandler(priority = EventPriority.LOWEST, ignoreCancelled = true)
+ public void commandPreprocess(final PlayerCommandPreprocessEvent event)
+ {
+ // This type of event is derived from PlayerChatEvent, therefore
+ // just treat it like that
+ chat(event);
+ }
+
+ /**
+ * We listen to PlayerChat events for obvious reasons
+ *
+ * @param event The PlayerChat event
+ */
+ @EventHandler(priority = EventPriority.LOWEST, ignoreCancelled = true)
+ public void chat(final PlayerChatEvent event)
+ {
+ boolean cancelled = false;
+
+ final NoCheatPlayer player = plugin.getPlayer(event.getPlayer());
+ final ChatConfig cc = ChatCheck.getConfig(player);
+ final ChatData data = ChatCheck.getData(player);
+
+ // Remember the original message
+ data.message = event.getMessage();
+
+ // Now do the actual checks
+
+ // First the spam check
+ if (cc.spamCheck && !player.hasPermission(Permissions.CHAT_SPAM))
+ {
+ cancelled = spamCheck.check(player, data, cc);
+ }
+
+ // Second the color check
+ if (!cancelled && cc.colorCheck && !player.hasPermission(Permissions.CHAT_COLOR))
+ {
+ cancelled = colorCheck.check(player, data, cc);
+ }
+
+ // If one of the checks requested the event to be cancelled, do it
+ if (cancelled)
+ {
+ event.setCancelled(cancelled);
+ }
+ else
+ {
+ // In case one of the events modified the message, make sure that
+ // the new message gets used
+ event.setMessage(data.message);
+ }
+ }
+
+ public List<String> getActiveChecks(ConfigurationCacheStore cc)
+ {
+ LinkedList<String> s = new LinkedList<String>();
+
+ ChatConfig c = ChatCheck.getConfig(cc);
+ if (c.spamCheck)
+ {
+ s.add("chat.spam");
+ }
+ if (c.colorCheck)
+ {
+ s.add("chat.color");
+ }
+ return s;
+ }
+}