|
1 | 1 | package io.papermc.testplugin; |
2 | 2 |
|
3 | | -import com.mojang.brigadier.Command; |
4 | | -import io.papermc.paper.command.brigadier.CommandSourceStack; |
5 | | -import io.papermc.paper.command.brigadier.Commands; |
6 | | -import io.papermc.paper.command.brigadier.argument.ArgumentTypes; |
7 | | -import io.papermc.paper.command.brigadier.argument.resolvers.selector.EntitySelectorArgumentResolver; |
8 | | -import io.papermc.paper.plugin.lifecycle.event.types.LifecycleEvents; |
9 | 3 | import org.bukkit.event.Listener; |
10 | 4 | import org.bukkit.plugin.java.JavaPlugin; |
11 | 5 |
|
12 | | -import static io.papermc.paper.command.brigadier.Commands.literal; |
13 | | - |
14 | 6 | public final class TestPlugin extends JavaPlugin implements Listener { |
15 | 7 |
|
16 | 8 | @Override |
17 | 9 | public void onEnable() { |
18 | 10 | this.getServer().getPluginManager().registerEvents(this, this); |
19 | 11 |
|
20 | 12 | // io.papermc.testplugin.brigtests.Registration.registerViaOnEnable(this); |
21 | | - |
22 | | - this.getLifecycleManager().registerEventHandler(LifecycleEvents.COMMANDS, event -> { |
23 | | - event.registrar().register( |
24 | | - literal("hide") |
25 | | - .executes(ctx -> { |
26 | | - ctx.getSource().getSender().sendMessage("hide"); |
27 | | - return Command.SINGLE_SUCCESS; |
28 | | - }) |
29 | | - .then(literal("something-else") |
30 | | - .executes(ctx -> { |
31 | | - ctx.getSource().getSender().sendMessage("hide something-else"); |
32 | | - return Command.SINGLE_SUCCESS; |
33 | | - })).build()); |
34 | | - |
35 | | - event.registrar().register( |
36 | | - literal("chat") |
37 | | - .then(literal("hide") |
38 | | - .executes(ctx -> { |
39 | | - ctx.getSource().getSender().sendMessage("chat hide"); |
40 | | - return Command.SINGLE_SUCCESS; |
41 | | - })).build()); |
42 | | - }); |
43 | | - |
44 | | - this.getLifecycleManager().registerEventHandler(LifecycleEvents.COMMANDS, event -> { |
45 | | - final Commands registrar = event.registrar(); |
46 | | - final var node = Commands.literal("target").then( |
47 | | - Commands.literal("type").executes(ctx -> { |
48 | | - final CommandSourceStack source = ctx.getSource(); |
49 | | - source.getSender().sendMessage(source.getExecutor().getType().toString()); |
50 | | - return Command.SINGLE_SUCCESS; |
51 | | - }) |
52 | | - ).build(); |
53 | | - registrar.register(node); |
54 | | - |
55 | | - event.registrar().register( |
56 | | - Commands.literal("test-execute").then( |
57 | | - Commands.argument("entity", ArgumentTypes.entities()) |
58 | | - .fork(node, ctx -> { |
59 | | - return ctx.getArgument("entity", EntitySelectorArgumentResolver.class).resolve(ctx.getSource()).stream().map(e -> ctx.getSource().withExecutor(e)).toList(); |
60 | | - }) |
61 | | - ).build() |
62 | | - ); |
63 | | - |
64 | | - event.registrar().register( |
65 | | - Commands.literal("root-execute") |
66 | | - .redirect(event.registrar().getDispatcher().getRoot()) |
67 | | - .build() |
68 | | - ); |
69 | | - }); |
70 | 13 | } |
71 | 14 | } |
0 commit comments