2021-06-11 14:02:28 +02:00
|
|
|
From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001
|
|
|
|
From: Callahan <mr.callahhh@gmail.com>
|
|
|
|
Date: Wed, 8 Apr 2020 02:42:14 -0500
|
|
|
|
Subject: [PATCH] Async command map building
|
|
|
|
|
2022-08-08 13:32:17 +02:00
|
|
|
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.
|
2021-06-11 14:02:28 +02:00
|
|
|
|
|
|
|
diff --git a/src/main/java/net/minecraft/commands/Commands.java b/src/main/java/net/minecraft/commands/Commands.java
|
2024-04-27 08:17:58 +02:00
|
|
|
index eec5279ac4386132fa053c57889e32e6b8141614..b754c0b3e2cd878fca5f702daca64f837ec83451 100644
|
2021-06-11 14:02:28 +02:00
|
|
|
--- a/src/main/java/net/minecraft/commands/Commands.java
|
|
|
|
+++ b/src/main/java/net/minecraft/commands/Commands.java
|
2024-04-27 08:17:58 +02:00
|
|
|
@@ -452,6 +452,24 @@ public class Commands {
|
2021-06-11 14:02:28 +02:00
|
|
|
if ( org.spigotmc.SpigotConfig.tabComplete < 0 ) return; // Spigot
|
|
|
|
// CraftBukkit start
|
|
|
|
// Register Vanilla commands into builtRoot as before
|
2024-01-21 13:56:22 +01:00
|
|
|
+ // Paper start - Perf: Async command map building
|
2022-08-08 13:32:17 +02:00
|
|
|
+ COMMAND_SENDING_POOL.execute(() -> {
|
|
|
|
+ this.sendAsync(player);
|
|
|
|
+ });
|
2021-06-11 14:02:28 +02:00
|
|
|
+ }
|
|
|
|
+
|
2022-08-08 13:32:17 +02:00
|
|
|
+ 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))
|
2022-08-10 05:51:17 +02:00
|
|
|
+ .build(),
|
|
|
|
+ new java.util.concurrent.ThreadPoolExecutor.DiscardPolicy()
|
2022-08-08 13:32:17 +02:00
|
|
|
+ );
|
|
|
|
+
|
2021-08-26 18:41:22 +02:00
|
|
|
+ private void sendAsync(ServerPlayer player) {
|
2024-01-21 13:56:22 +01:00
|
|
|
+ // Paper end - Perf: Async command map building
|
2021-06-11 14:02:28 +02:00
|
|
|
Map<CommandNode<CommandSourceStack>, CommandNode<SharedSuggestionProvider>> map = Maps.newIdentityHashMap(); // Use identity to prevent aliasing issues
|
|
|
|
RootCommandNode vanillaRoot = new RootCommandNode();
|
|
|
|
|
2024-04-27 08:17:58 +02:00
|
|
|
@@ -469,7 +487,14 @@ public class Commands {
|
2021-06-11 14:02:28 +02:00
|
|
|
for (CommandNode node : rootcommandnode.getChildren()) {
|
|
|
|
bukkit.add(node.getName());
|
|
|
|
}
|
2024-01-21 13:56:22 +01:00
|
|
|
+ // Paper start - Perf: Async command map building
|
2022-08-08 13:32:17 +02:00
|
|
|
+ net.minecraft.server.MinecraftServer.getServer().execute(() -> {
|
2021-08-26 18:41:22 +02:00
|
|
|
+ runSync(player, bukkit, rootcommandnode);
|
2021-06-11 14:02:28 +02:00
|
|
|
+ });
|
|
|
|
+ }
|
|
|
|
|
2021-08-26 18:41:22 +02:00
|
|
|
+ private void runSync(ServerPlayer player, Collection<String> bukkit, RootCommandNode<SharedSuggestionProvider> rootcommandnode) {
|
2024-01-21 13:56:22 +01:00
|
|
|
+ // Paper end - Perf: Async command map building
|
2021-08-26 18:41:22 +02:00
|
|
|
PlayerCommandSendEvent event = new PlayerCommandSendEvent(player.getBukkitEntity(), new LinkedHashSet<>(bukkit));
|
2021-06-11 14:02:28 +02:00
|
|
|
event.getPlayer().getServer().getPluginManager().callEvent(event);
|
|
|
|
|
2022-08-08 13:32:17 +02:00
|
|
|
diff --git a/src/main/java/net/minecraft/server/MinecraftServer.java b/src/main/java/net/minecraft/server/MinecraftServer.java
|
2024-04-27 01:17:13 +02:00
|
|
|
index 65e9ac5ba7237e97e286953568f28db86d244d1e..4f4e662e8f21e92b49c3d3811a24f9acedde9fff 100644
|
2022-08-08 13:32:17 +02:00
|
|
|
--- a/src/main/java/net/minecraft/server/MinecraftServer.java
|
|
|
|
+++ b/src/main/java/net/minecraft/server/MinecraftServer.java
|
2024-04-24 07:43:09 +02:00
|
|
|
@@ -927,6 +927,7 @@ public abstract class MinecraftServer extends ReentrantBlockableEventLoop<TickTa
|
2022-08-08 13:32:17 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
MinecraftServer.LOGGER.info("Stopping server");
|
2024-01-21 13:56:22 +01:00
|
|
|
+ Commands.COMMAND_SENDING_POOL.shutdownNow(); // Paper - Perf: Async command map building; Shutdown and don't bother finishing
|
2022-08-08 13:32:17 +02:00
|
|
|
MinecraftTimings.stopServer(); // Paper
|
|
|
|
// CraftBukkit start
|
|
|
|
if (this.server != null) {
|