config: Deprecate feature flag class

This commit is contained in:
Oliver
2025-07-19 19:32:51 +02:00
parent e005e5c212
commit b8512e503d
6 changed files with 83 additions and 85 deletions

View File

@@ -1,4 +1,4 @@
package de.oliver.fancylib;
package com.fancyinnovations.config;
import org.bukkit.configuration.file.FileConfiguration;

View File

@@ -1,5 +1,9 @@
package com.fancyinnovations.config.featureflags;
/**
* Use ConfigOption instead of this class.
*/
@Deprecated
public class FeatureFlag {
private final String name;

View File

@@ -8,6 +8,10 @@ import java.io.IOException;
import java.util.ArrayList;
import java.util.List;
/**
* Use Config instead of this class.
*/
@Deprecated
public class FeatureFlagConfig {
private final Plugin plugin;

View File

@@ -1,7 +1,7 @@
package com.fancyinnovations.fancydialogs.config;
import com.fancyinnovations.config.ConfigHelper;
import com.fancyinnovations.fancydialogs.FancyDialogsPlugin;
import de.oliver.fancylib.ConfigHelper;
import org.bukkit.configuration.file.FileConfiguration;
import java.util.List;

View File

@@ -1,8 +1,8 @@
package de.oliver.fancyholograms;
import com.fancyinnovations.config.ConfigHelper;
import de.oliver.fancyholograms.api.FancyHologramsPlugin;
import de.oliver.fancyholograms.api.HologramConfiguration;
import de.oliver.fancylib.ConfigHelper;
import org.bukkit.configuration.file.FileConfiguration;
import org.jetbrains.annotations.NotNull;
@@ -17,65 +17,17 @@ import java.util.Map;
*/
public final class FancyHologramsConfiguration implements HologramConfiguration {
/**
* Indicates whether autosave is enabled.
*/
private boolean autosaveEnabled;
private static final String CONFIG_AUTOSAVE_ENABLED = "saving.autosave.enabled";
/**
* The interval at which autosave is performed.
*/
private int autosaveInterval;
private static final String CONFIG_AUTOSAVE_INTERVAL = "saving.autosave.interval";
/**
* Indicates whether the plugin should save holograms when they are changed.
*/
private boolean saveOnChangedEnabled;
private static final String CONFIG_SAVE_ON_CHANGED = "saving.save_on_changed";
/**
* The log level for the plugin.
*/
private String logLevel;
private static final String CONFIG_LOG_LEVEL = "logging.log_level";
/**
* Indicates whether hologram loading should be logged on world loading.
*/
private boolean hologramLoadLogging;
private static final String CONFIG_LOG_ON_WORLD_LOAD = "logging.log_on_world_load";
/**
* Indicates whether version notifications are enabled or disabled.
*/
private boolean versionNotifs;
private static final String CONFIG_VERSION_NOTIFICATIONS = "logging.version_notifications";
/**
* The default visibility distance for holograms.
*/
private int defaultVisibilityDistance;
private static final String CONFIG_VISIBILITY_DISTANCE = "visibility_distance";
/**
* Indicates whether commands should be registered.
* <p>
* This is useful for users who want to use the plugin's API only.
*/
private boolean registerCommands;
private static final String CONFIG_REGISTER_COMMANDS = "register_commands";
/**
* The interval at which hologram visibility is updated.
*/
private int updateVisibilityInterval;
private static final String CONFIG_UPDATE_VISIBILITY_INTERVAL = "update_visibility_interval";
private static final String CONFIG_REPORT_ERRORS_TO_SENTRY = "report_errors_to_sentry";
private static final String CONFIG_VERSION = "config_version";
private static final Map<String, List<String>> CONFIG_COMMENTS = Map.of(
CONFIG_VERSION, List.of("Config version, do not modify."),
CONFIG_AUTOSAVE_ENABLED, List.of("Whether autosave is enabled."),
@@ -88,57 +40,95 @@ public final class FancyHologramsConfiguration implements HologramConfiguration
CONFIG_REGISTER_COMMANDS, List.of("Whether the plugin should register its commands."),
CONFIG_UPDATE_VISIBILITY_INTERVAL, List.of("The interval at which hologram visibility is updated in ticks.")
);
/**
* Indicates whether autosave is enabled.
*/
private boolean autosaveEnabled;
/**
* The interval at which autosave is performed.
*/
private int autosaveInterval;
/**
* Indicates whether the plugin should save holograms when they are changed.
*/
private boolean saveOnChangedEnabled;
/**
* The log level for the plugin.
*/
private String logLevel;
/**
* Indicates whether hologram loading should be logged on world loading.
*/
private boolean hologramLoadLogging;
/**
* Indicates whether version notifications are enabled or disabled.
*/
private boolean versionNotifs;
/**
* The default visibility distance for holograms.
*/
private int defaultVisibilityDistance;
/**
* Indicates whether commands should be registered.
* <p>
* This is useful for users who want to use the plugin's API only.
*/
private boolean registerCommands;
/**
* The interval at which hologram visibility is updated.
*/
private int updateVisibilityInterval;
private void updateChecker(@NotNull FancyHolograms plugin, @NotNull FileConfiguration config) {
final int latestVersion = 1;
int configVersion = (int) ConfigHelper.getOrDefault(config, CONFIG_VERSION, 0);
if (configVersion >= latestVersion ) {
if (configVersion >= latestVersion) {
setOptions(config);
return;
}
plugin.getFancyLogger().warn("Outdated config detected! Attempting to migrate previous settings to new config...");
plugin.getFancyLogger().warn("Outdated config detected! Attempting to migrate previous settings to new config...");
var oldConfig = plugin.getConfig();
try {
File backupFile = new File(plugin.getDataFolder(), "config_old.yml");
oldConfig.save(backupFile);
} catch (IOException e) {
plugin.getFancyLogger().warn("Unable to backup config to config_old.yml:" + e);
}
var oldConfig = plugin.getConfig();
try {
File backupFile = new File(plugin.getDataFolder(), "config_old.yml");
oldConfig.save(backupFile);
} catch (IOException e) {
plugin.getFancyLogger().warn("Unable to backup config to config_old.yml:" + e);
}
var newConfig = plugin.getConfig();
var newConfig = plugin.getConfig();
Map<String, Object> oldConfigValues = oldConfig.getValues(true);
Map<String, String> keyMap = Map.of(
"enable_autosave", CONFIG_AUTOSAVE_ENABLED,
"autosave_interval", CONFIG_AUTOSAVE_INTERVAL,
"save_on_changed", CONFIG_SAVE_ON_CHANGED,
"log_level", CONFIG_LOG_LEVEL,
"mute_version_notifications", CONFIG_VERSION_NOTIFICATIONS
);
Map<String, Object> oldConfigValues = oldConfig.getValues(true);
Map<String, String> keyMap = Map.of(
"enable_autosave", CONFIG_AUTOSAVE_ENABLED,
"autosave_interval", CONFIG_AUTOSAVE_INTERVAL,
"save_on_changed", CONFIG_SAVE_ON_CHANGED,
"log_level", CONFIG_LOG_LEVEL,
"mute_version_notifications", CONFIG_VERSION_NOTIFICATIONS
);
oldConfigValues.forEach((key, value) -> {
oldConfigValues.forEach((key, value) -> {
String newKey = keyMap.getOrDefault(key, null);
if (newKey != null) {
if (newKey.equals(CONFIG_VERSION_NOTIFICATIONS)) {
newConfig.set(newKey, !(Boolean) value);
} else {
newConfig.set(newKey, value);
}
plugin.getFancyLogger().info("> CONFIG: Set option '" + key + "' to '" + value + "' from old config.");
String newKey = keyMap.getOrDefault(key, null);
if (newKey != null) {
if (newKey.equals(CONFIG_VERSION_NOTIFICATIONS)) {
newConfig.set(newKey, !(Boolean) value);
} else {
plugin.getFancyLogger().warn("> CONFIG: Option '" + key + "' is deprecated/invalid! Please migrate this manually from config_old.yml");
newConfig.set(newKey, value);
}
});
plugin.getFancyLogger().info("> CONFIG: Set option '" + key + "' to '" + value + "' from old config.");
} else {
plugin.getFancyLogger().warn("> CONFIG: Option '" + key + "' is deprecated/invalid! Please migrate this manually from config_old.yml");
}
});
newConfig.set(CONFIG_VERSION, latestVersion);
setOptions(newConfig);
CONFIG_COMMENTS.forEach(config::setInlineComments);
newConfig.set(CONFIG_VERSION, latestVersion);
setOptions(newConfig);
CONFIG_COMMENTS.forEach(config::setInlineComments);
plugin.getFancyLogger().info("Configuration has finished migrating. Please double check your settings in config.yml.");
plugin.getFancyLogger().info("Configuration has finished migrating. Please double check your settings in config.yml.");
}
private void setOptions(@NotNull FileConfiguration config) {

View File

@@ -1,6 +1,6 @@
package de.oliver.fancynpcs;
import de.oliver.fancylib.ConfigHelper;
import com.fancyinnovations.config.ConfigHelper;
import de.oliver.fancynpcs.api.FancyNpcsConfig;
import org.bukkit.configuration.file.FileConfiguration;