From 4e066d8f11ce9ccc9e1b248d1a3d9e8fc35d0b60 Mon Sep 17 00:00:00 2001 From: Kenneth Endfinger Date: Thu, 23 Dec 2021 02:32:14 -0500 Subject: [PATCH] leaderboard: add tab completion --- .../core/command/LeaderboardCommand.kt | 20 ++++++++++++++++++- .../core/command/PersistentStoreCommand.kt | 20 +++++++++---------- 2 files changed, 28 insertions(+), 12 deletions(-) diff --git a/foundation-core/src/main/kotlin/cloud/kubelet/foundation/core/command/LeaderboardCommand.kt b/foundation-core/src/main/kotlin/cloud/kubelet/foundation/core/command/LeaderboardCommand.kt index 4d9dc04..3e11ea4 100644 --- a/foundation-core/src/main/kotlin/cloud/kubelet/foundation/core/command/LeaderboardCommand.kt +++ b/foundation-core/src/main/kotlin/cloud/kubelet/foundation/core/command/LeaderboardCommand.kt @@ -6,8 +6,9 @@ import org.bukkit.Statistic import org.bukkit.command.Command import org.bukkit.command.CommandExecutor import org.bukkit.command.CommandSender +import org.bukkit.command.TabCompleter -class LeaderboardCommand : CommandExecutor { +class LeaderboardCommand : CommandExecutor, TabCompleter { private val leaderboards = listOf( LeaderboardType("player-kills", Statistic.PLAYER_KILLS, "Player Kills", "kills"), LeaderboardType("mob-kills", Statistic.MOB_KILLS, "Mob Kills", "kills"), @@ -36,4 +37,21 @@ class LeaderboardCommand : CommandExecutor { } class LeaderboardType(val id: String, val statistic: Statistic, val friendlyName: String, val unit: String) + + override fun onTabComplete( + sender: CommandSender, + command: Command, + alias: String, + args: Array + ): MutableList = when { + args.isEmpty() -> { + leaderboards.map { it.id }.toMutableList() + } + args.size == 1 -> { + leaderboards.map { it.id }.filter { it.startsWith(args[0]) }.toMutableList() + } + else -> { + mutableListOf() + } + } } diff --git a/foundation-core/src/main/kotlin/cloud/kubelet/foundation/core/command/PersistentStoreCommand.kt b/foundation-core/src/main/kotlin/cloud/kubelet/foundation/core/command/PersistentStoreCommand.kt index 89e7c14..56387a5 100644 --- a/foundation-core/src/main/kotlin/cloud/kubelet/foundation/core/command/PersistentStoreCommand.kt +++ b/foundation-core/src/main/kotlin/cloud/kubelet/foundation/core/command/PersistentStoreCommand.kt @@ -73,17 +73,15 @@ class PersistentStoreCommand(private val plugin: FoundationCorePlugin) : Command command: Command, alias: String, args: Array - ): MutableList { - return when { - args.isEmpty() -> { - allSubCommands - } - args.size == 1 -> { - allSubCommands.filter { it.startsWith(args[0]) }.toMutableList() - } - else -> { - mutableListOf() - } + ): MutableList = when { + args.isEmpty() -> { + allSubCommands + } + args.size == 1 -> { + allSubCommands.filter { it.startsWith(args[0]) }.toMutableList() + } + else -> { + mutableListOf() } } }