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
|
|
|
|
|
|
|
|
|
|
|
|
diff --git a/src/main/java/net/minecraft/commands/Commands.java b/src/main/java/net/minecraft/commands/Commands.java
|
2021-07-18 07:41:53 +00:00
|
|
|
index 780f46c8fdbaafaca6babfa34ebd97f420d0d612..81146c07dad098a88d8bd3867d0aaf5c15e33961 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
|
|
|
|
@@ -29,6 +29,7 @@ import net.minecraft.network.chat.MutableComponent;
|
|
|
|
import net.minecraft.network.chat.TextComponent;
|
|
|
|
import net.minecraft.network.chat.TranslatableComponent;
|
|
|
|
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;
|
2021-06-14 01:06:38 +00:00
|
|
|
@@ -335,25 +336,40 @@ 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
|
|
|
|
+ java.util.concurrent.ForkJoinPool.commonPool().execute(() -> {
|
|
|
|
+ sendAsync(player);
|
|
|
|
+ });
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ private void sendAsync(ServerPlayer entityplayer) {
|
|
|
|
+ // Paper end - Async command map building
|
|
|
|
Map<CommandNode<CommandSourceStack>, CommandNode<SharedSuggestionProvider>> map = Maps.newIdentityHashMap(); // Use identity to prevent aliasing issues
|
|
|
|
RootCommandNode vanillaRoot = new RootCommandNode();
|
|
|
|
|
|
|
|
- RootCommandNode<CommandSourceStack> vanilla = player.server.vanillaCommandDispatcher.getDispatcher().getRoot();
|
|
|
|
+ RootCommandNode<CommandSourceStack> vanilla = entityplayer.server.vanillaCommandDispatcher.getDispatcher().getRoot();
|
|
|
|
map.put(vanilla, vanillaRoot);
|
|
|
|
- this.fillUsableCommands(vanilla, vanillaRoot, player.createCommandSourceStack(), (Map) map);
|
|
|
|
+ this.fillUsableCommands(vanilla, vanillaRoot, entityplayer.createCommandSourceStack(), (Map) map);
|
|
|
|
|
|
|
|
// Now build the global commands in a second pass
|
|
|
|
RootCommandNode<SharedSuggestionProvider> rootcommandnode = new RootCommandNode();
|
|
|
|
|
|
|
|
map.put(this.dispatcher.getRoot(), rootcommandnode);
|
|
|
|
- this.fillUsableCommands(this.dispatcher.getRoot(), rootcommandnode, player.createCommandSourceStack(), (Map) map);
|
|
|
|
+ this.fillUsableCommands(this.dispatcher.getRoot(), rootcommandnode, entityplayer.createCommandSourceStack(), (Map) map);
|
|
|
|
|
|
|
|
Collection<String> bukkit = new LinkedHashSet<>();
|
|
|
|
for (CommandNode node : rootcommandnode.getChildren()) {
|
|
|
|
bukkit.add(node.getName());
|
|
|
|
}
|
|
|
|
+ // Paper start - Async command map building
|
|
|
|
+ MinecraftServer.getServer().execute(() -> {
|
|
|
|
+ runSync(entityplayer, bukkit, rootcommandnode);
|
|
|
|
+ });
|
|
|
|
+ }
|
|
|
|
|
|
|
|
- PlayerCommandSendEvent event = new PlayerCommandSendEvent(player.getBukkitEntity(), new LinkedHashSet<>(bukkit));
|
|
|
|
+ private void runSync(ServerPlayer entityplayer, Collection<String> bukkit, RootCommandNode<SharedSuggestionProvider> rootcommandnode) {
|
|
|
|
+ // Paper end - Async command map building
|
|
|
|
+ PlayerCommandSendEvent event = new PlayerCommandSendEvent(entityplayer.getBukkitEntity(), new LinkedHashSet<>(bukkit));
|
|
|
|
event.getPlayer().getServer().getPluginManager().callEvent(event);
|
|
|
|
|
|
|
|
// Remove labels that were removed during the event
|
2021-06-14 01:06:38 +00:00
|
|
|
@@ -363,7 +379,7 @@ public class Commands {
|
2021-06-11 12:02:28 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
// CraftBukkit end
|
|
|
|
- player.connection.send(new ClientboundCommandsPacket(rootcommandnode));
|
|
|
|
+ entityplayer.connection.send(new ClientboundCommandsPacket(rootcommandnode));
|
|
|
|
}
|
|
|
|
|
|
|
|
private void fillUsableCommands(CommandNode<CommandSourceStack> tree, CommandNode<SharedSuggestionProvider> result, CommandSourceStack source, Map<CommandNode<CommandSourceStack>, CommandNode<SharedSuggestionProvider>> resultNodes) {
|