added files.

This commit is contained in:
nitrogenoliquido committed 2026-11-23 23:48:56 -05:00
commit 03a7ed8358
9721 files changed
+828024

No files matched your search

@@ -0,0 +1,185 @@
package net.augustus.config;
import net.augustus.Augustus;
import net.augustus.settings.options.NotificationCategoryOption;
import net.augustus.ui.notifications.NotificationLevel;
import net.augustus.ui.notifications.NotificationManager;
import net.augustus.utils.ChatUtil;
import net.augustus.utils.audio.ClientSounds;
import com.google.gson.JsonElement;
import com.google.gson.JsonObject;
import java.io.File;
import java.nio.charset.StandardCharsets;
import java.util.HashMap;
import net.minecraft.client.Minecraft;
import net.minecraft.network.PacketThreadUtil;
public class ModuleConfigStorage extends JsonConfigFile {
private final HashMap<Integer, ModuleConfigCodec> formatCodecs;
public ModuleConfigStorage() {
super(
text -> ((String)text).getBytes(StandardCharsets.UTF_8),
bytes -> new String((byte[])bytes, StandardCharsets.UTF_8)
);
this.formatCodecs = new HashMap<>();
this.formatCodecs.put(2, new ConfigFormatV2());
}
@Override
public Class getJsonType() {
return JsonObject.class;
}
@Override
public void deserialize(JsonElement elem) {
this.deserializeEmpty((JsonObject)elem);
}
public void loadConfig(String configName, String subDir) {
this.loadConfig(configName, subDir, true);
}
public void loadConfig(String configName, String subDir, boolean notify) {
JsonObject json = this.readConfigJson(subDir, configName);
if (json == null) {
if (notify) {
File file = new File(this.getDirectoryPath() + subDir, configName + ".json");
String message = !file.exists()
? "Config not found: §c" + configName
: "Failed to load config: §c" + configName;
this.notifyConfigStatus(message, NotificationLevel.ERROR);
}
return;
}
this.applyConfigJson(json, configName, notify);
}
public JsonObject buildConfigJson(String configName, boolean editable) {
return this.formatCodecs.get(2).encodeConfig(configName, Augustus.getInstance().getUsername(), editable);
}
public JsonObject readConfigJson(String subDir, String configName) {
File file = new File(this.getDirectoryPath() + subDir, configName + ".json");
if (!file.exists()) {
return null;
}
return (JsonObject)this.readJsonFile(file);
}
@Override
public boolean isBackupEnabled() {
return false;
}
public void applyConfigJson(JsonObject json, String configName, boolean notify) {
if (json == null) {
return;
}
Integer version = this.readConfigVersion(json);
if (version == null) {
return;
}
ModuleConfigCodec codec = this.formatCodecs.get(version);
if (codec != null) {
try {
long startTime = System.currentTimeMillis();
codec.applyConfig(json);
if (notify) {
long elapsed = System.currentTimeMillis() - startTime;
this.notifyConfigStatus("Config loaded: §c" + configName + " (" + elapsed + "ms)", NotificationLevel.INFO);
Augustus.getInstance().getModuleManager().sortModules();
ClientSounds.playSound(ClientSounds.AUGUSTUS_TEXTURE2);
}
} catch (Exception e) {
e.printStackTrace();
}
}
}
public void saveConfig(String configName, String subDir, boolean editable) {
try {
JsonObject json = this.buildConfigJson(configName, editable);
File file = new File(this.getDirectoryPath() + subDir, configName + ".json");
long startTime = System.currentTimeMillis();
this.writeJsonFile(file, json);
long elapsed = System.currentTimeMillis() - startTime;
ClientSounds.playSound(ClientSounds.AUGUSTUS_TEXTURE2);
this.notifyConfigStatus("Config saved: §c" + configName + " (" + elapsed + "ms)", NotificationLevel.INFO);
} catch (Exception e) {
e.printStackTrace();
}
}
public JsonObject serializeEmpty() {
return null;
}
@Override
public JsonElement serialize() {
return this.serializeEmpty();
}
private void notifyConfigStatus(String message, NotificationLevel level) {
ChatUtil.sendChat(message);
if (!Augustus.getInstance().getModuleManager().notifications.isToggled()) {
return;
}
if (!NotificationCategoryOption.CONFIG_SYSTEM.isSelected()) {
return;
}
if (Minecraft.getMinecraft().isCallingFromMinecraftThread()) {
NotificationManager.pushNotification("Configsystem", message, level);
return;
}
PacketThreadUtil.runOnMainThreadImmediate(() -> showNotification(message, level));
}
@Override
public String getName() {
return "";
}
@Override
public String getSubDirectory() {
return "";
}
public void deserializeEmpty(JsonObject json) {
}
@Override
public boolean isAutoManaged() {
return false;
}
private static void showNotification(String message, NotificationLevel level) {
NotificationManager.pushNotification("Configsystem", message, level);
}
public String[] getConfigHeaderInfo(String configName, String subDir) {
JsonObject json = this.readConfigJson(subDir, configName);
if (json == null) {
return null;
}
Integer version = this.readConfigVersion(json);
if (version == null) {
return null;
}
ModuleConfigCodec codec = this.formatCodecs.get(version);
if (codec == null) {
return null;
}
return codec.readHeaderInfo(json);
}
private Integer readConfigVersion(JsonObject json) {
if (json.has("Config_Header") && json.get("Config_Header").isJsonObject()) {
JsonObject header = json.getAsJsonObject("Config_Header");
if (header.has("ConfigVersion")) {
return header.get("ConfigVersion").getAsInt();
}
}
return null;
}
}