From 2eae56fabfd8c43ad2b5decc96a840e741796082 Mon Sep 17 00:00:00 2001 From: nea Date: Sat, 25 Mar 2023 03:02:33 +0100 Subject: The non controversial config changes --- src/main/java/at/hannibal2/skyhanni/SkyHanniMod.java | 1 + 1 file changed, 1 insertion(+) (limited to 'src/main/java/at/hannibal2/skyhanni/SkyHanniMod.java') diff --git a/src/main/java/at/hannibal2/skyhanni/SkyHanniMod.java b/src/main/java/at/hannibal2/skyhanni/SkyHanniMod.java index f3909ebce..3b2100afc 100644 --- a/src/main/java/at/hannibal2/skyhanni/SkyHanniMod.java +++ b/src/main/java/at/hannibal2/skyhanni/SkyHanniMod.java @@ -52,6 +52,7 @@ import at.hannibal2.skyhanni.test.LorenzTest; import at.hannibal2.skyhanni.test.PacketTest; import at.hannibal2.skyhanni.utils.MinecraftConsoleFilter; import at.hannibal2.skyhanni.utils.TabListData; +import io.github.moulberry.moulconfig.processor.MoulConfigProcessor; import kotlin.coroutines.EmptyCoroutineContext; import kotlinx.coroutines.*; import net.minecraft.client.Minecraft; -- cgit From 4b3f01bdfa771cb5b446888485f007d9178b6a7f Mon Sep 17 00:00:00 2001 From: hannibal2 <24389977+hannibal00212@users.noreply.github.com> Date: Sat, 25 Mar 2023 11:53:43 +0100 Subject: typo fix --- src/main/java/at/hannibal2/skyhanni/SkyHanniMod.java | 1 - src/main/java/at/hannibal2/skyhanni/config/features/GUI.java | 4 +--- src/main/java/at/hannibal2/skyhanni/config/features/Garden.java | 2 +- 3 files changed, 2 insertions(+), 5 deletions(-) (limited to 'src/main/java/at/hannibal2/skyhanni/SkyHanniMod.java') diff --git a/src/main/java/at/hannibal2/skyhanni/SkyHanniMod.java b/src/main/java/at/hannibal2/skyhanni/SkyHanniMod.java index 3b2100afc..f3909ebce 100644 --- a/src/main/java/at/hannibal2/skyhanni/SkyHanniMod.java +++ b/src/main/java/at/hannibal2/skyhanni/SkyHanniMod.java @@ -52,7 +52,6 @@ import at.hannibal2.skyhanni.test.LorenzTest; import at.hannibal2.skyhanni.test.PacketTest; import at.hannibal2.skyhanni.utils.MinecraftConsoleFilter; import at.hannibal2.skyhanni.utils.TabListData; -import io.github.moulberry.moulconfig.processor.MoulConfigProcessor; import kotlin.coroutines.EmptyCoroutineContext; import kotlinx.coroutines.*; import net.minecraft.client.Minecraft; diff --git a/src/main/java/at/hannibal2/skyhanni/config/features/GUI.java b/src/main/java/at/hannibal2/skyhanni/config/features/GUI.java index d6347a830..eba1feea8 100644 --- a/src/main/java/at/hannibal2/skyhanni/config/features/GUI.java +++ b/src/main/java/at/hannibal2/skyhanni/config/features/GUI.java @@ -16,9 +16,7 @@ public class GUI { @ConfigEditorButton( buttonText = "Edit" ) - public Runnable positions = () -> { - GuiEditManager.openGuiEditor(); - }; + public Runnable positions = GuiEditManager::openGuiEditor; @Expose @ConfigOption( diff --git a/src/main/java/at/hannibal2/skyhanni/config/features/Garden.java b/src/main/java/at/hannibal2/skyhanni/config/features/Garden.java index d0e322511..26734ef00 100644 --- a/src/main/java/at/hannibal2/skyhanni/config/features/Garden.java +++ b/src/main/java/at/hannibal2/skyhanni/config/features/Garden.java @@ -512,7 +512,7 @@ public class Garden { @Expose @ConfigOption( name = "Always On", - desc = "Show the money/hour Display always while on the ") + desc = "Show the money/hour Display always while on the garden.") @ConfigEditorBoolean @ConfigAccordionId(id = 13) public boolean moneyPerHourAlwaysOn = false; -- cgit From ed2dfa0bfd7a6d69a2eb7349009625991e363fee Mon Sep 17 00:00:00 2001 From: nea Date: Wed, 29 Mar 2023 17:10:01 +0200 Subject: config backups and better property adapter --- build.gradle.kts | 4 +-- .../java/at/hannibal2/skyhanni/SkyHanniMod.java | 4 ++- .../at/hannibal2/skyhanni/config/ConfigManager.kt | 37 ++++++++++++++++++---- 3 files changed, 35 insertions(+), 10 deletions(-) (limited to 'src/main/java/at/hannibal2/skyhanni/SkyHanniMod.java') diff --git a/build.gradle.kts b/build.gradle.kts index 8d60a3023..51ee17fec 100644 --- a/build.gradle.kts +++ b/build.gradle.kts @@ -71,8 +71,8 @@ dependencies { implementation("com.github.hannibal002:notenoughupdates:4957f0b:all") devenvMod("com.github.hannibal002:notenoughupdates:4957f0b:all") - shadowModImpl("com.github.notenoughupdates:moulconfig:3f469a8") - devenvMod("com.github.notenoughupdates:moulconfig:3f469a8:test") + shadowModImpl("com.github.notenoughupdates:moulconfig:df01eda") + devenvMod("com.github.notenoughupdates:moulconfig:df01eda:test") } // Minecraft configuration: diff --git a/src/main/java/at/hannibal2/skyhanni/SkyHanniMod.java b/src/main/java/at/hannibal2/skyhanni/SkyHanniMod.java index f3909ebce..782ae6d4a 100644 --- a/src/main/java/at/hannibal2/skyhanni/SkyHanniMod.java +++ b/src/main/java/at/hannibal2/skyhanni/SkyHanniMod.java @@ -84,6 +84,9 @@ public class SkyHanniMod { public static RepoManager repo; public static ConfigManager configManager; private static Logger logger; + public static org.slf4j.Logger getLogger(String name) { + return org.slf4j.LoggerFactory.getLogger("SkyHanni." + name); + } public static List modules = new ArrayList<>(); public static Job globalJob = JobKt.Job(null); @@ -241,7 +244,6 @@ public class SkyHanniMod { configManager = new ConfigManager(); configManager.firstLoad(); - new FirstConfigLoadedEvent().postAndCatch(); MinecraftConsoleFilter.Companion.initLogging(); diff --git a/src/main/java/at/hannibal2/skyhanni/config/ConfigManager.kt b/src/main/java/at/hannibal2/skyhanni/config/ConfigManager.kt index e3b040391..75e31ab2a 100644 --- a/src/main/java/at/hannibal2/skyhanni/config/ConfigManager.kt +++ b/src/main/java/at/hannibal2/skyhanni/config/ConfigManager.kt @@ -3,6 +3,7 @@ package at.hannibal2.skyhanni.config import at.hannibal2.skyhanni.SkyHanniMod import at.hannibal2.skyhanni.events.ConfigLoadEvent import com.google.gson.GsonBuilder +import io.github.moulberry.moulconfig.observer.PropertyTypeAdapterFactory import io.github.moulberry.moulconfig.processor.BuiltinMoulConfigGuis import io.github.moulberry.moulconfig.processor.ConfigProcessorDriver import io.github.moulberry.moulconfig.processor.MoulConfigProcessor @@ -11,9 +12,14 @@ import java.nio.charset.StandardCharsets class ConfigManager { companion object { - val gson = GsonBuilder().setPrettyPrinting().excludeFieldsWithoutExposeAnnotation().create() + val gson = GsonBuilder().setPrettyPrinting() + .excludeFieldsWithoutExposeAnnotation() + .registerTypeAdapterFactory(PropertyTypeAdapterFactory()) + .create() } + val logger = SkyHanniMod.getLogger("ConfigManager") + var configDirectory = File("config/skyhanni") private var configFile: File? = null lateinit var processor: MoulConfigProcessor @@ -26,23 +32,39 @@ class ConfigManager { configFile = File(configDirectory, "config.json") + logger.info("Trying to load config from $configFile") + if (configFile!!.exists()) { try { BufferedReader(InputStreamReader(FileInputStream(configFile!!), StandardCharsets.UTF_8)).use { reader -> - SkyHanniMod.feature = gson.fromJson(reader, - Features::class.java) + SkyHanniMod.feature = gson.fromJson( + reader, + Features::class.java + ) } - ConfigLoadEvent().postAndCatch() + logger.info("Loaded config from file") } catch (e: Exception) { - 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 + ) + try { + configFile!!.copyTo(backupFile) + } catch (e: Exception) { + logger.error("Could not create backup for config file", e) + } } } if (SkyHanniMod.feature == null) { + logger.info("Creating blank config and saving to file") SkyHanniMod.feature = Features() saveConfig() } + ConfigLoadEvent().postAndCatch() + val features = SkyHanniMod.feature processor = MoulConfigProcessor(SkyHanniMod.feature) BuiltinMoulConfigGuis.addProcessors(processor) @@ -51,17 +73,18 @@ class ConfigManager { features, processor ) - SkyHanniMod.DEPENDENCIES } fun saveConfig() { try { + logger.info("Saving config file") + configFile!!.parentFile.mkdirs() configFile!!.createNewFile() BufferedWriter(OutputStreamWriter(FileOutputStream(configFile!!), StandardCharsets.UTF_8)).use { writer -> writer.write(gson.toJson(SkyHanniMod.feature)) } } catch (e: IOException) { - e.printStackTrace() + logger.error("Could not save config file to $configFile", e) } } } \ No newline at end of file -- cgit