mirror of
https://gitlab.com/phoenix-dvpmt/mmocore.git
synced 2024-12-01 01:23:25 +01:00
UNTESTED CODE!
Restrictions.yml can now use MMOItems instead of just vanilla materials. Format is just 'type.id' (might be case sensitive!) Requires MMOLib 1.3.2
This commit is contained in:
parent
1d2da64593
commit
2620f67672
BIN
lib/MMOLib.jar
BIN
lib/MMOLib.jar
Binary file not shown.
@ -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;
|
||||
|
@ -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<String> breakBlackList = new HashSet<>();
|
||||
private final Map<Material, BlockPermissions> map = new HashMap<>();
|
||||
private final Map<ItemType, BlockPermissions> 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<BlockType> 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;
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user