SteamWar/BauSystem2.0
Archiviert
12
0
Dieser Commit ist enthalten in:
yoyosource 2021-05-01 11:50:27 +02:00
Ursprung 8a918a649b
Commit b63c388523

Datei anzeigen

@ -19,16 +19,47 @@
package de.steamwar.bausystem.features.world; package de.steamwar.bausystem.features.world;
import lombok.experimental.UtilityClass; import de.steamwar.bausystem.BauSystem;
import de.steamwar.bausystem.linkage.LinkageType;
import de.steamwar.bausystem.linkage.Linked;
import org.bukkit.Bukkit; 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.lang.management.ManagementFactory;
import java.util.logging.Level; import java.util.logging.Level;
@UtilityClass @Linked(LinkageType.LISTENER)
public class RamUsage { public class RamUsage implements Listener {
public double getUsage() { 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);
}, 1, 1);
}
@EventHandler
public void onPlayerJoin(PlayerJoinEvent event) {
bossBar.addPlayer(event.getPlayer());
}
@EventHandler
public void onPlayerQuit(PlayerQuitEvent event) {
bossBar.removePlayer(event.getPlayer());
}
public static double getUsage() {
try { try {
long memorySize = ((com.sun.management.OperatingSystemMXBean) ManagementFactory.getOperatingSystemMXBean()).getTotalPhysicalMemorySize(); long memorySize = ((com.sun.management.OperatingSystemMXBean) ManagementFactory.getOperatingSystemMXBean()).getTotalPhysicalMemorySize();
long freeMemory = ((com.sun.management.OperatingSystemMXBean) ManagementFactory.getOperatingSystemMXBean()).getFreePhysicalMemorySize(); long freeMemory = ((com.sun.management.OperatingSystemMXBean) ManagementFactory.getOperatingSystemMXBean()).getFreePhysicalMemorySize();