From 67e05955f84031a1fd2d66a1fc72ea1ee5b4b3ce Mon Sep 17 00:00:00 2001 From: Tastybento Date: Sat, 27 Jan 2018 15:48:44 -0800 Subject: [PATCH] Made skyblock sky again. The sea water level was being set. --- .../us/tastybento/bskyblock/Settings.java | 4 +- .../flatfile/FlatFileDatabaseHandler.java | 157 +++++++++--------- .../database/managers/island/NewIsland.java | 2 +- 3 files changed, 86 insertions(+), 77 deletions(-) diff --git a/src/main/java/us/tastybento/bskyblock/Settings.java b/src/main/java/us/tastybento/bskyblock/Settings.java index e23a038d6..a582bea6c 100644 --- a/src/main/java/us/tastybento/bskyblock/Settings.java +++ b/src/main/java/us/tastybento/bskyblock/Settings.java @@ -94,8 +94,8 @@ public class Settings implements ISettings { private int islandXOffset; private int islandZOffset; - @ConfigEntry(path = "world.sea-height", specificTo = GameType.ACIDISLAND) - private int seaHeight = 100; + @ConfigEntry(path = "world.sea-height") + private int seaHeight = 0; @ConfigEntry(path = "world.island-height") private int islandHeight = 100; diff --git a/src/main/java/us/tastybento/bskyblock/database/flatfile/FlatFileDatabaseHandler.java b/src/main/java/us/tastybento/bskyblock/database/flatfile/FlatFileDatabaseHandler.java index e4411e625..1838dda5d 100644 --- a/src/main/java/us/tastybento/bskyblock/database/flatfile/FlatFileDatabaseHandler.java +++ b/src/main/java/us/tastybento/bskyblock/database/flatfile/FlatFileDatabaseHandler.java @@ -324,84 +324,93 @@ public class FlatFileDatabaseHandler extends AbstractDatabaseHandler { filename = storeAt.filename(); } } - + // 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()) { + fields: + for (Field field : dataObject.getDeclaredFields()) { - // Get the property descriptor for this field - PropertyDescriptor propertyDescriptor = new PropertyDescriptor(field.getName(), dataObject); - // Get the read method, i.e., getXXXX(); - Method method = propertyDescriptor.getReadMethod(); - // Invoke the read method to get the value. We have no idea what type of value it is. - Object value = method.invoke(instance); + // Get the property descriptor for this field + PropertyDescriptor propertyDescriptor = new PropertyDescriptor(field.getName(), dataObject); + // Get the read method, i.e., getXXXX(); + Method method = propertyDescriptor.getReadMethod(); + // Invoke the read method to get the value. We have no idea what type of value it is. + Object value = method.invoke(instance); - String storageLocation = field.getName(); - // Check if there is an annotation on the field - ConfigEntry configEntry = field.getAnnotation(ConfigEntry.class); - // If there is a config path annotation then do something - if (configEntry != null) { - if (!configEntry.path().isEmpty()) { - storageLocation = configEntry.path(); - } - // TODO: add in game-specific saving - if (!configEntry.adapter().equals(Adapter.class)) { - // A conversion adapter has been defined - try { - config.set(storageLocation, ((Adapter)configEntry.adapter().newInstance()).convertTo(value)); - } catch (InstantiationException e) { - e.printStackTrace(); + String storageLocation = field.getName(); + // Check if there is an annotation on the field + ConfigEntry configEntry = field.getAnnotation(ConfigEntry.class); + // If there is a config path annotation then do something + if (configEntry != null) { + if (DEBUG) { + plugin.getLogger().info("DEBUG: configEntry fould " + configEntry.toString() + " " + configEntry.specificTo()); + plugin.getLogger().info("DEBUG: " + field.getName()); } - // We are done here - continue; + if (!configEntry.specificTo().equals(GameType.BOTH) && !configEntry.specificTo().equals(Constants.GAMETYPE)) { + continue fields; + } + if (!configEntry.path().isEmpty()) { + storageLocation = configEntry.path(); + } + // TODO: add in game-specific saving + if (!configEntry.adapter().equals(Adapter.class)) { + // A conversion adapter has been defined + try { + config.set(storageLocation, ((Adapter)configEntry.adapter().newInstance()).convertTo(value)); + } catch (InstantiationException e) { + e.printStackTrace(); + } + // We are done here + continue fields; + } + + } + //plugin.getLogger().info("DEBUG: property desc = " + propertyDescriptor.getPropertyType().getTypeName()); + // Depending on the vale type, it'll need serializing differenty + // Check if this field is the mandatory UniqueId field. This is used to identify this instantiation of the class + if (method.getName().equals("getUniqueId")) { + // If the object does not have a unique name assigned to it already, one is created at random + //plugin.getLogger().info("DEBUG: uniqueId = " + value); + String id = (String)value; + if (value == null || id.isEmpty()) { + id = databaseConnecter.getUniqueId(dataObject.getSimpleName()); + // Set it in the class so that it will be used next time + propertyDescriptor.getWriteMethod().invoke(instance, id); + } + // Save the name for when the file is saved + if (filename.isEmpty()) + filename = id; + } + // Collections need special serialization + if (Map.class.isAssignableFrom(propertyDescriptor.getPropertyType())) { + // Maps need to have keys serialized + //plugin.getLogger().info("DEBUG: Map for " + storageLocation); + if (value != null) { + Map result = new HashMap(); + for (Entry object : ((Map)value).entrySet()) { + // Serialize all key types + // TODO: also need to serialize values? + result.put(serialize(object.getKey()), object.getValue()); + } + // Save the list in the config file + config.set(storageLocation, result); + } + } else if (Set.class.isAssignableFrom(propertyDescriptor.getPropertyType())) { + // Sets need to be serialized as string lists + if (DEBUG) + plugin.getLogger().info("DEBUG: Set for " + storageLocation); + if (value != null) { + List list = new ArrayList(); + for (Object object : (Set)value) { + list.add(serialize(object)); + } + // Save the list in the config file + config.set(storageLocation, list); + } + } else { + // For all other data that doesn't need special serialization + config.set(storageLocation, serialize(value)); } } - //plugin.getLogger().info("DEBUG: property desc = " + propertyDescriptor.getPropertyType().getTypeName()); - // Depending on the vale type, it'll need serializing differenty - // Check if this field is the mandatory UniqueId field. This is used to identify this instantiation of the class - if (method.getName().equals("getUniqueId")) { - // If the object does not have a unique name assigned to it already, one is created at random - //plugin.getLogger().info("DEBUG: uniqueId = " + value); - String id = (String)value; - if (value == null || id.isEmpty()) { - id = databaseConnecter.getUniqueId(dataObject.getSimpleName()); - // Set it in the class so that it will be used next time - propertyDescriptor.getWriteMethod().invoke(instance, id); - } - // Save the name for when the file is saved - if (filename.isEmpty()) - filename = id; - } - // Collections need special serialization - if (Map.class.isAssignableFrom(propertyDescriptor.getPropertyType())) { - // Maps need to have keys serialized - //plugin.getLogger().info("DEBUG: Map for " + storageLocation); - if (value != null) { - Map result = new HashMap(); - for (Entry object : ((Map)value).entrySet()) { - // Serialize all key types - // TODO: also need to serialize values? - result.put(serialize(object.getKey()), object.getValue()); - } - // Save the list in the config file - config.set(storageLocation, result); - } - } else if (Set.class.isAssignableFrom(propertyDescriptor.getPropertyType())) { - // Sets need to be serialized as string lists - if (DEBUG) - plugin.getLogger().info("DEBUG: Set for " + storageLocation); - if (value != null) { - List list = new ArrayList(); - for (Object object : (Set)value) { - list.add(serialize(object)); - } - // Save the list in the config file - config.set(storageLocation, list); - } - } else { - // For all other data that doesn't need special serialization - config.set(storageLocation, serialize(value)); - } - } if (filename.isEmpty()) { throw new IllegalArgumentException("No uniqueId in class"); } @@ -504,9 +513,9 @@ public class FlatFileDatabaseHandler extends AbstractDatabaseHandler { @Override public T loadSettings(String uniqueId, T dbConfig) throws InstantiationException, IllegalAccessException, IllegalArgumentException, InvocationTargetException, ClassNotFoundException, IntrospectionException { if (dbConfig == null) return loadObject(uniqueId); - + // TODO: compare the loaded with the database copy - + return loadObject(uniqueId); } diff --git a/src/main/java/us/tastybento/bskyblock/database/managers/island/NewIsland.java b/src/main/java/us/tastybento/bskyblock/database/managers/island/NewIsland.java index ee85bbc7e..35e7b9f87 100644 --- a/src/main/java/us/tastybento/bskyblock/database/managers/island/NewIsland.java +++ b/src/main/java/us/tastybento/bskyblock/database/managers/island/NewIsland.java @@ -20,7 +20,7 @@ import us.tastybento.bskyblock.island.builders.IslandBuilder.IslandType; * */ public class NewIsland { - private static final boolean DEBUG = true; + private static final boolean DEBUG = false; private BSkyBlock plugin; private Island island; private final Player player;