package org.c4k3.NoSpam;

import org.bukkit.entity.Player;
import org.bukkit.event.EventHandler;
import org.bukkit.event.EventPriority;
import org.bukkit.event.Listener;
import org.bukkit.event.player.PlayerCommandPreprocessEvent;

public class CommandListener implements Listener {

	public CommandListener(NoSpam plugin) {
		plugin.getServer().getPluginManager().registerEvents(this, plugin);
	}

	@EventHandler(priority=EventPriority.LOW, ignoreCancelled=false)
	public void onPlayerCommandPreprocessEvent(PlayerCommandPreprocessEvent event) {

		Player player = event.getPlayer();

		String message = event.getMessage();

		/* Important: The spaces afterwards are necessary. Otherwise we get something like this being activated on /world because of /w */
		if ( message.startsWith("/tell ") || message.startsWith("/me ") || message.startsWith("/msg ") || message.startsWith("/w ") ) {

			boolean cancel = SpamHandler.isSpamming(player); // The Handler class checks if it's spam

			if ( cancel ) event.setCancelled(true);

		}

	}

}

@@ -780,17 +780,16 @@
 %0D%0A%09%09if (
- 
 message.
@@ -808,17 +808,22 @@
 /tell %22)
- 
+%0D%0A%09%09%09%09
 %7C%7C messa
@@ -843,17 +843,22 @@
 (%22/me %22)
- 
+%0D%0A%09%09%09%09
 %7C%7C messa
@@ -879,17 +879,22 @@
 %22/msg %22)
- 
+%0D%0A%09%09%09%09
 %7C%7C messa
@@ -913,17 +913,51 @@
 h(%22/w %22)
- 
+%0D%0A%09%09%09%09%7C%7C message.startsWith(%22/op %22)
 ) %7B%0D%0A%0D%0A%09

Add /op to spam-prevented commands