Skip to content

Commit

Permalink
Allow safe teleporting to in water
Browse files Browse the repository at this point in the history
  • Loading branch information
tastybento committed Jan 20, 2025
1 parent 6d2e729 commit 4ff0e8a
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 6 deletions.
15 changes: 10 additions & 5 deletions src/main/java/world/bentobox/bentobox/managers/IslandsManager.java
Original file line number Diff line number Diff line change
Expand Up @@ -152,8 +152,8 @@ public void setHandler(@NonNull Database<Island> 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
Expand All @@ -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;
}

/**
Expand All @@ -185,7 +186,8 @@ public CompletableFuture<Boolean> 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
Expand All @@ -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
Expand All @@ -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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
*/
Expand Down

0 comments on commit 4ff0e8a

Please sign in to comment.