package pcl.OpenFM.misc;

import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.server.MinecraftServer;
import net.minecraft.tileentity.TileEntity;
import net.minecraftforge.event.world.BlockEvent.BreakEvent;
import pcl.OpenFM.OpenFM;
import pcl.OpenFM.TileEntity.TileEntityRadio;
import cpw.mods.fml.common.eventhandler.EventPriority;
import cpw.mods.fml.common.eventhandler.SubscribeEvent;

public class OFMBreakEvent {
	
	public OFMBreakEvent() {
		OpenFM.logger.info("Registering BreakEvent");
	}
	
	public static boolean IsOp(EntityPlayer player) {
		return MinecraftServer.getServer().getConfigurationManager().func_152596_g(player.getGameProfile());
	}
	
	@SubscribeEvent(priority=EventPriority.NORMAL)
	public void onBlockBreak(BreakEvent event) {
		if (!IsOp(event.getPlayer())) {
			TileEntity TE = event.world.getTileEntity(event.x, event.y, event.z);
			if(TE instanceof TileEntityRadio){
				TileEntityRadio xEntity = (TileEntityRadio) TE;
				if(xEntity.owner!=null){
					if(!xEntity.owner.equals(event.getPlayer().getUniqueID().toString()) && xEntity.isLocked) {
						if(!xEntity.owner.isEmpty()) {
							event.setCanceled(true);						
						}
					}
				}
			}
		} else {
			OpenFM.logger.info("Op is breaking a radio at X:" + event.x + " Y: " + event.y + " Z: " + event.z);
		}
	}
}
@@ -431,17 +431,16 @@
 Event %7B%0A
-%09
 %0A%09public
@@ -509,17 +509,16 @@
 t%22);%0A%09%7D%0A
-%09
 %0A%09public
@@ -667,17 +667,16 @@
 ());%0A%09%7D%0A
-%09
 %0A%09@Subsc
@@ -1197,16 +1197,128 @@
  else %7B%0A
+%09%09%09TileEntity TE = event.world.getTileEntity(event.x, event.y, event.z);%0A%09%09%09if(TE instanceof TileEntityRadio)%7B%0A%09
 %09%09%09OpenF
@@ -1412,16 +1412,21 @@
 ent.z);%0A
+%09%09%09%7D%0A
 %09%09%7D%0A%09%7D%0A%7D

Allow but log ops breaking radios.