Config option to limit slash commands in claims.

Some can now require access trust.  Default list is only /sethome.
This commit is contained in:
ryanhamshire 2015-02-21 21:51:39 -08:00
parent 5fc17b9a44
commit f0625270fd
2 changed files with 56 additions and 16 deletions

View File

@ -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<String> config_claims_commandsRequiringAccessTrust; //the list of slash commands requiring access trust when in a claim
public ArrayList<World> config_siege_enabledWorlds; //whether or not /siege is enabled on this server
public ArrayList<Material> 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>();
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>();
String [] commands = slashCommandsToMonitor.split(";");
commands = slashCommandsToMonitor.split(";");
for(int i = 0; i < commands.length; i++)
{
this.config_spam_monitorSlashCommands.add(commands[i].trim());

View File

@ -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 the slash command used is in the list of monitored commands, treat it like a chat message (see above)
if(isMonitoredCommand)
{
event.setCancelled(this.handlePlayerChat(event.getPlayer(), event.getMessage(), event));
}
}
//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;
}
}
for(String monitoredCommand : GriefPrevention.instance.config_claims_commandsRequiringAccessTrust)
{
if(args[0].equalsIgnoreCase(monitoredCommand))
{
isMonitoredCommand = true;
break;
}
}
if(isMonitoredCommand)
{
event.setCancelled(this.handlePlayerChat(event.getPlayer(), event.getMessage(), event));
}
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<UUID, Date> lastLoginThisServerSessionMap = new ConcurrentHashMap<UUID, Date>();