Advertisement
broken-arrow

Untitled

May 21st, 2021
107
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.99 KB | None | 0 0
  1. public static Location deserializeLocation(Object raw) {
  2. if (raw == null)
  3. return null;
  4.  
  5. if (raw instanceof Location)
  6. return (Location) raw;
  7.  
  8. raw = raw.toString().replace("\"", "");
  9.  
  10. final String[] parts = raw.toString().contains(", ") ? raw.toString().split(", ") : raw.toString().split(" ");
  11. Valid.checkBoolean(parts.length == 4 || parts.length == 6, "Expected location (String) but got " + raw.getClass().getSimpleName() + ": " + raw);
  12.  
  13. final String world = parts[0];
  14. final World bukkitWorld = Bukkit.getWorld(world);
  15. if (bukkitWorld == null)
  16. throw new InvalidWorldException("Location with invalid world '" + world + "': " + raw + " (Doesn't exist)", world);
  17.  
  18. final int x = Integer.parseInt(parts[1]), y = Integer.parseInt(parts[2]), z = Integer.parseInt(parts[3]);
  19. final float yaw = Float.parseFloat(parts.length == 6 ? parts[4] : "0"), pitch = Float.parseFloat(parts.length == 6 ? parts[5] : "0");
  20.  
  21. return new Location(bukkitWorld, x, y, z, yaw, pitch);
  22. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement