parameter
Registers command parameters for the Lamp. This method allows you to define custom parameter types that can be used in commands.
Parameters
types
A vararg of pairs where each pair consists of a Class type and its corresponding ParameterType. Example:
class OnlinePlayer(val player: String) {}
class OnlinePlayerParameter : ParameterType<BukkitCommandActor, OnlinePlayer> {
override fun parse(input: MutableStringStream, context: ExecutionContext<BukkitCommandActor>): OnlinePlayer {
val name = input.readString()
val player = Bukkit.getPlayer(name)
?: throw CommandErrorException("Player with name '$name' is not online or does not exist.")
return OnlinePlayer(player.name)
}
override fun defaultSuggestions(): SuggestionProvider<BukkitCommandActor> {
return SuggestionProvider { _ ->
Bukkit.getOnlinePlayers().map { it.name }.toList()
}
}
}
Content copied to clipboard
Register it like this:
CommandManager().apply {
parameter(
OnlinePlayer::class.java to OnlinePlayerParameter()
)
build()
command(YourCommand())
}
Content copied to clipboard