9
0
mirror of https://github.com/SparklyPower/SparklyPaper.git synced 2025-12-19 15:09:27 +00:00

Add concurrency checks when modifying waypoints

This commit is contained in:
MrPowerGamerBR
2025-06-21 15:11:51 -03:00
parent 9a0034889f
commit b878ea1ebd

View File

@@ -178,7 +178,7 @@ index 2882cd829d4d8e1f8615f085f6908efcdf68ac62..7b058fed0ca52b2f74f5cf4534df7b24
}
}
diff --git a/net/minecraft/server/level/ServerLevel.java b/net/minecraft/server/level/ServerLevel.java
index ecfe237fbecde610d095647a1f2a10f7d426d786..7c178bd28880a8fea2bbae7cd0c81fa59448f439 100644
index ecfe237fbecde610d095647a1f2a10f7d426d786..4211816c3b21a2ee66297a8f58b51de378bfd36c 100644
--- a/net/minecraft/server/level/ServerLevel.java
+++ b/net/minecraft/server/level/ServerLevel.java
@@ -182,7 +182,7 @@ public class ServerLevel extends Level implements ServerEntityGetter, WorldGenLe
@@ -198,6 +198,15 @@ index ecfe237fbecde610d095647a1f2a10f7d426d786..7c178bd28880a8fea2bbae7cd0c81fa5
// CraftBukkit start
public final LevelStorageSource.LevelStorageAccess levelStorageAccess;
@@ -665,7 +666,7 @@ public class ServerLevel extends Level implements ServerEntityGetter, WorldGenLe
this.sleepStatus = new SleepStatus();
this.gameEventDispatcher = new GameEventDispatcher(this);
this.randomSequences = Objects.requireNonNullElseGet(randomSequences, () -> this.getDataStorage().computeIfAbsent(RandomSequences.TYPE));
- this.waypointManager = new ServerWaypointManager();
+ this.waypointManager = new ServerWaypointManager(this); // SparklyPaper - parallel world ticking
// Paper start - rewrite chunk system
this.moonrise$setEntityLookup(new ca.spottedleaf.moonrise.patches.chunk_system.level.entity.server.ServerEntityLookup((ServerLevel)(Object)this, ((ServerLevel)(Object)this).new EntityCallbacks()));
this.chunkTaskScheduler = new ca.spottedleaf.moonrise.patches.chunk_system.scheduling.ChunkTaskScheduler((ServerLevel)(Object)this);
@@ -681,6 +682,7 @@ public class ServerLevel extends Level implements ServerEntityGetter, WorldGenLe
this.chunkDataController = new ca.spottedleaf.moonrise.patches.chunk_system.io.datacontroller.ChunkDataController((ServerLevel)(Object)this, this.chunkTaskScheduler);
// Paper end - rewrite chunk system
@@ -345,6 +354,90 @@ index b1524279c02cd3be82338a6bd0320cb125a134d5..9b291998bb5a5dcb94e2e6f8f1813a08
// CraftBukkit end
serverPlayer.connection = player.connection;
serverPlayer.restoreFrom(player, keepInventory);
diff --git a/net/minecraft/server/waypoints/ServerWaypointManager.java b/net/minecraft/server/waypoints/ServerWaypointManager.java
index f9e7532f86122a379692561a639a209a126e8bba..2709dfae53c1a210f36c45fa0df0d49536341a38 100644
--- a/net/minecraft/server/waypoints/ServerWaypointManager.java
+++ b/net/minecraft/server/waypoints/ServerWaypointManager.java
@@ -20,8 +20,16 @@ public class ServerWaypointManager implements WaypointManager<WaypointTransmitte
private final Set<ServerPlayer> players = new HashSet<>();
private final Table<ServerPlayer, WaypointTransmitter, WaypointTransmitter.Connection> connections = HashBasedTable.create();
+ // SparklyPaper start - parallel world ticking
+ private final net.minecraft.server.level.ServerLevel level;
+ public ServerWaypointManager(net.minecraft.server.level.ServerLevel level) {
+ this.level = level;
+ }
+ // SparklyPaper end
+
@Override
public void trackWaypoint(WaypointTransmitter waypoint) {
+ ca.spottedleaf.moonrise.common.util.TickThread.ensureTickThread(this.level, "Cannot track waypoints off-main"); // SparklyPaper - parallel world ticking
this.waypoints.add(waypoint);
for (ServerPlayer serverPlayer : this.players) {
@@ -31,6 +39,7 @@ public class ServerWaypointManager implements WaypointManager<WaypointTransmitte
@Override
public void updateWaypoint(WaypointTransmitter waypoint) {
+ ca.spottedleaf.moonrise.common.util.TickThread.ensureTickThread(this.level, "Cannot update waypoints off-main"); // SparklyPaper - parallel world ticking
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());
@@ -47,12 +56,14 @@ public class ServerWaypointManager implements WaypointManager<WaypointTransmitte
@Override
public void untrackWaypoint(WaypointTransmitter waypoint) {
+ ca.spottedleaf.moonrise.common.util.TickThread.ensureTickThread(this.level, "Cannot untrack waypoints off-main"); // SparklyPaper - parallel world ticking
this.connections.column(waypoint).forEach((serverPlayer, connection) -> connection.disconnect());
Tables.transpose(this.connections).row(waypoint).clear();
this.waypoints.remove(waypoint);
}
public void addPlayer(ServerPlayer player) {
+ ca.spottedleaf.moonrise.common.util.TickThread.ensureTickThread(this.level, "Cannot add player to waypoints off-main"); // SparklyPaper - parallel world ticking
this.players.add(player);
for (WaypointTransmitter waypointTransmitter : this.waypoints) {
@@ -65,6 +76,7 @@ public class ServerWaypointManager implements WaypointManager<WaypointTransmitte
}
public void updatePlayer(ServerPlayer player) {
+ ca.spottedleaf.moonrise.common.util.TickThread.ensureTickThread(this.level, "Cannot update player for waypoints off-main"); // SparklyPaper - parallel world ticking
Map<WaypointTransmitter, WaypointTransmitter.Connection> map = this.connections.row(player);
SetView<WaypointTransmitter> set = Sets.difference(this.waypoints, map.keySet());
@@ -78,6 +90,7 @@ public class ServerWaypointManager implements WaypointManager<WaypointTransmitte
}
public void removePlayer(ServerPlayer player) {
+ ca.spottedleaf.moonrise.common.util.TickThread.ensureTickThread(this.level, "Cannot remove player from waypoints off-main"); // SparklyPaper - parallel world ticking
this.connections.row(player).values().removeIf(connection -> {
connection.disconnect();
return true;
@@ -87,6 +100,7 @@ public class ServerWaypointManager implements WaypointManager<WaypointTransmitte
}
public void breakAllConnections() {
+ ca.spottedleaf.moonrise.common.util.TickThread.ensureTickThread(this.level, "Cannot break all waypoint connections off-main"); // SparklyPaper - parallel world ticking
this.connections.values().forEach(WaypointTransmitter.Connection::disconnect);
this.connections.clear();
}
@@ -106,6 +120,7 @@ public class ServerWaypointManager implements WaypointManager<WaypointTransmitte
}
private void createConnection(ServerPlayer player, WaypointTransmitter waypoint) {
+ ca.spottedleaf.moonrise.common.util.TickThread.ensureTickThread(this.level, "Cannot create waypoint connections off-main"); // SparklyPaper - parallel world ticking
if (player != waypoint) {
if (isLocatorBarEnabledFor(player)) {
waypoint.makeWaypointConnectionWith(player).ifPresentOrElse(connection -> {
@@ -122,6 +137,7 @@ public class ServerWaypointManager implements WaypointManager<WaypointTransmitte
}
private void updateConnection(ServerPlayer player, WaypointTransmitter waypoint, WaypointTransmitter.Connection connection) {
+ ca.spottedleaf.moonrise.common.util.TickThread.ensureTickThread(this.level, "Cannot update waypoint connection off-main"); // SparklyPaper - parallel world ticking
if (player != waypoint) {
if (isLocatorBarEnabledFor(player)) {
if (!connection.isBroken()) {
diff --git a/net/minecraft/world/entity/Entity.java b/net/minecraft/world/entity/Entity.java
index 7546ff4c5ffc62d93a3f874519db8fef1e3bfbcb..ab951849440817877ecf6f52ba61cebd900cf100 100644
--- a/net/minecraft/world/entity/Entity.java