package me.km.plots; import me.km.KajetansMod; import me.km.api.Module; import me.km.api.Utils; import me.km.permissions.Permissions; import net.minecraft.entity.EntityLivingBase; import net.minecraft.entity.passive.EntityAnimal; import net.minecraft.entity.player.EntityPlayer; import net.minecraft.entity.projectile.EntityPotion; import net.minecraft.util.math.BlockPos; import net.minecraft.world.World; import net.minecraftforge.event.entity.EntityStruckByLightningEvent; import net.minecraftforge.event.entity.ThrowableImpactEvent; import net.minecraftforge.event.entity.living.LivingAttackEvent; import net.minecraftforge.fml.common.eventhandler.EventPriority; import net.minecraftforge.fml.common.eventhandler.SubscribeEvent; public class ProtectionEntity extends Protection { public ProtectionEntity(Module m) { super(m); } @SubscribeEvent(priority = EventPriority.HIGHEST) public void EntityProtection(LivingAttackEvent e) { EntityLivingBase ent = e.getEntityLiving(); if(!this.getProtectionBank().isProtected(ent.getClass())) { return; } World w = ent.world; BlockPos pos = ent.getPosition(); if(!this.getProtectionBank().hasProtection(w, pos) || (ent instanceof EntityAnimal && this.getProtectionBank().hasTag(w, pos, "animal"))) { return; } if(e.getSource().getImmediateSource() != null) { EntityPlayer p = Utils.getDamager(e.getSource()); if(p != null) { if(KajetansMod.perms.hasPermission(p, Permissions.PLOT_BYPASS) || this.getProtectionBank().canBuild(w, pos, p)) { return; } e.setCanceled(true); } } e.setCanceled(true); } @SubscribeEvent(priority = EventPriority.HIGHEST) public void EntityProtectionPotion(ThrowableImpactEvent e) { if(e.getEntityThrowable() instanceof EntityPotion) { EntityPotion potion = (EntityPotion) e.getEntityThrowable(); EntityLivingBase ent = potion.getThrower(); if(ent instanceof EntityPlayer && !KajetansMod.perms.hasPermission(ent, Permissions.PLOT_BYPASS) && !this.getProtectionBank().canBuild(potion.world, potion.getPosition(), (EntityPlayer) ent)) { e.setCanceled(true); } } } @SubscribeEvent(priority = EventPriority.HIGHEST) public void EntityProtectionPotion(EntityStruckByLightningEvent e) { e.setCanceled(true); } }