forked from Upstream/mmocore
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:
parent
6807a5f8f3
commit
55035d2c60
@ -29,7 +29,7 @@ public class CustomBlockMineEvent extends PlayerDataEvent implements Cancellable
|
|||||||
|
|
||||||
this.block = block;
|
this.block = block;
|
||||||
this.info = info;
|
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<>();
|
? info.collectDrops(new LootBuilder(player, 0)) : new ArrayList<>();
|
||||||
this.experience = info.hasExperience() ? info.getExperience().newInfo() : null;
|
this.experience = info.hasExperience() ? info.getExperience().newInfo() : null;
|
||||||
}
|
}
|
||||||
|
@ -1,5 +1,7 @@
|
|||||||
package net.Indyuce.mmocore.listener;
|
package net.Indyuce.mmocore.listener;
|
||||||
|
|
||||||
|
import java.util.Set;
|
||||||
|
|
||||||
import org.bukkit.Bukkit;
|
import org.bukkit.Bukkit;
|
||||||
import org.bukkit.GameMode;
|
import org.bukkit.GameMode;
|
||||||
import org.bukkit.Location;
|
import org.bukkit.Location;
|
||||||
@ -62,13 +64,14 @@ public class BlockListener implements Listener {
|
|||||||
}
|
}
|
||||||
|
|
||||||
ItemStack item = player.getInventory().getItemInMainHand();
|
ItemStack item = player.getInventory().getItemInMainHand();
|
||||||
BlockPermissions perms = MMOCore.plugin.restrictionManager.getPermissions(item);
|
Set<BlockPermissions> perms = MMOCore.plugin.restrictionManager.getPermissions(item);
|
||||||
if (perms == null) {
|
boolean check = false;
|
||||||
event.setCancelled(true);
|
for(BlockPermissions perm : perms)
|
||||||
return;
|
if(perm.canMine(info.getBlock())) {
|
||||||
|
check = true;
|
||||||
|
break;
|
||||||
}
|
}
|
||||||
|
if (!check) {
|
||||||
if (!perms.canMine(info.getBlock())) {
|
|
||||||
MMOCore.plugin.configManager.getSimpleMessage("cannot-break").send(player);
|
MMOCore.plugin.configManager.getSimpleMessage("cannot-break").send(player);
|
||||||
event.setCancelled(true);
|
event.setCancelled(true);
|
||||||
return;
|
return;
|
||||||
|
@ -48,10 +48,11 @@ public class RestrictionManager {
|
|||||||
// return breakBlackList.contains(s);
|
// 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())
|
for(ItemType type : map.keySet())
|
||||||
if(type.matches(item)) map.get(type);
|
if(type.matches(item)) set.add(map.get(type));
|
||||||
return null;
|
return set;
|
||||||
}
|
}
|
||||||
|
|
||||||
public class BlockPermissions extends PostLoadObject {
|
public class BlockPermissions extends PostLoadObject {
|
||||||
@ -69,7 +70,7 @@ public class RestrictionManager {
|
|||||||
@Override
|
@Override
|
||||||
protected void whenPostLoaded(ConfigurationSection config) {
|
protected void whenPostLoaded(ConfigurationSection config) {
|
||||||
if (config.contains("parent"))
|
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"))
|
for (String key : config.getStringList("can-mine"))
|
||||||
mineable.add(MMOCore.plugin.loadManager.loadBlockType(new MMOLineConfig(key)));
|
mineable.add(MMOCore.plugin.loadManager.loadBlockType(new MMOLineConfig(key)));
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user