Significantly speed up player list loading.

This commit is contained in:
StevenLawson 2014-07-29 22:38:08 -04:00
parent 01edfed307
commit 3d6be1cd51
3 changed files with 48 additions and 4 deletions

View File

@ -125,6 +125,11 @@ public class TFM_Player
}
public void save()
{
save(true);
}
public void save(boolean doConfigSave)
{
if (!isComplete())
{
@ -149,6 +154,9 @@ public class TFM_Player
section.set("lastjoinunix", lastLoginUnix);
section.set("ips", ips);
if (doConfigSave)
{
config.save();
}
}
}

View File

@ -5,7 +5,6 @@ import java.util.HashMap;
import java.util.Map;
import java.util.Set;
import java.util.UUID;
import static me.StevenLawson.TotalFreedomMod.TFM_AdminList.save;
import net.minecraft.util.com.google.common.collect.Sets;
import org.bukkit.Bukkit;
import org.bukkit.entity.Player;
@ -38,6 +37,9 @@ public class TFM_PlayerList
public static void load()
{
TFM_Util.TFMethodTimer timer = new TFM_Util.TFMethodTimer();
timer.start();
playerList.clear();
config.load();
@ -72,7 +74,9 @@ public class TFM_PlayerList
// Save list
saveAll();
TFM_Log.info("Loaded playerdata for " + playerList.size() + " players.");
timer.update();
TFM_Log.info("Loaded playerdata for " + playerList.size() + " players in " + timer.getTotal() + " ms.");
}
private static void saveAll()
@ -80,8 +84,10 @@ public class TFM_PlayerList
// Put entries
for (TFM_Player entry : playerList.values())
{
entry.save();
entry.save(false);
}
getConfig().save();
}
public static TFM_Player getEntry(String player)

View File

@ -1093,4 +1093,34 @@ public class TFM_Util
{
STRIKE_ONE, STRIKE_TWO, STRIKE_THREE;
}
public static class TFMethodTimer
{
private long lastStart;
private long total = 0;
public TFMethodTimer()
{
}
public void start()
{
this.lastStart = System.currentTimeMillis();
}
public void update()
{
this.total += (System.currentTimeMillis() - this.lastStart);
}
public long getTotal()
{
return this.total;
}
public void printTotalToLog(String timerName)
{
TFM_Log.info("DEBUG: " + timerName + " used " + this.getTotal() + " ms.");
}
}
}