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)
This commit is contained in:
Brettflan 2011-09-30 20:17:47 -05:00
parent 3627996dc6
commit 9c1cd8c85a
3 changed files with 12 additions and 6 deletions

View File

@ -27,6 +27,7 @@ public class FBaseCommand {
public CommandSender sender; public CommandSender sender;
public boolean senderMustBePlayer; public boolean senderMustBePlayer;
public boolean senderIsConsole;
public Player player; public Player player;
public FPlayer me; public FPlayer me;
@ -40,6 +41,7 @@ public class FBaseCommand {
optionalParameters = new ArrayList<String>(); optionalParameters = new ArrayList<String>();
senderMustBePlayer = true; senderMustBePlayer = true;
senderIsConsole = false;
helpNameAndParams = "fail!"; helpNameAndParams = "fail!";
helpDescription = "no description"; helpDescription = "no description";
@ -60,6 +62,10 @@ public class FBaseCommand {
if (sender instanceof Player) { if (sender instanceof Player) {
this.player = (Player)sender; this.player = (Player)sender;
this.me = FPlayer.get(this.player); this.me = FPlayer.get(this.player);
senderIsConsole = false;
}
else {
senderIsConsole = true;
} }
perform(); perform();
@ -80,7 +86,7 @@ public class FBaseCommand {
} }
public boolean validateCall() { public boolean validateCall() {
if ( this.senderMustBePlayer && ! (sender instanceof Player)) { if ( this.senderMustBePlayer && senderIsConsole ) {
sendMessage("This command can only be used by ingame players."); sendMessage("This command can only be used by ingame players.");
return false; return false;
} }
@ -202,7 +208,7 @@ public class FBaseCommand {
return fp.getFaction(); return fp.getFaction();
} }
if (defaultToMine && sender instanceof Player) { if (defaultToMine && !senderIsConsole) {
return me.getFaction(); return me.getFaction();
} }

View File

@ -62,9 +62,9 @@ public class FCommandDisband extends FBaseCommand {
// Inform all players // Inform all players
for (FPlayer fplayer : FPlayer.getAllOnline()) { for (FPlayer fplayer : FPlayer.getAllOnline()) {
if (fplayer.getFaction() == faction) { 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 { } 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() ); Faction.delete( faction.getId() );

View File

@ -38,8 +38,8 @@ public class FRelationCommand extends FBaseCommand {
return; return;
} }
if (otherFaction.getId() == 0) { if (!otherFaction.isNormal()) {
sendMessage("Nope! You can't :) The default faction is not a real faction."); sendMessage("Nope! You can't :) You can only ally with player factions.");
return; return;
} }