SteamWar/BauSystem2.0
Archiviert
12
0

Better RamUsage show meter

Dieser Commit ist enthalten in:
yoyosource 2021-05-01 21:39:01 +02:00
Ursprung 28fb3b7301
Commit f25fa86db9

Datei anzeigen

@ -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() {