From 203ecd1ca98d24ee12da87561e26a38bbe0c6558 Mon Sep 17 00:00:00 2001 From: Logan Gorence Date: Sun, 9 Jan 2022 23:46:43 -0800 Subject: [PATCH] Blindly wrote a command. --- .../features/player/LocalWeatherCommand.kt | 50 +++++++++++++++++++ .../core/features/player/PlayerFeature.kt | 1 + foundation-core/src/main/resources/plugin.yml | 3 ++ 3 files changed, 54 insertions(+) create mode 100644 foundation-core/src/main/kotlin/cloud/kubelet/foundation/core/features/player/LocalWeatherCommand.kt diff --git a/foundation-core/src/main/kotlin/cloud/kubelet/foundation/core/features/player/LocalWeatherCommand.kt b/foundation-core/src/main/kotlin/cloud/kubelet/foundation/core/features/player/LocalWeatherCommand.kt new file mode 100644 index 0000000..1ad22ec --- /dev/null +++ b/foundation-core/src/main/kotlin/cloud/kubelet/foundation/core/features/player/LocalWeatherCommand.kt @@ -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 + ): 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 + ): List = when { + args.isEmpty() -> weatherTypes.keys.toList() + else -> listOf() + } +} diff --git a/foundation-core/src/main/kotlin/cloud/kubelet/foundation/core/features/player/PlayerFeature.kt b/foundation-core/src/main/kotlin/cloud/kubelet/foundation/core/features/player/PlayerFeature.kt index 7d1f769..35b6046 100644 --- a/foundation-core/src/main/kotlin/cloud/kubelet/foundation/core/features/player/PlayerFeature.kt +++ b/foundation-core/src/main/kotlin/cloud/kubelet/foundation/core/features/player/PlayerFeature.kt @@ -9,5 +9,6 @@ class PlayerFeature : Feature() { registerCommandExecutor(listOf("creative", "c"), GamemodeCommand(GameMode.CREATIVE)) registerCommandExecutor(listOf("adventure", "a"), GamemodeCommand(GameMode.ADVENTURE)) registerCommandExecutor(listOf("spectator", "sp"), GamemodeCommand(GameMode.SPECTATOR)) + registerCommandExecutor(listOf("localweather", "lw"), LocalWeatherCommand()) } } diff --git a/foundation-core/src/main/resources/plugin.yml b/foundation-core/src/main/resources/plugin.yml index 529c5eb..7b4c483 100644 --- a/foundation-core/src/main/resources/plugin.yml +++ b/foundation-core/src/main/resources/plugin.yml @@ -57,3 +57,6 @@ commands: description: Teleport to the spawn of the current world. usage: /spawn permission: foundation.command.spawn + localweather: + description: Set the player's local weather in the client. + usage: /localweather