Skip to content

Commit b8512e5

Browse files
config: Deprecate feature flag class
1 parent e005e5c commit b8512e5

6 files changed

Lines changed: 69 additions & 71 deletions

File tree

libraries/config/src/main/java/de/oliver/fancylib/ConfigHelper.java renamed to libraries/config/src/main/java/com/fancyinnovations/config/ConfigHelper.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
package de.oliver.fancylib;
1+
package com.fancyinnovations.config;
22

33
import org.bukkit.configuration.file.FileConfiguration;
44

libraries/config/src/main/java/com/fancyinnovations/config/featureflags/FeatureFlag.java

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,9 @@
11
package com.fancyinnovations.config.featureflags;
22

3+
/**
4+
* Use ConfigOption instead of this class.
5+
*/
6+
@Deprecated
37
public class FeatureFlag {
48

59
private final String name;

libraries/config/src/main/java/com/fancyinnovations/config/featureflags/FeatureFlagConfig.java

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,10 @@
88
import java.util.ArrayList;
99
import java.util.List;
1010

11+
/**
12+
* Use Config instead of this class.
13+
*/
14+
@Deprecated
1115
public class FeatureFlagConfig {
1216

1317
private final Plugin plugin;

plugins/fancydialogs/src/main/java/com/fancyinnovations/fancydialogs/config/FancyDialogsConfig.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
package com.fancyinnovations.fancydialogs.config;
22

3+
import com.fancyinnovations.config.ConfigHelper;
34
import com.fancyinnovations.fancydialogs.FancyDialogsPlugin;
4-
import de.oliver.fancylib.ConfigHelper;
55
import org.bukkit.configuration.file.FileConfiguration;
66

77
import java.util.List;

plugins/fancyholograms-v2/src/main/java/de/oliver/fancyholograms/FancyHologramsConfiguration.java

Lines changed: 58 additions & 68 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
package de.oliver.fancyholograms;
22

3+
import com.fancyinnovations.config.ConfigHelper;
34
import de.oliver.fancyholograms.api.FancyHologramsPlugin;
45
import de.oliver.fancyholograms.api.HologramConfiguration;
5-
import de.oliver.fancylib.ConfigHelper;
66
import org.bukkit.configuration.file.FileConfiguration;
77
import org.jetbrains.annotations.NotNull;
88

@@ -17,128 +17,118 @@
1717
*/
1818
public final class FancyHologramsConfiguration implements HologramConfiguration {
1919

20+
private static final String CONFIG_AUTOSAVE_ENABLED = "saving.autosave.enabled";
21+
private static final String CONFIG_AUTOSAVE_INTERVAL = "saving.autosave.interval";
22+
private static final String CONFIG_SAVE_ON_CHANGED = "saving.save_on_changed";
23+
private static final String CONFIG_LOG_LEVEL = "logging.log_level";
24+
private static final String CONFIG_LOG_ON_WORLD_LOAD = "logging.log_on_world_load";
25+
private static final String CONFIG_VERSION_NOTIFICATIONS = "logging.version_notifications";
26+
private static final String CONFIG_VISIBILITY_DISTANCE = "visibility_distance";
27+
private static final String CONFIG_REGISTER_COMMANDS = "register_commands";
28+
private static final String CONFIG_UPDATE_VISIBILITY_INTERVAL = "update_visibility_interval";
29+
private static final String CONFIG_REPORT_ERRORS_TO_SENTRY = "report_errors_to_sentry";
30+
private static final String CONFIG_VERSION = "config_version";
31+
private static final Map<String, List<String>> CONFIG_COMMENTS = Map.of(
32+
CONFIG_VERSION, List.of("Config version, do not modify."),
33+
CONFIG_AUTOSAVE_ENABLED, List.of("Whether autosave is enabled."),
34+
CONFIG_AUTOSAVE_INTERVAL, List.of("The interval at which autosave is performed in minutes."),
35+
CONFIG_SAVE_ON_CHANGED, List.of("Whether the plugin should save holograms when they are changed."),
36+
CONFIG_LOG_LEVEL, List.of("The log level for the plugin (DEBUG, INFO, WARN, ERROR)."),
37+
CONFIG_LOG_ON_WORLD_LOAD, List.of("Whether hologram loading should be logged on world loading. Disable this if you load worlds dynamically to prevent console spam."),
38+
CONFIG_VERSION_NOTIFICATIONS, List.of("Whether the plugin should send notifications for new updates."),
39+
CONFIG_VISIBILITY_DISTANCE, List.of("The default visibility distance for holograms."),
40+
CONFIG_REGISTER_COMMANDS, List.of("Whether the plugin should register its commands."),
41+
CONFIG_UPDATE_VISIBILITY_INTERVAL, List.of("The interval at which hologram visibility is updated in ticks.")
42+
);
2043
/**
2144
* Indicates whether autosave is enabled.
2245
*/
2346
private boolean autosaveEnabled;
24-
private static final String CONFIG_AUTOSAVE_ENABLED = "saving.autosave.enabled";
25-
2647
/**
2748
* The interval at which autosave is performed.
2849
*/
2950
private int autosaveInterval;
30-
private static final String CONFIG_AUTOSAVE_INTERVAL = "saving.autosave.interval";
31-
3251
/**
3352
* Indicates whether the plugin should save holograms when they are changed.
3453
*/
3554
private boolean saveOnChangedEnabled;
36-
private static final String CONFIG_SAVE_ON_CHANGED = "saving.save_on_changed";
37-
3855
/**
3956
* The log level for the plugin.
4057
*/
4158
private String logLevel;
42-
private static final String CONFIG_LOG_LEVEL = "logging.log_level";
43-
4459
/**
4560
* Indicates whether hologram loading should be logged on world loading.
4661
*/
4762
private boolean hologramLoadLogging;
48-
private static final String CONFIG_LOG_ON_WORLD_LOAD = "logging.log_on_world_load";
49-
5063
/**
5164
* Indicates whether version notifications are enabled or disabled.
5265
*/
5366
private boolean versionNotifs;
54-
private static final String CONFIG_VERSION_NOTIFICATIONS = "logging.version_notifications";
55-
5667
/**
5768
* The default visibility distance for holograms.
5869
*/
5970
private int defaultVisibilityDistance;
60-
private static final String CONFIG_VISIBILITY_DISTANCE = "visibility_distance";
61-
6271
/**
6372
* Indicates whether commands should be registered.
6473
* <p>
6574
* This is useful for users who want to use the plugin's API only.
6675
*/
6776
private boolean registerCommands;
68-
private static final String CONFIG_REGISTER_COMMANDS = "register_commands";
69-
7077
/**
7178
* The interval at which hologram visibility is updated.
7279
*/
7380
private int updateVisibilityInterval;
74-
private static final String CONFIG_UPDATE_VISIBILITY_INTERVAL = "update_visibility_interval";
75-
76-
private static final String CONFIG_REPORT_ERRORS_TO_SENTRY = "report_errors_to_sentry";
77-
private static final String CONFIG_VERSION = "config_version";
78-
79-
private static final Map<String, List<String>> CONFIG_COMMENTS = Map.of(
80-
CONFIG_VERSION, List.of("Config version, do not modify."),
81-
CONFIG_AUTOSAVE_ENABLED, List.of("Whether autosave is enabled."),
82-
CONFIG_AUTOSAVE_INTERVAL, List.of("The interval at which autosave is performed in minutes."),
83-
CONFIG_SAVE_ON_CHANGED, List.of("Whether the plugin should save holograms when they are changed."),
84-
CONFIG_LOG_LEVEL, List.of("The log level for the plugin (DEBUG, INFO, WARN, ERROR)."),
85-
CONFIG_LOG_ON_WORLD_LOAD, List.of("Whether hologram loading should be logged on world loading. Disable this if you load worlds dynamically to prevent console spam."),
86-
CONFIG_VERSION_NOTIFICATIONS, List.of("Whether the plugin should send notifications for new updates."),
87-
CONFIG_VISIBILITY_DISTANCE, List.of("The default visibility distance for holograms."),
88-
CONFIG_REGISTER_COMMANDS, List.of("Whether the plugin should register its commands."),
89-
CONFIG_UPDATE_VISIBILITY_INTERVAL, List.of("The interval at which hologram visibility is updated in ticks.")
90-
);
9181

9282
private void updateChecker(@NotNull FancyHolograms plugin, @NotNull FileConfiguration config) {
9383
final int latestVersion = 1;
9484
int configVersion = (int) ConfigHelper.getOrDefault(config, CONFIG_VERSION, 0);
9585

96-
if (configVersion >= latestVersion ) {
86+
if (configVersion >= latestVersion) {
9787
setOptions(config);
9888
return;
9989
}
100-
plugin.getFancyLogger().warn("Outdated config detected! Attempting to migrate previous settings to new config...");
101-
102-
var oldConfig = plugin.getConfig();
103-
try {
104-
File backupFile = new File(plugin.getDataFolder(), "config_old.yml");
105-
oldConfig.save(backupFile);
106-
} catch (IOException e) {
107-
plugin.getFancyLogger().warn("Unable to backup config to config_old.yml:" + e);
108-
}
90+
plugin.getFancyLogger().warn("Outdated config detected! Attempting to migrate previous settings to new config...");
91+
92+
var oldConfig = plugin.getConfig();
93+
try {
94+
File backupFile = new File(plugin.getDataFolder(), "config_old.yml");
95+
oldConfig.save(backupFile);
96+
} catch (IOException e) {
97+
plugin.getFancyLogger().warn("Unable to backup config to config_old.yml:" + e);
98+
}
10999

110100

111-
var newConfig = plugin.getConfig();
101+
var newConfig = plugin.getConfig();
112102

113-
Map<String, Object> oldConfigValues = oldConfig.getValues(true);
114-
Map<String, String> keyMap = Map.of(
115-
"enable_autosave", CONFIG_AUTOSAVE_ENABLED,
116-
"autosave_interval", CONFIG_AUTOSAVE_INTERVAL,
117-
"save_on_changed", CONFIG_SAVE_ON_CHANGED,
118-
"log_level", CONFIG_LOG_LEVEL,
119-
"mute_version_notifications", CONFIG_VERSION_NOTIFICATIONS
120-
);
103+
Map<String, Object> oldConfigValues = oldConfig.getValues(true);
104+
Map<String, String> keyMap = Map.of(
105+
"enable_autosave", CONFIG_AUTOSAVE_ENABLED,
106+
"autosave_interval", CONFIG_AUTOSAVE_INTERVAL,
107+
"save_on_changed", CONFIG_SAVE_ON_CHANGED,
108+
"log_level", CONFIG_LOG_LEVEL,
109+
"mute_version_notifications", CONFIG_VERSION_NOTIFICATIONS
110+
);
121111

122-
oldConfigValues.forEach((key, value) -> {
112+
oldConfigValues.forEach((key, value) -> {
123113

124-
String newKey = keyMap.getOrDefault(key, null);
125-
if (newKey != null) {
126-
if (newKey.equals(CONFIG_VERSION_NOTIFICATIONS)) {
127-
newConfig.set(newKey, !(Boolean) value);
128-
} else {
129-
newConfig.set(newKey, value);
130-
}
131-
plugin.getFancyLogger().info("> CONFIG: Set option '" + key + "' to '" + value + "' from old config.");
114+
String newKey = keyMap.getOrDefault(key, null);
115+
if (newKey != null) {
116+
if (newKey.equals(CONFIG_VERSION_NOTIFICATIONS)) {
117+
newConfig.set(newKey, !(Boolean) value);
132118
} else {
133-
plugin.getFancyLogger().warn("> CONFIG: Option '" + key + "' is deprecated/invalid! Please migrate this manually from config_old.yml");
119+
newConfig.set(newKey, value);
134120
}
135-
});
121+
plugin.getFancyLogger().info("> CONFIG: Set option '" + key + "' to '" + value + "' from old config.");
122+
} else {
123+
plugin.getFancyLogger().warn("> CONFIG: Option '" + key + "' is deprecated/invalid! Please migrate this manually from config_old.yml");
124+
}
125+
});
136126

137-
newConfig.set(CONFIG_VERSION, latestVersion);
138-
setOptions(newConfig);
139-
CONFIG_COMMENTS.forEach(config::setInlineComments);
127+
newConfig.set(CONFIG_VERSION, latestVersion);
128+
setOptions(newConfig);
129+
CONFIG_COMMENTS.forEach(config::setInlineComments);
140130

141-
plugin.getFancyLogger().info("Configuration has finished migrating. Please double check your settings in config.yml.");
131+
plugin.getFancyLogger().info("Configuration has finished migrating. Please double check your settings in config.yml.");
142132
}
143133

144134
private void setOptions(@NotNull FileConfiguration config) {

plugins/fancynpcs/src/main/java/de/oliver/fancynpcs/FancyNpcsConfigImpl.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
package de.oliver.fancynpcs;
22

3-
import de.oliver.fancylib.ConfigHelper;
3+
import com.fancyinnovations.config.ConfigHelper;
44
import de.oliver.fancynpcs.api.FancyNpcsConfig;
55
import org.bukkit.configuration.file.FileConfiguration;
66

0 commit comments

Comments
 (0)