Don't repeatedly update FTeamWrapper for the same faction

This commit is contained in:
eueln 2014-11-09 21:12:42 -06:00
parent 81182dccaa
commit 00045b0186

View File

@ -14,6 +14,7 @@ public class FTeamWrapper {
private static final Map<Faction, FTeamWrapper> wrappers = new HashMap<Faction, FTeamWrapper>(); private static final Map<Faction, FTeamWrapper> wrappers = new HashMap<Faction, FTeamWrapper>();
private static final List<FScoreboard> tracking = new ArrayList<FScoreboard>(); private static final List<FScoreboard> tracking = new ArrayList<FScoreboard>();
private static int factionTeamPtr; private static int factionTeamPtr;
private static final Set<Faction> updating = new HashSet<Faction>();
private final Map<FScoreboard, Team> teams = new HashMap<FScoreboard, Team>(); private final Map<FScoreboard, Team> teams = new HashMap<FScoreboard, Team>();
private final String teamName; private final String teamName;
@ -25,12 +26,15 @@ public class FTeamWrapper {
return; return;
} }
Bukkit.getScheduler().runTask(P.p, new Runnable() { if (updating.add(faction)) {
@Override Bukkit.getScheduler().runTask(P.p, new Runnable() {
public void run() { @Override
applyUpdates(faction); public void run() {
} updating.remove(faction);
}); applyUpdates(faction);
}
});
}
} }
public static void applyUpdates(Faction faction) { public static void applyUpdates(Faction faction) {
@ -38,6 +42,11 @@ public class FTeamWrapper {
return; return;
} }
if (updating.contains(faction)) {
// Faction will be updated soon.
return;
}
FTeamWrapper wrapper = wrappers.get(faction); FTeamWrapper wrapper = wrappers.get(faction);
Set<FPlayer> factionMembers = faction.getFPlayers(); Set<FPlayer> factionMembers = faction.getFPlayers();