package musician101.controlcreativemode.listeners;

import musician101.controlcreativemode.ControlCreativeMode;
import musician101.controlcreativemode.lib.Constants;
import musician101.controlcreativemode.util.Utils;

import org.bukkit.entity.Entity;
import org.bukkit.entity.Player;
import org.bukkit.event.EventHandler;
import org.bukkit.event.Listener;
import org.bukkit.event.entity.EntityDamageByEntityEvent;

/**
 * Event handler for entity events.
 * 
 * @author Musician101
 */
public class EntityListener implements Listener
{
	ControlCreativeMode plugin;
	
	/**
	 * @param plugin References the Main class.
	 */
	public EntityListener(ControlCreativeMode plugin)
	{
		this.plugin = plugin;
	}
	
	/**
	 * Runs when a player receives damage.
	 * 
	 * @param event All info involved in the event.
	 */
	@EventHandler
    public void onDamage(EntityDamageByEntityEvent event)
	{
        if (event.getDamager() instanceof Player)
        {
            Entity entity = event.getEntity();
            Player player = (Player) event.getDamager();
 
            if (!player.hasPermission(Constants.PERMISSION_ALLOW_ATTACK))
            {
            	event.setCancelled(true);
                player.sendMessage(Constants.NO_PERMISSION_ATTACK);
            }
            else
            {
            	Utils.warnStaff(Constants.getAttackWarning(player, entity, player.getLocation()));
            	plugin.logger().info(Constants.getAttackWarning(player, entity, player.getLocation()));
            }
        }
    }
}

@@ -207,24 +207,52 @@
 til.Utils;%0A%0A
+import org.bukkit.GameMode;%0A
 import org.b
@@ -1071,18 +1071,16 @@
 ger();%0A 
-%0A 
         
@@ -1078,24 +1078,98 @@
             
+if (player.getGameMode() == GameMode.CREATIVE)%0A            %7B%0A            %09
 if (!player.
@@ -1222,32 +1222,36 @@
 K))%0A            
+    
 %7B%0A            %09e
@@ -1248,16 +1248,20 @@
         
+ 
+   
 %09event.s
@@ -1279,16 +1279,20 @@
 (true);%0A
+    
         
@@ -1355,34 +1355,42 @@
 K);%0A            
-%7D%0A
+    %7D%0A    
             else
@@ -1394,34 +1394,42 @@
 lse%0A            
-%7B%0A
+    %7B%0A    
             %09Uti
@@ -1520,16 +1520,20 @@
         
+    
 %09plugin.
@@ -1605,32 +1605,50 @@
 etLocation()));%0A
+                %7D%0A
             %7D%0A  

Fix onDamage() event so it checks for a player's Gamemode.