178 lines
10 KiB
Diff
178 lines
10 KiB
Diff
From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001
|
|
From: Helvetica Volubi <suisuroru@blue-millennium.fun>
|
|
Date: Mon, 7 Jul 2025 18:19:00 +0800
|
|
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 8d332f8e99ceb5a20b3b54bc327b024968719017..d4357499cbfd0474dae3c66b4473b81367f284d1 100644
|
|
--- a/net/minecraft/commands/Commands.java
|
|
+++ b/net/minecraft/commands/Commands.java
|
|
@@ -257,7 +257,11 @@ public class Commands {
|
|
TimeCommand.register(this.dispatcher);
|
|
TitleCommand.register(this.dispatcher, context);
|
|
//TriggerCommand.register(this.dispatcher); // Folia - region threading - TODO later
|
|
- //WaypointCommand.register(this.dispatcher, context); // Folia - region threading - TODO later
|
|
+ // Lophine start - unsafe waypoint bar
|
|
+ if (fun.bm.lophine.config.modules.experiment.CommandConfig.waypoint) {
|
|
+ WaypointCommand.register(this.dispatcher, context); // Folia - region threading - TODO later
|
|
+ }
|
|
+ // Lophine end - unsafe waypoint bar
|
|
WeatherCommand.register(this.dispatcher);
|
|
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..65a4956ba2f0e38da7ae4f8cd7ed6e4b02c015a9 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;
|
|
import net.minecraft.world.waypoints.WaypointTransmitter;
|
|
|
|
public class ServerWaypointManager implements WaypointManager<WaypointTransmitter> {
|
|
- private final Set<WaypointTransmitter> waypoints = new HashSet<>();
|
|
- private final Set<ServerPlayer> players = new HashSet<>();
|
|
- private final Table<ServerPlayer, WaypointTransmitter, WaypointTransmitter.Connection> connections = HashBasedTable.create();
|
|
+ private final Set<WaypointTransmitter> waypoints = new java.util.concurrent.CopyOnWriteArraySet<>(); // Lophine - concurrent
|
|
+ private final Set<ServerPlayer> players = new java.util.concurrent.CopyOnWriteArraySet<>(); // Lophine - concurrent
|
|
+ private final fun.bm.lophine.utils.concurrent.AbstractConcurrentTable<ServerPlayer, WaypointTransmitter, WaypointTransmitter.Connection> connections = fun.bm.lophine.config.modules.optimizations.WayPointOptimizedTableConfig.optimizedTable ? new fun.bm.lophine.utils.concurrent.OptimizedConcurrentTable<>() : new fun.bm.lophine.utils.concurrent.ConcurrentTable<>(); // Lophine - concurrent
|
|
|
|
@Override
|
|
public void trackWaypoint(WaypointTransmitter waypoint) {
|
|
- // Folia - region threading
|
|
+ // Lophine start - unsafe waypoint bar
|
|
+ if (!fun.bm.lophine.config.modules.experiment.CommandConfig.waypoint) return;
|
|
+ this.waypoints.add(waypoint);
|
|
+
|
|
+ for (ServerPlayer serverPlayer : this.players) {
|
|
+ this.createConnection(serverPlayer, waypoint);
|
|
+ }
|
|
+ // Lophine end - unsafe waypoint bar
|
|
}
|
|
|
|
@Override
|
|
public void updateWaypoint(WaypointTransmitter waypoint) {
|
|
if (this.waypoints.contains(waypoint)) {
|
|
- Map<ServerPlayer, WaypointTransmitter.Connection> map = Tables.transpose(this.connections).row(waypoint);
|
|
- SetView<ServerPlayer> set = Sets.difference(this.players, map.keySet());
|
|
+ java.util.List<Entry<ServerPlayer, WaypointTransmitter.Connection>> map = this.connections.getXZ(waypoint); // Lophine - concurrent
|
|
+ Set<ServerPlayer> players1 = new HashSet<>(); // Lophine - concurrent
|
|
+ if (!map.isEmpty()) map.forEach((entry) -> players1.add(entry.getKey())); // Lophine - concurrent
|
|
+ SetView<ServerPlayer> set = Sets.difference(this.players, players1); // Lophine - concurrent
|
|
|
|
- for (Entry<ServerPlayer, WaypointTransmitter.Connection> entry : ImmutableSet.copyOf(map.entrySet())) {
|
|
+ for (Entry<ServerPlayer, WaypointTransmitter.Connection> entry : map) { // Lophine - concurrent
|
|
this.updateConnection(entry.getKey(), waypoint, entry.getValue());
|
|
}
|
|
|
|
@@ -43,26 +52,65 @@ public class ServerWaypointManager implements WaypointManager<WaypointTransmitte
|
|
|
|
@Override
|
|
public void untrackWaypoint(WaypointTransmitter waypoint) {
|
|
- this.connections.column(waypoint).forEach((serverPlayer, connection) -> connection.disconnect());
|
|
- Tables.transpose(this.connections).row(waypoint).clear();
|
|
+ this.connections.getXZ(waypoint).forEach((entry) -> {
|
|
+ entry.getValue().disconnect();
|
|
+ this.connections.remove(entry.getKey(), waypoint, entry.getValue());
|
|
+ }); // Lophine - concurrent
|
|
this.waypoints.remove(waypoint);
|
|
}
|
|
|
|
public void addPlayer(ServerPlayer player) {
|
|
// Folia - region threading
|
|
+ // Lophine start - unsafe waypoint bar
|
|
+ if (!fun.bm.lophine.config.modules.experiment.CommandConfig.waypoint) return;
|
|
+ this.players.add(player);
|
|
+
|
|
+ for (WaypointTransmitter waypointTransmitter : this.waypoints) {
|
|
+ this.createConnection(player, waypointTransmitter);
|
|
+ }
|
|
+
|
|
+ if (player.isTransmittingWaypoint()) {
|
|
+ this.trackWaypoint((WaypointTransmitter)player);
|
|
+ }
|
|
+ // Lophine end - unsafe waypoint bar
|
|
}
|
|
|
|
public void updatePlayer(ServerPlayer player) {
|
|
// Folia - region threading
|
|
+ // Lophine start - unsafe waypoint bar
|
|
+ if (!fun.bm.lophine.config.modules.experiment.CommandConfig.waypoint) return;
|
|
+ java.util.List<Entry<WaypointTransmitter, WaypointTransmitter.Connection>> map = this.connections.getYZ(player); // Lophine - concurrent
|
|
+ Set<WaypointTransmitter> waypoints1 = new HashSet<>();// Lophine - concurrent
|
|
+ if (!map.isEmpty()) map.forEach((entry) -> waypoints1.add(entry.getKey()));// Lophine - concurrent
|
|
+ SetView<WaypointTransmitter> set = Sets.difference(this.waypoints, waypoints1); // Lophine - concurrent
|
|
+
|
|
+ for (Entry<WaypointTransmitter, WaypointTransmitter.Connection> entry : map) { // Lophine - concurrent
|
|
+ this.updateConnection(player, entry.getKey(), entry.getValue());
|
|
+ }
|
|
+
|
|
+ for (WaypointTransmitter waypointTransmitter : set) {
|
|
+ this.createConnection(player, waypointTransmitter);
|
|
+ }
|
|
+ // Lophine end - unsafe waypoint bar
|
|
}
|
|
|
|
public void removePlayer(ServerPlayer player) {
|
|
// Folia - region threading
|
|
+ // Lophine start - unsafe waypoint bar
|
|
+ if (!fun.bm.lophine.config.modules.experiment.CommandConfig.waypoint) return;
|
|
+ this.connections.getYZ(player).forEach((entry) -> {
|
|
+ entry.getValue().disconnect();
|
|
+ this.connections.remove(player, entry.getKey(), entry.getValue());
|
|
+ }); // Lophine - concurrent
|
|
+ this.untrackWaypoint((WaypointTransmitter)player);
|
|
+ this.players.remove(player);
|
|
+ // Lophine end - unsafe waypoint bar
|
|
}
|
|
|
|
public void breakAllConnections() {
|
|
- this.connections.values().forEach(WaypointTransmitter.Connection::disconnect);
|
|
- this.connections.clear();
|
|
+ java.util.List<WaypointTransmitter.Connection> map = this.connections.getAllZ(); // Lophine - concurrent
|
|
+ if (!map.isEmpty()) map.forEach(WaypointTransmitter.Connection::disconnect); // Lophine - concurrent
|
|
+ this.connections.clearAll(); // Lophine - concurrent
|
|
}
|
|
|
|
public void remakeConnections(WaypointTransmitter waypoint) {
|
|
@@ -83,13 +131,19 @@ 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);
|
|
- if (connection != null) {
|
|
- connection.disconnect();
|
|
- }
|
|
+ // Lophine start - concurrent
|
|
+ java.util.List<WaypointTransmitter.Connection> c = this.connections.getZ(player, waypoint);
|
|
+ if (c.isEmpty()) return; // Lophine - concurrent
|
|
+ c.forEach((connection) -> {
|
|
+ this.connections.remove(player, waypoint, connection);
|
|
+ if (connection != null) {
|
|
+ connection.disconnect();
|
|
+ }
|
|
+ });
|
|
+ // Lophine end - concurrent
|
|
});
|
|
}
|
|
}
|
|
@@ -103,10 +157,12 @@ 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);
|
|
+ java.util.List<WaypointTransmitter.Connection> c = this.connections.getZ(player, waypoint); // Lophine - concurrent
|
|
+ if (c.isEmpty()) return; // Lophine - concurrent
|
|
+ c.forEach((connection1) -> this.connections.remove(player, waypoint, connection1)); // Lophine - concurrent
|
|
});
|
|
}
|
|
}
|