From 4ff0e8a5609ba4ebe0354762aa5328b4a05e31fc Mon Sep 17 00:00:00 2001 From: tastybento Date: Sun, 19 Jan 2025 16:08:23 -0800 Subject: [PATCH] Allow safe teleporting to in water --- .../bentobox/managers/IslandsManager.java | 15 ++++++++++----- .../util/teleport/ClosestSafeSpotTeleport.java | 2 +- 2 files changed, 11 insertions(+), 6 deletions(-) diff --git a/src/main/java/world/bentobox/bentobox/managers/IslandsManager.java b/src/main/java/world/bentobox/bentobox/managers/IslandsManager.java index 559245645..b3a73b09f 100644 --- a/src/main/java/world/bentobox/bentobox/managers/IslandsManager.java +++ b/src/main/java/world/bentobox/bentobox/managers/IslandsManager.java @@ -152,8 +152,8 @@ public void setHandler(@NonNull Database h) { } /** - * Checks if this location is safe for a player to teleport to. Used by warps - * and boat exits Unsafe is any liquid or air and also if there's no space + * Checks if this location is safe for a player to teleport to. + * Safe may vary depending on the world. * * @param l Location to be checked, not null. * @return true if safe, otherwise false @@ -162,7 +162,8 @@ public boolean isSafeLocation(@NonNull Location l) { Block ground = l.getBlock().getRelative(BlockFace.DOWN); Block space1 = l.getBlock(); Block space2 = l.getBlock().getRelative(BlockFace.UP); - return checkIfSafe(l.getWorld(), ground.getType(), space1.getType(), space2.getType()); + boolean safe = checkIfSafe(l.getWorld(), ground.getType(), space1.getType(), space2.getType()); + return safe; } /** @@ -185,7 +186,8 @@ public CompletableFuture isSafeLocationAsync(@NonNull Location l) { } /** - * Check if a location is safe for teleporting + * Check if a location is safe for teleporting. + * The definition of safe can vary by world * * @param world - world * @param ground Material of the block that is going to be the ground @@ -199,10 +201,12 @@ public boolean checkIfSafe(@Nullable World world, @NonNull Material ground, @Non // Ground must be solid, space 1 and 2 must not be solid if (world == null || !ground.isSolid() || (space1.isSolid() && !Tag.SIGNS.isTagged(space1)) || (space2.isSolid() && !Tag.SIGNS.isTagged(space2))) { + BentoBox.getInstance().logDebug("Ground must be solid, space 1 and 2 must not be solid"); return false; } // Cannot be submerged or water cannot be dangerous - if (space1.equals(Material.WATER) && (space2.equals(Material.WATER) || plugin.getIWM().isWaterNotSafe(world))) { + if ((space1.equals(Material.WATER) || space2.equals(Material.WATER)) && plugin.getIWM().isWaterNotSafe(world)) { + BentoBox.getInstance().logDebug("water not safe"); return false; } // Unsafe @@ -214,6 +218,7 @@ public boolean checkIfSafe(@Nullable World world, @NonNull Material ground, @Non || Tag.CAMPFIRES.isTagged(ground) || Tag.FIRE.isTagged(ground) || Tag.FIRE.isTagged(space1) || space1.equals(Material.END_PORTAL) || space2.equals(Material.END_PORTAL) || space1.equals(Material.END_GATEWAY) || space2.equals(Material.END_GATEWAY)) { + BentoBox.getInstance().logDebug("Unsafe"); return false; } // Known unsafe blocks diff --git a/src/main/java/world/bentobox/bentobox/util/teleport/ClosestSafeSpotTeleport.java b/src/main/java/world/bentobox/bentobox/util/teleport/ClosestSafeSpotTeleport.java index 61ea184c8..98a873280 100644 --- a/src/main/java/world/bentobox/bentobox/util/teleport/ClosestSafeSpotTeleport.java +++ b/src/main/java/world/bentobox/bentobox/util/teleport/ClosestSafeSpotTeleport.java @@ -42,7 +42,7 @@ public class ClosestSafeSpotTeleport { /** - * Teleports and entity to a safe spot on island + * Teleports an entity to a safe spot on island * * @param builder - safe spot teleport builder */