config: Add forRemoval option

This commit is contained in:
Oliver
2025-07-19 18:54:35 +02:00
parent 54bdda5990
commit a744e6e354
3 changed files with 17 additions and 0 deletions

View File

@@ -71,6 +71,15 @@ public class Config {
String path = entry.getKey(); String path = entry.getKey();
ConfigField<?> field = entry.getValue(); ConfigField<?> field = entry.getValue();
if (field.forRemoval()) {
if (yaml.isSet(path)) {
logger.debug("Removing path '" + path + "' from config");
yaml.set(path, null);
dirty = true;
}
continue;
}
if (yaml.isSet(path)) { if (yaml.isSet(path)) {
Object value = yaml.get(path); Object value = yaml.get(path);
if (field.type().isInstance(value)) { if (field.type().isInstance(value)) {

View File

@@ -3,6 +3,7 @@ package com.fancyinnovations.config;
public record ConfigField<T>( public record ConfigField<T>(
String path, String path,
String description, String description,
boolean forRemoval,
T defaultValue, T defaultValue,
Class<T> type Class<T> type
) { ) {

View File

@@ -26,12 +26,14 @@ public final class FHConfiguration implements HologramConfiguration {
MUTE_VERSION_NOTIFICATION_PATH, MUTE_VERSION_NOTIFICATION_PATH,
"Whether version notifications are muted.", "Whether version notifications are muted.",
false, false,
false,
Boolean.class Boolean.class
)); ));
config.addField(new ConfigField<>( config.addField(new ConfigField<>(
ENABLE_AUTOSAVE_PATH, ENABLE_AUTOSAVE_PATH,
"Whether autosave is enabled.", "Whether autosave is enabled.",
false,
true, true,
Boolean.class Boolean.class
)); ));
@@ -39,6 +41,7 @@ public final class FHConfiguration implements HologramConfiguration {
config.addField(new ConfigField<>( config.addField(new ConfigField<>(
AUTOSAVE_INTERVAL_PATH, AUTOSAVE_INTERVAL_PATH,
"The interval at which autosave is performed in minutes.", "The interval at which autosave is performed in minutes.",
false,
15, 15,
Integer.class Integer.class
)); ));
@@ -46,6 +49,7 @@ public final class FHConfiguration implements HologramConfiguration {
config.addField(new ConfigField<>( config.addField(new ConfigField<>(
SAVE_ON_CHANGED_PATH, SAVE_ON_CHANGED_PATH,
"Whether the plugin should save holograms when they are changed.", "Whether the plugin should save holograms when they are changed.",
false,
true, true,
Boolean.class Boolean.class
)); ));
@@ -53,6 +57,7 @@ public final class FHConfiguration implements HologramConfiguration {
config.addField(new ConfigField<>( config.addField(new ConfigField<>(
VISIBILITY_DISTANCE_PATH, VISIBILITY_DISTANCE_PATH,
"The default visibility distance for holograms.", "The default visibility distance for holograms.",
false,
20, 20,
Integer.class Integer.class
)); ));
@@ -60,6 +65,7 @@ public final class FHConfiguration implements HologramConfiguration {
config.addField(new ConfigField<>( config.addField(new ConfigField<>(
REGISTER_COMMANDS_PATH, REGISTER_COMMANDS_PATH,
"Whether the plugin should register its commands.", "Whether the plugin should register its commands.",
false,
true, true,
Boolean.class Boolean.class
)); ));
@@ -67,6 +73,7 @@ public final class FHConfiguration implements HologramConfiguration {
config.addField(new ConfigField<>( config.addField(new ConfigField<>(
LOG_LEVEL_PATH, LOG_LEVEL_PATH,
"The log level for the plugin (DEBUG, INFO, WARN, ERROR).", "The log level for the plugin (DEBUG, INFO, WARN, ERROR).",
false,
"INFO", "INFO",
String.class String.class
)); ));