From 9c1cd8c85a4004a172d98f984ca0ff9cef29dcc1 Mon Sep 17 00:00:00 2001 From: Brettflan Date: Fri, 30 Sep 2011 20:17:47 -0500 Subject: [PATCH] Added senderIsConsole boolean to FBaseCommand to simplify checking whether sender is console or player Fix for /f disband indicating a random player if command came from console Fix for factions being able to potentially set relations with safe zone or war zone (though it didn't do anything, of course) --- .../massivecraft/factions/commands/FBaseCommand.java | 10 ++++++++-- .../factions/commands/FCommandDisband.java | 4 ++-- .../factions/commands/FRelationCommand.java | 4 ++-- 3 files changed, 12 insertions(+), 6 deletions(-) diff --git a/src/com/massivecraft/factions/commands/FBaseCommand.java b/src/com/massivecraft/factions/commands/FBaseCommand.java index 5f338f89..850d56de 100644 --- a/src/com/massivecraft/factions/commands/FBaseCommand.java +++ b/src/com/massivecraft/factions/commands/FBaseCommand.java @@ -27,6 +27,7 @@ public class FBaseCommand { public CommandSender sender; public boolean senderMustBePlayer; + public boolean senderIsConsole; public Player player; public FPlayer me; @@ -40,6 +41,7 @@ public class FBaseCommand { optionalParameters = new ArrayList(); senderMustBePlayer = true; + senderIsConsole = false; helpNameAndParams = "fail!"; helpDescription = "no description"; @@ -60,6 +62,10 @@ public class FBaseCommand { if (sender instanceof Player) { this.player = (Player)sender; this.me = FPlayer.get(this.player); + senderIsConsole = false; + } + else { + senderIsConsole = true; } perform(); @@ -80,7 +86,7 @@ public class FBaseCommand { } public boolean validateCall() { - if ( this.senderMustBePlayer && ! (sender instanceof Player)) { + if ( this.senderMustBePlayer && senderIsConsole ) { sendMessage("This command can only be used by ingame players."); return false; } @@ -202,7 +208,7 @@ public class FBaseCommand { return fp.getFaction(); } - if (defaultToMine && sender instanceof Player) { + if (defaultToMine && !senderIsConsole) { return me.getFaction(); } diff --git a/src/com/massivecraft/factions/commands/FCommandDisband.java b/src/com/massivecraft/factions/commands/FCommandDisband.java index 2599b063..a35724c8 100644 --- a/src/com/massivecraft/factions/commands/FCommandDisband.java +++ b/src/com/massivecraft/factions/commands/FCommandDisband.java @@ -62,9 +62,9 @@ public class FCommandDisband extends FBaseCommand { // Inform all players for (FPlayer fplayer : FPlayer.getAllOnline()) { if (fplayer.getFaction() == faction) { - fplayer.sendMessage(me.getNameAndRelevant(fplayer)+Conf.colorSystem+" disbanded your faction."); + fplayer.sendMessage((senderIsConsole ? "A server admin" : me.getNameAndRelevant(fplayer))+Conf.colorSystem+" disbanded your faction."); } else { - fplayer.sendMessage(me.getNameAndRelevant(fplayer)+Conf.colorSystem+" disbanded the faction "+faction.getTag(fplayer)+"."); + fplayer.sendMessage((senderIsConsole ? "A server admin" : me.getNameAndRelevant(fplayer))+Conf.colorSystem+" disbanded the faction "+faction.getTag(fplayer)+"."); } } Faction.delete( faction.getId() ); diff --git a/src/com/massivecraft/factions/commands/FRelationCommand.java b/src/com/massivecraft/factions/commands/FRelationCommand.java index 5e75ac55..0eeb6231 100644 --- a/src/com/massivecraft/factions/commands/FRelationCommand.java +++ b/src/com/massivecraft/factions/commands/FRelationCommand.java @@ -38,8 +38,8 @@ public class FRelationCommand extends FBaseCommand { return; } - if (otherFaction.getId() == 0) { - sendMessage("Nope! You can't :) The default faction is not a real faction."); + if (!otherFaction.isNormal()) { + sendMessage("Nope! You can't :) You can only ally with player factions."); return; }