Added support for the "experimental" tag from ConfigEntry

Watch out ! "/!\ This feature is experimental and might not work as expected or might not work at all."
This commit is contained in:
Florian CUNY 2018-10-30 17:58:50 +01:00
parent 86b1d09653
commit 538a34b0bd

View File

@ -324,12 +324,17 @@ public class YamlDatabaseHandler<T> extends AbstractDatabaseHandler<T> {
Method method = propertyDescriptor.getReadMethod(); Method method = propertyDescriptor.getReadMethod();
// Invoke the read method to get the value. We have no idea what type of value it is. // Invoke the read method to get the value. We have no idea what type of value it is.
Object value = method.invoke(instance); Object value = method.invoke(instance);
String storageLocation = field.getName(); String storageLocation = field.getName();
// Check if there is an annotation on the field // Check if there is an annotation on the field
ConfigEntry configEntry = field.getAnnotation(ConfigEntry.class); ConfigEntry configEntry = field.getAnnotation(ConfigEntry.class);
// If there is a config path annotation then do something // If there is a config path annotation then do something
boolean experimental = false;
if (configEntry != null && !configEntry.path().isEmpty()) { if (configEntry != null && !configEntry.path().isEmpty()) {
storageLocation = configEntry.path(); storageLocation = configEntry.path();
experimental = configEntry.experimental();
} }
// Get path for comments // Get path for comments
@ -350,6 +355,11 @@ public class YamlDatabaseHandler<T> extends AbstractDatabaseHandler<T> {
setComment(comment, config, yamlComments, parent); setComment(comment, config, yamlComments, parent);
} }
// If the configEntry is experimental, then tell it
if (experimental) {
setComment("/!\\ This feature is experimental and might not work as expected or might not work at all.", config, yamlComments, parent);
}
// Adapter // Adapter
Adapter adapterNotation = field.getAnnotation(Adapter.class); Adapter adapterNotation = field.getAnnotation(Adapter.class);
if (adapterNotation != null && AdapterInterface.class.isAssignableFrom(adapterNotation.value())) { if (adapterNotation != null && AdapterInterface.class.isAssignableFrom(adapterNotation.value())) {
@ -415,11 +425,15 @@ public class YamlDatabaseHandler<T> extends AbstractDatabaseHandler<T> {
} }
private void setComment(ConfigComment comment, YamlConfiguration config, Map<String, String> yamlComments, String parent) { private void setComment(ConfigComment comment, YamlConfiguration config, Map<String, String> yamlComments, String parent) {
setComment(comment.value(), config, yamlComments, parent);
}
private void setComment(String comment, YamlConfiguration config, Map<String, String> yamlComments, String parent) {
String random = "comment-" + UUID.randomUUID().toString(); String random = "comment-" + UUID.randomUUID().toString();
// Store placeholder // Store placeholder
config.set(parent + random, " "); config.set(parent + random, " ");
// Create comment // Create comment
yamlComments.put(random, "# " + comment.value().replace(TextVariables.VERSION, plugin.getDescription().getVersion())); yamlComments.put(random, "# " + comment.replace(TextVariables.VERSION, plugin.getDescription().getVersion()));
} }
/** /**