From 551dba9811641e33dda2b43d2bd7092421f5df9e Mon Sep 17 00:00:00 2001 From: DragonEggBedrockBreaking Date: Sun, 31 Jul 2022 13:08:37 +0100 Subject: [PATCH] Rewrite gamerule toggle system to use Gson reading from `vanilla_disable.mixins.json` file, to fix crash in prod --- .../util/gamerules/GameruleCategories.java | 34 +++++++++++++++---- 1 file changed, 27 insertions(+), 7 deletions(-) diff --git a/src/main/java/uk/debb/vanilla_disable/util/gamerules/GameruleCategories.java b/src/main/java/uk/debb/vanilla_disable/util/gamerules/GameruleCategories.java index eb5f9524..dc8bf58a 100644 --- a/src/main/java/uk/debb/vanilla_disable/util/gamerules/GameruleCategories.java +++ b/src/main/java/uk/debb/vanilla_disable/util/gamerules/GameruleCategories.java @@ -1,7 +1,6 @@ package uk.debb.vanilla_disable.util.gamerules; -import com.google.common.collect.ImmutableSet; -import com.google.common.reflect.ClassPath; +import com.google.gson.stream.JsonReader; import net.fabricmc.fabric.api.gamerule.v1.CustomGameRuleCategory; import net.minecraft.ChatFormatting; import net.minecraft.network.chat.Component; @@ -9,6 +8,9 @@ import uk.debb.vanilla_disable.mixin_plugins.CaffeineConfigMixinConfigPlugin; import java.io.IOException; +import java.io.InputStream; +import java.io.InputStreamReader; +import java.io.Reader; public enum GameruleCategories { VD_DAMAGE, @@ -57,12 +59,30 @@ private CustomGameRuleCategory createCustomGameRuleCategory(String name) { } public void toggle() throws IOException { - ClassPath cp = ClassPath.from(Thread.currentThread().getContextClassLoader()); String subpackage = this.name().substring(3).toLowerCase(); - ImmutableSet set = cp.getTopLevelClasses("uk.debb.vanilla_disable.mixin." + subpackage); - enabled = CaffeineConfigMixinConfigPlugin.caffeineConfig.getEffectiveOptionForMixin( - set.iterator().next().toString().split("mixin\\.")[1] - ).isEnabled(); + InputStream inputStream = GameruleCategories.class.getResourceAsStream("/vanilla_disable.mixins.json"); + if (inputStream != null) { + Reader reader = new InputStreamReader(inputStream); + JsonReader jsonReader = new JsonReader(reader); + jsonReader.beginObject(); + while (jsonReader.hasNext()) { + String name = jsonReader.nextName(); + if (name.equals("mixins")) { + jsonReader.beginArray(); + while (jsonReader.hasNext()) { + String mixin = jsonReader.nextString(); + if (mixin.startsWith(subpackage + ".")) { + enabled = CaffeineConfigMixinConfigPlugin.caffeineConfig.getEffectiveOptionForMixin(mixin).isEnabled(); + break; + } + } + break; + } else { + jsonReader.skipValue(); + } + } + reader.close(); + } } public CustomGameRuleCategory get() {