package me.km.plots; import me.km.KajetansMod; import me.km.api.Location; import me.km.api.Module; import me.km.permissions.Permissions; import net.minecraft.entity.player.EntityPlayer; import net.minecraft.init.Items; import net.minecraft.util.math.BlockPos; import net.minecraft.block.Block; import net.minecraft.init.Blocks; import net.minecraft.world.World; import net.minecraftforge.event.world.BlockEvent; import net.minecraftforge.fml.common.eventhandler.EventPriority; import net.minecraftforge.fml.common.eventhandler.SubscribeEvent; public class ProtectionBlockAction extends Protection { public ProtectionBlockAction(Module m) { super(m); } @SubscribeEvent(priority = EventPriority.HIGHEST) public void onBlockPlace(BlockEvent.PlaceEvent e) { EntityPlayer p = e.getPlayer(); if(KajetansMod.perms.has(p, Permissions.PLOT_BYPASS)) { return; } if(!this.getProtectionBank().canBuild(e.getWorld(), e.getPos(), p)) { if(this.getProtectionBank().hasTag(e.getWorld(), e.getPos(), "place")) { return; } e.setCanceled(true); } } @SubscribeEvent(priority = EventPriority.HIGHEST) public void onBlockBreak(BlockEvent.BreakEvent e) { EntityPlayer p = e.getPlayer(); if(KajetansMod.perms.has(p, Permissions.PLOT_MARK) && p.getHeldItemMainhand().getItem() == Items.WOODEN_SWORD && p.isCreative()) { e.setCanceled(true); return; } if(KajetansMod.perms.has(p, Permissions.PLOT_BYPASS)) { return; } BlockPos pos = e.getPos(); World w = e.getWorld(); Block b = e.getState().getBlock(); if(!this.getProtectionBank().canBuild(w, pos, p)) { if(b == Blocks.PUMPKIN || b == Blocks.MELON_BLOCK) { if(this.getProtectionBank().hasTag(w, pos, "farm")) { return; } } else if(b == Blocks.REEDS) { if(Location.getRelativeBlock(w, pos, 0, -1, 0).getBlock() == Blocks.REEDS) { if(this.getProtectionBank().hasTag(w, pos, "farm")) { return; } } } if(this.getProtectionBank().hasTag(w, pos, "break")) { return; } if(b == Blocks.SNOW_LAYER) { if(this.getProtectionBank().hasTag(w, pos, "snow")) { return; } } e.setCanceled(true); } } }