mirror of
https://github.com/Winds-Studio/Leaf.git
synced 2025-12-21 07:59:26 +00:00
* Region based comment helper functions * (Region based comment) Dont save entity * (Region based comment) Pufferfish DAB * (Region based comment) Cache EntityType * (Region based comment) Cache EntityType * (Region based comment) Pufferfish EntityTTL * (Region based comment) Faster sequence * (Region based comment) FastRNG * (Region based comment) 0042 * (Region based comment) 0721 * (Region based comment) 0009 * (Region based comment) V1rtUal tHReaD * (Region based comment) ZSSM * [ci skip] (Region based comment) 0079 * [ci skip] (Region based comment) 0089 0090 * [ci skip] (Region based comment) 0049 0118 0138 * [ci skip] (Region based comment) 0006 0017 0018 0080 0081 * [ci skip] (Region based comment) 0019 0038 0059 0108 0117 0127 * ALL PATCHES ARE DONE * [ci skip] NZDD
94 lines
5.1 KiB
Diff
94 lines
5.1 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 c2f2783fc4cdf5f222498d9bd08db152677bbfdb..e392f3fdc9b87c34f068743fff7ea486b19fa393 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.27.1") // 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 885c6b8c82d46f8e21eb648441dba10c3f3a99f6..7b494af5736c2036d4810f304eb238b531f3c47f 100644
|
|
--- a/src/main/java/net/minecraft/server/network/ServerLoginPacketListenerImpl.java
|
|
+++ b/src/main/java/net/minecraft/server/network/ServerLoginPacketListenerImpl.java
|
|
@@ -92,6 +92,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;
|
|
@@ -319,7 +324,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..ca342af5e5b305fe9f8ecb88d06af63426f11f87
|
|
--- /dev/null
|
|
+++ b/src/main/java/org/dreeam/leaf/config/modules/misc/Cache.java
|
|
@@ -0,0 +1,29 @@
|
|
+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, config.pickStringRegionBased("""
|
|
+ Cache the player profile result on they first join.
|
|
+ It's useful if Mojang's verification server is down.""",
|
|
+ """
|
|
+ 玩家首次加入时缓存 PlayerProfile.
|
|
+ 正版验证服务器宕机时非常有用."""));
|
|
+ cachePlayerProfileResultTimeout = config.getInt(getBasePath() + ".cache-player-profile-result-timeout", cachePlayerProfileResultTimeout,
|
|
+ config.pickStringRegionBased(
|
|
+ "The timeout of the cache. Unit: Minutes.",
|
|
+ "缓存过期时间. 单位: 分钟."
|
|
+ ));
|
|
+ }
|
|
+}
|