#450 Port usages of Settings#set(), #setValue() to NewSettings
This commit is contained in:
@@ -28,8 +28,7 @@ public class NewSetting {
|
||||
private FileConfiguration configuration;
|
||||
|
||||
/**
|
||||
* Constructor.
|
||||
* Loads the file as YAML and checks its integrity.
|
||||
* Constructor. Checks the given {@link FileConfiguration} object for completeness.
|
||||
*
|
||||
* @param configuration The configuration to interact with
|
||||
* @param file The configuration file
|
||||
@@ -74,7 +73,25 @@ public class NewSetting {
|
||||
return property.getFromFile(configuration);
|
||||
}
|
||||
|
||||
public void save(PropertyMap propertyMap) {
|
||||
/**
|
||||
* Set a new value for the given property.
|
||||
*
|
||||
* @param property The property to modify
|
||||
* @param value The new value to assign to the property
|
||||
* @param <T> The property's type
|
||||
*/
|
||||
public <T> void setProperty(Property<T> property, T value) {
|
||||
configuration.set(property.getPath(), value);
|
||||
}
|
||||
|
||||
/**
|
||||
* Save the config file. Use after migrating one or more settings.
|
||||
*/
|
||||
public void save() {
|
||||
save(SettingsFieldRetriever.getAllPropertyFields());
|
||||
}
|
||||
|
||||
private void save(PropertyMap propertyMap) {
|
||||
try (FileWriter writer = new FileWriter(file)) {
|
||||
Yaml simpleYaml = newYaml(false);
|
||||
Yaml singleQuoteYaml = newYaml(true);
|
||||
@@ -165,7 +182,7 @@ public class NewSetting {
|
||||
}
|
||||
|
||||
private static String indent(int level) {
|
||||
// YAML uses indentation of 4 spaces
|
||||
// We use an indentation of 4 spaces
|
||||
StringBuilder sb = new StringBuilder(level * 4);
|
||||
for (int i = 0; i < level; ++i) {
|
||||
sb.append(" ");
|
||||
|
||||
@@ -31,9 +31,8 @@ public final class Settings {
|
||||
public static final File PLUGIN_FOLDER = Wrapper.getInstance().getDataFolder();
|
||||
public static final File MODULE_FOLDER = new File(PLUGIN_FOLDER, "modules");
|
||||
public static final File CACHE_FOLDER = new File(PLUGIN_FOLDER, "cache");
|
||||
public static final File AUTH_FILE = new File(PLUGIN_FOLDER, "auths.db");
|
||||
public static final File EMAIL_FILE = new File(PLUGIN_FOLDER, "email.html");
|
||||
public static final File SETTINGS_FILE = new File(PLUGIN_FOLDER, "config.yml");
|
||||
private static final File EMAIL_FILE = new File(PLUGIN_FOLDER, "email.html");
|
||||
private static final File SETTINGS_FILE = new File(PLUGIN_FOLDER, "config.yml");
|
||||
public static final File LOG_FILE = new File(PLUGIN_FOLDER, "authme.log");
|
||||
// This is not an option!
|
||||
public static boolean antiBotInAction = false;
|
||||
@@ -311,15 +310,6 @@ public final class Settings {
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @param key the key to set
|
||||
* @param value the value to set
|
||||
*/
|
||||
public static void setValue(String key, Object value) {
|
||||
instance.set(key, value);
|
||||
save();
|
||||
}
|
||||
|
||||
/**
|
||||
* Method getPasswordHash.
|
||||
*
|
||||
@@ -392,7 +382,7 @@ public final class Settings {
|
||||
*
|
||||
* @return True if saved successfully
|
||||
*/
|
||||
public static boolean save() {
|
||||
private static boolean save() {
|
||||
try {
|
||||
configFile.save(SETTINGS_FILE);
|
||||
return true;
|
||||
@@ -503,25 +493,6 @@ public final class Settings {
|
||||
return correct;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param path
|
||||
*
|
||||
* @return
|
||||
*/
|
||||
private static boolean contains(String path) {
|
||||
return configFile.contains(path);
|
||||
}
|
||||
|
||||
// public because it's used in AuthMe at one place
|
||||
|
||||
/**
|
||||
* @param path String
|
||||
* @param value String
|
||||
*/
|
||||
public void set(String path, Object value) {
|
||||
configFile.set(path, value);
|
||||
}
|
||||
|
||||
/**
|
||||
* Saves current configuration (plus defaults) to disk.
|
||||
* <p>
|
||||
@@ -529,7 +500,7 @@ public final class Settings {
|
||||
*
|
||||
* @return True if saved successfully
|
||||
*/
|
||||
public final boolean saveDefaults() {
|
||||
private boolean saveDefaults() {
|
||||
configFile.options()
|
||||
.copyDefaults(true)
|
||||
.copyHeader(true);
|
||||
|
||||
Reference in New Issue
Block a user