improved command prevention from last commit to also monitor slashless Faction commands, for full coverage
This commit is contained in:
parent
699c22f655
commit
100a1ffb1e
@ -21,10 +21,14 @@ public class FactionsChatEarlyListener extends PlayerListener{
|
|||||||
@Override
|
@Override
|
||||||
public void onPlayerChat(PlayerChatEvent event) {
|
public void onPlayerChat(PlayerChatEvent event) {
|
||||||
if ((event.getMessage().startsWith(Factions.instance.getBaseCommand()+" ") || event.getMessage().equals(Factions.instance.getBaseCommand())) && Conf.allowNoSlashCommand) {
|
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();
|
||||||
parameters.remove(0);
|
// make sure command isn't denied due to being in enemy/neutral territory
|
||||||
CommandSender sender = event.getPlayer();
|
if (!FactionsPlayerListener.preventCommand("/" + msg.toLowerCase(), event.getPlayer())) {
|
||||||
Factions.instance.handleCommand(sender, parameters);
|
List<String> parameters = TextUtil.split(msg);
|
||||||
|
parameters.remove(0);
|
||||||
|
CommandSender sender = event.getPlayer();
|
||||||
|
Factions.instance.handleCommand(sender, parameters);
|
||||||
|
}
|
||||||
event.setCancelled(true);
|
event.setCancelled(true);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
@ -399,22 +399,31 @@ public class FactionsPlayerListener extends PlayerListener{
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void onPlayerCommandPreprocess(PlayerCommandPreprocessEvent event) {
|
public void onPlayerCommandPreprocess(PlayerCommandPreprocessEvent event) {
|
||||||
if (event.isCancelled() || (Conf.territoryNeutralDenyCommands.isEmpty() && Conf.territoryNeutralDenyCommands.isEmpty())) {
|
if (event.isCancelled()) {
|
||||||
return;
|
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()) {
|
if (!me.isInOthersTerritory()) {
|
||||||
return;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
Relation rel = me.getRelationToLocation();
|
Relation rel = me.getRelationToLocation();
|
||||||
if (rel.isAtLeast(Relation.ALLY)) {
|
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
|
String shortCmd = fullCmd.substring(1); // Get rid of the slash at the beginning
|
||||||
|
|
||||||
if (
|
if (
|
||||||
@ -428,8 +437,7 @@ public class FactionsPlayerListener extends PlayerListener{
|
|||||||
cmdCheck = iter.next().toLowerCase();
|
cmdCheck = iter.next().toLowerCase();
|
||||||
if (fullCmd.startsWith(cmdCheck) || shortCmd.startsWith(cmdCheck)) {
|
if (fullCmd.startsWith(cmdCheck) || shortCmd.startsWith(cmdCheck)) {
|
||||||
me.sendMessage("You can't use the command \""+fullCmd+"\" in neutral territory.");
|
me.sendMessage("You can't use the command \""+fullCmd+"\" in neutral territory.");
|
||||||
event.setCancelled(true);
|
return true;
|
||||||
return;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -444,10 +452,11 @@ public class FactionsPlayerListener extends PlayerListener{
|
|||||||
cmdCheck = iter.next().toLowerCase();
|
cmdCheck = iter.next().toLowerCase();
|
||||||
if (fullCmd.startsWith(cmdCheck) || shortCmd.startsWith(cmdCheck)) {
|
if (fullCmd.startsWith(cmdCheck) || shortCmd.startsWith(cmdCheck)) {
|
||||||
me.sendMessage("You can't use the command \""+fullCmd+"\" in enemy territory.");
|
me.sendMessage("You can't use the command \""+fullCmd+"\" in enemy territory.");
|
||||||
event.setCancelled(true);
|
return true;
|
||||||
return;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user