diff --git a/build.gradle b/build.gradle index 9d64b14..da1d728 100644 --- a/build.gradle +++ b/build.gradle @@ -26,9 +26,6 @@ dependencies { modImplementation "net.fabricmc:fabric-loader:${project.loader_version}" modImplementation "net.fabricmc.fabric-api:fabric-api:${project.fabric_version}" - - implementation("com.electronwill.night-config:core:3.8.2") - implementation("com.electronwill.night-config:json:3.8.2") } processResources { diff --git a/src/main/java/com/cimeyclust/ezcheat/Config.java b/src/main/java/com/cimeyclust/ezcheat/Config.java index d7771d7..6779115 100644 --- a/src/main/java/com/cimeyclust/ezcheat/Config.java +++ b/src/main/java/com/cimeyclust/ezcheat/Config.java @@ -1,32 +1,60 @@ package com.cimeyclust.ezcheat; -import com.electronwill.nightconfig.core.file.CommentedFileConfig; -import com.electronwill.nightconfig.core.file.FileConfig; -import com.electronwill.nightconfig.core.io.WritingMode; import net.fabricmc.loader.api.FabricLoader; import org.slf4j.Logger; import org.slf4j.LoggerFactory; +import java.io.IOException; +import java.nio.file.Files; import java.nio.file.Path; public class Config { - private static final Logger LOGGER = LoggerFactory.getLogger("ezcheat"); - private static final Path CONFIG_PATH = - FabricLoader.getInstance().getConfigDir().resolve("ezcheat.json"); + private static final Path CONFIG_PATH = FabricLoader + .getInstance() + .getConfigDir() + .resolve("ezcheat.toml"); - public static String MOD_ENDPOINT_URL = "https://modlist.ugasmp.com/api/mods"; + public static String modEndpointUrl = "https://modlist.ugasmp.com/api/mods"; + private static final Logger LOGGER = LoggerFactory.getLogger("ezcheat"); + + public Config() {} public static void load() { - var cfg = FileConfig.builder(CONFIG_PATH) - .sync() - .autosave() - .writingMode(WritingMode.REPLACE) - .build(); + if (!Files.exists(CONFIG_PATH)) { + save(); + return; + } - cfg.load(); - MOD_ENDPOINT_URL = cfg.getOrElse("modEndpointUrl", - "https://modlist.ugasmp.com/api/mods"); - cfg.save(); - LOGGER.info("Loaded config: modEndpointUrl={}", MOD_ENDPOINT_URL); + try { + for (String line : Files.readAllLines(CONFIG_PATH)) { + line = line.trim(); + if (line.isEmpty() || line.startsWith("#")) continue; + + if (line.startsWith("modEndpointUrl")) { + String[] parts = line.split("=", 2); + if (parts.length == 2) { + modEndpointUrl = parts[1].trim().replaceAll("^\"|\"$", ""); + Ezcheat.LOGGER.info("Loaded modEndpointUrl = {}", modEndpointUrl); + } + } + } + } catch (IOException e) { + Ezcheat.LOGGER.error("Failed to load config: {}", e.getMessage()); + } + } + + public static void save() { + StringBuilder toml = new StringBuilder(); + toml.append("# EZCheat Config\n"); + toml.append("# URL for the Mod‑Whitelist‑API\n"); + toml.append("modEndpointUrl = \"").append(modEndpointUrl).append("\"\n"); + + try { + Files.createDirectories(CONFIG_PATH.getParent()); + Files.writeString(CONFIG_PATH, toml.toString()); + Ezcheat.LOGGER.info("Saved modEndpointUrl = {}", modEndpointUrl); + } catch (IOException e) { + Ezcheat.LOGGER.error("Failed to save config: {}", e.getMessage()); + } } } diff --git a/src/main/java/com/cimeyclust/ezcheat/Ezcheat.java b/src/main/java/com/cimeyclust/ezcheat/Ezcheat.java index 6606ec0..c7c8f17 100644 --- a/src/main/java/com/cimeyclust/ezcheat/Ezcheat.java +++ b/src/main/java/com/cimeyclust/ezcheat/Ezcheat.java @@ -62,7 +62,7 @@ public class Ezcheat implements ModInitializer { // load config Config.load(); - LOGGER.info("Ezcheat initialized; endpoint = {}", Config.MOD_ENDPOINT_URL); + LOGGER.info("Ezcheat initialized; endpoint = {}", Config.modEndpointUrl); } private void onPlayerJoin(ServerPlayNetworkHandler handler, PacketSender sender, MinecraftServer server) { @@ -102,7 +102,7 @@ public class Ezcheat implements ModInitializer { LOGGER.info("Verifying mod hashes: {}", mapToString(hashes)); try { // fetch allowed list - HttpURLConnection conn = (HttpURLConnection) new URL(Config.MOD_ENDPOINT_URL).openConnection(); + HttpURLConnection conn = (HttpURLConnection) new URL(Config.modEndpointUrl).openConnection(); conn.setRequestMethod("GET"); conn.setDoInput(true);