mirror of
https://github.com/PaperMC/Paper.git
synced 2024-12-02 15:33:43 +01:00
Fix CommandRegisteredEvent not called
This commit is contained in:
parent
06e69c8991
commit
d9fb3effa1
123
patches/server/1051-Fix-CommandRegisteredEvent-not-called.patch
Normal file
123
patches/server/1051-Fix-CommandRegisteredEvent-not-called.patch
Normal file
@ -0,0 +1,123 @@
|
||||
From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001
|
||||
From: Jason Penilla <11360596+jpenilla@users.noreply.github.com>
|
||||
Date: Wed, 29 May 2024 13:15:43 -0700
|
||||
Subject: [PATCH] Fix CommandRegisteredEvent not called
|
||||
|
||||
|
||||
diff --git a/src/main/java/io/papermc/paper/command/brigadier/bukkit/BukkitBrigForwardingMap.java b/src/main/java/io/papermc/paper/command/brigadier/bukkit/BukkitBrigForwardingMap.java
|
||||
index f0cc27640bb3db275295a298d608c9d9f88df617..604438b10e3746837cda26cbf0ae21056f05c245 100644
|
||||
--- a/src/main/java/io/papermc/paper/command/brigadier/bukkit/BukkitBrigForwardingMap.java
|
||||
+++ b/src/main/java/io/papermc/paper/command/brigadier/bukkit/BukkitBrigForwardingMap.java
|
||||
@@ -3,7 +3,6 @@ package io.papermc.paper.command.brigadier.bukkit;
|
||||
import com.google.common.collect.Iterators;
|
||||
import com.mojang.brigadier.CommandDispatcher;
|
||||
import com.mojang.brigadier.tree.CommandNode;
|
||||
-import com.mojang.brigadier.tree.LiteralCommandNode;
|
||||
import io.papermc.paper.command.brigadier.CommandSourceStack;
|
||||
import io.papermc.paper.command.brigadier.PaperBrigadier;
|
||||
import io.papermc.paper.command.brigadier.PaperCommands;
|
||||
@@ -95,7 +94,10 @@ public class BukkitBrigForwardingMap extends HashMap<String, Command> {
|
||||
public Command put(String key, Command value) {
|
||||
Command old = this.get(key);
|
||||
this.getDispatcher().getRoot().removeCommand(key); // Override previous command
|
||||
- this.getDispatcher().getRoot().addChild(BukkitCommandNode.of(key, value));
|
||||
+ final BukkitCommandNode node = BukkitCommandNode.create(key, value, this.getDispatcher());
|
||||
+ if (node != null) {
|
||||
+ this.getDispatcher().getRoot().addChild(node);
|
||||
+ }
|
||||
return old;
|
||||
}
|
||||
|
||||
diff --git a/src/main/java/io/papermc/paper/command/brigadier/bukkit/BukkitCommandNode.java b/src/main/java/io/papermc/paper/command/brigadier/bukkit/BukkitCommandNode.java
|
||||
index 10a113b057b0a4d27cce3bae975e1108aaa7b517..ca9572bc5d742978932118b7703e807c67ecc9a8 100644
|
||||
--- a/src/main/java/io/papermc/paper/command/brigadier/bukkit/BukkitCommandNode.java
|
||||
+++ b/src/main/java/io/papermc/paper/command/brigadier/bukkit/BukkitCommandNode.java
|
||||
@@ -1,6 +1,7 @@
|
||||
package io.papermc.paper.command.brigadier.bukkit;
|
||||
|
||||
import co.aikar.timings.Timing;
|
||||
+import com.mojang.brigadier.CommandDispatcher;
|
||||
import com.mojang.brigadier.arguments.StringArgumentType;
|
||||
import com.mojang.brigadier.builder.RequiredArgumentBuilder;
|
||||
import com.mojang.brigadier.context.CommandContext;
|
||||
@@ -8,8 +9,15 @@ import com.mojang.brigadier.exceptions.CommandSyntaxException;
|
||||
import com.mojang.brigadier.suggestion.SuggestionProvider;
|
||||
import com.mojang.brigadier.suggestion.Suggestions;
|
||||
import com.mojang.brigadier.suggestion.SuggestionsBuilder;
|
||||
+import com.mojang.brigadier.tree.ArgumentCommandNode;
|
||||
+import com.mojang.brigadier.tree.CommandNode;
|
||||
import com.mojang.brigadier.tree.LiteralCommandNode;
|
||||
+import com.mojang.brigadier.tree.RootCommandNode;
|
||||
import io.papermc.paper.command.brigadier.CommandSourceStack;
|
||||
+import java.util.Arrays;
|
||||
+import java.util.List;
|
||||
+import java.util.concurrent.CompletableFuture;
|
||||
+import java.util.logging.Level;
|
||||
import net.minecraft.commands.CommandSource;
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.ChatColor;
|
||||
@@ -22,6 +30,8 @@ import java.util.Arrays;
|
||||
import java.util.List;
|
||||
import java.util.concurrent.CompletableFuture;
|
||||
import java.util.logging.Level;
|
||||
+import org.bukkit.craftbukkit.CraftServer;
|
||||
+import org.bukkit.craftbukkit.command.BukkitCommandWrapper;
|
||||
|
||||
public class BukkitCommandNode extends LiteralCommandNode<CommandSourceStack> {
|
||||
|
||||
@@ -43,16 +53,48 @@ public class BukkitCommandNode extends LiteralCommandNode<CommandSourceStack> {
|
||||
this.command = command;
|
||||
}
|
||||
|
||||
- public static BukkitCommandNode of(String name, Command command) {
|
||||
+ private static BukkitCommandNode convert(
|
||||
+ LiteralCommandNode<CommandSourceStack> node, Command command, BukkitBrigCommand bukkitBrigCommand
|
||||
+ ) {
|
||||
+ if (node instanceof BukkitCommandNode alreadyBukkit) {
|
||||
+ return alreadyBukkit;
|
||||
+ }
|
||||
+ BukkitCommandNode newNode = new BukkitCommandNode(node.getName(), command, bukkitBrigCommand);
|
||||
+ for (final CommandNode<CommandSourceStack> child : node.getChildren()) {
|
||||
+ newNode.addChild(child);
|
||||
+ }
|
||||
+ return newNode;
|
||||
+ }
|
||||
+
|
||||
+ @SuppressWarnings({"rawtypes", "removal", "deprecation", "unchecked"})
|
||||
+ public static BukkitCommandNode create(String name, Command command, CommandDispatcher<CommandSourceStack> dispatcher) {
|
||||
BukkitBrigCommand bukkitBrigCommand = new BukkitBrigCommand(command, name);
|
||||
- BukkitCommandNode commandNode = new BukkitCommandNode(name, command, bukkitBrigCommand);
|
||||
- commandNode.addChild(
|
||||
+ LiteralCommandNode<CommandSourceStack> commandNode = new BukkitCommandNode(name, command, bukkitBrigCommand);
|
||||
+ ArgumentCommandNode<CommandSourceStack, String> defaultArgs =
|
||||
RequiredArgumentBuilder.<CommandSourceStack, String>argument("args", StringArgumentType.greedyString())
|
||||
.suggests(new BukkitBrigSuggestionProvider(command, name))
|
||||
- .executes(bukkitBrigCommand).build()
|
||||
- );
|
||||
-
|
||||
- return commandNode;
|
||||
+ .executes(bukkitBrigCommand)
|
||||
+ .build();
|
||||
+ commandNode.addChild(defaultArgs);
|
||||
+ LiteralCommandNode<CommandSourceStack> defaultNode = commandNode;
|
||||
+ com.destroystokyo.paper.event.brigadier.CommandRegisteredEvent<net.minecraft.commands.CommandSourceStack> event =
|
||||
+ new com.destroystokyo.paper.event.brigadier.CommandRegisteredEvent<>(
|
||||
+ name,
|
||||
+ new BukkitCommandWrapper(((CraftServer) Bukkit.getServer()), command),
|
||||
+ command,
|
||||
+ (RootCommandNode) dispatcher.getRoot(),
|
||||
+ (LiteralCommandNode) commandNode,
|
||||
+ (ArgumentCommandNode) defaultArgs
|
||||
+ );
|
||||
+ if (!event.callEvent()) {
|
||||
+ return null;
|
||||
+ }
|
||||
+ commandNode = (LiteralCommandNode) event.getLiteral();
|
||||
+ if (event.isRawCommand()) {
|
||||
+ defaultNode.clientNode = (LiteralCommandNode) commandNode;
|
||||
+ commandNode = defaultNode;
|
||||
+ }
|
||||
+ return convert(commandNode, command, bukkitBrigCommand);
|
||||
}
|
||||
|
||||
public Command getBukkitCommand() {
|
Loading…
Reference in New Issue
Block a user