Skip to content

Commit

Permalink
Replace deprecated method calls to kotlin time
Browse files Browse the repository at this point in the history
  • Loading branch information
My-Name-Is-Jeff committed Mar 21, 2023
1 parent 2ce610f commit 6c822d6
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 14 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -36,8 +36,7 @@ import net.minecraft.item.ItemStack
import net.minecraftforge.client.event.ClientChatReceivedEvent
import net.minecraftforge.fml.common.eventhandler.EventPriority
import net.minecraftforge.fml.common.eventhandler.SubscribeEvent
import kotlin.time.Duration
import kotlin.time.ExperimentalTime
import kotlin.time.Duration.Companion.milliseconds

object MayorJerry {

Expand Down Expand Up @@ -79,13 +78,12 @@ object MayorJerry {
}

class JerryPerkGuiElement : GuiElement("Mayor Jerry Perk Display", FloatPair(10, 10)) {
@OptIn(ExperimentalTime::class)
override fun render() {
if (Utils.inSkyblock && toggled && MayorInfo.currentMayor == "Jerry") {
if (MayorInfo.jerryMayor == null || MayorInfo.newJerryPerks <= System.currentTimeMillis()) {
ScreenRenderer.fontRenderer.drawString("Visit Jerry!", 0f, 0f, CommonColors.RED)
} else {
val timeUntilNext = Duration.milliseconds(MayorInfo.newJerryPerks - System.currentTimeMillis())
val timeUntilNext = (MayorInfo.newJerryPerks - System.currentTimeMillis()).milliseconds
ScreenRenderer.fontRenderer.drawString(
"${MayorInfo.jerryMayor!!.name}: ${
timeUntilNext.toComponents { hours, minutes, _, _ ->
Expand Down Expand Up @@ -129,11 +127,10 @@ object MayorJerry {
class JerryTimerGuiElement : GuiElement("Hidden Jerry Timer", FloatPair(10, 10)) {
private val villagerEgg = ItemStack(Items.spawn_egg, 1, 120)

@OptIn(ExperimentalTime::class)
override fun render() {
if (Utils.inSkyblock && toggled && lastJerry != -1L) {
renderItem(villagerEgg, 0, 0)
val elapsed = Duration.milliseconds(System.currentTimeMillis() - lastJerry)
val elapsed = (System.currentTimeMillis() - lastJerry).milliseconds
ScreenRenderer.fontRenderer.drawString(
elapsed.toComponents { minutes, seconds, _ ->
"${if (minutes >= 6) "§a" else ""}${minutes}:${
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -46,8 +46,8 @@ import java.net.URLEncoder
import java.util.*
import kotlin.math.abs
import kotlin.math.round
import kotlin.time.Duration
import kotlin.time.ExperimentalTime
import kotlin.time.Duration.Companion.hours
import kotlin.time.Duration.Companion.minutes

object MayorInfo {

Expand Down Expand Up @@ -140,7 +140,6 @@ object MayorInfo {
}
}

@OptIn(ExperimentalTime::class)
@SubscribeEvent
fun onDrawSlot(event: GuiContainerEvent.DrawSlotEvent.Post) {
if (!Utils.inSkyblock) return
Expand Down Expand Up @@ -195,7 +194,7 @@ object MayorInfo {
} ?: return
val matcher = jerryNextPerkRegex.find(endingIn) ?: return
val timeLeft =
Duration.hours(matcher.groups["h"]!!.value.toInt()) + Duration.minutes(matcher.groups["m"]!!.value.toInt())
matcher.groups["h"]!!.value.toInt().hours + matcher.groups["m"]!!.value.toInt().minutes
val nextPerksNoRound = System.currentTimeMillis() + timeLeft.inWholeMilliseconds
val nextPerks = round(nextPerksNoRound / 300000.0).toLong() * 300000L
if (jerryMayor != mayor || abs(nextPerks - newJerryPerks) > 60000) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -78,8 +78,7 @@ import net.minecraftforge.fml.common.eventhandler.EventPriority
import net.minecraftforge.fml.common.eventhandler.SubscribeEvent
import net.minecraftforge.fml.common.gameevent.TickEvent
import java.awt.Color
import kotlin.time.Duration
import kotlin.time.ExperimentalTime
import kotlin.time.Duration.Companion.milliseconds

object MiscFeatures {
private var golemSpawnTime: Long = 0
Expand Down Expand Up @@ -134,7 +133,6 @@ object MiscFeatures {
}
}

@OptIn(ExperimentalTime::class)
@SubscribeEvent(priority = EventPriority.HIGHEST, receiveCanceled = true)
fun onChat(event: ClientChatReceivedEvent) {
if (!Utils.inSkyblock) return
Expand All @@ -160,7 +158,7 @@ object MiscFeatures {
}
}
if (unformatted == "Your zapper is temporarily fatigued!") {
val duration = Duration.milliseconds(blockZapperCooldownExpiration - System.currentTimeMillis())
val duration = (blockZapperCooldownExpiration - System.currentTimeMillis()).milliseconds
printDevMessage("$blockZapperUses ${duration.inWholeSeconds}", "zapper")
if (duration.isPositive()) {
UChat.chat("$prefix §eThis will expire in${
Expand Down

0 comments on commit 6c822d6

Please sign in to comment.