package wtf.beatrice.limbomanager.utils; import org.bukkit.Bukkit; import org.bukkit.Location; import org.bukkit.World; import org.bukkit.entity.Player; import wtf.beatrice.limbomanager.Cache; import wtf.beatrice.limbomanager.LimboManager; import wtf.beatrice.limbomanager.objects.Coordinates; import java.util.logging.Level; public class LocationUtils { public static void teleportToOwnIsland(Player player) { Location targetLocation = getPlayerSpawnLocation(player); Bukkit.getScheduler().runTask(LimboManager.getInstance(), () -> { targetLocation.getWorld().loadChunk(targetLocation.getChunk().getX(), targetLocation.getChunk().getZ(), true); player.teleport(targetLocation); }); } public static Location getPlayerSpawnLocation(Player player) { String worldName = Cache.getConfiguration().getString("island.world-name"); if(worldName == null) { LimboManager.getInstance().getLogger().log(Level.SEVERE, "World name is null!"); return null; } World spawnWorld = Bukkit.getWorld(worldName); if(spawnWorld == null) { LimboManager.getInstance().getLogger().log(Level.SEVERE, "World is null!"); return null; } String playerName = player.getName(); Coordinates coordinates = Cache.playerIslands.get(playerName); double offsetX = Cache.getConfiguration().getDouble("island.spawn-offset.x"); double y = Cache.getConfiguration().getDouble("island.spawn-offset.y"); double offsetZ = Cache.getConfiguration().getDouble("island.spawn-offset.z"); double x = coordinates.getX() + offsetX; double z = coordinates.getZ() + offsetZ; float yaw = (float) Cache.getConfiguration().getDouble("island.spawn-offset.yaw"); float pitch = (float) Cache.getConfiguration().getDouble("island.spawn-offset.pitch"); return new Location(spawnWorld, x, y, z, yaw, pitch); } }