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 {
			TileEntity TE = event.world.getTileEntity(event.x, event.y, event.z);
			if(TE instanceof TileEntityRadio){
				OpenFM.logger.info("Op is breaking a radio at X:" + event.x + " Y: " + event.y + " Z: " + event.z);
			}
		}
	}
}
@@ -64,24 +64,75 @@
 tityPlayer;%0A
+import net.minecraft.entity.player.EntityPlayerMP;%0A
 import net.m
@@ -813,16 +813,70 @@
 vent) %7B%0A
+%09%09if (event.getPlayer() instanceof EntityPlayerMP) %7B%0A%09
 %09%09if (!I
@@ -901,16 +901,17 @@
 r())) %7B%0A
+%09
 %09%09%09TileE
@@ -970,32 +970,33 @@
 y, event.z);%0A%09%09%09
+%09
 if(TE instanceof
@@ -1010,24 +1010,25 @@
 tityRadio)%7B%0A
+%09
 %09%09%09%09TileEnti
@@ -1071,16 +1071,17 @@
 TE;%0A%09%09%09%09
+%09
 if(xEnti
@@ -1097,16 +1097,17 @@
 =null)%7B%0A
+%09
 %09%09%09%09%09if(
@@ -1193,32 +1193,33 @@
 Locked) %7B%0A%09%09%09%09%09%09
+%09
 if(!xEntity.owne
@@ -1229,24 +1229,25 @@
 sEmpty()) %7B%0A
+%09
 %09%09%09%09%09%09%09event
@@ -1276,16 +1276,17 @@
 %09%09%09%0A
+%09
 %09%09%09%09%09%09%7D%0A
 %09%09%09%09
@@ -1277,24 +1277,32 @@
 %09%09%0A%09%09%09%09%09%09%09%7D%0A
+%09%09%09%09%09%09%7D%0A
 %09%09%09%09%09%7D%0A%09%09%09%09%7D
@@ -1306,20 +1306,16 @@
 %09%09%7D%0A%09%09%09%7D
-%0A%09%09%7D
  else %7B%0A
@@ -1317,16 +1317,17 @@
 se %7B%0A%09%09%09
+%09
 TileEnti
@@ -1391,16 +1391,17 @@
 .z);%0A%09%09%09
+%09
 if(TE in
@@ -1423,24 +1423,25 @@
 tityRadio)%7B%0A
+%09
 %09%09%09%09OpenFM.l
@@ -1532,16 +1532,22 @@
 ent.z);%0A
+%09%09%09%09%7D%0A
 %09%09%09%7D%0A%09%09%7D

Check if event is fired by player.