Skip to content
This repository was archived by the owner on Nov 27, 2024. It is now read-only.

Commit e8a07b9

Browse files
committed
fix player data updaters
1 parent dd0ae65 commit e8a07b9

File tree

18 files changed

+79
-78
lines changed

18 files changed

+79
-78
lines changed

constants/regexes.json

+5-4
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,7 @@
6060
"chat.hollows.run.crystalFound": "✦ CRYSTAL FOUND \\(\\d\\/5\\)",
6161
"chat.hollows.run.crystalPlaced": "✦ You placed the \\w+ Crystal!",
6262
"chat.general.server_send": "Sending to server (\\w{7,8})...",
63-
"chat.general.profile": "You are playing on profile: (\\w+)",
63+
"chat.general.profile": "§aYou are playing on profile: §e(\\w+)",
6464
"chat.mining.abilityUsed": "You used your (\\D+) Pickaxe Ability!",
6565
"chat.mining.abilityAvailable": "(\\D+) is now available!",
6666
"menu.clickToView": "Click to view!",
@@ -73,11 +73,12 @@
7373
"menu.bestiary.bestiary": "Bestiary ?.*?",
7474
"menu.bestiary.familiesCompleted": "Families Completed: 100%",
7575
"menu.bestiary.maxed": "Overall Progress: 100% \\(MAX!\\)",
76-
"menu.hotm.crystal.notfound": "✖ Not Found",
77-
"menu.hotm.crystal.notplaced": "✖ Not Placed",
76+
"menu.hotm.crystal.notfound": ".* ✖ Not Found",
77+
"menu.hotm.crystal.notplaced": ".* ✖ Not Placed",
7878
"menu.hotm.crystal.itemName": "Crystal Hollows Crystals",
7979
"menu.hotm.abilities.selected": "SELECTED",
8080
"menu.hotm.potm": "Peak of the Mountain",
81+
"menu.hotm.potm.level": "Level (\\d+)\\/10",
8182
"menu.hotm.hotm": "Heart of the Mountain",
8283
"menu.hotm.mithrilPowder": "Mithril Powder: (\\d+[,]?\\d{0,3}[,]?\\d{0,3}[,]?\\d{0,3}[,]?\\d{0,3})",
8384
"menu.hotm.gemstonePowder": "Gemstone Powder: (\\d+[,]?\\d{0,3}[,]?\\d{0,3}[,]?\\d{0,3}[,]?\\d{0,3})",
@@ -86,7 +87,7 @@
8687
"tablist.mining.gemstone": "Gemstone: (\\d+[,]?\\d{0,3}[,]?\\d{0,3}[,]?\\d{0,3}[,]?\\d{0,3})",
8788
"tablist.mining.glacite": "Glacite: (\\d+[,]?\\d{0,3}[,]?\\d{0,3}[,]?\\d{0,3}[,]?\\d{0,3})",
8889
"tablist.general.area": "Area: (.+)",
89-
"sideboard.general.skyblock": "skyblock|Skyblock|skiblock|Skiblock",
90+
"sideboard.general.skyblock": "SKYBLOCK",
9091
"sideboard.general.zone": " (?:⏣|ф) (.*)",
9192
"bossbar.hollows.powder": "PASSIVE EVENT 2X POWDER RUNNING FOR ?(?:\\((.*)\\))"
9293
}

src/main/java/dev/nyon/skylper/asm/mixins/ConnectionMixin.java

+1-1
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@ private void checkForHypixelConnection(
4343
}
4444

