From 663a7e9454efbdd857f59aa05652478a0bfdbeed Mon Sep 17 00:00:00 2001 From: Brettflan Date: Wed, 18 Jan 2012 23:31:33 -0600 Subject: [PATCH] New conf.json setting "permanentFactionMemberDenyCommands" (list, default empty), which can be used to prevent members of permanent factions from using specific commands. Also, a minor fix for the help page regarding faction banks being shown if "bankEnabled" setting was enabled but "econEnabled" setting was false (economy as a whole disabled). --- src/com/massivecraft/factions/Conf.java | 5 +- .../massivecraft/factions/cmd/CmdHelp.java | 2 +- .../listeners/FactionsPlayerListener.java | 101 ++++++++++-------- 3 files changed, 60 insertions(+), 48 deletions(-) diff --git a/src/com/massivecraft/factions/Conf.java b/src/com/massivecraft/factions/Conf.java index 4572207b..4315b838 100644 --- a/src/com/massivecraft/factions/Conf.java +++ b/src/com/massivecraft/factions/Conf.java @@ -127,7 +127,10 @@ public class Conf //public static double considerFactionsReallyOfflineAfterXMinutes = 0.0; public static int actionDeniedPainAmount = 2; - + + // commands which will be prevented if the player is a member of a permanent faction + public static Set permanentFactionMemberDenyCommands = new HashSet(); + // commands which will be prevented when in claimed territory of another faction public static Set territoryNeutralDenyCommands = new HashSet(); public static Set territoryEnemyDenyCommands = new HashSet(); diff --git a/src/com/massivecraft/factions/cmd/CmdHelp.java b/src/com/massivecraft/factions/cmd/CmdHelp.java index c5ddd038..476ab4f3 100644 --- a/src/com/massivecraft/factions/cmd/CmdHelp.java +++ b/src/com/massivecraft/factions/cmd/CmdHelp.java @@ -84,7 +84,7 @@ public class CmdHelp extends FCommand pageLines.add( p.cmdBase.cmdSethome.getUseageTemplate(true) ); helpPages.add(pageLines); - if (Econ.isSetup() && Conf.bankEnabled) + if (Econ.isSetup() && Conf.econEnabled && Conf.bankEnabled) { pageLines = new ArrayList(); pageLines.add( p.txt.parse("Your faction has a bank which is used to pay for certain" )); diff --git a/src/com/massivecraft/factions/listeners/FactionsPlayerListener.java b/src/com/massivecraft/factions/listeners/FactionsPlayerListener.java index eb88d166..16760a7c 100644 --- a/src/com/massivecraft/factions/listeners/FactionsPlayerListener.java +++ b/src/com/massivecraft/factions/listeners/FactionsPlayerListener.java @@ -29,6 +29,7 @@ import com.massivecraft.factions.FPlayer; import com.massivecraft.factions.FPlayers; import com.massivecraft.factions.P; import com.massivecraft.factions.integration.SpoutFeatures; +import com.massivecraft.factions.struct.FFlag; import com.massivecraft.factions.struct.FPerm; import com.massivecraft.factions.struct.Rel; @@ -316,19 +317,11 @@ public class FactionsPlayerListener extends PlayerListener public static boolean preventCommand(String fullCmd, Player player) { - if ((Conf.territoryNeutralDenyCommands.isEmpty() && Conf.territoryEnemyDenyCommands.isEmpty())) - { + if ((Conf.territoryNeutralDenyCommands.isEmpty() && Conf.territoryEnemyDenyCommands.isEmpty() && Conf.permanentFactionMemberDenyCommands.isEmpty())) return false; - } FPlayer me = FPlayers.i.get(player); - Rel rel = me.getRelationToLocation(); - if (rel.isAtLeast(Rel.TRUCE)) - { - return false; - } - String shortCmd; // command without the slash at the beginning if (fullCmd.startsWith("/")) shortCmd = fullCmd.substring(1); @@ -337,7 +330,30 @@ public class FactionsPlayerListener extends PlayerListener shortCmd = fullCmd; fullCmd = "/" + fullCmd; } - + + if + ( + me.hasFaction() + && + ! me.hasAdminMode() + && + ! Conf.permanentFactionMemberDenyCommands.isEmpty() + && + me.getFaction().getFlag(FFlag.PERMANENT) + && + isCommandInList(fullCmd, shortCmd, Conf.permanentFactionMemberDenyCommands.iterator()) + ) + { + me.msg("You can't use the command \""+fullCmd+"\" because you are in a permanent faction."); + return true; + } + + Rel rel = me.getRelationToLocation(); + if (rel.isAtLeast(Rel.TRUCE)) + { + return false; + } + if ( rel == Rel.NEUTRAL @@ -345,58 +361,51 @@ public class FactionsPlayerListener extends PlayerListener ! Conf.territoryNeutralDenyCommands.isEmpty() && ! me.hasAdminMode() + && + isCommandInList(fullCmd, shortCmd, Conf.territoryNeutralDenyCommands.iterator()) ) { - Iterator iter = Conf.territoryNeutralDenyCommands.iterator(); - String cmdCheck; - while (iter.hasNext()) - { - cmdCheck = iter.next(); - if (cmdCheck == null) - { - iter.remove(); - continue; - } - - cmdCheck = cmdCheck.toLowerCase(); - if (fullCmd.startsWith(cmdCheck) || shortCmd.startsWith(cmdCheck)) - { - me.msg("You can't use the command \""+fullCmd+"\" in neutral territory."); - return true; - } - } + me.msg("You can't use the command \""+fullCmd+"\" in neutral territory."); + return true; } - else if + + if ( rel == Rel.ENEMY && ! Conf.territoryEnemyDenyCommands.isEmpty() && ! me.hasAdminMode() + && + isCommandInList(fullCmd, shortCmd, Conf.territoryEnemyDenyCommands.iterator()) ) { - Iterator iter = Conf.territoryEnemyDenyCommands.iterator(); - String cmdCheck; - while (iter.hasNext()) - { - cmdCheck = iter.next(); - if (cmdCheck == null) - { - iter.remove(); - continue; - } + me.msg("You can't use the command \""+fullCmd+"\" in enemy territory."); + return true; + } - cmdCheck = cmdCheck.toLowerCase(); - if (fullCmd.startsWith(cmdCheck) || shortCmd.startsWith(cmdCheck)) - { - me.msg("You can't use the command \""+fullCmd+"\" in enemy territory."); - return true; - } + return false; + } + + private static boolean isCommandInList(String fullCmd, String shortCmd, Iterator iter) + { + String cmdCheck; + while (iter.hasNext()) + { + cmdCheck = iter.next(); + if (cmdCheck == null) + { + iter.remove(); + continue; } + + cmdCheck = cmdCheck.toLowerCase(); + if (fullCmd.startsWith(cmdCheck) || shortCmd.startsWith(cmdCheck)) + return true; } return false; } - + @Override public void onPlayerKick(PlayerKickEvent event) {