From c3c0a87dbb00d91982533c8b5ad8045d6a892a8a Mon Sep 17 00:00:00 2001 From: Tastybento Date: Sat, 20 Jan 2018 10:30:26 -0800 Subject: [PATCH] Added block search when making a new island. Fixed sign text. When finding a spot for a new island, the algorithm will ensure the island location is on the grid and check around for any blocks that may be there already. If they exist, then they will be added as unowned islands to the database. The sign text was not using the correct locale tags. --- .../managers/island/IslandsManager.java | 50 ++++++++++++++++++- .../island/builders/IslandBuilder.java | 4 +- 2 files changed, 51 insertions(+), 3 deletions(-) diff --git a/src/main/java/us/tastybento/bskyblock/database/managers/island/IslandsManager.java b/src/main/java/us/tastybento/bskyblock/database/managers/island/IslandsManager.java index 4cc67d4e0..2facd150a 100644 --- a/src/main/java/us/tastybento/bskyblock/database/managers/island/IslandsManager.java +++ b/src/main/java/us/tastybento/bskyblock/database/managers/island/IslandsManager.java @@ -648,10 +648,58 @@ public class IslandsManager { return spawn.onIsland(playerLoc); } + /** + * Checks if there is an island or blocks at this location + * @param location + * @return + */ public boolean isIsland(Location location){ - return islandCache.get(location) != null; + if (location == null) + return true; + location = getClosestIsland(location); + if (islandCache.contains(location)) + return true; + + if (!plugin.getSettings().isUseOwnGenerator()) { + // Block check + if (!location.getBlock().isEmpty() && !location.getBlock().isLiquid()) { + plugin.getLogger().info("Found solid block at island height - adding"); + createIsland(location); + return true; + } + // Look around + + for (int x = -5; x <= 5; x++) { + for (int y = 10; y <= 255; y++) { + for (int z = -5; z <= 5; z++) { + if (!location.getWorld().getBlockAt(x + location.getBlockX(), y, z + location.getBlockZ()).isEmpty() + && !location.getWorld().getBlockAt(x + location.getBlockX(), y, z + location.getBlockZ()).isLiquid()) { + plugin.getLogger().info("Solid block found during long search - adding "); + createIsland(location); + return true; + } + } + } + } + } + return false; } + /** + * This returns the coordinate of where an island should be on the grid. + * + * @param location location to query + * @return Location of closest island + */ + public Location getClosestIsland(Location location) { + long x = Math.round((double) location.getBlockX() / plugin.getSettings().getIslandDistance()) + * plugin.getSettings().getIslandDistance() + plugin.getSettings().getIslandXOffset(); + long z = Math.round((double) location.getBlockZ() / plugin.getSettings().getIslandDistance()) + * plugin.getSettings().getIslandDistance() + plugin.getSettings().getIslandZOffset(); + long y = plugin.getSettings().getIslandHeight(); + return new Location(location.getWorld(), x, y, z); + } + /** * @param uniqueId * @return true if the player is the owner of their island, i.e., owner or team leader diff --git a/src/main/java/us/tastybento/bskyblock/island/builders/IslandBuilder.java b/src/main/java/us/tastybento/bskyblock/island/builders/IslandBuilder.java index e81f490c1..ae3dc2181 100644 --- a/src/main/java/us/tastybento/bskyblock/island/builders/IslandBuilder.java +++ b/src/main/java/us/tastybento/bskyblock/island/builders/IslandBuilder.java @@ -481,8 +481,8 @@ public class IslandBuilder { if (this.playerUUID != null) { Sign sign = (Sign) blockToChange.getState(); User user = User.getInstance(playerUUID); - for (int i = 0; i < 4; i++) { - sign.setLine(i, user.getTranslation("island.sign.line" + i, "[player]", playerName)); + for (int i = 1; i < 5; i++) { + sign.setLine(i, user.getTranslation("new-island.sign.line" + i, "[player]", playerName)); } ((org.bukkit.material.Sign) sign.getData()).setFacingDirection(BlockFace.NORTH); sign.update();