diff --git a/src/main/java/com/songoda/skyblock/command/commands/island/TeleportCommand.java b/src/main/java/com/songoda/skyblock/command/commands/island/TeleportCommand.java index a499fdf4..4e4f3dd6 100644 --- a/src/main/java/com/songoda/skyblock/command/commands/island/TeleportCommand.java +++ b/src/main/java/com/songoda/skyblock/command/commands/island/TeleportCommand.java @@ -11,9 +11,13 @@ import com.songoda.skyblock.message.MessageManager; import com.songoda.skyblock.playerdata.PlayerDataManager; import com.songoda.skyblock.sound.SoundManager; import com.songoda.skyblock.utils.player.OfflinePlayer; +import com.songoda.skyblock.utils.world.LocationUtil; import com.songoda.skyblock.visit.Visit; import com.songoda.skyblock.visit.VisitManager; import org.bukkit.Bukkit; +import org.bukkit.Location; +import org.bukkit.Material; +import org.bukkit.block.data.Waterlogged; import org.bukkit.command.ConsoleCommandSender; import org.bukkit.configuration.file.FileConfiguration; import org.bukkit.entity.Player; @@ -105,7 +109,19 @@ public class TeleportCommand extends SubCommand { soundManager.playSound(player, CompatibleSound.ENTITY_ENDERMAN_TELEPORT.getSound(), 1.0F, 1.0F); Bukkit.getServer().getScheduler().runTask(skyblock, () -> { - player.teleport(island.getLocation(IslandWorld.Normal, IslandEnvironment.Main)); + Location loc = island.getLocation(IslandWorld.Normal, IslandEnvironment.Main); + if(skyblock.getFileManager().getConfig(new File(skyblock.getDataFolder(), "config.yml")) + .getFileConfiguration().getBoolean("Island.Teleport.RemoveWater", false)){ + Location tempLoc = LocationUtil.getDefinitiveLocation(loc); + if(tempLoc.getBlock().getType().equals(Material.WATER)){ + tempLoc.getBlock().setType(Material.AIR); + } else if(tempLoc.getBlock().getBlockData() instanceof Waterlogged){ + Waterlogged blockData = (Waterlogged) tempLoc.getBlock().getBlockData(); + blockData.setWaterlogged(false); + tempLoc.getBlock().setBlockData(blockData); + } + } + player.teleport(loc); if(!configLoad.getBoolean("Island.Teleport.FallDamage", true)){ player.setFallDistance(0.0F); diff --git a/src/main/java/com/songoda/skyblock/island/IslandManager.java b/src/main/java/com/songoda/skyblock/island/IslandManager.java index 687240fc..8c07e35e 100644 --- a/src/main/java/com/songoda/skyblock/island/IslandManager.java +++ b/src/main/java/com/songoda/skyblock/island/IslandManager.java @@ -1061,7 +1061,9 @@ public class IslandManager { player.setFallDistance(0.0F); } } else { - player.sendMessage(ChatColor.translateAlternateColorCodes('&', "&cNessuna posizione sicura trovata!")); // TODO: Use language.yml + player.sendMessage(ChatColor.translateAlternateColorCodes('&', + Objects.requireNonNull(skyblock.getFileManager().getConfig(new File(skyblock.getDataFolder(), "language.yml")) + .getFileConfiguration().getString("Island.Teleport.Unsafe.Message")))); } } else { if (scoreboardManager != null) { @@ -1099,7 +1101,9 @@ public class IslandManager { player.setFallDistance(0.0F); } } else { - player.sendMessage(ChatColor.translateAlternateColorCodes('&', "&cNessuna posizione sicura trovata!")); // TODO: Use language.yml + player.sendMessage(ChatColor.translateAlternateColorCodes('&', + Objects.requireNonNull(skyblock.getFileManager().getConfig(new File(skyblock.getDataFolder(), "language.yml")) + .getFileConfiguration().getString("Island.Teleport.Unsafe.Message")))); } if(!configLoad.getBoolean("Island.Teleport.FallDamage", true)){ player.setFallDistance(0.0F); diff --git a/src/main/java/com/songoda/skyblock/listeners/Move.java b/src/main/java/com/songoda/skyblock/listeners/Move.java index 11526bf7..87b016ff 100644 --- a/src/main/java/com/songoda/skyblock/listeners/Move.java +++ b/src/main/java/com/songoda/skyblock/listeners/Move.java @@ -13,11 +13,9 @@ import com.songoda.skyblock.sound.SoundManager; import com.songoda.skyblock.utils.version.NMSUtil; import com.songoda.skyblock.utils.world.LocationUtil; import com.songoda.skyblock.world.WorldManager; -import org.bukkit.Bukkit; -import org.bukkit.ChatColor; -import org.bukkit.GameMode; -import org.bukkit.Location; +import org.bukkit.*; import org.bukkit.attribute.Attribute; +import org.bukkit.block.data.Waterlogged; import org.bukkit.configuration.file.FileConfiguration; import org.bukkit.entity.Player; import org.bukkit.event.EventHandler; @@ -194,6 +192,17 @@ public class Move implements Listener { loc = LocationUtil.getSafeLocation(island.getLocation(world, IslandEnvironment.Main)); } else { loc = island.getLocation(world, IslandEnvironment.Main); + if(skyblock.getFileManager().getConfig(new File(skyblock.getDataFolder(), "config.yml")) + .getFileConfiguration().getBoolean("Island.Teleport.RemoveWater", false)){ + Location tempLoc = LocationUtil.getDefinitiveLocation(loc); + if(tempLoc.getBlock().getType().equals(Material.WATER)){ + tempLoc.getBlock().setType(Material.AIR); + } else if(tempLoc.getBlock().getBlockData() instanceof Waterlogged){ + Waterlogged blockData = (Waterlogged) tempLoc.getBlock().getBlockData(); + blockData.setWaterlogged(false); + tempLoc.getBlock().setBlockData(blockData); + } + } } } else { if (!player.getGameMode().equals(GameMode.CREATIVE) && !player.getGameMode().equals(GameMode.SPECTATOR)) { @@ -206,7 +215,9 @@ public class Move implements Listener { player.teleport(loc); } else { LocationUtil.teleportPlayerToSpawn(player); - player.sendMessage(ChatColor.translateAlternateColorCodes('&', "&cNessuna posizione sicura trovata!")); // TODO: Use language.yml + player.sendMessage(ChatColor.translateAlternateColorCodes('&', + Objects.requireNonNull(skyblock.getFileManager().getConfig(new File(skyblock.getDataFolder(), "language.yml")) + .getFileConfiguration().getString("Command.Island.Teleport.Unsafe.Message")))); } } diff --git a/src/main/java/com/songoda/skyblock/utils/world/LocationUtil.java b/src/main/java/com/songoda/skyblock/utils/world/LocationUtil.java index 5875b2e5..3bb79355 100644 --- a/src/main/java/com/songoda/skyblock/utils/world/LocationUtil.java +++ b/src/main/java/com/songoda/skyblock/utils/world/LocationUtil.java @@ -15,6 +15,7 @@ import org.bukkit.*; import org.bukkit.World.Environment; import org.bukkit.block.Block; import org.bukkit.block.BlockFace; +import org.bukkit.block.data.Waterlogged; import org.bukkit.entity.Player; import java.io.File; @@ -47,6 +48,19 @@ public final class LocationUtil { return locChecked; } + public static Location getDefinitiveLocation(Location loc){ + Location locWorking = loc.clone(); + for(int i=locWorking.getBlockY(); i>=0; i--){ + if(!locWorking.getBlock().isEmpty()){ + if(locWorking.getBlock().getType().equals(Material.WATER) || locWorking.getBlock().getBlockData() instanceof Waterlogged){ + loc = locWorking; + } + break; + } + } + return loc; + } + private static boolean checkBlock(Location locChecked) { boolean safe = false; if(!locChecked.getBlock().isEmpty() && diff --git a/src/main/resources/config.yml b/src/main/resources/config.yml index c89840a9..4c74c96a 100644 --- a/src/main/resources/config.yml +++ b/src/main/resources/config.yml @@ -317,6 +317,7 @@ Island: Teleport: # Enable or disable Fall damage FallDamage: true + RemoveWater: true Limits: # Should slime split bypass limits.yml AllowSlimeSplit: true diff --git a/src/main/resources/language.yml b/src/main/resources/language.yml index 7a63ec40..e4a499e3 100644 --- a/src/main/resources/language.yml +++ b/src/main/resources/language.yml @@ -905,6 +905,8 @@ Command: Message: '&bSkyBlock &8| &aInfo&8: &eYou have been teleported to your Island.' Other: Message: '&bSkyBlock &8| &aInfo&8: &eYou have been teleported to &a%player''s &eIsland.' + Unsafe: + Message: '&bSkyBlock &8| &cError&8: &eNo safe position found' Create: Owner: Message: '&bSkyBlock &8| &cError&8: &eYou are already an Island Owner.'