SteamWar/BauSystem2.0
Archiviert
12
0

Remove RamUsage.bossBar

Dieser Commit ist enthalten in:
yoyosource 2021-05-02 21:01:00 +02:00
Ursprung fadc8bd3da
Commit 3ce4a9b4d3

Datei anzeigen

@ -19,43 +19,14 @@
package de.steamwar.bausystem.features.world;
import de.steamwar.bausystem.BauSystem;
import de.steamwar.bausystem.linkage.LinkageType;
import de.steamwar.bausystem.linkage.Linked;
import lombok.experimental.UtilityClass;
import org.bukkit.Bukkit;
import org.bukkit.boss.BarColor;
import org.bukkit.boss.BarStyle;
import org.bukkit.boss.BossBar;
import org.bukkit.event.Listener;
import java.lang.management.ManagementFactory;
import java.util.logging.Level;
@Linked(LinkageType.PLAIN)
public class RamUsage implements Listener {
private boolean mode = false;
private BossBar bossBar;
public RamUsage() {
bossBar = Bukkit.createBossBar("§eRAM", BarColor.YELLOW, BarStyle.SEGMENTED_10);
Bukkit.getScheduler().runTaskTimer(BauSystem.getInstance(), () -> {
long allocatedMemory = Runtime.getRuntime().totalMemory() - Runtime.getRuntime().freeMemory();
long presumableFreeMemory = Runtime.getRuntime().maxMemory() - allocatedMemory;
double percentageFree = presumableFreeMemory / (double) Runtime.getRuntime().maxMemory();
bossBar.setProgress(1 - percentageFree);
if (mode && percentageFree > 0.5) {
mode = false;
} else if (!mode && percentageFree < 0.3) {
mode = true;
}
if (mode) {
Bukkit.getOnlinePlayers().forEach(bossBar::addPlayer);
} else {
bossBar.removeAll();
}
}, 1, 1);
}
@UtilityClass
public class RamUsage {
public static double getUsage() {
try {