From 8f1606bebab74d4e464f9f135756a4385fda59c6 Mon Sep 17 00:00:00 2001 From: Brettflan Date: Thu, 30 Jun 2011 05:56:02 -0500 Subject: [PATCH] /f disband, /f list, and /f who commands can now be used from the server console; /f list now shows "Factionless" instead of "Wilderness" for factioness players; fix for some potential NPEs --- src/org/mcteam/factions/Faction.java | 15 ++++++++++++--- .../mcteam/factions/commands/FBaseCommand.java | 4 ++-- .../mcteam/factions/commands/FCommandDisband.java | 6 ++++-- .../mcteam/factions/commands/FCommandList.java | 4 +++- .../mcteam/factions/commands/FCommandShow.java | 10 ++++++++++ 5 files changed, 31 insertions(+), 8 deletions(-) diff --git a/src/org/mcteam/factions/Faction.java b/src/org/mcteam/factions/Faction.java index 472c45ce..a8229c99 100644 --- a/src/org/mcteam/factions/Faction.java +++ b/src/org/mcteam/factions/Faction.java @@ -70,10 +70,16 @@ public class Faction { return prefix+this.tag; } public String getTag(Faction otherFaction) { - return this.getTag(otherFaction.getRelationColor(this).toString()); + if (otherFaction == null) + return getTag(); + else + return this.getTag(otherFaction.getRelationColor(this).toString()); } public String getTag(FPlayer otherFplayer) { - return this.getTag(otherFplayer.getRelationColor(this).toString()); + if (otherFplayer == null) + return getTag(); + else + return this.getTag(otherFplayer.getRelationColor(this).toString()); } public void setTag(String str) { if (Conf.factionTagForceUpperCase) { @@ -182,7 +188,10 @@ public class Faction { } public Relation getRelation(FPlayer fplayer) { - return getRelation(fplayer.getFaction()); + if (fplayer == null) + return Relation.NEUTRAL; + else + return getRelation(fplayer.getFaction()); } //----------------------------------------------// diff --git a/src/org/mcteam/factions/commands/FBaseCommand.java b/src/org/mcteam/factions/commands/FBaseCommand.java index 860c5fa8..f1d8cd26 100644 --- a/src/org/mcteam/factions/commands/FBaseCommand.java +++ b/src/org/mcteam/factions/commands/FBaseCommand.java @@ -189,11 +189,11 @@ public class FBaseCommand { return faction; } - if (defaultToMine) { + if (defaultToMine && sender instanceof Player) { return me.getFaction(); } - me.sendMessage(Conf.colorSystem+"No faction or player \""+factionName+"\" was found"); + sendMessage(Conf.colorSystem+"No faction or player \""+factionName+"\" was found"); return null; } diff --git a/src/org/mcteam/factions/commands/FCommandDisband.java b/src/org/mcteam/factions/commands/FCommandDisband.java index 562b7aaa..ace47a86 100644 --- a/src/org/mcteam/factions/commands/FCommandDisband.java +++ b/src/org/mcteam/factions/commands/FCommandDisband.java @@ -9,6 +9,8 @@ public class FCommandDisband extends FBaseCommand { public FCommandDisband() { aliases.add("disband"); + senderMustBePlayer = false; + requiredParameters.add("faction tag"); helpDescription = "Disband a faction"; @@ -25,10 +27,10 @@ public class FCommandDisband extends FBaseCommand { Faction faction = Faction.findByTag(parameters.get(0)); if( faction != null && faction.getId() > 0 ) { - me.sendMessage("Faction " + faction.getTag() + " got disbanded"); + sendMessage("Faction " + faction.getTag() + " got disbanded"); Faction.delete( faction.getId() ); } else { - me.sendMessage("Faction " + parameters.get(0) + "not found"); + sendMessage("Faction " + parameters.get(0) + "not found"); } } } diff --git a/src/org/mcteam/factions/commands/FCommandList.java b/src/org/mcteam/factions/commands/FCommandList.java index 07b12fdf..ccdef32a 100644 --- a/src/org/mcteam/factions/commands/FCommandList.java +++ b/src/org/mcteam/factions/commands/FCommandList.java @@ -16,6 +16,8 @@ public class FCommandList extends FBaseCommand { aliases.add("list"); aliases.add("ls"); + senderMustBePlayer = false; + optionalParameters.add("page"); helpDescription = "Show a list of the factions"; @@ -84,7 +86,7 @@ public class FCommandList extends FBaseCommand { for (int pos = page * 9; pos < maxPos; pos++) { Faction faction = FactionList.get(pos); if (faction.getId() == 0) { - sendMessage(faction.getTag(me)+Conf.colorSystem+" "+faction.getFPlayersWhereOnline(true).size() + " online"); + sendMessage("Factionless"+Conf.colorSystem+" "+faction.getFPlayersWhereOnline(true).size() + " online"); } else { sendMessage(faction.getTag(me)+Conf.colorSystem+" "+faction.getFPlayersWhereOnline(true).size()+"/"+faction.getFPlayers().size()+" online, "+faction.getLandRounded()+"/"+faction.getPowerRounded()+"/"+faction.getPowerMaxRounded()); } diff --git a/src/org/mcteam/factions/commands/FCommandShow.java b/src/org/mcteam/factions/commands/FCommandShow.java index e9a8f2d7..d12aa3c1 100644 --- a/src/org/mcteam/factions/commands/FCommandShow.java +++ b/src/org/mcteam/factions/commands/FCommandShow.java @@ -3,6 +3,7 @@ package org.mcteam.factions.commands; import java.util.Collection; import org.bukkit.command.CommandSender; +import org.bukkit.entity.Player; import org.mcteam.factions.Conf; import org.mcteam.factions.FPlayer; import org.mcteam.factions.Faction; @@ -17,6 +18,8 @@ public class FCommandShow extends FBaseCommand { aliases.add("show"); aliases.add("who"); + senderMustBePlayer = false; + optionalParameters.add("faction tag"); helpDescription = "Show faction information"; @@ -32,9 +35,16 @@ public class FCommandShow extends FBaseCommand { Faction faction; if (parameters.size() > 0) { faction = findFaction(parameters.get(0), true); + } else if (!(sender instanceof Player)) { + sendMessage("From the command line, you must specify a faction tag (f who )."); + return; } else { faction = me.getFaction(); } + + if (faction == null) { + return; + } Collection admins = faction.getFPlayersWhereRole(Role.ADMIN); Collection mods = faction.getFPlayersWhereRole(Role.MODERATOR);