mirror of
https://github.com/PurpurMC/Purpur.git
synced 2026-02-18 17:07:43 +01:00
Add compass command
This commit is contained in:
@@ -17,26 +17,26 @@ index a5712108fbbe5ddc61cdfd390f667ab013ba609d..73953ea69776bfe1dcb1504cd14a0f00
|
||||
|
||||
if (environment.includeIntegrated) {
|
||||
diff --git a/src/main/java/net/minecraft/server/MinecraftServer.java b/src/main/java/net/minecraft/server/MinecraftServer.java
|
||||
index 214b25f57f15e2127b92ec88117c36d4b2096477..652e596c37bf8d865c954b31ad7d2562b9e95c46 100644
|
||||
index 214b25f57f15e2127b92ec88117c36d4b2096477..fbb0840010443facb66b8e538c4fde035704896e 100644
|
||||
--- a/src/main/java/net/minecraft/server/MinecraftServer.java
|
||||
+++ b/src/main/java/net/minecraft/server/MinecraftServer.java
|
||||
@@ -1119,6 +1119,7 @@ public abstract class MinecraftServer extends ReentrantBlockableEventLoop<TickTa
|
||||
this.safeShutdown(flag, false);
|
||||
}
|
||||
public void safeShutdown(boolean flag, boolean isRestarting) {
|
||||
+ net.pl3x.purpur.task.TPSBarTask.stop(); // Purpur
|
||||
+ net.pl3x.purpur.task.BossBarTask.stopAll(); // Purpur
|
||||
this.isRestarting = isRestarting;
|
||||
this.hasLoggedStop = true; // Paper
|
||||
if (isDebugging()) io.papermc.paper.util.TraceUtil.dumpTraceForThread("Server stopped"); // Paper
|
||||
diff --git a/src/main/java/net/minecraft/server/dedicated/DedicatedServer.java b/src/main/java/net/minecraft/server/dedicated/DedicatedServer.java
|
||||
index fc6a6e88486c5c2dca1b10bfeae24124690d7b8d..4a3226b58ee3c11830dabba988b0665dc069559a 100644
|
||||
index fc6a6e88486c5c2dca1b10bfeae24124690d7b8d..7b66b301b10158e9c715834b24bdfab1610f4a94 100644
|
||||
--- a/src/main/java/net/minecraft/server/dedicated/DedicatedServer.java
|
||||
+++ b/src/main/java/net/minecraft/server/dedicated/DedicatedServer.java
|
||||
@@ -349,6 +349,8 @@ public class DedicatedServer extends MinecraftServer implements ServerInterface
|
||||
DedicatedServer.LOGGER.info("JMX monitoring enabled");
|
||||
}
|
||||
|
||||
+ net.pl3x.purpur.task.TPSBarTask.start(); // Purpur
|
||||
+ net.pl3x.purpur.task.BossBarTask.startAll(); // Purpur
|
||||
+
|
||||
return true;
|
||||
}
|
||||
@@ -84,14 +84,14 @@ index b520d4980180462628ede1383ee1826bbd6a6ad2..21696b7a35cabca1c470304573c01557
|
||||
// Purpur end
|
||||
}
|
||||
diff --git a/src/main/java/net/minecraft/server/players/PlayerList.java b/src/main/java/net/minecraft/server/players/PlayerList.java
|
||||
index 29043f9354b29f7766f1d6d8e793e2ea23883fa0..54db0206bbeea62525ada78b0f9cd99b4f9fddff 100644
|
||||
index 29043f9354b29f7766f1d6d8e793e2ea23883fa0..9a0065bd8eeb758daeb49d82ba8f2c09a6e4f533 100644
|
||||
--- a/src/main/java/net/minecraft/server/players/PlayerList.java
|
||||
+++ b/src/main/java/net/minecraft/server/players/PlayerList.java
|
||||
@@ -483,6 +483,7 @@ public abstract class PlayerList {
|
||||
scoreboard.addPlayerToTeam(player.getScoreboardName(), collideRuleTeam);
|
||||
}
|
||||
// Paper end
|
||||
+ if (player.tpsBar()) net.pl3x.purpur.task.TPSBarTask.addPlayer(player.getBukkitEntity()); // Purpur
|
||||
+ net.pl3x.purpur.task.BossBarTask.addToAll(player); // Purpur
|
||||
// CraftBukkit - Moved from above, added world
|
||||
PlayerList.LOGGER.info("{}[{}] logged in with entity id {} at ([{}]{}, {}, {})", player.getName().getString(), s1, player.getId(), worldserver1.serverLevelData.getLevelName(), player.getX(), player.getY(), player.getZ());
|
||||
}
|
||||
@@ -99,7 +99,7 @@ index 29043f9354b29f7766f1d6d8e793e2ea23883fa0..54db0206bbeea62525ada78b0f9cd99b
|
||||
}
|
||||
public net.kyori.adventure.text.Component disconnect(ServerPlayer entityplayer, net.kyori.adventure.text.Component leaveMessage) {
|
||||
// Paper end
|
||||
+ net.pl3x.purpur.task.TPSBarTask.removePlayer(entityplayer.getBukkitEntity()); // Purpur
|
||||
+ net.pl3x.purpur.task.BossBarTask.removeFromAll(entityplayer.getBukkitEntity()); // Purpur
|
||||
+
|
||||
ServerLevel worldserver = entityplayer.getLevel();
|
||||
|
||||
@@ -140,10 +140,10 @@ index e1701ab4bd6eccb9a525fa3eb8b35a1bf6f7ffcd..7ed1d5b2aab3442f80532c62a398353e
|
||||
public static boolean enderChestPermissionRows = false;
|
||||
diff --git a/src/main/java/net/pl3x/purpur/command/TPSBarCommand.java b/src/main/java/net/pl3x/purpur/command/TPSBarCommand.java
|
||||
new file mode 100644
|
||||
index 0000000000000000000000000000000000000000..5ed9d779fbdd9da1010f5f31ceec6b46496a21bb
|
||||
index 0000000000000000000000000000000000000000..2eca7b78907007be9683d87bf2346c87816ec3f0
|
||||
--- /dev/null
|
||||
+++ b/src/main/java/net/pl3x/purpur/command/TPSBarCommand.java
|
||||
@@ -0,0 +1,25 @@
|
||||
@@ -0,0 +1,21 @@
|
||||
+package net.pl3x.purpur.command;
|
||||
+
|
||||
+import com.mojang.brigadier.CommandDispatcher;
|
||||
@@ -156,32 +156,25 @@ index 0000000000000000000000000000000000000000..5ed9d779fbdd9da1010f5f31ceec6b46
|
||||
+ public static void register(CommandDispatcher<CommandSourceStack> dispatcher) {
|
||||
+ dispatcher.register(Commands.literal("tpsbar")
|
||||
+ .requires(listener -> listener.hasPermission(2))
|
||||
+ .executes(context -> execute(context.getSource(), context.getSource().getPlayerOrException()))
|
||||
+ .executes(context -> {
|
||||
+ ServerPlayer player = context.getSource().getPlayerOrException();
|
||||
+ boolean result = TPSBarTask.instance().togglePlayer(player.getBukkitEntity());
|
||||
+ player.tpsBar(result);
|
||||
+ return 1;
|
||||
+ })
|
||||
+ ).setPermission("bukkit.command.tpsbar");
|
||||
+ }
|
||||
+
|
||||
+ private static int execute(CommandSourceStack source, ServerPlayer player) {
|
||||
+ if (player != null) {
|
||||
+ boolean result = TPSBarTask.togglePlayer(player.getBukkitEntity());
|
||||
+ player.tpsBar(result);
|
||||
+ return 1;
|
||||
+ }
|
||||
+ return 0;
|
||||
+ }
|
||||
+}
|
||||
diff --git a/src/main/java/net/pl3x/purpur/task/TPSBarTask.java b/src/main/java/net/pl3x/purpur/task/TPSBarTask.java
|
||||
diff --git a/src/main/java/net/pl3x/purpur/task/BossBarTask.java b/src/main/java/net/pl3x/purpur/task/BossBarTask.java
|
||||
new file mode 100644
|
||||
index 0000000000000000000000000000000000000000..b81a0e3b54d2e2261069dc282aea412ab0840eec
|
||||
index 0000000000000000000000000000000000000000..1f55902eb8367b4d980a66f23ac2b57709ae78cf
|
||||
--- /dev/null
|
||||
+++ b/src/main/java/net/pl3x/purpur/task/TPSBarTask.java
|
||||
@@ -0,0 +1,202 @@
|
||||
+++ b/src/main/java/net/pl3x/purpur/task/BossBarTask.java
|
||||
@@ -0,0 +1,105 @@
|
||||
+package net.pl3x.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.Template;
|
||||
+import net.pl3x.purpur.PurpurConfig;
|
||||
+import net.minecraft.server.level.ServerPlayer;
|
||||
+import org.bukkit.Bukkit;
|
||||
+import org.bukkit.craftbukkit.scheduler.MinecraftInternalPlugin;
|
||||
+import org.bukkit.entity.Player;
|
||||
@@ -193,30 +186,16 @@ index 0000000000000000000000000000000000000000..b81a0e3b54d2e2261069dc282aea412a
|
||||
+import java.util.Map;
|
||||
+import java.util.UUID;
|
||||
+
|
||||
+public class TPSBarTask extends BukkitRunnable {
|
||||
+ private static TPSBarTask instance;
|
||||
+public abstract class BossBarTask extends BukkitRunnable {
|
||||
+ private final Map<UUID, BossBar> bossbars = new HashMap<>();
|
||||
+ private double tps = 20.0D;
|
||||
+ private double mspt = 0.0D;
|
||||
+ private int tick = 0;
|
||||
+ private boolean started;
|
||||
+
|
||||
+ private static TPSBarTask instance() {
|
||||
+ if (instance == null) {
|
||||
+ instance = new TPSBarTask();
|
||||
+ }
|
||||
+ return instance;
|
||||
+ }
|
||||
+ abstract BossBar createBossBar();
|
||||
+
|
||||
+ abstract void updateBossBar(BossBar bossbar, Player player);
|
||||
+
|
||||
+ @Override
|
||||
+ public void run() {
|
||||
+ if (++tick < PurpurConfig.commandTPSBarTickInterval) {
|
||||
+ return;
|
||||
+ }
|
||||
+ tick = 0;
|
||||
+
|
||||
+ this.tps = Math.max(Math.min(Bukkit.getTPS()[0], 20.0D), 0.0D);
|
||||
+ this.mspt = Bukkit.getAverageTickTime();
|
||||
+
|
||||
+ Iterator<Map.Entry<UUID, BossBar>> iter = bossbars.entrySet().iterator();
|
||||
+ while (iter.hasNext()) {
|
||||
+ Map.Entry<UUID, BossBar> entry = iter.next();
|
||||
@@ -229,7 +208,110 @@ index 0000000000000000000000000000000000000000..b81a0e3b54d2e2261069dc282aea412a
|
||||
+ }
|
||||
+ }
|
||||
+
|
||||
+ private void updateBossBar(BossBar bossbar, Player player) {
|
||||
+ @Override
|
||||
+ public void cancel() {
|
||||
+ super.cancel();
|
||||
+ new HashSet<>(this.bossbars.keySet()).forEach(uuid -> {
|
||||
+ Player player = Bukkit.getPlayer(uuid);
|
||||
+ if (player != null) {
|
||||
+ removePlayer(player);
|
||||
+ }
|
||||
+ });
|
||||
+ this.bossbars.clear();
|
||||
+ }
|
||||
+
|
||||
+ public boolean removePlayer(Player player) {
|
||||
+ BossBar bossbar = this.bossbars.remove(player.getUniqueId());
|
||||
+ if (bossbar != null) {
|
||||
+ player.hideBossBar(bossbar);
|
||||
+ return true;
|
||||
+ }
|
||||
+ return false;
|
||||
+ }
|
||||
+
|
||||
+ public void addPlayer(Player player) {
|
||||
+ removePlayer(player);
|
||||
+ BossBar bossbar = createBossBar();
|
||||
+ this.bossbars.put(player.getUniqueId(), bossbar);
|
||||
+ this.updateBossBar(bossbar, player);
|
||||
+ player.showBossBar(bossbar);
|
||||
+ }
|
||||
+
|
||||
+ public boolean togglePlayer(Player player) {
|
||||
+ if (removePlayer(player)) {
|
||||
+ return false;
|
||||
+ }
|
||||
+ addPlayer(player);
|
||||
+ return true;
|
||||
+ }
|
||||
+
|
||||
+ public void start() {
|
||||
+ stop();
|
||||
+ this.runTaskTimerAsynchronously(new MinecraftInternalPlugin(), 1, 1);
|
||||
+ started = true;
|
||||
+ }
|
||||
+
|
||||
+ public void stop() {
|
||||
+ if (started) {
|
||||
+ cancel();
|
||||
+ }
|
||||
+ }
|
||||
+
|
||||
+ public static void startAll() {
|
||||
+ TPSBarTask.instance().start();
|
||||
+ }
|
||||
+
|
||||
+ public static void stopAll() {
|
||||
+ TPSBarTask.instance().stop();
|
||||
+ }
|
||||
+
|
||||
+ public static void addToAll(ServerPlayer player) {
|
||||
+ Player bukkit = player.getBukkitEntity();
|
||||
+ if (player.tpsBar()) {
|
||||
+ TPSBarTask.instance().addPlayer(bukkit);
|
||||
+ }
|
||||
+ }
|
||||
+
|
||||
+ public static void removeFromAll(Player player) {
|
||||
+ TPSBarTask.instance().removePlayer(player);
|
||||
+ }
|
||||
+}
|
||||
diff --git a/src/main/java/net/pl3x/purpur/task/TPSBarTask.java b/src/main/java/net/pl3x/purpur/task/TPSBarTask.java
|
||||
new file mode 100644
|
||||
index 0000000000000000000000000000000000000000..cafb140ff57e5697d7c3705ff9be6411c0ad82d9
|
||||
--- /dev/null
|
||||
+++ b/src/main/java/net/pl3x/purpur/task/TPSBarTask.java
|
||||
@@ -0,0 +1,142 @@
|
||||
+package net.pl3x.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.Template;
|
||||
+import net.pl3x.purpur.PurpurConfig;
|
||||
+import org.bukkit.Bukkit;
|
||||
+import org.bukkit.entity.Player;
|
||||
+
|
||||
+public class TPSBarTask extends BossBarTask {
|
||||
+ private static TPSBarTask instance;
|
||||
+ private double tps = 20.0D;
|
||||
+ private double mspt = 0.0D;
|
||||
+ private int tick = 0;
|
||||
+
|
||||
+ public static TPSBarTask instance() {
|
||||
+ if (instance == null) {
|
||||
+ instance = new TPSBarTask();
|
||||
+ }
|
||||
+ return instance;
|
||||
+ }
|
||||
+
|
||||
+ @Override
|
||||
+ BossBar createBossBar() {
|
||||
+ return BossBar.bossBar(Component.text(""), 0.0F, instance().getBossBarColor(), PurpurConfig.commandTPSBarProgressOverlay);
|
||||
+ }
|
||||
+
|
||||
+ @Override
|
||||
+ void updateBossBar(BossBar bossbar, Player player) {
|
||||
+ bossbar.progress(getBossBarProgress());
|
||||
+ bossbar.color(getBossBarColor());
|
||||
+ bossbar.name(MiniMessage.get().parse(PurpurConfig.commandTPSBarTitle,
|
||||
@@ -239,6 +321,19 @@ index 0000000000000000000000000000000000000000..b81a0e3b54d2e2261069dc282aea412a
|
||||
+ ));
|
||||
+ }
|
||||
+
|
||||
+ @Override
|
||||
+ public void run() {
|
||||
+ if (++tick < PurpurConfig.commandTPSBarTickInterval) {
|
||||
+ return;
|
||||
+ }
|
||||
+ tick = 0;
|
||||
+
|
||||
+ this.tps = Math.max(Math.min(Bukkit.getTPS()[0], 20.0D), 0.0D);
|
||||
+ this.mspt = Bukkit.getAverageTickTime();
|
||||
+
|
||||
+ super.run();
|
||||
+ }
|
||||
+
|
||||
+ private float getBossBarProgress() {
|
||||
+ if (PurpurConfig.commandTPSBarProgressFillMode == FillMode.MSPT) {
|
||||
+ return Math.max(Math.min((float) mspt / 50.0F, 1.0F), 0.0F);
|
||||
@@ -325,54 +420,6 @@ index 0000000000000000000000000000000000000000..b81a0e3b54d2e2261069dc282aea412a
|
||||
+ return MiniMessage.get().parse(color, Template.of("text", String.format("%s", ping)));
|
||||
+ }
|
||||
+
|
||||
+ @Override
|
||||
+ public void cancel() {
|
||||
+ super.cancel();
|
||||
+ new HashSet<>(this.bossbars.keySet()).forEach(uuid -> {
|
||||
+ Player player = Bukkit.getPlayer(uuid);
|
||||
+ if (player != null) {
|
||||
+ removePlayer(player);
|
||||
+ }
|
||||
+ });
|
||||
+ this.bossbars.clear();
|
||||
+ }
|
||||
+
|
||||
+ public static boolean removePlayer(Player player) {
|
||||
+ BossBar bossbar = instance().bossbars.remove(player.getUniqueId());
|
||||
+ if (bossbar != null) {
|
||||
+ player.hideBossBar(bossbar);
|
||||
+ return true;
|
||||
+ }
|
||||
+ return false;
|
||||
+ }
|
||||
+
|
||||
+ public static void addPlayer(Player player) {
|
||||
+ removePlayer(player);
|
||||
+ BossBar bossbar = BossBar.bossBar(Component.text(""), 0.0F, instance().getBossBarColor(), PurpurConfig.commandTPSBarProgressOverlay);
|
||||
+ instance().bossbars.put(player.getUniqueId(), bossbar);
|
||||
+ instance().updateBossBar(bossbar, player);
|
||||
+ player.showBossBar(bossbar);
|
||||
+ }
|
||||
+
|
||||
+ public static boolean togglePlayer(Player player) {
|
||||
+ if (removePlayer(player)) {
|
||||
+ return false;
|
||||
+ }
|
||||
+ addPlayer(player);
|
||||
+ return true;
|
||||
+ }
|
||||
+
|
||||
+ public static void start() {
|
||||
+ stop();
|
||||
+ instance().runTaskTimerAsynchronously(new MinecraftInternalPlugin(), 1, 1);
|
||||
+ }
|
||||
+
|
||||
+ public static void stop() {
|
||||
+ if (instance != null) {
|
||||
+ instance.cancel();
|
||||
+ }
|
||||
+ }
|
||||
+
|
||||
+ public enum FillMode {
|
||||
+ TPS, MSPT, PING
|
||||
+ }
|
||||
|
||||
Reference in New Issue
Block a user