From 9a0120aef20525ac3580efdb674f87189ad49356 Mon Sep 17 00:00:00 2001 From: BuildTools <46540330+willkroboth@users.noreply.github.com> Date: Mon, 3 Jun 2024 14:22:07 -0400 Subject: [PATCH] Executor Rewrite Note: This commit makes this branch backwards incompatible, especially for non-DSL Kotlin code (see `commandapi-documentation-code/.../Examples.kt`). "Standard" Java and DSL API code usage looks the same, but I'm pretty sure plugins will need to recompile due to changes to the `FunctionalInterface`s. There are also some smaller public API changes, mentioned below. Notable changes: - Removed `AbstractCommandSender` and all its implemenations (i.e. the `dev.jorel.commandapi.commandsenders` package is completely gone) - Logic in `CommandAPIHandler#generateBrigadierRequirements` for checking if a sender satisfies a `CommandPermission` was moved to `CommandAPIPlatform#getPermissionCheck` - Previously, methods in `AbstractCommandSender` provided access to `hasPermission` and `isOp`. `CommandAPIBukkit` and `CommandAPIVelocity` now handle these definitions. - `CommandPermission.TRUE()` and `CommandPermission.FALSE()` added for computing short circuits when combining permissions and requirements - `PreviewInfo` now has the generic parameter `Player` rather than an `AbstractPlayer` - Backwards-incompatible (`(Player) player.getSource()` becomes `player`) - Generic parameter propogates to `PreviewableFunction` and `Previewable` - `CommandAPIPlatform` methods for convert Brigadier Source to CommandSender simplified - `getSenderForCommand` removed - just pass `CommandContext#getSource` into `getCommandSenderFromCommandSource` - `forceNative` parameter was only used on Bukkit, which is now handled by `NMS#getNativeProxyCommandSender` (more on that below) - `wrapCommandSender` removed - Wrapping the sender no longer necessary for `getBrigadierSourceFromCommandSender` - `CommandAPIVelocity` now does nothing in these methods :P - `CommandAPIExecutor` reworked - `ExecutorType` moved to platform modules (so Velocity can no longer try to define sender types that don't exist) - Detecting whether a certain executor can be run by the given class delegated to `BukkitTypedExecutor` and `VelocityTypedExecutor` - Priority of executors now depends on order of calling the `executes` methods (i.e the priority listed here https://commandapi.jorel.dev/9.4.1/normalexecutors.html#multiple-command-executor-implementations no longer applies) - Normal executors are no longer ignored if resulting executors exist (not sure if this was a bug or intended) - Tweaked `ExecutionInfo` - Added `CommandContext cmdCtx` to `ExecutionInfo` - This allows passing the information needed for a `NATIVE` executor on Bukkit to create a `NativeProxyCommandSender` - Uses `NMS#getNativeProxyCommandSender`, which was adapted from the removed `getSenderForCommand` method - Note: conflicts with https://github.com/JorelAli/CommandAPI/pull/478, though should be easily resolved - Note: Velocity can define the `CommandSource` object, though Bukkit has it as `?`. This makes it hard for non DSL Kotlin to infer the type parameters for some reason, which is annoying because you now need to specify the type parameter. I don't know if there's a better way to handle that. - TODO: Make sure depdendents can still use `ExecutionInfo` without including Brigadier as a dependency - `ExecutionInfo` is now a record (`BukkitExecutionInfo` and `VelocityExecutionInfo` removed) - Simplified `dev.jorel.commandapi.executors` package - Platform and sender specific executor classes (e.g. `PlayerCommandExecutor` and `EntityResultingExecutionInfo`) removed - Just the functional interfaces `NormalExecutorInfo`, `NormalExecutor`, `ResultingExecutorInfo`, and `ResultingExecutor` now - `BukkitExecutable` and `VelocityExecutable` link different command sender classes as type parameters to the `ExecutorType` enum values TODO: - Add executor tests to `dev/dev` to ensure same behavior - Especially for `PROXY` and `NATIVE` senders - Especially for non-DSL Kotlin to see how its lamdba type inference works - Update documentation --- .../java/dev/jorel/commandapi/Brigadier.java | 15 +- .../java/dev/jorel/commandapi/CommandAPI.java | 6 +- .../jorel/commandapi/CommandAPIExecutor.java | 164 +++------ .../jorel/commandapi/CommandAPIHandler.java | 70 +--- .../jorel/commandapi/CommandAPIPlatform.java | 50 +-- .../jorel/commandapi/CommandPermission.java | 72 ++++ .../java/dev/jorel/commandapi/Executable.java | 10 +- .../jorel/commandapi/ExecutableCommand.java | 5 +- .../jorel/commandapi/PlatformExecutable.java | 8 +- .../arguments/AbstractArgument.java | 4 +- .../commandapi/arguments/PreviewInfo.java | 6 +- .../commandapi/arguments/Previewable.java | 10 +- .../PreviewableArgumentBuilder.java | 6 +- .../commandnodes/PreviewableCommandNode.java | 6 +- .../AbstractBlockCommandSender.java | 4 - .../commandsenders/AbstractCommandSender.java | 29 -- .../AbstractConsoleCommandSender.java | 4 - .../commandsenders/AbstractEntity.java | 4 - ...stractFeedbackForwardingCommandSender.java | 4 - .../AbstractNativeProxyCommandSender.java | 4 - .../commandsenders/AbstractPlayer.java | 4 - .../AbstractProxiedCommandSender.java | 4 - .../AbstractRemoteConsoleCommandSender.java | 4 - .../commandapi/executors/ExecutionInfo.java | 40 ++- .../commandapi/executors/NormalExecutor.java | 67 ++-- .../executors/NormalExecutorInfo.java | 22 ++ .../executors/ResultingExecutor.java | 67 ++-- .../executors/ResultingExecutorInfo.java | 22 ++ .../commandapi/executors/TypedExecutor.java | 53 +-- .../wrappers/PreviewableFunction.java | 6 +- .../commandapi/examples/kotlin/Examples.kt | 263 +++++++------- .../commandapi/examples/kotlin/Examples.kt | 4 +- .../jorel/commandapi/kotlindsl/ExecutorDSL.kt | 108 ++---- .../jorel/commandapi/kotlindsl/ExecutorDSL.kt | 27 +- .../jorel/commandapi/BukkitExecutable.java | 328 +++++++----------- .../jorel/commandapi/CommandAPIBukkit.java | 94 ++--- .../java/dev/jorel/commandapi/Converter.java | 4 +- .../arguments/AdventureChatArgument.java | 15 +- .../commandapi/arguments/ChatArgument.java | 15 +- .../commandapi/arguments/CommandArgument.java | 3 +- .../commandapi/arguments/CustomArgument.java | 2 +- .../arguments/ListArgumentCommon.java | 2 +- .../BukkitBlockCommandSender.java | 28 -- .../commandsenders/BukkitCommandSender.java | 6 - .../BukkitConsoleCommandSender.java | 28 -- .../commandsenders/BukkitEntity.java | 28 -- ...BukkitFeedbackForwardingCommandSender.java | 28 -- .../BukkitNativeProxyCommandSender.java | 27 -- .../commandsenders/BukkitPlayer.java | 27 -- .../BukkitProxiedCommandSender.java | 27 -- .../BukkitRemoteConsoleCommandSender.java | 27 -- .../executors/BukkitExecutionInfo.java | 30 -- .../executors/BukkitNormalTypedExecutor.java | 33 ++ .../BukkitResultingTypedExecutor.java | 31 ++ .../executors/BukkitTypedExecutor.java | 58 ++++ .../CommandBlockCommandExecutor.java | 60 ---- .../executors/CommandBlockExecutionInfo.java | 28 -- .../CommandBlockResultingCommandExecutor.java | 65 ---- .../CommandBlockResultingExecutionInfo.java | 27 -- .../executors/CommandExecutionInfo.java | 28 -- .../commandapi/executors/CommandExecutor.java | 60 ---- .../executors/ConsoleCommandExecutor.java | 60 ---- .../executors/ConsoleExecutionInfo.java | 28 -- .../ConsoleResultingCommandExecutor.java | 62 ---- .../ConsoleResultingExecutionInfo.java | 26 -- .../executors/EntityCommandExecutor.java | 60 ---- .../executors/EntityExecutionInfo.java | 28 -- .../EntityResultingCommandExecutor.java | 61 ---- .../EntityResultingExecutionInfo.java | 27 -- ...CommandExecutor.java => ExecutorType.java} | 70 ++-- .../FeedbackForwardingCommandExecutor.java | 60 ---- .../FeedbackForwardingExecutionInfo.java | 29 -- ...ackForwardingResultingCommandExecutor.java | 65 ---- ...dbackForwardingResultingExecutionInfo.java | 28 -- .../executors/NativeCommandExecutor.java | 60 ---- .../executors/NativeExecutionInfo.java | 28 -- .../NativeResultingCommandExecutor.java | 61 ---- .../NativeResultingExecutionInfo.java | 26 -- .../executors/PlayerCommandExecutor.java | 59 ---- .../executors/PlayerExecutionInfo.java | 27 -- .../PlayerResultingCommandExecutor.java | 62 ---- .../PlayerResultingExecutionInfo.java | 24 -- .../executors/ProxyExecutionInfo.java | 28 -- .../ProxyResultingCommandExecutor.java | 62 ---- .../ProxyResultingExecutionInfo.java | 27 -- .../RemoteConsoleCommandExecutor.java | 38 -- .../executors/RemoteConsoleExecutionInfo.java | 27 -- ...RemoteConsoleResultingCommandExecutor.java | 40 --- .../RemoteConsoleResultingExecutionInfo.java | 28 -- .../ResultingCommandExecutionInfo.java | 27 -- .../executors/ResultingCommandExecutor.java | 63 ---- .../java/dev/jorel/commandapi/nms/NMS.java | 3 + .../jorel/commandapi/wrappers/Preview.java | 7 - .../commandapi/wrappers/PreviewLegacy.java | 7 - .../wrappers/SimpleFunctionWrapper.java | 2 +- .../dev/jorel/commandapi/nms/NMS_1_16_R3.java | 41 +-- .../jorel/commandapi/nms/NMS_1_17_Common.java | 33 +- .../dev/jorel/commandapi/nms/NMS_1_18_R2.java | 33 +- .../dev/jorel/commandapi/nms/NMS_1_18_R1.java | 33 +- .../jorel/commandapi/nms/NMS_1_19_Common.java | 24 +- .../NMS_1_19_Common_ChatPreviewHandler.java | 9 +- .../jorel/commandapi/nms/NMS_1_19_3_R2.java | 33 +- .../jorel/commandapi/nms/NMS_1_19_4_R3.java | 34 +- .../dev/jorel/commandapi/nms/NMS_1_20_R2.java | 34 +- .../dev/jorel/commandapi/nms/NMS_1_20_R3.java | 36 +- .../dev/jorel/commandapi/nms/NMS_1_20_R4.java | 36 +- .../dev/jorel/commandapi/nms/NMS_1_20_R1.java | 34 +- .../dev/jorel/commandapi/nms/NMS_1_21_R1.java | 36 +- .../dev/jorel/commandapi/nms/NMS_Common.java | 15 +- .../dev/jorel/commandapi/test/TestBase.kt | 4 +- .../dev/jorel/commandapi/test/MockNMS.java | 31 +- .../dev/jorel/commandapi/test/MockNMS.java | 31 +- .../dev/jorel/commandapi/test/MockNMS.java | 31 +- .../dev/jorel/commandapi/test/MockNMS.java | 31 +- .../dev/jorel/commandapi/test/MockNMS.java | 31 +- .../dev/jorel/commandapi/test/MockNMS.java | 31 +- .../dev/jorel/commandapi/test/MockNMS.java | 31 +- .../dev/jorel/commandapi/test/MockNMS.java | 31 +- .../dev/jorel/commandapi/test/MockNMS.java | 31 +- .../test/CommandConvertedTests.java | 4 +- .../test/CommandRegistrationTests.java | 6 +- .../test/RegisteredCommandTestBase.java | 2 +- .../dev/jorel/commandapi/test/TestBase.java | 5 +- .../test/arguments/ArgumentTests.java | 5 +- .../jorel/commandapi/CommandAPIVelocity.java | 59 ++-- .../jorel/commandapi/VelocityExecutable.java | 163 +++------ .../commandsenders/VelocityCommandSender.java | 6 - .../VelocityConsoleCommandSender.java | 27 -- .../commandsenders/VelocityPlayer.java | 27 -- .../executors/CommandExecutionInfo.java | 28 -- .../commandapi/executors/CommandExecutor.java | 39 --- .../executors/ConsoleCommandExecutor.java | 59 ---- .../executors/ConsoleExecutionInfo.java | 28 -- .../ConsoleResultingCommandExecutor.java | 59 ---- .../ConsoleResultingExecutionInfo.java | 27 -- .../commandapi/executors/ExecutorType.java | 46 +-- .../executors/PlayerCommandExecutor.java | 59 ---- .../executors/PlayerExecutionInfo.java | 28 -- .../PlayerResultingCommandExecutor.java | 59 ---- .../PlayerResultingExecutionInfo.java | 27 -- .../ResultingCommandExecutionInfo.java | 27 -- .../executors/ResultingCommandExecutor.java | 43 --- .../executors/VelocityExecutionInfo.java | 30 -- .../VelocityNormalTypedExecutor.java | 32 ++ .../VelocityResultingTypedExecutor.java | 30 ++ .../executors/VelocityTypedExecutor.java | 35 ++ 146 files changed, 1311 insertions(+), 3954 deletions(-) delete mode 100644 commandapi-core/src/main/java/dev/jorel/commandapi/commandsenders/AbstractBlockCommandSender.java delete mode 100644 commandapi-core/src/main/java/dev/jorel/commandapi/commandsenders/AbstractCommandSender.java delete mode 100644 commandapi-core/src/main/java/dev/jorel/commandapi/commandsenders/AbstractConsoleCommandSender.java delete mode 100644 commandapi-core/src/main/java/dev/jorel/commandapi/commandsenders/AbstractEntity.java delete mode 100644 commandapi-core/src/main/java/dev/jorel/commandapi/commandsenders/AbstractFeedbackForwardingCommandSender.java delete mode 100644 commandapi-core/src/main/java/dev/jorel/commandapi/commandsenders/AbstractNativeProxyCommandSender.java delete mode 100644 commandapi-core/src/main/java/dev/jorel/commandapi/commandsenders/AbstractPlayer.java delete mode 100644 commandapi-core/src/main/java/dev/jorel/commandapi/commandsenders/AbstractProxiedCommandSender.java delete mode 100644 commandapi-core/src/main/java/dev/jorel/commandapi/commandsenders/AbstractRemoteConsoleCommandSender.java create mode 100644 commandapi-core/src/main/java/dev/jorel/commandapi/executors/NormalExecutorInfo.java create mode 100644 commandapi-core/src/main/java/dev/jorel/commandapi/executors/ResultingExecutorInfo.java delete mode 100644 commandapi-platforms/commandapi-bukkit/commandapi-bukkit-core/src/main/java/dev/jorel/commandapi/commandsenders/BukkitBlockCommandSender.java delete mode 100644 commandapi-platforms/commandapi-bukkit/commandapi-bukkit-core/src/main/java/dev/jorel/commandapi/commandsenders/BukkitCommandSender.java delete mode 100644 commandapi-platforms/commandapi-bukkit/commandapi-bukkit-core/src/main/java/dev/jorel/commandapi/commandsenders/BukkitConsoleCommandSender.java delete mode 100644 commandapi-platforms/commandapi-bukkit/commandapi-bukkit-core/src/main/java/dev/jorel/commandapi/commandsenders/BukkitEntity.java delete mode 100644 commandapi-platforms/commandapi-bukkit/commandapi-bukkit-core/src/main/java/dev/jorel/commandapi/commandsenders/BukkitFeedbackForwardingCommandSender.java delete mode 100644 commandapi-platforms/commandapi-bukkit/commandapi-bukkit-core/src/main/java/dev/jorel/commandapi/commandsenders/BukkitNativeProxyCommandSender.java delete mode 100644 commandapi-platforms/commandapi-bukkit/commandapi-bukkit-core/src/main/java/dev/jorel/commandapi/commandsenders/BukkitPlayer.java delete mode 100644 commandapi-platforms/commandapi-bukkit/commandapi-bukkit-core/src/main/java/dev/jorel/commandapi/commandsenders/BukkitProxiedCommandSender.java delete mode 100644 commandapi-platforms/commandapi-bukkit/commandapi-bukkit-core/src/main/java/dev/jorel/commandapi/commandsenders/BukkitRemoteConsoleCommandSender.java delete mode 100644 commandapi-platforms/commandapi-bukkit/commandapi-bukkit-core/src/main/java/dev/jorel/commandapi/executors/BukkitExecutionInfo.java create mode 100644 commandapi-platforms/commandapi-bukkit/commandapi-bukkit-core/src/main/java/dev/jorel/commandapi/executors/BukkitNormalTypedExecutor.java create mode 100644 commandapi-platforms/commandapi-bukkit/commandapi-bukkit-core/src/main/java/dev/jorel/commandapi/executors/BukkitResultingTypedExecutor.java create mode 100644 commandapi-platforms/commandapi-bukkit/commandapi-bukkit-core/src/main/java/dev/jorel/commandapi/executors/BukkitTypedExecutor.java delete mode 100644 commandapi-platforms/commandapi-bukkit/commandapi-bukkit-core/src/main/java/dev/jorel/commandapi/executors/CommandBlockCommandExecutor.java delete mode 100644 commandapi-platforms/commandapi-bukkit/commandapi-bukkit-core/src/main/java/dev/jorel/commandapi/executors/CommandBlockExecutionInfo.java delete mode 100644 commandapi-platforms/commandapi-bukkit/commandapi-bukkit-core/src/main/java/dev/jorel/commandapi/executors/CommandBlockResultingCommandExecutor.java delete mode 100644 commandapi-platforms/commandapi-bukkit/commandapi-bukkit-core/src/main/java/dev/jorel/commandapi/executors/CommandBlockResultingExecutionInfo.java delete mode 100644 commandapi-platforms/commandapi-bukkit/commandapi-bukkit-core/src/main/java/dev/jorel/commandapi/executors/CommandExecutionInfo.java delete mode 100644 commandapi-platforms/commandapi-bukkit/commandapi-bukkit-core/src/main/java/dev/jorel/commandapi/executors/CommandExecutor.java delete mode 100644 commandapi-platforms/commandapi-bukkit/commandapi-bukkit-core/src/main/java/dev/jorel/commandapi/executors/ConsoleCommandExecutor.java delete mode 100644 commandapi-platforms/commandapi-bukkit/commandapi-bukkit-core/src/main/java/dev/jorel/commandapi/executors/ConsoleExecutionInfo.java delete mode 100644 commandapi-platforms/commandapi-bukkit/commandapi-bukkit-core/src/main/java/dev/jorel/commandapi/executors/ConsoleResultingCommandExecutor.java delete mode 100644 commandapi-platforms/commandapi-bukkit/commandapi-bukkit-core/src/main/java/dev/jorel/commandapi/executors/ConsoleResultingExecutionInfo.java delete mode 100644 commandapi-platforms/commandapi-bukkit/commandapi-bukkit-core/src/main/java/dev/jorel/commandapi/executors/EntityCommandExecutor.java delete mode 100644 commandapi-platforms/commandapi-bukkit/commandapi-bukkit-core/src/main/java/dev/jorel/commandapi/executors/EntityExecutionInfo.java delete mode 100644 commandapi-platforms/commandapi-bukkit/commandapi-bukkit-core/src/main/java/dev/jorel/commandapi/executors/EntityResultingCommandExecutor.java delete mode 100644 commandapi-platforms/commandapi-bukkit/commandapi-bukkit-core/src/main/java/dev/jorel/commandapi/executors/EntityResultingExecutionInfo.java rename commandapi-platforms/commandapi-bukkit/commandapi-bukkit-core/src/main/java/dev/jorel/commandapi/executors/{ProxyCommandExecutor.java => ExecutorType.java} (54%) delete mode 100644 commandapi-platforms/commandapi-bukkit/commandapi-bukkit-core/src/main/java/dev/jorel/commandapi/executors/FeedbackForwardingCommandExecutor.java delete mode 100644 commandapi-platforms/commandapi-bukkit/commandapi-bukkit-core/src/main/java/dev/jorel/commandapi/executors/FeedbackForwardingExecutionInfo.java delete mode 100644 commandapi-platforms/commandapi-bukkit/commandapi-bukkit-core/src/main/java/dev/jorel/commandapi/executors/FeedbackForwardingResultingCommandExecutor.java delete mode 100644 commandapi-platforms/commandapi-bukkit/commandapi-bukkit-core/src/main/java/dev/jorel/commandapi/executors/FeedbackForwardingResultingExecutionInfo.java delete mode 100644 commandapi-platforms/commandapi-bukkit/commandapi-bukkit-core/src/main/java/dev/jorel/commandapi/executors/NativeCommandExecutor.java delete mode 100644 commandapi-platforms/commandapi-bukkit/commandapi-bukkit-core/src/main/java/dev/jorel/commandapi/executors/NativeExecutionInfo.java delete mode 100644 commandapi-platforms/commandapi-bukkit/commandapi-bukkit-core/src/main/java/dev/jorel/commandapi/executors/NativeResultingCommandExecutor.java delete mode 100644 commandapi-platforms/commandapi-bukkit/commandapi-bukkit-core/src/main/java/dev/jorel/commandapi/executors/NativeResultingExecutionInfo.java delete mode 100644 commandapi-platforms/commandapi-bukkit/commandapi-bukkit-core/src/main/java/dev/jorel/commandapi/executors/PlayerCommandExecutor.java delete mode 100644 commandapi-platforms/commandapi-bukkit/commandapi-bukkit-core/src/main/java/dev/jorel/commandapi/executors/PlayerExecutionInfo.java delete mode 100644 commandapi-platforms/commandapi-bukkit/commandapi-bukkit-core/src/main/java/dev/jorel/commandapi/executors/PlayerResultingCommandExecutor.java delete mode 100644 commandapi-platforms/commandapi-bukkit/commandapi-bukkit-core/src/main/java/dev/jorel/commandapi/executors/PlayerResultingExecutionInfo.java delete mode 100644 commandapi-platforms/commandapi-bukkit/commandapi-bukkit-core/src/main/java/dev/jorel/commandapi/executors/ProxyExecutionInfo.java delete mode 100644 commandapi-platforms/commandapi-bukkit/commandapi-bukkit-core/src/main/java/dev/jorel/commandapi/executors/ProxyResultingCommandExecutor.java delete mode 100644 commandapi-platforms/commandapi-bukkit/commandapi-bukkit-core/src/main/java/dev/jorel/commandapi/executors/ProxyResultingExecutionInfo.java delete mode 100644 commandapi-platforms/commandapi-bukkit/commandapi-bukkit-core/src/main/java/dev/jorel/commandapi/executors/RemoteConsoleCommandExecutor.java delete mode 100644 commandapi-platforms/commandapi-bukkit/commandapi-bukkit-core/src/main/java/dev/jorel/commandapi/executors/RemoteConsoleExecutionInfo.java delete mode 100644 commandapi-platforms/commandapi-bukkit/commandapi-bukkit-core/src/main/java/dev/jorel/commandapi/executors/RemoteConsoleResultingCommandExecutor.java delete mode 100644 commandapi-platforms/commandapi-bukkit/commandapi-bukkit-core/src/main/java/dev/jorel/commandapi/executors/RemoteConsoleResultingExecutionInfo.java delete mode 100644 commandapi-platforms/commandapi-bukkit/commandapi-bukkit-core/src/main/java/dev/jorel/commandapi/executors/ResultingCommandExecutionInfo.java delete mode 100644 commandapi-platforms/commandapi-bukkit/commandapi-bukkit-core/src/main/java/dev/jorel/commandapi/executors/ResultingCommandExecutor.java delete mode 100644 commandapi-platforms/commandapi-bukkit/commandapi-bukkit-core/src/main/java/dev/jorel/commandapi/wrappers/Preview.java delete mode 100644 commandapi-platforms/commandapi-bukkit/commandapi-bukkit-core/src/main/java/dev/jorel/commandapi/wrappers/PreviewLegacy.java delete mode 100644 commandapi-platforms/commandapi-velocity/commandapi-velocity-core/src/main/java/dev/jorel/commandapi/commandsenders/VelocityCommandSender.java delete mode 100644 commandapi-platforms/commandapi-velocity/commandapi-velocity-core/src/main/java/dev/jorel/commandapi/commandsenders/VelocityConsoleCommandSender.java delete mode 100644 commandapi-platforms/commandapi-velocity/commandapi-velocity-core/src/main/java/dev/jorel/commandapi/commandsenders/VelocityPlayer.java delete mode 100644 commandapi-platforms/commandapi-velocity/commandapi-velocity-core/src/main/java/dev/jorel/commandapi/executors/CommandExecutionInfo.java delete mode 100644 commandapi-platforms/commandapi-velocity/commandapi-velocity-core/src/main/java/dev/jorel/commandapi/executors/CommandExecutor.java delete mode 100644 commandapi-platforms/commandapi-velocity/commandapi-velocity-core/src/main/java/dev/jorel/commandapi/executors/ConsoleCommandExecutor.java delete mode 100644 commandapi-platforms/commandapi-velocity/commandapi-velocity-core/src/main/java/dev/jorel/commandapi/executors/ConsoleExecutionInfo.java delete mode 100644 commandapi-platforms/commandapi-velocity/commandapi-velocity-core/src/main/java/dev/jorel/commandapi/executors/ConsoleResultingCommandExecutor.java delete mode 100644 commandapi-platforms/commandapi-velocity/commandapi-velocity-core/src/main/java/dev/jorel/commandapi/executors/ConsoleResultingExecutionInfo.java rename {commandapi-core => commandapi-platforms/commandapi-velocity/commandapi-velocity-core}/src/main/java/dev/jorel/commandapi/executors/ExecutorType.java (65%) delete mode 100644 commandapi-platforms/commandapi-velocity/commandapi-velocity-core/src/main/java/dev/jorel/commandapi/executors/PlayerCommandExecutor.java delete mode 100644 commandapi-platforms/commandapi-velocity/commandapi-velocity-core/src/main/java/dev/jorel/commandapi/executors/PlayerExecutionInfo.java delete mode 100644 commandapi-platforms/commandapi-velocity/commandapi-velocity-core/src/main/java/dev/jorel/commandapi/executors/PlayerResultingCommandExecutor.java delete mode 100644 commandapi-platforms/commandapi-velocity/commandapi-velocity-core/src/main/java/dev/jorel/commandapi/executors/PlayerResultingExecutionInfo.java delete mode 100644 commandapi-platforms/commandapi-velocity/commandapi-velocity-core/src/main/java/dev/jorel/commandapi/executors/ResultingCommandExecutionInfo.java delete mode 100644 commandapi-platforms/commandapi-velocity/commandapi-velocity-core/src/main/java/dev/jorel/commandapi/executors/ResultingCommandExecutor.java delete mode 100644 commandapi-platforms/commandapi-velocity/commandapi-velocity-core/src/main/java/dev/jorel/commandapi/executors/VelocityExecutionInfo.java create mode 100644 commandapi-platforms/commandapi-velocity/commandapi-velocity-core/src/main/java/dev/jorel/commandapi/executors/VelocityNormalTypedExecutor.java create mode 100644 commandapi-platforms/commandapi-velocity/commandapi-velocity-core/src/main/java/dev/jorel/commandapi/executors/VelocityResultingTypedExecutor.java create mode 100644 commandapi-platforms/commandapi-velocity/commandapi-velocity-core/src/main/java/dev/jorel/commandapi/executors/VelocityTypedExecutor.java diff --git a/commandapi-core/src/main/java/dev/jorel/commandapi/Brigadier.java b/commandapi-core/src/main/java/dev/jorel/commandapi/Brigadier.java index 99b0a6e423..5b137c0e87 100644 --- a/commandapi-core/src/main/java/dev/jorel/commandapi/Brigadier.java +++ b/commandapi-core/src/main/java/dev/jorel/commandapi/Brigadier.java @@ -32,7 +32,6 @@ import dev.jorel.commandapi.arguments.AbstractArgument; import dev.jorel.commandapi.arguments.ArgumentSuggestions; import dev.jorel.commandapi.arguments.Literal; -import dev.jorel.commandapi.commandsenders.AbstractCommandSender; import java.util.Collections; import java.util.List; @@ -206,19 +205,17 @@ Command fromCommand(AbstractCommandAPICommand comman */ public static Object getBrigadierSourceFromCommandSender(CommandSender sender) { CommandAPIPlatform platform = (CommandAPIPlatform) CommandAPIHandler.getInstance().getPlatform(); - return platform.getBrigadierSourceFromCommandSender(platform.wrapCommandSender(sender)); + return platform.getBrigadierSourceFromCommandSender(sender); } /** - * Returns a Bukkit CommandSender from a Brigadier CommandContext + * Returns the current platform's command sender from a Brigadier CommandContext * * @param cmdCtx the command context to get the CommandSender from - * @return a Bukkit CommandSender from the provided Brigadier CommandContext + * @return a command sender from the provided Brigadier CommandContext */ - public static CommandSender getCommandSenderFromContext(CommandContext cmdCtx) { - CommandAPIPlatform platform = (CommandAPIPlatform) CommandAPIHandler.getInstance().getPlatform(); - // For some reason putting this on one line doesn't work - very weird - AbstractCommandSender abstractSender = platform.getSenderForCommand(cmdCtx, false); - return abstractSender.getSource(); + public static CommandSender getCommandSenderFromContext(CommandContext cmdCtx) { + CommandAPIPlatform platform = (CommandAPIPlatform) CommandAPIHandler.getInstance().getPlatform(); + return platform.getCommandSenderFromCommandSource((Source) cmdCtx.getSource()); } } diff --git a/commandapi-core/src/main/java/dev/jorel/commandapi/CommandAPI.java b/commandapi-core/src/main/java/dev/jorel/commandapi/CommandAPI.java index 6d11569041..60b201be0a 100644 --- a/commandapi-core/src/main/java/dev/jorel/commandapi/CommandAPI.java +++ b/commandapi-core/src/main/java/dev/jorel/commandapi/CommandAPI.java @@ -3,7 +3,6 @@ import com.mojang.brigadier.Message; import com.mojang.brigadier.exceptions.CommandSyntaxException; import com.mojang.brigadier.exceptions.SimpleCommandExceptionType; -import dev.jorel.commandapi.commandsenders.AbstractPlayer; import dev.jorel.commandapi.exceptions.WrapperCommandSyntaxException; import java.util.ArrayList; @@ -230,14 +229,13 @@ public static void reloadDatapacks() { } /** - * Updates the requirements required for a given player to execute a command. + * Updates the player's view of the requirements for them to execute a command. * * @param player the player whose requirements should be updated */ public static void updateRequirements(Player player) { - @SuppressWarnings("unchecked") CommandAPIPlatform platform = (CommandAPIPlatform) CommandAPIHandler.getInstance().getPlatform(); - platform.updateRequirements((AbstractPlayer) platform.wrapCommandSender(player)); + platform.updateRequirements(player); } // Produce WrapperCommandSyntaxException diff --git a/commandapi-core/src/main/java/dev/jorel/commandapi/CommandAPIExecutor.java b/commandapi-core/src/main/java/dev/jorel/commandapi/CommandAPIExecutor.java index e4c616ccdf..a0c8dd041a 100644 --- a/commandapi-core/src/main/java/dev/jorel/commandapi/CommandAPIExecutor.java +++ b/commandapi-core/src/main/java/dev/jorel/commandapi/CommandAPIExecutor.java @@ -22,18 +22,14 @@ import java.util.ArrayList; import java.util.List; -import java.util.NoSuchElementException; +import java.util.Optional; import com.mojang.brigadier.LiteralMessage; import com.mojang.brigadier.exceptions.CommandSyntaxException; import com.mojang.brigadier.exceptions.SimpleCommandExceptionType; -import dev.jorel.commandapi.commandsenders.*; import dev.jorel.commandapi.exceptions.WrapperCommandSyntaxException; import dev.jorel.commandapi.executors.ExecutionInfo; -import dev.jorel.commandapi.executors.ExecutorType; -import dev.jorel.commandapi.executors.NormalExecutor; -import dev.jorel.commandapi.executors.ResultingExecutor; import dev.jorel.commandapi.executors.TypedExecutor; /** @@ -42,143 +38,67 @@ * executors) and switches its execution implementation based on the provided * command executor types. * - * @param The CommandSender for this executor - * @param The AbstractCommandSender that wraps the CommandSender + * @param The class for running platform commands */ -public class CommandAPIExecutor -/// @endcond -> { +public class CommandAPIExecutor { - private List> normalExecutors; - private List> resultingExecutors; + // Setup executors + private List> executors; public CommandAPIExecutor() { - normalExecutors = new ArrayList<>(); - resultingExecutors = new ArrayList<>(); + this.executors = new ArrayList<>(); } - @SuppressWarnings("unchecked") - public void addNormalExecutor(NormalExecutor executor) { - this.normalExecutors.add((NormalExecutor) executor); + public void addExecutor(TypedExecutor executor) { + this.executors.add(executor); } - @SuppressWarnings("unchecked") - public void addResultingExecutor(ResultingExecutor executor) { - this.resultingExecutors.add((ResultingExecutor) executor); + public void setExecutors(List> executors) { + this.executors = executors; } - public int execute(ExecutionInfo info) throws CommandSyntaxException { - // Parse executor type - if (!resultingExecutors.isEmpty()) { - // Run resulting executor - try { - return execute(resultingExecutors, info); - } catch (WrapperCommandSyntaxException e) { - throw e.getException(); - } catch (Throwable ex) { - CommandAPI.getLogger().severe("Unhandled exception executing '" + info.args().fullInput() + "'", ex); - if (ex instanceof Exception) { - throw ex; - } else { - throw new RuntimeException(ex); - } - } - } else { - // Run normal executor - try { - return execute(normalExecutors, info); - } catch (WrapperCommandSyntaxException e) { - throw e.getException(); - } catch (Throwable ex) { - CommandAPI.getLogger().severe("Unhandled exception executing '" + info.args().fullInput() + "'", ex); - if (ex instanceof Exception) { - throw ex; - } else { - throw new RuntimeException(ex); - } - } - } - } - - private int execute(List> executors, ExecutionInfo info) - throws WrapperCommandSyntaxException { - if (isForceNative()) { - return execute(executors, info, ExecutorType.NATIVE); - } else if (info.senderWrapper() instanceof AbstractPlayer && matches(executors, ExecutorType.PLAYER)) { - return execute(executors, info, ExecutorType.PLAYER); - } else if (info.senderWrapper() instanceof AbstractEntity && matches(executors, ExecutorType.ENTITY)) { - return execute(executors, info, ExecutorType.ENTITY); - } else if (info.senderWrapper() instanceof AbstractConsoleCommandSender && matches(executors, ExecutorType.CONSOLE)) { - return execute(executors, info, ExecutorType.CONSOLE); - } else if (info.senderWrapper() instanceof AbstractBlockCommandSender && matches(executors, ExecutorType.BLOCK)) { - return execute(executors, info, ExecutorType.BLOCK); - } else if (info.senderWrapper() instanceof AbstractProxiedCommandSender && matches(executors, ExecutorType.PROXY)) { - return execute(executors, info, ExecutorType.PROXY); - } else if (info.senderWrapper() instanceof AbstractRemoteConsoleCommandSender && matches(executors, ExecutorType.REMOTE)) { - return execute(executors, info, ExecutorType.REMOTE); - } else if (info.senderWrapper() instanceof AbstractFeedbackForwardingCommandSender && matches(executors, ExecutorType.FEEDBACK_FORWARDING)) { - return execute(executors, info, ExecutorType.FEEDBACK_FORWARDING); - } else if (matches(executors, ExecutorType.ALL)) { - return execute(executors, info, ExecutorType.ALL); - } else { - throw new WrapperCommandSyntaxException(new SimpleCommandExceptionType( - new LiteralMessage(CommandAPI.getConfiguration().getMissingImplementationMessage() - .replace("%s", info.sender().getClass().getSimpleName().toLowerCase()) - .replace("%S", info.sender().getClass().getSimpleName()))).create()); - } - } - - private int execute(List> executors, - ExecutionInfo info, ExecutorType type) throws WrapperCommandSyntaxException { - for (TypedExecutor executor : executors) { - if (executor.getType() == type) { - return executor.executeWith(info); - } - } - throw new NoSuchElementException("Executor had no valid executors for type " + type.toString()); - } - - public List> getNormalExecutors() { - return normalExecutors; - } - - public List> getResultingExecutors() { - return resultingExecutors; + public List> getExecutors() { + return this.executors; } public boolean hasAnyExecutors() { - return !(normalExecutors.isEmpty() && resultingExecutors.isEmpty()); - } - - public boolean isForceNative() { - return matches(normalExecutors, ExecutorType.NATIVE) || matches(resultingExecutors, ExecutorType.NATIVE); + return !executors.isEmpty(); } - private boolean matches(List> executors, ExecutorType type) { - for (TypedExecutor executor : executors) { - if (executor.getType() == type) { - return true; + // Use executors + public int execute(ExecutionInfo info) throws CommandSyntaxException { + try { + for (TypedExecutor executor : executors) { + Optional result = tryExecutor(executor, info); + + if (result.isPresent()) return result.get(); + } + } catch (WrapperCommandSyntaxException e) { + throw e.getException(); + } catch (Throwable ex) { + CommandAPI.getLogger().severe("Unhandled exception executing '" + info.args().fullInput() + "'", ex); + if (ex instanceof Exception) { + throw ex; + } else { + throw new RuntimeException(ex); } } - return false; - } - CommandAPIExecutor mergeExecutor(CommandAPIExecutor executor) { - CommandAPIExecutor result = new CommandAPIExecutor<>(); - result.normalExecutors = new ArrayList<>(normalExecutors); - result.resultingExecutors = new ArrayList<>(resultingExecutors); - result.normalExecutors.addAll(executor.normalExecutors); - result.resultingExecutors.addAll(executor.resultingExecutors); - return result; + // Executor not found + throw new SimpleCommandExceptionType(new LiteralMessage( + CommandAPI.getConfiguration().getMissingImplementationMessage() + .replace("%s", info.sender().getClass().getSimpleName().toLowerCase()) + .replace("%S", info.sender().getClass().getSimpleName()) + )).create(); } - public void setNormalExecutors(List> normalExecutors) { - this.normalExecutors = normalExecutors; - } + // This needs to be extracted into another method to name the `Sender` and `Source` generic, which allows `executeWith` to accept the converted info + private Optional tryExecutor(TypedExecutor executor, ExecutionInfo info) throws WrapperCommandSyntaxException { + ExecutionInfo convertedInfo = executor.tryForSender((ExecutionInfo) info); - public void setResultingExecutors(List> resultingExecutors) { - this.resultingExecutors = resultingExecutors; + if (convertedInfo != null) { + return Optional.of(executor.executeWith(convertedInfo)); + } + return Optional.empty(); } } \ No newline at end of file diff --git a/commandapi-core/src/main/java/dev/jorel/commandapi/CommandAPIHandler.java b/commandapi-core/src/main/java/dev/jorel/commandapi/CommandAPIHandler.java index 5f8ab70478..abc1544737 100644 --- a/commandapi-core/src/main/java/dev/jorel/commandapi/CommandAPIHandler.java +++ b/commandapi-core/src/main/java/dev/jorel/commandapi/CommandAPIHandler.java @@ -44,7 +44,6 @@ import com.mojang.brigadier.tree.ArgumentCommandNode; import com.mojang.brigadier.tree.LiteralCommandNode; import dev.jorel.commandapi.arguments.*; -import dev.jorel.commandapi.commandsenders.AbstractCommandSender; import dev.jorel.commandapi.exceptions.CommandConflictException; import dev.jorel.commandapi.executors.CommandArguments; import dev.jorel.commandapi.executors.ExecutionInfo; @@ -271,7 +270,7 @@ private void ensureNoCommandConflict(CommandNode nodeToRegister, Command * @param executor Code to run when the command is executed. * @return A Brigadier Command object that runs the given execution with the given arguments as input. */ - public Command generateBrigadierCommand(List args, CommandAPIExecutor> executor) { + public Command generateBrigadierCommand(List args, CommandAPIExecutor executor) { // We need to make sure our arguments list is never changed // If we just used the reference to the list, the caller might add arguments that aren't actually previous // arguments for this suggestion node, and we would be confused because the new arguments don't exist @@ -279,25 +278,10 @@ public Command generateBrigadierCommand(List args, CommandAPIE // Generate our command from executor return cmdCtx -> { // Construct the execution info - AbstractCommandSender sender = platform.getSenderForCommand(cmdCtx, executor.isForceNative()); + CommandSender sender = platform.getCommandSenderFromCommandSource(cmdCtx.getSource()); CommandArguments commandArguments = argsToCommandArgs(cmdCtx, immutableArguments); - ExecutionInfo> executionInfo = new ExecutionInfo<>() { - @Override - public CommandSender sender() { - return sender.getSource(); - } - - @Override - public AbstractCommandSender senderWrapper() { - return sender; - } - - @Override - public CommandArguments args() { - return commandArguments; - } - }; + ExecutionInfo executionInfo = new ExecutionInfo<>(sender, commandArguments, cmdCtx); // Apply the executor return executor.execute(executionInfo); @@ -375,7 +359,7 @@ public SuggestionProvider generateBrigadierSuggestions(List pr return (context, builder) -> { // Construct the suggestion info SuggestionInfo suggestionInfo = new SuggestionInfo<>( - platform.getCommandSenderFromCommandSource(context.getSource()).getSource(), + platform.getCommandSenderFromCommandSource(context.getSource()), argsToCommandArgs(context, immutableArguments), builder.getInput(), builder.getRemaining() ); @@ -393,44 +377,24 @@ public SuggestionProvider generateBrigadierSuggestions(List pr * @return A Predicate that makes sure a Brigadier source object satisfies the given permission and arbitrary requirements. */ public Predicate generateBrigadierRequirements(CommandPermission permission, Predicate requirements) { + // If requirements are always false, result is always false + if (requirements == CommandPermission.FALSE()) return CommandPermission.FALSE(); + // Find the intial check for the given CommandPermission - Predicate> senderCheck; - if (permission.equals(CommandPermission.NONE)) { - // No permissions always passes - senderCheck = null; - } else if (permission.equals(CommandPermission.OP)) { - // Check op status - senderCheck = AbstractCommandSender::isOp; - } else { - Optional permissionStringWrapper = permission.getPermission(); - if (permissionStringWrapper.isPresent()) { - String permissionString = permissionStringWrapper.get(); - // check permission - senderCheck = sender -> sender.hasPermission(permissionString); - } else { - // No permission always passes - senderCheck = null; - } - } + Predicate senderCheck = platform.getPermissionCheck(permission); - if (senderCheck == null) { - // Short circuit permissions check if it doesn't depend on source - if (permission.isNegated()) { - // A negated NONE permission never passes - return source -> false; - } else { - // Only need to check the requirements - return source -> requirements.test(platform.getCommandSenderFromCommandSource(source).getSource()); - } - } + // Merge with requirements (unless its always true, which wouldn't add anything) + if (requirements != CommandPermission.TRUE()) senderCheck = senderCheck.and(requirements); - // Negate permission check if appropriate - Predicate> finalSenderCheck = permission.isNegated() ? senderCheck.negate() : senderCheck; + // Short circuit if the final test is always true or false + if (senderCheck == CommandPermission.TRUE()) return CommandPermission.TRUE(); + if (senderCheck == CommandPermission.FALSE()) return CommandPermission.FALSE(); - // Merge permission check and requirements + // Otherwise, convert Brigadier Source to CommandSender and run the check + final Predicate finalSenderCheck = senderCheck; return source -> { - AbstractCommandSender sender = platform.getCommandSenderFromCommandSource(source); - return finalSenderCheck.test(sender) && requirements.test(sender.getSource()); + CommandSender sender = platform.getCommandSenderFromCommandSource(source); + return finalSenderCheck.test(sender); }; } diff --git a/commandapi-core/src/main/java/dev/jorel/commandapi/CommandAPIPlatform.java b/commandapi-core/src/main/java/dev/jorel/commandapi/CommandAPIPlatform.java index 967c05fc07..7b4e4704d2 100644 --- a/commandapi-core/src/main/java/dev/jorel/commandapi/CommandAPIPlatform.java +++ b/commandapi-core/src/main/java/dev/jorel/commandapi/CommandAPIPlatform.java @@ -2,17 +2,15 @@ import com.mojang.brigadier.CommandDispatcher; import com.mojang.brigadier.builder.LiteralArgumentBuilder; -import com.mojang.brigadier.context.CommandContext; import com.mojang.brigadier.suggestion.SuggestionProvider; import com.mojang.brigadier.tree.LiteralCommandNode; import dev.jorel.commandapi.arguments.AbstractArgument; import dev.jorel.commandapi.arguments.SuggestionProviders; -import dev.jorel.commandapi.commandsenders.AbstractCommandSender; -import dev.jorel.commandapi.commandsenders.AbstractPlayer; import java.io.File; import java.io.IOException; import java.util.List; +import java.util.function.Predicate; /** * @param The implementation of AbstractArgument used for the platform @@ -45,40 +43,22 @@ public interface CommandAPIPlatform getSenderForCommand(CommandContext cmdCtx, boolean forceNative); - - /** - * Converts the class used by Brigadier when running commands into an AbstractCommandSender wrapping the platform's CommandSender + * Converts the class used by Brigadier when running commands into the platform's CommandSender * * @param source The Brigadier source object - * @return An AbstractCommandSender wrapping the CommandSender represented by the source object + * @return The CommandSender represented by the source object */ - public abstract AbstractCommandSender getCommandSenderFromCommandSource(Source source); + public abstract CommandSender getCommandSenderFromCommandSource(Source source); /** - * Converts a CommandSender wrapped in an AbstractCommandSender to an object Brigadier can use when running its commands + * Converts a CommandSender to an object Brigadier can use when running its commands * - * @param sender The CommandSender to convert, wrapped in an AbstractCommandSender + * @param sender The CommandSender to convert * @return The Brigadier Source object represented by the sender */ - public abstract Source getBrigadierSourceFromCommandSender(AbstractCommandSender sender); - - /** - * Wraps a CommandSender in an AbstractCommandSender class, the inverse operation to {@link AbstractCommandSender#getSource()} - * - * @param sender The CommandSender to wrap - * @return An AbstractCommandSender with a class appropriate to the underlying class of the CommandSender - */ - public abstract AbstractCommandSender wrapCommandSender(CommandSender sender); + public abstract Source getBrigadierSourceFromCommandSender(CommandSender sender); // Some commands have existing suggestion providers public abstract SuggestionProvider getSuggestionProvider(SuggestionProviders suggestionProvider); @@ -196,13 +176,21 @@ public void severe(String message, Throwable throwable) { public abstract void reloadDataPacks(); /** - * Updates the requirements required for a given player to execute a command. + * Updates the player's view of the requirements for them to execute a command. * - * @param player the player to update + * @param player the player whose requirements should be updated */ - public abstract void updateRequirements(AbstractPlayer player); + public abstract void updateRequirements(CommandSender player); public abstract Argument newConcreteMultiLiteralArgument(String nodeName, String[] literals); public abstract Argument newConcreteLiteralArgument(String nodeName, String literal); + + /** + * Generates a {@link Predicate} that evaluates whether a command sender meets the given permission. + * + * @param permission The {@link CommandPermission} to check for. + * @return A {@link Predicate} that tests if a command sender meets the given permission. + */ + public abstract Predicate getPermissionCheck(CommandPermission permission); } diff --git a/commandapi-core/src/main/java/dev/jorel/commandapi/CommandPermission.java b/commandapi-core/src/main/java/dev/jorel/commandapi/CommandPermission.java index 962da1d689..fc89a84c20 100644 --- a/commandapi-core/src/main/java/dev/jorel/commandapi/CommandPermission.java +++ b/commandapi-core/src/main/java/dev/jorel/commandapi/CommandPermission.java @@ -22,6 +22,7 @@ import java.util.Objects; import java.util.Optional; +import java.util.function.Predicate; /** * A representation of permission nodes for commands. Represents permission @@ -51,6 +52,77 @@ private enum PermissionNode { */ public static final CommandPermission OP = new CommandPermission(PermissionNode.OP); + // Always true and always false Predicates allow us to short-circuit when combining predicates + // Unfortunately Java dosen't seem to have something like this built-in + // See https://bugs.openjdk.org/browse/JDK-8067971 + /** + * Returns a singleton {@link Predicate} that always returns true. When modifying this predicate + * using {@link Predicate#and(Predicate)}, {@link Predicate#negate()}, or {@link Predicate#or(Predicate)}, + * the result is short-circuited to avoid unecessarily creating and nesting predicate objects. + * + * @return A {@link Predicate} that always returns true. + */ + public static final Predicate TRUE() { + return (Predicate) TRUE; + } + + private static final Predicate TRUE = new Predicate<>() { + @Override + public boolean test(Object t) { + return true; + } + + @Override + public Predicate and(Predicate other) { + return Objects.requireNonNull(other); + } + + @Override + public Predicate negate() { + return FALSE; + } + + @Override + public Predicate or(Predicate other) { + Objects.requireNonNull(other); + return TRUE; + } + }; + + /** + * Returns a singleton {@link Predicate} that always returns false. When modifying this predicate + * using {@link Predicate#and(Predicate)}, {@link Predicate#negate()}, or {@link Predicate#or(Predicate)}, + * the result is short-circuited to avoid unecessarily creating and nesting predicate objects. + * + * @return A {@link Predicate} that always returns false + */ + public static final Predicate FALSE() { + return (Predicate) FALSE; + } + + private static final Predicate FALSE = new Predicate() { + @Override + public boolean test(Object t) { + return false; + } + + @Override + public Predicate and(Predicate other) { + Objects.requireNonNull(other); + return FALSE; + } + + @Override + public Predicate negate() { + return TRUE; + } + + @Override + public Predicate or(Predicate other) { + return Objects.requireNonNull(other); + } + }; + /** * Generates a new CommandPermission from a permission node * diff --git a/commandapi-core/src/main/java/dev/jorel/commandapi/Executable.java b/commandapi-core/src/main/java/dev/jorel/commandapi/Executable.java index 64deeb7ab2..c93418ee9b 100644 --- a/commandapi-core/src/main/java/dev/jorel/commandapi/Executable.java +++ b/commandapi-core/src/main/java/dev/jorel/commandapi/Executable.java @@ -1,7 +1,6 @@ package dev.jorel.commandapi; import dev.jorel.commandapi.arguments.AbstractArgument; -import dev.jorel.commandapi.commandsenders.AbstractCommandSender; import java.util.ArrayList; @@ -20,13 +19,13 @@ abstract class Executable> executor = new CommandAPIExecutor<>(); + protected CommandAPIExecutor executor = new CommandAPIExecutor<>(); /** * Returns the executors that this command has * @return the executors that this command has */ - public CommandAPIExecutor> getExecutor() { + public CommandAPIExecutor getExecutor() { return executor; } @@ -34,7 +33,7 @@ public CommandAPIExecutor> executor) { + public void setExecutor(CommandAPIExecutor executor) { this.executor = executor; } @@ -43,8 +42,7 @@ public void setExecutor(CommandAPIExecutor()); - this.executor.setResultingExecutors(new ArrayList<>()); + this.executor.setExecutors(new ArrayList<>()); return instance(); } diff --git a/commandapi-core/src/main/java/dev/jorel/commandapi/ExecutableCommand.java b/commandapi-core/src/main/java/dev/jorel/commandapi/ExecutableCommand.java index 04cf16c906..9b312ecdfd 100644 --- a/commandapi-core/src/main/java/dev/jorel/commandapi/ExecutableCommand.java +++ b/commandapi-core/src/main/java/dev/jorel/commandapi/ExecutableCommand.java @@ -7,7 +7,6 @@ import com.mojang.brigadier.builder.LiteralArgumentBuilder; import com.mojang.brigadier.tree.LiteralCommandNode; -import dev.jorel.commandapi.commandsenders.AbstractCommandSender; import dev.jorel.commandapi.exceptions.InvalidCommandNameException; import dev.jorel.commandapi.help.CommandAPIHelpTopic; import dev.jorel.commandapi.help.EditableHelpTopic; @@ -42,9 +41,9 @@ public abstract class ExecutableCommand requirements = s -> true; + protected Predicate requirements = CommandPermission.TRUE(); // Command help protected CommandAPIHelpTopic helpTopic = new EditableHelpTopic<>(); diff --git a/commandapi-core/src/main/java/dev/jorel/commandapi/PlatformExecutable.java b/commandapi-core/src/main/java/dev/jorel/commandapi/PlatformExecutable.java index df8682f41b..c8e4f9e53f 100644 --- a/commandapi-core/src/main/java/dev/jorel/commandapi/PlatformExecutable.java +++ b/commandapi-core/src/main/java/dev/jorel/commandapi/PlatformExecutable.java @@ -1,12 +1,12 @@ package dev.jorel.commandapi; -import dev.jorel.commandapi.commandsenders.AbstractCommandSender; - public interface PlatformExecutable /// @endcond , CommandSender> extends ChainableBuilder { - // Automatically links to Executable#getExecutor (make sure it has the same signature) - CommandAPIExecutor> getExecutor(); + /** + * Links to {@link Executable#getExecutor()} (make sure it has the same signature) + */ + CommandAPIExecutor getExecutor(); } diff --git a/commandapi-core/src/main/java/dev/jorel/commandapi/arguments/AbstractArgument.java b/commandapi-core/src/main/java/dev/jorel/commandapi/arguments/AbstractArgument.java index d60ae696b7..88e46d1c80 100644 --- a/commandapi-core/src/main/java/dev/jorel/commandapi/arguments/AbstractArgument.java +++ b/commandapi-core/src/main/java/dev/jorel/commandapi/arguments/AbstractArgument.java @@ -222,7 +222,7 @@ public CommandPermission getArgumentPermission() { // Requirements // ////////////////// - private Predicate requirements = s -> true; + private Predicate requirements = CommandPermission.TRUE(); /** * Returns the requirements required to run this command @@ -427,7 +427,7 @@ public void checkPreconditions( // this if statement, like what Literal#createArgumentBuilder does. SuggestionProvider suggestions = handler.generateBrigadierSuggestions(previousArguments, (Argument) this); ArgumentBuilder rootBuilder; - if (this instanceof Previewable previewable) { + if (this instanceof Previewable previewable) { // Handle previewable argument PreviewableArgumentBuilder builder = PreviewableArgumentBuilder.previewableArgument( nodeName, rawType, diff --git a/commandapi-core/src/main/java/dev/jorel/commandapi/arguments/PreviewInfo.java b/commandapi-core/src/main/java/dev/jorel/commandapi/arguments/PreviewInfo.java index 6c5ca64025..b07891bae9 100644 --- a/commandapi-core/src/main/java/dev/jorel/commandapi/arguments/PreviewInfo.java +++ b/commandapi-core/src/main/java/dev/jorel/commandapi/arguments/PreviewInfo.java @@ -1,10 +1,8 @@ package dev.jorel.commandapi.arguments; -import dev.jorel.commandapi.commandsenders.AbstractPlayer; - -public record PreviewInfo ( +public record PreviewInfo ( /** @param player the Player typing this command */ - AbstractPlayer player, + Player player, /** * @param input the current partially typed argument. For example "/mycmd tes" diff --git a/commandapi-core/src/main/java/dev/jorel/commandapi/arguments/Previewable.java b/commandapi-core/src/main/java/dev/jorel/commandapi/arguments/Previewable.java index d145a0b956..a773ae8ac8 100644 --- a/commandapi-core/src/main/java/dev/jorel/commandapi/arguments/Previewable.java +++ b/commandapi-core/src/main/java/dev/jorel/commandapi/arguments/Previewable.java @@ -9,11 +9,11 @@ * Minecraft's chat preview feature. To use this, the server must have * {@code previews-chat=true} set in its {@code server.properties} file */ -public interface Previewable /// @endcond -, A> { +, T, Player> { /** * Sets the {@link PreviewableFunction} for this argument. This function will @@ -24,13 +24,13 @@ public interface Previewable preview); + public Impl withPreview(PreviewableFunction preview); /** * @return the {@link PreviewableFunction} for this argument, as an * {@link Optional}. */ - public Optional> getPreview(); + public Optional> getPreview(); /** * Whether this argument should use the preview result as the argument value for @@ -41,7 +41,7 @@ public interface Previewable extends ArgumentBuilder suggestionsProvider = null; // `Previewable` information - private final PreviewableFunction previewableFunction; + private final PreviewableFunction previewableFunction; private final boolean legacy; private final boolean isListed; - private PreviewableArgumentBuilder(String name, ArgumentType type, PreviewableFunction previewableFunction, boolean legacy, boolean isListed) { + private PreviewableArgumentBuilder(String name, ArgumentType type, PreviewableFunction previewableFunction, boolean legacy, boolean isListed) { this.name = name; this.type = type; @@ -38,7 +38,7 @@ private PreviewableArgumentBuilder(String name, ArgumentType type, Previewabl this.isListed = isListed; } - public static PreviewableArgumentBuilder previewableArgument(String name, ArgumentType type, PreviewableFunction previewableFunction, boolean legacy, boolean isListed) { + public static PreviewableArgumentBuilder previewableArgument(String name, ArgumentType type, PreviewableFunction previewableFunction, boolean legacy, boolean isListed) { return new PreviewableArgumentBuilder<>(name, type, previewableFunction, legacy, isListed); } diff --git a/commandapi-core/src/main/java/dev/jorel/commandapi/commandnodes/PreviewableCommandNode.java b/commandapi-core/src/main/java/dev/jorel/commandapi/commandnodes/PreviewableCommandNode.java index 4093c54a4f..c3ad0d05ed 100644 --- a/commandapi-core/src/main/java/dev/jorel/commandapi/commandnodes/PreviewableCommandNode.java +++ b/commandapi-core/src/main/java/dev/jorel/commandapi/commandnodes/PreviewableCommandNode.java @@ -27,14 +27,14 @@ * @param The type returned when this argument is parsed. */ public class PreviewableCommandNode extends ArgumentCommandNode { - private final PreviewableFunction preview; + private final PreviewableFunction preview; private final boolean legacy; // Instead of having a listed and unlisted copy of this class, we can just handle this with this boolean private final boolean isListed; public PreviewableCommandNode( - PreviewableFunction preview, boolean legacy, boolean isListed, + PreviewableFunction preview, boolean legacy, boolean isListed, String name, ArgumentType type, Command command, Predicate requirement, CommandNode redirect, RedirectModifier modifier, boolean forks, SuggestionProvider customSuggestions ) { @@ -45,7 +45,7 @@ public PreviewableCommandNode( } // Methods needed to generate a preview - public Optional> getPreview() { + public Optional> getPreview() { return Optional.ofNullable(preview); } diff --git a/commandapi-core/src/main/java/dev/jorel/commandapi/commandsenders/AbstractBlockCommandSender.java b/commandapi-core/src/main/java/dev/jorel/commandapi/commandsenders/AbstractBlockCommandSender.java deleted file mode 100644 index 0ac8564103..0000000000 --- a/commandapi-core/src/main/java/dev/jorel/commandapi/commandsenders/AbstractBlockCommandSender.java +++ /dev/null @@ -1,4 +0,0 @@ -package dev.jorel.commandapi.commandsenders; - -public interface AbstractBlockCommandSender extends AbstractCommandSender { -} diff --git a/commandapi-core/src/main/java/dev/jorel/commandapi/commandsenders/AbstractCommandSender.java b/commandapi-core/src/main/java/dev/jorel/commandapi/commandsenders/AbstractCommandSender.java deleted file mode 100644 index 806ba11c42..0000000000 --- a/commandapi-core/src/main/java/dev/jorel/commandapi/commandsenders/AbstractCommandSender.java +++ /dev/null @@ -1,29 +0,0 @@ -package dev.jorel.commandapi.commandsenders; - -/** - * An interface that represents an object sends commands on some platform - * - * @param The class of the CommandSender being represented - */ -public interface AbstractCommandSender { - - /** - * Tests if this CommandSender has permission to use the given permission node - * - * @param permissionNode The node to check for - * @return True if this CommandSender holds the permission node, and false otherwise - */ - boolean hasPermission(String permissionNode); - - /** - * Tests if this CommandSender has `operator` status, or the ability to run any command - * - * @return True if this CommandSender is an operator, and false otherwise - */ - boolean isOp(); - - /** - * @return The underlying CommandSender object - */ - Source getSource(); -} diff --git a/commandapi-core/src/main/java/dev/jorel/commandapi/commandsenders/AbstractConsoleCommandSender.java b/commandapi-core/src/main/java/dev/jorel/commandapi/commandsenders/AbstractConsoleCommandSender.java deleted file mode 100644 index 05fdc81b34..0000000000 --- a/commandapi-core/src/main/java/dev/jorel/commandapi/commandsenders/AbstractConsoleCommandSender.java +++ /dev/null @@ -1,4 +0,0 @@ -package dev.jorel.commandapi.commandsenders; - -public interface AbstractConsoleCommandSender extends AbstractCommandSender { -} diff --git a/commandapi-core/src/main/java/dev/jorel/commandapi/commandsenders/AbstractEntity.java b/commandapi-core/src/main/java/dev/jorel/commandapi/commandsenders/AbstractEntity.java deleted file mode 100644 index c167eb3a07..0000000000 --- a/commandapi-core/src/main/java/dev/jorel/commandapi/commandsenders/AbstractEntity.java +++ /dev/null @@ -1,4 +0,0 @@ -package dev.jorel.commandapi.commandsenders; - -public interface AbstractEntity extends AbstractCommandSender { -} diff --git a/commandapi-core/src/main/java/dev/jorel/commandapi/commandsenders/AbstractFeedbackForwardingCommandSender.java b/commandapi-core/src/main/java/dev/jorel/commandapi/commandsenders/AbstractFeedbackForwardingCommandSender.java deleted file mode 100644 index 66e544d3bd..0000000000 --- a/commandapi-core/src/main/java/dev/jorel/commandapi/commandsenders/AbstractFeedbackForwardingCommandSender.java +++ /dev/null @@ -1,4 +0,0 @@ -package dev.jorel.commandapi.commandsenders; - -public interface AbstractFeedbackForwardingCommandSender extends AbstractCommandSender { -} diff --git a/commandapi-core/src/main/java/dev/jorel/commandapi/commandsenders/AbstractNativeProxyCommandSender.java b/commandapi-core/src/main/java/dev/jorel/commandapi/commandsenders/AbstractNativeProxyCommandSender.java deleted file mode 100644 index e008064d21..0000000000 --- a/commandapi-core/src/main/java/dev/jorel/commandapi/commandsenders/AbstractNativeProxyCommandSender.java +++ /dev/null @@ -1,4 +0,0 @@ -package dev.jorel.commandapi.commandsenders; - -public interface AbstractNativeProxyCommandSender extends AbstractProxiedCommandSender { -} diff --git a/commandapi-core/src/main/java/dev/jorel/commandapi/commandsenders/AbstractPlayer.java b/commandapi-core/src/main/java/dev/jorel/commandapi/commandsenders/AbstractPlayer.java deleted file mode 100644 index 6fa29febfd..0000000000 --- a/commandapi-core/src/main/java/dev/jorel/commandapi/commandsenders/AbstractPlayer.java +++ /dev/null @@ -1,4 +0,0 @@ -package dev.jorel.commandapi.commandsenders; - -public interface AbstractPlayer extends AbstractCommandSender { -} diff --git a/commandapi-core/src/main/java/dev/jorel/commandapi/commandsenders/AbstractProxiedCommandSender.java b/commandapi-core/src/main/java/dev/jorel/commandapi/commandsenders/AbstractProxiedCommandSender.java deleted file mode 100644 index c02b9f7096..0000000000 --- a/commandapi-core/src/main/java/dev/jorel/commandapi/commandsenders/AbstractProxiedCommandSender.java +++ /dev/null @@ -1,4 +0,0 @@ -package dev.jorel.commandapi.commandsenders; - -public interface AbstractProxiedCommandSender extends AbstractCommandSender { -} diff --git a/commandapi-core/src/main/java/dev/jorel/commandapi/commandsenders/AbstractRemoteConsoleCommandSender.java b/commandapi-core/src/main/java/dev/jorel/commandapi/commandsenders/AbstractRemoteConsoleCommandSender.java deleted file mode 100644 index f198138ec7..0000000000 --- a/commandapi-core/src/main/java/dev/jorel/commandapi/commandsenders/AbstractRemoteConsoleCommandSender.java +++ /dev/null @@ -1,4 +0,0 @@ -package dev.jorel.commandapi.commandsenders; - -public interface AbstractRemoteConsoleCommandSender extends AbstractCommandSender { -} diff --git a/commandapi-core/src/main/java/dev/jorel/commandapi/executors/ExecutionInfo.java b/commandapi-core/src/main/java/dev/jorel/commandapi/executors/ExecutionInfo.java index 45996a4917..3cb70e53d7 100644 --- a/commandapi-core/src/main/java/dev/jorel/commandapi/executors/ExecutionInfo.java +++ b/commandapi-core/src/main/java/dev/jorel/commandapi/executors/ExecutionInfo.java @@ -1,33 +1,41 @@ package dev.jorel.commandapi.executors; -import dev.jorel.commandapi.commandsenders.AbstractCommandSender; +import com.mojang.brigadier.context.CommandContext; /** - * This interface represents an ExecutionInfo for a command. It provides the sender of a command, as well as it's arguments + * This interface represents the information of running a command. It provides the sender of a command, as well as its arguments. * - * @param The type of the sender of a command this ExecutionInfo belongs to + * @param sender The sender of this command + * @param args The arguments of this command + * @param cmdCtx The Brigadier {@link CommandContext} that is running the commands + * @param The type of the sender of a command this ExecutionInfo belongs to + * @param The class for running Brigadier commands */ -public interface ExecutionInfo -/// @endcond -> { +public record ExecutionInfo( /** * @return The sender of this command */ - Sender sender(); + CommandSender sender, /** - * This is not intended for public use and is only used internally. The {@link ExecutionInfo#sender()} method should be used instead! - * - * @return The wrapper type of this command + * @return The arguments of this command */ - WrapperType senderWrapper(); + CommandArguments args, /** - * @return The arguments of this command + * @return cmdCtx The Brigadier {@link CommandContext} that is running the commands */ - CommandArguments args(); - + CommandContext cmdCtx +) { + /** + * Copies this {@link ExecutionInfo} for a different command sender + * + * @param The class of the new command sender + * @param newSender The new command sender + * @return A new {@link ExecutionInfo} object that uses the given command sender + */ + public ExecutionInfo copyWithNewSender(Sender newSender) { + return new ExecutionInfo<>(newSender, args, cmdCtx); + } } diff --git a/commandapi-core/src/main/java/dev/jorel/commandapi/executors/NormalExecutor.java b/commandapi-core/src/main/java/dev/jorel/commandapi/executors/NormalExecutor.java index c6c481d68a..0864bd2b3f 100644 --- a/commandapi-core/src/main/java/dev/jorel/commandapi/executors/NormalExecutor.java +++ b/commandapi-core/src/main/java/dev/jorel/commandapi/executors/NormalExecutor.java @@ -1,55 +1,28 @@ -/******************************************************************************* - * Copyright 2018, 2020 Jorel Ali (Skepter) - MIT License - * - * Permission is hereby granted, free of charge, to any person obtaining a copy of - * this software and associated documentation files (the "Software"), to deal in - * the Software without restriction, including without limitation the rights to - * use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of - * the Software, and to permit persons to whom the Software is furnished to do so, - * subject to the following conditions: - * - * The above copyright notice and this permission notice shall be included in all - * copies or substantial portions of the Software. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR - * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS - * FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR - * COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER - * IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN - * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. - *******************************************************************************/ package dev.jorel.commandapi.executors; -import dev.jorel.commandapi.commandsenders.AbstractCommandSender; import dev.jorel.commandapi.exceptions.WrapperCommandSyntaxException; /** - * The interface for normal command executors - * @param The CommandSender for this executor - * @param The AbstractCommandSender that wraps the CommandSender + * A {@link FunctionalInterface} for a command execution that inputs a command sender and {@link CommandArguments} + * and returns no result (see {@link NormalExecutor#run(Object, CommandArguments)}). When running this executor, + * the result will by 1 if successful and 0 otherwise. + * + * @param The class of the command sender for this executor. + * @param The class for running Brigadier commands. */ -public interface NormalExecutor -/// @endcond -> extends TypedExecutor { - /** - * Executes the command executor with the provided command sender and the provided arguments. - * @param info The ExecutionInfo for this command - * @return 1 if the command succeeds, 0 if the command fails - * @throws WrapperCommandSyntaxException if an error occurs during the execution of this command - */ - @Override - default int executeWith(ExecutionInfo info) throws WrapperCommandSyntaxException { - this.run(info); - return 1; - } - - /** - * Executes the command. - * @param info The ExecutionInfo for this command - * @throws WrapperCommandSyntaxException if an error occurs during the execution of this command - */ - void run(ExecutionInfo info) throws WrapperCommandSyntaxException; +@FunctionalInterface +public interface NormalExecutor extends NormalExecutorInfo { + @Override + default void run(ExecutionInfo info) throws WrapperCommandSyntaxException { + this.run(info.sender(), info.args()); + } + /** + * Runs this executor. + * + * @param sender The command sender. + * @param arguments The {@link CommandArguments} for this command. + * @throws WrapperCommandSyntaxException if something goes wrong while running this executor. + */ + void run(Sender sender, CommandArguments arguments) throws WrapperCommandSyntaxException; } diff --git a/commandapi-core/src/main/java/dev/jorel/commandapi/executors/NormalExecutorInfo.java b/commandapi-core/src/main/java/dev/jorel/commandapi/executors/NormalExecutorInfo.java new file mode 100644 index 0000000000..228d894ad7 --- /dev/null +++ b/commandapi-core/src/main/java/dev/jorel/commandapi/executors/NormalExecutorInfo.java @@ -0,0 +1,22 @@ +package dev.jorel.commandapi.executors; + +import dev.jorel.commandapi.exceptions.WrapperCommandSyntaxException; + +/** + * A {@link FunctionalInterface} for a command execution that inputs a {@link ExecutionInfo} + * and returns no result (see {@link NormalExecutorInfo#run(ExecutionInfo)}). When running + * this executor, the result will by 1 if successful and 0 otherwise. + * + * @param The class of the command sender for this executor. + * @param The class for running Brigadier commands. + */ +@FunctionalInterface +public interface NormalExecutorInfo { + /** + * Runs this executor. + * + * @param info The {@link ExecutionInfo} for this command. + * @throws WrapperCommandSyntaxException if something goes wrong while running this executor. + */ + void run(ExecutionInfo info) throws WrapperCommandSyntaxException; +} diff --git a/commandapi-core/src/main/java/dev/jorel/commandapi/executors/ResultingExecutor.java b/commandapi-core/src/main/java/dev/jorel/commandapi/executors/ResultingExecutor.java index 9444ae7432..b46bbb34a5 100644 --- a/commandapi-core/src/main/java/dev/jorel/commandapi/executors/ResultingExecutor.java +++ b/commandapi-core/src/main/java/dev/jorel/commandapi/executors/ResultingExecutor.java @@ -1,55 +1,28 @@ -/******************************************************************************* - * Copyright 2018, 2020 Jorel Ali (Skepter) - MIT License - * - * Permission is hereby granted, free of charge, to any person obtaining a copy of - * this software and associated documentation files (the "Software"), to deal in - * the Software without restriction, including without limitation the rights to - * use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of - * the Software, and to permit persons to whom the Software is furnished to do so, - * subject to the following conditions: - * - * The above copyright notice and this permission notice shall be included in all - * copies or substantial portions of the Software. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR - * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS - * FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR - * COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER - * IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN - * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. - *******************************************************************************/ package dev.jorel.commandapi.executors; -import dev.jorel.commandapi.commandsenders.AbstractCommandSender; import dev.jorel.commandapi.exceptions.WrapperCommandSyntaxException; /** - * The interface for resulting command executors - * @param The CommandSender for this executor - * @param The AbstractCommandSender that wraps the CommandSender + * A {@link FunctionalInterface} for a command execution that inputs a command sender and {@link CommandArguments} + * and returns an int result (see {@link ResultingExecutor#run(Object, CommandArguments)}). + * + * @param The class of the command sender for this executor. + * @param The class for running Brigadier commands. */ -public interface ResultingExecutor -/// @endcond -> extends TypedExecutor { +@FunctionalInterface +public interface ResultingExecutor extends ResultingExecutorInfo { + @Override + default int run(ExecutionInfo info) throws WrapperCommandSyntaxException { + return this.run(info.sender(), info.args()); + } - /** - * Executes the command executor with the provided command sender and the provided arguments. - * @param info The ExecutionInfo for this command - * @return the value returned by this command if the command succeeds, 0 if the command fails - * @throws WrapperCommandSyntaxException if an error occurs during the execution of this command - */ - @Override - default int executeWith(ExecutionInfo info) throws WrapperCommandSyntaxException { - return this.run(info); - } - - /** - * Executes the command. - * @param info The ExecutionInfo for this command - * @return the value returned by this command - * @throws WrapperCommandSyntaxException if an error occurs during the execution of this command - */ - int run(ExecutionInfo info) throws WrapperCommandSyntaxException; + /** + * Runs this executor. + * + * @param sender The command sender. + * @param arguments The {@link CommandArguments} for this command. + * @return The int result of running this executor. + * @throws WrapperCommandSyntaxException if something goes wrong while running this executor. + */ + int run(Sender sender, CommandArguments arguments) throws WrapperCommandSyntaxException; } diff --git a/commandapi-core/src/main/java/dev/jorel/commandapi/executors/ResultingExecutorInfo.java b/commandapi-core/src/main/java/dev/jorel/commandapi/executors/ResultingExecutorInfo.java new file mode 100644 index 0000000000..b50aaa8be3 --- /dev/null +++ b/commandapi-core/src/main/java/dev/jorel/commandapi/executors/ResultingExecutorInfo.java @@ -0,0 +1,22 @@ +package dev.jorel.commandapi.executors; + +import dev.jorel.commandapi.exceptions.WrapperCommandSyntaxException; + +/** + * A {@link FunctionalInterface} for a command execution that inputs a {@link ExecutionInfo} + * and returns an int result (see {@link ResultingExecutorInfo#run(ExecutionInfo)}). + * + * @param The class of the command sender for this executor. + * @param The class for running Brigadier commands. + */ +@FunctionalInterface +public interface ResultingExecutorInfo { + /** + * Runs this executor. + * + * @param info The {@link ExecutionInfo} for this command. + * @return The int result of running this executor. + * @throws WrapperCommandSyntaxException if something goes wrong while running this executor. + */ + int run(ExecutionInfo info) throws WrapperCommandSyntaxException; +} diff --git a/commandapi-core/src/main/java/dev/jorel/commandapi/executors/TypedExecutor.java b/commandapi-core/src/main/java/dev/jorel/commandapi/executors/TypedExecutor.java index cd95fac8c5..55a1c825d0 100644 --- a/commandapi-core/src/main/java/dev/jorel/commandapi/executors/TypedExecutor.java +++ b/commandapi-core/src/main/java/dev/jorel/commandapi/executors/TypedExecutor.java @@ -1,54 +1,33 @@ -/******************************************************************************* - * Copyright 2018, 2020 Jorel Ali (Skepter) - MIT License - * - * Permission is hereby granted, free of charge, to any person obtaining a copy of - * this software and associated documentation files (the "Software"), to deal in - * the Software without restriction, including without limitation the rights to - * use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of - * the Software, and to permit persons to whom the Software is furnished to do so, - * subject to the following conditions: - * - * The above copyright notice and this permission notice shall be included in all - * copies or substantial portions of the Software. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR - * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS - * FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR - * COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER - * IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN - * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. - *******************************************************************************/ package dev.jorel.commandapi.executors; -import dev.jorel.commandapi.commandsenders.AbstractCommandSender; import dev.jorel.commandapi.exceptions.WrapperCommandSyntaxException; /** - * An interface that includes the type of an executor (what command senders it - * can execute) and has a method that executes an executor with a given command - * sender and arguments - * @param The AbstractCommandSenderClass for this executor + * An interface that includes what command senders it can execute ({@link #tryForSender(ExecutionInfo)}) + * and has a method that executes an executor with a given {@link ExecutionInfo} ({@link #executeWith(ExecutionInfo)}). + * + * @param The class for executing platform commands. + * @param The class that this executor accepts. + * @param The class for running Brigadier commands. */ -public interface TypedExecutor -/// @endcond -> { +public interface TypedExecutor { /** - * Returns the type of the sender of the current executor. - * @return the type of the sender of the current executor + * Checks if the sender in the given {@link ExecutionInfo} can use this executor. + * If it can, an {@link ExecutionInfo} compatible with this executor is returned. + * If not, null is returned. + * + * @param info The {@link ExecutionInfo} that is trying to use this executor. + * @return An {@link ExecutionInfo} object that can use this executor, and null otherwise. */ - default ExecutorType getType() { - return ExecutorType.ALL; - } + ExecutionInfo tryForSender(ExecutionInfo info); /** * Executes the command executor with the provided command sender and the provided arguments. + * * @param info The ExecutionInfo for this command * @return the value returned by this command if the command succeeds, 0 if the command fails * @throws WrapperCommandSyntaxException if an error occurs during the execution of this command */ - int executeWith(ExecutionInfo info) throws WrapperCommandSyntaxException; - + int executeWith(ExecutionInfo info) throws WrapperCommandSyntaxException; } diff --git a/commandapi-core/src/main/java/dev/jorel/commandapi/wrappers/PreviewableFunction.java b/commandapi-core/src/main/java/dev/jorel/commandapi/wrappers/PreviewableFunction.java index ff70a70e60..fe01885ba6 100644 --- a/commandapi-core/src/main/java/dev/jorel/commandapi/wrappers/PreviewableFunction.java +++ b/commandapi-core/src/main/java/dev/jorel/commandapi/wrappers/PreviewableFunction.java @@ -3,8 +3,8 @@ import dev.jorel.commandapi.arguments.PreviewInfo; import dev.jorel.commandapi.exceptions.WrapperCommandSyntaxException; -public interface PreviewableFunction { +@FunctionalInterface +public interface PreviewableFunction { - public T generatePreview(PreviewInfo info) throws WrapperCommandSyntaxException; - + public T generatePreview(PreviewInfo info) throws WrapperCommandSyntaxException; } diff --git a/commandapi-documentation-code/src/main/kotlin/dev/jorel/commandapi/examples/kotlin/Examples.kt b/commandapi-documentation-code/src/main/kotlin/dev/jorel/commandapi/examples/kotlin/Examples.kt index b95e4c92f5..f45f9ad453 100644 --- a/commandapi-documentation-code/src/main/kotlin/dev/jorel/commandapi/examples/kotlin/Examples.kt +++ b/commandapi-documentation-code/src/main/kotlin/dev/jorel/commandapi/examples/kotlin/Examples.kt @@ -32,6 +32,7 @@ import org.bukkit.* import org.bukkit.advancement.Advancement import org.bukkit.block.* import org.bukkit.block.data.BlockData +import org.bukkit.command.BlockCommandSender import org.bukkit.command.CommandSender import org.bukkit.command.ProxiedCommandSender import org.bukkit.enchantments.Enchantment @@ -68,7 +69,7 @@ fun advancementArgument() { CommandAPICommand("award") .withArguments(PlayerArgument("player")) .withArguments(AdvancementArgument("advancement")) - .executes(CommandExecutor { _, args -> + .executes(NormalExecutor { _, args -> val target = args["player"] as Player val advancement = args["advancement"] as Advancement @@ -89,11 +90,11 @@ CommandAPICommand("getpos") .withAliases("getposition", "getloc", "getlocation", "whereami") // Declare your implementation - .executesEntity(EntityCommandExecutor { entity, _ -> + .executesEntity(NormalExecutor { entity, _ -> val loc = entity.location entity.sendMessage("You are at ${loc.blockX}, ${loc.blockY}, ${loc.blockZ}") }) - .executesCommandBlock(CommandBlockCommandExecutor { block, _ -> + .executesCommandBlock(NormalExecutor { block, _ -> val loc = block.block.location block.sendMessage("You are at ${loc.blockX}, ${loc.blockY}, ${loc.blockZ}") }) @@ -108,7 +109,7 @@ fun argument_angle() { /* ANCHOR: argumentAngle1 */ CommandAPICommand("yaw") .withArguments(AngleArgument("amount")) - .executesPlayer(PlayerCommandExecutor { player, args -> + .executesPlayer(NormalExecutor { player, args -> val newLocation = player.location newLocation.yaw = args["amount"] as Float player.teleport(newLocation) @@ -121,7 +122,7 @@ fun argument_biome() { /* ANCHOR: argumentBiome1 */ CommandAPICommand("setbiome") .withArguments(BiomeArgument("biome")) - .executesPlayer(PlayerCommandExecutor { player, args -> + .executesPlayer(NormalExecutor { player, args -> val biome = args["biome"] as Biome val chunk = player.location.chunk @@ -143,7 +144,7 @@ val arguments = arrayOf>( /* ANCHOR: argumentBlockPredicate2 */ CommandAPICommand("replace") .withArguments(*arguments) - .executesPlayer(PlayerCommandExecutor { player, args -> + .executesPlayer(NormalExecutor { player, args -> // Parse the arguments val radius = args["radius"] as Int @@ -176,7 +177,7 @@ fun argument_blockState() { /* ANCHOR: argumentBlockState1 */ CommandAPICommand("set") .withArguments(BlockStateArgument("block")) - .executesPlayer(PlayerCommandExecutor { player, args -> + .executesPlayer(NormalExecutor { player, args -> val blockdata = args["block"] as BlockData val targetBlock = player.getTargetBlockExact(256) @@ -192,7 +193,7 @@ fun argument_chatAdventure() { /* ANCHOR: argumentChatAdventure1 */ CommandAPICommand("namecolor") .withArguments(AdventureChatColorArgument("chatcolor")) - .executesPlayer(PlayerCommandExecutor { player, args -> + .executesPlayer(NormalExecutor { player, args -> val color = args["chatcolor"] as NamedTextColor player.displayName(Component.text().color(color).append(Component.text(player.name)).build()) }) @@ -205,7 +206,7 @@ CommandAPICommand("showbook") .withArguments(TextArgument("title")) .withArguments(StringArgument("author")) .withArguments(AdventureChatComponentArgument("contents")) - .executes(CommandExecutor { _, args -> + .executes(NormalExecutor { _, args -> val target = args["target"] as Player val title = args["title"] as String val author = args["author"] as String @@ -221,7 +222,7 @@ CommandAPICommand("showbook") /* ANCHOR: argumentChatAdventure3 */ CommandAPICommand("pbroadcast") .withArguments(AdventureChatArgument("message")) - .executes(CommandExecutor { _, args -> + .executes(NormalExecutor { _, args -> val message = args["message"] as Component // Broadcast the message to everyone with broadcast permissions. @@ -236,7 +237,7 @@ fun argument_chatSpigot() { /* ANCHOR: argumentChatSpigot1 */ CommandAPICommand("namecolor") .withArguments(ChatColorArgument("chatColor")) - .executesPlayer(PlayerCommandExecutor { player, args -> + .executesPlayer(NormalExecutor { player, args -> val color = args["chatColor"] as ChatColor player.setDisplayName("$color${player.name}") }) @@ -247,7 +248,7 @@ CommandAPICommand("namecolor") CommandAPICommand("makebook") .withArguments(PlayerArgument("player")) .withArguments(ChatComponentArgument("contents")) - .executes(CommandExecutor { _, args -> + .executes(NormalExecutor { _, args -> val player = args["player"] as Player val arr = args["contents"] as Array @@ -268,7 +269,7 @@ CommandAPICommand("makebook") /* ANCHOR: argumentChatSpigot3 */ CommandAPICommand("pbroadcast") .withArguments(ChatArgument("message")) - .executes(CommandExecutor { _, args -> + .executes(NormalExecutor { _, args -> val message = args["message"] as Array // Broadcast the message to everyone on the server @@ -283,7 +284,7 @@ fun argument_command() { CommandAPICommand("sudo") .withArguments(PlayerArgument("target")) .withArguments(CommandArgument("command")) - .executes(CommandExecutor { _, args -> + .executes(NormalExecutor { _, args -> val target = args["target"] as Player val command = args["command"] as CommandResult @@ -369,7 +370,7 @@ fun argumentCustom2() { /* ANCHOR: argumentCustom2 */ CommandAPICommand("tpworld") .withArguments(worldArgument("world")) - .executesPlayer(PlayerCommandExecutor { player, args -> + .executesPlayer(NormalExecutor { player, args -> player.teleport((args["world"] as World).spawnLocation) }) .register() @@ -382,7 +383,7 @@ fun argument_enchantment() { CommandAPICommand("enchantitem") .withArguments(EnchantmentArgument("enchantment")) .withArguments(IntegerArgument("level", 1, 5)) - .executesPlayer(PlayerCommandExecutor { player, args -> + .executesPlayer(NormalExecutor { player, args -> val enchantment = args["enchantment"] as Enchantment val level = args["level"] as Int @@ -398,7 +399,7 @@ fun argument_entities() { CommandAPICommand("remove") // Using a collective entity selector to select multiple entities .withArguments(EntitySelectorArgument.ManyEntities("entities")) - .executes(CommandExecutor { sender, args -> + .executes(NormalExecutor { sender, args -> // Parse the argument as a collection of entities (as stated above in the documentation) val entities = args["entities"] as Collection @@ -431,7 +432,7 @@ CommandAPICommand("warp") CommandAPICommand("spawnmob") .withArguments(EntityTypeArgument("entity")) .withArguments(IntegerArgument("amount", 1, 100)) // Prevent spawning too many entities - .executesPlayer(PlayerCommandExecutor { player, args -> + .executesPlayer(NormalExecutor { player, args -> for (i in 0 until args["amount"] as Int) { player.world.spawnEntity(player.location, args["entity"] as EntityType) } @@ -444,7 +445,7 @@ fun argument_function() { /* ANCHOR: argumentFunction1 */ CommandAPICommand("runfunction") .withArguments(FunctionArgument("function")) - .executes(CommandExecutor { _, args -> + .executes(NormalExecutor { _, args -> val functions = args["function"] as Array // Run all functions in our FunctionWrapper[] @@ -460,7 +461,7 @@ fun argument_itemStack() { /* ANCHOR: argumentItemStack1 */ CommandAPICommand("item") .withArguments(ItemStackArgument("itemStack")) - .executesPlayer(PlayerCommandExecutor { player, args -> + .executesPlayer(NormalExecutor { player, args -> player.inventory.addItem(args["itemStack"] as ItemStack) }) .register() @@ -472,7 +473,7 @@ fun argument_itemStackPredicate() { // Register our command CommandAPICommand("rem") .withArguments(ItemStackPredicateArgument("items")) - .executesPlayer(PlayerCommandExecutor { player, args -> + .executesPlayer(NormalExecutor { player, args -> // Get our predicate val predicate = args["items"] as Predicate @@ -496,7 +497,7 @@ CommandAPICommand("multigive") .withMapper { material -> material.name.lowercase() } .buildGreedy() ) - .executesPlayer(PlayerCommandExecutor { player, args -> + .executesPlayer(NormalExecutor { player, args -> val amount = args["amount"] as Int val theList = args["materials"] as List @@ -513,7 +514,7 @@ fun argument_literal() { CommandAPICommand("mycommand") .withArguments(LiteralArgument("hello")) .withArguments(TextArgument("text")) - .executes(CommandExecutor { _, args -> + .executes(NormalExecutor { _, args -> // This gives the variable "text" the contents of the TextArgument, and not the literal "hello" val text = args[0] as String }) @@ -524,7 +525,7 @@ CommandAPICommand("mycommand") CommandAPICommand("mycommand") .withArguments(LiteralArgument.of("hello")) .withArguments(TextArgument("text")) - .executes(CommandExecutor { _, args -> + .executes(NormalExecutor { _, args -> val text = args[0] as String }) .register() @@ -532,7 +533,7 @@ CommandAPICommand("mycommand") CommandAPICommand("mycommand") .withArguments(LiteralArgument.literal("hello")) .withArguments(TextArgument("text")) - .executes(CommandExecutor { _, args -> + .executes(NormalExecutor { _, args -> val text = args[0] as String }) .register() @@ -553,7 +554,7 @@ for ((key, _) in gamemodes) { // Register the command as usual CommandAPICommand("changegamemode") .withArguments(LiteralArgument(key)) - .executesPlayer(PlayerCommandExecutor { player, _ -> + .executesPlayer(NormalExecutor { player, _ -> // Retrieve the object from the map via the key and NOT the args[] player.gameMode = gamemodes[key]!! }) @@ -575,7 +576,7 @@ LocationArgument("location", LocationType.PRECISE_POSITION, false) CommandAPICommand("break") // We want to target blocks in particular, so use BLOCK_POSITION .withArguments(LocationArgument("block", LocationType.BLOCK_POSITION)) - .executesPlayer(PlayerCommandExecutor { _, args -> + .executesPlayer(NormalExecutor { _, args -> (args["block"] as Location).block.type = Material.AIR }) .register() @@ -587,7 +588,7 @@ fun argument_lootTable() { CommandAPICommand("giveloottable") .withArguments(LootTableArgument("lootTable")) .withArguments(LocationArgument("location", LocationType.BLOCK_POSITION)) - .executes(CommandExecutor { _, args -> + .executes(NormalExecutor { _, args -> val lootTable = args["lootTable"] as LootTable val location = args["location"] as Location @@ -627,7 +628,7 @@ CommandAPICommand("sendmessage") // Build the MapArgument .build() ) - .executesPlayer(PlayerCommandExecutor { _, args -> + .executesPlayer(NormalExecutor { _, args -> // The MapArgument returns a LinkedHashMap val map: LinkedHashMap = args["message"] as LinkedHashMap @@ -646,7 +647,7 @@ CommandAPICommand("changelevel") .withArguments(PlayerArgument("player")) .withArguments(MathOperationArgument("operation")) .withArguments(IntegerArgument("value")) - .executes(CommandExecutor { _, args -> + .executes(NormalExecutor { _, args -> val target = args["player"] as Player val op = args["operation"] as MathOperation val value = args["value"] as Int @@ -661,7 +662,7 @@ fun argument_multiLiteral() { /* ANCHOR: argumentMultiLiteral1 */ CommandAPICommand("gamemode") .withArguments(MultiLiteralArgument("gamemodes", "adventure", "creative", "spectator", "survival")) - .executesPlayer(PlayerCommandExecutor { player, args -> + .executesPlayer(NormalExecutor { player, args -> // The literal string that the player enters IS available in the args[] when (args["gamemodes"] as String) { "adventure" -> player.gameMode = GameMode.ADVENTURE @@ -688,7 +689,7 @@ fun argument_nbt2() { /* ANCHOR: argumentNBT2 */ CommandAPICommand("award") .withArguments(NBTCompoundArgument("nbt")) - .executes(CommandExecutor { _, args -> + .executes(NormalExecutor { _, args -> val nbt = args["nbt"] as NBTContainer // Do something with "nbt" here... @@ -703,7 +704,7 @@ fun argument_objectives() { /* ANCHOR: argumentObjectives1 */ CommandAPICommand("sidebar") .withArguments(ObjectiveArgument("objective")) - .executes(CommandExecutor { _, args -> + .executes(NormalExecutor { _, args -> val objective = args["objective"] as Objective // Set display slot @@ -715,7 +716,7 @@ CommandAPICommand("sidebar") /* ANCHOR: argumentObjectives2 */ CommandAPICommand("unregisterall") .withArguments(ObjectiveCriteriaArgument("objective criteria")) - .executes(CommandExecutor { _, args -> + .executes(NormalExecutor { _, args -> val objectiveCriteria = args["objective criteria"] as String val objectives = Bukkit.getScoreboardManager().mainScoreboard.getObjectivesByCriteria(objectiveCriteria) @@ -732,7 +733,7 @@ fun argument_particle() { /* ANCHOR: argumentParticle1 */ CommandAPICommand("showparticle") .withArguments(ParticleArgument("particle")) - .executesPlayer(PlayerCommandExecutor { player, args -> + .executesPlayer(NormalExecutor { player, args -> val particleData = args["particle"] as ParticleData player.world.spawnParticle(particleData.particle(), player.location, 1) }) @@ -742,7 +743,7 @@ CommandAPICommand("showparticle") /* ANCHOR: argumentParticle2 */ CommandAPICommand("showparticle") .withArguments(ParticleArgument("particle")) - .executesPlayer(PlayerCommandExecutor { player, args -> + .executesPlayer(NormalExecutor { player, args -> val particleData = args["particle"] as ParticleData player.world.spawnParticle(particleData.particle(), player.location, 1, particleData.data()) }) @@ -757,7 +758,7 @@ CommandAPICommand("potion") .withArguments(PotionEffectArgument("potion")) .withArguments(TimeArgument("duration")) .withArguments(IntegerArgument("strength")) - .executes(CommandExecutor { _, args -> + .executes(NormalExecutor { _, args -> val target = args["target"] as Player val potion = args["potion"] as PotionEffectType val duration = args["duration"] as Int @@ -774,7 +775,7 @@ CommandAPICommand("potion") .withArguments(PotionEffectArgument.NamespacedKey("potion")) .withArguments(TimeArgument("duration")) .withArguments(IntegerArgument("strength")) - .executes(CommandExecutor { _, args -> + .executes(NormalExecutor { _, args -> val target = args["target"] as Player val potionKey = args["potion"] as NamespacedKey val duration = args["duration"] as Int @@ -798,7 +799,7 @@ val configKeys: Array = config.getKeys(true).toTypedArray() CommandAPICommand("editconfig") .withArguments(TextArgument("config-key").replaceSuggestions(ArgumentSuggestions.strings { _ -> configKeys })) .withArguments(BooleanArgument("value")) - .executes(CommandExecutor { _, args -> + .executes(NormalExecutor { _, args -> // Update the config with the boolean argument config.set(args["config-key"] as String, args["value"] as Boolean) }) @@ -811,7 +812,7 @@ fun argument_range() { CommandAPICommand("searchrange") .withArguments(IntegerRangeArgument("range")) // Range argument .withArguments(ItemStackArgument("item")) // The item to search for - .executesPlayer(PlayerCommandExecutor { player, args -> + .executesPlayer(NormalExecutor { player, args -> // Retrieve the range from the arguments val range = args["range"] as IntegerRange val itemStack = args["item"] as ItemStack @@ -860,7 +861,7 @@ fun argument_recipe() { /* ANCHOR: argumentRecipe1 */ CommandAPICommand("giverecipe") .withArguments(RecipeArgument("recipe")) - .executesPlayer(PlayerCommandExecutor { player, args -> + .executesPlayer(NormalExecutor { player, args -> val recipe = args["recipe"] as ComplexRecipe player.inventory.addItem(recipe.result) }) @@ -871,7 +872,7 @@ CommandAPICommand("giverecipe") CommandAPICommand("unlockrecipe") .withArguments(PlayerArgument("player")) .withArguments(RecipeArgument("recipe")) - .executes(CommandExecutor { _, args -> + .executes(NormalExecutor { _, args -> val target = args["player"] as Player val recipe = args["recipe"] as ComplexRecipe @@ -886,7 +887,7 @@ fun argument_rotation() { CommandAPICommand("rotate") .withArguments(RotationArgument("rotation")) .withArguments(EntitySelectorArgument.OneEntity("target")) - .executes(CommandExecutor { _, args -> + .executes(NormalExecutor { _, args -> val rotation = args["rotation"] as Rotation val target = args["target"] as Entity @@ -903,7 +904,7 @@ fun argument_scoreboards() { CommandAPICommand("reward") // We want multiple players, so we use the ScoreHolderArgument.Multiple constructor .withArguments(ScoreHolderArgument.Multiple("players")) - .executes(CommandExecutor { _, args -> + .executes(NormalExecutor { _, args -> // Get player names by casting to Collection val players = args["players"] as Collection @@ -917,7 +918,7 @@ CommandAPICommand("reward") /* ANCHOR: argumentScoreboards2 */ CommandAPICommand("clearobjectives") .withArguments(ScoreboardSlotArgument("slot")) - .executes(CommandExecutor { _, args -> + .executes(NormalExecutor { _, args -> val scoreboard = Bukkit.getScoreboardManager().mainScoreboard val slot = (args["slot"] as ScoreboardSlot).displaySlot scoreboard.clearSlot(slot) @@ -930,7 +931,7 @@ fun argument_sound() { /* ANCHOR: argumentSound1 */ CommandAPICommand("sound") .withArguments(SoundArgument("sound")) - .executesPlayer(PlayerCommandExecutor { player, args -> + .executesPlayer(NormalExecutor { player, args -> player.world.playSound(player.location, args["sound"] as Sound, 100.0f, 1.0f) }) .register() @@ -939,7 +940,7 @@ CommandAPICommand("sound") /* ANCHOR: argumentSound2 */ CommandAPICommand("sound") .withArguments(SoundArgument.NamespacedKey("sound")) - .executesPlayer(PlayerCommandExecutor { player, args -> + .executesPlayer(NormalExecutor { player, args -> player.world.playSound(player.location, (args["sound"] as NamespacedKey).asString(), 100.0f, 1.0f) }) .register() @@ -951,7 +952,7 @@ fun argument_strings() { CommandAPICommand("message") .withArguments(PlayerArgument("target")) .withArguments(GreedyStringArgument("message")) - .executes(CommandExecutor { _, args -> + .executes(NormalExecutor { _, args -> (args["target"] as Player).sendMessage(args["message"] as String) }) .register() @@ -962,7 +963,7 @@ fun argument_team() { /* ANCHOR: argumentTeam1 */ CommandAPICommand("togglepvp") .withArguments(TeamArgument("team")) - .executes(CommandExecutor { _, args -> + .executes(NormalExecutor { _, args -> val team = args["team"] as Team // Toggle pvp @@ -977,7 +978,7 @@ fun argument_time() { CommandAPICommand("bigmsg") .withArguments(TimeArgument("duration")) .withArguments(GreedyStringArgument("message")) - .executes(CommandExecutor { _, args -> + .executes(NormalExecutor { _, args -> // Duration in ticks val duration = args["duration"] as Int val message = args["message"] as String @@ -995,7 +996,7 @@ fun argument_world() { /* ANCHOR: argumentWorld1 */ CommandAPICommand("unloadworld") .withArguments(WorldArgument("world")) - .executes(CommandExecutor { sender, args -> + .executes(NormalExecutor { sender, args -> val world = args["world"] as World // Unload the world (and save the world's chunks) @@ -1043,7 +1044,7 @@ val commandArguments = listOf( CommandAPICommand("cmd") .withArguments(commandArguments) - .executes(CommandExecutor { _, args -> + .executes(NormalExecutor { _, args -> val stringArg = args["arg0"] as String val potionArg = args["arg1"] as PotionEffectType val locationArg = args["arg2"] as Location @@ -1060,7 +1061,7 @@ CommandAPICommand("setconfig") CompletableFuture.supplyAsync { plugin.config.getKeys(false).toTypedArray() } } )) .withArguments(TextArgument("value")) - .executes(CommandExecutor { _, args -> + .executes(NormalExecutor { _, args -> val key = args["key"] as String val value = args["value"] as String plugin.config.set(key, value) @@ -1158,7 +1159,7 @@ val messageArgument = GreedyStringArgument("message") CommandAPICommand("emoji") .withArguments(messageArgument) - .executes(CommandExecutor { _, args -> + .executes(NormalExecutor { _, args -> Bukkit.broadcastMessage(args["message"] as String) }) .register() @@ -1205,7 +1206,7 @@ val commandSuggestions: ArgumentSuggestions = ArgumentSuggestions /* ANCHOR: brigadierSuggestions3 */ CommandAPICommand("commandargument") .withArguments(GreedyStringArgument("command").replaceSuggestions(commandSuggestions)) - .executes(CommandExecutor { sender, args -> + .executes(NormalExecutor { sender, args -> // Run the command using Bukkit.dispatchCommand() Bukkit.dispatchCommand(sender, args["command"] as String) }) @@ -1223,7 +1224,7 @@ CommandAPICommand("broadcast") // Translate the & in plain text and generate a new BaseComponent[] TextComponent.fromLegacyText(ChatColor.translateAlternateColorCodes('&', plainText)) } ) - .executesPlayer(PlayerCommandExecutor { _, args -> + .executesPlayer(NormalExecutor { _, args -> // The user still entered legacy text. We need to properly convert this // to a BaseComponent[] by converting to plain text then to BaseComponent[] val plainText: String = BaseComponent.toPlainText(*args["message"] as Array) @@ -1242,7 +1243,7 @@ CommandAPICommand("broadcast") // Translate the & in plain text and generate a new Component LegacyComponentSerializer.legacyAmpersand().deserialize(plainText) } ) - .executesPlayer(PlayerCommandExecutor { _, args -> + .executesPlayer(NormalExecutor { _, args -> // The user still entered legacy text. We need to properly convert this // to a Component by converting to plain text then to Component val plainText: String = PlainTextComponentSerializer.plainText().serialize(args["message"] as Component) @@ -1260,7 +1261,7 @@ CommandAPICommand("broadcast") // Translate the & in plain text and generate a new BaseComponent[] TextComponent.fromLegacyText(ChatColor.translateAlternateColorCodes('&', plainText)) } ) - .executesPlayer(PlayerCommandExecutor { _, args -> + .executesPlayer(NormalExecutor { _, args -> Bukkit.spigot().broadcast(*args["message"] as Array) }) .register() @@ -1275,7 +1276,7 @@ CommandAPICommand("broadcast") // Translate the & in plain text and generate a new Component LegacyComponentSerializer.legacyAmpersand().deserialize(plainText) } ) - .executesPlayer(PlayerCommandExecutor { _, args -> + .executesPlayer(NormalExecutor { _, args -> Bukkit.broadcast(args["message"] as Component) }) .register() @@ -1290,7 +1291,7 @@ CommandAPICommand("mycommand") .withOptionalArguments(PlayerArgument("player")) .withOptionalArguments(PlayerArgument("target")) .withOptionalArguments(GreedyStringArgument("message")) - .executesPlayer(PlayerCommandExecutor { player, args -> + .executesPlayer(NormalExecutor { player, args -> val name = args[0] as String // Access arguments by index val amount = args["amount"] as Int // Access arguments by node name val p = args.getOrDefault("player", player) as Player // Access arguments using the getOrDefault(String, Object) method @@ -1305,7 +1306,7 @@ CommandAPICommand("mycommand") /* ANCHOR: commandArguments2 */ CommandAPICommand("mycommand") .withArguments(EntitySelectorArgument.ManyEntities("entities")) - .executesPlayer(PlayerCommandExecutor { player, args -> + .executesPlayer(NormalExecutor { player, args -> val entitySelector = args.getRaw("entities")!! // Access the raw argument with getRaw(String) // Do whatever with the entity selector @@ -1316,7 +1317,7 @@ CommandAPICommand("mycommand") /* ANCHOR: commandArguments3 */ CommandAPICommand("mycommand") .withArguments(PlayerArgument("player")) - .executesPlayer(PlayerCommandExecutor { player, args -> + .executesPlayer(NormalExecutor { player, args -> val p: Player = args.getUnchecked("player")!! // Do whatever with the player @@ -1337,7 +1338,7 @@ CommandAPICommand("mycommand") .withOptionalArguments(playerArgument) .withOptionalArguments(targetArgument) .withOptionalArguments(messageArgument) - .executesPlayer(PlayerCommandExecutor { player, args -> + .executesPlayer(NormalExecutor { player, args -> val name: String = args.getByArgument(nameArgument)!! val amount: Int = args.getByArgument(amountArgument)!! val p: Player = args.getByArgumentOrDefault(playerArgument, player) @@ -1358,7 +1359,7 @@ val fruit = listOf("banana", "apple", "orange") // Register the command CommandAPICommand("getfruit") .withArguments(StringArgument("item").replaceSuggestions(ArgumentSuggestions.strings(fruit))) - .executes(CommandExecutor { _, args -> + .executes(NormalExecutor { _, args -> val inputFruit = args["item"] as String if(fruit.any { it == inputFruit }) { @@ -1379,7 +1380,7 @@ CommandAPICommand("broadcastmsg") .withArguments(GreedyStringArgument("message")) // The arguments .withAliases("broadcast", "broadcastmessage") // Command aliases .withPermission(CommandPermission.OP) // Required permissions - .executes(CommandExecutor { sender, args -> + .executes(NormalExecutor { sender, args -> val message = args["message"] as String Bukkit.getServer().broadcastMessage(message) }) @@ -1391,11 +1392,11 @@ class commandTrees : JavaPlugin() { fun commandTrees1() { /* ANCHOR: commandTrees1 */ CommandTree("sayhi") - .executes(CommandExecutor { sender, _ -> + .executes(NormalExecutor { sender, _ -> sender.sendMessage("Hi!") }) .then(PlayerArgument("target") - .executes(CommandExecutor { _, args -> + .executes(NormalExecutor { _, args -> val target = args["target"] as Player target.sendMessage("Hi") })) @@ -1407,7 +1408,7 @@ CommandTree("signedit") .then(LiteralArgument("set") .then(IntegerArgument("line_number", 1, 4) .then(GreedyStringArgument("text") - .executesPlayer(PlayerCommandExecutor { player, args -> + .executesPlayer(NormalExecutor { player, args -> // /signedit set val sign: Sign = getTargetSign(player) val line_number = args["line_number"] as Int @@ -1417,7 +1418,7 @@ CommandTree("signedit") })))) .then(LiteralArgument("clear") .then(IntegerArgument("line_number", 1, 4) - .executesPlayer(PlayerCommandExecutor { player, args -> + .executesPlayer(NormalExecutor { player, args -> // /signedit clear val sign: Sign = getTargetSign(player) val line_number = args["line_number"] as Int @@ -1426,7 +1427,7 @@ CommandTree("signedit") }))) .then(LiteralArgument("copy") .then(IntegerArgument("line_number", 1, 4) - .executesPlayer(PlayerCommandExecutor { player, args -> + .executesPlayer(NormalExecutor { player, args -> // /signedit copy val sign: Sign = getTargetSign(player) val line_number = args["line_number"] as Int @@ -1434,7 +1435,7 @@ CommandTree("signedit") }))) .then(LiteralArgument("paste") .then(IntegerArgument("line_number", 1, 4) - .executesPlayer(PlayerCommandExecutor { player, args -> + .executesPlayer(NormalExecutor { player, args -> // /signedit copy val sign: Sign = getTargetSign(player) val line_number = args["line_number"] as Int @@ -1481,7 +1482,7 @@ override fun onEnable() { // Register our new /gamemode, with survival, creative, adventure and spectator CommandAPICommand("gamemode") .withArguments(MultiLiteralArgument("gamemodes", "survival", "creative", "adventure", "spectator")) - .executes(CommandExecutor { sender, args -> + .executes(NormalExecutor { sender, args -> // Implementation of our /gamemode command }) .register() @@ -1598,7 +1599,7 @@ fun delegatedProperties() { CommandAPICommand("mycommand") .withArguments(StringArgument("string")) .withArguments(PlayerArgument("target")) - .executesPlayer(PlayerCommandExecutor { player, args -> + .executesPlayer(NormalExecutor { player, args -> val string: String by args val target: Player by args // Implementation... @@ -1615,7 +1616,7 @@ class Main : JavaPlugin() { // Commands which will be used in Minecraft functions are registered here CommandAPICommand("killall") - .executes(CommandExecutor { _, _ -> + .executes(NormalExecutor { _, _ -> // Kills all enemies in all worlds Bukkit.getWorlds().forEach { world -> world.livingEntities.forEach { entity -> entity.health = 0.0 } } }) @@ -1634,7 +1635,7 @@ fun functionWrapper() { /* ANCHOR: functionWrapper1 */ CommandAPICommand("runfunc") .withArguments(FunctionArgument("function")) - .executes(CommandExecutor { _, args -> + .executes(NormalExecutor { _, args -> val functions = args["function"] as Array for (function in functions) { function.run() // The command executor in this case is 'sender' @@ -1649,7 +1650,7 @@ fun help() { CommandAPICommand("mycmd") .withShortDescription("Says hi") .withFullDescription("Broadcasts hi to everyone on the server") - .executes(CommandExecutor { _, _ -> + .executes(NormalExecutor { _, _ -> Bukkit.broadcastMessage("Hi!") }) .register() @@ -1658,7 +1659,7 @@ CommandAPICommand("mycmd") /* ANCHOR: help2 */ CommandAPICommand("mycmd") .withHelp("Says hi", "Broadcasts hi to everyone on the server") - .executes(CommandExecutor { _, _ -> + .executes(NormalExecutor { _, _ -> Bukkit.broadcastMessage("Hi!") }) .register() @@ -1694,7 +1695,7 @@ fun help2() { /* ANCHOR: help4 */ return CommandAPICommand("mycmd") .withHelp(makeHelp("mycmd")) - .executes(CommandExecutor { _, _ -> + .executes(NormalExecutor { _, _ -> Bukkit.broadcastMessage("Hi!") }) .register() @@ -1707,7 +1708,7 @@ CommandAPICommand("mycommand") .withArguments(PlayerArgument("player")) .withArguments(IntegerArgument("value").setListed(false)) .withArguments(GreedyStringArgument("message")) - .executes(CommandExecutor { _, args -> + .executes(NormalExecutor { _, args -> // args == [player, message] val player = args["player"] as Player val message = args["message"] as String // Note that the IntegerArgument is not available in the CommandArguments @@ -1720,7 +1721,7 @@ CommandAPICommand("mycommand") fun native() { /* ANCHOR: native1 */ CommandAPICommand("break") - .executesNative(NativeCommandExecutor { sender, _ -> + .executesNative(NormalExecutor { sender, _ -> val location = sender.location location.block.breakNaturally() }) @@ -1735,7 +1736,7 @@ CommandAPICommand("broadcastmsg") .withArguments(GreedyStringArgument("message")) // The arguments .withAliases("broadcast", "broadcastmessage") // Command aliases .withPermission(CommandPermission.OP) // Required permissions - .executes(CommandExecutor { _, args -> + .executes(NormalExecutor { _, args -> val message = args["message"] as String Bukkit.getServer().broadcastMessage(message) }) @@ -1744,7 +1745,7 @@ CommandAPICommand("broadcastmsg") /* ANCHOR: normalExecutors2 */ CommandAPICommand("suicide") - .executesPlayer(PlayerCommandExecutor { player, _ -> + .executesPlayer(NormalExecutor { player, _ -> player.setHealth(0.0) }) .register() @@ -1752,10 +1753,10 @@ CommandAPICommand("suicide") /* ANCHOR: normalExecutors3 */ CommandAPICommand("suicide") - .executesPlayer(PlayerCommandExecutor { player, _ -> + .executesPlayer(NormalExecutor { player, _ -> player.setHealth(0.0) }) - .executesEntity(EntityCommandExecutor { entity, _ -> + .executesEntity(NormalExecutor { entity, _ -> entity.world.createExplosion(entity.location, 4f) entity.remove() }) @@ -1764,7 +1765,7 @@ CommandAPICommand("suicide") /* ANCHOR: normalExecutors4 */ CommandAPICommand("suicide") - .executes(CommandExecutor { sender, _ -> + .executes(NormalExecutor { sender, _ -> val entity = (if (sender is ProxiedCommandSender) sender.callee else sender) as LivingEntity entity.setHealth(0.0) }, ExecutorType.PLAYER, ExecutorType.PROXY) @@ -1776,7 +1777,7 @@ fun optionalArguments() { /* ANCHOR: optionalArguments1 */ CommandAPICommand("sayhi") .withOptionalArguments(PlayerArgument("target")) - .executesPlayer(PlayerCommandExecutor { player, args -> + .executesPlayer(NormalExecutor { player, args -> val target: Player? = args["target"] as Player? if (target != null) { target.sendMessage("Hi!") @@ -1790,7 +1791,7 @@ CommandAPICommand("sayhi") /* ANCHOR: optionalArguments2 */ CommandAPICommand("sayhi") .withOptionalArguments(PlayerArgument("target")) - .executesPlayer(PlayerCommandExecutor { player, args -> + .executesPlayer(NormalExecutor { player, args -> val target: Player = args.getOptional("target").orElse(player) as Player target.sendMessage("Hi!") }) @@ -1801,7 +1802,7 @@ CommandAPICommand("sayhi") CommandAPICommand("rate") .withOptionalArguments(StringArgument("topic").combineWith(IntegerArgument("rating", 0, 10))) .withOptionalArguments(PlayerArgument("target")) - .executes(CommandExecutor { sender, args -> + .executes(NormalExecutor { sender, args -> val topic: String? = args["topic"] as String? if (topic == null) { sender.sendMessage( @@ -1809,7 +1810,7 @@ CommandAPICommand("rate") "Select a topic to rate, then give a rating between 0 and 10", "You can optionally add a player at the end to give the rating to" ) - return@CommandExecutor + return@NormalExecutor } // We know this is not null because rating is required if topic is given @@ -1829,7 +1830,7 @@ fun permissions() { // Register the /god command with the permission node "command.god" CommandAPICommand("god") .withPermission(CommandPermission.fromString("command.god")) - .executesPlayer(PlayerCommandExecutor { player, _ -> + .executesPlayer(NormalExecutor { player, _ -> player.isInvulnerable = true }) .register() @@ -1839,7 +1840,7 @@ CommandAPICommand("god") // Register the /god command with the permission node "command.god", without creating a CommandPermission CommandAPICommand("god") .withPermission("command.god") - .executesPlayer(PlayerCommandExecutor { player, _ -> + .executesPlayer(NormalExecutor { player, _ -> player.isInvulnerable = true }) .register() @@ -1848,7 +1849,7 @@ CommandAPICommand("god") /* ANCHOR: permissions3 */ // Register /kill command normally. Since no permissions are applied, anyone can run this command CommandAPICommand("kill") - .executesPlayer(PlayerCommandExecutor { player, _ -> + .executesPlayer(NormalExecutor { player, _ -> player.health = 0.0 }) .register() @@ -1858,7 +1859,7 @@ CommandAPICommand("kill") // Adds the OP permission to the "target" argument. The sender requires OP to execute /kill CommandAPICommand("kill") .withArguments(PlayerArgument("target").withPermission(CommandPermission.OP)) - .executesPlayer(PlayerCommandExecutor { _, args -> + .executesPlayer(NormalExecutor { _, args -> (args["target"] as Player).health = 0.0 }) .register() @@ -1868,7 +1869,7 @@ CommandAPICommand("kill") // /economy - requires the permission "economy.self" to exectue CommandAPICommand("economy") .withPermission("economy.self") - .executesPlayer(PlayerCommandExecutor { player, _ -> + .executesPlayer(NormalExecutor { player, _ -> // send the executor their own balance here. }) .register() @@ -1877,7 +1878,7 @@ CommandAPICommand("economy") CommandAPICommand("economy") .withPermission("economy.other") // The important part of this example .withArguments(PlayerArgument("target")) - .executesPlayer(PlayerCommandExecutor { player, args -> + .executesPlayer(NormalExecutor { player, args -> val target = args["target"] as Player // send the executor the targets balance here. }) @@ -1888,7 +1889,7 @@ CommandAPICommand("economy") .withPermission("economy.admin.give") // The important part of this example .withArguments(PlayerArgument("target")) .withArguments(DoubleArgument("amount")) - .executesPlayer(PlayerCommandExecutor { player, args -> + .executesPlayer(NormalExecutor { player, args -> val target = args["target"] as Player val amount = args["amount"] as Double // update the targets balance here @@ -1899,7 +1900,7 @@ CommandAPICommand("economy") CommandAPICommand("economy") .withPermission("economy.admin.reset") // The important part of this example .withArguments(PlayerArgument("target")) - .executesPlayer(PlayerCommandExecutor { player, args -> + .executesPlayer(NormalExecutor { player, args -> val target = args["target"] as Player // reset the targets balance here }) @@ -1948,7 +1949,7 @@ args = listOf>(LiteralArgument("tp").withRequirement(testIfPlayerHas fun proxySender() { /* ANCHOR: proxySender1 */ CommandAPICommand("killme") - .executesPlayer(PlayerCommandExecutor { player, _ -> + .executesPlayer(NormalExecutor { player, _ -> player.setHealth(0.0) }) .register() @@ -1956,10 +1957,10 @@ CommandAPICommand("killme") /* ANCHOR: proxySender2 */ CommandAPICommand("killme") - .executesPlayer(PlayerCommandExecutor { player, _ -> + .executesPlayer(NormalExecutor { player, _ -> player.setHealth(0.0) }) - .executesProxy(ProxyCommandExecutor { proxy, _ -> + .executesProxy(NormalExecutor { proxy, _ -> // Check if the callee (target) is an Entity and kill it if (proxy.callee is LivingEntity) { (proxy.callee as LivingEntity).setHealth(0.0) @@ -1973,7 +1974,7 @@ fun requirements() { /* ANCHOR: requirements1 */ CommandAPICommand("repair") .withRequirement { (it as Player).level >= 30 } - .executesPlayer(PlayerCommandExecutor { player, _ -> + .executesPlayer(NormalExecutor { player, _ -> // Repair the item back to full durability val item = player.inventory.itemInMainHand @@ -2007,7 +2008,7 @@ arguments.add(StringArgument("partyName")) /* ANCHOR: requirements4 */ CommandAPICommand("party") .withArguments(*arguments.toTypedArray()) - .executesPlayer(PlayerCommandExecutor { player, args -> + .executesPlayer(NormalExecutor { player, args -> // Get the name of the party to create val partyName = args["partyName"] as String @@ -2056,7 +2057,7 @@ arguments.add(PlayerArgument("player") /* ANCHOR: requirements6 */ CommandAPICommand("party") .withArguments(arguments) - .executesPlayer(PlayerCommandExecutor { player, args -> + .executesPlayer(NormalExecutor { player, args -> val target = args["player"] as Player player.teleport(target) }) @@ -2066,7 +2067,7 @@ CommandAPICommand("party") /* ANCHOR: requirements7 */ CommandAPICommand("party") .withArguments(arguments) - .executesPlayer(PlayerCommandExecutor { player, args -> + .executesPlayer(NormalExecutor { player, args -> // Get the name of the party to create val partyName = args["partyName"] as String @@ -2083,7 +2084,7 @@ CommandAPICommand("someCommand") .withRequirement { (it as Player).level >= 30 } .withRequirement { (it as Player).inventory.contains(Material.DIAMOND_PICKAXE) } .withRequirement { (it as Player).isInvulnerable() } - .executesPlayer(PlayerCommandExecutor { player, args -> + .executesPlayer(NormalExecutor { player, args -> // Code goes here }) .register() @@ -2093,7 +2094,7 @@ CommandAPICommand("someCommand") fun resultingCommandExecutors() { /* ANCHOR: resultingCommandExecutors1 */ CommandAPICommand("randnum") - .executes(ResultingCommandExecutor { _, _ -> + .executes(ResultingExecutor { _, _ -> Random.nextInt() }) .register() @@ -2102,7 +2103,7 @@ CommandAPICommand("randnum") /* ANCHOR: resultingCommandExecutors2 */ // Register random number generator command from 1 to 99 (inclusive) CommandAPICommand("randomnumber") - .executes(ResultingCommandExecutor { _, _ -> + .executes(ResultingExecutor { _, _ -> (1..100).random() // Returns random number from 1 <= x < 100 }) .register() @@ -2112,7 +2113,7 @@ CommandAPICommand("randomnumber") // Register reward giving system for a target player CommandAPICommand("givereward") .withArguments(EntitySelectorArgument.OnePlayer("target")) - .executes(CommandExecutor { _, args -> + .executes(NormalExecutor { _, args -> val player = args["target"] as Player player.inventory.addItem(ItemStack(Material.DIAMOND, 64)) Bukkit.broadcastMessage("${player.name} won a rare 64 diamonds from a loot box!") @@ -2156,7 +2157,7 @@ val arguments = listOf>( // Register our command CommandAPICommand("giverecipe") .withArguments(arguments) - .executesPlayer(PlayerCommandExecutor { player, args -> + .executesPlayer(NormalExecutor { player, args -> val recipe = args["recipe"] as Recipe player.inventory.addItem(recipe.result) }) @@ -2188,7 +2189,7 @@ val safeArguments = listOf>( /* ANCHOR: safeArgumentSuggestions5 */ CommandAPICommand("spawnmob") .withArguments(safeArguments) - .executesPlayer(PlayerCommandExecutor { player, args -> + .executesPlayer(NormalExecutor { player, args -> val entityType = args["mob"] as EntityType player.world.spawnEntity(player.location, entityType) }) @@ -2211,7 +2212,7 @@ safeArgs.add(PotionEffectArgument("potioneffect").replaceSafeSuggestions(SafeSug /* ANCHOR: safeArgumentSuggestions7 */ CommandAPICommand("removeeffect") .withArguments(safeArgs) - .executesPlayer(PlayerCommandExecutor { _, args -> + .executesPlayer(NormalExecutor { _, args -> val target = args["target"] as Player val potionEffect = args["potioneffect"] as PotionEffectType target.removePotionEffect(potionEffect) @@ -2236,7 +2237,7 @@ class MyPlugin : JavaPlugin() { CommandAPI.onLoad(CommandAPIBukkitConfig(this).verboseOutput(true)) // Load with verbose output CommandAPICommand("ping") - .executes(CommandExecutor { sender, _ -> + .executes(NormalExecutor { sender, _ -> sender.sendMessage("pong!") }) .register() @@ -2268,7 +2269,7 @@ val arguments = listOf>( CommandAPICommand("warp") .withArguments(arguments) - .executesPlayer(PlayerCommandExecutor { player, args -> + .executesPlayer(NormalExecutor { player, args -> val warp = args["world"] as String player.teleport(warps[warp]!!) // Look up the warp in a map, for example }) @@ -2307,7 +2308,7 @@ val arguments = listOf>( CommandAPICommand("friendtp") .withArguments(arguments) - .executesPlayer(PlayerCommandExecutor { player, args -> + .executesPlayer(NormalExecutor { player, args -> val target = args["friend"] as Player player.teleport(target) }) @@ -2342,7 +2343,7 @@ commandArgs.add(GreedyStringArgument("message")) // Declare our command as normal CommandAPICommand("localmsg") .withArguments(*commandArgs.toTypedArray()) - .executesPlayer(PlayerCommandExecutor { _, args -> + .executesPlayer(NormalExecutor { _, args -> val target = args["target"] as Player val message = args["message"] as String target.sendMessage(message) @@ -2358,7 +2359,7 @@ fun subcommands() { val groupAdd = CommandAPICommand("add") .withArguments(StringArgument("permission")) .withArguments(StringArgument("groupName")) - .executes(CommandExecutor { sender, args -> + .executes(NormalExecutor { sender, args -> // perm group add code }) /* ANCHOR_END: subcommands1 */ @@ -2367,7 +2368,7 @@ val groupAdd = CommandAPICommand("add") val groupRemove = CommandAPICommand("remove") .withArguments(StringArgument("permission")) .withArguments(StringArgument("groupName")) - .executes(CommandExecutor { sender, args -> + .executes(NormalExecutor { sender, args -> // perm group remove code }) @@ -2388,14 +2389,14 @@ CommandAPICommand("perm") .withSubcommand(CommandAPICommand("add") .withArguments(StringArgument("permission")) .withArguments(StringArgument("groupName")) - .executes(CommandExecutor { sender, args -> + .executes(NormalExecutor { sender, args -> // perm group add code }) ) .withSubcommand(CommandAPICommand("remove") .withArguments(StringArgument("permission")) .withArguments(StringArgument("groupName")) - .executes(CommandExecutor { sender, args -> + .executes(NormalExecutor { sender, args -> // perm group remove code }) ) @@ -2404,14 +2405,14 @@ CommandAPICommand("perm") .withSubcommand(CommandAPICommand("add") .withArguments(StringArgument("permission")) .withArguments(StringArgument("userName")) - .executes(CommandExecutor { sender, args -> + .executes(NormalExecutor { sender, args -> // perm user add code }) ) .withSubcommand(CommandAPICommand("remove") .withArguments(StringArgument("permission")) .withArguments(StringArgument("userName")) - .executes(CommandExecutor { sender, args -> + .executes(NormalExecutor { sender, args -> // perm user remove code }) ) @@ -2439,7 +2440,7 @@ arguments.add(PlayerArgument("target")) /* ANCHOR: tooltips2 */ CommandAPICommand("emote") .withArguments(*arguments.toTypedArray()) - .executesPlayer(PlayerCommandExecutor { player, args -> + .executesPlayer(NormalExecutor { player, args -> val emote = args["emote"] as String val target = args["target"] as Player @@ -2479,7 +2480,7 @@ val customItems = arrayOf( CommandAPICommand("giveitem") .withArguments(StringArgument("item").replaceSuggestions(ArgumentSuggestions.stringsWithTooltips(*customItems))) // We use customItems[] as the input for our suggestions with tooltips - .executesPlayer(PlayerCommandExecutor { player, args -> + .executesPlayer(NormalExecutor { player, args -> val itemName = args["item"] as String // Give them the item @@ -2511,7 +2512,7 @@ val arguments = listOf>( /* ANCHOR: tooltips6 */ CommandAPICommand("warp") .withArguments(arguments) - .executesPlayer(PlayerCommandExecutor { player, args -> + .executesPlayer(NormalExecutor { player, args -> player.teleport(args["location"] as Location) }) .register() @@ -2525,31 +2526,31 @@ CommandTree("treeexample") // Set the aliases as you normally would .withAliases("treealias") // Set an executor on the command itself - .executes(CommandExecutor { sender, _ -> + .executes(NormalExecutor { sender, _ -> sender.sendMessage("Root with no arguments") }) // Create a new branch starting with a the literal 'integer' .then(LiteralArgument("integer") // Execute on the literal itself - .executes(CommandExecutor { sender, _ -> + .executes(NormalExecutor { sender, _ -> sender.sendMessage("Integer Branch with no arguments") }) // Create a further branch starting with an integer argument, which executes a command - .then(IntegerArgument("integer").executes(CommandExecutor { sender, args -> + .then(IntegerArgument("integer").executes(NormalExecutor { sender, args -> sender.sendMessage("Integer Branch with integer argument: ${args[0]}") }))) .then(LiteralArgument("biome") - .executes(CommandExecutor { sender, _ -> + .executes(NormalExecutor { sender, _ -> sender.sendMessage("Biome Branch with no arguments") }) - .then(BiomeArgument("biome").executes(CommandExecutor { sender, args -> + .then(BiomeArgument("biome").executes(NormalExecutor { sender, args -> sender.sendMessage("Biome Branch with biome argument: ${args[0]}") }))) .then(LiteralArgument("string") - .executes(CommandExecutor { sender, _ -> + .executes(NormalExecutor { sender, _ -> sender.sendMessage("String Branch with no arguments") }) - .then(StringArgument("string").executes(CommandExecutor { sender, args -> + .then(StringArgument("string").executes(NormalExecutor { sender, args -> sender.sendMessage("String Branch with string argument: ${args[0]}") }))) // Call register to finish as you normally would diff --git a/commandapi-documentation-velocity-code/src/main/kotlin/dev/jorel/commandapi/examples/kotlin/Examples.kt b/commandapi-documentation-velocity-code/src/main/kotlin/dev/jorel/commandapi/examples/kotlin/Examples.kt index 6dff041643..58e32243c6 100644 --- a/commandapi-documentation-velocity-code/src/main/kotlin/dev/jorel/commandapi/examples/kotlin/Examples.kt +++ b/commandapi-documentation-velocity-code/src/main/kotlin/dev/jorel/commandapi/examples/kotlin/Examples.kt @@ -9,7 +9,7 @@ import dev.jorel.commandapi.CommandAPICommand import dev.jorel.commandapi.CommandAPIVelocity import dev.jorel.commandapi.CommandAPIVelocityConfig import dev.jorel.commandapi.arguments.IntegerArgument -import dev.jorel.commandapi.executors.PlayerCommandExecutor +import dev.jorel.commandapi.executors.NormalExecutor import net.kyori.adventure.text.Component import org.slf4j.Logger import java.util.concurrent.ThreadLocalRandom @@ -22,7 +22,7 @@ fun velocityIntro() { CommandAPICommand("randomnumber") .withArguments(IntegerArgument("min")) .withArguments(IntegerArgument("max")) - .executesPlayer(PlayerCommandExecutor { player, args -> + .executesPlayer(NormalExecutor { player, args -> val min = args["min"] as Int val max = args["max"] as Int val random = ThreadLocalRandom.current() diff --git a/commandapi-kotlin/commandapi-bukkit-kotlin/src/main/kotlin/dev/jorel/commandapi/kotlindsl/ExecutorDSL.kt b/commandapi-kotlin/commandapi-bukkit-kotlin/src/main/kotlin/dev/jorel/commandapi/kotlindsl/ExecutorDSL.kt index f5bc5b0f9c..58115f293e 100644 --- a/commandapi-kotlin/commandapi-bukkit-kotlin/src/main/kotlin/dev/jorel/commandapi/kotlindsl/ExecutorDSL.kt +++ b/commandapi-kotlin/commandapi-bukkit-kotlin/src/main/kotlin/dev/jorel/commandapi/kotlindsl/ExecutorDSL.kt @@ -1,48 +1,14 @@ package dev.jorel.commandapi.kotlindsl import dev.jorel.commandapi.BukkitExecutable -import dev.jorel.commandapi.commandsenders.BukkitBlockCommandSender -import dev.jorel.commandapi.commandsenders.BukkitCommandSender -import dev.jorel.commandapi.commandsenders.BukkitConsoleCommandSender -import dev.jorel.commandapi.commandsenders.BukkitEntity -import dev.jorel.commandapi.commandsenders.BukkitNativeProxyCommandSender -import dev.jorel.commandapi.commandsenders.BukkitPlayer -import dev.jorel.commandapi.commandsenders.BukkitRemoteConsoleCommandSender import dev.jorel.commandapi.executors.CommandArguments -import dev.jorel.commandapi.executors.CommandBlockCommandExecutor -import dev.jorel.commandapi.executors.CommandBlockExecutionInfo -import dev.jorel.commandapi.executors.CommandBlockResultingCommandExecutor -import dev.jorel.commandapi.executors.CommandBlockResultingExecutionInfo -import dev.jorel.commandapi.executors.CommandExecutionInfo -import dev.jorel.commandapi.executors.CommandExecutor -import dev.jorel.commandapi.executors.ConsoleCommandExecutor -import dev.jorel.commandapi.executors.ConsoleExecutionInfo -import dev.jorel.commandapi.executors.ConsoleResultingCommandExecutor -import dev.jorel.commandapi.executors.ConsoleResultingExecutionInfo -import dev.jorel.commandapi.executors.EntityCommandExecutor -import dev.jorel.commandapi.executors.EntityExecutionInfo -import dev.jorel.commandapi.executors.EntityResultingCommandExecutor -import dev.jorel.commandapi.executors.EntityResultingExecutionInfo import dev.jorel.commandapi.executors.ExecutionInfo -import dev.jorel.commandapi.executors.NativeCommandExecutor -import dev.jorel.commandapi.executors.NativeExecutionInfo -import dev.jorel.commandapi.executors.NativeResultingCommandExecutor -import dev.jorel.commandapi.executors.NativeResultingExecutionInfo -import dev.jorel.commandapi.executors.PlayerCommandExecutor -import dev.jorel.commandapi.executors.PlayerExecutionInfo -import dev.jorel.commandapi.executors.PlayerResultingCommandExecutor -import dev.jorel.commandapi.executors.PlayerResultingExecutionInfo -import dev.jorel.commandapi.executors.ProxyCommandExecutor -import dev.jorel.commandapi.executors.ProxyExecutionInfo -import dev.jorel.commandapi.executors.ProxyResultingCommandExecutor -import dev.jorel.commandapi.executors.ProxyResultingExecutionInfo -import dev.jorel.commandapi.executors.RemoteConsoleCommandExecutor -import dev.jorel.commandapi.executors.RemoteConsoleExecutionInfo -import dev.jorel.commandapi.executors.RemoteConsoleResultingCommandExecutor -import dev.jorel.commandapi.executors.RemoteConsoleResultingExecutionInfo -import dev.jorel.commandapi.executors.ResultingCommandExecutionInfo -import dev.jorel.commandapi.executors.ResultingCommandExecutor +import dev.jorel.commandapi.executors.NormalExecutor +import dev.jorel.commandapi.executors.ResultingExecutor +import dev.jorel.commandapi.executors.NormalExecutorInfo +import dev.jorel.commandapi.executors.ResultingExecutorInfo import dev.jorel.commandapi.wrappers.NativeProxyCommandSender + import org.bukkit.command.BlockCommandSender import org.bukkit.command.CommandSender import org.bukkit.command.ConsoleCommandSender @@ -52,109 +18,109 @@ import org.bukkit.entity.Entity import org.bukkit.entity.Player // Executors for CommandAPICommand, CommandTree and ArgumentTree -inline fun BukkitExecutable<*>.anyExecutor(crossinline executor: (CommandSender, CommandArguments) -> Unit): BukkitExecutable<*> = executes(CommandExecutor { sender, args -> +inline fun BukkitExecutable<*>.anyExecutor(crossinline executor: (CommandSender, CommandArguments) -> Unit): BukkitExecutable<*> = executes( NormalExecutor { sender: CommandSender, args: CommandArguments -> executor(sender, args) }) -inline fun BukkitExecutable<*>.playerExecutor(crossinline executor: (Player, CommandArguments) -> Unit): BukkitExecutable<*> = executesPlayer(PlayerCommandExecutor { sender, args -> +inline fun BukkitExecutable<*>.playerExecutor(crossinline executor: (Player, CommandArguments) -> Unit): BukkitExecutable<*> = executesPlayer(NormalExecutor { sender, args -> executor(sender, args) }) -inline fun BukkitExecutable<*>.entityExecutor(crossinline executor: (Entity, CommandArguments) -> Unit): BukkitExecutable<*> = executesEntity(EntityCommandExecutor { sender, args -> +inline fun BukkitExecutable<*>.entityExecutor(crossinline executor: (Entity, CommandArguments) -> Unit): BukkitExecutable<*> = executesEntity(NormalExecutor { sender, args -> executor(sender, args) }) -inline fun BukkitExecutable<*>.consoleExecutor(crossinline executor: (ConsoleCommandSender, CommandArguments) -> Unit): BukkitExecutable<*> = executesConsole(ConsoleCommandExecutor { sender, args -> +inline fun BukkitExecutable<*>.consoleExecutor(crossinline executor: (ConsoleCommandSender, CommandArguments) -> Unit): BukkitExecutable<*> = executesConsole(NormalExecutor { sender, args -> executor(sender, args) }) -inline fun BukkitExecutable<*>.commandBlockExecutor(crossinline executor: (BlockCommandSender, CommandArguments) -> Unit): BukkitExecutable<*> = executesCommandBlock(CommandBlockCommandExecutor { sender, args -> +inline fun BukkitExecutable<*>.commandBlockExecutor(crossinline executor: (BlockCommandSender, CommandArguments) -> Unit): BukkitExecutable<*> = executesCommandBlock(NormalExecutor { sender, args -> executor(sender, args) }) -inline fun BukkitExecutable<*>.proxyExecutor(crossinline executor: (ProxiedCommandSender, CommandArguments) -> Unit): BukkitExecutable<*> = executesProxy(ProxyCommandExecutor { sender, args -> +inline fun BukkitExecutable<*>.proxyExecutor(crossinline executor: (NativeProxyCommandSender, CommandArguments) -> Unit): BukkitExecutable<*> = executesProxy(NormalExecutor { sender, args -> executor(sender, args) }) -inline fun BukkitExecutable<*>.nativeExecutor(crossinline executor: (NativeProxyCommandSender, CommandArguments) -> Unit): BukkitExecutable<*> = executesNative(NativeCommandExecutor { sender, args -> +inline fun BukkitExecutable<*>.nativeExecutor(crossinline executor: (NativeProxyCommandSender, CommandArguments) -> Unit): BukkitExecutable<*> = executesNative(NormalExecutor { sender, args -> executor(sender, args) }) -inline fun BukkitExecutable<*>.remoteConsoleExecutor(crossinline executor: (RemoteConsoleCommandSender, CommandArguments) -> Unit): BukkitExecutable<*> = executesRemoteConsole(RemoteConsoleCommandExecutor { sender, args -> +inline fun BukkitExecutable<*>.remoteConsoleExecutor(crossinline executor: (RemoteConsoleCommandSender, CommandArguments) -> Unit): BukkitExecutable<*> = executesRemoteConsole(NormalExecutor { sender, args -> executor(sender, args) }) // Resulting executors -inline fun BukkitExecutable<*>.anyResultingExecutor(crossinline executor: (CommandSender, CommandArguments) -> Int): BukkitExecutable<*> = executes(ResultingCommandExecutor { sender, args -> +inline fun BukkitExecutable<*>.anyResultingExecutor(crossinline executor: (CommandSender, CommandArguments) -> Int): BukkitExecutable<*> = executes(ResultingExecutor { sender, args -> executor(sender, args) }) -inline fun BukkitExecutable<*>.playerResultingExecutor(crossinline executor: (Player, CommandArguments) -> Int): BukkitExecutable<*> = executesPlayer(PlayerResultingCommandExecutor { sender, args -> +inline fun BukkitExecutable<*>.playerResultingExecutor(crossinline executor: (Player, CommandArguments) -> Int): BukkitExecutable<*> = executesPlayer(ResultingExecutor { sender, args -> executor(sender, args) }) -inline fun BukkitExecutable<*>.entityResultingExecutor(crossinline executor: (Entity, CommandArguments) -> Int): BukkitExecutable<*> = executesEntity(EntityResultingCommandExecutor { sender, args -> +inline fun BukkitExecutable<*>.entityResultingExecutor(crossinline executor: (Entity, CommandArguments) -> Int): BukkitExecutable<*> = executesEntity(ResultingExecutor { sender, args -> executor(sender, args) }) -inline fun BukkitExecutable<*>.consoleResultingExecutor(crossinline executor: (ConsoleCommandSender, CommandArguments) -> Int): BukkitExecutable<*> = executesConsole(ConsoleResultingCommandExecutor { sender, args -> +inline fun BukkitExecutable<*>.consoleResultingExecutor(crossinline executor: (ConsoleCommandSender, CommandArguments) -> Int): BukkitExecutable<*> = executesConsole(ResultingExecutor { sender, args -> executor(sender, args) }) -inline fun BukkitExecutable<*>.commandBlockResultingExecutor(crossinline executor: (BlockCommandSender, CommandArguments) -> Int): BukkitExecutable<*> = executesCommandBlock(CommandBlockResultingCommandExecutor { sender, args -> +inline fun BukkitExecutable<*>.commandBlockResultingExecutor(crossinline executor: (BlockCommandSender, CommandArguments) -> Int): BukkitExecutable<*> = executesCommandBlock(ResultingExecutor { sender, args -> executor(sender, args) }) -inline fun BukkitExecutable<*>.proxyResultingExecutor(crossinline executor: (ProxiedCommandSender, CommandArguments) -> Int): BukkitExecutable<*> = executesProxy(ProxyResultingCommandExecutor { sender, args -> +inline fun BukkitExecutable<*>.proxyResultingExecutor(crossinline executor: (NativeProxyCommandSender, CommandArguments) -> Int): BukkitExecutable<*> = executesProxy(ResultingExecutor { sender, args -> executor(sender, args) }) -inline fun BukkitExecutable<*>.nativeResultingExecutor(crossinline executor: (NativeProxyCommandSender, CommandArguments) -> Int): BukkitExecutable<*> = executesNative(NativeResultingCommandExecutor { sender, args -> +inline fun BukkitExecutable<*>.nativeResultingExecutor(crossinline executor: (NativeProxyCommandSender, CommandArguments) -> Int): BukkitExecutable<*> = executesNative(ResultingExecutor { sender, args -> executor(sender, args) }) -inline fun BukkitExecutable<*>.remoteConsoleResultingExecutor(crossinline executor: (RemoteConsoleCommandSender, CommandArguments) -> Int): BukkitExecutable<*> = executesRemoteConsole(RemoteConsoleResultingCommandExecutor { sender, args -> +inline fun BukkitExecutable<*>.remoteConsoleResultingExecutor(crossinline executor: (RemoteConsoleCommandSender, CommandArguments) -> Int): BukkitExecutable<*> = executesRemoteConsole(ResultingExecutor { sender, args -> executor(sender, args) }) // ExecutionInfo normal executors -inline fun BukkitExecutable<*>.anyExecutionInfo(crossinline executor: (ExecutionInfo>) -> Unit): BukkitExecutable<*> = executes(CommandExecutionInfo { info -> +inline fun BukkitExecutable<*>.anyExecutionInfo(crossinline executor: (ExecutionInfo) -> Unit): BukkitExecutable<*> = executes(NormalExecutorInfo { info -> executor(info) }) -inline fun BukkitExecutable<*>.playerExecutionInfo(crossinline executor: (ExecutionInfo) -> Unit): BukkitExecutable<*> = executesPlayer(PlayerExecutionInfo { info -> +inline fun BukkitExecutable<*>.playerExecutionInfo(crossinline executor: (ExecutionInfo) -> Unit): BukkitExecutable<*> = executesPlayer(NormalExecutorInfo { info -> executor(info) }) -inline fun BukkitExecutable<*>.entityExecutionInfo(crossinline executor: (ExecutionInfo) -> Unit): BukkitExecutable<*> = executesEntity(EntityExecutionInfo { info -> +inline fun BukkitExecutable<*>.entityExecutionInfo(crossinline executor: (ExecutionInfo) -> Unit): BukkitExecutable<*> = executesEntity(NormalExecutorInfo { info -> executor(info) }) -inline fun BukkitExecutable<*>.consoleExecutionInfo(crossinline executor: (ExecutionInfo) -> Unit): BukkitExecutable<*> = executesConsole(ConsoleExecutionInfo { info -> +inline fun BukkitExecutable<*>.consoleExecutionInfo(crossinline executor: (ExecutionInfo) -> Unit): BukkitExecutable<*> = executesConsole(NormalExecutorInfo { info -> executor(info) }) -inline fun BukkitExecutable<*>.commandBlockExecutionInfo(crossinline executor: (ExecutionInfo) -> Unit): BukkitExecutable<*> = executesCommandBlock(CommandBlockExecutionInfo { info -> +inline fun BukkitExecutable<*>.commandBlockExecutionInfo(crossinline executor: (ExecutionInfo) -> Unit): BukkitExecutable<*> = executesCommandBlock(NormalExecutorInfo { info -> executor(info) }) -inline fun BukkitExecutable<*>.proxyExecutionInfo(crossinline executor: (ExecutionInfo) -> Unit): BukkitExecutable<*> = executesProxy(ProxyExecutionInfo { info -> +inline fun BukkitExecutable<*>.proxyExecutionInfo(crossinline executor: (ExecutionInfo) -> Unit): BukkitExecutable<*> = executesProxy(NormalExecutorInfo { info -> executor(info) }) -inline fun BukkitExecutable<*>.nativeExecutionInfo(crossinline executor: (ExecutionInfo) -> Unit): BukkitExecutable<*> = executesNative(NativeExecutionInfo { info -> +inline fun BukkitExecutable<*>.nativeExecutionInfo(crossinline executor: (ExecutionInfo) -> Unit): BukkitExecutable<*> = executesNative(NormalExecutorInfo { info -> executor(info) }) -inline fun BukkitExecutable<*>.remoteConsoleExecutionInfo(crossinline executor: (ExecutionInfo) -> Unit): BukkitExecutable<*> = executesRemoteConsole(RemoteConsoleExecutionInfo { info -> +inline fun BukkitExecutable<*>.remoteConsoleExecutionInfo(crossinline executor: (ExecutionInfo) -> Unit): BukkitExecutable<*> = executesRemoteConsole(NormalExecutorInfo { info -> executor(info) }) // ExecutionInfo resulting executors -inline fun BukkitExecutable<*>.anyResultingExecutionInfo(crossinline executor: (ExecutionInfo>) -> Int): BukkitExecutable<*> = executes(ResultingCommandExecutionInfo { info -> +inline fun BukkitExecutable<*>.anyResultingExecutionInfo(crossinline executor: (ExecutionInfo) -> Int): BukkitExecutable<*> = executes(ResultingExecutorInfo { info -> executor(info) }) -inline fun BukkitExecutable<*>.playerResultingExecutionInfo(crossinline executor: (ExecutionInfo) -> Int): BukkitExecutable<*> = executesPlayer(PlayerResultingExecutionInfo { info -> +inline fun BukkitExecutable<*>.playerResultingExecutionInfo(crossinline executor: (ExecutionInfo) -> Int): BukkitExecutable<*> = executesPlayer(ResultingExecutorInfo { info -> executor(info) }) -inline fun BukkitExecutable<*>.entityResultingExecutionInfo(crossinline executor: (ExecutionInfo) -> Int): BukkitExecutable<*> = executesEntity(EntityResultingExecutionInfo { info -> +inline fun BukkitExecutable<*>.entityResultingExecutionInfo(crossinline executor: (ExecutionInfo) -> Int): BukkitExecutable<*> = executesEntity(ResultingExecutorInfo { info -> executor(info) }) -inline fun BukkitExecutable<*>.consoleResultingExecutionInfo(crossinline executor: (ExecutionInfo) -> Int): BukkitExecutable<*> = executesConsole(ConsoleResultingExecutionInfo { info -> +inline fun BukkitExecutable<*>.consoleResultingExecutionInfo(crossinline executor: (ExecutionInfo) -> Int): BukkitExecutable<*> = executesConsole(ResultingExecutorInfo { info -> executor(info) }) -inline fun BukkitExecutable<*>.commandBlockResultingExecutionInfo(crossinline executor: (ExecutionInfo) -> Int): BukkitExecutable<*> = executesCommandBlock(CommandBlockResultingExecutionInfo { info -> +inline fun BukkitExecutable<*>.commandBlockResultingExecutionInfo(crossinline executor: (ExecutionInfo) -> Int): BukkitExecutable<*> = executesCommandBlock(ResultingExecutorInfo { info -> executor(info) }) -inline fun BukkitExecutable<*>.proxyResultingExecutionInfo(crossinline executor: (ExecutionInfo) -> Int): BukkitExecutable<*> = executesProxy(ProxyResultingExecutionInfo { info -> +inline fun BukkitExecutable<*>.proxyResultingExecutionInfo(crossinline executor: (ExecutionInfo) -> Int): BukkitExecutable<*> = executesProxy(ResultingExecutorInfo { info -> executor(info) }) -inline fun BukkitExecutable<*>.nativeResultingExecutionInfo(crossinline executor: (ExecutionInfo) -> Int): BukkitExecutable<*> = executesNative(NativeResultingExecutionInfo { info -> +inline fun BukkitExecutable<*>.nativeResultingExecutionInfo(crossinline executor: (ExecutionInfo) -> Int): BukkitExecutable<*> = executesNative(ResultingExecutorInfo { info -> executor(info) }) -inline fun BukkitExecutable<*>.remoteConsoleResultingExecutionInfo(crossinline executor: (ExecutionInfo) -> Int): BukkitExecutable<*> = executesRemoteConsole(RemoteConsoleResultingExecutionInfo { info -> +inline fun BukkitExecutable<*>.remoteConsoleResultingExecutionInfo(crossinline executor: (ExecutionInfo) -> Int): BukkitExecutable<*> = executesRemoteConsole(ResultingExecutorInfo { info -> executor(info) }) \ No newline at end of file diff --git a/commandapi-kotlin/commandapi-velocity-kotlin/src/main/kotlin/dev/jorel/commandapi/kotlindsl/ExecutorDSL.kt b/commandapi-kotlin/commandapi-velocity-kotlin/src/main/kotlin/dev/jorel/commandapi/kotlindsl/ExecutorDSL.kt index 31edac5ae1..7f86caf18a 100644 --- a/commandapi-kotlin/commandapi-velocity-kotlin/src/main/kotlin/dev/jorel/commandapi/kotlindsl/ExecutorDSL.kt +++ b/commandapi-kotlin/commandapi-velocity-kotlin/src/main/kotlin/dev/jorel/commandapi/kotlindsl/ExecutorDSL.kt @@ -4,54 +4,51 @@ import com.velocitypowered.api.command.CommandSource import com.velocitypowered.api.proxy.ConsoleCommandSource import com.velocitypowered.api.proxy.Player import dev.jorel.commandapi.VelocityExecutable -import dev.jorel.commandapi.commandsenders.VelocityCommandSender -import dev.jorel.commandapi.commandsenders.VelocityConsoleCommandSender -import dev.jorel.commandapi.commandsenders.VelocityPlayer import dev.jorel.commandapi.executors.* // Executors for CommandAPICommand, CommandTree and ArgumentTree -inline fun VelocityExecutable<*>.anyExecutor(crossinline executor: (CommandSource, CommandArguments) -> Unit): VelocityExecutable<*> = executes(CommandExecutor { sender, args -> +inline fun VelocityExecutable<*>.anyExecutor(crossinline executor: (CommandSource, CommandArguments) -> Unit): VelocityExecutable<*> = executes(NormalExecutor { sender, args -> executor(sender, args) }) -inline fun VelocityExecutable<*>.playerExecutor(crossinline executor: (Player, CommandArguments) -> Unit): VelocityExecutable<*> = executesPlayer(PlayerCommandExecutor { sender, args -> +inline fun VelocityExecutable<*>.playerExecutor(crossinline executor: (Player, CommandArguments) -> Unit): VelocityExecutable<*> = executesPlayer(NormalExecutor { sender, args -> executor(sender, args) }) -inline fun VelocityExecutable<*>.consoleExecutor(crossinline executor: (ConsoleCommandSource, CommandArguments) -> Unit): VelocityExecutable<*> = executesConsole(ConsoleCommandExecutor { sender, args -> +inline fun VelocityExecutable<*>.consoleExecutor(crossinline executor: (ConsoleCommandSource, CommandArguments) -> Unit): VelocityExecutable<*> = executesConsole(NormalExecutor { sender, args -> executor(sender, args) }) // Resulting executors -inline fun VelocityExecutable<*>.anyResultingExecutor(crossinline executor: (CommandSource, CommandArguments) -> Int): VelocityExecutable<*> = executes(ResultingCommandExecutor { sender, args -> +inline fun VelocityExecutable<*>.anyResultingExecutor(crossinline executor: (CommandSource, CommandArguments) -> Int): VelocityExecutable<*> = executes(ResultingExecutor { sender, args -> executor(sender, args) }) -inline fun VelocityExecutable<*>.playerResultingExecutor(crossinline executor: (Player, CommandArguments) -> Int): VelocityExecutable<*> = executesPlayer(PlayerResultingCommandExecutor { sender, args -> +inline fun VelocityExecutable<*>.playerResultingExecutor(crossinline executor: (Player, CommandArguments) -> Int): VelocityExecutable<*> = executesPlayer(ResultingExecutor { sender, args -> executor(sender, args) }) -inline fun VelocityExecutable<*>.consoleResultingExecutor(crossinline executor: (ConsoleCommandSource, CommandArguments) -> Int): VelocityExecutable<*> = executesConsole(ConsoleResultingCommandExecutor { sender, args -> +inline fun VelocityExecutable<*>.consoleResultingExecutor(crossinline executor: (ConsoleCommandSource, CommandArguments) -> Int): VelocityExecutable<*> = executesConsole(ResultingExecutor { sender, args -> executor(sender, args) }) // ExecutionInfo normal executors -inline fun VelocityExecutable<*>.anyExecutionInfo(crossinline executor: (ExecutionInfo>) -> Unit): VelocityExecutable<*> = executes(CommandExecutionInfo { info -> +inline fun VelocityExecutable<*>.anyExecutionInfo(crossinline executor: (ExecutionInfo) -> Unit): VelocityExecutable<*> = executes(NormalExecutorInfo { info -> executor(info) }) -inline fun VelocityExecutable<*>.playerExecutionInfo(crossinline executor: (ExecutionInfo) -> Unit): VelocityExecutable<*> = executesPlayer(PlayerExecutionInfo { info -> +inline fun VelocityExecutable<*>.playerExecutionInfo(crossinline executor: (ExecutionInfo) -> Unit): VelocityExecutable<*> = executesPlayer(NormalExecutorInfo { info -> executor(info) }) -inline fun VelocityExecutable<*>.consoleExecutionInfo(crossinline executor: (ExecutionInfo) -> Unit): VelocityExecutable<*> = executesConsole(ConsoleExecutionInfo { info -> +inline fun VelocityExecutable<*>.consoleExecutionInfo(crossinline executor: (ExecutionInfo) -> Unit): VelocityExecutable<*> = executesConsole(NormalExecutorInfo { info -> executor(info) }) // ExecutionInfo resulting executors -inline fun VelocityExecutable<*>.anyResultingExecutionInfo(crossinline executor: (ExecutionInfo>) -> Int): VelocityExecutable<*> = executes(ResultingCommandExecutionInfo { info -> +inline fun VelocityExecutable<*>.anyResultingExecutionInfo(crossinline executor: (ExecutionInfo) -> Int): VelocityExecutable<*> = executes(ResultingExecutorInfo { info -> executor(info) }) -inline fun VelocityExecutable<*>.playerResultingExecutionInfo(crossinline executor: (ExecutionInfo) -> Int): VelocityExecutable<*> = executesPlayer(PlayerResultingExecutionInfo { info -> +inline fun VelocityExecutable<*>.playerResultingExecutionInfo(crossinline executor: (ExecutionInfo) -> Int): VelocityExecutable<*> = executesPlayer(ResultingExecutorInfo { info -> executor(info) }) -inline fun VelocityExecutable<*>.consoleResultingExecutionInfo(crossinline executor: (ExecutionInfo) -> Int): VelocityExecutable<*> = executesConsole(ConsoleResultingExecutionInfo { info -> +inline fun VelocityExecutable<*>.consoleResultingExecutionInfo(crossinline executor: (ExecutionInfo) -> Int): VelocityExecutable<*> = executesConsole(ResultingExecutorInfo { info -> executor(info) }) \ No newline at end of file diff --git a/commandapi-platforms/commandapi-bukkit/commandapi-bukkit-core/src/main/java/dev/jorel/commandapi/BukkitExecutable.java b/commandapi-platforms/commandapi-bukkit/commandapi-bukkit-core/src/main/java/dev/jorel/commandapi/BukkitExecutable.java index 08d26ffa64..d02ca16783 100644 --- a/commandapi-platforms/commandapi-bukkit/commandapi-bukkit-core/src/main/java/dev/jorel/commandapi/BukkitExecutable.java +++ b/commandapi-platforms/commandapi-bukkit/commandapi-bukkit-core/src/main/java/dev/jorel/commandapi/BukkitExecutable.java @@ -1,180 +1,128 @@ package dev.jorel.commandapi; -import dev.jorel.commandapi.commandsenders.BukkitCommandSender; -import dev.jorel.commandapi.exceptions.WrapperCommandSyntaxException; -import dev.jorel.commandapi.executors.*; +import org.bukkit.command.BlockCommandSender; import org.bukkit.command.CommandSender; +import org.bukkit.command.ConsoleCommandSender; +import org.bukkit.command.ProxiedCommandSender; +import org.bukkit.command.RemoteConsoleCommandSender; +import org.bukkit.entity.Entity; +import org.bukkit.entity.Player; + +import dev.jorel.commandapi.executors.BukkitNormalTypedExecutor; +import dev.jorel.commandapi.executors.BukkitResultingTypedExecutor; +import dev.jorel.commandapi.executors.ExecutorType; +import dev.jorel.commandapi.executors.NormalExecutor; +import dev.jorel.commandapi.executors.NormalExecutorInfo; +import dev.jorel.commandapi.executors.ResultingExecutor; +import dev.jorel.commandapi.executors.ResultingExecutorInfo; +import dev.jorel.commandapi.wrappers.NativeProxyCommandSender; public interface BukkitExecutable /// @endcond > extends PlatformExecutable { - // Regular command executor /** * Adds an executor to the current command builder * - * @param executor A lambda of type (CommandSender, Object[]) -> () that will be executed when the command is run + * @param executor A lambda of type ExecutionInfo<CommandSender, ?> -> () that will be executed when the command is run * @param types A list of executor types to use this executes method for. * @return this command builder */ - default Impl executes(CommandExecutor executor, ExecutorType... types) { + default Impl executes(NormalExecutorInfo executor, ExecutorType... types) { if (types == null || types.length == 0) { - getExecutor().addNormalExecutor(executor); - } else { - for (ExecutorType type : types) { - getExecutor().addNormalExecutor(new CommandExecutor() { - @Override - public void run(CommandSender sender, CommandArguments args) throws WrapperCommandSyntaxException { - executor.executeWith(new BukkitExecutionInfo<>(sender, CommandAPIBukkit.get().wrapCommandSender(sender), args)); - } - - @Override - public ExecutorType getType() { - return type; - } - }); - } + types = new ExecutorType[]{ExecutorType.ALL}; } + + getExecutor().addExecutor(new BukkitNormalTypedExecutor<>(executor, types)); return instance(); } /** * Adds an executor to the current command builder * - * @param executor A lambda of type (BukkitCommandExecutionInfo) -> () that will be executed when the command is run + * @param executor A lambda of type (CommandSender, CommandArguments) -> () that will be executed when the command is run * @param types A list of executor types to use this executes method for. * @return this command builder */ - default Impl executes(CommandExecutionInfo executor, ExecutorType... types) { - if (types == null || types.length == 0) { - getExecutor().addNormalExecutor(executor); - } else { - for (ExecutorType type : types) { - getExecutor().addNormalExecutor(new CommandExecutionInfo() { - - @Override - public void run(ExecutionInfo> info) throws WrapperCommandSyntaxException { - executor.executeWith(info); - } - - @Override - public ExecutorType getType() { - return type; - } - }); - } - } - return instance(); + default Impl executes(NormalExecutor executor, ExecutorType... types) { + // While we can cast directly to `NormalExecutorInfo` (because `NormalExecutor` extends it), this method + // is necessary to help Java identify the expression signature of user defined lambdas. + // The same applies for the rest of the executes methods. + return executes((NormalExecutorInfo) executor, types); } /** * Adds an executor to the current command builder * - * @param executor A lambda of type (CommandSender, CommandArguments) -> int that will be executed when the command is run + * @param executor A lambda of type ExecutionInfo<CommandSender, ?> -> int that will be executed when the command is run * @param types A list of executor types to use this executes method for. * @return this command builder */ - default Impl executes(ResultingCommandExecutor executor, ExecutorType... types) { + default Impl executes(ResultingExecutorInfo executor, ExecutorType... types) { if (types == null || types.length == 0) { - getExecutor().addResultingExecutor(executor); - } else { - for (ExecutorType type : types) { - getExecutor().addResultingExecutor(new ResultingCommandExecutor() { - - @Override - public int run(CommandSender sender, CommandArguments args) throws WrapperCommandSyntaxException { - executor.executeWith(new BukkitExecutionInfo<>(sender, CommandAPIBukkit.get().wrapCommandSender(sender), args)); - return 1; - } - - @Override - public ExecutorType getType() { - return type; - } - }); - } + types = new ExecutorType[]{ExecutorType.ALL}; } + + getExecutor().addExecutor(new BukkitResultingTypedExecutor<>(executor, types)); return instance(); } /** * Adds an executor to the current command builder * - * @param executor A lambda of type (BukkitCommandExecutionInfo) -> int that will be executed when the command is run + * @param executor A lambda of type (CommandSender, CommandArguments) -> int that will be executed when the command is run * @param types A list of executor types to use this executes method for. * @return this command builder */ - default Impl executes(ResultingCommandExecutionInfo executor, ExecutorType... types) { - if (types == null || types.length == 0) { - getExecutor().addResultingExecutor(executor); - } else { - for (ExecutorType type : types) { - getExecutor().addResultingExecutor(new ResultingCommandExecutionInfo() { - - @Override - public int run(ExecutionInfo> info) throws WrapperCommandSyntaxException { - executor.executeWith(info); - return 1; - } - - @Override - public ExecutorType getType() { - return type; - } - }); - } - } - return instance(); + default Impl executes(ResultingExecutor executor, ExecutorType... types) { + return executes((ResultingExecutorInfo) executor, types); } - // Player command executor /** * Adds an executor to the current command builder * - * @param executor A lambda of type (Player, CommandArguments) -> () that will be executed when the command is run + * @param executor A lambda of type ExecutionInfo<Player, ?> -> () that will be executed when the command is run * @return this command builder */ - default Impl executesPlayer(PlayerCommandExecutor executor) { - getExecutor().addNormalExecutor(executor); + default Impl executesPlayer(NormalExecutorInfo executor) { + getExecutor().addExecutor(new BukkitNormalTypedExecutor<>(executor, ExecutorType.PLAYER)); return instance(); } /** * Adds an executor to the current command builder * - * @param info A lambda of type (ExecutionInfo) -> () that will be executed when the command is run + * @param executor A lambda of type (Player, CommandArguments) -> () that will be executed when the command is run * @return this command builder */ - default Impl executesPlayer(PlayerExecutionInfo info) { - getExecutor().addNormalExecutor(info); - return instance(); + default Impl executesPlayer(NormalExecutor executor) { + return executesPlayer((NormalExecutorInfo) executor); } /** * Adds an executor to the current command builder * - * @param executor A lambda of type (Player, CommandArguments) -> int that will be executed when the command is run + * @param executor A lambda of type ExecutionInfo<Player, ?> -> int that will be executed when the command is run * @return this command builder */ - default Impl executesPlayer(PlayerResultingCommandExecutor executor) { - getExecutor().addResultingExecutor(executor); + default Impl executesPlayer(ResultingExecutorInfo executor) { + getExecutor().addExecutor(new BukkitResultingTypedExecutor<>(executor, ExecutorType.PLAYER)); return instance(); } /** * Adds an executor to the current command builder * - * @param info A lambda of type (ExecutionInfo) -> int that will be executed when the command is run + * @param executor A lambda of type (Player, CommandArguments) -> int that will be executed when the command is run * @return this command builder */ - default Impl executesPlayer(PlayerResultingExecutionInfo info) { - getExecutor().addResultingExecutor(info); - return instance(); + default Impl executesPlayer(ResultingExecutor executor) { + return executesPlayer((ResultingExecutorInfo) executor); } // Entity command executor @@ -182,45 +130,43 @@ default Impl executesPlayer(PlayerResultingExecutionInfo info) { /** * Adds an executor to the current command builder * - * @param executor A lambda of type (Entity, CommandArguments) -> () that will be executed when the command is run + * @param executor A lambda of type ExecutionInfo<Entity, ?> -> () that will be executed when the command is run * @return this command builder */ - default Impl executesEntity(EntityCommandExecutor executor) { - getExecutor().addNormalExecutor(executor); + default Impl executesEntity(NormalExecutorInfo executor) { + getExecutor().addExecutor(new BukkitNormalTypedExecutor<>(executor, ExecutorType.ENTITY)); return instance(); } /** * Adds an executor to the current command builder * - * @param info A lambda of type (ExecutionInfo) -> () that will be executed when the command is run + * @param executor A lambda of type (Entity, CommandArguments) -> () that will be executed when the command is run * @return this command builder */ - default Impl executesEntity(EntityExecutionInfo info) { - getExecutor().addNormalExecutor(info); - return instance(); + default Impl executesEntity(NormalExecutor executor) { + return executesEntity((NormalExecutorInfo) executor); } /** * Adds an executor to the current command builder * - * @param executor A lambda of type (Entity, CommandArguments) -> int that will be executed when the command is run + * @param executor A lambda of type ExecutionInfo<Entity, ?> -> int that will be executed when the command is run * @return this command builder */ - default Impl executesEntity(EntityResultingCommandExecutor executor) { - getExecutor().addResultingExecutor(executor); + default Impl executesEntity(ResultingExecutorInfo executor) { + getExecutor().addExecutor(new BukkitResultingTypedExecutor<>(executor, ExecutorType.ENTITY)); return instance(); } /** * Adds an executor to the current command builder * - * @param info A lambda of type (ExecutionInfo) -> int that will be executed when the command is run + * @param executor A lambda of type (Entity, CommandArguments) -> int that will be executed when the command is run * @return this command builder */ - default Impl executesEntity(EntityResultingExecutionInfo info) { - getExecutor().addResultingExecutor(info); - return instance(); + default Impl executesEntity(ResultingExecutor executor) { + return executesEntity((ResultingExecutorInfo) executor); } // Proxy command executor @@ -228,45 +174,43 @@ default Impl executesEntity(EntityResultingExecutionInfo info) { /** * Adds an executor to the current command builder * - * @param executor A lambda of type (Entity, CommandArguments) -> () that will be executed when the command is run + * @param executor A lambda of type ExecutionInfo<NativeProxyCommandSender, ?> -> () that will be executed when the command is run * @return this command builder */ - default Impl executesProxy(ProxyCommandExecutor executor) { - getExecutor().addNormalExecutor(executor); + default Impl executesProxy(NormalExecutorInfo executor) { + getExecutor().addExecutor(new BukkitNormalTypedExecutor<>(executor, ExecutorType.PROXY)); return instance(); } /** * Adds an executor to the current command builder * - * @param info A lambda of type (ExecutionInfo) -> () that will be executed when the command is run + * @param executor A lambda of type (NativeProxyCommandSender, CommandArguments) -> () that will be executed when the command is run * @return this command builder */ - default Impl executesProxy(ProxyExecutionInfo info) { - getExecutor().addNormalExecutor(info); - return instance(); + default Impl executesProxy(NormalExecutor executor) { + return executesProxy((NormalExecutorInfo) executor); } /** * Adds an executor to the current command builder * - * @param executor A lambda of type (Entity, CommandArguments) -> int that will be executed when the command is run + * @param executor A lambda of type ExecutionInfo<ProxiedCommandSender, ?> -> int that will be executed when the command is run * @return this command builder */ - default Impl executesProxy(ProxyResultingCommandExecutor executor) { - getExecutor().addResultingExecutor(executor); + default Impl executesProxy(ResultingExecutorInfo executor) { + getExecutor().addExecutor(new BukkitResultingTypedExecutor<>(executor, ExecutorType.PROXY)); return instance(); } /** * Adds an executor to the current command builder * - * @param info A lambda of type (ExecutionInfo) -> int that will be executed when the command is run + * @param executor A lambda of type (NativeProxyCommandSender, CommandArguments) -> int that will be executed when the command is run * @return this command builder */ - default Impl executesProxy(ProxyResultingExecutionInfo info) { - getExecutor().addResultingExecutor(info); - return instance(); + default Impl executesProxy(ResultingExecutor executor) { + return executesProxy((ResultingExecutorInfo) executor); } // Command block command executor @@ -274,45 +218,43 @@ default Impl executesProxy(ProxyResultingExecutionInfo info) { /** * Adds an executor to the current command builder * - * @param executor A lambda of type (BlockCommandSender, CommandArguments) -> () that will be executed when the command is run + * @param executor A lambda of type ExecutionInfo<BlockCommandSender, ?> -> () that will be executed when the command is run * @return this command builder */ - default Impl executesCommandBlock(CommandBlockCommandExecutor executor) { - getExecutor().addNormalExecutor(executor); + default Impl executesCommandBlock(NormalExecutorInfo executor) { + getExecutor().addExecutor(new BukkitNormalTypedExecutor<>(executor, ExecutorType.BLOCK)); return instance(); } /** * Adds an executor to the current command builder * - * @param info A lambda of type (ExecutionInfo) -> () that will be executed when the command is run + * @param executor A lambda of type (BlockCommandSender, CommandArguments) -> () that will be executed when the command is run * @return this command builder */ - default Impl executesCommandBlock(CommandBlockExecutionInfo info) { - getExecutor().addNormalExecutor(info); - return instance(); + default Impl executesCommandBlock(NormalExecutor executor) { + return executesCommandBlock((NormalExecutorInfo) executor); } /** * Adds an executor to the current command builder * - * @param executor A lambda of type (BlockCommandSender, CommandArguments) -> int that will be executed when the command is run + * @param executor A lambda of type ExecutionInfo<BlockCommandSender, ?> -> int that will be executed when the command is run * @return this command builder */ - default Impl executesCommandBlock(CommandBlockResultingCommandExecutor executor) { - getExecutor().addResultingExecutor(executor); + default Impl executesCommandBlock(ResultingExecutorInfo executor) { + getExecutor().addExecutor(new BukkitResultingTypedExecutor<>(executor, ExecutorType.BLOCK)); return instance(); } /** * Adds an executor to the current command builder * - * @param info A lambda of type (ExecutionInfo) -> int that will be executed when the command is run + * @param executor A lambda of type (BlockCommandSender, CommandArguments) -> int that will be executed when the command is run * @return this command builder */ - default Impl executesCommandBlock(CommandBlockResultingExecutionInfo info) { - getExecutor().addResultingExecutor(info); - return instance(); + default Impl executesCommandBlock(ResultingExecutor executor) { + return executesCommandBlock((ResultingExecutorInfo) executor); } // Console command executor @@ -320,45 +262,43 @@ default Impl executesCommandBlock(CommandBlockResultingExecutionInfo info) { /** * Adds an executor to the current command builder * - * @param executor A lambda of type (ConsoleCommandSender, CommandArguments) -> () that will be executed when the command is run + * @param executor A lambda of type ExecutionInfo<ConsoleCommandSender, ?> -> () that will be executed when the command is run * @return this command builder */ - default Impl executesConsole(ConsoleCommandExecutor executor) { - getExecutor().addNormalExecutor(executor); + default Impl executesConsole(NormalExecutorInfo executor) { + getExecutor().addExecutor(new BukkitNormalTypedExecutor<>(executor, ExecutorType.CONSOLE)); return instance(); } /** * Adds an executor to the current command builder * - * @param info A lambda of type (ExecutionInfo) -> () that will be executed when the command is run + * @param executor A lambda of type (ConsoleCommandSender, CommandArguments) -> () that will be executed when the command is run * @return this command builder */ - default Impl executesConsole(ConsoleExecutionInfo info) { - getExecutor().addNormalExecutor(info); - return instance(); + default Impl executesConsole(NormalExecutor executor) { + return executesConsole((NormalExecutorInfo) executor); } /** * Adds an executor to the current command builder * - * @param executor A lambda of type (ConsoleCommandSender, CommandArguments) -> int that will be executed when the command is run + * @param executor A lambda of type ExecutionInfo<ConsoleCommandSender, ?> -> int that will be executed when the command is run * @return this command builder */ - default Impl executesConsole(ConsoleResultingCommandExecutor executor) { - getExecutor().addResultingExecutor(executor); + default Impl executesConsole(ResultingExecutorInfo executor) { + getExecutor().addExecutor(new BukkitResultingTypedExecutor<>(executor, ExecutorType.CONSOLE)); return instance(); } /** * Adds an executor to the current command builder * - * @param info A lambda of type (ExecutionInfo) -> int that will be executed when the command is run + * @param executor A lambda of type (ConsoleCommandSender, CommandArguments) -> int that will be executed when the command is run * @return this command builder */ - default Impl executesConsole(ConsoleResultingExecutionInfo info) { - getExecutor().addResultingExecutor(info); - return instance(); + default Impl executesConsole(ResultingExecutor executor) { + return executesConsole((ResultingExecutorInfo) executor); } // Native command executor @@ -366,45 +306,43 @@ default Impl executesConsole(ConsoleResultingExecutionInfo info) { /** * Adds an executor to the current command builder * - * @param executor A lambda of type (NativeCommandExecutor, CommandArguments) -> () that will be executed when the command is run + * @param executor A lambda of type ExecutionInfo<NativeProxyCommandSender, ?> -> () that will be executed when the command is run * @return this command builder */ - default Impl executesNative(NativeCommandExecutor executor) { - getExecutor().addNormalExecutor(executor); + default Impl executesNative(NormalExecutorInfo executor) { + getExecutor().addExecutor(new BukkitNormalTypedExecutor<>(executor, ExecutorType.NATIVE)); return instance(); } /** * Adds an executor to the current command builder * - * @param info A lambda of type (ExecutionInfo) -> () that will be executed when the command is run + * @param executor A lambda of type (NativeProxyCommandSender, CommandArguments) -> () that will be executed when the command is run * @return this command builder */ - default Impl executesNative(NativeExecutionInfo info) { - getExecutor().addNormalExecutor(info); - return instance(); + default Impl executesNative(NormalExecutor executor) { + return executesNative((NormalExecutorInfo) executor); } /** * Adds an executor to the current command builder * - * @param executor A lambda of type (NativeCommandExecutor, CommandArguments) -> int that will be executed when the command is run + * @param executor A lambda of type ExecutionInfo<NativeProxyCommandSender, ?> -> int that will be executed when the command is run * @return this command builder */ - default Impl executesNative(NativeResultingCommandExecutor executor) { - getExecutor().addResultingExecutor(executor); + default Impl executesNative(ResultingExecutorInfo executor) { + getExecutor().addExecutor(new BukkitResultingTypedExecutor<>(executor, ExecutorType.NATIVE)); return instance(); } /** * Adds an executor to the current command builder * - * @param info A lambda of type (ExecutionInfo) -> int that will be executed when the command is run + * @param executor A lambda of type (NativeProxyCommandSender, CommandArguments) -> int that will be executed when the command is run * @return this command builder */ - default Impl executesNative(NativeResultingExecutionInfo info) { - getExecutor().addResultingExecutor(info); - return instance(); + default Impl executesNative(ResultingExecutor executor) { + return executesNative((ResultingExecutorInfo) executor); } // RemoteConsole command executor @@ -412,90 +350,86 @@ default Impl executesNative(NativeResultingExecutionInfo info) { /** * Adds an executor to the current command builder * - * @param executor A lambda of type (RemoteConsoleCommandExecutor, CommandArguments) -> () that will be executed when the command is run + * @param executor A lambda of type ExecutionInfo<RemoteConsoleCommandSender, ?> -> () that will be executed when the command is run * @return this command builder */ - default Impl executesRemoteConsole(RemoteConsoleCommandExecutor executor) { - getExecutor().addNormalExecutor(executor); + default Impl executesRemoteConsole(NormalExecutorInfo executor) { + getExecutor().addExecutor(new BukkitNormalTypedExecutor<>(executor, ExecutorType.REMOTE)); return instance(); } /** * Adds an executor to the current command builder * - * @param info A lambda of type (ExecutionInfo) -> () that will be executed when the command is run + * @param executor A lambda of type (RemoteConsoleCommandSender, CommandArguments) -> () that will be executed when the command is run * @return this command builder */ - default Impl executesRemoteConsole(RemoteConsoleExecutionInfo info) { - getExecutor().addNormalExecutor(info); - return instance(); + default Impl executesRemoteConsole(NormalExecutor executor) { + return executesRemoteConsole((NormalExecutorInfo) executor); } /** * Adds an executor to the current command builder * - * @param executor A lambda of type (RemoteConsoleResultingCommandExecutor, CommandArguments) -> int that will be executed when the command is run + * @param executor A lambda of type ExecutionInfo<RemoteConsoleCommandSender, ?> -> int that will be executed when the command is run * @return this command builder */ - default Impl executesRemoteConsole(RemoteConsoleResultingCommandExecutor executor) { - getExecutor().addResultingExecutor(executor); + default Impl executesRemoteConsole(ResultingExecutorInfo executor) { + getExecutor().addExecutor(new BukkitResultingTypedExecutor<>(executor, ExecutorType.REMOTE)); return instance(); } /** * Adds an executor to the current command builder * - * @param info A lambda of type (ExecutionInfo) -> int that will be executed when the command is run + * @param executor A lambda of type (RemoteConsoleCommandSender, CommandArguments) -> int that will be executed when the command is run * @return this command builder */ - default Impl executesRemoteConsole(RemoteConsoleResultingExecutionInfo info) { - getExecutor().addResultingExecutor(info); - return instance(); + default Impl executesRemoteConsole(ResultingExecutor executor) { + return executesRemoteConsole((ResultingExecutorInfo) executor); } // Feedback-forwarding command executor - + /** * Adds an executor to the current command builder * - * @param executor A lambda of type (FeedbackForwardingCommandExecutor, CommandArguments) -> () that will be executed when the command is run + * @param executor A lambda of type ExecutionInfo<FeedbackForwardingCommandExecutor, ?> -> () that will be executed when the command is run * @return this command builder */ - default Impl executesFeedbackForwarding(FeedbackForwardingCommandExecutor executor) { - getExecutor().addNormalExecutor(executor); + default Impl executesFeedbackForwarding(NormalExecutorInfo executor) { + getExecutor().addExecutor(new BukkitNormalTypedExecutor<>(executor, ExecutorType.FEEDBACK_FORWARDING)); return instance(); } /** * Adds an executor to the current command builder * - * @param info A lambda of type (ExecutionInfo) -> () that will be executed when the command is run + * @param executor A lambda of type (FeedbackForwardingCommandExecutor, CommandArguments) -> () that will be executed when the command is run * @return this command builder */ - default Impl executesFeedbackForwarding(FeedbackForwardingExecutionInfo info) { - getExecutor().addNormalExecutor(info); - return instance(); + default Impl executesFeedbackForwarding(NormalExecutor executor) { + return executesFeedbackForwarding((NormalExecutorInfo) executor); } /** * Adds an executor to the current command builder * - * @param executor A lambda of type (FeedbackForwardingCommandExecutor, CommandArguments) -> int that will be executed when the command is run + * @param executor A lambda of type ExecutionInfo<FeedbackForwardingCommandExecutor, ?> -> int that will be executed when the command is run * @return this command builder */ - default Impl executesFeedbackForwarding(FeedbackForwardingResultingCommandExecutor executor) { - getExecutor().addResultingExecutor(executor); + default Impl executesFeedbackForwarding(ResultingExecutorInfo executor) { + getExecutor().addExecutor(new BukkitResultingTypedExecutor<>(executor, ExecutorType.FEEDBACK_FORWARDING)); return instance(); } /** * Adds an executor to the current command builder * - * @param info A lambda of type (ExecutionInfo) -> int that will be executed when the command is run + * @param executor A lambda of type (FeedbackForwardingCommandExecutor, CommandArguments) -> int that will be executed when the command is run * @return this command builder */ - default Impl executesFeedbackForwarding(FeedbackForwardingResultingExecutionInfo info) { - getExecutor().addResultingExecutor(info); - return instance(); + default Impl executesFeedbackForwarding(ResultingExecutor executor) { + return executesFeedbackForwarding((ResultingExecutorInfo) executor); } } diff --git a/commandapi-platforms/commandapi-bukkit/commandapi-bukkit-core/src/main/java/dev/jorel/commandapi/CommandAPIBukkit.java b/commandapi-platforms/commandapi-bukkit/commandapi-bukkit-core/src/main/java/dev/jorel/commandapi/CommandAPIBukkit.java index 568ba3b79e..3312ad7865 100644 --- a/commandapi-platforms/commandapi-bukkit/commandapi-bukkit-core/src/main/java/dev/jorel/commandapi/CommandAPIBukkit.java +++ b/commandapi-platforms/commandapi-bukkit/commandapi-bukkit-core/src/main/java/dev/jorel/commandapi/CommandAPIBukkit.java @@ -7,24 +7,16 @@ import java.io.File; import java.io.IOException; -import java.util.ArrayList; -import java.util.Arrays; -import java.util.HashMap; -import java.util.Iterator; -import java.util.List; -import java.util.Map; +import java.util.*; import java.util.function.Function; +import java.util.function.Predicate; import java.util.logging.Level; import java.util.logging.Logger; import org.bukkit.Bukkit; import org.bukkit.Keyed; -import org.bukkit.command.BlockCommandSender; import org.bukkit.command.CommandSender; -import org.bukkit.command.ConsoleCommandSender; import org.bukkit.command.PluginCommand; -import org.bukkit.command.ProxiedCommandSender; -import org.bukkit.command.RemoteConsoleCommandSender; import org.bukkit.entity.Player; import org.bukkit.event.EventHandler; import org.bukkit.event.EventPriority; @@ -36,7 +28,6 @@ import org.bukkit.plugin.java.JavaPlugin; import com.mojang.brigadier.CommandDispatcher; -import com.mojang.brigadier.context.CommandContext; import com.mojang.brigadier.exceptions.CommandSyntaxException; import com.mojang.brigadier.suggestion.SuggestionProvider; import com.mojang.brigadier.tree.LiteralCommandNode; @@ -45,24 +36,12 @@ import dev.jorel.commandapi.arguments.LiteralArgument; import dev.jorel.commandapi.arguments.MultiLiteralArgument; import dev.jorel.commandapi.arguments.SuggestionProviders; -import dev.jorel.commandapi.commandsenders.AbstractCommandSender; -import dev.jorel.commandapi.commandsenders.AbstractPlayer; -import dev.jorel.commandapi.commandsenders.BukkitBlockCommandSender; -import dev.jorel.commandapi.commandsenders.BukkitCommandSender; -import dev.jorel.commandapi.commandsenders.BukkitConsoleCommandSender; -import dev.jorel.commandapi.commandsenders.BukkitEntity; -import dev.jorel.commandapi.commandsenders.BukkitFeedbackForwardingCommandSender; -import dev.jorel.commandapi.commandsenders.BukkitNativeProxyCommandSender; -import dev.jorel.commandapi.commandsenders.BukkitPlayer; -import dev.jorel.commandapi.commandsenders.BukkitProxiedCommandSender; -import dev.jorel.commandapi.commandsenders.BukkitRemoteConsoleCommandSender; import dev.jorel.commandapi.exceptions.WrapperCommandSyntaxException; import dev.jorel.commandapi.help.BukkitHelpTopicWrapper; import dev.jorel.commandapi.help.CommandAPIHelpTopic; import dev.jorel.commandapi.help.CustomCommandAPIHelpTopic; import dev.jorel.commandapi.nms.NMS; import dev.jorel.commandapi.preprocessor.Unimplemented; -import dev.jorel.commandapi.wrappers.NativeProxyCommandSender; import net.kyori.adventure.text.Component; import net.md_5.bungee.api.chat.BaseComponent; @@ -264,47 +243,11 @@ public void onDisable() { @Override @Unimplemented(because = REQUIRES_CSS) - public abstract BukkitCommandSender getSenderForCommand(CommandContext cmdCtx, boolean forceNative); - - @Override - @Unimplemented(because = REQUIRES_CSS) - public abstract BukkitCommandSender getCommandSenderFromCommandSource(Source cs); + public abstract CommandSender getCommandSenderFromCommandSource(Source cs); @Override @Unimplemented(because = REQUIRES_CRAFTBUKKIT) - public abstract Source getBrigadierSourceFromCommandSender(AbstractCommandSender sender); - - public BukkitCommandSender wrapCommandSender(CommandSender sender) { - if (sender instanceof BlockCommandSender block) { - return new BukkitBlockCommandSender(block); - } - if (sender instanceof ConsoleCommandSender console) { - return new BukkitConsoleCommandSender(console); - } - if (sender instanceof Player player) { - return new BukkitPlayer(player); - } - if (sender instanceof org.bukkit.entity.Entity entity) { - return new BukkitEntity(entity); - } - if (sender instanceof NativeProxyCommandSender nativeProxy) { - return new BukkitNativeProxyCommandSender(nativeProxy); - } - if (sender instanceof ProxiedCommandSender proxy) { - return new BukkitProxiedCommandSender(proxy); - } - if (sender instanceof RemoteConsoleCommandSender remote) { - return new BukkitRemoteConsoleCommandSender(remote); - } - if (paper.isPaperPresent()) { - final Class FeedbackForwardingSender = paper.getFeedbackForwardingCommandSender(); - if (FeedbackForwardingSender.isInstance(sender)) { - // We literally cannot type this at compile-time, so let's use a placeholder CommandSender instance - return new BukkitFeedbackForwardingCommandSender(FeedbackForwardingSender.cast(sender)); - } - } - throw new RuntimeException("Failed to wrap CommandSender " + sender + " to a CommandAPI-compatible BukkitCommandSender"); - } + public abstract Source getBrigadierSourceFromCommandSender(CommandSender sender); public void registerPermission(String string) { try { @@ -463,8 +406,8 @@ public void severe(String message, Throwable exception) { public abstract void reloadDataPacks(); @Override - public void updateRequirements(AbstractPlayer player) { - ((Player) player.getSource()).updateCommands(); + public void updateRequirements(CommandSender player) { + ((Player) player).updateCommands(); } @Override @@ -539,4 +482,29 @@ protected void registerBukkitRecipesSafely(Iterator recipes) { } } } + + @Override + public Predicate getPermissionCheck(CommandPermission permission) { + final Predicate senderCheck; + + if (permission.equals(CommandPermission.NONE)) { + // No permissions always passes + senderCheck = CommandPermission.TRUE(); + } else if (permission.equals(CommandPermission.OP)) { + senderCheck = CommandSender::isOp; + } else { + Optional permissionStringWrapper = permission.getPermission(); + if (permissionStringWrapper.isPresent()) { + String permissionString = permissionStringWrapper.get(); + // check permission + senderCheck = sender -> sender.hasPermission(permissionString); + } else { + // No permission always passes + senderCheck = CommandPermission.TRUE(); + } + } + + // Negate if specified + return permission.isNegated() ? senderCheck.negate() : senderCheck; + } } diff --git a/commandapi-platforms/commandapi-bukkit/commandapi-bukkit-core/src/main/java/dev/jorel/commandapi/Converter.java b/commandapi-platforms/commandapi-bukkit/commandapi-bukkit-core/src/main/java/dev/jorel/commandapi/Converter.java index 82c715067c..0493f118bb 100644 --- a/commandapi-platforms/commandapi-bukkit/commandapi-bukkit-core/src/main/java/dev/jorel/commandapi/Converter.java +++ b/commandapi-platforms/commandapi-bukkit/commandapi-bukkit-core/src/main/java/dev/jorel/commandapi/Converter.java @@ -24,7 +24,7 @@ import dev.jorel.commandapi.arguments.FlattenableArgument; import dev.jorel.commandapi.arguments.GreedyStringArgument; import dev.jorel.commandapi.executors.CommandArguments; -import dev.jorel.commandapi.executors.NativeResultingCommandExecutor; +import dev.jorel.commandapi.executors.ResultingExecutor; import dev.jorel.commandapi.wrappers.NativeProxyCommandSender; import org.bukkit.Bukkit; import org.bukkit.Location; @@ -184,7 +184,7 @@ private static void convertPluginCommand(JavaPlugin plugin, String commandName, permissionNode = CommandPermission.fromString(permission); } - NativeResultingCommandExecutor executor = (sender, args) -> { + ResultingExecutor executor = (sender, args) -> { org.bukkit.command.Command command = plugin.getCommand(commandName); if (command == null) { diff --git a/commandapi-platforms/commandapi-bukkit/commandapi-bukkit-core/src/main/java/dev/jorel/commandapi/arguments/AdventureChatArgument.java b/commandapi-platforms/commandapi-bukkit/commandapi-bukkit-core/src/main/java/dev/jorel/commandapi/arguments/AdventureChatArgument.java index bcc136de39..7dd3580076 100644 --- a/commandapi-platforms/commandapi-bukkit/commandapi-bukkit-core/src/main/java/dev/jorel/commandapi/arguments/AdventureChatArgument.java +++ b/commandapi-platforms/commandapi-bukkit/commandapi-bukkit-core/src/main/java/dev/jorel/commandapi/arguments/AdventureChatArgument.java @@ -24,7 +24,6 @@ import com.mojang.brigadier.exceptions.CommandSyntaxException; import dev.jorel.commandapi.CommandAPIHandler; import dev.jorel.commandapi.CommandAPIBukkit; -import dev.jorel.commandapi.commandsenders.BukkitPlayer; import dev.jorel.commandapi.exceptions.PaperAdventureNotFoundException; import dev.jorel.commandapi.exceptions.WrapperCommandSyntaxException; import dev.jorel.commandapi.executors.CommandArguments; @@ -42,9 +41,9 @@ * * @apiNote Returns a {@link Component} object */ -public class AdventureChatArgument extends Argument implements GreedyArgument, Previewable { +public class AdventureChatArgument extends Argument implements GreedyArgument, Previewable { - private PreviewableFunction preview; + private PreviewableFunction preview; private boolean usePreview; /** @@ -75,14 +74,14 @@ public CommandAPIArgumentType getArgumentType() { @Override public Component parseArgument(CommandContext cmdCtx, String key, CommandArguments previousArgs) throws CommandSyntaxException { - final CommandSender sender = CommandAPIBukkit.get().getCommandSenderFromCommandSource(cmdCtx.getSource()).getSource(); + final CommandSender sender = CommandAPIBukkit.get().getCommandSenderFromCommandSource(cmdCtx.getSource()); Component component = CommandAPIBukkit.get().getAdventureChat(cmdCtx, key); - Optional> previewOptional = getPreview(); + Optional> previewOptional = getPreview(); if (this.usePreview && previewOptional.isPresent() && sender instanceof Player player) { try { Component previewComponent = previewOptional.get() - .generatePreview(new PreviewInfo<>(new BukkitPlayer(player), CommandAPIHandler.getRawArgumentInput(cmdCtx, key), cmdCtx.getInput(), component)); + .generatePreview(new PreviewInfo<>(player, CommandAPIHandler.getRawArgumentInput(cmdCtx, key), cmdCtx.getInput(), component)); component = previewComponent; } catch (WrapperCommandSyntaxException e) { @@ -94,13 +93,13 @@ public Component parseArgument(CommandContext preview) { + public AdventureChatArgument withPreview(PreviewableFunction preview) { this.preview = preview; return this; } @Override - public Optional> getPreview() { + public Optional> getPreview() { return Optional.ofNullable(preview); } diff --git a/commandapi-platforms/commandapi-bukkit/commandapi-bukkit-core/src/main/java/dev/jorel/commandapi/arguments/ChatArgument.java b/commandapi-platforms/commandapi-bukkit/commandapi-bukkit-core/src/main/java/dev/jorel/commandapi/arguments/ChatArgument.java index e028fc7517..1af528e810 100644 --- a/commandapi-platforms/commandapi-bukkit/commandapi-bukkit-core/src/main/java/dev/jorel/commandapi/arguments/ChatArgument.java +++ b/commandapi-platforms/commandapi-bukkit/commandapi-bukkit-core/src/main/java/dev/jorel/commandapi/arguments/ChatArgument.java @@ -31,7 +31,6 @@ import dev.jorel.commandapi.CommandAPIBukkit; import dev.jorel.commandapi.CommandAPIHandler; -import dev.jorel.commandapi.commandsenders.BukkitPlayer; import dev.jorel.commandapi.exceptions.SpigotNotFoundException; import dev.jorel.commandapi.exceptions.WrapperCommandSyntaxException; import dev.jorel.commandapi.wrappers.PreviewableFunction; @@ -44,9 +43,9 @@ * * @apiNote Returns a {@link BaseComponent}{@code []} object */ -public class ChatArgument extends Argument implements GreedyArgument, Previewable { +public class ChatArgument extends Argument implements GreedyArgument, Previewable { - private PreviewableFunction preview; + private PreviewableFunction preview; private boolean usePreview; /** @@ -77,14 +76,14 @@ public CommandAPIArgumentType getArgumentType() { @Override public BaseComponent[] parseArgument(CommandContext cmdCtx, String key, CommandArguments previousArgs) throws CommandSyntaxException { - final CommandSender sender = CommandAPIBukkit.get().getCommandSenderFromCommandSource(cmdCtx.getSource()).getSource(); + final CommandSender sender = CommandAPIBukkit.get().getCommandSenderFromCommandSource(cmdCtx.getSource()); BaseComponent[] component = CommandAPIBukkit.get().getChat(cmdCtx, key); - Optional> previewOptional = getPreview(); + Optional> previewOptional = getPreview(); if (this.usePreview && previewOptional.isPresent() && sender instanceof Player player) { try { BaseComponent[] previewComponent = previewOptional.get() - .generatePreview(new PreviewInfo<>(new BukkitPlayer(player), CommandAPIHandler.getRawArgumentInput(cmdCtx, key), cmdCtx.getInput(), component)); + .generatePreview(new PreviewInfo<>(player, CommandAPIHandler.getRawArgumentInput(cmdCtx, key), cmdCtx.getInput(), component)); component = previewComponent; } catch (WrapperCommandSyntaxException e) { @@ -95,13 +94,13 @@ public BaseComponent[] parseArgument(CommandContext preview) { + public ChatArgument withPreview(PreviewableFunction preview) { this.preview = preview; return this; } @Override - public Optional> getPreview() { + public Optional> getPreview() { return Optional.ofNullable(preview); } diff --git a/commandapi-platforms/commandapi-bukkit/commandapi-bukkit-core/src/main/java/dev/jorel/commandapi/arguments/CommandArgument.java b/commandapi-platforms/commandapi-bukkit/commandapi-bukkit-core/src/main/java/dev/jorel/commandapi/arguments/CommandArgument.java index faf0543255..4403b316b9 100644 --- a/commandapi-platforms/commandapi-bukkit/commandapi-bukkit-core/src/main/java/dev/jorel/commandapi/arguments/CommandArgument.java +++ b/commandapi-platforms/commandapi-bukkit/commandapi-bukkit-core/src/main/java/dev/jorel/commandapi/arguments/CommandArgument.java @@ -17,7 +17,6 @@ import org.bukkit.entity.Player; import java.util.Arrays; -import java.util.HashMap; import java.util.LinkedHashMap; import java.util.List; @@ -195,7 +194,7 @@ public CommandResult parseArgument(CommandContextget().getSenderForCommand(cmdCtx, false).getSource(); + CommandSender sender = CommandAPIBukkit.get().getCommandSenderFromCommandSource(cmdCtx.getSource()); StringReader context = new StringReader(command); diff --git a/commandapi-platforms/commandapi-bukkit/commandapi-bukkit-core/src/main/java/dev/jorel/commandapi/arguments/CustomArgument.java b/commandapi-platforms/commandapi-bukkit/commandapi-bukkit-core/src/main/java/dev/jorel/commandapi/arguments/CustomArgument.java index 3d5a273170..1627cf6631 100644 --- a/commandapi-platforms/commandapi-bukkit/commandapi-bukkit-core/src/main/java/dev/jorel/commandapi/arguments/CustomArgument.java +++ b/commandapi-platforms/commandapi-bukkit/commandapi-bukkit-core/src/main/java/dev/jorel/commandapi/arguments/CustomArgument.java @@ -108,7 +108,7 @@ public T parseArgument(CommandContext c final B parsedInput = base.parseArgument(cmdCtx, key, previousArgs); try { - return infoParser.apply(new CustomArgumentInfo<>(CommandAPIBukkit.get().getCommandSenderFromCommandSource(cmdCtx.getSource()).getSource(), + return infoParser.apply(new CustomArgumentInfo<>(CommandAPIBukkit.get().getCommandSenderFromCommandSource(cmdCtx.getSource()), previousArgs, customresult, parsedInput)); } catch (CustomArgumentException e) { throw e.toCommandSyntax(customresult, cmdCtx); diff --git a/commandapi-platforms/commandapi-bukkit/commandapi-bukkit-core/src/main/java/dev/jorel/commandapi/arguments/ListArgumentCommon.java b/commandapi-platforms/commandapi-bukkit/commandapi-bukkit-core/src/main/java/dev/jorel/commandapi/arguments/ListArgumentCommon.java index 9fc6d9c5eb..1ca60be8b9 100644 --- a/commandapi-platforms/commandapi-bukkit/commandapi-bukkit-core/src/main/java/dev/jorel/commandapi/arguments/ListArgumentCommon.java +++ b/commandapi-platforms/commandapi-bukkit/commandapi-bukkit-core/src/main/java/dev/jorel/commandapi/arguments/ListArgumentCommon.java @@ -121,7 +121,7 @@ public CommandAPIArgumentType getArgumentType() { @Override public List parseArgument(CommandContext cmdCtx, String key, CommandArguments previousArgs) throws CommandSyntaxException { - final CommandSender sender = CommandAPIBukkit.get().getCommandSenderFromCommandSource(cmdCtx.getSource()).getSource(); + final CommandSender sender = CommandAPIBukkit.get().getCommandSenderFromCommandSource(cmdCtx.getSource()); final SuggestionInfo currentInfo = new SuggestionInfo<>(sender, previousArgs, cmdCtx.getInput(), cmdCtx.getArgument(key, String.class)); // Get the list of values which this can take diff --git a/commandapi-platforms/commandapi-bukkit/commandapi-bukkit-core/src/main/java/dev/jorel/commandapi/commandsenders/BukkitBlockCommandSender.java b/commandapi-platforms/commandapi-bukkit/commandapi-bukkit-core/src/main/java/dev/jorel/commandapi/commandsenders/BukkitBlockCommandSender.java deleted file mode 100644 index 941595f76a..0000000000 --- a/commandapi-platforms/commandapi-bukkit/commandapi-bukkit-core/src/main/java/dev/jorel/commandapi/commandsenders/BukkitBlockCommandSender.java +++ /dev/null @@ -1,28 +0,0 @@ -package dev.jorel.commandapi.commandsenders; - -import org.bukkit.command.BlockCommandSender; - -public class BukkitBlockCommandSender implements AbstractBlockCommandSender, BukkitCommandSender { - - private final BlockCommandSender commandBlock; - - public BukkitBlockCommandSender(BlockCommandSender commandBlock) { - this.commandBlock = commandBlock; - } - - @Override - public boolean hasPermission(String permissionNode) { - return this.commandBlock.hasPermission(permissionNode); - } - - @Override - public boolean isOp() { - return this.commandBlock.isOp(); - } - - @Override - public BlockCommandSender getSource() { - return this.commandBlock; - } - -} diff --git a/commandapi-platforms/commandapi-bukkit/commandapi-bukkit-core/src/main/java/dev/jorel/commandapi/commandsenders/BukkitCommandSender.java b/commandapi-platforms/commandapi-bukkit/commandapi-bukkit-core/src/main/java/dev/jorel/commandapi/commandsenders/BukkitCommandSender.java deleted file mode 100644 index 47a868269f..0000000000 --- a/commandapi-platforms/commandapi-bukkit/commandapi-bukkit-core/src/main/java/dev/jorel/commandapi/commandsenders/BukkitCommandSender.java +++ /dev/null @@ -1,6 +0,0 @@ -package dev.jorel.commandapi.commandsenders; - -import org.bukkit.command.CommandSender; - -public interface BukkitCommandSender extends AbstractCommandSender { -} diff --git a/commandapi-platforms/commandapi-bukkit/commandapi-bukkit-core/src/main/java/dev/jorel/commandapi/commandsenders/BukkitConsoleCommandSender.java b/commandapi-platforms/commandapi-bukkit/commandapi-bukkit-core/src/main/java/dev/jorel/commandapi/commandsenders/BukkitConsoleCommandSender.java deleted file mode 100644 index 51f500525d..0000000000 --- a/commandapi-platforms/commandapi-bukkit/commandapi-bukkit-core/src/main/java/dev/jorel/commandapi/commandsenders/BukkitConsoleCommandSender.java +++ /dev/null @@ -1,28 +0,0 @@ -package dev.jorel.commandapi.commandsenders; - -import org.bukkit.command.ConsoleCommandSender; - -public class BukkitConsoleCommandSender implements AbstractConsoleCommandSender, BukkitCommandSender { - - private final ConsoleCommandSender sender; - - public BukkitConsoleCommandSender(ConsoleCommandSender sender) { - this.sender = sender; - } - - @Override - public boolean hasPermission(String permissionNode) { - return sender.hasPermission(permissionNode); - } - - @Override - public boolean isOp() { - return sender.isOp(); - } - - @Override - public ConsoleCommandSender getSource() { - return sender; - } - -} diff --git a/commandapi-platforms/commandapi-bukkit/commandapi-bukkit-core/src/main/java/dev/jorel/commandapi/commandsenders/BukkitEntity.java b/commandapi-platforms/commandapi-bukkit/commandapi-bukkit-core/src/main/java/dev/jorel/commandapi/commandsenders/BukkitEntity.java deleted file mode 100644 index 7ef481f6cf..0000000000 --- a/commandapi-platforms/commandapi-bukkit/commandapi-bukkit-core/src/main/java/dev/jorel/commandapi/commandsenders/BukkitEntity.java +++ /dev/null @@ -1,28 +0,0 @@ -package dev.jorel.commandapi.commandsenders; - -import org.bukkit.entity.Entity; - -public class BukkitEntity implements AbstractEntity, BukkitCommandSender { - - private final Entity entity; - - public BukkitEntity(Entity entity) { - this.entity = entity; - } - - @Override - public boolean hasPermission(String permissionNode) { - return this.entity.hasPermission(permissionNode); - } - - @Override - public boolean isOp() { - return this.entity.isOp(); - } - - @Override - public Entity getSource() { - return this.entity; - } - -} diff --git a/commandapi-platforms/commandapi-bukkit/commandapi-bukkit-core/src/main/java/dev/jorel/commandapi/commandsenders/BukkitFeedbackForwardingCommandSender.java b/commandapi-platforms/commandapi-bukkit/commandapi-bukkit-core/src/main/java/dev/jorel/commandapi/commandsenders/BukkitFeedbackForwardingCommandSender.java deleted file mode 100644 index 0a933a1683..0000000000 --- a/commandapi-platforms/commandapi-bukkit/commandapi-bukkit-core/src/main/java/dev/jorel/commandapi/commandsenders/BukkitFeedbackForwardingCommandSender.java +++ /dev/null @@ -1,28 +0,0 @@ -package dev.jorel.commandapi.commandsenders; - -import org.bukkit.command.CommandSender; - -public class BukkitFeedbackForwardingCommandSender implements AbstractFeedbackForwardingCommandSender, BukkitCommandSender { - - private final FeedbackForwardingSender sender; - - public BukkitFeedbackForwardingCommandSender(FeedbackForwardingSender sender) { - this.sender = sender; - } - - @Override - public boolean hasPermission(String permissionNode) { - return this.sender.hasPermission(permissionNode); - } - - @Override - public boolean isOp() { - return this.sender.isOp(); - } - - @Override - public FeedbackForwardingSender getSource() { - return this.sender; - } - -} diff --git a/commandapi-platforms/commandapi-bukkit/commandapi-bukkit-core/src/main/java/dev/jorel/commandapi/commandsenders/BukkitNativeProxyCommandSender.java b/commandapi-platforms/commandapi-bukkit/commandapi-bukkit-core/src/main/java/dev/jorel/commandapi/commandsenders/BukkitNativeProxyCommandSender.java deleted file mode 100644 index 1ab27622cd..0000000000 --- a/commandapi-platforms/commandapi-bukkit/commandapi-bukkit-core/src/main/java/dev/jorel/commandapi/commandsenders/BukkitNativeProxyCommandSender.java +++ /dev/null @@ -1,27 +0,0 @@ -package dev.jorel.commandapi.commandsenders; -import dev.jorel.commandapi.wrappers.NativeProxyCommandSender; - -public class BukkitNativeProxyCommandSender implements AbstractNativeProxyCommandSender, BukkitCommandSender { - - private final NativeProxyCommandSender proxySender; - - public BukkitNativeProxyCommandSender(NativeProxyCommandSender player) { - this.proxySender = player; - } - - @Override - public boolean hasPermission(String permissionNode) { - return this.proxySender.hasPermission(permissionNode); - } - - @Override - public boolean isOp() { - return this.proxySender.isOp(); - } - - @Override - public NativeProxyCommandSender getSource() { - return this.proxySender; - } - -} diff --git a/commandapi-platforms/commandapi-bukkit/commandapi-bukkit-core/src/main/java/dev/jorel/commandapi/commandsenders/BukkitPlayer.java b/commandapi-platforms/commandapi-bukkit/commandapi-bukkit-core/src/main/java/dev/jorel/commandapi/commandsenders/BukkitPlayer.java deleted file mode 100644 index 58aaf19418..0000000000 --- a/commandapi-platforms/commandapi-bukkit/commandapi-bukkit-core/src/main/java/dev/jorel/commandapi/commandsenders/BukkitPlayer.java +++ /dev/null @@ -1,27 +0,0 @@ -package dev.jorel.commandapi.commandsenders; -import org.bukkit.entity.Player; - -public class BukkitPlayer implements AbstractPlayer, BukkitCommandSender { - - private final Player player; - - public BukkitPlayer(Player player) { - this.player = player; - } - - @Override - public boolean hasPermission(String permissionNode) { - return this.player.hasPermission(permissionNode); - } - - @Override - public boolean isOp() { - return this.player.isOp(); - } - - @Override - public Player getSource() { - return this.player; - } - -} diff --git a/commandapi-platforms/commandapi-bukkit/commandapi-bukkit-core/src/main/java/dev/jorel/commandapi/commandsenders/BukkitProxiedCommandSender.java b/commandapi-platforms/commandapi-bukkit/commandapi-bukkit-core/src/main/java/dev/jorel/commandapi/commandsenders/BukkitProxiedCommandSender.java deleted file mode 100644 index 22e465635c..0000000000 --- a/commandapi-platforms/commandapi-bukkit/commandapi-bukkit-core/src/main/java/dev/jorel/commandapi/commandsenders/BukkitProxiedCommandSender.java +++ /dev/null @@ -1,27 +0,0 @@ -package dev.jorel.commandapi.commandsenders; -import org.bukkit.command.ProxiedCommandSender; - -public class BukkitProxiedCommandSender implements AbstractProxiedCommandSender, BukkitCommandSender { - - private final ProxiedCommandSender proxySender; - - public BukkitProxiedCommandSender(ProxiedCommandSender player) { - this.proxySender = player; - } - - @Override - public boolean hasPermission(String permissionNode) { - return this.proxySender.hasPermission(permissionNode); - } - - @Override - public boolean isOp() { - return this.proxySender.isOp(); - } - - @Override - public ProxiedCommandSender getSource() { - return this.proxySender; - } - -} diff --git a/commandapi-platforms/commandapi-bukkit/commandapi-bukkit-core/src/main/java/dev/jorel/commandapi/commandsenders/BukkitRemoteConsoleCommandSender.java b/commandapi-platforms/commandapi-bukkit/commandapi-bukkit-core/src/main/java/dev/jorel/commandapi/commandsenders/BukkitRemoteConsoleCommandSender.java deleted file mode 100644 index 87956682af..0000000000 --- a/commandapi-platforms/commandapi-bukkit/commandapi-bukkit-core/src/main/java/dev/jorel/commandapi/commandsenders/BukkitRemoteConsoleCommandSender.java +++ /dev/null @@ -1,27 +0,0 @@ -package dev.jorel.commandapi.commandsenders; - -import org.bukkit.command.RemoteConsoleCommandSender; - -public class BukkitRemoteConsoleCommandSender implements AbstractRemoteConsoleCommandSender, BukkitCommandSender { - - private final RemoteConsoleCommandSender remote; - - public BukkitRemoteConsoleCommandSender(RemoteConsoleCommandSender remote) { - this.remote = remote; - } - - @Override - public boolean hasPermission(String permissionNode) { - return remote.hasPermission(permissionNode); - } - - @Override - public boolean isOp() { - return remote.isOp(); - } - - @Override - public RemoteConsoleCommandSender getSource() { - return remote; - } -} diff --git a/commandapi-platforms/commandapi-bukkit/commandapi-bukkit-core/src/main/java/dev/jorel/commandapi/executors/BukkitExecutionInfo.java b/commandapi-platforms/commandapi-bukkit/commandapi-bukkit-core/src/main/java/dev/jorel/commandapi/executors/BukkitExecutionInfo.java deleted file mode 100644 index 1c486cf759..0000000000 --- a/commandapi-platforms/commandapi-bukkit/commandapi-bukkit-core/src/main/java/dev/jorel/commandapi/executors/BukkitExecutionInfo.java +++ /dev/null @@ -1,30 +0,0 @@ -package dev.jorel.commandapi.executors; - -import dev.jorel.commandapi.commandsenders.BukkitCommandSender; - -/** - * This record represents a BukkitExecutionInfo for a command. It provides the sender of a command, as well as it's arguments - * - * @param The type of the sender of a command this BukkitExecutionInfo belongs to - */ -public record BukkitExecutionInfo( - - /** - * @return The sender of this command - */ - Sender sender, - - /** - * This is not intended for public use and is only used internally. The {@link BukkitExecutionInfo#sender()} method should be used instead! - * - * @return The wrapper type of this command - */ - BukkitCommandSender senderWrapper, - - /** - * @return The arguments of this command - */ - CommandArguments args - -) implements ExecutionInfo> { -} diff --git a/commandapi-platforms/commandapi-bukkit/commandapi-bukkit-core/src/main/java/dev/jorel/commandapi/executors/BukkitNormalTypedExecutor.java b/commandapi-platforms/commandapi-bukkit/commandapi-bukkit-core/src/main/java/dev/jorel/commandapi/executors/BukkitNormalTypedExecutor.java new file mode 100644 index 0000000000..8adffe0631 --- /dev/null +++ b/commandapi-platforms/commandapi-bukkit/commandapi-bukkit-core/src/main/java/dev/jorel/commandapi/executors/BukkitNormalTypedExecutor.java @@ -0,0 +1,33 @@ +package dev.jorel.commandapi.executors; + +import org.bukkit.command.CommandSender; + +import dev.jorel.commandapi.exceptions.WrapperCommandSyntaxException; + +/** + * A {@link BukkitTypedExecutor} for {@link NormalExecutorInfo} lambdas that don't have an int result. + * When running this executor succeeds, it simply returns 1. + * + * @param executor The {@link NormalExecutorInfo} to invoke when running this executor. + * @param types The {@link ExecutorType}s that this executor accepts. + * @param The {@link CommandSender} class that this executor accepts. + * @param The class for executing Brigadier commands. + */ +public record BukkitNormalTypedExecutor( + + /** + * @return The {@link NormalExecutorInfo} to invoke when running this executor. + */ + NormalExecutorInfo executor, + + /** + * @return The {@link ExecutorType}s that this executor accepts. + */ + ExecutorType... types +) implements BukkitTypedExecutor { + @Override + public int executeWith(ExecutionInfo info) throws WrapperCommandSyntaxException { + executor.run(info); + return 1; + } +} diff --git a/commandapi-platforms/commandapi-bukkit/commandapi-bukkit-core/src/main/java/dev/jorel/commandapi/executors/BukkitResultingTypedExecutor.java b/commandapi-platforms/commandapi-bukkit/commandapi-bukkit-core/src/main/java/dev/jorel/commandapi/executors/BukkitResultingTypedExecutor.java new file mode 100644 index 0000000000..9deaa1796b --- /dev/null +++ b/commandapi-platforms/commandapi-bukkit/commandapi-bukkit-core/src/main/java/dev/jorel/commandapi/executors/BukkitResultingTypedExecutor.java @@ -0,0 +1,31 @@ +package dev.jorel.commandapi.executors; + +import org.bukkit.command.CommandSender; + +import dev.jorel.commandapi.exceptions.WrapperCommandSyntaxException; + +/** + * A {@link BukkitTypedExecutor} for {@link ResultingExecutorInfo} lambdas that have an int result. + * + * @param executor The {@link ResultingExecutorInfo} to invoke when running this executor. + * @param types The {@link ExecutorType}s that this executor accepts. + * @param The {@link CommandSender} class that this executor accepts. + * @param The class for executing Brigadier commands. + */ +public record BukkitResultingTypedExecutor( + + /** + * @return The {@link ResultingExecutorInfo} to invoke when running this executor. + */ + ResultingExecutorInfo executor, + + /** + * @return The {@link ExecutorType}s that this executor accepts. + */ + ExecutorType... types +) implements BukkitTypedExecutor { + @Override + public int executeWith(ExecutionInfo info) throws WrapperCommandSyntaxException { + return executor.run(info); + } +} diff --git a/commandapi-platforms/commandapi-bukkit/commandapi-bukkit-core/src/main/java/dev/jorel/commandapi/executors/BukkitTypedExecutor.java b/commandapi-platforms/commandapi-bukkit/commandapi-bukkit-core/src/main/java/dev/jorel/commandapi/executors/BukkitTypedExecutor.java new file mode 100644 index 0000000000..2368ee4ba7 --- /dev/null +++ b/commandapi-platforms/commandapi-bukkit/commandapi-bukkit-core/src/main/java/dev/jorel/commandapi/executors/BukkitTypedExecutor.java @@ -0,0 +1,58 @@ +package dev.jorel.commandapi.executors; + +import org.bukkit.command.BlockCommandSender; +import org.bukkit.command.CommandSender; +import org.bukkit.command.ConsoleCommandSender; +import org.bukkit.command.ProxiedCommandSender; +import org.bukkit.command.RemoteConsoleCommandSender; +import org.bukkit.entity.Entity; +import org.bukkit.entity.Player; + +import dev.jorel.commandapi.CommandAPIBukkit; +import dev.jorel.commandapi.PaperImplementations; +import dev.jorel.commandapi.wrappers.NativeProxyCommandSender; + +/** + * A {@link TypedExecutor} for Bukkit. The {@link CommandSender}s accepted by + * this executor can be defined by overriding the method {@link #types()}. + * + * @param The {@link CommandSender} class that this executor accepts. + * @param The class for executing Brigadier commands. + */ +public interface BukkitTypedExecutor extends TypedExecutor { + @Override + default ExecutionInfo tryForSender(ExecutionInfo info) { + CommandSender sender = info.sender(); + + for (ExecutorType type : types()) { + // Check if we can cast to the defined sender type + if (switch (type) { + case ALL -> true; + case PLAYER -> sender instanceof Player; + case ENTITY -> sender instanceof Entity; + case CONSOLE -> sender instanceof ConsoleCommandSender; + case BLOCK -> sender instanceof BlockCommandSender; + case PROXY -> sender instanceof ProxiedCommandSender; + case NATIVE -> { + // If we're a NATIVE executor, always accept and convert sender to a NativeProxyCommandSender + NativeProxyCommandSender proxyCommandSender = CommandAPIBukkit.get().getNativeProxyCommandSender(info.cmdCtx()); + info = info.copyWithNewSender(proxyCommandSender); + yield true; + } + case REMOTE -> sender instanceof RemoteConsoleCommandSender; + case FEEDBACK_FORWARDING -> { + PaperImplementations paper = CommandAPIBukkit.get().getPaper(); + yield paper.isPaperPresent() && paper.getFeedbackForwardingCommandSender().isInstance(sender); + } + }) { + return (ExecutionInfo) info; + } + } + return null; + } + + /** + * @return The {@link ExecutorType}s that this executor accepts. + */ + ExecutorType[] types(); +} diff --git a/commandapi-platforms/commandapi-bukkit/commandapi-bukkit-core/src/main/java/dev/jorel/commandapi/executors/CommandBlockCommandExecutor.java b/commandapi-platforms/commandapi-bukkit/commandapi-bukkit-core/src/main/java/dev/jorel/commandapi/executors/CommandBlockCommandExecutor.java deleted file mode 100644 index 6d0d5eca75..0000000000 --- a/commandapi-platforms/commandapi-bukkit/commandapi-bukkit-core/src/main/java/dev/jorel/commandapi/executors/CommandBlockCommandExecutor.java +++ /dev/null @@ -1,60 +0,0 @@ -/******************************************************************************* - * Copyright 2018, 2020 Jorel Ali (Skepter) - MIT License - * - * Permission is hereby granted, free of charge, to any person obtaining a copy of - * this software and associated documentation files (the "Software"), to deal in - * the Software without restriction, including without limitation the rights to - * use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of - * the Software, and to permit persons to whom the Software is furnished to do so, - * subject to the following conditions: - * - * The above copyright notice and this permission notice shall be included in all - * copies or substantial portions of the Software. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR - * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS - * FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR - * COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER - * IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN - * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. - *******************************************************************************/ -package dev.jorel.commandapi.executors; - -import org.bukkit.command.BlockCommandSender; - -import dev.jorel.commandapi.commandsenders.BukkitBlockCommandSender; -import dev.jorel.commandapi.exceptions.WrapperCommandSyntaxException; - -/** - * A normal command executor for a BlockCommandSender - */ -@FunctionalInterface -public interface CommandBlockCommandExecutor extends NormalExecutor { - - /** - * The code to run when this command is performed - * - * @param sender The sender of this command (a player, the console etc.) - * @param args The arguments given to this command. - */ - void run(BlockCommandSender sender, CommandArguments args) throws WrapperCommandSyntaxException; - - /** - * The code to run when this command is performed - * - * @param info The ExecutionInfo for this command - */ - @Override - default void run(ExecutionInfo info) throws WrapperCommandSyntaxException { - this.run(info.sender(), info.args()); - } - - /** - * Returns the type of the sender of the current executor. - * @return the type of the sender of the current executor - */ - @Override - default ExecutorType getType() { - return ExecutorType.BLOCK; - } -} diff --git a/commandapi-platforms/commandapi-bukkit/commandapi-bukkit-core/src/main/java/dev/jorel/commandapi/executors/CommandBlockExecutionInfo.java b/commandapi-platforms/commandapi-bukkit/commandapi-bukkit-core/src/main/java/dev/jorel/commandapi/executors/CommandBlockExecutionInfo.java deleted file mode 100644 index 3e7e4abcc1..0000000000 --- a/commandapi-platforms/commandapi-bukkit/commandapi-bukkit-core/src/main/java/dev/jorel/commandapi/executors/CommandBlockExecutionInfo.java +++ /dev/null @@ -1,28 +0,0 @@ -package dev.jorel.commandapi.executors; - -import dev.jorel.commandapi.commandsenders.BukkitBlockCommandSender; -import dev.jorel.commandapi.exceptions.WrapperCommandSyntaxException; -import org.bukkit.command.BlockCommandSender; - -@FunctionalInterface -public interface CommandBlockExecutionInfo extends NormalExecutor { - - /** - * Executes the command. - * - * @param info The ExecutionInfo for this command - * @throws WrapperCommandSyntaxException if an error occurs during the execution of this command - */ - void run(ExecutionInfo info) throws WrapperCommandSyntaxException; - - /** - * Returns the type of the sender of the current executor. - * - * @return the type of the sender of the current executor - */ - @Override - default ExecutorType getType() { - return ExecutorType.BLOCK; - } - -} diff --git a/commandapi-platforms/commandapi-bukkit/commandapi-bukkit-core/src/main/java/dev/jorel/commandapi/executors/CommandBlockResultingCommandExecutor.java b/commandapi-platforms/commandapi-bukkit/commandapi-bukkit-core/src/main/java/dev/jorel/commandapi/executors/CommandBlockResultingCommandExecutor.java deleted file mode 100644 index 923fc17c0d..0000000000 --- a/commandapi-platforms/commandapi-bukkit/commandapi-bukkit-core/src/main/java/dev/jorel/commandapi/executors/CommandBlockResultingCommandExecutor.java +++ /dev/null @@ -1,65 +0,0 @@ -/******************************************************************************* - * Copyright 2018, 2020 Jorel Ali (Skepter) - MIT License - * - * Permission is hereby granted, free of charge, to any person obtaining a copy of - * this software and associated documentation files (the "Software"), to deal in - * the Software without restriction, including without limitation the rights to - * use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of - * the Software, and to permit persons to whom the Software is furnished to do so, - * subject to the following conditions: - * - * The above copyright notice and this permission notice shall be included in all - * copies or substantial portions of the Software. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR - * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS - * FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR - * COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER - * IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN - * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. - *******************************************************************************/ -package dev.jorel.commandapi.executors; - -import org.bukkit.command.BlockCommandSender; - -import dev.jorel.commandapi.commandsenders.BukkitBlockCommandSender; -import dev.jorel.commandapi.exceptions.WrapperCommandSyntaxException; - -/** - * A resulting command executor for a BlockCommandSender - */ -@FunctionalInterface -public interface CommandBlockResultingCommandExecutor extends ResultingExecutor { - - /** - * The code to run when this command is performed - * - * @param sender The sender of this command (a player, the console etc.) - * @param args The arguments given to this command. - * - * @return the result of this command - */ - int run(BlockCommandSender sender, CommandArguments args) throws WrapperCommandSyntaxException; - - /** - * The code to run when this command is performed - * - * @param info The ExecutionInfo for this command - * - * @return the result of this command - */ - @Override - default int run(ExecutionInfo info) throws WrapperCommandSyntaxException { - return this.run(info.sender(), info.args()); - } - - /** - * Returns the type of the sender of the current executor. - * @return the type of the sender of the current executor - */ - @Override - default ExecutorType getType() { - return ExecutorType.BLOCK; - } - -} diff --git a/commandapi-platforms/commandapi-bukkit/commandapi-bukkit-core/src/main/java/dev/jorel/commandapi/executors/CommandBlockResultingExecutionInfo.java b/commandapi-platforms/commandapi-bukkit/commandapi-bukkit-core/src/main/java/dev/jorel/commandapi/executors/CommandBlockResultingExecutionInfo.java deleted file mode 100644 index e583197cbf..0000000000 --- a/commandapi-platforms/commandapi-bukkit/commandapi-bukkit-core/src/main/java/dev/jorel/commandapi/executors/CommandBlockResultingExecutionInfo.java +++ /dev/null @@ -1,27 +0,0 @@ -package dev.jorel.commandapi.executors; - -import dev.jorel.commandapi.commandsenders.BukkitBlockCommandSender; -import dev.jorel.commandapi.exceptions.WrapperCommandSyntaxException; -import org.bukkit.command.BlockCommandSender; - -@FunctionalInterface -public interface CommandBlockResultingExecutionInfo extends ResultingExecutor { - - /** - * The code to run when this command is performed - * - * @param info The ExecutionInfo for this command - * @return the result of this command - */ - int run(ExecutionInfo info) throws WrapperCommandSyntaxException; - - /** - * Returns the type of the sender of the current executor. - * @return the type of the sender of the current executor - */ - @Override - default ExecutorType getType() { - return ExecutorType.BLOCK; - } - -} diff --git a/commandapi-platforms/commandapi-bukkit/commandapi-bukkit-core/src/main/java/dev/jorel/commandapi/executors/CommandExecutionInfo.java b/commandapi-platforms/commandapi-bukkit/commandapi-bukkit-core/src/main/java/dev/jorel/commandapi/executors/CommandExecutionInfo.java deleted file mode 100644 index d510e30a52..0000000000 --- a/commandapi-platforms/commandapi-bukkit/commandapi-bukkit-core/src/main/java/dev/jorel/commandapi/executors/CommandExecutionInfo.java +++ /dev/null @@ -1,28 +0,0 @@ -package dev.jorel.commandapi.executors; - -import dev.jorel.commandapi.commandsenders.BukkitCommandSender; -import dev.jorel.commandapi.exceptions.WrapperCommandSyntaxException; -import org.bukkit.command.CommandSender; - -@FunctionalInterface -public interface CommandExecutionInfo extends NormalExecutor> { - - /** - * Executes the command. - * - * @param info The ExecutionInfo for this command - * @throws WrapperCommandSyntaxException if an error occurs during the execution of this command - */ - void run(ExecutionInfo> info) throws WrapperCommandSyntaxException; - - /** - * Returns the type of the sender of the current executor. - * - * @return the type of the sender of the current executor - */ - @Override - default ExecutorType getType() { - return ExecutorType.ALL; - } - -} diff --git a/commandapi-platforms/commandapi-bukkit/commandapi-bukkit-core/src/main/java/dev/jorel/commandapi/executors/CommandExecutor.java b/commandapi-platforms/commandapi-bukkit/commandapi-bukkit-core/src/main/java/dev/jorel/commandapi/executors/CommandExecutor.java deleted file mode 100644 index 779b5380ae..0000000000 --- a/commandapi-platforms/commandapi-bukkit/commandapi-bukkit-core/src/main/java/dev/jorel/commandapi/executors/CommandExecutor.java +++ /dev/null @@ -1,60 +0,0 @@ -/******************************************************************************* - * Copyright 2018, 2020 Jorel Ali (Skepter) - MIT License - * - * Permission is hereby granted, free of charge, to any person obtaining a copy of - * this software and associated documentation files (the "Software"), to deal in - * the Software without restriction, including without limitation the rights to - * use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of - * the Software, and to permit persons to whom the Software is furnished to do so, - * subject to the following conditions: - * - * The above copyright notice and this permission notice shall be included in all - * copies or substantial portions of the Software. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR - * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS - * FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR - * COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER - * IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN - * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. - *******************************************************************************/ -package dev.jorel.commandapi.executors; - -import org.bukkit.command.CommandSender; - -import dev.jorel.commandapi.commandsenders.BukkitCommandSender; -import dev.jorel.commandapi.exceptions.WrapperCommandSyntaxException; - -/** - * A normal command executor for a CommandSender - */ -@FunctionalInterface -public interface CommandExecutor extends NormalExecutor> { - - /** - * The code to run when this command is performed - * - * @param sender The sender of this command (a player, the console etc.) - * @param args The arguments given to this command. - */ - void run(CommandSender sender, CommandArguments args) throws WrapperCommandSyntaxException; - - /** - * The code to run when this command is performed - * - * @param info The ExecutionInfo for this command - */ - @Override - default void run(ExecutionInfo> info) throws WrapperCommandSyntaxException { - this.run(info.sender(), info.args()); - } - - /** - * Returns the type of the sender of the current executor. - * @return the type of the sender of the current executor - */ - @Override - default ExecutorType getType() { - return ExecutorType.ALL; - } -} diff --git a/commandapi-platforms/commandapi-bukkit/commandapi-bukkit-core/src/main/java/dev/jorel/commandapi/executors/ConsoleCommandExecutor.java b/commandapi-platforms/commandapi-bukkit/commandapi-bukkit-core/src/main/java/dev/jorel/commandapi/executors/ConsoleCommandExecutor.java deleted file mode 100644 index a3bbec1e86..0000000000 --- a/commandapi-platforms/commandapi-bukkit/commandapi-bukkit-core/src/main/java/dev/jorel/commandapi/executors/ConsoleCommandExecutor.java +++ /dev/null @@ -1,60 +0,0 @@ -/******************************************************************************* - * Copyright 2018, 2020 Jorel Ali (Skepter) - MIT License - * - * Permission is hereby granted, free of charge, to any person obtaining a copy of - * this software and associated documentation files (the "Software"), to deal in - * the Software without restriction, including without limitation the rights to - * use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of - * the Software, and to permit persons to whom the Software is furnished to do so, - * subject to the following conditions: - * - * The above copyright notice and this permission notice shall be included in all - * copies or substantial portions of the Software. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR - * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS - * FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR - * COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER - * IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN - * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. - *******************************************************************************/ -package dev.jorel.commandapi.executors; - -import org.bukkit.command.ConsoleCommandSender; - -import dev.jorel.commandapi.commandsenders.BukkitConsoleCommandSender; -import dev.jorel.commandapi.exceptions.WrapperCommandSyntaxException; - -/** - * A normal command executor for a ConsoleCommandSender - */ -@FunctionalInterface -public interface ConsoleCommandExecutor extends NormalExecutor { - - /** - * The code to run when this command is performed - * - * @param sender The sender of this command (a player, the console etc.) - * @param args The arguments given to this command. - */ - void run(ConsoleCommandSender sender, CommandArguments args) throws WrapperCommandSyntaxException; - - /** - * The code to run when this command is performed - * - * @param info The ExecutionInfo for this command - */ - @Override - default void run(ExecutionInfo info) throws WrapperCommandSyntaxException { - this.run(info.sender(), info.args()); - } - - /** - * Returns the type of the sender of the current executor. - * @return the type of the sender of the current executor - */ - @Override - default ExecutorType getType() { - return ExecutorType.CONSOLE; - } -} diff --git a/commandapi-platforms/commandapi-bukkit/commandapi-bukkit-core/src/main/java/dev/jorel/commandapi/executors/ConsoleExecutionInfo.java b/commandapi-platforms/commandapi-bukkit/commandapi-bukkit-core/src/main/java/dev/jorel/commandapi/executors/ConsoleExecutionInfo.java deleted file mode 100644 index 0015c9bd22..0000000000 --- a/commandapi-platforms/commandapi-bukkit/commandapi-bukkit-core/src/main/java/dev/jorel/commandapi/executors/ConsoleExecutionInfo.java +++ /dev/null @@ -1,28 +0,0 @@ -package dev.jorel.commandapi.executors; - -import dev.jorel.commandapi.commandsenders.BukkitConsoleCommandSender; -import dev.jorel.commandapi.exceptions.WrapperCommandSyntaxException; -import org.bukkit.command.ConsoleCommandSender; - -@FunctionalInterface -public interface ConsoleExecutionInfo extends NormalExecutor { - - /** - * Executes the command. - * - * @param info The ExecutionInfo for this command - * @throws WrapperCommandSyntaxException if an error occurs during the execution of this command - */ - void run(ExecutionInfo info) throws WrapperCommandSyntaxException; - - /** - * Returns the type of the sender of the current executor. - * - * @return the type of the sender of the current executor - */ - @Override - default ExecutorType getType() { - return ExecutorType.CONSOLE; - } - -} diff --git a/commandapi-platforms/commandapi-bukkit/commandapi-bukkit-core/src/main/java/dev/jorel/commandapi/executors/ConsoleResultingCommandExecutor.java b/commandapi-platforms/commandapi-bukkit/commandapi-bukkit-core/src/main/java/dev/jorel/commandapi/executors/ConsoleResultingCommandExecutor.java deleted file mode 100644 index 3d858606ad..0000000000 --- a/commandapi-platforms/commandapi-bukkit/commandapi-bukkit-core/src/main/java/dev/jorel/commandapi/executors/ConsoleResultingCommandExecutor.java +++ /dev/null @@ -1,62 +0,0 @@ -/******************************************************************************* - * Copyright 2018, 2020 Jorel Ali (Skepter) - MIT License - * - * Permission is hereby granted, free of charge, to any person obtaining a copy of - * this software and associated documentation files (the "Software"), to deal in - * the Software without restriction, including without limitation the rights to - * use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of - * the Software, and to permit persons to whom the Software is furnished to do so, - * subject to the following conditions: - * - * The above copyright notice and this permission notice shall be included in all - * copies or substantial portions of the Software. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR - * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS - * FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR - * COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER - * IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN - * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. - *******************************************************************************/ -package dev.jorel.commandapi.executors; - -import org.bukkit.command.ConsoleCommandSender; - -import dev.jorel.commandapi.commandsenders.BukkitConsoleCommandSender; -import dev.jorel.commandapi.exceptions.WrapperCommandSyntaxException; - -/** - * A resulting command executor for a ConsoleCommandSender - */ -@FunctionalInterface -public interface ConsoleResultingCommandExecutor extends ResultingExecutor { - - /** - * The code to run when this command is performed - * - * @param sender The sender of this command (a player, the console etc.) - * @param args The arguments given to this command. - * @return the result of this command - */ - int run(ConsoleCommandSender sender, CommandArguments args) throws WrapperCommandSyntaxException; - - /** - * The code to run when this command is performed - * - * @param info The ExecutionInfo for this command - * @return the result of this command - */ - @Override - default int run(ExecutionInfo info) throws WrapperCommandSyntaxException { - return this.run(info.sender(), info.args()); - } - - /** - * Returns the type of the sender of the current executor. - * @return the type of the sender of the current executor - */ - @Override - default ExecutorType getType() { - return ExecutorType.CONSOLE; - } -} diff --git a/commandapi-platforms/commandapi-bukkit/commandapi-bukkit-core/src/main/java/dev/jorel/commandapi/executors/ConsoleResultingExecutionInfo.java b/commandapi-platforms/commandapi-bukkit/commandapi-bukkit-core/src/main/java/dev/jorel/commandapi/executors/ConsoleResultingExecutionInfo.java deleted file mode 100644 index 5eccd634eb..0000000000 --- a/commandapi-platforms/commandapi-bukkit/commandapi-bukkit-core/src/main/java/dev/jorel/commandapi/executors/ConsoleResultingExecutionInfo.java +++ /dev/null @@ -1,26 +0,0 @@ -package dev.jorel.commandapi.executors; - -import dev.jorel.commandapi.commandsenders.BukkitConsoleCommandSender; -import dev.jorel.commandapi.exceptions.WrapperCommandSyntaxException; -import org.bukkit.command.ConsoleCommandSender; - -@FunctionalInterface -public interface ConsoleResultingExecutionInfo extends ResultingExecutor { - - /** - * The code to run when this command is performed - * - * @param info The ExecutionInfo for this command - * @return the result of this command - */ - int run(ExecutionInfo info) throws WrapperCommandSyntaxException; - - /** - * Returns the type of the sender of the current executor. - * @return the type of the sender of the current executor - */ - @Override - default ExecutorType getType() { - return ExecutorType.CONSOLE; - } -} diff --git a/commandapi-platforms/commandapi-bukkit/commandapi-bukkit-core/src/main/java/dev/jorel/commandapi/executors/EntityCommandExecutor.java b/commandapi-platforms/commandapi-bukkit/commandapi-bukkit-core/src/main/java/dev/jorel/commandapi/executors/EntityCommandExecutor.java deleted file mode 100644 index 9b0e8ef811..0000000000 --- a/commandapi-platforms/commandapi-bukkit/commandapi-bukkit-core/src/main/java/dev/jorel/commandapi/executors/EntityCommandExecutor.java +++ /dev/null @@ -1,60 +0,0 @@ -/******************************************************************************* - * Copyright 2018, 2020 Jorel Ali (Skepter) - MIT License - * - * Permission is hereby granted, free of charge, to any person obtaining a copy of - * this software and associated documentation files (the "Software"), to deal in - * the Software without restriction, including without limitation the rights to - * use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of - * the Software, and to permit persons to whom the Software is furnished to do so, - * subject to the following conditions: - * - * The above copyright notice and this permission notice shall be included in all - * copies or substantial portions of the Software. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR - * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS - * FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR - * COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER - * IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN - * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. - *******************************************************************************/ -package dev.jorel.commandapi.executors; - -import dev.jorel.commandapi.commandsenders.BukkitEntity; -import dev.jorel.commandapi.exceptions.WrapperCommandSyntaxException; -import org.bukkit.entity.Entity; - -/** - * A normal command executor for an Entity - */ -@FunctionalInterface -public interface EntityCommandExecutor extends NormalExecutor { - - /** - * The code to run when this command is performed - * - * @param sender The sender of this command (a player, the console etc.) - * @param args The arguments given to this command. - */ - void run(Entity sender, CommandArguments args) throws WrapperCommandSyntaxException; - - /** - * Executes the command. - * - * @param info The ExecutionInfo for this command - * @throws WrapperCommandSyntaxException if an error occurs during the execution of this command - */ - @Override - default void run(ExecutionInfo info) throws WrapperCommandSyntaxException { - this.run(info.sender(), info.args()); - } - - /** - * Returns the type of the sender of the current executor. - * @return the type of the sender of the current executor - */ - @Override - default ExecutorType getType() { - return ExecutorType.ENTITY; - } -} diff --git a/commandapi-platforms/commandapi-bukkit/commandapi-bukkit-core/src/main/java/dev/jorel/commandapi/executors/EntityExecutionInfo.java b/commandapi-platforms/commandapi-bukkit/commandapi-bukkit-core/src/main/java/dev/jorel/commandapi/executors/EntityExecutionInfo.java deleted file mode 100644 index 90e82cff27..0000000000 --- a/commandapi-platforms/commandapi-bukkit/commandapi-bukkit-core/src/main/java/dev/jorel/commandapi/executors/EntityExecutionInfo.java +++ /dev/null @@ -1,28 +0,0 @@ -package dev.jorel.commandapi.executors; - -import dev.jorel.commandapi.commandsenders.BukkitEntity; -import dev.jorel.commandapi.exceptions.WrapperCommandSyntaxException; -import org.bukkit.entity.Entity; - -@FunctionalInterface -public interface EntityExecutionInfo extends NormalExecutor { - - /** - * Executes the command. - * - * @param info The ExecutionInfo for this command - * @throws WrapperCommandSyntaxException if an error occurs during the execution of this command - */ - void run(ExecutionInfo info) throws WrapperCommandSyntaxException; - - /** - * Returns the type of the sender of the current executor. - * - * @return the type of the sender of the current executor - */ - @Override - default ExecutorType getType() { - return ExecutorType.ENTITY; - } - -} diff --git a/commandapi-platforms/commandapi-bukkit/commandapi-bukkit-core/src/main/java/dev/jorel/commandapi/executors/EntityResultingCommandExecutor.java b/commandapi-platforms/commandapi-bukkit/commandapi-bukkit-core/src/main/java/dev/jorel/commandapi/executors/EntityResultingCommandExecutor.java deleted file mode 100644 index 51a0a28190..0000000000 --- a/commandapi-platforms/commandapi-bukkit/commandapi-bukkit-core/src/main/java/dev/jorel/commandapi/executors/EntityResultingCommandExecutor.java +++ /dev/null @@ -1,61 +0,0 @@ -/******************************************************************************* - * Copyright 2018, 2020 Jorel Ali (Skepter) - MIT License - * - * Permission is hereby granted, free of charge, to any person obtaining a copy of - * this software and associated documentation files (the "Software"), to deal in - * the Software without restriction, including without limitation the rights to - * use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of - * the Software, and to permit persons to whom the Software is furnished to do so, - * subject to the following conditions: - * - * The above copyright notice and this permission notice shall be included in all - * copies or substantial portions of the Software. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR - * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS - * FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR - * COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER - * IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN - * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. - *******************************************************************************/ -package dev.jorel.commandapi.executors; - -import dev.jorel.commandapi.commandsenders.BukkitEntity; -import dev.jorel.commandapi.exceptions.WrapperCommandSyntaxException; -import org.bukkit.entity.Entity; - -/** - * A resulting command executor for an Entity - */ -@FunctionalInterface -public interface EntityResultingCommandExecutor extends ResultingExecutor { - - /** - * The code to run when this command is performed - * - * @param sender The sender of this command (a player, the console etc.) - * @param args The arguments given to this command. - * @return the result of this command - */ - int run(Entity sender, CommandArguments args) throws WrapperCommandSyntaxException; - - /** - * The code to run when this command is performed - * - * @param info The ExecutionInfo for this command - * @return the result of this command - */ - @Override - default int run(ExecutionInfo info) throws WrapperCommandSyntaxException { - return this.run(info.sender(), info.args()); - } - - /** - * Returns the type of the sender of the current executor. - * @return the type of the sender of the current executor - */ - @Override - default ExecutorType getType() { - return ExecutorType.ENTITY; - } -} diff --git a/commandapi-platforms/commandapi-bukkit/commandapi-bukkit-core/src/main/java/dev/jorel/commandapi/executors/EntityResultingExecutionInfo.java b/commandapi-platforms/commandapi-bukkit/commandapi-bukkit-core/src/main/java/dev/jorel/commandapi/executors/EntityResultingExecutionInfo.java deleted file mode 100644 index cf28c9a713..0000000000 --- a/commandapi-platforms/commandapi-bukkit/commandapi-bukkit-core/src/main/java/dev/jorel/commandapi/executors/EntityResultingExecutionInfo.java +++ /dev/null @@ -1,27 +0,0 @@ -package dev.jorel.commandapi.executors; - -import dev.jorel.commandapi.commandsenders.BukkitEntity; -import dev.jorel.commandapi.exceptions.WrapperCommandSyntaxException; -import org.bukkit.entity.Entity; - -@FunctionalInterface -public interface EntityResultingExecutionInfo extends ResultingExecutor { - - /** - * The code to run when this command is performed - * - * @param info The ExecutionInfo for this command - * @return the result of this command - */ - int run(ExecutionInfo info) throws WrapperCommandSyntaxException; - - /** - * Returns the type of the sender of the current executor. - * - * @return the type of the sender of the current executor - */ - @Override - default ExecutorType getType() { - return ExecutorType.ENTITY; - } -} diff --git a/commandapi-platforms/commandapi-bukkit/commandapi-bukkit-core/src/main/java/dev/jorel/commandapi/executors/ProxyCommandExecutor.java b/commandapi-platforms/commandapi-bukkit/commandapi-bukkit-core/src/main/java/dev/jorel/commandapi/executors/ExecutorType.java similarity index 54% rename from commandapi-platforms/commandapi-bukkit/commandapi-bukkit-core/src/main/java/dev/jorel/commandapi/executors/ProxyCommandExecutor.java rename to commandapi-platforms/commandapi-bukkit/commandapi-bukkit-core/src/main/java/dev/jorel/commandapi/executors/ExecutorType.java index fdceb47977..74b6d9bf91 100644 --- a/commandapi-platforms/commandapi-bukkit/commandapi-bukkit-core/src/main/java/dev/jorel/commandapi/executors/ProxyCommandExecutor.java +++ b/commandapi-platforms/commandapi-bukkit/commandapi-bukkit-core/src/main/java/dev/jorel/commandapi/executors/ExecutorType.java @@ -20,41 +20,63 @@ *******************************************************************************/ package dev.jorel.commandapi.executors; -import dev.jorel.commandapi.commandsenders.BukkitNativeProxyCommandSender; -import dev.jorel.commandapi.exceptions.WrapperCommandSyntaxException; +import org.bukkit.command.BlockCommandSender; +import org.bukkit.command.CommandSender; +import org.bukkit.command.ConsoleCommandSender; +import org.bukkit.command.ProxiedCommandSender; +import org.bukkit.command.RemoteConsoleCommandSender; +import org.bukkit.entity.Entity; +import org.bukkit.entity.Player; + import dev.jorel.commandapi.wrappers.NativeProxyCommandSender; /** - * A normal command executor for a NativeProxyCommandSender + * An enum representing the type of an executor */ -@FunctionalInterface -public interface ProxyCommandExecutor extends NormalExecutor { +public enum ExecutorType { + + /** + * An executor where the CommandSender is any {@link CommandSender} + */ + ALL, + + /** + * An executor where the CommandSender is a {@link Player} + */ + PLAYER, + + /** + * An executor where the CommandSender is an {@link Entity} + */ + ENTITY, + + /** + * An executor where the CommandSender is a {@link ConsoleCommandSender} + */ + CONSOLE, + + /** + * An executor where the CommandSender is a {@link BlockCommandSender} + */ + BLOCK, + + /** + * An executor where the CommandSender is a {@link ProxiedCommandSender} + */ + PROXY, /** - * The code to run when this command is performed - * - * @param sender The sender of this command (a player, the console etc.) - * @param args The arguments given to this command. + * An executor where the CommandSender is (always) a {@link NativeProxyCommandSender} */ - void run(NativeProxyCommandSender sender, CommandArguments args) throws WrapperCommandSyntaxException; + NATIVE, /** - * Executes the command. - * - * @param info The ExecutionInfo for this command - * @throws WrapperCommandSyntaxException if an error occurs during the execution of this command + * An executor where the CommandSender is a {@link RemoteConsoleCommandSender} */ - @Override - default void run(ExecutionInfo info) throws WrapperCommandSyntaxException { - this.run(info.sender(), info.args()); - } + REMOTE, /** - * Returns the type of the sender of the current executor. - * @return the type of the sender of the current executor + * An executor where the CommandSender is a {@code io.papermc.paper.commands.FeedbackForwardingSender} */ - @Override - default ExecutorType getType() { - return ExecutorType.PROXY; - } + FEEDBACK_FORWARDING; } diff --git a/commandapi-platforms/commandapi-bukkit/commandapi-bukkit-core/src/main/java/dev/jorel/commandapi/executors/FeedbackForwardingCommandExecutor.java b/commandapi-platforms/commandapi-bukkit/commandapi-bukkit-core/src/main/java/dev/jorel/commandapi/executors/FeedbackForwardingCommandExecutor.java deleted file mode 100644 index 05ec98c740..0000000000 --- a/commandapi-platforms/commandapi-bukkit/commandapi-bukkit-core/src/main/java/dev/jorel/commandapi/executors/FeedbackForwardingCommandExecutor.java +++ /dev/null @@ -1,60 +0,0 @@ -/******************************************************************************* - * Copyright 2018, 2020 Jorel Ali (Skepter) - MIT License - * - * Permission is hereby granted, free of charge, to any person obtaining a copy of - * this software and associated documentation files (the "Software"), to deal in - * the Software without restriction, including without limitation the rights to - * use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of - * the Software, and to permit persons to whom the Software is furnished to do so, - * subject to the following conditions: - * - * The above copyright notice and this permission notice shall be included in all - * copies or substantial portions of the Software. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR - * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS - * FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR - * COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER - * IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN - * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. - *******************************************************************************/ -package dev.jorel.commandapi.executors; - -import org.bukkit.command.CommandSender; - -import dev.jorel.commandapi.commandsenders.BukkitFeedbackForwardingCommandSender; -import dev.jorel.commandapi.exceptions.WrapperCommandSyntaxException; - -/** - * A normal command executor for a BlockCommandSender - */ -@FunctionalInterface -public interface FeedbackForwardingCommandExecutor extends NormalExecutor< CommandSender, BukkitFeedbackForwardingCommandSender> { - - /** - * The code to run when this command is performed - * - * @param sender The sender of this command (a player, the console etc.) - * @param args The arguments given to this command. - */ - void run(CommandSender sender, CommandArguments args) throws WrapperCommandSyntaxException; - - /** - * The code to run when this command is performed - * - * @param info The ExecutionInfo for this command - */ - @Override - default void run(ExecutionInfo> info) throws WrapperCommandSyntaxException { - this.run(info.sender(), info.args()); - } - - /** - * Returns the type of the sender of the current executor. - * @return the type of the sender of the current executor - */ - @Override - default ExecutorType getType() { - return ExecutorType.FEEDBACK_FORWARDING; - } -} diff --git a/commandapi-platforms/commandapi-bukkit/commandapi-bukkit-core/src/main/java/dev/jorel/commandapi/executors/FeedbackForwardingExecutionInfo.java b/commandapi-platforms/commandapi-bukkit/commandapi-bukkit-core/src/main/java/dev/jorel/commandapi/executors/FeedbackForwardingExecutionInfo.java deleted file mode 100644 index 886e8b367f..0000000000 --- a/commandapi-platforms/commandapi-bukkit/commandapi-bukkit-core/src/main/java/dev/jorel/commandapi/executors/FeedbackForwardingExecutionInfo.java +++ /dev/null @@ -1,29 +0,0 @@ -package dev.jorel.commandapi.executors; - -import org.bukkit.command.CommandSender; - -import dev.jorel.commandapi.commandsenders.BukkitFeedbackForwardingCommandSender; -import dev.jorel.commandapi.exceptions.WrapperCommandSyntaxException; - -@FunctionalInterface -public interface FeedbackForwardingExecutionInfo extends NormalExecutor> { - - /** - * Executes the command. - * - * @param info The ExecutionInfo for this command - * @throws WrapperCommandSyntaxException if an error occurs during the execution of this command - */ - void run(ExecutionInfo> info) throws WrapperCommandSyntaxException; - - /** - * Returns the type of the sender of the current executor. - * - * @return the type of the sender of the current executor - */ - @Override - default ExecutorType getType() { - return ExecutorType.FEEDBACK_FORWARDING; - } - -} diff --git a/commandapi-platforms/commandapi-bukkit/commandapi-bukkit-core/src/main/java/dev/jorel/commandapi/executors/FeedbackForwardingResultingCommandExecutor.java b/commandapi-platforms/commandapi-bukkit/commandapi-bukkit-core/src/main/java/dev/jorel/commandapi/executors/FeedbackForwardingResultingCommandExecutor.java deleted file mode 100644 index 09efe13ae5..0000000000 --- a/commandapi-platforms/commandapi-bukkit/commandapi-bukkit-core/src/main/java/dev/jorel/commandapi/executors/FeedbackForwardingResultingCommandExecutor.java +++ /dev/null @@ -1,65 +0,0 @@ -/******************************************************************************* - * Copyright 2018, 2020 Jorel Ali (Skepter) - MIT License - * - * Permission is hereby granted, free of charge, to any person obtaining a copy of - * this software and associated documentation files (the "Software"), to deal in - * the Software without restriction, including without limitation the rights to - * use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of - * the Software, and to permit persons to whom the Software is furnished to do so, - * subject to the following conditions: - * - * The above copyright notice and this permission notice shall be included in all - * copies or substantial portions of the Software. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR - * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS - * FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR - * COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER - * IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN - * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. - *******************************************************************************/ -package dev.jorel.commandapi.executors; - -import org.bukkit.command.CommandSender; - -import dev.jorel.commandapi.commandsenders.BukkitFeedbackForwardingCommandSender; -import dev.jorel.commandapi.exceptions.WrapperCommandSyntaxException; - -/** - * A resulting command executor for a BlockCommandSender - */ -@FunctionalInterface -public interface FeedbackForwardingResultingCommandExecutor extends ResultingExecutor> { - - /** - * The code to run when this command is performed - * - * @param sender The sender of this command (a player, the console etc.) - * @param args The arguments given to this command. - * - * @return the result of this command - */ - int run(CommandSender sender, CommandArguments args) throws WrapperCommandSyntaxException; - - /** - * The code to run when this command is performed - * - * @param info The ExecutionInfo for this command - * - * @return the result of this command - */ - @Override - default int run(ExecutionInfo> info) throws WrapperCommandSyntaxException { - return this.run(info.sender(), info.args()); - } - - /** - * Returns the type of the sender of the current executor. - * @return the type of the sender of the current executor - */ - @Override - default ExecutorType getType() { - return ExecutorType.FEEDBACK_FORWARDING ; - } - -} diff --git a/commandapi-platforms/commandapi-bukkit/commandapi-bukkit-core/src/main/java/dev/jorel/commandapi/executors/FeedbackForwardingResultingExecutionInfo.java b/commandapi-platforms/commandapi-bukkit/commandapi-bukkit-core/src/main/java/dev/jorel/commandapi/executors/FeedbackForwardingResultingExecutionInfo.java deleted file mode 100644 index a01947f7be..0000000000 --- a/commandapi-platforms/commandapi-bukkit/commandapi-bukkit-core/src/main/java/dev/jorel/commandapi/executors/FeedbackForwardingResultingExecutionInfo.java +++ /dev/null @@ -1,28 +0,0 @@ -package dev.jorel.commandapi.executors; - -import org.bukkit.command.CommandSender; - -import dev.jorel.commandapi.commandsenders.BukkitFeedbackForwardingCommandSender; -import dev.jorel.commandapi.exceptions.WrapperCommandSyntaxException; - -@FunctionalInterface -public interface FeedbackForwardingResultingExecutionInfo extends ResultingExecutor> { - - /** - * The code to run when this command is performed - * - * @param info The ExecutionInfo for this command - * @return the result of this command - */ - int run(ExecutionInfo> info) throws WrapperCommandSyntaxException; - - /** - * Returns the type of the sender of the current executor. - * @return the type of the sender of the current executor - */ - @Override - default ExecutorType getType() { - return ExecutorType.FEEDBACK_FORWARDING; - } - -} diff --git a/commandapi-platforms/commandapi-bukkit/commandapi-bukkit-core/src/main/java/dev/jorel/commandapi/executors/NativeCommandExecutor.java b/commandapi-platforms/commandapi-bukkit/commandapi-bukkit-core/src/main/java/dev/jorel/commandapi/executors/NativeCommandExecutor.java deleted file mode 100644 index afb23693f0..0000000000 --- a/commandapi-platforms/commandapi-bukkit/commandapi-bukkit-core/src/main/java/dev/jorel/commandapi/executors/NativeCommandExecutor.java +++ /dev/null @@ -1,60 +0,0 @@ -/******************************************************************************* - * Copyright 2018, 2020 Jorel Ali (Skepter) - MIT License - * - * Permission is hereby granted, free of charge, to any person obtaining a copy of - * this software and associated documentation files (the "Software"), to deal in - * the Software without restriction, including without limitation the rights to - * use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of - * the Software, and to permit persons to whom the Software is furnished to do so, - * subject to the following conditions: - * - * The above copyright notice and this permission notice shall be included in all - * copies or substantial portions of the Software. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR - * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS - * FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR - * COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER - * IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN - * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. - *******************************************************************************/ -package dev.jorel.commandapi.executors; - -import dev.jorel.commandapi.commandsenders.BukkitNativeProxyCommandSender; -import dev.jorel.commandapi.exceptions.WrapperCommandSyntaxException; -import dev.jorel.commandapi.wrappers.NativeProxyCommandSender; - -/** - * A normal command executor for a NativeProxyCommandSender - */ -@FunctionalInterface -public interface NativeCommandExecutor extends NormalExecutor { - - /** - * The code to run when this command is performed - * - * @param sender The sender of this command (a player, the console etc.) - * @param args The arguments given to this command. - */ - void run(NativeProxyCommandSender sender, CommandArguments args) throws WrapperCommandSyntaxException; - - /** - * The code to run when this command is performed - * - * @param info The ExecutionInfo for this command - * @throws WrapperCommandSyntaxException if an error occurs during the execution of this command - */ - @Override - default void run(ExecutionInfo info) throws WrapperCommandSyntaxException { - this.run(info.sender(), info.args()); - } - - /** - * Returns the type of the sender of the current executor. - * @return the type of the sender of the current executor - */ - @Override - default ExecutorType getType() { - return ExecutorType.NATIVE; - } -} diff --git a/commandapi-platforms/commandapi-bukkit/commandapi-bukkit-core/src/main/java/dev/jorel/commandapi/executors/NativeExecutionInfo.java b/commandapi-platforms/commandapi-bukkit/commandapi-bukkit-core/src/main/java/dev/jorel/commandapi/executors/NativeExecutionInfo.java deleted file mode 100644 index ad5b6e468d..0000000000 --- a/commandapi-platforms/commandapi-bukkit/commandapi-bukkit-core/src/main/java/dev/jorel/commandapi/executors/NativeExecutionInfo.java +++ /dev/null @@ -1,28 +0,0 @@ -package dev.jorel.commandapi.executors; - -import dev.jorel.commandapi.commandsenders.BukkitNativeProxyCommandSender; -import dev.jorel.commandapi.exceptions.WrapperCommandSyntaxException; -import dev.jorel.commandapi.wrappers.NativeProxyCommandSender; - -@FunctionalInterface -public interface NativeExecutionInfo extends NormalExecutor { - - /** - * Executes the command. - * - * @param info The ExecutionInfo for this command - * @throws WrapperCommandSyntaxException if an error occurs during the execution of this command - */ - void run(ExecutionInfo info) throws WrapperCommandSyntaxException; - - /** - * Returns the type of the sender of the current executor. - * - * @return the type of the sender of the current executor - */ - @Override - default ExecutorType getType() { - return ExecutorType.NATIVE; - } - -} diff --git a/commandapi-platforms/commandapi-bukkit/commandapi-bukkit-core/src/main/java/dev/jorel/commandapi/executors/NativeResultingCommandExecutor.java b/commandapi-platforms/commandapi-bukkit/commandapi-bukkit-core/src/main/java/dev/jorel/commandapi/executors/NativeResultingCommandExecutor.java deleted file mode 100644 index 3c9b537187..0000000000 --- a/commandapi-platforms/commandapi-bukkit/commandapi-bukkit-core/src/main/java/dev/jorel/commandapi/executors/NativeResultingCommandExecutor.java +++ /dev/null @@ -1,61 +0,0 @@ -/******************************************************************************* - * Copyright 2018, 2020 Jorel Ali (Skepter) - MIT License - * - * Permission is hereby granted, free of charge, to any person obtaining a copy of - * this software and associated documentation files (the "Software"), to deal in - * the Software without restriction, including without limitation the rights to - * use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of - * the Software, and to permit persons to whom the Software is furnished to do so, - * subject to the following conditions: - * - * The above copyright notice and this permission notice shall be included in all - * copies or substantial portions of the Software. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR - * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS - * FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR - * COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER - * IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN - * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. - *******************************************************************************/ -package dev.jorel.commandapi.executors; - -import dev.jorel.commandapi.commandsenders.BukkitNativeProxyCommandSender; -import dev.jorel.commandapi.exceptions.WrapperCommandSyntaxException; -import dev.jorel.commandapi.wrappers.NativeProxyCommandSender; - -/** - * A resulting command executor for a NativeProxyCommandSender - */ -@FunctionalInterface -public interface NativeResultingCommandExecutor extends ResultingExecutor { - - /** - * The code to run when this command is performed - * - * @param sender The sender of this command (a player, the console etc.) - * @param args The arguments given to this command. - * @return the result of this command - */ - int run(NativeProxyCommandSender sender, CommandArguments args) throws WrapperCommandSyntaxException; - - /** - * The code to run when this command is performed - * - * @param info The ExecutionInfo for this command - * @return the result of this command - */ - @Override - default int run(ExecutionInfo info) throws WrapperCommandSyntaxException { - return this.run(info.sender(), info.args()); - } - - /** - * Returns the type of the sender of the current executor. - * @return the type of the sender of the current executor - */ - @Override - default ExecutorType getType() { - return ExecutorType.NATIVE; - } -} diff --git a/commandapi-platforms/commandapi-bukkit/commandapi-bukkit-core/src/main/java/dev/jorel/commandapi/executors/NativeResultingExecutionInfo.java b/commandapi-platforms/commandapi-bukkit/commandapi-bukkit-core/src/main/java/dev/jorel/commandapi/executors/NativeResultingExecutionInfo.java deleted file mode 100644 index 0807a03c8a..0000000000 --- a/commandapi-platforms/commandapi-bukkit/commandapi-bukkit-core/src/main/java/dev/jorel/commandapi/executors/NativeResultingExecutionInfo.java +++ /dev/null @@ -1,26 +0,0 @@ -package dev.jorel.commandapi.executors; - -import dev.jorel.commandapi.commandsenders.BukkitNativeProxyCommandSender; -import dev.jorel.commandapi.exceptions.WrapperCommandSyntaxException; -import dev.jorel.commandapi.wrappers.NativeProxyCommandSender; - -public interface NativeResultingExecutionInfo extends ResultingExecutor { - - /** - * The code to run when this command is performed - * - * @param info The ExecutionInfo for this command - * @return the result of this command - */ - int run(ExecutionInfo info) throws WrapperCommandSyntaxException; - - /** - * Returns the type of the sender of the current executor. - * - * @return the type of the sender of the current executor - */ - @Override - default ExecutorType getType() { - return ExecutorType.NATIVE; - } -} diff --git a/commandapi-platforms/commandapi-bukkit/commandapi-bukkit-core/src/main/java/dev/jorel/commandapi/executors/PlayerCommandExecutor.java b/commandapi-platforms/commandapi-bukkit/commandapi-bukkit-core/src/main/java/dev/jorel/commandapi/executors/PlayerCommandExecutor.java deleted file mode 100644 index ce7151c1a5..0000000000 --- a/commandapi-platforms/commandapi-bukkit/commandapi-bukkit-core/src/main/java/dev/jorel/commandapi/executors/PlayerCommandExecutor.java +++ /dev/null @@ -1,59 +0,0 @@ -/******************************************************************************* - * Copyright 2018, 2020 Jorel Ali (Skepter) - MIT License - * - * Permission is hereby granted, free of charge, to any person obtaining a copy of - * this software and associated documentation files (the "Software"), to deal in - * the Software without restriction, including without limitation the rights to - * use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of - * the Software, and to permit persons to whom the Software is furnished to do so, - * subject to the following conditions: - * - * The above copyright notice and this permission notice shall be included in all - * copies or substantial portions of the Software. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR - * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS - * FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR - * COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER - * IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN - * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. - *******************************************************************************/ -package dev.jorel.commandapi.executors; - -import dev.jorel.commandapi.commandsenders.BukkitPlayer; -import dev.jorel.commandapi.exceptions.WrapperCommandSyntaxException; -import org.bukkit.entity.Player; - -/** - * A normal command executor for a Player - */ -@FunctionalInterface -public interface PlayerCommandExecutor extends NormalExecutor { - - /** - * The code to run when this command is performed - * - * @param sender The sender of this command (a player, the console etc.) - * @param args The arguments given to this command. - */ - void run(Player sender, CommandArguments args) throws WrapperCommandSyntaxException; - - /** - * The code to run when this command is performed - * - * @param info The ExecutionInfo for this command - */ - @Override - default void run(ExecutionInfo info) throws WrapperCommandSyntaxException { - this.run(info.sender(), info.args()); - } - - /** - * Returns the type of the sender of the current executor. - * @return the type of the sender of the current executor - */ - @Override - default ExecutorType getType() { - return ExecutorType.PLAYER; - } -} diff --git a/commandapi-platforms/commandapi-bukkit/commandapi-bukkit-core/src/main/java/dev/jorel/commandapi/executors/PlayerExecutionInfo.java b/commandapi-platforms/commandapi-bukkit/commandapi-bukkit-core/src/main/java/dev/jorel/commandapi/executors/PlayerExecutionInfo.java deleted file mode 100644 index 6d5a3168e5..0000000000 --- a/commandapi-platforms/commandapi-bukkit/commandapi-bukkit-core/src/main/java/dev/jorel/commandapi/executors/PlayerExecutionInfo.java +++ /dev/null @@ -1,27 +0,0 @@ -package dev.jorel.commandapi.executors; - -import dev.jorel.commandapi.commandsenders.BukkitPlayer; -import dev.jorel.commandapi.exceptions.WrapperCommandSyntaxException; -import org.bukkit.entity.Player; - -@FunctionalInterface -public interface PlayerExecutionInfo extends NormalExecutor { - - /** - * Executes the command. - * - * @param info The ExecutionInfo for this command - * @throws WrapperCommandSyntaxException if an error occurs during the execution of this command - */ - void run(ExecutionInfo info) throws WrapperCommandSyntaxException; - - /** - * Returns the type of the sender of the current executor. - * - * @return the type of the sender of the current executor - */ - @Override - default ExecutorType getType() { - return ExecutorType.PLAYER; - } -} diff --git a/commandapi-platforms/commandapi-bukkit/commandapi-bukkit-core/src/main/java/dev/jorel/commandapi/executors/PlayerResultingCommandExecutor.java b/commandapi-platforms/commandapi-bukkit/commandapi-bukkit-core/src/main/java/dev/jorel/commandapi/executors/PlayerResultingCommandExecutor.java deleted file mode 100644 index 729ed8acf2..0000000000 --- a/commandapi-platforms/commandapi-bukkit/commandapi-bukkit-core/src/main/java/dev/jorel/commandapi/executors/PlayerResultingCommandExecutor.java +++ /dev/null @@ -1,62 +0,0 @@ -/******************************************************************************* - * Copyright 2018, 2020 Jorel Ali (Skepter) - MIT License - * - * Permission is hereby granted, free of charge, to any person obtaining a copy of - * this software and associated documentation files (the "Software"), to deal in - * the Software without restriction, including without limitation the rights to - * use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of - * the Software, and to permit persons to whom the Software is furnished to do so, - * subject to the following conditions: - * - * The above copyright notice and this permission notice shall be included in all - * copies or substantial portions of the Software. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR - * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS - * FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR - * COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER - * IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN - * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. - *******************************************************************************/ -package dev.jorel.commandapi.executors; - -import dev.jorel.commandapi.commandsenders.BukkitPlayer; -import dev.jorel.commandapi.exceptions.WrapperCommandSyntaxException; -import org.bukkit.entity.Player; - -/** - * A resulting command executor for a Player - */ -@FunctionalInterface -public interface PlayerResultingCommandExecutor extends ResultingExecutor { - - /** - * The code to run when this command is performed - * - * @param sender The sender of this command (a player, the console etc.) - * @param args The arguments given to this command. - * @return the result of this command - */ - int run(Player sender, CommandArguments args) throws WrapperCommandSyntaxException; - - /** - * The code to run when this command is performed - * - * @param info The ExecutionInfo for this command - * @return the result of this command - * @throws WrapperCommandSyntaxException - */ - @Override - default int run(ExecutionInfo info) throws WrapperCommandSyntaxException { - return this.run(info.sender(), info.args()); - } - - /** - * Returns the type of the sender of the current executor. - * @return the type of the sender of the current executor - */ - @Override - default ExecutorType getType() { - return ExecutorType.PLAYER; - } -} diff --git a/commandapi-platforms/commandapi-bukkit/commandapi-bukkit-core/src/main/java/dev/jorel/commandapi/executors/PlayerResultingExecutionInfo.java b/commandapi-platforms/commandapi-bukkit/commandapi-bukkit-core/src/main/java/dev/jorel/commandapi/executors/PlayerResultingExecutionInfo.java deleted file mode 100644 index a18df5eb95..0000000000 --- a/commandapi-platforms/commandapi-bukkit/commandapi-bukkit-core/src/main/java/dev/jorel/commandapi/executors/PlayerResultingExecutionInfo.java +++ /dev/null @@ -1,24 +0,0 @@ -package dev.jorel.commandapi.executors; - -import dev.jorel.commandapi.commandsenders.BukkitPlayer; -import dev.jorel.commandapi.exceptions.WrapperCommandSyntaxException; -import org.bukkit.entity.Player; - -public interface PlayerResultingExecutionInfo extends ResultingExecutor { - - /** - * @param info The ExecutionInfo for this command - * @return the result of this command - * @throws WrapperCommandSyntaxException - */ - int run(ExecutionInfo info) throws WrapperCommandSyntaxException; - - /** - * Returns the type of the sender of the current executor. - * @return the type of the sender of the current executor - */ - @Override - default ExecutorType getType() { - return ExecutorType.PLAYER; - } -} diff --git a/commandapi-platforms/commandapi-bukkit/commandapi-bukkit-core/src/main/java/dev/jorel/commandapi/executors/ProxyExecutionInfo.java b/commandapi-platforms/commandapi-bukkit/commandapi-bukkit-core/src/main/java/dev/jorel/commandapi/executors/ProxyExecutionInfo.java deleted file mode 100644 index 6b54c6f3f7..0000000000 --- a/commandapi-platforms/commandapi-bukkit/commandapi-bukkit-core/src/main/java/dev/jorel/commandapi/executors/ProxyExecutionInfo.java +++ /dev/null @@ -1,28 +0,0 @@ -package dev.jorel.commandapi.executors; - -import dev.jorel.commandapi.commandsenders.BukkitNativeProxyCommandSender; -import dev.jorel.commandapi.exceptions.WrapperCommandSyntaxException; -import dev.jorel.commandapi.wrappers.NativeProxyCommandSender; - -@FunctionalInterface -public interface ProxyExecutionInfo extends NormalExecutor { - - /** - * Executes the command. - * - * @param info The ExecutionInfo for this command - * @throws WrapperCommandSyntaxException if an error occurs during the execution of this command - */ - void run(ExecutionInfo info) throws WrapperCommandSyntaxException; - - /** - * Returns the type of the sender of the current executor. - * - * @return the type of the sender of the current executor - */ - @Override - default ExecutorType getType() { - return ExecutorType.PROXY; - } - -} diff --git a/commandapi-platforms/commandapi-bukkit/commandapi-bukkit-core/src/main/java/dev/jorel/commandapi/executors/ProxyResultingCommandExecutor.java b/commandapi-platforms/commandapi-bukkit/commandapi-bukkit-core/src/main/java/dev/jorel/commandapi/executors/ProxyResultingCommandExecutor.java deleted file mode 100644 index 1400c9b265..0000000000 --- a/commandapi-platforms/commandapi-bukkit/commandapi-bukkit-core/src/main/java/dev/jorel/commandapi/executors/ProxyResultingCommandExecutor.java +++ /dev/null @@ -1,62 +0,0 @@ -/******************************************************************************* - * Copyright 2018, 2020 Jorel Ali (Skepter) - MIT License - * - * Permission is hereby granted, free of charge, to any person obtaining a copy of - * this software and associated documentation files (the "Software"), to deal in - * the Software without restriction, including without limitation the rights to - * use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of - * the Software, and to permit persons to whom the Software is furnished to do so, - * subject to the following conditions: - * - * The above copyright notice and this permission notice shall be included in all - * copies or substantial portions of the Software. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR - * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS - * FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR - * COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER - * IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN - * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. - *******************************************************************************/ -package dev.jorel.commandapi.executors; - -import dev.jorel.commandapi.commandsenders.BukkitNativeProxyCommandSender; -import dev.jorel.commandapi.exceptions.WrapperCommandSyntaxException; -import dev.jorel.commandapi.wrappers.NativeProxyCommandSender; - -/** - * A resulting command executor for a NativeProxyCommandSender - */ -@FunctionalInterface -public interface ProxyResultingCommandExecutor extends ResultingExecutor { - - /** - * The code to run when this command is performed - * - * @param sender The sender of this command (a player, the console etc.) - * @param args The arguments given to this command. - * @return the result of this command - */ - int run(NativeProxyCommandSender sender, CommandArguments args) throws WrapperCommandSyntaxException; - - /** - * The code to run when this command is performed - * - * @param info The ExecutionInfo for this command - * @return the result of this command - * @throws WrapperCommandSyntaxException - */ - @Override - default int run(ExecutionInfo info) throws WrapperCommandSyntaxException { - return this.run(info.sender(), info.args()); - } - - /** - * Returns the type of the sender of the current executor. - * @return the type of the sender of the current executor - */ - @Override - default ExecutorType getType() { - return ExecutorType.PROXY; - } -} diff --git a/commandapi-platforms/commandapi-bukkit/commandapi-bukkit-core/src/main/java/dev/jorel/commandapi/executors/ProxyResultingExecutionInfo.java b/commandapi-platforms/commandapi-bukkit/commandapi-bukkit-core/src/main/java/dev/jorel/commandapi/executors/ProxyResultingExecutionInfo.java deleted file mode 100644 index d103f7653e..0000000000 --- a/commandapi-platforms/commandapi-bukkit/commandapi-bukkit-core/src/main/java/dev/jorel/commandapi/executors/ProxyResultingExecutionInfo.java +++ /dev/null @@ -1,27 +0,0 @@ -package dev.jorel.commandapi.executors; - -import dev.jorel.commandapi.commandsenders.BukkitNativeProxyCommandSender; -import dev.jorel.commandapi.exceptions.WrapperCommandSyntaxException; -import dev.jorel.commandapi.wrappers.NativeProxyCommandSender; - -@FunctionalInterface -public interface ProxyResultingExecutionInfo extends ResultingExecutor { - - /** - * The code to run when this command is performed - * - * @param info The ExecutionInfo for this command - * @return the command result - * @throws WrapperCommandSyntaxException - */ - int run(ExecutionInfo info) throws WrapperCommandSyntaxException; - - /** - * Returns the type of the sender of the current executor. - * @return the type of the sender of the current executor - */ - @Override - default ExecutorType getType() { - return ExecutorType.PROXY; - } -} diff --git a/commandapi-platforms/commandapi-bukkit/commandapi-bukkit-core/src/main/java/dev/jorel/commandapi/executors/RemoteConsoleCommandExecutor.java b/commandapi-platforms/commandapi-bukkit/commandapi-bukkit-core/src/main/java/dev/jorel/commandapi/executors/RemoteConsoleCommandExecutor.java deleted file mode 100644 index e7b9f92d49..0000000000 --- a/commandapi-platforms/commandapi-bukkit/commandapi-bukkit-core/src/main/java/dev/jorel/commandapi/executors/RemoteConsoleCommandExecutor.java +++ /dev/null @@ -1,38 +0,0 @@ -package dev.jorel.commandapi.executors; - -import dev.jorel.commandapi.commandsenders.BukkitRemoteConsoleCommandSender; -import dev.jorel.commandapi.exceptions.WrapperCommandSyntaxException; -import org.bukkit.command.RemoteConsoleCommandSender; - -@FunctionalInterface -public interface RemoteConsoleCommandExecutor extends NormalExecutor { - - /** - * The code to run when this command is performed - * - * @param sender The sender of this command (a player, the console etc.) - * @param args The arguments given to this command. - */ - void run(RemoteConsoleCommandSender sender, CommandArguments args) throws WrapperCommandSyntaxException; - - /** - * Executes the command. - * - * @param info The ExecutionInfo for this command - * @throws WrapperCommandSyntaxException if an error occurs during the execution of this command - */ - @Override - default void run(ExecutionInfo info) throws WrapperCommandSyntaxException { - this.run(info.sender(), info.args()); - } - - /** - * Returns the type of the sender of the current executor. - * - * @return the type of the sender of the current executor - */ - @Override - default ExecutorType getType() { - return ExecutorType.REMOTE; - } -} diff --git a/commandapi-platforms/commandapi-bukkit/commandapi-bukkit-core/src/main/java/dev/jorel/commandapi/executors/RemoteConsoleExecutionInfo.java b/commandapi-platforms/commandapi-bukkit/commandapi-bukkit-core/src/main/java/dev/jorel/commandapi/executors/RemoteConsoleExecutionInfo.java deleted file mode 100644 index 5a819cc54a..0000000000 --- a/commandapi-platforms/commandapi-bukkit/commandapi-bukkit-core/src/main/java/dev/jorel/commandapi/executors/RemoteConsoleExecutionInfo.java +++ /dev/null @@ -1,27 +0,0 @@ -package dev.jorel.commandapi.executors; - -import dev.jorel.commandapi.commandsenders.BukkitRemoteConsoleCommandSender; -import dev.jorel.commandapi.exceptions.WrapperCommandSyntaxException; -import org.bukkit.command.RemoteConsoleCommandSender; - -@FunctionalInterface -public interface RemoteConsoleExecutionInfo extends NormalExecutor { - - /** - * Executes the command. - * - * @param info The ExecutionInfo for this command - * @throws WrapperCommandSyntaxException if an error occurs during the execution of this command - */ - void run(ExecutionInfo info) throws WrapperCommandSyntaxException; - - /** - * Returns the type of the sender of the current executor. - * - * @return the type of the sender of the current executor - */ - @Override - default ExecutorType getType() { - return ExecutorType.REMOTE; - } -} diff --git a/commandapi-platforms/commandapi-bukkit/commandapi-bukkit-core/src/main/java/dev/jorel/commandapi/executors/RemoteConsoleResultingCommandExecutor.java b/commandapi-platforms/commandapi-bukkit/commandapi-bukkit-core/src/main/java/dev/jorel/commandapi/executors/RemoteConsoleResultingCommandExecutor.java deleted file mode 100644 index 6c1f1b1cb8..0000000000 --- a/commandapi-platforms/commandapi-bukkit/commandapi-bukkit-core/src/main/java/dev/jorel/commandapi/executors/RemoteConsoleResultingCommandExecutor.java +++ /dev/null @@ -1,40 +0,0 @@ -package dev.jorel.commandapi.executors; - -import dev.jorel.commandapi.commandsenders.BukkitRemoteConsoleCommandSender; -import dev.jorel.commandapi.exceptions.WrapperCommandSyntaxException; -import org.bukkit.command.RemoteConsoleCommandSender; - -@FunctionalInterface -public interface RemoteConsoleResultingCommandExecutor extends ResultingExecutor { - - /** - * The code to run when this command is performed - * - * @param sender The sender of this command (a player, the console etc.) - * @param args The arguments given to this command. - * @return the result of this command - */ - int run(RemoteConsoleCommandSender sender, CommandArguments args) throws WrapperCommandSyntaxException; - - /** - * Executes the command. - * - * @param info The ExecutionInfo for this command - * @return the value returned by this command - * @throws WrapperCommandSyntaxException if an error occurs during the execution of this command - */ - @Override - default int run(ExecutionInfo info) throws WrapperCommandSyntaxException { - return this.run(info.sender(), info.args()); - } - - /** - * Returns the type of the sender of the current executor. - * - * @return the type of the sender of the current executor - */ - @Override - default ExecutorType getType() { - return ExecutorType.REMOTE; - } -} diff --git a/commandapi-platforms/commandapi-bukkit/commandapi-bukkit-core/src/main/java/dev/jorel/commandapi/executors/RemoteConsoleResultingExecutionInfo.java b/commandapi-platforms/commandapi-bukkit/commandapi-bukkit-core/src/main/java/dev/jorel/commandapi/executors/RemoteConsoleResultingExecutionInfo.java deleted file mode 100644 index e0bade3ec3..0000000000 --- a/commandapi-platforms/commandapi-bukkit/commandapi-bukkit-core/src/main/java/dev/jorel/commandapi/executors/RemoteConsoleResultingExecutionInfo.java +++ /dev/null @@ -1,28 +0,0 @@ -package dev.jorel.commandapi.executors; - -import dev.jorel.commandapi.commandsenders.BukkitRemoteConsoleCommandSender; -import dev.jorel.commandapi.exceptions.WrapperCommandSyntaxException; -import org.bukkit.command.RemoteConsoleCommandSender; - -@FunctionalInterface -public interface RemoteConsoleResultingExecutionInfo extends ResultingExecutor { - - /** - * Executes the command. - * - * @param info The ExecutionInfo for this command - * @return the value returned by this command - * @throws WrapperCommandSyntaxException if an error occurs during the execution of this command - */ - int run(ExecutionInfo info) throws WrapperCommandSyntaxException; - - /** - * Returns the type of the sender of the current executor. - * - * @return the type of the sender of the current executor - */ - @Override - default ExecutorType getType() { - return ExecutorType.REMOTE; - } -} diff --git a/commandapi-platforms/commandapi-bukkit/commandapi-bukkit-core/src/main/java/dev/jorel/commandapi/executors/ResultingCommandExecutionInfo.java b/commandapi-platforms/commandapi-bukkit/commandapi-bukkit-core/src/main/java/dev/jorel/commandapi/executors/ResultingCommandExecutionInfo.java deleted file mode 100644 index 444448fd0b..0000000000 --- a/commandapi-platforms/commandapi-bukkit/commandapi-bukkit-core/src/main/java/dev/jorel/commandapi/executors/ResultingCommandExecutionInfo.java +++ /dev/null @@ -1,27 +0,0 @@ -package dev.jorel.commandapi.executors; - -import dev.jorel.commandapi.commandsenders.BukkitCommandSender; -import dev.jorel.commandapi.exceptions.WrapperCommandSyntaxException; -import org.bukkit.command.CommandSender; - -@FunctionalInterface -public interface ResultingCommandExecutionInfo extends ResultingExecutor> { - - /** - * The code to run when this command is performed - * - * @param info The ExecutionInfo for this command - * @return the result of this command - * @throws WrapperCommandSyntaxException - */ - int run(ExecutionInfo> info) throws WrapperCommandSyntaxException; - - /** - * Returns the type of the sender of the current executor. - * @return the type of the sender of the current executor - */ - @Override - default ExecutorType getType() { - return ExecutorType.ALL; - } -} diff --git a/commandapi-platforms/commandapi-bukkit/commandapi-bukkit-core/src/main/java/dev/jorel/commandapi/executors/ResultingCommandExecutor.java b/commandapi-platforms/commandapi-bukkit/commandapi-bukkit-core/src/main/java/dev/jorel/commandapi/executors/ResultingCommandExecutor.java deleted file mode 100644 index 8641dc40be..0000000000 --- a/commandapi-platforms/commandapi-bukkit/commandapi-bukkit-core/src/main/java/dev/jorel/commandapi/executors/ResultingCommandExecutor.java +++ /dev/null @@ -1,63 +0,0 @@ -/******************************************************************************* - * Copyright 2018, 2020 Jorel Ali (Skepter) - MIT License - * - * Permission is hereby granted, free of charge, to any person obtaining a copy of - * this software and associated documentation files (the "Software"), to deal in - * the Software without restriction, including without limitation the rights to - * use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of - * the Software, and to permit persons to whom the Software is furnished to do so, - * subject to the following conditions: - * - * The above copyright notice and this permission notice shall be included in all - * copies or substantial portions of the Software. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR - * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS - * FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR - * COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER - * IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN - * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. - *******************************************************************************/ -package dev.jorel.commandapi.executors; - -import org.bukkit.command.CommandSender; - -import dev.jorel.commandapi.commandsenders.BukkitCommandSender; -import dev.jorel.commandapi.exceptions.WrapperCommandSyntaxException; - -/** - * A resulting command executor for a CommandSender - */ -@FunctionalInterface -public interface ResultingCommandExecutor extends ResultingExecutor> { - - /** - * The code to run when this command is performed - * - * @param sender The sender of this command (a player, the console etc.) - * @param args The arguments given to this command. - * @return the result of this command - */ - int run(CommandSender sender, CommandArguments args) throws WrapperCommandSyntaxException; - - /** - * The code to run when this command is performed - * - * @param info The ExecutionInfo for this command - * @return the result of this command - * @throws WrapperCommandSyntaxException - */ - @Override - default int run(ExecutionInfo> info) throws WrapperCommandSyntaxException { - return this.run(info.sender(), info.args()); - } - - /** - * Returns the type of the sender of the current executor. - * @return the type of the sender of the current executor - */ - @Override - default ExecutorType getType() { - return ExecutorType.ALL; - } -} diff --git a/commandapi-platforms/commandapi-bukkit/commandapi-bukkit-core/src/main/java/dev/jorel/commandapi/nms/NMS.java b/commandapi-platforms/commandapi-bukkit/commandapi-bukkit-core/src/main/java/dev/jorel/commandapi/nms/NMS.java index 002927d26a..b0bb9e6ec0 100644 --- a/commandapi-platforms/commandapi-bukkit/commandapi-bukkit-core/src/main/java/dev/jorel/commandapi/nms/NMS.java +++ b/commandapi-platforms/commandapi-bukkit/commandapi-bukkit-core/src/main/java/dev/jorel/commandapi/nms/NMS.java @@ -64,6 +64,7 @@ import dev.jorel.commandapi.wrappers.IntegerRange; import dev.jorel.commandapi.wrappers.Location2D; import dev.jorel.commandapi.wrappers.MathOperation; +import dev.jorel.commandapi.wrappers.NativeProxyCommandSender; import dev.jorel.commandapi.wrappers.ParticleData; import dev.jorel.commandapi.wrappers.Rotation; import dev.jorel.commandapi.wrappers.ScoreboardSlot; @@ -393,6 +394,8 @@ String getScoreHolderSingle(CommandContext cmdCtx, Strin Object getSound(CommandContext cmdCtx, String key, ArgumentSubType subType); + public abstract NativeProxyCommandSender getNativeProxyCommandSender(CommandContext cmdCtx); + /** * Retrieve a specific NMS implemented SuggestionProvider * diff --git a/commandapi-platforms/commandapi-bukkit/commandapi-bukkit-core/src/main/java/dev/jorel/commandapi/wrappers/Preview.java b/commandapi-platforms/commandapi-bukkit/commandapi-bukkit-core/src/main/java/dev/jorel/commandapi/wrappers/Preview.java deleted file mode 100644 index 63822e6ccc..0000000000 --- a/commandapi-platforms/commandapi-bukkit/commandapi-bukkit-core/src/main/java/dev/jorel/commandapi/wrappers/Preview.java +++ /dev/null @@ -1,7 +0,0 @@ -package dev.jorel.commandapi.wrappers; - -import net.kyori.adventure.text.Component; - -@FunctionalInterface -public interface Preview extends PreviewableFunction { -} diff --git a/commandapi-platforms/commandapi-bukkit/commandapi-bukkit-core/src/main/java/dev/jorel/commandapi/wrappers/PreviewLegacy.java b/commandapi-platforms/commandapi-bukkit/commandapi-bukkit-core/src/main/java/dev/jorel/commandapi/wrappers/PreviewLegacy.java deleted file mode 100644 index ccdaf127f2..0000000000 --- a/commandapi-platforms/commandapi-bukkit/commandapi-bukkit-core/src/main/java/dev/jorel/commandapi/wrappers/PreviewLegacy.java +++ /dev/null @@ -1,7 +0,0 @@ -package dev.jorel.commandapi.wrappers; - -import net.md_5.bungee.api.chat.BaseComponent; - -@FunctionalInterface -public interface PreviewLegacy extends PreviewableFunction { -} diff --git a/commandapi-platforms/commandapi-bukkit/commandapi-bukkit-core/src/main/java/dev/jorel/commandapi/wrappers/SimpleFunctionWrapper.java b/commandapi-platforms/commandapi-bukkit/commandapi-bukkit-core/src/main/java/dev/jorel/commandapi/wrappers/SimpleFunctionWrapper.java index 1d3398e934..804f2ede08 100644 --- a/commandapi-platforms/commandapi-bukkit/commandapi-bukkit-core/src/main/java/dev/jorel/commandapi/wrappers/SimpleFunctionWrapper.java +++ b/commandapi-platforms/commandapi-bukkit/commandapi-bukkit-core/src/main/java/dev/jorel/commandapi/wrappers/SimpleFunctionWrapper.java @@ -98,7 +98,7 @@ public static Set getTags() { */ public int run(CommandSender sender) { CommandAPIBukkit platform = CommandAPIBukkit.get(); - return runInternal(platform.getBrigadierSourceFromCommandSender(platform.wrapCommandSender(sender))); + return runInternal(platform.getBrigadierSourceFromCommandSender(sender)); } /** diff --git a/commandapi-platforms/commandapi-bukkit/commandapi-bukkit-nms/commandapi-bukkit-1.16.5/src/main/java/dev/jorel/commandapi/nms/NMS_1_16_R3.java b/commandapi-platforms/commandapi-bukkit/commandapi-bukkit-nms/commandapi-bukkit-1.16.5/src/main/java/dev/jorel/commandapi/nms/NMS_1_16_R3.java index 4064ec960a..a09ba4df15 100644 --- a/commandapi-platforms/commandapi-bukkit/commandapi-bukkit-nms/commandapi-bukkit-1.16.5/src/main/java/dev/jorel/commandapi/nms/NMS_1_16_R3.java +++ b/commandapi-platforms/commandapi-bukkit/commandapi-bukkit-nms/commandapi-bukkit-1.16.5/src/main/java/dev/jorel/commandapi/nms/NMS_1_16_R3.java @@ -98,9 +98,6 @@ import dev.jorel.commandapi.SpigotCommandRegistration; import dev.jorel.commandapi.arguments.ArgumentSubType; import dev.jorel.commandapi.arguments.SuggestionProviders; -import dev.jorel.commandapi.commandsenders.AbstractCommandSender; -import dev.jorel.commandapi.commandsenders.BukkitCommandSender; -import dev.jorel.commandapi.commandsenders.BukkitNativeProxyCommandSender; import dev.jorel.commandapi.preprocessor.Differs; import dev.jorel.commandapi.preprocessor.NMSMeta; import dev.jorel.commandapi.preprocessor.RequireField; @@ -499,14 +496,18 @@ public BaseComponent[] getChatComponent(CommandContext c } @Override - public CommandListenerWrapper getBrigadierSourceFromCommandSender(AbstractCommandSender senderWrapper) { - return VanillaCommandWrapper.getListener(senderWrapper.getSource()); + public CommandListenerWrapper getBrigadierSourceFromCommandSender(CommandSender sender) { + return VanillaCommandWrapper.getListener(sender); } @Override - public BukkitCommandSender getCommandSenderFromCommandSource(CommandListenerWrapper clw) { + public CommandSender getCommandSenderFromCommandSource(CommandListenerWrapper clw) { try { - return wrapCommandSender(clw.getBukkitSender()); + CommandSender sender = clw.getBukkitSender(); + // Sender CANNOT be null. This can occur when using a remote console + // sender. You can access it directly using this.getMinecraftServer().remoteConsole + // however this may also be null, so delegate to the next most-meaningful sender. + return sender == null ? Bukkit.getConsoleSender() : sender; } catch (UnsupportedOperationException e) { return null; } @@ -810,31 +811,23 @@ public String getScoreHolderSingle(CommandContext cmdCtx } @Override - public BukkitCommandSender getSenderForCommand(CommandContext cmdCtx, boolean isNative) { + public NativeProxyCommandSender getNativeProxyCommandSender(CommandContext cmdCtx) { CommandListenerWrapper clw = cmdCtx.getSource(); - CommandSender sender = clw.getBukkitSender(); - if (sender == null) { - // Sender CANNOT be null. This can occur when using a remote console - // sender. You can access it directly using this.getMinecraftServer().remoteConsole - // however this may also be null, so delegate to the next most-meaningful sender. - sender = Bukkit.getConsoleSender(); - } + // Get original sender + CommandSender sender = getCommandSenderFromCommandSource(clw); + + // Get position Vec3D pos = clw.getPosition(); Vec2F rot = clw.i(); World world = getWorldForCSS(clw); Location location = new Location(world, pos.getX(), pos.getY(), pos.getZ(), rot.j, rot.i); + // Get proxy sender (default to sender if null) Entity proxyEntity = clw.getEntity(); - CommandSender proxy = proxyEntity == null ? null : proxyEntity.getBukkitEntity(); - if (isNative || (proxy != null && !sender.equals(proxy))) { - if (proxy == null) { - proxy = sender; - } - return new BukkitNativeProxyCommandSender(new NativeProxyCommandSender(sender, proxy, location, world)); - } else { - return wrapCommandSender(sender); - } + CommandSender proxy = proxyEntity == null ? sender : proxyEntity.getBukkitEntity(); + + return new NativeProxyCommandSender(sender, proxy, location, world); } @Override diff --git a/commandapi-platforms/commandapi-bukkit/commandapi-bukkit-nms/commandapi-bukkit-1.17-common/src/main/java/dev/jorel/commandapi/nms/NMS_1_17_Common.java b/commandapi-platforms/commandapi-bukkit/commandapi-bukkit-nms/commandapi-bukkit-1.17-common/src/main/java/dev/jorel/commandapi/nms/NMS_1_17_Common.java index dee8b13188..c5d7aa7109 100644 --- a/commandapi-platforms/commandapi-bukkit/commandapi-bukkit-nms/commandapi-bukkit-1.17-common/src/main/java/dev/jorel/commandapi/nms/NMS_1_17_Common.java +++ b/commandapi-platforms/commandapi-bukkit/commandapi-bukkit-nms/commandapi-bukkit-1.17-common/src/main/java/dev/jorel/commandapi/nms/NMS_1_17_Common.java @@ -87,9 +87,6 @@ import dev.jorel.commandapi.arguments.ArgumentSubType; import dev.jorel.commandapi.arguments.SuggestionProviders; -import dev.jorel.commandapi.commandsenders.AbstractCommandSender; -import dev.jorel.commandapi.commandsenders.BukkitCommandSender; -import dev.jorel.commandapi.commandsenders.BukkitNativeProxyCommandSender; import dev.jorel.commandapi.preprocessor.RequireField; import dev.jorel.commandapi.preprocessor.Unimplemented; import net.kyori.adventure.text.Component; @@ -305,8 +302,8 @@ public BlockData getBlockState(CommandContext cmdCtx, String } @Override - public CommandSourceStack getBrigadierSourceFromCommandSender(AbstractCommandSender senderWrapper) { - return VanillaCommandWrapper.getListener(senderWrapper.getSource()); + public CommandSourceStack getBrigadierSourceFromCommandSender(CommandSender sender) { + return VanillaCommandWrapper.getListener(sender); } @Override @@ -587,31 +584,23 @@ public ScoreboardSlot getScoreboardSlot(CommandContext cmdCt } @Override - public BukkitCommandSender getSenderForCommand(CommandContext cmdCtx, boolean isNative) { + public NativeProxyCommandSender getNativeProxyCommandSender(CommandContext cmdCtx) { CommandSourceStack css = cmdCtx.getSource(); - CommandSender sender = css.getBukkitSender(); - if (sender == null) { - // Sender CANNOT be null. This can occur when using a remote console - // sender. You can access it directly using this.getMinecraftServer().remoteConsole - // however this may also be null, so delegate to the next most-meaningful sender. - sender = Bukkit.getConsoleSender(); - } + // Get original sender + CommandSender sender = getCommandSenderFromCommandSource(css); + + // Get position Vec3 pos = css.getPosition(); Vec2 rot = css.getRotation(); World world = getWorldForCSS(css); Location location = new Location(world, pos.x(), pos.y(), pos.z(), rot.y, rot.x); + // Get proxy sender (default to sender if null) Entity proxyEntity = css.getEntity(); - CommandSender proxy = proxyEntity == null ? null : proxyEntity.getBukkitEntity(); - if (isNative || (proxy != null && !sender.equals(proxy))) { - if (proxy == null) { - proxy = sender; - } - return new BukkitNativeProxyCommandSender(new NativeProxyCommandSender(sender, proxy, location, world)); - } else { - return wrapCommandSender(sender); - } + CommandSender proxy = proxyEntity == null ? sender : proxyEntity.getBukkitEntity(); + + return new NativeProxyCommandSender(sender, proxy, location, world); } @Override diff --git a/commandapi-platforms/commandapi-bukkit/commandapi-bukkit-nms/commandapi-bukkit-1.18.2/src/main/java/dev/jorel/commandapi/nms/NMS_1_18_R2.java b/commandapi-platforms/commandapi-bukkit/commandapi-bukkit-nms/commandapi-bukkit-1.18.2/src/main/java/dev/jorel/commandapi/nms/NMS_1_18_R2.java index ee7009f4d1..c7e316b005 100644 --- a/commandapi-platforms/commandapi-bukkit/commandapi-bukkit-nms/commandapi-bukkit-1.18.2/src/main/java/dev/jorel/commandapi/nms/NMS_1_18_R2.java +++ b/commandapi-platforms/commandapi-bukkit/commandapi-bukkit-nms/commandapi-bukkit-1.18.2/src/main/java/dev/jorel/commandapi/nms/NMS_1_18_R2.java @@ -91,9 +91,6 @@ import dev.jorel.commandapi.arguments.ArgumentSubType; import dev.jorel.commandapi.arguments.SuggestionProviders; -import dev.jorel.commandapi.commandsenders.AbstractCommandSender; -import dev.jorel.commandapi.commandsenders.BukkitCommandSender; -import dev.jorel.commandapi.commandsenders.BukkitNativeProxyCommandSender; import dev.jorel.commandapi.preprocessor.Differs; import dev.jorel.commandapi.preprocessor.NMSMeta; import dev.jorel.commandapi.preprocessor.RequireField; @@ -365,8 +362,8 @@ public BlockData getBlockState(CommandContext cmdCtx, String } @Override - public CommandSourceStack getBrigadierSourceFromCommandSender(AbstractCommandSender senderWrapper) { - return VanillaCommandWrapper.getListener(senderWrapper.getSource()); + public CommandSourceStack getBrigadierSourceFromCommandSender(CommandSender sender) { + return VanillaCommandWrapper.getListener(sender); } @Override @@ -637,31 +634,23 @@ public ScoreboardSlot getScoreboardSlot(CommandContext cmdCt } @Override - public BukkitCommandSender getSenderForCommand(CommandContext cmdCtx, boolean isNative) { + public NativeProxyCommandSender getNativeProxyCommandSender(CommandContext cmdCtx) { CommandSourceStack css = cmdCtx.getSource(); - CommandSender sender = css.getBukkitSender(); - if (sender == null) { - // Sender CANNOT be null. This can occur when using a remote console - // sender. You can access it directly using this.getMinecraftServer().remoteConsole - // however this may also be null, so delegate to the next most-meaningful sender. - sender = Bukkit.getConsoleSender(); - } + // Get original sender + CommandSender sender = getCommandSenderFromCommandSource(css); + + // Get position Vec3 pos = css.getPosition(); Vec2 rot = css.getRotation(); World world = getWorldForCSS(css); Location location = new Location(world, pos.x(), pos.y(), pos.z(), rot.y, rot.x); + // Get proxy sender (default to sender if null) Entity proxyEntity = css.getEntity(); - CommandSender proxy = proxyEntity == null ? null : proxyEntity.getBukkitEntity(); - if (isNative || (proxy != null && !sender.equals(proxy))) { - if (proxy == null) { - proxy = sender; - } - return new BukkitNativeProxyCommandSender(new NativeProxyCommandSender(sender, proxy, location, world)); - } else { - return wrapCommandSender(sender); - } + CommandSender proxy = proxyEntity == null ? sender : proxyEntity.getBukkitEntity(); + + return new NativeProxyCommandSender(sender, proxy, location, world); } @Override diff --git a/commandapi-platforms/commandapi-bukkit/commandapi-bukkit-nms/commandapi-bukkit-1.18/src/main/java/dev/jorel/commandapi/nms/NMS_1_18_R1.java b/commandapi-platforms/commandapi-bukkit/commandapi-bukkit-nms/commandapi-bukkit-1.18/src/main/java/dev/jorel/commandapi/nms/NMS_1_18_R1.java index 65a3076256..09bc7395cc 100644 --- a/commandapi-platforms/commandapi-bukkit/commandapi-bukkit-nms/commandapi-bukkit-1.18/src/main/java/dev/jorel/commandapi/nms/NMS_1_18_R1.java +++ b/commandapi-platforms/commandapi-bukkit/commandapi-bukkit-nms/commandapi-bukkit-1.18/src/main/java/dev/jorel/commandapi/nms/NMS_1_18_R1.java @@ -87,9 +87,6 @@ import dev.jorel.commandapi.arguments.ArgumentSubType; import dev.jorel.commandapi.arguments.SuggestionProviders; -import dev.jorel.commandapi.commandsenders.AbstractCommandSender; -import dev.jorel.commandapi.commandsenders.BukkitCommandSender; -import dev.jorel.commandapi.commandsenders.BukkitNativeProxyCommandSender; import dev.jorel.commandapi.preprocessor.Differs; import dev.jorel.commandapi.preprocessor.NMSMeta; import dev.jorel.commandapi.preprocessor.RequireField; @@ -312,8 +309,8 @@ public BlockData getBlockState(CommandContext cmdCtx, String } @Override - public CommandSourceStack getBrigadierSourceFromCommandSender(AbstractCommandSender senderWrapper) { - return VanillaCommandWrapper.getListener(senderWrapper.getSource()); + public CommandSourceStack getBrigadierSourceFromCommandSender(CommandSender sender) { + return VanillaCommandWrapper.getListener(sender); } @Override @@ -587,31 +584,23 @@ public ScoreboardSlot getScoreboardSlot(CommandContext cmdCt } @Override - public BukkitCommandSender getSenderForCommand(CommandContext cmdCtx, boolean isNative) { + public NativeProxyCommandSender getNativeProxyCommandSender(CommandContext cmdCtx) { CommandSourceStack css = cmdCtx.getSource(); - CommandSender sender = css.getBukkitSender(); - if (sender == null) { - // Sender CANNOT be null. This can occur when using a remote console - // sender. You can access it directly using this.getMinecraftServer().remoteConsole - // however this may also be null, so delegate to the next most-meaningful sender. - sender = Bukkit.getConsoleSender(); - } + // Get original sender + CommandSender sender = getCommandSenderFromCommandSource(css); + + // Get position Vec3 pos = css.getPosition(); Vec2 rot = css.getRotation(); World world = getWorldForCSS(css); Location location = new Location(world, pos.x(), pos.y(), pos.z(), rot.y, rot.x); + // Get proxy sender (default to sender if null) Entity proxyEntity = css.getEntity(); - CommandSender proxy = proxyEntity == null ? null : proxyEntity.getBukkitEntity(); - if (isNative || (proxy != null && !sender.equals(proxy))) { - if (proxy == null) { - proxy = sender; - } - return new BukkitNativeProxyCommandSender(new NativeProxyCommandSender(sender, proxy, location, world)); - } else { - return wrapCommandSender(sender); - } + CommandSender proxy = proxyEntity == null ? sender : proxyEntity.getBukkitEntity(); + + return new NativeProxyCommandSender(sender, proxy, location, world); } @Override diff --git a/commandapi-platforms/commandapi-bukkit/commandapi-bukkit-nms/commandapi-bukkit-1.19-common/src/main/java/dev/jorel/commandapi/nms/NMS_1_19_Common.java b/commandapi-platforms/commandapi-bukkit/commandapi-bukkit-nms/commandapi-bukkit-1.19-common/src/main/java/dev/jorel/commandapi/nms/NMS_1_19_Common.java index 0dfb840475..5932a4dd75 100644 --- a/commandapi-platforms/commandapi-bukkit/commandapi-bukkit-nms/commandapi-bukkit-1.19-common/src/main/java/dev/jorel/commandapi/nms/NMS_1_19_Common.java +++ b/commandapi-platforms/commandapi-bukkit/commandapi-bukkit-nms/commandapi-bukkit-1.19-common/src/main/java/dev/jorel/commandapi/nms/NMS_1_19_Common.java @@ -35,9 +35,6 @@ import dev.jorel.commandapi.*; import dev.jorel.commandapi.arguments.ArgumentSubType; import dev.jorel.commandapi.arguments.SuggestionProviders; -import dev.jorel.commandapi.commandsenders.AbstractCommandSender; -import dev.jorel.commandapi.commandsenders.BukkitCommandSender; -import dev.jorel.commandapi.commandsenders.BukkitNativeProxyCommandSender; import dev.jorel.commandapi.preprocessor.Differs; import dev.jorel.commandapi.preprocessor.RequireField; import dev.jorel.commandapi.preprocessor.Unimplemented; @@ -434,8 +431,8 @@ public final BlockData getBlockState(CommandContext cmdCtx, } @Override - public final CommandSourceStack getBrigadierSourceFromCommandSender(AbstractCommandSender senderWrapper) { - return VanillaCommandWrapper.getListener(senderWrapper.getSource()); + public final CommandSourceStack getBrigadierSourceFromCommandSender(CommandSender sender) { + return VanillaCommandWrapper.getListener(sender); } @Override @@ -692,22 +689,23 @@ public ScoreboardSlot getScoreboardSlot(CommandContext cmdCt } @Override - public BukkitCommandSender getSenderForCommand(CommandContext cmdCtx, boolean isNative) { + public NativeProxyCommandSender getNativeProxyCommandSender(CommandContext cmdCtx) { CommandSourceStack css = cmdCtx.getSource(); - CommandSender sender = css.getBukkitSender(); + // Get original sender + CommandSender sender = getCommandSenderFromCommandSource(css); + + // Get position Vec3 pos = css.getPosition(); Vec2 rot = css.getRotation(); World world = getWorldForCSS(css); Location location = new Location(world, pos.x(), pos.y(), pos.z(), rot.y, rot.x); + + // Get proxy sender (default to sender if null) Entity proxyEntity = css.getEntity(); - CommandSender proxy = proxyEntity == null ? null : proxyEntity.getBukkitEntity(); + CommandSender proxy = proxyEntity == null ? sender : proxyEntity.getBukkitEntity(); - if (isNative || (proxy != null && !sender.equals(proxy))) { - return new BukkitNativeProxyCommandSender(new NativeProxyCommandSender(sender, proxy, location, world)); - } else { - return wrapCommandSender(sender); - } + return new NativeProxyCommandSender(sender, proxy, location, world); } @Override diff --git a/commandapi-platforms/commandapi-bukkit/commandapi-bukkit-nms/commandapi-bukkit-1.19-common/src/main/java/dev/jorel/commandapi/nms/NMS_1_19_Common_ChatPreviewHandler.java b/commandapi-platforms/commandapi-bukkit/commandapi-bukkit-nms/commandapi-bukkit-1.19-common/src/main/java/dev/jorel/commandapi/nms/NMS_1_19_Common_ChatPreviewHandler.java index ebbd69b31f..1946a35d10 100644 --- a/commandapi-platforms/commandapi-bukkit/commandapi-bukkit-nms/commandapi-bukkit-1.19-common/src/main/java/dev/jorel/commandapi/nms/NMS_1_19_Common_ChatPreviewHandler.java +++ b/commandapi-platforms/commandapi-bukkit/commandapi-bukkit-nms/commandapi-bukkit-1.19-common/src/main/java/dev/jorel/commandapi/nms/NMS_1_19_Common_ChatPreviewHandler.java @@ -6,7 +6,6 @@ import dev.jorel.commandapi.CommandAPIBukkit; import dev.jorel.commandapi.arguments.PreviewInfo; import dev.jorel.commandapi.commandnodes.PreviewableCommandNode; -import dev.jorel.commandapi.commandsenders.BukkitPlayer; import dev.jorel.commandapi.exceptions.WrapperCommandSyntaxException; import dev.jorel.commandapi.wrappers.PreviewableFunction; import io.netty.channel.ChannelDuplexHandler; @@ -68,7 +67,7 @@ public MutableComponent parseChatPreviewQuery(String chatPreviewQuery) { // Return early if the node is not previewable final PreviewableCommandNode previewableNode = ip.previewableNode; - final Optional> preview = previewableNode.getPreview(); + final Optional> preview = previewableNode.getPreview(); if (preview.isEmpty()) { return null; } @@ -92,7 +91,7 @@ public MutableComponent parseChatPreviewQuery(String chatPreviewQuery) { } catch (CommandSyntaxException e) { throw new WrapperCommandSyntaxException(e); } - previewInfo = new PreviewInfo<>(new BukkitPlayer(player), input, chatPreviewQuery, parsedInput); + previewInfo = new PreviewInfo<>(player, input, chatPreviewQuery, parsedInput); } else { Component parsedInput; try { @@ -100,7 +99,7 @@ public MutableComponent parseChatPreviewQuery(String chatPreviewQuery) { } catch (CommandSyntaxException e) { throw new WrapperCommandSyntaxException(e); } - previewInfo = new PreviewInfo<>(new BukkitPlayer(player), input, chatPreviewQuery, parsedInput); + previewInfo = new PreviewInfo<>(player, input, chatPreviewQuery, parsedInput); } component = preview.get().generatePreview(previewInfo); @@ -136,7 +135,7 @@ public static InitialParse processChatPreviewQuery(String chatPreviewQuery, Comm if(cachedResult != null && cachedResult.fullInput.equals(fullInput)) return cachedResult; ParseResults results = platform.getBrigadierDispatcher() - .parse(fullInput, platform.getBrigadierSourceFromCommandSender(new BukkitPlayer(player))); + .parse(fullInput, platform.getBrigadierSourceFromCommandSender(player)); // Get the last node List> nodes = results.getContext().getNodes(); diff --git a/commandapi-platforms/commandapi-bukkit/commandapi-bukkit-nms/commandapi-bukkit-1.19.3/src/main/java/dev/jorel/commandapi/nms/NMS_1_19_3_R2.java b/commandapi-platforms/commandapi-bukkit/commandapi-bukkit-nms/commandapi-bukkit-1.19.3/src/main/java/dev/jorel/commandapi/nms/NMS_1_19_3_R2.java index d77e7f6e3f..f649ed71c2 100644 --- a/commandapi-platforms/commandapi-bukkit/commandapi-bukkit-nms/commandapi-bukkit-1.19.3/src/main/java/dev/jorel/commandapi/nms/NMS_1_19_3_R2.java +++ b/commandapi-platforms/commandapi-bukkit/commandapi-bukkit-nms/commandapi-bukkit-1.19.3/src/main/java/dev/jorel/commandapi/nms/NMS_1_19_3_R2.java @@ -34,9 +34,6 @@ import dev.jorel.commandapi.*; import dev.jorel.commandapi.arguments.ArgumentSubType; import dev.jorel.commandapi.arguments.SuggestionProviders; -import dev.jorel.commandapi.commandsenders.AbstractCommandSender; -import dev.jorel.commandapi.commandsenders.BukkitCommandSender; -import dev.jorel.commandapi.commandsenders.BukkitNativeProxyCommandSender; import dev.jorel.commandapi.preprocessor.Differs; import dev.jorel.commandapi.preprocessor.NMSMeta; import dev.jorel.commandapi.preprocessor.RequireField; @@ -309,8 +306,8 @@ public final BlockData getBlockState(CommandContext cmdCtx, } @Override - public CommandSourceStack getBrigadierSourceFromCommandSender(AbstractCommandSender sender) { - return VanillaCommandWrapper.getListener(sender.getSource()); + public CommandSourceStack getBrigadierSourceFromCommandSender(CommandSender sender) { + return VanillaCommandWrapper.getListener(sender); } @Override @@ -571,31 +568,23 @@ public ScoreboardSlot getScoreboardSlot(CommandContext cmdCt } @Override - public BukkitCommandSender getSenderForCommand(CommandContext cmdCtx, boolean isNative) { + public NativeProxyCommandSender getNativeProxyCommandSender(CommandContext cmdCtx) { CommandSourceStack css = cmdCtx.getSource(); - CommandSender sender = css.getBukkitSender(); - if (sender == null) { - // Sender CANNOT be null. This can occur when using a remote console - // sender. You can access it directly using this.getMinecraftServer().remoteConsole - // however this may also be null, so delegate to the next most-meaningful sender. - sender = Bukkit.getConsoleSender(); - } + // Get original sender + CommandSender sender = getCommandSenderFromCommandSource(css); + + // Get position Vec3 pos = css.getPosition(); Vec2 rot = css.getRotation(); World world = getWorldForCSS(css); Location location = new Location(world, pos.x(), pos.y(), pos.z(), rot.y, rot.x); + // Get proxy sender (default to sender if null) Entity proxyEntity = css.getEntity(); - CommandSender proxy = proxyEntity == null ? null : proxyEntity.getBukkitEntity(); - if (isNative || (proxy != null && !sender.equals(proxy))) { - if (proxy == null) { - proxy = sender; - } - return new BukkitNativeProxyCommandSender(new NativeProxyCommandSender(sender, proxy, location, world)); - } else { - return wrapCommandSender(sender); - } + CommandSender proxy = proxyEntity == null ? sender : proxyEntity.getBukkitEntity(); + + return new NativeProxyCommandSender(sender, proxy, location, world); } @Override diff --git a/commandapi-platforms/commandapi-bukkit/commandapi-bukkit-nms/commandapi-bukkit-1.19.4/src/main/java/dev/jorel/commandapi/nms/NMS_1_19_4_R3.java b/commandapi-platforms/commandapi-bukkit/commandapi-bukkit-nms/commandapi-bukkit-1.19.4/src/main/java/dev/jorel/commandapi/nms/NMS_1_19_4_R3.java index 4febcec271..025b2ac88d 100644 --- a/commandapi-platforms/commandapi-bukkit/commandapi-bukkit-nms/commandapi-bukkit-1.19.4/src/main/java/dev/jorel/commandapi/nms/NMS_1_19_4_R3.java +++ b/commandapi-platforms/commandapi-bukkit/commandapi-bukkit-nms/commandapi-bukkit-1.19.4/src/main/java/dev/jorel/commandapi/nms/NMS_1_19_4_R3.java @@ -34,9 +34,6 @@ import dev.jorel.commandapi.*; import dev.jorel.commandapi.arguments.ArgumentSubType; import dev.jorel.commandapi.arguments.SuggestionProviders; -import dev.jorel.commandapi.commandsenders.AbstractCommandSender; -import dev.jorel.commandapi.commandsenders.BukkitCommandSender; -import dev.jorel.commandapi.commandsenders.BukkitNativeProxyCommandSender; import dev.jorel.commandapi.preprocessor.Differs; import dev.jorel.commandapi.preprocessor.NMSMeta; import dev.jorel.commandapi.preprocessor.RequireField; @@ -307,8 +304,8 @@ public final BlockData getBlockState(CommandContext cmdCtx, } @Override - public CommandSourceStack getBrigadierSourceFromCommandSender(AbstractCommandSender sender) { - return VanillaCommandWrapper.getListener(sender.getSource()); + public CommandSourceStack getBrigadierSourceFromCommandSender(CommandSender sender) { + return VanillaCommandWrapper.getListener(sender); } @Override @@ -565,32 +562,23 @@ public ScoreboardSlot getScoreboardSlot(CommandContext cmdCt } @Override - public BukkitCommandSender getSenderForCommand(CommandContext cmdCtx, boolean isNative) { + public NativeProxyCommandSender getNativeProxyCommandSender(CommandContext cmdCtx) { CommandSourceStack css = cmdCtx.getSource(); - CommandSender sender = css.getBukkitSender(); - if (sender == null) { - // Sender CANNOT be null. This can occur when using a remote console - // sender. You can access it directly using this.getMinecraftServer().remoteConsole - // however this may also be null, so delegate to the next most-meaningful sender. - sender = Bukkit.getConsoleSender(); - } + // Get original sender + CommandSender sender = getCommandSenderFromCommandSource(css); + + // Get position Vec3 pos = css.getPosition(); Vec2 rot = css.getRotation(); World world = getWorldForCSS(css); Location location = new Location(world, pos.x(), pos.y(), pos.z(), rot.y, rot.x); + // Get proxy sender (default to sender if null) Entity proxyEntity = css.getEntity(); - CommandSender proxy = proxyEntity == null ? null : proxyEntity.getBukkitEntity(); - if (isNative || (proxy != null && !sender.equals(proxy))) { - if (proxy == null) { - proxy = sender; - } - - return new BukkitNativeProxyCommandSender(new NativeProxyCommandSender(sender, proxy, location, world)); - } else { - return wrapCommandSender(sender); - } + CommandSender proxy = proxyEntity == null ? sender : proxyEntity.getBukkitEntity(); + + return new NativeProxyCommandSender(sender, proxy, location, world); } @Override diff --git a/commandapi-platforms/commandapi-bukkit/commandapi-bukkit-nms/commandapi-bukkit-1.20.2/src/main/java/dev/jorel/commandapi/nms/NMS_1_20_R2.java b/commandapi-platforms/commandapi-bukkit/commandapi-bukkit-nms/commandapi-bukkit-1.20.2/src/main/java/dev/jorel/commandapi/nms/NMS_1_20_R2.java index 92b7781637..bc8bf29521 100644 --- a/commandapi-platforms/commandapi-bukkit/commandapi-bukkit-nms/commandapi-bukkit-1.20.2/src/main/java/dev/jorel/commandapi/nms/NMS_1_20_R2.java +++ b/commandapi-platforms/commandapi-bukkit/commandapi-bukkit-nms/commandapi-bukkit-1.20.2/src/main/java/dev/jorel/commandapi/nms/NMS_1_20_R2.java @@ -89,9 +89,6 @@ import dev.jorel.commandapi.arguments.ArgumentSubType; import dev.jorel.commandapi.arguments.SuggestionProviders; -import dev.jorel.commandapi.commandsenders.AbstractCommandSender; -import dev.jorel.commandapi.commandsenders.BukkitCommandSender; -import dev.jorel.commandapi.commandsenders.BukkitNativeProxyCommandSender; import dev.jorel.commandapi.preprocessor.Differs; import dev.jorel.commandapi.preprocessor.NMSMeta; import dev.jorel.commandapi.preprocessor.RequireField; @@ -329,8 +326,8 @@ public final BlockData getBlockState(CommandContext cmdCtx, } @Override - public CommandSourceStack getBrigadierSourceFromCommandSender(AbstractCommandSender sender) { - return VanillaCommandWrapper.getListener(sender.getSource()); + public CommandSourceStack getBrigadierSourceFromCommandSender(CommandSender sender) { + return VanillaCommandWrapper.getListener(sender); } @Override @@ -585,32 +582,23 @@ public ScoreboardSlot getScoreboardSlot(CommandContext cmdCt } @Override - public BukkitCommandSender getSenderForCommand(CommandContext cmdCtx, boolean isNative) { + public NativeProxyCommandSender getNativeProxyCommandSender(CommandContext cmdCtx) { CommandSourceStack css = cmdCtx.getSource(); - CommandSender sender = css.getBukkitSender(); - if (sender == null) { - // Sender CANNOT be null. This can occur when using a remote console - // sender. You can access it directly using this.getMinecraftServer().remoteConsole - // however this may also be null, so delegate to the next most-meaningful sender. - sender = Bukkit.getConsoleSender(); - } + // Get original sender + CommandSender sender = getCommandSenderFromCommandSource(css); + + // Get position Vec3 pos = css.getPosition(); Vec2 rot = css.getRotation(); World world = getWorldForCSS(css); Location location = new Location(world, pos.x(), pos.y(), pos.z(), rot.y, rot.x); + // Get proxy sender (default to sender if null) Entity proxyEntity = css.getEntity(); - CommandSender proxy = proxyEntity == null ? null : proxyEntity.getBukkitEntity(); - if (isNative || (proxy != null && !sender.equals(proxy))) { - if (proxy == null) { - proxy = sender; - } - - return new BukkitNativeProxyCommandSender(new NativeProxyCommandSender(sender, proxy, location, world)); - } else { - return wrapCommandSender(sender); - } + CommandSender proxy = proxyEntity == null ? sender : proxyEntity.getBukkitEntity(); + + return new NativeProxyCommandSender(sender, proxy, location, world); } @Override diff --git a/commandapi-platforms/commandapi-bukkit/commandapi-bukkit-nms/commandapi-bukkit-1.20.3/src/main/java/dev/jorel/commandapi/nms/NMS_1_20_R3.java b/commandapi-platforms/commandapi-bukkit/commandapi-bukkit-nms/commandapi-bukkit-1.20.3/src/main/java/dev/jorel/commandapi/nms/NMS_1_20_R3.java index cc46076b05..c001defd08 100644 --- a/commandapi-platforms/commandapi-bukkit/commandapi-bukkit-nms/commandapi-bukkit-1.20.3/src/main/java/dev/jorel/commandapi/nms/NMS_1_20_R3.java +++ b/commandapi-platforms/commandapi-bukkit/commandapi-bukkit-nms/commandapi-bukkit-1.20.3/src/main/java/dev/jorel/commandapi/nms/NMS_1_20_R3.java @@ -89,9 +89,6 @@ import dev.jorel.commandapi.arguments.ArgumentSubType; import dev.jorel.commandapi.arguments.SuggestionProviders; -import dev.jorel.commandapi.commandsenders.AbstractCommandSender; -import dev.jorel.commandapi.commandsenders.BukkitCommandSender; -import dev.jorel.commandapi.commandsenders.BukkitNativeProxyCommandSender; import dev.jorel.commandapi.preprocessor.Differs; import dev.jorel.commandapi.preprocessor.NMSMeta; import dev.jorel.commandapi.preprocessor.RequireField; @@ -403,9 +400,8 @@ public final BlockData getBlockState(CommandContext cmdCtx, } @Override - public CommandSourceStack getBrigadierSourceFromCommandSender( - AbstractCommandSender sender) { - return VanillaCommandWrapper.getListener(sender.getSource()); + public CommandSourceStack getBrigadierSourceFromCommandSender(CommandSender sender) { + return VanillaCommandWrapper.getListener(sender); } @Override @@ -712,35 +708,23 @@ public String getScoreHolderSingle(CommandContext cmdCtx, St } @Override - public BukkitCommandSender getSenderForCommand(CommandContext cmdCtx, - boolean isNative) { + public NativeProxyCommandSender getNativeProxyCommandSender(CommandContext cmdCtx) { CommandSourceStack css = cmdCtx.getSource(); - CommandSender sender = css.getBukkitSender(); - if (sender == null) { - // Sender CANNOT be null. This can occur when using a remote console - // sender. You can access it directly using - // this.getMinecraftServer().remoteConsole - // however this may also be null, so delegate to the next most-meaningful - // sender. - sender = Bukkit.getConsoleSender(); - } + // Get original sender + CommandSender sender = getCommandSenderFromCommandSource(css); + + // Get position Vec3 pos = css.getPosition(); Vec2 rot = css.getRotation(); World world = getWorldForCSS(css); Location location = new Location(world, pos.x(), pos.y(), pos.z(), rot.y, rot.x); + // Get proxy sender (default to sender if null) Entity proxyEntity = css.getEntity(); - CommandSender proxy = proxyEntity == null ? null : proxyEntity.getBukkitEntity(); - if (isNative || (proxy != null && !sender.equals(proxy))) { - if (proxy == null) { - proxy = sender; - } + CommandSender proxy = proxyEntity == null ? sender : proxyEntity.getBukkitEntity(); - return new BukkitNativeProxyCommandSender(new NativeProxyCommandSender(sender, proxy, location, world)); - } else { - return wrapCommandSender(sender); - } + return new NativeProxyCommandSender(sender, proxy, location, world); } @Override diff --git a/commandapi-platforms/commandapi-bukkit/commandapi-bukkit-nms/commandapi-bukkit-1.20.5/src/main/java/dev/jorel/commandapi/nms/NMS_1_20_R4.java b/commandapi-platforms/commandapi-bukkit/commandapi-bukkit-nms/commandapi-bukkit-1.20.5/src/main/java/dev/jorel/commandapi/nms/NMS_1_20_R4.java index b8fcb01598..74ae982cc7 100644 --- a/commandapi-platforms/commandapi-bukkit/commandapi-bukkit-nms/commandapi-bukkit-1.20.5/src/main/java/dev/jorel/commandapi/nms/NMS_1_20_R4.java +++ b/commandapi-platforms/commandapi-bukkit/commandapi-bukkit-nms/commandapi-bukkit-1.20.5/src/main/java/dev/jorel/commandapi/nms/NMS_1_20_R4.java @@ -91,9 +91,6 @@ import dev.jorel.commandapi.arguments.ArgumentSubType; import dev.jorel.commandapi.arguments.SuggestionProviders; -import dev.jorel.commandapi.commandsenders.AbstractCommandSender; -import dev.jorel.commandapi.commandsenders.BukkitCommandSender; -import dev.jorel.commandapi.commandsenders.BukkitNativeProxyCommandSender; import dev.jorel.commandapi.preprocessor.Differs; import dev.jorel.commandapi.preprocessor.NMSMeta; import dev.jorel.commandapi.preprocessor.RequireField; @@ -452,9 +449,8 @@ public final BlockData getBlockState(CommandContext cmdCtx, } @Override - public CommandSourceStack getBrigadierSourceFromCommandSender( - AbstractCommandSender sender) { - return VanillaCommandWrapper.getListener(sender.getSource()); + public CommandSourceStack getBrigadierSourceFromCommandSender(CommandSender sender) { + return VanillaCommandWrapper.getListener(sender); } @Differs(from = "1.20.4", by = "Serializer.toJson now needs a Provider") @@ -784,35 +780,23 @@ public String getScoreHolderSingle(CommandContext cmdCtx, St } @Override - public BukkitCommandSender getSenderForCommand(CommandContext cmdCtx, - boolean isNative) { + public NativeProxyCommandSender getNativeProxyCommandSender(CommandContext cmdCtx) { CommandSourceStack css = cmdCtx.getSource(); - CommandSender sender = css.getBukkitSender(); - if (sender == null) { - // Sender CANNOT be null. This can occur when using a remote console - // sender. You can access it directly using - // this.getMinecraftServer().remoteConsole - // however this may also be null, so delegate to the next most-meaningful - // sender. - sender = Bukkit.getConsoleSender(); - } + // Get original sender + CommandSender sender = getCommandSenderFromCommandSource(css); + + // Get position Vec3 pos = css.getPosition(); Vec2 rot = css.getRotation(); World world = getWorldForCSS(css); Location location = new Location(world, pos.x(), pos.y(), pos.z(), rot.y, rot.x); + // Get proxy sender (default to sender if null) Entity proxyEntity = css.getEntity(); - CommandSender proxy = proxyEntity == null ? null : proxyEntity.getBukkitEntity(); - if (isNative || (proxy != null && !sender.equals(proxy))) { - if (proxy == null) { - proxy = sender; - } + CommandSender proxy = proxyEntity == null ? sender : proxyEntity.getBukkitEntity(); - return new BukkitNativeProxyCommandSender(new NativeProxyCommandSender(sender, proxy, location, world)); - } else { - return wrapCommandSender(sender); - } + return new NativeProxyCommandSender(sender, proxy, location, world); } @Override diff --git a/commandapi-platforms/commandapi-bukkit/commandapi-bukkit-nms/commandapi-bukkit-1.20/src/main/java/dev/jorel/commandapi/nms/NMS_1_20_R1.java b/commandapi-platforms/commandapi-bukkit/commandapi-bukkit-nms/commandapi-bukkit-1.20/src/main/java/dev/jorel/commandapi/nms/NMS_1_20_R1.java index d15570524a..dd6d9e3a5f 100644 --- a/commandapi-platforms/commandapi-bukkit/commandapi-bukkit-nms/commandapi-bukkit-1.20/src/main/java/dev/jorel/commandapi/nms/NMS_1_20_R1.java +++ b/commandapi-platforms/commandapi-bukkit/commandapi-bukkit-nms/commandapi-bukkit-1.20/src/main/java/dev/jorel/commandapi/nms/NMS_1_20_R1.java @@ -34,9 +34,6 @@ import dev.jorel.commandapi.*; import dev.jorel.commandapi.arguments.ArgumentSubType; import dev.jorel.commandapi.arguments.SuggestionProviders; -import dev.jorel.commandapi.commandsenders.AbstractCommandSender; -import dev.jorel.commandapi.commandsenders.BukkitCommandSender; -import dev.jorel.commandapi.commandsenders.BukkitNativeProxyCommandSender; import dev.jorel.commandapi.preprocessor.Differs; import dev.jorel.commandapi.preprocessor.NMSMeta; import dev.jorel.commandapi.preprocessor.RequireField; @@ -306,8 +303,8 @@ public final BlockData getBlockState(CommandContext cmdCtx, } @Override - public CommandSourceStack getBrigadierSourceFromCommandSender(AbstractCommandSender sender) { - return VanillaCommandWrapper.getListener(sender.getSource()); + public CommandSourceStack getBrigadierSourceFromCommandSender(CommandSender sender) { + return VanillaCommandWrapper.getListener(sender); } @Override @@ -565,32 +562,23 @@ public ScoreboardSlot getScoreboardSlot(CommandContext cmdCt } @Override - public BukkitCommandSender getSenderForCommand(CommandContext cmdCtx, boolean isNative) { + public NativeProxyCommandSender getNativeProxyCommandSender(CommandContext cmdCtx) { CommandSourceStack css = cmdCtx.getSource(); - CommandSender sender = css.getBukkitSender(); - if (sender == null) { - // Sender CANNOT be null. This can occur when using a remote console - // sender. You can access it directly using this.getMinecraftServer().remoteConsole - // however this may also be null, so delegate to the next most-meaningful sender. - sender = Bukkit.getConsoleSender(); - } + // Get original sender + CommandSender sender = getCommandSenderFromCommandSource(css); + + // Get position Vec3 pos = css.getPosition(); Vec2 rot = css.getRotation(); World world = getWorldForCSS(css); Location location = new Location(world, pos.x(), pos.y(), pos.z(), rot.y, rot.x); + // Get proxy sender (default to sender if null) Entity proxyEntity = css.getEntity(); - CommandSender proxy = proxyEntity == null ? null : proxyEntity.getBukkitEntity(); - if (isNative || (proxy != null && !sender.equals(proxy))) { - if (proxy == null) { - proxy = sender; - } - - return new BukkitNativeProxyCommandSender(new NativeProxyCommandSender(sender, proxy, location, world)); - } else { - return wrapCommandSender(sender); - } + CommandSender proxy = proxyEntity == null ? sender : proxyEntity.getBukkitEntity(); + + return new NativeProxyCommandSender(sender, proxy, location, world); } @Override diff --git a/commandapi-platforms/commandapi-bukkit/commandapi-bukkit-nms/commandapi-bukkit-1.21/src/main/java/dev/jorel/commandapi/nms/NMS_1_21_R1.java b/commandapi-platforms/commandapi-bukkit/commandapi-bukkit-nms/commandapi-bukkit-1.21/src/main/java/dev/jorel/commandapi/nms/NMS_1_21_R1.java index 38899e554e..f11dfe3ab1 100644 --- a/commandapi-platforms/commandapi-bukkit/commandapi-bukkit-nms/commandapi-bukkit-1.21/src/main/java/dev/jorel/commandapi/nms/NMS_1_21_R1.java +++ b/commandapi-platforms/commandapi-bukkit/commandapi-bukkit-nms/commandapi-bukkit-1.21/src/main/java/dev/jorel/commandapi/nms/NMS_1_21_R1.java @@ -96,9 +96,6 @@ import dev.jorel.commandapi.SpigotCommandRegistration; import dev.jorel.commandapi.arguments.ArgumentSubType; import dev.jorel.commandapi.arguments.SuggestionProviders; -import dev.jorel.commandapi.commandsenders.AbstractCommandSender; -import dev.jorel.commandapi.commandsenders.BukkitCommandSender; -import dev.jorel.commandapi.commandsenders.BukkitNativeProxyCommandSender; import dev.jorel.commandapi.preprocessor.Differs; import dev.jorel.commandapi.preprocessor.NMSMeta; import dev.jorel.commandapi.preprocessor.RequireField; @@ -451,9 +448,8 @@ public final BlockData getBlockState(CommandContext cmdCtx, } @Override - public CommandSourceStack getBrigadierSourceFromCommandSender( - AbstractCommandSender sender) { - return VanillaCommandWrapper.getListener(sender.getSource()); + public CommandSourceStack getBrigadierSourceFromCommandSender(CommandSender sender) { + return VanillaCommandWrapper.getListener(sender); } @Override @@ -781,35 +777,23 @@ public String getScoreHolderSingle(CommandContext cmdCtx, St } @Override - public BukkitCommandSender getSenderForCommand(CommandContext cmdCtx, - boolean isNative) { + public NativeProxyCommandSender getNativeProxyCommandSender(CommandContext cmdCtx) { CommandSourceStack css = cmdCtx.getSource(); - CommandSender sender = css.getBukkitSender(); - if (sender == null) { - // Sender CANNOT be null. This can occur when using a remote console - // sender. You can access it directly using - // this.getMinecraftServer().remoteConsole - // however this may also be null, so delegate to the next most-meaningful - // sender. - sender = Bukkit.getConsoleSender(); - } + // Get original sender + CommandSender sender = getCommandSenderFromCommandSource(css); + + // Get position Vec3 pos = css.getPosition(); Vec2 rot = css.getRotation(); World world = getWorldForCSS(css); Location location = new Location(world, pos.x(), pos.y(), pos.z(), rot.y, rot.x); + // Get proxy sender (default to sender if null) Entity proxyEntity = css.getEntity(); - CommandSender proxy = proxyEntity == null ? null : proxyEntity.getBukkitEntity(); - if (isNative || (proxy != null && !sender.equals(proxy))) { - if (proxy == null) { - proxy = sender; - } + CommandSender proxy = proxyEntity == null ? sender : proxyEntity.getBukkitEntity(); - return new BukkitNativeProxyCommandSender(new NativeProxyCommandSender(sender, proxy, location, world)); - } else { - return wrapCommandSender(sender); - } + return new NativeProxyCommandSender(sender, proxy, location, world); } @Override diff --git a/commandapi-platforms/commandapi-bukkit/commandapi-bukkit-nms/commandapi-bukkit-nms-common/src/main/java/dev/jorel/commandapi/nms/NMS_Common.java b/commandapi-platforms/commandapi-bukkit/commandapi-bukkit-nms/commandapi-bukkit-nms-common/src/main/java/dev/jorel/commandapi/nms/NMS_Common.java index 2d5fc161b1..785c27caf3 100644 --- a/commandapi-platforms/commandapi-bukkit/commandapi-bukkit-nms/commandapi-bukkit-nms-common/src/main/java/dev/jorel/commandapi/nms/NMS_Common.java +++ b/commandapi-platforms/commandapi-bukkit/commandapi-bukkit-nms/commandapi-bukkit-nms-common/src/main/java/dev/jorel/commandapi/nms/NMS_Common.java @@ -30,8 +30,6 @@ import dev.jorel.commandapi.CommandRegistrationStrategy; import dev.jorel.commandapi.arguments.ArgumentSubType; import dev.jorel.commandapi.arguments.SuggestionProviders; -import dev.jorel.commandapi.commandsenders.AbstractCommandSender; -import dev.jorel.commandapi.commandsenders.BukkitCommandSender; import dev.jorel.commandapi.preprocessor.Differs; import dev.jorel.commandapi.preprocessor.Overridden; import dev.jorel.commandapi.preprocessor.Unimplemented; @@ -357,12 +355,17 @@ public final BaseComponent[] getChatComponent(CommandContext } @Override - public abstract CommandSourceStack getBrigadierSourceFromCommandSender(AbstractCommandSender sender); + @Unimplemented(because = REQUIRES_CRAFTBUKKIT, classNamed = "VanillaCommandWrapper") + public abstract CommandSourceStack getBrigadierSourceFromCommandSender(CommandSender sender); @Override - public final BukkitCommandSender getCommandSenderFromCommandSource(CommandSourceStack css) { + public final CommandSender getCommandSenderFromCommandSource(CommandSourceStack css) { try { - return wrapCommandSender(css.getBukkitSender()); + CommandSender sender = css.getBukkitSender(); + // Sender CANNOT be null. This can occur when using a remote console + // sender. You can access it directly using this.getMinecraftServer().remoteConsole + // however this may also be null, so delegate to the next most-meaningful sender. + return sender == null ? Bukkit.getConsoleSender() : sender; } catch (UnsupportedOperationException e) { return null; } @@ -526,7 +529,7 @@ public String getScoreHolderSingle(CommandContext cmdCtx, St @Unimplemented(because = NAME_CHANGED, info = "i (1.17) -> getRotation (1.18) -> l (1.19)") @Unimplemented(because = NAME_CHANGED, info = "getEntity (1.17) -> getEntity (1.18) -> g (1.19)") @Unimplemented(because = NAME_CHANGED, info = "getWorld (1.17) -> getLevel (1.18) -> f (1.19)") - public abstract BukkitCommandSender getSenderForCommand(CommandContext cmdCtx, boolean isNative); + public abstract NativeProxyCommandSender getNativeProxyCommandSender(CommandContext cmdCtx); @Override @Unimplemented(because = REQUIRES_CRAFTBUKKIT, classNamed = "CraftServer") diff --git a/commandapi-platforms/commandapi-bukkit/commandapi-bukkit-test/commandapi-bukkit-kotlin-test/src/test/kotlin/dev/jorel/commandapi/test/TestBase.kt b/commandapi-platforms/commandapi-bukkit/commandapi-bukkit-test/commandapi-bukkit-kotlin-test/src/test/kotlin/dev/jorel/commandapi/test/TestBase.kt index 3f6e0ee466..7cd37a2fd6 100644 --- a/commandapi-platforms/commandapi-bukkit/commandapi-bukkit-test/commandapi-bukkit-kotlin-test/src/test/kotlin/dev/jorel/commandapi/test/TestBase.kt +++ b/commandapi-platforms/commandapi-bukkit/commandapi-bukkit-test/commandapi-bukkit-kotlin-test/src/test/kotlin/dev/jorel/commandapi/test/TestBase.kt @@ -3,7 +3,7 @@ package dev.jorel.commandapi.test import be.seeseemelk.mockbukkit.MockBukkit import com.mojang.brigadier.exceptions.CommandSyntaxException import dev.jorel.commandapi.executors.CommandArguments -import dev.jorel.commandapi.executors.PlayerCommandExecutor +import dev.jorel.commandapi.executors.NormalExecutor import org.bukkit.Bukkit import org.bukkit.command.Command import org.bukkit.command.CommandMap @@ -87,6 +87,6 @@ abstract class TestBase { } companion object { - val P_EXEC = PlayerCommandExecutor { _: Player, _: CommandArguments -> } + val P_EXEC = NormalExecutor { _: Player, _: CommandArguments -> } } } \ No newline at end of file diff --git a/commandapi-platforms/commandapi-bukkit/commandapi-bukkit-test/commandapi-bukkit-test-impl-1.16.5/src/main/java/dev/jorel/commandapi/test/MockNMS.java b/commandapi-platforms/commandapi-bukkit/commandapi-bukkit-test/commandapi-bukkit-test-impl-1.16.5/src/main/java/dev/jorel/commandapi/test/MockNMS.java index 7c9bb5e891..ee6c916cfb 100644 --- a/commandapi-platforms/commandapi-bukkit/commandapi-bukkit-test/commandapi-bukkit-test-impl-1.16.5/src/main/java/dev/jorel/commandapi/test/MockNMS.java +++ b/commandapi-platforms/commandapi-bukkit/commandapi-bukkit-test/commandapi-bukkit-test-impl-1.16.5/src/main/java/dev/jorel/commandapi/test/MockNMS.java @@ -13,6 +13,7 @@ import be.seeseemelk.mockbukkit.help.HelpMapMock; import dev.jorel.commandapi.*; +import dev.jorel.commandapi.wrappers.NativeProxyCommandSender; import org.bukkit.Bukkit; import org.bukkit.Color; import org.bukkit.Location; @@ -45,9 +46,6 @@ import be.seeseemelk.mockbukkit.ServerMock; import be.seeseemelk.mockbukkit.enchantments.EnchantmentMock; import be.seeseemelk.mockbukkit.potion.MockPotionEffectType; -import dev.jorel.commandapi.commandsenders.AbstractCommandSender; -import dev.jorel.commandapi.commandsenders.BukkitCommandSender; -import dev.jorel.commandapi.commandsenders.BukkitPlayer; import net.minecraft.server.v1_16_R3.Advancement; import net.minecraft.server.v1_16_R3.AdvancementDataWorld; import net.minecraft.server.v1_16_R3.ArgumentAnchor.Anchor; @@ -277,8 +275,7 @@ public SimpleCommandMap getSimpleCommandMap() { } @Override - public CommandListenerWrapper getBrigadierSourceFromCommandSender(AbstractCommandSender senderWrapper) { - CommandSender sender = senderWrapper.getSource(); + public CommandListenerWrapper getBrigadierSourceFromCommandSender(CommandSender sender) { CommandListenerWrapper clw = Mockito.mock(CommandListenerWrapper.class); Mockito.when(clw.getBukkitSender()).thenReturn(sender); @@ -363,6 +360,11 @@ public CommandListenerWrapper getBrigadierSourceFromCommandSender(AbstractComman return clw; } + @Override + public NativeProxyCommandSender getNativeProxyCommandSender(CommandContext cmdCtx) { + return baseNMS.getNativeProxyCommandSender(cmdCtx); + } + @SuppressWarnings({ "rawtypes", "unchecked" }) @Override public void createDispatcherFile(File file, CommandDispatcher dispatcher) @@ -556,7 +558,7 @@ public void addFunction(NamespacedKey key, List commands) { } MinecraftKey resourceLocation = new MinecraftKey(key.toString()); - CommandListenerWrapper css = getBrigadierSourceFromCommandSender(new BukkitPlayer(Bukkit.getOnlinePlayers().iterator().next())); + CommandListenerWrapper css = getBrigadierSourceFromCommandSender(Bukkit.getOnlinePlayers().iterator().next()); // So for very interesting reasons, Brigadier.getCommandDispatcher() // gives a different result in this method than using getBrigadierDispatcher() @@ -571,7 +573,7 @@ public void addTag(NamespacedKey key, List> commands) { } MinecraftKey resourceLocation = new MinecraftKey(key.toString()); - CommandListenerWrapper css = getBrigadierSourceFromCommandSender(new BukkitPlayer(Bukkit.getOnlinePlayers().iterator().next())); + CommandListenerWrapper css = getBrigadierSourceFromCommandSender(Bukkit.getOnlinePlayers().iterator().next()); List tagFunctions = new ArrayList<>(); for(List functionCommands : commands) { @@ -594,7 +596,7 @@ public Player setupMockedCraftPlayer(String name) { Mockito.when(player.getWorld()).thenReturn(world); // Provide proper handle as VanillaCommandWrapper expects - CommandListenerWrapper css = getBrigadierSourceFromCommandSender(wrapCommandSender(player)); + CommandListenerWrapper css = getBrigadierSourceFromCommandSender(player); EntityPlayer handle = Mockito.mock(EntityPlayer.class); Mockito.when(handle.getCommandListener()).thenReturn(css); @@ -630,17 +632,8 @@ public Collection getCriteria() { } @Override - public BukkitCommandSender getSenderForCommand(CommandContext cmdCtx, boolean forceNative) { - return baseNMS.getSenderForCommand(cmdCtx, forceNative); - } - - @Override - public BukkitCommandSender getCommandSenderFromCommandSource(CommandListenerWrapper cs) { - try { - return wrapCommandSender(cs.getBukkitSender()); - } catch (UnsupportedOperationException e) { - return null; - } + public CommandSender getCommandSenderFromCommandSource(CommandListenerWrapper cs) { + return baseNMS.getCommandSenderFromCommandSource(cs); } @Override diff --git a/commandapi-platforms/commandapi-bukkit/commandapi-bukkit-test/commandapi-bukkit-test-impl-1.17/src/main/java/dev/jorel/commandapi/test/MockNMS.java b/commandapi-platforms/commandapi-bukkit/commandapi-bukkit-test/commandapi-bukkit-test-impl-1.17/src/main/java/dev/jorel/commandapi/test/MockNMS.java index 765030ec49..3c657fafbf 100644 --- a/commandapi-platforms/commandapi-bukkit/commandapi-bukkit-test/commandapi-bukkit-test-impl-1.17/src/main/java/dev/jorel/commandapi/test/MockNMS.java +++ b/commandapi-platforms/commandapi-bukkit/commandapi-bukkit-test/commandapi-bukkit-test-impl-1.17/src/main/java/dev/jorel/commandapi/test/MockNMS.java @@ -12,6 +12,7 @@ import be.seeseemelk.mockbukkit.help.HelpMapMock; import dev.jorel.commandapi.*; +import dev.jorel.commandapi.wrappers.NativeProxyCommandSender; import net.minecraft.commands.Commands; import org.bukkit.Bukkit; import org.bukkit.Color; @@ -43,9 +44,6 @@ import be.seeseemelk.mockbukkit.ServerMock; import be.seeseemelk.mockbukkit.enchantments.EnchantmentMock; import be.seeseemelk.mockbukkit.potion.MockPotionEffectType; -import dev.jorel.commandapi.commandsenders.AbstractCommandSender; -import dev.jorel.commandapi.commandsenders.BukkitCommandSender; -import dev.jorel.commandapi.commandsenders.BukkitPlayer; import net.minecraft.SharedConstants; import net.minecraft.advancements.Advancement; import net.minecraft.commands.CommandFunction; @@ -261,8 +259,7 @@ public SimpleCommandMap getSimpleCommandMap() { } @Override - public CommandSourceStack getBrigadierSourceFromCommandSender(AbstractCommandSender senderWrapper) { - CommandSender sender = senderWrapper.getSource(); + public CommandSourceStack getBrigadierSourceFromCommandSender(CommandSender sender) { CommandSourceStack css = Mockito.mock(CommandSourceStack.class); Mockito.when(css.getBukkitSender()).thenReturn(sender); @@ -346,6 +343,11 @@ public CommandSourceStack getBrigadierSourceFromCommandSender(AbstractCommandSen return css; } + @Override + public NativeProxyCommandSender getNativeProxyCommandSender(CommandContext cmdCtx) { + return baseNMS.getNativeProxyCommandSender(cmdCtx); + } + @SuppressWarnings({ "rawtypes", "unchecked" }) @Override public void createDispatcherFile(File file, CommandDispatcher dispatcher) @@ -541,7 +543,7 @@ public void addFunction(NamespacedKey key, List commands) { } ResourceLocation resourceLocation = new ResourceLocation(key.toString()); - CommandSourceStack css = getBrigadierSourceFromCommandSender(new BukkitPlayer(Bukkit.getOnlinePlayers().iterator().next())); + CommandSourceStack css = getBrigadierSourceFromCommandSender(Bukkit.getOnlinePlayers().iterator().next()); // So for very interesting reasons, Brigadier.getCommandDispatcher() // gives a different result in this method than using getBrigadierDispatcher() @@ -556,7 +558,7 @@ public void addTag(NamespacedKey key, List> commands) { } ResourceLocation resourceLocation = new ResourceLocation(key.toString()); - CommandSourceStack css = getBrigadierSourceFromCommandSender(new BukkitPlayer(Bukkit.getOnlinePlayers().iterator().next())); + CommandSourceStack css = getBrigadierSourceFromCommandSender(Bukkit.getOnlinePlayers().iterator().next()); List tagFunctions = new ArrayList<>(); for(List functionCommands : commands) { @@ -579,7 +581,7 @@ public Player setupMockedCraftPlayer(String name) { Mockito.when(player.getWorld()).thenReturn(world); // Provide proper handle as VanillaCommandWrapper expects - CommandSourceStack css = getBrigadierSourceFromCommandSender(wrapCommandSender(player)); + CommandSourceStack css = getBrigadierSourceFromCommandSender(player); ServerPlayer handle = Mockito.mock(ServerPlayer.class); Mockito.when(handle.createCommandSourceStack()).thenReturn(css); @@ -614,17 +616,8 @@ public Collection getCriteria() { } @Override - public BukkitCommandSender getSenderForCommand(CommandContext cmdCtx, boolean forceNative) { - return baseNMS.getSenderForCommand(cmdCtx, forceNative); - } - - @Override - public BukkitCommandSender getCommandSenderFromCommandSource(CommandSourceStack clw) { - try { - return wrapCommandSender(clw.getBukkitSender()); - } catch (UnsupportedOperationException e) { - return null; - } + public CommandSender getCommandSenderFromCommandSource(CommandSourceStack clw) { + return baseNMS.getCommandSenderFromCommandSource(clw); } @Override diff --git a/commandapi-platforms/commandapi-bukkit/commandapi-bukkit-test/commandapi-bukkit-test-impl-1.18/src/main/java/dev/jorel/commandapi/test/MockNMS.java b/commandapi-platforms/commandapi-bukkit/commandapi-bukkit-test/commandapi-bukkit-test-impl-1.18/src/main/java/dev/jorel/commandapi/test/MockNMS.java index b978113c70..f52c9e2eb2 100644 --- a/commandapi-platforms/commandapi-bukkit/commandapi-bukkit-test/commandapi-bukkit-test-impl-1.18/src/main/java/dev/jorel/commandapi/test/MockNMS.java +++ b/commandapi-platforms/commandapi-bukkit/commandapi-bukkit-test/commandapi-bukkit-test-impl-1.18/src/main/java/dev/jorel/commandapi/test/MockNMS.java @@ -13,6 +13,7 @@ import be.seeseemelk.mockbukkit.help.HelpMapMock; import dev.jorel.commandapi.*; +import dev.jorel.commandapi.wrappers.NativeProxyCommandSender; import net.minecraft.commands.Commands; import org.bukkit.Bukkit; import org.bukkit.Color; @@ -47,9 +48,6 @@ import be.seeseemelk.mockbukkit.ServerMock; import be.seeseemelk.mockbukkit.enchantments.EnchantmentMock; import be.seeseemelk.mockbukkit.potion.MockPotionEffectType; -import dev.jorel.commandapi.commandsenders.AbstractCommandSender; -import dev.jorel.commandapi.commandsenders.BukkitCommandSender; -import dev.jorel.commandapi.commandsenders.BukkitPlayer; import io.papermc.paper.advancement.AdvancementDisplay; import net.minecraft.SharedConstants; import net.minecraft.advancements.Advancement; @@ -279,8 +277,7 @@ public SimpleCommandMap getSimpleCommandMap() { @SuppressWarnings({ "deprecation", "unchecked" }) @Override - public CommandSourceStack getBrigadierSourceFromCommandSender(AbstractCommandSender senderWrapper) { - CommandSender sender = senderWrapper.getSource(); + public CommandSourceStack getBrigadierSourceFromCommandSender(CommandSender sender) { CommandSourceStack css = Mockito.mock(CommandSourceStack.class); Mockito.when(css.getBukkitSender()).thenReturn(sender); @@ -363,6 +360,11 @@ public CommandSourceStack getBrigadierSourceFromCommandSender(AbstractCommandSen return css; } + @Override + public NativeProxyCommandSender getNativeProxyCommandSender(CommandContext cmdCtx) { + return baseNMS.getNativeProxyCommandSender(cmdCtx); + } + @SuppressWarnings({ "rawtypes", "unchecked" }) @Override public void createDispatcherFile(File file, CommandDispatcher dispatcher) @@ -556,7 +558,7 @@ public void addFunction(NamespacedKey key, List commands) { } ResourceLocation resourceLocation = new ResourceLocation(key.toString()); - CommandSourceStack css = getBrigadierSourceFromCommandSender(new BukkitPlayer(Bukkit.getOnlinePlayers().iterator().next())); + CommandSourceStack css = getBrigadierSourceFromCommandSender(Bukkit.getOnlinePlayers().iterator().next()); // So for very interesting reasons, Brigadier.getCommandDispatcher() // gives a different result in this method than using getBrigadierDispatcher() @@ -571,7 +573,7 @@ public void addTag(NamespacedKey key, List> commands) { } ResourceLocation resourceLocation = new ResourceLocation(key.toString()); - CommandSourceStack css = getBrigadierSourceFromCommandSender(new BukkitPlayer(Bukkit.getOnlinePlayers().iterator().next())); + CommandSourceStack css = getBrigadierSourceFromCommandSender(Bukkit.getOnlinePlayers().iterator().next()); List tagFunctions = new ArrayList<>(); for(List functionCommands : commands) { @@ -594,7 +596,7 @@ public Player setupMockedCraftPlayer(String name) { Mockito.when(player.getWorld()).thenReturn(world); // Provide proper handle as VanillaCommandWrapper expects - CommandSourceStack css = getBrigadierSourceFromCommandSender(wrapCommandSender(player)); + CommandSourceStack css = getBrigadierSourceFromCommandSender(player); ServerPlayer handle = Mockito.mock(ServerPlayer.class); Mockito.when(handle.createCommandSourceStack()).thenReturn(css); @@ -649,17 +651,8 @@ public Collection getCriteria() { } @Override - public BukkitCommandSender getSenderForCommand(CommandContext cmdCtx, boolean forceNative) { - return baseNMS.getSenderForCommand(cmdCtx, forceNative); - } - - @Override - public BukkitCommandSender getCommandSenderFromCommandSource(CommandSourceStack clw) { - try { - return wrapCommandSender(clw.getBukkitSender()); - } catch (UnsupportedOperationException e) { - return null; - } + public CommandSender getCommandSenderFromCommandSource(CommandSourceStack clw) { + return baseNMS.getCommandSenderFromCommandSource(clw); } @Override diff --git a/commandapi-platforms/commandapi-bukkit/commandapi-bukkit-test/commandapi-bukkit-test-impl-1.19.2/src/main/java/dev/jorel/commandapi/test/MockNMS.java b/commandapi-platforms/commandapi-bukkit/commandapi-bukkit-test/commandapi-bukkit-test-impl-1.19.2/src/main/java/dev/jorel/commandapi/test/MockNMS.java index 936dc35099..9fc949ed73 100644 --- a/commandapi-platforms/commandapi-bukkit/commandapi-bukkit-test/commandapi-bukkit-test-impl-1.19.2/src/main/java/dev/jorel/commandapi/test/MockNMS.java +++ b/commandapi-platforms/commandapi-bukkit/commandapi-bukkit-test/commandapi-bukkit-test-impl-1.19.2/src/main/java/dev/jorel/commandapi/test/MockNMS.java @@ -13,6 +13,7 @@ import be.seeseemelk.mockbukkit.help.HelpMapMock; import dev.jorel.commandapi.*; +import dev.jorel.commandapi.wrappers.NativeProxyCommandSender; import net.minecraft.commands.Commands; import org.bukkit.Bukkit; import org.bukkit.Color; @@ -47,9 +48,6 @@ import be.seeseemelk.mockbukkit.ServerMock; import be.seeseemelk.mockbukkit.enchantments.EnchantmentMock; import be.seeseemelk.mockbukkit.potion.MockPotionEffectType; -import dev.jorel.commandapi.commandsenders.AbstractCommandSender; -import dev.jorel.commandapi.commandsenders.BukkitCommandSender; -import dev.jorel.commandapi.commandsenders.BukkitPlayer; import io.papermc.paper.advancement.AdvancementDisplay; import net.kyori.adventure.text.Component; import net.minecraft.SharedConstants; @@ -275,8 +273,7 @@ public SimpleCommandMap getSimpleCommandMap() { @SuppressWarnings({ "deprecation", "unchecked" }) @Override - public CommandSourceStack getBrigadierSourceFromCommandSender(AbstractCommandSender senderWrapper) { - CommandSender sender = senderWrapper.getSource(); + public CommandSourceStack getBrigadierSourceFromCommandSender(CommandSender sender) { CommandSourceStack css = Mockito.mock(CommandSourceStack.class); Mockito.when(css.getBukkitSender()).thenReturn(sender); @@ -359,6 +356,11 @@ public CommandSourceStack getBrigadierSourceFromCommandSender(AbstractCommandSen return css; } + @Override + public NativeProxyCommandSender getNativeProxyCommandSender(CommandContext cmdCtx) { + return baseNMS.getNativeProxyCommandSender(cmdCtx); + } + @SuppressWarnings({ "rawtypes", "unchecked" }) @Override public void createDispatcherFile(File file, CommandDispatcher dispatcher) @@ -549,7 +551,7 @@ public void addFunction(NamespacedKey key, List commands) { } ResourceLocation resourceLocation = new ResourceLocation(key.toString()); - CommandSourceStack css = getBrigadierSourceFromCommandSender(new BukkitPlayer(Bukkit.getOnlinePlayers().iterator().next())); + CommandSourceStack css = getBrigadierSourceFromCommandSender(Bukkit.getOnlinePlayers().iterator().next()); // So for very interesting reasons, Brigadier.getCommandDispatcher() // gives a different result in this method than using getBrigadierDispatcher() @@ -564,7 +566,7 @@ public void addTag(NamespacedKey key, List> commands) { } ResourceLocation resourceLocation = new ResourceLocation(key.toString()); - CommandSourceStack css = getBrigadierSourceFromCommandSender(new BukkitPlayer(Bukkit.getOnlinePlayers().iterator().next())); + CommandSourceStack css = getBrigadierSourceFromCommandSender(Bukkit.getOnlinePlayers().iterator().next()); List tagFunctions = new ArrayList<>(); for(List functionCommands : commands) { @@ -587,7 +589,7 @@ public Player setupMockedCraftPlayer(String name) { Mockito.when(player.getWorld()).thenReturn(world); // Provide proper handle as VanillaCommandWrapper expects - CommandSourceStack css = getBrigadierSourceFromCommandSender(wrapCommandSender(player)); + CommandSourceStack css = getBrigadierSourceFromCommandSender(player); ServerPlayer handle = Mockito.mock(ServerPlayer.class); Mockito.when(handle.createCommandSourceStack()).thenReturn(css); @@ -647,17 +649,8 @@ public Collection getCriteria() { } @Override - public BukkitCommandSender getSenderForCommand(CommandContext cmdCtx, boolean forceNative) { - return baseNMS.getSenderForCommand(cmdCtx, forceNative); - } - - @Override - public BukkitCommandSender getCommandSenderFromCommandSource(CommandSourceStack clw) { - try { - return wrapCommandSender(clw.getBukkitSender()); - } catch (UnsupportedOperationException e) { - return null; - } + public CommandSender getCommandSenderFromCommandSource(CommandSourceStack clw) { + return baseNMS.getCommandSenderFromCommandSource(clw); } // @Override diff --git a/commandapi-platforms/commandapi-bukkit/commandapi-bukkit-test/commandapi-bukkit-test-impl-1.19.4/src/main/java/dev/jorel/commandapi/test/MockNMS.java b/commandapi-platforms/commandapi-bukkit/commandapi-bukkit-test/commandapi-bukkit-test-impl-1.19.4/src/main/java/dev/jorel/commandapi/test/MockNMS.java index fada5fcb92..3cfebf7fcd 100644 --- a/commandapi-platforms/commandapi-bukkit/commandapi-bukkit-test/commandapi-bukkit-test-impl-1.19.4/src/main/java/dev/jorel/commandapi/test/MockNMS.java +++ b/commandapi-platforms/commandapi-bukkit/commandapi-bukkit-test/commandapi-bukkit-test-impl-1.19.4/src/main/java/dev/jorel/commandapi/test/MockNMS.java @@ -13,6 +13,7 @@ import be.seeseemelk.mockbukkit.help.HelpMapMock; import dev.jorel.commandapi.*; +import dev.jorel.commandapi.wrappers.NativeProxyCommandSender; import net.minecraft.commands.Commands; import org.bukkit.Bukkit; import org.bukkit.Color; @@ -47,9 +48,6 @@ import be.seeseemelk.mockbukkit.ServerMock; import be.seeseemelk.mockbukkit.enchantments.EnchantmentMock; import be.seeseemelk.mockbukkit.potion.MockPotionEffectType; -import dev.jorel.commandapi.commandsenders.AbstractCommandSender; -import dev.jorel.commandapi.commandsenders.BukkitCommandSender; -import dev.jorel.commandapi.commandsenders.BukkitPlayer; import io.papermc.paper.advancement.AdvancementDisplay; import net.kyori.adventure.text.Component; import net.minecraft.SharedConstants; @@ -276,8 +274,7 @@ public SimpleCommandMap getSimpleCommandMap() { @SuppressWarnings({ "deprecation", "unchecked" }) @Override - public CommandSourceStack getBrigadierSourceFromCommandSender(AbstractCommandSender senderWrapper) { - CommandSender sender = senderWrapper.getSource(); + public CommandSourceStack getBrigadierSourceFromCommandSender(CommandSender sender) { CommandSourceStack css = Mockito.mock(CommandSourceStack.class); Mockito.when(css.getBukkitSender()).thenReturn(sender); @@ -362,6 +359,11 @@ public CommandSourceStack getBrigadierSourceFromCommandSender(AbstractCommandSen return css; } + @Override + public NativeProxyCommandSender getNativeProxyCommandSender(CommandContext cmdCtx) { + return baseNMS.getNativeProxyCommandSender(cmdCtx); + } + @SuppressWarnings({ "rawtypes", "unchecked" }) @Override public void createDispatcherFile(File file, CommandDispatcher dispatcher) @@ -559,7 +561,7 @@ public void addFunction(NamespacedKey key, List commands) { } ResourceLocation resourceLocation = new ResourceLocation(key.toString()); - CommandSourceStack css = getBrigadierSourceFromCommandSender(new BukkitPlayer(Bukkit.getOnlinePlayers().iterator().next())); + CommandSourceStack css = getBrigadierSourceFromCommandSender(Bukkit.getOnlinePlayers().iterator().next()); // So for very interesting reasons, Brigadier.getCommandDispatcher() // gives a different result in this method than using getBrigadierDispatcher() @@ -574,7 +576,7 @@ public void addTag(NamespacedKey key, List> commands) { } ResourceLocation resourceLocation = new ResourceLocation(key.toString()); - CommandSourceStack css = getBrigadierSourceFromCommandSender(new BukkitPlayer(Bukkit.getOnlinePlayers().iterator().next())); + CommandSourceStack css = getBrigadierSourceFromCommandSender(Bukkit.getOnlinePlayers().iterator().next()); List tagFunctions = new ArrayList<>(); for(List functionCommands : commands) { @@ -597,7 +599,7 @@ public Player setupMockedCraftPlayer(String name) { Mockito.when(player.getWorld()).thenReturn(world); // Provide proper handle as VanillaCommandWrapper expects - CommandSourceStack css = getBrigadierSourceFromCommandSender(wrapCommandSender(player)); + CommandSourceStack css = getBrigadierSourceFromCommandSender(player); ServerPlayer handle = Mockito.mock(ServerPlayer.class); Mockito.when(handle.createCommandSourceStack()).thenReturn(css); @@ -657,17 +659,8 @@ public Collection getCriteria() { } @Override - public BukkitCommandSender getSenderForCommand(CommandContext cmdCtx, boolean forceNative) { - return baseNMS.getSenderForCommand(cmdCtx, forceNative); - } - - @Override - public BukkitCommandSender getCommandSenderFromCommandSource(CommandSourceStack clw) { - try { - return wrapCommandSender(clw.getBukkitSender()); - } catch (UnsupportedOperationException e) { - return null; - } + public CommandSender getCommandSenderFromCommandSource(CommandSourceStack clw) { + return baseNMS.getCommandSenderFromCommandSource(clw); } // @Override diff --git a/commandapi-platforms/commandapi-bukkit/commandapi-bukkit-test/commandapi-bukkit-test-impl-1.20.2/src/main/java/dev/jorel/commandapi/test/MockNMS.java b/commandapi-platforms/commandapi-bukkit/commandapi-bukkit-test/commandapi-bukkit-test-impl-1.20.2/src/main/java/dev/jorel/commandapi/test/MockNMS.java index e2959928b5..ffd49fc656 100644 --- a/commandapi-platforms/commandapi-bukkit/commandapi-bukkit-test/commandapi-bukkit-test-impl-1.20.2/src/main/java/dev/jorel/commandapi/test/MockNMS.java +++ b/commandapi-platforms/commandapi-bukkit/commandapi-bukkit-test/commandapi-bukkit-test-impl-1.20.2/src/main/java/dev/jorel/commandapi/test/MockNMS.java @@ -9,9 +9,7 @@ import com.mojang.brigadier.CommandDispatcher; import com.mojang.brigadier.context.CommandContext; import dev.jorel.commandapi.*; -import dev.jorel.commandapi.commandsenders.AbstractCommandSender; -import dev.jorel.commandapi.commandsenders.BukkitCommandSender; -import dev.jorel.commandapi.commandsenders.BukkitPlayer; +import dev.jorel.commandapi.wrappers.NativeProxyCommandSender; import net.minecraft.SharedConstants; import net.minecraft.advancements.Advancement; import net.minecraft.advancements.AdvancementHolder; @@ -260,8 +258,7 @@ public SimpleCommandMap getSimpleCommandMap() { @SuppressWarnings({ "deprecation", "unchecked" }) @Override - public CommandSourceStack getBrigadierSourceFromCommandSender(AbstractCommandSender senderWrapper) { - CommandSender sender = senderWrapper.getSource(); + public CommandSourceStack getBrigadierSourceFromCommandSender(CommandSender sender) { CommandSourceStack css = Mockito.mock(CommandSourceStack.class); Mockito.when(css.getBukkitSender()).thenReturn(sender); @@ -357,6 +354,11 @@ public CommandSourceStack getBrigadierSourceFromCommandSender(AbstractCommandSen return css; } + @Override + public NativeProxyCommandSender getNativeProxyCommandSender(CommandContext cmdCtx) { + return baseNMS.getNativeProxyCommandSender(cmdCtx); + } + @SuppressWarnings({ "rawtypes", "unchecked" }) @Override public void createDispatcherFile(File file, CommandDispatcher dispatcher) @@ -556,7 +558,7 @@ public void addFunction(NamespacedKey key, List commands) { } ResourceLocation resourceLocation = new ResourceLocation(key.toString()); - CommandSourceStack css = getBrigadierSourceFromCommandSender(new BukkitPlayer(Bukkit.getOnlinePlayers().iterator().next())); + CommandSourceStack css = getBrigadierSourceFromCommandSender(Bukkit.getOnlinePlayers().iterator().next()); // So for very interesting reasons, Brigadier.getCommandDispatcher() // gives a different result in this method than using getBrigadierDispatcher() @@ -571,7 +573,7 @@ public void addTag(NamespacedKey key, List> commands) { } ResourceLocation resourceLocation = new ResourceLocation(key.toString()); - CommandSourceStack css = getBrigadierSourceFromCommandSender(new BukkitPlayer(Bukkit.getOnlinePlayers().iterator().next())); + CommandSourceStack css = getBrigadierSourceFromCommandSender(Bukkit.getOnlinePlayers().iterator().next()); List tagFunctions = new ArrayList<>(); for(List functionCommands : commands) { @@ -594,7 +596,7 @@ public Player setupMockedCraftPlayer(String name) { Mockito.when(player.getWorld()).thenReturn(world); // Provide proper handle as VanillaCommandWrapper expects - CommandSourceStack css = getBrigadierSourceFromCommandSender(wrapCommandSender(player)); + CommandSourceStack css = getBrigadierSourceFromCommandSender(player); ServerPlayer handle = Mockito.mock(ServerPlayer.class); Mockito.when(handle.createCommandSourceStack()).thenReturn(css); @@ -657,17 +659,8 @@ public Collection getCriteria() { } @Override - public BukkitCommandSender getSenderForCommand(CommandContext cmdCtx, boolean forceNative) { - return baseNMS.getSenderForCommand(cmdCtx, forceNative); - } - - @Override - public BukkitCommandSender getCommandSenderFromCommandSource(CommandSourceStack clw) { - try { - return wrapCommandSender(clw.getBukkitSender()); - } catch (UnsupportedOperationException e) { - return null; - } + public CommandSender getCommandSenderFromCommandSource(CommandSourceStack clw) { + return baseNMS.getCommandSenderFromCommandSource(clw); } // @Override diff --git a/commandapi-platforms/commandapi-bukkit/commandapi-bukkit-test/commandapi-bukkit-test-impl-1.20.3/src/main/java/dev/jorel/commandapi/test/MockNMS.java b/commandapi-platforms/commandapi-bukkit/commandapi-bukkit-test/commandapi-bukkit-test-impl-1.20.3/src/main/java/dev/jorel/commandapi/test/MockNMS.java index 198d16fb8d..8f5f6c9261 100644 --- a/commandapi-platforms/commandapi-bukkit/commandapi-bukkit-test/commandapi-bukkit-test-impl-1.20.3/src/main/java/dev/jorel/commandapi/test/MockNMS.java +++ b/commandapi-platforms/commandapi-bukkit/commandapi-bukkit-test/commandapi-bukkit-test-impl-1.20.3/src/main/java/dev/jorel/commandapi/test/MockNMS.java @@ -10,9 +10,7 @@ import com.mojang.brigadier.context.CommandContext; import com.mojang.serialization.JsonOps; import dev.jorel.commandapi.*; -import dev.jorel.commandapi.commandsenders.AbstractCommandSender; -import dev.jorel.commandapi.commandsenders.BukkitCommandSender; -import dev.jorel.commandapi.commandsenders.BukkitPlayer; +import dev.jorel.commandapi.wrappers.NativeProxyCommandSender; import net.minecraft.SharedConstants; import net.minecraft.advancements.Advancement; import net.minecraft.advancements.AdvancementHolder; @@ -269,8 +267,7 @@ public SimpleCommandMap getSimpleCommandMap() { @SuppressWarnings({ "deprecation", "unchecked" }) @Override - public CommandSourceStack getBrigadierSourceFromCommandSender(AbstractCommandSender senderWrapper) { - CommandSender sender = senderWrapper.getSource(); + public CommandSourceStack getBrigadierSourceFromCommandSender(CommandSender sender) { CommandSourceStack css = Mockito.mock(CommandSourceStack.class); Mockito.when(css.getBukkitSender()).thenReturn(sender); @@ -370,6 +367,11 @@ public CommandSourceStack getBrigadierSourceFromCommandSender(AbstractCommandSen return css; } + @Override + public NativeProxyCommandSender getNativeProxyCommandSender(CommandContext cmdCtx) { + return baseNMS.getNativeProxyCommandSender(cmdCtx); + } + @SuppressWarnings({ "rawtypes", "unchecked" }) @Override public void createDispatcherFile(File file, CommandDispatcher dispatcher) @@ -569,7 +571,7 @@ public void addFunction(NamespacedKey key, List commands) { } ResourceLocation resourceLocation = new ResourceLocation(key.toString()); - CommandSourceStack css = getBrigadierSourceFromCommandSender(new BukkitPlayer(Bukkit.getOnlinePlayers().iterator().next())); + CommandSourceStack css = getBrigadierSourceFromCommandSender(Bukkit.getOnlinePlayers().iterator().next()); // So for very interesting reasons, Brigadier.getCommandDispatcher() // gives a different result in this method than using getBrigadierDispatcher() @@ -584,7 +586,7 @@ public void addTag(NamespacedKey key, List> commands) { } ResourceLocation resourceLocation = new ResourceLocation(key.toString()); - CommandSourceStack css = getBrigadierSourceFromCommandSender(new BukkitPlayer(Bukkit.getOnlinePlayers().iterator().next())); + CommandSourceStack css = getBrigadierSourceFromCommandSender(Bukkit.getOnlinePlayers().iterator().next()); List tagFunctions = new ArrayList<>(); for(List functionCommands : commands) { @@ -607,7 +609,7 @@ public Player setupMockedCraftPlayer(String name) { Mockito.when(player.getWorld()).thenReturn(world); // Provide proper handle as VanillaCommandWrapper expects - CommandSourceStack css = getBrigadierSourceFromCommandSender(wrapCommandSender(player)); + CommandSourceStack css = getBrigadierSourceFromCommandSender(player); ServerPlayer handle = Mockito.mock(ServerPlayer.class); Mockito.when(handle.createCommandSourceStack()).thenReturn(css); @@ -670,17 +672,8 @@ public Collection getCriteria() { } @Override - public BukkitCommandSender getSenderForCommand(CommandContext cmdCtx, boolean forceNative) { - return baseNMS.getSenderForCommand(cmdCtx, forceNative); - } - - @Override - public BukkitCommandSender getCommandSenderFromCommandSource(CommandSourceStack clw) { - try { - return wrapCommandSender(clw.getBukkitSender()); - } catch (UnsupportedOperationException e) { - return null; - } + public CommandSender getCommandSenderFromCommandSource(CommandSourceStack clw) { + return baseNMS.getCommandSenderFromCommandSource(clw); } @Override diff --git a/commandapi-platforms/commandapi-bukkit/commandapi-bukkit-test/commandapi-bukkit-test-impl-1.20.5/src/main/java/dev/jorel/commandapi/test/MockNMS.java b/commandapi-platforms/commandapi-bukkit/commandapi-bukkit-test/commandapi-bukkit-test-impl-1.20.5/src/main/java/dev/jorel/commandapi/test/MockNMS.java index 1a9a47b3d8..629721b52d 100644 --- a/commandapi-platforms/commandapi-bukkit/commandapi-bukkit-test/commandapi-bukkit-test-impl-1.20.5/src/main/java/dev/jorel/commandapi/test/MockNMS.java +++ b/commandapi-platforms/commandapi-bukkit/commandapi-bukkit-test/commandapi-bukkit-test-impl-1.20.5/src/main/java/dev/jorel/commandapi/test/MockNMS.java @@ -8,9 +8,7 @@ import com.mojang.brigadier.context.CommandContext; import com.mojang.serialization.JsonOps; import dev.jorel.commandapi.*; -import dev.jorel.commandapi.commandsenders.AbstractCommandSender; -import dev.jorel.commandapi.commandsenders.BukkitCommandSender; -import dev.jorel.commandapi.commandsenders.BukkitPlayer; +import dev.jorel.commandapi.wrappers.NativeProxyCommandSender; import net.minecraft.SharedConstants; import net.minecraft.advancements.Advancement; import net.minecraft.advancements.AdvancementHolder; @@ -288,8 +286,7 @@ public SimpleCommandMap getSimpleCommandMap() { @SuppressWarnings({ "deprecation", "unchecked" }) @Override - public CommandSourceStack getBrigadierSourceFromCommandSender(AbstractCommandSender senderWrapper) { - CommandSender sender = senderWrapper.getSource(); + public CommandSourceStack getBrigadierSourceFromCommandSender(CommandSender sender) { CommandSourceStack css = Mockito.mock(CommandSourceStack.class); Mockito.when(css.getBukkitSender()).thenReturn(sender); @@ -389,6 +386,11 @@ public CommandSourceStack getBrigadierSourceFromCommandSender(AbstractCommandSen return css; } + @Override + public NativeProxyCommandSender getNativeProxyCommandSender(CommandContext cmdCtx) { + return baseNMS.getNativeProxyCommandSender(cmdCtx); + } + @SuppressWarnings({ "rawtypes", "unchecked" }) @Override public void createDispatcherFile(File file, CommandDispatcher dispatcher) @@ -698,7 +700,7 @@ public void addFunction(NamespacedKey key, List commands) { } ResourceLocation resourceLocation = new ResourceLocation(key.toString()); - CommandSourceStack css = getBrigadierSourceFromCommandSender(new BukkitPlayer(Bukkit.getOnlinePlayers().iterator().next())); + CommandSourceStack css = getBrigadierSourceFromCommandSender(Bukkit.getOnlinePlayers().iterator().next()); // So for very interesting reasons, Brigadier.getCommandDispatcher() // gives a different result in this method than using getBrigadierDispatcher() @@ -713,7 +715,7 @@ public void addTag(NamespacedKey key, List> commands) { } ResourceLocation resourceLocation = new ResourceLocation(key.toString()); - CommandSourceStack css = getBrigadierSourceFromCommandSender(new BukkitPlayer(Bukkit.getOnlinePlayers().iterator().next())); + CommandSourceStack css = getBrigadierSourceFromCommandSender(Bukkit.getOnlinePlayers().iterator().next()); List tagFunctions = new ArrayList<>(); for(List functionCommands : commands) { @@ -736,7 +738,7 @@ public Player setupMockedCraftPlayer(String name) { Mockito.when(player.getWorld()).thenReturn(world); // Provide proper handle as VanillaCommandWrapper expects - CommandSourceStack css = getBrigadierSourceFromCommandSender(wrapCommandSender(player)); + CommandSourceStack css = getBrigadierSourceFromCommandSender(player); ServerPlayer handle = Mockito.mock(ServerPlayer.class); Mockito.when(handle.createCommandSourceStack()).thenReturn(css); @@ -799,17 +801,8 @@ public Collection getCriteria() { } @Override - public BukkitCommandSender getSenderForCommand(CommandContext cmdCtx, boolean forceNative) { - return baseNMS.getSenderForCommand(cmdCtx, forceNative); - } - - @Override - public BukkitCommandSender getCommandSenderFromCommandSource(CommandSourceStack clw) { - try { - return wrapCommandSender(clw.getBukkitSender()); - } catch (UnsupportedOperationException e) { - return null; - } + public CommandSender getCommandSenderFromCommandSource(CommandSourceStack clw) { + return baseNMS.getCommandSenderFromCommandSource(clw); } @Override diff --git a/commandapi-platforms/commandapi-bukkit/commandapi-bukkit-test/commandapi-bukkit-test-impl-1.20/src/main/java/dev/jorel/commandapi/test/MockNMS.java b/commandapi-platforms/commandapi-bukkit/commandapi-bukkit-test/commandapi-bukkit-test-impl-1.20/src/main/java/dev/jorel/commandapi/test/MockNMS.java index ba0cee5b54..5662828842 100644 --- a/commandapi-platforms/commandapi-bukkit/commandapi-bukkit-test/commandapi-bukkit-test-impl-1.20/src/main/java/dev/jorel/commandapi/test/MockNMS.java +++ b/commandapi-platforms/commandapi-bukkit/commandapi-bukkit-test/commandapi-bukkit-test-impl-1.20/src/main/java/dev/jorel/commandapi/test/MockNMS.java @@ -9,9 +9,7 @@ import com.mojang.brigadier.CommandDispatcher; import com.mojang.brigadier.context.CommandContext; import dev.jorel.commandapi.*; -import dev.jorel.commandapi.commandsenders.AbstractCommandSender; -import dev.jorel.commandapi.commandsenders.BukkitCommandSender; -import dev.jorel.commandapi.commandsenders.BukkitPlayer; +import dev.jorel.commandapi.wrappers.NativeProxyCommandSender; import net.minecraft.SharedConstants; import net.minecraft.advancements.Advancement; import net.minecraft.commands.CommandFunction; @@ -260,8 +258,7 @@ public SimpleCommandMap getSimpleCommandMap() { @SuppressWarnings({ "deprecation", "unchecked" }) @Override - public CommandSourceStack getBrigadierSourceFromCommandSender(AbstractCommandSender senderWrapper) { - CommandSender sender = senderWrapper.getSource(); + public CommandSourceStack getBrigadierSourceFromCommandSender(CommandSender sender) { CommandSourceStack css = Mockito.mock(CommandSourceStack.class); Mockito.when(css.getBukkitSender()).thenReturn(sender); @@ -357,6 +354,11 @@ public CommandSourceStack getBrigadierSourceFromCommandSender(AbstractCommandSen return css; } + @Override + public NativeProxyCommandSender getNativeProxyCommandSender(CommandContext cmdCtx) { + return baseNMS.getNativeProxyCommandSender(cmdCtx); + } + @SuppressWarnings({ "rawtypes", "unchecked" }) @Override public void createDispatcherFile(File file, CommandDispatcher dispatcher) @@ -557,7 +559,7 @@ public void addFunction(NamespacedKey key, List commands) { } ResourceLocation resourceLocation = new ResourceLocation(key.toString()); - CommandSourceStack css = getBrigadierSourceFromCommandSender(new BukkitPlayer(Bukkit.getOnlinePlayers().iterator().next())); + CommandSourceStack css = getBrigadierSourceFromCommandSender(Bukkit.getOnlinePlayers().iterator().next()); // So for very interesting reasons, Brigadier.getCommandDispatcher() // gives a different result in this method than using getBrigadierDispatcher() @@ -572,7 +574,7 @@ public void addTag(NamespacedKey key, List> commands) { } ResourceLocation resourceLocation = new ResourceLocation(key.toString()); - CommandSourceStack css = getBrigadierSourceFromCommandSender(new BukkitPlayer(Bukkit.getOnlinePlayers().iterator().next())); + CommandSourceStack css = getBrigadierSourceFromCommandSender(Bukkit.getOnlinePlayers().iterator().next()); List tagFunctions = new ArrayList<>(); for(List functionCommands : commands) { @@ -595,7 +597,7 @@ public Player setupMockedCraftPlayer(String name) { Mockito.when(player.getWorld()).thenReturn(world); // Provide proper handle as VanillaCommandWrapper expects - CommandSourceStack css = getBrigadierSourceFromCommandSender(wrapCommandSender(player)); + CommandSourceStack css = getBrigadierSourceFromCommandSender(player); ServerPlayer handle = Mockito.mock(ServerPlayer.class); Mockito.when(handle.createCommandSourceStack()).thenReturn(css); @@ -655,17 +657,8 @@ public Collection getCriteria() { } @Override - public BukkitCommandSender getSenderForCommand(CommandContext cmdCtx, boolean forceNative) { - return baseNMS.getSenderForCommand(cmdCtx, forceNative); - } - - @Override - public BukkitCommandSender getCommandSenderFromCommandSource(CommandSourceStack clw) { - try { - return wrapCommandSender(clw.getBukkitSender()); - } catch (UnsupportedOperationException e) { - return null; - } + public CommandSender getCommandSenderFromCommandSource(CommandSourceStack clw) { + return baseNMS.getCommandSenderFromCommandSource(clw); } // @Override diff --git a/commandapi-platforms/commandapi-bukkit/commandapi-bukkit-test/commandapi-bukkit-test-tests/src/test/java/dev/jorel/commandapi/test/CommandConvertedTests.java b/commandapi-platforms/commandapi-bukkit/commandapi-bukkit-test/commandapi-bukkit-test-tests/src/test/java/dev/jorel/commandapi/test/CommandConvertedTests.java index c4d5c144dd..78df148dd0 100644 --- a/commandapi-platforms/commandapi-bukkit/commandapi-bukkit-test/commandapi-bukkit-test-tests/src/test/java/dev/jorel/commandapi/test/CommandConvertedTests.java +++ b/commandapi-platforms/commandapi-bukkit/commandapi-bukkit-test/commandapi-bukkit-test-tests/src/test/java/dev/jorel/commandapi/test/CommandConvertedTests.java @@ -10,7 +10,6 @@ import be.seeseemelk.mockbukkit.MockBukkit; import be.seeseemelk.mockbukkit.entity.PlayerMock; import dev.jorel.commandapi.Converter; -import dev.jorel.commandapi.wrappers.NativeProxyCommandSender; /** * Tests for converted commands @@ -42,8 +41,7 @@ void test1() { Converter.convert(plugin, "mycommand"); PlayerMock player = server.addPlayer(); - NativeProxyCommandSender nativeProxyMockedPlayer = new NativeProxyCommandSender(player, player, player.getLocation(), player.getWorld()); - server.dispatchBrigadierCommand(nativeProxyMockedPlayer, "mycommand"); + server.dispatchBrigadierCommand(player, "mycommand"); assertEquals("hello", player.nextMessage()); } diff --git a/commandapi-platforms/commandapi-bukkit/commandapi-bukkit-test/commandapi-bukkit-test-tests/src/test/java/dev/jorel/commandapi/test/CommandRegistrationTests.java b/commandapi-platforms/commandapi-bukkit/commandapi-bukkit-test/commandapi-bukkit-test-tests/src/test/java/dev/jorel/commandapi/test/CommandRegistrationTests.java index b04ac5c9b1..7f81f5f604 100644 --- a/commandapi-platforms/commandapi-bukkit/commandapi-bukkit-test/commandapi-bukkit-test-tests/src/test/java/dev/jorel/commandapi/test/CommandRegistrationTests.java +++ b/commandapi-platforms/commandapi-bukkit/commandapi-bukkit-test/commandapi-bukkit-test-tests/src/test/java/dev/jorel/commandapi/test/CommandRegistrationTests.java @@ -14,7 +14,7 @@ import dev.jorel.commandapi.exceptions.GreedyArgumentException; import dev.jorel.commandapi.exceptions.InvalidCommandNameException; import dev.jorel.commandapi.exceptions.MissingCommandExecutorException; -import dev.jorel.commandapi.executors.PlayerExecutionInfo; +import dev.jorel.commandapi.executors.NormalExecutorInfo; import org.junit.jupiter.api.AfterEach; import org.junit.jupiter.api.BeforeEach; @@ -380,8 +380,8 @@ void testCommandConflictException() { Player player = server.addPlayer(); // The executor we register first should not be overwritten and should always run - PlayerExecutionInfo firstExecutor = info -> {results.set("first");}; - PlayerExecutionInfo secondExecutor = info -> {results.set("second");}; + NormalExecutorInfo firstExecutor = info -> {results.set("first");}; + NormalExecutorInfo secondExecutor = info -> {results.set("second");}; // No arguments new CommandAPICommand("noArguments") diff --git a/commandapi-platforms/commandapi-bukkit/commandapi-bukkit-test/commandapi-bukkit-test-tests/src/test/java/dev/jorel/commandapi/test/RegisteredCommandTestBase.java b/commandapi-platforms/commandapi-bukkit/commandapi-bukkit-test/commandapi-bukkit-test-tests/src/test/java/dev/jorel/commandapi/test/RegisteredCommandTestBase.java index cb0c316e78..212aaaae0b 100644 --- a/commandapi-platforms/commandapi-bukkit/commandapi-bukkit-test/commandapi-bukkit-test-tests/src/test/java/dev/jorel/commandapi/test/RegisteredCommandTestBase.java +++ b/commandapi-platforms/commandapi-bukkit/commandapi-bukkit-test/commandapi-bukkit-test-tests/src/test/java/dev/jorel/commandapi/test/RegisteredCommandTestBase.java @@ -76,7 +76,7 @@ public static List> children(NodeBuilder... children) { private String helpString; private CommandPermission permission = CommandPermission.NONE; - private Predicate requirements = sender -> true; + private Predicate requirements = CommandPermission.TRUE(); private final List> children; diff --git a/commandapi-platforms/commandapi-bukkit/commandapi-bukkit-test/commandapi-bukkit-test-tests/src/test/java/dev/jorel/commandapi/test/TestBase.java b/commandapi-platforms/commandapi-bukkit/commandapi-bukkit-test/commandapi-bukkit-test-tests/src/test/java/dev/jorel/commandapi/test/TestBase.java index 71b22d7ba8..29a418b170 100644 --- a/commandapi-platforms/commandapi-bukkit/commandapi-bukkit-test/commandapi-bukkit-test-tests/src/test/java/dev/jorel/commandapi/test/TestBase.java +++ b/commandapi-platforms/commandapi-bukkit/commandapi-bukkit-test/commandapi-bukkit-test-tests/src/test/java/dev/jorel/commandapi/test/TestBase.java @@ -17,6 +17,7 @@ import org.bukkit.command.Command; import org.bukkit.command.CommandMap; import org.bukkit.command.CommandSender; +import org.bukkit.entity.Player; import org.bukkit.event.server.ServerLoadEvent; import org.bukkit.plugin.java.JavaPlugin; import org.bukkit.potion.PotionEffectType; @@ -35,7 +36,7 @@ import dev.jorel.commandapi.MCVersion; import dev.jorel.commandapi.PaperImplementations; import dev.jorel.commandapi.SafeVarHandle; -import dev.jorel.commandapi.executors.PlayerCommandExecutor; +import dev.jorel.commandapi.executors.NormalExecutor; import static org.junit.jupiter.api.Assertions.*; @@ -91,7 +92,7 @@ public void enableServer() { assertFalse(CommandAPI.canRegister()); } - public static final PlayerCommandExecutor P_EXEC = (player, args) -> {}; + public static final NormalExecutor P_EXEC = (player, args) -> {}; private void resetAllPotions() { PotionEffectType[] arr = MockPlatform.getFieldAs(PotionEffectType.class, "byId", null, PotionEffectType[].class); diff --git a/commandapi-platforms/commandapi-bukkit/commandapi-bukkit-test/commandapi-bukkit-test-tests/src/test/java/dev/jorel/commandapi/test/arguments/ArgumentTests.java b/commandapi-platforms/commandapi-bukkit/commandapi-bukkit-test/commandapi-bukkit-test-tests/src/test/java/dev/jorel/commandapi/test/arguments/ArgumentTests.java index c476b14705..3fbc66b74f 100644 --- a/commandapi-platforms/commandapi-bukkit/commandapi-bukkit-test/commandapi-bukkit-test-tests/src/test/java/dev/jorel/commandapi/test/arguments/ArgumentTests.java +++ b/commandapi-platforms/commandapi-bukkit/commandapi-bukkit-test/commandapi-bukkit-test-tests/src/test/java/dev/jorel/commandapi/test/arguments/ArgumentTests.java @@ -8,6 +8,7 @@ import java.util.concurrent.ThreadLocalRandom; import org.bukkit.Location; +import org.bukkit.command.CommandSender; import org.bukkit.entity.Player; import org.junit.jupiter.api.AfterEach; import org.junit.jupiter.api.BeforeEach; @@ -26,7 +27,7 @@ import dev.jorel.commandapi.arguments.LocationType; import dev.jorel.commandapi.arguments.PlayerArgument; import dev.jorel.commandapi.arguments.StringArgument; -import dev.jorel.commandapi.executors.CommandExecutor; +import dev.jorel.commandapi.executors.NormalExecutor; import dev.jorel.commandapi.test.Mut; import dev.jorel.commandapi.test.TestBase; import dev.jorel.commandapi.wrappers.Location2D; @@ -262,7 +263,7 @@ void executionTestWithCommandTree() { assertEquals("222", result.get()); } - private CommandExecutor givePosition(String pos, Mut result) { + private NormalExecutor givePosition(String pos, Mut result) { return (sender, args) -> result.set(pos); } diff --git a/commandapi-platforms/commandapi-velocity/commandapi-velocity-core/src/main/java/dev/jorel/commandapi/CommandAPIVelocity.java b/commandapi-platforms/commandapi-velocity/commandapi-velocity-core/src/main/java/dev/jorel/commandapi/CommandAPIVelocity.java index fedbaaf446..af6cac6e1d 100644 --- a/commandapi-platforms/commandapi-velocity/commandapi-velocity-core/src/main/java/dev/jorel/commandapi/CommandAPIVelocity.java +++ b/commandapi-platforms/commandapi-velocity/commandapi-velocity-core/src/main/java/dev/jorel/commandapi/CommandAPIVelocity.java @@ -6,7 +6,6 @@ import com.google.gson.JsonObject; import com.mojang.brigadier.CommandDispatcher; import com.mojang.brigadier.arguments.ArgumentType; -import com.mojang.brigadier.context.CommandContext; import com.mojang.brigadier.suggestion.SuggestionProvider; import com.mojang.brigadier.suggestion.Suggestions; import com.mojang.brigadier.tree.ArgumentCommandNode; @@ -16,12 +15,10 @@ import com.velocitypowered.api.command.CommandManager; import com.velocitypowered.api.command.CommandSource; import com.velocitypowered.api.proxy.ConsoleCommandSource; -import com.velocitypowered.api.proxy.Player; import dev.jorel.commandapi.arguments.Argument; import dev.jorel.commandapi.arguments.LiteralArgument; import dev.jorel.commandapi.arguments.MultiLiteralArgument; import dev.jorel.commandapi.arguments.SuggestionProviders; -import dev.jorel.commandapi.commandsenders.*; import org.apache.logging.log4j.LogManager; import java.io.File; @@ -30,6 +27,8 @@ import java.nio.charset.StandardCharsets; import java.util.Collection; import java.util.List; +import java.util.Optional; +import java.util.function.Predicate; public class CommandAPIVelocity implements CommandAPIPlatform, CommandSource, CommandSource> { @@ -164,31 +163,15 @@ public CommandAPILogger getLogger() { return CommandAPILogger.fromApacheLog4jLogger(LogManager.getLogger("CommandAPI")); } + // Velocity's CommandSender and Source are the same, so these two methods are easy @Override - public VelocityCommandSender getSenderForCommand(CommandContext cmdCtx, boolean forceNative) { - // Velocity doesn't have proxy senders, so nothing needs to be done with forceNative - return getCommandSenderFromCommandSource(cmdCtx.getSource()); + public CommandSource getCommandSenderFromCommandSource(CommandSource commandSource) { + return commandSource; } @Override - public VelocityCommandSender getCommandSenderFromCommandSource(CommandSource cs) { - // Given a Brigadier CommandContext source (result of CommandContext.getSource), - // we need to convert that to an AbstractCommandSender. - if (cs instanceof ConsoleCommandSource ccs) - return new VelocityConsoleCommandSender(ccs); - if (cs instanceof Player p) - return new VelocityPlayer(p); - throw new IllegalArgumentException("Unknown CommandSource: " + cs); - } - - @Override - public VelocityCommandSender wrapCommandSender(CommandSource commandSource) { - return getCommandSenderFromCommandSource(commandSource); - } - - @Override - public CommandSource getBrigadierSourceFromCommandSender(AbstractCommandSender sender) { - return sender.getSource(); + public CommandSource getBrigadierSourceFromCommandSender(CommandSource sender) { + return sender; } @Override @@ -242,7 +225,7 @@ public void reloadDataPacks() { } @Override - public void updateRequirements(AbstractPlayer player) { + public void updateRequirements(CommandSource player) { // TODO Auto-generated method stub } @@ -255,4 +238,30 @@ public Argument newConcreteMultiLiteralArgument(String nodeName, String[ public Argument newConcreteLiteralArgument(String nodeName, String literal) { return new LiteralArgument(nodeName, literal); } + + @Override + public Predicate getPermissionCheck(CommandPermission permission) { + final Predicate senderCheck; + + if (permission.equals(CommandPermission.NONE)) { + // No permissions always passes + senderCheck = CommandPermission.TRUE(); + } else if (permission.equals(CommandPermission.OP)) { + // Console is op, and other senders (Players) are not + senderCheck = ConsoleCommandSource.class::isInstance; + } else { + Optional permissionStringWrapper = permission.getPermission(); + if (permissionStringWrapper.isPresent()) { + String permissionString = permissionStringWrapper.get(); + // check permission + senderCheck = sender -> sender.hasPermission(permissionString); + } else { + // No permission always passes + senderCheck = CommandPermission.TRUE(); + } + } + + // Negate if specified + return permission.isNegated() ? senderCheck.negate() : senderCheck; + } } diff --git a/commandapi-platforms/commandapi-velocity/commandapi-velocity-core/src/main/java/dev/jorel/commandapi/VelocityExecutable.java b/commandapi-platforms/commandapi-velocity/commandapi-velocity-core/src/main/java/dev/jorel/commandapi/VelocityExecutable.java index efd0c80af6..412a6cb7e2 100644 --- a/commandapi-platforms/commandapi-velocity/commandapi-velocity-core/src/main/java/dev/jorel/commandapi/VelocityExecutable.java +++ b/commandapi-platforms/commandapi-velocity/commandapi-velocity-core/src/main/java/dev/jorel/commandapi/VelocityExecutable.java @@ -1,9 +1,16 @@ package dev.jorel.commandapi; import com.velocitypowered.api.command.CommandSource; -import dev.jorel.commandapi.commandsenders.VelocityCommandSender; -import dev.jorel.commandapi.exceptions.WrapperCommandSyntaxException; -import dev.jorel.commandapi.executors.*; +import com.velocitypowered.api.proxy.ConsoleCommandSource; +import com.velocitypowered.api.proxy.Player; + +import dev.jorel.commandapi.executors.ExecutorType; +import dev.jorel.commandapi.executors.NormalExecutor; +import dev.jorel.commandapi.executors.NormalExecutorInfo; +import dev.jorel.commandapi.executors.ResultingExecutor; +import dev.jorel.commandapi.executors.ResultingExecutorInfo; +import dev.jorel.commandapi.executors.VelocityNormalTypedExecutor; +import dev.jorel.commandapi.executors.VelocityResultingTypedExecutor; public interface VelocityExecutable> extends PlatformExecutable { // Regular command executor @@ -11,116 +18,58 @@ public interface VelocityExecutable> exten /** * Adds an executor to the current command builder * - * @param executor A lambda of type (CommandSource, Object[]) -> () that will be executed when the command is run + * @param executor A lambda of type ExecutionInfo<CommandSource, CommandSource> -> () that will be executed when the command is run * @param types A list of executor types to use this executes method for. * @return this command builder */ - default Impl executes(CommandExecutor executor, ExecutorType... types) { + default Impl executes(NormalExecutorInfo executor, ExecutorType... types) { if (types == null || types.length == 0) { - getExecutor().addNormalExecutor(executor); - } else { - for (ExecutorType type : types) { - getExecutor().addNormalExecutor(new CommandExecutor() { - @Override - public void run(CommandSource sender, CommandArguments args) throws WrapperCommandSyntaxException { - executor.executeWith(new VelocityExecutionInfo<>(sender, CommandAPIVelocity.get().wrapCommandSender(sender), args)); - } - - @Override - public ExecutorType getType() { - return type; - } - }); - } + types = new ExecutorType[]{ExecutorType.ALL}; } + + getExecutor().addExecutor(new VelocityNormalTypedExecutor<>(executor, types)); return instance(); } /** * Adds an executor to the current command builder * - * @param executor A lambda of type (ExecutionInfo<CommandSender, BukkitCommandSender<? extends CommandSender>>) -> () that will be executed when the command is run + * @param executor A lambda of type (CommandSource, CommandArguments) -> () that will be executed when the command is run * @param types A list of executor types to use this executes method for. * @return this command builder */ - default Impl executes(CommandExecutionInfo executor, ExecutorType... types) { - if (types == null || types.length == 0) { - getExecutor().addNormalExecutor(executor); - } else { - for (ExecutorType type : types) { - getExecutor().addNormalExecutor(new CommandExecutionInfo() { - - @Override - public void run(ExecutionInfo> info) throws WrapperCommandSyntaxException { - executor.executeWith(info); - } - - @Override - public ExecutorType getType() { - return type; - } - }); - } - } - return instance(); + default Impl executes(NormalExecutor executor, ExecutorType... types) { + // While we can cast directly to `NormalExecutorInfo` (because `NormalExecutor` extends it), this method + // is necessary to help Java identify the expression signature of user defined lambdas. + // The same applies for the rest of the executes methods + return executes((NormalExecutorInfo) executor, types); } /** * Adds an executor to the current command builder * - * @param executor A lambda of type (CommandSource, Object[]) -> int that will be executed when the command is run + * @param executor A lambda of type ExecutionInfo<CommandSource, CommandSource> -> int that will be executed when the command is run * @param types A list of executor types to use this executes method for. * @return this command builder */ - default Impl executes(ResultingCommandExecutor executor, ExecutorType... types) { + default Impl executes(ResultingExecutorInfo executor, ExecutorType... types) { if (types == null || types.length == 0) { - getExecutor().addResultingExecutor(executor); - } else { - for (ExecutorType type : types) { - getExecutor().addResultingExecutor(new ResultingCommandExecutor() { - - @Override - public int run(CommandSource sender, CommandArguments args) throws WrapperCommandSyntaxException { - return executor.executeWith(new VelocityExecutionInfo<>(sender, CommandAPIVelocity.get().wrapCommandSender(sender), args)); - } - - @Override - public ExecutorType getType() { - return type; - } - }); - } + types = new ExecutorType[]{ExecutorType.ALL}; } + + getExecutor().addExecutor(new VelocityResultingTypedExecutor<>(executor, types)); return instance(); } /** * Adds an executor to the current command builder * - * @param executor A lambda of type (ExecutionInfo<CommandSender, VelocityCommandSender<? extends CommandSender>>) -> () that will be executed when the command is run + * @param executor A lambda of type (CommandSource, CommandArguments) -> int that will be executed when the command is run * @param types A list of executor types to use this executes method for. * @return this command builder */ - default Impl executes(ResultingCommandExecutionInfo executor, ExecutorType... types) { - if (types == null || types.length == 0) { - getExecutor().addResultingExecutor(executor); - } else { - for (ExecutorType type : types) { - getExecutor().addResultingExecutor(new ResultingCommandExecutionInfo() { - - @Override - public int run(ExecutionInfo> info) throws WrapperCommandSyntaxException { - return executor.executeWith(info); - } - - @Override - public ExecutorType getType() { - return type; - } - }); - } - } - return instance(); + default Impl executes(ResultingExecutor executor, ExecutorType... types) { + return executes((ResultingExecutorInfo) executor, types); } // Player command executor @@ -128,45 +77,43 @@ public ExecutorType getType() { /** * Adds an executor to the current command builder * - * @param executor A lambda of type (Player, CommandArguments) -> () that will be executed when the command is run + * @param executor A lambda of type ExecutionInfo<Player, CommandSource> -> () that will be executed when the command is run * @return this command builder */ - default Impl executesPlayer(PlayerCommandExecutor executor) { - getExecutor().addNormalExecutor(executor); + default Impl executesPlayer(NormalExecutorInfo executor) { + getExecutor().addExecutor(new VelocityNormalTypedExecutor<>(executor, ExecutorType.PLAYER)); return instance(); } /** * Adds an executor to the current command builder * - * @param executor A lambda of type (ExecutionInfo) -> () that will be executed when the command is run + * @param executor A lambda of type (Player, CommandArguments) -> () that will be executed when the command is run * @return this command builder */ - default Impl executesPlayer(PlayerExecutionInfo executor) { - getExecutor().addNormalExecutor(executor); - return instance(); + default Impl executesPlayer(NormalExecutor executor) { + return executesPlayer((NormalExecutorInfo) executor); } /** * Adds an executor to the current command builder * - * @param executor A lambda of type (Player, CommandArguments) -> int that will be executed when the command is run + * @param executor A lambda of type ExecutionInfo<Player, CommandSource> -> int that will be executed when the command is run * @return this command builder */ - default Impl executesPlayer(PlayerResultingCommandExecutor executor) { - getExecutor().addResultingExecutor(executor); + default Impl executesPlayer(ResultingExecutorInfo executor) { + getExecutor().addExecutor(new VelocityResultingTypedExecutor<>(executor, ExecutorType.PLAYER)); return instance(); } /** * Adds an executor to the current command builder * - * @param executor A lambda of type (ExecutionInfo) -> int that will be executed when the command is run + * @param executor A lambda of type (Player, CommandArguments) -> int that will be executed when the command is run * @return this command builder */ - default Impl executesPlayer(PlayerResultingExecutionInfo executor) { - getExecutor().addResultingExecutor(executor); - return instance(); + default Impl executesPlayer(ResultingExecutor executor) { + return executesPlayer((ResultingExecutorInfo) executor); } // Console command executor @@ -174,44 +121,44 @@ default Impl executesPlayer(PlayerResultingExecutionInfo executor) { /** * Adds an executor to the current command builder * - * @param executor A lambda of type (ConsoleCommandSource, CommandArguments) -> () that will be executed when the command is run + * @param executor A lambda of type ExecutionInfo<ConsoleCommandSource, CommandSource> -> () that will be executed when the command is run * @return this command builder */ - default Impl executesConsole(ConsoleCommandExecutor executor) { - getExecutor().addNormalExecutor(executor); + default Impl executesConsole(NormalExecutorInfo executor) { + getExecutor().addExecutor(new VelocityNormalTypedExecutor<>(executor, ExecutorType.CONSOLE)); return instance(); } /** * Adds an executor to the current command builder * - * @param executor A lambda of type (ExecutionInfo) -> () that will be executed when the command is run + * @param executor A lambda of type (ConsoleCommandSource, CommandArguments) -> () that will be executed when the command is run * @return this command builder */ - default Impl executesConsole(ConsoleExecutionInfo executor) { - getExecutor().addNormalExecutor(executor); - return instance(); + default Impl executesConsole(NormalExecutor executor) { + return executesConsole((NormalExecutorInfo) executor); } /** * Adds an executor to the current command builder * - * @param executor A lambda of type (ConsoleCommandSource, CommandArguments) -> int that will be executed when the command is run + * @param executor A lambda of type ExecutionInfo<ConsoleCommandSource, CommandSource> -> int or + * (ConsoleCommandSource, CommandArguments) -> int that will be executed when the command is run * @return this command builder */ - default Impl executesConsole(ConsoleResultingCommandExecutor executor) { - getExecutor().addResultingExecutor(executor); + default Impl executesConsole(ResultingExecutorInfo executor) { + getExecutor().addExecutor(new VelocityResultingTypedExecutor<>(executor, ExecutorType.CONSOLE)); return instance(); } /** * Adds an executor to the current command builder * - * @param executor A lambda of type (ExecutionInfo) -> int that will be executed when the command is run + * @param executor A lambda of type ExecutionInfo<ConsoleCommandSource> -> int or + * (ConsoleCommandSource, CommandArguments) -> int that will be executed when the command is run * @return this command builder */ - default Impl executesConsole(ConsoleResultingExecutionInfo executor) { - getExecutor().addResultingExecutor(executor); - return instance(); + default Impl executesConsole(ResultingExecutor executor) { + return executesConsole((ResultingExecutorInfo) executor); } } diff --git a/commandapi-platforms/commandapi-velocity/commandapi-velocity-core/src/main/java/dev/jorel/commandapi/commandsenders/VelocityCommandSender.java b/commandapi-platforms/commandapi-velocity/commandapi-velocity-core/src/main/java/dev/jorel/commandapi/commandsenders/VelocityCommandSender.java deleted file mode 100644 index f7d50c272e..0000000000 --- a/commandapi-platforms/commandapi-velocity/commandapi-velocity-core/src/main/java/dev/jorel/commandapi/commandsenders/VelocityCommandSender.java +++ /dev/null @@ -1,6 +0,0 @@ -package dev.jorel.commandapi.commandsenders; - -import com.velocitypowered.api.command.CommandSource; - -public interface VelocityCommandSender extends AbstractCommandSender { -} diff --git a/commandapi-platforms/commandapi-velocity/commandapi-velocity-core/src/main/java/dev/jorel/commandapi/commandsenders/VelocityConsoleCommandSender.java b/commandapi-platforms/commandapi-velocity/commandapi-velocity-core/src/main/java/dev/jorel/commandapi/commandsenders/VelocityConsoleCommandSender.java deleted file mode 100644 index 9da55c3726..0000000000 --- a/commandapi-platforms/commandapi-velocity/commandapi-velocity-core/src/main/java/dev/jorel/commandapi/commandsenders/VelocityConsoleCommandSender.java +++ /dev/null @@ -1,27 +0,0 @@ -package dev.jorel.commandapi.commandsenders; -import com.velocitypowered.api.proxy.ConsoleCommandSource; - -public class VelocityConsoleCommandSender implements AbstractConsoleCommandSender, VelocityCommandSender { - - private final ConsoleCommandSource source; - - public VelocityConsoleCommandSender(ConsoleCommandSource source) { - this.source = source; - } - - @Override - public boolean hasPermission(String permissionNode) { - return this.source.hasPermission(permissionNode); - } - - @Override - public boolean isOp() { - return true; - } - - @Override - public ConsoleCommandSource getSource() { - return this.source; - } - -} diff --git a/commandapi-platforms/commandapi-velocity/commandapi-velocity-core/src/main/java/dev/jorel/commandapi/commandsenders/VelocityPlayer.java b/commandapi-platforms/commandapi-velocity/commandapi-velocity-core/src/main/java/dev/jorel/commandapi/commandsenders/VelocityPlayer.java deleted file mode 100644 index b24476db23..0000000000 --- a/commandapi-platforms/commandapi-velocity/commandapi-velocity-core/src/main/java/dev/jorel/commandapi/commandsenders/VelocityPlayer.java +++ /dev/null @@ -1,27 +0,0 @@ -package dev.jorel.commandapi.commandsenders; -import com.velocitypowered.api.proxy.Player; - -public class VelocityPlayer implements AbstractPlayer, VelocityCommandSender { - - private final Player player; - - public VelocityPlayer(Player player) { - this.player = player; - } - - @Override - public boolean hasPermission(String permissionNode) { - return this.player.hasPermission(permissionNode); - } - - @Override - public boolean isOp() { - return false; - } - - @Override - public Player getSource() { - return this.player; - } - -} diff --git a/commandapi-platforms/commandapi-velocity/commandapi-velocity-core/src/main/java/dev/jorel/commandapi/executors/CommandExecutionInfo.java b/commandapi-platforms/commandapi-velocity/commandapi-velocity-core/src/main/java/dev/jorel/commandapi/executors/CommandExecutionInfo.java deleted file mode 100644 index e95014ac02..0000000000 --- a/commandapi-platforms/commandapi-velocity/commandapi-velocity-core/src/main/java/dev/jorel/commandapi/executors/CommandExecutionInfo.java +++ /dev/null @@ -1,28 +0,0 @@ -package dev.jorel.commandapi.executors; - -import com.velocitypowered.api.command.CommandSource; -import dev.jorel.commandapi.commandsenders.VelocityCommandSender; -import dev.jorel.commandapi.exceptions.WrapperCommandSyntaxException; - -@FunctionalInterface -public interface CommandExecutionInfo extends NormalExecutor> { - - /** - * Executes the command. - * - * @param info The ExecutionInfo for this command - * @throws WrapperCommandSyntaxException if an error occurs during the execution of this command - */ - void run(ExecutionInfo> info) throws WrapperCommandSyntaxException; - - /** - * Returns the type of the sender of the current executor. - * - * @return the type of the sender of the current executor - */ - @Override - default ExecutorType getType() { - return ExecutorType.ALL; - } - -} diff --git a/commandapi-platforms/commandapi-velocity/commandapi-velocity-core/src/main/java/dev/jorel/commandapi/executors/CommandExecutor.java b/commandapi-platforms/commandapi-velocity/commandapi-velocity-core/src/main/java/dev/jorel/commandapi/executors/CommandExecutor.java deleted file mode 100644 index dc86278b19..0000000000 --- a/commandapi-platforms/commandapi-velocity/commandapi-velocity-core/src/main/java/dev/jorel/commandapi/executors/CommandExecutor.java +++ /dev/null @@ -1,39 +0,0 @@ -package dev.jorel.commandapi.executors; - -import com.velocitypowered.api.command.CommandSource; -import dev.jorel.commandapi.commandsenders.VelocityCommandSender; -import dev.jorel.commandapi.exceptions.WrapperCommandSyntaxException; - -/** - * A normal CommandExecutor for a CommandSource - */ -@FunctionalInterface -public interface CommandExecutor extends NormalExecutor> { - - /** - * The code to run when this command is performed - * - * @param sender The sender of this command (a player, the console etc.) - * @param args The arguments given to this command. - */ - void run(CommandSource sender, CommandArguments args) throws WrapperCommandSyntaxException; - - /** - * The code to run when this command is performed - * - * @param info The ExecutionInfo for this command - */ - @Override - default void run(ExecutionInfo> info) throws WrapperCommandSyntaxException { - this.run(info.sender(), info.args()); - } - - /** - * Returns the type of the sender of the current executor. - * @return the type of the sender of the current executor - */ - @Override - default ExecutorType getType() { - return ExecutorType.ALL; - } -} diff --git a/commandapi-platforms/commandapi-velocity/commandapi-velocity-core/src/main/java/dev/jorel/commandapi/executors/ConsoleCommandExecutor.java b/commandapi-platforms/commandapi-velocity/commandapi-velocity-core/src/main/java/dev/jorel/commandapi/executors/ConsoleCommandExecutor.java deleted file mode 100644 index 84dc4b8e4d..0000000000 --- a/commandapi-platforms/commandapi-velocity/commandapi-velocity-core/src/main/java/dev/jorel/commandapi/executors/ConsoleCommandExecutor.java +++ /dev/null @@ -1,59 +0,0 @@ -/******************************************************************************* - * Copyright 2018, 2020 Jorel Ali (Skepter) - MIT License - * - * Permission is hereby granted, free of charge, to any person obtaining a copy of - * this software and associated documentation files (the "Software"), to deal in - * the Software without restriction, including without limitation the rights to - * use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of - * the Software, and to permit persons to whom the Software is furnished to do so, - * subject to the following conditions: - * - * The above copyright notice and this permission notice shall be included in all - * copies or substantial portions of the Software. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR - * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS - * FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR - * COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER - * IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN - * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. - *******************************************************************************/ -package dev.jorel.commandapi.executors; - -import com.velocitypowered.api.proxy.ConsoleCommandSource; -import dev.jorel.commandapi.commandsenders.VelocityConsoleCommandSender; -import dev.jorel.commandapi.exceptions.WrapperCommandSyntaxException; - -/** - * A normal command executor for a ConsoleCommandSender - */ -@FunctionalInterface -public interface ConsoleCommandExecutor extends NormalExecutor { - - /** - * The code to run when this command is performed - * - * @param sender The sender of this command (a player, the console etc.) - * @param args The arguments given to this command. - */ - void run(ConsoleCommandSource sender, CommandArguments args) throws WrapperCommandSyntaxException; - - /** - * The code to run when this command is performed - * - * @param info The ExecutionInfo for this command - */ - @Override - default void run(ExecutionInfo info) throws WrapperCommandSyntaxException { - this.run(info.sender(), info.args()); - } - - /** - * Returns the type of the sender of the current executor. - * @return the type of the sender of the current executor - */ - @Override - default ExecutorType getType() { - return ExecutorType.CONSOLE; - } -} diff --git a/commandapi-platforms/commandapi-velocity/commandapi-velocity-core/src/main/java/dev/jorel/commandapi/executors/ConsoleExecutionInfo.java b/commandapi-platforms/commandapi-velocity/commandapi-velocity-core/src/main/java/dev/jorel/commandapi/executors/ConsoleExecutionInfo.java deleted file mode 100644 index c54a394717..0000000000 --- a/commandapi-platforms/commandapi-velocity/commandapi-velocity-core/src/main/java/dev/jorel/commandapi/executors/ConsoleExecutionInfo.java +++ /dev/null @@ -1,28 +0,0 @@ -package dev.jorel.commandapi.executors; - -import com.velocitypowered.api.proxy.ConsoleCommandSource; -import dev.jorel.commandapi.commandsenders.VelocityConsoleCommandSender; -import dev.jorel.commandapi.exceptions.WrapperCommandSyntaxException; - -@FunctionalInterface -public interface ConsoleExecutionInfo extends NormalExecutor { - - /** - * Executes the command. - * - * @param info The ExecutionInfo for this command - * @throws WrapperCommandSyntaxException if an error occurs during the execution of this command - */ - void run(ExecutionInfo info) throws WrapperCommandSyntaxException; - - /** - * Returns the type of the sender of the current executor. - * - * @return the type of the sender of the current executor - */ - @Override - default ExecutorType getType() { - return ExecutorType.ALL; - } - -} diff --git a/commandapi-platforms/commandapi-velocity/commandapi-velocity-core/src/main/java/dev/jorel/commandapi/executors/ConsoleResultingCommandExecutor.java b/commandapi-platforms/commandapi-velocity/commandapi-velocity-core/src/main/java/dev/jorel/commandapi/executors/ConsoleResultingCommandExecutor.java deleted file mode 100644 index 07e48f8052..0000000000 --- a/commandapi-platforms/commandapi-velocity/commandapi-velocity-core/src/main/java/dev/jorel/commandapi/executors/ConsoleResultingCommandExecutor.java +++ /dev/null @@ -1,59 +0,0 @@ -/******************************************************************************* - * Copyright 2018, 2020 Jorel Ali (Skepter) - MIT License - * - * Permission is hereby granted, free of charge, to any person obtaining a copy of - * this software and associated documentation files (the "Software"), to deal in - * the Software without restriction, including without limitation the rights to - * use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of - * the Software, and to permit persons to whom the Software is furnished to do so, - * subject to the following conditions: - * - * The above copyright notice and this permission notice shall be included in all - * copies or substantial portions of the Software. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR - * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS - * FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR - * COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER - * IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN - * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. - *******************************************************************************/ -package dev.jorel.commandapi.executors; - -import com.velocitypowered.api.proxy.ConsoleCommandSource; -import dev.jorel.commandapi.commandsenders.VelocityConsoleCommandSender; -import dev.jorel.commandapi.exceptions.WrapperCommandSyntaxException; - -/** - * A resulting command executor for a ConsoleCommandSender - */ -@FunctionalInterface -public interface ConsoleResultingCommandExecutor extends ResultingExecutor { - - /** - * The code to run when this command is performed - * - * @param sender The sender of this command (a player, the console etc.) - * @param args The arguments given to this command. - */ - int run(ConsoleCommandSource sender, CommandArguments args) throws WrapperCommandSyntaxException; - - /** - * The code to run when this command is performed - * - * @param info The ExecutionInfo for this command - */ - @Override - default int run(ExecutionInfo info) throws WrapperCommandSyntaxException { - return this.run(info.sender(), info.args()); - } - - /** - * Returns the type of the sender of the current executor. - * @return the type of the sender of the current executor - */ - @Override - default ExecutorType getType() { - return ExecutorType.CONSOLE; - } -} diff --git a/commandapi-platforms/commandapi-velocity/commandapi-velocity-core/src/main/java/dev/jorel/commandapi/executors/ConsoleResultingExecutionInfo.java b/commandapi-platforms/commandapi-velocity/commandapi-velocity-core/src/main/java/dev/jorel/commandapi/executors/ConsoleResultingExecutionInfo.java deleted file mode 100644 index d558e64320..0000000000 --- a/commandapi-platforms/commandapi-velocity/commandapi-velocity-core/src/main/java/dev/jorel/commandapi/executors/ConsoleResultingExecutionInfo.java +++ /dev/null @@ -1,27 +0,0 @@ -package dev.jorel.commandapi.executors; - -import com.velocitypowered.api.proxy.ConsoleCommandSource; -import dev.jorel.commandapi.commandsenders.VelocityConsoleCommandSender; -import dev.jorel.commandapi.exceptions.WrapperCommandSyntaxException; - -@FunctionalInterface -public interface ConsoleResultingExecutionInfo extends ResultingExecutor { - - /** - * The code to run when this command is performed - * - * @param info The ExecutionInfo for this command - * @return the result of this command - * @throws WrapperCommandSyntaxException - */ - int run(ExecutionInfo info) throws WrapperCommandSyntaxException; - - /** - * Returns the type of the sender of the current executor. - * @return the type of the sender of the current executor - */ - @Override - default ExecutorType getType() { - return ExecutorType.ALL; - } -} diff --git a/commandapi-core/src/main/java/dev/jorel/commandapi/executors/ExecutorType.java b/commandapi-platforms/commandapi-velocity/commandapi-velocity-core/src/main/java/dev/jorel/commandapi/executors/ExecutorType.java similarity index 65% rename from commandapi-core/src/main/java/dev/jorel/commandapi/executors/ExecutorType.java rename to commandapi-platforms/commandapi-velocity/commandapi-velocity-core/src/main/java/dev/jorel/commandapi/executors/ExecutorType.java index e705d1eea0..24f209d0ad 100644 --- a/commandapi-core/src/main/java/dev/jorel/commandapi/executors/ExecutorType.java +++ b/commandapi-platforms/commandapi-velocity/commandapi-velocity-core/src/main/java/dev/jorel/commandapi/executors/ExecutorType.java @@ -20,53 +20,27 @@ *******************************************************************************/ package dev.jorel.commandapi.executors; +import com.velocitypowered.api.command.CommandSource; +import com.velocitypowered.api.proxy.ConsoleCommandSource; +import com.velocitypowered.api.proxy.Player; + /** * An enum representing the type of an executor */ public enum ExecutorType { /** - * An executor where the CommandSender is a Player + * An executor where the CommandSender is any {@link CommandSource} */ - PLAYER, + ALL, /** - * An executor where the CommandSender is an Entity - */ - ENTITY, - - /** - * An executor where the CommandSender is a ConsoleCommandSender - */ - CONSOLE, - - /** - * An executor where the CommandSender is a BlockCommandSender - */ - BLOCK, - - /** - * An executor where the CommandSender is any CommandSender + * An executor where the CommandSender is a {@link Player} */ - ALL, - - /** - * An executor where the CommandSender is a NativeProxyCommandSender - */ - PROXY, - - /** - * An executor where the CommandSender is (always) a NativeProxyCommandSender - */ - NATIVE, + PLAYER, /** - * An executor where the CommandSender is a RemoteConsoleCommandSender - */ - REMOTE, - - /** - * An executor where the CommandSender is a {@code io.papermc.paper.commands.FeedbackForwardingSender} + * An executor where the CommandSender is a {@link ConsoleCommandSource} */ - FEEDBACK_FORWARDING; + CONSOLE; } diff --git a/commandapi-platforms/commandapi-velocity/commandapi-velocity-core/src/main/java/dev/jorel/commandapi/executors/PlayerCommandExecutor.java b/commandapi-platforms/commandapi-velocity/commandapi-velocity-core/src/main/java/dev/jorel/commandapi/executors/PlayerCommandExecutor.java deleted file mode 100644 index 16efabfac3..0000000000 --- a/commandapi-platforms/commandapi-velocity/commandapi-velocity-core/src/main/java/dev/jorel/commandapi/executors/PlayerCommandExecutor.java +++ /dev/null @@ -1,59 +0,0 @@ -/******************************************************************************* - * Copyright 2018, 2020 Jorel Ali (Skepter) - MIT License - * - * Permission is hereby granted, free of charge, to any person obtaining a copy of - * this software and associated documentation files (the "Software"), to deal in - * the Software without restriction, including without limitation the rights to - * use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of - * the Software, and to permit persons to whom the Software is furnished to do so, - * subject to the following conditions: - * - * The above copyright notice and this permission notice shall be included in all - * copies or substantial portions of the Software. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR - * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS - * FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR - * COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER - * IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN - * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. - *******************************************************************************/ -package dev.jorel.commandapi.executors; - -import com.velocitypowered.api.proxy.Player; -import dev.jorel.commandapi.commandsenders.VelocityPlayer; -import dev.jorel.commandapi.exceptions.WrapperCommandSyntaxException; - -/** - * A normal command executor for a Player - */ -@FunctionalInterface -public interface PlayerCommandExecutor extends NormalExecutor { - - /** - * The code to run when this command is performed - * - * @param sender The sender of this command (a player, the console etc.) - * @param args The arguments given to this command. - */ - void run(Player sender, CommandArguments args) throws WrapperCommandSyntaxException; - - /** - * The code to run when this command is performed - * - * @param info The ExecutionInfo for this command - */ - @Override - default void run(ExecutionInfo info) throws WrapperCommandSyntaxException { - this.run(info.sender(), info.args()); - } - - /** - * Returns the type of the sender of the current executor. - * @return the type of the sender of the current executor - */ - @Override - default ExecutorType getType() { - return ExecutorType.PLAYER; - } -} diff --git a/commandapi-platforms/commandapi-velocity/commandapi-velocity-core/src/main/java/dev/jorel/commandapi/executors/PlayerExecutionInfo.java b/commandapi-platforms/commandapi-velocity/commandapi-velocity-core/src/main/java/dev/jorel/commandapi/executors/PlayerExecutionInfo.java deleted file mode 100644 index 92a30019ec..0000000000 --- a/commandapi-platforms/commandapi-velocity/commandapi-velocity-core/src/main/java/dev/jorel/commandapi/executors/PlayerExecutionInfo.java +++ /dev/null @@ -1,28 +0,0 @@ -package dev.jorel.commandapi.executors; - -import com.velocitypowered.api.proxy.Player; -import dev.jorel.commandapi.commandsenders.VelocityPlayer; -import dev.jorel.commandapi.exceptions.WrapperCommandSyntaxException; - -@FunctionalInterface -public interface PlayerExecutionInfo extends NormalExecutor { - - /** - * Executes the command. - * - * @param info The ExecutionInfo for this command - * @throws WrapperCommandSyntaxException if an error occurs during the execution of this command - */ - void run(ExecutionInfo info) throws WrapperCommandSyntaxException; - - /** - * Returns the type of the sender of the current executor. - * - * @return the type of the sender of the current executor - */ - @Override - default ExecutorType getType() { - return ExecutorType.ALL; - } - -} diff --git a/commandapi-platforms/commandapi-velocity/commandapi-velocity-core/src/main/java/dev/jorel/commandapi/executors/PlayerResultingCommandExecutor.java b/commandapi-platforms/commandapi-velocity/commandapi-velocity-core/src/main/java/dev/jorel/commandapi/executors/PlayerResultingCommandExecutor.java deleted file mode 100644 index 3ff4dfeda4..0000000000 --- a/commandapi-platforms/commandapi-velocity/commandapi-velocity-core/src/main/java/dev/jorel/commandapi/executors/PlayerResultingCommandExecutor.java +++ /dev/null @@ -1,59 +0,0 @@ -/******************************************************************************* - * Copyright 2018, 2020 Jorel Ali (Skepter) - MIT License - * - * Permission is hereby granted, free of charge, to any person obtaining a copy of - * this software and associated documentation files (the "Software"), to deal in - * the Software without restriction, including without limitation the rights to - * use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of - * the Software, and to permit persons to whom the Software is furnished to do so, - * subject to the following conditions: - * - * The above copyright notice and this permission notice shall be included in all - * copies or substantial portions of the Software. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR - * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS - * FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR - * COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER - * IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN - * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. - *******************************************************************************/ -package dev.jorel.commandapi.executors; - -import com.velocitypowered.api.proxy.Player; -import dev.jorel.commandapi.commandsenders.VelocityPlayer; -import dev.jorel.commandapi.exceptions.WrapperCommandSyntaxException; - -/** - * A resulting command executor for a Player - */ -@FunctionalInterface -public interface PlayerResultingCommandExecutor extends ResultingExecutor { - - /** - * The code to run when this command is performed - * - * @param sender The sender of this command (a player, the console etc.) - * @param args The arguments given to this command. - */ - int run(Player sender, CommandArguments args) throws WrapperCommandSyntaxException; - - /** - * The code to run when this command is performed - * - * @param info The ExecutionInfo for this command - */ - @Override - default int run(ExecutionInfo info) throws WrapperCommandSyntaxException { - return this.run(info.sender(), info.args()); - } - - /** - * Returns the type of the sender of the current executor. - * @return the type of the sender of the current executor - */ - @Override - default ExecutorType getType() { - return ExecutorType.PLAYER; - } -} diff --git a/commandapi-platforms/commandapi-velocity/commandapi-velocity-core/src/main/java/dev/jorel/commandapi/executors/PlayerResultingExecutionInfo.java b/commandapi-platforms/commandapi-velocity/commandapi-velocity-core/src/main/java/dev/jorel/commandapi/executors/PlayerResultingExecutionInfo.java deleted file mode 100644 index 8186f868ba..0000000000 --- a/commandapi-platforms/commandapi-velocity/commandapi-velocity-core/src/main/java/dev/jorel/commandapi/executors/PlayerResultingExecutionInfo.java +++ /dev/null @@ -1,27 +0,0 @@ -package dev.jorel.commandapi.executors; - -import com.velocitypowered.api.proxy.Player; -import dev.jorel.commandapi.commandsenders.VelocityPlayer; -import dev.jorel.commandapi.exceptions.WrapperCommandSyntaxException; - -@FunctionalInterface -public interface PlayerResultingExecutionInfo extends ResultingExecutor { - - /** - * The code to run when this command is performed - * - * @param info The ExecutionInfo for this command - * @return the result of this command - * @throws WrapperCommandSyntaxException - */ - int run(ExecutionInfo info) throws WrapperCommandSyntaxException; - - /** - * Returns the type of the sender of the current executor. - * @return the type of the sender of the current executor - */ - @Override - default ExecutorType getType() { - return ExecutorType.ALL; - } -} diff --git a/commandapi-platforms/commandapi-velocity/commandapi-velocity-core/src/main/java/dev/jorel/commandapi/executors/ResultingCommandExecutionInfo.java b/commandapi-platforms/commandapi-velocity/commandapi-velocity-core/src/main/java/dev/jorel/commandapi/executors/ResultingCommandExecutionInfo.java deleted file mode 100644 index 4cdc28b6f7..0000000000 --- a/commandapi-platforms/commandapi-velocity/commandapi-velocity-core/src/main/java/dev/jorel/commandapi/executors/ResultingCommandExecutionInfo.java +++ /dev/null @@ -1,27 +0,0 @@ -package dev.jorel.commandapi.executors; - -import com.velocitypowered.api.command.CommandSource; -import dev.jorel.commandapi.commandsenders.VelocityCommandSender; -import dev.jorel.commandapi.exceptions.WrapperCommandSyntaxException; - -@FunctionalInterface -public interface ResultingCommandExecutionInfo extends ResultingExecutor> { - - /** - * The code to run when this command is performed - * - * @param info The ExecutionInfo for this command - * @return the result of this command - * @throws WrapperCommandSyntaxException - */ - int run(ExecutionInfo> info) throws WrapperCommandSyntaxException; - - /** - * Returns the type of the sender of the current executor. - * @return the type of the sender of the current executor - */ - @Override - default ExecutorType getType() { - return ExecutorType.ALL; - } -} diff --git a/commandapi-platforms/commandapi-velocity/commandapi-velocity-core/src/main/java/dev/jorel/commandapi/executors/ResultingCommandExecutor.java b/commandapi-platforms/commandapi-velocity/commandapi-velocity-core/src/main/java/dev/jorel/commandapi/executors/ResultingCommandExecutor.java deleted file mode 100644 index 8619ead5c7..0000000000 --- a/commandapi-platforms/commandapi-velocity/commandapi-velocity-core/src/main/java/dev/jorel/commandapi/executors/ResultingCommandExecutor.java +++ /dev/null @@ -1,43 +0,0 @@ -package dev.jorel.commandapi.executors; - -import com.velocitypowered.api.command.CommandSource; -import dev.jorel.commandapi.commandsenders.VelocityCommandSender; -import dev.jorel.commandapi.exceptions.WrapperCommandSyntaxException; - -/** - * A resulting command executor for a CommandSource - */ -@FunctionalInterface -public interface ResultingCommandExecutor extends ResultingExecutor> { - - /** - * The code to run when this command is performed - * - * @param sender The sender of this command (a player, the console etc.) - * @param args The arguments given to this command. - * @return the result of this command - */ - int run(CommandSource sender, CommandArguments args) throws WrapperCommandSyntaxException; - - /** - * The code to run when this command is performed - * - * @param info The ExecutionInfo for this command - * @return the result of this command - * @throws WrapperCommandSyntaxException - */ - @Override - default int run(ExecutionInfo> info) throws WrapperCommandSyntaxException { - return this.run(info.sender(), info.args()); - } - - /** - * Returns the type of the sender of the current executor. - * - * @return the type of the sender of the current executor - */ - @Override - default ExecutorType getType() { - return ExecutorType.ALL; - } -} diff --git a/commandapi-platforms/commandapi-velocity/commandapi-velocity-core/src/main/java/dev/jorel/commandapi/executors/VelocityExecutionInfo.java b/commandapi-platforms/commandapi-velocity/commandapi-velocity-core/src/main/java/dev/jorel/commandapi/executors/VelocityExecutionInfo.java deleted file mode 100644 index 45e2b8fbe8..0000000000 --- a/commandapi-platforms/commandapi-velocity/commandapi-velocity-core/src/main/java/dev/jorel/commandapi/executors/VelocityExecutionInfo.java +++ /dev/null @@ -1,30 +0,0 @@ -package dev.jorel.commandapi.executors; - -import dev.jorel.commandapi.commandsenders.VelocityCommandSender; - -/** - * This record represents a VelocityExecutionInfo for a command. It provides the sender of a command, as well as it's arguments - * - * @param The type of the sender of a command this BukkitExecutionInfo belongs to - */ -public record VelocityExecutionInfo( - - /** - * @return The sender of this command - */ - Sender sender, - - /** - * This is not intended for public use and is only used internally. The {@link BukkitExecutionInfo#sender()} method should be used instead! - * - * @return The wrapper type of this command - */ - VelocityCommandSender senderWrapper, - - /** - * @return The arguments of this command - */ - CommandArguments args - -) implements ExecutionInfo> { -} diff --git a/commandapi-platforms/commandapi-velocity/commandapi-velocity-core/src/main/java/dev/jorel/commandapi/executors/VelocityNormalTypedExecutor.java b/commandapi-platforms/commandapi-velocity/commandapi-velocity-core/src/main/java/dev/jorel/commandapi/executors/VelocityNormalTypedExecutor.java new file mode 100644 index 0000000000..d0e700c6d0 --- /dev/null +++ b/commandapi-platforms/commandapi-velocity/commandapi-velocity-core/src/main/java/dev/jorel/commandapi/executors/VelocityNormalTypedExecutor.java @@ -0,0 +1,32 @@ +package dev.jorel.commandapi.executors; + +import com.velocitypowered.api.command.CommandSource; + +import dev.jorel.commandapi.exceptions.WrapperCommandSyntaxException; + +/** + * A {@link VelocityTypedExecutor} for {@link NormalExecutorInfo} lambdas that don't have an int result. + * When running this executor succeeds, it simply returns 1. + * + * @param executor The {@link NormalExecutorInfo} to invoke when running this executor. + * @param types The {@link ExecutorType}s that this executor accepts. + * @param The {@link CommandSource} class that this executor accepts. + */ +public record VelocityNormalTypedExecutor( + + /** + * @return The {@link NormalExecutorInfo} to invoke when running this executor. + */ + NormalExecutorInfo executor, + + /** + * @return The {@link ExecutorType}s that this executor accepts. + */ + ExecutorType... types +) implements VelocityTypedExecutor { + @Override + public int executeWith(ExecutionInfo info) throws WrapperCommandSyntaxException { + executor.run(info); + return 1; + } +} diff --git a/commandapi-platforms/commandapi-velocity/commandapi-velocity-core/src/main/java/dev/jorel/commandapi/executors/VelocityResultingTypedExecutor.java b/commandapi-platforms/commandapi-velocity/commandapi-velocity-core/src/main/java/dev/jorel/commandapi/executors/VelocityResultingTypedExecutor.java new file mode 100644 index 0000000000..5d725c0db1 --- /dev/null +++ b/commandapi-platforms/commandapi-velocity/commandapi-velocity-core/src/main/java/dev/jorel/commandapi/executors/VelocityResultingTypedExecutor.java @@ -0,0 +1,30 @@ +package dev.jorel.commandapi.executors; + +import com.velocitypowered.api.command.CommandSource; + +import dev.jorel.commandapi.exceptions.WrapperCommandSyntaxException; + +/** + * A {@link VelocityTypedExecutor} for {@link ResultingExecutorInfo} lambdas that have an int result. + * + * @param executor The {@link ResultingExecutorInfo} to invoke when running this executor. + * @param types The {@link ExecutorType}s that this executor accepts. + * @param The {@link CommandSource} class that this executor accepts. + */ +public record VelocityResultingTypedExecutor( + + /** + * @return The {@link ResultingExecutorInfo} to invoke when running this executor. + */ + ResultingExecutorInfo executor, + + /** + * @return The {@link ExecutorType}s that this executor accepts. + */ + ExecutorType... types +) implements VelocityTypedExecutor { + @Override + public int executeWith(ExecutionInfo info) throws WrapperCommandSyntaxException { + return executor.run(info); + } +} diff --git a/commandapi-platforms/commandapi-velocity/commandapi-velocity-core/src/main/java/dev/jorel/commandapi/executors/VelocityTypedExecutor.java b/commandapi-platforms/commandapi-velocity/commandapi-velocity-core/src/main/java/dev/jorel/commandapi/executors/VelocityTypedExecutor.java new file mode 100644 index 0000000000..93fb48897a --- /dev/null +++ b/commandapi-platforms/commandapi-velocity/commandapi-velocity-core/src/main/java/dev/jorel/commandapi/executors/VelocityTypedExecutor.java @@ -0,0 +1,35 @@ +package dev.jorel.commandapi.executors; + +import com.velocitypowered.api.command.CommandSource; +import com.velocitypowered.api.proxy.ConsoleCommandSource; +import com.velocitypowered.api.proxy.Player; + +/** + * A {@link TypedExecutor} for Velocity. The {@link CommandSource}s accepted by + * this executor can be defined by overriding the method {@link #types()}. + * + * @param The {@link CommandSource} class that this executor accepts. + */ +public interface VelocityTypedExecutor extends TypedExecutor { + @Override + default ExecutionInfo tryForSender(ExecutionInfo info) { + CommandSource sender = info.sender(); + + for (ExecutorType type : types()) { + // Check if we can cast to the defined sender type + if (switch (type) { + case ALL -> true; + case PLAYER -> sender instanceof Player; + case CONSOLE -> sender instanceof ConsoleCommandSource; + }) { + return (ExecutionInfo) info; + } + } + return null; + } + + /** + * @return The {@link ExecutorType}s that this executor accepts. + */ + ExecutorType[] types(); +}