From ab66bad6a5f4a1835248dc05cc8f8c7dbd433611 Mon Sep 17 00:00:00 2001 From: Fabrizio La Rosa Date: Sat, 13 Jun 2020 00:03:44 +0200 Subject: [PATCH] Look for safe location before teleporting --- .../skyblock/island/IslandManager.java | 26 +++++++++++++++++-- 1 file changed, 24 insertions(+), 2 deletions(-) diff --git a/src/main/java/com/songoda/skyblock/island/IslandManager.java b/src/main/java/com/songoda/skyblock/island/IslandManager.java index 1577302e..8672b6ec 100644 --- a/src/main/java/com/songoda/skyblock/island/IslandManager.java +++ b/src/main/java/com/songoda/skyblock/island/IslandManager.java @@ -1033,8 +1033,30 @@ public class IslandManager { FileConfiguration configLoad = languageConfig.getFileConfiguration(); if (island.hasRole(IslandRole.Member, player.getUniqueId()) || island.hasRole(IslandRole.Operator, player.getUniqueId()) || island.hasRole(IslandRole.Owner, player.getUniqueId())) { - player.teleport(island.getLocation(IslandWorld.Normal, IslandEnvironment.Visitor)); - player.setFallDistance(0.0F); + boolean found = false; + Location loc = island.getLocation(IslandWorld.Normal, IslandEnvironment.Visitor); + Location locChecked = loc.clone(); + loc.getWorld().loadChunk(loc.getWorld().getChunkAt(loc)); + for(int i=loc.getBlockY(); i>=0 && !found; i--){ + locChecked.subtract(0, 1, 0); + if(!locChecked.getBlock().isEmpty() && !locChecked.getBlock().isLiquid()){ + found = true; + } + } + if(!found){ + for(int i=loc.getBlockY(); i<256 && !found; i++){ + locChecked.add(0, 1, 0); + if(!locChecked.getBlock().isEmpty() && !locChecked.getBlock().isLiquid()){ + found = true; + } + } + } + if(found){ + player.teleport(locChecked); + player.setFallDistance(0.0F); + } else { + player.sendMessage(ChatColor.translateAlternateColorCodes('&', "&cNessuna posizione sicura trovata!")); + } } else { if (scoreboardManager != null) { int islandVisitors = getVisitorsAtIsland(island).size(), islandMembers = island.getRole(IslandRole.Member).size() + island.getRole(IslandRole.Operator).size() + 1;