diff --git a/Plugins/Mineplex.Core/src/mineplex/core/disguise/DisguiseManager.java b/Plugins/Mineplex.Core/src/mineplex/core/disguise/DisguiseManager.java index 56f05c1ad..14ef675c3 100644 --- a/Plugins/Mineplex.Core/src/mineplex/core/disguise/DisguiseManager.java +++ b/Plugins/Mineplex.Core/src/mineplex/core/disguise/DisguiseManager.java @@ -45,6 +45,7 @@ import mineplex.core.disguise.disguises.DisguisePlayer; import mineplex.core.packethandler.IPacketRunnable; import mineplex.core.packethandler.PacketHandler; import mineplex.core.packethandler.PacketVerifier; +import mineplex.core.timing.TimingManager; import mineplex.core.updater.UpdateType; import mineplex.core.updater.event.UpdateEvent; @@ -233,6 +234,7 @@ public class DisguiseManager extends MiniPlugin implements IPacketRunnable if (event.getType() != UpdateType.SEC) return; + TimingManager.startTotal("Teleport Disguises"); for (Player player : Bukkit.getOnlinePlayers()) { for (Player otherPlayer : Bukkit.getOnlinePlayers()) @@ -244,6 +246,7 @@ public class DisguiseManager extends MiniPlugin implements IPacketRunnable ((CraftPlayer)player).getHandle().playerConnection.sendPacket(new PacketPlayOutEntityTeleport(((CraftPlayer)otherPlayer).getHandle())); } } + TimingManager.stopTotal("Teleport Disguises"); } public void clearDisguises() diff --git a/Plugins/Mineplex.Core/src/mineplex/core/timing/TimeData.java b/Plugins/Mineplex.Core/src/mineplex/core/timing/TimeData.java new file mode 100644 index 000000000..4e3093d75 --- /dev/null +++ b/Plugins/Mineplex.Core/src/mineplex/core/timing/TimeData.java @@ -0,0 +1,27 @@ +package mineplex.core.timing; + +public class TimeData +{ + public TimeData(String title, long time) + { + Started = time; + LastMarker = time; + Total = 0L; + } + + public String Title; + public long Started; + public long LastMarker; + public long Total; + + public void addTime() + { + Total += System.currentTimeMillis() - LastMarker; + LastMarker = System.currentTimeMillis(); + } + + public void printInfo() + { + System.out.println("]==[TIME DATA]==[" + Title + " took " + Total + "ms in the last " + (System.currentTimeMillis() - Started) + "ms"); + } +} diff --git a/Plugins/Mineplex.Core.Common/src/mineplex/core/common/util/TimeUtil.java b/Plugins/Mineplex.Core/src/mineplex/core/timing/TimingManager.java similarity index 50% rename from Plugins/Mineplex.Core.Common/src/mineplex/core/common/util/TimeUtil.java rename to Plugins/Mineplex.Core/src/mineplex/core/timing/TimingManager.java index 0044887fe..7f4020fe1 100644 --- a/Plugins/Mineplex.Core.Common/src/mineplex/core/common/util/TimeUtil.java +++ b/Plugins/Mineplex.Core/src/mineplex/core/timing/TimingManager.java @@ -1,18 +1,49 @@ -package mineplex.core.common.util; +package mineplex.core.timing; -import java.util.AbstractMap; import java.util.Map.Entry; -public class TimeUtil +import org.bukkit.event.Listener; +import org.bukkit.plugin.java.JavaPlugin; + +import mineplex.core.common.util.NautHashMap; + +public class TimingManager implements Listener { + private static TimingManager _instance; + + private JavaPlugin _plugin; private static NautHashMap _timingList = new NautHashMap(); - private static NautHashMap> _totalList = new NautHashMap>(); + private static NautHashMap _totalList = new NautHashMap(); private static Object _timingLock = new Object(); private static Object _totalLock = new Object(); public static boolean Debug = false; + protected TimingManager(JavaPlugin plugin) + { + _instance = this; + + _plugin = plugin; + + _plugin.getServer().getPluginManager().registerEvents(this, _plugin); + } + + public static TimingManager Initialize(JavaPlugin plugin) + { + if (_instance == null) + { + _instance = new TimingManager(plugin); + } + + return _instance; + } + + public static TimingManager instance() + { + return _instance; + } + public static void startTotal(String title) { if (!Debug) @@ -22,11 +53,15 @@ public class TimeUtil { if (_totalList.containsKey(title)) { - _totalList.put(title, new AbstractMap.SimpleEntry(System.currentTimeMillis(), _totalList.get(title).getValue())); + TimeData data = _totalList.get(title); + data.LastMarker = System.currentTimeMillis(); + + _totalList.put(title, data); } else { - _totalList.put(title, new AbstractMap.SimpleEntry(System.currentTimeMillis(), 0L)); + TimeData data = new TimeData(title, System.currentTimeMillis()); + _totalList.put(title, data); } } } @@ -40,8 +75,10 @@ public class TimeUtil { if (_totalList.containsKey(title)) { - long additionalTime = System.currentTimeMillis() - _totalList.get(title).getKey(); - _totalList.put(title, new AbstractMap.SimpleEntry(System.currentTimeMillis(), _totalList.get(title).getValue() + additionalTime)); + TimeData data = _totalList.get(title); + data.addTime(); + + _totalList.put(title, data); } } } @@ -53,7 +90,7 @@ public class TimeUtil synchronized(_totalLock) { - System.out.println("]==[TIMING]==[" + title + " has taken " + _totalList.get(title).getValue() + "ms so far"); + _totalList.get(title).printInfo(); } } @@ -64,12 +101,10 @@ public class TimeUtil synchronized(_totalLock) { - for (Entry> entry : _totalList.entrySet()) + for (Entry entry : _totalList.entrySet()) { - System.out.println("]==[TIMING]==[" + entry.getKey() + " has taken " + entry.getValue().getValue() + "ms so far"); + entry.getValue().printInfo(); } - - _totalList.clear(); } } diff --git a/Plugins/Nautilus.Game.Arcade/src/nautilus/game/arcade/ArcadeManager.java b/Plugins/Nautilus.Game.Arcade/src/nautilus/game/arcade/ArcadeManager.java index 5fd2bb608..143e9f88a 100644 --- a/Plugins/Nautilus.Game.Arcade/src/nautilus/game/arcade/ArcadeManager.java +++ b/Plugins/Nautilus.Game.Arcade/src/nautilus/game/arcade/ArcadeManager.java @@ -72,6 +72,7 @@ import mineplex.core.projectile.ProjectileManager; import mineplex.core.stats.StatsManager; import mineplex.core.status.ServerStatusManager; import mineplex.core.teleport.Teleport; +import mineplex.core.timing.TimingManager; public class ArcadeManager extends MiniPlugin implements IRelation { @@ -561,7 +562,7 @@ public class ArcadeManager extends MiniPlugin implements IRelation public ArrayList LoadFiles(String gameName) { - TimeUtil.start("ArcadeManager LoadFiles"); + TimingManager.start("ArcadeManager LoadFiles"); File folder = new File(".." + File.separatorChar + ".." + File.separatorChar + "update" + File.separatorChar + "maps" + File.separatorChar + gameName); if (!folder.exists()) folder.mkdirs(); @@ -590,7 +591,7 @@ public class ArcadeManager extends MiniPlugin implements IRelation for (String map : maps) System.out.println("Found Map: " + map); - TimeUtil.stop("ArcadeManager LoadFiles"); + TimingManager.stop("ArcadeManager LoadFiles"); return maps; } diff --git a/Plugins/Nautilus.Game.Arcade/src/nautilus/game/arcade/game/Game.java b/Plugins/Nautilus.Game.Arcade/src/nautilus/game/arcade/game/Game.java index c9da551bd..682efa1b1 100644 --- a/Plugins/Nautilus.Game.Arcade/src/nautilus/game/arcade/game/Game.java +++ b/Plugins/Nautilus.Game.Arcade/src/nautilus/game/arcade/game/Game.java @@ -4,13 +4,13 @@ import java.util.ArrayList; import java.util.HashMap; import java.util.HashSet; +import mineplex.core.timing.TimingManager; import mineplex.core.updater.event.UpdateEvent; import mineplex.core.updater.UpdateType; import mineplex.core.common.Rank; import mineplex.core.common.util.C; import mineplex.core.common.util.F; import mineplex.core.common.util.NautHashMap; -import mineplex.core.common.util.TimeUtil; import mineplex.core.common.util.UtilBlock; import mineplex.core.common.util.UtilMath; import mineplex.core.common.util.UtilPlayer; diff --git a/Plugins/Nautilus.Game.Arcade/src/nautilus/game/arcade/managers/GameCreationManager.java b/Plugins/Nautilus.Game.Arcade/src/nautilus/game/arcade/managers/GameCreationManager.java index c00e95110..2e149ed61 100644 --- a/Plugins/Nautilus.Game.Arcade/src/nautilus/game/arcade/managers/GameCreationManager.java +++ b/Plugins/Nautilus.Game.Arcade/src/nautilus/game/arcade/managers/GameCreationManager.java @@ -4,10 +4,10 @@ import java.util.ArrayList; import java.util.HashMap; import java.util.Iterator; -import mineplex.core.common.util.TimeUtil; import mineplex.core.common.util.UtilMath; import mineplex.core.common.util.UtilServer; import mineplex.core.common.util.UtilTime; +import mineplex.core.timing.TimingManager; import mineplex.core.updater.UpdateType; import mineplex.core.updater.event.UpdateEvent; import nautilus.game.arcade.ArcadeManager; @@ -94,7 +94,7 @@ public class GameCreationManager implements Listener HandlerList.unregisterAll(game); - TimeUtil.start("GameCreationManager - Attempting Removal - " + game.GetName()); + TimingManager.start("GameCreationManager - Attempting Removal - " + game.GetName()); //Cleaned if (game.WorldData == null || game.WorldData.World == null) @@ -107,7 +107,7 @@ public class GameCreationManager implements Listener boolean removedPlayers = false; if (UtilTime.elapsed(game.GetStateTime(), 20000)) { - TimeUtil.start("GameCreationManager - Kick Players - " + game.GetName()); + TimingManager.start("GameCreationManager - Kick Players - " + game.GetName()); for (Player player : game.WorldData.World.getPlayers()) { @@ -119,7 +119,7 @@ public class GameCreationManager implements Listener removedPlayers = true; - TimeUtil.stop("GameCreationManager - Kick Players - " + game.GetName()); + TimingManager.stop("GameCreationManager - Kick Players - " + game.GetName()); } //Clean @@ -128,17 +128,17 @@ public class GameCreationManager implements Listener if (game.WorldData.World.getPlayers().isEmpty()) System.out.println("World Player Count [" + game.WorldData.World.getPlayers().size() + "]"); - TimeUtil.start("GameCreationManager - Uninit World - " + game.GetName()); + TimingManager.start("GameCreationManager - Uninit World - " + game.GetName()); game.WorldData.Uninitialize(); game.WorldData = null; gameIterator.remove(); - TimeUtil.stop("GameCreationManager - Uninit World - " + game.GetName()); + TimingManager.stop("GameCreationManager - Uninit World - " + game.GetName()); }; } - TimeUtil.stop("GameCreationManager - Attempting Removal - " + game.GetName()); + TimingManager.stop("GameCreationManager - Attempting Removal - " + game.GetName()); } } @@ -185,13 +185,13 @@ public class GameCreationManager implements Listener return; } - TimeUtil.start("DisplayNext"); + TimingManager.start("DisplayNext"); Manager.GetLobby().DisplayNext(Manager.GetGame(), pastTeams); - TimeUtil.stop("DisplayNext"); + TimingManager.stop("DisplayNext"); - TimeUtil.start("registerEvents"); + TimingManager.start("registerEvents"); UtilServer.getServer().getPluginManager().registerEvents(Manager.GetGame(), Manager.GetPlugin()); - TimeUtil.stop("registerEvents"); + TimingManager.stop("registerEvents"); } public void SetNextGameType(GameType type) diff --git a/Plugins/Nautilus.Game.Arcade/src/nautilus/game/arcade/world/WorldData.java b/Plugins/Nautilus.Game.Arcade/src/nautilus/game/arcade/world/WorldData.java index f598bb867..fc455008a 100644 --- a/Plugins/Nautilus.Game.Arcade/src/nautilus/game/arcade/world/WorldData.java +++ b/Plugins/Nautilus.Game.Arcade/src/nautilus/game/arcade/world/WorldData.java @@ -12,11 +12,11 @@ import java.util.HashMap; import mineplex.core.common.util.FileUtil; import mineplex.core.common.util.MapUtil; -import mineplex.core.common.util.TimeUtil; import mineplex.core.common.util.UtilMath; import mineplex.core.common.util.UtilServer; import mineplex.core.common.util.WorldUtil; import mineplex.core.common.util.ZipUtil; +import mineplex.core.timing.TimingManager; import nautilus.game.arcade.game.Game; import net.minecraft.server.v1_7_R3.ChunkPreLoadEvent; @@ -78,17 +78,17 @@ public class WorldData { public void run() { - TimeUtil.start("WorldData loading world."); + TimingManager.start("WorldData loading world."); //Start World World = WorldUtil.LoadWorld(new WorldCreator(GetFolder())); - TimeUtil.stop("WorldData loading world."); + TimingManager.stop("WorldData loading world."); World.setDifficulty(Difficulty.HARD); - TimeUtil.start("WorldData loading WorldConfig."); + TimingManager.start("WorldData loading WorldConfig."); //Load World Data worldData.LoadWorldConfig(); - TimeUtil.stop("WorldData loading WorldConfig."); + TimingManager.stop("WorldData loading WorldConfig."); } }); } @@ -126,16 +126,16 @@ public class WorldData protected void UnzipWorld() { - TimeUtil.start("UnzipWorld creating folders"); + TimingManager.start("UnzipWorld creating folders"); String folder = GetFolder(); new File(folder).mkdir(); new File(folder + java.io.File.separator + "region").mkdir(); new File(folder + java.io.File.separator + "data").mkdir(); - TimeUtil.stop("UnzipWorld creating folders"); + TimingManager.stop("UnzipWorld creating folders"); - TimeUtil.start("UnzipWorld UnzipToDirectory"); + TimingManager.start("UnzipWorld UnzipToDirectory"); ZipUtil.UnzipToDirectory("../../update/maps/" + Host.GetName() + "/" + GetFile() + ".zip", folder); - TimeUtil.stop("UnzipWorld UnzipToDirectory"); + TimingManager.stop("UnzipWorld UnzipToDirectory"); } public void LoadWorldConfig()