ProtectionInteract.java 2.2 KB

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