mirror of
https://github.com/FancyInnovations/FancyPlugins.git
synced 2025-12-06 07:43:36 +00:00
config: Add forceDefault option
This commit is contained in:
@@ -45,12 +45,16 @@ public class Config {
|
|||||||
*/
|
*/
|
||||||
public <T> T get(String path) {
|
public <T> T get(String path) {
|
||||||
ConfigField<?> field = fields.get(path);
|
ConfigField<?> field = fields.get(path);
|
||||||
if (field != null) {
|
if (field == null) {
|
||||||
Object value = values.computeIfAbsent(path, k -> field.defaultValue());
|
return null;
|
||||||
return (T) field.type().cast(value);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
return null;
|
if (field.forceDefault()) {
|
||||||
|
return (T) field.defaultValue();
|
||||||
|
}
|
||||||
|
|
||||||
|
Object value = values.computeIfAbsent(path, k -> field.defaultValue());
|
||||||
|
return (T) field.type().cast(value);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|||||||
@@ -8,6 +8,7 @@ package com.fancyinnovations.config;
|
|||||||
* @param description a description of the field
|
* @param description a description of the field
|
||||||
* @param forRemoval indicates if this field should be removed
|
* @param forRemoval indicates if this field should be removed
|
||||||
* @param defaultValue the default value of the field
|
* @param defaultValue the default value of the field
|
||||||
|
* @param forceDefault indicates if the default value should be enforced
|
||||||
* @param type the class type of the field value
|
* @param type the class type of the field value
|
||||||
*/
|
*/
|
||||||
public record ConfigField<T>(
|
public record ConfigField<T>(
|
||||||
@@ -15,6 +16,7 @@ public record ConfigField<T>(
|
|||||||
String description,
|
String description,
|
||||||
boolean forRemoval,
|
boolean forRemoval,
|
||||||
T defaultValue,
|
T defaultValue,
|
||||||
|
boolean forceDefault,
|
||||||
Class<T> type
|
Class<T> type
|
||||||
) {
|
) {
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -26,6 +26,7 @@ public final class FHConfiguration implements HologramConfiguration {
|
|||||||
"Whether version notifications are muted.",
|
"Whether version notifications are muted.",
|
||||||
false,
|
false,
|
||||||
false,
|
false,
|
||||||
|
false,
|
||||||
Boolean.class
|
Boolean.class
|
||||||
));
|
));
|
||||||
|
|
||||||
@@ -34,6 +35,7 @@ public final class FHConfiguration implements HologramConfiguration {
|
|||||||
"Whether autosave is enabled.",
|
"Whether autosave is enabled.",
|
||||||
false,
|
false,
|
||||||
true,
|
true,
|
||||||
|
false,
|
||||||
Boolean.class
|
Boolean.class
|
||||||
));
|
));
|
||||||
|
|
||||||
@@ -42,6 +44,7 @@ public final class FHConfiguration implements HologramConfiguration {
|
|||||||
"The interval at which autosave is performed in minutes.",
|
"The interval at which autosave is performed in minutes.",
|
||||||
false,
|
false,
|
||||||
15,
|
15,
|
||||||
|
false,
|
||||||
Integer.class
|
Integer.class
|
||||||
));
|
));
|
||||||
|
|
||||||
@@ -50,6 +53,7 @@ public final class FHConfiguration implements HologramConfiguration {
|
|||||||
"Whether the plugin should save holograms when they are changed.",
|
"Whether the plugin should save holograms when they are changed.",
|
||||||
false,
|
false,
|
||||||
true,
|
true,
|
||||||
|
false,
|
||||||
Boolean.class
|
Boolean.class
|
||||||
));
|
));
|
||||||
|
|
||||||
@@ -58,6 +62,7 @@ public final class FHConfiguration implements HologramConfiguration {
|
|||||||
"The default visibility distance for holograms.",
|
"The default visibility distance for holograms.",
|
||||||
false,
|
false,
|
||||||
20,
|
20,
|
||||||
|
false,
|
||||||
Integer.class
|
Integer.class
|
||||||
));
|
));
|
||||||
|
|
||||||
@@ -66,6 +71,7 @@ public final class FHConfiguration implements HologramConfiguration {
|
|||||||
"Whether the plugin should register its commands.",
|
"Whether the plugin should register its commands.",
|
||||||
false,
|
false,
|
||||||
true,
|
true,
|
||||||
|
false,
|
||||||
Boolean.class
|
Boolean.class
|
||||||
));
|
));
|
||||||
|
|
||||||
@@ -74,6 +80,7 @@ public final class FHConfiguration implements HologramConfiguration {
|
|||||||
"The log level for the plugin (DEBUG, INFO, WARN, ERROR).",
|
"The log level for the plugin (DEBUG, INFO, WARN, ERROR).",
|
||||||
false,
|
false,
|
||||||
"INFO",
|
"INFO",
|
||||||
|
false,
|
||||||
String.class
|
String.class
|
||||||
));
|
));
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user