aboutsummaryrefslogtreecommitdiff
path: root/src/main/java/at/hannibal2/skyhanni/config
diff options
context:
space:
mode:
authorhannibal2 <24389977+hannibal00212@users.noreply.github.com>2023-04-22 21:47:16 +0200
committerhannibal2 <24389977+hannibal00212@users.noreply.github.com>2023-04-22 21:47:16 +0200
commit08a3ec8ec388835373b5363cd1219601bfdcc1ad (patch)
tree91d47d9fc8643769500ab159c2c258ea072ccfc9 /src/main/java/at/hannibal2/skyhanni/config
parent707007fa1a00adebec09af4c1efbf8dc55bb852e (diff)
downloadSkyHanni-08a3ec8ec388835373b5363cd1219601bfdcc1ad.tar.gz
SkyHanni-08a3ec8ec388835373b5363cd1219601bfdcc1ad.tar.bz2
SkyHanni-08a3ec8ec388835373b5363cd1219601bfdcc1ad.zip
Hopefully fixed config reset bug and added more logging
Diffstat (limited to 'src/main/java/at/hannibal2/skyhanni/config')
-rw-r--r--src/main/java/at/hannibal2/skyhanni/config/ConfigManager.kt36
-rw-r--r--src/main/java/at/hannibal2/skyhanni/config/commands/Commands.kt2
2 files changed, 22 insertions, 16 deletions
diff --git a/src/main/java/at/hannibal2/skyhanni/config/ConfigManager.kt b/src/main/java/at/hannibal2/skyhanni/config/ConfigManager.kt
index 9fa562986..a9c755cf9 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.events.ConfigLoadEvent
import at.hannibal2.skyhanni.features.garden.CropType
import at.hannibal2.skyhanni.features.misc.update.UpdateManager
+import at.hannibal2.skyhanni.utils.LorenzLogger
import com.google.gson.GsonBuilder
import io.github.moulberry.moulconfig.observer.PropertyTypeAdapterFactory
import io.github.moulberry.moulconfig.processor.BuiltinMoulConfigGuis
@@ -21,7 +22,7 @@ class ConfigManager {
.create()
}
- val logger = SkyHanniMod.getLogger("ConfigManager")
+ val logger = LorenzLogger("config_manager")
var configDirectory = File("config/skyhanni")
private var configFile: File? = null
@@ -31,11 +32,12 @@ class ConfigManager {
configDirectory.mkdir()
configFile = File(configDirectory, "config.json")
- fixedRateTimer(name = "config-auto-save", period = 60_000L) {
- saveConfig()
+
+ fixedRateTimer(name = "config-auto-save", period = 60_000L, initialDelay = 60_000L) {
+ saveConfig("autp-save-60s")
}
- logger.info("Trying to load config from $configFile")
+ logger.log("Trying to load config from $configFile")
if (configFile!!.exists()) {
try {
@@ -49,31 +51,31 @@ class ConfigManager {
}
+ logger.log("load-config-now")
SkyHanniMod.feature = gson.fromJson(
builder.toString(),
Features::class.java
)
- logger.info("Loaded config from file")
+ logger.log("Loaded config from file")
} catch (e: Exception) {
println("config error")
e.printStackTrace()
val backupFile = configFile!!.resolveSibling("config-${System.currentTimeMillis()}-backup.json")
- logger.error(
- "Exception while reading $configFile. Will load blank config and save backup to $backupFile",
- e
- )
+ logger.log("Exception while reading $configFile. Will load blank config and save backup to $backupFile")
+ e.printStackTrace()
try {
configFile!!.copyTo(backupFile)
} catch (e: Exception) {
- logger.error("Could not create backup for config file", e)
+ logger.log("Could not create backup for config file")
+ e.printStackTrace()
}
}
}
if (SkyHanniMod.feature == null) {
- logger.info("Creating blank config and saving to file")
+ logger.log("Creating blank config and saving to file")
SkyHanniMod.feature = Features()
- saveConfig()
+ saveConfig("blank config")
}
ConfigLoadEvent().postAndCatch()
@@ -101,17 +103,21 @@ class ConfigManager {
return result
}
- fun saveConfig() {
+ fun saveConfig(reason: String) {
+ val text = "saveConfig: $reason"
+ println(text)
+ logger.log(text)
val file = configFile ?: throw Error("Can not save config, configFile is null!")
try {
- logger.info("Saving config file")
+ logger.log("Saving config file")
file.parentFile.mkdirs()
file.createNewFile()
BufferedWriter(OutputStreamWriter(FileOutputStream(file), StandardCharsets.UTF_8)).use { writer ->
writer.write(gson.toJson(SkyHanniMod.feature))
}
} catch (e: IOException) {
- logger.error("Could not save config file to $file", e)
+ logger.log("Could not save config file to $file")
+ e.printStackTrace()
}
}
} \ No newline at end of file
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 5a0c8379c..4c3bdc573 100644
--- a/src/main/java/at/hannibal2/skyhanni/config/commands/Commands.kt
+++ b/src/main/java/at/hannibal2/skyhanni/config/commands/Commands.kt
@@ -42,7 +42,7 @@ object Commands {
registerCommand("copylocation") { LorenzTest.copyLocation() }
registerCommand("copyentities") { CopyNearbyEntitiesCommand.command(it) }
registerCommand("copyitem") { CopyItemCommand.command(it) }
- registerCommand("shconfigsave") { SkyHanniMod.configManager.saveConfig() }
+ registerCommand("shconfigsave") { SkyHanniMod.configManager.saveConfig("manual-command") }
registerCommand("shmarkplayer") { MarkedPlayerManager.command(it) }
registerCommand("shtestpacket") { PacketTest.toggle() }
registerCommand("shreloadlisteners") { LorenzTest.reloadListeners() }