From ea18f1dd0d54ce83542f47db4b150558c237ff9d Mon Sep 17 00:00:00 2001 From: Olof Larsson Date: Tue, 23 Apr 2013 12:31:07 +0200 Subject: [PATCH] Refactor denied commands --- .../massivecraft/factions/entity/UConf.java | 15 ++++++------- .../listeners/FactionsListenerMain.java | 21 +++++++------------ 2 files changed, 14 insertions(+), 22 deletions(-) diff --git a/src/com/massivecraft/factions/entity/UConf.java b/src/com/massivecraft/factions/entity/UConf.java index 01f27ed6..eb668ff9 100644 --- a/src/com/massivecraft/factions/entity/UConf.java +++ b/src/com/massivecraft/factions/entity/UConf.java @@ -61,15 +61,12 @@ public class UConf extends Entity public List denyCommandsPermanentFactionMember = new ArrayList(); // commands which will be prevented when in claimed territory of another faction - public List denyCommandsTerritoryNeutral = new ArrayList(); - public List denyCommandsTerritoryEnemy = MUtil.list( - "home", - "sethome", - "spawn", - "tpahere", - "tpaccept", - "tpa", - "warp" + public Map> denyCommandsTerritoryRelation = MUtil.map( + Rel.ENEMY, MUtil.list("home", "sethome", "spawn", "tpahere", "tpaccept", "tpa", "warp"), + Rel.NEUTRAL, new ArrayList(), + Rel.TRUCE, new ArrayList(), + Rel.ALLY, new ArrayList(), + Rel.MEMBER, new ArrayList() ); } diff --git a/src/com/massivecraft/factions/listeners/FactionsListenerMain.java b/src/com/massivecraft/factions/listeners/FactionsListenerMain.java index f913d5ab..90022b29 100644 --- a/src/com/massivecraft/factions/listeners/FactionsListenerMain.java +++ b/src/com/massivecraft/factions/listeners/FactionsListenerMain.java @@ -3,6 +3,7 @@ package com.massivecraft.factions.listeners; import java.text.MessageFormat; import java.util.Collection; import java.util.Iterator; +import java.util.List; import org.bukkit.Bukkit; import org.bukkit.block.Block; @@ -351,6 +352,7 @@ public class FactionsListenerMain implements Listener command = command.toLowerCase(); command = command.trim(); + // ... the command may be denied for members of permanent factions ... if (uplayer.hasFaction() && uplayer.getFaction().getFlag(FFlag.PERMANENT) && containsCommand(command, UConf.get(player).denyCommandsPermanentFactionMember)) { uplayer.msg("You can't use \"/%s\" as member of a permanent faction.", command); @@ -358,23 +360,16 @@ public class FactionsListenerMain implements Listener return; } + // ... the command may be denied in the territory of this relation type ... Rel rel = uplayer.getRelationToLocation(); PS ps = PS.valueOf(player).getChunk(true); if (BoardColls.get().getFactionAt(ps).isNone()) return; - if (rel == Rel.NEUTRAL && containsCommand(command, UConf.get(player).denyCommandsTerritoryNeutral)) - { - uplayer.msg("You can't use \"/%s\" in neutral territory.", command); - event.setCancelled(true); - return; - } - - if (rel == Rel.ENEMY && containsCommand(command, UConf.get(player).denyCommandsTerritoryEnemy)) - { - uplayer.msg("You can't use \"/%s\" in enemy territory.", command); - event.setCancelled(true); - return; - } + List deniedCommands = UConf.get(player).denyCommandsTerritoryRelation.get(rel); + if (!containsCommand(command, deniedCommands)) return; + + uplayer.msg("You can't use \"/%s\" in %s territory.", Txt.getNicedEnum(rel), command); + event.setCancelled(true); } private static boolean containsCommand(String needle, Collection haystack)