diff options
author | Nassim Jahnke <[email protected]> | 2024-07-14 14:04:38 +0200 |
---|---|---|
committer | GitHub <[email protected]> | 2024-07-14 14:04:38 +0200 |
commit | 34a2917dccd1a39888c85badd7cf7aad7c44ff61 (patch) | |
tree | 969bef118a439471074210089a8a05795c627f9e /patches/api | |
parent | 1595e4afc097ad595cf10106044774170f779701 (diff) | |
download | Paper-34a2917dccd1a39888c85badd7cf7aad7c44ff61.tar.gz Paper-34a2917dccd1a39888c85badd7cf7aad7c44ff61.zip |
Add default canUse and permission methods to BasicCommand (#11047)
Diffstat (limited to 'patches/api')
-rw-r--r-- | patches/api/0469-Brigadier-based-command-API.patch | 28 |
1 files changed, 26 insertions, 2 deletions
diff --git a/patches/api/0469-Brigadier-based-command-API.patch b/patches/api/0469-Brigadier-based-command-API.patch index a47c1b82c5..9e99f07ecd 100644 --- a/patches/api/0469-Brigadier-based-command-API.patch +++ b/patches/api/0469-Brigadier-based-command-API.patch @@ -502,16 +502,18 @@ index 0000000000000000000000000000000000000000..9df87708206e26167a2c4934deff7fc6 +} diff --git a/src/main/java/io/papermc/paper/command/brigadier/BasicCommand.java b/src/main/java/io/papermc/paper/command/brigadier/BasicCommand.java new file mode 100644 -index 0000000000000000000000000000000000000000..0f6b921b4bcf983cf25188823f78a061eec5263d +index 0000000000000000000000000000000000000000..99a9a5ecc5010bcd30351f8844cb5d824c252523 --- /dev/null +++ b/src/main/java/io/papermc/paper/command/brigadier/BasicCommand.java -@@ -0,0 +1,36 @@ +@@ -0,0 +1,60 @@ +package io.papermc.paper.command.brigadier; + +import java.util.Collection; +import java.util.Collections; ++import org.bukkit.command.CommandSender; +import org.jetbrains.annotations.ApiStatus; +import org.jetbrains.annotations.NotNull; ++import org.jetbrains.annotations.Nullable; + +/** + * Implementing this interface allows for easily creating "Bukkit-style" {@code String[] args} commands. @@ -541,6 +543,28 @@ index 0000000000000000000000000000000000000000..0f6b921b4bcf983cf25188823f78a061 + default @NotNull Collection<String> suggest(final @NotNull CommandSourceStack commandSourceStack, final @NotNull String[] args) { + return Collections.emptyList(); + } ++ ++ /** ++ * Checks whether a command sender can receive and run the root command. ++ * ++ * @param sender the command sender trying to execute the command ++ * @return whether the command sender fulfills the root command requirement ++ * @see #permission() ++ */ ++ @ApiStatus.OverrideOnly ++ default boolean canUse(final @NotNull CommandSender sender) { ++ return this.permission() == null || sender.hasPermission(this.permission()); ++ } ++ ++ /** ++ * Returns the permission for the root command used in {@link #canUse(CommandSender)} by default. ++ * ++ * @return the permission for the root command used in {@link #canUse(CommandSender)} ++ */ ++ @ApiStatus.OverrideOnly ++ default @Nullable String permission() { ++ return null; ++ } +} diff --git a/src/main/java/io/papermc/paper/command/brigadier/CommandRegistrationFlag.java b/src/main/java/io/papermc/paper/command/brigadier/CommandRegistrationFlag.java new file mode 100644 |