SemiProtections.java 1.4 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647
  1. package me.km.blockprotections;
  2. import me.km.KajetansMod;
  3. import me.km.api.Module;
  4. import me.km.api.ModuleListener;
  5. import me.km.permissions.Permissions;
  6. import me.km.plots.ProtectionBank;
  7. import net.minecraft.block.BlockCrops;
  8. import net.minecraft.block.state.IBlockState;
  9. import net.minecraft.entity.player.EntityPlayer;
  10. import net.minecraftforge.event.world.BlockEvent;
  11. import net.minecraftforge.fml.common.eventhandler.SubscribeEvent;
  12. public class SemiProtections extends ModuleListener
  13. {
  14. private final ProtectionBank bank;
  15. public SemiProtections(Module m)
  16. {
  17. super(m);
  18. bank = KajetansMod.plots.getDataBank(ProtectionBank.class);
  19. }
  20. @SubscribeEvent
  21. public void onBlockBreak(BlockEvent.BreakEvent e)
  22. {
  23. EntityPlayer p = e.getPlayer();
  24. if(KajetansMod.perms.hasPermission(p, Permissions.BLOCK_BYPASS) && p.isCreative())
  25. {
  26. return;
  27. }
  28. IBlockState b = e.getState();
  29. if(b.getBlock() instanceof BlockCrops)
  30. {
  31. if(!bank.hasTag(e.getWorld(), e.getPos(), "farm"))
  32. {
  33. return;
  34. }
  35. e.setCanceled(true);
  36. if(b.getValue(BlockCrops.AGE) == 7)
  37. {
  38. b.getBlock().dropBlockAsItem(e.getWorld(), e.getPos(), b, 0);
  39. }
  40. e.getWorld().setBlockState(e.getPos(), b.withProperty(BlockCrops.AGE, 0));
  41. }
  42. }
  43. }