From 59cace61f88c3320e3fa6426a7ce274a3d758adb Mon Sep 17 00:00:00 2001 From: tastybento Date: Thu, 25 Jun 2020 01:22:01 -0700 Subject: [PATCH] Update to BentoBox API 1.14 (#67) Short table names for SQL DB's and async DB saving. --- pom.xml | 4 +- .../bentobox/biomes/BiomesAddonManager.java | 1314 ++++++++--------- .../objects/BiomeChunkUpdateObject.java | 580 ++++---- .../biomes/database/objects/BiomesObject.java | 696 ++++----- src/main/resources/addon.yml | 2 +- 5 files changed, 1300 insertions(+), 1296 deletions(-) diff --git a/pom.xml b/pom.xml index a02f66a..8d2811d 100644 --- a/pom.xml +++ b/pom.xml @@ -47,13 +47,13 @@ 2.0.2 1.15.2-R0.1-SNAPSHOT - 1.12.0 + 1.14.0-SNAPSHOT 1.9.3 1.7 ${build.version}-SNAPSHOT - 1.12.0 + 1.13.0 -LOCAL diff --git a/src/main/java/world/bentobox/biomes/BiomesAddonManager.java b/src/main/java/world/bentobox/biomes/BiomesAddonManager.java index 08f4292..ad3e960 100644 --- a/src/main/java/world/bentobox/biomes/BiomesAddonManager.java +++ b/src/main/java/world/bentobox/biomes/BiomesAddonManager.java @@ -37,664 +37,664 @@ */ public class BiomesAddonManager { - private static final String BIOME = "[biome]"; + private static final String BIOME = "[biome]"; /** - * This is default constructor for Addon Manager. - * @param addon Inits addon manager. - */ - protected BiomesAddonManager(BiomesAddon addon) - { - this.addon = addon; + * This is default constructor for Addon Manager. + * @param addon Inits addon manager. + */ + protected BiomesAddonManager(BiomesAddon addon) + { + this.addon = addon; - this.biomesDatabase = new Database<>(addon, BiomesObject.class); - this.biomesCacheData = new TreeMap<>(String.CASE_INSENSITIVE_ORDER); - - this.biomesFile = new File(this.addon.getDataFolder(), "biomes.yml"); - - if (!this.biomesFile.exists()) - { - this.addon.saveResource("biomes.yml", false); - } - - this.biomePendingChunkUpdateDatabase = new Database<>(addon, BiomeChunkUpdateObject.class); - this.biomePendingChunkUpdateMap = new TreeMap<>(String.CASE_INSENSITIVE_ORDER); - - this.load(); - } - - -// --------------------------------------------------------------------- -// Section: Loading -// --------------------------------------------------------------------- - - - /** - * Creates biomes cache. - */ - private void load() - { - this.biomesCacheData.clear(); - this.biomePendingChunkUpdateMap.clear(); - - this.addon.getLogger().info("Loading biomes..."); - - this.biomesDatabase.loadObjects().forEach(this::loadBiomes); - this.biomePendingChunkUpdateDatabase.loadObjects().forEach(this::addChunkUpdateObject); - } - - - /** - * This class reload - */ - public void reload() - { - this.addon.getLogger().info("Reloading biomes..."); - - this.biomesDatabase = new Database<>(this.addon, BiomesObject.class); - this.biomesDatabase.loadObjects().forEach(this::loadBiomes); - - this.biomePendingChunkUpdateDatabase = new Database<>(this.addon, BiomeChunkUpdateObject.class); - this.biomePendingChunkUpdateDatabase.loadObjects().forEach(this::addChunkUpdateObject); - } - - -// --------------------------------------------------------------------- -// Section: Storing -// --------------------------------------------------------------------- - - - /** - * This method allows to store single biome object. - * @param biome Biome that must be saved in database. - */ - public void saveBiome(BiomesObject biome) - { - this.biomesDatabase.saveObject(biome); - } - - - /** - * Save biomes from cache into database - */ - public void save() - { - this.biomesCacheData.values().forEach(this.biomesDatabase::saveObject); - - // Clear Database. - List objectList = - this.biomePendingChunkUpdateDatabase.loadObjects(); - objectList.forEach(object -> this.biomePendingChunkUpdateDatabase. - deleteID(object.getUniqueId())); - - // Save cache into database. - if (!this.biomePendingChunkUpdateMap.isEmpty()) - { - this.biomePendingChunkUpdateMap.values().forEach( - this.biomePendingChunkUpdateDatabase::saveObject); - } - } - - /** - * Loads biomes in cache silently. Used when loading. - * @param biome that must be stored. - * @return true if successful - */ - private boolean loadBiomes(BiomesObject biome) - { - return this.loadBiomes(biome, true, null, true); - } - - - /** - * Load biomes in the cache. - * @param biome - biome that must be stored. - * @param overwrite - true if previous biomes should be overwritten - * @param user - user making the request - * @param silent - if true, no messages are sent to user - * @return - true if imported - */ - public boolean loadBiomes(BiomesObject biome, boolean overwrite, User user, boolean silent) - { - // If biome is null, the skip this biome! - if (biome.getBiome() == null) - { - if (!silent) - { - user.sendMessage("biomes.messages.skipping", - BIOME, - biome.toString()); - } - - return false; - } - - // Contains in array list is not fast.. but list is not so large, so it is ok there. - - if (this.biomesCacheData.containsKey(biome.getUniqueId())) - { - if (!overwrite) - { - if (!silent) - { - user.sendMessage("biomes.messages.skipping", - BIOME, - biome.getFriendlyName()); - } - - return false; - } - else - { - if (!silent) - { - user.sendMessage("biomes.messages.overwriting", - BIOME, - biome.getFriendlyName()); - } - - this.biomesCacheData.replace(biome.getUniqueId(), biome); - return true; - } - } - - if (!silent) - { - user.sendMessage("biomes.messages.imported", - BIOME, - biome.getFriendlyName()); - } - - this.biomesCacheData.put(biome.getUniqueId(), biome); - return true; - } - - -// --------------------------------------------------------------------- -// Section: Importing -// --------------------------------------------------------------------- - - - /** - * This method imports biomes - * - * @param user - user - * @param world - world to import into - * @param overwrite - true if previous ones should be overwritten - * @return true if successful - */ - public boolean importBiomes(User user, World world, boolean overwrite) - { - world = Util.getWorld(world); - - if (!this.biomesFile.exists()) - { - user.sendMessage("biomes.errors.no-file"); - return false; - } - - YamlConfiguration config = new YamlConfiguration(); - - try - { - config.load(this.biomesFile); - } - catch (IOException | InvalidConfigurationException e) - { - user.sendMessage("biomes.errors.no-load", - "[message]", - e.getMessage()); - return false; - } - - this.readBiomes(config, user, world, overwrite); - - // Update biome order. - this.addon.getAddonManager().save(); - return true; - } - - - /** - * This method creates biomes object from config file. - * @param config YamlConfiguration that contains all biomes. - * @param user User who calls reading. - * @param world World in which biomes must be imported - * @param overwrite Boolean that indicate if biomes should be overwritted. - */ - private void readBiomes(YamlConfiguration config, User user, World world, boolean overwrite) - { - int size = 0; - - ConfigurationSection reader = config.getConfigurationSection("biomes.biomesList"); - - Map biomeNameMap = BiomesAddonManager.getBiomeNameMap(); - - for (String biome : reader.getKeys(false)) - { - if (biomeNameMap.containsKey(biome.toUpperCase())) - { - BiomesObject newBiomeObject = new BiomesObject(Biome.valueOf(biome.toUpperCase()), world); - newBiomeObject.setDeployed(true); - - ConfigurationSection details = reader.getConfigurationSection(biome); - - newBiomeObject.setFriendlyName(details.getString("friendlyName", biome)); - - newBiomeObject.setDescription( - GuiUtils.stringSplit(details.getString("description", ""), - this.addon.getSettings().getLoreLineLength())); - newBiomeObject.setIcon(ItemParser.parse(details.getString("icon") + ":1")); - - newBiomeObject.setRequiredLevel(details.getInt("islandLevel", 0)); - newBiomeObject.setRequiredCost(details.getInt("cost", 0)); - - List permissions = details.getStringList("permission"); - - if (permissions.isEmpty()) - { - newBiomeObject.setRequiredPermissions(Collections.emptySet()); - } - else - { - newBiomeObject.setRequiredPermissions(new HashSet<>(permissions)); - } - - if (this.addon.getAddonManager().loadBiomes( - newBiomeObject, overwrite, user, false)) - { - size++; - } - } - else - { - user.sendMessage("biomes.errors.load-biome", - BIOME, - biome); - } - } - - user.sendMessage("biomes.messages.import-count", - TextVariables.NUMBER, - String.valueOf(size)); - } - - -// --------------------------------------------------------------------- -// Section: Migrate -// --------------------------------------------------------------------- - - - /** - * This method migrated all biomes addon data from worldName to addonID format. - */ - public void migrateDatabase(User user, World world) - { - world = Util.getWorld(world); - - if (user.isPlayer()) - { - user.sendMessage("biomes.messages.admin.migrate-start"); - } - else - { - this.addon.log("Starting migration to new data format."); - } - - boolean biomes = this.migrateBiomes(world); - - if (biomes) - { - if (user.isPlayer()) - { - user.sendMessage("biomes.messages.admin.migrate-end"); - } - else - { - this.addon.log("Migration to new data format completed."); - } - } - else - { - if (user.isPlayer()) - { - user.sendMessage("biomes.messages.admin.migrate-not"); - } - else - { - this.addon.log("All data is valid. Migration is not necessary."); - } - } - } - - - /** - * This method migrates biomes object to new id format. - * @param world World which biomes must be updated. - * @return {@code true} if any biome is updated, - * {@code false} otherwise. - */ - private boolean migrateBiomes(World world) - { - String addonName = Utils.getGameMode(world); - - if (addonName == null || addonName.equalsIgnoreCase(world.getName())) - { - return false; - } - - boolean updated = false; - List objectList = this.biomesDatabase.loadObjects(); - - for (BiomesObject biomesObject : objectList) - { - if (biomesObject.getUniqueId().regionMatches(true, 0, world.getName() + "-", 0, world.getName().length() + 1)) - { - this.biomesDatabase.deleteID(biomesObject.getUniqueId()); - this.biomesCacheData.remove(biomesObject.getUniqueId()); - - biomesObject.setUniqueId( - addonName + "_" + biomesObject.getUniqueId().substring(world.getName().length() + 1)); - - // Update world, as in some situations it was not set. - biomesObject.setWorld(Util.getWorld(world).getName()); - - this.biomesDatabase.saveObject(biomesObject); - this.biomesCacheData.put(biomesObject.getUniqueId(), biomesObject); - - updated = true; - } - } - - return updated; - } - - -// --------------------------------------------------------------------- -// Section: Creating -// --------------------------------------------------------------------- - - - /** - * This method creates and returns new biome with given uniqueID. - * @param uniqueID - new ID for challenge. - * @param worldName - world name where biome operates. - * @return biome that is currently created. - */ - public BiomesObject createBiome(String uniqueID, String worldName) - { - if (!this.containsBiome(uniqueID)) - { - BiomesObject biome = new BiomesObject(); - biome.setUniqueId(uniqueID); - - // Sets default biome as VOID. - biome.setBiome(Biome.THE_VOID); - biome.setWorld(worldName); - - this.saveBiome(biome); - this.loadBiomes(biome); - - return biome; - } - else - { - return null; - } - } - - -// --------------------------------------------------------------------- -// Section: Getters / Setters -// --------------------------------------------------------------------- - - - /** - * This method returns biomes that is visible for user by using default visibility mode. - * @param world World in which biomes must be returned. - * @param user User who will see biomes. - * @return Visible biome list. - */ - public List getBiomes(World world, User user) - { - return this.getBiomes(world, user, this.addon.getSettings().getVisibilityMode()); - } - - - /** - * This method returns biomes that is visible for user in given world. - * @param world World in which biomes must be returned. - * @param user User who will see biomes. - * @param visibilityMode active visibilityMode. Only ALL will return all biomes. - * DEPLOYED will show biomes that has deployedFlag enabled. - * ACCESSIBLE will show biomes that are deployed and user has permission that unlocks biome. - * TOGGLEABLE will work as ACCESSIBLE. - * @return Visible biome list. - */ - public List getBiomes(World world, User user, VisibilityMode visibilityMode) - { - List allBiomeList = this.getBiomes(world); - - if (visibilityMode.equals(VisibilityMode.ALL)) - { - return allBiomeList; - } - - List returnBiomesList = new ArrayList<>(allBiomeList.size()); - - allBiomeList.forEach(biomesObject -> { - if (biomesObject.isDeployed() && - (visibilityMode.equals(VisibilityMode.DEPLOYED) || - biomesObject.getRequiredPermissions().isEmpty() || - biomesObject.getRequiredPermissions().stream().allMatch(user::hasPermission))) - { - returnBiomesList.add(biomesObject); - } - }); - - return returnBiomesList; - } - - - /** - * This method returns list with loaded biomes for given world. - * @param world World where biome operates. - * @return list with loaded biomes. - */ - public List getBiomes(World world) - { - world = Util.getWorld(world); - - return world == null ? Collections.emptyList() : this.getBiomes(world.getName()); - } - - - /** - * This method returns list with loaded biomes for given world. - * @param worldName Name of world where biome operates. - * @return list with loaded biomes. - */ - public List getBiomes(String worldName) - { - return this.biomesCacheData.values().stream(). - sorted(BiomesObject::compareTo). - filter(biome -> biome.getWorld().equalsIgnoreCase(worldName)). - collect(Collectors.toList()); - } - - - /** - * This method returns biome object that hides behind biome name or null, if biome - * with name does not exist. - * @param biomeUniqueID Biome's name. - * @return BiomesObject that is represented by biome string. - */ - public BiomesObject getBiomeFromString(String biomeUniqueID) - { - return this.biomesCacheData.getOrDefault(biomeUniqueID, null); - } - - - /** - * Check if a biome exists - case insensitive - * - * @param name - name of biome - * @return true if it exists, otherwise false - */ - public boolean containsBiome(String name) - { - if (this.biomesCacheData.containsKey(name)) - { - return true; - } - else - { - // check database. - if (this.biomesDatabase.objectExists(name)) - { - BiomesObject biome = this.biomesDatabase.loadObject(name); - this.biomesCacheData.put(name, biome); - return true; - } - } - - return false; - } - - - /** - * Given method removes biome from database and cache. - * @param biome Biome that must be removed. - */ - public void removeBiome(BiomesObject biome) - { - if (this.biomesCacheData.containsKey(biome.getUniqueId())) - { - this.biomesCacheData.remove(biome.getUniqueId()); - this.biomesDatabase.deleteObject(biome); - } - } - - - /** - * This method returns map that contains biomes name as key and biome as value. - * @return Map that contains relation from biome name to biome. - */ - public static Map getBiomeNameMap() - { - Biome[] biomes = Biome.values(); - - Map returnMap = new HashMap<>(biomes.length); - - for (Biome biome : biomes) - { - returnMap.put(biome.name(), biome); - } - - return returnMap; - } - - - /** - * This method returns if in given world biomes are setup. - * @param world World that must be checked. - * @return True if in given world exist biomes. - */ - public boolean hasAnyBiome(World world) - { - String worldName = Util.getWorld(world) == null ? "" : Util.getWorld(world).getName(); - - return !worldName.isEmpty() && - this.biomesCacheData.values().stream().anyMatch(biome -> biome.getWorld().equalsIgnoreCase(worldName)); - } - - -// --------------------------------------------------------------------- -// Section: Later Biome Updater -// --------------------------------------------------------------------- - - - /** - * This method finds and returns BiomeChunkUpdaterObject in given world with given - * chunk X and Z coordinates. - * @param world World where process will happen. - * @param x Chunk X coordinate. - * @param z Chunk Z coordinate. - * @return BiomeChunkUpdateObject where update is pending or null. - */ - public BiomeChunkUpdateObject getPendingChunkUpdateObject(World world, int x, int z) - { - return this.biomePendingChunkUpdateMap.get(Utils.getGameMode(world) + "_" + x + "-" + z); - } - - - /** - * This method returns collection with all objects that contains information about - * chunks where biome update is still not completed. - * @return Collection of BiomeCHunkUpdateObjects. - */ - public Collection getBiomeUpdaterCollection() - { - return this.biomePendingChunkUpdateMap.values(); - } - - - /** - * This method adds BiomeChunkUpdateObject to cache. - * @param updateObject Object that must be added to cache. - */ - public void addChunkUpdateObject(BiomeChunkUpdateObject updateObject) - { - this.biomePendingChunkUpdateMap.put(updateObject.getUniqueId(), updateObject); - } - - - /** - * This method removes given element form cache and database. - * @param element Element that should be removed. - */ - public void removeUpdateObject(BiomeChunkUpdateObject element) - { - if (this.biomePendingChunkUpdateMap.containsKey(element.getUniqueId())) - { - this.biomePendingChunkUpdateMap.remove(element.getUniqueId()); - this.biomePendingChunkUpdateDatabase.deleteObject(element); - } - } - - -// --------------------------------------------------------------------- -// Section: Variables -// --------------------------------------------------------------------- - - /** - * Variable current addon. - */ - private BiomesAddon addon; - - /** - * Variable stores map that links String to loaded biomes object. - */ - private Map biomesCacheData; - - /** - * Variable stores database of biomes objects. - */ - private Database biomesDatabase; - - /** - * Variable stores biomes.yml location - */ - private File biomesFile; - - /** - * Variable stores BiomeChunkUpdateObject objects that contains information about - * chunk that is not updated yet. - */ - private Map biomePendingChunkUpdateMap; - - /** - * Variable stores database of BiomeChunkUpdateObject. - */ - private Database biomePendingChunkUpdateDatabase; + this.biomesDatabase = new Database<>(addon, BiomesObject.class); + this.biomesCacheData = new TreeMap<>(String.CASE_INSENSITIVE_ORDER); + + this.biomesFile = new File(this.addon.getDataFolder(), "biomes.yml"); + + if (!this.biomesFile.exists()) + { + this.addon.saveResource("biomes.yml", false); + } + + this.biomePendingChunkUpdateDatabase = new Database<>(addon, BiomeChunkUpdateObject.class); + this.biomePendingChunkUpdateMap = new TreeMap<>(String.CASE_INSENSITIVE_ORDER); + + this.load(); + } + + + // --------------------------------------------------------------------- + // Section: Loading + // --------------------------------------------------------------------- + + + /** + * Creates biomes cache. + */ + private void load() + { + this.biomesCacheData.clear(); + this.biomePendingChunkUpdateMap.clear(); + + this.addon.getLogger().info("Loading biomes..."); + + this.biomesDatabase.loadObjects().forEach(this::loadBiomes); + this.biomePendingChunkUpdateDatabase.loadObjects().forEach(this::addChunkUpdateObject); + } + + + /** + * This class reload + */ + public void reload() + { + this.addon.getLogger().info("Reloading biomes..."); + + this.biomesDatabase = new Database<>(this.addon, BiomesObject.class); + this.biomesDatabase.loadObjects().forEach(this::loadBiomes); + + this.biomePendingChunkUpdateDatabase = new Database<>(this.addon, BiomeChunkUpdateObject.class); + this.biomePendingChunkUpdateDatabase.loadObjects().forEach(this::addChunkUpdateObject); + } + + + // --------------------------------------------------------------------- + // Section: Storing + // --------------------------------------------------------------------- + + + /** + * This method allows to store single biome object. + * @param biome Biome that must be saved in database. + */ + public void saveBiome(BiomesObject biome) + { + this.biomesDatabase.saveObjectAsync(biome); + } + + + /** + * Save biomes from cache into database + */ + public void save() + { + this.biomesCacheData.values().forEach(this.biomesDatabase::saveObjectAsync); + + // Clear Database. + List objectList = + this.biomePendingChunkUpdateDatabase.loadObjects(); + objectList.forEach(object -> this.biomePendingChunkUpdateDatabase. + deleteID(object.getUniqueId())); + + // Save cache into database. + if (!this.biomePendingChunkUpdateMap.isEmpty()) + { + this.biomePendingChunkUpdateMap.values().forEach( + this.biomePendingChunkUpdateDatabase::saveObjectAsync); + } + } + + /** + * Loads biomes in cache silently. Used when loading. + * @param biome that must be stored. + * @return true if successful + */ + private boolean loadBiomes(BiomesObject biome) + { + return this.loadBiomes(biome, true, null, true); + } + + + /** + * Load biomes in the cache. + * @param biome - biome that must be stored. + * @param overwrite - true if previous biomes should be overwritten + * @param user - user making the request + * @param silent - if true, no messages are sent to user + * @return - true if imported + */ + public boolean loadBiomes(BiomesObject biome, boolean overwrite, User user, boolean silent) + { + // If biome is null, the skip this biome! + if (biome.getBiome() == null) + { + if (!silent) + { + user.sendMessage("biomes.messages.skipping", + BIOME, + biome.toString()); + } + + return false; + } + + // Contains in array list is not fast.. but list is not so large, so it is ok there. + + if (this.biomesCacheData.containsKey(biome.getUniqueId())) + { + if (!overwrite) + { + if (!silent) + { + user.sendMessage("biomes.messages.skipping", + BIOME, + biome.getFriendlyName()); + } + + return false; + } + else + { + if (!silent) + { + user.sendMessage("biomes.messages.overwriting", + BIOME, + biome.getFriendlyName()); + } + + this.biomesCacheData.replace(biome.getUniqueId(), biome); + return true; + } + } + + if (!silent) + { + user.sendMessage("biomes.messages.imported", + BIOME, + biome.getFriendlyName()); + } + + this.biomesCacheData.put(biome.getUniqueId(), biome); + return true; + } + + + // --------------------------------------------------------------------- + // Section: Importing + // --------------------------------------------------------------------- + + + /** + * This method imports biomes + * + * @param user - user + * @param world - world to import into + * @param overwrite - true if previous ones should be overwritten + * @return true if successful + */ + public boolean importBiomes(User user, World world, boolean overwrite) + { + world = Util.getWorld(world); + + if (!this.biomesFile.exists()) + { + user.sendMessage("biomes.errors.no-file"); + return false; + } + + YamlConfiguration config = new YamlConfiguration(); + + try + { + config.load(this.biomesFile); + } + catch (IOException | InvalidConfigurationException e) + { + user.sendMessage("biomes.errors.no-load", + "[message]", + e.getMessage()); + return false; + } + + this.readBiomes(config, user, world, overwrite); + + // Update biome order. + this.addon.getAddonManager().save(); + return true; + } + + + /** + * This method creates biomes object from config file. + * @param config YamlConfiguration that contains all biomes. + * @param user User who calls reading. + * @param world World in which biomes must be imported + * @param overwrite Boolean that indicate if biomes should be overwritted. + */ + private void readBiomes(YamlConfiguration config, User user, World world, boolean overwrite) + { + int size = 0; + + ConfigurationSection reader = config.getConfigurationSection("biomes.biomesList"); + + Map biomeNameMap = BiomesAddonManager.getBiomeNameMap(); + + for (String biome : reader.getKeys(false)) + { + if (biomeNameMap.containsKey(biome.toUpperCase())) + { + BiomesObject newBiomeObject = new BiomesObject(Biome.valueOf(biome.toUpperCase()), world); + newBiomeObject.setDeployed(true); + + ConfigurationSection details = reader.getConfigurationSection(biome); + + newBiomeObject.setFriendlyName(details.getString("friendlyName", biome)); + + newBiomeObject.setDescription( + GuiUtils.stringSplit(details.getString("description", ""), + this.addon.getSettings().getLoreLineLength())); + newBiomeObject.setIcon(ItemParser.parse(details.getString("icon") + ":1")); + + newBiomeObject.setRequiredLevel(details.getInt("islandLevel", 0)); + newBiomeObject.setRequiredCost(details.getInt("cost", 0)); + + List permissions = details.getStringList("permission"); + + if (permissions.isEmpty()) + { + newBiomeObject.setRequiredPermissions(Collections.emptySet()); + } + else + { + newBiomeObject.setRequiredPermissions(new HashSet<>(permissions)); + } + + if (this.addon.getAddonManager().loadBiomes( + newBiomeObject, overwrite, user, false)) + { + size++; + } + } + else + { + user.sendMessage("biomes.errors.load-biome", + BIOME, + biome); + } + } + + user.sendMessage("biomes.messages.import-count", + TextVariables.NUMBER, + String.valueOf(size)); + } + + + // --------------------------------------------------------------------- + // Section: Migrate + // --------------------------------------------------------------------- + + + /** + * This method migrated all biomes addon data from worldName to addonID format. + */ + public void migrateDatabase(User user, World world) + { + world = Util.getWorld(world); + + if (user.isPlayer()) + { + user.sendMessage("biomes.messages.admin.migrate-start"); + } + else + { + this.addon.log("Starting migration to new data format."); + } + + boolean biomes = this.migrateBiomes(world); + + if (biomes) + { + if (user.isPlayer()) + { + user.sendMessage("biomes.messages.admin.migrate-end"); + } + else + { + this.addon.log("Migration to new data format completed."); + } + } + else + { + if (user.isPlayer()) + { + user.sendMessage("biomes.messages.admin.migrate-not"); + } + else + { + this.addon.log("All data is valid. Migration is not necessary."); + } + } + } + + + /** + * This method migrates biomes object to new id format. + * @param world World which biomes must be updated. + * @return {@code true} if any biome is updated, + * {@code false} otherwise. + */ + private boolean migrateBiomes(World world) + { + String addonName = Utils.getGameMode(world); + + if (addonName == null || addonName.equalsIgnoreCase(world.getName())) + { + return false; + } + + boolean updated = false; + List objectList = this.biomesDatabase.loadObjects(); + + for (BiomesObject biomesObject : objectList) + { + if (biomesObject.getUniqueId().regionMatches(true, 0, world.getName() + "-", 0, world.getName().length() + 1)) + { + this.biomesDatabase.deleteID(biomesObject.getUniqueId()); + this.biomesCacheData.remove(biomesObject.getUniqueId()); + + biomesObject.setUniqueId( + addonName + "_" + biomesObject.getUniqueId().substring(world.getName().length() + 1)); + + // Update world, as in some situations it was not set. + biomesObject.setWorld(Util.getWorld(world).getName()); + + this.biomesDatabase.saveObjectAsync(biomesObject); + this.biomesCacheData.put(biomesObject.getUniqueId(), biomesObject); + + updated = true; + } + } + + return updated; + } + + + // --------------------------------------------------------------------- + // Section: Creating + // --------------------------------------------------------------------- + + + /** + * This method creates and returns new biome with given uniqueID. + * @param uniqueID - new ID for challenge. + * @param worldName - world name where biome operates. + * @return biome that is currently created. + */ + public BiomesObject createBiome(String uniqueID, String worldName) + { + if (!this.containsBiome(uniqueID)) + { + BiomesObject biome = new BiomesObject(); + biome.setUniqueId(uniqueID); + + // Sets default biome as VOID. + biome.setBiome(Biome.THE_VOID); + biome.setWorld(worldName); + + this.saveBiome(biome); + this.loadBiomes(biome); + + return biome; + } + else + { + return null; + } + } + + + // --------------------------------------------------------------------- + // Section: Getters / Setters + // --------------------------------------------------------------------- + + + /** + * This method returns biomes that is visible for user by using default visibility mode. + * @param world World in which biomes must be returned. + * @param user User who will see biomes. + * @return Visible biome list. + */ + public List getBiomes(World world, User user) + { + return this.getBiomes(world, user, this.addon.getSettings().getVisibilityMode()); + } + + + /** + * This method returns biomes that is visible for user in given world. + * @param world World in which biomes must be returned. + * @param user User who will see biomes. + * @param visibilityMode active visibilityMode. Only ALL will return all biomes. + * DEPLOYED will show biomes that has deployedFlag enabled. + * ACCESSIBLE will show biomes that are deployed and user has permission that unlocks biome. + * TOGGLEABLE will work as ACCESSIBLE. + * @return Visible biome list. + */ + public List getBiomes(World world, User user, VisibilityMode visibilityMode) + { + List allBiomeList = this.getBiomes(world); + + if (visibilityMode.equals(VisibilityMode.ALL)) + { + return allBiomeList; + } + + List returnBiomesList = new ArrayList<>(allBiomeList.size()); + + allBiomeList.forEach(biomesObject -> { + if (biomesObject.isDeployed() && + (visibilityMode.equals(VisibilityMode.DEPLOYED) || + biomesObject.getRequiredPermissions().isEmpty() || + biomesObject.getRequiredPermissions().stream().allMatch(user::hasPermission))) + { + returnBiomesList.add(biomesObject); + } + }); + + return returnBiomesList; + } + + + /** + * This method returns list with loaded biomes for given world. + * @param world World where biome operates. + * @return list with loaded biomes. + */ + public List getBiomes(World world) + { + world = Util.getWorld(world); + + return world == null ? Collections.emptyList() : this.getBiomes(world.getName()); + } + + + /** + * This method returns list with loaded biomes for given world. + * @param worldName Name of world where biome operates. + * @return list with loaded biomes. + */ + public List getBiomes(String worldName) + { + return this.biomesCacheData.values().stream(). + sorted(BiomesObject::compareTo). + filter(biome -> biome.getWorld().equalsIgnoreCase(worldName)). + collect(Collectors.toList()); + } + + + /** + * This method returns biome object that hides behind biome name or null, if biome + * with name does not exist. + * @param biomeUniqueID Biome's name. + * @return BiomesObject that is represented by biome string. + */ + public BiomesObject getBiomeFromString(String biomeUniqueID) + { + return this.biomesCacheData.getOrDefault(biomeUniqueID, null); + } + + + /** + * Check if a biome exists - case insensitive + * + * @param name - name of biome + * @return true if it exists, otherwise false + */ + public boolean containsBiome(String name) + { + if (this.biomesCacheData.containsKey(name)) + { + return true; + } + else + { + // check database. + if (this.biomesDatabase.objectExists(name)) + { + BiomesObject biome = this.biomesDatabase.loadObject(name); + this.biomesCacheData.put(name, biome); + return true; + } + } + + return false; + } + + + /** + * Given method removes biome from database and cache. + * @param biome Biome that must be removed. + */ + public void removeBiome(BiomesObject biome) + { + if (this.biomesCacheData.containsKey(biome.getUniqueId())) + { + this.biomesCacheData.remove(biome.getUniqueId()); + this.biomesDatabase.deleteObject(biome); + } + } + + + /** + * This method returns map that contains biomes name as key and biome as value. + * @return Map that contains relation from biome name to biome. + */ + public static Map getBiomeNameMap() + { + Biome[] biomes = Biome.values(); + + Map returnMap = new HashMap<>(biomes.length); + + for (Biome biome : biomes) + { + returnMap.put(biome.name(), biome); + } + + return returnMap; + } + + + /** + * This method returns if in given world biomes are setup. + * @param world World that must be checked. + * @return True if in given world exist biomes. + */ + public boolean hasAnyBiome(World world) + { + String worldName = Util.getWorld(world) == null ? "" : Util.getWorld(world).getName(); + + return !worldName.isEmpty() && + this.biomesCacheData.values().stream().anyMatch(biome -> biome.getWorld().equalsIgnoreCase(worldName)); + } + + + // --------------------------------------------------------------------- + // Section: Later Biome Updater + // --------------------------------------------------------------------- + + + /** + * This method finds and returns BiomeChunkUpdaterObject in given world with given + * chunk X and Z coordinates. + * @param world World where process will happen. + * @param x Chunk X coordinate. + * @param z Chunk Z coordinate. + * @return BiomeChunkUpdateObject where update is pending or null. + */ + public BiomeChunkUpdateObject getPendingChunkUpdateObject(World world, int x, int z) + { + return this.biomePendingChunkUpdateMap.get(Utils.getGameMode(world) + "_" + x + "-" + z); + } + + + /** + * This method returns collection with all objects that contains information about + * chunks where biome update is still not completed. + * @return Collection of BiomeCHunkUpdateObjects. + */ + public Collection getBiomeUpdaterCollection() + { + return this.biomePendingChunkUpdateMap.values(); + } + + + /** + * This method adds BiomeChunkUpdateObject to cache. + * @param updateObject Object that must be added to cache. + */ + public void addChunkUpdateObject(BiomeChunkUpdateObject updateObject) + { + this.biomePendingChunkUpdateMap.put(updateObject.getUniqueId(), updateObject); + } + + + /** + * This method removes given element form cache and database. + * @param element Element that should be removed. + */ + public void removeUpdateObject(BiomeChunkUpdateObject element) + { + if (this.biomePendingChunkUpdateMap.containsKey(element.getUniqueId())) + { + this.biomePendingChunkUpdateMap.remove(element.getUniqueId()); + this.biomePendingChunkUpdateDatabase.deleteObject(element); + } + } + + + // --------------------------------------------------------------------- + // Section: Variables + // --------------------------------------------------------------------- + + /** + * Variable current addon. + */ + private BiomesAddon addon; + + /** + * Variable stores map that links String to loaded biomes object. + */ + private Map biomesCacheData; + + /** + * Variable stores database of biomes objects. + */ + private Database biomesDatabase; + + /** + * Variable stores biomes.yml location + */ + private File biomesFile; + + /** + * Variable stores BiomeChunkUpdateObject objects that contains information about + * chunk that is not updated yet. + */ + private Map biomePendingChunkUpdateMap; + + /** + * Variable stores database of BiomeChunkUpdateObject. + */ + private Database biomePendingChunkUpdateDatabase; } diff --git a/src/main/java/world/bentobox/biomes/database/objects/BiomeChunkUpdateObject.java b/src/main/java/world/bentobox/biomes/database/objects/BiomeChunkUpdateObject.java index 5a1b5d5..f5ae533 100644 --- a/src/main/java/world/bentobox/biomes/database/objects/BiomeChunkUpdateObject.java +++ b/src/main/java/world/bentobox/biomes/database/objects/BiomeChunkUpdateObject.java @@ -7,6 +7,7 @@ import com.google.gson.annotations.Expose; import world.bentobox.bentobox.database.objects.DataObject; +import world.bentobox.bentobox.database.objects.Table; /** @@ -16,295 +17,296 @@ * @author BONNe * Created on 2019-07-03 */ +@Table(name = "BiomeUpdateChunks") public class BiomeChunkUpdateObject implements DataObject { - /** - * Constructor ChunkUpdateObject creates a new ChunkUpdateObject instance. - */ - public BiomeChunkUpdateObject() - { - } - - - // --------------------------------------------------------------------- - // Section: Getters and setters - // --------------------------------------------------------------------- - - - /** - * This method returns the uniqueId value. - * @return the value of uniqueId. - */ - @Override - public String getUniqueId() - { - return this.uniqueId; - } - - - /** - * This method sets the uniqueId value. - * @param uniqueId the uniqueId new value. - * - */ - @Override - public void setUniqueId(String uniqueId) - { - this.uniqueId = uniqueId; - } - - - /** - * This method returns the minX value. - * @return the value of minX. - */ - public int getMinX() - { - return minX; - } - - - /** - * This method sets the minX value. - * @param minX the minX new value. - * - */ - public void setMinX(int minX) - { - this.minX = minX; - } - - - /** - * This method returns the maxX value. - * @return the value of maxX. - */ - public int getMaxX() - { - return maxX; - } - - - /** - * This method sets the maxX value. - * @param maxX the maxX new value. - * - */ - public void setMaxX(int maxX) - { - this.maxX = maxX; - } - - - /** - * This method returns the minZ value. - * @return the value of minZ. - */ - public int getMinZ() - { - return minZ; - } - - - /** - * This method sets the minZ value. - * @param minZ the minZ new value. - * - */ - public void setMinZ(int minZ) - { - this.minZ = minZ; - } - - - /** - * This method returns the maxZ value. - * @return the value of maxZ. - */ - public int getMaxZ() - { - return maxZ; - } - - - /** - * This method sets the maxZ value. - * @param maxZ the maxZ new value. - * - */ - public void setMaxZ(int maxZ) - { - this.maxZ = maxZ; - } - - - /** - * This method returns the chunkX value. - * @return the value of chunkX. - */ - public int getChunkX() - { - return chunkX; - } - - - /** - * This method sets the chunkX value. - * @param chunkX the chunkX new value. - * - */ - public void setChunkX(int chunkX) - { - this.chunkX = chunkX; - } - - - /** - * This method returns the chunkZ value. - * @return the value of chunkZ. - */ - public int getChunkZ() - { - return chunkZ; - } - - - /** - * This method sets the chunkZ value. - * @param chunkZ the chunkZ new value. - * - */ - public void setChunkZ(int chunkZ) - { - this.chunkZ = chunkZ; - } - - - /** - * This method returns the biome value. - * @return the value of biome. - */ - public Biome getBiome() - { - return biome; - } - - - /** - * This method sets the biome value. - * @param biome the biome new value. - * - */ - public void setBiome(Biome biome) - { - this.biome = biome; - } - - - /** - * This method returns the world value. - * @return the value of world. - */ - public World getWorld() - { - return world; - } - - - /** - * This method sets the world value. - * @param world the world new value. - * - */ - public void setWorld(World world) - { - this.world = world; - } - - - /** - * This method returns the forceLoaded value. - * @return the value of forceLoaded. - */ - public boolean isForceLoaded() - { - return forceLoaded; - } - - - /** - * This method sets the forceLoaded value. - * @param forceLoaded the forceLoaded new value. - * - */ - public void setForceLoaded(boolean forceLoaded) - { - this.forceLoaded = forceLoaded; - } - - - // --------------------------------------------------------------------- - // Section: Variables - // --------------------------------------------------------------------- - - - /** - * Unique ID of current object. - */ - @Expose - private String uniqueId; - - /** - * Minimal X coordinate of biome update. - */ - @Expose - private int minX; - - /** - * Maximal X coordinate of biome update. - */ - @Expose - private int maxX; - - /** - * Minimal Z coordinate of biome update. - */ - @Expose - private int minZ; - - /** - * Maximal Z coordinate of biome update. - */ - @Expose - private int maxZ; - - /** - * Chunk X coordinate. - */ - @Expose - private int chunkX; - - /** - * Chunk Z coordinate. - */ - @Expose - private int chunkZ; - - /** - * Biome that will update in current update process. - */ - @Expose - private Biome biome; - - /** - * World where current object should work. - */ - @Expose - private World world; - - /** - * Boolean that indicate that chunk is already force-loaded. - */ - @Expose - private boolean forceLoaded; + /** + * Constructor ChunkUpdateObject creates a new ChunkUpdateObject instance. + */ + public BiomeChunkUpdateObject() + { + } + + + // --------------------------------------------------------------------- + // Section: Getters and setters + // --------------------------------------------------------------------- + + + /** + * This method returns the uniqueId value. + * @return the value of uniqueId. + */ + @Override + public String getUniqueId() + { + return this.uniqueId; + } + + + /** + * This method sets the uniqueId value. + * @param uniqueId the uniqueId new value. + * + */ + @Override + public void setUniqueId(String uniqueId) + { + this.uniqueId = uniqueId; + } + + + /** + * This method returns the minX value. + * @return the value of minX. + */ + public int getMinX() + { + return minX; + } + + + /** + * This method sets the minX value. + * @param minX the minX new value. + * + */ + public void setMinX(int minX) + { + this.minX = minX; + } + + + /** + * This method returns the maxX value. + * @return the value of maxX. + */ + public int getMaxX() + { + return maxX; + } + + + /** + * This method sets the maxX value. + * @param maxX the maxX new value. + * + */ + public void setMaxX(int maxX) + { + this.maxX = maxX; + } + + + /** + * This method returns the minZ value. + * @return the value of minZ. + */ + public int getMinZ() + { + return minZ; + } + + + /** + * This method sets the minZ value. + * @param minZ the minZ new value. + * + */ + public void setMinZ(int minZ) + { + this.minZ = minZ; + } + + + /** + * This method returns the maxZ value. + * @return the value of maxZ. + */ + public int getMaxZ() + { + return maxZ; + } + + + /** + * This method sets the maxZ value. + * @param maxZ the maxZ new value. + * + */ + public void setMaxZ(int maxZ) + { + this.maxZ = maxZ; + } + + + /** + * This method returns the chunkX value. + * @return the value of chunkX. + */ + public int getChunkX() + { + return chunkX; + } + + + /** + * This method sets the chunkX value. + * @param chunkX the chunkX new value. + * + */ + public void setChunkX(int chunkX) + { + this.chunkX = chunkX; + } + + + /** + * This method returns the chunkZ value. + * @return the value of chunkZ. + */ + public int getChunkZ() + { + return chunkZ; + } + + + /** + * This method sets the chunkZ value. + * @param chunkZ the chunkZ new value. + * + */ + public void setChunkZ(int chunkZ) + { + this.chunkZ = chunkZ; + } + + + /** + * This method returns the biome value. + * @return the value of biome. + */ + public Biome getBiome() + { + return biome; + } + + + /** + * This method sets the biome value. + * @param biome the biome new value. + * + */ + public void setBiome(Biome biome) + { + this.biome = biome; + } + + + /** + * This method returns the world value. + * @return the value of world. + */ + public World getWorld() + { + return world; + } + + + /** + * This method sets the world value. + * @param world the world new value. + * + */ + public void setWorld(World world) + { + this.world = world; + } + + + /** + * This method returns the forceLoaded value. + * @return the value of forceLoaded. + */ + public boolean isForceLoaded() + { + return forceLoaded; + } + + + /** + * This method sets the forceLoaded value. + * @param forceLoaded the forceLoaded new value. + * + */ + public void setForceLoaded(boolean forceLoaded) + { + this.forceLoaded = forceLoaded; + } + + + // --------------------------------------------------------------------- + // Section: Variables + // --------------------------------------------------------------------- + + + /** + * Unique ID of current object. + */ + @Expose + private String uniqueId; + + /** + * Minimal X coordinate of biome update. + */ + @Expose + private int minX; + + /** + * Maximal X coordinate of biome update. + */ + @Expose + private int maxX; + + /** + * Minimal Z coordinate of biome update. + */ + @Expose + private int minZ; + + /** + * Maximal Z coordinate of biome update. + */ + @Expose + private int maxZ; + + /** + * Chunk X coordinate. + */ + @Expose + private int chunkX; + + /** + * Chunk Z coordinate. + */ + @Expose + private int chunkZ; + + /** + * Biome that will update in current update process. + */ + @Expose + private Biome biome; + + /** + * World where current object should work. + */ + @Expose + private World world; + + /** + * Boolean that indicate that chunk is already force-loaded. + */ + @Expose + private boolean forceLoaded; } diff --git a/src/main/java/world/bentobox/biomes/database/objects/BiomesObject.java b/src/main/java/world/bentobox/biomes/database/objects/BiomesObject.java index 3ca901f..178e218 100644 --- a/src/main/java/world/bentobox/biomes/database/objects/BiomesObject.java +++ b/src/main/java/world/bentobox/biomes/database/objects/BiomesObject.java @@ -15,359 +15,361 @@ import world.bentobox.bentobox.api.configuration.ConfigComment; import world.bentobox.bentobox.database.objects.DataObject; +import world.bentobox.bentobox.database.objects.Table; import world.bentobox.biomes.utils.Utils; /** * This class stores necessary information for each Biomes object. */ +@Table(name = "Biomes") public class BiomesObject implements DataObject, Comparable { - /** - * Empty constructor for loader. - */ - public BiomesObject() - { - // Empty constructor. - } - - - /** - * Default constructor. - */ - public BiomesObject(Biome biome, World world) - { - this.biome = biome; - this.world = world.getName(); - this.friendlyName = biome.name(); - this.setUniqueId(Utils.getGameMode(world) + "_" + this.biome.toString().toLowerCase()); - } - - -// --------------------------------------------------------------------- -// Section: Setters and Getters -// --------------------------------------------------------------------- - - - /** - * This method returns biomes name. - * @return Biomes name. - */ - public Biome getBiome() - { - return this.biome; - } - - - /** - * This method sets biomes name. - * @param biome Biomes name. - */ - public void setBiome(Biome biome) - { - this.biome = biome; - } - - - /** - * @return the deployed - */ - public boolean isDeployed() - { - return deployed; - } - - - /** - * @param deployed the deployed to set - */ - public void setDeployed(boolean deployed) - { - this.deployed = deployed; - } - - - /** - * @return the description - */ - public List getDescription() - { - return description; - } - - - /** - * @param description the description to set - */ - public void setDescription(List description) - { - this.description = description; - } - - - /** - * @return the friendlyName - */ - public String getFriendlyName() - { - return friendlyName; - } - - - /** - * @param friendlyName the friendlyName to set - */ - public void setFriendlyName(String friendlyName) - { - this.friendlyName = friendlyName; - } - - - /** - * @return the icon - */ - public ItemStack getIcon() - { - return icon != null ? icon.clone() : new ItemStack(Material.MAP); - } - - - /** - * @param icon the icon to set - */ - public void setIcon(ItemStack icon) - { - this.icon = icon; - } - - - /** - * @return the reqIslandlevel - */ - public long getRequiredLevel() - { - return this.requiredLevel; - } - - - /** - * @param requiredLevel the requiredLevel to set - */ - public void setRequiredLevel(long requiredLevel) - { - this.requiredLevel = requiredLevel; - } - - - /** - * @return the cost of changing biome - */ - public int getRequiredCost() - { - return this.requiredCost; - } - - - /** - * @param requiredCost the reqMoney to set - */ - public void setRequiredCost(int requiredCost) - { - this.requiredCost = requiredCost; - } - - - /** - * - * @return world in which biome operates - */ - public String getWorld() - { - return this.world; - } - - - /** - * @param world where biome must operate. - */ - public void setWorld(String world) - { - this.world = world; - } - - - /** - * @return the uniqueId - */ - @Override - public String getUniqueId() - { - return uniqueId; - } - - - /** - * @param uniqueId the uniqueId to set - */ - @Override - public void setUniqueId(String uniqueId) - { - this.uniqueId = uniqueId; - } - - - /** - * This method returns the order object. - * @return the order object. - */ - public int getOrder() - { - return order; - } - - - /** - * This method sets the order object value. - * @param order the order object new value. - * - */ - public void setOrder(int order) - { - this.order = order; - } - - - /** - * This method returns the permissions object. - * @return the permissions object. - */ - public Set getRequiredPermissions() - { - return requiredPermissions; - } - - - /** - * This method sets the permissions object value. - * @param requiredPermissions the permissions object new value. - * - */ - public void setRequiredPermissions(Set requiredPermissions) - { - this.requiredPermissions = requiredPermissions; - } - - -// --------------------------------------------------------------------- -// Section: Other methods -// --------------------------------------------------------------------- - - - /* - * (non-Javadoc) - * @see java.lang.Object#hashCode() - */ - @Override - public int hashCode() - { - return 31 + ((this.uniqueId == null) ? 0 : this.uniqueId.hashCode()); - } - - - /* - *(non-Javadoc) - * @see java.lang.Object#equals(java.lang.Object) - */ - @Override - public boolean equals(Object obj) - { - if (this == obj) - { - return true; - } - - if (!(obj instanceof BiomesObject)) - { - return false; - } - - BiomesObject other = (BiomesObject) obj; - - if (this.uniqueId == null && other.getUniqueId() == null) - { - return this.biome == other.getBiome(); - } - else if (this.uniqueId == null || other.getUniqueId() == null) - { - return false; - } - else - { - return this.uniqueId.equals(other.getUniqueId()); - } - } - - - /* - * (non-Javadoc) - * @see java.lang.Object#equals(java.lang.Object) - */ - @Override - public int compareTo(BiomesObject object) - { - int rc = Integer.compare(this.order, object.getOrder()); - - return this.biome != null && object.getBiome() != null && rc == 0 ? - this.biome.compareTo(object.getBiome()) : rc; - } - - -// --------------------------------------------------------------------- -// Section: Variables -// --------------------------------------------------------------------- - - - @ConfigComment("Official minecraft biome name.") - @Expose - private Biome biome; - - @ConfigComment("Whether this biome is deployed or not") - @Expose - private boolean deployed; - - @ConfigComment("Name of the icon and biomes. May include color codes. Single line.") - @Expose - private String friendlyName = ""; - - @ConfigComment("Description of the biomes. Will become the lore on the icon. Can include & color codes. String List.") - @Expose - private List description = new ArrayList<>(); - - @ConfigComment("The icon in the GUI for this biome. ItemStack.") - @Expose - private ItemStack icon = new ItemStack(Material.PAPER); - - @ConfigComment("Order of biome. Biomes will be ordered in ascending order.") - @Expose - private int order = -1; - - @ConfigComment("Required island level for this biome. Only works if Level Addon is being used.") - @Expose - private long requiredLevel; - - @ConfigComment("Cost of changing biome.") - @Expose - private int requiredCost; - - @ConfigComment("Set of String permission that is required for this biome to be activated.") - @Expose - private Set requiredPermissions = new HashSet<>(); - - @ConfigComment("World where this biome operates. List only NORMAL. NETHER and THE_END are automatically covered.") - @Expose - private String world; - - @ConfigComment("Unique StringName of the biome") - @Expose - private String uniqueId; + /** + * Empty constructor for loader. + */ + public BiomesObject() + { + // Empty constructor. + } + + + /** + * Default constructor. + */ + public BiomesObject(Biome biome, World world) + { + this.biome = biome; + this.world = world.getName(); + this.friendlyName = biome.name(); + this.setUniqueId(Utils.getGameMode(world) + "_" + this.biome.toString().toLowerCase()); + } + + + // --------------------------------------------------------------------- + // Section: Setters and Getters + // --------------------------------------------------------------------- + + + /** + * This method returns biomes name. + * @return Biomes name. + */ + public Biome getBiome() + { + return this.biome; + } + + + /** + * This method sets biomes name. + * @param biome Biomes name. + */ + public void setBiome(Biome biome) + { + this.biome = biome; + } + + + /** + * @return the deployed + */ + public boolean isDeployed() + { + return deployed; + } + + + /** + * @param deployed the deployed to set + */ + public void setDeployed(boolean deployed) + { + this.deployed = deployed; + } + + + /** + * @return the description + */ + public List getDescription() + { + return description; + } + + + /** + * @param description the description to set + */ + public void setDescription(List description) + { + this.description = description; + } + + + /** + * @return the friendlyName + */ + public String getFriendlyName() + { + return friendlyName; + } + + + /** + * @param friendlyName the friendlyName to set + */ + public void setFriendlyName(String friendlyName) + { + this.friendlyName = friendlyName; + } + + + /** + * @return the icon + */ + public ItemStack getIcon() + { + return icon != null ? icon.clone() : new ItemStack(Material.MAP); + } + + + /** + * @param icon the icon to set + */ + public void setIcon(ItemStack icon) + { + this.icon = icon; + } + + + /** + * @return the reqIslandlevel + */ + public long getRequiredLevel() + { + return this.requiredLevel; + } + + + /** + * @param requiredLevel the requiredLevel to set + */ + public void setRequiredLevel(long requiredLevel) + { + this.requiredLevel = requiredLevel; + } + + + /** + * @return the cost of changing biome + */ + public int getRequiredCost() + { + return this.requiredCost; + } + + + /** + * @param requiredCost the reqMoney to set + */ + public void setRequiredCost(int requiredCost) + { + this.requiredCost = requiredCost; + } + + + /** + * + * @return world in which biome operates + */ + public String getWorld() + { + return this.world; + } + + + /** + * @param world where biome must operate. + */ + public void setWorld(String world) + { + this.world = world; + } + + + /** + * @return the uniqueId + */ + @Override + public String getUniqueId() + { + return uniqueId; + } + + + /** + * @param uniqueId the uniqueId to set + */ + @Override + public void setUniqueId(String uniqueId) + { + this.uniqueId = uniqueId; + } + + + /** + * This method returns the order object. + * @return the order object. + */ + public int getOrder() + { + return order; + } + + + /** + * This method sets the order object value. + * @param order the order object new value. + * + */ + public void setOrder(int order) + { + this.order = order; + } + + + /** + * This method returns the permissions object. + * @return the permissions object. + */ + public Set getRequiredPermissions() + { + return requiredPermissions; + } + + + /** + * This method sets the permissions object value. + * @param requiredPermissions the permissions object new value. + * + */ + public void setRequiredPermissions(Set requiredPermissions) + { + this.requiredPermissions = requiredPermissions; + } + + + // --------------------------------------------------------------------- + // Section: Other methods + // --------------------------------------------------------------------- + + + /* + * (non-Javadoc) + * @see java.lang.Object#hashCode() + */ + @Override + public int hashCode() + { + return 31 + ((this.uniqueId == null) ? 0 : this.uniqueId.hashCode()); + } + + + /* + *(non-Javadoc) + * @see java.lang.Object#equals(java.lang.Object) + */ + @Override + public boolean equals(Object obj) + { + if (this == obj) + { + return true; + } + + if (!(obj instanceof BiomesObject)) + { + return false; + } + + BiomesObject other = (BiomesObject) obj; + + if (this.uniqueId == null && other.getUniqueId() == null) + { + return this.biome == other.getBiome(); + } + else if (this.uniqueId == null || other.getUniqueId() == null) + { + return false; + } + else + { + return this.uniqueId.equals(other.getUniqueId()); + } + } + + + /* + * (non-Javadoc) + * @see java.lang.Object#equals(java.lang.Object) + */ + @Override + public int compareTo(BiomesObject object) + { + int rc = Integer.compare(this.order, object.getOrder()); + + return this.biome != null && object.getBiome() != null && rc == 0 ? + this.biome.compareTo(object.getBiome()) : rc; + } + + + // --------------------------------------------------------------------- + // Section: Variables + // --------------------------------------------------------------------- + + + @ConfigComment("Official minecraft biome name.") + @Expose + private Biome biome; + + @ConfigComment("Whether this biome is deployed or not") + @Expose + private boolean deployed; + + @ConfigComment("Name of the icon and biomes. May include color codes. Single line.") + @Expose + private String friendlyName = ""; + + @ConfigComment("Description of the biomes. Will become the lore on the icon. Can include & color codes. String List.") + @Expose + private List description = new ArrayList<>(); + + @ConfigComment("The icon in the GUI for this biome. ItemStack.") + @Expose + private ItemStack icon = new ItemStack(Material.PAPER); + + @ConfigComment("Order of biome. Biomes will be ordered in ascending order.") + @Expose + private int order = -1; + + @ConfigComment("Required island level for this biome. Only works if Level Addon is being used.") + @Expose + private long requiredLevel; + + @ConfigComment("Cost of changing biome.") + @Expose + private int requiredCost; + + @ConfigComment("Set of String permission that is required for this biome to be activated.") + @Expose + private Set requiredPermissions = new HashSet<>(); + + @ConfigComment("World where this biome operates. List only NORMAL. NETHER and THE_END are automatically covered.") + @Expose + private String world; + + @ConfigComment("Unique StringName of the biome") + @Expose + private String uniqueId; } diff --git a/src/main/resources/addon.yml b/src/main/resources/addon.yml index 51c42f7..ad747af 100644 --- a/src/main/resources/addon.yml +++ b/src/main/resources/addon.yml @@ -1,7 +1,7 @@ name: Biomes main: world.bentobox.biomes.BiomesAddon version: ${project.version}${build.number} -api-version: 1.12 +api-version: 1.14 repository: 'BentoBoxWorld/Biomes' metrics: true