|
2 | 2 |
|
3 | 3 | import io.papermc.paper.command.brigadier.CommandSourceStack; |
4 | 4 | import org.bukkit.command.CommandSender; |
| 5 | +import org.bukkit.entity.Player; |
5 | 6 | import org.bukkit.plugin.java.JavaPlugin; |
6 | 7 | import org.checkerframework.checker.nullness.qual.NonNull; |
7 | 8 | import org.incendo.cloud.SenderMapper; |
8 | 9 | import org.incendo.cloud.execution.ExecutionCoordinator; |
9 | 10 | import org.incendo.cloud.paper.LegacyPaperCommandManager; |
10 | 11 | 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; |
11 | 15 |
|
12 | 16 | public class PaperExample { |
13 | 17 |
|
@@ -58,6 +62,28 @@ public void exampleModernCustom( |
58 | 62 | // --8<-- [end:modern_custom] |
59 | 63 | } |
60 | 64 |
|
| 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 | + |
61 | 87 | public record YourSenderType() { |
62 | 88 | } |
63 | 89 | } |
0 commit comments