From 39c6747e132ff75cf90942171eb3ece2d2428c9e Mon Sep 17 00:00:00 2001 From: Blast-MC Date: Fri, 19 Jan 2024 14:34:38 -0500 Subject: [PATCH] properly implement sidebar display values --- patches/api/0022-Add-Sidebar-Utility.patch | 10 +++++++--- patches/server/0028-Add-Sidebar-Utility.patch | 9 ++++++--- 2 files changed, 13 insertions(+), 6 deletions(-) diff --git a/patches/api/0022-Add-Sidebar-Utility.patch b/patches/api/0022-Add-Sidebar-Utility.patch index 208c17a..8a0f6c9 100644 --- a/patches/api/0022-Add-Sidebar-Utility.patch +++ b/patches/api/0022-Add-Sidebar-Utility.patch @@ -9,7 +9,7 @@ new file mode 100644 index 0000000000000000000000000000000000000000..f3f7a138d8d0a0e5f863f50fa39ffd861a8a1db9 --- /dev/null +++ b/src/main/java/gg/projecteden/parchment/sidebar/Sidebar.java -@@ -0,0 +1,124 @@ +@@ -0,0 +1,123 @@ +package gg.projecteden.parchment.sidebar; + +import gg.projecteden.parchment.entity.EntityData; @@ -77,7 +77,6 @@ index 0000000000000000000000000000000000000000..f3f7a138d8d0a0e5f863f50fa39ffd86 + this.buffer[this.back].clearLine(idx); + } else { + this.buffer[this.back].setLine(idx, value, display); -+ this.buffer[this.back ^ 1].stagedDisplays[idx] = display; + } + } + @@ -139,7 +138,7 @@ new file mode 100644 index 0000000000000000000000000000000000000000..c4a58a2b4e8bf5d3130b7da71616f06b6ed98e8f --- /dev/null +++ b/src/main/java/gg/projecteden/parchment/sidebar/SidebarBuffer.java -@@ -0,0 +1,95 @@ +@@ -0,0 +1,100 @@ +package gg.projecteden.parchment.sidebar; + +import org.bukkit.entity.Player; @@ -155,6 +154,7 @@ index 0000000000000000000000000000000000000000..c4a58a2b4e8bf5d3130b7da71616f06b + protected final int size; + protected final String[] liveLines; + protected final String[] stagedLines; ++ protected final String[] liveDisplays; + protected final String[] stagedDisplays; + + protected String liveTitle = ""; @@ -165,6 +165,7 @@ index 0000000000000000000000000000000000000000..c4a58a2b4e8bf5d3130b7da71616f06b + this.size = size; + this.liveLines = new String[size]; + this.stagedLines = new String[size]; ++ this.liveDisplays = new String[size]; + this.stagedDisplays = new String[size]; + } + @@ -221,16 +222,19 @@ index 0000000000000000000000000000000000000000..c4a58a2b4e8bf5d3130b7da71616f06b + void sync(SidebarBuffer live) { + this.stagedTitle = live.liveTitle; + System.arraycopy(live.liveLines, 0, this.stagedLines, 0, this.size); ++ System.arraycopy(live.liveDisplays, 0, this.stagedDisplays, 0, this.size); + } + + void clear() { + this.stagedTitle = ""; + Arrays.fill(this.stagedLines, null); ++ Arrays.fill(this.stagedDisplays, null); + } + + boolean hasDiverged(SidebarBuffer live) { + boolean out = !Objects.equals(this.stagedTitle, live.liveTitle); + out = out || !Arrays.equals(this.stagedLines, live.liveLines); ++ out = out || !Arrays.equals(this.stagedDisplays, live.liveDisplays); + + return out; + } diff --git a/patches/server/0028-Add-Sidebar-Utility.patch b/patches/server/0028-Add-Sidebar-Utility.patch index ed95ebc..c862ef4 100644 --- a/patches/server/0028-Add-Sidebar-Utility.patch +++ b/patches/server/0028-Add-Sidebar-Utility.patch @@ -30,7 +30,7 @@ new file mode 100644 index 0000000000000000000000000000000000000000..5a1e28da1f3dcae1abeb016708dc6fdf883cd213 --- /dev/null +++ b/src/main/java/gg/projecteden/parchment/sidebar/SidebarBufferImpl.java -@@ -0,0 +1,178 @@ +@@ -0,0 +1,181 @@ +package gg.projecteden.parchment.sidebar; + +import gg.projecteden.parchment.util.StringUtils; @@ -40,7 +40,6 @@ index 0000000000000000000000000000000000000000..5a1e28da1f3dcae1abeb016708dc6fdf +import net.minecraft.network.chat.numbers.FixedFormat; +import net.minecraft.network.chat.numbers.NumberFormat; +import net.minecraft.network.protocol.game.*; -+import net.minecraft.server.ServerScoreboard; +import net.minecraft.server.dedicated.DedicatedServer; +import net.minecraft.world.scores.DisplaySlot; +import net.minecraft.world.scores.Objective; @@ -111,7 +110,10 @@ index 0000000000000000000000000000000000000000..5a1e28da1f3dcae1abeb016708dc6fdf + String live = liveIdx >= 0 ? this.liveLines[liveIdx] : null; + String staged = stagedIdx >= 0 ? this.stagedLines[stagedIdx] : null; + -+ if (!Objects.equals(live, staged)) { ++ String liveDisplay = liveIdx >= 0 ? this.liveDisplays[liveIdx] : null; ++ String stagedDisplay = stagedIdx >= 0 ? this.stagedDisplays[stagedIdx] : null; ++ ++ if (!Objects.equals(live, staged) || !Objects.equals(liveDisplay, stagedDisplay)) { + if (live != null) { + this.sendDelete(live, liveEnd - liveIdx); + } @@ -126,6 +128,7 @@ index 0000000000000000000000000000000000000000..5a1e28da1f3dcae1abeb016708dc6fdf + } + + System.arraycopy(this.stagedLines, 0, this.liveLines, 0, this.size); ++ System.arraycopy(this.stagedDisplays, 0, this.liveDisplays, 0, this.size); + } + + @Override