aboutsummaryrefslogtreecommitdiff
path: root/src/main/java/at
diff options
context:
space:
mode:
authorCalMWolfs <94038482+CalMWolfs@users.noreply.github.com>2023-11-18 09:44:42 +1100
committerGitHub <noreply@github.com>2023-11-17 23:44:42 +0100
commit65a2c5625f5f07e7c7e354e4a1397282032c9ae0 (patch)
treed710597e8278d15780b67e4afca7aae286970b28 /src/main/java/at
parentab4aadf4a6c8564b3bddde6b9b9ecfcabe4254a7 (diff)
downloadskyhanni-65a2c5625f5f07e7c7e354e4a1397282032c9ae0.tar.gz
skyhanni-65a2c5625f5f07e7c7e354e4a1397282032c9ae0.tar.bz2
skyhanni-65a2c5625f5f07e7c7e354e4a1397282032c9ae0.zip
Split storage into more files plus code cleanup (#695)
Extracted sacks, friends, known features and jacob contests in to their separate files. #695
Diffstat (limited to 'src/main/java/at')
-rw-r--r--src/main/java/at/hannibal2/skyhanni/SkyHanniMod.kt12
-rw-r--r--src/main/java/at/hannibal2/skyhanni/config/ConfigManager.kt163
-rw-r--r--src/main/java/at/hannibal2/skyhanni/config/Features.java2
-rw-r--r--src/main/java/at/hannibal2/skyhanni/config/Storage.java3
-rw-r--r--src/main/java/at/hannibal2/skyhanni/config/commands/Commands.kt3
-rw-r--r--src/main/java/at/hannibal2/skyhanni/data/FriendAPI.kt50
-rw-r--r--src/main/java/at/hannibal2/skyhanni/data/SackAPI.kt3
-rw-r--r--src/main/java/at/hannibal2/skyhanni/features/garden/GardenNextJacobContest.kt6
-rw-r--r--src/main/java/at/hannibal2/skyhanni/features/misc/massconfiguration/DefaultConfigFeatures.kt15
-rw-r--r--src/main/java/at/hannibal2/skyhanni/test/SkyHanniDebugsAndTests.kt5
-rw-r--r--src/main/java/at/hannibal2/skyhanni/utils/jsonobjects/JacobContestsJson.java13
-rw-r--r--src/main/java/at/hannibal2/skyhanni/utils/jsonobjects/KnownFeaturesJson.java12
12 files changed, 163 insertions, 124 deletions
diff --git a/src/main/java/at/hannibal2/skyhanni/SkyHanniMod.kt b/src/main/java/at/hannibal2/skyhanni/SkyHanniMod.kt
index 5309a4e2e..8fc4f42e1 100644
--- a/src/main/java/at/hannibal2/skyhanni/SkyHanniMod.kt
+++ b/src/main/java/at/hannibal2/skyhanni/SkyHanniMod.kt
@@ -1,6 +1,7 @@
package at.hannibal2.skyhanni
import at.hannibal2.skyhanni.api.CollectionAPI
+import at.hannibal2.skyhanni.config.ConfigFileType
import at.hannibal2.skyhanni.config.ConfigManager
import at.hannibal2.skyhanni.config.Features
import at.hannibal2.skyhanni.config.SackData
@@ -306,6 +307,9 @@ import at.hannibal2.skyhanni.utils.KeyboardManager
import at.hannibal2.skyhanni.utils.MinecraftConsoleFilter.Companion.initLogging
import at.hannibal2.skyhanni.utils.NEUVersionCheck.checkIfNeuIsLoaded
import at.hannibal2.skyhanni.utils.TabListData
+import at.hannibal2.skyhanni.utils.jsonobjects.FriendsJson
+import at.hannibal2.skyhanni.utils.jsonobjects.JacobContestsJson
+import at.hannibal2.skyhanni.utils.jsonobjects.KnownFeaturesJson
import kotlinx.coroutines.CoroutineName
import kotlinx.coroutines.CoroutineScope
import kotlinx.coroutines.Job
@@ -384,7 +388,7 @@ class SkyHanniMod {
loadModule(GardenAPI)
loadModule(CollectionAPI())
loadModule(FarmingContestAPI)
- loadModule(FriendAPI())
+ loadModule(FriendAPI)
loadModule(PartyAPI)
loadModule(GuildAPI)
loadModule(SlayerAPI)
@@ -652,7 +656,7 @@ class SkyHanniMod {
configManager.firstLoad()
initLogging()
Runtime.getRuntime().addShutdownHook(Thread {
- configManager.saveConfig("shutdown-hook")
+ configManager.saveConfig(ConfigFileType.FEATURES, "shutdown-hook")
})
repo = RepoManager(configManager.configDirectory)
try {
@@ -689,6 +693,10 @@ class SkyHanniMod {
@JvmStatic
val feature: Features get() = configManager.features
val sackData: SackData get() = configManager.sackData
+ val friendsData: FriendsJson get() = configManager.friendsData
+ val knownFeaturesData: KnownFeaturesJson get() = configManager.knownFeaturesData
+ val jacobContestsData: JacobContestsJson get() = configManager.jacobContestData
+
lateinit var repo: RepoManager
lateinit var configManager: ConfigManager
val logger: Logger = LogManager.getLogger("SkyHanni")
diff --git a/src/main/java/at/hannibal2/skyhanni/config/ConfigManager.kt b/src/main/java/at/hannibal2/skyhanni/config/ConfigManager.kt
index 508f18dea..80db032e9 100644
--- a/src/main/java/at/hannibal2/skyhanni/config/ConfigManager.kt
+++ b/src/main/java/at/hannibal2/skyhanni/config/ConfigManager.kt
@@ -10,6 +10,9 @@ import at.hannibal2.skyhanni.utils.LorenzVec
import at.hannibal2.skyhanni.utils.NEUInternalName
import at.hannibal2.skyhanni.utils.NEUInternalName.Companion.asInternalName
import at.hannibal2.skyhanni.utils.NEUItems
+import at.hannibal2.skyhanni.utils.jsonobjects.FriendsJson
+import at.hannibal2.skyhanni.utils.jsonobjects.JacobContestsJson
+import at.hannibal2.skyhanni.utils.jsonobjects.KnownFeaturesJson
import com.google.gson.GsonBuilder
import com.google.gson.JsonObject
import com.google.gson.TypeAdapter
@@ -110,13 +113,26 @@ class ConfigManager {
}
lateinit var features: Features
+ private set
lateinit var sackData: SackData
private set
+ lateinit var friendsData: FriendsJson
+ private set
+ lateinit var knownFeaturesData: KnownFeaturesJson
+ private set
+ lateinit var jacobContestData: JacobContestsJson
+ private set
+
private val logger = LorenzLogger("config_manager")
var configDirectory = File("config/skyhanni")
+
private var configFile: File? = null
private var sackFile: File? = null
+ private var friendsFile: File? = null
+ private var knowFeaturesFile: File? = null
+ private var jacobContestsFile: File? = null
+
lateinit var processor: MoulConfigProcessor<Features>
private var disableSaving = false
@@ -128,91 +144,94 @@ class ConfigManager {
configFile = File(configDirectory, "config.json")
sackFile = File(configDirectory, "sacks.json")
+ friendsFile = File(configDirectory, "friends.json")
+ knowFeaturesFile = File(configDirectory, "known_features.json")
+ jacobContestsFile = File(configDirectory, "jacob_contests.json")
- logger.log("Trying to load config from $configFile")
+ features = firstLoadFile(configFile, ConfigFileType.FEATURES, Features(), true)
+ sackData = firstLoadFile(sackFile, ConfigFileType.SACKS, SackData(), false)
+ friendsData = firstLoadFile(friendsFile, ConfigFileType.FRIENDS, FriendsJson(), false)
+ knownFeaturesData = firstLoadFile(knowFeaturesFile, ConfigFileType.KNOWN_FEATURES, KnownFeaturesJson(), false)
+ jacobContestData = firstLoadFile(jacobContestsFile, ConfigFileType.JACOB_CONTESTS, JacobContestsJson(), false)
- if (configFile!!.exists()) {
+ fixedRateTimer(name = "skyhanni-config-auto-save", period = 60_000L, initialDelay = 60_000L) {
+ saveConfig(ConfigFileType.FEATURES, "auto-save-60s")
+ }
+
+ val features = SkyHanniMod.feature
+ processor = MoulConfigProcessor(SkyHanniMod.feature)
+ BuiltinMoulConfigGuis.addProcessors(processor)
+ UpdateManager.injectConfigProcessor(processor)
+ ConfigProcessorDriver.processConfig(
+ features.javaClass,
+ features,
+ processor
+ )
+ }
+
+ private inline fun <reified T> firstLoadFile(file: File?, fileType: ConfigFileType, defaultValue: T, isConfig: Boolean): T {
+ val fileName = fileType.fileName
+ logger.log("Trying to load $fileName from $file")
+ var output: T = defaultValue
+
+ if (file!!.exists()) {
try {
- val inputStreamReader = InputStreamReader(FileInputStream(configFile!!), StandardCharsets.UTF_8)
+ val inputStreamReader = InputStreamReader(FileInputStream(file), StandardCharsets.UTF_8)
val bufferedReader = BufferedReader(inputStreamReader)
- logger.log("load-config-now")
- val jsonObject = gson.fromJson(bufferedReader.readText(), JsonObject::class.java)
- val newJsonObject = ConfigUpdaterMigrator.fixConfig(jsonObject)
- features = gson.fromJson(
- newJsonObject,
- Features::class.java
- )
- logger.log("Loaded config from file")
+ logger.log("load-$fileName-now")
+
+ output = if (isConfig) {
+ val jsonObject = gson.fromJson(bufferedReader.readText(), JsonObject::class.java)
+ val newJsonObject = ConfigUpdaterMigrator.fixConfig(jsonObject)
+ gson.fromJson(newJsonObject, T::class.java)
+ } else {
+ gson.fromJson(bufferedReader.readText(), T::class.java)
+ }
+
+ logger.log("Loaded $fileName from file")
} catch (error: Exception) {
error.printStackTrace()
- val backupFile = configFile!!.resolveSibling("config-${System.currentTimeMillis()}-backup.json")
- logger.log("Exception while reading $configFile. Will load blank config and save backup to $backupFile")
+ val backupFile = file.resolveSibling("$fileName-${System.currentTimeMillis()}-backup.json")
+ logger.log("Exception while reading $file. Will load blank $fileName and save backup to $backupFile")
logger.log("Exception was $error")
try {
- configFile!!.copyTo(backupFile)
+ file.copyTo(backupFile)
} catch (e: Exception) {
- logger.log("Could not create backup for config file")
+ logger.log("Could not create backup for $fileName file")
e.printStackTrace()
}
}
}
- if (sackFile!!.exists()) {
- try {
- val inputStreamReader = InputStreamReader(FileInputStream(sackFile!!), StandardCharsets.UTF_8)
- val bufferedReader = BufferedReader(inputStreamReader)
-
- logger.log("load-sacks-now")
- sackData = gson.fromJson(
- bufferedReader.readText(),
- SackData::class.java
- )
- logger.log("Loaded sacks from file")
- } catch (error: Exception) {
- error.printStackTrace()
- }
- }
-
- if (!::features.isInitialized) {
- logger.log("Creating blank config and saving to file")
- features = Features()
- saveConfig("blank config")
+ if (output == defaultValue) {
+ logger.log("Setting $fileName to be blank as it did not exist. It will be saved once something is written to it")
}
- fixedRateTimer(name = "skyhanni-config-auto-save", period = 60_000L, initialDelay = 60_000L) {
- saveConfig("auto-save-60s")
- }
+ return output
+ }
- if (!::sackData.isInitialized) {
- logger.log("Creating blank sack data and saving")
- sackData = SackData()
- saveSackData("blank config")
+ fun saveConfig(fileType: ConfigFileType, reason: String) {
+ when (fileType) {
+ ConfigFileType.FEATURES -> saveFile(configFile, fileType.fileName, SkyHanniMod.feature, reason)
+ ConfigFileType.SACKS -> saveFile(sackFile, fileType.fileName, SkyHanniMod.sackData, reason)
+ ConfigFileType.FRIENDS -> saveFile(friendsFile, fileType.fileName, SkyHanniMod.friendsData, reason)
+ ConfigFileType.KNOWN_FEATURES -> saveFile(knowFeaturesFile, fileType.fileName, SkyHanniMod.knownFeaturesData, reason)
+ ConfigFileType.JACOB_CONTESTS -> saveFile(jacobContestsFile, fileType.fileName, SkyHanniMod.jacobContestsData, reason)
}
-
- val features = SkyHanniMod.feature
- processor = MoulConfigProcessor(SkyHanniMod.feature)
- BuiltinMoulConfigGuis.addProcessors(processor)
- UpdateManager.injectConfigProcessor(processor)
- ConfigProcessorDriver.processConfig(
- features.javaClass,
- features,
- processor
- )
}
- fun saveConfig(reason: String) {
+ private fun saveFile(file: File?, fileName: String, data: Any, reason: String) {
if (disableSaving) return
logger.log("saveConfig: $reason")
- val file = configFile ?: throw Error("Can not save config, configFile is null!")
+ if (file == null) throw Error("Can not save $fileName, ${fileName}File is null!")
try {
- logger.log("Saving config file")
+ logger.log("Saving $fileName file")
file.parentFile.mkdirs()
- val unit = file.parentFile.resolve("config.json.write")
+ val unit = file.parentFile.resolve("$fileName.json.write")
unit.createNewFile()
BufferedWriter(OutputStreamWriter(FileOutputStream(unit), StandardCharsets.UTF_8)).use { writer ->
- // TODO remove old "hidden" area
- writer.write(gson.toJson(SkyHanniMod.feature))
+ writer.write(gson.toJson(data))
}
// Perform move — which is atomic, unlike writing — after writing is done.
Files.move(
@@ -222,24 +241,7 @@ class ConfigManager {
StandardCopyOption.ATOMIC_MOVE
)
} catch (e: IOException) {
- logger.log("Could not save config file to $file")
- e.printStackTrace()
- }
- }
-
- fun saveSackData(reason: String) {
- if (disableSaving) return
- logger.log("saveSackData: $reason")
- val file = sackFile ?: throw Error("Can not save sacks, sackFile is null!")
- try {
- logger.log("Saving sack file")
- file.parentFile.mkdirs()
- file.createNewFile()
- BufferedWriter(OutputStreamWriter(FileOutputStream(file), StandardCharsets.UTF_8)).use { writer ->
- writer.write(gson.toJson(SkyHanniMod.sackData))
- }
- } catch (e: IOException) {
- logger.log("Could not save sacks file to $file")
+ logger.log("Could not save $fileName file to $file")
e.printStackTrace()
}
}
@@ -248,3 +250,12 @@ class ConfigManager {
disableSaving = true
}
}
+
+enum class ConfigFileType(val fileName: String) {
+ FEATURES("config"),
+ SACKS("sacks"),
+ FRIENDS("friends"),
+ KNOWN_FEATURES("known_features"),
+ JACOB_CONTESTS("jacob_contests"),
+ ;
+}
diff --git a/src/main/java/at/hannibal2/skyhanni/config/Features.java b/src/main/java/at/hannibal2/skyhanni/config/Features.java
index 4085eb069..bb0861e83 100644
--- a/src/main/java/at/hannibal2/skyhanni/config/Features.java
+++ b/src/main/java/at/hannibal2/skyhanni/config/Features.java
@@ -51,7 +51,7 @@ public class Features extends Config {
@Override
public void saveNow() {
- SkyHanniMod.configManager.saveConfig("close-gui");
+ SkyHanniMod.configManager.saveConfig(ConfigFileType.FEATURES, "close-gui");
}
@Override
diff --git a/src/main/java/at/hannibal2/skyhanni/config/Storage.java b/src/main/java/at/hannibal2/skyhanni/config/Storage.java
index 21a54735e..7170dde20 100644
--- a/src/main/java/at/hannibal2/skyhanni/config/Storage.java
+++ b/src/main/java/at/hannibal2/skyhanni/config/Storage.java
@@ -40,9 +40,6 @@ public class Storage {
public Map<String, List<String>> knownFeatureToggles = new HashMap<>();
@Expose
- public Map<Long, List<CropType>> gardenJacobFarmingContestTimes = new HashMap<>();
-
- @Expose
public List<VisualWord> modifiedWords = new ArrayList<>();
@Expose
diff --git a/src/main/java/at/hannibal2/skyhanni/config/commands/Commands.kt b/src/main/java/at/hannibal2/skyhanni/config/commands/Commands.kt
index dfc76a70a..f59830810 100644
--- a/src/main/java/at/hannibal2/skyhanni/config/commands/Commands.kt
+++ b/src/main/java/at/hannibal2/skyhanni/config/commands/Commands.kt
@@ -1,6 +1,7 @@
package at.hannibal2.skyhanni.config.commands
import at.hannibal2.skyhanni.SkyHanniMod
+import at.hannibal2.skyhanni.config.ConfigFileType
import at.hannibal2.skyhanni.config.ConfigGuiManager
import at.hannibal2.skyhanni.data.ChatManager
import at.hannibal2.skyhanni.data.GuiEditManager
@@ -254,7 +255,7 @@ object Commands {
registerCommand(
"shconfigsave",
"Manually saving the config"
- ) { SkyHanniMod.configManager.saveConfig("manual-command") }
+ ) { SkyHanniMod.configManager.saveConfig(ConfigFileType.FEATURES, "manual-command") }
}
private fun developersCodingHelp() {
diff --git a/src/main/java/at/hannibal2/skyhanni/data/FriendAPI.kt b/src/main/java/at/hannibal2/skyhanni/data/FriendAPI.kt
index bca06d18c..224522c06 100644
--- a/src/main/java/at/hannibal2/skyhanni/data/FriendAPI.kt
+++ b/src/main/java/at/hannibal2/skyhanni/data/FriendAPI.kt
@@ -1,6 +1,7 @@
package at.hannibal2.skyhanni.data
-import at.hannibal2.skyhanni.config.ConfigManager
+import at.hannibal2.skyhanni.SkyHanniMod
+import at.hannibal2.skyhanni.config.ConfigFileType
import at.hannibal2.skyhanni.events.HypixelJoinEvent
import at.hannibal2.skyhanni.events.LorenzChatEvent
import at.hannibal2.skyhanni.test.command.ErrorManager
@@ -11,13 +12,9 @@ import at.hannibal2.skyhanni.utils.jsonobjects.FriendsJson
import at.hannibal2.skyhanni.utils.jsonobjects.FriendsJson.PlayerFriends.Friend
import net.minecraft.util.ChatStyle
import net.minecraftforge.fml.common.eventhandler.SubscribeEvent
-import java.io.File
-import java.io.FileReader
import java.util.UUID
-class FriendAPI {
- private val file = File("config/skyhanni/friends.json")
-
+object FriendAPI {
// TODO USE SH-REPO
private val removedFriendPattern =
".*\n§r§eYou removed §r(?<name>.*)§e from your friends list!§r§9§m\n.*".toPattern()
@@ -25,42 +22,31 @@ class FriendAPI {
private val noBestFriendPattern = ".*\n§r(?<name>.*)§e is no longer a best friend!§r§9§m\n.*".toPattern()
private val bestFriendPattern = ".*\n(?<name>.*)§a is now a best friend!§r§9§m\n.*".toPattern()
- companion object {
-
- private var friendsJson: FriendsJson? = null
-
- private fun getFriends(): MutableMap<UUID, Friend> {
- val friendsJson = friendsJson ?: error("savedFriends not loaded yet!")
- return friendsJson.players.getOrPut(LorenzUtils.getRawPlayerUuid()) {
- FriendsJson.PlayerFriends().also { it.friends = mutableMapOf() }
- }.friends
- }
-
- private val tempFriends = mutableListOf<Friend>()
+ private val tempFriends = mutableListOf<Friend>()
- fun getAllFriends(): List<Friend> {
- val list = mutableListOf<Friend>()
- list.addAll(getFriends().values)
- list.addAll(tempFriends)
- return list
- }
+ private fun getFriends(): MutableMap<UUID, Friend> {
+ return SkyHanniMod.friendsData.players.getOrPut(LorenzUtils.getRawPlayerUuid()) {
+ FriendsJson.PlayerFriends().also { it.friends = mutableMapOf() }
+ }.friends
}
@SubscribeEvent
fun onHypixelJoin(event: HypixelJoinEvent) {
- if (file.isFile) {
- friendsJson = ConfigManager.gson.fromJson(FileReader(file), FriendsJson::class.java)
- }
- if (friendsJson == null) {
- file.parentFile.mkdirs()
- file.createNewFile()
- friendsJson = FriendsJson().also { it.players = mutableMapOf() }
+ if (SkyHanniMod.friendsData.players == null) {
+ SkyHanniMod.friendsData.players = mutableMapOf()
saveConfig()
}
}
+ fun getAllFriends(): List<Friend> {
+ val list = mutableListOf<Friend>()
+ list.addAll(getFriends().values)
+ list.addAll(tempFriends)
+ return list
+ }
+
fun saveConfig() {
- file.writeText(ConfigManager.gson.toJson(friendsJson))
+ SkyHanniMod.configManager.saveConfig(ConfigFileType.FRIENDS, "Save file")
}
@SubscribeEvent
diff --git a/src/main/java/at/hannibal2/skyhanni/data/SackAPI.kt b/src/main/java/at/hannibal2/skyhanni/data/SackAPI.kt
index 8417bc786..7079ae6fd 100644
--- a/src/main/java/at/hannibal2/skyhanni/data/SackAPI.kt
+++ b/src/main/java/at/hannibal2/skyhanni/data/SackAPI.kt
@@ -1,6 +1,7 @@
package at.hannibal2.skyhanni.data
import at.hannibal2.skyhanni.SkyHanniMod
+import at.hannibal2.skyhanni.config.ConfigFileType
import at.hannibal2.skyhanni.events.InventoryCloseEvent
import at.hannibal2.skyhanni.events.InventoryFullyOpenedEvent
import at.hannibal2.skyhanni.events.LorenzChatEvent
@@ -303,7 +304,7 @@ object SackAPI {
private fun saveSackData() {
ProfileStorageData.sackProfiles?.sackContents = sackData
- SkyHanniMod.configManager.saveSackData("saving-data")
+ SkyHanniMod.configManager.saveConfig(ConfigFileType.SACKS, "saving-data")
}
data class SackGemstone(
diff --git a/src/main/java/at/hannibal2/skyhanni/features/garden/GardenNextJacobContest.kt b/src/main/java/at/hannibal2/skyhanni/features/garden/GardenNextJacobContest.kt
index 9a9e9c1d3..af535615a 100644
--- a/src/main/java/at/hannibal2/skyhanni/features/garden/GardenNextJacobContest.kt
+++ b/src/main/java/at/hannibal2/skyhanni/features/garden/GardenNextJacobContest.kt
@@ -1,6 +1,7 @@
package at.hannibal2.skyhanni.features.garden
import at.hannibal2.skyhanni.SkyHanniMod
+import at.hannibal2.skyhanni.config.ConfigFileType
import at.hannibal2.skyhanni.config.ConfigUpdaterMigrator
import at.hannibal2.skyhanni.events.ConfigLoadEvent
import at.hannibal2.skyhanni.events.GuiRenderEvent
@@ -178,7 +179,7 @@ object GardenNextJacobContest {
}
private fun saveConfig() {
- val map = SkyHanniMod.feature.storage.gardenJacobFarmingContestTimes
+ val map = SkyHanniMod.jacobContestsData.contestTimes
map.clear()
val currentYear = SkyBlockTime.now().year
@@ -189,11 +190,12 @@ object GardenNextJacobContest {
map[contest.endTime] = contest.crops
}
+ SkyHanniMod.configManager.saveConfig(ConfigFileType.JACOB_CONTESTS, "Save contests")
}
@SubscribeEvent
fun onConfigLoad(event: ConfigLoadEvent) {
- val savedContests = SkyHanniMod.feature.storage.gardenJacobFarmingContestTimes
+ val savedContests = SkyHanniMod.jacobContestsData.contestTimes
val year = savedContests.firstNotNullOfOrNull {
val endTime = it.key
diff --git a/src/main/java/at/hannibal2/skyhanni/features/misc/massconfiguration/DefaultConfigFeatures.kt b/src/main/java/at/hannibal2/skyhanni/features/misc/massconfiguration/DefaultConfigFeatures.kt
index 930c67358..067a3a8bf 100644
--- a/src/main/java/at/hannibal2/skyhanni/features/misc/massconfiguration/DefaultConfigFeatures.kt
+++ b/src/main/java/at/hannibal2/skyhanni/features/misc/massconfiguration/DefaultConfigFeatures.kt
@@ -1,6 +1,7 @@
package at.hannibal2.skyhanni.features.misc.massconfiguration
import at.hannibal2.skyhanni.SkyHanniMod
+import at.hannibal2.skyhanni.config.ConfigFileType
import at.hannibal2.skyhanni.events.LorenzTickEvent
import at.hannibal2.skyhanni.utils.LorenzUtils
import io.github.moulberry.moulconfig.processor.ConfigProcessorDriver
@@ -17,12 +18,18 @@ object DefaultConfigFeatures {
Minecraft.getMinecraft().thePlayer ?: return
didNotifyOnce = true
- val knownToggles = SkyHanniMod.feature.storage.knownFeatureToggles
+ val oldToggles = SkyHanniMod.feature.storage.knownFeatureToggles
+ if (oldToggles.isNotEmpty()) {
+ SkyHanniMod.knownFeaturesData.knownFeatures = oldToggles
+ SkyHanniMod.feature.storage.knownFeatureToggles = emptyMap()
+ }
+
+ val knownToggles = SkyHanniMod.knownFeaturesData.knownFeatures
val updated = SkyHanniMod.version !in knownToggles
val processor = FeatureToggleProcessor()
ConfigProcessorDriver.processConfig(SkyHanniMod.feature.javaClass, SkyHanniMod.feature, processor)
knownToggles[SkyHanniMod.version] = processor.allOptions.map { it.path }
- SkyHanniMod.configManager.saveConfig("Updated known feature flags")
+ SkyHanniMod.configManager.saveConfig(ConfigFileType.KNOWN_FEATURES, "Updated known feature flags")
if (!SkyHanniMod.feature.storage.hasPlayedBefore) {
SkyHanniMod.feature.storage.hasPlayedBefore = true
LorenzUtils.clickableChat(
@@ -46,7 +53,7 @@ object DefaultConfigFeatures {
val processor = FeatureToggleProcessor()
ConfigProcessorDriver.processConfig(SkyHanniMod.feature.javaClass, SkyHanniMod.feature, processor)
var optionList = processor.orderedOptions
- val knownToggles = SkyHanniMod.feature.storage.knownFeatureToggles
+ val knownToggles = SkyHanniMod.knownFeaturesData.knownFeatures
val togglesInNewVersion = knownToggles[new]
if (new != "null" && togglesInNewVersion == null) {
LorenzUtils.chat("§e[SkyHanni] Unknown version $new")
@@ -95,7 +102,7 @@ object DefaultConfigFeatures {
if (strings.size <= 2)
return CommandBase.getListOfStringsMatchingLastWord(
strings,
- SkyHanniMod.feature.storage.knownFeatureToggles.keys + listOf("null")
+ SkyHanniMod.knownFeaturesData.knownFeatures.keys + listOf("null")
)
return listOf()
}
diff --git a/src/main/java/at/hannibal2/skyhanni/test/SkyHanniDebugsAndTests.kt b/src/main/java/at/hannibal2/skyhanni/test/SkyHanniDebugsAndTests.kt
index 763b4602e..d88f9b67a 100644
--- a/src/main/java/at/hannibal2/skyhanni/test/SkyHanniDebugsAndTests.kt
+++ b/src/main/java/at/hannibal2/skyhanni/test/SkyHanniDebugsAndTests.kt
@@ -1,6 +1,7 @@
package at.hannibal2.skyhanni.test
import at.hannibal2.skyhanni.SkyHanniMod
+import at.hannibal2.skyhanni.config.ConfigFileType
import at.hannibal2.skyhanni.config.ConfigGuiManager
import at.hannibal2.skyhanni.config.ConfigManager
import at.hannibal2.skyhanni.config.ConfigUpdaterMigrator
@@ -147,8 +148,8 @@ class SkyHanniDebugsAndTests {
// TODO make it so that it does not reset the config
// saving old config state
- SkyHanniMod.configManager.saveConfig("reload config manager")
- SkyHanniMod.configManager.saveSackData("reload config manager")
+ SkyHanniMod.configManager.saveConfig(ConfigFileType.FEATURES, "reload config manager")
+ SkyHanniMod.configManager.saveConfig(ConfigFileType.SACKS,"reload config manager")
Thread {
Thread.sleep(500)
SkyHanniMod.configManager.disableSaving()
diff --git a/src/main/java/at/hannibal2/skyhanni/utils/jsonobjects/JacobContestsJson.java b/src/main/java/at/hannibal2/skyhanni/utils/jsonobjects/JacobContestsJson.java
new file mode 100644
index 000000000..87d1e9a22
--- /dev/null
+++ b/src/main/java/at/hannibal2/skyhanni/utils/jsonobjects/JacobContestsJson.java
@@ -0,0 +1,13 @@
+package at.hannibal2.skyhanni.utils.jsonobjects;
+
+import at.hannibal2.skyhanni.features.garden.CropType;
+import com.google.gson.annotations.Expose;
+
+import java.util.HashMap;
+import java.util.List;
+import java.util.Map;
+
+public class JacobContestsJson {
+ @Expose
+ public Map<Long, List<CropType>> contestTimes = new HashMap<>();
+}
diff --git a/src/main/java/at/hannibal2/skyhanni/utils/jsonobjects/KnownFeaturesJson.java b/src/main/java/at/hannibal2/skyhanni/utils/jsonobjects/KnownFeaturesJson.java
new file mode 100644
index 000000000..bd5048cfb
--- /dev/null
+++ b/src/main/java/at/hannibal2/skyhanni/utils/jsonobjects/KnownFeaturesJson.java
@@ -0,0 +1,12 @@
+package at.hannibal2.skyhanni.utils.jsonobjects;
+
+import com.google.gson.annotations.Expose;
+
+import java.util.HashMap;
+import java.util.List;
+import java.util.Map;
+
+public class KnownFeaturesJson {
+ @Expose
+ public Map<String, List<String>> knownFeatures = new HashMap<>();
+}