diff --git a/code/gradle/libs.versions.toml b/code/gradle/libs.versions.toml index 91d3038..0a89b9a 100644 --- a/code/gradle/libs.versions.toml +++ b/code/gradle/libs.versions.toml @@ -2,7 +2,7 @@ indra = "3.1.3" cloud = "2.0.0-rc.2" -cloudMinecraft = "2.0.0-beta.8" +cloudMinecraft = "2.0.0-SNAPSHOT" cloudProcessors = "1.0.0-beta.3" paper = "1.20.6-R0.1-SNAPSHOT" diff --git a/code/src/main/java/org/incendo/cloud/snippet/minecraft/PaperExample.java b/code/src/main/java/org/incendo/cloud/snippet/minecraft/PaperExample.java index 4db0ebf..7bd9f85 100644 --- a/code/src/main/java/org/incendo/cloud/snippet/minecraft/PaperExample.java +++ b/code/src/main/java/org/incendo/cloud/snippet/minecraft/PaperExample.java @@ -2,12 +2,16 @@ import io.papermc.paper.command.brigadier.CommandSourceStack; import org.bukkit.command.CommandSender; +import org.bukkit.entity.Player; import org.bukkit.plugin.java.JavaPlugin; import org.checkerframework.checker.nullness.qual.NonNull; import org.incendo.cloud.SenderMapper; import org.incendo.cloud.execution.ExecutionCoordinator; import org.incendo.cloud.paper.LegacyPaperCommandManager; import org.incendo.cloud.paper.PaperCommandManager; +import org.incendo.cloud.paper.util.sender.PaperSimpleSenderMapper; +import org.incendo.cloud.paper.util.sender.PlayerSource; +import org.incendo.cloud.paper.util.sender.Source; public class PaperExample { @@ -58,6 +62,28 @@ public void exampleModernCustom( // --8<-- [end:modern_custom] } + public void exampleModernSimpleSEnderMapper( + final @NonNull JavaPlugin javaPlugin + ) { + final ExecutionCoordinator executionCoordinator = ExecutionCoordinator.simpleCoordinator(); + // --8<-- [start:modern_simple_sender_mapper] + PaperCommandManager commandManager = PaperCommandManager + .builder(PaperSimpleSenderMapper.simpleSenderMapper()) + .executionCoordinator(executionCoordinator) + .buildOnEnable(javaPlugin); + // or: .buildBootstrapped(bootstrapContext); + + // this command will only be available to players, and the player type is directly available. + commandManager.command(commandManager.commandBuilder("player_command") + .senderType(PlayerSource.class) + .handler(context -> { + Player player = context.sender().source(); + player.sendMessage("Hello, player!"); + }) + ); + // --8<-- [end:modern_simple_sender_mapper] + } + public record YourSenderType() { } } diff --git a/docs/minecraft/brigadier.md b/docs/minecraft/brigadier.md index fcbe1f4..cb79dc8 100644 --- a/docs/minecraft/brigadier.md +++ b/docs/minecraft/brigadier.md @@ -29,11 +29,6 @@ per-argument validation, coloring and syntax hinting.
Accurate Command Structure
-!!! warning "Alias Registration" - - Only aliases for root nodes will be registered when using Brigadier. Due to how it's command - tree works it can quickly become inflated when sub-commands have aliases. - ## CloudBrigadierManager You can get an instance of `CloudBrigadierManager` from the command manager for your platform of choice. @@ -41,6 +36,11 @@ If the command manager is a `BrigadierManagerHolder`, then you can get the insta The `CloudBrigadierManager` is how you interact with Brigadier to register mappings and configure settings. +!!! warning "Alias Registration" + + Only aliases for root nodes will be registered when using Brigadier. Due to how it's command + tree works it can quickly become inflated when sub-commands have aliases. + ### Settings `CloudBrigadierManager` has settings that can be accessed using `CloudBrigadierManager.settings()`. diff --git a/docs/minecraft/paper.md b/docs/minecraft/paper.md index 4a3df44..b89aa73 100644 --- a/docs/minecraft/paper.md +++ b/docs/minecraft/paper.md @@ -39,7 +39,7 @@ should be used. !!! tip "Plugin Configuration Files" - Do not register your commands in your plugin.yml or paper-plugin.yml, Cloud handles the registration + Do not register your commands in your plugin.yml or paper-plugin.yml, Cloud handles the registration itself and doing it yourself will cause issues. ### Legacy @@ -140,10 +140,9 @@ if (commandManager.hasCapability(CloudBukkitCapabilities.NATIVE_BRIGADIER)) { ## Provided Sender Mapper -Cloud includes a built-in sender mapper designed for the command manager. Due to the CommandSourceStack having no extensions it can be difficult to work, our sender mapper can be used like so: +Cloud includes a built-in sender mapper designed for the command manager. Due to the CommandSourceStack having no exposed implementations it can be difficult to work, +here's an example of creating a command manager with the sender mapper and using the provided mapped sender: -```java -PaperCommandManager.builder(PaperSimpleSenderMapper.simpleSenderMapper()) -``` +{{ snippet("minecraft/PaperExample.java", section = "modern_simple_sender_mapper", title = "") }} -This will give you access to Source with the included extensions: PlayerSource, ConsoleSource, EntitySource and GenericSource \ No newline at end of file +This will give you access to Source with the included extensions: PlayerSource, ConsoleSource, EntitySource and GenericSource