-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: Personal Time and Weather (#148)
- Loading branch information
1 parent
1e88576
commit 0467b57
Showing
3 changed files
with
174 additions
and
0 deletions.
There are no files selected for viewing
84 changes: 84 additions & 0 deletions
84
src/main/kotlin/net/blockventuremc/modules/general/commands/club/PersonalTimeCommand.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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() | ||
} | ||
} | ||
} |
82 changes: 82 additions & 0 deletions
82
src/main/kotlin/net/blockventuremc/modules/general/commands/club/PersonalWeatherCommand.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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() | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters