Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- public static String serializeLocation(Location l) {
- String s = "";
- s += "@w;" + l.getWorld().getName();
- s += ":@x;" + l.getBlockX();
- s += ":@y;" + l.getBlockY();
- s += ":@z;" + l.getBlockZ();
- s += ":@p;" + l.getPitch();
- s += ":@ya;" + l.getYaw();
- return s;
- }
- public static Location deserializeLocation(String s) {
- try {
- Location l = new Location(Bukkit.getWorlds().get(0), 0, 0, 0);
- String[] att = s.split(":");
- for (String attribute : att) {
- String[] split = attribute.split(";");
- if (split[0].equalsIgnoreCase("@w"))
- l.setWorld(Bukkit.getWorld(split[1]));
- if (split[0].equalsIgnoreCase("@x"))
- l.setX(Double.parseDouble(split[1]));
- if (split[0].equalsIgnoreCase("@y"))
- l.setY(Double.parseDouble(split[1]));
- if (split[0].equalsIgnoreCase("@z"))
- l.setZ(Double.parseDouble(split[1]));
- if (split[0].equalsIgnoreCase("@p"))
- l.setPitch(Float.parseFloat(split[1]));
- if (split[0].equalsIgnoreCase("@ya"))
- l.setYaw(Float.parseFloat(split[1]));
- }
- return l;
- } catch (Exception e) {
- return null;
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment