70 lines
5.0 KiB
Diff
70 lines
5.0 KiB
Diff
From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001
|
|
From: AlphaKR93 <dev@alpha93.kr>
|
|
Date: Sat, 26 Oct 2024 18:09:08 +0900
|
|
Subject: [PATCH] Load player data asynchronously
|
|
|
|
|
|
diff --git a/src/main/java/net/minecraft/server/network/ServerLoginPacketListenerImpl.java b/src/main/java/net/minecraft/server/network/ServerLoginPacketListenerImpl.java
|
|
index 16069b9cbf6c7679c28a2e9a54e77d23cd10e541..bb10892f33ba0d7fc3959debef1045073868f8b8 100644
|
|
--- a/src/main/java/net/minecraft/server/network/ServerLoginPacketListenerImpl.java
|
|
+++ b/src/main/java/net/minecraft/server/network/ServerLoginPacketListenerImpl.java
|
|
@@ -76,7 +76,7 @@ public class ServerLoginPacketListenerImpl implements ServerLoginPacketListener,
|
|
// CraftBukkit end
|
|
private static final AtomicInteger UNIQUE_THREAD_ID = new AtomicInteger(0);
|
|
static final Logger LOGGER = LogUtils.getLogger();
|
|
- private static final java.util.concurrent.ExecutorService authenticatorPool = java.util.concurrent.Executors.newCachedThreadPool(new com.google.common.util.concurrent.ThreadFactoryBuilder().setNameFormat("User Authenticator #%d").setUncaughtExceptionHandler(new DefaultUncaughtExceptionHandler(LOGGER)).build()); // Paper - Cache authenticator threads
|
|
+ public static final java.util.concurrent.ExecutorService authenticatorPool = java.util.concurrent.Executors.newCachedThreadPool(new com.google.common.util.concurrent.ThreadFactoryBuilder().setNameFormat("User Authenticator #%d").setUncaughtExceptionHandler(new DefaultUncaughtExceptionHandler(LOGGER)).build()); // Paper - Cache authenticator threads // Plazma - private -> public
|
|
private static final int MAX_TICKS_BEFORE_LOGIN = 600;
|
|
private final byte[] challenge;
|
|
final MinecraftServer server;
|
|
diff --git a/src/main/java/net/minecraft/server/players/PlayerList.java b/src/main/java/net/minecraft/server/players/PlayerList.java
|
|
index 503716bfa3d54c46534738d4209ef1a8ab50f7c3..14dd70f95ed6f6d4f24b509becf764aad60a3df1 100644
|
|
--- a/src/main/java/net/minecraft/server/players/PlayerList.java
|
|
+++ b/src/main/java/net/minecraft/server/players/PlayerList.java
|
|
@@ -183,6 +183,16 @@ public abstract class PlayerList {
|
|
abstract public void loadAndSaveFiles(); // Paper - fix converting txt to json file; moved from DedicatedPlayerList constructor
|
|
|
|
public void placeNewPlayer(Connection connection, ServerPlayer player, CommonListenerCookie clientData) {
|
|
+ // Plazma start - load player information asynchronously
|
|
+ if (!org.plazmamc.plazma.configurations.GlobalConfiguration.get().player.loadAsynchronously)
|
|
+ this.placeNewPlayer(connection, player, clientData, this.load(player));
|
|
+ else java.util.concurrent.CompletableFuture
|
|
+ .supplyAsync(() -> this.load(player), net.minecraft.server.network.ServerLoginPacketListenerImpl.authenticatorPool)
|
|
+ .thenAcceptAsync(nbt -> this.placeNewPlayer(connection, player, clientData, nbt), this.server);
|
|
+ }
|
|
+
|
|
+ private void placeNewPlayer(Connection connection, ServerPlayer player, CommonListenerCookie clientData, Optional<CompoundTag> optional) {
|
|
+ // Plazma end - load player information asynchronously
|
|
player.isRealPlayer = true; // Paper
|
|
player.loginTime = System.currentTimeMillis(); // Paper - Replace OfflinePlayer#getLastPlayed
|
|
GameProfile gameprofile = player.getGameProfile();
|
|
@@ -191,14 +201,13 @@ public abstract class PlayerList {
|
|
String s;
|
|
|
|
if (usercache != null) {
|
|
- Optional<GameProfile> optional = usercache.get(gameprofile.getId()); // CraftBukkit - decompile error
|
|
- s = (String) optional.map(GameProfile::getName).orElse(gameprofile.getName());
|
|
+ s = usercache.get(gameprofile.getId()).map(GameProfile::getName).orElse(gameprofile.getName()); // CraftBukkit - decompile error // Plazma - varname conflict
|
|
usercache.add(gameprofile);
|
|
} else {
|
|
s = gameprofile.getName();
|
|
}
|
|
|
|
- Optional<CompoundTag> optional = this.load(player); // CraftBukkit - decompile error
|
|
+ // Optional<CompoundTag> optional = this.load(player); // CraftBukkit - decompile error // Plazma - extract
|
|
ResourceKey<Level> resourcekey = null; // Paper
|
|
// CraftBukkit start - Better rename detection
|
|
if (optional.isPresent()) {
|
|
diff --git a/src/main/java/org/plazmamc/plazma/configurations/GlobalConfiguration.java b/src/main/java/org/plazmamc/plazma/configurations/GlobalConfiguration.java
|
|
index 2a1dceb5251c67d6a5c60e1b9fb3ef2931055673..4a73bffae1531b42a2718cbe620fe2fc53139c45 100644
|
|
--- a/src/main/java/org/plazmamc/plazma/configurations/GlobalConfiguration.java
|
|
+++ b/src/main/java/org/plazmamc/plazma/configurations/GlobalConfiguration.java
|
|
@@ -28,6 +28,7 @@ public class GlobalConfiguration extends ConfigurationPart {
|
|
public class Player extends ConfigurationPart {
|
|
|
|
public boolean checkSpectatorMovedToQuickly = !OPTIMIZE;
|
|
+ public boolean loadAsynchronously = OPTIMIZE;
|
|
|
|
public FreedomChat freedomChat;
|
|
public class FreedomChat extends ConfigurationPart {
|