ReplenishEnchantment.java 1.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243
  1. package me.lethunderhawk.custom.enchantment.tools;
  2. import me.lethunderhawk.custom.enchantment.CustomEnchantment;
  3. import org.bukkit.Material;
  4. import org.bukkit.block.Block;
  5. import org.bukkit.event.block.BlockBreakEvent;
  6. import org.bukkit.inventory.ItemStack;
  7. public class ReplenishEnchantment extends CustomEnchantment {
  8. public ReplenishEnchantment() {
  9. super("replenish", 1);
  10. }
  11. @Override
  12. public boolean canEnchantItem(ItemStack item) {
  13. if (item == null) return false;
  14. return item.getType().toString().endsWith("_HOE");
  15. }
  16. @Override
  17. public void applyEffect(org.bukkit.entity.Player player, ItemStack item, int level) {}
  18. public void autoReplant(BlockBreakEvent event) {
  19. if (event == null || event.getBlock() == null) return;
  20. Block block = event.getBlock();
  21. Material crop = block.getType();
  22. if (isCrop(crop)) {
  23. block.setType(crop);
  24. }
  25. }
  26. private boolean isCrop(Material mat) {
  27. switch (mat) {
  28. case WHEAT:
  29. case CARROTS:
  30. case POTATOES:
  31. case BEETROOTS:
  32. case NETHER_WART:
  33. case COCOA:
  34. case MELON_STEM:
  35. case PUMPKIN_STEM:
  36. return true;
  37. default:
  38. return false;
  39. }
  40. }
  41. }