From 7fdce6aedd1f3be3a9991a5a2e239000eddcbc13 Mon Sep 17 00:00:00 2001 From: Helvetica Volubi Date: Tue, 23 Dec 2025 10:07:28 +0800 Subject: [PATCH] backport: fix waypoint module origin commit: db772aaf62b8346edf5a107daeb64ae12c8b9923 --- ...onfig-to-enable-waypoint-command-bar.patch | 18 +++++++--- .../concurrent/AbstractConcurrentTable.java | 2 ++ .../utils/concurrent/ConcurrentTable.java | 11 +++++++ .../concurrent/OptimizedConcurrentTable.java | 33 +++++++++++++++++-- .../lophine/utils/concurrent/TableEntry.java | 6 +++- 5 files changed, 62 insertions(+), 8 deletions(-) diff --git a/lophine-server/minecraft-patches/features/0007-Add-config-to-enable-waypoint-command-bar.patch b/lophine-server/minecraft-patches/features/0007-Add-config-to-enable-waypoint-command-bar.patch index bfa6fd7..95e1829 100644 --- a/lophine-server/minecraft-patches/features/0007-Add-config-to-enable-waypoint-command-bar.patch +++ b/lophine-server/minecraft-patches/features/0007-Add-config-to-enable-waypoint-command-bar.patch @@ -23,7 +23,7 @@ index 1fb359073342a657e9e493403263b56be5b3393f..451a685782da46f5683ea6707289bbaf WorldBorderCommand.register(this.dispatcher); if (JvmProfiler.INSTANCE.isAvailable()) { diff --git a/net/minecraft/server/waypoints/ServerWaypointManager.java b/net/minecraft/server/waypoints/ServerWaypointManager.java -index 0f8cacbb8fe55a60e2f0c98bf36c005b29f41a4b..55cb2d16e22e4d8745da539177b636d188ad0489 100644 +index 0f8cacbb8fe55a60e2f0c98bf36c005b29f41a4b..e1feca6d9e737e6b6c780af2c78344b147e7ae94 100644 --- a/net/minecraft/server/waypoints/ServerWaypointManager.java +++ b/net/minecraft/server/waypoints/ServerWaypointManager.java @@ -16,22 +16,31 @@ import net.minecraft.world.waypoints.WaypointManager; @@ -130,8 +130,12 @@ index 0f8cacbb8fe55a60e2f0c98bf36c005b29f41a4b..55cb2d16e22e4d8745da539177b636d1 } public void remakeConnections(WaypointTransmitter waypoint) { -@@ -86,10 +129,15 @@ public class ServerWaypointManager implements WaypointManager { +- this.connections.put(player, waypoint, connection); ++ this.connections.putOrUpdate(player, waypoint, connection); connection.connect(); }, () -> { - WaypointTransmitter.Connection connection = this.connections.remove(player, waypoint); @@ -150,8 +154,12 @@ index 0f8cacbb8fe55a60e2f0c98bf36c005b29f41a4b..55cb2d16e22e4d8745da539177b636d1 }); } } -@@ -106,7 +154,8 @@ public class ServerWaypointManager implements WaypointManager { + connection1.connect(); +- this.connections.put(player, waypoint, connection1); ++ this.connections.putOrUpdate(player, waypoint, connection1); }, () -> { connection.disconnect(); - this.connections.remove(player, waypoint); diff --git a/lophine-server/src/main/java/fun/bm/lophine/utils/concurrent/AbstractConcurrentTable.java b/lophine-server/src/main/java/fun/bm/lophine/utils/concurrent/AbstractConcurrentTable.java index 7a886d8..f187916 100644 --- a/lophine-server/src/main/java/fun/bm/lophine/utils/concurrent/AbstractConcurrentTable.java +++ b/lophine-server/src/main/java/fun/bm/lophine/utils/concurrent/AbstractConcurrentTable.java @@ -4,6 +4,8 @@ import java.util.List; import java.util.Map; public abstract class AbstractConcurrentTable { + public abstract void putOrUpdate(X x, Y y, Z z); + public abstract void put(X x, Y y, Z z); public abstract void remove(X x, Y y, Z z); diff --git a/lophine-server/src/main/java/fun/bm/lophine/utils/concurrent/ConcurrentTable.java b/lophine-server/src/main/java/fun/bm/lophine/utils/concurrent/ConcurrentTable.java index f400994..9965f35 100644 --- a/lophine-server/src/main/java/fun/bm/lophine/utils/concurrent/ConcurrentTable.java +++ b/lophine-server/src/main/java/fun/bm/lophine/utils/concurrent/ConcurrentTable.java @@ -10,6 +10,17 @@ import java.util.function.Predicate; public class ConcurrentTable extends AbstractConcurrentTable { protected final ConcurrentLinkedDeque> data = new ConcurrentLinkedDeque<>(); + @Override + public void putOrUpdate(X x, Y y, Z z) { + for (TableEntry entry : data) { + if (entry.getX().equals(x) && entry.getY().equals(y)) { + entry.setZ(z); + return; + } + } + this.put(x, y, z); + } + @Override public void put(X x, Y y, Z z) { data.add(new TableEntry<>(x, y, z)); diff --git a/lophine-server/src/main/java/fun/bm/lophine/utils/concurrent/OptimizedConcurrentTable.java b/lophine-server/src/main/java/fun/bm/lophine/utils/concurrent/OptimizedConcurrentTable.java index a64ab8a..6744131 100644 --- a/lophine-server/src/main/java/fun/bm/lophine/utils/concurrent/OptimizedConcurrentTable.java +++ b/lophine-server/src/main/java/fun/bm/lophine/utils/concurrent/OptimizedConcurrentTable.java @@ -11,8 +11,30 @@ public class OptimizedConcurrentTable extends ConcurrentTable private final ConcurrentHashMap>> zxIndex = new ConcurrentHashMap<>(); @Override - public void put(X x, Y y, Z z) { - super.put(x, y, z); + public void putOrUpdate(X x, Y y, Z z) { + boolean updated = false; + + for (TableEntry entry : data) { + if (entry.getX().equals(x) && entry.getY().equals(y)) { + removeFromIndex(xyIndex, entry.getX(), entry.getY(), entry.getZ()); + removeFromIndex(yzIndex, entry.getY(), entry.getZ(), entry.getX()); + removeFromIndex(zxIndex, entry.getZ(), entry.getX(), entry.getY()); + + entry.setZ(z); + + putData(x, y, z); + + updated = true; + break; + } + } + + if (!updated) { + this.put(x, y, z); + } + } + + private void putData(X x, Y y, Z z) { xyIndex.computeIfAbsent(x, k -> new ConcurrentHashMap<>()) .computeIfAbsent(y, k -> ConcurrentHashMap.newKeySet()).add(z); yzIndex.computeIfAbsent(y, k -> new ConcurrentHashMap<>()) @@ -21,6 +43,13 @@ public class OptimizedConcurrentTable extends ConcurrentTable .computeIfAbsent(x, k -> ConcurrentHashMap.newKeySet()).add(y); } + + @Override + public void put(X x, Y y, Z z) { + super.put(x, y, z); + putData(x, y, z); + } + @Override public void remove(X x, Y y, Z z) { super.remove(x, y, z); diff --git a/lophine-server/src/main/java/fun/bm/lophine/utils/concurrent/TableEntry.java b/lophine-server/src/main/java/fun/bm/lophine/utils/concurrent/TableEntry.java index 391ee37..3fd7200 100644 --- a/lophine-server/src/main/java/fun/bm/lophine/utils/concurrent/TableEntry.java +++ b/lophine-server/src/main/java/fun/bm/lophine/utils/concurrent/TableEntry.java @@ -3,7 +3,7 @@ package fun.bm.lophine.utils.concurrent; public class TableEntry { private final X x; private final Y y; - private final Z z; + private Z z; public TableEntry(X x, Y y, Z z) { this.x = x; @@ -22,4 +22,8 @@ public class TableEntry { public Z getZ() { return z; } + + public void setZ(Z z) { + this.z = z; + } }