Skip to content

Commit

Permalink
properly implement sidebar display values
Browse files Browse the repository at this point in the history
  • Loading branch information
Blast-MC committed Jan 19, 2024
1 parent d204d8c commit 39c6747
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 6 deletions.
10 changes: 7 additions & 3 deletions patches/api/0022-Add-Sidebar-Utility.patch
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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;
+ }
+ }
+
Expand Down Expand Up @@ -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;
Expand All @@ -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 = "";
Expand All @@ -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];
+ }
+
Expand Down Expand Up @@ -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;
+ }
Expand Down
9 changes: 6 additions & 3 deletions patches/server/0028-Add-Sidebar-Utility.patch
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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;
Expand Down Expand Up @@ -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);
+ }
Expand All @@ -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
Expand Down

0 comments on commit 39c6747

Please sign in to comment.