9
0
mirror of https://github.com/BX-Team/DivineMC.git synced 2025-12-22 00:09:15 +00:00
Files
DivineMC/divinemc-server/minecraft-patches/features/0046-Player-ProfileResult-caching.patch
2025-04-26 22:44:49 +03:00

50 lines
3.1 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 738c8749593cf3c30a1c321664abf12ba8dac635..7dbd73d8b5f5d2888cede36f9ea0d0cf71b4a49d 100644
--- a/net/minecraft/server/network/ServerLoginPacketListenerImpl.java
+++ b/net/minecraft/server/network/ServerLoginPacketListenerImpl.java
@@ -74,6 +74,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<String, ProfileResult> 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;
@@ -293,9 +298,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