AlanGomes

Untitled

Mar 24th, 2015
244
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 1.10 KB | None | 0 0
  1. public static String serializeLocation(Location l) {
  2.         String s = "";
  3.         s += "@w;" + l.getWorld().getName();
  4.         s += ":@x;" + l.getBlockX();
  5.         s += ":@y;" + l.getBlockY();
  6.         s += ":@z;" + l.getBlockZ();
  7.         s += ":@p;" + l.getPitch();
  8.         s += ":@ya;" + l.getYaw();
  9.         return s;
  10.     }
  11.     public static Location deserializeLocation(String s) {
  12.         try {
  13.             Location l = new Location(Bukkit.getWorlds().get(0), 0, 0, 0);
  14.             String[] att = s.split(":");
  15.             for (String attribute : att) {
  16.                 String[] split = attribute.split(";");
  17.                 if (split[0].equalsIgnoreCase("@w"))
  18.                     l.setWorld(Bukkit.getWorld(split[1]));
  19.                 if (split[0].equalsIgnoreCase("@x"))
  20.                     l.setX(Double.parseDouble(split[1]));
  21.                 if (split[0].equalsIgnoreCase("@y"))
  22.                     l.setY(Double.parseDouble(split[1]));
  23.                 if (split[0].equalsIgnoreCase("@z"))
  24.                     l.setZ(Double.parseDouble(split[1]));
  25.                 if (split[0].equalsIgnoreCase("@p"))
  26.                     l.setPitch(Float.parseFloat(split[1]));
  27.                 if (split[0].equalsIgnoreCase("@ya"))
  28.                     l.setYaw(Float.parseFloat(split[1]));
  29.  
  30.             }
  31.             return l;
  32.         } catch (Exception e) {
  33.             return null;
  34.         }
  35.     }
Advertisement
Add Comment
Please, Sign In to add comment