Allow disabling SafeLocationCheck

This commit is contained in:
Fabrizio La Rosa 2020-07-31 23:20:47 +02:00
parent 72f468d191
commit d1fdc9217a
6 changed files with 27 additions and 22 deletions

View File

@ -1240,7 +1240,7 @@ public class IslandManager {
}
Location loc = island.getLocation(IslandWorld.Normal, IslandEnvironment.Visitor);
if (!player.getGameMode().equals(GameMode.CREATIVE) && !player.getGameMode().equals(GameMode.SPECTATOR)) {
Location safeLoc = LocationUtil.getSafeLocation(loc);
Location safeLoc = LocationUtil.getSafeLocation(plugin, loc);
if(safeLoc != null){
loc = safeLoc;
}

View File

@ -203,7 +203,7 @@ public class Move implements Listener {
if (island.hasRole(IslandRole.Member, player.getUniqueId()) || island.hasRole(IslandRole.Operator, player.getUniqueId())
|| island.hasRole(IslandRole.Owner, player.getUniqueId())) {
if (!player.getGameMode().equals(GameMode.CREATIVE) && !player.getGameMode().equals(GameMode.SPECTATOR)) {
Location safeLoc = LocationUtil.getSafeLocation(island.getLocation(world, IslandEnvironment.Main));
Location safeLoc = LocationUtil.getSafeLocation(plugin, island.getLocation(world, IslandEnvironment.Main));
if(safeLoc != null){
loc = safeLoc;
}
@ -213,7 +213,7 @@ public class Move implements Listener {
}
} else {
if (!player.getGameMode().equals(GameMode.CREATIVE) && !player.getGameMode().equals(GameMode.SPECTATOR)) {
Location safeLoc = LocationUtil.getSafeLocation(island.getLocation(world, IslandEnvironment.Visitor));
Location safeLoc = LocationUtil.getSafeLocation(plugin, island.getLocation(world, IslandEnvironment.Visitor));
if(safeLoc != null){
loc = safeLoc;
}

View File

@ -163,7 +163,7 @@ public class Portal implements Listener {
IslandWorld toWorldF = toWorld;
Bukkit.getScheduler().runTaskLater(plugin, () -> {
Location loc = island.getLocation(toWorldF, spawnEnvironment);
Location tempSafeLoc = LocationUtil.getSafeLocation(loc);
Location tempSafeLoc = LocationUtil.getSafeLocation(plugin, loc);
Location safeLoc = null;
if(tempSafeLoc != null) {
safeLoc = tempSafeLoc;

View File

@ -71,7 +71,7 @@ public class PortalPermission extends ListeningPermission {
Island island = islandManager.getIslandAtLocation(from);
Location to = island.getLocation(IslandWorld.Normal, IslandEnvironment.Main);
if(island.hasRole(IslandRole.Visitor, player.getUniqueId())){
Location safeLoc = LocationUtil.getSafeLocation(island.getLocation(IslandWorld.Normal, IslandEnvironment.Visitor));
Location safeLoc = LocationUtil.getSafeLocation(plugin, island.getLocation(IslandWorld.Normal, IslandEnvironment.Visitor));
if(safeLoc != null) {
to = safeLoc;
}

View File

@ -45,26 +45,29 @@ public final class LocationUtil {
}
}
public static @Nullable Location getSafeLocation(@Nonnull Location loc){
boolean found = false;
public static @Nullable Location getSafeLocation(SkyBlock plugin, @Nonnull Location loc){
Location locChecked = null;
if(loc.getWorld() != null){
locChecked = loc.clone();
loc.getWorld().loadChunk(loc.getWorld().getChunkAt(loc));
for(int i=loc.getBlockY(); i>=0 && !found; i--){
locChecked = locChecked.subtract(0d, 1d, 0d);
found = checkBlock(locChecked);
}
if(!found){
for(int i=loc.getBlockY(); i<256 && !found; i++){
locChecked = locChecked.add(0d, 1d, 0d);
if(plugin.getFileManager().getConfig(new File(plugin.getDataFolder(), "config.yml"))
.getFileConfiguration().getBoolean("Island.Teleport.SafetyCheck", true)) {
boolean found = false;
if(loc.getWorld() != null){
locChecked = loc.clone();
loc.getWorld().loadChunk(loc.getWorld().getChunkAt(loc));
for(int i=loc.getBlockY(); i>=0 && !found; i--){
locChecked = locChecked.subtract(0d, 1d, 0d);
found = checkBlock(locChecked);
}
}
if (found) {
locChecked = locChecked.add(0d,1d,0d);
} else {
locChecked = null;
if(!found){
for(int i=loc.getBlockY(); i<256 && !found; i++){
locChecked = locChecked.add(0d, 1d, 0d);
found = checkBlock(locChecked);
}
}
if (found) {
locChecked = locChecked.add(0d,1d,0d);
} else {
locChecked = null;
}
}
}
return locChecked;

View File

@ -359,6 +359,8 @@ Island:
# Enable or disable Fall damage
FallDamage: true
RemoveWater: true
# Check if location is safe before teleporting
SafetyCheck: true
Limits:
# Should slime split bypass limits.yml
AllowSlimeSplit: true