Skip to content

Commit

Permalink
Feature: Limbo time PB v2 (#848)
Browse files Browse the repository at this point in the history
Co-authored-by: hannibal2 <24389977+hannibal00212@users.noreply.github.com>
  • Loading branch information
martimavocado and hannibal002 authored Mar 9, 2024
1 parent afbd5b2 commit d902e7d
Show file tree
Hide file tree
Showing 10 changed files with 373 additions and 91 deletions.
6 changes: 4 additions & 2 deletions src/main/java/at/hannibal2/skyhanni/SkyHanniMod.kt
Original file line number Diff line number Diff line change
Expand Up @@ -257,7 +257,6 @@ import at.hannibal2.skyhanni.features.misc.HideArmor
import at.hannibal2.skyhanni.features.misc.InGameDateDisplay
import at.hannibal2.skyhanni.features.misc.JoinCrystalHollows
import at.hannibal2.skyhanni.features.misc.LesserOrbHider
import at.hannibal2.skyhanni.features.misc.LimboTimeTracker
import at.hannibal2.skyhanni.features.misc.LockMouseLook
import at.hannibal2.skyhanni.features.misc.MarkedPlayerManager
import at.hannibal2.skyhanni.features.misc.MiscFeatures
Expand Down Expand Up @@ -287,6 +286,8 @@ import at.hannibal2.skyhanni.features.misc.items.AuctionHouseCopyUnderbidPrice
import at.hannibal2.skyhanni.features.misc.items.EstimatedItemValue
import at.hannibal2.skyhanni.features.misc.items.EstimatedWardrobePrice
import at.hannibal2.skyhanni.features.misc.items.GlowingDroppedItems
import at.hannibal2.skyhanni.features.misc.limbo.LimboPlaytime
import at.hannibal2.skyhanni.features.misc.limbo.LimboTimeTracker
import at.hannibal2.skyhanni.features.misc.massconfiguration.DefaultConfigFeatures
import at.hannibal2.skyhanni.features.misc.teleportpad.TeleportPadCompactName
import at.hannibal2.skyhanni.features.misc.teleportpad.TeleportPadInventoryNumber
Expand Down Expand Up @@ -732,7 +733,7 @@ class SkyHanniMod {
loadModule(FixNEUHeavyPearls())
loadModule(QuickCraftFeatures())
loadModule(SkyBlockKickDuration())
loadModule(LimboTimeTracker())
loadModule(LimboTimeTracker)
loadModule(PartyMemberOutlines())
loadModule(ArrowTrail())
loadModule(ShiftClickEquipment())
Expand Down Expand Up @@ -762,6 +763,7 @@ class SkyHanniMod {
loadModule(MaxPurseItems())
loadModule(SuperCraftFeatures())
loadModule(InfernoMinionFeatures())
loadModule(LimboPlaytime())

init()

Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package at.hannibal2.skyhanni.config

import at.hannibal2.skyhanni.events.LorenzEvent
import at.hannibal2.skyhanni.features.misc.limbo.LimboTimeTracker
import at.hannibal2.skyhanni.utils.LorenzLogger
import at.hannibal2.skyhanni.utils.LorenzUtils.asIntOrNull
import com.google.gson.JsonElement
Expand All @@ -10,7 +11,7 @@ import com.google.gson.JsonPrimitive
object ConfigUpdaterMigrator {

val logger = LorenzLogger("ConfigMigration")
const val CONFIG_VERSION = 26
const val CONFIG_VERSION = 27
fun JsonElement.at(chain: List<String>, init: Boolean): JsonElement? {
if (chain.isEmpty()) return this
if (this !is JsonObject) return null
Expand Down Expand Up @@ -81,6 +82,7 @@ object ConfigUpdaterMigrator {
return
}
movesPerformed++
if (np == listOf("#player", "personalBest")) LimboTimeTracker.workaroundMigration(oldElem.asInt)
newParentElement.add(np.last(), transform(oldElem))
logger.log("Moved element from $oldPath to $newPath")
}
Expand Down
15 changes: 15 additions & 0 deletions src/main/java/at/hannibal2/skyhanni/config/Storage.java
Original file line number Diff line number Diff line change
Expand Up @@ -119,6 +119,21 @@ public static class BingoSession {
@Expose
public Map<Integer, BingoGoal> goals = new HashMap<>();
}

@Expose
public LimboStats limbo = new LimboStats();

public static class LimboStats {

@Expose
public int playtime = 0;

@Expose
public int personalBest = 0;

@Expose
public float userLuck = 0f;
}
}

public static class ProfileSpecific {
Expand Down
10 changes: 10 additions & 0 deletions src/main/java/at/hannibal2/skyhanni/config/commands/Commands.kt
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,9 @@ import at.hannibal2.skyhanni.features.minion.MinionFeatures
import at.hannibal2.skyhanni.features.misc.CollectionTracker
import at.hannibal2.skyhanni.features.misc.LockMouseLook
import at.hannibal2.skyhanni.features.misc.MarkedPlayerManager
import at.hannibal2.skyhanni.features.misc.MiscFeatures
import at.hannibal2.skyhanni.features.misc.discordrpc.DiscordRPCManager
import at.hannibal2.skyhanni.features.misc.limbo.LimboTimeTracker
import at.hannibal2.skyhanni.features.misc.massconfiguration.DefaultConfigFeatures
import at.hannibal2.skyhanni.features.misc.visualwords.VisualWordGui
import at.hannibal2.skyhanni.features.rift.area.westvillage.VerminTracker
Expand Down Expand Up @@ -280,6 +282,14 @@ object Commands {
{ SkillAPI.onCommand(it) },
SkillAPI::onComplete
)
registerCommand(
"shlimbostats",
"Prints your Limbo Stats!"
) { LimboTimeTracker.printStats() }
registerCommand(
"shlimbo",
"Warps you to Limbo."
) { MiscFeatures().goToLimbo() }
}

private fun usersBugFix() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -250,9 +250,6 @@ public class MiscConfig {
@Expose
public Position inventoryLoadPos = new Position(394, 124, false, true);

@Expose
public int limboTimePB = 0;

@Expose
@ConfigOption(name = "Fix Ghost Entities", desc = "Removes ghost entities caused by a Hypixel bug. " +
"This included Diana, Dungeon and Crimson Isle mobs and nametags.")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import at.hannibal2.skyhanni.config.ConfigUpdaterMigrator
import at.hannibal2.skyhanni.data.FriendAPI
import at.hannibal2.skyhanni.data.PartyAPI
import at.hannibal2.skyhanni.events.MessageSendToServerEvent
import at.hannibal2.skyhanni.features.misc.limbo.LimboTimeTracker
import at.hannibal2.skyhanni.utils.ChatUtils
import net.minecraftforge.fml.common.eventhandler.SubscribeEvent

Expand Down Expand Up @@ -42,6 +43,10 @@ object PartyCommands {

fun transfer(args: Array<String>) {
if (args.isEmpty()) {
if (LimboTimeTracker.inLimbo) {
LimboTimeTracker.printStats(true)
return
}
ChatUtils.sendCommandToServer("pt")
return
}
Expand Down

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ package at.hannibal2.skyhanni.features.misc
import at.hannibal2.skyhanni.SkyHanniMod
import at.hannibal2.skyhanni.config.ConfigUpdaterMigrator
import at.hannibal2.skyhanni.events.ReceiveParticleEvent
import at.hannibal2.skyhanni.utils.ChatUtils
import at.hannibal2.skyhanni.utils.LorenzUtils
import net.minecraft.util.EnumParticleTypes
import net.minecraftforge.client.event.RenderBlockOverlayEvent
Expand Down Expand Up @@ -51,4 +52,8 @@ class MiscFeatures {
fun onConfigFix(event: ConfigUpdaterMigrator.ConfigFixEvent) {
event.move(2, "mobs", "combat.mobs")
}

fun goToLimbo() {
ChatUtils.sendMessageToServer("§")
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,139 @@
package at.hannibal2.skyhanni.features.misc.limbo

import at.hannibal2.skyhanni.data.ProfileStorageData
import at.hannibal2.skyhanni.events.InventoryOpenEvent
import at.hannibal2.skyhanni.events.LorenzToolTipEvent
import at.hannibal2.skyhanni.utils.LorenzUtils
import at.hannibal2.skyhanni.utils.LorenzUtils.round
import at.hannibal2.skyhanni.utils.NEUInternalName.Companion.asInternalName
import at.hannibal2.skyhanni.utils.NEUItems.getItemStack
import at.hannibal2.skyhanni.utils.NumberUtil.addSeparators
import at.hannibal2.skyhanni.utils.SimpleTimeMark
import at.hannibal2.skyhanni.utils.StringUtils.matches
import at.hannibal2.skyhanni.utils.repopatterns.RepoPattern
import io.github.moulberry.notenoughupdates.events.ReplaceItemEvent
import io.github.moulberry.notenoughupdates.util.Utils
import net.minecraft.client.player.inventory.ContainerLocalMenu
import net.minecraft.item.ItemStack
import net.minecraftforge.fml.common.eventhandler.SubscribeEvent
import kotlin.time.Duration.Companion.seconds

class LimboPlaytime {
private lateinit var modifiedList: MutableList<String>
private var setMinutes = false
private val patternGroup = RepoPattern.group("misc.limbo.tooltip")
private val minutesPattern by patternGroup.pattern(
"minutes",
"§5§o§a([\\d.,]+) minutes.+\$"
)
private val hoursPattern by patternGroup.pattern(
"hours",
"§5§o§b([\\d.,]+) hours.+\$"
)

private var wholeMinutes: Long = 0
private var hoursString: String = ""

private val storage get() = ProfileStorageData.playerSpecific?.limbo

private val itemID = "ENDER_PEARL".asInternalName()
private val itemName = "§aLimbo"
private lateinit var limboItem: ItemStack
private var lastCreateCooldown = SimpleTimeMark.farPast()

@SubscribeEvent
fun replaceItem(event: ReplaceItemEvent) {
if (event.inventory !is ContainerLocalMenu) return
if (event.inventory.displayName.unformattedText != "Detailed /playtime") return
if (event.slotNumber != 43) return
if (storage?.playtime == 0) return

if (lastCreateCooldown.passedSince() > 3.seconds) {
lastCreateCooldown = SimpleTimeMark.now()
limboItem = if (wholeMinutes >= 60) Utils.createItemStack(
itemID.getItemStack().item,
itemName,
"§7Playtime: §a${wholeMinutes.addSeparators()} minutes",
"§7Or: §b$hoursString hours"
)
else Utils.createItemStack(itemID.getItemStack().item, itemName, "§7Playtime: §a$wholeMinutes minutes")
}
event.replaceWith(limboItem)
}

@SubscribeEvent
fun onHoverItem(event: LorenzToolTipEvent) {
if (!LorenzUtils.inSkyBlock) return
if (!event.slot.inventory.displayName.unformattedText.startsWith("Detailed /playtime")) return
if (event.slot.slotIndex != 4) return
if (storage?.playtime == 0) return

val lore = event.toolTip
val hoursList = lore.filter { hoursPattern.matches(it) }.toMutableList()
val minutesList = lore.filter { minutesPattern.matches(it) }.toMutableList()

addLimbo(hoursList, minutesList)
remakeList(event.toolTip, minutesList, hoursList)
}

@SubscribeEvent
fun onRenderGUI(event: InventoryOpenEvent) {
if (event.inventoryName != "Detailed /playtime") return
val storedPlaytime = storage?.playtime ?: 0
if (storedPlaytime < 60) return
val playtime = storedPlaytime.seconds
val wholeHours = playtime.inWholeHours
wholeMinutes = playtime.inWholeMinutes
if ((wholeMinutes % 60).toInt() == 0) {
hoursString = "$wholeHours"
} else {
val minutes: Float = ((wholeMinutes - wholeHours * 60).toFloat() / 60)
hoursString = wholeHours.addSeparators() + minutes.round(1).toString().replace("0", "")
}
}

private fun addLimbo(hoursList: MutableList<String>, minutesList: MutableList<String>) {
val storedPlaytime = storage?.playtime ?: 0
if (wholeMinutes >= 60) {
val hours = storedPlaytime.seconds.inWholeHours
val minutes = (storedPlaytime.seconds.inWholeMinutes - (hours * 60).toFloat() / 6).toInt()
modifiedList = hoursList
if (minutes == 0) modifiedList.add("§5§o§b$hours hours §7on Limbo")
else modifiedList.add("§5§o§b$hoursString hours §7on Limbo")
modifiedList = modifiedList.sortedByDescending {
val matcher = hoursPattern.matcher(it)
if (matcher.find()) {
matcher.group(1).replace(",", "").toDoubleOrNull() ?: 0.0
} else 0.0
}.toMutableList()
setMinutes = false
} else {
val minutes = storedPlaytime.seconds.inWholeMinutes
modifiedList = minutesList
modifiedList.add("§a$minutes minutes §7on Limbo")
modifiedList = modifiedList.sortedByDescending {
it.substringAfter("§a").substringBefore(" minutes").toDoubleOrNull()
}.toMutableList()
setMinutes = true
}
}

private fun remakeList(
toolTip: MutableList<String>,
minutesList: MutableList<String>,
hoursList: MutableList<String>
) {
val firstLine = toolTip.first()
val totalPlaytime = toolTip.last()
toolTip.clear()
toolTip.add(firstLine)
if (!setMinutes) {
toolTip.addAll(modifiedList)
toolTip.addAll(minutesList)
} else {
toolTip.addAll(hoursList)
toolTip.addAll(modifiedList)
}
toolTip.add(totalPlaytime)
}
}
Loading

0 comments on commit d902e7d

Please sign in to comment.