Advertisement
Dudemister1999

LocationStringer.java

Nov 2nd, 2014
52
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 0.95 KB | None | 0 0
  1. import org.bukkit.Bukkit;
  2. import org.bukkit.Location;
  3. import org.bukkit.World;
  4.  
  5. public class LocationStringer
  6. {
  7.     public static String format = "%world%,%x%,%y%,%z%";
  8.    
  9.     public static String toString(Location loc)
  10.     {
  11.         String location = format
  12.                 .replaceAll("%world%", loc.getWorld().getName())
  13.                 .replaceAll("%x%", String.valueOf(loc.getBlockX()))
  14.                 .replaceAll("%y%", String.valueOf(loc.getBlockY()))
  15.                 .replaceAll("%z%", String.valueOf(loc.getBlockZ()));
  16.        
  17.         return location;
  18.     }
  19.    
  20.     public static Location fromString(String loc)
  21.     {
  22.         String[] parts = loc.split(",");
  23.        
  24.         World world = Bukkit.getWorld(parts[0]);
  25.         double xPos = Double.valueOf(parts[1]);
  26.         double yPos = Double.valueOf(parts[2]);
  27.         double zPos = Double.valueOf(parts[3]);
  28.        
  29.         return new Location(world, xPos, yPos, zPos);
  30.     }
  31. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement