aboutsummaryrefslogtreecommitdiff
path: root/src/Java/miscutil/core/handler/XEventHandler.java
blob: db6a03e3e66a8d5c59ea48cfcfd1b95dd1d9cfdd (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
package miscutil.core.handler;

import gregtech.api.interfaces.metatileentity.IMetaTileEntity;
import gregtech.api.metatileentity.BaseMetaPipeEntity;
import gregtech.api.metatileentity.BaseMetaTileEntity;
import gregtech.api.metatileentity.BaseTileEntity;
import miscutil.core.util.Utils;
import miscutil.gregtech.metatileentity.implementations.base.GregtechMetaSafeBlockBase;
import net.minecraft.block.Block;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.tileentity.TileEntity;
import net.minecraftforge.event.world.BlockEvent.BreakEvent;
import cpw.mods.fml.common.eventhandler.SubscribeEvent;

public class XEventHandler {
	@SubscribeEvent
	public void onBreakBlock(BreakEvent event) {
		try{
			TileEntity entity = event.world.getTileEntity(event.x, event.y, event.z);
			if (entity != null && !entity.equals(null)){
				EntityPlayer playerInternal = event.getPlayer();
				Utils.LOG_WARNING(entity.getClass().getSimpleName());
				if (entity.getClass().getSimpleName().equals("")){

				}
				if (entity instanceof BaseTileEntity && !(entity instanceof BaseMetaPipeEntity)){
					IMetaTileEntity X = ((BaseMetaTileEntity)entity).getMetaTileEntity();
					Block ThisBlock = X.getBaseMetaTileEntity().getBlock(event.x, event.y, event.z);
					if (X instanceof GregtechMetaSafeBlockBase){

						String ownerUUID = ((GregtechMetaSafeBlockBase)X).ownerUUID;
						String accessorUUID = playerInternal.getUniqueID().toString();
						Utils.LOG_WARNING("Owner UUID: "+ownerUUID);
						Utils.LOG_WARNING("Accessor UUID: "+accessorUUID);					

						if (((GregtechMetaSafeBlockBase)X).bUnbreakable){
							if (accessorUUID.equals(ownerUUID)){							
								Utils.messagePlayer(playerInternal, "Since you own this block, it has been destroyed.");
								event.setCanceled(false);
							}
							else {
								event.setCanceled(true);
								Utils.messagePlayer(playerInternal, "Since you do not own this block, it has not been destroyed.");
							}
							//
						}
					}
				}
			}

		}
		catch (NullPointerException e) {
			System.out.print("Caught a NullPointerException involving Safe Blocks. Cause: "+e.getCause());
		}














	}
}