ProtectionInteract.java 2.5 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374
  1. package me.km.plots;
  2. import me.kcm.events.FarmlandTrampleEvent;
  3. import me.km.KajetansMod;
  4. import me.km.api.Module;
  5. import me.km.permissions.Permissions;
  6. import net.minecraft.block.Block;
  7. import net.minecraft.entity.player.EntityPlayer;
  8. import net.minecraft.init.Blocks;
  9. import net.minecraftforge.event.entity.player.PlayerInteractEvent;
  10. import net.minecraftforge.fml.common.eventhandler.EventPriority;
  11. import net.minecraftforge.fml.common.eventhandler.SubscribeEvent;
  12. public class ProtectionInteract extends Protection
  13. {
  14. public ProtectionInteract(Module m)
  15. {
  16. super(m);
  17. }
  18. @SubscribeEvent(priority = EventPriority.HIGHEST)
  19. public void onPlayerInteract(PlayerInteractEvent.LeftClickBlock e)
  20. {
  21. EntityPlayer p = e.getEntityPlayer();
  22. if(KajetansMod.perms.hasPermission(p, Permissions.PLOT_BYPASS))
  23. {
  24. return;
  25. }
  26. Block b = e.getWorld().getBlockState(e.getPos()).getBlock();
  27. if (b == Blocks.FIRE && !this.getProtectionBank().canBuild(e.getWorld(), e.getPos(), p))
  28. {
  29. e.setCanceled(true);
  30. }
  31. }
  32. @SubscribeEvent(priority = EventPriority.HIGHEST)
  33. public void onPlayerInteract(PlayerInteractEvent.RightClickBlock e)
  34. {
  35. EntityPlayer p = e.getEntityPlayer();
  36. if(KajetansMod.perms.hasPermission(p, Permissions.PLOT_BYPASS))
  37. {
  38. return;
  39. }
  40. Block b = e.getWorld().getBlockState(e.getPos()).getBlock();
  41. if(b == Blocks.DAYLIGHT_DETECTOR || b == Blocks.DAYLIGHT_DETECTOR_INVERTED ||
  42. b == Blocks.POWERED_REPEATER || b == Blocks.UNPOWERED_REPEATER ||
  43. b == Blocks.POWERED_COMPARATOR || b == Blocks.UNPOWERED_COMPARATOR ||
  44. b == Blocks.DRAGON_EGG)
  45. {
  46. if(!this.getProtectionBank().canBuild(e.getWorld(), e.getPos(), p))
  47. {
  48. e.setCanceled(true);
  49. }
  50. }
  51. }
  52. @SubscribeEvent(priority = EventPriority.HIGHEST)
  53. public void protectFromInteract(PlayerInteractEvent.EntityInteract e)
  54. {
  55. EntityPlayer p = e.getEntityPlayer();
  56. if(KajetansMod.perms.hasPermission(p, Permissions.PLOT_BYPASS) ||
  57. this.getProtectionBank().canBuild(e.getWorld(), e.getTarget().getPosition(), p))
  58. {
  59. return;
  60. }
  61. e.setCanceled(true);
  62. }
  63. @SubscribeEvent(priority = EventPriority.HIGHEST)
  64. public void protectFromInteract(FarmlandTrampleEvent e)
  65. {
  66. e.setCanceled(true);
  67. }
  68. }