fix: fix waypoint module

This commit is contained in:
Helvetica Volubi
2025-12-23 10:07:28 +08:00
parent b1bee59e6c
commit db772aaf62
5 changed files with 63 additions and 11 deletions
@@ -6,7 +6,7 @@ Subject: [PATCH] Add config to enable waypoint command & bar
use concurrent method to fix it (now, they are thread safe)
diff --git a/net/minecraft/commands/Commands.java b/net/minecraft/commands/Commands.java
index b9dc7dd77aeb6e3b59b6903cb5094b7eadee4d2d..b049520cca9f365282493d7c442bbcd3075d78ac 100644
index 23f047a47cdccc90a96153cc52bdedf91cd15db9..9cfcac44b4d51cb5f122d7e1fa980791a23dd38f 100644
--- a/net/minecraft/commands/Commands.java
+++ b/net/minecraft/commands/Commands.java
@@ -270,7 +270,11 @@ public class Commands {
@@ -23,7 +23,7 @@ index b9dc7dd77aeb6e3b59b6903cb5094b7eadee4d2d..b049520cca9f365282493d7c442bbcd3
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 1cbc46e480cc7d109c6128f109a1a9e38bf1a193..9492698541bfe704a1075a8fb58a9d7624895e48 100644
index 1cbc46e480cc7d109c6128f109a1a9e38bf1a193..d2c0b532200f274e44f18147d294dfe5d3f52d1d 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 1cbc46e480cc7d109c6128f109a1a9e38bf1a193..9492698541bfe704a1075a8fb58a9d76
}
public void remakeConnections(WaypointTransmitter waypoint) {
@@ -86,10 +129,15 @@ public class ServerWaypointManager implements WaypointManager<WaypointTransmitte
this.connections.put(player, waypoint, connection);
@@ -83,13 +126,18 @@ public class ServerWaypointManager implements WaypointManager<WaypointTransmitte
if (player != waypoint) {
if (isLocatorBarEnabledFor(player)) {
waypoint.makeWaypointConnectionWith(player).ifPresentOrElse(connection -> {
- 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 1cbc46e480cc7d109c6128f109a1a9e38bf1a193..9492698541bfe704a1075a8fb58a9d76
});
}
}
@@ -106,7 +154,8 @@ public class ServerWaypointManager implements WaypointManager<WaypointTransmitte
this.connections.put(player, waypoint, connection1);
@@ -103,10 +151,11 @@ public class ServerWaypointManager implements WaypointManager<WaypointTransmitte
} else {
waypoint.makeWaypointConnectionWith(player).ifPresentOrElse(connection1 -> {
connection1.connect();
- this.connections.put(player, waypoint, connection1);
+ this.connections.putOrUpdate(player, waypoint, connection1);
}, () -> {
connection.disconnect();
- this.connections.remove(player, waypoint);
@@ -4,6 +4,8 @@ import java.util.List;
import java.util.Map;
public abstract class AbstractConcurrentTable<X, Y, Z> {
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);
@@ -10,9 +10,19 @@ import java.util.function.Predicate;
public class ConcurrentTable<X, Y, Z> extends AbstractConcurrentTable<X, Y, Z> {
protected final ConcurrentLinkedDeque<TableEntry<X, Y, Z>> data = new ConcurrentLinkedDeque<>();
@Override
public void putOrUpdate(X x, Y y, Z z) {
for (TableEntry<X, Y, Z> 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) {
if (true) return; // TODO: because of some bug, we disabled it
data.add(new TableEntry<>(x, y, z));
}
@@ -11,9 +11,30 @@ public class OptimizedConcurrentTable<X, Y, Z> extends ConcurrentTable<X, Y, Z>
private final ConcurrentHashMap<Z, ConcurrentHashMap<X, Set<Y>>> zxIndex = new ConcurrentHashMap<>();
@Override
public void put(X x, Y y, Z z) {
if (true) return; // TODO: because of some bug, we disabled it
super.put(x, y, z);
public void putOrUpdate(X x, Y y, Z z) {
boolean updated = false;
for (TableEntry<X, Y, Z> 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<>())
@@ -22,6 +43,13 @@ public class OptimizedConcurrentTable<X, Y, Z> extends ConcurrentTable<X, Y, Z>
.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);
@@ -3,7 +3,7 @@ package fun.bm.lophine.utils.concurrent;
public class TableEntry<X, Y, Z> {
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<X, Y, Z> {
public Z getZ() {
return z;
}
public void setZ(Z z) {
this.z = z;
}
}