/f disband, /f list, and /f who <tag> 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

This commit is contained in:
Brettflan 2011-06-30 05:56:02 -05:00
parent 24e85e0e77
commit 8f1606beba
5 changed files with 31 additions and 8 deletions

View File

@ -70,10 +70,16 @@ public class Faction {
return prefix+this.tag; return prefix+this.tag;
} }
public String getTag(Faction otherFaction) { 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) { 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) { public void setTag(String str) {
if (Conf.factionTagForceUpperCase) { if (Conf.factionTagForceUpperCase) {
@ -182,7 +188,10 @@ public class Faction {
} }
public Relation getRelation(FPlayer fplayer) { public Relation getRelation(FPlayer fplayer) {
return getRelation(fplayer.getFaction()); if (fplayer == null)
return Relation.NEUTRAL;
else
return getRelation(fplayer.getFaction());
} }
//----------------------------------------------// //----------------------------------------------//

View File

@ -189,11 +189,11 @@ public class FBaseCommand {
return faction; return faction;
} }
if (defaultToMine) { if (defaultToMine && sender instanceof Player) {
return me.getFaction(); 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; return null;
} }

View File

@ -9,6 +9,8 @@ public class FCommandDisband extends FBaseCommand {
public FCommandDisband() { public FCommandDisband() {
aliases.add("disband"); aliases.add("disband");
senderMustBePlayer = false;
requiredParameters.add("faction tag"); requiredParameters.add("faction tag");
helpDescription = "Disband a faction"; helpDescription = "Disband a faction";
@ -25,10 +27,10 @@ public class FCommandDisband extends FBaseCommand {
Faction faction = Faction.findByTag(parameters.get(0)); Faction faction = Faction.findByTag(parameters.get(0));
if( faction != null && faction.getId() > 0 ) { if( faction != null && faction.getId() > 0 ) {
me.sendMessage("Faction " + faction.getTag() + " got disbanded"); sendMessage("Faction " + faction.getTag() + " got disbanded");
Faction.delete( faction.getId() ); Faction.delete( faction.getId() );
} else { } else {
me.sendMessage("Faction " + parameters.get(0) + "not found"); sendMessage("Faction " + parameters.get(0) + "not found");
} }
} }
} }

View File

@ -16,6 +16,8 @@ public class FCommandList extends FBaseCommand {
aliases.add("list"); aliases.add("list");
aliases.add("ls"); aliases.add("ls");
senderMustBePlayer = false;
optionalParameters.add("page"); optionalParameters.add("page");
helpDescription = "Show a list of the factions"; helpDescription = "Show a list of the factions";
@ -84,7 +86,7 @@ public class FCommandList extends FBaseCommand {
for (int pos = page * 9; pos < maxPos; pos++) { for (int pos = page * 9; pos < maxPos; pos++) {
Faction faction = FactionList.get(pos); Faction faction = FactionList.get(pos);
if (faction.getId() == 0) { 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 { } else {
sendMessage(faction.getTag(me)+Conf.colorSystem+" "+faction.getFPlayersWhereOnline(true).size()+"/"+faction.getFPlayers().size()+" online, "+faction.getLandRounded()+"/"+faction.getPowerRounded()+"/"+faction.getPowerMaxRounded()); sendMessage(faction.getTag(me)+Conf.colorSystem+" "+faction.getFPlayersWhereOnline(true).size()+"/"+faction.getFPlayers().size()+" online, "+faction.getLandRounded()+"/"+faction.getPowerRounded()+"/"+faction.getPowerMaxRounded());
} }

View File

@ -3,6 +3,7 @@ package org.mcteam.factions.commands;
import java.util.Collection; import java.util.Collection;
import org.bukkit.command.CommandSender; import org.bukkit.command.CommandSender;
import org.bukkit.entity.Player;
import org.mcteam.factions.Conf; import org.mcteam.factions.Conf;
import org.mcteam.factions.FPlayer; import org.mcteam.factions.FPlayer;
import org.mcteam.factions.Faction; import org.mcteam.factions.Faction;
@ -17,6 +18,8 @@ public class FCommandShow extends FBaseCommand {
aliases.add("show"); aliases.add("show");
aliases.add("who"); aliases.add("who");
senderMustBePlayer = false;
optionalParameters.add("faction tag"); optionalParameters.add("faction tag");
helpDescription = "Show faction information"; helpDescription = "Show faction information";
@ -32,10 +35,17 @@ public class FCommandShow extends FBaseCommand {
Faction faction; Faction faction;
if (parameters.size() > 0) { if (parameters.size() > 0) {
faction = findFaction(parameters.get(0), true); faction = findFaction(parameters.get(0), true);
} else if (!(sender instanceof Player)) {
sendMessage("From the command line, you must specify a faction tag (f who <faction tag>).");
return;
} else { } else {
faction = me.getFaction(); faction = me.getFaction();
} }
if (faction == null) {
return;
}
Collection<FPlayer> admins = faction.getFPlayersWhereRole(Role.ADMIN); Collection<FPlayer> admins = faction.getFPlayersWhereRole(Role.ADMIN);
Collection<FPlayer> mods = faction.getFPlayersWhereRole(Role.MODERATOR); Collection<FPlayer> mods = faction.getFPlayersWhereRole(Role.MODERATOR);
Collection<FPlayer> normals = faction.getFPlayersWhereRole(Role.NORMAL); Collection<FPlayer> normals = faction.getFPlayersWhereRole(Role.NORMAL);