Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package me.port.dlteleport;
- import org.bukkit.Bukkit;
- import org.bukkit.Location;
- import org.bukkit.World;
- public class SerializableLocation {
- public static String locationToString(Location l) {
- if (l != null) {
- String w = l.getWorld().getName();
- double x = l.getX();
- double y = l.getY();
- double z = l.getZ();
- return w + "," + x + "," + y + "," + z;
- } else {
- return null;
- }
- }
- public static Location stringToLocation(String s) {
- if (s != null) {
- String[] str = s.split(",");
- World w = Bukkit.getServer().getWorld(str[0]);
- double x = Double.parseDouble(str[1]);
- double y = Double.parseDouble(str[2]);
- double z = Double.parseDouble(str[3]);
- return new Location(w, x, y, z);
- } else {
- return null;
- }
- }
- public static boolean compareLocations(Location one, Location two) {
- String w = one.getWorld().getName();
- double x = (double) one.getBlockX();
- double y = (double) one.getBlockY();
- double z = (double) one.getBlockZ();
- String checkw = two.getWorld().getName();
- double checkx = (double) two.getBlockX();
- double checky = (double) two.getBlockY();
- double checkz = (double) two.getBlockZ();
- return w.equalsIgnoreCase(checkw) && x == checkx && y == checky && z == checkz;
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement