From 4b9b6774ea86f6fdd3c4d8823d5d2350387bd9c1 Mon Sep 17 00:00:00 2001 From: tastybento Date: Sat, 27 Mar 2021 16:57:15 -0700 Subject: [PATCH] Teleport based on protection center and world height. --- .../listeners/PortalTeleportationListener.java | 6 +++--- .../util/teleport/SafeSpotTeleport.java | 17 +++++++++-------- 2 files changed, 12 insertions(+), 11 deletions(-) diff --git a/src/main/java/world/bentobox/bentobox/listeners/PortalTeleportationListener.java b/src/main/java/world/bentobox/bentobox/listeners/PortalTeleportationListener.java index d3adf07de..52cc0d3ad 100644 --- a/src/main/java/world/bentobox/bentobox/listeners/PortalTeleportationListener.java +++ b/src/main/java/world/bentobox/bentobox/listeners/PortalTeleportationListener.java @@ -279,7 +279,7 @@ public class PortalTeleportationListener implements Listener { // Find the maximum x and z corner for (; (i < x + 5) && e.getWorld().getBlockAt(i, k, z).getType().equals(Material.END_PORTAL); i++); for (; (j < z + 5) && e.getWorld().getBlockAt(x, k, j).getType().equals(Material.END_PORTAL); j++); - + // Mojang end platform generation is: // AIR // AIR @@ -422,8 +422,8 @@ public class PortalTeleportationListener implements Listener { void setSeachRadius(PlayerEntityPortalEvent e, Island i) { if (!i.onIsland(e.getFrom())) return; // Find max x or max z - int x = Math.abs(i.getCenter().getBlockX() - e.getFrom().getBlockX()); - int z = Math.abs(i.getCenter().getBlockZ() - e.getFrom().getBlockZ()); + int x = Math.abs(i.getProtectionCenter().getBlockX() - e.getFrom().getBlockX()); + int z = Math.abs(i.getProtectionCenter().getBlockZ() - e.getFrom().getBlockZ()); int diff = i.getProtectionRange() - Math.max(x, z); if (diff > 0 && diff < 128) { e.setSearchRadius(diff); diff --git a/src/main/java/world/bentobox/bentobox/util/teleport/SafeSpotTeleport.java b/src/main/java/world/bentobox/bentobox/util/teleport/SafeSpotTeleport.java index bc3c5beeb..2756e1220 100644 --- a/src/main/java/world/bentobox/bentobox/util/teleport/SafeSpotTeleport.java +++ b/src/main/java/world/bentobox/bentobox/util/teleport/SafeSpotTeleport.java @@ -34,7 +34,6 @@ public class SafeSpotTeleport { private static final int MAX_CHUNKS = 6; private static final long SPEED = 1; private static final int MAX_RADIUS = 50; - private static final int MAX_HEIGHT = 235; private boolean notChecking; private BukkitTask task; @@ -52,6 +51,7 @@ public class SafeSpotTeleport { private final Runnable runnable; private final CompletableFuture result; private final String homeName; + private final int maxHeight; /** * Teleports and entity to a safe spot on island @@ -66,12 +66,13 @@ public class SafeSpotTeleport { this.homeName = builder.getHomeName(); this.runnable = builder.getRunnable(); this.result = builder.getResult(); - - // If there is no portal scan required, try the desired location immediately - Util.getChunkAtAsync(location).thenRun(()-> tryTogo(builder.getFailureMessage())); + this.maxHeight = location.getWorld().getMaxHeight() - 20; + BentoBox.getInstance().logDebug("World = " + location.getWorld().getName() + " " + maxHeight); + // Try to go + Util.getChunkAtAsync(location).thenRun(()-> tryToGo(builder.getFailureMessage())); } - private void tryTogo(String failureMessage) { + private void tryToGo(String failureMessage) { if (plugin.getIslands().isSafeLocation(location)) { if (portal) { // If the desired location is safe, then that's where you'll go if there's no portal @@ -226,7 +227,7 @@ public class SafeSpotTeleport { for (int x = 0; x< 16; x++) { for (int z = 0; z < 16; z++) { // Work down from the entry point up - for (int y = Math.min(chunk.getHighestBlockYAt(x, z), MAX_HEIGHT); y >= 0; y--) { + for (int y = Math.min(chunk.getHighestBlockYAt(x, z), maxHeight); y >= 0; y--) { if (checkBlock(chunk, x,y,z)) { return true; } @@ -265,8 +266,8 @@ public class SafeSpotTeleport { boolean checkBlock(ChunkSnapshot chunk, int x, int y, int z) { World world = location.getWorld(); Material type = chunk.getBlockType(x, y, z); - Material space1 = chunk.getBlockType(x, Math.min(y + 1, SafeSpotTeleport.MAX_HEIGHT), z); - Material space2 = chunk.getBlockType(x, Math.min(y + 2, SafeSpotTeleport.MAX_HEIGHT), z); + Material space1 = chunk.getBlockType(x, Math.min(y + 1, maxHeight), z); + Material space2 = chunk.getBlockType(x, Math.min(y + 2, maxHeight), z); if (space1.equals(Material.NETHER_PORTAL) || space2.equals(Material.NETHER_PORTAL)) { // A portal has been found, switch to non-portal mode now portal = false;