ProtectionBlockAction.java 2.7 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091
  1. package me.km.plots;
  2. import me.km.KajetansMod;
  3. import me.km.api.Location;
  4. import me.km.api.Module;
  5. import me.km.permissions.Permissions;
  6. import net.minecraft.entity.player.EntityPlayer;
  7. import net.minecraft.init.Items;
  8. import net.minecraft.util.math.BlockPos;
  9. import net.minecraft.block.Block;
  10. import net.minecraft.init.Blocks;
  11. import net.minecraft.world.World;
  12. import net.minecraftforge.event.world.BlockEvent;
  13. import net.minecraftforge.fml.common.eventhandler.EventPriority;
  14. import net.minecraftforge.fml.common.eventhandler.SubscribeEvent;
  15. public class ProtectionBlockAction extends Protection
  16. {
  17. public ProtectionBlockAction(Module m)
  18. {
  19. super(m);
  20. }
  21. @SubscribeEvent(priority = EventPriority.HIGHEST)
  22. public void onBlockPlace(BlockEvent.PlaceEvent e)
  23. {
  24. EntityPlayer p = e.getPlayer();
  25. if(KajetansMod.perms.has(p, Permissions.PLOT_BYPASS))
  26. {
  27. return;
  28. }
  29. if(!this.getProtectionBank().canBuild(e.getWorld(), e.getPos(), p))
  30. {
  31. if(this.getProtectionBank().hasTag(e.getWorld(), e.getPos(), "place"))
  32. {
  33. return;
  34. }
  35. e.setCanceled(true);
  36. }
  37. }
  38. @SubscribeEvent(priority = EventPriority.HIGHEST)
  39. public void onBlockBreak(BlockEvent.BreakEvent e)
  40. {
  41. EntityPlayer p = e.getPlayer();
  42. if(KajetansMod.perms.has(p, Permissions.PLOT_MARK) && p.getHeldItemMainhand().getItem() == Items.WOODEN_SWORD && p.isCreative())
  43. {
  44. e.setCanceled(true);
  45. return;
  46. }
  47. if(KajetansMod.perms.has(p, Permissions.PLOT_BYPASS))
  48. {
  49. return;
  50. }
  51. BlockPos pos = e.getPos();
  52. World w = e.getWorld();
  53. Block b = e.getState().getBlock();
  54. if(!this.getProtectionBank().canBuild(w, pos, p))
  55. {
  56. if(b == Blocks.PUMPKIN || b == Blocks.MELON_BLOCK)
  57. {
  58. if(this.getProtectionBank().hasTag(w, pos, "farm"))
  59. {
  60. return;
  61. }
  62. }
  63. else if(b == Blocks.REEDS)
  64. {
  65. if(Location.getRelativeBlock(w, pos, 0, -1, 0).getBlock() == Blocks.REEDS)
  66. {
  67. if(this.getProtectionBank().hasTag(w, pos, "farm"))
  68. {
  69. return;
  70. }
  71. }
  72. }
  73. if(this.getProtectionBank().hasTag(w, pos, "break"))
  74. {
  75. return;
  76. }
  77. if(b == Blocks.SNOW_LAYER)
  78. {
  79. if(this.getProtectionBank().hasTag(w, pos, "snow"))
  80. {
  81. return;
  82. }
  83. }
  84. e.setCanceled(true);
  85. }
  86. }
  87. }