Skip to content

Commit 54fb2b1

Browse files
authored
feat(minecraft): improvements & simple sender mapper information (#45)
1 parent b52dc77 commit 54fb2b1

5 files changed

Lines changed: 49 additions & 1 deletion

File tree

.gitignore

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -400,3 +400,6 @@ poetry.toml
400400
pyrightconfig.json
401401

402402
# End of https://www.toptal.com/developers/gitignore/api/python,intellij+all,node
403+
404+
# Project specific
405+
code/.gradle

code/gradle/libs.versions.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
indra = "3.1.3"
33

44
cloud = "2.0.0-rc.2"
5-
cloudMinecraft = "2.0.0-beta.8"
5+
cloudMinecraft = "2.0.0-SNAPSHOT"
66
cloudProcessors = "1.0.0-beta.3"
77

88
paper = "1.20.6-R0.1-SNAPSHOT"

code/src/main/java/org/incendo/cloud/snippet/minecraft/PaperExample.java

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,12 +2,16 @@
22

33
import io.papermc.paper.command.brigadier.CommandSourceStack;
44
import org.bukkit.command.CommandSender;
5+
import org.bukkit.entity.Player;
56
import org.bukkit.plugin.java.JavaPlugin;
67
import org.checkerframework.checker.nullness.qual.NonNull;
78
import org.incendo.cloud.SenderMapper;
89
import org.incendo.cloud.execution.ExecutionCoordinator;
910
import org.incendo.cloud.paper.LegacyPaperCommandManager;
1011
import org.incendo.cloud.paper.PaperCommandManager;
12+
import org.incendo.cloud.paper.util.sender.PaperSimpleSenderMapper;
13+
import org.incendo.cloud.paper.util.sender.PlayerSource;
14+
import org.incendo.cloud.paper.util.sender.Source;
1115

1216
public class PaperExample {
1317

@@ -58,6 +62,28 @@ public void exampleModernCustom(
5862
// --8<-- [end:modern_custom]
5963
}
6064

65+
public void exampleModernSimpleSenderMapper(
66+
final @NonNull JavaPlugin javaPlugin
67+
) {
68+
final ExecutionCoordinator<Source> executionCoordinator = ExecutionCoordinator.simpleCoordinator();
69+
// --8<-- [start:modern_simple_sender_mapper]
70+
PaperCommandManager<Source> commandManager = PaperCommandManager
71+
.builder(PaperSimpleSenderMapper.simpleSenderMapper())
72+
.executionCoordinator(executionCoordinator)
73+
.buildOnEnable(javaPlugin);
74+
// or: .buildBootstrapped(bootstrapContext);
75+
76+
// this command will only be available to players, and the player type is directly available.
77+
commandManager.command(commandManager.commandBuilder("player_command")
78+
.senderType(PlayerSource.class)
79+
.handler(context -> {
80+
Player player = context.sender().source();
81+
player.sendMessage("Hello, player!");
82+
})
83+
);
84+
// --8<-- [end:modern_simple_sender_mapper]
85+
}
86+
6187
public record YourSenderType() {
6288
}
6389
}

docs/minecraft/brigadier.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,11 @@ If the command manager is a `BrigadierManagerHolder`, then you can get the insta
3636

3737
The `CloudBrigadierManager` is how you interact with Brigadier to register mappings and configure settings.
3838

39+
!!! warning "Alias Registration"
40+
41+
Only aliases for root nodes will be registered when using Brigadier. Due to how it's command
42+
tree works it can quickly become inflated when sub-commands have aliases.
43+
3944
### Settings
4045

4146
`CloudBrigadierManager` has settings that can be accessed using `CloudBrigadierManager.settings()`.

docs/minecraft/paper.md

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,11 @@ If the plugin is targeting older Paper versions or non-paper servers, then
3737
{{ javadoc("https://javadoc.io/doc/org.incendo/cloud-paper/latest/org/incendo/cloud/paper/LegacyPaperCommandManager.html", "LegacyPaperCommandManager") }}
3838
should be used.
3939

40+
!!! tip "Plugin Configuration Files"
41+
42+
Do not register your commands in your plugin.yml or paper-plugin.yml, Cloud handles the registration
43+
itself and doing it yourself will cause issues.
44+
4045
### Legacy
4146

4247
The legacy command manager can be instantiated in two different ways.
@@ -132,3 +137,12 @@ if (commandManager.hasCapability(CloudBukkitCapabilities.NATIVE_BRIGADIER)) {
132137
## Parsers
133138

134139
`cloud-paper` has access to all the parsers from [cloud-bukkit](bukkit.md#parsers).
140+
141+
## Provided Sender Mapper
142+
143+
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,
144+
here's an example of creating a command manager with the sender mapper and using the provided mapped sender:
145+
146+
{{ snippet("minecraft/PaperExample.java", section = "modern_simple_sender_mapper", title = "") }}
147+
148+
This will give you access to Source with the included extensions: PlayerSource, ConsoleSource, EntitySource and GenericSource

0 commit comments

Comments
 (0)