From f25fa86db9d6832918abc7af2337326303efa760 Mon Sep 17 00:00:00 2001 From: yoyosource Date: Sat, 1 May 2021 21:39:01 +0200 Subject: [PATCH] Better RamUsage show meter --- .../bausystem/features/world/RamUsage.java | 28 +++++++++---------- 1 file changed, 13 insertions(+), 15 deletions(-) diff --git a/BauSystem_Main/src/de/steamwar/bausystem/features/world/RamUsage.java b/BauSystem_Main/src/de/steamwar/bausystem/features/world/RamUsage.java index 5ba0f45c..22ba7226 100644 --- a/BauSystem_Main/src/de/steamwar/bausystem/features/world/RamUsage.java +++ b/BauSystem_Main/src/de/steamwar/bausystem/features/world/RamUsage.java @@ -26,17 +26,15 @@ import org.bukkit.Bukkit; import org.bukkit.boss.BarColor; import org.bukkit.boss.BarStyle; import org.bukkit.boss.BossBar; -import org.bukkit.event.EventHandler; import org.bukkit.event.Listener; -import org.bukkit.event.player.PlayerJoinEvent; -import org.bukkit.event.player.PlayerQuitEvent; import java.lang.management.ManagementFactory; import java.util.logging.Level; -@Linked(LinkageType.LISTENER) +@Linked(LinkageType.PLAIN) public class RamUsage implements Listener { + private boolean mode = false; private BossBar bossBar; public RamUsage() { @@ -46,17 +44,17 @@ public class RamUsage implements Listener { long presumableFreeMemory = Runtime.getRuntime().maxMemory() - allocatedMemory; double percentageFree = presumableFreeMemory / (double) Runtime.getRuntime().maxMemory(); bossBar.setProgress(1 - percentageFree); - }, 20, 20); - } - - @EventHandler - public void onPlayerJoin(PlayerJoinEvent event) { - bossBar.addPlayer(event.getPlayer()); - } - - @EventHandler - public void onPlayerQuit(PlayerQuitEvent event) { - bossBar.removePlayer(event.getPlayer()); + if (mode && percentageFree > 0.7) { + mode = false; + } else if (!mode && percentageFree < 0.5) { + mode = true; + } + if (mode) { + Bukkit.getOnlinePlayers().forEach(bossBar::addPlayer); + } else { + bossBar.removeAll(); + } + }, 1, 1); } public static double getUsage() {