diff --git a/src/main/java/world/bentobox/bentobox/database/yaml/YamlDatabaseHandler.java b/src/main/java/world/bentobox/bentobox/database/yaml/YamlDatabaseHandler.java index 40342ea2c..92286d45a 100644 --- a/src/main/java/world/bentobox/bentobox/database/yaml/YamlDatabaseHandler.java +++ b/src/main/java/world/bentobox/bentobox/database/yaml/YamlDatabaseHandler.java @@ -491,30 +491,19 @@ public class YamlDatabaseHandler extends AbstractDatabaseHandler { return Long.valueOf((Integer) value); } if (value.getClass().equals(String.class)) { - if (clazz.equals(Integer.class)) { - return Integer.valueOf((String) value); - } - if (clazz.equals(Long.class)) { - return Long.valueOf((String) value); - } - if (clazz.equals(Double.class)) { - return Double.valueOf((String) value); - } - if (clazz.equals(Float.class)) { - return Float.valueOf((String) value); - } + return deserializeGenericTypes((String) value, clazz); } if (clazz.equals(UUID.class)) { - value = UUID.fromString((String)value); + return UUID.fromString((String)value); } // Bukkit Types if (clazz.equals(Location.class)) { // Get Location from String - may be null... - value = Util.getLocationString(((String)value)); + return Util.getLocationString(((String)value)); } if (clazz.equals(World.class)) { // Get world by name - may be null... - value = plugin.getServer().getWorld((String)value); + return plugin.getServer().getWorld((String)value); } // Enums if (Enum.class.isAssignableFrom(clazz)) { @@ -522,7 +511,7 @@ public class YamlDatabaseHandler extends AbstractDatabaseHandler { // Find out the value Class enumClass = (Class)clazz; try { - value = Enum.valueOf(enumClass, (String)value); + return Enum.valueOf(enumClass, (String)value); } catch (Exception e) { // This value does not exist - probably admin typed it wrongly // Show what is available and pick one at random @@ -531,12 +520,28 @@ public class YamlDatabaseHandler extends AbstractDatabaseHandler { for (Field fields : enumClass.getFields()) { plugin.logError(fields.getName()); } - value = null; } } + // Could not deserialize the value. return value; } + private Object deserializeGenericTypes(String value, Class clazz) { + if (clazz.equals(Integer.class)) { + return Integer.valueOf(value); + } + if (clazz.equals(Long.class)) { + return Long.valueOf(value); + } + if (clazz.equals(Double.class)) { + return Double.valueOf(value); + } + if (clazz.equals(Float.class)) { + return Float.valueOf(value); + } + return null; + } + /* (non-Javadoc) * @see world.bentobox.bentobox.database.AbstractDatabaseHandler#deleteObject(java.lang.Object) */