aboutsummaryrefslogtreecommitdiff
path: root/src/main/java/at/hannibal2/skyhanni/data
diff options
context:
space:
mode:
authorhannibal2 <24389977+hannibal00212@users.noreply.github.com>2023-05-18 00:27:01 +0200
committerhannibal2 <24389977+hannibal00212@users.noreply.github.com>2023-05-18 00:27:01 +0200
commita10c097974d0b476be275c1fd2888d7502508efd (patch)
treeb9059f9ff1d010ce7ee32c4aece25a5dbc4141c3 /src/main/java/at/hannibal2/skyhanni/data
parent88bff6a920bd597e7ef2a22bbcd99750158e6816 (diff)
downloadskyhanni-a10c097974d0b476be275c1fd2888d7502508efd.tar.gz
skyhanni-a10c097974d0b476be275c1fd2888d7502508efd.tar.bz2
skyhanni-a10c097974d0b476be275c1fd2888d7502508efd.zip
added profile specific config support
Diffstat (limited to 'src/main/java/at/hannibal2/skyhanni/data')
-rw-r--r--src/main/java/at/hannibal2/skyhanni/data/ApiDataLoader.kt10
-rw-r--r--src/main/java/at/hannibal2/skyhanni/data/CropAccessoryData.kt6
-rw-r--r--src/main/java/at/hannibal2/skyhanni/data/GardenComposterUpgradesData.kt2
-rw-r--r--src/main/java/at/hannibal2/skyhanni/data/GardenCropMilestones.kt21
-rw-r--r--src/main/java/at/hannibal2/skyhanni/data/GardenCropUpgrades.kt13
-rw-r--r--src/main/java/at/hannibal2/skyhanni/data/HypixelData.kt4
-rw-r--r--src/main/java/at/hannibal2/skyhanni/data/ProfileStorageData.kt131
-rw-r--r--src/main/java/at/hannibal2/skyhanni/data/RenderGuiData.kt2
-rw-r--r--src/main/java/at/hannibal2/skyhanni/data/TitleUtils.kt6
9 files changed, 165 insertions, 30 deletions
diff --git a/src/main/java/at/hannibal2/skyhanni/data/ApiDataLoader.kt b/src/main/java/at/hannibal2/skyhanni/data/ApiDataLoader.kt
index d3b6a4e29..82938994a 100644
--- a/src/main/java/at/hannibal2/skyhanni/data/ApiDataLoader.kt
+++ b/src/main/java/at/hannibal2/skyhanni/data/ApiDataLoader.kt
@@ -28,7 +28,7 @@ class ApiDataLoader {
if (nextApiCallTime != -1L && System.currentTimeMillis() > nextApiCallTime) {
nextApiCallTime = System.currentTimeMillis() + 60_000 * 5
SkyHanniMod.coroutineScope.launch {
- val apiKey = SkyHanniMod.feature.hidden.apiKey
+ val apiKey = SkyHanniMod.feature.storage.apiKey
val uuid = LorenzUtils.getPlayerUuid()
loadProfileData(apiKey, uuid, currentProfileId)
}
@@ -39,7 +39,7 @@ class ApiDataLoader {
fun onStatusBar(event: LorenzChatEvent) {
val message = event.message
if (message.startsWith("§aYour new API key is §r§b")) {
- SkyHanniMod.feature.hidden.apiKey = message.substring(26)
+ SkyHanniMod.feature.storage.apiKey = message.substring(26)
LorenzUtils.chat("§b[SkyHanni] A new API Key has been detected and installed")
if (currentProfileName != "") {
@@ -86,13 +86,13 @@ class ApiDataLoader {
private fun updateApiData() {
nextApiCallTime = -1
SkyHanniMod.coroutineScope.launch {
- val oldApiKey = SkyHanniMod.feature.hidden.apiKey
+ val oldApiKey = SkyHanniMod.feature.storage.apiKey
if (oldApiKey.isNotEmpty() && tryUpdateProfileDataAndVerifyKey(oldApiKey)) {
return@launch
}
findApiCandidatesFromOtherMods().forEach { (modName, newApiKey) ->
if (tryUpdateProfileDataAndVerifyKey(newApiKey)) {
- SkyHanniMod.feature.hidden.apiKey = newApiKey
+ SkyHanniMod.feature.storage.apiKey = newApiKey
LorenzUtils.chat("§e[SkyHanni] Imported valid new API key from $modName.")
return@launch
} else {
@@ -149,7 +149,7 @@ class ApiDataLoader {
private var nextApiCallTime = -1L
fun command(args: Array<String>) {
- SkyHanniMod.feature.hidden.apiKey = args[0]
+ SkyHanniMod.feature.storage.apiKey = args[0]
LorenzUtils.chat("§e[SkyHanni] Api key set via command!")
nextApiCallTime = -1
}
diff --git a/src/main/java/at/hannibal2/skyhanni/data/CropAccessoryData.kt b/src/main/java/at/hannibal2/skyhanni/data/CropAccessoryData.kt
index ed524e233..2899999c3 100644
--- a/src/main/java/at/hannibal2/skyhanni/data/CropAccessoryData.kt
+++ b/src/main/java/at/hannibal2/skyhanni/data/CropAccessoryData.kt
@@ -1,11 +1,11 @@
package at.hannibal2.skyhanni.data
-import at.hannibal2.skyhanni.SkyHanniMod
import at.hannibal2.skyhanni.events.InventoryCloseEvent
import at.hannibal2.skyhanni.events.InventoryOpenEvent
import at.hannibal2.skyhanni.events.ProfileApiDataLoadedEvent
import at.hannibal2.skyhanni.events.ProfileJoinEvent
import at.hannibal2.skyhanni.features.garden.CropAccessory
+import at.hannibal2.skyhanni.features.garden.GardenAPI
import at.hannibal2.skyhanni.utils.InventoryUtils
import at.hannibal2.skyhanni.utils.ItemUtils.getInternalName
import at.hannibal2.skyhanni.utils.LorenzUtils
@@ -116,9 +116,9 @@ class CropAccessoryData {
val pagesLoaded get() = accessoryPage.size
var cropAccessory: CropAccessory?
- get() = SkyHanniMod.feature.hidden.savedCropAccessory
+ get() = GardenAPI.config?.savedCropAccessory
private set(accessory) {
- SkyHanniMod.feature.hidden.savedCropAccessory = accessory
+ GardenAPI.config?.savedCropAccessory = accessory
}
// Derived partially from NotEnoughUpdates/NotEnoughUpdates, ProfileViewer.Profile#getInventoryInfo
diff --git a/src/main/java/at/hannibal2/skyhanni/data/GardenComposterUpgradesData.kt b/src/main/java/at/hannibal2/skyhanni/data/GardenComposterUpgradesData.kt
index 126cd52ea..1cf65578d 100644
--- a/src/main/java/at/hannibal2/skyhanni/data/GardenComposterUpgradesData.kt
+++ b/src/main/java/at/hannibal2/skyhanni/data/GardenComposterUpgradesData.kt
@@ -23,7 +23,7 @@ class GardenComposterUpgradesData {
val name = matcher.group("name")
val level = matcher.group("level")?.romanToDecimalIfNeeded() ?: 0
val composterUpgrade = ComposterUpgrade.getByName(name)!!
- ComposterAPI.composterUpgrades[composterUpgrade] = level
+ ComposterAPI.composterUpgrades?.put(composterUpgrade, level)
}
}
}
diff --git a/src/main/java/at/hannibal2/skyhanni/data/GardenCropMilestones.kt b/src/main/java/at/hannibal2/skyhanni/data/GardenCropMilestones.kt
index da7f0b05b..e78c68872 100644
--- a/src/main/java/at/hannibal2/skyhanni/data/GardenCropMilestones.kt
+++ b/src/main/java/at/hannibal2/skyhanni/data/GardenCropMilestones.kt
@@ -1,12 +1,11 @@
package at.hannibal2.skyhanni.data
-import at.hannibal2.skyhanni.SkyHanniMod
import at.hannibal2.skyhanni.events.CropMilestoneUpdateEvent
import at.hannibal2.skyhanni.events.InventoryOpenEvent
import at.hannibal2.skyhanni.features.garden.CropType
+import at.hannibal2.skyhanni.features.garden.GardenAPI
import at.hannibal2.skyhanni.utils.ItemUtils.getLore
import at.hannibal2.skyhanni.utils.StringUtils.matchMatcher
-import net.minecraftforge.event.world.WorldEvent
import net.minecraftforge.fml.common.eventhandler.SubscribeEvent
class GardenCropMilestones {
@@ -27,15 +26,6 @@ class GardenCropMilestones {
// }
@SubscribeEvent
- fun onWorldChange(event: WorldEvent.Load) {
- if (cropCounter.isEmpty()) {
- for (crop in CropType.values()) {
- crop.setCounter(0)
- }
- }
- }
-
- @SubscribeEvent
fun onInventoryOpen(event: InventoryOpenEvent) {
if (event.inventoryName != "Crop Milestones") return
@@ -52,17 +42,17 @@ class GardenCropMilestones {
}
}
}
-
CropMilestoneUpdateEvent().postAndCatch()
}
companion object {
- val cropCounter: MutableMap<CropType, Long> get() = SkyHanniMod.feature.hidden.gardenCropCounter
+ val cropCounter: MutableMap<CropType, Long>? get() = GardenAPI.config?.cropCounter
- fun CropType.getCounter() = cropCounter[this]!!
+ // TODO make nullable
+ fun CropType.getCounter() = cropCounter?.get(this) ?: 0
fun CropType.setCounter(counter: Long) {
- cropCounter[this] = counter
+ cropCounter?.set(this, counter)
}
fun getTierForCrops(crops: Long): Int {
@@ -153,6 +143,7 @@ class GardenCropMilestones {
}
}
+// TODO delete?
private fun String.formatNumber(): Long {
var text = replace(",", "")
val multiplier = if (text.endsWith("k")) {
diff --git a/src/main/java/at/hannibal2/skyhanni/data/GardenCropUpgrades.kt b/src/main/java/at/hannibal2/skyhanni/data/GardenCropUpgrades.kt
index e5ece4acc..04717a9a5 100644
--- a/src/main/java/at/hannibal2/skyhanni/data/GardenCropUpgrades.kt
+++ b/src/main/java/at/hannibal2/skyhanni/data/GardenCropUpgrades.kt
@@ -1,11 +1,11 @@
package at.hannibal2.skyhanni.data
-import at.hannibal2.skyhanni.SkyHanniMod
import at.hannibal2.skyhanni.events.CropUpgradeUpdateEvent
import at.hannibal2.skyhanni.events.InventoryOpenEvent
import at.hannibal2.skyhanni.events.LorenzChatEvent
import at.hannibal2.skyhanni.features.garden.CropType
import at.hannibal2.skyhanni.features.garden.CropType.Companion.getByNameOrNull
+import at.hannibal2.skyhanni.features.garden.GardenAPI
import at.hannibal2.skyhanni.utils.ItemUtils.getLore
import at.hannibal2.skyhanni.utils.ItemUtils.name
import at.hannibal2.skyhanni.utils.StringUtils.removeColor
@@ -32,22 +32,23 @@ class GardenCropUpgrades {
val crop = item.name?.removeColor()?.let {
CropType.getByNameOrNull(it)
} ?: return@forEach
+ println("finding for '$crop'")
val level = item.getLore().firstNotNullOfOrNull {
tierPattern.matchEntire(it)?.groups?.get(1)?.value?.toIntOrNull()
- } ?: return@forEach
+ } ?: 0
+ println("found: $level")
crop.setUpgradeLevel(level)
}
CropUpgradeUpdateEvent().postAndCatch()
}
companion object {
- private val cropUpgrades: MutableMap<CropType, Int> get() =
- SkyHanniMod.feature.hidden.gardenCropUpgrades
+ private val cropUpgrades: MutableMap<CropType, Int>? get() = GardenAPI.config?.cropUpgrades
- fun CropType.getUpgradeLevel() = cropUpgrades[this]
+ fun CropType.getUpgradeLevel() = cropUpgrades?.get(this)
fun CropType.setUpgradeLevel(level: Int) {
- cropUpgrades[this] = level
+ cropUpgrades?.put(this, level)
}
}
diff --git a/src/main/java/at/hannibal2/skyhanni/data/HypixelData.kt b/src/main/java/at/hannibal2/skyhanni/data/HypixelData.kt
index 580954dc2..b3e27f011 100644
--- a/src/main/java/at/hannibal2/skyhanni/data/HypixelData.kt
+++ b/src/main/java/at/hannibal2/skyhanni/data/HypixelData.kt
@@ -1,5 +1,6 @@
package at.hannibal2.skyhanni.data
+import at.hannibal2.skyhanni.events.HypixelJoinEvent
import at.hannibal2.skyhanni.events.IslandChangeEvent
import at.hannibal2.skyhanni.events.LorenzChatEvent
import at.hannibal2.skyhanni.events.ProfileJoinEvent
@@ -83,6 +84,9 @@ class HypixelData {
if (!LorenzUtils.onHypixel) {
checkHypixel()
+ if (LorenzUtils.onHypixel) {
+ HypixelJoinEvent().postAndCatch()
+ }
}
if (!LorenzUtils.onHypixel) return
diff --git a/src/main/java/at/hannibal2/skyhanni/data/ProfileStorageData.kt b/src/main/java/at/hannibal2/skyhanni/data/ProfileStorageData.kt
new file mode 100644
index 000000000..4a15c90d4
--- /dev/null
+++ b/src/main/java/at/hannibal2/skyhanni/data/ProfileStorageData.kt
@@ -0,0 +1,131 @@
+package at.hannibal2.skyhanni.data
+
+import at.hannibal2.skyhanni.SkyHanniMod
+import at.hannibal2.skyhanni.config.Storage
+import at.hannibal2.skyhanni.events.*
+import at.hannibal2.skyhanni.utils.LorenzUtils
+import at.hannibal2.skyhanni.utils.StringUtils.matchMatcher
+import net.minecraftforge.event.world.WorldEvent
+import net.minecraftforge.fml.common.eventhandler.EventPriority
+import net.minecraftforge.fml.common.eventhandler.SubscribeEvent
+
+object ProfileStorageData {
+ var playerSpecific: Storage.PlayerSpecific? = null
+ var profileSpecific: Storage.ProfileSpecific? = null
+ var loaded = false
+
+ private var nextProfile: String? = null
+
+ @SubscribeEvent(priority = EventPriority.HIGHEST)
+ fun onChat(event: LorenzChatEvent) {
+ "§7Switching to profile (?<name>.*)\\.\\.\\.".toPattern().matchMatcher(event.message) {
+ nextProfile = group("name").lowercase()
+ println("switching to profile: '$nextProfile'")
+ loaded = false
+ PreProfileSwitchEvent().postAndCatch()
+ }
+ }
+
+ @SubscribeEvent(priority = EventPriority.HIGHEST)
+ fun onWorldChange(event: WorldEvent.Load) {
+ val profileName = nextProfile ?: return
+ nextProfile = null
+ println("new world after profile swap.")
+
+ val playerSpecific = playerSpecific
+ if (playerSpecific == null) {
+ LorenzUtils.error("profileSpecific after profile swap can not be set: playerSpecific is null!")
+ return
+ }
+ profileSpecific = playerSpecific.profiles.getOrPut(profileName) { Storage.ProfileSpecific() }
+ loaded = true
+ println("profileSpecific loaded after profile swap!")
+ ConfigLoadEvent().postAndCatch()
+ }
+
+ @SubscribeEvent(priority = EventPriority.HIGHEST)
+ fun onProfileJoin(event: ProfileJoinEvent) {
+ val playerSpecific = playerSpecific
+ if (playerSpecific == null) {
+ LorenzUtils.error("playerSpecific is null in ProfileJoinEvent!")
+ return
+ }
+
+ if (profileSpecific == null) {
+ val profileName = event.name
+ profileSpecific = playerSpecific.profiles.getOrPut(profileName) { Storage.ProfileSpecific() }
+ loaded = true
+ migrateProfileSpecific()
+ println("profileSpecific loaded for first join!")
+ ConfigLoadEvent().postAndCatch()
+ }
+ }
+
+ @SubscribeEvent
+ fun onConfigLoad(event: HypixelJoinEvent) {
+ val playerUuid = LorenzUtils.getRawPlayerUuid()
+ playerSpecific = SkyHanniMod.feature.storage.players.getOrPut(playerUuid) { Storage.PlayerSpecific() }
+ migratePlayerSpecific()
+ println("loaded playerSpecific because of HypixelJoinEvent!")
+ ConfigLoadEvent().postAndCatch()
+ }
+
+ private fun migratePlayerSpecific() {
+ val oldHidden = SkyHanniMod.feature.hidden
+ if (oldHidden.isMigrated) return
+
+ SkyHanniMod.feature.storage.apiKey = oldHidden.apiKey
+
+ SkyHanniMod.feature.storage?.let {
+ it.gardenJacobFarmingContestTimes = oldHidden.gardenJacobFarmingContestTimes
+ }
+ }
+
+ private fun migrateProfileSpecific() {
+ val oldHidden = SkyHanniMod.feature.hidden
+ if (oldHidden.isMigrated) return
+
+ profileSpecific?.let {
+ it.currentPet = oldHidden.currentPet
+ }
+
+ profileSpecific?.garden?.let {
+ it.experience = oldHidden.gardenExp
+ it.cropCounter = oldHidden.gardenCropCounter
+ it.cropUpgrades = oldHidden.gardenCropUpgrades
+
+ for ((crop, speed) in oldHidden.gardenCropsPerSecond) {
+ if (speed != -1) {
+ it.cropsPerSecond[crop] = speed
+ }
+ }
+
+ it.latestBlocksPerSecond = oldHidden.gardenLatestBlocksPerSecond
+ it.latestTrueFarmingFortune = oldHidden.gardenLatestTrueFarmingFortune
+ it.savedCropAccessory = oldHidden.savedCropAccessory
+ it.dicerRngDrops = oldHidden.gardenDicerRngDrops
+ it.informedAboutLowMatter = oldHidden.informedAboutLowMatter
+ it.informedAboutLowFuel = oldHidden.informedAboutLowFuel
+ it.visitorInterval = oldHidden.visitorInterval
+ it.nextSixthVisitorArrival = oldHidden.nextSixthVisitorArrival
+ it.farmArmorDrops = oldHidden.gardenFarmingArmorDrops
+ it.composterUpgrades = oldHidden.gardenComposterUpgrades
+ it.toolWithBountiful = oldHidden.gardenToolHasBountiful
+ it.composterCurrentOrganicMatterItem = oldHidden.gardenComposterCurrentOrganicMatterItem
+ it.composterCurrentFuelItem = oldHidden.gardenComposterCurrentFuelItem
+ }
+
+ profileSpecific?.garden?.visitorDrops?.let {
+ val old = oldHidden.visitorDrops
+ it.acceptedVisitors = old.acceptedVisitors
+ it.deniedVisitors = old.deniedVisitors
+ it.visitorRarities = old.visitorRarities
+ it.copper = old.copper
+ it.farmingExp = old.farmingExp
+ it.coinsSpent = old.coinsSpent
+ it.rewardsCount = old.rewardsCount
+ }
+
+ oldHidden.isMigrated = true
+ }
+} \ No newline at end of file
diff --git a/src/main/java/at/hannibal2/skyhanni/data/RenderGuiData.kt b/src/main/java/at/hannibal2/skyhanni/data/RenderGuiData.kt
index 11e6f86f5..3f0562f0d 100644
--- a/src/main/java/at/hannibal2/skyhanni/data/RenderGuiData.kt
+++ b/src/main/java/at/hannibal2/skyhanni/data/RenderGuiData.kt
@@ -13,6 +13,7 @@ class RenderGuiData {
@SubscribeEvent
fun onRenderOverlay(event: RenderGameOverlayEvent.Pre) {
+// if (!ProfileStorage.loaded) return
if (event.type != RenderGameOverlayEvent.ElementType.HOTBAR) return
if (GuiEditManager.isInGui()) return
@@ -21,6 +22,7 @@ class RenderGuiData {
@SubscribeEvent
fun onBackgroundDraw(event: GuiScreenEvent.BackgroundDrawnEvent) {
+// if (!ProfileStorage.loaded) return
if (GuiEditManager.isInGui()) return
val currentScreen = Minecraft.getMinecraft().currentScreen ?: return
if (currentScreen !is GuiInventory && currentScreen !is GuiChest) return
diff --git a/src/main/java/at/hannibal2/skyhanni/data/TitleUtils.kt b/src/main/java/at/hannibal2/skyhanni/data/TitleUtils.kt
index 89e11f447..c43511afa 100644
--- a/src/main/java/at/hannibal2/skyhanni/data/TitleUtils.kt
+++ b/src/main/java/at/hannibal2/skyhanni/data/TitleUtils.kt
@@ -1,6 +1,7 @@
package at.hannibal2.skyhanni.data
import at.hannibal2.skyhanni.events.GuiRenderEvent
+import at.hannibal2.skyhanni.events.PreProfileSwitchEvent
import io.github.moulberry.moulconfig.internal.TextRenderUtils
import net.minecraft.client.Minecraft
import net.minecraft.client.gui.ScaledResolution
@@ -20,6 +21,11 @@ class TitleUtils {
}
@SubscribeEvent
+ fun onPreProfileSwitch(event: PreProfileSwitchEvent) {
+ sendTitle("", 1)
+ }
+
+ @SubscribeEvent
fun onRenderOverlay(event: GuiRenderEvent.GameOverlayRenderEvent) {
if (System.currentTimeMillis() > endTime) return