From d2b524c25929524e552324088d8e245e487eeeba Mon Sep 17 00:00:00 2001 From: Telesphoreo Date: Sat, 20 Jan 2024 14:47:23 -0600 Subject: [PATCH] fix tab completion --- .../plex/extras/command/AdminInfoCommand.java | 7 +++++ .../extras/command/AttributeListCommand.java | 8 ++++++ .../plex/extras/command/AutoClearCommand.java | 9 +++++++ .../extras/command/AutoTeleportCommand.java | 8 ++++++ .../plex/extras/command/BanListCommand.java | 9 +++++++ .../dev/plex/extras/command/CakeCommand.java | 8 ++++++ .../plex/extras/command/CartSitCommand.java | 12 +++++++-- .../plex/extras/command/ClearChatCommand.java | 8 ++++++ .../extras/command/CloudClearCommand.java | 8 ++++++ .../dev/plex/extras/command/EjectCommand.java | 8 ++++++ .../plex/extras/command/EnchantCommand.java | 24 +++++++++++++++++ .../plex/extras/command/EnglishMfCommand.java | 8 +++--- .../plex/extras/command/JumpPadsCommand.java | 18 ++++++++----- .../extras/command/RandomFishCommand.java | 7 +++++ .../extras/command/slime/MyWorldCommand.java | 27 +++++++++++++++---- .../command/slime/SlimeManagerCommand.java | 26 ++++++++++++++---- 16 files changed, 171 insertions(+), 24 deletions(-) diff --git a/src/main/java/dev/plex/extras/command/AdminInfoCommand.java b/src/main/java/dev/plex/extras/command/AdminInfoCommand.java index 833a81d..f46220b 100755 --- a/src/main/java/dev/plex/extras/command/AdminInfoCommand.java +++ b/src/main/java/dev/plex/extras/command/AdminInfoCommand.java @@ -4,6 +4,7 @@ import dev.plex.command.PlexCommand; import dev.plex.command.annotation.CommandParameters; import dev.plex.command.annotation.CommandPermissions; import dev.plex.extras.TFMExtras; +import java.util.Collections; import java.util.List; import net.kyori.adventure.text.Component; import net.kyori.adventure.text.minimessage.MiniMessage; @@ -29,4 +30,10 @@ public class AdminInfoCommand extends PlexCommand ADMIN_INFO.forEach(component -> send(sender, component)); return null; } + + @Override + public @NotNull List smartTabComplete(@NotNull CommandSender sender, @NotNull String alias, @NotNull String[] args) throws IllegalArgumentException + { + return Collections.emptyList(); + } } diff --git a/src/main/java/dev/plex/extras/command/AttributeListCommand.java b/src/main/java/dev/plex/extras/command/AttributeListCommand.java index bfdd5ea..0835e3e 100755 --- a/src/main/java/dev/plex/extras/command/AttributeListCommand.java +++ b/src/main/java/dev/plex/extras/command/AttributeListCommand.java @@ -4,6 +4,8 @@ import dev.plex.command.PlexCommand; import dev.plex.command.annotation.CommandParameters; import dev.plex.command.annotation.CommandPermissions; import java.util.Arrays; +import java.util.Collections; +import java.util.List; import net.kyori.adventure.text.Component; import org.apache.commons.lang3.StringUtils; import org.bukkit.attribute.Attribute; @@ -21,4 +23,10 @@ public class AttributeListCommand extends PlexCommand { return messageComponent("attributeList", StringUtils.join(Arrays.stream(Attribute.values()).map(Enum::name).toList(), ", ")); } + + @Override + public @NotNull List smartTabComplete(@NotNull CommandSender commandSender, @NotNull String s, @NotNull String[] strings) throws IllegalArgumentException + { + return Collections.emptyList(); + } } diff --git a/src/main/java/dev/plex/extras/command/AutoClearCommand.java b/src/main/java/dev/plex/extras/command/AutoClearCommand.java index 1738eb2..4c0331a 100755 --- a/src/main/java/dev/plex/extras/command/AutoClearCommand.java +++ b/src/main/java/dev/plex/extras/command/AutoClearCommand.java @@ -1,5 +1,6 @@ package dev.plex.extras.command; +import com.google.common.collect.ImmutableList; import dev.plex.cache.DataUtils; import dev.plex.command.PlexCommand; import dev.plex.command.annotation.CommandParameters; @@ -7,6 +8,7 @@ import dev.plex.command.annotation.CommandPermissions; import dev.plex.command.exception.PlayerNotFoundException; import dev.plex.extras.TFMExtras; import dev.plex.player.PlexPlayer; +import dev.plex.util.PlexUtils; import java.util.List; import net.kyori.adventure.text.Component; import org.bukkit.command.CommandSender; @@ -45,4 +47,11 @@ public class AutoClearCommand extends PlexCommand isEnabled = !isEnabled; return messageComponent("modifiedAutoClear", target.getName(), isEnabled ? "now" : "no longer"); } + + + @Override + public @NotNull List smartTabComplete(@NotNull CommandSender sender, @NotNull String alias, @NotNull String[] args) throws IllegalArgumentException + { + return args.length == 1 && silentCheckPermission(sender, this.getPermission()) ? PlexUtils.getPlayerNameList() : ImmutableList.of(); + } } diff --git a/src/main/java/dev/plex/extras/command/AutoTeleportCommand.java b/src/main/java/dev/plex/extras/command/AutoTeleportCommand.java index 5e1615a..edd6310 100755 --- a/src/main/java/dev/plex/extras/command/AutoTeleportCommand.java +++ b/src/main/java/dev/plex/extras/command/AutoTeleportCommand.java @@ -1,5 +1,6 @@ package dev.plex.extras.command; +import com.google.common.collect.ImmutableList; import dev.plex.cache.DataUtils; import dev.plex.command.PlexCommand; import dev.plex.command.annotation.CommandParameters; @@ -7,6 +8,7 @@ import dev.plex.command.annotation.CommandPermissions; import dev.plex.command.exception.PlayerNotFoundException; import dev.plex.extras.TFMExtras; import dev.plex.player.PlexPlayer; +import dev.plex.util.PlexUtils; import java.util.List; import net.kyori.adventure.text.Component; import org.bukkit.command.CommandSender; @@ -52,4 +54,10 @@ public class AutoTeleportCommand extends PlexCommand isEnabled = !isEnabled; return messageComponent("modifiedAutoTeleport", target.getName(), isEnabled ? "now" : "no longer"); } + + @Override + public @NotNull List smartTabComplete(@NotNull CommandSender sender, @NotNull String alias, @NotNull String[] args) throws IllegalArgumentException + { + return args.length == 1 && silentCheckPermission(sender, this.getPermission()) ? PlexUtils.getPlayerNameList() : ImmutableList.of(); + } } diff --git a/src/main/java/dev/plex/extras/command/BanListCommand.java b/src/main/java/dev/plex/extras/command/BanListCommand.java index dc651ab..1f99532 100755 --- a/src/main/java/dev/plex/extras/command/BanListCommand.java +++ b/src/main/java/dev/plex/extras/command/BanListCommand.java @@ -1,9 +1,12 @@ package dev.plex.extras.command; +import com.google.common.collect.ImmutableList; import dev.plex.command.PlexCommand; import dev.plex.command.annotation.CommandParameters; import dev.plex.command.annotation.CommandPermissions; import dev.plex.punishment.Punishment; +import java.util.Collections; +import java.util.List; import java.util.stream.Collectors; import net.kyori.adventure.text.Component; import org.apache.commons.lang3.StringUtils; @@ -48,4 +51,10 @@ public class BanListCommand extends PlexCommand } return null; } + + @Override + public @NotNull List smartTabComplete(@NotNull CommandSender sender, @NotNull String alias, @NotNull String[] args) throws IllegalArgumentException + { + return args.length == 1 && silentCheckPermission(sender, "plex.tfmextras.banlist.clear") ? Collections.singletonList("purge") : ImmutableList.of(); + } } diff --git a/src/main/java/dev/plex/extras/command/CakeCommand.java b/src/main/java/dev/plex/extras/command/CakeCommand.java index afce34d..873bcf5 100755 --- a/src/main/java/dev/plex/extras/command/CakeCommand.java +++ b/src/main/java/dev/plex/extras/command/CakeCommand.java @@ -5,6 +5,8 @@ import dev.plex.command.annotation.CommandParameters; import dev.plex.command.annotation.CommandPermissions; import dev.plex.util.PlexUtils; import dev.plex.util.item.ItemBuilder; +import java.util.Collections; +import java.util.List; import net.kyori.adventure.text.Component; import net.kyori.adventure.text.minimessage.MiniMessage; import org.bukkit.Bukkit; @@ -33,4 +35,10 @@ public class CakeCommand extends PlexCommand PlexUtils.broadcast(messageComponent("cakeLyrics")); return null; } + + @Override + public @NotNull List smartTabComplete(@NotNull CommandSender commandSender, @NotNull String s, @NotNull String[] strings) throws IllegalArgumentException + { + return Collections.emptyList(); + } } diff --git a/src/main/java/dev/plex/extras/command/CartSitCommand.java b/src/main/java/dev/plex/extras/command/CartSitCommand.java index 8c171ae..c5acde4 100755 --- a/src/main/java/dev/plex/extras/command/CartSitCommand.java +++ b/src/main/java/dev/plex/extras/command/CartSitCommand.java @@ -1,9 +1,11 @@ package dev.plex.extras.command; +import com.google.common.collect.ImmutableList; import dev.plex.Plex; import dev.plex.command.PlexCommand; import dev.plex.command.annotation.CommandParameters; import dev.plex.command.annotation.CommandPermissions; +import dev.plex.util.PlexUtils; import java.util.List; import java.util.concurrent.CompletableFuture; import java.util.stream.Collectors; @@ -17,7 +19,7 @@ import org.bukkit.entity.Player; import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.Nullable; -@CommandParameters(name = "cartsit", description = "Sit in nearest minecart. If target is in a minecart already, they will be ejected", aliases = "minecartsit") +@CommandParameters(name = "cartsit", usage = "/ ", description = "Sit in nearest minecart. If target is in a minecart already, they will be ejected", aliases = "minecartsit") @CommandPermissions(permission = "plex.tfmextras.cartsit") public class CartSitCommand extends PlexCommand { @@ -26,7 +28,7 @@ public class CartSitCommand extends PlexCommand { if (!(sender instanceof Player) && args.length == 0) { - return usage("/cartsit "); + return usage(); } if (args.length == 0) @@ -80,4 +82,10 @@ public class CartSitCommand extends PlexCommand return nearest; }); } + + @Override + public @NotNull List smartTabComplete(@NotNull CommandSender sender, @NotNull String alias, @NotNull String[] args) throws IllegalArgumentException + { + return args.length == 1 && silentCheckPermission(sender, this.getPermission()) ? PlexUtils.getPlayerNameList() : ImmutableList.of(); + } } diff --git a/src/main/java/dev/plex/extras/command/ClearChatCommand.java b/src/main/java/dev/plex/extras/command/ClearChatCommand.java index 39af1b5..402311e 100755 --- a/src/main/java/dev/plex/extras/command/ClearChatCommand.java +++ b/src/main/java/dev/plex/extras/command/ClearChatCommand.java @@ -4,6 +4,8 @@ import dev.plex.command.PlexCommand; import dev.plex.command.annotation.CommandParameters; import dev.plex.command.annotation.CommandPermissions; import dev.plex.util.PlexUtils; +import java.util.Collections; +import java.util.List; import net.kyori.adventure.text.Component; import org.bukkit.Bukkit; import org.bukkit.command.CommandSender; @@ -29,4 +31,10 @@ public class ClearChatCommand extends PlexCommand PlexUtils.broadcast(messageComponent("chatCleared", sender.getName())); return null; } + + @Override + public @NotNull List smartTabComplete(@NotNull CommandSender sender, @NotNull String alias, @NotNull String[] args) throws IllegalArgumentException + { + return Collections.emptyList(); + } } diff --git a/src/main/java/dev/plex/extras/command/CloudClearCommand.java b/src/main/java/dev/plex/extras/command/CloudClearCommand.java index f9fd9e8..e769b26 100755 --- a/src/main/java/dev/plex/extras/command/CloudClearCommand.java +++ b/src/main/java/dev/plex/extras/command/CloudClearCommand.java @@ -5,6 +5,8 @@ import dev.plex.command.annotation.CommandParameters; import dev.plex.command.annotation.CommandPermissions; import dev.plex.util.PlexUtils; import java.util.Collection; +import java.util.Collections; +import java.util.List; import java.util.concurrent.atomic.AtomicInteger; import net.kyori.adventure.text.Component; import net.kyori.adventure.text.minimessage.MiniMessage; @@ -32,4 +34,10 @@ public class CloudClearCommand extends PlexCommand PlexUtils.broadcast(messageComponent("areaEffectCloudClear", sender.getName())); return MiniMessage.miniMessage().deserialize("" + removed.get() + " area effect clouds removed."); } + + @Override + public @NotNull List smartTabComplete(@NotNull CommandSender sender, @NotNull String alias, @NotNull String[] args) throws IllegalArgumentException + { + return Collections.emptyList(); + } } diff --git a/src/main/java/dev/plex/extras/command/EjectCommand.java b/src/main/java/dev/plex/extras/command/EjectCommand.java index ba9053e..4ba3fa8 100755 --- a/src/main/java/dev/plex/extras/command/EjectCommand.java +++ b/src/main/java/dev/plex/extras/command/EjectCommand.java @@ -4,6 +4,8 @@ import dev.plex.command.PlexCommand; import dev.plex.command.annotation.CommandParameters; import dev.plex.command.annotation.CommandPermissions; import dev.plex.command.source.RequiredCommandSource; +import java.util.Collections; +import java.util.List; import net.kyori.adventure.text.Component; import net.kyori.adventure.text.minimessage.MiniMessage; import org.bukkit.command.CommandSender; @@ -22,4 +24,10 @@ public class EjectCommand extends PlexCommand player.eject(); return MiniMessage.miniMessage().deserialize("Ejected " + passengers + " passengers."); } + + @Override + public @NotNull List smartTabComplete(@NotNull CommandSender sender, @NotNull String alias, @NotNull String[] args) throws IllegalArgumentException + { + return Collections.emptyList(); + } } diff --git a/src/main/java/dev/plex/extras/command/EnchantCommand.java b/src/main/java/dev/plex/extras/command/EnchantCommand.java index a935949..1d4fb4f 100755 --- a/src/main/java/dev/plex/extras/command/EnchantCommand.java +++ b/src/main/java/dev/plex/extras/command/EnchantCommand.java @@ -6,10 +6,12 @@ import dev.plex.command.annotation.CommandParameters; import dev.plex.command.annotation.CommandPermissions; import dev.plex.command.source.RequiredCommandSource; import java.util.Arrays; +import java.util.Collections; import java.util.List; import net.kyori.adventure.text.Component; import net.kyori.adventure.text.minimessage.MiniMessage; import org.apache.commons.lang3.StringUtils; +import org.bukkit.Bukkit; import org.bukkit.Material; import org.bukkit.Sound; import org.bukkit.command.CommandSender; @@ -70,4 +72,26 @@ public class EnchantCommand extends PlexCommand { return getEnchantments(item).stream().map(enchantment -> enchantment.key().value()).toArray(String[]::new); } + + @Override + public @NotNull List smartTabComplete(@NotNull CommandSender sender, @NotNull String alias, @NotNull String[] args) throws IllegalArgumentException + { + if (silentCheckPermission(sender, this.getPermission())) + { + if (args.length == 1) + { + return Arrays.asList("add", "reset", "list", "addall", "remove"); + } + if (args[0].equalsIgnoreCase("add") || args[0].equalsIgnoreCase("remove")) + { + Player player = Bukkit.getPlayer(sender.getName()); + if (player != null) + { + return List.of(getEnchantmentNames(player.getActiveItem())); + } + } + return Collections.emptyList(); + } + return Collections.emptyList(); + } } diff --git a/src/main/java/dev/plex/extras/command/EnglishMfCommand.java b/src/main/java/dev/plex/extras/command/EnglishMfCommand.java index 795810f..f809889 100755 --- a/src/main/java/dev/plex/extras/command/EnglishMfCommand.java +++ b/src/main/java/dev/plex/extras/command/EnglishMfCommand.java @@ -1,15 +1,13 @@ package dev.plex.extras.command; +import com.google.common.collect.ImmutableList; import dev.plex.command.PlexCommand; import dev.plex.command.annotation.CommandParameters; import dev.plex.command.annotation.CommandPermissions; import dev.plex.util.PlexUtils; import java.util.List; -import java.util.stream.Collectors; import net.kyori.adventure.text.Component; -import org.bukkit.Bukkit; import org.bukkit.command.CommandSender; -import org.bukkit.entity.HumanEntity; import org.bukkit.entity.Player; import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.Nullable; @@ -39,8 +37,8 @@ public class EnglishMfCommand extends PlexCommand } @Override - public @NotNull List tabComplete(@NotNull CommandSender sender, @NotNull String alias, @NotNull String[] args) throws IllegalArgumentException + public @NotNull List smartTabComplete(@NotNull CommandSender sender, @NotNull String alias, @NotNull String[] args) throws IllegalArgumentException { - return Bukkit.getOnlinePlayers().stream().map(HumanEntity::getName).collect(Collectors.toList()); + return args.length == 1 && silentCheckPermission(sender, this.getPermission()) ? PlexUtils.getPlayerNameList() : ImmutableList.of(); } } diff --git a/src/main/java/dev/plex/extras/command/JumpPadsCommand.java b/src/main/java/dev/plex/extras/command/JumpPadsCommand.java index c91444c..348a197 100755 --- a/src/main/java/dev/plex/extras/command/JumpPadsCommand.java +++ b/src/main/java/dev/plex/extras/command/JumpPadsCommand.java @@ -120,15 +120,19 @@ public class JumpPadsCommand extends PlexCommand } @Override - public @NotNull List tabComplete(@NotNull CommandSender sender, @NotNull String alias, @NotNull String[] args) throws IllegalArgumentException + public @NotNull List smartTabComplete(@NotNull CommandSender sender, @NotNull String alias, @NotNull String[] args) throws IllegalArgumentException { - if (args.length == 1) + if (silentCheckPermission(sender, this.getPermission())) { - return Arrays.asList("none", "normal", "enhanced", "extreme", "ultimate"); - } - else if (args.length == 2) - { - return PlexUtils.getPlayerNameList(); + if (args.length == 1) + { + return Arrays.asList("none", "normal", "enhanced", "extreme", "ultimate"); + } + else if (args.length == 2) + { + return PlexUtils.getPlayerNameList(); + } + return Collections.emptyList(); } return Collections.emptyList(); } diff --git a/src/main/java/dev/plex/extras/command/RandomFishCommand.java b/src/main/java/dev/plex/extras/command/RandomFishCommand.java index 1b84d14..60fc331 100755 --- a/src/main/java/dev/plex/extras/command/RandomFishCommand.java +++ b/src/main/java/dev/plex/extras/command/RandomFishCommand.java @@ -5,6 +5,7 @@ import dev.plex.command.annotation.CommandParameters; import dev.plex.command.annotation.CommandPermissions; import dev.plex.command.source.RequiredCommandSource; import java.util.Arrays; +import java.util.Collections; import java.util.List; import java.util.concurrent.ThreadLocalRandom; import net.kyori.adventure.text.Component; @@ -38,4 +39,10 @@ public class RandomFishCommand extends PlexCommand { return FISH_TYPES.get(ThreadLocalRandom.current().nextInt(FISH_TYPES.size())); } + + @Override + public @NotNull List smartTabComplete(@NotNull CommandSender sender, @NotNull String alias, @NotNull String[] args) throws IllegalArgumentException + { + return Collections.emptyList(); + } } diff --git a/src/main/java/dev/plex/extras/command/slime/MyWorldCommand.java b/src/main/java/dev/plex/extras/command/slime/MyWorldCommand.java index fa69ee5..11570c9 100644 --- a/src/main/java/dev/plex/extras/command/slime/MyWorldCommand.java +++ b/src/main/java/dev/plex/extras/command/slime/MyWorldCommand.java @@ -6,6 +6,10 @@ import dev.plex.command.annotation.CommandPermissions; import dev.plex.command.exception.PlayerNotFoundException; import dev.plex.command.source.RequiredCommandSource; import dev.plex.extras.TFMExtras; +import dev.plex.util.PlexUtils; +import java.util.Arrays; +import java.util.Collections; +import java.util.List; import net.kyori.adventure.text.Component; import org.bukkit.Bukkit; import org.bukkit.Sound; @@ -15,11 +19,6 @@ import org.bukkit.entity.Player; import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.Nullable; -/** - * @author Taah - * @since 7:43 PM [24-08-2023] - */ - @CommandParameters(name = "myworld", usage = "/ [player]") @CommandPermissions(permission = "plex.tfmextras.myworld", source = RequiredCommandSource.IN_GAME) public class MyWorldCommand extends PlexCommand @@ -81,4 +80,22 @@ public class MyWorldCommand extends PlexCommand } return null; } + + @Override + public @NotNull List smartTabComplete(@NotNull CommandSender sender, @NotNull String alias, @NotNull String[] args) throws IllegalArgumentException + { + if (silentCheckPermission(sender, this.getPermission())) + { + if (args.length == 1) + { + return Arrays.asList("create", "goto", "manage", "members", "shared", "add", "remove", "settings"); + } + if (args.length == 2) + { + return PlexUtils.getPlayerNameList(); + } + return Collections.emptyList(); + } + return Collections.emptyList(); + } } diff --git a/src/main/java/dev/plex/extras/command/slime/SlimeManagerCommand.java b/src/main/java/dev/plex/extras/command/slime/SlimeManagerCommand.java index 5572836..6e69fc2 100644 --- a/src/main/java/dev/plex/extras/command/slime/SlimeManagerCommand.java +++ b/src/main/java/dev/plex/extras/command/slime/SlimeManagerCommand.java @@ -8,6 +8,9 @@ import dev.plex.extras.TFMExtras; import dev.plex.util.PlexLog; import dev.plex.util.PlexUtils; import io.papermc.paper.threadedregions.scheduler.ScheduledTask; +import java.util.Arrays; +import java.util.Collections; +import java.util.List; import net.kyori.adventure.text.Component; import org.apache.commons.lang3.StringUtils; import org.bukkit.Bukkit; @@ -16,11 +19,6 @@ import org.bukkit.entity.Player; import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.Nullable; -/** - * @author Taah - * @since 7:11 PM [24-08-2023] - */ - @CommandParameters(name = "slimemanager", usage = "/ [world | all]", description = "Manages the slime worlds handled by the plugin") @CommandPermissions(source = RequiredCommandSource.CONSOLE, permission = "plex.tfmextras.slimemanager") public class SlimeManagerCommand extends PlexCommand @@ -97,4 +95,22 @@ public class SlimeManagerCommand extends PlexCommand } return null; } + + @Override + public @NotNull List smartTabComplete(@NotNull CommandSender sender, @NotNull String alias, @NotNull String[] args) throws IllegalArgumentException + { + if (silentCheckPermission(sender, this.getPermission())) + { + if (args.length == 1) + { + return Arrays.asList("delete", "list"); + } + if (args.length == 2) + { + return TFMExtras.getModule().getSlimeWorldHook().loadedWorlds().stream().toList(); + } + return Collections.emptyList(); + } + return Collections.emptyList(); + } }