aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorhannibal2 <24389977+hannibal00212@users.noreply.github.com>2023-05-18 01:43:51 +0200
committerhannibal2 <24389977+hannibal00212@users.noreply.github.com>2023-05-18 01:43:51 +0200
commit4eed61a02ad91cc68160754e68e9f4d23bd32e53 (patch)
treeeeb7638f7db3fb0e94e090483b038cc608f6baac
parenta10c097974d0b476be275c1fd2888d7502508efd (diff)
downloadskyhanni-4eed61a02ad91cc68160754e68e9f4d23bd32e53.tar.gz
skyhanni-4eed61a02ad91cc68160754e68e9f4d23bd32e53.tar.bz2
skyhanni-4eed61a02ad91cc68160754e68e9f4d23bd32e53.zip
Migrated minion data into profile specific logic
-rw-r--r--src/main/java/at/hannibal2/skyhanni/config/ConfigManager.kt11
-rw-r--r--src/main/java/at/hannibal2/skyhanni/config/Storage.java14
-rw-r--r--src/main/java/at/hannibal2/skyhanni/config/features/OldHidden.java4
-rw-r--r--src/main/java/at/hannibal2/skyhanni/data/ProfileStorageData.kt10
-rw-r--r--src/main/java/at/hannibal2/skyhanni/features/minion/MinionData.kt5
-rw-r--r--src/main/java/at/hannibal2/skyhanni/features/minion/MinionFeatures.kt60
-rw-r--r--src/main/java/at/hannibal2/skyhanni/utils/LorenzVec.kt12
7 files changed, 58 insertions, 58 deletions
diff --git a/src/main/java/at/hannibal2/skyhanni/config/ConfigManager.kt b/src/main/java/at/hannibal2/skyhanni/config/ConfigManager.kt
index 74e6f1461..dbd197436 100644
--- a/src/main/java/at/hannibal2/skyhanni/config/ConfigManager.kt
+++ b/src/main/java/at/hannibal2/skyhanni/config/ConfigManager.kt
@@ -4,6 +4,7 @@ import at.hannibal2.skyhanni.SkyHanniMod
import at.hannibal2.skyhanni.features.garden.CropType
import at.hannibal2.skyhanni.features.misc.update.UpdateManager
import at.hannibal2.skyhanni.utils.LorenzLogger
+import at.hannibal2.skyhanni.utils.LorenzVec
import com.google.gson.GsonBuilder
import com.google.gson.TypeAdapter
import com.google.gson.stream.JsonReader
@@ -32,6 +33,16 @@ class ConfigManager {
return UUID.fromString(reader.nextString())
}
}.nullSafe())
+ .registerTypeAdapter(LorenzVec::class.java, object : TypeAdapter<LorenzVec>() {
+ override fun write(out: JsonWriter, value: LorenzVec) {
+ value.run { out.value("$x:$y:$z") }
+ }
+
+ override fun read(reader: JsonReader): LorenzVec {
+ val (x, y, z) = reader.nextString().split(":").map { it.toDouble() }
+ return LorenzVec(x, y, z)
+ }
+ }.nullSafe())
.enableComplexMapKeySerialization()
.create()
}
diff --git a/src/main/java/at/hannibal2/skyhanni/config/Storage.java b/src/main/java/at/hannibal2/skyhanni/config/Storage.java
index b99b7cd7d..5e84daaf1 100644
--- a/src/main/java/at/hannibal2/skyhanni/config/Storage.java
+++ b/src/main/java/at/hannibal2/skyhanni/config/Storage.java
@@ -4,6 +4,7 @@ import at.hannibal2.skyhanni.data.model.ComposterUpgrade;
import at.hannibal2.skyhanni.features.garden.CropAccessory;
import at.hannibal2.skyhanni.features.garden.CropType;
import at.hannibal2.skyhanni.features.garden.visitor.VisitorReward;
+import at.hannibal2.skyhanni.utils.LorenzVec;
import com.google.gson.annotations.Expose;
import java.util.*;
@@ -33,6 +34,19 @@ public class Storage {
public String currentPet = "";
@Expose
+ public Map<LorenzVec, MinionConfig> minions = new HashMap<>();
+
+ public static class MinionConfig {
+
+ @Expose
+ public String displayName = "";
+
+ @Expose
+ public long lastClicked = -1;
+
+ }
+
+ @Expose
public GardenStorage garden = new GardenStorage();
public static class GardenStorage {
diff --git a/src/main/java/at/hannibal2/skyhanni/config/features/OldHidden.java b/src/main/java/at/hannibal2/skyhanni/config/features/OldHidden.java
index be4407ce0..1feb80bbc 100644
--- a/src/main/java/at/hannibal2/skyhanni/config/features/OldHidden.java
+++ b/src/main/java/at/hannibal2/skyhanni/config/features/OldHidden.java
@@ -20,10 +20,10 @@ public class OldHidden {
public String currentPet = "";
@Expose
- public Map<String, Long> minionLastClick = new HashMap<>(); // TODO migration needed
+ public Map<String, Long> minionLastClick = new HashMap<>();
@Expose
- public Map<String, String> minionName = new HashMap<>(); // TODO migration needed
+ public Map<String, String> minionName = new HashMap<>();
@Expose
public List<String> crimsonIsleQuests = new ArrayList<>(); // TODO migration needed
diff --git a/src/main/java/at/hannibal2/skyhanni/data/ProfileStorageData.kt b/src/main/java/at/hannibal2/skyhanni/data/ProfileStorageData.kt
index 4a15c90d4..eeab991ea 100644
--- a/src/main/java/at/hannibal2/skyhanni/data/ProfileStorageData.kt
+++ b/src/main/java/at/hannibal2/skyhanni/data/ProfileStorageData.kt
@@ -4,6 +4,7 @@ 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.LorenzVec
import at.hannibal2.skyhanni.utils.StringUtils.matchMatcher
import net.minecraftforge.event.world.WorldEvent
import net.minecraftforge.fml.common.eventhandler.EventPriority
@@ -87,6 +88,15 @@ object ProfileStorageData {
profileSpecific?.let {
it.currentPet = oldHidden.currentPet
+
+ for ((rawLocation, minionName) in oldHidden.minionName) {
+ val lastClick = oldHidden.minionLastClick[rawLocation] ?: -1
+ val location = LorenzVec.decodeFromString(rawLocation)
+ val minionConfig = Storage.ProfileSpecific.MinionConfig()
+ minionConfig.displayName = minionName
+ minionConfig.lastClicked = lastClick
+ it.minions[location] = minionConfig
+ }
}
profileSpecific?.garden?.let {
diff --git a/src/main/java/at/hannibal2/skyhanni/features/minion/MinionData.kt b/src/main/java/at/hannibal2/skyhanni/features/minion/MinionData.kt
deleted file mode 100644
index e05e56544..000000000
--- a/src/main/java/at/hannibal2/skyhanni/features/minion/MinionData.kt
+++ /dev/null
@@ -1,5 +0,0 @@
-package at.hannibal2.skyhanni.features.minion
-
-import scala.Serializable
-
-class MinionData(var displayName: String, var lastClicked: Long) : Serializable \ No newline at end of file
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 4c0cd3937..b836fb315 100644
--- a/src/main/java/at/hannibal2/skyhanni/features/minion/MinionFeatures.kt
+++ b/src/main/java/at/hannibal2/skyhanni/features/minion/MinionFeatures.kt
@@ -1,8 +1,9 @@
package at.hannibal2.skyhanni.features.minion
import at.hannibal2.skyhanni.SkyHanniMod
+import at.hannibal2.skyhanni.config.Storage
import at.hannibal2.skyhanni.data.IslandType
-import at.hannibal2.skyhanni.events.ConfigLoadEvent
+import at.hannibal2.skyhanni.data.ProfileStorageData
import at.hannibal2.skyhanni.events.LorenzChatEvent
import at.hannibal2.skyhanni.test.GriffinUtils.drawWaypointFilled
import at.hannibal2.skyhanni.utils.*
@@ -42,17 +43,6 @@ class MinionFeatures {
private val minionUpgradePattern = "§aYou have upgraded your Minion to Tier (?<tier>.*)".toPattern()
@SubscribeEvent
- fun onConfigLoad(event: ConfigLoadEvent) {
- for (minion in SkyHanniMod.feature.hidden.minionLastClick) {
- val key = minion.key
- val vec = LorenzVec.decodeFromString(key)
- val name = SkyHanniMod.feature.hidden.minionName[key] ?: "§cNo name saved!"
- val data = MinionData(name, minion.value)
- minions[vec] = data
- }
- }
-
- @SubscribeEvent
fun onClick(event: InputEvent.MouseInputEvent) {
if (!LorenzUtils.inSkyBlock) return
if (LorenzUtils.skyBlockIsland != IslandType.PRIVATE_ISLAND) return
@@ -95,18 +85,20 @@ class MinionFeatures {
@SubscribeEvent
fun onTick(event: TickEvent.ClientTickEvent) {
if (LorenzUtils.skyBlockIsland != IslandType.PRIVATE_ISLAND) return
+ val minions = minions ?: return
val openInventory = InventoryUtils.currentlyOpenInventory()
if (openInventory.contains("Minion")) {
lastClickedEntity?.let {
val name = getMinionName(openInventory)
if (!minions.contains(it)) {
- minions[it] = MinionData(name, 0)
- saveConfig()
+ minions[it] = Storage.ProfileSpecific.MinionConfig().apply {
+ displayName = name
+ lastClicked = 0
+ }
} else {
if (minions[it]!!.displayName != name) {
minions[it]!!.displayName = name
- saveConfig()
}
}
lastMinion = it
@@ -124,7 +116,6 @@ class MinionFeatures {
if (System.currentTimeMillis() - lastCoinsRecived < 2_000) {
minions[location]!!.lastClicked = System.currentTimeMillis()
- saveConfig()
}
if (location !in minions) {
minions[location]!!.lastClicked = 0
@@ -132,7 +123,6 @@ class MinionFeatures {
if (System.currentTimeMillis() - lastMinionPickedUp < 2_000) {
minions.remove(location)
- saveConfig()
}
}
}
@@ -163,11 +153,13 @@ class MinionFeatures {
if (coinsPerDay != "") return coinsPerDay
- val lastClicked = minions[loc]!!.lastClicked
- if (lastClicked == 0L) {
- return "Can't calculate coins/day: No time data available!"
- }
- val duration = System.currentTimeMillis() - lastClicked
+ val duration = minions?.get(loc)?.let {
+ val lastClicked = it.lastClicked
+ if (lastClicked == 0L) {
+ return "Can't calculate coins/day: No time data available!"
+ }
+ System.currentTimeMillis() - lastClicked
+ } ?: return "Can't calculate coins/day: No time data available!"
//§7Held Coins: §b151,389
val coins = line.split(": §b")[1].replace(",", "").toDouble()
@@ -202,10 +194,9 @@ class MinionFeatures {
minionUpgradePattern.matchMatcher(message) {
val newTier = group("tier").romanToDecimalIfNeeded()
- minions[lastMinion]?.let {
+ minions?.get(lastMinion)?.let {
val minionName = getMinionName(it.displayName, newTier)
it.displayName = minionName
- saveConfig()
}
}
}
@@ -217,6 +208,7 @@ class MinionFeatures {
val playerLocation = LocationUtils.playerLocation()
val playerEyeLocation = LocationUtils.playerEyeLocation()
+ val minions = minions ?: return
for (minion in minions) {
val location = minion.key.add(0.0, 1.0, 0.0)
if (!LocationUtils.canSee(playerEyeLocation, location)) continue
@@ -253,6 +245,7 @@ class MinionFeatures {
if (entity !is EntityArmorStand) return
if (!entity.hasCustomName()) return
if (entity.isDead) return
+ val minions = minions ?: return
if (entity.customNameTag.contains("§c❤")) {
val loc = entity.getLorenzVec()
@@ -270,26 +263,11 @@ class MinionFeatures {
}
companion object {
- private val minions = mutableMapOf<LorenzVec, MinionData>()
+ private val minions get() = ProfileStorageData.profileSpecific?.minions
fun clearMinionData() {
- minions.clear()
- saveConfig()
+ minions?.clear()
LorenzUtils.chat("§e[SkyHanni] Manually reset all private island minion location data!")
}
-
- private fun saveConfig() {
- val minionConfig = SkyHanniMod.feature.hidden.minionLastClick
- val minionName = SkyHanniMod.feature.hidden.minionName
-
- minionConfig.clear()
- minionName.clear()
- for (minion in minions) {
- val coordinates = minion.key.encodeToString()
- val data = minion.value
- minionConfig[coordinates] = data.lastClicked
- minionName[coordinates] = data.displayName
- }
- }
}
} \ No newline at end of file
diff --git a/src/main/java/at/hannibal2/skyhanni/utils/LorenzVec.kt b/src/main/java/at/hannibal2/skyhanni/utils/LorenzVec.kt
index 8ac086718..5bce2d762 100644
--- a/src/main/java/at/hannibal2/skyhanni/utils/LorenzVec.kt
+++ b/src/main/java/at/hannibal2/skyhanni/utils/LorenzVec.kt
@@ -79,11 +79,6 @@ data class LorenzVec(
return sqrt(x * x + y * y + z * z)
}
- //TODO make this class json serializable
- fun encodeToString(): String {
- return "$x:$y:$z"
- }
-
fun isZero(): Boolean = x == 0.0 && y == 0.0 && z == 0.0
fun clone(): LorenzVec = LorenzVec(x, y, z)
@@ -107,12 +102,9 @@ data class LorenzVec(
return LorenzVec(x, z, y)
}
- //TODO make this class json serializable
+ // only for migration purposes
fun decodeFromString(string: String): LorenzVec {
- val split = string.split(":")
- val x = split[0].toDouble()
- val y = split[1].toDouble()
- val z = split[2].toDouble()
+ val (x, y, z) = string.split(":").map { it.toDouble() }
return LorenzVec(x, y, z)
}
}