diff --git a/src/me/ryanhamshire/GriefPrevention/GriefPrevention.java b/src/me/ryanhamshire/GriefPrevention/GriefPrevention.java index ec07c90..7be9692 100644 --- a/src/me/ryanhamshire/GriefPrevention/GriefPrevention.java +++ b/src/me/ryanhamshire/GriefPrevention/GriefPrevention.java @@ -103,6 +103,8 @@ public class GriefPrevention extends JavaPlugin public Material config_claims_investigationTool; //which material will be used to investigate claims with a right click public Material config_claims_modificationTool; //which material will be used to create/resize claims with a right click + public ArrayList config_claims_commandsRequiringAccessTrust; //the list of slash commands requiring access trust when in a claim + public ArrayList config_siege_enabledWorlds; //whether or not /siege is enabled on this server public ArrayList config_siege_blocks; //which blocks will be breakable in siege mode @@ -498,6 +500,7 @@ public class GriefPrevention extends JavaPlugin this.config_claims_maxClaimsPerPlayer = config.getInt("GriefPrevention.Claims.MaximumNumberOfClaimsPerPlayer", 0); this.config_claims_respectWorldGuard = config.getBoolean("GriefPrevention.Claims.CreationRequiresWorldGuardBuildPermission", true); this.config_claims_portalsRequirePermission = config.getBoolean("GriefPrevention.Claims.PortalGenerationRequiresPermission", false); + String accessTrustSlashCommands = config.getString("GriefPrevention.Claims.CommandsRequiringAccessTrust", "/sethome"); this.config_spam_enabled = config.getBoolean("GriefPrevention.Spam.Enabled", true); this.config_spam_loginCooldownSeconds = config.getInt("GriefPrevention.Spam.LoginCooldownSeconds", 60); @@ -710,6 +713,7 @@ public class GriefPrevention extends JavaPlugin outConfig.set("GriefPrevention.Claims.MaximumNumberOfClaimsPerPlayer", this.config_claims_maxClaimsPerPlayer); outConfig.set("GriefPrevention.Claims.CreationRequiresWorldGuardBuildPermission", this.config_claims_respectWorldGuard); outConfig.set("GriefPrevention.Claims.PortalGenerationRequiresPermission", this.config_claims_portalsRequirePermission); + outConfig.set("GriefPrevention.Claims.CommandsRequiringAccessTrust", accessTrustSlashCommands); outConfig.set("GriefPrevention.Spam.Enabled", this.config_spam_enabled); outConfig.set("GriefPrevention.Spam.LoginCooldownSeconds", this.config_spam_loginCooldownSeconds); @@ -783,9 +787,17 @@ public class GriefPrevention extends JavaPlugin AddLogEntry("Unable to write to the configuration file at \"" + DataStore.configFilePath + "\""); } + //try to parse the list of commands requiring access trust in land claims + this.config_claims_commandsRequiringAccessTrust = new ArrayList(); + String [] commands = accessTrustSlashCommands.split(";"); + for(int i = 0; i < commands.length; i++) + { + this.config_claims_commandsRequiringAccessTrust.add(commands[i].trim()); + } + //try to parse the list of commands which should be monitored for spam this.config_spam_monitorSlashCommands = new ArrayList(); - String [] commands = slashCommandsToMonitor.split(";"); + commands = slashCommandsToMonitor.split(";"); for(int i = 0; i < commands.length; i++) { this.config_spam_monitorSlashCommands.add(commands[i].trim()); diff --git a/src/me/ryanhamshire/GriefPrevention/PlayerEventHandler.java b/src/me/ryanhamshire/GriefPrevention/PlayerEventHandler.java index 1760089..5beb939 100644 --- a/src/me/ryanhamshire/GriefPrevention/PlayerEventHandler.java +++ b/src/me/ryanhamshire/GriefPrevention/PlayerEventHandler.java @@ -450,23 +450,51 @@ class PlayerEventHandler implements Listener } //if anti spam enabled, check for spam - if(!GriefPrevention.instance.config_spam_enabled) return; + if(GriefPrevention.instance.config_spam_enabled) + { + //if the slash command used is in the list of monitored commands, treat it like a chat message (see above) + boolean isMonitoredCommand = false; + for(String monitoredCommand : GriefPrevention.instance.config_spam_monitorSlashCommands) + { + if(args[0].equalsIgnoreCase(monitoredCommand)) + { + isMonitoredCommand = true; + break; + } + } + + if(isMonitoredCommand) + { + event.setCancelled(this.handlePlayerChat(event.getPlayer(), event.getMessage(), event)); + } + } - //if the slash command used is in the list of monitored commands, treat it like a chat message (see above) + //if requires access trust, check for permission boolean isMonitoredCommand = false; - for(String monitoredCommand : GriefPrevention.instance.config_spam_monitorSlashCommands) - { - if(args[0].equalsIgnoreCase(monitoredCommand)) - { - isMonitoredCommand = true; - break; - } - } - - if(isMonitoredCommand) - { - event.setCancelled(this.handlePlayerChat(event.getPlayer(), event.getMessage(), event)); - } + for(String monitoredCommand : GriefPrevention.instance.config_claims_commandsRequiringAccessTrust) + { + if(args[0].equalsIgnoreCase(monitoredCommand)) + { + isMonitoredCommand = true; + break; + } + } + + if(isMonitoredCommand) + { + Player player = event.getPlayer(); + Claim claim = this.dataStore.getClaimAt(player.getLocation(), false, playerData.lastClaim); + if(claim != null) + { + playerData.lastClaim = claim; + String reason = claim.allowAccess(player); + if(reason != null) + { + GriefPrevention.sendMessage(player, TextMode.Err, reason); + event.setCancelled(true); + } + } + } } private ConcurrentHashMap lastLoginThisServerSessionMap = new ConcurrentHashMap();