Stable 2
This commit is contained in:
parent
9a47b201ca
commit
4ee09e5a13
@ -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 {
|
||||
|
||||
@ -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());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@ -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);
|
||||
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user