mirror of
https://github.com/PEXPlugins/Modifyworld.git
synced 2025-01-07 18:58:39 +01:00
Added block metadata value check option for blocks permissions (ex: modifyworld.blocks.destroy.35.5 - removal of lime wool block)
This commit is contained in:
parent
f8673eb49d
commit
1bfbbcff6b
@ -22,6 +22,7 @@ import java.lang.reflect.Method;
|
|||||||
import java.util.logging.Logger;
|
import java.util.logging.Logger;
|
||||||
import org.bukkit.ChatColor;
|
import org.bukkit.ChatColor;
|
||||||
import org.bukkit.Material;
|
import org.bukkit.Material;
|
||||||
|
import org.bukkit.block.Block;
|
||||||
import org.bukkit.entity.*;
|
import org.bukkit.entity.*;
|
||||||
import org.bukkit.event.Event;
|
import org.bukkit.event.Event;
|
||||||
import org.bukkit.event.Listener;
|
import org.bukkit.event.Listener;
|
||||||
@ -44,6 +45,7 @@ public abstract class ModifyworldListener implements Listener {
|
|||||||
protected ConfigurationNode config;
|
protected ConfigurationNode config;
|
||||||
protected boolean informPlayers = false;
|
protected boolean informPlayers = false;
|
||||||
protected boolean useMaterialNames = true;
|
protected boolean useMaterialNames = true;
|
||||||
|
protected boolean checkMetadata = false;
|
||||||
|
|
||||||
public ModifyworldListener(Plugin plugin, ConfigurationNode config) {
|
public ModifyworldListener(Plugin plugin, ConfigurationNode config) {
|
||||||
this.permissionsManager = PermissionsEx.getPermissionManager();
|
this.permissionsManager = PermissionsEx.getPermissionManager();
|
||||||
@ -54,6 +56,7 @@ public abstract class ModifyworldListener implements Listener {
|
|||||||
this.informPlayers = config.getBoolean("informPlayers", informPlayers);
|
this.informPlayers = config.getBoolean("informPlayers", informPlayers);
|
||||||
this.permissionDenied = config.getString("messages.permissionDenied", this.permissionDenied);
|
this.permissionDenied = config.getString("messages.permissionDenied", this.permissionDenied);
|
||||||
this.useMaterialNames = config.getBoolean("use-material-names", useMaterialNames);
|
this.useMaterialNames = config.getBoolean("use-material-names", useMaterialNames);
|
||||||
|
this.checkMetadata = config.getBoolean("check-metadata", checkMetadata);
|
||||||
}
|
}
|
||||||
|
|
||||||
protected void informPlayer(Player player, String message) {
|
protected void informPlayer(Player player, String message) {
|
||||||
@ -110,8 +113,22 @@ public abstract class ModifyworldListener implements Listener {
|
|||||||
return entityName;
|
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) {
|
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) {
|
private void registerEvents(Plugin plugin) {
|
||||||
|
@ -42,7 +42,7 @@ public class BlockListener extends ModifyworldListener {
|
|||||||
|
|
||||||
@EventHandler(Type.BLOCK_BREAK)
|
@EventHandler(Type.BLOCK_BREAK)
|
||||||
public void onBlockBreak(BlockBreakEvent event) {
|
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());
|
informPlayerAboutDenial(event.getPlayer());
|
||||||
event.setCancelled(true);
|
event.setCancelled(true);
|
||||||
}
|
}
|
||||||
@ -50,7 +50,7 @@ public class BlockListener extends ModifyworldListener {
|
|||||||
|
|
||||||
@EventHandler(Type.BLOCK_PLACE)
|
@EventHandler(Type.BLOCK_PLACE)
|
||||||
public void onBlockPlace(BlockPlaceEvent event) {
|
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());
|
informPlayerAboutDenial(event.getPlayer());
|
||||||
event.setCancelled(true);
|
event.setCancelled(true);
|
||||||
}
|
}
|
||||||
|
@ -187,7 +187,7 @@ public class PlayerListener extends ModifyworldListener {
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!canInteractWithMaterial(event.getPlayer(), "modifyworld.blocks.interact.", event.getClickedBlock().getType())) {
|
if (!canInteractWithBlock(event.getPlayer(), "modifyworld.blocks.interact.", event.getClickedBlock())) {
|
||||||
informPlayerAboutDenial(event.getPlayer());
|
informPlayerAboutDenial(event.getPlayer());
|
||||||
event.setCancelled(true);
|
event.setCancelled(true);
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user