ProtectionBlockAction.java 2.7 KB

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