Solved Converting String to Location Errors

Discussion in 'Plugin Development' started by danthonywalker, May 25, 2013.

Thread Status:
Not open for further replies.
  1. Offline

    danthonywalker

    I'm trying to change my strings back into their location variant. However, split for some reason is not working.

    Functions:
    Code:java
    1. public String locToString(Location loc)
    2. {
    3. return loc.getWorld().getName() + "|" + loc.getX() + "|" + loc.getY() + "|" + loc.getZ();
    4. }
    5.  
    6. public Location stringToLoc(String loc)
    7. {
    8. System.out.print(loc);
    9. String[] locParts = loc.split("|");
    10.  
    11. try
    12. {
    13. return new Location(Bukkit.getWorld(locParts[0]), Double.parseDouble(locParts[1]),
    14. Double.parseDouble(locParts[2]), Double.parseDouble(locParts[3]));
    15. }
    16.  
    17. {
    18. System.out.print(locParts[0]);
    19. System.out.print(locParts[1]);
    20. System.out.print(locParts[2]);
    21. System.out.print(locParts[3]);
    22. return new Location(Bukkit.getWorld("Runeterra"), 0.25, 65, 0.25);
    23. }
    24.  
    25. }


    What it's printing is the first 3 letters of the world name. Help?

    What the string it's coding looks like:
    Code:
    world|164.82972642008417|65.0|6.42774276656558
     
  2. Offline

    Lucariatias

  3. Offline

    danthonywalker

    Thank you, that fixed it.
     
Thread Status:
Not open for further replies.

Share This Page