improved command prevention from last commit to also monitor slashless Faction commands, for full coverage

This commit is contained in:
Brettflan 2011-08-04 00:34:52 -05:00
parent 699c22f655
commit 100a1ffb1e
2 changed files with 26 additions and 13 deletions

View File

@ -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<String> parameters = TextUtil.split(event.getMessage().trim());
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<String> parameters = TextUtil.split(msg);
parameters.remove(0);
CommandSender sender = event.getPlayer();
Factions.instance.handleCommand(sender, parameters);
}
event.setCancelled(true);
return;
}

View File

@ -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;
}
}