Blindly wrote a command.

This commit is contained in:
Logan Gorence 2022-01-09 23:46:43 -08:00
parent 3ac24f6912
commit 203ecd1ca9
3 changed files with 54 additions and 0 deletions

View File

@ -0,0 +1,50 @@
package cloud.kubelet.foundation.core.features.player
import org.bukkit.GameMode
import org.bukkit.WeatherType
import org.bukkit.command.Command
import org.bukkit.command.CommandExecutor
import org.bukkit.command.CommandSender
import org.bukkit.command.TabCompleter
import org.bukkit.entity.Player
class LocalWeatherCommand : CommandExecutor, TabCompleter {
private val weatherTypes = WeatherType.values().associateBy { it.name.lowercase() }
override fun onCommand(
sender: CommandSender,
command: Command,
label: String,
args: Array<out String>
): Boolean {
if (sender !is Player) {
sender.sendMessage("You are not a player.")
return true
}
if (args.size != 1) {
return false
}
val name = args[0].lowercase()
val weatherType = weatherTypes[name]
if (weatherType == null) {
sender.sendMessage("Not a valid weather type.")
return true
}
sender.setPlayerWeather(weatherType)
sender.sendMessage("Weather set to \"$name\"")
return true
}
override fun onTabComplete(
sender: CommandSender,
command: Command,
alias: String,
args: Array<out String>
): List<String> = when {
args.isEmpty() -> weatherTypes.keys.toList()
else -> listOf()
}
}

View File

@ -9,5 +9,6 @@ class PlayerFeature : Feature() {
registerCommandExecutor(listOf("creative", "c"), GamemodeCommand(GameMode.CREATIVE)) registerCommandExecutor(listOf("creative", "c"), GamemodeCommand(GameMode.CREATIVE))
registerCommandExecutor(listOf("adventure", "a"), GamemodeCommand(GameMode.ADVENTURE)) registerCommandExecutor(listOf("adventure", "a"), GamemodeCommand(GameMode.ADVENTURE))
registerCommandExecutor(listOf("spectator", "sp"), GamemodeCommand(GameMode.SPECTATOR)) registerCommandExecutor(listOf("spectator", "sp"), GamemodeCommand(GameMode.SPECTATOR))
registerCommandExecutor(listOf("localweather", "lw"), LocalWeatherCommand())
} }
} }

View File

@ -57,3 +57,6 @@ commands:
description: Teleport to the spawn of the current world. description: Teleport to the spawn of the current world.
usage: /spawn usage: /spawn
permission: foundation.command.spawn permission: foundation.command.spawn
localweather:
description: Set the player's local weather in the client.
usage: /localweather <type>