ProtectionEntity.java 2.6 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677
  1. package me.km.plots;
  2. import me.km.KajetansMod;
  3. import me.km.api.Module;
  4. import me.km.api.Utils;
  5. import me.km.permissions.Permissions;
  6. import net.minecraft.entity.EntityLivingBase;
  7. import net.minecraft.entity.passive.EntityAnimal;
  8. import net.minecraft.entity.player.EntityPlayer;
  9. import net.minecraft.entity.projectile.EntityPotion;
  10. import net.minecraft.util.math.BlockPos;
  11. import net.minecraft.world.World;
  12. import net.minecraftforge.event.entity.EntityStruckByLightningEvent;
  13. import net.minecraftforge.event.entity.ThrowableImpactEvent;
  14. import net.minecraftforge.event.entity.living.LivingAttackEvent;
  15. import net.minecraftforge.fml.common.eventhandler.EventPriority;
  16. import net.minecraftforge.fml.common.eventhandler.SubscribeEvent;
  17. public class ProtectionEntity extends Protection
  18. {
  19. public ProtectionEntity(Module m)
  20. {
  21. super(m);
  22. }
  23. @SubscribeEvent(priority = EventPriority.HIGHEST)
  24. public void EntityProtection(LivingAttackEvent e)
  25. {
  26. EntityLivingBase ent = e.getEntityLiving();
  27. if(!this.getProtectionBank().isProtected(ent.getClass()))
  28. {
  29. return;
  30. }
  31. World w = ent.world;
  32. BlockPos pos = ent.getPosition();
  33. if(!this.getProtectionBank().hasProtection(w, pos) ||
  34. (ent instanceof EntityAnimal && this.getProtectionBank().hasTag(w, pos, "animal")))
  35. {
  36. return;
  37. }
  38. if(e.getSource().getImmediateSource() != null)
  39. {
  40. EntityPlayer p = Utils.getDamager(e.getSource());
  41. if(p != null)
  42. {
  43. if(KajetansMod.perms.has(p, Permissions.PLOT_BYPASS) || this.getProtectionBank().canBuild(w, pos, p))
  44. {
  45. return;
  46. }
  47. e.setCanceled(true);
  48. }
  49. }
  50. e.setCanceled(true);
  51. }
  52. @SubscribeEvent(priority = EventPriority.HIGHEST)
  53. public void EntityProtectionPotion(ThrowableImpactEvent e)
  54. {
  55. if(e.getEntityThrowable() instanceof EntityPotion)
  56. {
  57. EntityPotion potion = (EntityPotion) e.getEntityThrowable();
  58. EntityLivingBase ent = potion.getThrower();
  59. if(ent instanceof EntityPlayer && !KajetansMod.perms.has(ent, Permissions.PLOT_BYPASS) &&
  60. !this.getProtectionBank().canBuild(potion.world, potion.getPosition(), (EntityPlayer) ent))
  61. {
  62. e.setCanceled(true);
  63. }
  64. }
  65. }
  66. @SubscribeEvent(priority = EventPriority.HIGHEST)
  67. public void EntityProtectionPotion(EntityStruckByLightningEvent e)
  68. {
  69. e.setCanceled(true);
  70. }
  71. }