added files.

This commit is contained in:
nitrogenoliquido committed 2026-11-24 21:29:20 -05:00
1 parent adf299cc81
commit 4e22dc2f72
10 files changed
+119 -17

No files matched your search

+21 -7
View File
@@ -177,18 +177,32 @@ public class Augustus {
}
}
public void stop() {
public synchronized void stop() {
if (this.shuttingDown) {
return;
}
this.shuttingDown = true;
try {
if (this.moduleManager != null && this.moduleManager.clickGui != null && this.moduleManager.clickGui.isToggled()) {
this.moduleManager.clickGui.setToggled(false, false);
}
} catch (Throwable ignored) {
}
try {
if (Minecraft.getMinecraft() != null && Minecraft.getMinecraft().getSession() != null) {
Minecraft.getMinecraft().getSession().updatePlayTime(false);
}
this.configManager.snapshotAll();
this.configManager.saveAll();
} catch (Throwable ignored) {
}
try {
Thread.sleep(200L);
} catch (InterruptedException e) {
throw new RuntimeException(e);
if (this.configManager != null) {
this.configManager.saveAllForShutdown();
}
} catch (Throwable t) {
t.printStackTrace();
}
}
@@ -77,7 +77,7 @@ public class CommandManager implements ChatListener {
if (args.length > 0 && args[0].equalsIgnoreCase(command.getCommand())) {
command.commandAction(args, message);
event.cancel();
Augustus.getInstance().getConfigManager().snapshotAll();
Augustus.getInstance().getConfigManager().saveAllAsync();
}
}
@@ -23,4 +23,9 @@ public class ClientSettingsConfigFile extends AbstractFeatureConfigFile {
public boolean alwaysReserializeOnSave() {
return true;
}
@Override
public boolean markLoadedEvenIfEmpty() {
return true;
}
}
@@ -1,10 +1,22 @@
package net.augustus.config;
import net.augustus.settings.Setting;
import com.google.gson.JsonElement;
import java.util.ArrayList;
import java.util.LinkedHashMap;
import java.util.List;
import java.util.Map;
import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;
public class ConfigManager {
public static final ArrayList CONFIG_FILES = new ArrayList();
private final Object ioLock = new Object();
private volatile boolean shuttingDown = false;
private final ExecutorService saveExecutor = Executors.newSingleThreadExecutor(r -> {
Thread t = new Thread(r, "OpenAugustus-ConfigSaver");
t.setDaemon(true);
return t;
});
public final ModuleSettingsConfigSection moduleSettingsConfig;
public final AccountConfigStorage accountConfig;
public final ProxyConfigStorage proxyConfig;
@@ -21,7 +33,7 @@ public class ConfigManager {
}
public void loadAll() {
((java.util.List<JsonConfigFile>)CONFIG_FILES).forEach((JsonConfigFile jsonConfigFile) -> {
((List<JsonConfigFile>)CONFIG_FILES).forEach((JsonConfigFile jsonConfigFile) -> {
if (jsonConfigFile.isAutoManaged()) {
jsonConfigFile.load();
}
@@ -29,17 +41,60 @@ public class ConfigManager {
}
public void saveAll() {
((java.util.List<JsonConfigFile>)CONFIG_FILES).forEach((JsonConfigFile jsonConfigFile) -> saveConfigFile(jsonConfigFile));
synchronized (this.ioLock) {
((List<JsonConfigFile>)CONFIG_FILES).forEach((JsonConfigFile jsonConfigFile) -> saveConfigFile(jsonConfigFile));
}
}
public void saveAllForShutdown() {
this.shuttingDown = true;
this.saveAll();
}
public void saveAllAsync() {
if (this.shuttingDown) {
return;
}
Map<JsonConfigFile, JsonElement> snapshots = new LinkedHashMap<>();
for (JsonConfigFile jsonConfigFile : (List<JsonConfigFile>)CONFIG_FILES) {
if (jsonConfigFile.isAutoManaged()) {
jsonConfigFile.captureSnapshot();
JsonElement snapshot = jsonConfigFile.getCachedJson();
if (snapshot != null) {
snapshots.put(jsonConfigFile, snapshot);
}
}
}
if (snapshots.isEmpty()) {
return;
}
this.saveExecutor.execute(() -> {
synchronized (this.ioLock) {
if (this.shuttingDown) {
return;
}
for (Map.Entry<JsonConfigFile, JsonElement> entry : snapshots.entrySet()) {
try {
entry.getKey().writeSnapshot(entry.getValue());
} catch (Throwable t) {
t.printStackTrace();
}
}
}
});
}
private static void saveConfigFile(JsonConfigFile jsonConfigFile) {
if (jsonConfigFile.isAutoManaged()) {
jsonConfigFile.save();
jsonConfigFile.save(true);
}
}
public void snapshotAll() {
((java.util.List<JsonConfigFile>)CONFIG_FILES).forEach((JsonConfigFile jsonConfigFile) -> snapshotConfigFile(jsonConfigFile));
((List<JsonConfigFile>)CONFIG_FILES).forEach((JsonConfigFile jsonConfigFile) -> snapshotConfigFile(jsonConfigFile));
}
private static void snapshotConfigFile(JsonConfigFile jsonConfigFile) {
@@ -201,6 +201,12 @@ public abstract class JsonConfigFile implements NamedConfigComponent {
}
}
public void writeSnapshot(JsonElement snapshot) {
if (snapshot != null) {
this.writeJsonFile(new File(this.getFilePath()), snapshot);
}
}
public boolean markLoadedEvenIfEmpty() {
return false;
}
@@ -11,6 +11,7 @@ import java.io.IOException;
import java.nio.charset.StandardCharsets;
import java.nio.file.Files;
import java.nio.file.Path;
import java.nio.file.StandardCopyOption;
import java.nio.file.StandardOpenOption;
import java.util.function.Supplier;
@@ -89,18 +90,29 @@ public class JsonFileStorageHandler {
public void write(File file, JsonElement elem, Gson gson) {
this.ensureParentDirectory(file);
Path target = file.toPath();
Path tmp = target.resolveSibling(file.getName() + ".tmp");
try {
String str = gson.toJson(elem);
if (this.encoder != null) {
byte[] bytes = (byte[])this.encoder.apply(str);
Files.write(file.toPath(), bytes, StandardOpenOption.CREATE, StandardOpenOption.TRUNCATE_EXISTING);
Files.write(tmp, bytes, StandardOpenOption.CREATE, StandardOpenOption.TRUNCATE_EXISTING, StandardOpenOption.WRITE);
} else {
try (BufferedWriter writer = Files.newBufferedWriter(file.toPath(), StandardCharsets.UTF_8)) {
try (BufferedWriter writer = Files.newBufferedWriter(tmp, StandardCharsets.UTF_8, StandardOpenOption.CREATE, StandardOpenOption.TRUNCATE_EXISTING, StandardOpenOption.WRITE)) {
writer.write(str);
writer.flush();
}
}
try {
Files.move(tmp, target, StandardCopyOption.REPLACE_EXISTING, StandardCopyOption.ATOMIC_MOVE);
} catch (IOException atomicEx) {
Files.move(tmp, target, StandardCopyOption.REPLACE_EXISTING);
}
} catch (IOException e) {
try {
Files.deleteIfExists(tmp);
} catch (IOException ignored) {
}
e.printStackTrace();
}
}
@@ -755,6 +755,10 @@ public class ModuleConfigStorage extends JsonConfigFile {
Augustus.getInstance().getModuleManager().sortModules();
}
if (Augustus.getInstance().getConfigManager() != null) {
Augustus.getInstance().getConfigManager().saveAllAsync();
}
if (report.hasAnyIssue()) {
report.logToConsole();
if (notify) {
@@ -93,6 +93,11 @@ public class ModuleSettingsConfigSection extends AbstractFeatureConfigFile {
return true;
}
@Override
public boolean markLoadedEvenIfEmpty() {
return true;
}
private static JsonObject deepMergeJson(JsonObject json, JsonObject json2) {
JsonObject json3 = new JsonObject();
@@ -132,7 +132,7 @@ public class ClickGui extends Module implements DownloadTerrainListener, TickLis
@Override
public void onDisable() {
Augustus.getInstance().getConfigManager().snapshotAll();
Augustus.getInstance().getConfigManager().saveAllAsync();
}
@Override
@@ -2215,6 +2215,7 @@ this.entityRenderer.itemRenderer.resetEquippedProgress();
try {
flag = true;
Augustus.getInstance().stop();
Augustus.getInstance().getDiscordRpcManager().shutdown();
LOGGER.info("Stopping!");
@@ -2727,7 +2728,7 @@ if (this.gameSettings.language != null) {
this.ingameGUI = new GuiIngameHook(this);
Augustus.getInstance().preStart();
Augustus.getInstance().start();
Runtime.getRuntime().addShutdownHook(new Thread(Augustus.getInstance()::getMouseWheelTracker));
Runtime.getRuntime().addShutdownHook(new Thread(Augustus.getInstance()::stop, "OpenAugustus-ShutdownHook"));
mc = this;
if (this.serverName != null) {
this.displayGuiScreen(new GuiConnecting(new GuiMainMenu(), this, this.serverName, this.serverPort));