From a15152e96a0c1f8b8f6792f4308e8077e01614d2 Mon Sep 17 00:00:00 2001
From: Jason <11360596+jpenilla@users.noreply.github.com>
Date: Sat, 6 Aug 2022 16:22:51 -0700
Subject: [PATCH] Allow old behavior for CommandRegisteredEvent (#8249)
---
.../brigadier/BukkitBrigadierCommand.java | 5 +
.../brigadier/CommandRegisteredEvent.java | 94 ++++++++++++++-----
.../0298-Implement-Brigadier-Mojang-API.patch | 37 +++++++-
...-brigadier-child-sorting-performance.patch | 4 +-
...-Vanilla-Command-permission-checking.patch | 4 +-
...from-signs-not-firing-command-events.patch | 4 +-
...y-type-tags-suggestions-in-selectors.patch | 6 +-
7 files changed, 116 insertions(+), 38 deletions(-)
diff --git a/Paper-MojangAPI/src/main/java/com/destroystokyo/paper/brigadier/BukkitBrigadierCommand.java b/Paper-MojangAPI/src/main/java/com/destroystokyo/paper/brigadier/BukkitBrigadierCommand.java
index 3848933b6..0b1af3a8d 100644
--- a/Paper-MojangAPI/src/main/java/com/destroystokyo/paper/brigadier/BukkitBrigadierCommand.java
+++ b/Paper-MojangAPI/src/main/java/com/destroystokyo/paper/brigadier/BukkitBrigadierCommand.java
@@ -5,5 +5,10 @@ import com.mojang.brigadier.suggestion.SuggestionProvider;
import java.util.function.Predicate;
+/**
+ * Brigadier {@link Command}, {@link SuggestionProvider}, and permission checker for Bukkit {@link Command}s.
+ *
+ * @param command source type
+ */
public interface BukkitBrigadierCommand extends Command, Predicate, SuggestionProvider {
}
diff --git a/Paper-MojangAPI/src/main/java/com/destroystokyo/paper/event/brigadier/CommandRegisteredEvent.java b/Paper-MojangAPI/src/main/java/com/destroystokyo/paper/event/brigadier/CommandRegisteredEvent.java
index 7bfa71f15..b7e09256a 100644
--- a/Paper-MojangAPI/src/main/java/com/destroystokyo/paper/event/brigadier/CommandRegisteredEvent.java
+++ b/Paper-MojangAPI/src/main/java/com/destroystokyo/paper/event/brigadier/CommandRegisteredEvent.java
@@ -13,18 +13,17 @@ import org.bukkit.event.server.ServerEvent;
import org.jetbrains.annotations.NotNull;
/**
- * Fired anytime the server synchronizes Bukkit CommandMap to Brigadier.
+ * Fired anytime the server synchronizes Bukkit commands to Brigadier.
*
- * Allows a plugin to control the Literal and Argument nodes for this command to be
- * sent to the client.
- * This is done at Plugin Enable time after commands have been registered, but some
- * plugins may use reflection to retrigger this rebuild during runtime.
+ * Allows a plugin to control the command node structure for its commands.
+ * This is done at Plugin Enable time after commands have been registered, but may also
+ * run at a later point in the server lifetime due to plugins, a server reload, etc.
*
* @deprecated Draft API - Subject to change until confirmed solves desired use cases
*/
@Deprecated
@Warning(false)
-public class CommandRegisteredEvent extends ServerEvent implements Cancellable {
+public class CommandRegisteredEvent extends ServerEvent implements Cancellable {
private static final HandlerList handlers = new HandlerList();
private final String commandLabel;
@@ -33,6 +32,7 @@ public class CommandRegisteredEvent ext
private final RootCommandNode root;
private final ArgumentCommandNode defaultArgs;
private LiteralCommandNode literal;
+ private boolean rawCommand = false;
private boolean cancelled = false;
public CommandRegisteredEvent(String commandLabel, BukkitBrigadierCommand brigadierCommand, Command command, RootCommandNode root, LiteralCommandNode literal, ArgumentCommandNode defaultArgs) {
@@ -45,55 +45,99 @@ public class CommandRegisteredEvent ext
}
/**
- * @return The command name being registered
+ * Gets the command label of the {@link Command} being registered.
+ *
+ * @return the command label
*/
public String getCommandLabel() {
- return commandLabel;
+ return this.commandLabel;
}
/**
- * @return The Bukkit API Brigadier Wrapped Command Object to handle executions and suggestions
+ * Gets the {@link BukkitBrigadierCommand} for the {@link Command} being registered. This can be used
+ * as the {@link com.mojang.brigadier.Command command executor} or
+ * {@link com.mojang.brigadier.suggestion.SuggestionProvider} of a {@link com.mojang.brigadier.tree.CommandNode}
+ * to delegate to the {@link Command} being registered.
+ *
+ * @return the {@link BukkitBrigadierCommand}
*/
public BukkitBrigadierCommand getBrigadierCommand() {
- return brigadierCommand;
- }
-
- public Command getCommand() {
- return command;
+ return this.brigadierCommand;
}
/**
- * @return Gets the root command node being used to register a command to.
+ * Gets the {@link Command} being registered.
+ *
+ * @return the {@link Command}
+ */
+ public Command getCommand() {
+ return this.command;
+ }
+
+ /**
+ * Gets the {@link RootCommandNode} which is being registered to.
+ *
+ * @return the {@link RootCommandNode}
*/
public RootCommandNode getRoot() {
- return root;
+ return this.root;
}
/**
- * Returns the Bukkit API's default handling of Arguments, if you wish to reuse it.
- * @return
+ * Gets the Bukkit APIs default arguments node (greedy string), for if
+ * you wish to reuse it.
+ *
+ * @return default arguments node
*/
public ArgumentCommandNode getDefaultArgs() {
- return defaultArgs;
+ return this.defaultArgs;
}
/**
- * Returns the Bukkit API's default literal for this command, including the {@link #getDefaultArgs()} as a child already.
- * @return
+ * Gets the {@link LiteralCommandNode} to be registered for the {@link Command}.
+ *
+ * @return the {@link LiteralCommandNode}
*/
public LiteralCommandNode getLiteral() {
- return literal;
+ return this.literal;
}
/**
- * Changes the literal used to register this command. The previous literable is mutable, so this is primarily if
- * you want to completely replace the object.
- * @param literal
+ * Sets the {@link LiteralCommandNode} used to register this command. The default literal is mutable, so
+ * this is primarily if you want to completely replace the object.
+ *
+ * @param literal new node
*/
public void setLiteral(LiteralCommandNode literal) {
this.literal = literal;
}
+ /**
+ * Gets whether this command should is treated as "raw".
+ *
+ * @see #setRawCommand(boolean)
+ * @return whether this command is treated as "raw"
+ */
+ public boolean isRawCommand() {
+ return this.rawCommand;
+ }
+
+ /**
+ * Sets whether this command should be treated as "raw".
+ *
+ *
A "raw" command will only use the node provided by this event for + * sending the command tree to the client. For execution purposes, the default + * greedy string execution of a standard Bukkit {@link Command} is used.
+ * + *On older versions of Paper, this was the default and only behavior of this + * event.
+ * + * @param rawCommand whether this command should be treated as "raw" + */ + public void setRawCommand(final boolean rawCommand) { + this.rawCommand = rawCommand; + } + /** * {@inheritDoc} */ diff --git a/patches/server/0298-Implement-Brigadier-Mojang-API.patch b/patches/server/0298-Implement-Brigadier-Mojang-API.patch index c48ac178e..295727c04 100644 --- a/patches/server/0298-Implement-Brigadier-Mojang-API.patch +++ b/patches/server/0298-Implement-Brigadier-Mojang-API.patch @@ -21,6 +21,18 @@ index 6dbac0f93481256dd57e76630ae9eea9d5c56849..e260462933a9f7065b2360e6bf9e4ee5 // Paper start implementation("org.jline:jline-terminal-jansi:3.21.0") implementation("net.minecrell:terminalconsoleappender:1.3.0") +diff --git a/src/main/java/com/mojang/brigadier/tree/CommandNode.java b/src/main/java/com/mojang/brigadier/tree/CommandNode.java +index da6250df1c5f3385b683cffde47754bca4606f5e..3384501f83d445f45aa8233e98c7597daa67b8ef 100644 +--- a/src/main/java/com/mojang/brigadier/tree/CommandNode.java ++++ b/src/main/java/com/mojang/brigadier/tree/CommandNode.java +@@ -34,6 +34,7 @@ public abstract class CommandNode