Refactor YamlDatabaseHandler to reduce continue statements

in a loop to just one.
This commit is contained in:
tastybento 2023-07-22 15:52:15 -07:00
parent 7a21aba3a8
commit fec43adc35

View File

@ -358,11 +358,11 @@ public class YamlDatabaseHandler<T> extends AbstractDatabaseHandler<T> {
// See if there are any top-level comments
handleComments(instance.getClass(), config, yamlComments, "");
// Run through all the fields in the class that is being stored. EVERY field must have a get and set method
for (Field field : dataObject.getDeclaredFields()) {
if (field.isSynthetic()) {
continue;
}
// Get the property descriptor for this field
PropertyDescriptor propertyDescriptor = new PropertyDescriptor(field.getName(), dataObject);
// Get the read method
@ -376,12 +376,7 @@ public class YamlDatabaseHandler<T> extends AbstractDatabaseHandler<T> {
ConfigEntry configEntry = field.getAnnotation(ConfigEntry.class);
// If there is a config path annotation or adapter then deal with them
if (configEntry != null && !configEntry.path().isEmpty()) {
if (configEntry.hidden()) {
// If the annotation tells us to not print the config entry, then we won't.
continue;
}
if (configEntry != null && !configEntry.path().isEmpty() && !configEntry.hidden()) {
// Get the storage location
storageLocation = configEntry.path();
@ -392,9 +387,7 @@ public class YamlDatabaseHandler<T> extends AbstractDatabaseHandler<T> {
}
handleComments(field, config, yamlComments, parent);
handleConfigEntryComments(configEntry, config, yamlComments, parent);
}
if (!checkAdapter(field, config, storageLocation, value)) {
} else if (!checkAdapter(field, config, storageLocation, value)) {
// Set the filename if it has not be set already
if (filename.isEmpty() && method.getName().equals("getUniqueId")) {
// Save the name for when the file is saved
@ -411,6 +404,7 @@ public class YamlDatabaseHandler<T> extends AbstractDatabaseHandler<T> {
}
}
}
// If the filename has not been set by now then we have a problem
if (filename.isEmpty()) {
throw new IllegalArgumentException("No uniqueId in class");