@@ -2,31 +2,13 @@ package io.github.frostzie.skyfall.utils.garden
22
33import io.github.frostzie.skyfall.data.GardenPlot
44import io.github.frostzie.skyfall.data.GardenPlots
5- import net.fabricmc.fabric.api.client.message.v1.ClientReceiveMessageEvents
6- import net.minecraft.text.Text
75import net.minecraft.util.Formatting
86
97object SprayUtils {
108
119 private val sprayedPlots: MutableMap <GardenPlot , Long > = mutableMapOf ()
1210 private const val DEFAULT_SPRAY_DURATION_MIN = 30
1311
14- init {
15- ClientReceiveMessageEvents .ALLOW_GAME .register(::onReceiveMessage)
16- }
17-
18- /* *
19- * Callback for incoming chat messages.
20- * It strips formatting from the message and processes only non-overlay chat.
21- */
22- private fun onReceiveMessage (message : Text , overlay : Boolean ): Boolean {
23- if (overlay) return false
24- val cleanMessage = Formatting .strip(message.string)
25- println (" SprayUtils: Received chat message: $cleanMessage " )
26- processChatMessage(cleanMessage.toString())
27- return true
28- }
29-
3012 /* *
3113 * Returns a list of currently sprayed plots by removing any that have expired.
3214 */
@@ -43,8 +25,9 @@ object SprayUtils {
4325 * Expected format: "SPRAYONATOR! You sprayed Plot - [number] ..."
4426 */
4527 fun processChatMessage (message : String ) {
28+ val cleanMessage = Formatting .strip(message) ? : return
4629 val chatRegex = """ SPRAYONATOR!\s+You sprayed Plot - (\d+).*""" .toRegex()
47- val match = chatRegex.find(message )
30+ val match = chatRegex.find(cleanMessage )
4831 match?.groupValues?.get(1 )?.toIntOrNull()?.let { plotNumber ->
4932 GardenPlots .allPlots.find { it.id == plotNumber }?.let { plot ->
5033 val expiration = System .currentTimeMillis() + DEFAULT_SPRAY_DURATION_MIN * 60 * 1000
0 commit comments