mirror of
https://github.com/songoda/FabledSkyBlock.git
synced 2024-11-24 03:05:56 +01:00
Improved location safety check
This commit is contained in:
parent
336d5bf067
commit
cb2570b1ad
@ -1035,9 +1035,9 @@ public class IslandManager {
|
|||||||
FileConfiguration configLoad = languageConfig.getFileConfiguration();
|
FileConfiguration configLoad = languageConfig.getFileConfiguration();
|
||||||
|
|
||||||
if (island.hasRole(IslandRole.Member, player.getUniqueId()) || island.hasRole(IslandRole.Operator, player.getUniqueId()) || island.hasRole(IslandRole.Owner, player.getUniqueId())) {
|
if (island.hasRole(IslandRole.Member, player.getUniqueId()) || island.hasRole(IslandRole.Operator, player.getUniqueId()) || island.hasRole(IslandRole.Owner, player.getUniqueId())) {
|
||||||
Location loc = LocationUtil.getSafeLocation(island.getLocation(IslandWorld.Normal, IslandEnvironment.Visitor));
|
Location loc = island.getLocation(IslandWorld.Normal, IslandEnvironment.Main);
|
||||||
if(loc != null){
|
if(loc != null){
|
||||||
player.teleport(loc.add(0d,1d,0d));
|
player.teleport(loc);
|
||||||
if(!configLoad.getBoolean("Island.Teleport.FallDamage")){
|
if(!configLoad.getBoolean("Island.Teleport.FallDamage")){
|
||||||
player.setFallDistance(0.0F);
|
player.setFallDistance(0.0F);
|
||||||
}
|
}
|
||||||
@ -1072,7 +1072,15 @@ public class IslandManager {
|
|||||||
}
|
}
|
||||||
|
|
||||||
Bukkit.getServer().getScheduler().runTask(skyblock, () -> {
|
Bukkit.getServer().getScheduler().runTask(skyblock, () -> {
|
||||||
player.teleport(island.getLocation(IslandWorld.Normal, IslandEnvironment.Visitor));
|
Location loc = LocationUtil.getSafeLocation(island.getLocation(IslandWorld.Normal, IslandEnvironment.Visitor));
|
||||||
|
if(loc != null){
|
||||||
|
player.teleport(loc);
|
||||||
|
if(!configLoad.getBoolean("Island.Teleport.FallDamage")){
|
||||||
|
player.setFallDistance(0.0F);
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
player.sendMessage(ChatColor.translateAlternateColorCodes('&', "&cNessuna posizione sicura trovata!")); // TODO: Use language.yml
|
||||||
|
}
|
||||||
if(!configLoad.getBoolean("Island.Teleport.FallDamage")){
|
if(!configLoad.getBoolean("Island.Teleport.FallDamage")){
|
||||||
player.setFallDistance(0.0F);
|
player.setFallDistance(0.0F);
|
||||||
}
|
}
|
||||||
|
@ -31,30 +31,66 @@ public final class LocationUtil {
|
|||||||
loc.getWorld().loadChunk(loc.getWorld().getChunkAt(loc));
|
loc.getWorld().loadChunk(loc.getWorld().getChunkAt(loc));
|
||||||
for(int i=loc.getBlockY(); i>=0 && !found; i--){
|
for(int i=loc.getBlockY(); i>=0 && !found; i--){
|
||||||
locChecked = locChecked.subtract(0d, 1d, 0d);
|
locChecked = locChecked.subtract(0d, 1d, 0d);
|
||||||
if(!locChecked.getBlock().isEmpty() &&
|
found = checkBlock(locChecked);
|
||||||
!locChecked.getBlock().isLiquid() &&
|
|
||||||
locChecked.add(0d,1d,0d).getBlock().isEmpty() &&
|
|
||||||
locChecked.add(0d,2d,0d).getBlock().isEmpty()){
|
|
||||||
found = true;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
if(!found){
|
if(!found){
|
||||||
for(int i=loc.getBlockY(); i<256 && !found; i++){
|
for(int i=loc.getBlockY(); i<256 && !found; i++){
|
||||||
locChecked = locChecked.add(0d, 1d, 0d);
|
locChecked = locChecked.add(0d, 1d, 0d);
|
||||||
if(!locChecked.getBlock().isEmpty() &&
|
found = checkBlock(locChecked);
|
||||||
!locChecked.getBlock().isLiquid() &&
|
|
||||||
locChecked.add(0d,1d,0d).getBlock().isEmpty() &&
|
|
||||||
locChecked.add(0d,2d,0d).getBlock().isEmpty()){
|
|
||||||
found = true;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
if (found) {
|
||||||
if(!found){
|
locChecked = locChecked.add(0d,1d,0d);
|
||||||
|
} else {
|
||||||
locChecked = null;
|
locChecked = null;
|
||||||
}
|
}
|
||||||
return locChecked;
|
return locChecked;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private static boolean checkBlock(Location locChecked) {
|
||||||
|
boolean safe = false;
|
||||||
|
if(!locChecked.getBlock().isEmpty() &&
|
||||||
|
!locChecked.getBlock().isLiquid() &&
|
||||||
|
!locChecked.getBlock().isPassable() &&
|
||||||
|
locChecked.getBlock().getType().isSolid() &&
|
||||||
|
locChecked.getBlock().getType().isBlock() &&
|
||||||
|
locChecked.add(0d,1d,0d).getBlock().getType().isAir() &&
|
||||||
|
locChecked.add(0d,2d,0d).getBlock().getType().isAir()){
|
||||||
|
safe = true;
|
||||||
|
switch(locChecked.getBlock().getType()){
|
||||||
|
case ACACIA_BUTTON:
|
||||||
|
case ACACIA_DOOR:
|
||||||
|
case ACACIA_FENCE_GATE:
|
||||||
|
case ACACIA_TRAPDOOR:
|
||||||
|
case BIRCH_DOOR:
|
||||||
|
case BIRCH_FENCE_GATE:
|
||||||
|
case BIRCH_TRAPDOOR:
|
||||||
|
case CACTUS:
|
||||||
|
case CAKE:
|
||||||
|
case CAMPFIRE:
|
||||||
|
case COBWEB:
|
||||||
|
case DARK_OAK_DOOR:
|
||||||
|
case DARK_OAK_FENCE_GATE:
|
||||||
|
case DARK_OAK_TRAPDOOR:
|
||||||
|
case IRON_TRAPDOOR:
|
||||||
|
case JUNGLE_DOOR:
|
||||||
|
case JUNGLE_FENCE_GATE:
|
||||||
|
case JUNGLE_TRAPDOOR:
|
||||||
|
case LADDER:
|
||||||
|
case MAGMA_BLOCK:
|
||||||
|
case NETHER_PORTAL:
|
||||||
|
case OAK_DOOR:
|
||||||
|
case OAK_FENCE_GATE:
|
||||||
|
case SPRUCE_DOOR:
|
||||||
|
case SPRUCE_FENCE_GATE:
|
||||||
|
safe = false;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return safe;
|
||||||
|
}
|
||||||
|
|
||||||
public static boolean isLocationLocation(Location location1, Location location2) {
|
public static boolean isLocationLocation(Location location1, Location location2) {
|
||||||
return location1.getBlockX() == location2.getBlockX() && location1.getBlockY() == location2.getBlockY() && location1.getBlockZ() == location2.getBlockZ();
|
return location1.getBlockX() == location2.getBlockX() && location1.getBlockY() == location2.getBlockY() && location1.getBlockZ() == location2.getBlockZ();
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user