Skip to content

Commit

Permalink
Use caffeine cache kickPermission instead of using google.common.cache
Browse files Browse the repository at this point in the history
  • Loading branch information
Dreeam-qwq committed Jun 23, 2024
1 parent 0c93068 commit cca79a7
Show file tree
Hide file tree
Showing 2 changed files with 38 additions and 21 deletions.
26 changes: 5 additions & 21 deletions patches/server/0066-Cache-player-profileResult.patch
Original file line number Diff line number Diff line change
Expand Up @@ -20,38 +20,22 @@ index 989cf44a97e046ff5204184a5ae42504814aebd8..d0e1f73ef1b543c3ad32874dbda0aedf
implementation("org.jline:jline-terminal-jansi:3.26.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 00d8b8d4d2d1c73c4eeeaa9483cca2999df65a54..19d1ab56e1fbf64f786c756043ce995f3333e4b7 100644
index 00d8b8d4d2d1c73c4eeeaa9483cca2999df65a54..db5d35143ae97bd9e040b3c893b582c03dd18d77 100644
--- a/src/main/java/net/minecraft/server/network/ServerLoginPacketListenerImpl.java
+++ b/src/main/java/net/minecraft/server/network/ServerLoginPacketListenerImpl.java
@@ -1,5 +1,7 @@
package net.minecraft.server.network;

+import com.github.benmanes.caffeine.cache.Cache;
+import com.github.benmanes.caffeine.cache.Caffeine;
import com.google.common.primitives.Ints;
import com.mojang.authlib.GameProfile;
import com.mojang.authlib.exceptions.AuthenticationUnavailableException;
@@ -11,6 +13,7 @@ import java.net.InetSocketAddress;
import java.net.SocketAddress;
import java.security.PrivateKey;
import java.util.Objects;
+import java.util.concurrent.TimeUnit;
import java.util.concurrent.atomic.AtomicInteger;
import javax.annotation.Nullable;
import javax.crypto.Cipher;
@@ -88,6 +91,11 @@ public class ServerLoginPacketListenerImpl implements ServerLoginPacketListener,
@@ -88,6 +88,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 Cache<String, ProfileResult> playerProfileResultCahce = Caffeine.newBuilder()
+ .expireAfterWrite(org.dreeam.leaf.config.modules.misc.Cache.cachePlayerProfileResultTimeout, TimeUnit.MINUTES)
+ 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;
@@ -313,7 +321,19 @@ public class ServerLoginPacketListenerImpl implements ServerLoginPacketListener,
@@ -313,7 +318,19 @@ public class ServerLoginPacketListenerImpl implements ServerLoginPacketListener,
String s1 = (String) Objects.requireNonNull(ServerLoginPacketListenerImpl.this.requestedUsername, "Player name not initialized");

try {
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001
From: Dreeam <61569423+Dreeam-qwq@users.noreply.github.com>
Date: Sun, 23 Jun 2024 11:26:20 +0800
Subject: [PATCH] Use caffeine cache kickPermission instead of using
google.common.cache


diff --git a/src/main/java/net/minecraft/server/network/ServerGamePacketListenerImpl.java b/src/main/java/net/minecraft/server/network/ServerGamePacketListenerImpl.java
index 1dcf131335fbeb19f6e01dee921587075df1231c..8b0578423b7107fb9152cc258fd082cf13aa9ab9 100644
--- a/src/main/java/net/minecraft/server/network/ServerGamePacketListenerImpl.java
+++ b/src/main/java/net/minecraft/server/network/ServerGamePacketListenerImpl.java
@@ -338,17 +338,12 @@ public class ServerGamePacketListenerImpl extends ServerCommonPacketListenerImpl
// CraftBukkit end

// Purpur start
- private final com.google.common.cache.LoadingCache<CraftPlayer, Boolean> kickPermissionCache = com.google.common.cache.CacheBuilder.newBuilder()
+ // Leaf start - Use caffeine cache kickPermission instead of using google.common.cache
+ private final com.github.benmanes.caffeine.cache.Cache<CraftPlayer, Boolean> kickPermissionCache = com.github.benmanes.caffeine.cache.Caffeine.newBuilder()
.maximumSize(1000)
.expireAfterWrite(1, java.util.concurrent.TimeUnit.MINUTES)
- .build(
- new com.google.common.cache.CacheLoader<>() {
- @Override
- public Boolean load(CraftPlayer player) {
- return player.hasPermission("purpur.bypassIdleKick");
- }
- }
- );
+ .build(player -> player.hasPermission("purpur.bypassIdleKick"));
+ // Leaf - Use caffeine cache kickPermission instead of using google.common.cache
// Purpur end

@Override

0 comments on commit cca79a7

Please sign in to comment.