Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- public class SerializedLocation
- {
- private Location location;
- private String raw;
- public SerializedLocation(String raw)
- {
- this.raw = raw;
- this.location = parseLocation(this.raw);
- }
- public SerializedLocation(World world, double x, double y, double z)
- {
- this.location = new Location(world, x, y, z);
- this.raw = serializeLocation(this.location);
- }
- public SerializedLocation(World world, double x, double y, double z, float yaw, float pitch)
- {
- this.location = new Location(world, x, y, z, yaw, pitch);
- this.raw = serializeLocation(this.location);
- }
- public SerializedLocation(Location location)
- {
- this.location = location;
- this.raw = serializeLocation(this.location);
- }
- private String serializeLocation(Location location)
- {
- if ((location.getYaw() == 0.0F) && (location.getPitch() == 0.0F)) {
- return location.getWorld().getName() + ":" + location.getX() + ":" + location.getY() + ":" + location.getBlockZ();
- }
- return location.getWorld().getName() + ":" + location.getX() + ":" + location.getY() + ":" + location.getBlockZ() + ":" + location.getYaw() + ":" + location.getPitch();
- }
- private Location parseLocation(String raw)
- {
- World world = null;
- double x = 0.0D;
- double y = 0.0D;
- double z = 0.0D;
- float yaw = 0.0F;
- float pitch = 0.0F;
- int index = -1;
- for (String s : raw.split(":")) {
- index++;
- switch (index) {
- case 0:
- world = Bukkit.getWorld(s);
- if (world == null) {
- world = (World)Bukkit.getWorlds().get(0);
- MainWrapper.instance.getLogger().warning("World '" + s + "' could not be found, setting it to '" + world.getName() + "'");
- }
- break;
- case 1:
- x = Double.parseDouble(s);
- break;
- case 2:
- y = Double.parseDouble(s);
- break;
- case 3:
- z = Double.parseDouble(s);
- break;
- case 4:
- yaw = Float.parseFloat(s);
- break;
- case 5:
- pitch = Float.parseFloat(s);
- }
- }
- if (index == 3)
- return new Location(world, x, y, z);
- if (index == 5) {
- return new Location(world, x, y, z, yaw, pitch);
- }
- return null;
- }
- public Location getLocation()
- {
- return this.location;
- }
- public String getRaw()
- {
- return this.raw;
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement