package net.knarcraft.minigames.command; import net.knarcraft.minigames.arena.ArenaGameMode; import org.bukkit.command.Command; import org.bukkit.command.CommandSender; import org.bukkit.command.TabCompleter; import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.Nullable; import java.util.ArrayList; import java.util.List; import java.util.function.Supplier; import static net.knarcraft.knarlib.util.TabCompletionHelper.filterMatchingContains; /** * An abstract class for an arena joining tab-completer */ public abstract class JoinArenaTabCompleter implements TabCompleter { private final ArenaGameMode gameMode; private final Supplier> arenaNameSupplier; /** * Implements a new join arena tab completer * * @param arenaNameSupplier

The supplier to ask for arena names

* @param gameMode

An instance of one of the available game-modes

*/ public JoinArenaTabCompleter(Supplier> arenaNameSupplier, ArenaGameMode gameMode) { this.arenaNameSupplier = arenaNameSupplier; this.gameMode = gameMode; } @Override public @Nullable List onTabComplete(@NotNull CommandSender sender, @NotNull Command command, @NotNull String label, @NotNull String[] arguments) { if (arguments.length == 1) { return filterMatchingContains(arenaNameSupplier.get(), arguments[0]); } else if (arguments.length == 2) { List gameModes = new ArrayList<>(); for (ArenaGameMode gameMode : gameMode.getValues()) { gameModes.add(gameMode.name().toLowerCase()); } return filterMatchingContains(gameModes, arguments[1]); } else { return new ArrayList<>(); } } }