diff options
Diffstat (limited to 'src/main/java/at')
17 files changed, 152 insertions, 119 deletions
diff --git a/src/main/java/at/hannibal2/skyhanni/config/features/Ashfang.java b/src/main/java/at/hannibal2/skyhanni/config/features/Ashfang.java index f92b576b1..9708f5dd4 100644 --- a/src/main/java/at/hannibal2/skyhanni/config/features/Ashfang.java +++ b/src/main/java/at/hannibal2/skyhanni/config/features/Ashfang.java @@ -20,7 +20,7 @@ public class Ashfang { public Position freezeCooldownPos = new Position(10, 10, false, true); @Expose - @ConfigOption(name = "Reset Time", desc = "Shows the cooldown until ashfang pulls his underlings back.") + @ConfigOption(name = "Reset Time", desc = "Show the cooldown until ashfang pulls his underlings back.") @ConfigEditorBoolean public boolean nextResetCooldown = false; diff --git a/src/main/java/at/hannibal2/skyhanni/config/features/DamageIndicator.java b/src/main/java/at/hannibal2/skyhanni/config/features/DamageIndicator.java index c8a9dd750..c392edeba 100644 --- a/src/main/java/at/hannibal2/skyhanni/config/features/DamageIndicator.java +++ b/src/main/java/at/hannibal2/skyhanni/config/features/DamageIndicator.java @@ -81,4 +81,9 @@ public class DamageIndicator { @ConfigOption(name = "Hide Nametag", desc = "Hide the vanilla nametag of damage indicator bosses.") @ConfigEditorBoolean public boolean hideVanillaNametag = false; + + @Expose + @ConfigOption(name = "Time to Kill", desc = "Show the time it takes to kill the Slayer boss.") + @ConfigEditorBoolean + public boolean timeToKillSlayer = true; } diff --git a/src/main/java/at/hannibal2/skyhanni/config/features/Fishing.java b/src/main/java/at/hannibal2/skyhanni/config/features/Fishing.java index 325dd1333..9bb106829 100644 --- a/src/main/java/at/hannibal2/skyhanni/config/features/Fishing.java +++ b/src/main/java/at/hannibal2/skyhanni/config/features/Fishing.java @@ -60,7 +60,7 @@ public class Fishing { @Expose @ConfigOption( name = "Barn Fishing Timer", - desc = "Shows the time and amount of sea creatures while fishing on the barn via hub." + desc = "Show the time and amount of sea creatures while fishing on the barn via hub." ) @ConfigEditorBoolean @ConfigAccordionId(id = 2) diff --git a/src/main/java/at/hannibal2/skyhanni/config/features/Mobs.java b/src/main/java/at/hannibal2/skyhanni/config/features/Mobs.java index 2253dc3eb..d135427e0 100644 --- a/src/main/java/at/hannibal2/skyhanni/config/features/Mobs.java +++ b/src/main/java/at/hannibal2/skyhanni/config/features/Mobs.java @@ -38,7 +38,10 @@ public class Mobs { public boolean zealotBruiserHighlighter = false; @Expose - @ConfigOption(name = "Special Zealots", desc = "Highlight Special Zealots in The End. (The one that drops Summoning Eyes)") + @ConfigOption( + name = "Special Zealots", + desc = "Highlight Special Zealots in The End. (The one that drops Summoning Eyes)" + ) @ConfigEditorBoolean @ConfigAccordionId(id = 0) public boolean specialZealotHighlighter = true; @@ -55,7 +58,11 @@ public class Mobs { public boolean timers = false; @Expose - @ConfigOption(name = "Area Boss", desc = "Show a timer when Golden Ghoul, Old Wolf, Voidling Extremist or Millenia-Aged Blaze respawns.") + @ConfigOption( + name = "Area Boss", + desc = "Show a timer when Golden Ghoul, Old Wolf, Voidling Extremist or Millenia-Aged Blaze respawns. " + + "§cSometimes it takes 20-30 seconds to calibrate correctly." + ) @ConfigEditorBoolean @ConfigAccordionId(id = 1) public boolean areaBossRespawnTimer = false; diff --git a/src/main/java/at/hannibal2/skyhanni/features/bazaar/BazaarUpdateTimer.kt b/src/main/java/at/hannibal2/skyhanni/features/bazaar/BazaarUpdateTimer.kt index 0a99f942a..a60af8ec8 100644 --- a/src/main/java/at/hannibal2/skyhanni/features/bazaar/BazaarUpdateTimer.kt +++ b/src/main/java/at/hannibal2/skyhanni/features/bazaar/BazaarUpdateTimer.kt @@ -5,10 +5,11 @@ import at.hannibal2.skyhanni.events.BazaarUpdateEvent import at.hannibal2.skyhanni.utils.InventoryUtils import at.hannibal2.skyhanni.utils.LorenzUtils import at.hannibal2.skyhanni.utils.RenderUtils.renderStrings +import at.hannibal2.skyhanni.utils.TimeUnit +import at.hannibal2.skyhanni.utils.TimeUtils import net.minecraftforge.client.event.GuiScreenEvent import net.minecraftforge.fml.common.eventhandler.EventPriority import net.minecraftforge.fml.common.eventhandler.SubscribeEvent -import java.text.DecimalFormat class BazaarUpdateTimer { private var lastBazaarUpdateTime = 0L @@ -24,13 +25,11 @@ class BazaarUpdateTimer { if (!isEnabled()) return if (!BazaarApi.isBazaarInventory(InventoryUtils.openInventoryName())) return - val duration = System.currentTimeMillis() - lastBazaarUpdateTime - val durationSeconds = duration.toDouble() / 1000 - val nextUpdateIn = 10 - durationSeconds - val format = if (nextUpdateIn < 0) { + val duration = 10_000 - (System.currentTimeMillis() - lastBazaarUpdateTime) + val format = if (duration < 0) { "Updating" } else { - DecimalFormat("0.0").format(nextUpdateIn) + TimeUtils.formatDuration(duration, TimeUnit.SECOND, showMilliSeconds = true) } val list = mutableListOf<String>() diff --git a/src/main/java/at/hannibal2/skyhanni/features/damageindicator/BossType.kt b/src/main/java/at/hannibal2/skyhanni/features/damageindicator/BossType.kt index 2f7e09184..c0b282e18 100644 --- a/src/main/java/at/hannibal2/skyhanni/features/damageindicator/BossType.kt +++ b/src/main/java/at/hannibal2/skyhanni/features/damageindicator/BossType.kt @@ -1,6 +1,6 @@ package at.hannibal2.skyhanni.features.damageindicator -enum class BossType(val fullName: String, val bossTypeToggle: Int, val shortName: String = fullName) { +enum class BossType(val fullName: String, val bossTypeToggle: Int, val shortName: String = fullName, val showDeathTime: Boolean = false) { GENERIC_DUNGEON_BOSS("Generic Dungeon boss", 0),//TODO split into different bosses //Nether Mini Bosses @@ -15,31 +15,31 @@ enum class BossType(val fullName: String, val bossTypeToggle: Int, val shortName END_ENDSTONE_PROTECTOR("§cEndstone Protector", 3), END_ENDER_DRAGON("Ender Dragon", 4),//TODO fix totally - SLAYER_ZOMBIE_1("§aRevenant Horror 1", 5, "§aRev 1"), - SLAYER_ZOMBIE_2("§eRevenant Horror 2", 5, "§eRev 2"), - SLAYER_ZOMBIE_3("§cRevenant Horror 3", 5, "§cRev 3"), - SLAYER_ZOMBIE_4("§4Revenant Horror 4", 5, "§4Rev 4"), - SLAYER_ZOMBIE_5("§5Revenant Horror 5", 5, "§5Rev 5"), - - SLAYER_SPIDER_1("§aTarantula Broodfather 1", 6, "§aTara 1"), - SLAYER_SPIDER_2("§eTarantula Broodfather 2", 6, "§eTara 2"), - SLAYER_SPIDER_3("§cTarantula Broodfather 3", 6, "§cTara 3"), - SLAYER_SPIDER_4("§4Tarantula Broodfather 4", 6, "§4Tara 4"), - - SLAYER_WOLF_1("§aSven Packmaster 1", 7, "§aSven 1"), - SLAYER_WOLF_2("§eSven Packmaster 2", 7, "§eSven 2"), - SLAYER_WOLF_3("§cSven Packmaster 3", 7, "§cSven 3"), - SLAYER_WOLF_4("§4Sven Packmaster 4", 7, "§4Sven 4"), - - SLAYER_ENDERMAN_1("§aVoidgloom Seraph 1", 8, "§aVoid 1"), - SLAYER_ENDERMAN_2("§eVoidgloom Seraph 2", 8, "§eVoid 2"), - SLAYER_ENDERMAN_3("§cVoidgloom Seraph 3", 8, "§cVoid 3"), - SLAYER_ENDERMAN_4("§4Voidgloom Seraph 4", 8, "§4Void 4"), - - SLAYER_BLAZE_1("§aInferno Demonlord 1", 9, "§aInferno 1"), - SLAYER_BLAZE_2("§aInferno Demonlord 2", 9, "§aInferno 2"), - SLAYER_BLAZE_3("§aInferno Demonlord 3", 9, "§aInferno 3"), - SLAYER_BLAZE_4("§aInferno Demonlord 4", 9, "§aInferno 4"), + SLAYER_ZOMBIE_1("§aRevenant Horror 1", 5, "§aRev 1", showDeathTime = true), + SLAYER_ZOMBIE_2("§eRevenant Horror 2", 5, "§eRev 2", showDeathTime = true), + SLAYER_ZOMBIE_3("§cRevenant Horror 3", 5, "§cRev 3", showDeathTime = true), + SLAYER_ZOMBIE_4("§4Revenant Horror 4", 5, "§4Rev 4", showDeathTime = true), + SLAYER_ZOMBIE_5("§5Revenant Horror 5", 5, "§5Rev 5", showDeathTime = true), + + SLAYER_SPIDER_1("§aTarantula Broodfather 1", 6, "§aTara 1", showDeathTime = true), + SLAYER_SPIDER_2("§eTarantula Broodfather 2", 6, "§eTara 2", showDeathTime = true), + SLAYER_SPIDER_3("§cTarantula Broodfather 3", 6, "§cTara 3", showDeathTime = true), + SLAYER_SPIDER_4("§4Tarantula Broodfather 4", 6, "§4Tara 4", showDeathTime = true), + + SLAYER_WOLF_1("§aSven Packmaster 1", 7, "§aSven 1", showDeathTime = true), + SLAYER_WOLF_2("§eSven Packmaster 2", 7, "§eSven 2", showDeathTime = true), + SLAYER_WOLF_3("§cSven Packmaster 3", 7, "§cSven 3", showDeathTime = true), + SLAYER_WOLF_4("§4Sven Packmaster 4", 7, "§4Sven 4", showDeathTime = true), + + SLAYER_ENDERMAN_1("§aVoidgloom Seraph 1", 8, "§aVoid 1", showDeathTime = true), + SLAYER_ENDERMAN_2("§eVoidgloom Seraph 2", 8, "§eVoid 2", showDeathTime = true), + SLAYER_ENDERMAN_3("§cVoidgloom Seraph 3", 8, "§cVoid 3", showDeathTime = true), + SLAYER_ENDERMAN_4("§4Voidgloom Seraph 4", 8, "§4Void 4", showDeathTime = true), + + SLAYER_BLAZE_1("§aInferno Demonlord 1", 9, "§aInferno 1", showDeathTime = true), + SLAYER_BLAZE_2("§aInferno Demonlord 2", 9, "§aInferno 2", showDeathTime = true), + SLAYER_BLAZE_3("§aInferno Demonlord 3", 9, "§aInferno 3", showDeathTime = true), + SLAYER_BLAZE_4("§aInferno Demonlord 4", 9, "§aInferno 4", showDeathTime = true), SLAYER_BLAZE_TYPHOEUS_1("§aInferno Typhoeus 1", 9, "§aTyphoeus 1"), SLAYER_BLAZE_TYPHOEUS_2("§eInferno Typhoeus 2", 9, "§eTyphoeus 2"), diff --git a/src/main/java/at/hannibal2/skyhanni/features/damageindicator/DamageIndicatorManager.kt b/src/main/java/at/hannibal2/skyhanni/features/damageindicator/DamageIndicatorManager.kt index 7390393d9..44c2e47ad 100644 --- a/src/main/java/at/hannibal2/skyhanni/features/damageindicator/DamageIndicatorManager.kt +++ b/src/main/java/at/hannibal2/skyhanni/features/damageindicator/DamageIndicatorManager.kt @@ -32,7 +32,6 @@ import net.minecraftforge.event.world.WorldEvent import net.minecraftforge.fml.common.eventhandler.EventPriority import net.minecraftforge.fml.common.eventhandler.SubscribeEvent import net.minecraftforge.fml.common.gameevent.TickEvent -import java.text.DecimalFormat import java.util.* import java.util.regex.Pattern import kotlin.math.max @@ -40,7 +39,6 @@ import kotlin.math.max class DamageIndicatorManager { private var mobFinder: MobFinder? = null - private val decimalFormat = DecimalFormat("0.0") private val maxHealth = mutableMapOf<UUID, Long>() companion object { @@ -294,8 +292,8 @@ class DamageIndicatorManager { else -> LorenzColor.WHITE } - val d = (delay * 1.0) / 1000 - return color.getChatColor() + decimalFormat.format(d) + val format = TimeUtils.formatDuration(delay, showMilliSeconds = true) + return color.getChatColor() + format } @SubscribeEvent @@ -331,6 +329,9 @@ class DamageIndicatorManager { entityData.nameAbove = "" val customHealthText = if (health == 0L) { entityData.dead = true + if (entityData.bossType.showDeathTime && SkyHanniMod.feature.damageIndicator.timeToKillSlayer) { + entityData.nameAbove = entityData.timeToKill + } "§cDead" } else { getCustomHealth(entityData, health, entity, maxHealth) ?: return @@ -714,7 +715,8 @@ class DamageIndicatorManager { entityResult.ignoreBlocks, entityResult.delayedStart, entityResult.finalDungeonBoss, - entityResult.bossType + entityResult.bossType, + foundTime = System.currentTimeMillis() ) } diff --git a/src/main/java/at/hannibal2/skyhanni/features/damageindicator/EntityData.kt b/src/main/java/at/hannibal2/skyhanni/features/damageindicator/EntityData.kt index 2c7acc54b..7055b7df4 100644 --- a/src/main/java/at/hannibal2/skyhanni/features/damageindicator/EntityData.kt +++ b/src/main/java/at/hannibal2/skyhanni/features/damageindicator/EntityData.kt @@ -1,6 +1,8 @@ package at.hannibal2.skyhanni.features.damageindicator import at.hannibal2.skyhanni.utils.LorenzVec +import at.hannibal2.skyhanni.utils.TimeUnit +import at.hannibal2.skyhanni.utils.TimeUtils import net.minecraft.entity.EntityLivingBase class EntityData( @@ -10,6 +12,7 @@ class EntityData( val finalDungeonBoss: Boolean, val bossType: BossType, val damageCounter: DamageCounter = DamageCounter(), + val foundTime: Long, var lastHealth: Long = 0L, var healthText: String = "", @@ -19,4 +22,9 @@ class EntityData( var nameAbove: String = "", var dead: Boolean = false, var deathLocation: LorenzVec? = null, -)
\ No newline at end of file +) { + val timeToKill by lazy { + val duration = System.currentTimeMillis() - foundTime + "§e" + TimeUtils.formatDuration(duration, TimeUnit.SECOND, showMilliSeconds = true) + } +}
\ No newline at end of file diff --git a/src/main/java/at/hannibal2/skyhanni/features/fishing/BarnFishingTimer.kt b/src/main/java/at/hannibal2/skyhanni/features/fishing/BarnFishingTimer.kt index baa5898c8..0487dfa2f 100644 --- a/src/main/java/at/hannibal2/skyhanni/features/fishing/BarnFishingTimer.kt +++ b/src/main/java/at/hannibal2/skyhanni/features/fishing/BarnFishingTimer.kt @@ -2,12 +2,9 @@ package at.hannibal2.skyhanni.features.fishing import at.hannibal2.skyhanni.SkyHanniMod import at.hannibal2.skyhanni.data.IslandType -import at.hannibal2.skyhanni.utils.LocationUtils -import at.hannibal2.skyhanni.utils.LorenzUtils -import at.hannibal2.skyhanni.utils.LorenzVec +import at.hannibal2.skyhanni.utils.* import at.hannibal2.skyhanni.utils.RenderUtils.renderString import at.hannibal2.skyhanni.utils.SoundUtils.playSound -import at.hannibal2.skyhanni.utils.StringUtils import net.minecraft.client.Minecraft import net.minecraft.client.audio.ISound import net.minecraft.client.audio.PositionedSound @@ -101,7 +98,7 @@ class BarnFishingTimer { val duration = System.currentTimeMillis() - startTime val barnTimerAlertTime = SkyHanniMod.feature.fishing.barnTimerAlertTime * 1_000 val color = if (duration > barnTimerAlertTime) "§c" else "§e" - val timeFormat = StringUtils.formatDuration(duration / 1000, decimalFormat = true) + val timeFormat = TimeUtils.formatDuration(duration, biggestUnit = TimeUnit.MINUTE) val name = if (currentCount == 1) "sea creature" else "sea creatures" val text = "$color$timeFormat §8(§e$currentCount §b$name§8)" diff --git a/src/main/java/at/hannibal2/skyhanni/features/minion/MinionFeatures.kt b/src/main/java/at/hannibal2/skyhanni/features/minion/MinionFeatures.kt index cbf3f7fd1..30849e01d 100644 --- a/src/main/java/at/hannibal2/skyhanni/features/minion/MinionFeatures.kt +++ b/src/main/java/at/hannibal2/skyhanni/features/minion/MinionFeatures.kt @@ -235,7 +235,7 @@ class MinionFeatures { if (SkyHanniMod.feature.minions.emptiedTimeDisplay) { if (lastEmptied != 0L) { val duration = System.currentTimeMillis() - lastEmptied - val format = StringUtils.formatDuration(duration / 1000) + " ago" + val format = TimeUtils.formatDuration(duration, longName = true) + " ago" val text = "§eHopper Emptied: $format" event.drawString(location.add(0.0, 1.15, 0.0), text, true) } diff --git a/src/main/java/at/hannibal2/skyhanni/features/misc/NonGodPotEffectDisplay.kt b/src/main/java/at/hannibal2/skyhanni/features/misc/NonGodPotEffectDisplay.kt index 65b7992d6..7d118c1c5 100644 --- a/src/main/java/at/hannibal2/skyhanni/features/misc/NonGodPotEffectDisplay.kt +++ b/src/main/java/at/hannibal2/skyhanni/features/misc/NonGodPotEffectDisplay.kt @@ -9,7 +9,8 @@ import at.hannibal2.skyhanni.utils.ItemUtils.name import at.hannibal2.skyhanni.utils.LorenzUtils import at.hannibal2.skyhanni.utils.LorenzUtils.sorted import at.hannibal2.skyhanni.utils.RenderUtils.renderStrings -import at.hannibal2.skyhanni.utils.StringUtils +import at.hannibal2.skyhanni.utils.TimeUnit +import at.hannibal2.skyhanni.utils.TimeUtils import net.minecraft.network.play.server.S30PacketWindowItems import net.minecraft.network.play.server.S47PacketPlayerListHeaderFooter import net.minecraftforge.client.event.RenderGameOverlayEvent @@ -81,8 +82,8 @@ class NonGodPotEffectDisplay { if (label.contains("Fumes")) continue val until = effect.value - val seconds = (until - now) / 1000 - val format = StringUtils.formatDuration(seconds) + val seconds = until - now + val format = TimeUtils.formatDuration(seconds, TimeUnit.HOUR) val color = colorForTime(seconds) @@ -213,8 +214,8 @@ class NonGodPotEffectDisplay { if (label.contains("Invisibility")) { activeEffects[label] = System.currentTimeMillis() + 1000 * 60 * 60 * 24 } else { - activeEffects[label] = newValue - } + activeEffects[label] = newValue + } } } diff --git a/src/main/java/at/hannibal2/skyhanni/features/mobs/AreaMiniBossFeatures.kt b/src/main/java/at/hannibal2/skyhanni/features/mobs/AreaMiniBossFeatures.kt index 163563981..09f125dbf 100644 --- a/src/main/java/at/hannibal2/skyhanni/features/mobs/AreaMiniBossFeatures.kt +++ b/src/main/java/at/hannibal2/skyhanni/features/mobs/AreaMiniBossFeatures.kt @@ -4,12 +4,8 @@ import at.hannibal2.skyhanni.SkyHanniMod import at.hannibal2.skyhanni.events.EntityMaxHealthUpdateEvent import at.hannibal2.skyhanni.events.withAlpha import at.hannibal2.skyhanni.mixins.hooks.RenderLivingEntityHelper +import at.hannibal2.skyhanni.utils.* import at.hannibal2.skyhanni.utils.EntityUtils.hasMaxHealth -import at.hannibal2.skyhanni.utils.LocationUtils -import at.hannibal2.skyhanni.utils.LorenzColor -import at.hannibal2.skyhanni.utils.LorenzUtils -import at.hannibal2.skyhanni.utils.LorenzUtils.round -import at.hannibal2.skyhanni.utils.LorenzVec import at.hannibal2.skyhanni.utils.RenderUtils.drawDynamicText import net.minecraft.entity.EntityLiving import net.minecraft.entity.monster.EntityBlaze @@ -70,8 +66,8 @@ class AreaMiniBossFeatures { private fun AreaMiniBossType.getTime(): String { val duration = System.currentTimeMillis() - lastTime val estimatedTime = respawnCooldown - duration % respawnCooldown - val double = (estimatedTime.toDouble() / 1000).round(1) - return color.getChatColor() + "" + LorenzUtils.formatDouble(double, "0.0") + "s" + val format = TimeUtils.formatDuration(estimatedTime, showMilliSeconds = true) + return color.getChatColor() + format } @SubscribeEvent diff --git a/src/main/java/at/hannibal2/skyhanni/features/nether/ashfang/AshfangFreezeCooldown.kt b/src/main/java/at/hannibal2/skyhanni/features/nether/ashfang/AshfangFreezeCooldown.kt index 6fb7be0ff..2bafd6507 100644 --- a/src/main/java/at/hannibal2/skyhanni/features/nether/ashfang/AshfangFreezeCooldown.kt +++ b/src/main/java/at/hannibal2/skyhanni/features/nether/ashfang/AshfangFreezeCooldown.kt @@ -7,9 +7,9 @@ import at.hannibal2.skyhanni.features.damageindicator.DamageIndicatorManager import at.hannibal2.skyhanni.utils.LorenzUtils import at.hannibal2.skyhanni.utils.RenderUtils.renderString import at.hannibal2.skyhanni.utils.StringUtils.matchRegex +import at.hannibal2.skyhanni.utils.TimeUtils import net.minecraftforge.client.event.RenderGameOverlayEvent import net.minecraftforge.fml.common.eventhandler.SubscribeEvent -import java.text.DecimalFormat class AshfangFreezeCooldown { @@ -34,9 +34,8 @@ class AshfangFreezeCooldown { val remainingLong = maxDuration - duration if (remainingLong > 0) { - val remaining = (remainingLong.toFloat() / 1000) - val format = DecimalFormat("0.0").format(remaining + 0.1) - SkyHanniMod.feature.ashfang.freezeCooldownPos.renderString("§cAshfang Freeze: §a${format}s") + var format = TimeUtils.formatDuration(remainingLong, showMilliSeconds = true) + SkyHanniMod.feature.ashfang.freezeCooldownPos.renderString("§cAshfang Freeze: §a$format") } } diff --git a/src/main/java/at/hannibal2/skyhanni/features/nether/ashfang/AshfangNextResetCooldown.kt b/src/main/java/at/hannibal2/skyhanni/features/nether/ashfang/AshfangNextResetCooldown.kt index 5fe8c7d8a..011c716df 100644 --- a/src/main/java/at/hannibal2/skyhanni/features/nether/ashfang/AshfangNextResetCooldown.kt +++ b/src/main/java/at/hannibal2/skyhanni/features/nether/ashfang/AshfangNextResetCooldown.kt @@ -5,13 +5,14 @@ import at.hannibal2.skyhanni.features.damageindicator.BossType import at.hannibal2.skyhanni.features.damageindicator.DamageIndicatorManager import at.hannibal2.skyhanni.utils.LorenzUtils import at.hannibal2.skyhanni.utils.RenderUtils.renderString +import at.hannibal2.skyhanni.utils.TimeUnit +import at.hannibal2.skyhanni.utils.TimeUtils import net.minecraft.client.Minecraft import net.minecraft.entity.item.EntityArmorStand import net.minecraftforge.client.event.RenderGameOverlayEvent import net.minecraftforge.event.world.WorldEvent import net.minecraftforge.fml.common.eventhandler.SubscribeEvent import net.minecraftforge.fml.common.gameevent.TickEvent.ClientTickEvent -import java.text.DecimalFormat class AshfangNextResetCooldown { @@ -37,9 +38,8 @@ class AshfangNextResetCooldown { val remainingTime = spawnTime + 46_100 - System.currentTimeMillis() if (remainingTime > 0) { - val remaining = (remainingTime.toFloat() / 1000) - val format = DecimalFormat("0.0").format(remaining + 0.1) - SkyHanniMod.feature.ashfang.nextResetCooldownPos.renderString("§cAshfang next reset in: §a${format}s") + val format = TimeUtils.formatDuration(remainingTime, TimeUnit.SECOND, showMilliSeconds = true) + SkyHanniMod.feature.ashfang.nextResetCooldownPos.renderString("§cAshfang next reset in: §a$format") } else { spawnTime = -1 } diff --git a/src/main/java/at/hannibal2/skyhanni/test/LorenzTest.kt b/src/main/java/at/hannibal2/skyhanni/test/LorenzTest.kt index 983459531..0002e0db8 100644 --- a/src/main/java/at/hannibal2/skyhanni/test/LorenzTest.kt +++ b/src/main/java/at/hannibal2/skyhanni/test/LorenzTest.kt @@ -146,22 +146,22 @@ class LorenzTest { SkyHanniMod.feature.dev.debugPos.renderString(text) } - @SubscribeEvent(priority = EventPriority.LOW, receiveCanceled = true) + @SubscribeEvent fun onHypExplosions(event: ReceiveParticleEvent) { -// if (!LorenzUtils.inSkyblock) return -// when (event.type) { -// EnumParticleTypes.EXPLOSION_LARGE, -// EnumParticleTypes.EXPLOSION_HUGE, -// EnumParticleTypes.EXPLOSION_NORMAL, -// -> event.isCanceled = true -// -// else -> {} -// } + if (!LorenzUtils.inSkyBlock) return + when (event.type) { + EnumParticleTypes.EXPLOSION_LARGE, + EnumParticleTypes.EXPLOSION_HUGE, + EnumParticleTypes.EXPLOSION_NORMAL, + -> event.isCanceled = true + else -> {} + } } @SubscribeEvent fun onEnderTeleport(event: EnderTeleportEvent) { -// event.isCanceled = true + if (!LorenzUtils.inSkyBlock) return + event.isCanceled = true } @SubscribeEvent diff --git a/src/main/java/at/hannibal2/skyhanni/utils/StringUtils.kt b/src/main/java/at/hannibal2/skyhanni/utils/StringUtils.kt index 877e0edf6..4b01f9499 100644 --- a/src/main/java/at/hannibal2/skyhanni/utils/StringUtils.kt +++ b/src/main/java/at/hannibal2/skyhanni/utils/StringUtils.kt @@ -1,12 +1,9 @@ package at.hannibal2.skyhanni.utils import org.intellij.lang.annotations.Language -import java.text.DecimalFormat import java.util.* object StringUtils { - private val durationFormat = DecimalFormat("00") - fun String.firstLetterUppercase(): String { if (isEmpty()) return this @@ -35,43 +32,6 @@ object StringUtils { return builder.toString() } - fun formatDuration(seconds: Long, decimalFormat: Boolean = false): String { - var sec: Long = seconds - - var minutes: Long = sec / 60 - sec %= 60 - - var hours = minutes / 60 - minutes %= 60 - - val days = hours / 24 - hours %= 24 - - - val formatHours = durationFormat.format(hours) - val formatMinutes = durationFormat.format(minutes) - val formatSeconds = durationFormat.format(sec) - - if (decimalFormat) { - return "$formatMinutes:$formatSeconds" - } - - if (days > 0) { - return "${days}d $formatHours:$formatMinutes:$formatSeconds" - } - if (hours > 0) { - return "$formatHours:$formatMinutes:$formatSeconds".removeAtBeginning("0") - } - if (minutes > 0) { - return "$formatMinutes:$formatSeconds".removeAtBeginning("0") - } - if (sec > 0) { - return "${sec}s" - } - - return "Now" - } - /** * From https://stackoverflow.com/questions/10711494/get-values-in-treemap-whose-string-keys-start-with-a-pattern */ diff --git a/src/main/java/at/hannibal2/skyhanni/utils/TimeUtils.kt b/src/main/java/at/hannibal2/skyhanni/utils/TimeUtils.kt new file mode 100644 index 000000000..107395886 --- /dev/null +++ b/src/main/java/at/hannibal2/skyhanni/utils/TimeUtils.kt @@ -0,0 +1,59 @@ +package at.hannibal2.skyhanni.utils + +object TimeUtils { + fun formatDuration( + millis: Long, + biggestUnit: TimeUnit = TimeUnit.YEAR, + showMilliSeconds: Boolean = false, + longName: Boolean = false + ): String { + var milliseconds = millis + val map = mutableMapOf<TimeUnit, Int>() + for (unit in TimeUnit.values()) { + if (unit.ordinal >= biggestUnit.ordinal) { + val factor = unit.factor + map[unit] = (milliseconds / factor).toInt() + milliseconds %= factor + } + } + + val builder = StringBuilder() + for ((unit, value) in map.entries) { + if (value > 0 || builder.isNotEmpty() || unit == TimeUnit.SECOND) { + builder.append(value) + val name = if (longName) { + " " + unit.longName + if (value > 1) "s" else "" + } else { + unit.shortName + } + + if (unit == TimeUnit.SECOND) { + if (showMilliSeconds) { + val formatMillis = milliseconds / 100 + builder.append(".") + builder.append(formatMillis) + } + builder.append(name) + } else { + builder.append("$name ") + } + } + } + return builder.toString() + } +} + +private const val FACTOR_SECONDS = 1000L +private const val FACTOR_MINUTES = FACTOR_SECONDS * 60 +private const val FACTOR_HOURS = FACTOR_MINUTES * 60 +private const val FACTOR_DAYS = FACTOR_HOURS * 24 +private const val FACTOR_YEARS = (FACTOR_DAYS * 365.25).toLong() + +enum class TimeUnit(val factor: Long, val shortName: String, val longName: String) { + YEAR(FACTOR_YEARS, "y", "Year"), + DAY(FACTOR_DAYS, "d", "Day"), + HOUR(FACTOR_HOURS, "h", "Hour"), + MINUTE(FACTOR_MINUTES, "m", "Minute"), + SECOND(FACTOR_SECONDS, "s", "Second"), + ; +}
\ No newline at end of file |