Minor refactor to remove continue from for loop

This commit is contained in:
tastybento 2023-02-05 10:39:10 -08:00
parent ad2541963e
commit 2d8b3074a9

View File

@ -338,13 +338,11 @@ public class YamlDatabaseHandler<T> extends AbstractDatabaseHandler<T> {
// Null check
if (instance == null) {
plugin.logError("YAML database request to store a null.");
completableFuture.complete(false);
return completableFuture;
return CompletableFuture.completedFuture(false);
}
if (!(instance instanceof DataObject)) {
plugin.logError("This class is not a DataObject: " + instance.getClass().getName());
completableFuture.complete(false);
return completableFuture;
return CompletableFuture.completedFuture(false);
}
// This is the Yaml Configuration that will be used and saved at the end
YamlConfiguration config = new YamlConfiguration();
@ -396,9 +394,7 @@ public class YamlDatabaseHandler<T> extends AbstractDatabaseHandler<T> {
handleConfigEntryComments(configEntry, config, yamlComments, parent);
}
if (checkAdapter(field, config, storageLocation, value)) {
continue;
}
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
@ -414,6 +410,7 @@ public class YamlDatabaseHandler<T> extends AbstractDatabaseHandler<T> {
config.set(storageLocation, serialize(value));
}
}
}
// If the filename has not been set by now then we have a problem
if (filename.isEmpty()) {
throw new IllegalArgumentException("No uniqueId in class");
@ -469,6 +466,16 @@ public class YamlDatabaseHandler<T> extends AbstractDatabaseHandler<T> {
return id;
}
/**
* Checks if an adapter is to be used. If so, it is used and true returned, if not, fase is returned
* @param field Field
* @param config Yaml Config
* @param storageLocation Storage location
* @param value Value
* @return true if adapater used
* @throws IllegalAccessException exception
* @throws InvocationTargetException exception
*/
private boolean checkAdapter(Field field, YamlConfiguration config, String storageLocation, Object value) throws IllegalAccessException, InvocationTargetException {
Adapter adapterNotation = field.getAnnotation(Adapter.class);
if (adapterNotation != null && AdapterInterface.class.isAssignableFrom(adapterNotation.value())) {