mirror of
https://github.com/GayPizzaSpecifications/foundation.git
synced 2025-08-02 13:10:55 +00:00
leaderboard: add tab completion
This commit is contained in:
parent
76019a62fc
commit
4e066d8f11
@ -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<out String>
|
||||
): MutableList<String> = when {
|
||||
args.isEmpty() -> {
|
||||
leaderboards.map { it.id }.toMutableList()
|
||||
}
|
||||
args.size == 1 -> {
|
||||
leaderboards.map { it.id }.filter { it.startsWith(args[0]) }.toMutableList()
|
||||
}
|
||||
else -> {
|
||||
mutableListOf()
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -73,17 +73,15 @@ class PersistentStoreCommand(private val plugin: FoundationCorePlugin) : Command
|
||||
command: Command,
|
||||
alias: String,
|
||||
args: Array<out String>
|
||||
): MutableList<String> {
|
||||
return when {
|
||||
args.isEmpty() -> {
|
||||
allSubCommands
|
||||
}
|
||||
args.size == 1 -> {
|
||||
allSubCommands.filter { it.startsWith(args[0]) }.toMutableList()
|
||||
}
|
||||
else -> {
|
||||
mutableListOf()
|
||||
}
|
||||
): MutableList<String> = when {
|
||||
args.isEmpty() -> {
|
||||
allSubCommands
|
||||
}
|
||||
args.size == 1 -> {
|
||||
allSubCommands.filter { it.startsWith(args[0]) }.toMutableList()
|
||||
}
|
||||
else -> {
|
||||
mutableListOf()
|
||||
}
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user