Optimization: Factions (as objects) now maintain a list of FPlayers in the faction for faster lookup

INTEGRATION NOTE: getFPlayers() and getFPlayersWhereOnline(boolean online) now return Set<FPlayer> instead of ArrayList<FPlayer>, so other plugins which hook into those methods will probably need to be updated.
This commit is contained in:
Brettflan
2012-01-13 03:46:31 -06:00
parent 4b4d26ed29
commit 47ba56de9e
3 changed files with 53 additions and 21 deletions

View File

@@ -1,6 +1,5 @@
package com.massivecraft.factions;
import java.util.ArrayList;
import java.util.HashSet;
import java.util.Set;
@@ -48,6 +47,9 @@ public class FPlayer extends PlayerEntity implements EconomyParticipator
public boolean hasFaction() { return ! factionId.equals("0"); }
public void setFaction(Faction faction)
{
Faction oldFaction = this.getFaction();
if (oldFaction != null) oldFaction.removeFPlayer(this);
faction.addFPlayer(this);
this.factionId = faction.getId();
SpoutFeatures.updateAppearances(this.getPlayer());
}
@@ -130,6 +132,10 @@ public class FPlayer extends PlayerEntity implements EconomyParticipator
public final void resetFactionData(boolean doSpotUpdate)
{
Faction currentFaction = this.getFaction();
if (currentFaction != null)
currentFaction.removeFPlayer(this);
this.factionId = "0"; // The default neutral faction
this.chatMode = ChatMode.PUBLIC;
this.role = Rel.MEMBER;
@@ -491,8 +497,7 @@ public class FPlayer extends PlayerEntity implements EconomyParticipator
}
// Am I the last one in the faction?
ArrayList<FPlayer> fplayers = myFaction.getFPlayers();
if (fplayers.size() == 1 && fplayers.get(0) == this)
if (myFaction.getFPlayers().size() == 1)
{
// Transfer all money
if (Econ.shouldBeUsed())