From 77c412bfe851244fd3379bf151a1e5e3337951ed Mon Sep 17 00:00:00 2001 From: Helvetica Volubi Date: Thu, 11 Dec 2025 02:05:57 +0800 Subject: [PATCH] feat: update concurrent in waypoint --- ...onfig-to-enable-waypoint-command-bar.patch | 35 ++++++++++------ .../features/0023-Leaves-Fakeplayer.patch | 4 +- .../concurrent/AbstractConcurrentTable.java | 20 +++++++-- .../utils/concurrent/ConcurrentTable.java | 20 ++++----- .../concurrent/OptimizedConcurrentTable.java | 41 ++++++++----------- 5 files changed, 68 insertions(+), 52 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 eb952a3..bfa6fd7 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,10 +23,10 @@ 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..40675f209518d58267fb6ce3bfe697a2e681ea29 100644 +index 0f8cacbb8fe55a60e2f0c98bf36c005b29f41a4b..55cb2d16e22e4d8745da539177b636d188ad0489 100644 --- a/net/minecraft/server/waypoints/ServerWaypointManager.java +++ b/net/minecraft/server/waypoints/ServerWaypointManager.java -@@ -16,19 +16,26 @@ import net.minecraft.world.waypoints.WaypointManager; +@@ -16,22 +16,31 @@ import net.minecraft.world.waypoints.WaypointManager; import net.minecraft.world.waypoints.WaypointTransmitter; public class ServerWaypointManager implements WaypointManager { @@ -54,17 +54,24 @@ index 0f8cacbb8fe55a60e2f0c98bf36c005b29f41a4b..40675f209518d58267fb6ce3bfe697a2 public void updateWaypoint(WaypointTransmitter waypoint) { if (this.waypoints.contains(waypoint)) { - Map map = Tables.transpose(this.connections).row(waypoint); -+ Map map = this.connections.getXZ(waypoint); // Lophine - concurrent - SetView set = Sets.difference(this.players, map.keySet()); +- SetView set = Sets.difference(this.players, map.keySet()); ++ java.util.List> map = this.connections.getXZ(waypoint); // Lophine - concurrent ++ Set players1 = new HashSet<>(); // Lophine - concurrent ++ map.forEach((entry) -> players1.add(entry.getKey())); // Lophine - concurrent ++ SetView set = Sets.difference(this.players, players1); // Lophine - concurrent - for (Entry entry : ImmutableSet.copyOf(map.entrySet())) { -@@ -43,26 +50,58 @@ public class ServerWaypointManager implements WaypointManager entry : ImmutableSet.copyOf(map.entrySet())) { ++ for (Entry entry : map) { // Lophine - concurrent + this.updateConnection(entry.getKey(), waypoint, entry.getValue()); + } + +@@ -43,26 +52,60 @@ public class ServerWaypointManager implements WaypointManager connection.disconnect()); - Tables.transpose(this.connections).row(waypoint).clear(); -+ this.connections.getXZ(waypoint).forEach((serverPlayer, connection) -> connection.disconnect()); // Lophine - concurrent ++ this.connections.getXZ(waypoint).forEach((entry) -> entry.getKey().disconnect()); // Lophine - concurrent + this.connections.clearXZ(waypoint); // Lophine - concurrent this.waypoints.remove(waypoint); } @@ -89,10 +96,12 @@ index 0f8cacbb8fe55a60e2f0c98bf36c005b29f41a4b..40675f209518d58267fb6ce3bfe697a2 // Folia - region threading + // Lophine start - unsafe waypoint bar + if (!fun.bm.lophine.config.modules.experiment.CommandConfig.waypoint) return; -+ Map map = this.connections.getYZ(player); // Lophine - concurrent -+ SetView set = Sets.difference(this.waypoints, map.keySet()); ++ java.util.List> map = this.connections.getYZ(player); // Lophine - concurrent ++ Set waypoints1 = new HashSet<>();// Lophine - concurrent ++ map.forEach((entry) -> waypoints1.add(entry.getKey()));// Lophine - concurrent ++ SetView set = Sets.difference(this.waypoints, waypoints1); // Lophine - concurrent + -+ for (Entry entry : ImmutableSet.copyOf(map.entrySet())) { ++ for (Entry entry : map) { // Lophine - concurrent + this.updateConnection(player, entry.getKey(), entry.getValue()); + } + @@ -106,7 +115,7 @@ index 0f8cacbb8fe55a60e2f0c98bf36c005b29f41a4b..40675f209518d58267fb6ce3bfe697a2 // Folia - region threading + // Lophine start - unsafe waypoint bar + if (!fun.bm.lophine.config.modules.experiment.CommandConfig.waypoint) return; -+ this.connections.getYZ(player).values().forEach(WaypointTransmitter.Connection::disconnect); // Lophine - concurrent ++ this.connections.getYZ(player).forEach((entry) -> entry.getValue().disconnect()); // Lophine - concurrent + this.connections.clearYZ(player); // Lophine - concurrent + this.untrackWaypoint((WaypointTransmitter)player); + this.players.remove(player); @@ -121,7 +130,7 @@ index 0f8cacbb8fe55a60e2f0c98bf36c005b29f41a4b..40675f209518d58267fb6ce3bfe697a2 } public void remakeConnections(WaypointTransmitter waypoint) { -@@ -86,10 +125,15 @@ public class ServerWaypointManager implements WaypointManager { @@ -141,7 +150,7 @@ index 0f8cacbb8fe55a60e2f0c98bf36c005b29f41a4b..40675f209518d58267fb6ce3bfe697a2 }); } } -@@ -106,7 +150,8 @@ public class ServerWaypointManager implements WaypointManager { connection.disconnect(); diff --git a/lophine-server/minecraft-patches/features/0023-Leaves-Fakeplayer.patch b/lophine-server/minecraft-patches/features/0023-Leaves-Fakeplayer.patch index 0984376..9ca642d 100644 --- a/lophine-server/minecraft-patches/features/0023-Leaves-Fakeplayer.patch +++ b/lophine-server/minecraft-patches/features/0023-Leaves-Fakeplayer.patch @@ -511,7 +511,7 @@ index 8e2775e873c92beed6a0e4e8ce1304ab8ca6e8d1..580f114fd99b017403c61e994d0c947d public boolean canBypassPlayerLimit(GameProfile profile) { diff --git a/net/minecraft/server/waypoints/ServerWaypointManager.java b/net/minecraft/server/waypoints/ServerWaypointManager.java -index 52fd730998535ea071bfc99b7cc2c254b9b656d7..0abf6f0265fcb916f2c2c76fb1313bd13444f4ad 100644 +index 55cb2d16e22e4d8745da539177b636d188ad0489..ce0942793c4098a1274b8ef5736e824a6eec0152 100644 --- a/net/minecraft/server/waypoints/ServerWaypointManager.java +++ b/net/minecraft/server/waypoints/ServerWaypointManager.java @@ -24,6 +24,11 @@ public class ServerWaypointManager implements WaypointManager { public abstract void put(X x, Y y, Z z); + public abstract void remove(X x, Y y, Z z); + public abstract List getZ(X x, Y y); + public abstract List getY(X x, Z z); + public abstract List getX(Y y, Z z); - public abstract Map getXY(Z z); - public abstract Map getYZ(X x); - public abstract Map getXZ(Y y); + + public abstract List> getXY(Z z); + + public abstract List> getYZ(X x); + + public abstract List> getXZ(Y y); + public abstract List getAllX(); + public abstract List getAllY(); + public abstract List getAllZ(); + public abstract void clearXY(Z z); + public abstract void clearYZ(X x); + public abstract void clearXZ(Y y); + public abstract void clearAll(); } 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 11db91e..f400994 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 @@ -1,7 +1,7 @@ package fun.bm.lophine.utils.concurrent; +import java.util.AbstractMap; import java.util.ArrayList; -import java.util.HashMap; import java.util.List; import java.util.Map; import java.util.concurrent.ConcurrentLinkedDeque; @@ -45,7 +45,7 @@ public class ConcurrentTable extends AbstractConcurrentTable { } @Override - public Map getXY(Z z) { + public List> getXY(Z z) { return filterAndMap( entry -> entry.getZ().equals(z), TableEntry::getX, @@ -54,7 +54,7 @@ public class ConcurrentTable extends AbstractConcurrentTable { } @Override - public Map getYZ(X x) { + public List> getYZ(X x) { return filterAndMap( entry -> entry.getX().equals(x), TableEntry::getY, @@ -63,7 +63,7 @@ public class ConcurrentTable extends AbstractConcurrentTable { } @Override - public Map getXZ(Y y) { + public List> getXZ(Y y) { return filterAndMap( entry -> entry.getY().equals(y), TableEntry::getX, @@ -117,16 +117,16 @@ public class ConcurrentTable extends AbstractConcurrentTable { return result; } - private Map filterAndMap(Predicate> filter, - java.util.function.Function, K> keyMapper, - java.util.function.Function, V> valueMapper) { - Map map = new HashMap<>(); + private List> filterAndMap(Predicate> filter, + java.util.function.Function, K> keyMapper, + java.util.function.Function, V> valueMapper) { + List> list = new ArrayList<>(); for (TableEntry entry : data) { if (filter.test(entry)) { - map.put(keyMapper.apply(entry), valueMapper.apply(entry)); + list.add(new AbstractMap.SimpleEntry<>(keyMapper.apply(entry), valueMapper.apply(entry))); } } - return map; + return list; } private List collectAll(java.util.function.Function, T> mapper) { 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 01359c4..a64ab8a 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 @@ -2,7 +2,7 @@ package fun.bm.lophine.utils.concurrent; import java.util.*; import java.util.concurrent.ConcurrentHashMap; -import java.util.function.Function; +import java.util.function.BiFunction; import java.util.function.Predicate; public class OptimizedConcurrentTable extends ConcurrentTable { @@ -81,18 +81,18 @@ public class OptimizedConcurrentTable extends ConcurrentTable } @Override - public Map getXY(Z z) { - return buildMapFromIndex(zxIndex.get(z), Function.identity(), Function.identity()); + public List> getXY(Z z) { + return buildDataFromIndex(zxIndex.get(z)); } @Override - public Map getYZ(X x) { - return buildMapFromIndex(xyIndex.get(x), Function.identity(), Function.identity()); + public List> getYZ(X x) { + return buildDataFromIndex(xyIndex.get(x)); } @Override - public Map getXZ(Y y) { - return reverseMapFromIndex(yzIndex.get(y)); + public List> getXZ(Y y) { + return reverseDataFromIndex(yzIndex.get(y)); } @Override @@ -141,15 +141,16 @@ public class OptimizedConcurrentTable extends ConcurrentTable } - private Map buildMapFromIndex(ConcurrentHashMap> indexMap, java.util.function.Function keyMapper, java.util.function.Function valueMapper) { - Map result = new HashMap<>(); + private List buildEntriesFromIndex(ConcurrentHashMap> indexMap, + BiFunction entryCreator) { + List result = new ArrayList<>(); if (indexMap != null) { for (Map.Entry> entry : indexMap.entrySet()) { K key = entry.getKey(); Set valueSet = entry.getValue(); if (valueSet != null && !valueSet.isEmpty()) { for (V value : valueSet) { - result.put(keyMapper.apply(key), valueMapper.apply(value)); + result.add(entryCreator.apply(key, value)); } } } @@ -157,19 +158,11 @@ public class OptimizedConcurrentTable extends ConcurrentTable return result; } - private Map reverseMapFromIndex(ConcurrentHashMap> indexMap) { - Map result = new HashMap<>(); - if (indexMap != null) { - for (Map.Entry> entry : indexMap.entrySet()) { - K key = entry.getKey(); - Set valueSet = entry.getValue(); - if (valueSet != null && !valueSet.isEmpty()) { - for (V value : valueSet) { - result.put(value, key); - } - } - } - } - return result; + private List> buildDataFromIndex(ConcurrentHashMap> indexMap) { + return buildEntriesFromIndex(indexMap, AbstractMap.SimpleEntry::new); + } + + private List> reverseDataFromIndex(ConcurrentHashMap> indexMap) { + return buildEntriesFromIndex(indexMap, (key, value) -> new AbstractMap.SimpleEntry<>(value, key)); } }