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 f4a9d49247d2124b03273c38b14ddf9661184749..818284f0fb3069363fc6849c0daeddb690a24e2b 100644 --- a/net/minecraft/server/network/ServerLoginPacketListenerImpl.java +++ b/net/minecraft/server/network/ServerLoginPacketListenerImpl.java @@ -75,6 +75,11 @@ public class ServerLoginPacketListenerImpl implements ServerLoginPacketListener, private net.minecraft.server.level.ServerPlayer player; // CraftBukkit public boolean iKnowThisMayNotBeTheBestIdeaButPleaseDisableUsernameValidation = false; // Paper - username validation overriding private int velocityLoginMessageId = -1; // Paper - Add Velocity IP Forwarding Support + // DivineMC start - Player ProfileResult caching + private static final com.google.common.cache.Cache playerProfileResultCache = com.google.common.cache.CacheBuilder.newBuilder() + .expireAfterWrite(1, java.util.concurrent.TimeUnit.MINUTES) + .build(); + // DivineMC end - Player ProfileResult caching public ServerLoginPacketListenerImpl(MinecraftServer server, Connection connection, boolean transferred) { this.server = server; @@ -294,9 +299,23 @@ public class ServerLoginPacketListenerImpl implements ServerLoginPacketListener, String string1 = Objects.requireNonNull(ServerLoginPacketListenerImpl.this.requestedUsername, "Player name not initialized"); try { - ProfileResult profileResult = ServerLoginPacketListenerImpl.this.server - .getSessionService() - .hasJoinedServer(string1, string, this.getAddress()); + // DivineMC start - Player ProfileResult caching + ProfileResult profileResult; + if (org.bxteam.divinemc.DivineConfig.playerProfileResultCachingEnabled) { + profileResult = playerProfileResultCache.getIfPresent(string1); + + if (profileResult == null) { + profileResult = ServerLoginPacketListenerImpl.this.server + .getSessionService() + .hasJoinedServer(string1, string, this.getAddress()); + playerProfileResultCache.put(string1, profileResult); + } + } else { + profileResult = ServerLoginPacketListenerImpl.this.server + .getSessionService() + .hasJoinedServer(string1, string, this.getAddress()); + } + // DivineMC end - Player ProfileResult caching if (profileResult != null) { GameProfile gameProfile = profileResult.profile(); // CraftBukkit start - fire PlayerPreLoginEvent