|
1 | 1 | package io.papermc.paperweight.testplugin; |
2 | 2 |
|
3 | | -import com.destroystokyo.paper.brigadier.BukkitBrigadierCommandSource; |
4 | | -import com.destroystokyo.paper.event.brigadier.CommandRegisteredEvent; |
5 | | -import com.mojang.brigadier.Command; |
6 | | -import com.mojang.brigadier.builder.LiteralArgumentBuilder; |
7 | | -import com.mojang.brigadier.tree.LiteralCommandNode; |
8 | | -import java.util.Collection; |
9 | | -import java.util.function.Consumer; |
10 | | -import net.minecraft.ChatFormatting; |
11 | | -import net.minecraft.commands.CommandSourceStack; |
12 | | -import net.minecraft.commands.arguments.EntityArgument; |
13 | | -import net.minecraft.network.chat.ClickEvent; |
14 | | -import net.minecraft.network.chat.Component; |
15 | | -import net.minecraft.server.level.ServerPlayer; |
16 | | -import org.bukkit.craftbukkit.CraftServer; |
17 | | -import org.bukkit.event.EventHandler; |
| 3 | +import net.minecraft.SharedConstants; |
18 | 4 | import org.bukkit.event.Listener; |
19 | 5 | import org.bukkit.plugin.java.JavaPlugin; |
20 | 6 | import org.checkerframework.checker.nullness.qual.NonNull; |
21 | 7 | import org.checkerframework.framework.qual.DefaultQualifier; |
22 | 8 |
|
23 | | -import static net.kyori.adventure.text.Component.text; |
24 | | -import static net.kyori.adventure.text.format.NamedTextColor.BLUE; |
25 | | -import static net.minecraft.commands.Commands.argument; |
26 | | -import static net.minecraft.commands.Commands.literal; |
27 | | -import static net.minecraft.commands.arguments.EntityArgument.players; |
28 | | - |
29 | 9 | @DefaultQualifier(NonNull.class) |
30 | 10 | public final class TestPlugin extends JavaPlugin implements Listener { |
31 | 11 | @Override |
32 | 12 | public void onEnable() { |
33 | 13 | this.getServer().getPluginManager().registerEvents(this, this); |
34 | 14 |
|
35 | | - this.registerPluginBrigadierCommand( |
36 | | - "paperweight", |
37 | | - literal -> literal.requires(stack -> stack.getBukkitSender().hasPermission("paperweight")) |
38 | | - .then(literal("hello") |
39 | | - .executes(ctx -> { |
40 | | - ctx.getSource().getBukkitSender().sendMessage(text("Hello!", BLUE)); |
41 | | - return Command.SINGLE_SUCCESS; |
42 | | - })) |
43 | | - .then(argument("players", players()) |
44 | | - .executes(ctx -> { |
45 | | - final Collection<ServerPlayer> players = EntityArgument.getPlayers(ctx, "players"); |
46 | | - for (final ServerPlayer player : players) { |
47 | | - player.sendSystemMessage( |
48 | | - Component.literal("Hello from Paperweight test plugin!") |
49 | | - .withStyle(ChatFormatting.ITALIC, ChatFormatting.GREEN) |
50 | | - .withStyle(style -> style.withClickEvent(new ClickEvent.RunCommand("/paperweight @a"))) |
51 | | - ); |
52 | | - } |
53 | | - return players.size(); |
54 | | - })) |
55 | | - ); |
56 | | - } |
57 | | - |
58 | | - private PluginBrigadierCommand registerPluginBrigadierCommand(final String label, final Consumer<LiteralArgumentBuilder<CommandSourceStack>> command) { |
59 | | - final PluginBrigadierCommand pluginBrigadierCommand = new PluginBrigadierCommand(this, label, command); |
60 | | - this.getServer().getCommandMap().register(this.getName(), pluginBrigadierCommand); |
61 | | - ((CraftServer) this.getServer()).syncCommands(); |
62 | | - return pluginBrigadierCommand; |
63 | | - } |
64 | | - |
65 | | - @SuppressWarnings({"rawtypes", "unchecked"}) |
66 | | - @EventHandler |
67 | | - public void onCommandRegistered(final CommandRegisteredEvent<BukkitBrigadierCommandSource> event) { |
68 | | - if (!(event.getCommand() instanceof PluginBrigadierCommand pluginBrigadierCommand)) { |
69 | | - return; |
70 | | - } |
71 | | - final LiteralArgumentBuilder<CommandSourceStack> node = literal(event.getCommandLabel()); |
72 | | - pluginBrigadierCommand.command().accept(node); |
73 | | - event.setLiteral((LiteralCommandNode) node.build()); |
| 15 | + this.getLogger().info(SharedConstants.getCurrentVersion().id()); |
74 | 16 | } |
75 | 17 | } |
0 commit comments