diff --git a/lib/MMOLib.jar b/lib/MMOLib.jar index 633121c9..a0cbd6c0 100644 Binary files a/lib/MMOLib.jar and b/lib/MMOLib.jar differ diff --git a/src/main/java/net/Indyuce/mmocore/listener/BlockListener.java b/src/main/java/net/Indyuce/mmocore/listener/BlockListener.java index 273388eb..892594b3 100644 --- a/src/main/java/net/Indyuce/mmocore/listener/BlockListener.java +++ b/src/main/java/net/Indyuce/mmocore/listener/BlockListener.java @@ -62,7 +62,7 @@ public class BlockListener implements Listener { } ItemStack item = player.getInventory().getItemInMainHand(); - BlockPermissions perms = MMOCore.plugin.restrictionManager.getPermissions(item.getType()); + BlockPermissions perms = MMOCore.plugin.restrictionManager.getPermissions(item); if (perms == null) { event.setCancelled(true); return; diff --git a/src/main/java/net/Indyuce/mmocore/manager/RestrictionManager.java b/src/main/java/net/Indyuce/mmocore/manager/RestrictionManager.java index dfbab78c..d5a06210 100644 --- a/src/main/java/net/Indyuce/mmocore/manager/RestrictionManager.java +++ b/src/main/java/net/Indyuce/mmocore/manager/RestrictionManager.java @@ -6,18 +6,19 @@ import java.util.Map; import java.util.Set; import java.util.logging.Level; -import org.bukkit.Material; import org.bukkit.configuration.ConfigurationSection; import org.bukkit.configuration.file.FileConfiguration; +import org.bukkit.inventory.ItemStack; import net.Indyuce.mmocore.MMOCore; import net.Indyuce.mmocore.api.block.BlockType; import net.Indyuce.mmocore.api.load.PostLoadObject; import net.mmogroup.mmolib.api.MMOLineConfig; +import net.mmogroup.mmolib.api.itemtype.ItemType; public class RestrictionManager { // private Set breakBlackList = new HashSet<>(); - private final Map map = new HashMap<>(); + private final Map map = new HashMap<>(); public RestrictionManager(FileConfiguration config) { @@ -32,7 +33,7 @@ public class RestrictionManager { try { perms.postLoad(); } catch (IllegalArgumentException exception) { - MMOCore.log(Level.WARNING, "Could not load block perms " + perms.getTool().name() + ": " + exception.getMessage()); + MMOCore.log(Level.WARNING, "Could not load block perms " + perms.getTool().display() + ": " + exception.getMessage()); } } @@ -47,26 +48,28 @@ public class RestrictionManager { // return breakBlackList.contains(s); // } - public BlockPermissions getPermissions(Material tool) { - return map.getOrDefault(tool, null); + public BlockPermissions getPermissions(ItemStack item) { + for(ItemType type : map.keySet()) + if(type.matches(item)) map.get(type); + return null; } public class BlockPermissions extends PostLoadObject { private final Set mineable = new HashSet<>(); - private final Material tool; + private final ItemType tool; private BlockPermissions parent; public BlockPermissions(ConfigurationSection config) { super(config); - tool = Material.valueOf(config.getName()); + tool = ItemType.fromString(config.getName()); } @Override protected void whenPostLoaded(ConfigurationSection config) { if (config.contains("parent")) - parent = map.get(Material.valueOf(config.getString("parent", "None").toUpperCase().replace("-", "_").replace(" ", "_"))); + parent = map.get(ItemType.fromString(config.getString("parent", "None"))); for (String key : config.getStringList("can-mine")) mineable.add(MMOCore.plugin.loadManager.loadBlockType(new MMOLineConfig(key))); } @@ -85,7 +88,7 @@ public class RestrictionManager { return parent != null && parent.canMine(type); } - public Material getTool() { + public ItemType getTool() { return tool; }