|
| 1 | +From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001 |
| 2 | +From: MidnightTale < [email protected]> |
| 3 | +Date: Thu, 24 Jul 2025 08:38:51 +0700 |
| 4 | +Subject: [PATCH] Add config for force enabled waypoint |
| 5 | + |
| 6 | + |
| 7 | +diff --git a/net/minecraft/commands/Commands.java b/net/minecraft/commands/Commands.java |
| 8 | +index 8a90aa5c145f53afbb3f2371f97cb09974f30bbb..f08f4cb7258726b740b3e0b21e8832455b29d6c6 100644 |
| 9 | +--- a/net/minecraft/commands/Commands.java |
| 10 | ++++ b/net/minecraft/commands/Commands.java |
| 11 | +@@ -247,7 +247,9 @@ public class Commands { |
| 12 | + TimeCommand.register(this.dispatcher); |
| 13 | + TitleCommand.register(this.dispatcher, context); |
| 14 | + //TriggerCommand.register(this.dispatcher); // Folia - region threading - TODO later |
| 15 | +- //WaypointCommand.register(this.dispatcher, context); // Folia - region threading - TODO later |
| 16 | ++ if (fun.mntale.atdeprecated.config.AtCoreConfig.WAYPOINT_CONFIG.forceEnable) { // atDeprecated - Force enabled waypoint |
| 17 | ++ WaypointCommand.register(this.dispatcher, context); // Folia - region threading - TODO later |
| 18 | ++ } |
| 19 | + WeatherCommand.register(this.dispatcher); |
| 20 | + WorldBorderCommand.register(this.dispatcher); |
| 21 | + if (JvmProfiler.INSTANCE.isAvailable()) { |
| 22 | +diff --git a/net/minecraft/server/waypoints/ServerWaypointManager.java b/net/minecraft/server/waypoints/ServerWaypointManager.java |
| 23 | +index 0f8cacbb8fe55a60e2f0c98bf36c005b29f41a4b..b489f47c914a65654289de9d811a28de5a8780e5 100644 |
| 24 | +--- a/net/minecraft/server/waypoints/ServerWaypointManager.java |
| 25 | ++++ b/net/minecraft/server/waypoints/ServerWaypointManager.java |
| 26 | +@@ -6,6 +6,7 @@ import com.google.common.collect.Sets; |
| 27 | + import com.google.common.collect.Table; |
| 28 | + import com.google.common.collect.Tables; |
| 29 | + import com.google.common.collect.Sets.SetView; |
| 30 | ++import java.util.Collections; |
| 31 | + import java.util.HashSet; |
| 32 | + import java.util.Map; |
| 33 | + import java.util.Set; |
| 34 | +@@ -16,29 +17,48 @@ import net.minecraft.world.waypoints.WaypointManager; |
| 35 | + import net.minecraft.world.waypoints.WaypointTransmitter; |
| 36 | + |
| 37 | + public class ServerWaypointManager implements WaypointManager<WaypointTransmitter> { |
| 38 | +- private final Set<WaypointTransmitter> waypoints = new HashSet<>(); |
| 39 | +- private final Set<ServerPlayer> players = new HashSet<>(); |
| 40 | +- private final Table<ServerPlayer, WaypointTransmitter, WaypointTransmitter.Connection> connections = HashBasedTable.create(); |
| 41 | ++ // atDeprecated start - Thread safe collections |
| 42 | ++ private final Set<WaypointTransmitter> waypoints = Collections.synchronizedSet(new HashSet<>()); |
| 43 | ++ private final Set<ServerPlayer> players = Collections.synchronizedSet(new HashSet<>()); |
| 44 | ++ private final Table<ServerPlayer, WaypointTransmitter, WaypointTransmitter.Connection> connections = Tables.synchronizedTable(HashBasedTable.create()); |
| 45 | ++ // atDeprecated end |
| 46 | + |
| 47 | + @Override |
| 48 | + public void trackWaypoint(WaypointTransmitter waypoint) { |
| 49 | +- // Folia - region threading |
| 50 | ++ // atDeprecated start - Force enabled waypoint |
| 51 | ++ if (fun.mntale.atdeprecated.config.AtCoreConfig.WAYPOINT_CONFIG.forceEnable) { |
| 52 | ++ synchronized (this) { |
| 53 | ++ this.waypoints.add(waypoint); |
| 54 | ++ for (ServerPlayer serverPlayer : this.players) { |
| 55 | ++ this.createConnection(serverPlayer, waypoint); |
| 56 | ++ } |
| 57 | ++ } |
| 58 | ++ } |
| 59 | ++ // atDeprecated end - Force enabled waypoint |
| 60 | + } |
| 61 | + |
| 62 | + @Override |
| 63 | + public void updateWaypoint(WaypointTransmitter waypoint) { |
| 64 | +- if (this.waypoints.contains(waypoint)) { |
| 65 | +- Map<ServerPlayer, WaypointTransmitter.Connection> map = Tables.transpose(this.connections).row(waypoint); |
| 66 | +- SetView<ServerPlayer> set = Sets.difference(this.players, map.keySet()); |
| 67 | +- |
| 68 | +- for (Entry<ServerPlayer, WaypointTransmitter.Connection> entry : ImmutableSet.copyOf(map.entrySet())) { |
| 69 | +- this.updateConnection(entry.getKey(), waypoint, entry.getValue()); |
| 70 | +- } |
| 71 | ++ // atDeprecated start - Thread safe |
| 72 | ++ synchronized (this) { |
| 73 | ++ if (this.waypoints.contains(waypoint)) { |
| 74 | ++ Map<ServerPlayer, WaypointTransmitter.Connection> map = Tables.transpose(this.connections).row(waypoint); |
| 75 | ++ Set<ServerPlayer> currentPlayers = ImmutableSet.copyOf(this.players); |
| 76 | ++ SetView<ServerPlayer> set = Sets.difference(currentPlayers, map.keySet()); |
| 77 | ++ |
| 78 | ++ // Update existing connections |
| 79 | ++ Set<Entry<ServerPlayer, WaypointTransmitter.Connection>> entries = ImmutableSet.copyOf(map.entrySet()); |
| 80 | ++ for (Entry<ServerPlayer, WaypointTransmitter.Connection> entry : entries) { |
| 81 | ++ this.updateConnection(entry.getKey(), waypoint, entry.getValue()); |
| 82 | ++ } |
| 83 | + |
| 84 | +- for (ServerPlayer serverPlayer : set) { |
| 85 | +- this.createConnection(serverPlayer, waypoint); |
| 86 | ++ // Create new connections |
| 87 | ++ for (ServerPlayer serverPlayer : set) { |
| 88 | ++ this.createConnection(serverPlayer, waypoint); |
| 89 | ++ } |
| 90 | + } |
| 91 | + } |
| 92 | ++ // atDeprecated end |
| 93 | + } |
| 94 | + |
| 95 | + @Override |
| 96 | +@@ -49,26 +69,72 @@ public class ServerWaypointManager implements WaypointManager<WaypointTransmitte |
| 97 | + } |
| 98 | + |
| 99 | + public void addPlayer(ServerPlayer player) { |
| 100 | +- // Folia - region threading |
| 101 | ++ // atDeprecated start - Force enabled waypoint |
| 102 | ++ if (fun.mntale.atdeprecated.config.AtCoreConfig.WAYPOINT_CONFIG.forceEnable) { |
| 103 | ++ synchronized (this) { |
| 104 | ++ this.players.add(player); |
| 105 | ++ for (WaypointTransmitter waypointTransmitter : this.waypoints) { |
| 106 | ++ this.createConnection(player, waypointTransmitter); |
| 107 | ++ } |
| 108 | ++ if (player.isTransmittingWaypoint()) { |
| 109 | ++ this.trackWaypoint((WaypointTransmitter)player); |
| 110 | ++ } |
| 111 | ++ } |
| 112 | ++ } |
| 113 | ++ // atDeprecated end - Force enabled waypoint |
| 114 | + } |
| 115 | + |
| 116 | + public void updatePlayer(ServerPlayer player) { |
| 117 | +- // Folia - region threading |
| 118 | ++ // atDeprecated start - Force enabled waypoint |
| 119 | ++ if (fun.mntale.atdeprecated.config.AtCoreConfig.WAYPOINT_CONFIG.forceEnable) { |
| 120 | ++ synchronized (this) { |
| 121 | ++ Map<WaypointTransmitter, WaypointTransmitter.Connection> map = this.connections.row(player); |
| 122 | ++ SetView<WaypointTransmitter> set = Sets.difference(this.waypoints, map.keySet()); |
| 123 | ++ for (Entry<WaypointTransmitter, WaypointTransmitter.Connection> entry : ImmutableSet.copyOf(map.entrySet())) { |
| 124 | ++ this.updateConnection(player, entry.getKey(), entry.getValue()); |
| 125 | ++ } |
| 126 | ++ for (WaypointTransmitter waypointTransmitter : ImmutableSet.copyOf(set)) { |
| 127 | ++ this.createConnection(player, waypointTransmitter); |
| 128 | ++ } |
| 129 | ++ } |
| 130 | ++ } |
| 131 | ++ // atDeprecated end - Force enabled waypoint |
| 132 | + } |
| 133 | + |
| 134 | + public void removePlayer(ServerPlayer player) { |
| 135 | +- // Folia - region threading |
| 136 | ++ // atDeprecated start - Force enabled waypoint |
| 137 | ++ if (fun.mntale.atdeprecated.config.AtCoreConfig.WAYPOINT_CONFIG.forceEnable) { |
| 138 | ++ synchronized (this) { |
| 139 | ++ this.connections.row(player).values().removeIf(connection -> { |
| 140 | ++ connection.disconnect(); |
| 141 | ++ return true; |
| 142 | ++ }); |
| 143 | ++ this.untrackWaypoint((WaypointTransmitter)player); |
| 144 | ++ this.players.remove(player); |
| 145 | ++ } |
| 146 | ++ } |
| 147 | ++ // atDeprecated end - Force enabled waypoint |
| 148 | + } |
| 149 | + |
| 150 | + public void breakAllConnections() { |
| 151 | +- this.connections.values().forEach(WaypointTransmitter.Connection::disconnect); |
| 152 | +- this.connections.clear(); |
| 153 | ++ // atDeprecated start - Thread safe |
| 154 | ++ synchronized (this) { |
| 155 | ++ Set<WaypointTransmitter.Connection> currentConnections = ImmutableSet.copyOf(this.connections.values()); |
| 156 | ++ currentConnections.forEach(WaypointTransmitter.Connection::disconnect); |
| 157 | ++ this.connections.clear(); |
| 158 | ++ } |
| 159 | ++ // atDeprecated end |
| 160 | + } |
| 161 | + |
| 162 | + public void remakeConnections(WaypointTransmitter waypoint) { |
| 163 | +- for (ServerPlayer serverPlayer : this.players) { |
| 164 | +- this.createConnection(serverPlayer, waypoint); |
| 165 | ++ // atDeprecated start - Thread safe |
| 166 | ++ synchronized (this) { |
| 167 | ++ Set<ServerPlayer> currentPlayers = ImmutableSet.copyOf(this.players); |
| 168 | ++ for (ServerPlayer serverPlayer : currentPlayers) { |
| 169 | ++ this.createConnection(serverPlayer, waypoint); |
| 170 | ++ } |
| 171 | + } |
| 172 | ++ // atDeprecated end |
| 173 | + } |
| 174 | + |
| 175 | + public Set<WaypointTransmitter> transmitters() { |
0 commit comments