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)
This commit is contained in:
ASangarin 2020-09-12 23:18:57 +02:00
parent 6807a5f8f3
commit 55035d2c60
3 changed files with 17 additions and 13 deletions

View File

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

View File

@ -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;
Set<BlockPermissions> perms = MMOCore.plugin.restrictionManager.getPermissions(item);
boolean check = false;
for(BlockPermissions perm : perms)
if(perm.canMine(info.getBlock())) {
check = true;
break;
}
if (!perms.canMine(info.getBlock())) {
if (!check) {
MMOCore.plugin.configManager.getSimpleMessage("cannot-break").send(player);
event.setCancelled(true);
return;

View File

@ -48,10 +48,11 @@ public class RestrictionManager {
// return breakBlackList.contains(s);
// }
public BlockPermissions getPermissions(ItemStack item) {
public Set<BlockPermissions> getPermissions(ItemStack item) {
Set<BlockPermissions> 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 {
@ -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)));
}