[fix] Don't save config if mod isn't loaded

This commit is contained in:
Xiaro 2020-12-21 20:33:54 -05:00
parent fdbaf57066
commit 43ad247470
No known key found for this signature in database
GPG Key ID: 996D265D6E155377
2 changed files with 12 additions and 10 deletions

View File

@ -54,6 +54,7 @@ public class KamiMod {
public static KamiMod INSTANCE;
public static Thread MAIN_THREAD;
private static boolean ready = false;
private KamiGUI guiManager;
private Setting<JsonObject> guiStateSetting;
@ -103,6 +104,7 @@ public class KamiMod {
// Need to reload the font after the settings were loaded
KamiFontRenderer.INSTANCE.reloadFonts();
ready = true;
LOG.info(NAME + " Mod initialized!");
}
@ -119,4 +121,8 @@ public class KamiMod {
return guiStateSetting;
}
public static boolean isReady() {
return ready;
}
}

View File

@ -1,14 +1,14 @@
package me.zeroeightsix.kami.mixin.client;
import me.zeroeightsix.kami.KamiMod;
import me.zeroeightsix.kami.event.KamiEventBus;
import me.zeroeightsix.kami.event.events.GuiScreenEvent;
import me.zeroeightsix.kami.module.modules.combat.CrystalAura;
import me.zeroeightsix.kami.module.modules.misc.DiscordRPC;
import me.zeroeightsix.kami.util.ConfigUtils;
import net.minecraft.client.Minecraft;
import net.minecraft.client.audio.SoundHandler;
import net.minecraft.client.entity.EntityPlayerSP;
import net.minecraft.client.gui.*;
import net.minecraft.client.gui.GuiScreen;
import net.minecraft.client.multiplayer.PlayerControllerMP;
import net.minecraft.client.multiplayer.WorldClient;
import net.minecraft.client.renderer.EntityRenderer;
@ -34,9 +34,6 @@ public class MixinMinecraft {
@Shadow public EntityPlayerSP player;
@Shadow public GuiScreen currentScreen;
@Shadow public GameSettings gameSettings;
@Shadow public GuiIngame ingameGUI;
@Shadow public boolean skipRenderWorld;
@Shadow public SoundHandler soundHandler;
@Shadow public RayTraceResult objectMouseOver;
@Shadow public PlayerControllerMP playerController;
@Shadow public EntityRenderer entityRenderer;
@ -65,23 +62,22 @@ public class MixinMinecraft {
return screenEvent1.getScreen();
}
@Inject(method = "run", at = @At(value = "INVOKE",
target = "Lnet/minecraft/client/Minecraft;displayCrashReport(Lnet/minecraft/crash/CrashReport;)V", shift = At.Shift.BEFORE))
public void displayCrashReport(CallbackInfo _info) {
@Inject(method = "run", at = @At(value = "INVOKE", target = "Lnet/minecraft/client/Minecraft;displayCrashReport(Lnet/minecraft/crash/CrashReport;)V", shift = At.Shift.BEFORE))
public void displayCrashReport(CallbackInfo info) {
save();
DiscordRPC.INSTANCE.end();
}
@Inject(method = "shutdown", at = @At("HEAD"))
public void shutdown(CallbackInfo info) {
save();
DiscordRPC.INSTANCE.end();
}
private void save() {
if (!KamiMod.isReady()) return;
System.out.println("Shutting down: saving KAMI configuration");
ConfigUtils.INSTANCE.saveAll();
System.out.println("Configuration saved.");
DiscordRPC.INSTANCE.end();
}
}