Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- public static Location deserializeLocation(Object raw) {
- if (raw == null)
- return null;
- if (raw instanceof Location)
- return (Location) raw;
- raw = raw.toString().replace("\"", "");
- final String[] parts = raw.toString().contains(", ") ? raw.toString().split(", ") : raw.toString().split(" ");
- Valid.checkBoolean(parts.length == 4 || parts.length == 6, "Expected location (String) but got " + raw.getClass().getSimpleName() + ": " + raw);
- final String world = parts[0];
- final World bukkitWorld = Bukkit.getWorld(world);
- if (bukkitWorld == null)
- throw new InvalidWorldException("Location with invalid world '" + world + "': " + raw + " (Doesn't exist)", world);
- final int x = Integer.parseInt(parts[1]), y = Integer.parseInt(parts[2]), z = Integer.parseInt(parts[3]);
- final float yaw = Float.parseFloat(parts.length == 6 ? parts[4] : "0"), pitch = Float.parseFloat(parts.length == 6 ? parts[5] : "0");
- return new Location(bukkitWorld, x, y, z, yaw, pitch);
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement