ArrayList of Locations to String

Discussion in 'Plugin Development' started by tbrooks23, Aug 5, 2014.

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

    tbrooks23

    How would I take an ArrayList of Locations and convert them to a string, to save in a config?

    Thanks for reading/helping!
     
  2. Offline

    xXMaTTHDXx

    tbrooks23, dont save them to strings, what I would do is loop through the ArrayList of locations then save it to the string list in the config like this "- x,y,z" then when you go to get the locations, loop through the list and split the x,y,z at the ','
     
  3. Offline

    tbrooks23

    Code:java
    1. public List<Location> deserializeListLoc(List<String> s){
    2. for (int i = 0; i < s.size(); i++){
    3. String ss = s.get(i);
    4. String[] st = ss.split(",");
    5. ArrayList<Location> Spawns = new ArrayList<>();
    6. Spawns.add(new Location(Bukkit.getWorld(st[0]), Integer.parseInt(st[1]), Integer.parseInt(st[2]), Integer.parseInt(st[3])));
    7. return Spawns;
    8. }
    9. return null;
    10. }
    11.  
    12. public List<String> serializeListLoc(List<Location> s){
    13. for (int i = 0; i < s.size(); i++){
    14. Location l = s.get(i);
    15. List<String> sp = new ArrayList<>();
    16. sp.add(serializeLoc(l));
    17. return sp;
    18. }
    19. return null;
    20. }


    xXMaTTHDXx
     
Thread Status:
Not open for further replies.

Share This Page