From ae12206958a0ba848594beeb2f804720d1a89d4f Mon Sep 17 00:00:00 2001 From: HackOS <63157139+HackedOS@users.noreply.github.com> Date: Thu, 12 May 2022 22:11:18 +0530 Subject: Add Auto-Toggle and Send Scoreboard/Tab Menu Data (#58) * Add Auto-Toggle * Send Scoreboard data to the Server * Fix Privacy settings and respect collect scoreboard * Move code to EventHandlers.java and collect Tab Manu data * Remove unused import * Refactor for Readability * Bug Fix * Fix bug * Add LocalConfig and Respect AutoStart * Add chat msg when leaving skyblock * Add ChatRegex * Fix bug where purse doesnt update with pigyy bank * Improve Performance * Fix chatregex always being null --- src/main/java/de/torui/coflsky/CoflSky.java | 37 ++++++++++++++++++++++++++--- 1 file changed, 34 insertions(+), 3 deletions(-) (limited to 'src/main/java/de/torui/coflsky/CoflSky.java') diff --git a/src/main/java/de/torui/coflsky/CoflSky.java b/src/main/java/de/torui/coflsky/CoflSky.java index 6e7fde7..7ecccf0 100644 --- a/src/main/java/de/torui/coflsky/CoflSky.java +++ b/src/main/java/de/torui/coflsky/CoflSky.java @@ -1,12 +1,18 @@ package de.torui.coflsky; +import java.io.File; +import java.io.IOException; import java.net.URISyntaxException; +import java.nio.file.Files; +import java.nio.file.Paths; +import com.google.gson.Gson; +import de.torui.coflsky.configuration.LocalConfig; +import net.minecraftforge.fml.common.event.FMLPreInitializationEvent; import org.lwjgl.input.Keyboard; -import de.torui.coflsky.configuration.ConfigurationManager; import de.torui.coflsky.network.WSClientWrapper; import net.minecraft.client.settings.KeyBinding; import net.minecraftforge.client.ClientCommandHandler; @@ -27,6 +33,9 @@ public class CoflSky public static KeyBinding[] keyBindings; public static EventRegistry Events; + public static File configFile; + private File coflDir; + public static LocalConfig config; public static final String[] webSocketURIPrefix = new String [] { "wss://sky.coflnet.com/modsocket", @@ -36,7 +45,25 @@ public class CoflSky }; public static String CommandUri = "https://sky-commands.coflnet.com/api/mod/commands"; - + @EventHandler + public void preInit(FMLPreInitializationEvent event) { + String configString = null; + Gson gson = new Gson(); + coflDir = new File(event.getModConfigurationDirectory(), "CoflSky"); + coflDir.mkdirs(); + configFile = new File(coflDir, "config.json"); + try { + if (configFile.isFile()) { + configString = new String(Files.readAllBytes(Paths.get(configFile.getPath()))); + config = gson.fromJson(configString, LocalConfig.class); + } + } catch (IOException e) { + e.printStackTrace(); + } + if (configString == null) { + config = LocalConfig.createDefaultConfig(); + } + } @EventHandler public void init(FMLInitializationEvent event) throws URISyntaxException { @@ -62,7 +89,11 @@ public class CoflSky } Events = new EventRegistry(); - MinecraftForge.EVENT_BUS.register(Events); + MinecraftForge.EVENT_BUS.register(Events); + Runtime.getRuntime() + .addShutdownHook( + new Thread( + () -> config.saveConfig(configFile , config))); } -- cgit