mirror of
https://github.com/BentoBoxWorld/BentoBox.git
synced 2025-01-29 19:41:24 +01:00
Improved accuracy of location - string conversion.
This commit is contained in:
parent
2e1c055cd7
commit
f98c5527bc
@ -4,6 +4,7 @@ import java.io.File;
|
||||
import java.lang.reflect.Method;
|
||||
import java.lang.reflect.ParameterizedType;
|
||||
import java.lang.reflect.Type;
|
||||
import java.text.DecimalFormat;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Arrays;
|
||||
import java.util.List;
|
||||
@ -30,6 +31,7 @@ import us.tastybento.bskyblock.api.user.User;
|
||||
*/
|
||||
public class Util {
|
||||
|
||||
private static final DecimalFormat df = new DecimalFormat("#.###");
|
||||
private static String serverVersion = null;
|
||||
private static BSkyBlock plugin = BSkyBlock.getInstance();
|
||||
|
||||
@ -54,31 +56,24 @@ public class Util {
|
||||
* @return Location
|
||||
*/
|
||||
public static Location getLocationString(final String s) {
|
||||
plugin.getLogger().info("DEBUG: getting location from string");
|
||||
if (s == null || s.trim().equals("")) {
|
||||
return null;
|
||||
}
|
||||
final String[] parts = s.split(":");
|
||||
if (parts.length == 4) {
|
||||
if (parts.length == 6) {
|
||||
final World w = Bukkit.getServer().getWorld(parts[0]);
|
||||
if (w == null) {
|
||||
return null;
|
||||
}
|
||||
final int x = Integer.parseInt(parts[1]);
|
||||
final int y = Integer.parseInt(parts[2]);
|
||||
final int z = Integer.parseInt(parts[3]);
|
||||
return new Location(w, x, y, z);
|
||||
} else if (parts.length == 6) {
|
||||
final World w = Bukkit.getServer().getWorld(parts[0]);
|
||||
if (w == null) {
|
||||
return null;
|
||||
}
|
||||
final int x = Integer.parseInt(parts[1]);
|
||||
final int y = Integer.parseInt(parts[2]);
|
||||
final int z = Integer.parseInt(parts[3]);
|
||||
double x = Double.parseDouble(parts[1]);
|
||||
double y = Double.parseDouble(parts[2]);
|
||||
double z = Double.parseDouble(parts[3]);
|
||||
final float yaw = Float.intBitsToFloat(Integer.parseInt(parts[4]));
|
||||
final float pitch = Float.intBitsToFloat(Integer.parseInt(parts[5]));
|
||||
return new Location(w, x, y, z, yaw, pitch);
|
||||
}
|
||||
plugin.getLogger().info("DEBUG: not right length");
|
||||
return null;
|
||||
}
|
||||
|
||||
@ -86,14 +81,14 @@ public class Util {
|
||||
* Converts a location to a simple string representation
|
||||
* If location is null, returns empty string
|
||||
*
|
||||
* @param location - the location
|
||||
* @param l - the location
|
||||
* @return String of location
|
||||
*/
|
||||
public static String getStringLocation(final Location location) {
|
||||
if (location == null || location.getWorld() == null) {
|
||||
public static String getStringLocation(final Location l) {
|
||||
if (l == null || l.getWorld() == null) {
|
||||
return "";
|
||||
}
|
||||
return location.getWorld().getName() + ":" + location.getBlockX() + ":" + location.getBlockY() + ":" + location.getBlockZ() + ":" + Float.floatToIntBits(location.getYaw()) + ":" + Float.floatToIntBits(location.getPitch());
|
||||
return l.getWorld().getName() + ":" + df.format(l.getX()) + ":" + df.format(l.getY()) + ":" + df.format(l.getZ()) + ":" + Float.floatToIntBits(l.getYaw()) + ":" + Float.floatToIntBits(l.getPitch());
|
||||
}
|
||||
|
||||
/**
|
||||
|
Loading…
Reference in New Issue
Block a user