Add RamUsage
Dieser Commit ist enthalten in:
Ursprung
8a918a649b
Commit
b63c388523
@ -19,16 +19,47 @@
|
||||
|
||||
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.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;
|
||||
|
||||
@UtilityClass
|
||||
public class RamUsage {
|
||||
@Linked(LinkageType.LISTENER)
|
||||
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 {
|
||||
long memorySize = ((com.sun.management.OperatingSystemMXBean) ManagementFactory.getOperatingSystemMXBean()).getTotalPhysicalMemorySize();
|
||||
long freeMemory = ((com.sun.management.OperatingSystemMXBean) ManagementFactory.getOperatingSystemMXBean()).getFreePhysicalMemorySize();
|
||||
|
In neuem Issue referenzieren
Einen Benutzer sperren