Advertisement
Guest User

Untitled

a guest
Oct 15th, 2018
73
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.26 KB | None | 0 0
  1. package me.port.dlteleport;
  2.  
  3. import org.bukkit.Bukkit;
  4. import org.bukkit.Location;
  5. import org.bukkit.World;
  6.  
  7. public class SerializableLocation {
  8. public static String locationToString(Location l) {
  9. if (l != null) {
  10. String w = l.getWorld().getName();
  11. double x = l.getX();
  12. double y = l.getY();
  13. double z = l.getZ();
  14. return w + "," + x + "," + y + "," + z;
  15. } else {
  16. return null;
  17. }
  18. }
  19.  
  20. public static Location stringToLocation(String s) {
  21. if (s != null) {
  22. String[] str = s.split(",");
  23. World w = Bukkit.getServer().getWorld(str[0]);
  24. double x = Double.parseDouble(str[1]);
  25. double y = Double.parseDouble(str[2]);
  26. double z = Double.parseDouble(str[3]);
  27. return new Location(w, x, y, z);
  28. } else {
  29. return null;
  30. }
  31. }
  32.  
  33. public static boolean compareLocations(Location one, Location two) {
  34. String w = one.getWorld().getName();
  35. double x = (double) one.getBlockX();
  36. double y = (double) one.getBlockY();
  37. double z = (double) one.getBlockZ();
  38. String checkw = two.getWorld().getName();
  39. double checkx = (double) two.getBlockX();
  40. double checky = (double) two.getBlockY();
  41. double checkz = (double) two.getBlockZ();
  42. return w.equalsIgnoreCase(checkw) && x == checkx && y == checky && z == checkz;
  43. }
  44. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement