From 35eb4baa20f77cd57e08fa70dc76c8d7d87a3b35 Mon Sep 17 00:00:00 2001 From: xpple Date: Fri, 14 Jun 2024 21:55:49 +0200 Subject: [PATCH] Use deep copied value when resetting config --- .../java/dev/xpple/betterconfig/impl/BetterConfigInternals.java | 2 +- src/main/java/dev/xpple/betterconfig/impl/ModConfigImpl.java | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/src/main/java/dev/xpple/betterconfig/impl/BetterConfigInternals.java b/src/main/java/dev/xpple/betterconfig/impl/BetterConfigInternals.java index a50c793..7b1773b 100644 --- a/src/main/java/dev/xpple/betterconfig/impl/BetterConfigInternals.java +++ b/src/main/java/dev/xpple/betterconfig/impl/BetterConfigInternals.java @@ -47,7 +47,7 @@ public static void init(ModConfigImpl modConfig) { String fieldName = field.getName(); modConfig.getConfigs().put(fieldName, field); try { - modConfig.getDefaults().put(fieldName, field.get(null)); + modConfig.getDefaults().put(fieldName, modConfig.getGson().fromJson(modConfig.getGson().toJsonTree(field.get(null)), field.getGenericType())); } catch (ReflectiveOperationException e) { throw new AssertionError(e); } diff --git a/src/main/java/dev/xpple/betterconfig/impl/ModConfigImpl.java b/src/main/java/dev/xpple/betterconfig/impl/ModConfigImpl.java index 1f7f395..24435b8 100644 --- a/src/main/java/dev/xpple/betterconfig/impl/ModConfigImpl.java +++ b/src/main/java/dev/xpple/betterconfig/impl/ModConfigImpl.java @@ -121,7 +121,7 @@ public void reset(String config) { throw new IllegalArgumentException(); } try { - field.set(null, this.defaults.get(config)); + field.set(null, this.gson.fromJson(this.gson.toJsonTree(this.defaults.get(config)), field.getGenericType())); } catch (ReflectiveOperationException e) { throw new AssertionError(e); }