Skip to content

Commit

Permalink
feat: Personal Time and Weather (#148)
Browse files Browse the repository at this point in the history
  • Loading branch information
CoasterFreakDE authored May 22, 2024
1 parent 1e88576 commit 0467b57
Show file tree
Hide file tree
Showing 3 changed files with 174 additions and 0 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,84 @@
package net.blockventuremc.modules.general.commands.club

import net.blockventuremc.annotations.VentureCommand
import net.blockventuremc.extensions.sendMessagePrefixed
import net.blockventuremc.extensions.translate
import org.bukkit.command.Command
import org.bukkit.command.CommandExecutor
import org.bukkit.command.CommandSender
import org.bukkit.command.TabExecutor
import org.bukkit.entity.Player
import org.bukkit.permissions.PermissionDefault

@VentureCommand(
name = "personaltime",
description = "Toggle personal time",
permission = "blockventure.personaltime",
permissionDefault = PermissionDefault.OP,
usage = "/personaltime [reset|noon|midnight|day|night|<0-24000>]",
aliases = ["pt", "ptime"]
)
class PersonalTimeCommand : CommandExecutor, TabExecutor {

override fun onCommand(sender: CommandSender, command: Command, label: String, args: Array<out String>): Boolean {
if (sender !is Player) return true

if (args.isEmpty()) {
sender.sendMessagePrefixed(
sender.translate(
"commands.personaltime.current",
mapOf("time" to sender.playerTime)
)?.message ?: "Personal current time: <color:#feca57>${sender.playerTime}</color>. Use <color:#c8d6e5>/personaltime <reset|noon|midnight|day|night|<0-24000>></color> to change it."
)
return true
}

val time = when (args[0]) {
"reset" -> -1L
"noon" -> 6000L
"midnight" -> 18000L
"day" -> 1000L
"night" -> 13000L
else -> try {
args[0].toLong()
} catch (e: NumberFormatException) {
sender.sendMessagePrefixed(
sender.translate(
"commands.personaltime.invalid",
mapOf()
)?.message ?: "Invalid time. Use <color:#c8d6e5>/personaltime <reset|noon|midnight|day|night|<0-24000>></color> to change it."
)
return true
}
}

if (time !in 0..24000) {
sender.resetPlayerTime()
sender.sendMessagePrefixed(
sender.translate(
"commands.personaltime.reset",
mapOf("time" to sender.world.time)
)?.message ?: "Personal time reset to <color:#feca57>${sender.world.time}</color>."
)
return true
}

sender.setPlayerTime(time, false)
sender.sendMessagePrefixed(
sender.translate(
"commands.personaltime.set",
mapOf("time" to time)
)?.message ?: "Personal time set to <color:#feca57>$time</color>."
)
return true
}

override fun onTabComplete(
sender: CommandSender, command: Command, label: String, args: Array<out String>
): List<String> {
return when (args.size) {
1 -> listOf("reset", "noon", "midnight", "day", "night").filter { it.startsWith(args[0]) }
else -> emptyList()
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,82 @@
package net.blockventuremc.modules.general.commands.club

import net.blockventuremc.annotations.VentureCommand
import net.blockventuremc.extensions.sendMessagePrefixed
import net.blockventuremc.extensions.translate
import org.bukkit.WeatherType
import org.bukkit.command.Command
import org.bukkit.command.CommandExecutor
import org.bukkit.command.CommandSender
import org.bukkit.command.TabExecutor
import org.bukkit.entity.Player
import org.bukkit.permissions.PermissionDefault

@VentureCommand(
name = "personaweather",
description = "Toggle personal weather",
permission = "blockventure.personaweather",
permissionDefault = PermissionDefault.OP,
usage = "/personaweather [reset|clear|rain]",
aliases = ["pw", "pweather"]
)
class PersonalWeatherCommand : CommandExecutor, TabExecutor {

override fun onCommand(sender: CommandSender, command: Command, label: String, args: Array<out String>): Boolean {
if (sender !is Player) return true

if (args.isEmpty()) {
sender.sendMessagePrefixed(
sender.translate(
"commands.personaweather.current",
mapOf("weather" to (sender.playerWeather?.name ?: "None"))
)?.message ?: "Personal current weather: <color:#feca57>${sender.playerWeather?.name ?: "None"}</color>. Use <color:#c8d6e5>/personaweather <reset|clear|rain></color> to change it."
)
return true
}

if (args[0] == "reset") {
sender.resetPlayerWeather()
sender.sendMessagePrefixed(
sender.translate(
"commands.personaweather.reset",
mapOf()
)?.message ?: "Personal weather reset."
)
return true
}

val weather = when (args[0]) {
"clear" -> WeatherType.CLEAR
"rain" -> WeatherType.DOWNFALL
else -> {
sender.sendMessagePrefixed(
sender.translate(
"commands.personaweather.invalid",
mapOf()
)?.message ?: "Invalid weather. Use <color:#c8d6e5>/personalweather <reset|clear|rain></color> to change it."
)
return true
}
}

sender.setPlayerWeather(weather)

sender.sendMessagePrefixed(
sender.translate(
"commands.personaweather.set",
mapOf("weather" to weather.name)
)?.message ?: "Personal weather set to <color:#feca57>${weather.name}</color>."
)

return true
}

override fun onTabComplete(
sender: CommandSender, command: Command, label: String, args: Array<out String>
): List<String> {
return when (args.size) {
1 -> listOf("reset", "clear", "rain").filter { it.startsWith(args[0]) }
else -> emptyList()
}
}
}
8 changes: 8 additions & 0 deletions src/main/resources/translations/en-US.json
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,14 @@
"commands.warp.create.success": "<green>Warp <yellow>%warp%</yellow> created for rank %rank%.",
"commands.warp.invalid_usage": "<color:#e74c3c>Invalid usage. Use <color:#f78fb3>/warp <color:#e74c3c>to teleport to a warp.",
"commands.warp.invalid_rank": "<color:#f78fb3>%rank% <color:#e74c3c>is no valid rank.",
"commands.personaltime.current": "Personal current time: <color:#feca57>%time%</color>. Use <color:#c8d6e5>/personaltime <reset|noon|midnight|day|night|<0-24000>></color> to change it.",
"commands.personaltime.reset": "Personal time reset to <color:#feca57>%time%</color>.",
"commands.personaltime.invalid": "Invalid time. Use <color:#c8d6e5>/personaltime <reset|noon|midnight|day|night|<0-24000>></color> to change it.",
"commands.personaltime.set": "Personal time set to <color:#feca57>%time%</color>.",
"commands.personaweather.current": "Personal current weather: <color:#feca57>%weather%</color>. Use <color:#c8d6e5>/personalweather <reset|clear|rain></color> to change it.",
"commands.personaweather.reset": "Personal weather reset.",
"commands.personaweather.invalid": "Invalid weather. Use <color:#c8d6e5>/personalweather <reset|clear|rain></color> to change it.",
"commands.personaweather.set": "Personal weather set to <color:#feca57>%weather%</color>.",
"booster.category.event": "Event Booster",
"booster.category.shop_refill": "Shop Refill Booster",
"booster.category.user_activated": "User Activated Booster",
Expand Down

0 comments on commit 0467b57

Please sign in to comment.