aboutsummaryrefslogtreecommitdiff
path: root/src/main/java/at/hannibal2/skyhanni
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
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')
-rw-r--r--src/main/java/at/hannibal2/skyhanni/SkyHanniMod.java2
-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
-rw-r--r--src/main/java/at/hannibal2/skyhanni/features/misc/update/UpdateManager.kt19
4 files changed, 33 insertions, 26 deletions
diff --git a/src/main/java/at/hannibal2/skyhanni/SkyHanniMod.java b/src/main/java/at/hannibal2/skyhanni/SkyHanniMod.java
index 8427a540b..50cb1fa0f 100644
--- a/src/main/java/at/hannibal2/skyhanni/SkyHanniMod.java
+++ b/src/main/java/at/hannibal2/skyhanni/SkyHanniMod.java
@@ -290,7 +290,7 @@ public class SkyHanniMod {
MinecraftConsoleFilter.Companion.initLogging();
- Runtime.getRuntime().addShutdownHook(new Thread(configManager::saveConfig));
+ Runtime.getRuntime().addShutdownHook(new Thread(() -> configManager.saveConfig("shutdown-hook")));
repo = new RepoManager(configManager.getConfigDirectory());
repo.loadRepoInformation();
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() }
diff --git a/src/main/java/at/hannibal2/skyhanni/features/misc/update/UpdateManager.kt b/src/main/java/at/hannibal2/skyhanni/features/misc/update/UpdateManager.kt
index 2e3d848b2..10a93753a 100644
--- a/src/main/java/at/hannibal2/skyhanni/features/misc/update/UpdateManager.kt
+++ b/src/main/java/at/hannibal2/skyhanni/features/misc/update/UpdateManager.kt
@@ -3,6 +3,7 @@ package at.hannibal2.skyhanni.features.misc.update
import at.hannibal2.skyhanni.SkyHanniMod
import at.hannibal2.skyhanni.config.features.About
import at.hannibal2.skyhanni.events.ConfigLoadEvent
+import at.hannibal2.skyhanni.utils.LorenzLogger
import at.hannibal2.skyhanni.utils.LorenzUtils
import io.github.moulberry.moulconfig.processor.MoulConfigProcessor
import io.github.moulberry.notenoughupdates.util.MinecraftExecutor
@@ -15,7 +16,7 @@ import java.util.concurrent.CompletableFuture
object UpdateManager {
- private val logger = SkyHanniMod.getLogger("UpdateManager")
+ private val logger = LorenzLogger("update_manager")
private var _activePromise: CompletableFuture<*>? = null
private var activePromise: CompletableFuture<*>?
get() = _activePromise
@@ -67,24 +68,24 @@ object UpdateManager {
updateState = UpdateState.NONE
_activePromise = null
potentialUpdate = null
- logger.info("Reset update state")
+ logger.log("Reset update state")
}
fun checkUpdate() {
if (updateState != UpdateState.NONE) {
- logger.error("Trying to perform update check while another update is already in progress")
+ logger.log("Trying to perform update check while another update is already in progress")
return
}
- logger.info("Starting update check")
+ logger.log("Starting update check")
var updateStream = config.updateStream.get()
if (updateStream == About.UpdateStream.RELEASES && isBetaRelease()) {
updateStream = About.UpdateStream.BETA
}
activePromise = context.checkUpdate(updateStream.stream)
.thenAcceptAsync({
- logger.info("Update check completed")
+ logger.log("Update check completed")
if (updateState != UpdateState.NONE) {
- logger.warn("This appears to be the second update check. Ignoring this one")
+ logger.log("This appears to be the second update check. Ignoring this one")
return@thenAcceptAsync
}
potentialUpdate = it
@@ -97,14 +98,14 @@ object UpdateManager {
fun queueUpdate() {
if (updateState != UpdateState.AVAILABLE) {
- logger.error("Trying to enqueue an update while another one is already downloaded or none is present")
+ logger.log("Trying to enqueue an update while another one is already downloaded or none is present")
}
updateState = UpdateState.QUEUED
activePromise = CompletableFuture.supplyAsync {
- logger.info("Update download started")
+ logger.log("Update download started")
potentialUpdate!!.prepareUpdate()
}.thenAcceptAsync({
- logger.info("Update download completed, setting exit hook")
+ logger.log("Update download completed, setting exit hook")
updateState = UpdateState.DOWNLOADED
potentialUpdate!!.executeUpdate()
}, MinecraftExecutor.OnThread)