Location util
package fr.hugo4715.paytoprotect.utils;
import org.bukkit.Bukkit;
import org.bukkit.Location;
public class LocationUtils {
public static org.bukkit.Location toBlockLocation(org.bukkit.Location l){
return l.getBlock().getLocation().add(0.5, 0, 0.5);
}
public static String toString(Location l, boolean usePitchAndYaw){
if(!usePitchAndYaw){
return new String(l.getWorld().getName() + "," + l.getX() + "," + l.getY() + "," + l.getZ());
}
return new String(l.getWorld().getName() + "," + l.getX() + "," + l.getY() + "," + l.getZ() + "," + l.getPitch() + "," + l.getYaw());
}
public static Location fromString(String s){
String[] i = s.split(",");
if(i.length == 4){
return new Location(Bukkit.getWorld(i[0]),Double.valueOf(i[1]),Double.valueOf(i[2]),Double.valueOf(i[3]));
}else if(i.length == 6){
return new Location(Bukkit.getWorld(i[0]),Double.valueOf(i[1]),Double.valueOf(i[2]),Double.valueOf(i[3]),Float.valueOf(i[4]),Float.valueOf(i[5]));
}
return null;
}
public static String toReadableString(Location l){
return " " + l.getX() + " / " + l.getY() + " / " + l.getZ();
}
}