package com.trc202.CombatTagListeners;

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;

import com.trc202.CombatTag.CombatTag;


public class CombatTagCommandPrevention implements Listener{
	
	CombatTag plugin;
	
	public CombatTagCommandPrevention(CombatTag plugin){
		this.plugin = plugin;
	}
	
	@EventHandler(priority = EventPriority.LOWEST)
    public void onPlayerCommandPreprocess(PlayerCommandPreprocessEvent event)
    {
		Player player = event.getPlayer();
		if(plugin.hasDataContainer(player.getName()) && !plugin.getPlayerData(player.getName()).hasPVPtagExpired()){
			String command = event.getMessage();
			if(command.indexOf(" ")>=0)
				command = command.substring(0, command.indexOf(" "));
			for(String disabledCommand : plugin.settings.getDisabledCommands()){
				if(command.equalsIgnoreCase(disabledCommand)){
					if(plugin.isDebugEnabled()){plugin.log.info("[CombatTag] Combat Tag has blocked the command: " + disabledCommand + " .");}
					player.sendMessage("[CombatTag] This command is disabled while in combat");
					event.setCancelled(true);
					return;
				}
			}
		}else if(plugin.hasDataContainer(player.getName()) && plugin.getPlayerData(player.getName()).hasPVPtagExpired()){
			plugin.removeDataContainer(player.getName());
		}
	}
}

@@ -799,51 +799,145 @@
 %0A%09%09%09
-if(command.indexOf(%22 %22)%3E=0)
+for(String disabledCommand : plugin.settings.getDisabledCommands())%7B%0D%0A%09%09%09%09if(command.indexOf(%22 %22) == disabledCommand.length())%7B
 %0D%0A%09%09%09%09
+%09
-command = 
+if(
 comm
@@ -978,84 +978,366 @@
  %22))
-;
+.equalsIgnoreCase(disabledCommand))%7B
 %0D%0A%09%09%09
+%09
-for(String disabledCommand : plugin.settings.getDisabledCommands()
+%09%09if(plugin.isDebugEnabled())%7Bplugin.log.info(%22%5BCombatTag%5D Combat Tag has blocked the command: %22 + disabledCommand + %22 .%22);%7D%0D%0A%09%09%09%09%09%09player.sendMessage(%22%5BCombatTag%5D This command is disabled while in combat%22);%0D%0A%09%09%09%09%09%09event.setCancelled(true);%0D%0A%09%09%09%09%09%09return;%0D%0A%09%09%09%09%09%7D%0D%0A%09%09%09%09%7D else if(disabledCommand.indexOf(%22 %22) %3E 0
 )%7B%0D%0A
+%09
 %09%09%09%09
@@ -1347,32 +1347,40 @@
 command.
-equalsIgnoreCase
+toLowerCase().startsWith
 (disable
@@ -1383,29 +1383,44 @@
 abledCommand
+.toLowerCase()
 ))%7B%0D%0A
+%09
 %09%09%09%09%09if(plug
@@ -1537,24 +1537,25 @@
 .%22);%7D%0D%0A%09%09%09%09%09
+%09
 player.sendM
@@ -1620,24 +1620,25 @@
 at%22);%0D%0A%09%09%09%09%09
+%09
 event.setCan
@@ -1653,24 +1653,25 @@
 rue);%0D%0A%09%09%09%09%09
+%09
 return;%0D%0A%09%09%09
@@ -1663,24 +1663,32 @@
 %09%09%09return;%0D%0A
+%09%09%09%09%09%7D%0D%0A
 %09%09%09%09%7D%0D%0A%09%09%09%7D%0D

Update command handling: fix ticket #135