From e88828f420215e2bac87b1e8de3b0f525870e6af Mon Sep 17 00:00:00 2001 From: benwoo1110 <30431861+benwoo1110@users.noreply.github.com> Date: Mon, 28 Dec 2020 01:04:44 +0800 Subject: [PATCH] Add playerOnly flag to tab-complete suggestions. --- .../commandTools/MVCommandCompletions.java | 42 ++++++++++++++++--- .../commands/TeleportCommand.java | 5 +-- 2 files changed, 38 insertions(+), 9 deletions(-) diff --git a/src/main/java/com/onarandombox/MultiverseCore/commandTools/MVCommandCompletions.java b/src/main/java/com/onarandombox/MultiverseCore/commandTools/MVCommandCompletions.java index fe4b1bea..8989886f 100644 --- a/src/main/java/com/onarandombox/MultiverseCore/commandTools/MVCommandCompletions.java +++ b/src/main/java/com/onarandombox/MultiverseCore/commandTools/MVCommandCompletions.java @@ -27,6 +27,7 @@ import org.bukkit.World; import org.bukkit.entity.EntityType; import org.bukkit.entity.Player; import org.jetbrains.annotations.NotNull; +import sun.rmi.runtime.Log; import java.io.File; import java.text.DecimalFormat; @@ -121,13 +122,12 @@ public class MVCommandCompletions extends PaperCommandCompletions { return this.plugin.getMVCommandManager().hasPermission(issuer, cmd.getRequiredPermissions()); } - @NotNull - private Collection suggestToggles() { - return Arrays.asList("on", "off"); - } - @NotNull private Collection suggestMVWorlds(@NotNull BukkitCommandCompletionContext context) { + if (isPlayerOnly(context)) { + return Collections.emptyList(); + } + return this.worldManager.getMVWorlds().parallelStream() .unordered() .map(MultiverseWorld::getName) @@ -136,11 +136,19 @@ public class MVCommandCompletions extends PaperCommandCompletions { @NotNull private Collection suggestUnloadedWorlds(@NotNull BukkitCommandCompletionContext context) { + if (isPlayerOnly(context)) { + return Collections.emptyList(); + } + return this.worldManager.getUnloadedWorlds(); } @NotNull private Collection suggestPotentialWorlds(@NotNull BukkitCommandCompletionContext context) { + if (isPlayerOnly(context)) { + return Collections.emptyList(); + } + Collection worlds = this.worldManager.getMVWorlds(); Set knownWorlds = worlds.parallelStream() .unordered() @@ -158,10 +166,14 @@ public class MVCommandCompletions extends PaperCommandCompletions { @NotNull private Collection suggestLocation(@NotNull BukkitCommandCompletionContext context) { + if (isPlayerOnly(context)) { + return Collections.emptyList(); + } + Logging.info("location"); Player player = context.getPlayer(); if (player == null) { - return Collections.singletonList("0"); + return Collections.emptyList(); } DecimalFormat df = new DecimalFormat(); @@ -195,6 +207,10 @@ public class MVCommandCompletions extends PaperCommandCompletions { @NotNull private Collection suggestDestinations(@NotNull BukkitCommandCompletionContext context) { + if (isPlayerOnly(context)) { + return Collections.emptyList(); + } + return this.plugin.getDestFactory().getIdentifiers().parallelStream() .unordered() .filter(id -> !id.isEmpty()) @@ -204,9 +220,18 @@ public class MVCommandCompletions extends PaperCommandCompletions { @NotNull private Collection suggestAnchors(@NotNull BukkitCommandCompletionContext context) { + if (isPlayerOnly(context)) { + return Collections.emptyList(); + } + return this.plugin.getAnchorManager().getAnchors(context.getPlayer()); } + private boolean isPlayerOnly(@NotNull BukkitCommandCompletionContext context) { + String config = context.getConfig(); + return config != null && context.getPlayer() == null && config.equals("playerOnly"); + } + @NotNull private Collection suggestMVConfig() { final Set configOptions = this.plugin.getMVConfig().serialize().keySet(); @@ -254,4 +279,9 @@ public class MVCommandCompletions extends PaperCommandCompletions { .map(p -> p.toString().toLowerCase()) .collect(Collectors.toList()); } + + @NotNull + private Collection suggestToggles() { + return Arrays.asList("on", "off"); + } } diff --git a/src/main/java/com/onarandombox/MultiverseCore/commands/TeleportCommand.java b/src/main/java/com/onarandombox/MultiverseCore/commands/TeleportCommand.java index 328e3125..dfb6b093 100644 --- a/src/main/java/com/onarandombox/MultiverseCore/commands/TeleportCommand.java +++ b/src/main/java/com/onarandombox/MultiverseCore/commands/TeleportCommand.java @@ -48,7 +48,7 @@ public class TeleportCommand extends MultiverseCommand { @Subcommand("tp|teleport") @Syntax("[player] ") - @CommandCompletion("@players|@MVWorlds|@destinations @MVWorlds|@destinations") + @CommandCompletion("@players|@MVWorlds:playerOnly|@destinations:playerOnly @MVWorlds|@destinations") @Description("Allows you to the teleport to a location on your server!") public void doTeleportCommand(@NotNull CommandSender sender, @@ -73,8 +73,7 @@ public class TeleportCommand extends MultiverseCommand { @CommandAlias("mvtp") @Syntax("[player] ") - //TODO ACF: playerOnly flag - @CommandCompletion("@players|@MVWorlds|@destinations @MVWorlds|@destinations") + @CommandCompletion("@players|@MVWorlds:playerOnly|@destinations:playerOnly @MVWorlds|@destinations") @Description("Alias for /mv tp") public void doTeleportCommand(@NotNull CommandSender sender,