9
0
mirror of https://github.com/Winds-Studio/Leaf.git synced 2025-12-19 15:09:25 +00:00
Files
Leaf/patches/server/0068-Cache-player-profileResult.patch
Dreeam 337a94cda9 Updated Upstream (Paper/Gale/Purpur)
Upstream has released updates that appear to apply and compile correctly

Paper Changes:
PaperMC/Paper@d1a72ea Updated Upstream (Bukkit/CraftBukkit/Spigot) (#11405)
PaperMC/Paper@0a53f1d Set default drop behavior for player deaths (#11380)
PaperMC/Paper@951e7dd Fix TrialSpawner forgetting assigned mob when placed by player (#11381)
PaperMC/Paper@13a2395 Fix enable-player-collisions playing sounds when set to false (#11390)
PaperMC/Paper@1348e44 Prevent NPE when serializing unresolved profile (#11407)

Gale Changes:
Dreeam-qwq/Gale@f346681 Updated Upstream (Paper)
Dreeam-qwq/Gale@bba1737 Updated Upstream (Paper)

Purpur Changes:
PurpurMC/Purpur@88352c3 Updated Upstream (Paper)
PurpurMC/Purpur@dee41bc Updated Upstream (Paper)
PurpurMC/Purpur@fdfc12e Updated Upstream (Paper)
PurpurMC/Purpur@bc7bcbb Fix elytra durability setting not working properly (#1589)
PurpurMC/Purpur@8af4ea6 Updated Upstream (Paper)
PurpurMC/Purpur@8332fa4 Updated Upstream (Paper)
2024-09-17 01:38:58 -04:00

89 lines
4.8 KiB
Diff

From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001
From: Dreeam <61569423+Dreeam-qwq@users.noreply.github.com>
Date: Thu, 28 Mar 2024 13:36:09 -0400
Subject: [PATCH] Cache player profileResult
diff --git a/build.gradle.kts b/build.gradle.kts
index e16e9b3b815065ed4aae1965edc3a68471470ec5..57f309dc5259a4ca935c12c99e835734cf2480c7 100644
--- a/build.gradle.kts
+++ b/build.gradle.kts
@@ -26,6 +26,10 @@ dependencies {
implementation("org.lz4:lz4-java:1.8.0")
// LinearPaper end
+ // Leaf start - Libraries
+ implementation("com.github.ben-manes.caffeine:caffeine:3.1.8")
+ // Leaf end - Libraries
+
// Paper start
implementation("org.jline:jline-terminal-jansi:3.26.3") // Leaf - Bump Dependencies
implementation("net.minecrell:terminalconsoleappender:1.3.0")
diff --git a/src/main/java/net/minecraft/server/network/ServerLoginPacketListenerImpl.java b/src/main/java/net/minecraft/server/network/ServerLoginPacketListenerImpl.java
index 2fd40cf41d54e450939d11b8ea183ab248072e22..3539397dba1246f345cd3cd210a6e6db876b1c89 100644
--- a/src/main/java/net/minecraft/server/network/ServerLoginPacketListenerImpl.java
+++ b/src/main/java/net/minecraft/server/network/ServerLoginPacketListenerImpl.java
@@ -93,6 +93,11 @@ public class ServerLoginPacketListenerImpl implements ServerLoginPacketListener,
private ServerPlayer player; // CraftBukkit
public boolean iKnowThisMayNotBeTheBestIdeaButPleaseDisableUsernameValidation = false; // Paper - username validation overriding
private int velocityLoginMessageId = -1; // Paper - Add Velocity IP Forwarding Support
+ // Leaf start - Cache player profileResult
+ private final com.github.benmanes.caffeine.cache.Cache<String, ProfileResult> playerProfileResultCahce = com.github.benmanes.caffeine.cache.Caffeine.newBuilder()
+ .expireAfterWrite(org.dreeam.leaf.config.modules.misc.Cache.cachePlayerProfileResultTimeout, java.util.concurrent.TimeUnit.MINUTES)
+ .build();
+ // Leaf end
public ServerLoginPacketListenerImpl(MinecraftServer server, Connection connection, boolean transferred) {
this.state = ServerLoginPacketListenerImpl.State.HELLO;
@@ -320,7 +325,19 @@ public class ServerLoginPacketListenerImpl implements ServerLoginPacketListener,
String s1 = (String) Objects.requireNonNull(ServerLoginPacketListenerImpl.this.requestedUsername, "Player name not initialized");
try {
- ProfileResult profileresult = ServerLoginPacketListenerImpl.this.server.getSessionService().hasJoinedServer(s1, s, this.getAddress());
+ // Leaf start - Cache player profileResult
+ ProfileResult profileresult;
+ if (org.dreeam.leaf.config.modules.misc.Cache.cachePlayerProfileResult) {
+ profileresult = playerProfileResultCahce.getIfPresent(s1);
+
+ if (profileresult == null) {
+ profileresult = ServerLoginPacketListenerImpl.this.server.getSessionService().hasJoinedServer(s1, s, this.getAddress());
+ playerProfileResultCahce.put(s1, profileresult);
+ }
+ } else {
+ profileresult = ServerLoginPacketListenerImpl.this.server.getSessionService().hasJoinedServer(s1, s, this.getAddress());
+ }
+ // Leaf end
if (profileresult != null) {
GameProfile gameprofile = profileresult.profile();
diff --git a/src/main/java/org/dreeam/leaf/config/modules/misc/Cache.java b/src/main/java/org/dreeam/leaf/config/modules/misc/Cache.java
new file mode 100644
index 0000000000000000000000000000000000000000..b0a5bfbebb3ad1598ba4164a8f2635862d3e424c
--- /dev/null
+++ b/src/main/java/org/dreeam/leaf/config/modules/misc/Cache.java
@@ -0,0 +1,24 @@
+package org.dreeam.leaf.config.modules.misc;
+
+import org.dreeam.leaf.config.ConfigModules;
+import org.dreeam.leaf.config.EnumConfigCategory;
+
+public class Cache extends ConfigModules {
+
+ public String getBasePath() {
+ return EnumConfigCategory.MISC.getBaseKeyName() + ".cache";
+ }
+
+ public static boolean cachePlayerProfileResult = true;
+ public static int cachePlayerProfileResultTimeout = 1440;
+
+ @Override
+ public void onLoaded() {
+ cachePlayerProfileResult = config.getBoolean(getBasePath() + ".cache-player-profile-result", cachePlayerProfileResult, """
+ Cache the player profile result on they first join.
+ It's useful if Mojang's verification server is down.
+ """);
+ cachePlayerProfileResultTimeout = config.getInt(getBasePath() + ".cache-player-profile-result-timeout", cachePlayerProfileResultTimeout,
+ "The timeout of the cache. Unit: Minutes.");
+ }
+}