Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save electronicboy/9e89c9898e0ec2347ece8adc292f8e5b to your computer and use it in GitHub Desktop.
Save electronicboy/9e89c9898e0ec2347ece8adc292f8e5b to your computer and use it in GitHub Desktop.
From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001
From: Shane Freeder <theboyetronic@gmail.com>
Date: Thu, 2 Jun 2022 01:42:43 +0100
Subject: [PATCH] Configurable chat thread limit
diff --git a/src/main/java/com/destroystokyo/paper/PaperConfig.java b/src/main/java/com/destroystokyo/paper/PaperConfig.java
index fafbebbb5e8c1a381b673f97f1fa210687b52823..af95a648a03af1be265e11f4fb236ac19fcaf379 100644
--- a/src/main/java/com/destroystokyo/paper/PaperConfig.java
+++ b/src/main/java/com/destroystokyo/paper/PaperConfig.java
@@ -693,4 +693,23 @@ public class PaperConfig {
private static void useProxyProtocol() {
useProxyProtocol = getBoolean("settings.proxy-protocol", false);
}
+
+ private static void chatThreads() {
+ int chatExecutorCoreSize = getInt("settings.chat-threads-core", -1);
+ int chatExecutorMaxSize = getInt("settings.chat-threads-max", -1);
+ if (chatExecutorMaxSize <= 0) chatExecutorMaxSize = Integer.MAX_VALUE; // This is somewhat dumb, but, this is the default, do we cap this?
+
+ if (chatExecutorCoreSize <= 0) {
+ chatExecutorCoreSize = 0;
+ }
+
+ if (chatExecutorMaxSize < chatExecutorCoreSize) {
+ logError("chat-threads-max is lower than chat-threads-max core size! Defaulting to core size...");
+ chatExecutorMaxSize = chatExecutorCoreSize;
+ }
+
+ java.util.concurrent.ThreadPoolExecutor executor = ((java.util.concurrent.ThreadPoolExecutor) net.minecraft.network.protocol.game.ServerboundChatPacket.executors);
+ executor.setCorePoolSize(chatExecutorCoreSize);
+ executor.setMaximumPoolSize(chatExecutorMaxSize);
+ }
}
diff --git a/src/main/java/net/minecraft/network/protocol/game/ServerboundChatPacket.java b/src/main/java/net/minecraft/network/protocol/game/ServerboundChatPacket.java
index 21588ce5a408fed3454c317b56c05439ad3af27d..4cfefd280c1814435c2286dba35fac2c244292ed 100644
--- a/src/main/java/net/minecraft/network/protocol/game/ServerboundChatPacket.java
+++ b/src/main/java/net/minecraft/network/protocol/game/ServerboundChatPacket.java
@@ -26,7 +26,7 @@ public class ServerboundChatPacket implements Packet<ServerGamePacketListener> {
}
// Spigot Start
- private static final java.util.concurrent.ExecutorService executors = java.util.concurrent.Executors.newCachedThreadPool(
+ public static final java.util.concurrent.ExecutorService executors = java.util.concurrent.Executors.newCachedThreadPool( // Paper - make public
new com.google.common.util.concurrent.ThreadFactoryBuilder().setDaemon( true ).setNameFormat( "Async Chat Thread - #%d" ).setUncaughtExceptionHandler(new net.minecraft.DefaultUncaughtExceptionHandlerWithName(net.minecraft.server.MinecraftServer.LOGGER)).build() ); // Paper
public void handle(final ServerGamePacketListener listener) {
if ( !this.message.startsWith("/") )
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment