Refactor denied commands

This commit is contained in:
Olof Larsson 2013-04-23 12:31:07 +02:00
parent 3c60f75bbd
commit ea18f1dd0d
2 changed files with 14 additions and 22 deletions

View File

@ -61,15 +61,12 @@ public class UConf extends Entity<UConf>
public List<String> denyCommandsPermanentFactionMember = new ArrayList<String>();
// commands which will be prevented when in claimed territory of another faction
public List<String> denyCommandsTerritoryNeutral = new ArrayList<String>();
public List<String> denyCommandsTerritoryEnemy = MUtil.list(
"home",
"sethome",
"spawn",
"tpahere",
"tpaccept",
"tpa",
"warp"
public Map<Rel, List<String>> denyCommandsTerritoryRelation = MUtil.map(
Rel.ENEMY, MUtil.list("home", "sethome", "spawn", "tpahere", "tpaccept", "tpa", "warp"),
Rel.NEUTRAL, new ArrayList<String>(),
Rel.TRUCE, new ArrayList<String>(),
Rel.ALLY, new ArrayList<String>(),
Rel.MEMBER, new ArrayList<String>()
);
}

View File

@ -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("<b>You can't use \"<h>/%s<b>\" 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("<b>You can't use \"<h>/%s<b>\" in neutral territory.", command);
event.setCancelled(true);
return;
}
List<String> deniedCommands = UConf.get(player).denyCommandsTerritoryRelation.get(rel);
if (!containsCommand(command, deniedCommands)) return;
if (rel == Rel.ENEMY && containsCommand(command, UConf.get(player).denyCommandsTerritoryEnemy))
{
uplayer.msg("<b>You can't use \"<h>/%s<b>\" in enemy territory.", command);
uplayer.msg("<b>You can't use \"<h>/%s<b>\" in %s territory.", Txt.getNicedEnum(rel), command);
event.setCancelled(true);
return;
}
}
private static boolean containsCommand(String needle, Collection<String> haystack)