From 3d6be1cd51c07b0734095c5cf2f753c03001488c Mon Sep 17 00:00:00 2001 From: StevenLawson Date: Tue, 29 Jul 2014 22:38:08 -0400 Subject: [PATCH] Significantly speed up player list loading. --- .../TotalFreedomMod/TFM_Player.java | 10 ++++++- .../TotalFreedomMod/TFM_PlayerList.java | 12 ++++++-- .../TotalFreedomMod/TFM_Util.java | 30 +++++++++++++++++++ 3 files changed, 48 insertions(+), 4 deletions(-) diff --git a/src/me/StevenLawson/TotalFreedomMod/TFM_Player.java b/src/me/StevenLawson/TotalFreedomMod/TFM_Player.java index c112480..1ed31e4 100644 --- a/src/me/StevenLawson/TotalFreedomMod/TFM_Player.java +++ b/src/me/StevenLawson/TotalFreedomMod/TFM_Player.java @@ -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); - config.save(); + if (doConfigSave) + { + config.save(); + } } } diff --git a/src/me/StevenLawson/TotalFreedomMod/TFM_PlayerList.java b/src/me/StevenLawson/TotalFreedomMod/TFM_PlayerList.java index c5695f7..5ed4f73 100644 --- a/src/me/StevenLawson/TotalFreedomMod/TFM_PlayerList.java +++ b/src/me/StevenLawson/TotalFreedomMod/TFM_PlayerList.java @@ -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) diff --git a/src/me/StevenLawson/TotalFreedomMod/TFM_Util.java b/src/me/StevenLawson/TotalFreedomMod/TFM_Util.java index 41d5cf7..78af28a 100644 --- a/src/me/StevenLawson/TotalFreedomMod/TFM_Util.java +++ b/src/me/StevenLawson/TotalFreedomMod/TFM_Util.java @@ -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."); + } + } }