From 55035d2c607bc8172d035819399fb0ca2be5f5c7 Mon Sep 17 00:00:00 2001 From: ASangarin Date: Sat, 12 Sep 2020 23:18:57 +0200 Subject: [PATCH] Restrictions Update restrictions.yml has been fixed and now work as it should. 'required tool' message now displays even if a tool is not registered You can now use MMOItems in restrictions.yml, format = 'TYPE?ID' Requires MMOLib 1.3.3.1 (1.3.3 works too, but the 'parent' feature is broken in that case) --- .../mmocore/api/event/CustomBlockMineEvent.java | 2 +- .../Indyuce/mmocore/listener/BlockListener.java | 17 ++++++++++------- .../mmocore/manager/RestrictionManager.java | 11 ++++++----- 3 files changed, 17 insertions(+), 13 deletions(-) diff --git a/src/main/java/net/Indyuce/mmocore/api/event/CustomBlockMineEvent.java b/src/main/java/net/Indyuce/mmocore/api/event/CustomBlockMineEvent.java index 0bc336bc..21f55257 100644 --- a/src/main/java/net/Indyuce/mmocore/api/event/CustomBlockMineEvent.java +++ b/src/main/java/net/Indyuce/mmocore/api/event/CustomBlockMineEvent.java @@ -29,7 +29,7 @@ public class CustomBlockMineEvent extends PlayerDataEvent implements Cancellable this.block = block; this.info = info; - this.drops = (info.getDropTable().areConditionsMet(new ConditionInstance(player.getPlayer()))) + this.drops = (info.hasDropTable() && info.getDropTable().areConditionsMet(new ConditionInstance(player.getPlayer()))) ? info.collectDrops(new LootBuilder(player, 0)) : new ArrayList<>(); this.experience = info.hasExperience() ? info.getExperience().newInfo() : null; } diff --git a/src/main/java/net/Indyuce/mmocore/listener/BlockListener.java b/src/main/java/net/Indyuce/mmocore/listener/BlockListener.java index 892594b3..c0c74cd1 100644 --- a/src/main/java/net/Indyuce/mmocore/listener/BlockListener.java +++ b/src/main/java/net/Indyuce/mmocore/listener/BlockListener.java @@ -1,5 +1,7 @@ package net.Indyuce.mmocore.listener; +import java.util.Set; + import org.bukkit.Bukkit; import org.bukkit.GameMode; import org.bukkit.Location; @@ -62,13 +64,14 @@ public class BlockListener implements Listener { } ItemStack item = player.getInventory().getItemInMainHand(); - BlockPermissions perms = MMOCore.plugin.restrictionManager.getPermissions(item); - if (perms == null) { - event.setCancelled(true); - return; - } - - if (!perms.canMine(info.getBlock())) { + Set perms = MMOCore.plugin.restrictionManager.getPermissions(item); + boolean check = false; + for(BlockPermissions perm : perms) + if(perm.canMine(info.getBlock())) { + check = true; + break; + } + if (!check) { MMOCore.plugin.configManager.getSimpleMessage("cannot-break").send(player); 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 a953a761..08e5913a 100644 --- a/src/main/java/net/Indyuce/mmocore/manager/RestrictionManager.java +++ b/src/main/java/net/Indyuce/mmocore/manager/RestrictionManager.java @@ -48,10 +48,11 @@ public class RestrictionManager { // return breakBlackList.contains(s); // } - public BlockPermissions getPermissions(ItemStack item) { + public Set getPermissions(ItemStack item) { + Set set = new HashSet<>(); for(ItemType type : map.keySet()) - if(type.matches(item)) map.get(type); - return null; + if(type.matches(item)) set.add(map.get(type)); + return set; } public class BlockPermissions extends PostLoadObject { @@ -59,7 +60,7 @@ public class RestrictionManager { private final ItemType tool; private BlockPermissions parent; - + public BlockPermissions(ConfigurationSection config) { super(config); @@ -69,7 +70,7 @@ public class RestrictionManager { @Override protected void whenPostLoaded(ConfigurationSection config) { if (config.contains("parent")) - parent = map.get(ItemType.fromString(config.getString("parent", "None"))); + parent = map.get(ItemType.fromString(config.getString("parent"))); for (String key : config.getStringList("can-mine")) mineable.add(MMOCore.plugin.loadManager.loadBlockType(new MMOLineConfig(key))); }