2021-06-11 12:02:28 +00: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 11:32:17 +00: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 12:02:28 +00:00
|
|
|
|
|
|
|
diff --git a/src/main/java/net/minecraft/commands/Commands.java b/src/main/java/net/minecraft/commands/Commands.java
|
2022-08-10 03:51:17 +00:00
|
|
|
index 2bf67468a6c745bc6243c65210477ba129bfcb07..c4315531f93f4ed68b4621157b02572886e1ed30 100644
|
2021-06-11 12:02:28 +00:00
|
|
|
--- a/src/main/java/net/minecraft/commands/Commands.java
|
|
|
|
+++ b/src/main/java/net/minecraft/commands/Commands.java
|
2022-08-10 03:51:17 +00:00
|
|
|
@@ -360,6 +360,24 @@ public class Commands {
|
2021-06-11 12:02:28 +00:00
|
|
|
if ( org.spigotmc.SpigotConfig.tabComplete < 0 ) return; // Spigot
|
|
|
|
// CraftBukkit start
|
|
|
|
// Register Vanilla commands into builtRoot as before
|
|
|
|
+ // Paper start - Async command map building
|
2022-08-08 11:32:17 +00:00
|
|
|
+ COMMAND_SENDING_POOL.execute(() -> {
|
|
|
|
+ this.sendAsync(player);
|
|
|
|
+ });
|
2021-06-11 12:02:28 +00:00
|
|
|
+ }
|
|
|
|
+
|
2022-08-08 11:32:17 +00: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 03:51:17 +00:00
|
|
|
+ .build(),
|
|
|
|
+ new java.util.concurrent.ThreadPoolExecutor.DiscardPolicy()
|
2022-08-08 11:32:17 +00:00
|
|
|
+ );
|
|
|
|
+
|
2021-08-26 16:41:22 +00:00
|
|
|
+ private void sendAsync(ServerPlayer player) {
|
2021-06-11 12:02:28 +00:00
|
|
|
+ // Paper end - Async command map building
|
|
|
|
Map<CommandNode<CommandSourceStack>, CommandNode<SharedSuggestionProvider>> map = Maps.newIdentityHashMap(); // Use identity to prevent aliasing issues
|
|
|
|
RootCommandNode vanillaRoot = new RootCommandNode();
|
|
|
|
|
2022-08-10 03:51:17 +00:00
|
|
|
@@ -377,7 +395,14 @@ public class Commands {
|
2021-06-11 12:02:28 +00:00
|
|
|
for (CommandNode node : rootcommandnode.getChildren()) {
|
|
|
|
bukkit.add(node.getName());
|
|
|
|
}
|
|
|
|
+ // Paper start - Async command map building
|
2022-08-08 11:32:17 +00:00
|
|
|
+ net.minecraft.server.MinecraftServer.getServer().execute(() -> {
|
2021-08-26 16:41:22 +00:00
|
|
|
+ runSync(player, bukkit, rootcommandnode);
|
2021-06-11 12:02:28 +00:00
|
|
|
+ });
|
|
|
|
+ }
|
|
|
|
|
2021-08-26 16:41:22 +00:00
|
|
|
+ private void runSync(ServerPlayer player, Collection<String> bukkit, RootCommandNode<SharedSuggestionProvider> rootcommandnode) {
|
2021-06-11 12:02:28 +00:00
|
|
|
+ // Paper end - Async command map building
|
2021-08-26 16:41:22 +00:00
|
|
|
PlayerCommandSendEvent event = new PlayerCommandSendEvent(player.getBukkitEntity(), new LinkedHashSet<>(bukkit));
|
2021-06-11 12:02:28 +00:00
|
|
|
event.getPlayer().getServer().getPluginManager().callEvent(event);
|
|
|
|
|
2022-08-08 11:32:17 +00:00
|
|
|
diff --git a/src/main/java/net/minecraft/server/MinecraftServer.java b/src/main/java/net/minecraft/server/MinecraftServer.java
|
2022-10-02 07:56:36 +00:00
|
|
|
index 44b70cef867093979e5481bee4d60676bdca6d47..acc9f22a1284cea2e29f3616598f8388f0a0e6f6 100644
|
2022-08-08 11:32:17 +00:00
|
|
|
--- a/src/main/java/net/minecraft/server/MinecraftServer.java
|
|
|
|
+++ b/src/main/java/net/minecraft/server/MinecraftServer.java
|
2022-09-26 08:02:51 +00:00
|
|
|
@@ -889,6 +889,7 @@ public abstract class MinecraftServer extends ReentrantBlockableEventLoop<TickTa
|
2022-08-08 11:32:17 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
MinecraftServer.LOGGER.info("Stopping server");
|
|
|
|
+ Commands.COMMAND_SENDING_POOL.shutdownNow(); // Paper - Shutdown and don't bother finishing
|
|
|
|
MinecraftTimings.stopServer(); // Paper
|
|
|
|
// CraftBukkit start
|
|
|
|
if (this.server != null) {
|