mirror of
https://github.com/PurpurMC/Purpur.git
synced 2026-02-19 17:37:42 +01:00
More TPSBar upgrades
This commit is contained in:
@@ -41,11 +41,61 @@ index 1b8d836607d52c3bc67ad5f2accbc94663637d49..606d5577f121b0103e272bbe4ffa4b58
|
||||
return true;
|
||||
}
|
||||
}
|
||||
diff --git a/src/main/java/net/minecraft/server/level/ServerPlayer.java b/src/main/java/net/minecraft/server/level/ServerPlayer.java
|
||||
index b52cea07a77bd5124881e144483e148cbf5ad54d..d20ccfd3aa974fe84eb675dc040c7e25dbb25920 100644
|
||||
--- a/src/main/java/net/minecraft/server/level/ServerPlayer.java
|
||||
+++ b/src/main/java/net/minecraft/server/level/ServerPlayer.java
|
||||
@@ -258,6 +258,7 @@ public class ServerPlayer extends Player {
|
||||
public Integer clientViewDistance;
|
||||
// CraftBukkit end
|
||||
public PlayerNaturallySpawnCreaturesEvent playerNaturallySpawnedEvent; // Paper
|
||||
+ private boolean tpsBar = false;
|
||||
|
||||
public double lastEntitySpawnRadiusSquared; // Paper - optimise isOutsideRange, this field is in blocks
|
||||
public final com.destroystokyo.paper.util.misc.PooledLinkedHashSets.PooledObjectLinkedOpenHashSet<ServerPlayer> cachedSingleHashSet; // Paper
|
||||
@@ -480,6 +481,7 @@ public class ServerPlayer extends Player {
|
||||
}
|
||||
}
|
||||
|
||||
+ if (nbt.contains("Purpur.TPSBar")) { this.tpsBar = nbt.getBoolean("Purpur.TPSBar"); } // Purpur
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -540,6 +542,7 @@ public class ServerPlayer extends Player {
|
||||
}
|
||||
this.getBukkitEntity().setExtraData(nbt); // CraftBukkit
|
||||
|
||||
+ nbt.putBoolean("Purpur.TPSBar", this.tpsBar); // Purpur
|
||||
}
|
||||
|
||||
// CraftBukkit start - World fallback code, either respawn location or global spawn
|
||||
@@ -2517,5 +2520,13 @@ public class ServerPlayer extends Player {
|
||||
this.server.getPlayerList().moveToWorld(this, toLevel, true, to, !toLevel.paperConfig.disableTeleportationSuffocationCheck);
|
||||
}
|
||||
}
|
||||
+
|
||||
+ public boolean tpsBar() {
|
||||
+ return this.tpsBar;
|
||||
+ }
|
||||
+
|
||||
+ public void tpsBar(boolean tpsBar) {
|
||||
+ this.tpsBar = tpsBar;
|
||||
+ }
|
||||
// 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..5141185821c798cb20f7936d7927d2256d9be75f 100644
|
||||
index 29043f9354b29f7766f1d6d8e793e2ea23883fa0..54db0206bbeea62525ada78b0f9cd99b4f9fddff 100644
|
||||
--- a/src/main/java/net/minecraft/server/players/PlayerList.java
|
||||
+++ b/src/main/java/net/minecraft/server/players/PlayerList.java
|
||||
@@ -593,6 +593,8 @@ public abstract class PlayerList {
|
||||
@@ -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
|
||||
// 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());
|
||||
}
|
||||
@@ -593,6 +594,8 @@ public abstract class PlayerList {
|
||||
}
|
||||
public net.kyori.adventure.text.Component disconnect(ServerPlayer entityplayer, net.kyori.adventure.text.Component leaveMessage) {
|
||||
// Paper end
|
||||
@@ -55,10 +105,10 @@ index 29043f9354b29f7766f1d6d8e793e2ea23883fa0..5141185821c798cb20f7936d7927d225
|
||||
|
||||
entityplayer.awardStat(Stats.LEAVE_GAME);
|
||||
diff --git a/src/main/java/net/pl3x/purpur/PurpurConfig.java b/src/main/java/net/pl3x/purpur/PurpurConfig.java
|
||||
index e1701ab4bd6eccb9a525fa3eb8b35a1bf6f7ffcd..2d64a219becb3006dc12c25ee4d39597fbc2de35 100644
|
||||
index e1701ab4bd6eccb9a525fa3eb8b35a1bf6f7ffcd..7ed1d5b2aab3442f80532c62a398353e89c18b0c 100644
|
||||
--- a/src/main/java/net/pl3x/purpur/PurpurConfig.java
|
||||
+++ b/src/main/java/net/pl3x/purpur/PurpurConfig.java
|
||||
@@ -324,6 +324,27 @@ public class PurpurConfig {
|
||||
@@ -324,6 +324,29 @@ public class PurpurConfig {
|
||||
disableGiveCommandDrops = getBoolean("settings.disable-give-dropping", disableGiveCommandDrops);
|
||||
}
|
||||
|
||||
@@ -71,6 +121,7 @@ index e1701ab4bd6eccb9a525fa3eb8b35a1bf6f7ffcd..2d64a219becb3006dc12c25ee4d39597
|
||||
+ public static String commandTPSBarTextColorGood = "<gradient:#55ff55:#00aa00><text></gradient>";
|
||||
+ public static String commandTPSBarTextColorMedium = "<gradient:#ffff55:#ffaa00><text></gradient>";
|
||||
+ public static String commandTPSBarTextColorLow = "<gradient:#ff5555:#aa0000><text></gradient>";
|
||||
+ public static int commandTPSBarTickInterval = 20;
|
||||
+ private static void commandSettings() {
|
||||
+ commandTPSBarTitle = getString("settings.command.tpsbar.title", commandTPSBarTitle);
|
||||
+ commandTPSBarProgressOverlay = BossBar.Overlay.valueOf(getString("settings.command.tpsbar.overlay", commandTPSBarProgressOverlay.name()));
|
||||
@@ -81,6 +132,7 @@ index e1701ab4bd6eccb9a525fa3eb8b35a1bf6f7ffcd..2d64a219becb3006dc12c25ee4d39597
|
||||
+ commandTPSBarTextColorGood = getString("settings.command.tpsbar.text-color.good", commandTPSBarTextColorGood);
|
||||
+ commandTPSBarTextColorMedium = getString("settings.command.tpsbar.text-color.medium", commandTPSBarTextColorMedium);
|
||||
+ commandTPSBarTextColorLow = getString("settings.command.tpsbar.text-color.low", commandTPSBarTextColorLow);
|
||||
+ commandTPSBarTickInterval = getInt("settings.command.tpsbar.tick-interval", commandTPSBarTickInterval);
|
||||
+ }
|
||||
+
|
||||
public static boolean barrelSixRows = false;
|
||||
@@ -88,10 +140,10 @@ index e1701ab4bd6eccb9a525fa3eb8b35a1bf6f7ffcd..2d64a219becb3006dc12c25ee4d39597
|
||||
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..2803a1b95121fbff3066fd2d1abaf8723386781f
|
||||
index 0000000000000000000000000000000000000000..5ed9d779fbdd9da1010f5f31ceec6b46496a21bb
|
||||
--- /dev/null
|
||||
+++ b/src/main/java/net/pl3x/purpur/command/TPSBarCommand.java
|
||||
@@ -0,0 +1,24 @@
|
||||
@@ -0,0 +1,25 @@
|
||||
+package net.pl3x.purpur.command;
|
||||
+
|
||||
+import com.mojang.brigadier.CommandDispatcher;
|
||||
@@ -110,7 +162,8 @@ index 0000000000000000000000000000000000000000..2803a1b95121fbff3066fd2d1abaf872
|
||||
+
|
||||
+ private static int execute(CommandSourceStack source, ServerPlayer player) {
|
||||
+ if (player != null) {
|
||||
+ TPSBarTask.togglePlayer(player.getBukkitEntity());
|
||||
+ boolean result = TPSBarTask.togglePlayer(player.getBukkitEntity());
|
||||
+ player.tpsBar(result);
|
||||
+ return 1;
|
||||
+ }
|
||||
+ return 0;
|
||||
@@ -118,10 +171,10 @@ index 0000000000000000000000000000000000000000..2803a1b95121fbff3066fd2d1abaf872
|
||||
+}
|
||||
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..12ba7e8a31de9610ca2468a59a28d3f963c5b8f3
|
||||
index 0000000000000000000000000000000000000000..8d3823e0be0cab31a906ec30f0a16fe11de86f25
|
||||
--- /dev/null
|
||||
+++ b/src/main/java/net/pl3x/purpur/task/TPSBarTask.java
|
||||
@@ -0,0 +1,183 @@
|
||||
@@ -0,0 +1,201 @@
|
||||
+package net.pl3x.purpur.task;
|
||||
+
|
||||
+import net.kyori.adventure.bossbar.BossBar;
|
||||
@@ -144,6 +197,7 @@ index 0000000000000000000000000000000000000000..12ba7e8a31de9610ca2468a59a28d3f9
|
||||
+ private final Map<UUID, BossBar> bossbars = new HashMap<>();
|
||||
+ private double tps = 20.0D;
|
||||
+ private double mspt = 0.0D;
|
||||
+ private int tick = 0;
|
||||
+
|
||||
+ private static TPSBarTask instance() {
|
||||
+ if (instance == null) {
|
||||
@@ -154,6 +208,11 @@ index 0000000000000000000000000000000000000000..12ba7e8a31de9610ca2468a59a28d3f9
|
||||
+
|
||||
+ @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();
|
||||
+
|
||||
@@ -268,31 +327,43 @@ index 0000000000000000000000000000000000000000..12ba7e8a31de9610ca2468a59a28d3f9
|
||||
+ @Override
|
||||
+ public void cancel() {
|
||||
+ super.cancel();
|
||||
+ this.bossbars.keySet().forEach(uuid -> {
|
||||
+ Player player = Bukkit.getPlayer(uuid);
|
||||
+ if (player != null) {
|
||||
+ removePlayer(player);
|
||||
+ }
|
||||
+ });
|
||||
+ this.bossbars.clear();
|
||||
+ }
|
||||
+
|
||||
+ public static void removePlayer(Player player) {
|
||||
+ 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 togglePlayer(Player player) {
|
||||
+ BossBar bossbar = instance().bossbars.remove(player.getUniqueId());
|
||||
+ if (bossbar != null) {
|
||||
+ player.hideBossBar(bossbar);
|
||||
+ } else {
|
||||
+ 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 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(), 20L, 20L);
|
||||
+ instance().runTaskTimerAsynchronously(new MinecraftInternalPlugin(), 1, 1);
|
||||
+ }
|
||||
+
|
||||
+ public static void stop() {
|
||||
|
||||
Reference in New Issue
Block a user