Last active
December 25, 2015 01:19
-
-
Save PaulBGD/6893650 to your computer and use it in GitHub Desktop.
LocationUtils Resource 1
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package me.ultimate.Arena; | |
import org.bukkit.Bukkit; | |
import org.bukkit.Location; | |
import org.bukkit.World; | |
public class LocationUtils { | |
public static String fromLocation(Location l, boolean block, boolean yp) { | |
String world = l.getWorld().getName(); | |
double x = l.getX(); | |
double y = l.getY(); | |
double z = l.getZ(); | |
double yaw = l.getYaw(); | |
double pitch = l.getPitch(); | |
if (block) { | |
x = l.getBlockX(); | |
y = l.getBlockY(); | |
z = l.getBlockZ(); | |
} | |
String f = world + ";" + x + ";" + y + ";" + z; | |
if (yp) { | |
f += ";" + yaw + ";" + pitch; | |
} | |
return f; | |
} | |
public static Location toLocation(String s) { | |
String[] fi = s.split(";"); | |
World w = Bukkit.getWorld(fi[0]); | |
double x = Double.parseDouble(fi[1]); | |
double y = Double.parseDouble(fi[2]); | |
double z = Double.parseDouble(fi[3]); | |
if (fi.length == 6) { | |
return new Location(w, x, y, z, Float.parseFloat(fi[4]), Float.parseFloat(fi[5])); | |
} | |
return new Location(w, x, y, z); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment