From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001 From: NONPLAYT <76615486+NONPLAYT@users.noreply.github.com> Date: Sat, 26 Apr 2025 22:30:35 +0300 Subject: [PATCH] Player ProfileResult caching diff --git a/net/minecraft/server/network/ServerLoginPacketListenerImpl.java b/net/minecraft/server/network/ServerLoginPacketListenerImpl.java index ace65f36d6562988665c530dd3fdbfaa5d2e2071..68e88a923d8dd8cd91f0ccd2b82cd60a492ad359 100644 --- a/net/minecraft/server/network/ServerLoginPacketListenerImpl.java +++ b/net/minecraft/server/network/ServerLoginPacketListenerImpl.java @@ -72,6 +72,11 @@ public class ServerLoginPacketListenerImpl implements ServerLoginPacketListener, public @Nullable java.util.UUID requestedUuid; // Paper private final io.papermc.paper.connection.PaperPlayerLoginConnection paperLoginConnection; // Paper - Config API private volatile boolean disconnecting = false; // Paper - Fix disconnect still ticking login + // DivineMC start - Player ProfileResult caching + private static final com.google.common.cache.Cache playerProfileResultCache = com.google.common.cache.CacheBuilder.newBuilder() + .expireAfterWrite(org.bxteam.divinemc.config.DivineConfig.NetworkCategory.playerProfileResultCachingTimeout, java.util.concurrent.TimeUnit.MINUTES) + .build(); + // DivineMC end - Player ProfileResult caching public ServerLoginPacketListenerImpl(MinecraftServer server, Connection connection, boolean transferred) { this.server = server; @@ -258,10 +263,25 @@ public class ServerLoginPacketListenerImpl implements ServerLoginPacketListener, String string1 = Objects.requireNonNull(ServerLoginPacketListenerImpl.this.requestedUsername, "Player name not initialized"); try { - ProfileResult profileResult = ServerLoginPacketListenerImpl.this.server - .services() - .sessionService() - .hasJoinedServer(string1, string, this.getAddress()); + // DivineMC start - Player ProfileResult caching + ProfileResult profileResult; + if (org.bxteam.divinemc.config.DivineConfig.NetworkCategory.playerProfileResultCachingEnabled) { + profileResult = playerProfileResultCache.getIfPresent(string1); + + if (profileResult == null) { + profileResult = ServerLoginPacketListenerImpl.this.server + .services() + .sessionService() + .hasJoinedServer(string1, string, this.getAddress()); + playerProfileResultCache.put(string1, profileResult); + } + } else { + profileResult = ServerLoginPacketListenerImpl.this.server + .services() + .sessionService() + .hasJoinedServer(string1, string, this.getAddress()); + } + // DivineMC end - Player ProfileResult caching if (profileResult != null) { GameProfile gameProfile = profileResult.profile(); // CraftBukkit start - fire PlayerPreLoginEvent