diff --git a/src/main/java/net/Indyuce/mmocore/api/block/BlockType.java b/src/main/java/net/Indyuce/mmocore/api/block/BlockType.java index 869e9070..abd0b66b 100644 --- a/src/main/java/net/Indyuce/mmocore/api/block/BlockType.java +++ b/src/main/java/net/Indyuce/mmocore/api/block/BlockType.java @@ -1,6 +1,7 @@ package net.Indyuce.mmocore.api.block; import org.bukkit.Location; +import org.bukkit.block.Block; import net.Indyuce.mmocore.api.block.BlockInfo.RegeneratingBlock; @@ -10,8 +11,15 @@ public interface BlockType { // public boolean matches(Block block); /* - * generates a key used to store the BlockInfo instance in the manager map, - * the key depends on the block type to make sure there is no interference + * generates a key used to store the BlockInfo instance in the manager map, the + * key depends on the block type to make sure there is no interference */ public String generateKey(); + + /* + * generateKey() determines if the block is handled by that block type, + * breakRestrictions(Block) applies some extra break restrictions; returns TRUE + * if the block can be broken + */ + public boolean breakRestrictions(Block block); } diff --git a/src/main/java/net/Indyuce/mmocore/api/block/SkullBlockType.java b/src/main/java/net/Indyuce/mmocore/api/block/SkullBlockType.java index 549a9210..11b42947 100644 --- a/src/main/java/net/Indyuce/mmocore/api/block/SkullBlockType.java +++ b/src/main/java/net/Indyuce/mmocore/api/block/SkullBlockType.java @@ -41,4 +41,9 @@ public class SkullBlockType implements BlockType { public String generateKey() { return "vanilla-skull-" + value; } + + @Override + public boolean breakRestrictions(Block block) { + return true; + } } diff --git a/src/main/java/net/Indyuce/mmocore/api/block/VanillaBlockType.java b/src/main/java/net/Indyuce/mmocore/api/block/VanillaBlockType.java index 4e219fc4..a2580775 100644 --- a/src/main/java/net/Indyuce/mmocore/api/block/VanillaBlockType.java +++ b/src/main/java/net/Indyuce/mmocore/api/block/VanillaBlockType.java @@ -14,8 +14,8 @@ public class VanillaBlockType implements BlockType { private final Material type; /* - * allows to plant back crops with a custom age so that it does not always - * have to full grow again + * allows to plant back crops with a custom age so that it does not always have + * to full grow again */ private final int age; @@ -52,4 +52,10 @@ public class VanillaBlockType implements BlockType { public String generateKey() { return "vanilla-block-" + type.name(); } + + @Override + public boolean breakRestrictions(Block block) { + return age == 0 + || (block.getBlockData() instanceof Ageable && ((Ageable) block.getBlockData()).getAge() >= age); + } } diff --git a/src/main/java/net/Indyuce/mmocore/listener/BlockListener.java b/src/main/java/net/Indyuce/mmocore/listener/BlockListener.java index 8b75b615..80878e1f 100644 --- a/src/main/java/net/Indyuce/mmocore/listener/BlockListener.java +++ b/src/main/java/net/Indyuce/mmocore/listener/BlockListener.java @@ -46,7 +46,7 @@ public class BlockListener implements Listener { return; BlockInfo info = MMOCore.plugin.mineManager.getInfo(block); - if (info == null) { + if (info == null || !info.getBlock().breakRestrictions(block)) { event.setCancelled(true); return; }