Skip to content

Instantly share code, notes, and snippets.

@PaulBGD
Last active December 25, 2015 01:19
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save PaulBGD/6893650 to your computer and use it in GitHub Desktop.
Save PaulBGD/6893650 to your computer and use it in GitHub Desktop.
LocationUtils Resource 1
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