From b8510aa2efe6c0e084b533d2107aab2392ee9af0 Mon Sep 17 00:00:00 2001 From: tastybento Date: Mon, 20 Feb 2023 12:07:05 -0800 Subject: [PATCH 1/5] Version 1.12.3 --- pom.xml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) 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 From e4a58eb12c6d0b061986b1fe50ea6cfec53ac05d Mon Sep 17 00:00:00 2001 From: tastybento Date: Mon, 20 Feb 2023 12:32:15 -0800 Subject: [PATCH 2/5] Prevents errors when NPCs finish or start a phase Commands were assuming a real player. Addresses #300 --- .../aoneblock/listeners/BlockListener.java | 68 +++++++++++-------- 1 file changed, 39 insertions(+), 29 deletions(-) diff --git a/src/main/java/world/bentobox/aoneblock/listeners/BlockListener.java b/src/main/java/world/bentobox/aoneblock/listeners/BlockListener.java index f702e55..7914b67 100644 --- a/src/main/java/world/bentobox/aoneblock/listeners/BlockListener.java +++ b/src/main/java/world/bentobox/aoneblock/listeners/BlockListener.java @@ -182,9 +182,9 @@ public void saveCache() { } -// --------------------------------------------------------------------- -// Section: Listeners -// --------------------------------------------------------------------- + // --------------------------------------------------------------------- + // Section: Listeners + // --------------------------------------------------------------------- @EventHandler(priority = EventPriority.NORMAL, ignoreCancelled = true) @@ -290,8 +290,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 +302,9 @@ public void onItemStackSpawn(EntitySpawnEvent event) } -// --------------------------------------------------------------------- -// Section: Processing methods -// --------------------------------------------------------------------- + // --------------------------------------------------------------------- + // Section: Processing methods + // --------------------------------------------------------------------- private void setUp(@NonNull Island island) { @@ -488,24 +488,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 +654,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 +683,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 +698,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 +712,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 +759,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)) From 273da8475ca98a4e0f386194285b33ce5dfd054f Mon Sep 17 00:00:00 2001 From: tastybento Date: Mon, 20 Feb 2023 18:22:37 -0800 Subject: [PATCH 3/5] Added getAllIslands method --- .../world/bentobox/aoneblock/listeners/BlockListener.java | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/src/main/java/world/bentobox/aoneblock/listeners/BlockListener.java b/src/main/java/world/bentobox/aoneblock/listeners/BlockListener.java index 7914b67..61aea10 100644 --- a/src/main/java/world/bentobox/aoneblock/listeners/BlockListener.java +++ b/src/main/java/world/bentobox/aoneblock/listeners/BlockListener.java @@ -825,6 +825,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) { From bebb0bf4f2b206db2e1f37928bc6ab3a91c7b88e Mon Sep 17 00:00:00 2001 From: tastybento Date: Fri, 24 Feb 2023 19:02:41 -0800 Subject: [PATCH 4/5] Fixes a bug where non-AOneBlock islands were stored Commit a507029 introduced a bug where every island operated by the server was loaded into the AOneBlock cache and a Hologram placed at the center location of every island on the server even if the hologram was blank. In writing the top ten addon for AOneBlock these erroneous islands were discovered. This commit stops this from happening and cleans up the database of all the unonwed and non-AOneBlock islands. --- .../world/bentobox/aoneblock/AOneBlock.java | 8 +++++--- .../aoneblock/dataobjects/OneBlockIslands.java | 1 + .../aoneblock/listeners/BlockListener.java | 18 ++++++++++++++++++ 3 files changed, 24 insertions(+), 3 deletions(-) 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 61aea10..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 */ From db6da6e5449aff14cdb77471255ce43d28657866 Mon Sep 17 00:00:00 2001 From: tastybento Date: Sat, 25 Feb 2023 14:01:34 -0800 Subject: [PATCH 5/5] Fixes wrong value for end of phase. --- src/main/resources/phases/12000_goto_0.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) 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