4545
@Inject(
46-
method = "disconnect",
46+
method = "disconnect*",
4747
at = @At("TAIL")
4848
)
4949
private void clearDestinationTargets(

src/main/kotlin/dev/nyon/skylper/extensions/Items.kt

+5
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,11 @@ import net.minecraft.world.item.Item
77
import net.minecraft.world.item.ItemStack
88
import net.minecraft.world.item.TooltipFlag
99

10+
val ItemStack.nameAsString: String
11+
get() {
12+
return displayName.string.replace("[", "").replace("]", "")
13+
}
14+
1015
val ItemStack.extraAttributes: CompoundTag?
1116
get() {
1217
val tag = get(DataComponents.CUSTOM_DATA)?.copyTag() ?: return null

src/main/kotlin/dev/nyon/skylper/extensions/math/Location.kt

-9
This file was deleted.

src/main/kotlin/dev/nyon/skylper/extensions/render/hud/components/PlainTextHudComponent.kt

+1-1
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ import dev.nyon.skylper.minecraft
44
import net.minecraft.client.gui.GuiGraphics
55
import net.minecraft.network.chat.Component
66

7-
class PlainTextHudComponent(val text: Component) : HudComponent {
7+
class PlainTextHudComponent(private val text: Component) : HudComponent {
88
override val width: Int = minecraft.font.width(text)
99
override val height: Int = minecraft.font.lineHeight
1010

src/main/kotlin/dev/nyon/skylper/skyblock/data/online/OnlineData.kt

+6-1
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,9 @@ import io.ktor.client.request.*
66
import io.ktor.client.statement.*
77
import kotlinx.serialization.InternalSerializationApi
88
import kotlinx.serialization.serializer
9+
import net.fabricmc.loader.api.FabricLoader
10+
import kotlin.io.path.Path
11+
import kotlin.io.path.readText
912
import kotlin.reflect.KClass
1013

1114
abstract class OnlineData<T : Any>(val kClass: KClass<T>) {
@@ -22,7 +25,9 @@ abstract class OnlineData<T : Any>(val kClass: KClass<T>) {
2225
@OptIn(InternalSerializationApi::class)
2326
suspend inline fun refresh() {
2427
val result = runCatching {
25-
val result = httpClient.get("$url$path").bodyAsText()
28+
val result =
29+
if (FabricLoader.getInstance().isDevelopmentEnvironment && url == SKYLPER_REPO_URL) Path("../constants/$path").readText()
30+
else httpClient.get("$url$path").bodyAsText()
2631
json.decodeFromString(kClass.serializer(), result)
2732
}.onFailure { throwable ->
2833
println("Failed to load data from $url$path.")

src/main/kotlin/dev/nyon/skylper/skyblock/data/skylper/Extensions.kt

-8
This file was deleted.

src/main/kotlin/dev/nyon/skylper/skyblock/data/skylper/PlayerDataSaver.kt

+2-2
Original file line numberDiff line numberDiff line change
@@ -4,13 +4,13 @@ import dev.nyon.konfig.config.saveConfig
44
import dev.nyon.skylper.mcScope
55
import kotlinx.coroutines.delay
66
import kotlinx.coroutines.launch
7-
import kotlin.time.Duration.Companion.minutes
7+
import kotlin.time.Duration.Companion.seconds
88

99
object PlayerDataSaver {
1010
fun startSaveTask() {
1111
mcScope.launch {
1212
while (true) {
13-
delay(1.minutes)
13+
delay(30.seconds)
1414
saveConfig(playerData)
1515
}
1616
}

src/main/kotlin/dev/nyon/skylper/skyblock/data/skylper/PlayerDataUpdater.kt

+22-24
Original file line numberDiff line numberDiff line change
@@ -24,17 +24,15 @@ object PlayerDataUpdater {
2424

2525
private fun crystalHollowsChecker() {
2626
listenEvent<CrystalFoundEvent, Unit> {
27-
playerData.currentProfile?.mining?.crystalHollows?.crystals?.find { it.crystal == crystal }?.state =
28-
CrystalState.FOUND
27+
currentProfile.mining.crystalHollows.crystals.find { it.crystal == crystal }?.state = CrystalState.FOUND
2928
}
3029

3130
listenEvent<NucleusRunCompleteEvent, Unit> {
32-
playerData.currentProfile?.mining?.crystalHollows?.crystals?.forEach { it.state = CrystalState.NOT_FOUND }
31+
currentProfile.mining.crystalHollows.crystals.forEach { it.state = CrystalState.NOT_FOUND }
3332
}
3433

3534
listenEvent<CrystalPlaceEvent, Unit> {
36-
playerData.currentProfile?.mining?.crystalHollows?.crystals?.find { it.crystal == crystal }?.state =
37-
CrystalState.PLACED
35+
currentProfile.mining.crystalHollows.crystals.find { it.crystal == crystal }?.state = CrystalState.PLACED
3836
}
3937
}
4038

@@ -47,56 +45,56 @@ object PlayerDataUpdater {
4745
lore.map { it.string }.forEach {
4846
val crystalName = crystalNames.find { c -> it.contains(c) } ?: return@forEach
4947
val crystal = Crystal.entries.first { c -> c.displayName == crystalName }
50-
playerData.currentProfile?.mining?.crystalHollows?.crystals?.first { instance -> instance.crystal == crystal }?.state =
51-
if (crystalNotFoundRegex.matches(it)) {
52-
CrystalState.NOT_FOUND
53-
} else if (crystalNotPlacedRegex.matches(it)) {
54-
CrystalState.FOUND
55-
} else {
56-
CrystalState.PLACED
57-
}
48+
val newState = when {
49+
crystalNotFoundRegex.matches(it) -> CrystalState.NOT_FOUND
50+
crystalNotPlacedRegex.matches(it) -> CrystalState.FOUND
51+
else -> CrystalState.PLACED
52+
}
53+
currentProfile.mining.crystalHollows.crystals.first { instance -> instance.crystal == crystal }.state = newState
5854
}
5955
}
6056

6157
val hotmTitleRegex = regex("menu.hotm.hotm")
6258
val crystalHollowsCrystalsRegex = regex("menu.hotm.crystal.itemName")
6359
val abilitySelectedRegex = regex("menu.hotm.abilities.selected")
6460
val peakOfTheMountainRegex = regex("menu.hotm.potm")
61+
val peakOfTheMountainLevelRegex = regex("menu.hotm.potm.level")
6562

6663
val mithrilPowderRegex = regex("menu.hotm.mithrilPowder")
6764
val gemstonePowderRegex = regex("menu.hotm.gemstonePowder")
6865
val glacitePowderRegex = regex("menu.hotm.glacitePowder")
6966
listenEvent<SetItemEvent, Unit> {
70-
if (hotmTitleRegex.matches(PlayerSessionData.currentScreen?.title?.string.toString())) return@listenEvent
67+
if (!hotmTitleRegex.matches(PlayerSessionData.currentScreen?.title?.string.toString())) return@listenEvent
7168

72-
val itemNameString = itemStack.displayName.string
69+
val itemNameString = itemStack.nameAsString
7370
when {
7471
crystalHollowsCrystalsRegex.matches(itemNameString) -> updateCrystalState(itemStack)
7572
MiningAbility.rawNames.any { name -> itemNameString.contains(name) } -> {
7673
val selected = itemStack.lore.any { lore -> abilitySelectedRegex.matches(lore.string) }
7774
if (selected) {
7875
val rawName =
7976
MiningAbility.rawNames.find { name -> itemNameString.contains(name) } ?: return@listenEvent
80-
playerData.currentProfile?.mining?.selectedAbility = MiningAbility.byRawName(rawName)
77+
currentProfile.mining.selectedAbility = MiningAbility.byRawName(rawName)
8178
}
8279
}
8380
peakOfTheMountainRegex.matches(itemNameString) -> {
8481
val lore = itemStack.lore
8582
val firstLine = lore.first().string
86-
val level = firstLine.drop(6).first().digitToIntOrNull() ?: return@listenEvent
87-
playerData.currentProfile?.mining?.abilityLevel = if (level > 1) 2 else 1
83+
val level = peakOfTheMountainLevelRegex.singleGroup(firstLine)?.toIntOrNull() ?: return@listenEvent
84+
currentProfile.mining.abilityLevel = if (level > 1) 2 else 1
85+
currentProfile.mining.peakOfTheMountain = level
8886
}
8987
hotmTitleRegex.matches(itemNameString) -> {
9088
val lore = itemStack.lore.map { line -> line.string }
9189
val (mithrilPowder, gemstonePowder, glacitePowder) = lore.mapNotNull { line ->
9290
mithrilPowderRegex.singleGroup(line) ?: gemstonePowderRegex.singleGroup(line)
9391
?: glacitePowderRegex.singleGroup(line)
9492
}
95-
playerData.currentProfile?.mining?.mithrilPowder =
93+
currentProfile.mining.mithrilPowder =
9694
mithrilPowder.doubleOrNull()?.toInt() ?: return@listenEvent
97-
playerData.currentProfile?.mining?.gemstonePowder =
95+
currentProfile.mining.gemstonePowder =
9896
gemstonePowder.doubleOrNull()?.toInt() ?: return@listenEvent
99-
playerData.currentProfile?.mining?.glacitePowder =
97+
currentProfile.mining.glacitePowder =
10098
glacitePowder.doubleOrNull()?.toInt() ?: return@listenEvent
10199
}
102100
}
@@ -115,15 +113,15 @@ object PlayerDataUpdater {
115113
val glacitePowder = tablistGlacitePowderRegex.singleGroup(line)?.doubleOrNull()?.toInt()
116114

117115
if (mithrilPowder != null) {
118-
playerData.currentProfile?.mining?.mithrilPowder = mithrilPowder
116+
currentProfile.mining.mithrilPowder = mithrilPowder
119117
EventHandler.invokeEvent(PowderGainEvent(PowderGainEvent.PowderType.MITHRIL, mithrilPowder))
120118
}
121119
if (gemstonePowder != null) {
122-
playerData.currentProfile?.mining?.gemstonePowder = gemstonePowder
120+
currentProfile.mining.gemstonePowder = gemstonePowder
123121
EventHandler.invokeEvent(PowderGainEvent(PowderGainEvent.PowderType.GEMSTONE, gemstonePowder))
124122
}
125123
if (glacitePowder != null) {
126-
playerData.currentProfile?.mining?.glacitePowder = glacitePowder
124+
currentProfile.mining.glacitePowder = glacitePowder
127125
EventHandler.invokeEvent(PowderGainEvent(PowderGainEvent.PowderType.GLACITE, glacitePowder))
128126
}
129127
}

src/main/kotlin/dev/nyon/skylper/skyblock/data/skylper/StoredPlayerData.kt

+17
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,28 @@
11
package dev.nyon.skylper.skyblock.data.skylper
22

3+
import dev.nyon.skylper.skyblock.data.session.PlayerSessionData
34
import dev.nyon.skylper.skyblock.mining.MiningAbility
45
import dev.nyon.skylper.skyblock.mining.hollows.Crystal
56
import dev.nyon.skylper.skyblock.mining.hollows.CrystalInstance
67
import dev.nyon.skylper.skyblock.mining.hollows.CrystalState
8+
import kotlinx.datetime.Clock
9+
import kotlinx.datetime.Instant
710
import kotlinx.serialization.Serializable
11+
import kotlin.time.Duration.Companion.minutes
812

913
lateinit var playerData: StoredPlayerData
14+
private var lastProfileNotice: Instant = Clock.System.now()
15+
val currentProfile: ProfileData
16+
get() {
17+
val profile = playerData.profiles[PlayerSessionData.profile]
18+
if (profile == null) {
19+
val now = Clock.System.now()
20+
if (PlayerSessionData.isOnSkyblock && now - lastProfileNotice > 1.minutes) println("No active Skyblock profile found. Please relog into Skyblock.")
21+
lastProfileNotice = now
22+
return ProfileData()
23+
}
24+
return profile
25+
}
1026

1127
@Serializable
1228
data class StoredPlayerData(
@@ -18,6 +34,7 @@ data class ProfileData(val mining: Mining = Mining())
1834

1935
@Serializable
2036
data class Mining(
37+
var peakOfTheMountain: Int = 0,
2138
var abilityLevel: Int = 1,
2239
var selectedAbility: MiningAbility? = null,
2340
var mithrilPowder: Int = 0,

src/main/kotlin/dev/nyon/skylper/skyblock/menu/bestiary/CompletionHighlighter.kt

+1-2
Original file line numberDiff line numberDiff line change
@@ -18,9 +18,8 @@ object CompletionHighlighter {
1818
val screenName = title.string
1919
if (bestiaryRegex.matches(screenName)) {
2020
val lore = slot.item.lore.map { it.string }
21-
val rest = screenName.drop(11)
2221
if (lore.none { Menu.clickToViewRegex.matches(it) }) return@listenEvent null
23-
if (lore.any { (rest.isEmpty() && familiesCompletedRegex.matches(it)) || maxedRegex.matches("MAX!") }) return@listenEvent null
22+
if (lore.any { familiesCompletedRegex.matches(it) || maxedRegex.matches(it) }) return@listenEvent null
2423

2524
return@listenEvent config.menu.bestiary.nonCompletedBestiaryHighlightColor.rgb
2625
}

src/main/kotlin/dev/nyon/skylper/skyblock/menu/collections/CompletionHighlighter.kt

+6-4
Original file line numberDiff line numberDiff line change
@@ -4,22 +4,24 @@ import dev.nyon.skylper.config.config
44
import dev.nyon.skylper.extensions.EventHandler.listenEvent
55
import dev.nyon.skylper.extensions.RenderItemBackgroundEvent
66
import dev.nyon.skylper.extensions.lore
7+
import dev.nyon.skylper.extensions.nameAsString
78
import dev.nyon.skylper.extensions.regex
89
import dev.nyon.skylper.skyblock.menu.Menu
910

1011
object CompletionHighlighter {
1112
private val collectionsRegex = regex("menu.collections.collections")
12-
private val collectionsMaxedOut = regex("menu.collections.collectionsMaxedOut")
13-
private val collectionMaxedOut = regex("menu.collections.collectionMaxedOut")
13+
private val collectionsMaxedOutRegex = regex("menu.collections.collectionsMaxedOut")
14+
private val collectionMaxedOutRegex = regex("menu.collections.collectionMaxedOut")
1415

1516
@Suppress("unused")
1617
val renderItemBackgroundEvent = listenEvent<RenderItemBackgroundEvent, Int?> {
1718
if (!config.menu.collections.highlightNonCompletedCollections) return@listenEvent null
1819
val screenName = title.string
1920
if (collectionsRegex.matches(screenName)) {
2021
val lore = slot.item.lore.map { it.string }
21-
if (lore.none { Menu.clickToViewRegex.matches(it) } || MinionCompletionHighlighter.craftedMinionsRegex.matches(slot.item.displayName.string)) return@listenEvent null
22-
if (lore.any { collectionsMaxedOut.matches("Collections Maxed Out: 100%") || collectionMaxedOut.matches("COLLECTION MAXED OUT!") }) return@listenEvent null
22+
if (lore.none { Menu.clickToViewRegex.matches(it) }) return@listenEvent null
23+
if (MinionCompletionHighlighter.craftedMinionsRegex.matches(slot.item.nameAsString)) return@listenEvent null
24+
if (lore.any { collectionsMaxedOutRegex.matches(it) || collectionMaxedOutRegex.matches(it) }) return@listenEvent null
2325
return@listenEvent config.menu.collections.nonCompletedCollectionHighlightColor.rgb
2426
}
2527

src/main/kotlin/dev/nyon/skylper/skyblock/menu/collections/MinionCompletionHighlighter.kt

+2-5
Original file line numberDiff line numberDiff line change
@@ -18,11 +18,8 @@ object MinionCompletionHighlighter {
1818
if (craftedMinionsRegex.matches(screenName)) {
1919
val lore = slot.item.lore.map { it.string }
2020
if (lore.none { clickToViewRecipesRegex.matches(it) }) return@listenEvent null
21-
val incompleteCount = lore.count { minionUncompletedRegex.matches(it) }
22-
if (incompleteCount == 0) return@listenEvent null
23-
if (incompleteCount == 1) return@listenEvent config.menu.collections.barelyCompletedCollectionHighlightColor.rgb
24-
if (lore.any { minionUncompletedRegex.matches(it) }) return@listenEvent config.menu.collections.nonCompletedCollectionHighlightColor.rgb
25-
return@listenEvent null
21+
if (lore.none { minionUncompletedRegex.matches(it) }) return@listenEvent null
22+
return@listenEvent config.menu.collections.nonCompletedCollectionHighlightColor.rgb
2623
}
2724

2825
null

src/main/kotlin/dev/nyon/skylper/skyblock/mining/MiningCooldown.kt

+4-5
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,6 @@ import dev.nyon.skylper.skyblock.data.online.IslandGroups
1313
import dev.nyon.skylper.skyblock.data.online.ToolGroups
1414
import dev.nyon.skylper.skyblock.data.session.PlayerSessionData
1515
import dev.nyon.skylper.skyblock.data.skylper.currentProfile
16-
import dev.nyon.skylper.skyblock.data.skylper.playerData
1716
import kotlinx.coroutines.delay
1817
import kotlinx.coroutines.launch
1918
import kotlinx.datetime.Clock
@@ -95,10 +94,10 @@ object MiningCooldown : Cooldown {
9594
}
9695

9796
override fun getCooldownTime(): Duration? {
98-
return when (playerData.currentProfile?.mining?.abilityLevel) {
99-
1 -> playerData.currentProfile?.mining?.selectedAbility?.levelOne?.seconds
100-
2 -> playerData.currentProfile?.mining?.selectedAbility?.levelTwo?.seconds
101-
3 -> playerData.currentProfile?.mining?.selectedAbility?.levelThree?.seconds
97+
return when (currentProfile.mining.abilityLevel) {
98+
1 -> currentProfile.mining.selectedAbility?.levelOne?.seconds
99+
2 -> currentProfile.mining.selectedAbility?.levelTwo?.seconds
100+
3 -> currentProfile.mining.selectedAbility?.levelThree?.seconds
102101
else -> null
103102
}
104103
}

src/main/kotlin/dev/nyon/skylper/skyblock/mining/TotalPowderWidget.kt

+3-4
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,6 @@ import dev.nyon.skylper.extensions.render.hud.TableHudWidget
88
import dev.nyon.skylper.extensions.render.hud.components.PlainTextHudComponent
99
import dev.nyon.skylper.independentScope
1010
import dev.nyon.skylper.skyblock.data.skylper.currentProfile
11-
import dev.nyon.skylper.skyblock.data.skylper.playerData
1211
import kotlinx.coroutines.delay
1312
import kotlinx.coroutines.launch
1413
import net.minecraft.ChatFormatting
@@ -41,7 +40,7 @@ object TotalPowderWidget :
4140
addComponent(
4241
0, 1, PlainTextHudComponent(
4342
Component.literal(
44-
playerData.currentProfile?.mining?.mithrilPowder?.format() ?: "Open /hotm screen"
43+
currentProfile.mining.mithrilPowder.format()
4544
)
4645
)
4746
)
@@ -55,7 +54,7 @@ object TotalPowderWidget :
5554
addComponent(
5655
1, 1, PlainTextHudComponent(
5756
Component.literal(
58-
playerData.currentProfile?.mining?.gemstonePowder?.format() ?: "Open /hotm screen"
57+
currentProfile.mining.gemstonePowder.format()
5958
)
6059
)
6160
)
@@ -69,7 +68,7 @@ object TotalPowderWidget :
6968
addComponent(
7069
2, 1, PlainTextHudComponent(
7170
Component.literal(
72-
playerData.currentProfile?.mining?.glacitePowder?.format() ?: "Open /hotm screen"
71+
currentProfile.mining.glacitePowder.format()
7372
)
7473
)
7574
)

src/main/kotlin/dev/nyon/skylper/skyblock/mining/hollows/locations/CrystalRunListener.kt

+1-1
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ import dev.nyon.skylper.skyblock.mining.hollows.HollowsModule
88

99
object CrystalRunListener {
1010
private val crystalFoundRegex = regex("chat.hollows.run.crystalFound")
11-
private val crystalPlacedRegex = regex("chat.hollows.run.crystalPlaced") // todo
11+
private val crystalPlacedRegex = regex("chat.hollows.run.crystalPlaced")
1212
private val runCompletedRegex = regex("chat.hollows.run.completed")
1313

1414
private var nextIsCrystal = false

0 commit comments

Comments
 (0)