aboutsummaryrefslogtreecommitdiff
path: root/src/main/kotlin/moe/nea/notenoughupdates/util
diff options
context:
space:
mode:
authornea <romangraef@gmail.com>2022-08-04 04:26:51 +0200
committernea <romangraef@gmail.com>2022-08-04 04:26:51 +0200
commit05a4a5b3817ea3e70662d3834fd56a1b249fa70e (patch)
treea02169948679be5a748a3255e99738133bf8f83c /src/main/kotlin/moe/nea/notenoughupdates/util
parentc83890afc8304fc0a1b1d0ea8da791c6d9b90439 (diff)
downloadFirmament-05a4a5b3817ea3e70662d3834fd56a1b249fa70e.tar.gz
Firmament-05a4a5b3817ea3e70662d3834fd56a1b249fa70e.tar.bz2
Firmament-05a4a5b3817ea3e70662d3834fd56a1b249fa70e.zip
screen padding
Diffstat (limited to 'src/main/kotlin/moe/nea/notenoughupdates/util')
-rw-r--r--src/main/kotlin/moe/nea/notenoughupdates/util/ConfigHolder.kt34
1 files changed, 25 insertions, 9 deletions
diff --git a/src/main/kotlin/moe/nea/notenoughupdates/util/ConfigHolder.kt b/src/main/kotlin/moe/nea/notenoughupdates/util/ConfigHolder.kt
index 003de6c..07a9b4c 100644
--- a/src/main/kotlin/moe/nea/notenoughupdates/util/ConfigHolder.kt
+++ b/src/main/kotlin/moe/nea/notenoughupdates/util/ConfigHolder.kt
@@ -4,6 +4,7 @@ import kotlinx.serialization.KSerializer
import kotlinx.serialization.SerializationException
import moe.nea.notenoughupdates.NotEnoughUpdates
import moe.nea.notenoughupdates.events.NEUScreenEvents
+import net.fabricmc.fabric.api.client.event.lifecycle.v1.ClientLifecycleEvents
import net.minecraft.client.Minecraft
import net.minecraft.commands.CommandSource
import net.minecraft.network.chat.Component
@@ -15,9 +16,11 @@ import kotlin.io.path.readText
import kotlin.io.path.writeText
import kotlin.reflect.KClass
-abstract class ConfigHolder<T>(val serializer: KSerializer<T>,
- val name: String,
- val default: () -> T) {
+abstract class ConfigHolder<T>(
+ val serializer: KSerializer<T>,
+ val name: String,
+ val default: () -> T
+) {
var config: T
private set
@@ -33,15 +36,21 @@ abstract class ConfigHolder<T>(val serializer: KSerializer<T>,
if (file.exists())
try {
return NotEnoughUpdates.json.decodeFromString(
- serializer,
- file.readText()
+ serializer,
+ file.readText()
)
} catch (e: IOException) {
badLoads.add(name)
- NotEnoughUpdates.logger.error("IO exception during loading of config file $name. This will reset this config.", e)
+ NotEnoughUpdates.logger.error(
+ "IO exception during loading of config file $name. This will reset this config.",
+ e
+ )
} catch (e: SerializationException) {
badLoads.add(name)
- NotEnoughUpdates.logger.error("Serialization exception during loading of config file $name. This will reset this config.", e)
+ NotEnoughUpdates.logger.error(
+ "Serialization exception during loading of config file $name. This will reset this config.",
+ e
+ )
}
return default()
}
@@ -95,8 +104,12 @@ abstract class ConfigHolder<T>(val serializer: KSerializer<T>,
private fun warnForResetConfigs(player: CommandSource) {
if (badLoads.isNotEmpty()) {
- player.sendSystemMessage(Component.literal("The following configs have been reset: ${badLoads.joinToString(", ")}. " +
- "This can be intentional, but probably isn't."))
+ player.sendSystemMessage(
+ Component.literal(
+ "The following configs have been reset: ${badLoads.joinToString(", ")}. " +
+ "This can be intentional, but probably isn't."
+ )
+ )
badLoads.clear()
}
}
@@ -110,6 +123,9 @@ abstract class ConfigHolder<T>(val serializer: KSerializer<T>,
}
false
})
+ ClientLifecycleEvents.CLIENT_STOPPING.register(ClientLifecycleEvents.ClientStopping {
+ performSaves()
+ })
}