aboutsummaryrefslogtreecommitdiffhomepage
path: root/Spigot-Server-Patches/0446-Async-command-map-building.patch
blob: 953f418632953b238ff031032e99a4480b1501d9 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
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


diff --git a/src/main/java/net/minecraft/server/CommandDispatcher.java b/src/main/java/net/minecraft/server/CommandDispatcher.java
index e6030512dbbfac3c2ab29e20562ad666f7608295..1229aaf19de60f1e3ce161b5c3b7ef659d14c018 100644
--- a/src/main/java/net/minecraft/server/CommandDispatcher.java
+++ b/src/main/java/net/minecraft/server/CommandDispatcher.java
@@ -242,6 +242,14 @@ public class CommandDispatcher {
         if ( org.spigotmc.SpigotConfig.tabComplete < 0 ) return; // Spigot
         // CraftBukkit start
         // Register Vanilla commands into builtRoot as before
+        // Paper start - Async command map building
+        java.util.concurrent.ForkJoinPool.commonPool().execute(() -> {
+            sendAsync(entityplayer);
+        });
+    }
+
+    private void sendAsync(EntityPlayer entityplayer) {
+        // Paper end - Async command map building
         Map<CommandNode<CommandListenerWrapper>, CommandNode<ICompletionProvider>> map = Maps.newIdentityHashMap(); // Use identity to prevent aliasing issues
         RootCommandNode vanillaRoot = new RootCommandNode();
 
@@ -259,7 +267,14 @@ public class CommandDispatcher {
         for (CommandNode node : rootcommandnode.getChildren()) {
             bukkit.add(node.getName());
         }
+        // Paper start - Async command map building
+        MinecraftServer.getServer().execute(() -> {
+           runSync(entityplayer, bukkit, rootcommandnode);
+        });
+    }
 
+    private void runSync(EntityPlayer entityplayer, Collection<String> bukkit, RootCommandNode<ICompletionProvider> rootcommandnode) {
+        // Paper end - Async command map building
         PlayerCommandSendEvent event = new PlayerCommandSendEvent(entityplayer.getBukkitEntity(), new LinkedHashSet<>(bukkit));
         event.getPlayer().getServer().getPluginManager().callEvent(event);