From 2380b9041da2afeec32771f5dab0c7a9f48059d8 Mon Sep 17 00:00:00 2001 From: Jonathan Williams Date: Fri, 11 Sep 2015 22:50:53 -0700 Subject: [PATCH] Added automatic timings report in the event of lag. Added more exception handling around LoadingWindow --- .../core/gui/pages/LoadingWindow.java | 54 ++++++++++++++----- .../src/mineplex/core/monitor/LagMeter.java | 21 ++++++++ 2 files changed, 61 insertions(+), 14 deletions(-) diff --git a/Plugins/Mineplex.Core/src/mineplex/core/gui/pages/LoadingWindow.java b/Plugins/Mineplex.Core/src/mineplex/core/gui/pages/LoadingWindow.java index 3546d17cc..b14d00d41 100644 --- a/Plugins/Mineplex.Core/src/mineplex/core/gui/pages/LoadingWindow.java +++ b/Plugins/Mineplex.Core/src/mineplex/core/gui/pages/LoadingWindow.java @@ -151,21 +151,47 @@ public class LoadingWindow implements Runnable, Listener { { Player player = Bukkit.getPlayer(_playersUUID); - if (player == null || player.getOpenInventory() == null || player.getOpenInventory().getTopInventory() == null || _inv == null ? !player.getOpenInventory().equals(_currentInventory) : (_inv != null && !player.getOpenInventory().getTopInventory().equals(_inv))) { - end(); - return; - } - if (_inv == null) { - _inv = Bukkit.createInventory(null, _size, _title); + try + { + if (player == null || player.getOpenInventory() == null || player.getOpenInventory().getTopInventory() == null || _inv == null ? !player.getOpenInventory().equals(_currentInventory) : (!player.getOpenInventory().getTopInventory().equals(_inv))) + { + end(); + return; + } - setBackGround(); - setLoadingBarItems(); - UtilPlayer.swapToInventory(player, _inv); - Bukkit.getPluginManager().registerEvents(this, _plugin); - } else - setLoadingBarItems(); - - _ticker++; + if (_inv == null) + { + _inv = Bukkit.createInventory(null, _size, _title); + + setBackGround(); + setLoadingBarItems(); + UtilPlayer.swapToInventory(player, _inv); + Bukkit.getPluginManager().registerEvents(this, _plugin); + } + else + setLoadingBarItems(); + } + catch (Exception exception) + { + try + { + System.out.println("player ? " + (player == null)); + System.out.println("player.getOpenInventory() ? " + (player.getOpenInventory() == null)); + System.out.println("player.getOpenInventory().getTopInventory() ? " + (player.getOpenInventory().getTopInventory() == null)); + System.out.println("_inv ? " + (_inv == null)); + exception.printStackTrace(); + } + catch (Exception exception2) + { + exception.printStackTrace(); + } + + end(); + } + finally + { + _ticker++; + } } public void end() { diff --git a/Plugins/Mineplex.Core/src/mineplex/core/monitor/LagMeter.java b/Plugins/Mineplex.Core/src/mineplex/core/monitor/LagMeter.java index 0460b145a..448b55a6f 100644 --- a/Plugins/Mineplex.Core/src/mineplex/core/monitor/LagMeter.java +++ b/Plugins/Mineplex.Core/src/mineplex/core/monitor/LagMeter.java @@ -9,7 +9,9 @@ import mineplex.core.common.util.F; import mineplex.core.updater.UpdateType; import mineplex.core.updater.event.UpdateEvent; +import org.bukkit.Bukkit; import org.bukkit.ChatColor; +import org.bukkit.command.CommandSender; import org.bukkit.entity.Player; import org.bukkit.event.EventHandler; import org.bukkit.event.EventPriority; @@ -28,6 +30,10 @@ public class LagMeter extends MiniPlugin private long _lastTick = 0; + private boolean _timingsRunning; + private boolean _timingsPasted; + private long _timingsStarted; + private HashSet _monitoring = new HashSet(); public LagMeter(JavaPlugin plugin, CoreClientManager clientManager) @@ -87,6 +93,21 @@ public class LagMeter extends MiniPlugin _lastRun = now; _count++; + + if (_timingsRunning) + { + if (_ticksPerSecond > 15 || System.currentTimeMillis() - _timingsStarted > 60000) + { + getPlugin().getServer().dispatchCommand(Bukkit.getConsoleSender(), "timings paste"); + _timingsRunning = false; + } + } + else if (_ticksPerSecond < 10) + { + _timingsRunning = true; + _timingsStarted = System.currentTimeMillis(); + getPlugin().getServer().dispatchCommand(Bukkit.getConsoleSender(), "timings on"); + } } public double getTicksPerSecond()