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 boolean senderMustBePlayer;
public boolean senderIsConsole;
public Player player;
public FPlayer me;
@ -40,6 +41,7 @@ public class FBaseCommand {
optionalParameters = new ArrayList<String>();
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();
}

View File

@ -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() );

View File

@ -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;
}