9
0
mirror of https://github.com/BX-Team/DivineMC.git synced 2025-12-19 14:59:25 +00:00
Files
DivineMC/patches/todo/minecraft-patches/0040-Player-ProfileResult-caching.patch
2025-10-10 01:56:03 +03:00

50 lines
3.2 KiB
Diff

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 20ba45054c243fbb85e50cf0bdf75648730cb0bc..443aebb71b2a55ee9dcd2dd4bf9a30fbb8da9e49 100644
--- a/net/minecraft/server/network/ServerLoginPacketListenerImpl.java
+++ b/net/minecraft/server/network/ServerLoginPacketListenerImpl.java
@@ -71,6 +71,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<String, ProfileResult> 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;
@@ -256,9 +261,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.config.DivineConfig.NetworkCategory.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