From 57bd89c06dc5fb8fcb18f8ba9dd1d64d89a55ecf Mon Sep 17 00:00:00 2001
From: Owen1212055 <23108066+Owen1212055@users.noreply.github.com>
Date: Mon, 1 Aug 2022 22:52:29 -0400
Subject: [PATCH 01/27] Brig
Update
Rebased
Rebase
mark COMMANDS lifecycle event as blocking reloads
re-fire event for plugins after bukkit reload
move command reloading up
Update and rebase
rebase
clean up examples in TestPlugin
switch to lifecycle events
rebased + javadoc + style changes
fix compile issues
refactor to not rely on MinecraftServer.getServer()
update brig
cleanup
fix plugin command overrides
add range arguments
some refactoring
Unwrap custom argument types
Make BasicCommand even more basic
Remove use of brig types for BasicCommand
fix issue with redirected sub commands not running requires checks
Add color and heightmap arg types
Add requirement for redirects
fix issue with redirect root command not being applied
rework command registration
Rebuild
Fix
Add some utilitites + new api
Remove deprecations
Fixes
Rework api a bit
Resolve conflicts
Fix removal logic
Update command builder
Cleanup
Some resolves
Rename methods, add validation to constructor
Revert "Pull #7387"
This reverts commit b2fc9b47fdb7b6ed87bac423e5abdfbb481ebb5f.
Pull #7387
Remove class usage in resolve argument utility
Fix alias, smart usage, and overriding issues
Add resolver utility
Fix splitting getting rid of trailing spaces
Wtf is this?
Fix tests
Fix arguments + unknown command event logic
Support dispatcher reloading with bukkit commands
Assume true if unexpected command source is used to check conditions.
Properly remove legacy command aliases/namespaced names
Don't recreate collections, prefer mirroring + support mutability
Diff cleanup
Improve example command + update docs
Fix tests + cleanup
Cleanup + fix test
Documentation + redirect sending fixes
Signing support
Use only 1 dispatcher + shadow node
one dispatcher
Rebase + bukkit test
Work
More work
Initial work
---
.../brigadier/BukkitBrigadierCommand.java | 2 +
.../BukkitBrigadierCommandSource.java | 4 +
.../AsyncPlayerSendCommandsEvent.java | 2 +
.../brigadier/CommandRegisteredEvent.java | 2 +
.../paper/brigadier/PaperBrigadier.java | 7 +-
.../brigadier/PaperBrigadierProvider.java | 30 -
.../0474-Brigadier-based-command-API.patch | 1197 ++++++++
...d-missing-default-perms-for-commands.patch | 6 +-
.../1060-Brigadier-based-command-API.patch | 2506 +++++++++++++++++
.../io/papermc/testplugin/TestPlugin.java | 110 +
.../testplugin/TestPluginBootstrap.java | 47 +
.../ComponentCommandExceptionType.java | 25 +
.../example/ExampleAdminCommand.java | 153 +
.../testplugin/example/IceCreamType.java | 9 +
.../example/IceCreamTypeArgument.java | 48 +
.../example/MaterialArgumentType.java | 88 +
16 files changed, 4203 insertions(+), 33 deletions(-)
delete mode 100644 Paper-MojangAPI/src/main/java/io/papermc/paper/brigadier/PaperBrigadierProvider.java
create mode 100644 patches/api/0474-Brigadier-based-command-API.patch
create mode 100644 patches/server/1060-Brigadier-based-command-API.patch
create mode 100644 test-plugin/src/main/java/io/papermc/testplugin/example/ComponentCommandExceptionType.java
create mode 100644 test-plugin/src/main/java/io/papermc/testplugin/example/ExampleAdminCommand.java
create mode 100644 test-plugin/src/main/java/io/papermc/testplugin/example/IceCreamType.java
create mode 100644 test-plugin/src/main/java/io/papermc/testplugin/example/IceCreamTypeArgument.java
create mode 100644 test-plugin/src/main/java/io/papermc/testplugin/example/MaterialArgumentType.java
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 0b1af3a8d45d..515595d589ed 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
@@ -9,6 +9,8 @@
* Brigadier {@link Command}, {@link SuggestionProvider}, and permission checker for Bukkit {@link Command}s.
*
* @param command source type
+ * @deprecated For removal, use the new brigadier api.
*/
+@Deprecated(forRemoval = true) // Paper
public interface BukkitBrigadierCommand extends Command, Predicate, SuggestionProvider {
}
diff --git a/Paper-MojangAPI/src/main/java/com/destroystokyo/paper/brigadier/BukkitBrigadierCommandSource.java b/Paper-MojangAPI/src/main/java/com/destroystokyo/paper/brigadier/BukkitBrigadierCommandSource.java
index 7a0e81658cc2..904c56acd3e2 100644
--- a/Paper-MojangAPI/src/main/java/com/destroystokyo/paper/brigadier/BukkitBrigadierCommandSource.java
+++ b/Paper-MojangAPI/src/main/java/com/destroystokyo/paper/brigadier/BukkitBrigadierCommandSource.java
@@ -6,6 +6,10 @@
import org.bukkit.entity.Entity;
import org.jetbrains.annotations.Nullable;
+/**
+ * @deprecated For removal, use the new brigadier api.
+ */
+@Deprecated(forRemoval = true) // Paper
public interface BukkitBrigadierCommandSource {
@Nullable
diff --git a/Paper-MojangAPI/src/main/java/com/destroystokyo/paper/event/brigadier/AsyncPlayerSendCommandsEvent.java b/Paper-MojangAPI/src/main/java/com/destroystokyo/paper/event/brigadier/AsyncPlayerSendCommandsEvent.java
index 495b0f0d2f29..3513ec81a4ea 100644
--- a/Paper-MojangAPI/src/main/java/com/destroystokyo/paper/event/brigadier/AsyncPlayerSendCommandsEvent.java
+++ b/Paper-MojangAPI/src/main/java/com/destroystokyo/paper/event/brigadier/AsyncPlayerSendCommandsEvent.java
@@ -28,8 +28,10 @@
*
If your logic is not safe to run asynchronously, only react to the synchronous version.
* *This is a draft/experimental API and is subject to change.
+ * @deprecated For removal, use the new brigadier api. */ @ApiStatus.Experimental +@Deprecated public class AsyncPlayerSendCommandsEventThis is a draft/experimental API and is subject to change.
+ * @deprecated For removal, use the new brigadier api. */ @ApiStatus.Experimental +@Deprecated public class CommandRegisteredEventNote: This is a delicate API that must be used with care to ensure a consistent user experience.
++ * ++ *When registering commands, it should be preferred to use {@link #register(PluginMeta, LiteralCommandNode, String, List) register methods} ++ * over directly registering to the dispatcher wherever possible. {@link #register(PluginMeta, LiteralCommandNode, String, List) Register methods} ++ * automatically handle command namespacing, command help, plugin association with commands, and more.
++ * ++ *Example use cases for this method may include: ++ *
Commands have certain the overriding behavior of: ++ *
Commands have certain the overriding behavior of: ++ *
Commands have certain the overriding behavior of: ++ *
Commands have certain the overriding behavior of: ++ *
Commands have certain the overriding behavior of: ++ *
++ * These provide rich argument parsing on the client and
++ * may also provide additional signing context.
++ */
++@ApiStatus.Experimental
++public final class ArgumentTypes {
++
++ static final @NotNull VanillaArgumentProvider PROVIDER = ServiceLoader.load(VanillaArgumentProvider.class)
++ .findFirst()
++ .orElseThrow();
++
++ @ApiStatus.Internal
++ ArgumentTypes() {
++ }
++
++ /**
++ * Represents a selector that can capture any
++ * entity.
++ *
++ * @return argument that takes one entity
++ */
++ public static @NotNull ArgumentType
++ * When extending this class, you have to implement your own parsing logic. If
++ * you want to have the command value parsed into the native type and then
++ * converted to your custom type, use {@link Converted}.
++ *
++ * @param
++ * The parsed native type will be converted via the implementation of
++ * {@link #convert(Object)}. Use {@link CustomArgumentType} if you want
++ * to handle parsing the type yourself.
++ *
++ * @param
++ * In the case that signed message information isn't provided, a "system"
++ * signed message will be provided instead.
++ * @param argumentName argument name
++ * @param context context
++ * @return signed message
++ * @throws CommandSyntaxException syntax exception
++ */
++ @NotNull CompletableFuture
++ * The reason for this is conversion is we do NOT want there to be NMS types
++ * in the api. This allows us to reconstruct the nodes to be more api friendly, while
++ * we can then unwrap it when needed and convert them to NMS types.
++ *
++ * Command nodes such as vanilla (those without a proper "api node")
++ * will be assigned a {@link ShadowBrigNode}.
++ * This prevents certain parts of it (children) from being accessed by the api.
++ */
++public abstract class ApiMirrorRootNode extends RootCommandNode
++ * However, if it doesn't seem to have a wrapped version we will return
++ * a {@link ShadowBrigNode} instead. This supports being unwrapped/wrapped while
++ * preventing the API from accessing it unsafely.
++ *
++ * @param unwrapped argument node
++ * @return wrapped node
++ */
++ private @Nullable CommandNode {
++
++ private final ArgumentType context type
++ */
++ @Override
++ default @NotNull CompletableFuture context, final @NotNull SuggestionsBuilder builder) {
++ return ArgumentType.super.listSuggestions(context, builder);
++ }
++
++ /**
++ * An argument type that wraps around a native-to-vanilla argument type.
++ * This argument is special in that the underlying native argument type
++ * will be sent to the client.
++ * > {
++}
+diff --git a/src/main/java/io/papermc/paper/command/brigadier/argument/resolvers/selector/PlayerSelectorArgumentResolver.java b/src/main/java/io/papermc/paper/command/brigadier/argument/resolvers/selector/PlayerSelectorArgumentResolver.java
+new file mode 100644
+index 0000000000000000000000000000000000000000..ecd7d56d80d64e1fef61dc39072bffb516b724a3
+--- /dev/null
++++ b/src/main/java/io/papermc/paper/command/brigadier/argument/resolvers/selector/PlayerSelectorArgumentResolver.java
+@@ -0,0 +1,10 @@
++package io.papermc.paper.command.brigadier.argument.resolvers.selector;
++
++import java.util.List;
++import org.bukkit.entity.Player;
++import org.jetbrains.annotations.ApiStatus;
++
++@ApiStatus.Experimental
++@ApiStatus.NonExtendable
++public interface PlayerSelectorArgumentResolver extends SelectorArgumentResolver
> {
++}
+diff --git a/src/main/java/io/papermc/paper/command/brigadier/argument/resolvers/selector/SelectorArgumentResolver.java b/src/main/java/io/papermc/paper/command/brigadier/argument/resolvers/selector/SelectorArgumentResolver.java
+new file mode 100644
+index 0000000000000000000000000000000000000000..20fd1eca4775c4b56b717f78af4986ba68e06f76
+--- /dev/null
++++ b/src/main/java/io/papermc/paper/command/brigadier/argument/resolvers/selector/SelectorArgumentResolver.java
+@@ -0,0 +1,14 @@
++package io.papermc.paper.command.brigadier.argument.resolvers.selector;
++
++import io.papermc.paper.command.brigadier.argument.resolvers.ArgumentResolver;
++import org.jetbrains.annotations.ApiStatus;
++
++/**
++ * Represents a selector argument which requires
++ * the context of a command source stack to be fully resolved.
++ * @param
{
+ }
+
+ private String getSmartUsage(final CommandNode node, final S source, final boolean optional, final boolean deep) {
+- if (!node.canUse(source)) {
++ if (source != null && !node.canUse(source)) { // Paper
+ return null;
+ }
+
+@@ -473,7 +473,7 @@ public class CommandDispatcher {
+ final String redirect = node.getRedirect() == this.root ? "..." : "-> " + node.getRedirect().getUsageText();
+ return self + CommandDispatcher.ARGUMENT_SEPARATOR + redirect;
+ } else {
+- final Collection implements Comparable command;
+ public LiteralCommandNode implements Comparable CompletableFuture context, final SuggestionsBuilder builder) {
++ return this.nmsBase.listSuggestions(context, builder);
++ }
++
++ @Override
++ public Collection