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-loader:${project.loader_version}"
|
||||||
|
|
||||||
modImplementation "net.fabricmc.fabric-api:fabric-api:${project.fabric_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 {
|
processResources {
|
||||||
|
|||||||
@ -1,32 +1,60 @@
|
|||||||
package com.cimeyclust.ezcheat;
|
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 net.fabricmc.loader.api.FabricLoader;
|
||||||
import org.slf4j.Logger;
|
import org.slf4j.Logger;
|
||||||
import org.slf4j.LoggerFactory;
|
import org.slf4j.LoggerFactory;
|
||||||
|
|
||||||
|
import java.io.IOException;
|
||||||
|
import java.nio.file.Files;
|
||||||
import java.nio.file.Path;
|
import java.nio.file.Path;
|
||||||
|
|
||||||
public class Config {
|
public class Config {
|
||||||
private static final Logger LOGGER = LoggerFactory.getLogger("ezcheat");
|
private static final Path CONFIG_PATH = FabricLoader
|
||||||
private static final Path CONFIG_PATH =
|
.getInstance()
|
||||||
FabricLoader.getInstance().getConfigDir().resolve("ezcheat.json");
|
.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() {
|
public static void load() {
|
||||||
var cfg = FileConfig.builder(CONFIG_PATH)
|
if (!Files.exists(CONFIG_PATH)) {
|
||||||
.sync()
|
save();
|
||||||
.autosave()
|
return;
|
||||||
.writingMode(WritingMode.REPLACE)
|
}
|
||||||
.build();
|
|
||||||
|
|
||||||
cfg.load();
|
try {
|
||||||
MOD_ENDPOINT_URL = cfg.getOrElse("modEndpointUrl",
|
for (String line : Files.readAllLines(CONFIG_PATH)) {
|
||||||
"https://modlist.ugasmp.com/api/mods");
|
line = line.trim();
|
||||||
cfg.save();
|
if (line.isEmpty() || line.startsWith("#")) continue;
|
||||||
LOGGER.info("Loaded config: modEndpointUrl={}", MOD_ENDPOINT_URL);
|
|
||||||
|
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
|
// load config
|
||||||
Config.load();
|
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) {
|
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));
|
LOGGER.info("Verifying mod hashes: {}", mapToString(hashes));
|
||||||
try {
|
try {
|
||||||
// fetch allowed list
|
// 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.setRequestMethod("GET");
|
||||||
conn.setDoInput(true);
|
conn.setDoInput(true);
|
||||||
|
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user