Commit c31c920f authored by Setako's avatar Setako

[Add] Common candidates iterable for command completion

parent 65e9d165
package dev.reactant.reactant.core.commands.completion
import org.bukkit.Bukkit
/**
* We will not guarantee the correctness of following list
* Please only use those class as picocli command candidates
*
* DO NOT use in your logic!
*/
class CommonCandidates {
class Player {
class Online {
class Name : Iterable<String> {
override fun iterator(): Iterator<String> = Bukkit.getOnlinePlayers().map { it.name }.iterator()
}
class UUID : Iterable<String> {
override fun iterator(): Iterator<String> = Bukkit.getOnlinePlayers().map { it.uniqueId.toString() }.iterator()
}
}
class Offline {
class Name : Iterable<String> {
override fun iterator(): Iterator<String> = Bukkit.getOnlinePlayers().map { it.name }.iterator()
}
class UUID : Iterable<String> {
override fun iterator(): Iterator<String> = Bukkit.getOnlinePlayers().map { it.uniqueId.toString() }.iterator()
}
}
class Banned {
class Name : Iterable<String> {
override fun iterator(): Iterator<String> = Bukkit.getBannedPlayers().mapNotNull { it.name }.iterator()
}
class UUID : Iterable<String> {
override fun iterator(): Iterator<String> = Bukkit.getBannedPlayers().map { it.uniqueId.toString() }.iterator()
}
class IP : Iterable<String> {
override fun iterator(): Iterator<String> = Bukkit.getIPBans().iterator()
}
}
class Operator {
class Name : Iterable<String> {
override fun iterator(): Iterator<String> = Bukkit.getOperators().mapNotNull { it.name }.iterator()
}
class UUID : Iterable<String> {
override fun iterator(): Iterator<String> = Bukkit.getOperators().map { it.uniqueId.toString() }.iterator()
}
}
class Whitelisted {
class Name : Iterable<String> {
override fun iterator(): Iterator<String> = Bukkit.getWhitelistedPlayers().mapNotNull { it.name }.iterator()
}
class UUID : Iterable<String> {
override fun iterator(): Iterator<String> = Bukkit.getWhitelistedPlayers().map { it.uniqueId.toString() }.iterator()
}
}
}
class World {
class Name : Iterable<String> {
override fun iterator(): Iterator<String> = Bukkit.getWorlds().map { it.name }.iterator()
}
class UUID : Iterable<String> {
override fun iterator(): Iterator<String> = Bukkit.getWorlds().map { it.uid.toString() }.iterator()
}
}
}
package dev.reactant.reactant.core.commands.completion
import dev.reactant.reactant.core.ReactantCore
import dev.reactant.reactant.core.dependency.ProviderManager
import kotlin.reflect.jvm.jvmErasure
import kotlin.reflect.jvm.jvmName
class ReactantInternalCommandCandidates {
class ComponentClassNames : Iterable<String> {
override fun iterator(): Iterator<String> = (ReactantCore.instance.instanceManager.getInstance(ProviderManager::class)?.let {
it.providers.union(it.blacklistedProviders).map { it.productType.jvmErasure.jvmName }.toList()
} ?: listOf()).iterator()
}
}
package dev.reactant.reactant.core.commands.provider
import dev.reactant.reactant.core.commands.ReactantPermissions
import dev.reactant.reactant.core.commands.completion.ReactantInternalCommandCandidates.ComponentClassNames
import dev.reactant.reactant.core.component.container.ContainerManager
import dev.reactant.reactant.core.dependency.ProviderManager
import dev.reactant.reactant.core.dependency.injection.producer.Provider
......@@ -42,7 +43,8 @@ internal class ReactantProviderListSubCommand(
@CommandLine.Parameters(arity = "1", paramLabel = "TARGET_CLASS_NAME",
description = ["The canonical name of searching class or interface"])
description = ["The canonical name of searching class or interface"],
completionCandidates = ComponentClassNames::class)
var targetClassName: String = ""
private val listTable = MultiColumns.create {
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment