New conf.json settings "territoryNeutralDenyCommands" and "territoryEnemyDenyCommands", which can have lists of commands added to them that will be denied while in the territory of a neutral or enemy faction. It is recommended you use /f config to add/remove such commands, for example /f config territoryEnemyDenyCommands spawn would prevent players from using /spawn in enemy territory. You can add the slash to the command string or not, it will work either way. If the used command starts with one of your denied commands, it will be prevented. For example, if you deny "time", both "/time night" and "/time day" will be prevented. However, if you deny "time n", /time night will be prevented but /time day won't. (thanks for some code contribution from Cal27)

This commit is contained in:
Brettflan 2011-08-04 00:07:38 -05:00
parent 7d3cdfdc20
commit 699c22f655
4 changed files with 77 additions and 3 deletions

View File

@ -85,6 +85,10 @@ public class Conf {
public static int actionDeniedPainAmount = 1;
// commands which will be prevented when in claimed territory of another faction
public static Set<String> territoryNeutralDenyCommands = new HashSet<String>();
public static Set<String> territoryEnemyDenyCommands = new HashSet<String>();
public static double territoryShieldFactor = 0.3;
public static boolean territoryDenyBuild = true;
public static boolean territoryDenyBuildWhenOffline = true;

View File

@ -329,6 +329,10 @@ public class FPlayer {
return this.getFaction().getRelation(fplayer);
}
public Relation getRelationToLocation() {
return Board.getFactionAt(new FLocation(this)).getRelation(this);
}
public ChatColor getRelationColor(Faction faction) {
return faction.getRelationColor(this);
}
@ -417,10 +421,18 @@ public class FPlayer {
return idHere > 0 && idHere != this.factionId;
}
public boolean isInEnemyTerritory() {
return Board.getFactionAt(new FLocation(this)).getRelation(this) == Relation.ENEMY;
public boolean isInAllyTerritory() {
return Board.getFactionAt(new FLocation(this)).getRelation(this).isAlly();
}
public boolean isInNeutralTerritory() {
return Board.getFactionAt(new FLocation(this)).getRelation(this).isNeutral();
}
public boolean isInEnemyTerritory() {
return Board.getFactionAt(new FLocation(this)).getRelation(this).isEnemy();
}
public void sendFactionHereMessage() {
Faction factionHere = Board.getFactionAt(new FLocation(this));
String msg = Conf.colorSystem+" ~ "+factionHere.getTag(this);

View File

@ -153,6 +153,7 @@ public class Factions extends JavaPlugin {
PluginManager pm = this.getServer().getPluginManager();
pm.registerEvent(Event.Type.PLAYER_CHAT, this.playerListener, Event.Priority.Highest, this);
pm.registerEvent(Event.Type.PLAYER_CHAT, this.chatEarlyListener, Event.Priority.Lowest, this);
pm.registerEvent(Event.Type.PLAYER_COMMAND_PREPROCESS, this.playerListener, Event.Priority.Normal, this);
pm.registerEvent(Event.Type.PLAYER_INTERACT, this.playerListener, Event.Priority.Normal, this);
pm.registerEvent(Event.Type.PLAYER_MOVE, this.playerListener, Event.Priority.Normal, this);
pm.registerEvent(Event.Type.PLAYER_JOIN, this.playerListener, Event.Priority.Normal, this);

View File

@ -1,6 +1,7 @@
package com.massivecraft.factions.listeners;
import java.util.logging.Logger;
import java.util.Iterator;
import org.bukkit.ChatColor;
import org.bukkit.Location;
@ -12,6 +13,7 @@ import org.bukkit.event.block.Action;
import org.bukkit.event.player.PlayerBucketEmptyEvent;
import org.bukkit.event.player.PlayerBucketFillEvent;
import org.bukkit.event.player.PlayerChatEvent;
import org.bukkit.event.player.PlayerCommandPreprocessEvent;
import org.bukkit.event.player.PlayerInteractEvent;
import org.bukkit.event.player.PlayerJoinEvent;
import org.bukkit.event.player.PlayerListener;
@ -27,6 +29,7 @@ import com.massivecraft.factions.FPlayer;
import com.massivecraft.factions.Faction;
import com.massivecraft.factions.Factions;
import com.massivecraft.factions.struct.Role;
import com.massivecraft.factions.struct.Relation;
import com.massivecraft.factions.util.TextUtil;
@ -393,4 +396,58 @@ public class FactionsPlayerListener extends PlayerListener{
return;
}
}
@Override
public void onPlayerCommandPreprocess(PlayerCommandPreprocessEvent event) {
if (event.isCancelled() || (Conf.territoryNeutralDenyCommands.isEmpty() && Conf.territoryNeutralDenyCommands.isEmpty())) {
return;
}
FPlayer me = FPlayer.get(event.getPlayer());
if (!me.isInOthersTerritory()) {
return;
}
Relation rel = me.getRelationToLocation();
if (rel.isAtLeast(Relation.ALLY)) {
return;
}
String fullCmd = event.getMessage().toLowerCase();
String shortCmd = fullCmd.substring(1); // Get rid of the slash at the beginning
if (
rel.isNeutral()
&& !Conf.territoryNeutralDenyCommands.isEmpty()
&& !Conf.adminBypassPlayers.contains(me.getName())
) {
Iterator<String> iter = Conf.territoryNeutralDenyCommands.iterator();
String cmdCheck;
while (iter.hasNext()) {
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;
}
}
}
else if (
rel.isEnemy()
&& !Conf.territoryEnemyDenyCommands.isEmpty()
&& !Conf.adminBypassPlayers.contains(me.getName())
) {
Iterator<String> iter = Conf.territoryEnemyDenyCommands.iterator();
String cmdCheck;
while (iter.hasNext()) {
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;
}
}
}
}
}