diff --git a/src/main/java/ru/tehkode/modifyworld/ModifyworldListener.java b/src/main/java/ru/tehkode/modifyworld/ModifyworldListener.java index a506944..d5a6c84 100644 --- a/src/main/java/ru/tehkode/modifyworld/ModifyworldListener.java +++ b/src/main/java/ru/tehkode/modifyworld/ModifyworldListener.java @@ -22,6 +22,7 @@ import java.lang.reflect.Method; import java.util.logging.Logger; import org.bukkit.ChatColor; import org.bukkit.Material; +import org.bukkit.block.Block; import org.bukkit.entity.*; import org.bukkit.event.Event; import org.bukkit.event.Listener; @@ -44,6 +45,7 @@ public abstract class ModifyworldListener implements Listener { protected ConfigurationNode config; protected boolean informPlayers = false; protected boolean useMaterialNames = true; + protected boolean checkMetadata = false; public ModifyworldListener(Plugin plugin, ConfigurationNode config) { this.permissionsManager = PermissionsEx.getPermissionManager(); @@ -54,6 +56,7 @@ public abstract class ModifyworldListener implements Listener { this.informPlayers = config.getBoolean("informPlayers", informPlayers); this.permissionDenied = config.getString("messages.permissionDenied", this.permissionDenied); this.useMaterialNames = config.getBoolean("use-material-names", useMaterialNames); + this.checkMetadata = config.getBoolean("check-metadata", checkMetadata); } protected void informPlayer(Player player, String message) { @@ -110,8 +113,22 @@ public abstract class ModifyworldListener implements Listener { return entityName; } + protected String getMaterialPermission(String basePermission, Material type){ + return basePermission + (this.useMaterialNames ? type.name().toLowerCase().replace("_", "") : type.getId() ); + } + protected boolean canInteractWithMaterial(Player player, String basePermission, Material type) { - return permissionsManager.has(player, basePermission + (this.useMaterialNames ? type.name().toLowerCase().replace("_", "") : type.getId() ) ); + return permissionsManager.has(player, this.getMaterialPermission(basePermission, type)); + } + + protected boolean canInteractWithBlock(Player player, String basePermission, Block block) { + String permission = this.getMaterialPermission(basePermission, block.getType()); + + if(this.checkMetadata){ + permission += "." + block.getData(); + } + + return permissionsManager.has(player, permission); } private void registerEvents(Plugin plugin) { diff --git a/src/main/java/ru/tehkode/modifyworld/handlers/BlockListener.java b/src/main/java/ru/tehkode/modifyworld/handlers/BlockListener.java index 14f878b..3347ece 100644 --- a/src/main/java/ru/tehkode/modifyworld/handlers/BlockListener.java +++ b/src/main/java/ru/tehkode/modifyworld/handlers/BlockListener.java @@ -42,7 +42,7 @@ public class BlockListener extends ModifyworldListener { @EventHandler(Type.BLOCK_BREAK) public void onBlockBreak(BlockBreakEvent event) { - if (!canInteractWithMaterial(event.getPlayer(), "modifyworld.blocks.destroy.", event.getBlock().getType())) { + if (!canInteractWithBlock(event.getPlayer(), "modifyworld.blocks.destroy.", event.getBlock())) { informPlayerAboutDenial(event.getPlayer()); event.setCancelled(true); } @@ -50,7 +50,7 @@ public class BlockListener extends ModifyworldListener { @EventHandler(Type.BLOCK_PLACE) public void onBlockPlace(BlockPlaceEvent event) { - if (!canInteractWithMaterial(event.getPlayer(), "modifyworld.blocks.place.", event.getBlock().getType())) { + if (!canInteractWithBlock(event.getPlayer(), "modifyworld.blocks.place.", event.getBlock())) { informPlayerAboutDenial(event.getPlayer()); event.setCancelled(true); } diff --git a/src/main/java/ru/tehkode/modifyworld/handlers/PlayerListener.java b/src/main/java/ru/tehkode/modifyworld/handlers/PlayerListener.java index 22622cd..7289fbf 100644 --- a/src/main/java/ru/tehkode/modifyworld/handlers/PlayerListener.java +++ b/src/main/java/ru/tehkode/modifyworld/handlers/PlayerListener.java @@ -187,7 +187,7 @@ public class PlayerListener extends ModifyworldListener { return; } - if (!canInteractWithMaterial(event.getPlayer(), "modifyworld.blocks.interact.", event.getClickedBlock().getType())) { + if (!canInteractWithBlock(event.getPlayer(), "modifyworld.blocks.interact.", event.getClickedBlock())) { informPlayerAboutDenial(event.getPlayer()); event.setCancelled(true); }