diff --git a/core/build.gradle b/core/build.gradle index 89ce2a8f..4fbf16b9 100644 --- a/core/build.gradle +++ b/core/build.gradle @@ -32,15 +32,20 @@ println "Java: ${System.getProperty 'java.version'}, JVM: ${System.getProperty ' // Include resources generated by data generators. sourceSets.main.resources { srcDir 'src/generated/resources' } +tasks.named('shadowJar', ShadowJar) { + relocate('computer.heather.simpleconfig', 'shadow/advancedbackups/simpleconfig') + relocate('org.fusesource.jansi', 'shadow/advancedbackups/jansi') + archiveClassifier.set('') +} repositories { // These repositories are only for Gradle plugins, put any other repositories in the repository block further below mavenCentral() -} + maven { + name "heatherComputer" + url "https://maven.heather.computer/public" + } -tasks.named('shadowJar', ShadowJar) { - enableRelocation true - archiveClassifier.set('') } dependencies { @@ -50,6 +55,9 @@ dependencies { //extraLibs 'com.sun.jna.platform:5.13.0' compileOnly 'com.google.code.gson:gson:2.10.1' implementation 'org.fusesource.jansi:jansi:2.4.0' + //The + allows us to pin to the latest version. This is fine and useful. + implementation "computer.heather:SimpleConfig:+" + // Real mod deobf dependency examples - these get remapped to your current mappings // compileOnly fg.deobf("mezz.jei:jei-${mc_version}:${jei_version}:api") // Adds JEI API as a compile dependency @@ -70,11 +78,11 @@ jar { attributes([ "Main-Class" : "computer.heather.advancedbackups.cli.AdvancedBackupsCLI", "Specification-Title" : "advancedbackups", - "Specification-Vendor" : "raveninthedark", + "Specification-Vendor" : "heathercomputer", "Specification-Version" : "1", // We are version 1 of ourselves "Implementation-Title" : project.name, "Implementation-Version" : project.jar.archiveVersion, - "Implementation-Vendor" : "raveninthedark", + "Implementation-Vendor" : "heathercomputer", "Implementation-Timestamp": new Date().format("yyyy-MM-dd'T'HH:mm:ssZ") ]) } diff --git a/core/src/main/java/computer/heather/advancedbackups/core/CoreCommandSystem.java b/core/src/main/java/computer/heather/advancedbackups/core/CoreCommandSystem.java index 670d25d0..0ec37637 100644 --- a/core/src/main/java/computer/heather/advancedbackups/core/CoreCommandSystem.java +++ b/core/src/main/java/computer/heather/advancedbackups/core/CoreCommandSystem.java @@ -11,6 +11,7 @@ import java.io.File; import java.io.FileWriter; +import java.io.IOException; import java.nio.file.Files; import java.util.function.Consumer; @@ -35,13 +36,13 @@ public static void startBackup(Consumer chat) { BackupWrapper.makeSingleBackup(0, chat, false); } - public static void reloadConfig(Consumer chat) { + public static void reloadConfig(Consumer chat) throws IOException { chat.accept("Reloading config..."); ConfigManager.loadOrCreateConfig(); chat.accept("Done!"); } - public static void reloadClientConfig(Consumer chat) { + public static void reloadClientConfig(Consumer chat) throws IOException { chat.accept("Reloading client config..."); ClientConfigManager.loadOrCreateConfig(); chat.accept("Done!"); @@ -66,8 +67,8 @@ public static void resetChainLength(Consumer chat) { try { BackupManifest manifest = gson.fromJson(new String(Files.readAllBytes(backupManifest.toPath())), BackupManifest.class); - manifest.incremental.chainLength += (int) ConfigManager.length.get(); - manifest.differential.chainLength += (int) ConfigManager.length.get(); + manifest.incremental.chainLength += ConfigManager.length.get().intValue(); + manifest.differential.chainLength += ConfigManager.length.get().intValue(); FileWriter writer = new FileWriter(backupManifest); diff --git a/core/src/main/java/computer/heather/advancedbackups/core/backups/ThreadedBackup.java b/core/src/main/java/computer/heather/advancedbackups/core/backups/ThreadedBackup.java index e8b2e690..07b81aeb 100644 --- a/core/src/main/java/computer/heather/advancedbackups/core/backups/ThreadedBackup.java +++ b/core/src/main/java/computer/heather/advancedbackups/core/backups/ThreadedBackup.java @@ -169,7 +169,7 @@ private void makeZipBackup(File file, boolean b) throws InterruptedException, IO this.output.accept("Preparing " + (this.snapshot ? "snapshot" : "zip") + " backup with name:\n " + zip.getName().replace("incomplete", this.snapshot ? snapshotName : "backup")); FileOutputStream outputStream = new FileOutputStream(zip); ZipOutputStream zipOutputStream = new ZipOutputStream(outputStream); - zipOutputStream.setLevel((int) ConfigManager.compression.get()); + zipOutputStream.setLevel(ConfigManager.compression.get().intValue()); ArrayList paths = new ArrayList<>(); @@ -227,7 +227,7 @@ public FileVisitResult visitFileFailed(Path path, IOException exc) { continue; } zipOutputStream.putNextEntry(new ZipEntry(targetFile.toString())); - byte[] bytes = new byte[(int) ConfigManager.buffer.get()]; + byte[] bytes = new byte[ConfigManager.buffer.get().intValue()]; try { FileInputStream is = new FileInputStream(sourceFile); while (true) { @@ -378,7 +378,7 @@ public FileVisitResult visitFileFailed(Path path, IOException exc) { File zip = differential ? new File(location.toString() + "/differential/", backupName + ".zip") : new File(location.toString() + "/incremental/", backupName + ".zip"); FileOutputStream outputStream = new FileOutputStream(zip); ZipOutputStream zipOutputStream = new ZipOutputStream(outputStream); - zipOutputStream.setLevel((int) ConfigManager.compression.get()); + zipOutputStream.setLevel(ConfigManager.compression.get().intValue()); int max = toBackup.size(); int index = 0; @@ -402,7 +402,7 @@ public FileVisitResult visitFileFailed(Path path, IOException exc) { } zipOutputStream.putNextEntry(new ZipEntry(path.toString())); - byte[] bytes = new byte[(int) ConfigManager.buffer.get()]; + byte[] bytes = new byte[ConfigManager.buffer.get().intValue()]; try { FileInputStream is = new FileInputStream(sourceFile); while (true) { @@ -523,7 +523,7 @@ public void shutdown() { private String getFileHash(Path path) { try { MessageDigest md5 = MessageDigest.getInstance("MD5"); - byte[] data = new byte[(int) ConfigManager.buffer.get()]; + byte[] data = new byte[ConfigManager.buffer.get().intValue()]; FileInputStream is = new FileInputStream(path.toFile()); while (true) { int i = is.read(data); diff --git a/core/src/main/java/computer/heather/advancedbackups/core/config/ClientConfigManager.java b/core/src/main/java/computer/heather/advancedbackups/core/config/ClientConfigManager.java index fd99f295..c4853d1d 100644 --- a/core/src/main/java/computer/heather/advancedbackups/core/config/ClientConfigManager.java +++ b/core/src/main/java/computer/heather/advancedbackups/core/config/ClientConfigManager.java @@ -1,136 +1,106 @@ package computer.heather.advancedbackups.core.config; import computer.heather.advancedbackups.core.ABCore; -import computer.heather.advancedbackups.core.config.ConfigTypes.BooleanValue; -import computer.heather.advancedbackups.core.config.ConfigTypes.ConfigValidationEnum; -import computer.heather.advancedbackups.core.config.ConfigTypes.LongValue; - -import java.io.BufferedReader; -import java.io.File; -import java.io.FileReader; -import java.io.FileWriter; +import computer.heather.simpleconfig.exceptions.validation.BaseValidationException; +import computer.heather.simpleconfig.exceptions.validation.MissingOptionException; +import computer.heather.simpleconfig.exceptions.validation.MissingValueException; +import computer.heather.simpleconfig.managers.PremadePropertiesManager; +import computer.heather.simpleconfig.types.BaseConfigType; +import computer.heather.simpleconfig.types.BooleanValue; +import computer.heather.simpleconfig.types.LongValue; + import java.io.IOException; -import java.io.InputStream; -import java.io.InputStreamReader; -import java.nio.charset.StandardCharsets; +import java.nio.file.Paths; import java.util.ArrayList; -import java.util.HashMap; -import java.util.Properties; -import java.util.stream.Collectors; public class ClientConfigManager { - private static HashMap entries = new HashMap<>(); - - - public static void register(String key, ConfigTypes configType) { - entries.put(key, configType); - } + public static final BooleanValue showProgress = new BooleanValue("config.advancedbackups.showProgress", true); - public static final BooleanValue showProgress = new BooleanValue("config.advancedbackups.showProgress", true, ClientConfigManager::register); + public static final BooleanValue darkMode = new BooleanValue("config.advancedbackups.darkToasts", true); - public static final BooleanValue darkMode = new BooleanValue("config.advancedbackups.darkToasts", true, ClientConfigManager::register); + public static final LongValue progressTextRed = new LongValue("config.advancedbackups.colours.progress.red", 82, 0, 255); + public static final LongValue progressTextGreen = new LongValue("config.advancedbackups.colours.progress.green", 255, 0, 255); + public static final LongValue progressTextBlue = new LongValue("config.advancedbackups.colours.progress.blue", 82, 0, 255); - public static final LongValue progressTextRed = new LongValue("config.advancedbackups.colours.progress.red", 82, 0, 255, ClientConfigManager::register); - public static final LongValue progressTextGreen = new LongValue("config.advancedbackups.colours.progress.green", 255, 0, 255, ClientConfigManager::register); - public static final LongValue progressTextBlue = new LongValue("config.advancedbackups.colours.progress.blue", 82, 0, 255, ClientConfigManager::register); + public static final LongValue errorTextRed = new LongValue("config.advancedbackups.colours.error.red", 255, 0, 255); + public static final LongValue errorTextGreen = new LongValue("config.advancedbackups.colours.error.green", 50, 0, 255); + public static final LongValue errorTextBlue = new LongValue("config.advancedbackups.colours.error.blue", 50, 0, 255); - public static final LongValue errorTextRed = new LongValue("config.advancedbackups.colours.error.red", 255, 0, 255, ClientConfigManager::register); - public static final LongValue errorTextGreen = new LongValue("config.advancedbackups.colours.error.green", 50, 0, 255, ClientConfigManager::register); - public static final LongValue errorTextBlue = new LongValue("config.advancedbackups.colours.error.blue", 50, 0, 255, ClientConfigManager::register); + public static final LongValue progressBarRed = new LongValue("config.advancedbackups.colours.bar.red", 88, 0, 255); + public static final LongValue progressBarGreen = new LongValue("config.advancedbackups.colours.bar.green", 242, 0, 255); + public static final LongValue progressBarBlue = new LongValue("config.advancedbackups.colours.bar.blue", 82, 0, 255); - public static final LongValue progressBarRed = new LongValue("config.advancedbackups.colours.bar.red", 88, 0, 255, ClientConfigManager::register); - public static final LongValue progressBarGreen = new LongValue("config.advancedbackups.colours.bar.green", 242, 0, 255, ClientConfigManager::register); - public static final LongValue progressBarBlue = new LongValue("config.advancedbackups.colours.bar.blue", 82, 0, 255, ClientConfigManager::register); + public static final LongValue progressBackgroundRed = new LongValue("config.advancedbackups.colours.background.red", 255, 0, 255); + public static final LongValue progressBackgroundGreen = new LongValue("config.advancedbackups.colours.background.green", 255, 0, 255); + public static final LongValue progressBackgroundBlue = new LongValue("config.advancedbackups.colours.background.blue", 255, 0, 255); - public static final LongValue progressBackgroundRed = new LongValue("config.advancedbackups.colours.background.red", 255, 0, 255, ClientConfigManager::register); - public static final LongValue progressBackgroundGreen = new LongValue("config.advancedbackups.colours.background.green", 255, 0, 255, ClientConfigManager::register); - public static final LongValue progressBackgroundBlue = new LongValue("config.advancedbackups.colours.background.blue", 255, 0, 255, ClientConfigManager::register); + + //Make the manager. Chaining! + private static final PremadePropertiesManager MANAGER = new PremadePropertiesManager() + .setConfigLocation(Paths.get("config/Advancedbackups-client.properties")) + .setPremadeLocation("advancedbackups-client-properties.txt") + .register( + showProgress, darkMode, + progressTextRed, progressTextGreen, progressTextBlue, + errorTextRed, errorTextGreen, errorTextBlue, + progressBarRed, progressBarGreen, progressBarBlue, + progressBackgroundRed, progressBackgroundGreen, progressBackgroundBlue + ); - public static void loadOrCreateConfig() { - // Called when the config needs to be loaded, but one may not exist. - // Creates a new config it one doesn't exist, then loads it. - File dir = new File("./config"); - if (!dir.exists()) { - dir.mkdirs(); - } - File file = new File(dir, "AdvancedBackups-client.properties"); - if (!file.exists()) { - writeConfig(); + public static void loadOrCreateConfig() throws IOException { + ArrayList missingProperties = new ArrayList<>(); + ArrayList erroringProperties = new ArrayList<>(); + try { + MANAGER.loadOrCreate((configType, value, exception) -> { + //MissingOptionException is used for config types that don't exist in code. This means we can migrate stuff. + if (exception instanceof MissingOptionException) { + handleMigration(configType, value); + } + else if (exception instanceof MissingValueException) { + missingProperties.add(configType.getKey()); + } + else { + erroringProperties.add(configType.getKey() + exception); + } + }); + } catch (IOException e) { + ABCore.errorLogger.accept("Failed to load config! Cannot proceed due to IO error."); + throw e; + } catch (BaseValidationException e) { + // Nothing to do here. This catch will never trigger. } - loadConfig(); - } - private static void writeConfig() { - // Called to write to a config file. - // Create a complete properties file in the cwd, including any existing changes - ABCore.infoLogger.accept("Preparing to write to client properties file..."); - File file = new File("./config/AdvancedBackups-client.properties"); - try { - file.createNewFile(); - file.setWritable(true); - InputStream is = ClientConfigManager.class.getClassLoader().getResourceAsStream("advancedbackups-client-properties.txt"); - String text = new BufferedReader(new InputStreamReader(is, StandardCharsets.UTF_8)) - .lines().collect(Collectors.joining("\n")); + //We use this flat just so we can ensure the final error message is only logged once. + boolean flag = false; - for (String key : entries.keySet()) { - text = text.replace(key, key + "=" + entries.get(key).save()); + //Now, we have loaded and created with our error handler. But let's make sure we log missing options properly! + if (!missingProperties.isEmpty()) { + flag = true; + ABCore.warningLogger.accept("The following options were missing from the loaded file :"); + for (String string : missingProperties) { + ABCore.warningLogger.accept(string); } - - FileWriter writer = new FileWriter(file); - writer.write(text); - writer.close(); - } catch (IOException e) { - // TODO : Scream to user - ABCore.logStackTrace(e); } - } - - private static void loadConfig() { - //Load the config file. - Properties props = new Properties(); - File file = new File("./config/AdvancedBackups-client.properties"); - FileReader reader; - try { - reader = new FileReader(file); - props.load(reader); - reader.close(); - } catch (IOException e) { - // TODO : Scream to user - ABCore.logStackTrace(e); - return; + //And now the same for erroring options. + if (!erroringProperties.isEmpty()) { + ABCore.warningLogger.accept("The following options failed to validate :"); + for (String string : erroringProperties) { + ABCore.warningLogger.accept(string); + } } - ArrayList missingProps = new ArrayList<>(); + if (flag) ABCore.warningLogger.accept("Client config file has been regenerated! Existing config values have been preserved."); + } - for (String key : entries.keySet()) { - if (!props.containsKey(key)) { - missingProps.add(key); - ABCore.warningLogger.accept("Missing key : " + key); - continue; - } - ConfigValidationEnum valid = entries.get(key).validate(props.getProperty(key)); - if (valid != ConfigValidationEnum.VALID) { - missingProps.add(key); - ABCore.warningLogger.accept(valid.getError() + " : " + key); - continue; - } - entries.get(key).load(props.getProperty(key)); - } - if (!missingProps.isEmpty()) { - ABCore.warningLogger.accept("The following properties were missing from the loaded file :"); - for (String string : missingProps) { - ABCore.warningLogger.accept(string); - } - ABCore.warningLogger.accept("Client properties file will be regenerated! Existing config values will be preserved."); - - writeConfig(); - } + private static void handleMigration(BaseConfigType configType, String value) { + //For now, do nothing! Migratory code from the past is unneeded now. + ABCore.warningLogger.accept("Discarding unused config option: " + configType.getKey() + " with value: " + value); } } \ No newline at end of file diff --git a/core/src/main/java/computer/heather/advancedbackups/core/config/ConfigManager.java b/core/src/main/java/computer/heather/advancedbackups/core/config/ConfigManager.java index 1b1aed48..63947b2f 100644 --- a/core/src/main/java/computer/heather/advancedbackups/core/config/ConfigManager.java +++ b/core/src/main/java/computer/heather/advancedbackups/core/config/ConfigManager.java @@ -1,57 +1,43 @@ package computer.heather.advancedbackups.core.config; -import computer.heather.advancedbackups.core.ABCore; -import computer.heather.advancedbackups.core.backups.BackupWrapper; -import computer.heather.advancedbackups.core.backups.ThreadedBackup; -import computer.heather.advancedbackups.core.config.ConfigTypes.BooleanValue; -import computer.heather.advancedbackups.core.config.ConfigTypes.ConfigValidationEnum; -import computer.heather.advancedbackups.core.config.ConfigTypes.FloatValue; -import computer.heather.advancedbackups.core.config.ConfigTypes.FreeStringValue; -import computer.heather.advancedbackups.core.config.ConfigTypes.LongValue; -import computer.heather.advancedbackups.core.config.ConfigTypes.StringArrayValue; -import computer.heather.advancedbackups.core.config.ConfigTypes.ValidatedStringValue; - -import java.io.BufferedReader; -import java.io.File; -import java.io.FileReader; -import java.io.FileWriter; import java.io.IOException; -import java.io.InputStream; -import java.io.InputStreamReader; -import java.nio.charset.StandardCharsets; +import java.nio.file.Paths; import java.util.ArrayList; -import java.util.HashMap; -import java.util.Properties; -import java.util.regex.Matcher; import java.util.regex.Pattern; -import java.util.stream.Collectors; - -public class ConfigManager { - - private static HashMap entries = new HashMap<>(); - - - public static void register(String key, ConfigTypes configType) { - entries.put(key, configType); - } +import computer.heather.advancedbackups.core.ABCore; +import computer.heather.advancedbackups.core.backups.BackupWrapper; +import computer.heather.advancedbackups.core.backups.ThreadedBackup; +import computer.heather.simpleconfig.exceptions.validation.BaseValidationException; +import computer.heather.simpleconfig.exceptions.validation.MissingOptionException; +import computer.heather.simpleconfig.exceptions.validation.MissingValueException; +import computer.heather.simpleconfig.managers.PremadePropertiesManager; +import computer.heather.simpleconfig.types.BaseConfigType; +import computer.heather.simpleconfig.types.BooleanValue; +import computer.heather.simpleconfig.types.FloatValue; +import computer.heather.simpleconfig.types.FreeStringValue; +import computer.heather.simpleconfig.types.LongValue; +import computer.heather.simpleconfig.types.StringArrayValue; +import computer.heather.simpleconfig.types.ValidatedStringValue; - public static final BooleanValue enabled = new BooleanValue("config.advancedbackups.enabled", true, ConfigManager::register); - public static final BooleanValue save = new BooleanValue("config.advancedbackups.save", true, ConfigManager::register); - public static final BooleanValue toggleSave = new BooleanValue("config.advancedbackups.togglesave", true, ConfigManager::register); - public static final LongValue buffer = new LongValue("config.advancedbackups.buffer", 1048576, 1024, Integer.MAX_VALUE, ConfigManager::register); //5mb - public static final BooleanValue flush = new BooleanValue("config.advancedbackups.flush", false, ConfigManager::register); - public static final BooleanValue activity = new BooleanValue("config.advancedbackups.activity", true, ConfigManager::register); - public static final StringArrayValue blacklist = new StringArrayValue("config.advancedbackups.blacklist", new String[]{"session.lock", "*_old"}, ConfigManager::register); - public static final ValidatedStringValue type = new ValidatedStringValue("config.advancedbackups.type", "differential", new String[]{"zip", "differential", "incremental"}, ConfigManager::register); - public static final FreeStringValue path = new FreeStringValue("config.advancedbackups.path", "./backups", ConfigManager::register); - public static final FloatValue minFrequency = new FloatValue("config.advancedbackups.frequency.min", 0.25F, 0F, 500F, ConfigManager::register); - public static final FloatValue maxFrequency = new FloatValue("config.advancedbackups.frequency.max", 24F, 0.5F, 500F, ConfigManager::register); - public static final BooleanValue uptime = new BooleanValue("config.advancedbackups.frequency.uptime", true, ConfigManager::register); - public static final StringArrayValue timesArray = new StringArrayValue("config.advancedbackups.frequency.schedule", new String[]{"1:00"}, ConfigManager::register); - public static final BooleanValue shutdown = new BooleanValue("config.advancedbackups.frequency.shutdown", false, ConfigManager::register); - public static final BooleanValue startup = new BooleanValue("config.advancedbackups.frequency.startup", false, ConfigManager::register); - public static final LongValue delay = new LongValue("config.advancedbackups.frequency.delay", 30, 5, 1000, ConfigManager::register); +public class ConfigManager { + + public static final BooleanValue enabled = new BooleanValue("config.advancedbackups.enabled", true); + public static final BooleanValue save = new BooleanValue("config.advancedbackups.save", true); + public static final BooleanValue toggleSave = new BooleanValue("config.advancedbackups.togglesave", true); + public static final LongValue buffer = new LongValue("config.advancedbackups.buffer", 1048576, 1024, Integer.MAX_VALUE); //5mb + public static final BooleanValue flush = new BooleanValue("config.advancedbackups.flush", false); + public static final BooleanValue activity = new BooleanValue("config.advancedbackups.activity", true); + public static final StringArrayValue blacklist = new StringArrayValue("config.advancedbackups.blacklist", new String[]{"session.lock", "*_old"}); + public static final ValidatedStringValue type = new ValidatedStringValue("config.advancedbackups.type", "differential", new String[]{"zip", "differential", "incremental"}); + public static final FreeStringValue path = new FreeStringValue("config.advancedbackups.path", "./backups"); + public static final FloatValue minFrequency = new FloatValue("config.advancedbackups.frequency.min", 0.25F, 0F, 500F); + public static final FloatValue maxFrequency = new FloatValue("config.advancedbackups.frequency.max", 24F, 0.5F, 500F); + public static final BooleanValue uptime = new BooleanValue("config.advancedbackups.frequency.uptime", true); + public static final StringArrayValue timesArray = new StringArrayValue("config.advancedbackups.frequency.schedule", new String[]{"1:00"}); + public static final BooleanValue shutdown = new BooleanValue("config.advancedbackups.frequency.shutdown", false); + public static final BooleanValue startup = new BooleanValue("config.advancedbackups.frequency.startup", false); + public static final LongValue delay = new LongValue("config.advancedbackups.frequency.delay", 30, 5, 1000); /* * New logging options! * Clients = OPS, ALL, NONE. OPS is default, means operator permission is required. ALL is all clients with the mod. NONE disabled. @@ -59,120 +45,90 @@ public static void register(String key, ConfigTypes configType) { * Console - enable or disable console logging for backup progress. Start / finish are always logged. * Console frequency - how often progress is logged in console. */ - public static final ValidatedStringValue clients = new ValidatedStringValue("config.advancedbackups.logging.clients", "ops", new String[]{"ops", "all", "none"}, ConfigManager::register); - public static final LongValue clientFrequency = new LongValue("config.advancedbackups.logging.clientfrequency", 500L, 0L, Long.MAX_VALUE, ConfigManager::register); - public static final BooleanValue console = new BooleanValue("config.advancedbackups.logging.console", true, ConfigManager::register); - public static final LongValue consoleFrequency = new LongValue("config.advancedbackups.logging.consolefrequency", 5000L, 0L, Long.MAX_VALUE, ConfigManager::register); - public static final LongValue compression = new LongValue("config.advancedbackups.zips.compression", 4, 1, 9, ConfigManager::register); - public static final LongValue length = new LongValue("config.advancedbackups.chains.length", 50, 5, 500, ConfigManager::register); - public static final BooleanValue compressChains = new BooleanValue("config.advancedbackups.chains.compress", true, ConfigManager::register); - public static final BooleanValue smartChains = new BooleanValue("config.advancedbackups.chains.smart", true, ConfigManager::register); - public static final FloatValue chainsPercent = new FloatValue("config.advancedbackups.chains.maxpercent", 50F, 1F, 100F, ConfigManager::register); - public static final FloatValue size = new FloatValue("config.advancedbackups.purge.size", 50F, 0F, Float.MAX_VALUE, ConfigManager::register); - public static final LongValue daysToKeep = new LongValue("config.advancedbackups.purge.days", 0L, 0L, Long.MAX_VALUE, ConfigManager::register); - public static final LongValue backupsToKeep = new LongValue("config.advancedbackups.purge.count", 0L, 0L, Long.MAX_VALUE, ConfigManager::register); - public static final BooleanValue purgeIncrementals = new BooleanValue("config.advancedbackups.purge.incrementals", true, ConfigManager::register); - public static final LongValue incrementalChains = new LongValue("config.advancedbackups.purge.incrementalchains", 1, 1, Long.MAX_VALUE, ConfigManager::register); - - - public static void loadOrCreateConfig() { - // Called when the config needs to be loaded, but one may not exist. - // Creates a new config it one doesn't exist, then loads it. - File dir = new File("./config"); - if (!dir.exists()) { - dir.mkdirs(); - } - File file = new File("./AdvancedBackups.properties"); - if (file.exists()) { - migrateConfig(); - } - file = new File(dir, "AdvancedBackups.properties"); - if (!file.exists()) { - writeConfig(); - } - loadConfig(); - } - - private static void writeConfig() { - // Called to write to a config file. - // Create a complete properties file in the cwd, including any existing changes - ABCore.infoLogger.accept("Preparing to write to properties file..."); - File file = new File("./config/AdvancedBackups.properties"); + public static final ValidatedStringValue clients = new ValidatedStringValue("config.advancedbackups.logging.clients", "ops", new String[]{"ops", "all", "none"}); + public static final LongValue clientFrequency = new LongValue("config.advancedbackups.logging.clientfrequency", 500L, 0L, Long.MAX_VALUE); + public static final BooleanValue console = new BooleanValue("config.advancedbackups.logging.console", true); + public static final LongValue consoleFrequency = new LongValue("config.advancedbackups.logging.consolefrequency", 5000L, 0L, Long.MAX_VALUE); + public static final LongValue compression = new LongValue("config.advancedbackups.zips.compression", 4, 1, 9); + public static final LongValue length = new LongValue("config.advancedbackups.chains.length", 50, 5, 500); + public static final BooleanValue compressChains = new BooleanValue("config.advancedbackups.chains.compress", true); + public static final BooleanValue smartChains = new BooleanValue("config.advancedbackups.chains.smart", true); + public static final FloatValue chainsPercent = new FloatValue("config.advancedbackups.chains.maxpercent", 50F, 1F, 100F); + public static final FloatValue size = new FloatValue("config.advancedbackups.purge.size", 50F, 0F, Float.MAX_VALUE); + public static final LongValue daysToKeep = new LongValue("config.advancedbackups.purge.days", 0L, 0L, Long.MAX_VALUE); + public static final LongValue backupsToKeep = new LongValue("config.advancedbackups.purge.count", 0L, 0L, Long.MAX_VALUE); + public static final BooleanValue purgeIncrementals = new BooleanValue("config.advancedbackups.purge.incrementals", true); + public static final LongValue incrementalChains = new LongValue("config.advancedbackups.purge.incrementalchains", 1, 1, Long.MAX_VALUE); + + + //Make the manager. Chaining! + private static final PremadePropertiesManager MANAGER = new PremadePropertiesManager() + .setConfigLocation(Paths.get("config/Advancedbackups.properties")) + .setPremadeLocation("advancedbackups-properties.txt") + .register( + enabled, save, toggleSave, + buffer, flush, activity, + blacklist, type, path, + minFrequency, maxFrequency, uptime, + timesArray, shutdown, startup, + delay, clients, clientFrequency, + console, consoleFrequency, compression, + length, compressChains, smartChains, + chainsPercent, size, daysToKeep, + backupsToKeep, purgeIncrementals, incrementalChains + ); + + + public static void loadOrCreateConfig() throws IOException { + ArrayList missingProperties = new ArrayList<>(); + ArrayList erroringProperties = new ArrayList<>(); try { - file.createNewFile(); - file.setWritable(true); - InputStream is = ConfigManager.class.getClassLoader().getResourceAsStream("advancedbackups-properties.txt"); - - String text = new BufferedReader(new InputStreamReader(is, StandardCharsets.UTF_8)) - .lines().collect(Collectors.joining("\n")); - - for (String key : entries.keySet()) { - Matcher matcher = Pattern.compile(Pattern.quote(key) + "$", Pattern.MULTILINE).matcher(text); - text = matcher.replaceAll(key + "=" + entries.get(key).save()); - } - - FileWriter writer = new FileWriter(file); - writer.write(text); - writer.close(); - } catch (IOException e) { - // TODO : Scream to user - ABCore.logStackTrace(e); + MANAGER.loadOrCreate((configType, value, exception) -> { + //MissingOptionException is used for config types that don't exist in code. This means we can migrate stuff. + if (exception instanceof MissingOptionException) { + handleMigration(configType, value); + } + else if (exception instanceof MissingValueException) { + missingProperties.add(configType.getKey()); + } + else { + erroringProperties.add(configType.getKey() + exception); + } + }); + } catch (IOException e) { + ABCore.errorLogger.accept("Failed to load config! Cannot proceed due to IO error."); + throw e; + } catch (BaseValidationException e) { + // Nothing to do here. This catch will never trigger. } - } - - private static void loadConfig() { - //Load the config file. - Properties props = new Properties(); - File file = new File("./config/AdvancedBackups.properties"); - FileReader reader; - try { - reader = new FileReader(file); - props.load(reader); - reader.close(); - } catch (IOException e) { - // TODO : Scream to user - ABCore.logStackTrace(e); - return; - } - ArrayList missingProps = new ArrayList<>(); + //We use this flat just so we can ensure the final error message is only logged once. + boolean flag = false; - for (String key : entries.keySet()) { - if (!props.containsKey(key)) { - missingProps.add(key); - ABCore.warningLogger.accept("Missing key : " + key); - continue; + //Now, we have loaded and created with our error handler. But let's make sure we log missing options properly! + if (!missingProperties.isEmpty()) { + flag = true; + ABCore.warningLogger.accept("The following options were missing from the loaded file :"); + for (String string : missingProperties) { + ABCore.warningLogger.accept(string); } - ConfigValidationEnum valid = entries.get(key).validate(props.getProperty(key)); - if (valid != ConfigValidationEnum.VALID) { - missingProps.add(key); - ABCore.warningLogger.accept(valid.getError() + " : " + key); - continue; + } + //And now the same for erroring options. + if (!erroringProperties.isEmpty()) { + ABCore.warningLogger.accept("The following options failed to validate :"); + for (String string : erroringProperties) { + ABCore.warningLogger.accept(string); } - entries.get(key).load(props.getProperty(key)); } - if (props.containsKey("config.advancedbackups.size")) { - ABCore.warningLogger.accept("Migrating old config value :"); - ABCore.warningLogger.accept("config.advancedbackups.size -> config.advancedbackups.purge.size"); + if (flag) ABCore.warningLogger.accept("Config file has been regenerated! Existing config values have been preserved."); - size.load(props.getProperty("config.advancedbackups.size")); - } - - if (!missingProps.isEmpty()) { - ABCore.warningLogger.accept("The following properties were missing from the loaded file :"); - for (String string : missingProps) { - ABCore.warningLogger.accept(string); - } - ABCore.warningLogger.accept("Properties file will be regenerated! Existing config values will be preserved."); - - writeConfig(); - } + //And now for post-load shenanigans. BackupWrapper.configuredPlaytime = new ArrayList<>(); for (String time : timesArray.get()) { String[] hm = time.split(":"); @@ -196,36 +152,11 @@ private static void loadConfig() { } - private static void migrateConfig() { - //Load the config file. - Properties props = new Properties(); - File file = new File("./AdvancedBackups.properties"); - FileReader reader; - try { - reader = new FileReader(file); - props.load(reader); - reader.close(); - file.delete(); - } catch (IOException e) { - // TODO : Scream to user - ABCore.logStackTrace(e); - return; - } - - for (String key : entries.keySet()) { - if (!props.containsKey(key)) { - continue; - } - ConfigValidationEnum valid = entries.get(key).validate(props.getProperty(key)); - if (valid != ConfigValidationEnum.VALID) { - continue; + private static void handleMigration(BaseConfigType configType, String value) { + //For now, do nothing! Migratory code from the past is unneeded now. + ABCore.warningLogger.accept("Discarding unused config option: " + configType.getKey() + " with value: " + value); + } - } - entries.get(key).load(props.getProperty(key)); - } - ABCore.warningLogger.accept("Config in old location detected! Migrating."); - writeConfig(); - } -} \ No newline at end of file +} diff --git a/core/src/main/java/computer/heather/advancedbackups/core/config/ConfigTypes.java b/core/src/main/java/computer/heather/advancedbackups/core/config/ConfigTypes.java deleted file mode 100644 index 97e9b19b..00000000 --- a/core/src/main/java/computer/heather/advancedbackups/core/config/ConfigTypes.java +++ /dev/null @@ -1,251 +0,0 @@ -package computer.heather.advancedbackups.core.config; - -import java.util.Arrays; -import java.util.List; -import java.util.function.BiConsumer; - -public abstract class ConfigTypes { - - private String key; - - - public ConfigTypes(String key, BiConsumer manager) { - this.key = key; - manager.accept(key, this); - } - - public String getKey() { - return key; - } - - public abstract ConfigValidationEnum validate(String in); - - public abstract void load(String in); - - public abstract String save(); - - - public static enum ConfigValidationEnum { - OUT_OF_RANGE, - INCORRECT_FORMAT, - VALID; - - public String getError() { - switch (this) { - case OUT_OF_RANGE: - return "Value not within specified parameters!"; - case INCORRECT_FORMAT: - return "Value is of an incorrect type!"; - default: - return ""; - } - } - } - - - public static class LongValue extends ConfigTypes { - private long value; - private long min; - private long max; - - public LongValue(String key, long defaultValue, long min, long max, BiConsumer manager) { - super(key, manager); - this.value = defaultValue; - this.min = min; - this.max = max; - } - - public long get() { - return value; - } - - @Override - public void load(String in) { - value = Long.parseLong(in); - } - - @Override - public String save() { - return Long.toString(value); - } - - @Override - public ConfigValidationEnum validate(String in) { - long i; - try { - i = Long.parseLong(in); - } catch (NumberFormatException e) { - return ConfigValidationEnum.INCORRECT_FORMAT; - } - - if (i < min || i > max) return ConfigValidationEnum.OUT_OF_RANGE; - - return ConfigValidationEnum.VALID; - } - } - - public static class FloatValue extends ConfigTypes { - private float value; - private float min; - private float max; - - public FloatValue(String key, float defaultValue, float min, float max, BiConsumer manager) { - super(key, manager); - value = defaultValue; - this.min = min; - this.max = max; - } - - @Override - public ConfigValidationEnum validate(String in) { - float i; - try { - i = Float.parseFloat(in); - } catch (NumberFormatException e) { - return ConfigValidationEnum.INCORRECT_FORMAT; - } - - if (i < min || i > max) return ConfigValidationEnum.OUT_OF_RANGE; - - return ConfigValidationEnum.VALID; - } - - @Override - public void load(String in) { - value = Float.parseFloat(in); - } - - @Override - public String save() { - return Float.toString(value); - } - - public Float get() { - return value; - } - } - - public static class BooleanValue extends ConfigTypes { - - private boolean value; - - public BooleanValue(String key, boolean defaultValue, BiConsumer manager) { - super(key, manager); - value = defaultValue; - } - - @Override - public ConfigValidationEnum validate(String in) { - if (in.toLowerCase().equals("false") || in.toLowerCase().equals("true")) return ConfigValidationEnum.VALID; - return ConfigValidationEnum.INCORRECT_FORMAT; - } - - @Override - public void load(String in) { - value = Boolean.parseBoolean(in); - } - - @Override - public String save() { - return Boolean.toString(value); - } - - public Boolean get() { - return value; - } - - } - - public static class ValidatedStringValue extends ConfigTypes { - private String value; - private List allowedStrings; - - - public ValidatedStringValue(String key, String defaultValue, String[] allowedStrings, BiConsumer manager) { - super(key, manager); - value = defaultValue; - this.allowedStrings = Arrays.asList(allowedStrings); - } - - @Override - public ConfigValidationEnum validate(String in) { - if (allowedStrings.contains(in)) return ConfigValidationEnum.VALID; - return ConfigValidationEnum.OUT_OF_RANGE; - } - - - @Override - public void load(String in) { - value = in; - } - - - @Override - public String save() { - return value; - } - - public String get() { - return value; - } - } - - public static class FreeStringValue extends ConfigTypes { - private String value; - - public FreeStringValue(String key, String defaultValue, BiConsumer manager) { - super(key, manager); - value = defaultValue; - } - - @Override - public ConfigValidationEnum validate(String in) { - return ConfigValidationEnum.VALID; - } - - @Override - public void load(String in) { - value = in; - } - - @Override - public String save() { - return value; - } - - public String get() { - return value; - } - } - - public static class StringArrayValue extends ConfigTypes { - private String[] value; - - public StringArrayValue(String key, String[] defaultValue, BiConsumer manager) { - super(key, manager); - value = defaultValue; - } - - @Override - public ConfigValidationEnum validate(String in) { - if (in.length() == 0) return ConfigValidationEnum.OUT_OF_RANGE; - String[] values = in.split(","); - if (values.length == 0) return ConfigValidationEnum.INCORRECT_FORMAT; - return ConfigValidationEnum.VALID; - } - - @Override - public void load(String in) { - value = in.split(","); - } - - @Override - public String save() { - return String.join(",", value); - } - - public String[] get() { - return value; - } - } -} diff --git a/fabric/1.18/src/main/java/computer/heather/advancedbackups/AdvancedBackups.java b/fabric/1.18/src/main/java/computer/heather/advancedbackups/AdvancedBackups.java index 9455cc3d..66c72348 100644 --- a/fabric/1.18/src/main/java/computer/heather/advancedbackups/AdvancedBackups.java +++ b/fabric/1.18/src/main/java/computer/heather/advancedbackups/AdvancedBackups.java @@ -1,6 +1,7 @@ package computer.heather.advancedbackups; import java.io.File; +import java.io.IOException; import java.util.ArrayList; import java.util.List; import java.util.function.Consumer; @@ -66,8 +67,13 @@ public void onInitialize() { ABCore.modJar = new File(FabricLoaderImpl.INSTANCE.getModContainer("advancedbackups").get().getOrigin().getPaths().get(0).toAbsolutePath().toString()); - ConfigManager.loadOrCreateConfig(); - LOGGER.info("Config loaded!!"); + try { + ConfigManager.loadOrCreateConfig(); + LOGGER.info("Config loaded!!"); + } catch (IOException e) { + LOGGER.error("Unable to load config! Falling back to defaults..."); + ABCore.logStackTrace(e); + } }); ServerLifecycleEvents.SERVER_STARTED.register((server) -> { diff --git a/fabric/1.18/src/main/java/computer/heather/advancedbackups/AdvancedBackupsCommand.java b/fabric/1.18/src/main/java/computer/heather/advancedbackups/AdvancedBackupsCommand.java index 1da44b9e..85ae6d06 100644 --- a/fabric/1.18/src/main/java/computer/heather/advancedbackups/AdvancedBackupsCommand.java +++ b/fabric/1.18/src/main/java/computer/heather/advancedbackups/AdvancedBackupsCommand.java @@ -1,9 +1,12 @@ package computer.heather.advancedbackups; +import java.io.IOException; + import com.mojang.brigadier.CommandDispatcher; import com.mojang.brigadier.ParseResults; import com.mojang.brigadier.arguments.StringArgumentType; +import computer.heather.advancedbackups.core.ABCore; import computer.heather.advancedbackups.core.CoreCommandSystem; import net.minecraft.server.command.CommandManager; import net.minecraft.server.command.ServerCommandSource; @@ -21,9 +24,15 @@ public static void register(CommandDispatcher stack) { })) .then(CommandManager.literal("reload-config").executes((runner) -> { - CoreCommandSystem.reloadConfig((response) -> { - runner.getSource().sendFeedback(Text.of(response), true); - }); + try { + CoreCommandSystem.reloadConfig((response) -> { + runner.getSource().sendFeedback(Text.of(response), true); + }); + } catch (IOException e) { + runner.getSource().sendError(Text.of("Command failed to execute! Check log for error")); + ABCore.errorLogger.accept("Error reloading config :"); + ABCore.logStackTrace(e); + } return 1; })) diff --git a/fabric/1.18/src/main/java/computer/heather/advancedbackups/client/AdvancedBackupsClientCommand.java b/fabric/1.18/src/main/java/computer/heather/advancedbackups/client/AdvancedBackupsClientCommand.java index c750a4bf..bc25060a 100644 --- a/fabric/1.18/src/main/java/computer/heather/advancedbackups/client/AdvancedBackupsClientCommand.java +++ b/fabric/1.18/src/main/java/computer/heather/advancedbackups/client/AdvancedBackupsClientCommand.java @@ -1,15 +1,17 @@ package computer.heather.advancedbackups.client; +import java.io.IOException; + import com.mojang.brigadier.ParseResults; import com.mojang.brigadier.arguments.StringArgumentType; +import computer.heather.advancedbackups.core.ABCore; import computer.heather.advancedbackups.core.CoreCommandSystem; import net.fabricmc.fabric.api.client.command.v1.ClientCommandManager; import net.fabricmc.fabric.api.client.command.v1.FabricClientCommandSource; import net.minecraft.client.MinecraftClient; import net.minecraft.network.packet.c2s.play.ChatMessageC2SPacket; -import net.minecraft.server.command.ServerCommandSource; import net.minecraft.text.Text; public class AdvancedBackupsClientCommand { @@ -50,9 +52,15 @@ public static void register() { })) .then(ClientCommandManager.literal("reload-client-config").executes((runner) -> { - CoreCommandSystem.reloadClientConfig((response) -> { - runner.getSource().sendFeedback(Text.of(response)); - }); + try { + CoreCommandSystem.reloadClientConfig((response) -> { + runner.getSource().sendFeedback(Text.of(response)); + }); + } catch (IOException e) { + runner.getSource().sendError(Text.of("Command failed to execute! Check log for error")); + ABCore.errorLogger.accept("Error reloading client config :"); + ABCore.logStackTrace(e); + } return 1; })) diff --git a/fabric/1.18/src/main/java/computer/heather/advancedbackups/client/BackupToast.java b/fabric/1.18/src/main/java/computer/heather/advancedbackups/client/BackupToast.java index 119b6f40..85166b09 100644 --- a/fabric/1.18/src/main/java/computer/heather/advancedbackups/client/BackupToast.java +++ b/fabric/1.18/src/main/java/computer/heather/advancedbackups/client/BackupToast.java @@ -44,7 +44,7 @@ public Visibility draw(MatrixStack matrix, ToastManager manager, long startTime) float percent = finished ? 100 : (float) progress / (float) max; DrawableHelper.fill(matrix, 4, 28, 156, 29, ColourHelper.colour - (255, (int) ClientConfigManager.progressBackgroundRed.get(), (int) ClientConfigManager.progressBackgroundGreen.get(), (int) ClientConfigManager.progressBackgroundBlue.get())); + (255, ClientConfigManager.progressBackgroundRed.get(), ClientConfigManager.progressBackgroundGreen.get(), ClientConfigManager.progressBackgroundBlue.get())); float f = Math.min(156, ( 156 * percent @@ -52,13 +52,13 @@ public Visibility draw(MatrixStack matrix, ToastManager manager, long startTime) if (!exists) { if (title.equals(I18n.translate("advancedbackups.backup_finished"))){ - textColour = ColourHelper.colour(255, (int) ClientConfigManager.progressTextRed.get(), (int) ClientConfigManager.progressTextGreen.get(), (int) ClientConfigManager.progressTextBlue.get()); + textColour = ColourHelper.colour(255, ClientConfigManager.progressTextRed.get(), ClientConfigManager.progressTextGreen.get(), ClientConfigManager.progressTextBlue.get()); manager.getClient().textRenderer.draw(matrix, I18n.translate(title), 25, 11, textColour); DrawableHelper.fill(matrix, 3, 28, 156, 29, ColourHelper.colour - (255, (int) ClientConfigManager.progressBarRed.get(), (int) ClientConfigManager.progressBarGreen.get(), (int) ClientConfigManager.progressBarBlue.get())); + (255, ClientConfigManager.progressBarRed.get(), ClientConfigManager.progressBarGreen.get(), ClientConfigManager.progressBarBlue.get())); } else { - textColour = ColourHelper.colour(255, (int) ClientConfigManager.errorTextRed.get(), (int) ClientConfigManager.errorTextGreen.get(), (int) ClientConfigManager.errorTextBlue.get()); + textColour = ColourHelper.colour(255, ClientConfigManager.errorTextRed.get(), ClientConfigManager.errorTextGreen.get(), ClientConfigManager.errorTextBlue.get()); manager.getClient().textRenderer.draw(matrix, I18n.translate(title), 25, 11, textColour); } return Visibility.HIDE; @@ -68,15 +68,15 @@ public Visibility draw(MatrixStack matrix, ToastManager manager, long startTime) if (starting) { - textColour = ColourHelper.colour(255, (int) ClientConfigManager.progressTextRed.get(), (int) ClientConfigManager.progressTextGreen.get(), (int) ClientConfigManager.progressTextBlue.get()); + textColour = ColourHelper.colour(255, ClientConfigManager.progressTextRed.get(), ClientConfigManager.progressTextGreen.get(), ClientConfigManager.progressTextBlue.get()); title = I18n.translate("advancedbackups.backup_starting"); } else if (started) { - textColour = ColourHelper.colour(255, (int) ClientConfigManager.progressTextRed.get(), (int) ClientConfigManager.progressTextGreen.get(), (int) ClientConfigManager.progressTextBlue.get()); + textColour = ColourHelper.colour(255, ClientConfigManager.progressTextRed.get(), ClientConfigManager.progressTextGreen.get(), ClientConfigManager.progressTextBlue.get()); title = I18n.translate("advancedbackups.progress", round(percent * 100)); } else if (failed) { - textColour = ColourHelper.colour(255, (int) ClientConfigManager.errorTextRed.get(), (int) ClientConfigManager.errorTextGreen.get(), (int) ClientConfigManager.errorTextBlue.get()); + textColour = ColourHelper.colour(255, ClientConfigManager.errorTextRed.get(), ClientConfigManager.errorTextGreen.get(), ClientConfigManager.errorTextBlue.get()); title = I18n.translate("advancedbackups.backup_failed"); if (!timeSet) { time = System.currentTimeMillis(); @@ -84,7 +84,7 @@ else if (failed) { } } else if (finished) { - textColour = ColourHelper.colour(255, (int) ClientConfigManager.progressTextRed.get(), (int) ClientConfigManager.progressTextGreen.get(), (int) ClientConfigManager.progressTextBlue.get()); + textColour = ColourHelper.colour(255, ClientConfigManager.progressTextRed.get(), ClientConfigManager.progressTextGreen.get(), ClientConfigManager.progressTextBlue.get()); title = I18n.translate("advancedbackups.backup_finished"); if (!timeSet) { time = System.currentTimeMillis(); @@ -92,7 +92,7 @@ else if (finished) { } } else if (cancelled) { - textColour = ColourHelper.colour(255, (int) ClientConfigManager.errorTextRed.get(), (int) ClientConfigManager.errorTextGreen.get(), (int) ClientConfigManager.errorTextBlue.get()); + textColour = ColourHelper.colour(255, ClientConfigManager.errorTextRed.get(), ClientConfigManager.errorTextGreen.get(), ClientConfigManager.errorTextBlue.get()); title = I18n.translate("advancedbackups.backup_cancelled"); if (!timeSet) { time = System.currentTimeMillis(); @@ -115,7 +115,7 @@ else if (cancelled) { } DrawableHelper.fill(matrix, 4, 28, Math.max(3, (int) f), 29, ColourHelper.colour - (255, (int) ClientConfigManager.progressBarRed.get(), (int) ClientConfigManager.progressBarGreen.get(), (int) ClientConfigManager.progressBarBlue.get())); + (255, ClientConfigManager.progressBarRed.get().intValue(), ClientConfigManager.progressBarGreen.get().intValue(), ClientConfigManager.progressBarBlue.get().intValue())); return Visibility.SHOW; } diff --git a/fabric/1.18/src/main/java/computer/heather/advancedbackups/client/ClientWrapper.java b/fabric/1.18/src/main/java/computer/heather/advancedbackups/client/ClientWrapper.java index ee9b1ef5..5d61e486 100644 --- a/fabric/1.18/src/main/java/computer/heather/advancedbackups/client/ClientWrapper.java +++ b/fabric/1.18/src/main/java/computer/heather/advancedbackups/client/ClientWrapper.java @@ -1,13 +1,15 @@ package computer.heather.advancedbackups.client; import computer.heather.advancedbackups.core.ABCore; + +import java.io.IOException; + import computer.heather.advancedbackups.AdvancedBackups; import computer.heather.advancedbackups.core.config.ClientConfigManager; import computer.heather.advancedbackups.network.NetworkHandler; import computer.heather.advancedbackups.network.PacketBackupStatus; import computer.heather.advancedbackups.network.PacketToastSubscribe; import net.fabricmc.api.ClientModInitializer; -import net.fabricmc.fabric.api.client.command.v1.ClientCommandManager; import net.fabricmc.fabric.api.client.event.lifecycle.v1.ClientLifecycleEvents; import net.fabricmc.fabric.api.client.networking.v1.ClientPlayConnectionEvents; import net.fabricmc.fabric.api.client.networking.v1.ClientPlayNetworking; @@ -46,7 +48,12 @@ public void onInitializeClient() { ClientPlayNetworking.registerGlobalReceiver(NetworkHandler.STATUS_PACKET_ID, PacketBackupStatus::handle); ClientLifecycleEvents.CLIENT_STARTED.register((client) -> { - ClientConfigManager.loadOrCreateConfig(); + try { + ClientConfigManager.loadOrCreateConfig(); + } catch (IOException e) { + ABCore.errorLogger.accept("Unable to load client config! Default will be used..."); + ABCore.logStackTrace(e); + } }); ClientPlayConnectionEvents.JOIN.register((handler, sender, client) -> { diff --git a/fabric/1.19.2/src/main/java/computer/heather/advancedbackups/AdvancedBackups.java b/fabric/1.19.2/src/main/java/computer/heather/advancedbackups/AdvancedBackups.java index 0e522bf3..4b93b54c 100644 --- a/fabric/1.19.2/src/main/java/computer/heather/advancedbackups/AdvancedBackups.java +++ b/fabric/1.19.2/src/main/java/computer/heather/advancedbackups/AdvancedBackups.java @@ -1,6 +1,7 @@ package computer.heather.advancedbackups; import java.io.File; +import java.io.IOException; import java.util.ArrayList; import java.util.List; import java.util.function.Consumer; @@ -64,7 +65,13 @@ public void onInitialize() { ABCore.modJar = new File(FabricLoaderImpl.INSTANCE.getModContainer("advancedbackups").get().getOrigin().getPaths().get(0).toAbsolutePath().toString()); - ConfigManager.loadOrCreateConfig(); + try { + ConfigManager.loadOrCreateConfig(); + LOGGER.info("Config loaded!!"); + } catch (IOException e) { + LOGGER.error("Unable to load config! Falling back to defaults..."); + ABCore.logStackTrace(e); + } LOGGER.info("Config loaded!!"); }); diff --git a/fabric/1.19.2/src/main/java/computer/heather/advancedbackups/AdvancedBackupsCommand.java b/fabric/1.19.2/src/main/java/computer/heather/advancedbackups/AdvancedBackupsCommand.java index 1da44b9e..85ae6d06 100644 --- a/fabric/1.19.2/src/main/java/computer/heather/advancedbackups/AdvancedBackupsCommand.java +++ b/fabric/1.19.2/src/main/java/computer/heather/advancedbackups/AdvancedBackupsCommand.java @@ -1,9 +1,12 @@ package computer.heather.advancedbackups; +import java.io.IOException; + import com.mojang.brigadier.CommandDispatcher; import com.mojang.brigadier.ParseResults; import com.mojang.brigadier.arguments.StringArgumentType; +import computer.heather.advancedbackups.core.ABCore; import computer.heather.advancedbackups.core.CoreCommandSystem; import net.minecraft.server.command.CommandManager; import net.minecraft.server.command.ServerCommandSource; @@ -21,9 +24,15 @@ public static void register(CommandDispatcher stack) { })) .then(CommandManager.literal("reload-config").executes((runner) -> { - CoreCommandSystem.reloadConfig((response) -> { - runner.getSource().sendFeedback(Text.of(response), true); - }); + try { + CoreCommandSystem.reloadConfig((response) -> { + runner.getSource().sendFeedback(Text.of(response), true); + }); + } catch (IOException e) { + runner.getSource().sendError(Text.of("Command failed to execute! Check log for error")); + ABCore.errorLogger.accept("Error reloading config :"); + ABCore.logStackTrace(e); + } return 1; })) diff --git a/fabric/1.19.2/src/main/java/computer/heather/advancedbackups/client/AdvancedBackupsClientCommand.java b/fabric/1.19.2/src/main/java/computer/heather/advancedbackups/client/AdvancedBackupsClientCommand.java index b16f6b6c..8393240d 100644 --- a/fabric/1.19.2/src/main/java/computer/heather/advancedbackups/client/AdvancedBackupsClientCommand.java +++ b/fabric/1.19.2/src/main/java/computer/heather/advancedbackups/client/AdvancedBackupsClientCommand.java @@ -1,12 +1,14 @@ package computer.heather.advancedbackups.client; +import java.io.IOException; import java.time.Instant; import com.mojang.brigadier.CommandDispatcher; import com.mojang.brigadier.ParseResults; import com.mojang.brigadier.arguments.StringArgumentType; +import computer.heather.advancedbackups.core.ABCore; import computer.heather.advancedbackups.core.CoreCommandSystem; import net.fabricmc.fabric.api.client.command.v2.ClientCommandManager; import net.fabricmc.fabric.api.client.command.v2.FabricClientCommandSource; @@ -60,9 +62,15 @@ public static void register(CommandDispatcher dispatc })) .then(ClientCommandManager.literal("reload-client-config").executes((runner) -> { - CoreCommandSystem.reloadClientConfig((response) -> { - runner.getSource().sendFeedback(Text.of(response)); - }); + try { + CoreCommandSystem.reloadClientConfig((response) -> { + runner.getSource().sendFeedback(Text.of(response)); + }); + } catch (IOException e) { + runner.getSource().sendError(Text.of("Command failed to execute! Check log for error")); + ABCore.errorLogger.accept("Error reloading client config :"); + ABCore.logStackTrace(e); + } return 1; })) diff --git a/fabric/1.19.2/src/main/java/computer/heather/advancedbackups/client/BackupToast.java b/fabric/1.19.2/src/main/java/computer/heather/advancedbackups/client/BackupToast.java index 987d2b0c..e0e17915 100644 --- a/fabric/1.19.2/src/main/java/computer/heather/advancedbackups/client/BackupToast.java +++ b/fabric/1.19.2/src/main/java/computer/heather/advancedbackups/client/BackupToast.java @@ -44,7 +44,7 @@ public Visibility draw(MatrixStack matrix, ToastManager manager, long startTime) float percent = finished ? 100 : (float) progress / (float) max; DrawableHelper.fill(matrix, 4, 28, 156, 29, ColourHelper.colour - (255, (int) ClientConfigManager.progressBackgroundRed.get(), (int) ClientConfigManager.progressBackgroundGreen.get(), (int) ClientConfigManager.progressBackgroundBlue.get())); + (255, ClientConfigManager.progressBackgroundRed.get(), ClientConfigManager.progressBackgroundGreen.get(), ClientConfigManager.progressBackgroundBlue.get())); float f = Math.min(156, ( 156 * percent @@ -52,13 +52,13 @@ public Visibility draw(MatrixStack matrix, ToastManager manager, long startTime) if (!exists) { if (title.equals(I18n.translate("advancedbackups.backup_finished"))){ - textColour = ColourHelper.colour(255, (int) ClientConfigManager.progressTextRed.get(), (int) ClientConfigManager.progressTextGreen.get(), (int) ClientConfigManager.progressTextBlue.get()); + textColour = ColourHelper.colour(255, ClientConfigManager.progressTextRed.get(), ClientConfigManager.progressTextGreen.get(), ClientConfigManager.progressTextBlue.get()); manager.getClient().textRenderer.draw(matrix, I18n.translate(title), 25, 11, textColour); DrawableHelper.fill(matrix, 4, 28, 156, 29, ColourHelper.colour - (255, (int) ClientConfigManager.progressBarRed.get(), (int) ClientConfigManager.progressBarGreen.get(), (int) ClientConfigManager.progressBarBlue.get())); + (255, ClientConfigManager.progressBarRed.get(), ClientConfigManager.progressBarGreen.get(), ClientConfigManager.progressBarBlue.get())); } else { - textColour = ColourHelper.colour(255, (int) ClientConfigManager.errorTextRed.get(), (int) ClientConfigManager.errorTextGreen.get(), (int) ClientConfigManager.errorTextBlue.get()); + textColour = ColourHelper.colour(255, ClientConfigManager.errorTextRed.get(), ClientConfigManager.errorTextGreen.get(), ClientConfigManager.errorTextBlue.get()); manager.getClient().textRenderer.draw(matrix, I18n.translate(title), 25, 11, textColour); } return Visibility.HIDE; @@ -68,15 +68,15 @@ public Visibility draw(MatrixStack matrix, ToastManager manager, long startTime) if (starting) { - textColour = ColourHelper.colour(255, (int) ClientConfigManager.progressTextRed.get(), (int) ClientConfigManager.progressTextGreen.get(), (int) ClientConfigManager.progressTextBlue.get()); + textColour = ColourHelper.colour(255, ClientConfigManager.progressTextRed.get(), ClientConfigManager.progressTextGreen.get(), ClientConfigManager.progressTextBlue.get()); title = I18n.translate("advancedbackups.backup_starting"); } else if (started) { - textColour = ColourHelper.colour(255, (int) ClientConfigManager.progressTextRed.get(), (int) ClientConfigManager.progressTextGreen.get(), (int) ClientConfigManager.progressTextBlue.get()); + textColour = ColourHelper.colour(255, ClientConfigManager.progressTextRed.get(), ClientConfigManager.progressTextGreen.get(), ClientConfigManager.progressTextBlue.get()); title = I18n.translate("advancedbackups.progress", round(percent * 100)); } else if (failed) { - textColour = ColourHelper.colour(255, (int) ClientConfigManager.errorTextRed.get(), (int) ClientConfigManager.errorTextGreen.get(), (int) ClientConfigManager.errorTextBlue.get()); + textColour = ColourHelper.colour(255, ClientConfigManager.errorTextRed.get(), ClientConfigManager.errorTextGreen.get(), ClientConfigManager.errorTextBlue.get()); title = I18n.translate("advancedbackups.backup_failed"); if (!timeSet) { time = System.currentTimeMillis(); @@ -84,7 +84,7 @@ else if (failed) { } } else if (finished) { - textColour = ColourHelper.colour(255, (int) ClientConfigManager.progressTextRed.get(), (int) ClientConfigManager.progressTextGreen.get(), (int) ClientConfigManager.progressTextBlue.get()); + textColour = ColourHelper.colour(255, ClientConfigManager.progressTextRed.get(), ClientConfigManager.progressTextGreen.get(), ClientConfigManager.progressTextBlue.get()); title = I18n.translate("advancedbackups.backup_finished"); if (!timeSet) { time = System.currentTimeMillis(); @@ -92,7 +92,7 @@ else if (finished) { } } else if (cancelled) { - textColour = ColourHelper.colour(255, (int) ClientConfigManager.errorTextRed.get(), (int) ClientConfigManager.errorTextGreen.get(), (int) ClientConfigManager.errorTextBlue.get()); + textColour = ColourHelper.colour(255, ClientConfigManager.errorTextRed.get(), ClientConfigManager.errorTextGreen.get(), ClientConfigManager.errorTextBlue.get()); title = I18n.translate("advancedbackups.backup_cancelled"); if (!timeSet) { time = System.currentTimeMillis(); @@ -115,7 +115,7 @@ else if (cancelled) { } DrawableHelper.fill(matrix, 4, 28, Math.max(3, (int) f), 29, ColourHelper.colour - (255, (int) ClientConfigManager.progressBarRed.get(), (int) ClientConfigManager.progressBarGreen.get(), (int) ClientConfigManager.progressBarBlue.get())); + (255, ClientConfigManager.progressBarRed.get(), ClientConfigManager.progressBarGreen.get(), ClientConfigManager.progressBarBlue.get())); return Visibility.SHOW; } diff --git a/fabric/1.19.2/src/main/java/computer/heather/advancedbackups/client/ClientWrapper.java b/fabric/1.19.2/src/main/java/computer/heather/advancedbackups/client/ClientWrapper.java index a4fa758a..0c3006bb 100644 --- a/fabric/1.19.2/src/main/java/computer/heather/advancedbackups/client/ClientWrapper.java +++ b/fabric/1.19.2/src/main/java/computer/heather/advancedbackups/client/ClientWrapper.java @@ -1,5 +1,7 @@ package computer.heather.advancedbackups.client; +import java.io.IOException; + import computer.heather.advancedbackups.AdvancedBackups; import computer.heather.advancedbackups.core.ABCore; import computer.heather.advancedbackups.core.config.ClientConfigManager; @@ -28,7 +30,12 @@ public void onInitializeClient() { ClientPlayNetworking.registerGlobalReceiver(NetworkHandler.STATUS_PACKET_ID, ClientWrapper::handle); ClientLifecycleEvents.CLIENT_STARTED.register((client) -> { - ClientConfigManager.loadOrCreateConfig(); + try { + ClientConfigManager.loadOrCreateConfig(); + } catch (IOException e) { + ABCore.errorLogger.accept("Unable to load client config! Default will be used..."); + ABCore.logStackTrace(e); + } }); ClientPlayConnectionEvents.JOIN.register((handler, sender, client) -> { diff --git a/fabric/1.19.3/src/main/java/computer/heather/advancedbackups/AdvancedBackups.java b/fabric/1.19.3/src/main/java/computer/heather/advancedbackups/AdvancedBackups.java index 0e522bf3..66c72348 100644 --- a/fabric/1.19.3/src/main/java/computer/heather/advancedbackups/AdvancedBackups.java +++ b/fabric/1.19.3/src/main/java/computer/heather/advancedbackups/AdvancedBackups.java @@ -1,6 +1,7 @@ package computer.heather.advancedbackups; import java.io.File; +import java.io.IOException; import java.util.ArrayList; import java.util.List; import java.util.function.Consumer; @@ -16,7 +17,7 @@ import computer.heather.advancedbackups.network.NetworkHandler; import computer.heather.advancedbackups.network.PacketToastSubscribe; import net.fabricmc.api.ModInitializer; -import net.fabricmc.fabric.api.command.v2.CommandRegistrationCallback; +import net.fabricmc.fabric.api.command.v1.CommandRegistrationCallback; import net.fabricmc.fabric.api.event.lifecycle.v1.ServerLifecycleEvents; import net.fabricmc.fabric.api.event.lifecycle.v1.ServerTickEvents; import net.fabricmc.fabric.api.networking.v1.ServerPlayConnectionEvents; @@ -37,14 +38,15 @@ public class AdvancedBackups implements ModInitializer { public static final Consumer infoLogger = LOGGER::info; public static final Consumer warningLogger = LOGGER::warn; public static final Consumer errorLogger = LOGGER::error; - - public static final ArrayList players = new ArrayList<>(); public static MinecraftServer server; + + public static final ArrayList players = new ArrayList<>(); @Override public void onInitialize() { + ServerLifecycleEvents.SERVER_STARTING.register((server) -> { AdvancedBackups.server = server; ABCore.worldName = server.getSaveProperties().getLevelName(); @@ -61,11 +63,17 @@ public void onInitialize() { ABCore.resetActivity = AdvancedBackups::resetActivity; ABCore.clientContactor = new ClientContactor(); + ABCore.modJar = new File(FabricLoaderImpl.INSTANCE.getModContainer("advancedbackups").get().getOrigin().getPaths().get(0).toAbsolutePath().toString()); - ConfigManager.loadOrCreateConfig(); - LOGGER.info("Config loaded!!"); + try { + ConfigManager.loadOrCreateConfig(); + LOGGER.info("Config loaded!!"); + } catch (IOException e) { + LOGGER.error("Unable to load config! Falling back to defaults..."); + ABCore.logStackTrace(e); + } }); ServerLifecycleEvents.SERVER_STARTED.register((server) -> { @@ -79,17 +87,17 @@ public void onInitialize() { ABCore.setActivity(true); }); - CommandRegistrationCallback.EVENT.register((dispatcher, registryAccess, environment) -> { + CommandRegistrationCallback.EVENT.register((dispatcher, isDedicated) -> { AdvancedBackupsCommand.register(dispatcher); }); + ServerTickEvents.END_SERVER_TICK.register((server) -> { BackupTimer.check(); }); ServerPlayNetworking.registerGlobalReceiver(NetworkHandler.TOAST_SUBSCRIBE_ID, PacketToastSubscribe::handle); - } diff --git a/fabric/1.19.3/src/main/java/computer/heather/advancedbackups/AdvancedBackupsCommand.java b/fabric/1.19.3/src/main/java/computer/heather/advancedbackups/AdvancedBackupsCommand.java index ac96fc59..7c30cf02 100644 --- a/fabric/1.19.3/src/main/java/computer/heather/advancedbackups/AdvancedBackupsCommand.java +++ b/fabric/1.19.3/src/main/java/computer/heather/advancedbackups/AdvancedBackupsCommand.java @@ -1,9 +1,12 @@ package computer.heather.advancedbackups; +import java.io.IOException; + import com.mojang.brigadier.CommandDispatcher; import com.mojang.brigadier.ParseResults; import com.mojang.brigadier.arguments.StringArgumentType; +import computer.heather.advancedbackups.core.ABCore; import computer.heather.advancedbackups.core.CoreCommandSystem; import net.minecraft.server.command.CommandManager; import net.minecraft.server.command.ServerCommandSource; @@ -21,9 +24,15 @@ public static void register(CommandDispatcher stack) { })) .then(CommandManager.literal("reload-config").executes((runner) -> { - CoreCommandSystem.reloadConfig((response) -> { - runner.getSource().sendFeedback(Text.of(response), true); - }); + try { + CoreCommandSystem.reloadConfig((response) -> { + runner.getSource().sendFeedback(Text.of(response), true); + }); + } catch (IOException e) { + runner.getSource().sendError(Text.of("Command failed to execute! Check log for error")); + ABCore.errorLogger.accept("Error reloading config :"); + ABCore.logStackTrace(e); + } return 1; })) diff --git a/fabric/1.19.3/src/main/java/computer/heather/advancedbackups/client/AdvancedBackupsClientCommand.java b/fabric/1.19.3/src/main/java/computer/heather/advancedbackups/client/AdvancedBackupsClientCommand.java index 990c6257..95fabb66 100644 --- a/fabric/1.19.3/src/main/java/computer/heather/advancedbackups/client/AdvancedBackupsClientCommand.java +++ b/fabric/1.19.3/src/main/java/computer/heather/advancedbackups/client/AdvancedBackupsClientCommand.java @@ -1,12 +1,14 @@ package computer.heather.advancedbackups.client; +import java.io.IOException; import java.time.Instant; import com.mojang.brigadier.CommandDispatcher; import com.mojang.brigadier.ParseResults; import com.mojang.brigadier.arguments.StringArgumentType; +import computer.heather.advancedbackups.core.ABCore; import computer.heather.advancedbackups.core.CoreCommandSystem; import net.fabricmc.fabric.api.client.command.v2.ClientCommandManager; import net.fabricmc.fabric.api.client.command.v2.FabricClientCommandSource; @@ -59,9 +61,15 @@ public static void register(CommandDispatcher dispatc })) .then(ClientCommandManager.literal("reload-client-config").executes((runner) -> { - CoreCommandSystem.reloadClientConfig((response) -> { - runner.getSource().sendFeedback(Text.of(response)); - }); + try { + CoreCommandSystem.reloadClientConfig((response) -> { + runner.getSource().sendFeedback(Text.of(response)); + }); + } catch (IOException e) { + runner.getSource().sendError(Text.of("Command failed to execute! Check log for error")); + ABCore.errorLogger.accept("Error reloading client config :"); + ABCore.logStackTrace(e); + } return 1; })) diff --git a/fabric/1.19.3/src/main/java/computer/heather/advancedbackups/client/BackupToast.java b/fabric/1.19.3/src/main/java/computer/heather/advancedbackups/client/BackupToast.java index 79c4b01a..81beccc4 100644 --- a/fabric/1.19.3/src/main/java/computer/heather/advancedbackups/client/BackupToast.java +++ b/fabric/1.19.3/src/main/java/computer/heather/advancedbackups/client/BackupToast.java @@ -42,7 +42,7 @@ public Visibility draw(MatrixStack matrix, ToastManager manager, long startTime) float percent = finished ? 100 : (float) progress / (float) max; DrawableHelper.fill(matrix, 4, 28, 156, 29, ColourHelper.colour - (255, (int) ClientConfigManager.progressBackgroundRed.get(), (int) ClientConfigManager.progressBackgroundGreen.get(), (int) ClientConfigManager.progressBackgroundBlue.get())); + (255, ClientConfigManager.progressBackgroundRed.get(), ClientConfigManager.progressBackgroundGreen.get(), ClientConfigManager.progressBackgroundBlue.get())); float f = Math.min(156, ( 156 * percent @@ -51,13 +51,13 @@ public Visibility draw(MatrixStack matrix, ToastManager manager, long startTime) if (!exists) { if (title.equals(I18n.translate("advancedbackups.backup_finished"))){ - textColour = ColourHelper.colour(255, (int) ClientConfigManager.progressTextRed.get(), (int) ClientConfigManager.progressTextGreen.get(), (int) ClientConfigManager.progressTextBlue.get()); + textColour = ColourHelper.colour(255, ClientConfigManager.progressTextRed.get(), ClientConfigManager.progressTextGreen.get(), ClientConfigManager.progressTextBlue.get()); manager.getClient().textRenderer.draw(matrix, I18n.translate(title), 25, 11, textColour); DrawableHelper.fill(matrix, 4, 28, 156, 29, ColourHelper.colour - (255, (int) ClientConfigManager.progressBarRed.get(), (int) ClientConfigManager.progressBarGreen.get(), (int) ClientConfigManager.progressBarBlue.get())); + (255, ClientConfigManager.progressBarRed.get(), ClientConfigManager.progressBarGreen.get(), ClientConfigManager.progressBarBlue.get())); } else { - textColour = ColourHelper.colour(255, (int) ClientConfigManager.errorTextRed.get(), (int) ClientConfigManager.errorTextGreen.get(), (int) ClientConfigManager.errorTextBlue.get()); + textColour = ColourHelper.colour(255, ClientConfigManager.errorTextRed.get(), ClientConfigManager.errorTextGreen.get(), ClientConfigManager.errorTextBlue.get()); manager.getClient().textRenderer.draw(matrix, I18n.translate(title), 25, 11, textColour); } return Visibility.HIDE; @@ -67,15 +67,15 @@ public Visibility draw(MatrixStack matrix, ToastManager manager, long startTime) if (starting) { - textColour = ColourHelper.colour(255, (int) ClientConfigManager.progressTextRed.get(), (int) ClientConfigManager.progressTextGreen.get(), (int) ClientConfigManager.progressTextBlue.get()); + textColour = ColourHelper.colour(255, ClientConfigManager.progressTextRed.get(), ClientConfigManager.progressTextGreen.get(), ClientConfigManager.progressTextBlue.get()); title = I18n.translate("advancedbackups.backup_starting"); } else if (started) { - textColour = ColourHelper.colour(255, (int) ClientConfigManager.progressTextRed.get(), (int) ClientConfigManager.progressTextGreen.get(), (int) ClientConfigManager.progressTextBlue.get()); + textColour = ColourHelper.colour(255, ClientConfigManager.progressTextRed.get(), ClientConfigManager.progressTextGreen.get(), ClientConfigManager.progressTextBlue.get()); title = I18n.translate("advancedbackups.progress", round(percent * 100)); } else if (failed) { - textColour = ColourHelper.colour(255, (int) ClientConfigManager.errorTextRed.get(), (int) ClientConfigManager.errorTextGreen.get(), (int) ClientConfigManager.errorTextBlue.get()); + textColour = ColourHelper.colour(255, ClientConfigManager.errorTextRed.get(), ClientConfigManager.errorTextGreen.get(), ClientConfigManager.errorTextBlue.get()); title = I18n.translate("advancedbackups.backup_failed"); if (!timeSet) { time = System.currentTimeMillis(); @@ -83,7 +83,7 @@ else if (failed) { } } else if (finished) { - textColour = ColourHelper.colour(255, (int) ClientConfigManager.progressTextRed.get(), (int) ClientConfigManager.progressTextGreen.get(), (int) ClientConfigManager.progressTextBlue.get()); + textColour = ColourHelper.colour(255, ClientConfigManager.progressTextRed.get(), ClientConfigManager.progressTextGreen.get(), ClientConfigManager.progressTextBlue.get()); title = I18n.translate("advancedbackups.backup_finished"); if (!timeSet) { time = System.currentTimeMillis(); @@ -91,7 +91,7 @@ else if (finished) { } } else if (cancelled) { - textColour = ColourHelper.colour(255, (int) ClientConfigManager.errorTextRed.get(), (int) ClientConfigManager.errorTextGreen.get(), (int) ClientConfigManager.errorTextBlue.get()); + textColour = ColourHelper.colour(255, ClientConfigManager.errorTextRed.get(), ClientConfigManager.errorTextGreen.get(), ClientConfigManager.errorTextBlue.get()); title = I18n.translate("advancedbackups.backup_cancelled"); if (!timeSet) { time = System.currentTimeMillis(); @@ -115,7 +115,7 @@ else if (cancelled) { } DrawableHelper.fill(matrix, 4, 28, Math.max(4, (int) f), 29, ColourHelper.colour - (255, (int) ClientConfigManager.progressBarRed.get(), (int) ClientConfigManager.progressBarGreen.get(), (int) ClientConfigManager.progressBarBlue.get())); + (255, ClientConfigManager.progressBarRed.get(), ClientConfigManager.progressBarGreen.get(), ClientConfigManager.progressBarBlue.get())); return Visibility.SHOW; } diff --git a/fabric/1.19.3/src/main/java/computer/heather/advancedbackups/client/ClientWrapper.java b/fabric/1.19.3/src/main/java/computer/heather/advancedbackups/client/ClientWrapper.java index a4fa758a..0c3006bb 100644 --- a/fabric/1.19.3/src/main/java/computer/heather/advancedbackups/client/ClientWrapper.java +++ b/fabric/1.19.3/src/main/java/computer/heather/advancedbackups/client/ClientWrapper.java @@ -1,5 +1,7 @@ package computer.heather.advancedbackups.client; +import java.io.IOException; + import computer.heather.advancedbackups.AdvancedBackups; import computer.heather.advancedbackups.core.ABCore; import computer.heather.advancedbackups.core.config.ClientConfigManager; @@ -28,7 +30,12 @@ public void onInitializeClient() { ClientPlayNetworking.registerGlobalReceiver(NetworkHandler.STATUS_PACKET_ID, ClientWrapper::handle); ClientLifecycleEvents.CLIENT_STARTED.register((client) -> { - ClientConfigManager.loadOrCreateConfig(); + try { + ClientConfigManager.loadOrCreateConfig(); + } catch (IOException e) { + ABCore.errorLogger.accept("Unable to load client config! Default will be used..."); + ABCore.logStackTrace(e); + } }); ClientPlayConnectionEvents.JOIN.register((handler, sender, client) -> { diff --git a/fabric/1.20.2/src/main/java/computer/heather/advancedbackups/AdvancedBackups.java b/fabric/1.20.2/src/main/java/computer/heather/advancedbackups/AdvancedBackups.java index d363d006..0595b547 100644 --- a/fabric/1.20.2/src/main/java/computer/heather/advancedbackups/AdvancedBackups.java +++ b/fabric/1.20.2/src/main/java/computer/heather/advancedbackups/AdvancedBackups.java @@ -1,6 +1,7 @@ package computer.heather.advancedbackups; import java.io.File; +import java.io.IOException; import java.util.ArrayList; import java.util.List; import java.util.function.Consumer; @@ -64,8 +65,13 @@ public void onInitialize() { ABCore.modJar = new File(FabricLoaderImpl.INSTANCE.getModContainer("advancedbackups").get().getOrigin().getPaths().get(0).toAbsolutePath().toString()); - ConfigManager.loadOrCreateConfig(); - LOGGER.info("Config loaded!!"); + try { + ConfigManager.loadOrCreateConfig(); + LOGGER.info("Config loaded!!"); + } catch (IOException e) { + LOGGER.error("Unable to load config! Falling back to defaults..."); + ABCore.logStackTrace(e); + } }); ServerLifecycleEvents.SERVER_STARTED.register((server) -> { diff --git a/fabric/1.20.2/src/main/java/computer/heather/advancedbackups/AdvancedBackupsCommand.java b/fabric/1.20.2/src/main/java/computer/heather/advancedbackups/AdvancedBackupsCommand.java index 31f75a23..c8096eac 100644 --- a/fabric/1.20.2/src/main/java/computer/heather/advancedbackups/AdvancedBackupsCommand.java +++ b/fabric/1.20.2/src/main/java/computer/heather/advancedbackups/AdvancedBackupsCommand.java @@ -1,9 +1,12 @@ package computer.heather.advancedbackups; +import java.io.IOException; + import com.mojang.brigadier.CommandDispatcher; import com.mojang.brigadier.ParseResults; import com.mojang.brigadier.arguments.StringArgumentType; +import computer.heather.advancedbackups.core.ABCore; import computer.heather.advancedbackups.core.CoreCommandSystem; import net.minecraft.server.command.CommandManager; import net.minecraft.server.command.ServerCommandSource; @@ -21,9 +24,15 @@ public static void register(CommandDispatcher stack) { })) .then(CommandManager.literal("reload-config").executes((runner) -> { - CoreCommandSystem.reloadConfig((response) -> { - runner.getSource().sendFeedback(() -> Text.of(response), true); - }); + try { + CoreCommandSystem.reloadConfig((response) -> { + runner.getSource().sendFeedback(() -> Text.of(response), true); + }); + } catch (IOException e) { + runner.getSource().sendError(Text.of("Command failed to execute! Check log for error")); + ABCore.errorLogger.accept("Error reloading config :"); + ABCore.logStackTrace(e); + } return 1; })) diff --git a/fabric/1.20.2/src/main/java/computer/heather/advancedbackups/client/AdvancedBackupsClientCommand.java b/fabric/1.20.2/src/main/java/computer/heather/advancedbackups/client/AdvancedBackupsClientCommand.java index 990c6257..95fabb66 100644 --- a/fabric/1.20.2/src/main/java/computer/heather/advancedbackups/client/AdvancedBackupsClientCommand.java +++ b/fabric/1.20.2/src/main/java/computer/heather/advancedbackups/client/AdvancedBackupsClientCommand.java @@ -1,12 +1,14 @@ package computer.heather.advancedbackups.client; +import java.io.IOException; import java.time.Instant; import com.mojang.brigadier.CommandDispatcher; import com.mojang.brigadier.ParseResults; import com.mojang.brigadier.arguments.StringArgumentType; +import computer.heather.advancedbackups.core.ABCore; import computer.heather.advancedbackups.core.CoreCommandSystem; import net.fabricmc.fabric.api.client.command.v2.ClientCommandManager; import net.fabricmc.fabric.api.client.command.v2.FabricClientCommandSource; @@ -59,9 +61,15 @@ public static void register(CommandDispatcher dispatc })) .then(ClientCommandManager.literal("reload-client-config").executes((runner) -> { - CoreCommandSystem.reloadClientConfig((response) -> { - runner.getSource().sendFeedback(Text.of(response)); - }); + try { + CoreCommandSystem.reloadClientConfig((response) -> { + runner.getSource().sendFeedback(Text.of(response)); + }); + } catch (IOException e) { + runner.getSource().sendError(Text.of("Command failed to execute! Check log for error")); + ABCore.errorLogger.accept("Error reloading client config :"); + ABCore.logStackTrace(e); + } return 1; })) diff --git a/fabric/1.20.2/src/main/java/computer/heather/advancedbackups/client/BackupToast.java b/fabric/1.20.2/src/main/java/computer/heather/advancedbackups/client/BackupToast.java index 1c38169c..2a39343f 100644 --- a/fabric/1.20.2/src/main/java/computer/heather/advancedbackups/client/BackupToast.java +++ b/fabric/1.20.2/src/main/java/computer/heather/advancedbackups/client/BackupToast.java @@ -45,7 +45,7 @@ public Visibility draw(DrawContext context, ToastManager manager, long startTime float percent = finished ? 100 : (float) progress / (float) max; context.fill(4, 28, 156, 29, ColourHelper.colour - (255, (int) ClientConfigManager.progressBackgroundRed.get(), (int) ClientConfigManager.progressBackgroundGreen.get(), (int) ClientConfigManager.progressBackgroundBlue.get())); + (255, ClientConfigManager.progressBackgroundRed.get(), ClientConfigManager.progressBackgroundGreen.get(), ClientConfigManager.progressBackgroundBlue.get())); float f = Math.min(156, ( 156 * percent @@ -53,13 +53,13 @@ public Visibility draw(DrawContext context, ToastManager manager, long startTime if (!exists) { if (title.equals(I18n.translate("advancedbackups.backup_finished"))){ - textColour = ColourHelper.colour(255, (int) ClientConfigManager.progressTextRed.get(), (int) ClientConfigManager.progressTextGreen.get(), (int) ClientConfigManager.progressTextBlue.get()); + textColour = ColourHelper.colour(255, ClientConfigManager.progressTextRed.get(), ClientConfigManager.progressTextGreen.get(), ClientConfigManager.progressTextBlue.get()); context.drawText(manager.getClient().textRenderer, I18n.translate(title), 25, 11, textColour, false); context.fill(4, 28, 156, 29, ColourHelper.colour - (255, (int) ClientConfigManager.progressBarRed.get(), (int) ClientConfigManager.progressBarGreen.get(), (int) ClientConfigManager.progressBarBlue.get())); + (255, ClientConfigManager.progressBarRed.get(), ClientConfigManager.progressBarGreen.get(), ClientConfigManager.progressBarBlue.get())); } else { - textColour = ColourHelper.colour(255, (int) ClientConfigManager.errorTextRed.get(), (int) ClientConfigManager.errorTextGreen.get(), (int) ClientConfigManager.errorTextBlue.get()); + textColour = ColourHelper.colour(255, ClientConfigManager.errorTextRed.get(), ClientConfigManager.errorTextGreen.get(), ClientConfigManager.errorTextBlue.get()); context.drawText(manager.getClient().textRenderer, I18n.translate(title), 25, 11, textColour, false); } return Visibility.HIDE; @@ -69,15 +69,15 @@ public Visibility draw(DrawContext context, ToastManager manager, long startTime if (starting) { - textColour = ColourHelper.colour(255, (int) ClientConfigManager.progressTextRed.get(), (int) ClientConfigManager.progressTextGreen.get(), (int) ClientConfigManager.progressTextBlue.get()); + textColour = ColourHelper.colour(255, ClientConfigManager.progressTextRed.get(), ClientConfigManager.progressTextGreen.get(), ClientConfigManager.progressTextBlue.get()); title = I18n.translate("advancedbackups.backup_starting"); } else if (started) { - textColour = ColourHelper.colour(255, (int) ClientConfigManager.progressTextRed.get(), (int) ClientConfigManager.progressTextGreen.get(), (int) ClientConfigManager.progressTextBlue.get()); + textColour = ColourHelper.colour(255, ClientConfigManager.progressTextRed.get(), ClientConfigManager.progressTextGreen.get(), ClientConfigManager.progressTextBlue.get()); title = I18n.translate("advancedbackups.progress", round(percent * 100)); } else if (failed) { - textColour = ColourHelper.colour(255, (int) ClientConfigManager.errorTextRed.get(), (int) ClientConfigManager.errorTextGreen.get(), (int) ClientConfigManager.errorTextBlue.get()); + textColour = ColourHelper.colour(255, ClientConfigManager.errorTextRed.get(), ClientConfigManager.errorTextGreen.get(), ClientConfigManager.errorTextBlue.get()); title = I18n.translate("advancedbackups.backup_failed"); if (!timeSet) { time = System.currentTimeMillis(); @@ -85,7 +85,7 @@ else if (failed) { } } else if (finished) { - textColour = ColourHelper.colour(255, (int) ClientConfigManager.progressTextRed.get(), (int) ClientConfigManager.progressTextGreen.get(), (int) ClientConfigManager.progressTextBlue.get()); + textColour = ColourHelper.colour(255, ClientConfigManager.progressTextRed.get(), ClientConfigManager.progressTextGreen.get(), ClientConfigManager.progressTextBlue.get()); title = I18n.translate("advancedbackups.backup_finished"); if (!timeSet) { time = System.currentTimeMillis(); @@ -93,7 +93,7 @@ else if (finished) { } } else if (cancelled) { - textColour = ColourHelper.colour(255, (int) ClientConfigManager.errorTextRed.get(), (int) ClientConfigManager.errorTextGreen.get(), (int) ClientConfigManager.errorTextBlue.get()); + textColour = ColourHelper.colour(255, ClientConfigManager.errorTextRed.get(), ClientConfigManager.errorTextGreen.get(), ClientConfigManager.errorTextBlue.get()); title = I18n.translate("advancedbackups.backup_cancelled"); if (!timeSet) { time = System.currentTimeMillis(); @@ -116,7 +116,7 @@ else if (cancelled) { } context.fill(4, 28, Math.max(4, (int) f), 29, ColourHelper.colour - (255, (int) ClientConfigManager.progressBarRed.get(), (int) ClientConfigManager.progressBarGreen.get(), (int) ClientConfigManager.progressBarBlue.get())); + (255, ClientConfigManager.progressBarRed.get(), ClientConfigManager.progressBarGreen.get(), ClientConfigManager.progressBarBlue.get())); return Visibility.SHOW; } diff --git a/fabric/1.20.2/src/main/java/computer/heather/advancedbackups/client/ClientWrapper.java b/fabric/1.20.2/src/main/java/computer/heather/advancedbackups/client/ClientWrapper.java index a4fa758a..0c3006bb 100644 --- a/fabric/1.20.2/src/main/java/computer/heather/advancedbackups/client/ClientWrapper.java +++ b/fabric/1.20.2/src/main/java/computer/heather/advancedbackups/client/ClientWrapper.java @@ -1,5 +1,7 @@ package computer.heather.advancedbackups.client; +import java.io.IOException; + import computer.heather.advancedbackups.AdvancedBackups; import computer.heather.advancedbackups.core.ABCore; import computer.heather.advancedbackups.core.config.ClientConfigManager; @@ -28,7 +30,12 @@ public void onInitializeClient() { ClientPlayNetworking.registerGlobalReceiver(NetworkHandler.STATUS_PACKET_ID, ClientWrapper::handle); ClientLifecycleEvents.CLIENT_STARTED.register((client) -> { - ClientConfigManager.loadOrCreateConfig(); + try { + ClientConfigManager.loadOrCreateConfig(); + } catch (IOException e) { + ABCore.errorLogger.accept("Unable to load client config! Default will be used..."); + ABCore.logStackTrace(e); + } }); ClientPlayConnectionEvents.JOIN.register((handler, sender, client) -> { diff --git a/fabric/1.20.6/src/main/java/computer/heather/advancedbackups/AdvancedBackups.java b/fabric/1.20.6/src/main/java/computer/heather/advancedbackups/AdvancedBackups.java index 5710d4e8..0fcd63b2 100644 --- a/fabric/1.20.6/src/main/java/computer/heather/advancedbackups/AdvancedBackups.java +++ b/fabric/1.20.6/src/main/java/computer/heather/advancedbackups/AdvancedBackups.java @@ -1,6 +1,7 @@ package computer.heather.advancedbackups; import java.io.File; +import java.io.IOException; import java.util.ArrayList; import java.util.List; import java.util.function.Consumer; @@ -65,8 +66,13 @@ public void onInitialize() { ABCore.modJar = new File(FabricLoaderImpl.INSTANCE.getModContainer("advancedbackups").get().getOrigin().getPaths().get(0).toAbsolutePath().toString()); - ConfigManager.loadOrCreateConfig(); - LOGGER.info("Config loaded!!"); + try { + ConfigManager.loadOrCreateConfig(); + LOGGER.info("Config loaded!!"); + } catch (IOException e) { + LOGGER.error("Unable to load config! Falling back to defaults..."); + ABCore.logStackTrace(e); + } }); ServerLifecycleEvents.SERVER_STARTED.register((server) -> { diff --git a/fabric/1.20.6/src/main/java/computer/heather/advancedbackups/AdvancedBackupsCommand.java b/fabric/1.20.6/src/main/java/computer/heather/advancedbackups/AdvancedBackupsCommand.java index 31f75a23..c8096eac 100644 --- a/fabric/1.20.6/src/main/java/computer/heather/advancedbackups/AdvancedBackupsCommand.java +++ b/fabric/1.20.6/src/main/java/computer/heather/advancedbackups/AdvancedBackupsCommand.java @@ -1,9 +1,12 @@ package computer.heather.advancedbackups; +import java.io.IOException; + import com.mojang.brigadier.CommandDispatcher; import com.mojang.brigadier.ParseResults; import com.mojang.brigadier.arguments.StringArgumentType; +import computer.heather.advancedbackups.core.ABCore; import computer.heather.advancedbackups.core.CoreCommandSystem; import net.minecraft.server.command.CommandManager; import net.minecraft.server.command.ServerCommandSource; @@ -21,9 +24,15 @@ public static void register(CommandDispatcher stack) { })) .then(CommandManager.literal("reload-config").executes((runner) -> { - CoreCommandSystem.reloadConfig((response) -> { - runner.getSource().sendFeedback(() -> Text.of(response), true); - }); + try { + CoreCommandSystem.reloadConfig((response) -> { + runner.getSource().sendFeedback(() -> Text.of(response), true); + }); + } catch (IOException e) { + runner.getSource().sendError(Text.of("Command failed to execute! Check log for error")); + ABCore.errorLogger.accept("Error reloading config :"); + ABCore.logStackTrace(e); + } return 1; })) diff --git a/fabric/1.20.6/src/main/java/computer/heather/advancedbackups/client/AdvancedBackupsClientCommand.java b/fabric/1.20.6/src/main/java/computer/heather/advancedbackups/client/AdvancedBackupsClientCommand.java index 67478c3a..8153c1ad 100644 --- a/fabric/1.20.6/src/main/java/computer/heather/advancedbackups/client/AdvancedBackupsClientCommand.java +++ b/fabric/1.20.6/src/main/java/computer/heather/advancedbackups/client/AdvancedBackupsClientCommand.java @@ -1,10 +1,13 @@ package computer.heather.advancedbackups.client; +import java.io.IOException; + import com.mojang.brigadier.CommandDispatcher; import com.mojang.brigadier.ParseResults; import com.mojang.brigadier.arguments.StringArgumentType; +import computer.heather.advancedbackups.core.ABCore; import computer.heather.advancedbackups.core.CoreCommandSystem; import net.fabricmc.fabric.api.client.command.v2.ClientCommandManager; import net.fabricmc.fabric.api.client.command.v2.FabricClientCommandSource; @@ -49,9 +52,15 @@ public static void register(CommandDispatcher dispatc })) .then(ClientCommandManager.literal("reload-client-config").executes((runner) -> { - CoreCommandSystem.reloadClientConfig((response) -> { - runner.getSource().sendFeedback(Text.of(response)); - }); + try { + CoreCommandSystem.reloadClientConfig((response) -> { + runner.getSource().sendFeedback(Text.of(response)); + }); + } catch (IOException e) { + runner.getSource().sendError(Text.of("Command failed to execute! Check log for error")); + ABCore.errorLogger.accept("Error reloading client config :"); + ABCore.logStackTrace(e); + } return 1; })) diff --git a/fabric/1.20.6/src/main/java/computer/heather/advancedbackups/client/BackupToast.java b/fabric/1.20.6/src/main/java/computer/heather/advancedbackups/client/BackupToast.java index 1c38169c..2a39343f 100644 --- a/fabric/1.20.6/src/main/java/computer/heather/advancedbackups/client/BackupToast.java +++ b/fabric/1.20.6/src/main/java/computer/heather/advancedbackups/client/BackupToast.java @@ -45,7 +45,7 @@ public Visibility draw(DrawContext context, ToastManager manager, long startTime float percent = finished ? 100 : (float) progress / (float) max; context.fill(4, 28, 156, 29, ColourHelper.colour - (255, (int) ClientConfigManager.progressBackgroundRed.get(), (int) ClientConfigManager.progressBackgroundGreen.get(), (int) ClientConfigManager.progressBackgroundBlue.get())); + (255, ClientConfigManager.progressBackgroundRed.get(), ClientConfigManager.progressBackgroundGreen.get(), ClientConfigManager.progressBackgroundBlue.get())); float f = Math.min(156, ( 156 * percent @@ -53,13 +53,13 @@ public Visibility draw(DrawContext context, ToastManager manager, long startTime if (!exists) { if (title.equals(I18n.translate("advancedbackups.backup_finished"))){ - textColour = ColourHelper.colour(255, (int) ClientConfigManager.progressTextRed.get(), (int) ClientConfigManager.progressTextGreen.get(), (int) ClientConfigManager.progressTextBlue.get()); + textColour = ColourHelper.colour(255, ClientConfigManager.progressTextRed.get(), ClientConfigManager.progressTextGreen.get(), ClientConfigManager.progressTextBlue.get()); context.drawText(manager.getClient().textRenderer, I18n.translate(title), 25, 11, textColour, false); context.fill(4, 28, 156, 29, ColourHelper.colour - (255, (int) ClientConfigManager.progressBarRed.get(), (int) ClientConfigManager.progressBarGreen.get(), (int) ClientConfigManager.progressBarBlue.get())); + (255, ClientConfigManager.progressBarRed.get(), ClientConfigManager.progressBarGreen.get(), ClientConfigManager.progressBarBlue.get())); } else { - textColour = ColourHelper.colour(255, (int) ClientConfigManager.errorTextRed.get(), (int) ClientConfigManager.errorTextGreen.get(), (int) ClientConfigManager.errorTextBlue.get()); + textColour = ColourHelper.colour(255, ClientConfigManager.errorTextRed.get(), ClientConfigManager.errorTextGreen.get(), ClientConfigManager.errorTextBlue.get()); context.drawText(manager.getClient().textRenderer, I18n.translate(title), 25, 11, textColour, false); } return Visibility.HIDE; @@ -69,15 +69,15 @@ public Visibility draw(DrawContext context, ToastManager manager, long startTime if (starting) { - textColour = ColourHelper.colour(255, (int) ClientConfigManager.progressTextRed.get(), (int) ClientConfigManager.progressTextGreen.get(), (int) ClientConfigManager.progressTextBlue.get()); + textColour = ColourHelper.colour(255, ClientConfigManager.progressTextRed.get(), ClientConfigManager.progressTextGreen.get(), ClientConfigManager.progressTextBlue.get()); title = I18n.translate("advancedbackups.backup_starting"); } else if (started) { - textColour = ColourHelper.colour(255, (int) ClientConfigManager.progressTextRed.get(), (int) ClientConfigManager.progressTextGreen.get(), (int) ClientConfigManager.progressTextBlue.get()); + textColour = ColourHelper.colour(255, ClientConfigManager.progressTextRed.get(), ClientConfigManager.progressTextGreen.get(), ClientConfigManager.progressTextBlue.get()); title = I18n.translate("advancedbackups.progress", round(percent * 100)); } else if (failed) { - textColour = ColourHelper.colour(255, (int) ClientConfigManager.errorTextRed.get(), (int) ClientConfigManager.errorTextGreen.get(), (int) ClientConfigManager.errorTextBlue.get()); + textColour = ColourHelper.colour(255, ClientConfigManager.errorTextRed.get(), ClientConfigManager.errorTextGreen.get(), ClientConfigManager.errorTextBlue.get()); title = I18n.translate("advancedbackups.backup_failed"); if (!timeSet) { time = System.currentTimeMillis(); @@ -85,7 +85,7 @@ else if (failed) { } } else if (finished) { - textColour = ColourHelper.colour(255, (int) ClientConfigManager.progressTextRed.get(), (int) ClientConfigManager.progressTextGreen.get(), (int) ClientConfigManager.progressTextBlue.get()); + textColour = ColourHelper.colour(255, ClientConfigManager.progressTextRed.get(), ClientConfigManager.progressTextGreen.get(), ClientConfigManager.progressTextBlue.get()); title = I18n.translate("advancedbackups.backup_finished"); if (!timeSet) { time = System.currentTimeMillis(); @@ -93,7 +93,7 @@ else if (finished) { } } else if (cancelled) { - textColour = ColourHelper.colour(255, (int) ClientConfigManager.errorTextRed.get(), (int) ClientConfigManager.errorTextGreen.get(), (int) ClientConfigManager.errorTextBlue.get()); + textColour = ColourHelper.colour(255, ClientConfigManager.errorTextRed.get(), ClientConfigManager.errorTextGreen.get(), ClientConfigManager.errorTextBlue.get()); title = I18n.translate("advancedbackups.backup_cancelled"); if (!timeSet) { time = System.currentTimeMillis(); @@ -116,7 +116,7 @@ else if (cancelled) { } context.fill(4, 28, Math.max(4, (int) f), 29, ColourHelper.colour - (255, (int) ClientConfigManager.progressBarRed.get(), (int) ClientConfigManager.progressBarGreen.get(), (int) ClientConfigManager.progressBarBlue.get())); + (255, ClientConfigManager.progressBarRed.get(), ClientConfigManager.progressBarGreen.get(), ClientConfigManager.progressBarBlue.get())); return Visibility.SHOW; } diff --git a/fabric/1.20.6/src/main/java/computer/heather/advancedbackups/client/ClientWrapper.java b/fabric/1.20.6/src/main/java/computer/heather/advancedbackups/client/ClientWrapper.java index b137a58a..d1b90d9c 100644 --- a/fabric/1.20.6/src/main/java/computer/heather/advancedbackups/client/ClientWrapper.java +++ b/fabric/1.20.6/src/main/java/computer/heather/advancedbackups/client/ClientWrapper.java @@ -1,5 +1,7 @@ package computer.heather.advancedbackups.client; +import java.io.IOException; + import computer.heather.advancedbackups.AdvancedBackups; import computer.heather.advancedbackups.core.ABCore; import computer.heather.advancedbackups.core.config.ClientConfigManager; @@ -22,7 +24,12 @@ public void onInitializeClient() { ABCore.errorLogger = AdvancedBackups.errorLogger; ClientLifecycleEvents.CLIENT_STARTED.register((client) -> { - ClientConfigManager.loadOrCreateConfig(); + try { + ClientConfigManager.loadOrCreateConfig(); + } catch (IOException e) { + ABCore.errorLogger.accept("Unable to load client config! Default will be used..."); + ABCore.logStackTrace(e); + } }); ClientPlayConnectionEvents.JOIN.register((handler, sender, client) -> { diff --git a/fabric/1.20/src/main/java/computer/heather/advancedbackups/AdvancedBackups.java b/fabric/1.20/src/main/java/computer/heather/advancedbackups/AdvancedBackups.java index d363d006..0595b547 100644 --- a/fabric/1.20/src/main/java/computer/heather/advancedbackups/AdvancedBackups.java +++ b/fabric/1.20/src/main/java/computer/heather/advancedbackups/AdvancedBackups.java @@ -1,6 +1,7 @@ package computer.heather.advancedbackups; import java.io.File; +import java.io.IOException; import java.util.ArrayList; import java.util.List; import java.util.function.Consumer; @@ -64,8 +65,13 @@ public void onInitialize() { ABCore.modJar = new File(FabricLoaderImpl.INSTANCE.getModContainer("advancedbackups").get().getOrigin().getPaths().get(0).toAbsolutePath().toString()); - ConfigManager.loadOrCreateConfig(); - LOGGER.info("Config loaded!!"); + try { + ConfigManager.loadOrCreateConfig(); + LOGGER.info("Config loaded!!"); + } catch (IOException e) { + LOGGER.error("Unable to load config! Falling back to defaults..."); + ABCore.logStackTrace(e); + } }); ServerLifecycleEvents.SERVER_STARTED.register((server) -> { diff --git a/fabric/1.20/src/main/java/computer/heather/advancedbackups/AdvancedBackupsCommand.java b/fabric/1.20/src/main/java/computer/heather/advancedbackups/AdvancedBackupsCommand.java index 31f75a23..c8096eac 100644 --- a/fabric/1.20/src/main/java/computer/heather/advancedbackups/AdvancedBackupsCommand.java +++ b/fabric/1.20/src/main/java/computer/heather/advancedbackups/AdvancedBackupsCommand.java @@ -1,9 +1,12 @@ package computer.heather.advancedbackups; +import java.io.IOException; + import com.mojang.brigadier.CommandDispatcher; import com.mojang.brigadier.ParseResults; import com.mojang.brigadier.arguments.StringArgumentType; +import computer.heather.advancedbackups.core.ABCore; import computer.heather.advancedbackups.core.CoreCommandSystem; import net.minecraft.server.command.CommandManager; import net.minecraft.server.command.ServerCommandSource; @@ -21,9 +24,15 @@ public static void register(CommandDispatcher stack) { })) .then(CommandManager.literal("reload-config").executes((runner) -> { - CoreCommandSystem.reloadConfig((response) -> { - runner.getSource().sendFeedback(() -> Text.of(response), true); - }); + try { + CoreCommandSystem.reloadConfig((response) -> { + runner.getSource().sendFeedback(() -> Text.of(response), true); + }); + } catch (IOException e) { + runner.getSource().sendError(Text.of("Command failed to execute! Check log for error")); + ABCore.errorLogger.accept("Error reloading config :"); + ABCore.logStackTrace(e); + } return 1; })) diff --git a/fabric/1.20/src/main/java/computer/heather/advancedbackups/client/AdvancedBackupsClientCommand.java b/fabric/1.20/src/main/java/computer/heather/advancedbackups/client/AdvancedBackupsClientCommand.java index 990c6257..95fabb66 100644 --- a/fabric/1.20/src/main/java/computer/heather/advancedbackups/client/AdvancedBackupsClientCommand.java +++ b/fabric/1.20/src/main/java/computer/heather/advancedbackups/client/AdvancedBackupsClientCommand.java @@ -1,12 +1,14 @@ package computer.heather.advancedbackups.client; +import java.io.IOException; import java.time.Instant; import com.mojang.brigadier.CommandDispatcher; import com.mojang.brigadier.ParseResults; import com.mojang.brigadier.arguments.StringArgumentType; +import computer.heather.advancedbackups.core.ABCore; import computer.heather.advancedbackups.core.CoreCommandSystem; import net.fabricmc.fabric.api.client.command.v2.ClientCommandManager; import net.fabricmc.fabric.api.client.command.v2.FabricClientCommandSource; @@ -59,9 +61,15 @@ public static void register(CommandDispatcher dispatc })) .then(ClientCommandManager.literal("reload-client-config").executes((runner) -> { - CoreCommandSystem.reloadClientConfig((response) -> { - runner.getSource().sendFeedback(Text.of(response)); - }); + try { + CoreCommandSystem.reloadClientConfig((response) -> { + runner.getSource().sendFeedback(Text.of(response)); + }); + } catch (IOException e) { + runner.getSource().sendError(Text.of("Command failed to execute! Check log for error")); + ABCore.errorLogger.accept("Error reloading client config :"); + ABCore.logStackTrace(e); + } return 1; })) diff --git a/fabric/1.20/src/main/java/computer/heather/advancedbackups/client/BackupToast.java b/fabric/1.20/src/main/java/computer/heather/advancedbackups/client/BackupToast.java index e1e6330c..5600c34e 100644 --- a/fabric/1.20/src/main/java/computer/heather/advancedbackups/client/BackupToast.java +++ b/fabric/1.20/src/main/java/computer/heather/advancedbackups/client/BackupToast.java @@ -43,7 +43,7 @@ public Visibility draw(DrawContext context, ToastManager manager, long startTime float percent = finished ? 100 : (float) progress / (float) max; context.fill(4, 28, 156, 29, ColourHelper.colour - (255, (int) ClientConfigManager.progressBackgroundRed.get(), (int) ClientConfigManager.progressBackgroundGreen.get(), (int) ClientConfigManager.progressBackgroundBlue.get())); + (255, ClientConfigManager.progressBackgroundRed.get(), ClientConfigManager.progressBackgroundGreen.get(), ClientConfigManager.progressBackgroundBlue.get())); float f = Math.min(156, ( 156 * percent @@ -51,13 +51,13 @@ public Visibility draw(DrawContext context, ToastManager manager, long startTime if (!exists) { if (title.equals(I18n.translate("advancedbackups.backup_finished"))){ - textColour = ColourHelper.colour(255, (int) ClientConfigManager.progressTextRed.get(), (int) ClientConfigManager.progressTextGreen.get(), (int) ClientConfigManager.progressTextBlue.get()); + textColour = ColourHelper.colour(255, ClientConfigManager.progressTextRed.get(), ClientConfigManager.progressTextGreen.get(), ClientConfigManager.progressTextBlue.get()); context.drawText(manager.getClient().textRenderer, I18n.translate(title), 25, 11, textColour, false); context.fill(4, 28, 156, 29, ColourHelper.colour - (255, (int) ClientConfigManager.progressBarRed.get(), (int) ClientConfigManager.progressBarGreen.get(), (int) ClientConfigManager.progressBarBlue.get())); + (255, ClientConfigManager.progressBarRed.get(), ClientConfigManager.progressBarGreen.get(), ClientConfigManager.progressBarBlue.get())); } else { - textColour = ColourHelper.colour(255, (int) ClientConfigManager.errorTextRed.get(), (int) ClientConfigManager.errorTextGreen.get(), (int) ClientConfigManager.errorTextBlue.get()); + textColour = ColourHelper.colour(255, ClientConfigManager.errorTextRed.get(), ClientConfigManager.errorTextGreen.get(), ClientConfigManager.errorTextBlue.get()); context.drawText(manager.getClient().textRenderer, I18n.translate(title), 25, 11, textColour, false); } return Visibility.HIDE; @@ -67,15 +67,15 @@ public Visibility draw(DrawContext context, ToastManager manager, long startTime if (starting) { - textColour = ColourHelper.colour(255, (int) ClientConfigManager.progressTextRed.get(), (int) ClientConfigManager.progressTextGreen.get(), (int) ClientConfigManager.progressTextBlue.get()); + textColour = ColourHelper.colour(255, ClientConfigManager.progressTextRed.get(), ClientConfigManager.progressTextGreen.get(), ClientConfigManager.progressTextBlue.get()); title = I18n.translate("advancedbackups.backup_starting"); } else if (started) { - textColour = ColourHelper.colour(255, (int) ClientConfigManager.progressTextRed.get(), (int) ClientConfigManager.progressTextGreen.get(), (int) ClientConfigManager.progressTextBlue.get()); + textColour = ColourHelper.colour(255, ClientConfigManager.progressTextRed.get(), ClientConfigManager.progressTextGreen.get(), ClientConfigManager.progressTextBlue.get()); title = I18n.translate("advancedbackups.progress", round(percent * 100)); } else if (failed) { - textColour = ColourHelper.colour(255, (int) ClientConfigManager.errorTextRed.get(), (int) ClientConfigManager.errorTextGreen.get(), (int) ClientConfigManager.errorTextBlue.get()); + textColour = ColourHelper.colour(255, ClientConfigManager.errorTextRed.get(), ClientConfigManager.errorTextGreen.get(), ClientConfigManager.errorTextBlue.get()); title = I18n.translate("advancedbackups.backup_failed"); if (!timeSet) { time = System.currentTimeMillis(); @@ -83,7 +83,7 @@ else if (failed) { } } else if (finished) { - textColour = ColourHelper.colour(255, (int) ClientConfigManager.progressTextRed.get(), (int) ClientConfigManager.progressTextGreen.get(), (int) ClientConfigManager.progressTextBlue.get()); + textColour = ColourHelper.colour(255, ClientConfigManager.progressTextRed.get(), ClientConfigManager.progressTextGreen.get(), ClientConfigManager.progressTextBlue.get()); title = I18n.translate("advancedbackups.backup_finished"); if (!timeSet) { time = System.currentTimeMillis(); @@ -91,7 +91,7 @@ else if (finished) { } } else if (cancelled) { - textColour = ColourHelper.colour(255, (int) ClientConfigManager.errorTextRed.get(), (int) ClientConfigManager.errorTextGreen.get(), (int) ClientConfigManager.errorTextBlue.get()); + textColour = ColourHelper.colour(255, ClientConfigManager.errorTextRed.get(), ClientConfigManager.errorTextGreen.get(), ClientConfigManager.errorTextBlue.get()); title = I18n.translate("advancedbackups.backup_cancelled"); if (!timeSet) { time = System.currentTimeMillis(); @@ -114,7 +114,7 @@ else if (cancelled) { } context.fill(4, 28, Math.max(4, (int) f), 29, ColourHelper.colour - (255, (int) ClientConfigManager.progressBarRed.get(), (int) ClientConfigManager.progressBarGreen.get(), (int) ClientConfigManager.progressBarBlue.get())); + (255, ClientConfigManager.progressBarRed.get(), ClientConfigManager.progressBarGreen.get(), ClientConfigManager.progressBarBlue.get())); return Visibility.SHOW; } diff --git a/fabric/1.20/src/main/java/computer/heather/advancedbackups/client/ClientWrapper.java b/fabric/1.20/src/main/java/computer/heather/advancedbackups/client/ClientWrapper.java index a4fa758a..0c3006bb 100644 --- a/fabric/1.20/src/main/java/computer/heather/advancedbackups/client/ClientWrapper.java +++ b/fabric/1.20/src/main/java/computer/heather/advancedbackups/client/ClientWrapper.java @@ -1,5 +1,7 @@ package computer.heather.advancedbackups.client; +import java.io.IOException; + import computer.heather.advancedbackups.AdvancedBackups; import computer.heather.advancedbackups.core.ABCore; import computer.heather.advancedbackups.core.config.ClientConfigManager; @@ -28,7 +30,12 @@ public void onInitializeClient() { ClientPlayNetworking.registerGlobalReceiver(NetworkHandler.STATUS_PACKET_ID, ClientWrapper::handle); ClientLifecycleEvents.CLIENT_STARTED.register((client) -> { - ClientConfigManager.loadOrCreateConfig(); + try { + ClientConfigManager.loadOrCreateConfig(); + } catch (IOException e) { + ABCore.errorLogger.accept("Unable to load client config! Default will be used..."); + ABCore.logStackTrace(e); + } }); ClientPlayConnectionEvents.JOIN.register((handler, sender, client) -> { diff --git a/fabric/1.21.2/src/main/java/computer/heather/advancedbackups/AdvancedBackups.java b/fabric/1.21.2/src/main/java/computer/heather/advancedbackups/AdvancedBackups.java index 5710d4e8..0fcd63b2 100644 --- a/fabric/1.21.2/src/main/java/computer/heather/advancedbackups/AdvancedBackups.java +++ b/fabric/1.21.2/src/main/java/computer/heather/advancedbackups/AdvancedBackups.java @@ -1,6 +1,7 @@ package computer.heather.advancedbackups; import java.io.File; +import java.io.IOException; import java.util.ArrayList; import java.util.List; import java.util.function.Consumer; @@ -65,8 +66,13 @@ public void onInitialize() { ABCore.modJar = new File(FabricLoaderImpl.INSTANCE.getModContainer("advancedbackups").get().getOrigin().getPaths().get(0).toAbsolutePath().toString()); - ConfigManager.loadOrCreateConfig(); - LOGGER.info("Config loaded!!"); + try { + ConfigManager.loadOrCreateConfig(); + LOGGER.info("Config loaded!!"); + } catch (IOException e) { + LOGGER.error("Unable to load config! Falling back to defaults..."); + ABCore.logStackTrace(e); + } }); ServerLifecycleEvents.SERVER_STARTED.register((server) -> { diff --git a/fabric/1.21.2/src/main/java/computer/heather/advancedbackups/AdvancedBackupsCommand.java b/fabric/1.21.2/src/main/java/computer/heather/advancedbackups/AdvancedBackupsCommand.java index 31f75a23..c8096eac 100644 --- a/fabric/1.21.2/src/main/java/computer/heather/advancedbackups/AdvancedBackupsCommand.java +++ b/fabric/1.21.2/src/main/java/computer/heather/advancedbackups/AdvancedBackupsCommand.java @@ -1,9 +1,12 @@ package computer.heather.advancedbackups; +import java.io.IOException; + import com.mojang.brigadier.CommandDispatcher; import com.mojang.brigadier.ParseResults; import com.mojang.brigadier.arguments.StringArgumentType; +import computer.heather.advancedbackups.core.ABCore; import computer.heather.advancedbackups.core.CoreCommandSystem; import net.minecraft.server.command.CommandManager; import net.minecraft.server.command.ServerCommandSource; @@ -21,9 +24,15 @@ public static void register(CommandDispatcher stack) { })) .then(CommandManager.literal("reload-config").executes((runner) -> { - CoreCommandSystem.reloadConfig((response) -> { - runner.getSource().sendFeedback(() -> Text.of(response), true); - }); + try { + CoreCommandSystem.reloadConfig((response) -> { + runner.getSource().sendFeedback(() -> Text.of(response), true); + }); + } catch (IOException e) { + runner.getSource().sendError(Text.of("Command failed to execute! Check log for error")); + ABCore.errorLogger.accept("Error reloading config :"); + ABCore.logStackTrace(e); + } return 1; })) diff --git a/fabric/1.21.2/src/main/java/computer/heather/advancedbackups/client/AdvancedBackupsClientCommand.java b/fabric/1.21.2/src/main/java/computer/heather/advancedbackups/client/AdvancedBackupsClientCommand.java index 67478c3a..8153c1ad 100644 --- a/fabric/1.21.2/src/main/java/computer/heather/advancedbackups/client/AdvancedBackupsClientCommand.java +++ b/fabric/1.21.2/src/main/java/computer/heather/advancedbackups/client/AdvancedBackupsClientCommand.java @@ -1,10 +1,13 @@ package computer.heather.advancedbackups.client; +import java.io.IOException; + import com.mojang.brigadier.CommandDispatcher; import com.mojang.brigadier.ParseResults; import com.mojang.brigadier.arguments.StringArgumentType; +import computer.heather.advancedbackups.core.ABCore; import computer.heather.advancedbackups.core.CoreCommandSystem; import net.fabricmc.fabric.api.client.command.v2.ClientCommandManager; import net.fabricmc.fabric.api.client.command.v2.FabricClientCommandSource; @@ -49,9 +52,15 @@ public static void register(CommandDispatcher dispatc })) .then(ClientCommandManager.literal("reload-client-config").executes((runner) -> { - CoreCommandSystem.reloadClientConfig((response) -> { - runner.getSource().sendFeedback(Text.of(response)); - }); + try { + CoreCommandSystem.reloadClientConfig((response) -> { + runner.getSource().sendFeedback(Text.of(response)); + }); + } catch (IOException e) { + runner.getSource().sendError(Text.of("Command failed to execute! Check log for error")); + ABCore.errorLogger.accept("Error reloading client config :"); + ABCore.logStackTrace(e); + } return 1; })) diff --git a/fabric/1.21.2/src/main/java/computer/heather/advancedbackups/client/BackupToast.java b/fabric/1.21.2/src/main/java/computer/heather/advancedbackups/client/BackupToast.java index 90471bb5..037ae978 100644 --- a/fabric/1.21.2/src/main/java/computer/heather/advancedbackups/client/BackupToast.java +++ b/fabric/1.21.2/src/main/java/computer/heather/advancedbackups/client/BackupToast.java @@ -45,7 +45,7 @@ public void draw(DrawContext context, TextRenderer renderer, long startTime) { float percent = finished ? 100 : (float) progress / (float) max; context.fill(4, 28, 156, 29, ColourHelper.colour - (255, (int) ClientConfigManager.progressBackgroundRed.get(), (int) ClientConfigManager.progressBackgroundGreen.get(), (int) ClientConfigManager.progressBackgroundBlue.get())); + (255, ClientConfigManager.progressBackgroundRed.get(), ClientConfigManager.progressBackgroundGreen.get(), ClientConfigManager.progressBackgroundBlue.get())); float f = Math.min(156, ( 156 * percent @@ -53,13 +53,13 @@ public void draw(DrawContext context, TextRenderer renderer, long startTime) { if (!exists) { if (title.equals(I18n.translate("advancedbackups.backup_finished"))){ - textColour = ColourHelper.colour(255, (int) ClientConfigManager.progressTextRed.get(), (int) ClientConfigManager.progressTextGreen.get(), (int) ClientConfigManager.progressTextBlue.get()); + textColour = ColourHelper.colour(255, ClientConfigManager.progressTextRed.get(), ClientConfigManager.progressTextGreen.get(), ClientConfigManager.progressTextBlue.get()); context.drawText(renderer, I18n.translate(title), 25, 11, textColour, false); context.fill(4, 28, 156, 29, ColourHelper.colour - (255, (int) ClientConfigManager.progressBarRed.get(), (int) ClientConfigManager.progressBarGreen.get(), (int) ClientConfigManager.progressBarBlue.get())); + (255, ClientConfigManager.progressBarRed.get(), ClientConfigManager.progressBarGreen.get(), ClientConfigManager.progressBarBlue.get())); } else { - textColour = ColourHelper.colour(255, (int) ClientConfigManager.errorTextRed.get(), (int) ClientConfigManager.errorTextGreen.get(), (int) ClientConfigManager.errorTextBlue.get()); + textColour = ColourHelper.colour(255, ClientConfigManager.errorTextRed.get(), ClientConfigManager.errorTextGreen.get(), ClientConfigManager.errorTextBlue.get()); context.drawText(renderer, I18n.translate(title), 25, 11, textColour, false); } visibility = Visibility.HIDE; @@ -70,15 +70,15 @@ public void draw(DrawContext context, TextRenderer renderer, long startTime) { if (starting) { - textColour = ColourHelper.colour(255, (int) ClientConfigManager.progressTextRed.get(), (int) ClientConfigManager.progressTextGreen.get(), (int) ClientConfigManager.progressTextBlue.get()); + textColour = ColourHelper.colour(255, ClientConfigManager.progressTextRed.get(), ClientConfigManager.progressTextGreen.get(), ClientConfigManager.progressTextBlue.get()); title = I18n.translate("advancedbackups.backup_starting"); } else if (started) { - textColour = ColourHelper.colour(255, (int) ClientConfigManager.progressTextRed.get(), (int) ClientConfigManager.progressTextGreen.get(), (int) ClientConfigManager.progressTextBlue.get()); + textColour = ColourHelper.colour(255, ClientConfigManager.progressTextRed.get(), ClientConfigManager.progressTextGreen.get(), ClientConfigManager.progressTextBlue.get()); title = I18n.translate("advancedbackups.progress", round(percent * 100)); } else if (failed) { - textColour = ColourHelper.colour(255, (int) ClientConfigManager.errorTextRed.get(), (int) ClientConfigManager.errorTextGreen.get(), (int) ClientConfigManager.errorTextBlue.get()); + textColour = ColourHelper.colour(255, ClientConfigManager.errorTextRed.get(), ClientConfigManager.errorTextGreen.get(), ClientConfigManager.errorTextBlue.get()); title = I18n.translate("advancedbackups.backup_failed"); if (!timeSet) { time = System.currentTimeMillis(); @@ -86,7 +86,7 @@ else if (failed) { } } else if (finished) { - textColour = ColourHelper.colour(255, (int) ClientConfigManager.progressTextRed.get(), (int) ClientConfigManager.progressTextGreen.get(), (int) ClientConfigManager.progressTextBlue.get()); + textColour = ColourHelper.colour(255, ClientConfigManager.progressTextRed.get(), ClientConfigManager.progressTextGreen.get(), ClientConfigManager.progressTextBlue.get()); title = I18n.translate("advancedbackups.backup_finished"); if (!timeSet) { time = System.currentTimeMillis(); @@ -94,7 +94,7 @@ else if (finished) { } } else if (cancelled) { - textColour = ColourHelper.colour(255, (int) ClientConfigManager.errorTextRed.get(), (int) ClientConfigManager.errorTextGreen.get(), (int) ClientConfigManager.errorTextBlue.get()); + textColour = ColourHelper.colour(255, ClientConfigManager.errorTextRed.get(), ClientConfigManager.errorTextGreen.get(), ClientConfigManager.errorTextBlue.get()); title = I18n.translate("advancedbackups.backup_cancelled"); if (!timeSet) { time = System.currentTimeMillis(); @@ -118,7 +118,7 @@ else if (cancelled) { } context.fill(4, 28, Math.max(4, (int) f), 29, ColourHelper.colour - (255, (int) ClientConfigManager.progressBarRed.get(), (int) ClientConfigManager.progressBarGreen.get(), (int) ClientConfigManager.progressBarBlue.get())); + (255, ClientConfigManager.progressBarRed.get(), ClientConfigManager.progressBarGreen.get(), ClientConfigManager.progressBarBlue.get())); visibility = Visibility.SHOW; } diff --git a/fabric/1.21.2/src/main/java/computer/heather/advancedbackups/client/ClientWrapper.java b/fabric/1.21.2/src/main/java/computer/heather/advancedbackups/client/ClientWrapper.java index b137a58a..d1b90d9c 100644 --- a/fabric/1.21.2/src/main/java/computer/heather/advancedbackups/client/ClientWrapper.java +++ b/fabric/1.21.2/src/main/java/computer/heather/advancedbackups/client/ClientWrapper.java @@ -1,5 +1,7 @@ package computer.heather.advancedbackups.client; +import java.io.IOException; + import computer.heather.advancedbackups.AdvancedBackups; import computer.heather.advancedbackups.core.ABCore; import computer.heather.advancedbackups.core.config.ClientConfigManager; @@ -22,7 +24,12 @@ public void onInitializeClient() { ABCore.errorLogger = AdvancedBackups.errorLogger; ClientLifecycleEvents.CLIENT_STARTED.register((client) -> { - ClientConfigManager.loadOrCreateConfig(); + try { + ClientConfigManager.loadOrCreateConfig(); + } catch (IOException e) { + ABCore.errorLogger.accept("Unable to load client config! Default will be used..."); + ABCore.logStackTrace(e); + } }); ClientPlayConnectionEvents.JOIN.register((handler, sender, client) -> { diff --git a/fabric/1.21/src/main/java/computer/heather/advancedbackups/AdvancedBackups.java b/fabric/1.21/src/main/java/computer/heather/advancedbackups/AdvancedBackups.java index 5710d4e8..0fcd63b2 100644 --- a/fabric/1.21/src/main/java/computer/heather/advancedbackups/AdvancedBackups.java +++ b/fabric/1.21/src/main/java/computer/heather/advancedbackups/AdvancedBackups.java @@ -1,6 +1,7 @@ package computer.heather.advancedbackups; import java.io.File; +import java.io.IOException; import java.util.ArrayList; import java.util.List; import java.util.function.Consumer; @@ -65,8 +66,13 @@ public void onInitialize() { ABCore.modJar = new File(FabricLoaderImpl.INSTANCE.getModContainer("advancedbackups").get().getOrigin().getPaths().get(0).toAbsolutePath().toString()); - ConfigManager.loadOrCreateConfig(); - LOGGER.info("Config loaded!!"); + try { + ConfigManager.loadOrCreateConfig(); + LOGGER.info("Config loaded!!"); + } catch (IOException e) { + LOGGER.error("Unable to load config! Falling back to defaults..."); + ABCore.logStackTrace(e); + } }); ServerLifecycleEvents.SERVER_STARTED.register((server) -> { diff --git a/fabric/1.21/src/main/java/computer/heather/advancedbackups/AdvancedBackupsCommand.java b/fabric/1.21/src/main/java/computer/heather/advancedbackups/AdvancedBackupsCommand.java index 31f75a23..c8096eac 100644 --- a/fabric/1.21/src/main/java/computer/heather/advancedbackups/AdvancedBackupsCommand.java +++ b/fabric/1.21/src/main/java/computer/heather/advancedbackups/AdvancedBackupsCommand.java @@ -1,9 +1,12 @@ package computer.heather.advancedbackups; +import java.io.IOException; + import com.mojang.brigadier.CommandDispatcher; import com.mojang.brigadier.ParseResults; import com.mojang.brigadier.arguments.StringArgumentType; +import computer.heather.advancedbackups.core.ABCore; import computer.heather.advancedbackups.core.CoreCommandSystem; import net.minecraft.server.command.CommandManager; import net.minecraft.server.command.ServerCommandSource; @@ -21,9 +24,15 @@ public static void register(CommandDispatcher stack) { })) .then(CommandManager.literal("reload-config").executes((runner) -> { - CoreCommandSystem.reloadConfig((response) -> { - runner.getSource().sendFeedback(() -> Text.of(response), true); - }); + try { + CoreCommandSystem.reloadConfig((response) -> { + runner.getSource().sendFeedback(() -> Text.of(response), true); + }); + } catch (IOException e) { + runner.getSource().sendError(Text.of("Command failed to execute! Check log for error")); + ABCore.errorLogger.accept("Error reloading config :"); + ABCore.logStackTrace(e); + } return 1; })) diff --git a/fabric/1.21/src/main/java/computer/heather/advancedbackups/client/AdvancedBackupsClientCommand.java b/fabric/1.21/src/main/java/computer/heather/advancedbackups/client/AdvancedBackupsClientCommand.java index 67478c3a..8153c1ad 100644 --- a/fabric/1.21/src/main/java/computer/heather/advancedbackups/client/AdvancedBackupsClientCommand.java +++ b/fabric/1.21/src/main/java/computer/heather/advancedbackups/client/AdvancedBackupsClientCommand.java @@ -1,10 +1,13 @@ package computer.heather.advancedbackups.client; +import java.io.IOException; + import com.mojang.brigadier.CommandDispatcher; import com.mojang.brigadier.ParseResults; import com.mojang.brigadier.arguments.StringArgumentType; +import computer.heather.advancedbackups.core.ABCore; import computer.heather.advancedbackups.core.CoreCommandSystem; import net.fabricmc.fabric.api.client.command.v2.ClientCommandManager; import net.fabricmc.fabric.api.client.command.v2.FabricClientCommandSource; @@ -49,9 +52,15 @@ public static void register(CommandDispatcher dispatc })) .then(ClientCommandManager.literal("reload-client-config").executes((runner) -> { - CoreCommandSystem.reloadClientConfig((response) -> { - runner.getSource().sendFeedback(Text.of(response)); - }); + try { + CoreCommandSystem.reloadClientConfig((response) -> { + runner.getSource().sendFeedback(Text.of(response)); + }); + } catch (IOException e) { + runner.getSource().sendError(Text.of("Command failed to execute! Check log for error")); + ABCore.errorLogger.accept("Error reloading client config :"); + ABCore.logStackTrace(e); + } return 1; })) diff --git a/fabric/1.21/src/main/java/computer/heather/advancedbackups/client/BackupToast.java b/fabric/1.21/src/main/java/computer/heather/advancedbackups/client/BackupToast.java index 1d62ea79..8de24a28 100644 --- a/fabric/1.21/src/main/java/computer/heather/advancedbackups/client/BackupToast.java +++ b/fabric/1.21/src/main/java/computer/heather/advancedbackups/client/BackupToast.java @@ -41,7 +41,7 @@ public Visibility draw(DrawContext context, ToastManager manager, long startTime float percent = finished ? 100 : (float) progress / (float) max; context.fill(4, 28, 156, 29, ColourHelper.colour - (255, (int) ClientConfigManager.progressBackgroundRed.get(), (int) ClientConfigManager.progressBackgroundGreen.get(), (int) ClientConfigManager.progressBackgroundBlue.get())); + (255, ClientConfigManager.progressBackgroundRed.get(), ClientConfigManager.progressBackgroundGreen.get(), ClientConfigManager.progressBackgroundBlue.get())); float f = Math.min(156, ( 156 * percent @@ -49,13 +49,13 @@ public Visibility draw(DrawContext context, ToastManager manager, long startTime if (!exists) { if (title.equals(I18n.translate("advancedbackups.backup_finished"))){ - textColour = ColourHelper.colour(255, (int) ClientConfigManager.progressTextRed.get(), (int) ClientConfigManager.progressTextGreen.get(), (int) ClientConfigManager.progressTextBlue.get()); + textColour = ColourHelper.colour(255, ClientConfigManager.progressTextRed.get(), ClientConfigManager.progressTextGreen.get(), ClientConfigManager.progressTextBlue.get()); context.drawText(manager.getClient().textRenderer, I18n.translate(title), 25, 11, textColour, false); context.fill(4, 28, 156, 29, ColourHelper.colour - (255, (int) ClientConfigManager.progressBarRed.get(), (int) ClientConfigManager.progressBarGreen.get(), (int) ClientConfigManager.progressBarBlue.get())); + (255, ClientConfigManager.progressBarRed.get(), ClientConfigManager.progressBarGreen.get(), ClientConfigManager.progressBarBlue.get())); } else { - textColour = ColourHelper.colour(255, (int) ClientConfigManager.errorTextRed.get(), (int) ClientConfigManager.errorTextGreen.get(), (int) ClientConfigManager.errorTextBlue.get()); + textColour = ColourHelper.colour(255, ClientConfigManager.errorTextRed.get(), ClientConfigManager.errorTextGreen.get(), ClientConfigManager.errorTextBlue.get()); context.drawText(manager.getClient().textRenderer, I18n.translate(title), 25, 11, textColour, false); } return Visibility.HIDE; @@ -65,15 +65,15 @@ public Visibility draw(DrawContext context, ToastManager manager, long startTime if (starting) { - textColour = ColourHelper.colour(255, (int) ClientConfigManager.progressTextRed.get(), (int) ClientConfigManager.progressTextGreen.get(), (int) ClientConfigManager.progressTextBlue.get()); + textColour = ColourHelper.colour(255, ClientConfigManager.progressTextRed.get(), ClientConfigManager.progressTextGreen.get(), ClientConfigManager.progressTextBlue.get()); title = I18n.translate("advancedbackups.backup_starting"); } else if (started) { - textColour = ColourHelper.colour(255, (int) ClientConfigManager.progressTextRed.get(), (int) ClientConfigManager.progressTextGreen.get(), (int) ClientConfigManager.progressTextBlue.get()); + textColour = ColourHelper.colour(255, ClientConfigManager.progressTextRed.get(), ClientConfigManager.progressTextGreen.get(), ClientConfigManager.progressTextBlue.get()); title = I18n.translate("advancedbackups.progress", round(percent * 100)); } else if (failed) { - textColour = ColourHelper.colour(255, (int) ClientConfigManager.errorTextRed.get(), (int) ClientConfigManager.errorTextGreen.get(), (int) ClientConfigManager.errorTextBlue.get()); + textColour = ColourHelper.colour(255, ClientConfigManager.errorTextRed.get(), ClientConfigManager.errorTextGreen.get(), ClientConfigManager.errorTextBlue.get()); title = I18n.translate("advancedbackups.backup_failed"); if (!timeSet) { time = System.currentTimeMillis(); @@ -81,7 +81,7 @@ else if (failed) { } } else if (finished) { - textColour = ColourHelper.colour(255, (int) ClientConfigManager.progressTextRed.get(), (int) ClientConfigManager.progressTextGreen.get(), (int) ClientConfigManager.progressTextBlue.get()); + textColour = ColourHelper.colour(255, ClientConfigManager.progressTextRed.get(), ClientConfigManager.progressTextGreen.get(), ClientConfigManager.progressTextBlue.get()); title = I18n.translate("advancedbackups.backup_finished"); if (!timeSet) { time = System.currentTimeMillis(); @@ -89,7 +89,7 @@ else if (finished) { } } else if (cancelled) { - textColour = ColourHelper.colour(255, (int) ClientConfigManager.errorTextRed.get(), (int) ClientConfigManager.errorTextGreen.get(), (int) ClientConfigManager.errorTextBlue.get()); + textColour = ColourHelper.colour(255, ClientConfigManager.errorTextRed.get(), ClientConfigManager.errorTextGreen.get(), ClientConfigManager.errorTextBlue.get()); title = I18n.translate("advancedbackups.backup_cancelled"); if (!timeSet) { time = System.currentTimeMillis(); @@ -112,7 +112,7 @@ else if (cancelled) { } context.fill(4, 28, Math.max(4, (int) f), 29, ColourHelper.colour - (255, (int) ClientConfigManager.progressBarRed.get(), (int) ClientConfigManager.progressBarGreen.get(), (int) ClientConfigManager.progressBarBlue.get())); + (255, ClientConfigManager.progressBarRed.get(), ClientConfigManager.progressBarGreen.get(), ClientConfigManager.progressBarBlue.get())); return Visibility.SHOW; } diff --git a/fabric/1.21/src/main/java/computer/heather/advancedbackups/client/ClientWrapper.java b/fabric/1.21/src/main/java/computer/heather/advancedbackups/client/ClientWrapper.java index b137a58a..d1b90d9c 100644 --- a/fabric/1.21/src/main/java/computer/heather/advancedbackups/client/ClientWrapper.java +++ b/fabric/1.21/src/main/java/computer/heather/advancedbackups/client/ClientWrapper.java @@ -1,5 +1,7 @@ package computer.heather.advancedbackups.client; +import java.io.IOException; + import computer.heather.advancedbackups.AdvancedBackups; import computer.heather.advancedbackups.core.ABCore; import computer.heather.advancedbackups.core.config.ClientConfigManager; @@ -22,7 +24,12 @@ public void onInitializeClient() { ABCore.errorLogger = AdvancedBackups.errorLogger; ClientLifecycleEvents.CLIENT_STARTED.register((client) -> { - ClientConfigManager.loadOrCreateConfig(); + try { + ClientConfigManager.loadOrCreateConfig(); + } catch (IOException e) { + ABCore.errorLogger.accept("Unable to load client config! Default will be used..."); + ABCore.logStackTrace(e); + } }); ClientPlayConnectionEvents.JOIN.register((handler, sender, client) -> { diff --git a/forge/1.12/src/main/java/computer/heather/advancedbackups/AdvancedBackups.java b/forge/1.12/src/main/java/computer/heather/advancedbackups/AdvancedBackups.java index 9d9937e9..91762fd5 100644 --- a/forge/1.12/src/main/java/computer/heather/advancedbackups/AdvancedBackups.java +++ b/forge/1.12/src/main/java/computer/heather/advancedbackups/AdvancedBackups.java @@ -1,6 +1,7 @@ package computer.heather.advancedbackups; import java.io.File; +import java.io.IOException; import java.util.ArrayList; import java.util.List; import java.util.function.Consumer; @@ -100,9 +101,13 @@ public void onServerStarting(FMLServerStartingEvent event) ABCore.modJar = Loader.instance().getIndexedModList().get("advancedbackups").getSource(); //ModList.get().getModFileById("advancedbackups").getFile().getFilePath().toFile(); - ConfigManager.loadOrCreateConfig(); - LOGGER.info("Config loaded!!"); - + try { + ConfigManager.loadOrCreateConfig(); + LOGGER.info("Config loaded!!"); + } catch (IOException e) { + LOGGER.error("Unable to load config! Falling back to defaults..."); + ABCore.logStackTrace(e); + } event.registerServerCommand(new AdvancedBackupsCommand()); diff --git a/forge/1.12/src/main/java/computer/heather/advancedbackups/AdvancedBackupsCommand.java b/forge/1.12/src/main/java/computer/heather/advancedbackups/AdvancedBackupsCommand.java index 08c09053..aaf6b3fb 100644 --- a/forge/1.12/src/main/java/computer/heather/advancedbackups/AdvancedBackupsCommand.java +++ b/forge/1.12/src/main/java/computer/heather/advancedbackups/AdvancedBackupsCommand.java @@ -1,5 +1,8 @@ package computer.heather.advancedbackups; +import java.io.IOException; + +import computer.heather.advancedbackups.core.ABCore; import computer.heather.advancedbackups.core.CoreCommandSystem; import net.minecraft.command.CommandException; @@ -49,9 +52,15 @@ public static class Reload extends CommandTreeBase { public Reload(){} @Override public void execute(MinecraftServer server, ICommandSender sender, String[] args) throws CommandException { - CoreCommandSystem.reloadConfig((response) -> { - sender.sendMessage(new TextComponentString(response)); - }); + try { + CoreCommandSystem.reloadConfig((response) -> { + sender.sendMessage(new TextComponentString(response)); + }); + } catch (IOException e) { + sender.sendMessage(new TextComponentString("Command failed to execute! Check log for error")); + ABCore.errorLogger.accept("Error reloading config :"); + ABCore.logStackTrace(e); + } } @Override public String getName() diff --git a/forge/1.12/src/main/java/computer/heather/advancedbackups/client/BackupToast.java b/forge/1.12/src/main/java/computer/heather/advancedbackups/client/BackupToast.java index 336e0b7a..fa93a4a8 100644 --- a/forge/1.12/src/main/java/computer/heather/advancedbackups/client/BackupToast.java +++ b/forge/1.12/src/main/java/computer/heather/advancedbackups/client/BackupToast.java @@ -62,15 +62,15 @@ public Visibility draw(GuiToast toastGui, long delta) { if (starting) { title = I18n.format("advancedbackups.backup_starting"); - textColour = ColourHelper.colour(255, (int) ClientConfigManager.progressTextRed.get(), (int) ClientConfigManager.progressTextGreen.get(), (int) ClientConfigManager.progressTextBlue.get()); + textColour = ColourHelper.colour(255, ClientConfigManager.progressTextRed.get(), ClientConfigManager.progressTextGreen.get(), ClientConfigManager.progressTextBlue.get()); } else if (started) { title = I18n.format("advancedbackups.progress", round(percent * 100)); - textColour = ColourHelper.colour(255, (int) ClientConfigManager.progressTextRed.get(), (int) ClientConfigManager.progressTextGreen.get(), (int) ClientConfigManager.progressTextBlue.get()); + textColour = ColourHelper.colour(255, ClientConfigManager.progressTextRed.get(), ClientConfigManager.progressTextGreen.get(), ClientConfigManager.progressTextBlue.get()); } else if (failed) { title = I18n.format("advancedbackups.backup_failed"); - textColour = ColourHelper.colour(255, (int) ClientConfigManager.errorTextRed.get(), (int) ClientConfigManager.errorTextGreen.get(), (int) ClientConfigManager.errorTextBlue.get()); + textColour = ColourHelper.colour(255, ClientConfigManager.errorTextRed.get(), ClientConfigManager.errorTextGreen.get(), ClientConfigManager.errorTextBlue.get()); if (!timeSet) { time = System.currentTimeMillis(); timeSet = true; @@ -78,7 +78,7 @@ else if (failed) { } else if (cancelled) { title = I18n.format("advancedbackups.backup_cancelled"); - textColour = ColourHelper.colour(255, (int) ClientConfigManager.errorTextRed.get(), (int) ClientConfigManager.errorTextGreen.get(), (int) ClientConfigManager.errorTextBlue.get()); + textColour = ColourHelper.colour(255, ClientConfigManager.errorTextRed.get(), ClientConfigManager.errorTextGreen.get(), ClientConfigManager.errorTextBlue.get()); if (!timeSet) { time = System.currentTimeMillis(); timeSet = true; @@ -86,7 +86,7 @@ else if (cancelled) { } else if (finished) { title = I18n.format("advancedbackups.backup_finished"); - textColour = ColourHelper.colour(255, (int) ClientConfigManager.progressTextRed.get(), (int) ClientConfigManager.progressTextGreen.get(), (int) ClientConfigManager.progressTextBlue.get()); + textColour = ColourHelper.colour(255, ClientConfigManager.progressTextRed.get(), ClientConfigManager.progressTextGreen.get(), ClientConfigManager.progressTextBlue.get()); if (!timeSet) { time = System.currentTimeMillis(); timeSet = true; diff --git a/forge/1.12/src/main/java/computer/heather/advancedbackups/client/ClientBridge.java b/forge/1.12/src/main/java/computer/heather/advancedbackups/client/ClientBridge.java index edb3ffcb..a77f7a84 100644 --- a/forge/1.12/src/main/java/computer/heather/advancedbackups/client/ClientBridge.java +++ b/forge/1.12/src/main/java/computer/heather/advancedbackups/client/ClientBridge.java @@ -1,8 +1,12 @@ package computer.heather.advancedbackups.client; +import java.io.IOException; + +import computer.heather.advancedbackups.core.ABCore; import computer.heather.advancedbackups.core.CoreCommandSystem; import computer.heather.advancedbackups.network.PacketBackupStatus; import net.minecraft.client.Minecraft; +import net.minecraft.util.text.TextComponentString; import net.minecraftforge.client.event.ClientChatEvent; public class ClientBridge { @@ -32,7 +36,15 @@ public static void handle(PacketBackupStatus message) { public static void onClientChat(ClientChatEvent event) { if (event.getMessage().equals("/backup reload-client-config")) { event.setCanceled(true); - CoreCommandSystem.reloadClientConfig(Minecraft.getMinecraft().player::sendChatMessage); + try { + CoreCommandSystem.reloadClientConfig((response) -> { + Minecraft.getMinecraft().player.sendMessage(new TextComponentString(response)); + }); + } catch (IOException e) { + Minecraft.getMinecraft().player.sendMessage(new TextComponentString("Command failed to execute! Check log for error")); + ABCore.errorLogger.accept("Error reloading client config :"); + ABCore.logStackTrace(e); + } } } diff --git a/forge/1.12/src/main/java/computer/heather/advancedbackups/network/PacketToastTest.java b/forge/1.12/src/main/java/computer/heather/advancedbackups/network/PacketToastTest.java index 67b7ce83..07c564fd 100644 --- a/forge/1.12/src/main/java/computer/heather/advancedbackups/network/PacketToastTest.java +++ b/forge/1.12/src/main/java/computer/heather/advancedbackups/network/PacketToastTest.java @@ -1,5 +1,8 @@ package computer.heather.advancedbackups.network; +import java.io.IOException; + +import computer.heather.advancedbackups.core.ABCore; import computer.heather.advancedbackups.core.config.ClientConfigManager; import io.netty.buffer.ByteBuf; import net.minecraftforge.fml.common.network.simpleimpl.IMessage; @@ -34,7 +37,12 @@ public static class Handler implements IMessageHandler stack) { })) .then(Commands.literal("reload-config").executes((runner) -> { - CoreCommandSystem.reloadConfig((response) -> { - runner.getSource().sendSuccess(new StringTextComponent(response), true); - }); + try { + CoreCommandSystem.reloadConfig((response) -> { + runner.getSource().sendSuccess(new StringTextComponent(response), true); + }); + } catch (IOException e) { + runner.getSource().sendFailure(new StringTextComponent("Command failed to execute! Check log for error")); + ABCore.errorLogger.accept("Error reloading config :"); + ABCore.logStackTrace(e); + } return 1; })) diff --git a/forge/1.16/src/main/java/computer/heather/advancedbackups/client/BackupToast.java b/forge/1.16/src/main/java/computer/heather/advancedbackups/client/BackupToast.java index 8c26d60d..fa596711 100644 --- a/forge/1.16/src/main/java/computer/heather/advancedbackups/client/BackupToast.java +++ b/forge/1.16/src/main/java/computer/heather/advancedbackups/client/BackupToast.java @@ -10,7 +10,6 @@ import net.minecraft.client.resources.I18n; import net.minecraft.item.ItemStack; import net.minecraft.item.Items; -import net.minecraft.util.ColorHelper; public class BackupToast implements IToast { @@ -43,21 +42,21 @@ public Visibility render(MatrixStack matrix, ToastGui toastGui, long delta) { float percent = finished ? 100 : (float) progress / (float) max; - AbstractGui.fill(matrix, 4, 28, 156, 29, ColorHelper.PackedColor.color - (255, (int) ClientConfigManager.progressBackgroundRed.get(), (int) ClientConfigManager.progressBackgroundGreen.get(), (int) ClientConfigManager.progressBackgroundBlue.get())); + AbstractGui.fill(matrix, 4, 28, 156, 29, ColourHelper.colour + (255, ClientConfigManager.progressBackgroundRed.get(), ClientConfigManager.progressBackgroundGreen.get(), ClientConfigManager.progressBackgroundBlue.get())); float f = Math.min(156, ( 156 * percent )); if (!exists) { if (title.equals(I18n.get("advancedbackups.backup_finished"))){ - textColour = ColorHelper.PackedColor.color(255, (int) ClientConfigManager.progressTextRed.get(), (int) ClientConfigManager.progressTextGreen.get(), (int) ClientConfigManager.progressTextBlue.get()); + textColour = ColourHelper.colour(255, ClientConfigManager.progressTextRed.get(), ClientConfigManager.progressTextGreen.get(), ClientConfigManager.progressTextBlue.get()); toastGui.getMinecraft().font.draw(matrix, I18n.get(title), 25, 11, textColour); - AbstractGui.fill(matrix, 3, 28, 156, 29, ColorHelper.PackedColor.color - (255, (int) ClientConfigManager.progressBarRed.get(), (int) ClientConfigManager.progressBarGreen.get(), (int) ClientConfigManager.progressBarBlue.get())); + AbstractGui.fill(matrix, 3, 28, 156, 29, ColourHelper.colour + (255, ClientConfigManager.progressBarRed.get(), ClientConfigManager.progressBarGreen.get(), ClientConfigManager.progressBarBlue.get())); } else { - textColour = ColorHelper.PackedColor.color(255, (int) ClientConfigManager.errorTextRed.get(), (int) ClientConfigManager.errorTextGreen.get(), (int) ClientConfigManager.errorTextBlue.get()); + textColour = ColourHelper.colour(255, ClientConfigManager.errorTextRed.get(), ClientConfigManager.errorTextGreen.get(), ClientConfigManager.errorTextBlue.get()); toastGui.getMinecraft().font.draw(matrix, I18n.get(title), 25, 11, textColour); } return Visibility.HIDE; @@ -66,15 +65,15 @@ public Visibility render(MatrixStack matrix, ToastGui toastGui, long delta) { if (starting) { - textColour = ColorHelper.PackedColor.color(255, (int) ClientConfigManager.progressTextRed.get(), (int) ClientConfigManager.progressTextGreen.get(), (int) ClientConfigManager.progressTextBlue.get()); + textColour = ColourHelper.colour(255, ClientConfigManager.progressTextRed.get(), ClientConfigManager.progressTextGreen.get(), ClientConfigManager.progressTextBlue.get()); title = I18n.get("advancedbackups.backup_starting"); } else if (started) { - textColour = ColorHelper.PackedColor.color(255, (int) ClientConfigManager.progressTextRed.get(), (int) ClientConfigManager.progressTextGreen.get(), (int) ClientConfigManager.progressTextBlue.get()); + textColour = ColourHelper.colour(255, ClientConfigManager.progressTextRed.get(), ClientConfigManager.progressTextGreen.get(), ClientConfigManager.progressTextBlue.get()); title = I18n.get("advancedbackups.progress", round(percent * 100)); } else if (failed) { - textColour = ColorHelper.PackedColor.color(255, (int) ClientConfigManager.errorTextRed.get(), (int) ClientConfigManager.errorTextGreen.get(), (int) ClientConfigManager.errorTextBlue.get()); + textColour = ColourHelper.colour(255, ClientConfigManager.errorTextRed.get(), ClientConfigManager.errorTextGreen.get(), ClientConfigManager.errorTextBlue.get()); title = I18n.get("advancedbackups.backup_failed"); if (!timeSet) { time = System.currentTimeMillis(); @@ -82,7 +81,7 @@ else if (failed) { } } else if (finished) { - textColour = ColorHelper.PackedColor.color(255, (int) ClientConfigManager.progressTextRed.get(), (int) ClientConfigManager.progressTextGreen.get(), (int) ClientConfigManager.progressTextBlue.get()); + textColour = ColourHelper.colour(255, ClientConfigManager.progressTextRed.get(), ClientConfigManager.progressTextGreen.get(), ClientConfigManager.progressTextBlue.get()); title = I18n.get("advancedbackups.backup_finished"); if (!timeSet) { time = System.currentTimeMillis(); @@ -90,7 +89,7 @@ else if (finished) { } } else if (cancelled) { - textColour = ColorHelper.PackedColor.color(255, (int) ClientConfigManager.errorTextRed.get(), (int) ClientConfigManager.errorTextGreen.get(), (int) ClientConfigManager.errorTextBlue.get()); + textColour = ColourHelper.colour(255, ClientConfigManager.errorTextRed.get(), ClientConfigManager.errorTextGreen.get(), ClientConfigManager.errorTextBlue.get()); title = I18n.get("advancedbackups.backup_cancelled"); if (!timeSet) { time = System.currentTimeMillis(); @@ -117,8 +116,8 @@ else if (cancelled) { return Visibility.HIDE; } - AbstractGui.fill(matrix, 4, 28, Math.max(3, (int) f), 29, ColorHelper.PackedColor.color - (255, (int) ClientConfigManager.progressBarRed.get(), (int) ClientConfigManager.progressBarGreen.get(), (int) ClientConfigManager.progressBarBlue.get())); + AbstractGui.fill(matrix, 4, 28, Math.max(3, (int) f), 29, ColourHelper.colour + (255, ClientConfigManager.progressBarRed.get(), ClientConfigManager.progressBarGreen.get(), ClientConfigManager.progressBarBlue.get())); return Visibility.SHOW; diff --git a/forge/1.16/src/main/java/computer/heather/advancedbackups/client/ClientWrapper.java b/forge/1.16/src/main/java/computer/heather/advancedbackups/client/ClientWrapper.java index ee99bf71..ada83920 100644 --- a/forge/1.16/src/main/java/computer/heather/advancedbackups/client/ClientWrapper.java +++ b/forge/1.16/src/main/java/computer/heather/advancedbackups/client/ClientWrapper.java @@ -1,13 +1,16 @@ package computer.heather.advancedbackups.client; +import java.io.IOException; import java.util.function.Supplier; +import computer.heather.advancedbackups.core.ABCore; import computer.heather.advancedbackups.core.CoreCommandSystem; import computer.heather.advancedbackups.core.config.ClientConfigManager; import computer.heather.advancedbackups.network.NetworkHandler; import computer.heather.advancedbackups.network.PacketBackupStatus; import computer.heather.advancedbackups.network.PacketToastSubscribe; import net.minecraft.client.Minecraft; +import net.minecraft.util.text.StringTextComponent; import net.minecraftforge.client.event.ClientChatEvent; import net.minecraftforge.client.event.ClientPlayerNetworkEvent; import net.minecraftforge.common.MinecraftForge; @@ -38,17 +41,28 @@ public static void handle(Supplier ctx, PacketBackupStatus packet) { }); } - public static void init(FMLClientSetupEvent e) { + public static void init(FMLClientSetupEvent event) { MinecraftForge.EVENT_BUS.addListener(ClientWrapper::onClientChat); MinecraftForge.EVENT_BUS.addListener(ClientWrapper::onServerConnected); - ClientConfigManager.loadOrCreateConfig(); + try { + ClientConfigManager.loadOrCreateConfig(); + } catch (IOException e) { + ABCore.errorLogger.accept("Unable to load client config! Default will be used..."); + ABCore.logStackTrace(e); + } } public static void onClientChat(ClientChatEvent event) { if (event.getMessage().equals("/backup reload-client-config")) { event.setCanceled(true); - - CoreCommandSystem.reloadClientConfig(Minecraft.getInstance().player::chat); + try { + CoreCommandSystem.reloadClientConfig((response) -> { + Minecraft.getInstance().player.sendMessage(new StringTextComponent(response), null); + }); + } catch (IOException e) { + Minecraft.getInstance().player.sendMessage(new StringTextComponent("Command failed to execute! Check log for error"), null); + ABCore.errorLogger.accept("Error reloading client config :"); + } } } diff --git a/forge/1.16/src/main/java/computer/heather/advancedbackups/client/ColourHelper.java b/forge/1.16/src/main/java/computer/heather/advancedbackups/client/ColourHelper.java new file mode 100644 index 00000000..bbb826e9 --- /dev/null +++ b/forge/1.16/src/main/java/computer/heather/advancedbackups/client/ColourHelper.java @@ -0,0 +1,30 @@ +package computer.heather.advancedbackups.client; + +//Same colour helper featured in other versions. Could this possibly be moved to core in future...? +public class ColourHelper { + + public static int alpha(int in) { + return in >>> 24; + } + + public static int red(int in) { + return in >> 16 & 255; + } + + public static int green(int in) { + return in >> 8 & 255; + } + + public static int blue(int in) { + return in & 255; + } + + public static int colour(int a, int r, int g, int b) { + return a << 24 | r << 16 | g << 8 | b; + } + + public static int colour(int a, long r, long g, long b) { + return colour(a, (int) r, (int) g, (int) b); + } + +} diff --git a/forge/1.18/src/main/java/computer/heather/advancedbackups/AdvancedBackups.java b/forge/1.18/src/main/java/computer/heather/advancedbackups/AdvancedBackups.java index c4496f40..332f5284 100644 --- a/forge/1.18/src/main/java/computer/heather/advancedbackups/AdvancedBackups.java +++ b/forge/1.18/src/main/java/computer/heather/advancedbackups/AdvancedBackups.java @@ -1,5 +1,6 @@ package computer.heather.advancedbackups; +import java.io.IOException; import java.util.ArrayList; import java.util.List; import java.util.function.Consumer; @@ -77,8 +78,13 @@ public void onServerStarting(ServerStartingEvent event) ABCore.modJar = ModList.get().getModFileById("advancedbackups").getFile().getFilePath().toFile(); - ConfigManager.loadOrCreateConfig(); - LOGGER.info("Config loaded!!"); + try { + ConfigManager.loadOrCreateConfig(); + LOGGER.info("Config loaded!!"); + } catch (IOException e) { + LOGGER.error("Unable to load config! Falling back to defaults..."); + ABCore.logStackTrace(e); + } } diff --git a/forge/1.18/src/main/java/computer/heather/advancedbackups/AdvancedBackupsCommand.java b/forge/1.18/src/main/java/computer/heather/advancedbackups/AdvancedBackupsCommand.java index 3e05bca6..7f04f0e8 100644 --- a/forge/1.18/src/main/java/computer/heather/advancedbackups/AdvancedBackupsCommand.java +++ b/forge/1.18/src/main/java/computer/heather/advancedbackups/AdvancedBackupsCommand.java @@ -1,8 +1,11 @@ package computer.heather.advancedbackups; +import java.io.IOException; + import com.mojang.brigadier.CommandDispatcher; import com.mojang.brigadier.arguments.StringArgumentType; +import computer.heather.advancedbackups.core.ABCore; import computer.heather.advancedbackups.core.CoreCommandSystem; import net.minecraft.commands.CommandSourceStack; import net.minecraft.commands.Commands; @@ -21,9 +24,15 @@ public static void register(CommandDispatcher stack) { })) .then(Commands.literal("reload-config").executes((runner) -> { - CoreCommandSystem.reloadConfig((response) -> { - runner.getSource().sendSuccess(new TextComponent(response), true); - }); + try { + CoreCommandSystem.reloadConfig((response) -> { + runner.getSource().sendSuccess(new TextComponent(response), true); + }); + } catch (IOException e) { + runner.getSource().sendFailure(new TextComponent("Command failed to execute! Check log for error")); + ABCore.errorLogger.accept("Error reloading config :"); + ABCore.logStackTrace(e); + } return 1; })) diff --git a/forge/1.18/src/main/java/computer/heather/advancedbackups/client/BackupToast.java b/forge/1.18/src/main/java/computer/heather/advancedbackups/client/BackupToast.java index 1e5e765a..a18ba6d3 100644 --- a/forge/1.18/src/main/java/computer/heather/advancedbackups/client/BackupToast.java +++ b/forge/1.18/src/main/java/computer/heather/advancedbackups/client/BackupToast.java @@ -4,7 +4,6 @@ import com.mojang.blaze3d.vertex.PoseStack; import computer.heather.advancedbackups.core.config.ClientConfigManager; -import net.minecraft.ChatFormatting; import net.minecraft.client.gui.Gui; import net.minecraft.client.gui.components.toasts.Toast; import net.minecraft.client.gui.components.toasts.ToastComponent; @@ -46,7 +45,7 @@ public Visibility render(PoseStack matrix, ToastComponent toastGui, long delta) float percent = finished ? 100 : (float) progress / (float) max; Gui.fill(matrix, 4, 28, 156, 29, ColourHelper.colour - (255, (int) ClientConfigManager.progressBackgroundRed.get(), (int) ClientConfigManager.progressBackgroundGreen.get(), (int) ClientConfigManager.progressBackgroundBlue.get())); + (255, ClientConfigManager.progressBackgroundRed.get(), ClientConfigManager.progressBackgroundGreen.get(), ClientConfigManager.progressBackgroundBlue.get())); float f = Math.min(156, ( 156 * percent @@ -54,13 +53,13 @@ public Visibility render(PoseStack matrix, ToastComponent toastGui, long delta) if (!exists) { if (title.equals(I18n.get("advancedbackups.backup_finished"))){ - textColour = ColourHelper.colour(255, (int) ClientConfigManager.progressTextRed.get(), (int) ClientConfigManager.progressTextGreen.get(), (int) ClientConfigManager.progressTextBlue.get()); + textColour = ColourHelper.colour(255, ClientConfigManager.progressTextRed.get(), ClientConfigManager.progressTextGreen.get(), ClientConfigManager.progressTextBlue.get()); toastGui.getMinecraft().font.draw(matrix, I18n.get(title), 25, 11, textColour); Gui.fill(matrix, 3, 28, 156, 29, ColourHelper.colour - (255, (int) ClientConfigManager.progressBarRed.get(), (int) ClientConfigManager.progressBarGreen.get(), (int) ClientConfigManager.progressBarBlue.get())); + (255, ClientConfigManager.progressBarRed.get(), ClientConfigManager.progressBarGreen.get(), ClientConfigManager.progressBarBlue.get())); } else { - textColour = ColourHelper.colour(255, (int) ClientConfigManager.errorTextRed.get(), (int) ClientConfigManager.errorTextGreen.get(), (int) ClientConfigManager.errorTextBlue.get()); + textColour = ColourHelper.colour(255, ClientConfigManager.errorTextRed.get(), ClientConfigManager.errorTextGreen.get(), ClientConfigManager.errorTextBlue.get()); toastGui.getMinecraft().font.draw(matrix, I18n.get(title), 25, 11, textColour); } return Visibility.HIDE; @@ -70,15 +69,15 @@ public Visibility render(PoseStack matrix, ToastComponent toastGui, long delta) if (starting) { - textColour = ColourHelper.colour(255, (int) ClientConfigManager.progressTextRed.get(), (int) ClientConfigManager.progressTextGreen.get(), (int) ClientConfigManager.progressTextBlue.get()); + textColour = ColourHelper.colour(255, ClientConfigManager.progressTextRed.get(), ClientConfigManager.progressTextGreen.get(), ClientConfigManager.progressTextBlue.get()); title = I18n.get("advancedbackups.backup_starting"); } else if (started) { - textColour = ColourHelper.colour(255, (int) ClientConfigManager.progressTextRed.get(), (int) ClientConfigManager.progressTextGreen.get(), (int) ClientConfigManager.progressTextBlue.get()); + textColour = ColourHelper.colour(255, ClientConfigManager.progressTextRed.get(), ClientConfigManager.progressTextGreen.get(), ClientConfigManager.progressTextBlue.get()); title = I18n.get("advancedbackups.progress", round(percent * 100)); } else if (failed) { - textColour = ColourHelper.colour(255, (int) ClientConfigManager.errorTextRed.get(), (int) ClientConfigManager.errorTextGreen.get(), (int) ClientConfigManager.errorTextBlue.get()); + textColour = ColourHelper.colour(255, ClientConfigManager.errorTextRed.get(), ClientConfigManager.errorTextGreen.get(), ClientConfigManager.errorTextBlue.get()); title = I18n.get("advancedbackups.backup_failed"); if (!timeSet) { time = System.currentTimeMillis(); @@ -86,7 +85,7 @@ else if (failed) { } } else if (finished) { - textColour = ColourHelper.colour(255, (int) ClientConfigManager.progressTextRed.get(), (int) ClientConfigManager.progressTextGreen.get(), (int) ClientConfigManager.progressTextBlue.get()); + textColour = ColourHelper.colour(255, ClientConfigManager.progressTextRed.get(), ClientConfigManager.progressTextGreen.get(), ClientConfigManager.progressTextBlue.get()); title = I18n.get("advancedbackups.backup_finished"); if (!timeSet) { time = System.currentTimeMillis(); @@ -94,7 +93,7 @@ else if (finished) { } } else if (cancelled) { - textColour = ColourHelper.colour(255, (int) ClientConfigManager.errorTextRed.get(), (int) ClientConfigManager.errorTextGreen.get(), (int) ClientConfigManager.errorTextBlue.get()); + textColour = ColourHelper.colour(255, ClientConfigManager.errorTextRed.get(), ClientConfigManager.errorTextGreen.get(), ClientConfigManager.errorTextBlue.get()); title = I18n.get("advancedbackups.backup_cancelled"); if (!timeSet) { time = System.currentTimeMillis(); @@ -117,7 +116,7 @@ else if (cancelled) { } Gui.fill(matrix, 4, 28, Math.max(4, (int) f), 29, ColourHelper.colour - (255, (int) ClientConfigManager.progressBarRed.get(), (int) ClientConfigManager.progressBarGreen.get(), (int) ClientConfigManager.progressBarBlue.get())); + (255, ClientConfigManager.progressBarRed.get(), ClientConfigManager.progressBarGreen.get(), ClientConfigManager.progressBarBlue.get())); return Visibility.SHOW; diff --git a/forge/1.18/src/main/java/computer/heather/advancedbackups/client/ClientWrapper.java b/forge/1.18/src/main/java/computer/heather/advancedbackups/client/ClientWrapper.java index 9248a93d..194b536f 100644 --- a/forge/1.18/src/main/java/computer/heather/advancedbackups/client/ClientWrapper.java +++ b/forge/1.18/src/main/java/computer/heather/advancedbackups/client/ClientWrapper.java @@ -1,11 +1,15 @@ package computer.heather.advancedbackups.client; +import java.io.IOException; + +import computer.heather.advancedbackups.core.ABCore; import computer.heather.advancedbackups.core.CoreCommandSystem; import computer.heather.advancedbackups.core.config.ClientConfigManager; import computer.heather.advancedbackups.network.NetworkHandler; import computer.heather.advancedbackups.network.PacketBackupStatus; import computer.heather.advancedbackups.network.PacketToastSubscribe; import net.minecraft.client.Minecraft; +import net.minecraft.network.chat.TextComponent; import net.minecraftforge.client.event.ClientChatEvent; import net.minecraftforge.client.event.ClientPlayerNetworkEvent; import net.minecraftforge.common.MinecraftForge; @@ -29,17 +33,29 @@ public static void handle(PacketBackupStatus packet) { } } - public static void init(FMLClientSetupEvent e) { + public static void init(FMLClientSetupEvent event) { MinecraftForge.EVENT_BUS.addListener(ClientWrapper::onClientChat); MinecraftForge.EVENT_BUS.addListener(ClientWrapper::onServerConnected); - ClientConfigManager.loadOrCreateConfig(); + try { + ClientConfigManager.loadOrCreateConfig(); + } catch (IOException e) { + ABCore.errorLogger.accept("Unable to load client config! Default will be used..."); + ABCore.logStackTrace(e); + } } public static void onClientChat(ClientChatEvent event) { if (event.getMessage().equals("/backup reload-client-config")) { event.setCanceled(true); - CoreCommandSystem.reloadClientConfig(Minecraft.getInstance().player::chat); + try { + CoreCommandSystem.reloadClientConfig((response) -> { + Minecraft.getInstance().player.sendMessage(new TextComponent(response), null); + }); + } catch (IOException e) { + Minecraft.getInstance().player.sendMessage(new TextComponent("Command failed to execute! Check log for error"), null); + ABCore.errorLogger.accept("Error reloading client config :"); + } } } diff --git a/forge/1.19.2/src/main/java/computer/heather/advancedbackups/AdvancedBackups.java b/forge/1.19.2/src/main/java/computer/heather/advancedbackups/AdvancedBackups.java index c4496f40..332f5284 100644 --- a/forge/1.19.2/src/main/java/computer/heather/advancedbackups/AdvancedBackups.java +++ b/forge/1.19.2/src/main/java/computer/heather/advancedbackups/AdvancedBackups.java @@ -1,5 +1,6 @@ package computer.heather.advancedbackups; +import java.io.IOException; import java.util.ArrayList; import java.util.List; import java.util.function.Consumer; @@ -77,8 +78,13 @@ public void onServerStarting(ServerStartingEvent event) ABCore.modJar = ModList.get().getModFileById("advancedbackups").getFile().getFilePath().toFile(); - ConfigManager.loadOrCreateConfig(); - LOGGER.info("Config loaded!!"); + try { + ConfigManager.loadOrCreateConfig(); + LOGGER.info("Config loaded!!"); + } catch (IOException e) { + LOGGER.error("Unable to load config! Falling back to defaults..."); + ABCore.logStackTrace(e); + } } diff --git a/forge/1.19.2/src/main/java/computer/heather/advancedbackups/AdvancedBackupsCommand.java b/forge/1.19.2/src/main/java/computer/heather/advancedbackups/AdvancedBackupsCommand.java index 0c008420..99d9ca3e 100644 --- a/forge/1.19.2/src/main/java/computer/heather/advancedbackups/AdvancedBackupsCommand.java +++ b/forge/1.19.2/src/main/java/computer/heather/advancedbackups/AdvancedBackupsCommand.java @@ -1,8 +1,11 @@ package computer.heather.advancedbackups; +import java.io.IOException; + import com.mojang.brigadier.CommandDispatcher; import com.mojang.brigadier.arguments.StringArgumentType; +import computer.heather.advancedbackups.core.ABCore; import computer.heather.advancedbackups.core.CoreCommandSystem; import net.minecraft.commands.CommandSourceStack; import net.minecraft.commands.Commands; @@ -20,10 +23,16 @@ public static void register(CommandDispatcher stack) { return 1; })) - .then(Commands.literal("reload-config").executes((runner) -> { - CoreCommandSystem.reloadConfig((response) -> { - runner.getSource().sendSuccess(Component.literal(response), true); - }); + .then(Commands.literal("reload-config").executes((runner) -> { + try { + CoreCommandSystem.reloadConfig((response) -> { + runner.getSource().sendSuccess(Component.literal(response), true); + }); + } catch (IOException e) { + runner.getSource().sendFailure(Component.literal("Command failed to execute! Check log for error")); + ABCore.errorLogger.accept("Error reloading config :"); + ABCore.logStackTrace(e); + } return 1; })) diff --git a/forge/1.19.2/src/main/java/computer/heather/advancedbackups/client/AdvancedBackupsClientCommand.java b/forge/1.19.2/src/main/java/computer/heather/advancedbackups/client/AdvancedBackupsClientCommand.java index b0e897c7..5036d161 100644 --- a/forge/1.19.2/src/main/java/computer/heather/advancedbackups/client/AdvancedBackupsClientCommand.java +++ b/forge/1.19.2/src/main/java/computer/heather/advancedbackups/client/AdvancedBackupsClientCommand.java @@ -1,11 +1,13 @@ package computer.heather.advancedbackups.client; +import java.io.IOException; import java.time.Instant; import com.mojang.brigadier.CommandDispatcher; import com.mojang.brigadier.arguments.StringArgumentType; import com.mojang.brigadier.builder.LiteralArgumentBuilder; +import computer.heather.advancedbackups.core.ABCore; import computer.heather.advancedbackups.core.CoreCommandSystem; import net.minecraft.client.Minecraft; import net.minecraft.commands.CommandSourceStack; @@ -54,10 +56,16 @@ public static void register(CommandDispatcher commandDispatc return 1; })) - .then(literal("reload-client-config").executes((runner) -> { - CoreCommandSystem.reloadClientConfig((response) -> { - runner.getSource().sendSuccess(Component.literal(response), true); - }); + .then(literal("reload-client-config").executes((runner) -> { + try { + CoreCommandSystem.reloadClientConfig((response) -> { + runner.getSource().sendSuccess(Component.literal(response), true); + }); + } catch (IOException e) { + runner.getSource().sendFailure(Component.literal("Command failed to execute! Check log for error")); + ABCore.errorLogger.accept("Error reloading client config :"); + ABCore.logStackTrace(e); + } return 1; })) diff --git a/forge/1.19.2/src/main/java/computer/heather/advancedbackups/client/BackupToast.java b/forge/1.19.2/src/main/java/computer/heather/advancedbackups/client/BackupToast.java index 995e93aa..a18ba6d3 100644 --- a/forge/1.19.2/src/main/java/computer/heather/advancedbackups/client/BackupToast.java +++ b/forge/1.19.2/src/main/java/computer/heather/advancedbackups/client/BackupToast.java @@ -45,7 +45,7 @@ public Visibility render(PoseStack matrix, ToastComponent toastGui, long delta) float percent = finished ? 100 : (float) progress / (float) max; Gui.fill(matrix, 4, 28, 156, 29, ColourHelper.colour - (255, (int) ClientConfigManager.progressBackgroundRed.get(), (int) ClientConfigManager.progressBackgroundGreen.get(), (int) ClientConfigManager.progressBackgroundBlue.get())); + (255, ClientConfigManager.progressBackgroundRed.get(), ClientConfigManager.progressBackgroundGreen.get(), ClientConfigManager.progressBackgroundBlue.get())); float f = Math.min(156, ( 156 * percent @@ -53,13 +53,13 @@ public Visibility render(PoseStack matrix, ToastComponent toastGui, long delta) if (!exists) { if (title.equals(I18n.get("advancedbackups.backup_finished"))){ - textColour = ColourHelper.colour(255, (int) ClientConfigManager.progressTextRed.get(), (int) ClientConfigManager.progressTextGreen.get(), (int) ClientConfigManager.progressTextBlue.get()); + textColour = ColourHelper.colour(255, ClientConfigManager.progressTextRed.get(), ClientConfigManager.progressTextGreen.get(), ClientConfigManager.progressTextBlue.get()); toastGui.getMinecraft().font.draw(matrix, I18n.get(title), 25, 11, textColour); Gui.fill(matrix, 3, 28, 156, 29, ColourHelper.colour - (255, (int) ClientConfigManager.progressBarRed.get(), (int) ClientConfigManager.progressBarGreen.get(), (int) ClientConfigManager.progressBarBlue.get())); + (255, ClientConfigManager.progressBarRed.get(), ClientConfigManager.progressBarGreen.get(), ClientConfigManager.progressBarBlue.get())); } else { - textColour = ColourHelper.colour(255, (int) ClientConfigManager.errorTextRed.get(), (int) ClientConfigManager.errorTextGreen.get(), (int) ClientConfigManager.errorTextBlue.get()); + textColour = ColourHelper.colour(255, ClientConfigManager.errorTextRed.get(), ClientConfigManager.errorTextGreen.get(), ClientConfigManager.errorTextBlue.get()); toastGui.getMinecraft().font.draw(matrix, I18n.get(title), 25, 11, textColour); } return Visibility.HIDE; @@ -69,15 +69,15 @@ public Visibility render(PoseStack matrix, ToastComponent toastGui, long delta) if (starting) { - textColour = ColourHelper.colour(255, (int) ClientConfigManager.progressTextRed.get(), (int) ClientConfigManager.progressTextGreen.get(), (int) ClientConfigManager.progressTextBlue.get()); + textColour = ColourHelper.colour(255, ClientConfigManager.progressTextRed.get(), ClientConfigManager.progressTextGreen.get(), ClientConfigManager.progressTextBlue.get()); title = I18n.get("advancedbackups.backup_starting"); } else if (started) { - textColour = ColourHelper.colour(255, (int) ClientConfigManager.progressTextRed.get(), (int) ClientConfigManager.progressTextGreen.get(), (int) ClientConfigManager.progressTextBlue.get()); + textColour = ColourHelper.colour(255, ClientConfigManager.progressTextRed.get(), ClientConfigManager.progressTextGreen.get(), ClientConfigManager.progressTextBlue.get()); title = I18n.get("advancedbackups.progress", round(percent * 100)); } else if (failed) { - textColour = ColourHelper.colour(255, (int) ClientConfigManager.errorTextRed.get(), (int) ClientConfigManager.errorTextGreen.get(), (int) ClientConfigManager.errorTextBlue.get()); + textColour = ColourHelper.colour(255, ClientConfigManager.errorTextRed.get(), ClientConfigManager.errorTextGreen.get(), ClientConfigManager.errorTextBlue.get()); title = I18n.get("advancedbackups.backup_failed"); if (!timeSet) { time = System.currentTimeMillis(); @@ -85,7 +85,7 @@ else if (failed) { } } else if (finished) { - textColour = ColourHelper.colour(255, (int) ClientConfigManager.progressTextRed.get(), (int) ClientConfigManager.progressTextGreen.get(), (int) ClientConfigManager.progressTextBlue.get()); + textColour = ColourHelper.colour(255, ClientConfigManager.progressTextRed.get(), ClientConfigManager.progressTextGreen.get(), ClientConfigManager.progressTextBlue.get()); title = I18n.get("advancedbackups.backup_finished"); if (!timeSet) { time = System.currentTimeMillis(); @@ -93,7 +93,7 @@ else if (finished) { } } else if (cancelled) { - textColour = ColourHelper.colour(255, (int) ClientConfigManager.errorTextRed.get(), (int) ClientConfigManager.errorTextGreen.get(), (int) ClientConfigManager.errorTextBlue.get()); + textColour = ColourHelper.colour(255, ClientConfigManager.errorTextRed.get(), ClientConfigManager.errorTextGreen.get(), ClientConfigManager.errorTextBlue.get()); title = I18n.get("advancedbackups.backup_cancelled"); if (!timeSet) { time = System.currentTimeMillis(); @@ -116,7 +116,7 @@ else if (cancelled) { } Gui.fill(matrix, 4, 28, Math.max(4, (int) f), 29, ColourHelper.colour - (255, (int) ClientConfigManager.progressBarRed.get(), (int) ClientConfigManager.progressBarGreen.get(), (int) ClientConfigManager.progressBarBlue.get())); + (255, ClientConfigManager.progressBarRed.get(), ClientConfigManager.progressBarGreen.get(), ClientConfigManager.progressBarBlue.get())); return Visibility.SHOW; diff --git a/forge/1.19.2/src/main/java/computer/heather/advancedbackups/client/ClientWrapper.java b/forge/1.19.2/src/main/java/computer/heather/advancedbackups/client/ClientWrapper.java index 48e23fdb..2895ca8c 100644 --- a/forge/1.19.2/src/main/java/computer/heather/advancedbackups/client/ClientWrapper.java +++ b/forge/1.19.2/src/main/java/computer/heather/advancedbackups/client/ClientWrapper.java @@ -1,5 +1,8 @@ package computer.heather.advancedbackups.client; +import java.io.IOException; + +import computer.heather.advancedbackups.core.ABCore; import computer.heather.advancedbackups.core.config.ClientConfigManager; import computer.heather.advancedbackups.network.NetworkHandler; import computer.heather.advancedbackups.network.PacketBackupStatus; @@ -28,10 +31,15 @@ public static void handle(PacketBackupStatus packet) { } } - public static void init(FMLClientSetupEvent e) { + public static void init(FMLClientSetupEvent event) { MinecraftForge.EVENT_BUS.addListener(ClientWrapper::registerClientCommands); MinecraftForge.EVENT_BUS.addListener(ClientWrapper::onServerConnected); - ClientConfigManager.loadOrCreateConfig(); + try { + ClientConfigManager.loadOrCreateConfig(); + } catch (IOException e) { + ABCore.errorLogger.accept("Unable to load client config! Default will be used..."); + ABCore.logStackTrace(e); + } } public static void registerClientCommands(RegisterClientCommandsEvent event) { diff --git a/forge/1.19.3/src/main/java/computer/heather/advancedbackups/AdvancedBackups.java b/forge/1.19.3/src/main/java/computer/heather/advancedbackups/AdvancedBackups.java index edcfead8..c3878f28 100644 --- a/forge/1.19.3/src/main/java/computer/heather/advancedbackups/AdvancedBackups.java +++ b/forge/1.19.3/src/main/java/computer/heather/advancedbackups/AdvancedBackups.java @@ -1,5 +1,6 @@ package computer.heather.advancedbackups; +import java.io.IOException; import java.util.ArrayList; import java.util.List; import java.util.function.Consumer; @@ -85,8 +86,13 @@ public void onServerStarting(ServerStartingEvent event) ABCore.modJar = ModList.get().getModFileById("advancedbackups").getFile().getFilePath().toFile(); - ConfigManager.loadOrCreateConfig(); - LOGGER.info("Config loaded!!"); + try { + ConfigManager.loadOrCreateConfig(); + LOGGER.info("Config loaded!!"); + } catch (IOException e) { + LOGGER.error("Unable to load config! Falling back to defaults..."); + ABCore.logStackTrace(e); + } } diff --git a/forge/1.19.3/src/main/java/computer/heather/advancedbackups/AdvancedBackupsCommand.java b/forge/1.19.3/src/main/java/computer/heather/advancedbackups/AdvancedBackupsCommand.java index 0c008420..99d9ca3e 100644 --- a/forge/1.19.3/src/main/java/computer/heather/advancedbackups/AdvancedBackupsCommand.java +++ b/forge/1.19.3/src/main/java/computer/heather/advancedbackups/AdvancedBackupsCommand.java @@ -1,8 +1,11 @@ package computer.heather.advancedbackups; +import java.io.IOException; + import com.mojang.brigadier.CommandDispatcher; import com.mojang.brigadier.arguments.StringArgumentType; +import computer.heather.advancedbackups.core.ABCore; import computer.heather.advancedbackups.core.CoreCommandSystem; import net.minecraft.commands.CommandSourceStack; import net.minecraft.commands.Commands; @@ -20,10 +23,16 @@ public static void register(CommandDispatcher stack) { return 1; })) - .then(Commands.literal("reload-config").executes((runner) -> { - CoreCommandSystem.reloadConfig((response) -> { - runner.getSource().sendSuccess(Component.literal(response), true); - }); + .then(Commands.literal("reload-config").executes((runner) -> { + try { + CoreCommandSystem.reloadConfig((response) -> { + runner.getSource().sendSuccess(Component.literal(response), true); + }); + } catch (IOException e) { + runner.getSource().sendFailure(Component.literal("Command failed to execute! Check log for error")); + ABCore.errorLogger.accept("Error reloading config :"); + ABCore.logStackTrace(e); + } return 1; })) diff --git a/forge/1.19.3/src/main/java/computer/heather/advancedbackups/client/AdvancedBackupsClientCommand.java b/forge/1.19.3/src/main/java/computer/heather/advancedbackups/client/AdvancedBackupsClientCommand.java index 13573787..6329c42c 100644 --- a/forge/1.19.3/src/main/java/computer/heather/advancedbackups/client/AdvancedBackupsClientCommand.java +++ b/forge/1.19.3/src/main/java/computer/heather/advancedbackups/client/AdvancedBackupsClientCommand.java @@ -1,11 +1,13 @@ package computer.heather.advancedbackups.client; +import java.io.IOException; import java.time.Instant; import com.mojang.brigadier.CommandDispatcher; import com.mojang.brigadier.arguments.StringArgumentType; import com.mojang.brigadier.builder.LiteralArgumentBuilder; +import computer.heather.advancedbackups.core.ABCore; import computer.heather.advancedbackups.core.CoreCommandSystem; import net.minecraft.client.Minecraft; import net.minecraft.commands.CommandSourceStack; @@ -64,10 +66,16 @@ public static void register(CommandDispatcher commandDispatc return 1; })) - .then(literal("reload-client-config").executes((runner) -> { - CoreCommandSystem.reloadClientConfig((response) -> { - runner.getSource().sendSuccess(Component.literal(response), true); - }); + .then(literal("reload-client-config").executes((runner) -> { + try { + CoreCommandSystem.reloadClientConfig((response) -> { + runner.getSource().sendSuccess(Component.literal(response), true); + }); + } catch (IOException e) { + runner.getSource().sendFailure(Component.literal("Command failed to execute! Check log for error")); + ABCore.errorLogger.accept("Error reloading client config :"); + ABCore.logStackTrace(e); + } return 1; })) diff --git a/forge/1.19.3/src/main/java/computer/heather/advancedbackups/client/BackupToast.java b/forge/1.19.3/src/main/java/computer/heather/advancedbackups/client/BackupToast.java index cd2049ec..27588464 100644 --- a/forge/1.19.3/src/main/java/computer/heather/advancedbackups/client/BackupToast.java +++ b/forge/1.19.3/src/main/java/computer/heather/advancedbackups/client/BackupToast.java @@ -46,7 +46,7 @@ public Visibility render(PoseStack matrix, ToastComponent toastGui, long delta) float percent = finished ? 100 : (float) progress / (float) max; Gui.fill(matrix, 4, 28, 156, 29, ColourHelper.colour - (255, (int) ClientConfigManager.progressBackgroundRed.get(), (int) ClientConfigManager.progressBackgroundGreen.get(), (int) ClientConfigManager.progressBackgroundBlue.get())); + (255, ClientConfigManager.progressBackgroundRed.get(), ClientConfigManager.progressBackgroundGreen.get(), ClientConfigManager.progressBackgroundBlue.get())); float f = Math.min(156, ( 156 * percent @@ -54,13 +54,13 @@ public Visibility render(PoseStack matrix, ToastComponent toastGui, long delta) if (!exists) { if (title.equals(I18n.get("advancedbackups.backup_finished"))){ - textColour = ColourHelper.colour(255, (int) ClientConfigManager.progressTextRed.get(), (int) ClientConfigManager.progressTextGreen.get(), (int) ClientConfigManager.progressTextBlue.get()); + textColour = ColourHelper.colour(255, ClientConfigManager.progressTextRed.get(), ClientConfigManager.progressTextGreen.get(), ClientConfigManager.progressTextBlue.get()); toastGui.getMinecraft().font.draw(matrix, I18n.get(title), 25, 11, textColour); Gui.fill(matrix, 3, 28, 156, 29, ColourHelper.colour - (255, (int) ClientConfigManager.progressBarRed.get(), (int) ClientConfigManager.progressBarGreen.get(), (int) ClientConfigManager.progressBarBlue.get())); + (255, ClientConfigManager.progressBarRed.get(), ClientConfigManager.progressBarGreen.get(), ClientConfigManager.progressBarBlue.get())); } else { - textColour = ColourHelper.colour(255, (int) ClientConfigManager.errorTextRed.get(), (int) ClientConfigManager.errorTextGreen.get(), (int) ClientConfigManager.errorTextBlue.get()); + textColour = ColourHelper.colour(255, ClientConfigManager.errorTextRed.get(), ClientConfigManager.errorTextGreen.get(), ClientConfigManager.errorTextBlue.get()); toastGui.getMinecraft().font.draw(matrix, I18n.get(title), 25, 11, textColour); } return Visibility.HIDE; @@ -70,15 +70,15 @@ public Visibility render(PoseStack matrix, ToastComponent toastGui, long delta) if (starting) { - textColour = ColourHelper.colour(255, (int) ClientConfigManager.progressTextRed.get(), (int) ClientConfigManager.progressTextGreen.get(), (int) ClientConfigManager.progressTextBlue.get()); + textColour = ColourHelper.colour(255, ClientConfigManager.progressTextRed.get(), ClientConfigManager.progressTextGreen.get(), ClientConfigManager.progressTextBlue.get()); title = I18n.get("advancedbackups.backup_starting"); } else if (started) { - textColour = ColourHelper.colour(255, (int) ClientConfigManager.progressTextRed.get(), (int) ClientConfigManager.progressTextGreen.get(), (int) ClientConfigManager.progressTextBlue.get()); + textColour = ColourHelper.colour(255, ClientConfigManager.progressTextRed.get(), ClientConfigManager.progressTextGreen.get(), ClientConfigManager.progressTextBlue.get()); title = I18n.get("advancedbackups.progress", round(percent * 100)); } else if (failed) { - textColour = ColourHelper.colour(255, (int) ClientConfigManager.errorTextRed.get(), (int) ClientConfigManager.errorTextGreen.get(), (int) ClientConfigManager.errorTextBlue.get()); + textColour = ColourHelper.colour(255, ClientConfigManager.errorTextRed.get(), ClientConfigManager.errorTextGreen.get(), ClientConfigManager.errorTextBlue.get()); title = I18n.get("advancedbackups.backup_failed"); if (!timeSet) { time = System.currentTimeMillis(); @@ -86,7 +86,7 @@ else if (failed) { } } else if (finished) { - textColour = ColourHelper.colour(255, (int) ClientConfigManager.progressTextRed.get(), (int) ClientConfigManager.progressTextGreen.get(), (int) ClientConfigManager.progressTextBlue.get()); + textColour = ColourHelper.colour(255, ClientConfigManager.progressTextRed.get(), ClientConfigManager.progressTextGreen.get(), ClientConfigManager.progressTextBlue.get()); title = I18n.get("advancedbackups.backup_finished"); if (!timeSet) { time = System.currentTimeMillis(); @@ -94,7 +94,7 @@ else if (finished) { } } else if (cancelled) { - textColour = ColourHelper.colour(255, (int) ClientConfigManager.errorTextRed.get(), (int) ClientConfigManager.errorTextGreen.get(), (int) ClientConfigManager.errorTextBlue.get()); + textColour = ColourHelper.colour(255, ClientConfigManager.errorTextRed.get(), ClientConfigManager.errorTextGreen.get(), ClientConfigManager.errorTextBlue.get()); title = I18n.get("advancedbackups.backup_cancelled"); if (!timeSet) { time = System.currentTimeMillis(); @@ -117,7 +117,7 @@ else if (cancelled) { } Gui.fill(matrix, 4, 28, Math.max(4, (int) f), 29, ColourHelper.colour - (255, (int) ClientConfigManager.progressBarRed.get(), (int) ClientConfigManager.progressBarGreen.get(), (int) ClientConfigManager.progressBarBlue.get())); + (255, ClientConfigManager.progressBarRed.get(), ClientConfigManager.progressBarGreen.get(), ClientConfigManager.progressBarBlue.get())); return Visibility.SHOW; diff --git a/forge/1.19.3/src/main/java/computer/heather/advancedbackups/client/ClientWrapper.java b/forge/1.19.3/src/main/java/computer/heather/advancedbackups/client/ClientWrapper.java index 48e23fdb..2895ca8c 100644 --- a/forge/1.19.3/src/main/java/computer/heather/advancedbackups/client/ClientWrapper.java +++ b/forge/1.19.3/src/main/java/computer/heather/advancedbackups/client/ClientWrapper.java @@ -1,5 +1,8 @@ package computer.heather.advancedbackups.client; +import java.io.IOException; + +import computer.heather.advancedbackups.core.ABCore; import computer.heather.advancedbackups.core.config.ClientConfigManager; import computer.heather.advancedbackups.network.NetworkHandler; import computer.heather.advancedbackups.network.PacketBackupStatus; @@ -28,10 +31,15 @@ public static void handle(PacketBackupStatus packet) { } } - public static void init(FMLClientSetupEvent e) { + public static void init(FMLClientSetupEvent event) { MinecraftForge.EVENT_BUS.addListener(ClientWrapper::registerClientCommands); MinecraftForge.EVENT_BUS.addListener(ClientWrapper::onServerConnected); - ClientConfigManager.loadOrCreateConfig(); + try { + ClientConfigManager.loadOrCreateConfig(); + } catch (IOException e) { + ABCore.errorLogger.accept("Unable to load client config! Default will be used..."); + ABCore.logStackTrace(e); + } } public static void registerClientCommands(RegisterClientCommandsEvent event) { diff --git a/forge/1.20/src/main/java/computer/heather/advancedbackups/AdvancedBackups.java b/forge/1.20/src/main/java/computer/heather/advancedbackups/AdvancedBackups.java index e4ec4915..0e62d285 100644 --- a/forge/1.20/src/main/java/computer/heather/advancedbackups/AdvancedBackups.java +++ b/forge/1.20/src/main/java/computer/heather/advancedbackups/AdvancedBackups.java @@ -1,5 +1,6 @@ package computer.heather.advancedbackups; +import java.io.IOException; import java.util.ArrayList; import java.util.List; import java.util.function.Consumer; @@ -75,8 +76,13 @@ public void onServerStarting(ServerStartingEvent event) ABCore.modJar = ModList.get().getModFileById("advancedbackups").getFile().getFilePath().toFile(); - ConfigManager.loadOrCreateConfig(); - LOGGER.info("Config loaded!!"); + try { + ConfigManager.loadOrCreateConfig(); + LOGGER.info("Config loaded!!"); + } catch (IOException e) { + LOGGER.error("Unable to load config! Falling back to defaults..."); + ABCore.logStackTrace(e); + } } diff --git a/forge/1.20/src/main/java/computer/heather/advancedbackups/AdvancedBackupsCommand.java b/forge/1.20/src/main/java/computer/heather/advancedbackups/AdvancedBackupsCommand.java index bc300b95..5b0290c1 100644 --- a/forge/1.20/src/main/java/computer/heather/advancedbackups/AdvancedBackupsCommand.java +++ b/forge/1.20/src/main/java/computer/heather/advancedbackups/AdvancedBackupsCommand.java @@ -1,8 +1,11 @@ package computer.heather.advancedbackups; +import java.io.IOException; + import com.mojang.brigadier.CommandDispatcher; import com.mojang.brigadier.arguments.StringArgumentType; +import computer.heather.advancedbackups.core.ABCore; import computer.heather.advancedbackups.core.CoreCommandSystem; import net.minecraft.commands.CommandSourceStack; import net.minecraft.commands.Commands; @@ -22,12 +25,16 @@ public static void register(CommandDispatcher stack) { return 1; })) - .then(Commands.literal("reload-config").executes((runner) -> { - CoreCommandSystem.reloadConfig((response) -> { - runner.getSource().sendSuccess(() -> { - return Component.literal(response) ; - }, true); - }); + .then(Commands.literal("reload-config").executes((runner) -> { + try { + CoreCommandSystem.reloadConfig((response) -> { + runner.getSource().sendSuccess(() -> Component.literal(response), true); + }); + } catch (IOException e) { + runner.getSource().sendFailure(Component.literal("Command failed to execute! Check log for error")); + ABCore.errorLogger.accept("Error reloading config :"); + ABCore.logStackTrace(e); + } return 1; })) diff --git a/forge/1.20/src/main/java/computer/heather/advancedbackups/client/AdvancedBackupsClientCommand.java b/forge/1.20/src/main/java/computer/heather/advancedbackups/client/AdvancedBackupsClientCommand.java index 11b901a5..2cc55d24 100644 --- a/forge/1.20/src/main/java/computer/heather/advancedbackups/client/AdvancedBackupsClientCommand.java +++ b/forge/1.20/src/main/java/computer/heather/advancedbackups/client/AdvancedBackupsClientCommand.java @@ -1,11 +1,13 @@ package computer.heather.advancedbackups.client; +import java.io.IOException; import java.time.Instant; import com.mojang.brigadier.CommandDispatcher; import com.mojang.brigadier.arguments.StringArgumentType; import com.mojang.brigadier.builder.LiteralArgumentBuilder; +import computer.heather.advancedbackups.core.ABCore; import computer.heather.advancedbackups.core.CoreCommandSystem; import net.minecraft.client.Minecraft; import net.minecraft.commands.CommandSourceStack; @@ -14,8 +16,6 @@ import net.minecraft.network.chat.Component; import net.minecraft.network.chat.LastSeenMessages.Update; import net.minecraft.network.protocol.game.ServerboundChatCommandPacket; -import net.minecraftforge.client.ClientCommandSourceStack; -import net.minecraftforge.server.ServerLifecycleHooks; public class AdvancedBackupsClientCommand { public static void register(CommandDispatcher commandDispatcher) { @@ -64,12 +64,16 @@ public static void register(CommandDispatcher commandDispatc return 1; })) - .then(literal("reload-client-config").executes((runner) -> { - CoreCommandSystem.reloadClientConfig((response) -> { - runner.getSource().sendSuccess(() -> { - return Component.literal(response); - }, true); - }); + .then(literal("reload-client-config").executes((runner) -> { + try { + CoreCommandSystem.reloadClientConfig((response) -> { + runner.getSource().sendSuccess(() -> Component.literal(response), true); + }); + } catch (IOException e) { + runner.getSource().sendFailure(Component.literal("Command failed to execute! Check log for error")); + ABCore.errorLogger.accept("Error reloading client config :"); + ABCore.logStackTrace(e); + } return 1; })) diff --git a/forge/1.20/src/main/java/computer/heather/advancedbackups/client/BackupToast.java b/forge/1.20/src/main/java/computer/heather/advancedbackups/client/BackupToast.java index b4b03809..2f433f08 100644 --- a/forge/1.20/src/main/java/computer/heather/advancedbackups/client/BackupToast.java +++ b/forge/1.20/src/main/java/computer/heather/advancedbackups/client/BackupToast.java @@ -45,7 +45,7 @@ public Visibility render(GuiGraphics graphics, ToastComponent toastGui, long del float percent = finished ? 100 : (float) progress / (float) max; graphics.fill(4, 28, 156, 29, ColourHelper.colour - (255, (int) ClientConfigManager.progressBackgroundRed.get(), (int) ClientConfigManager.progressBackgroundGreen.get(), (int) ClientConfigManager.progressBackgroundBlue.get())); + (255, ClientConfigManager.progressBackgroundRed.get(), ClientConfigManager.progressBackgroundGreen.get(), ClientConfigManager.progressBackgroundBlue.get())); float f = Math.min(156, ( 156 * percent @@ -53,13 +53,13 @@ public Visibility render(GuiGraphics graphics, ToastComponent toastGui, long del if (!exists) { if (title.equals(I18n.get("advancedbackups.backup_finished"))){ - textColour = ColourHelper.colour(255, (int) ClientConfigManager.progressTextRed.get(), (int) ClientConfigManager.progressTextGreen.get(), (int) ClientConfigManager.progressTextBlue.get()); + textColour = ColourHelper.colour(255, ClientConfigManager.progressTextRed.get(), ClientConfigManager.progressTextGreen.get(), ClientConfigManager.progressTextBlue.get()); graphics.drawString(toastGui.getMinecraft().font, I18n.get(title), 25, 11, textColour); graphics.fill(3, 28, 156, 29, ColourHelper.colour - (255, (int) ClientConfigManager.progressBarRed.get(), (int) ClientConfigManager.progressBarGreen.get(), (int) ClientConfigManager.progressBarBlue.get())); + (255, ClientConfigManager.progressBarRed.get(), ClientConfigManager.progressBarGreen.get(), ClientConfigManager.progressBarBlue.get())); } else { - textColour = ColourHelper.colour(255, (int) ClientConfigManager.errorTextRed.get(), (int) ClientConfigManager.errorTextGreen.get(), (int) ClientConfigManager.errorTextBlue.get()); + textColour = ColourHelper.colour(255, ClientConfigManager.errorTextRed.get(), ClientConfigManager.errorTextGreen.get(), ClientConfigManager.errorTextBlue.get()); graphics.drawString(toastGui.getMinecraft().font, I18n.get(title), 25, 11, textColour); } return Visibility.HIDE; @@ -67,15 +67,15 @@ public Visibility render(GuiGraphics graphics, ToastComponent toastGui, long del if (starting) { - textColour = ColourHelper.colour(255, (int) ClientConfigManager.progressTextRed.get(), (int) ClientConfigManager.progressTextGreen.get(), (int) ClientConfigManager.progressTextBlue.get()); + textColour = ColourHelper.colour(255, ClientConfigManager.progressTextRed.get(), ClientConfigManager.progressTextGreen.get(), ClientConfigManager.progressTextBlue.get()); title = I18n.get("advancedbackups.backup_starting"); } else if (started) { - textColour = ColourHelper.colour(255, (int) ClientConfigManager.progressTextRed.get(), (int) ClientConfigManager.progressTextGreen.get(), (int) ClientConfigManager.progressTextBlue.get()); + textColour = ColourHelper.colour(255, ClientConfigManager.progressTextRed.get(), ClientConfigManager.progressTextGreen.get(), ClientConfigManager.progressTextBlue.get()); title = I18n.get("advancedbackups.progress", round(percent * 100)); } else if (failed) { - textColour = ColourHelper.colour(255, (int) ClientConfigManager.errorTextRed.get(), (int) ClientConfigManager.errorTextGreen.get(), (int) ClientConfigManager.errorTextBlue.get()); + textColour = ColourHelper.colour(255, ClientConfigManager.errorTextRed.get(), ClientConfigManager.errorTextGreen.get(), ClientConfigManager.errorTextBlue.get()); title = I18n.get("advancedbackups.backup_failed"); if (!timeSet) { time = System.currentTimeMillis(); @@ -83,7 +83,7 @@ else if (failed) { } } else if (finished) { - textColour = ColourHelper.colour(255, (int) ClientConfigManager.progressTextRed.get(), (int) ClientConfigManager.progressTextGreen.get(), (int) ClientConfigManager.progressTextBlue.get()); + textColour = ColourHelper.colour(255, ClientConfigManager.progressTextRed.get(), ClientConfigManager.progressTextGreen.get(), ClientConfigManager.progressTextBlue.get()); title = I18n.get("advancedbackups.backup_finished"); if (!timeSet) { time = System.currentTimeMillis(); @@ -91,7 +91,7 @@ else if (finished) { } } else if (cancelled) { - textColour = ColourHelper.colour(255, (int) ClientConfigManager.errorTextRed.get(), (int) ClientConfigManager.errorTextGreen.get(), (int) ClientConfigManager.errorTextBlue.get()); + textColour = ColourHelper.colour(255, ClientConfigManager.errorTextRed.get(), ClientConfigManager.errorTextGreen.get(), ClientConfigManager.errorTextBlue.get()); title = I18n.get("advancedbackups.backup_cancelled"); if (!timeSet) { time = System.currentTimeMillis(); @@ -114,7 +114,7 @@ else if (cancelled) { } graphics.fill(4, 28, Math.max(4, (int) f), 29, ColourHelper.colour - (255, (int) ClientConfigManager.progressBarRed.get(), (int) ClientConfigManager.progressBarGreen.get(), (int) ClientConfigManager.progressBarBlue.get())); + (255, ClientConfigManager.progressBarRed.get(), ClientConfigManager.progressBarGreen.get(), ClientConfigManager.progressBarBlue.get())); return Visibility.SHOW; diff --git a/forge/1.20/src/main/java/computer/heather/advancedbackups/client/ClientWrapper.java b/forge/1.20/src/main/java/computer/heather/advancedbackups/client/ClientWrapper.java index cff2706b..1fb62c88 100644 --- a/forge/1.20/src/main/java/computer/heather/advancedbackups/client/ClientWrapper.java +++ b/forge/1.20/src/main/java/computer/heather/advancedbackups/client/ClientWrapper.java @@ -1,5 +1,8 @@ package computer.heather.advancedbackups.client; +import java.io.IOException; + +import computer.heather.advancedbackups.core.ABCore; import computer.heather.advancedbackups.core.config.ClientConfigManager; import computer.heather.advancedbackups.network.NetworkHandler; import computer.heather.advancedbackups.network.PacketBackupStatus; @@ -30,10 +33,15 @@ public static void handle(PacketBackupStatus packet) { } } - public static void init(FMLClientSetupEvent e) { + public static void init(FMLClientSetupEvent event) { MinecraftForge.EVENT_BUS.addListener(ClientWrapper::registerClientCommands); MinecraftForge.EVENT_BUS.addListener(ClientWrapper::onServerConnected); - ClientConfigManager.loadOrCreateConfig(); + try { + ClientConfigManager.loadOrCreateConfig(); + } catch (IOException e) { + ABCore.errorLogger.accept("Unable to load client config! Default will be used..."); + ABCore.logStackTrace(e); + } } public static void registerClientCommands(RegisterClientCommandsEvent event) { diff --git a/forge/1.7.10/src/main/java/computer/heather/advancedbackups/AdvancedBackups.java b/forge/1.7.10/src/main/java/computer/heather/advancedbackups/AdvancedBackups.java index a7dbc050..33e9a948 100644 --- a/forge/1.7.10/src/main/java/computer/heather/advancedbackups/AdvancedBackups.java +++ b/forge/1.7.10/src/main/java/computer/heather/advancedbackups/AdvancedBackups.java @@ -30,6 +30,7 @@ import net.minecraftforge.common.MinecraftForge; import java.io.File; +import java.io.IOException; import java.util.ArrayList; import java.util.function.Consumer; @@ -101,8 +102,13 @@ public void onServerStarting(FMLServerStartingEvent event) ABCore.modJar = Loader.instance().getIndexedModList().get("advancedbackups").getSource(); - ConfigManager.loadOrCreateConfig(); - LOGGER.info("Config loaded!!"); + try { + ConfigManager.loadOrCreateConfig(); + LOGGER.info("Config loaded!!"); + } catch (IOException e) { + LOGGER.error("Unable to load config! Falling back to defaults..."); + ABCore.logStackTrace(e); + } } diff --git a/forge/1.7.10/src/main/java/computer/heather/advancedbackups/AdvancedBackupsCommand.java b/forge/1.7.10/src/main/java/computer/heather/advancedbackups/AdvancedBackupsCommand.java index a46f4ee0..57e22efa 100644 --- a/forge/1.7.10/src/main/java/computer/heather/advancedbackups/AdvancedBackupsCommand.java +++ b/forge/1.7.10/src/main/java/computer/heather/advancedbackups/AdvancedBackupsCommand.java @@ -1,7 +1,9 @@ package computer.heather.advancedbackups; +import java.io.IOException; import java.util.Arrays; +import computer.heather.advancedbackups.core.ABCore; import computer.heather.advancedbackups.core.CoreCommandSystem; import computer.heather.advancedbackups.network.NetworkHandler; import computer.heather.advancedbackups.network.PacketClientReload; @@ -84,9 +86,15 @@ else if ("cancel".equals(args[0])) { public static class Reload { public static void execute(ICommandSender sender) { - CoreCommandSystem.reloadConfig((response) -> { - sender.addChatMessage(new ChatComponentText(response)); - }); + try { + CoreCommandSystem.reloadConfig((response) -> { + sender.addChatMessage(new ChatComponentText(response)); + }); + } catch (IOException e) { + sender.addChatMessage(new ChatComponentText("Command failed to execute! Check log for error")); + ABCore.errorLogger.accept("Error reloading config :"); + ABCore.logStackTrace(e); + } } } diff --git a/forge/1.7.10/src/main/java/computer/heather/advancedbackups/client/ABClientRenderer.java b/forge/1.7.10/src/main/java/computer/heather/advancedbackups/client/ABClientRenderer.java index 2a52a4ce..da182af6 100644 --- a/forge/1.7.10/src/main/java/computer/heather/advancedbackups/client/ABClientRenderer.java +++ b/forge/1.7.10/src/main/java/computer/heather/advancedbackups/client/ABClientRenderer.java @@ -1,7 +1,10 @@ package computer.heather.advancedbackups.client; +import java.io.IOException; + import com.mojang.realmsclient.gui.ChatFormatting; +import computer.heather.advancedbackups.core.ABCore; import computer.heather.advancedbackups.core.config.ClientConfigManager; import computer.heather.advancedbackups.network.NetworkHandler; import computer.heather.advancedbackups.network.PacketToastSubscribe; @@ -83,7 +86,12 @@ private static String round (float value) { @SubscribeEvent public void onServerConnected(ClientConnectedToServerEvent event) { //may aswell just do it here. 1.7 is so horribly documented - ClientConfigManager.loadOrCreateConfig(); + try { + ClientConfigManager.loadOrCreateConfig(); + } catch (IOException e) { + ABCore.errorLogger.accept("Unable to load client config! Default will be used..."); + ABCore.logStackTrace(e); + } //NetworkHandler.HANDLER.sendToServer(new PacketToastSubscribe(ClientConfigManager.showProgress.get())); diff --git a/forge/1.7.10/src/main/java/computer/heather/advancedbackups/network/PacketClientReload.java b/forge/1.7.10/src/main/java/computer/heather/advancedbackups/network/PacketClientReload.java index 84ec6f05..f81049b0 100644 --- a/forge/1.7.10/src/main/java/computer/heather/advancedbackups/network/PacketClientReload.java +++ b/forge/1.7.10/src/main/java/computer/heather/advancedbackups/network/PacketClientReload.java @@ -1,11 +1,15 @@ package computer.heather.advancedbackups.network; +import java.io.IOException; + +import computer.heather.advancedbackups.core.ABCore; import computer.heather.advancedbackups.core.CoreCommandSystem; import cpw.mods.fml.common.network.simpleimpl.IMessage; import cpw.mods.fml.common.network.simpleimpl.IMessageHandler; import cpw.mods.fml.common.network.simpleimpl.MessageContext; import io.netty.buffer.ByteBuf; import net.minecraft.client.Minecraft; +import net.minecraft.util.ChatComponentText; //I hate this. public class PacketClientReload implements IMessage{ @@ -35,7 +39,13 @@ public static class Handler implements IMessageHandler Minecraft.getMinecraft().thePlayer.addChatMessage(new ChatComponentText(response))); + } catch (IOException e) { + Minecraft.getMinecraft().thePlayer.addChatMessage(new ChatComponentText("Command failed to execute! Check log for error")); + ABCore.errorLogger.accept("Error reloading config :"); + ABCore.logStackTrace(e); + } return null; }