From fa737884a73e83740ae7c50a0f7926d95d6be09e Mon Sep 17 00:00:00 2001 From: Owen1212055 <23108066+Owen1212055@users.noreply.github.com> Date: Mon, 8 Aug 2022 07:32:17 -0400 Subject: [PATCH] Separate Command Sending to Separate Thread Pool (#8170) --- .../server/Async-command-map-building.patch | 39 ++++++++++++++----- .../Implement-Brigadier-Mojang-API.patch | 2 +- 2 files changed, 30 insertions(+), 11 deletions(-) diff --git a/patches/server/Async-command-map-building.patch b/patches/server/Async-command-map-building.patch index 87998e40da..d166b6b6b8 100644 --- a/patches/server/Async-command-map-building.patch +++ b/patches/server/Async-command-map-building.patch @@ -3,27 +3,34 @@ From: Callahan Date: Wed, 8 Apr 2020 02:42:14 -0500 Subject: [PATCH] Async command map building +This adds a custom pool inorder to make sure that they are closed +without much though, as it doesn't matter if the client is not sent +commands if the server is restarting. Using the default async pool caused issues to arise +due to the shutdown logic generally being much later. diff --git a/src/main/java/net/minecraft/commands/Commands.java b/src/main/java/net/minecraft/commands/Commands.java index 0000000000000000000000000000000000000000..0000000000000000000000000000000000000000 100644 --- a/src/main/java/net/minecraft/commands/Commands.java +++ b/src/main/java/net/minecraft/commands/Commands.java -@@ -0,0 +0,0 @@ import net.minecraft.network.chat.ComponentUtils; - import net.minecraft.network.chat.HoverEvent; - import net.minecraft.network.chat.MutableComponent; - import net.minecraft.network.protocol.game.ClientboundCommandsPacket; -+import net.minecraft.server.MinecraftServer; - import net.minecraft.server.commands.AdvancementCommands; - import net.minecraft.server.commands.AttributeCommand; - import net.minecraft.server.commands.BanIpCommands; @@ -0,0 +0,0 @@ public class Commands { if ( org.spigotmc.SpigotConfig.tabComplete < 0 ) return; // Spigot // CraftBukkit start // Register Vanilla commands into builtRoot as before + // Paper start - Async command map building -+ net.minecraft.server.MCUtil.scheduleAsyncTask(() -> this.sendAsync(player)); ++ COMMAND_SENDING_POOL.execute(() -> { ++ this.sendAsync(player); ++ }); + } + ++ public static final java.util.concurrent.ThreadPoolExecutor COMMAND_SENDING_POOL = new java.util.concurrent.ThreadPoolExecutor( ++ 0, 2, 60L, java.util.concurrent.TimeUnit.SECONDS, ++ new java.util.concurrent.LinkedBlockingQueue<>(), ++ new com.google.common.util.concurrent.ThreadFactoryBuilder() ++ .setNameFormat("Paper Async Command Builder Thread Pool - %1$d") ++ .setUncaughtExceptionHandler(new net.minecraft.DefaultUncaughtExceptionHandlerWithName(net.minecraft.server.MinecraftServer.LOGGER)) ++ .build() ++ ); ++ + private void sendAsync(ServerPlayer player) { + // Paper end - Async command map building Map, CommandNode> map = Maps.newIdentityHashMap(); // Use identity to prevent aliasing issues @@ -34,7 +41,7 @@ index 0000000000000000000000000000000000000000..00000000000000000000000000000000 bukkit.add(node.getName()); } + // Paper start - Async command map building -+ MinecraftServer.getServer().execute(() -> { ++ net.minecraft.server.MinecraftServer.getServer().execute(() -> { + runSync(player, bukkit, rootcommandnode); + }); + } @@ -44,3 +51,15 @@ index 0000000000000000000000000000000000000000..00000000000000000000000000000000 PlayerCommandSendEvent event = new PlayerCommandSendEvent(player.getBukkitEntity(), new LinkedHashSet<>(bukkit)); event.getPlayer().getServer().getPluginManager().callEvent(event); +diff --git a/src/main/java/net/minecraft/server/MinecraftServer.java b/src/main/java/net/minecraft/server/MinecraftServer.java +index 0000000000000000000000000000000000000000..0000000000000000000000000000000000000000 100644 +--- a/src/main/java/net/minecraft/server/MinecraftServer.java ++++ b/src/main/java/net/minecraft/server/MinecraftServer.java +@@ -0,0 +0,0 @@ public abstract class MinecraftServer extends ReentrantBlockableEventLoop(player.getBukkitEntity(), (RootCommandNode) rootcommandnode, false).callEvent(); // Paper - MinecraftServer.getServer().execute(() -> { + net.minecraft.server.MinecraftServer.getServer().execute(() -> { runSync(player, bukkit, rootcommandnode); }); @@ -0,0 +0,0 @@ public class Commands {