mirror of
https://github.com/PurpurMC/Purpur.git
synced 2026-02-17 08:27:43 +01:00
Implement ram and rambar commands
This commit is contained in:
@@ -1,360 +0,0 @@
|
|||||||
From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001
|
|
||||||
From: BillyGalbreath <blake.galbreath@gmail.com>
|
|
||||||
Date: Mon, 26 Sep 2022 07:43:30 -0500
|
|
||||||
Subject: [PATCH] Implement ram and rambar commands
|
|
||||||
|
|
||||||
|
|
||||||
diff --git a/net/minecraft/commands/Commands.java b/net/minecraft/commands/Commands.java
|
|
||||||
index 5873f74df67d59f25682286a5b027963d8a6d382..93c07a4c96e25ed1db5e1f721ab5d53192a0225f 100644
|
|
||||||
--- a/net/minecraft/commands/Commands.java
|
|
||||||
+++ b/net/minecraft/commands/Commands.java
|
|
||||||
@@ -261,6 +261,8 @@ public class Commands {
|
|
||||||
org.purpurmc.purpur.command.UptimeCommand.register(this.dispatcher); // Purpur
|
|
||||||
org.purpurmc.purpur.command.TPSBarCommand.register(this.dispatcher); // Purpur
|
|
||||||
org.purpurmc.purpur.command.CompassCommand.register(this.dispatcher); // Purpur
|
|
||||||
+ org.purpurmc.purpur.command.RamBarCommand.register(this.dispatcher); // Purpur - Implement ram and rambar commands
|
|
||||||
+ org.purpurmc.purpur.command.RamCommand.register(this.dispatcher); // Purpur - Implement ram and rambar commands
|
|
||||||
}
|
|
||||||
|
|
||||||
if (environment.includeIntegrated) {
|
|
||||||
diff --git a/net/minecraft/server/level/ServerPlayer.java b/net/minecraft/server/level/ServerPlayer.java
|
|
||||||
index d97db4d05d7940d8408e7e0d473a3b17d956b858..6f39fd99ffb28d6c0267f4251c54af0c519289db 100644
|
|
||||||
--- a/net/minecraft/server/level/ServerPlayer.java
|
|
||||||
+++ b/net/minecraft/server/level/ServerPlayer.java
|
|
||||||
@@ -330,6 +330,7 @@ public class ServerPlayer extends net.minecraft.world.entity.player.Player imple
|
|
||||||
public boolean purpurClient = false; // Purpur - Purpur client support
|
|
||||||
private boolean tpsBar = false; // Purpur
|
|
||||||
private boolean compassBar = false; // Purpur
|
|
||||||
+ private boolean ramBar = false; // Purpur - Implement ram and rambar commands
|
|
||||||
|
|
||||||
// Paper start - rewrite chunk system
|
|
||||||
private ca.spottedleaf.moonrise.patches.chunk_system.player.RegionizedPlayerChunkLoader.PlayerChunkLoaderData chunkLoader;
|
|
||||||
@@ -694,6 +695,7 @@ public class ServerPlayer extends net.minecraft.world.entity.player.Player imple
|
|
||||||
|
|
||||||
if (nbt.contains("Purpur.TPSBar")) { this.tpsBar = nbt.getBoolean("Purpur.TPSBar"); } // Purpur
|
|
||||||
if (nbt.contains("Purpur.CompassBar")) { this.compassBar = nbt.getBoolean("Purpur.CompassBar"); } // Purpur
|
|
||||||
+ if (nbt.contains("Purpur.RamBar")) { this.ramBar = nbt.getBoolean("Purpur.RamBar"); } // Purpur - Implement ram and rambar commands
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
@@ -746,6 +748,7 @@ public class ServerPlayer extends net.minecraft.world.entity.player.Player imple
|
|
||||||
}
|
|
||||||
|
|
||||||
this.saveEnderPearls(nbt);
|
|
||||||
+ nbt.putBoolean("Purpur.RamBar", this.ramBar); // Purpur - Implement ram and rambar commands
|
|
||||||
nbt.putBoolean("Purpur.TPSBar", this.tpsBar); // Purpur
|
|
||||||
nbt.putBoolean("Purpur.CompassBar", this.compassBar); // Purpur
|
|
||||||
}
|
|
||||||
@@ -3457,5 +3460,13 @@ public class ServerPlayer extends net.minecraft.world.entity.player.Player imple
|
|
||||||
public void compassBar(boolean compassBar) {
|
|
||||||
this.compassBar = compassBar;
|
|
||||||
}
|
|
||||||
+
|
|
||||||
+ public boolean ramBar() {
|
|
||||||
+ return this.ramBar;
|
|
||||||
+ }
|
|
||||||
+
|
|
||||||
+ public void ramBar(boolean ramBar) {
|
|
||||||
+ this.ramBar = ramBar;
|
|
||||||
+ }
|
|
||||||
// Purpur end
|
|
||||||
}
|
|
||||||
diff --git a/src/main/java/org/purpurmc/purpur/PurpurConfig.java b/src/main/java/org/purpurmc/purpur/PurpurConfig.java
|
|
||||||
index 4218aa563ba435a67c8e7af1fa9dc0c0d8d6b377..dca02d697dd0982b006d4d975e7df745ab62dac5 100644
|
|
||||||
--- a/src/main/java/org/purpurmc/purpur/PurpurConfig.java
|
|
||||||
+++ b/src/main/java/org/purpurmc/purpur/PurpurConfig.java
|
|
||||||
@@ -185,6 +185,8 @@ public class PurpurConfig {
|
|
||||||
public static String creditsCommandOutput = "<green>%s has been shown the end credits";
|
|
||||||
public static String demoCommandOutput = "<green>%s has been shown the demo screen";
|
|
||||||
public static String pingCommandOutput = "<green>%s's ping is %sms";
|
|
||||||
+ public static String ramCommandOutput = "<green>Ram Usage: <used>/<xmx> (<percent>)";
|
|
||||||
+ public static String rambarCommandOutput = "<green>Rambar toggled <onoff> for <target>";
|
|
||||||
public static String tpsbarCommandOutput = "<green>Tpsbar toggled <onoff> for <target>";
|
|
||||||
public static String dontRunWithScissors = "<red><italic>Don't run with scissors!";
|
|
||||||
public static String uptimeCommandOutput = "<green>Server uptime is <uptime>";
|
|
||||||
@@ -202,6 +204,8 @@ public class PurpurConfig {
|
|
||||||
creditsCommandOutput = getString("settings.messages.credits-command-output", creditsCommandOutput);
|
|
||||||
demoCommandOutput = getString("settings.messages.demo-command-output", demoCommandOutput);
|
|
||||||
pingCommandOutput = getString("settings.messages.ping-command-output", pingCommandOutput);
|
|
||||||
+ ramCommandOutput = getString("settings.messages.ram-command-output", ramCommandOutput);
|
|
||||||
+ rambarCommandOutput = getString("settings.messages.rambar-command-output", rambarCommandOutput);
|
|
||||||
tpsbarCommandOutput = getString("settings.messages.tpsbar-command-output", tpsbarCommandOutput);
|
|
||||||
dontRunWithScissors = getString("settings.messages.dont-run-with-scissors", dontRunWithScissors);
|
|
||||||
uptimeCommandOutput = getString("settings.messages.uptime-command-output", uptimeCommandOutput);
|
|
||||||
@@ -250,6 +254,15 @@ public class PurpurConfig {
|
|
||||||
disableGiveCommandDrops = getBoolean("settings.disable-give-dropping", disableGiveCommandDrops);
|
|
||||||
}
|
|
||||||
|
|
||||||
+ public static String commandRamBarTitle = "<gray>Ram<yellow>:</yellow> <used>/<xmx> (<percent>)";
|
|
||||||
+ public static BossBar.Overlay commandRamBarProgressOverlay = BossBar.Overlay.NOTCHED_20;
|
|
||||||
+ public static BossBar.Color commandRamBarProgressColorGood = BossBar.Color.GREEN;
|
|
||||||
+ public static BossBar.Color commandRamBarProgressColorMedium = BossBar.Color.YELLOW;
|
|
||||||
+ public static BossBar.Color commandRamBarProgressColorLow = BossBar.Color.RED;
|
|
||||||
+ public static String commandRamBarTextColorGood = "<gradient:#55ff55:#00aa00><text></gradient>";
|
|
||||||
+ public static String commandRamBarTextColorMedium = "<gradient:#ffff55:#ffaa00><text></gradient>";
|
|
||||||
+ public static String commandRamBarTextColorLow = "<gradient:#ff5555:#aa0000><text></gradient>";
|
|
||||||
+ public static int commandRamBarTickInterval = 20;
|
|
||||||
public static String commandTPSBarTitle = "<gray>TPS<yellow>:</yellow> <tps> MSPT<yellow>:</yellow> <mspt> Ping<yellow>:</yellow> <ping>ms";
|
|
||||||
public static BossBar.Overlay commandTPSBarProgressOverlay = BossBar.Overlay.NOTCHED_20;
|
|
||||||
public static TPSBarTask.FillMode commandTPSBarProgressFillMode = TPSBarTask.FillMode.MSPT;
|
|
||||||
@@ -277,6 +290,16 @@ public class PurpurConfig {
|
|
||||||
public static String uptimeSecond = "%02d second";
|
|
||||||
public static String uptimeSeconds = "%02d seconds";
|
|
||||||
private static void commandSettings() {
|
|
||||||
+ commandRamBarTitle = getString("settings.command.rambar.title", commandRamBarTitle);
|
|
||||||
+ commandRamBarProgressOverlay = BossBar.Overlay.valueOf(getString("settings.command.rambar.overlay", commandRamBarProgressOverlay.name()));
|
|
||||||
+ commandRamBarProgressColorGood = BossBar.Color.valueOf(getString("settings.command.rambar.progress-color.good", commandRamBarProgressColorGood.name()));
|
|
||||||
+ commandRamBarProgressColorMedium = BossBar.Color.valueOf(getString("settings.command.rambar.progress-color.medium", commandRamBarProgressColorMedium.name()));
|
|
||||||
+ commandRamBarProgressColorLow = BossBar.Color.valueOf(getString("settings.command.rambar.progress-color.low", commandRamBarProgressColorLow.name()));
|
|
||||||
+ commandRamBarTextColorGood = getString("settings.command.rambar.text-color.good", commandRamBarTextColorGood);
|
|
||||||
+ commandRamBarTextColorMedium = getString("settings.command.rambar.text-color.medium", commandRamBarTextColorMedium);
|
|
||||||
+ commandRamBarTextColorLow = getString("settings.command.rambar.text-color.low", commandRamBarTextColorLow);
|
|
||||||
+ commandRamBarTickInterval = getInt("settings.command.rambar.tick-interval", commandRamBarTickInterval);
|
|
||||||
+
|
|
||||||
commandTPSBarTitle = getString("settings.command.tpsbar.title", commandTPSBarTitle);
|
|
||||||
commandTPSBarProgressOverlay = BossBar.Overlay.valueOf(getString("settings.command.tpsbar.overlay", commandTPSBarProgressOverlay.name()));
|
|
||||||
commandTPSBarProgressFillMode = TPSBarTask.FillMode.valueOf(getString("settings.command.tpsbar.fill-mode", commandTPSBarProgressFillMode.name()));
|
|
||||||
diff --git a/src/main/java/org/purpurmc/purpur/command/RamBarCommand.java b/src/main/java/org/purpurmc/purpur/command/RamBarCommand.java
|
|
||||||
new file mode 100644
|
|
||||||
index 0000000000000000000000000000000000000000..2852c07adb080c34905f5d1b19efed8ea47eecc6
|
|
||||||
--- /dev/null
|
|
||||||
+++ b/src/main/java/org/purpurmc/purpur/command/RamBarCommand.java
|
|
||||||
@@ -0,0 +1,44 @@
|
|
||||||
+package org.purpurmc.purpur.command;
|
|
||||||
+
|
|
||||||
+import com.mojang.brigadier.CommandDispatcher;
|
|
||||||
+import net.kyori.adventure.text.Component;
|
|
||||||
+import net.kyori.adventure.text.format.NamedTextColor;
|
|
||||||
+import net.kyori.adventure.text.minimessage.MiniMessage;
|
|
||||||
+import net.kyori.adventure.text.minimessage.tag.resolver.Placeholder;
|
|
||||||
+import net.minecraft.commands.CommandSourceStack;
|
|
||||||
+import net.minecraft.commands.Commands;
|
|
||||||
+import net.minecraft.commands.arguments.EntityArgument;
|
|
||||||
+import net.minecraft.server.level.ServerPlayer;
|
|
||||||
+import org.purpurmc.purpur.PurpurConfig;
|
|
||||||
+import org.purpurmc.purpur.task.RamBarTask;
|
|
||||||
+
|
|
||||||
+import java.util.Collection;
|
|
||||||
+import java.util.Collections;
|
|
||||||
+
|
|
||||||
+public class RamBarCommand {
|
|
||||||
+ public static void register(CommandDispatcher<CommandSourceStack> dispatcher) {
|
|
||||||
+ dispatcher.register(Commands.literal("rambar")
|
|
||||||
+ .requires(listener -> listener.hasPermission(2, "bukkit.command.rambar"))
|
|
||||||
+ .executes(context -> execute(context.getSource(), Collections.singleton(context.getSource().getPlayerOrException())))
|
|
||||||
+ .then(Commands.argument("targets", EntityArgument.players())
|
|
||||||
+ .requires(listener -> listener.hasPermission(2, "bukkit.command.rambar.other"))
|
|
||||||
+ .executes((context) -> execute(context.getSource(), EntityArgument.getPlayers(context, "targets")))
|
|
||||||
+ )
|
|
||||||
+ );
|
|
||||||
+ }
|
|
||||||
+
|
|
||||||
+ private static int execute(CommandSourceStack sender, Collection<ServerPlayer> targets) {
|
|
||||||
+ for (ServerPlayer player : targets) {
|
|
||||||
+ boolean result = RamBarTask.instance().togglePlayer(player.getBukkitEntity());
|
|
||||||
+ player.ramBar(result);
|
|
||||||
+
|
|
||||||
+ Component output = MiniMessage.miniMessage().deserialize(PurpurConfig.rambarCommandOutput,
|
|
||||||
+ Placeholder.component("onoff", Component.translatable(result ? "options.on" : "options.off")
|
|
||||||
+ .color(result ? NamedTextColor.GREEN : NamedTextColor.RED)),
|
|
||||||
+ Placeholder.parsed("target", player.getGameProfile().getName()));
|
|
||||||
+
|
|
||||||
+ sender.sendSuccess(output, false);
|
|
||||||
+ }
|
|
||||||
+ return targets.size();
|
|
||||||
+ }
|
|
||||||
+}
|
|
||||||
diff --git a/src/main/java/org/purpurmc/purpur/command/RamCommand.java b/src/main/java/org/purpurmc/purpur/command/RamCommand.java
|
|
||||||
new file mode 100644
|
|
||||||
index 0000000000000000000000000000000000000000..992f8dfc628c7485e335191e1308cdfd4eedfbe8
|
|
||||||
--- /dev/null
|
|
||||||
+++ b/src/main/java/org/purpurmc/purpur/command/RamCommand.java
|
|
||||||
@@ -0,0 +1,30 @@
|
|
||||||
+package org.purpurmc.purpur.command;
|
|
||||||
+
|
|
||||||
+import com.mojang.brigadier.CommandDispatcher;
|
|
||||||
+import io.papermc.paper.adventure.PaperAdventure;
|
|
||||||
+import net.kyori.adventure.text.minimessage.MiniMessage;
|
|
||||||
+import net.kyori.adventure.text.minimessage.tag.resolver.Placeholder;
|
|
||||||
+import net.minecraft.commands.CommandSourceStack;
|
|
||||||
+import net.minecraft.commands.Commands;
|
|
||||||
+import org.purpurmc.purpur.PurpurConfig;
|
|
||||||
+import org.purpurmc.purpur.task.RamBarTask;
|
|
||||||
+
|
|
||||||
+public class RamCommand {
|
|
||||||
+ public static void register(CommandDispatcher<CommandSourceStack> dispatcher) {
|
|
||||||
+ dispatcher.register(Commands.literal("ram")
|
|
||||||
+ .requires(listener -> listener.hasPermission(2, "bukkit.command.ram"))
|
|
||||||
+ .executes(context -> {
|
|
||||||
+ CommandSourceStack sender = context.getSource();
|
|
||||||
+ RamBarTask ramBar = RamBarTask.instance();
|
|
||||||
+ sender.sendSuccess(() -> PaperAdventure.asVanilla(MiniMessage.miniMessage().deserialize(PurpurConfig.ramCommandOutput,
|
|
||||||
+ Placeholder.component("allocated", ramBar.format(ramBar.getAllocated())),
|
|
||||||
+ Placeholder.component("used", ramBar.format(ramBar.getUsed())),
|
|
||||||
+ Placeholder.component("xmx", ramBar.format(ramBar.getXmx())),
|
|
||||||
+ Placeholder.component("xms", ramBar.format(ramBar.getXms())),
|
|
||||||
+ Placeholder.unparsed("percent", ((int) (ramBar.getPercent() * 100)) + "%")
|
|
||||||
+ )), false);
|
|
||||||
+ return 1;
|
|
||||||
+ })
|
|
||||||
+ );
|
|
||||||
+ }
|
|
||||||
+}
|
|
||||||
diff --git a/src/main/java/org/purpurmc/purpur/task/BossBarTask.java b/src/main/java/org/purpurmc/purpur/task/BossBarTask.java
|
|
||||||
index 65c1bac3daf781c66442350ba08c43b21d2f1637..3c3d4cd52db93b97a40321030a70ebc282c9636b 100644
|
|
||||||
--- a/src/main/java/org/purpurmc/purpur/task/BossBarTask.java
|
|
||||||
+++ b/src/main/java/org/purpurmc/purpur/task/BossBarTask.java
|
|
||||||
@@ -89,17 +89,22 @@ public abstract class BossBarTask extends BukkitRunnable {
|
|
||||||
}
|
|
||||||
|
|
||||||
public static void startAll() {
|
|
||||||
+ RamBarTask.instance().start();
|
|
||||||
TPSBarTask.instance().start();
|
|
||||||
CompassTask.instance().start();
|
|
||||||
}
|
|
||||||
|
|
||||||
public static void stopAll() {
|
|
||||||
+ RamBarTask.instance().stop();
|
|
||||||
TPSBarTask.instance().stop();
|
|
||||||
CompassTask.instance().stop();
|
|
||||||
}
|
|
||||||
|
|
||||||
public static void addToAll(ServerPlayer player) {
|
|
||||||
Player bukkit = player.getBukkitEntity();
|
|
||||||
+ if (player.ramBar()) {
|
|
||||||
+ RamBarTask.instance().addPlayer(bukkit);
|
|
||||||
+ }
|
|
||||||
if (player.tpsBar()) {
|
|
||||||
TPSBarTask.instance().addPlayer(bukkit);
|
|
||||||
}
|
|
||||||
@@ -109,6 +114,7 @@ public abstract class BossBarTask extends BukkitRunnable {
|
|
||||||
}
|
|
||||||
|
|
||||||
public static void removeFromAll(Player player) {
|
|
||||||
+ RamBarTask.instance().removePlayer(player);
|
|
||||||
TPSBarTask.instance().removePlayer(player);
|
|
||||||
CompassTask.instance().removePlayer(player);
|
|
||||||
}
|
|
||||||
diff --git a/src/main/java/org/purpurmc/purpur/task/RamBarTask.java b/src/main/java/org/purpurmc/purpur/task/RamBarTask.java
|
|
||||||
new file mode 100644
|
|
||||||
index 0000000000000000000000000000000000000000..8e98c0ae73e2c40002a72b5d0d246ffa0c3ab38f
|
|
||||||
--- /dev/null
|
|
||||||
+++ b/src/main/java/org/purpurmc/purpur/task/RamBarTask.java
|
|
||||||
@@ -0,0 +1,117 @@
|
|
||||||
+package org.purpurmc.purpur.task;
|
|
||||||
+
|
|
||||||
+import net.kyori.adventure.bossbar.BossBar;
|
|
||||||
+import net.kyori.adventure.text.Component;
|
|
||||||
+import net.kyori.adventure.text.minimessage.MiniMessage;
|
|
||||||
+import net.kyori.adventure.text.minimessage.tag.resolver.Placeholder;
|
|
||||||
+import org.bukkit.entity.Player;
|
|
||||||
+import org.purpurmc.purpur.PurpurConfig;
|
|
||||||
+
|
|
||||||
+import java.lang.management.ManagementFactory;
|
|
||||||
+import java.lang.management.MemoryUsage;
|
|
||||||
+
|
|
||||||
+public class RamBarTask extends BossBarTask {
|
|
||||||
+ private static RamBarTask instance;
|
|
||||||
+ private long allocated = 0L;
|
|
||||||
+ private long used = 0L;
|
|
||||||
+ private long xmx = 0L;
|
|
||||||
+ private long xms = 0L;
|
|
||||||
+ private float percent = 0F;
|
|
||||||
+ private int tick = 0;
|
|
||||||
+
|
|
||||||
+ public static RamBarTask instance() {
|
|
||||||
+ if (instance == null) {
|
|
||||||
+ instance = new RamBarTask();
|
|
||||||
+ }
|
|
||||||
+ return instance;
|
|
||||||
+ }
|
|
||||||
+
|
|
||||||
+ @Override
|
|
||||||
+ BossBar createBossBar() {
|
|
||||||
+ return BossBar.bossBar(Component.text(""), 0.0F, instance().getBossBarColor(), PurpurConfig.commandRamBarProgressOverlay);
|
|
||||||
+ }
|
|
||||||
+
|
|
||||||
+ @Override
|
|
||||||
+ void updateBossBar(BossBar bossbar, Player player) {
|
|
||||||
+ bossbar.progress(getBossBarProgress());
|
|
||||||
+ bossbar.color(getBossBarColor());
|
|
||||||
+ bossbar.name(MiniMessage.miniMessage().deserialize(PurpurConfig.commandRamBarTitle,
|
|
||||||
+ Placeholder.component("allocated", format(this.allocated)),
|
|
||||||
+ Placeholder.component("used", format(this.used)),
|
|
||||||
+ Placeholder.component("xmx", format(this.xmx)),
|
|
||||||
+ Placeholder.component("xms", format(this.xms)),
|
|
||||||
+ Placeholder.unparsed("percent", ((int) (this.percent * 100)) + "%")
|
|
||||||
+ ));
|
|
||||||
+ }
|
|
||||||
+
|
|
||||||
+ @Override
|
|
||||||
+ public void run() {
|
|
||||||
+ if (++this.tick < PurpurConfig.commandRamBarTickInterval) {
|
|
||||||
+ return;
|
|
||||||
+ }
|
|
||||||
+ this.tick = 0;
|
|
||||||
+
|
|
||||||
+ MemoryUsage heap = ManagementFactory.getMemoryMXBean().getHeapMemoryUsage();
|
|
||||||
+
|
|
||||||
+ this.allocated = heap.getCommitted();
|
|
||||||
+ this.used = heap.getUsed();
|
|
||||||
+ this.xmx = heap.getMax();
|
|
||||||
+ this.xms = heap.getInit();
|
|
||||||
+ this.percent = Math.max(Math.min((float) this.used / this.xmx, 1.0F), 0.0F);
|
|
||||||
+
|
|
||||||
+ super.run();
|
|
||||||
+ }
|
|
||||||
+
|
|
||||||
+ private float getBossBarProgress() {
|
|
||||||
+ return this.percent;
|
|
||||||
+ }
|
|
||||||
+
|
|
||||||
+ private BossBar.Color getBossBarColor() {
|
|
||||||
+ if (this.percent < 0.5F) {
|
|
||||||
+ return PurpurConfig.commandRamBarProgressColorGood;
|
|
||||||
+ } else if (this.percent < 0.75F) {
|
|
||||||
+ return PurpurConfig.commandRamBarProgressColorMedium;
|
|
||||||
+ } else {
|
|
||||||
+ return PurpurConfig.commandRamBarProgressColorLow;
|
|
||||||
+ }
|
|
||||||
+ }
|
|
||||||
+
|
|
||||||
+ public Component format(long v) {
|
|
||||||
+ String color;
|
|
||||||
+ if (this.percent < 0.60F) {
|
|
||||||
+ color = PurpurConfig.commandRamBarTextColorGood;
|
|
||||||
+ } else if (this.percent < 0.85F) {
|
|
||||||
+ color = PurpurConfig.commandRamBarTextColorMedium;
|
|
||||||
+ } else {
|
|
||||||
+ color = PurpurConfig.commandRamBarTextColorLow;
|
|
||||||
+ }
|
|
||||||
+ String value;
|
|
||||||
+ if (v < 1024) {
|
|
||||||
+ value = v + "B";
|
|
||||||
+ } else {
|
|
||||||
+ int z = (63 - Long.numberOfLeadingZeros(v)) / 10;
|
|
||||||
+ value = String.format("%.1f%s", (double) v / (1L << (z * 10)), "BKMGTPE".charAt(z));
|
|
||||||
+ }
|
|
||||||
+ return MiniMessage.miniMessage().deserialize(color, Placeholder.unparsed("text", value));
|
|
||||||
+ }
|
|
||||||
+
|
|
||||||
+ public long getAllocated() {
|
|
||||||
+ return this.allocated;
|
|
||||||
+ }
|
|
||||||
+
|
|
||||||
+ public long getUsed() {
|
|
||||||
+ return this.used;
|
|
||||||
+ }
|
|
||||||
+
|
|
||||||
+ public long getXmx() {
|
|
||||||
+ return this.xmx;
|
|
||||||
+ }
|
|
||||||
+
|
|
||||||
+ public long getXms() {
|
|
||||||
+ return this.xms;
|
|
||||||
+ }
|
|
||||||
+
|
|
||||||
+ public float getPercent() {
|
|
||||||
+ return this.percent;
|
|
||||||
+ }
|
|
||||||
+}
|
|
||||||
@@ -8,7 +8,7 @@
|
|||||||
import org.slf4j.Logger;
|
import org.slf4j.Logger;
|
||||||
|
|
||||||
public class Commands {
|
public class Commands {
|
||||||
@@ -245,6 +_,12 @@
|
@@ -245,6 +_,14 @@
|
||||||
StopCommand.register(this.dispatcher);
|
StopCommand.register(this.dispatcher);
|
||||||
TransferCommand.register(this.dispatcher);
|
TransferCommand.register(this.dispatcher);
|
||||||
WhitelistCommand.register(this.dispatcher);
|
WhitelistCommand.register(this.dispatcher);
|
||||||
@@ -18,6 +18,8 @@
|
|||||||
+ org.purpurmc.purpur.command.UptimeCommand.register(this.dispatcher); // Purpur - Add uptime command
|
+ org.purpurmc.purpur.command.UptimeCommand.register(this.dispatcher); // Purpur - Add uptime command
|
||||||
+ org.purpurmc.purpur.command.TPSBarCommand.register(this.dispatcher); // Purpur - Implement TPSBar
|
+ org.purpurmc.purpur.command.TPSBarCommand.register(this.dispatcher); // Purpur - Implement TPSBar
|
||||||
+ org.purpurmc.purpur.command.CompassCommand.register(this.dispatcher); // Purpur - Add compass command
|
+ org.purpurmc.purpur.command.CompassCommand.register(this.dispatcher); // Purpur - Add compass command
|
||||||
|
+ org.purpurmc.purpur.command.RamBarCommand.register(this.dispatcher); // Purpur - Add rambar command
|
||||||
|
+ org.purpurmc.purpur.command.RamCommand.register(this.dispatcher); // Purpur - Add ram command
|
||||||
}
|
}
|
||||||
|
|
||||||
if (selection.includeIntegrated) {
|
if (selection.includeIntegrated) {
|
||||||
|
|||||||
@@ -1,31 +1,34 @@
|
|||||||
--- a/net/minecraft/server/level/ServerPlayer.java
|
--- a/net/minecraft/server/level/ServerPlayer.java
|
||||||
+++ b/net/minecraft/server/level/ServerPlayer.java
|
+++ b/net/minecraft/server/level/ServerPlayer.java
|
||||||
@@ -393,6 +_,9 @@
|
@@ -393,6 +_,10 @@
|
||||||
public com.destroystokyo.paper.event.entity.PlayerNaturallySpawnCreaturesEvent playerNaturallySpawnedEvent; // Paper - PlayerNaturallySpawnCreaturesEvent
|
public com.destroystokyo.paper.event.entity.PlayerNaturallySpawnCreaturesEvent playerNaturallySpawnedEvent; // Paper - PlayerNaturallySpawnCreaturesEvent
|
||||||
public @Nullable String clientBrandName = null; // Paper - Brand support
|
public @Nullable String clientBrandName = null; // Paper - Brand support
|
||||||
public org.bukkit.event.player.PlayerQuitEvent.QuitReason quitReason = null; // Paper - Add API for quit reason; there are a lot of changes to do if we change all methods leading to the event
|
public org.bukkit.event.player.PlayerQuitEvent.QuitReason quitReason = null; // Paper - Add API for quit reason; there are a lot of changes to do if we change all methods leading to the event
|
||||||
+ public boolean purpurClient = false; // Purpur - Purpur client support
|
+ public boolean purpurClient = false; // Purpur - Purpur client support
|
||||||
+ private boolean tpsBar = false; // Purpur - Implement TPSBar
|
+ private boolean tpsBar = false; // Purpur - Implement TPSBar
|
||||||
+ private boolean compassBar = false; // Purpur - Add compass command
|
+ private boolean compassBar = false; // Purpur - Add compass command
|
||||||
|
+ private boolean ramBar = false; // Purpur - Implement rambar commands
|
||||||
|
|
||||||
// Paper start - rewrite chunk system
|
// Paper start - rewrite chunk system
|
||||||
private ca.spottedleaf.moonrise.patches.chunk_system.player.RegionizedPlayerChunkLoader.PlayerChunkLoaderData chunkLoader;
|
private ca.spottedleaf.moonrise.patches.chunk_system.player.RegionizedPlayerChunkLoader.PlayerChunkLoaderData chunkLoader;
|
||||||
@@ -561,6 +_,9 @@
|
@@ -561,6 +_,10 @@
|
||||||
if (tag != null) {
|
if (tag != null) {
|
||||||
BlockPos.CODEC.parse(NbtOps.INSTANCE, tag).resultOrPartial(LOGGER::error).ifPresent(pos -> this.raidOmenPosition = pos);
|
BlockPos.CODEC.parse(NbtOps.INSTANCE, tag).resultOrPartial(LOGGER::error).ifPresent(pos -> this.raidOmenPosition = pos);
|
||||||
}
|
}
|
||||||
+
|
+
|
||||||
+ if (compound.contains("Purpur.TPSBar")) { this.tpsBar = compound.getBoolean("Purpur.TPSBar"); } // Purpur - Implement TPSBar
|
+ if (compound.contains("Purpur.TPSBar")) { this.tpsBar = compound.getBoolean("Purpur.TPSBar"); } // Purpur - Implement TPSBar
|
||||||
+ if (compound.contains("Purpur.CompassBar")) { this.compassBar = compound.getBoolean("Purpur.CompassBar"); } // Purpur - Add compass command
|
+ if (compound.contains("Purpur.CompassBar")) { this.compassBar = compound.getBoolean("Purpur.CompassBar"); } // Purpur - Add compass command
|
||||||
|
+ if (compound.contains("Purpur.RamBar")) { this.ramBar = compound.getBoolean("Purpur.RamBar"); } // Purpur - Implement rambar command
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@@ -605,6 +_,8 @@
|
@@ -605,6 +_,9 @@
|
||||||
}
|
}
|
||||||
|
|
||||||
this.saveEnderPearls(compound);
|
this.saveEnderPearls(compound);
|
||||||
+ compound.putBoolean("Purpur.TPSBar", this.tpsBar); // Purpur - Implement TPSBar
|
+ compound.putBoolean("Purpur.TPSBar", this.tpsBar); // Purpur - Implement TPSBar
|
||||||
+ compound.putBoolean("Purpur.CompassBar", this.compassBar); // Purpur - Add compass command
|
+ compound.putBoolean("Purpur.CompassBar", this.compassBar); // Purpur - Add compass command
|
||||||
|
+ compound.putBoolean("Purpur.CompassBar", this.compassBar); // Purpur - Add rambar command
|
||||||
}
|
}
|
||||||
|
|
||||||
private void saveParentVehicle(CompoundTag tag) {
|
private void saveParentVehicle(CompoundTag tag) {
|
||||||
@@ -214,7 +217,7 @@
|
|||||||
|
|
||||||
public ServerStatsCounter getStats() {
|
public ServerStatsCounter getStats() {
|
||||||
return this.stats;
|
return this.stats;
|
||||||
@@ -3077,4 +_,46 @@
|
@@ -3077,4 +_,56 @@
|
||||||
return (org.bukkit.craftbukkit.entity.CraftPlayer) super.getBukkitEntity();
|
return (org.bukkit.craftbukkit.entity.CraftPlayer) super.getBukkitEntity();
|
||||||
}
|
}
|
||||||
// CraftBukkit end
|
// CraftBukkit end
|
||||||
@@ -260,4 +263,14 @@
|
|||||||
+ this.compassBar = compassBar;
|
+ this.compassBar = compassBar;
|
||||||
+ }
|
+ }
|
||||||
+ // Purpur end - Add compass command
|
+ // Purpur end - Add compass command
|
||||||
|
+
|
||||||
|
+ // Purpur start - Add rambar command
|
||||||
|
+ public boolean ramBar() {
|
||||||
|
+ return this.ramBar;
|
||||||
|
+ }
|
||||||
|
+
|
||||||
|
+ public void ramBar(boolean ramBar) {
|
||||||
|
+ this.ramBar = ramBar;
|
||||||
|
+ }
|
||||||
|
+ // Purpur end - Add rambar command
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -178,6 +178,8 @@ public class PurpurConfig {
|
|||||||
public static String creditsCommandOutput = "<green>%s has been shown the end credits";
|
public static String creditsCommandOutput = "<green>%s has been shown the end credits";
|
||||||
public static String demoCommandOutput = "<green>%s has been shown the demo screen";
|
public static String demoCommandOutput = "<green>%s has been shown the demo screen";
|
||||||
public static String pingCommandOutput = "<green>%s's ping is %sms";
|
public static String pingCommandOutput = "<green>%s's ping is %sms";
|
||||||
|
public static String ramCommandOutput = "<green>Ram Usage: <used>/<xmx> (<percent>)";
|
||||||
|
public static String rambarCommandOutput = "<green>Rambar toggled <onoff> for <target>";
|
||||||
public static String tpsbarCommandOutput = "<green>Tpsbar toggled <onoff> for <target>";
|
public static String tpsbarCommandOutput = "<green>Tpsbar toggled <onoff> for <target>";
|
||||||
public static String dontRunWithScissors = "<red><italic>Don't run with scissors!";
|
public static String dontRunWithScissors = "<red><italic>Don't run with scissors!";
|
||||||
public static String uptimeCommandOutput = "<green>Server uptime is <uptime>";
|
public static String uptimeCommandOutput = "<green>Server uptime is <uptime>";
|
||||||
@@ -195,6 +197,8 @@ public class PurpurConfig {
|
|||||||
creditsCommandOutput = getString("settings.messages.credits-command-output", creditsCommandOutput);
|
creditsCommandOutput = getString("settings.messages.credits-command-output", creditsCommandOutput);
|
||||||
demoCommandOutput = getString("settings.messages.demo-command-output", demoCommandOutput);
|
demoCommandOutput = getString("settings.messages.demo-command-output", demoCommandOutput);
|
||||||
pingCommandOutput = getString("settings.messages.ping-command-output", pingCommandOutput);
|
pingCommandOutput = getString("settings.messages.ping-command-output", pingCommandOutput);
|
||||||
|
ramCommandOutput = getString("settings.messages.ram-command-output", ramCommandOutput);
|
||||||
|
rambarCommandOutput = getString("settings.messages.rambar-command-output", rambarCommandOutput);
|
||||||
tpsbarCommandOutput = getString("settings.messages.tpsbar-command-output", tpsbarCommandOutput);
|
tpsbarCommandOutput = getString("settings.messages.tpsbar-command-output", tpsbarCommandOutput);
|
||||||
dontRunWithScissors = getString("settings.messages.dont-run-with-scissors", dontRunWithScissors);
|
dontRunWithScissors = getString("settings.messages.dont-run-with-scissors", dontRunWithScissors);
|
||||||
uptimeCommandOutput = getString("settings.messages.uptime-command-output", uptimeCommandOutput);
|
uptimeCommandOutput = getString("settings.messages.uptime-command-output", uptimeCommandOutput);
|
||||||
@@ -243,6 +247,15 @@ public class PurpurConfig {
|
|||||||
disableGiveCommandDrops = getBoolean("settings.disable-give-dropping", disableGiveCommandDrops);
|
disableGiveCommandDrops = getBoolean("settings.disable-give-dropping", disableGiveCommandDrops);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public static String commandRamBarTitle = "<gray>Ram<yellow>:</yellow> <used>/<xmx> (<percent>)";
|
||||||
|
public static BossBar.Overlay commandRamBarProgressOverlay = BossBar.Overlay.NOTCHED_20;
|
||||||
|
public static BossBar.Color commandRamBarProgressColorGood = BossBar.Color.GREEN;
|
||||||
|
public static BossBar.Color commandRamBarProgressColorMedium = BossBar.Color.YELLOW;
|
||||||
|
public static BossBar.Color commandRamBarProgressColorLow = BossBar.Color.RED;
|
||||||
|
public static String commandRamBarTextColorGood = "<gradient:#55ff55:#00aa00><text></gradient>";
|
||||||
|
public static String commandRamBarTextColorMedium = "<gradient:#ffff55:#ffaa00><text></gradient>";
|
||||||
|
public static String commandRamBarTextColorLow = "<gradient:#ff5555:#aa0000><text></gradient>";
|
||||||
|
public static int commandRamBarTickInterval = 20;
|
||||||
public static String commandTPSBarTitle = "<gray>TPS<yellow>:</yellow> <tps> MSPT<yellow>:</yellow> <mspt> Ping<yellow>:</yellow> <ping>ms";
|
public static String commandTPSBarTitle = "<gray>TPS<yellow>:</yellow> <tps> MSPT<yellow>:</yellow> <mspt> Ping<yellow>:</yellow> <ping>ms";
|
||||||
public static BossBar.Overlay commandTPSBarProgressOverlay = BossBar.Overlay.NOTCHED_20;
|
public static BossBar.Overlay commandTPSBarProgressOverlay = BossBar.Overlay.NOTCHED_20;
|
||||||
public static TPSBarTask.FillMode commandTPSBarProgressFillMode = TPSBarTask.FillMode.MSPT;
|
public static TPSBarTask.FillMode commandTPSBarProgressFillMode = TPSBarTask.FillMode.MSPT;
|
||||||
@@ -270,6 +283,16 @@ public class PurpurConfig {
|
|||||||
public static String uptimeSecond = "%02d second";
|
public static String uptimeSecond = "%02d second";
|
||||||
public static String uptimeSeconds = "%02d seconds";
|
public static String uptimeSeconds = "%02d seconds";
|
||||||
private static void commandSettings() {
|
private static void commandSettings() {
|
||||||
|
commandRamBarTitle = getString("settings.command.rambar.title", commandRamBarTitle);
|
||||||
|
commandRamBarProgressOverlay = BossBar.Overlay.valueOf(getString("settings.command.rambar.overlay", commandRamBarProgressOverlay.name()));
|
||||||
|
commandRamBarProgressColorGood = BossBar.Color.valueOf(getString("settings.command.rambar.progress-color.good", commandRamBarProgressColorGood.name()));
|
||||||
|
commandRamBarProgressColorMedium = BossBar.Color.valueOf(getString("settings.command.rambar.progress-color.medium", commandRamBarProgressColorMedium.name()));
|
||||||
|
commandRamBarProgressColorLow = BossBar.Color.valueOf(getString("settings.command.rambar.progress-color.low", commandRamBarProgressColorLow.name()));
|
||||||
|
commandRamBarTextColorGood = getString("settings.command.rambar.text-color.good", commandRamBarTextColorGood);
|
||||||
|
commandRamBarTextColorMedium = getString("settings.command.rambar.text-color.medium", commandRamBarTextColorMedium);
|
||||||
|
commandRamBarTextColorLow = getString("settings.command.rambar.text-color.low", commandRamBarTextColorLow);
|
||||||
|
commandRamBarTickInterval = getInt("settings.command.rambar.tick-interval", commandRamBarTickInterval);
|
||||||
|
|
||||||
commandTPSBarTitle = getString("settings.command.tpsbar.title", commandTPSBarTitle);
|
commandTPSBarTitle = getString("settings.command.tpsbar.title", commandTPSBarTitle);
|
||||||
commandTPSBarProgressOverlay = BossBar.Overlay.valueOf(getString("settings.command.tpsbar.overlay", commandTPSBarProgressOverlay.name()));
|
commandTPSBarProgressOverlay = BossBar.Overlay.valueOf(getString("settings.command.tpsbar.overlay", commandTPSBarProgressOverlay.name()));
|
||||||
commandTPSBarProgressFillMode = TPSBarTask.FillMode.valueOf(getString("settings.command.tpsbar.fill-mode", commandTPSBarProgressFillMode.name()));
|
commandTPSBarProgressFillMode = TPSBarTask.FillMode.valueOf(getString("settings.command.tpsbar.fill-mode", commandTPSBarProgressFillMode.name()));
|
||||||
|
|||||||
@@ -0,0 +1,44 @@
|
|||||||
|
package org.purpurmc.purpur.command;
|
||||||
|
|
||||||
|
import com.mojang.brigadier.CommandDispatcher;
|
||||||
|
import net.kyori.adventure.text.Component;
|
||||||
|
import net.kyori.adventure.text.format.NamedTextColor;
|
||||||
|
import net.kyori.adventure.text.minimessage.MiniMessage;
|
||||||
|
import net.kyori.adventure.text.minimessage.tag.resolver.Placeholder;
|
||||||
|
import net.minecraft.commands.CommandSourceStack;
|
||||||
|
import net.minecraft.commands.Commands;
|
||||||
|
import net.minecraft.commands.arguments.EntityArgument;
|
||||||
|
import net.minecraft.server.level.ServerPlayer;
|
||||||
|
import org.purpurmc.purpur.PurpurConfig;
|
||||||
|
import org.purpurmc.purpur.task.RamBarTask;
|
||||||
|
|
||||||
|
import java.util.Collection;
|
||||||
|
import java.util.Collections;
|
||||||
|
|
||||||
|
public class RamBarCommand {
|
||||||
|
public static void register(CommandDispatcher<CommandSourceStack> dispatcher) {
|
||||||
|
dispatcher.register(Commands.literal("rambar")
|
||||||
|
.requires(listener -> listener.hasPermission(2, "bukkit.command.rambar"))
|
||||||
|
.executes(context -> execute(context.getSource(), Collections.singleton(context.getSource().getPlayerOrException())))
|
||||||
|
.then(Commands.argument("targets", EntityArgument.players())
|
||||||
|
.requires(listener -> listener.hasPermission(2, "bukkit.command.rambar.other"))
|
||||||
|
.executes((context) -> execute(context.getSource(), EntityArgument.getPlayers(context, "targets")))
|
||||||
|
)
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
private static int execute(CommandSourceStack sender, Collection<ServerPlayer> targets) {
|
||||||
|
for (ServerPlayer player : targets) {
|
||||||
|
boolean result = RamBarTask.instance().togglePlayer(player.getBukkitEntity());
|
||||||
|
player.ramBar(result);
|
||||||
|
|
||||||
|
Component output = MiniMessage.miniMessage().deserialize(PurpurConfig.rambarCommandOutput,
|
||||||
|
Placeholder.component("onoff", Component.translatable(result ? "options.on" : "options.off")
|
||||||
|
.color(result ? NamedTextColor.GREEN : NamedTextColor.RED)),
|
||||||
|
Placeholder.parsed("target", player.getGameProfile().getName()));
|
||||||
|
|
||||||
|
sender.sendSuccess(output, false);
|
||||||
|
}
|
||||||
|
return targets.size();
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,30 @@
|
|||||||
|
package org.purpurmc.purpur.command;
|
||||||
|
|
||||||
|
import com.mojang.brigadier.CommandDispatcher;
|
||||||
|
import io.papermc.paper.adventure.PaperAdventure;
|
||||||
|
import net.kyori.adventure.text.minimessage.MiniMessage;
|
||||||
|
import net.kyori.adventure.text.minimessage.tag.resolver.Placeholder;
|
||||||
|
import net.minecraft.commands.CommandSourceStack;
|
||||||
|
import net.minecraft.commands.Commands;
|
||||||
|
import org.purpurmc.purpur.PurpurConfig;
|
||||||
|
import org.purpurmc.purpur.task.RamBarTask;
|
||||||
|
|
||||||
|
public class RamCommand {
|
||||||
|
public static void register(CommandDispatcher<CommandSourceStack> dispatcher) {
|
||||||
|
dispatcher.register(Commands.literal("ram")
|
||||||
|
.requires(listener -> listener.hasPermission(2, "bukkit.command.ram"))
|
||||||
|
.executes(context -> {
|
||||||
|
CommandSourceStack sender = context.getSource();
|
||||||
|
RamBarTask ramBar = RamBarTask.instance();
|
||||||
|
sender.sendSuccess(() -> PaperAdventure.asVanilla(MiniMessage.miniMessage().deserialize(PurpurConfig.ramCommandOutput,
|
||||||
|
Placeholder.component("allocated", ramBar.format(ramBar.getAllocated())),
|
||||||
|
Placeholder.component("used", ramBar.format(ramBar.getUsed())),
|
||||||
|
Placeholder.component("xmx", ramBar.format(ramBar.getXmx())),
|
||||||
|
Placeholder.component("xms", ramBar.format(ramBar.getXms())),
|
||||||
|
Placeholder.unparsed("percent", ((int) (ramBar.getPercent() * 100)) + "%")
|
||||||
|
)), false);
|
||||||
|
return 1;
|
||||||
|
})
|
||||||
|
);
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -89,17 +89,22 @@ public abstract class BossBarTask extends BukkitRunnable {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public static void startAll() {
|
public static void startAll() {
|
||||||
|
RamBarTask.instance().start();
|
||||||
TPSBarTask.instance().start();
|
TPSBarTask.instance().start();
|
||||||
CompassTask.instance().start();
|
CompassTask.instance().start();
|
||||||
}
|
}
|
||||||
|
|
||||||
public static void stopAll() {
|
public static void stopAll() {
|
||||||
|
RamBarTask.instance().stop();
|
||||||
TPSBarTask.instance().stop();
|
TPSBarTask.instance().stop();
|
||||||
CompassTask.instance().stop();
|
CompassTask.instance().stop();
|
||||||
}
|
}
|
||||||
|
|
||||||
public static void addToAll(ServerPlayer player) {
|
public static void addToAll(ServerPlayer player) {
|
||||||
Player bukkit = player.getBukkitEntity();
|
Player bukkit = player.getBukkitEntity();
|
||||||
|
if (player.ramBar()) {
|
||||||
|
RamBarTask.instance().addPlayer(bukkit);
|
||||||
|
}
|
||||||
if (player.tpsBar()) {
|
if (player.tpsBar()) {
|
||||||
TPSBarTask.instance().addPlayer(bukkit);
|
TPSBarTask.instance().addPlayer(bukkit);
|
||||||
}
|
}
|
||||||
@@ -109,6 +114,7 @@ public abstract class BossBarTask extends BukkitRunnable {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public static void removeFromAll(Player player) {
|
public static void removeFromAll(Player player) {
|
||||||
|
RamBarTask.instance().removePlayer(player);
|
||||||
TPSBarTask.instance().removePlayer(player);
|
TPSBarTask.instance().removePlayer(player);
|
||||||
CompassTask.instance().removePlayer(player);
|
CompassTask.instance().removePlayer(player);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -0,0 +1,117 @@
|
|||||||
|
package org.purpurmc.purpur.task;
|
||||||
|
|
||||||
|
import net.kyori.adventure.bossbar.BossBar;
|
||||||
|
import net.kyori.adventure.text.Component;
|
||||||
|
import net.kyori.adventure.text.minimessage.MiniMessage;
|
||||||
|
import net.kyori.adventure.text.minimessage.tag.resolver.Placeholder;
|
||||||
|
import org.bukkit.entity.Player;
|
||||||
|
import org.purpurmc.purpur.PurpurConfig;
|
||||||
|
|
||||||
|
import java.lang.management.ManagementFactory;
|
||||||
|
import java.lang.management.MemoryUsage;
|
||||||
|
|
||||||
|
public class RamBarTask extends BossBarTask {
|
||||||
|
private static RamBarTask instance;
|
||||||
|
private long allocated = 0L;
|
||||||
|
private long used = 0L;
|
||||||
|
private long xmx = 0L;
|
||||||
|
private long xms = 0L;
|
||||||
|
private float percent = 0F;
|
||||||
|
private int tick = 0;
|
||||||
|
|
||||||
|
public static RamBarTask instance() {
|
||||||
|
if (instance == null) {
|
||||||
|
instance = new RamBarTask();
|
||||||
|
}
|
||||||
|
return instance;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
BossBar createBossBar() {
|
||||||
|
return BossBar.bossBar(Component.text(""), 0.0F, instance().getBossBarColor(), PurpurConfig.commandRamBarProgressOverlay);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
void updateBossBar(BossBar bossbar, Player player) {
|
||||||
|
bossbar.progress(getBossBarProgress());
|
||||||
|
bossbar.color(getBossBarColor());
|
||||||
|
bossbar.name(MiniMessage.miniMessage().deserialize(PurpurConfig.commandRamBarTitle,
|
||||||
|
Placeholder.component("allocated", format(this.allocated)),
|
||||||
|
Placeholder.component("used", format(this.used)),
|
||||||
|
Placeholder.component("xmx", format(this.xmx)),
|
||||||
|
Placeholder.component("xms", format(this.xms)),
|
||||||
|
Placeholder.unparsed("percent", ((int) (this.percent * 100)) + "%")
|
||||||
|
));
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void run() {
|
||||||
|
if (++this.tick < PurpurConfig.commandRamBarTickInterval) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
this.tick = 0;
|
||||||
|
|
||||||
|
MemoryUsage heap = ManagementFactory.getMemoryMXBean().getHeapMemoryUsage();
|
||||||
|
|
||||||
|
this.allocated = heap.getCommitted();
|
||||||
|
this.used = heap.getUsed();
|
||||||
|
this.xmx = heap.getMax();
|
||||||
|
this.xms = heap.getInit();
|
||||||
|
this.percent = Math.max(Math.min((float) this.used / this.xmx, 1.0F), 0.0F);
|
||||||
|
|
||||||
|
super.run();
|
||||||
|
}
|
||||||
|
|
||||||
|
private float getBossBarProgress() {
|
||||||
|
return this.percent;
|
||||||
|
}
|
||||||
|
|
||||||
|
private BossBar.Color getBossBarColor() {
|
||||||
|
if (this.percent < 0.5F) {
|
||||||
|
return PurpurConfig.commandRamBarProgressColorGood;
|
||||||
|
} else if (this.percent < 0.75F) {
|
||||||
|
return PurpurConfig.commandRamBarProgressColorMedium;
|
||||||
|
} else {
|
||||||
|
return PurpurConfig.commandRamBarProgressColorLow;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public Component format(long v) {
|
||||||
|
String color;
|
||||||
|
if (this.percent < 0.60F) {
|
||||||
|
color = PurpurConfig.commandRamBarTextColorGood;
|
||||||
|
} else if (this.percent < 0.85F) {
|
||||||
|
color = PurpurConfig.commandRamBarTextColorMedium;
|
||||||
|
} else {
|
||||||
|
color = PurpurConfig.commandRamBarTextColorLow;
|
||||||
|
}
|
||||||
|
String value;
|
||||||
|
if (v < 1024) {
|
||||||
|
value = v + "B";
|
||||||
|
} else {
|
||||||
|
int z = (63 - Long.numberOfLeadingZeros(v)) / 10;
|
||||||
|
value = String.format("%.1f%s", (double) v / (1L << (z * 10)), "BKMGTPE".charAt(z));
|
||||||
|
}
|
||||||
|
return MiniMessage.miniMessage().deserialize(color, Placeholder.unparsed("text", value));
|
||||||
|
}
|
||||||
|
|
||||||
|
public long getAllocated() {
|
||||||
|
return this.allocated;
|
||||||
|
}
|
||||||
|
|
||||||
|
public long getUsed() {
|
||||||
|
return this.used;
|
||||||
|
}
|
||||||
|
|
||||||
|
public long getXmx() {
|
||||||
|
return this.xmx;
|
||||||
|
}
|
||||||
|
|
||||||
|
public long getXms() {
|
||||||
|
return this.xms;
|
||||||
|
}
|
||||||
|
|
||||||
|
public float getPercent() {
|
||||||
|
return this.percent;
|
||||||
|
}
|
||||||
|
}
|
||||||
Reference in New Issue
Block a user