From ea06c468fc8fcf9601120da84fa2f698c5da3c80 Mon Sep 17 00:00:00 2001 From: Olof Larsson Date: Thu, 25 Apr 2013 16:02:37 +0200 Subject: [PATCH] Fix some more small bugs --- .../factions/cmd/CmdFactionsJoin.java | 8 ++++---- .../factions/cmd/CmdFactionsList.java | 2 +- .../factions/cmd/CmdFactionsShow.java | 19 ++++++++++++------- .../massivecraft/factions/entity/UPlayer.java | 8 ++++---- .../factions/entity/UPlayerColl.java | 11 +++++++++-- .../massivecraft/factions/entity/XColls.java | 9 +++++++-- .../listeners/FactionsListenerEcon.java | 10 ++++++---- 7 files changed, 43 insertions(+), 24 deletions(-) diff --git a/src/com/massivecraft/factions/cmd/CmdFactionsJoin.java b/src/com/massivecraft/factions/cmd/CmdFactionsJoin.java index 3d2e1bc0..71066219 100644 --- a/src/com/massivecraft/factions/cmd/CmdFactionsJoin.java +++ b/src/com/massivecraft/factions/cmd/CmdFactionsJoin.java @@ -48,7 +48,7 @@ public class CmdFactionsJoin extends FCommand if (faction == uplayerFaction) { - msg("%s %s already a member of %s", uplayer.describeTo(usender, true), (samePlayer ? "are" : "is"), faction.getName(usender)); + msg("%s %s already a member of %s.", uplayer.describeTo(usender, true), (samePlayer ? "are" : "is"), faction.getName(usender)); return; } @@ -88,10 +88,10 @@ public class CmdFactionsJoin extends FCommand // Inform if (!samePlayer) { - uplayer.msg("%s moved you into the faction %s.", usender.describeTo(uplayer, true), faction.getName(uplayer)); + uplayer.msg("%s moved you into the faction %s.", usender.describeTo(uplayer, true), faction.getName(uplayer)); } - faction.msg("%s joined your faction.", uplayer.describeTo(faction, true)); - usender.msg("%s successfully joined %s.", uplayer.describeTo(usender, true), faction.getName(usender)); + faction.msg("%s joined your faction.", uplayer.describeTo(faction, true)); + usender.msg("%s successfully joined %s.", uplayer.describeTo(usender, true), faction.getName(usender)); // Apply uplayer.resetFactionData(); diff --git a/src/com/massivecraft/factions/cmd/CmdFactionsList.java b/src/com/massivecraft/factions/cmd/CmdFactionsList.java index 59acbe52..c2306117 100644 --- a/src/com/massivecraft/factions/cmd/CmdFactionsList.java +++ b/src/com/massivecraft/factions/cmd/CmdFactionsList.java @@ -17,7 +17,7 @@ public class CmdFactionsList extends FCommand { public CmdFactionsList() { - this.addAliases("ls", "list"); + this.addAliases("l", "list"); this.addOptionalArg("page", "1"); diff --git a/src/com/massivecraft/factions/cmd/CmdFactionsShow.java b/src/com/massivecraft/factions/cmd/CmdFactionsShow.java index 2f5713c0..b7031f3f 100644 --- a/src/com/massivecraft/factions/cmd/CmdFactionsShow.java +++ b/src/com/massivecraft/factions/cmd/CmdFactionsShow.java @@ -27,7 +27,7 @@ public class CmdFactionsShow extends FCommand { public CmdFactionsShow() { - this.addAliases("show", "who"); + this.addAliases("s", "show", "who"); this.addOptionalArg("faction", "you"); @@ -42,15 +42,12 @@ public class CmdFactionsShow extends FCommand if (faction == null) return; UConf uconf = UConf.get(faction); - - Collection leaders = faction.getUPlayersWhereRole(Rel.LEADER); - Collection officers = faction.getUPlayersWhereRole(Rel.OFFICER); - Collection normals = faction.getUPlayersWhereRole(Rel.MEMBER); - Collection recruits = faction.getUPlayersWhereRole(Rel.RECRUIT); + // INFO: Description msg(Txt.titleize(faction.getName(usender))); msg("Description: %s", faction.getDescription()); + // INFO: Age long ageMillis = faction.getCreatedAtMillis() - System.currentTimeMillis(); LinkedHashMap ageUnitcounts = TimeDiffUtil.limit(TimeDiffUtil.unitcounts(ageMillis, TimeUnit.getAllButMillis()), 3); String ageString = TimeDiffUtil.formatedVerboose(ageUnitcounts, ""); @@ -68,8 +65,10 @@ public class CmdFactionsShow extends FCommand msg("This faction is peaceful - in truce with everyone."); } - msg("Joining: "+(faction.isOpen() ? "no invitation is needed" : "invitation is required")); + // INFO: Open + msg("Open: "+(faction.isOpen() ? "Yes - anyone can join" : "No - only invited people can join")); + // INFO: Power double powerBoost = faction.getPowerBoost(); String boost = (powerBoost == 0.0) ? "" : (powerBoost > 0.0 ? " (bonus: " : " (penalty: ") + powerBoost + ")"; msg("Land / Power / Maxpower: %d/%d/%d %s", faction.getLandCount(), faction.getPowerRounded(), faction.getPowerMaxRounded(), boost); @@ -124,6 +123,12 @@ public class CmdFactionsShow extends FCommand sendMessage(Txt.parse("Enemies: ") + Txt.implode(relationNames.get(Rel.ENEMY), sepparator)); // List the members... + + Collection leaders = faction.getUPlayersWhereRole(Rel.LEADER); + Collection officers = faction.getUPlayersWhereRole(Rel.OFFICER); + Collection normals = faction.getUPlayersWhereRole(Rel.MEMBER); + Collection recruits = faction.getUPlayersWhereRole(Rel.RECRUIT); + List memberOnlineNames = new ArrayList(); List memberOfflineNames = new ArrayList(); diff --git a/src/com/massivecraft/factions/entity/UPlayer.java b/src/com/massivecraft/factions/entity/UPlayer.java index f84593ac..abd8b8e2 100644 --- a/src/com/massivecraft/factions/entity/UPlayer.java +++ b/src/com/massivecraft/factions/entity/UPlayer.java @@ -423,8 +423,8 @@ public class UPlayer extends SenderEntity implements EconomyParticipato public String getNameAndSomething(String something) { - String ret = this.role.getPrefix(); - if (something.length() > 0) + String ret = this.getRole().getPrefix(); + if (something != null && something.length() > 0) { ret += something+" "; } @@ -440,7 +440,7 @@ public class UPlayer extends SenderEntity implements EconomyParticipato } else { - return this.getName(); + return this.getNameAndSomething(null); } } @@ -557,7 +557,7 @@ public class UPlayer extends SenderEntity implements EconomyParticipato } // Event - FactionsEventMembershipChange membershipChangeEvent = new FactionsEventMembershipChange(sender, this, myFaction, MembershipChangeReason.LEAVE); + FactionsEventMembershipChange membershipChangeEvent = new FactionsEventMembershipChange(this.getSender(), this, myFaction, MembershipChangeReason.LEAVE); membershipChangeEvent.run(); if (membershipChangeEvent.isCancelled()) return; diff --git a/src/com/massivecraft/factions/entity/UPlayerColl.java b/src/com/massivecraft/factions/entity/UPlayerColl.java index 3d1af909..6a94c29c 100644 --- a/src/com/massivecraft/factions/entity/UPlayerColl.java +++ b/src/com/massivecraft/factions/entity/UPlayerColl.java @@ -7,6 +7,7 @@ import com.massivecraft.mcore.mixin.Mixin; import com.massivecraft.mcore.store.MStore; import com.massivecraft.mcore.store.SenderColl; import com.massivecraft.mcore.util.TimeUnit; +import com.massivecraft.mcore.util.Txt; public class UPlayerColl extends SenderColl { @@ -64,11 +65,17 @@ public class UPlayerColl extends SenderColl public void clean() { + FactionColl factionColl = FactionColls.get().get(this); + String universe = this.getUniverse(); for (UPlayer uplayer : this.getAll()) { - if (FactionColls.get().get(this).containsId(uplayer.getFactionId())) continue; + String factionId = uplayer.getFactionId(); + if (factionColl.containsId(factionId)) continue; - Factions.get().log("Reset faction data (invalid faction) for player "+uplayer.getName()); + uplayer.resetFactionData(); + + String message = Txt.parse("Reset data for %s in %s universe. Unknown factionId %s", uplayer.getDisplayName(), universe, factionId); + Factions.get().log(message); } } diff --git a/src/com/massivecraft/factions/entity/XColls.java b/src/com/massivecraft/factions/entity/XColls.java index 0fb7e15f..4a502ff5 100644 --- a/src/com/massivecraft/factions/entity/XColls.java +++ b/src/com/massivecraft/factions/entity/XColls.java @@ -17,12 +17,17 @@ public abstract class XColls, E> extends Colls if (o instanceof Entity) { - return this.getForUniverse(((Entity)o).getUniverse()); + String universe = ((Entity)o).getUniverse(); + if (universe == null) return null; + return this.getForUniverse(universe); } if (o instanceof Coll) { - return this.getForUniverse(((Coll)o).getUniverse()); + String universe = ((Coll)o).getUniverse(); + if (universe == null) return null; + return this.getForUniverse(universe); + } if (SenderUtil.isNonplayer(o)) diff --git a/src/com/massivecraft/factions/listeners/FactionsListenerEcon.java b/src/com/massivecraft/factions/listeners/FactionsListenerEcon.java index b7f37a71..0ac90ccc 100644 --- a/src/com/massivecraft/factions/listeners/FactionsListenerEcon.java +++ b/src/com/massivecraft/factions/listeners/FactionsListenerEcon.java @@ -131,20 +131,22 @@ public class FactionsListenerEcon implements Listener Double cost = null; String desc = null; + UConf uconf = UConf.get(event.getSender()); + if (uconf == null) return; + if (event.getReason() == MembershipChangeReason.JOIN) { - cost = UConf.get(event.getSender()).econCostJoin; + cost = uconf.econCostJoin; desc = "join a faction"; } else if (event.getReason() == MembershipChangeReason.LEAVE) { - // TODO: NPE once occurred on line below. - cost = UConf.get(event.getSender()).econCostLeave; + cost = uconf.econCostLeave; desc = "leave a faction"; } else if (event.getReason() == MembershipChangeReason.KICK) { - cost = UConf.get(event.getSender()).econCostKick; + cost = uconf.econCostKick; desc = "kick someone from a faction"; } else