diff --git a/core/src/main/java/com/seibel/distanthorizons/core/config/eventHandlers/presets/AbstractPresetConfigEventHandler.java b/core/src/main/java/com/seibel/distanthorizons/core/config/eventHandlers/presets/AbstractPresetConfigEventHandler.java index 53f0dd9cf..343af2b65 100644 --- a/core/src/main/java/com/seibel/distanthorizons/core/config/eventHandlers/presets/AbstractPresetConfigEventHandler.java +++ b/core/src/main/java/com/seibel/distanthorizons/core/config/eventHandlers/presets/AbstractPresetConfigEventHandler.java @@ -122,9 +122,6 @@ public abstract class AbstractPresetConfigEventHandler) entry.getType()))); + entry.pureSet((T) (workConfig.getEnum(entry.getNameWCategory(), (Class) entry.getType()))); return; } Class originalClass = ConfigTypeConverters.isClassConvertable(entry.getType()); if (originalClass != null) { - entry.setWithoutSaving((T) ConfigTypeConverters.convertFromString(originalClass, workConfig.get(entry.getNameWCategory()))); + entry.pureSet((T) ConfigTypeConverters.convertFromString(originalClass, workConfig.get(entry.getNameWCategory()))); return; } if (entry.getType() == workConfig.get(entry.getNameWCategory()).getClass()) { // If the types are the same - entry.setWithoutSaving((T) workConfig.get(entry.getNameWCategory())); + entry.pureSet((T) workConfig.get(entry.getNameWCategory())); entry.clampWithinRange(); return; } @@ -247,19 +247,11 @@ public class ConfigFileHandling Files.createDirectory(this.configPath.getParent()); } - try - { - boolean fileDeleted = Files.deleteIfExists(this.configPath); - System.out.println("File at [" + this.configPath + "] was " + (fileDeleted ? "" : "not ") + "able to be deleted."); - } - catch (AccessDeniedException ignored) { /* temporary fix due to windows/Intellij issues either locking or changing the permissions of the file */ } + boolean fileDeleted = Files.deleteIfExists(this.configPath); + System.out.println("File at [" + this.configPath + "] was " + (fileDeleted ? "" : "not ") + "able to be deleted."); - try - { - Files.createFile(this.configPath); - } - catch (FileAlreadyExistsException ignore) { /* temporary fix due to windows/Intellij issues either locking or changing the permissions of the file */ } + Files.createFile(this.configPath); config.load(); } diff --git a/core/src/main/java/com/seibel/distanthorizons/core/config/listeners/IConfigListener.java b/core/src/main/java/com/seibel/distanthorizons/core/config/listeners/IConfigListener.java index 20749748c..5d643db5b 100644 --- a/core/src/main/java/com/seibel/distanthorizons/core/config/listeners/IConfigListener.java +++ b/core/src/main/java/com/seibel/distanthorizons/core/config/listeners/IConfigListener.java @@ -3,12 +3,9 @@ package com.seibel.distanthorizons.core.config.listeners; public interface IConfigListener { /** Called whenever the value is set (including in core DH code) */ - void onConfigValueSet(); + default void onConfigValueSet() {}; - /** - * TODO not implemented - * Called whenever the value is changed through the UI (only when the done button is pressed) - */ - void onUiModify(); + /** Called whenever the value is changed through the UI */ + default void onUiModify() {}; } diff --git a/core/src/main/java/com/seibel/distanthorizons/core/config/types/ConfigEntry.java b/core/src/main/java/com/seibel/distanthorizons/core/config/types/ConfigEntry.java index f768ffb13..cf3a820d1 100644 --- a/core/src/main/java/com/seibel/distanthorizons/core/config/types/ConfigEntry.java +++ b/core/src/main/java/com/seibel/distanthorizons/core/config/types/ConfigEntry.java @@ -66,18 +66,42 @@ public class ConfigEntry extends AbstractConfigType> implem public T getApiValue() { return this.apiValue; } @Override public boolean getAllowApiOverride() { return this.allowApiOverride; } + + /** + * DONT USE THIS IN YOUR CODE
+ * Sets the value without informing the rest of the code (ie, doesnt call listeners, or saves the value).
+ * Should only be used when loading the config from the file + */ + public void pureSet(T newValue) { + super.set(newValue); + } + + /** Sets the value without saving */ + @Override + public void setWithoutSaving(T newValue) + { + super.set(newValue); + this.listenerList.forEach(IConfigListener::onConfigValueSet); + } @Override public void set(T newValue) { - super.set(newValue); + this.setWithoutSaving(newValue); this.save(); - this.listenerList.forEach(IConfigListener::onConfigValueSet); + } + + public void uiSetWithoutSaving(T newValue) + { + this.setWithoutSaving(newValue); + this.listenerList.forEach(IConfigListener::onUiModify); } public void uiSet(T newValue) { this.set(newValue); this.listenerList.forEach(IConfigListener::onUiModify); } + + @Override public T get() { @@ -94,13 +118,6 @@ public class ConfigEntry extends AbstractConfigType> implem return super.get(); } - /** Sets the value without saving */ - @Override - public void setWithoutSaving(T newValue) - { - super.set(newValue); - this.listenerList.forEach(IConfigListener::onConfigValueSet); - } /** Gets the min value */ @Override @@ -301,7 +318,9 @@ public class ConfigEntry extends AbstractConfigType> implem return this; } - public Builder replaceListener(ArrayList newConfigListener) + + + public Builder replaceListeners(ArrayList newConfigListener) { this.tmpIConfigListener = newConfigListener; return this;