diff --git a/pom.xml b/pom.xml index feeb9e8..cf46776 100644 --- a/pom.xml +++ b/pom.xml @@ -67,7 +67,7 @@ -LOCAL - 1.12.2 + 1.12.3 BentoBoxWorld_AOneBlock bentobox-world diff --git a/src/main/java/world/bentobox/aoneblock/AOneBlock.java b/src/main/java/world/bentobox/aoneblock/AOneBlock.java index a205e53..9bec523 100644 --- a/src/main/java/world/bentobox/aoneblock/AOneBlock.java +++ b/src/main/java/world/bentobox/aoneblock/AOneBlock.java @@ -264,17 +264,19 @@ public void allLoaded() { // Manage Old Holograms if (useHolographicDisplays()) { - for (Island island : getIslands().getIslands()) { + getIslands().getIslands().stream() + .filter(i -> this.inWorld(i.getWorld())) + .forEach(island -> { OneBlockIslands oneBlockIsland = getOneBlocksIsland(island); String hololine = oneBlockIsland.getHologram(); Location center = island.getCenter(); - if (hololine != null) { + if (!hololine.isEmpty()) { final Hologram hologram = HologramsAPI.createHologram(BentoBox.getInstance(), center.add(0.5, 2.6, 0.5)); for (String line : hololine.split("\\n")) { hologram.appendTextLine(ChatColor.translateAlternateColorCodes('&', line)); } } - } + }); } } diff --git a/src/main/java/world/bentobox/aoneblock/dataobjects/OneBlockIslands.java b/src/main/java/world/bentobox/aoneblock/dataobjects/OneBlockIslands.java index 364b99c..d69d0e1 100644 --- a/src/main/java/world/bentobox/aoneblock/dataobjects/OneBlockIslands.java +++ b/src/main/java/world/bentobox/aoneblock/dataobjects/OneBlockIslands.java @@ -93,6 +93,7 @@ public void incrementBlockNumber() { /** * @return the hologram Line */ + @NonNull public String getHologram() { return hologram == null ? "" : hologram; } diff --git a/src/main/java/world/bentobox/aoneblock/listeners/BlockListener.java b/src/main/java/world/bentobox/aoneblock/listeners/BlockListener.java index f702e55..6a8a416 100644 --- a/src/main/java/world/bentobox/aoneblock/listeners/BlockListener.java +++ b/src/main/java/world/bentobox/aoneblock/listeners/BlockListener.java @@ -57,6 +57,7 @@ import world.bentobox.aoneblock.oneblocks.OneBlocksManager; import world.bentobox.aoneblock.oneblocks.Requirement; import world.bentobox.bank.Bank; +import world.bentobox.bentobox.api.events.BentoBoxReadyEvent; import world.bentobox.bentobox.api.events.island.IslandCreatedEvent; import world.bentobox.bentobox.api.events.island.IslandDeleteEvent; import world.bentobox.bentobox.api.events.island.IslandResettedEvent; @@ -174,6 +175,23 @@ public BlockListener(@NonNull AOneBlock addon) { oneBlocksManager = addon.getOneBlockManager(); } + /** + * This cleans up the cache files in the database and removed old junk. + * This is to address a bug introduced 2 years ago that caused non AOneBlock islands + * to be stored in the AOneBlock database. This should be able to be + * removed in the future. + * @deprecated will be removed in the future + * @param e event + */ + @Deprecated(since = "1.12.3", forRemoval = true) + @EventHandler(priority = EventPriority.NORMAL, ignoreCancelled = true) + private void cleanCache(BentoBoxReadyEvent e) { + handler.loadObjects().forEach(i -> + addon.getIslandsManager().getIslandById(i.getUniqueId()) + .filter(is -> !addon.inWorld(is.getWorld()) || is.isUnowned()) + .ifPresent(is -> handler.deleteID(is.getUniqueId()))); + } + /** * Save the island cache */ @@ -182,9 +200,9 @@ public void saveCache() { } -// --------------------------------------------------------------------- -// Section: Listeners -// --------------------------------------------------------------------- + // --------------------------------------------------------------------- + // Section: Listeners + // --------------------------------------------------------------------- @EventHandler(priority = EventPriority.NORMAL, ignoreCancelled = true) @@ -290,8 +308,8 @@ public void onItemStackSpawn(EntitySpawnEvent event) Location location = event.getLocation(); Optional optionalIsland = this.addon.getIslands(). - getIslandAt(location). - filter(island -> location.getBlock().getLocation().equals(island.getCenter())); + getIslandAt(location). + filter(island -> location.getBlock().getLocation().equals(island.getCenter())); if (optionalIsland.isPresent()) { @@ -302,9 +320,9 @@ public void onItemStackSpawn(EntitySpawnEvent event) } -// --------------------------------------------------------------------- -// Section: Processing methods -// --------------------------------------------------------------------- + // --------------------------------------------------------------------- + // Section: Processing methods + // --------------------------------------------------------------------- private void setUp(@NonNull Island island) { @@ -488,24 +506,34 @@ private void playWarning(@NonNull OneBlockIslands is, @NonNull Block block) { * @return true if this is a new phase, false if not */ private boolean checkPhase(@Nullable Player player, @NonNull Island i, @NonNull OneBlockIslands is, @NonNull OneBlockPhase phase) { + // Handle NPCs + User user; + if (player == null || player.hasMetadata("NPC")) { + // Default to the owner + user = addon.getPlayers().getUser(i.getOwner()); + } else { + user = User.getInstance(player); + } + String phaseName = phase.getPhaseName() == null ? "" : phase.getPhaseName(); if (!is.getPhaseName().equalsIgnoreCase(phaseName)) { // Run previous phase end commands oneBlocksManager.getPhase(is.getPhaseName()).ifPresent(oldPhase -> { String oldPhaseName = oldPhase.getPhaseName() == null ? "" : oldPhase.getPhaseName(); - Util.runCommands(User.getInstance(player), + Util.runCommands(user, replacePlaceholders(player, oldPhaseName, phase.getBlockNumber(), i, oldPhase.getEndCommands()), "Commands run for end of " + oldPhaseName); }); // Set the phase name is.setPhaseName(phaseName); - if (player != null) { - player.sendTitle(phaseName, null, -1, -1, -1); - // Run phase start commands - Util.runCommands(User.getInstance(player), - replacePlaceholders(player, phaseName, phase.getBlockNumber(), i, phase.getStartCommands()), - "Commands run for start of " + phaseName); + if (user.isPlayer() && user.isOnline() && addon.inWorld(user.getWorld())) { + user.getPlayer().sendTitle(phaseName, null, -1, -1, -1); } + // Run phase start commands + Util.runCommands(user, + replacePlaceholders(player, phaseName, phase.getBlockNumber(), i, phase.getStartCommands()), + "Commands run for start of " + phaseName); + saveIsland(i); return true; } @@ -644,7 +672,7 @@ private void makeSpace(@NonNull Entity entity, @NonNull Location spawnLocation) // Make space for entity based on the entity's size final BoundingBox boundingBox = entity.getBoundingBox(); final boolean isWaterProtected = this.addon.getSettings().isWaterMobProtection() && - WATER_ENTITIES.contains(entity.getType()); + WATER_ENTITIES.contains(entity.getType()); for (double y = boundingBox.getMinY(); y <= Math.min(boundingBox.getMaxY(), world.getMaxHeight()); y++) { @@ -673,9 +701,9 @@ private void makeSpace(@NonNull Entity entity, @NonNull Location spawnLocation) for (double z = boundingBox.getMinZ() - 0.5; z < boundingBox.getMaxZ() + 0.5; z++) { block = world.getBlockAt(new Location(world, - x, - y, - z)); + x, + y, + z)); // Check if block should be marked. this.checkBlock(block, boundingBox, isWaterProtected, airBlocks, waterBlocks); @@ -688,9 +716,9 @@ else if (boundingBox.getWidthX() > 1) for (double x = boundingBox.getMinX() - 0.5; x < boundingBox.getMaxX() + 0.5; x++) { block = world.getBlockAt(new Location(world, - x, - y, - spawnLocation.getZ())); + x, + y, + spawnLocation.getZ())); // Check if block should be marked. this.checkBlock(block, boundingBox, isWaterProtected, airBlocks, waterBlocks); @@ -702,9 +730,9 @@ else if (boundingBox.getWidthZ() > 1) for (double z = boundingBox.getMinZ() - 0.5; z < boundingBox.getMaxZ() + 0.5; z++) { block = world.getBlockAt(new Location(world, - spawnLocation.getX(), - y, - z)); + spawnLocation.getX(), + y, + z)); // Check if block should be marked. this.checkBlock(block, boundingBox, isWaterProtected, airBlocks, waterBlocks); @@ -749,10 +777,10 @@ else if (boundingBox.getWidthZ() > 1) * @param waterBlocks List of water blocks. */ private void checkBlock(Block block, - BoundingBox boundingBox, - boolean isWaterEntity, - List airBlocks, - List waterBlocks) + BoundingBox boundingBox, + boolean isWaterEntity, + List airBlocks, + List waterBlocks) { // Check if block should be marked for destroying. if (block.getBoundingBox().overlaps(boundingBox)) @@ -815,6 +843,13 @@ public OneBlockIslands getIsland(@NonNull Island i) { return cache.containsKey(i.getUniqueId()) ? cache.get(i.getUniqueId()) : loadIsland(i.getUniqueId()); } + /** + * Get all the OneBlockIslands from the Database + * @return list of oneblock islands + */ + public List getAllIslands() { + return handler.loadObjects(); + } @NonNull private OneBlockIslands loadIsland(@NonNull String uniqueId) { diff --git a/src/main/resources/phases/12000_goto_0.yml b/src/main/resources/phases/12000_goto_0.yml index fdacdaa..d79c6c2 100644 --- a/src/main/resources/phases/12000_goto_0.yml +++ b/src/main/resources/phases/12000_goto_0.yml @@ -1,2 +1,2 @@ -'11000': +'12000': gotoBlock: 0 \ No newline at end of file