This commit is contained in:
Indyuce 2020-07-10 14:44:57 +02:00
commit 90199ef98f
4 changed files with 24 additions and 5 deletions

View File

@ -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);
}

View File

@ -41,4 +41,9 @@ public class SkullBlockType implements BlockType {
public String generateKey() {
return "vanilla-skull-" + value;
}
@Override
public boolean breakRestrictions(Block block) {
return true;
}
}

View File

@ -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);
}
}

View File

@ -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;
}