feat: update concurrent in waypoint
This commit is contained in:
+22
-13
@@ -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<WaypointTransmitter> {
|
||||
@@ -54,17 +54,24 @@ index 0f8cacbb8fe55a60e2f0c98bf36c005b29f41a4b..40675f209518d58267fb6ce3bfe697a2
|
||||
public void updateWaypoint(WaypointTransmitter waypoint) {
|
||||
if (this.waypoints.contains(waypoint)) {
|
||||
- Map<ServerPlayer, WaypointTransmitter.Connection> map = Tables.transpose(this.connections).row(waypoint);
|
||||
+ Map<ServerPlayer, WaypointTransmitter.Connection> map = this.connections.getXZ(waypoint); // Lophine - concurrent
|
||||
SetView<ServerPlayer> set = Sets.difference(this.players, map.keySet());
|
||||
- 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
|
||||
+ 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())) {
|
||||
@@ -43,26 +50,58 @@ public class ServerWaypointManager implements WaypointManager<WaypointTransmitte
|
||||
- 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,60 @@ 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((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<WaypointTransmitter, WaypointTransmitter.Connection> map = this.connections.getYZ(player); // Lophine - concurrent
|
||||
+ SetView<WaypointTransmitter> set = Sets.difference(this.waypoints, map.keySet());
|
||||
+ java.util.List<Entry<WaypointTransmitter, WaypointTransmitter.Connection>> map = this.connections.getYZ(player); // Lophine - concurrent
|
||||
+ Set<WaypointTransmitter> waypoints1 = new HashSet<>();// Lophine - concurrent
|
||||
+ 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 : ImmutableSet.copyOf(map.entrySet())) {
|
||||
+ for (Entry<WaypointTransmitter, WaypointTransmitter.Connection> 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<WaypointTransmitte
|
||||
@@ -86,10 +129,15 @@ public class ServerWaypointManager implements WaypointManager<WaypointTransmitte
|
||||
this.connections.put(player, waypoint, connection);
|
||||
connection.connect();
|
||||
}, () -> {
|
||||
@@ -141,7 +150,7 @@ index 0f8cacbb8fe55a60e2f0c98bf36c005b29f41a4b..40675f209518d58267fb6ce3bfe697a2
|
||||
});
|
||||
}
|
||||
}
|
||||
@@ -106,7 +150,8 @@ public class ServerWaypointManager implements WaypointManager<WaypointTransmitte
|
||||
@@ -106,7 +154,8 @@ public class ServerWaypointManager implements WaypointManager<WaypointTransmitte
|
||||
this.connections.put(player, waypoint, connection1);
|
||||
}, () -> {
|
||||
connection.disconnect();
|
||||
|
||||
@@ -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<WaypointTransmitte
|
||||
@@ -526,7 +526,7 @@ index 52fd730998535ea071bfc99b7cc2c254b9b656d7..0abf6f0265fcb916f2c2c76fb1313bd1
|
||||
this.waypoints.add(waypoint);
|
||||
|
||||
for (ServerPlayer serverPlayer : this.players) {
|
||||
@@ -59,6 +64,11 @@ public class ServerWaypointManager implements WaypointManager<WaypointTransmitte
|
||||
@@ -61,6 +66,11 @@ public class ServerWaypointManager implements WaypointManager<WaypointTransmitte
|
||||
// Folia - region threading
|
||||
// Lophine start - unsafe waypoint bar
|
||||
if (!fun.bm.lophine.config.modules.experiment.CommandConfig.waypoint) return;
|
||||
|
||||
+17
-3
@@ -5,18 +5,32 @@ import java.util.Map;
|
||||
|
||||
public abstract class AbstractConcurrentTable<X, Y, Z> {
|
||||
public abstract void put(X x, Y y, Z z);
|
||||
|
||||
public abstract void remove(X x, Y y, Z z);
|
||||
|
||||
public abstract List<Z> getZ(X x, Y y);
|
||||
|
||||
public abstract List<Y> getY(X x, Z z);
|
||||
|
||||
public abstract List<X> getX(Y y, Z z);
|
||||
public abstract Map<X, Y> getXY(Z z);
|
||||
public abstract Map<Y, Z> getYZ(X x);
|
||||
public abstract Map<X, Z> getXZ(Y y);
|
||||
|
||||
public abstract List<Map.Entry<X, Y>> getXY(Z z);
|
||||
|
||||
public abstract List<Map.Entry<Y, Z>> getYZ(X x);
|
||||
|
||||
public abstract List<Map.Entry<X, Z>> getXZ(Y y);
|
||||
|
||||
public abstract List<X> getAllX();
|
||||
|
||||
public abstract List<Y> getAllY();
|
||||
|
||||
public abstract List<Z> getAllZ();
|
||||
|
||||
public abstract void clearXY(Z z);
|
||||
|
||||
public abstract void clearYZ(X x);
|
||||
|
||||
public abstract void clearXZ(Y y);
|
||||
|
||||
public abstract void clearAll();
|
||||
}
|
||||
|
||||
@@ -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<X, Y, Z> extends AbstractConcurrentTable<X, Y, Z> {
|
||||
}
|
||||
|
||||
@Override
|
||||
public Map<X, Y> getXY(Z z) {
|
||||
public List<Map.Entry<X, Y>> getXY(Z z) {
|
||||
return filterAndMap(
|
||||
entry -> entry.getZ().equals(z),
|
||||
TableEntry::getX,
|
||||
@@ -54,7 +54,7 @@ public class ConcurrentTable<X, Y, Z> extends AbstractConcurrentTable<X, Y, Z> {
|
||||
}
|
||||
|
||||
@Override
|
||||
public Map<Y, Z> getYZ(X x) {
|
||||
public List<Map.Entry<Y, Z>> getYZ(X x) {
|
||||
return filterAndMap(
|
||||
entry -> entry.getX().equals(x),
|
||||
TableEntry::getY,
|
||||
@@ -63,7 +63,7 @@ public class ConcurrentTable<X, Y, Z> extends AbstractConcurrentTable<X, Y, Z> {
|
||||
}
|
||||
|
||||
@Override
|
||||
public Map<X, Z> getXZ(Y y) {
|
||||
public List<Map.Entry<X, Z>> getXZ(Y y) {
|
||||
return filterAndMap(
|
||||
entry -> entry.getY().equals(y),
|
||||
TableEntry::getX,
|
||||
@@ -117,16 +117,16 @@ public class ConcurrentTable<X, Y, Z> extends AbstractConcurrentTable<X, Y, Z> {
|
||||
return result;
|
||||
}
|
||||
|
||||
private <K, V> Map<K, V> filterAndMap(Predicate<TableEntry<X, Y, Z>> filter,
|
||||
java.util.function.Function<TableEntry<X, Y, Z>, K> keyMapper,
|
||||
java.util.function.Function<TableEntry<X, Y, Z>, V> valueMapper) {
|
||||
Map<K, V> map = new HashMap<>();
|
||||
private <K, V> List<Map.Entry<K, V>> filterAndMap(Predicate<TableEntry<X, Y, Z>> filter,
|
||||
java.util.function.Function<TableEntry<X, Y, Z>, K> keyMapper,
|
||||
java.util.function.Function<TableEntry<X, Y, Z>, V> valueMapper) {
|
||||
List<Map.Entry<K, V>> list = new ArrayList<>();
|
||||
for (TableEntry<X, Y, Z> 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 <T> List<T> collectAll(java.util.function.Function<TableEntry<X, Y, Z>, T> mapper) {
|
||||
|
||||
+17
-24
@@ -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<X, Y, Z> extends ConcurrentTable<X, Y, Z> {
|
||||
@@ -81,18 +81,18 @@ public class OptimizedConcurrentTable<X, Y, Z> extends ConcurrentTable<X, Y, Z>
|
||||
}
|
||||
|
||||
@Override
|
||||
public Map<X, Y> getXY(Z z) {
|
||||
return buildMapFromIndex(zxIndex.get(z), Function.identity(), Function.identity());
|
||||
public List<Map.Entry<X, Y>> getXY(Z z) {
|
||||
return buildDataFromIndex(zxIndex.get(z));
|
||||
}
|
||||
|
||||
@Override
|
||||
public Map<Y, Z> getYZ(X x) {
|
||||
return buildMapFromIndex(xyIndex.get(x), Function.identity(), Function.identity());
|
||||
public List<Map.Entry<Y, Z>> getYZ(X x) {
|
||||
return buildDataFromIndex(xyIndex.get(x));
|
||||
}
|
||||
|
||||
@Override
|
||||
public Map<X, Z> getXZ(Y y) {
|
||||
return reverseMapFromIndex(yzIndex.get(y));
|
||||
public List<Map.Entry<X, Z>> getXZ(Y y) {
|
||||
return reverseDataFromIndex(yzIndex.get(y));
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -141,15 +141,16 @@ public class OptimizedConcurrentTable<X, Y, Z> extends ConcurrentTable<X, Y, Z>
|
||||
}
|
||||
|
||||
|
||||
private <K, V, R, S> Map<R, S> buildMapFromIndex(ConcurrentHashMap<K, Set<V>> indexMap, java.util.function.Function<K, R> keyMapper, java.util.function.Function<V, S> valueMapper) {
|
||||
Map<R, S> result = new HashMap<>();
|
||||
private <K, V, R> List<R> buildEntriesFromIndex(ConcurrentHashMap<K, Set<V>> indexMap,
|
||||
BiFunction<K, V, R> entryCreator) {
|
||||
List<R> result = new ArrayList<>();
|
||||
if (indexMap != null) {
|
||||
for (Map.Entry<K, Set<V>> entry : indexMap.entrySet()) {
|
||||
K key = entry.getKey();
|
||||
Set<V> 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<X, Y, Z> extends ConcurrentTable<X, Y, Z>
|
||||
return result;
|
||||
}
|
||||
|
||||
private <K, V> Map<V, K> reverseMapFromIndex(ConcurrentHashMap<K, Set<V>> indexMap) {
|
||||
Map<V, K> result = new HashMap<>();
|
||||
if (indexMap != null) {
|
||||
for (Map.Entry<K, Set<V>> entry : indexMap.entrySet()) {
|
||||
K key = entry.getKey();
|
||||
Set<V> valueSet = entry.getValue();
|
||||
if (valueSet != null && !valueSet.isEmpty()) {
|
||||
for (V value : valueSet) {
|
||||
result.put(value, key);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
return result;
|
||||
private <K, V> List<Map.Entry<K, V>> buildDataFromIndex(ConcurrentHashMap<K, Set<V>> indexMap) {
|
||||
return buildEntriesFromIndex(indexMap, AbstractMap.SimpleEntry::new);
|
||||
}
|
||||
|
||||
private <K, V> List<Map.Entry<V, K>> reverseDataFromIndex(ConcurrentHashMap<K, Set<V>> indexMap) {
|
||||
return buildEntriesFromIndex(indexMap, (key, value) -> new AbstractMap.SimpleEntry<>(value, key));
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user