Update adventure to 4.13.0

This commit is contained in:
Nassim Jahnke
2023-03-15 13:19:54 +01:00
parent 239e16a2be
commit 8640f5feff
11 changed files with 174 additions and 64 deletions

View File

@@ -87,10 +87,7 @@ index 0000000000000000000000000000000000000000..00000000000000000000000000000000
@@ -0,0 +0,0 @@
+package io.papermc.paper.command;
+
+import io.papermc.paper.command.subcommands.EntityCommand;
+import io.papermc.paper.command.subcommands.HeapDumpCommand;
+import io.papermc.paper.command.subcommands.ReloadCommand;
+import io.papermc.paper.command.subcommands.VersionCommand;
+import io.papermc.paper.command.subcommands.*;
+import it.unimi.dsi.fastutil.Pair;
+import java.util.ArrayList;
+import java.util.Arrays;
@@ -127,11 +124,13 @@ index 0000000000000000000000000000000000000000..00000000000000000000000000000000
+ commands.put(Set.of("entity"), new EntityCommand());
+ commands.put(Set.of("reload"), new ReloadCommand());
+ commands.put(Set.of("version"), new VersionCommand());
+ commands.put(Set.of("callback"), new CallbackCommand());
+
+ return commands.entrySet().stream()
+ .flatMap(entry -> entry.getKey().stream().map(s -> Map.entry(s, entry.getValue())))
+ .collect(Collectors.toMap(Map.Entry::getKey, Map.Entry::getValue));
+ });
+ private static final Set<String> COMPLETABLE_SUBCOMMANDS = SUBCOMMANDS.entrySet().stream().filter(entry -> entry.getValue().tabCompletes()).map(Map.Entry::getKey).collect(Collectors.toSet());
+ // alias -> subcommand label
+ private static final Map<String, String> ALIASES = Util.make(() -> {
+ final Map<String, Set<String>> aliases = new HashMap<>();
@@ -173,7 +172,7 @@ index 0000000000000000000000000000000000000000..00000000000000000000000000000000
+ final @Nullable Location location
+ ) throws IllegalArgumentException {
+ if (args.length <= 1) {
+ return CommandUtil.getListMatchingLast(sender, args, SUBCOMMANDS.keySet());
+ return CommandUtil.getListMatchingLast(sender, args, COMPLETABLE_SUBCOMMANDS);
+ }
+
+ final @Nullable Pair<String, PaperSubcommand> subCommand = resolveCommand(args[0]);
@@ -284,6 +283,53 @@ index 0000000000000000000000000000000000000000..00000000000000000000000000000000
+ default List<String> tabComplete(final CommandSender sender, final String subCommand, final String[] args) {
+ return Collections.emptyList();
+ }
+
+ default boolean tabCompletes() {
+ return true;
+ }
+}
diff --git a/src/main/java/io/papermc/paper/command/subcommands/CallbackCommand.java b/src/main/java/io/papermc/paper/command/subcommands/CallbackCommand.java
new file mode 100644
index 0000000000000000000000000000000000000000..0000000000000000000000000000000000000000
--- /dev/null
+++ b/src/main/java/io/papermc/paper/command/subcommands/CallbackCommand.java
@@ -0,0 +0,0 @@
+package io.papermc.paper.command.subcommands;
+
+import io.papermc.paper.adventure.providers.ClickCallbackProviderImpl;
+import io.papermc.paper.command.PaperSubcommand;
+import net.kyori.adventure.text.Component;
+import net.kyori.adventure.text.event.ClickCallback;
+import net.kyori.adventure.text.event.ClickEvent;
+import org.bukkit.command.CommandSender;
+import org.checkerframework.checker.nullness.qual.NonNull;
+import org.checkerframework.framework.qual.DefaultQualifier;
+
+import java.time.Duration;
+
+@DefaultQualifier(NonNull.class)
+public final class CallbackCommand implements PaperSubcommand {
+ @Override
+ public boolean execute(final CommandSender sender, final String subCommand, final String[] args) {
+ if (args.length != 1) {
+ return false;
+ }
+
+ final long id;
+ try {
+ id = Long.parseLong(args[0]);
+ } catch (final NumberFormatException ignored) {
+ return false;
+ }
+
+ ClickCallbackProviderImpl.CALLBACK_MANAGER.runCallback(sender, id);
+ return true;
+ }
+
+ @Override
+ public boolean tabCompletes() {
+ return false;
+ }
+}
diff --git a/src/main/java/io/papermc/paper/command/subcommands/EntityCommand.java b/src/main/java/io/papermc/paper/command/subcommands/EntityCommand.java
new file mode 100644