From 100a1ffb1e8b46f58c32c2d3cb7bcacbb89aa1bf Mon Sep 17 00:00:00 2001 From: Brettflan Date: Thu, 4 Aug 2011 00:34:52 -0500 Subject: [PATCH] improved command prevention from last commit to also monitor slashless Faction commands, for full coverage --- .../listeners/FactionsChatEarlyListener.java | 12 ++++++--- .../listeners/FactionsPlayerListener.java | 27 ++++++++++++------- 2 files changed, 26 insertions(+), 13 deletions(-) diff --git a/src/com/massivecraft/factions/listeners/FactionsChatEarlyListener.java b/src/com/massivecraft/factions/listeners/FactionsChatEarlyListener.java index 092eedcb..369520fd 100644 --- a/src/com/massivecraft/factions/listeners/FactionsChatEarlyListener.java +++ b/src/com/massivecraft/factions/listeners/FactionsChatEarlyListener.java @@ -21,10 +21,14 @@ public class FactionsChatEarlyListener extends PlayerListener{ @Override public void onPlayerChat(PlayerChatEvent event) { if ((event.getMessage().startsWith(Factions.instance.getBaseCommand()+" ") || event.getMessage().equals(Factions.instance.getBaseCommand())) && Conf.allowNoSlashCommand) { - List parameters = TextUtil.split(event.getMessage().trim()); - parameters.remove(0); - CommandSender sender = event.getPlayer(); - Factions.instance.handleCommand(sender, parameters); + String msg = event.getMessage().trim(); + // make sure command isn't denied due to being in enemy/neutral territory + if (!FactionsPlayerListener.preventCommand("/" + msg.toLowerCase(), event.getPlayer())) { + List parameters = TextUtil.split(msg); + parameters.remove(0); + CommandSender sender = event.getPlayer(); + Factions.instance.handleCommand(sender, parameters); + } event.setCancelled(true); return; } diff --git a/src/com/massivecraft/factions/listeners/FactionsPlayerListener.java b/src/com/massivecraft/factions/listeners/FactionsPlayerListener.java index 58fb7497..5644de4a 100644 --- a/src/com/massivecraft/factions/listeners/FactionsPlayerListener.java +++ b/src/com/massivecraft/factions/listeners/FactionsPlayerListener.java @@ -399,22 +399,31 @@ public class FactionsPlayerListener extends PlayerListener{ @Override public void onPlayerCommandPreprocess(PlayerCommandPreprocessEvent event) { - if (event.isCancelled() || (Conf.territoryNeutralDenyCommands.isEmpty() && Conf.territoryNeutralDenyCommands.isEmpty())) { + if (event.isCancelled()) { return; } - FPlayer me = FPlayer.get(event.getPlayer()); + if (preventCommand(event.getMessage().toLowerCase(), event.getPlayer())) { + event.setCancelled(true); + } + } + + public static boolean preventCommand(String fullCmd, Player player) { + if ((Conf.territoryNeutralDenyCommands.isEmpty() && Conf.territoryEnemyDenyCommands.isEmpty())) { + return false; + } + + FPlayer me = FPlayer.get(player); if (!me.isInOthersTerritory()) { - return; + return false; } Relation rel = me.getRelationToLocation(); if (rel.isAtLeast(Relation.ALLY)) { - return; + return false; } - String fullCmd = event.getMessage().toLowerCase(); String shortCmd = fullCmd.substring(1); // Get rid of the slash at the beginning if ( @@ -428,8 +437,7 @@ public class FactionsPlayerListener extends PlayerListener{ cmdCheck = iter.next().toLowerCase(); if (fullCmd.startsWith(cmdCheck) || shortCmd.startsWith(cmdCheck)) { me.sendMessage("You can't use the command \""+fullCmd+"\" in neutral territory."); - event.setCancelled(true); - return; + return true; } } } @@ -444,10 +452,11 @@ public class FactionsPlayerListener extends PlayerListener{ cmdCheck = iter.next().toLowerCase(); if (fullCmd.startsWith(cmdCheck) || shortCmd.startsWith(cmdCheck)) { me.sendMessage("You can't use the command \""+fullCmd+"\" in enemy territory."); - event.setCancelled(true); - return; + return true; } } } + return false; } + }