Solved Retrieving Saved data out of a String

Discussion in 'Plugin Development' started by JeroenV, Dec 7, 2012.

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

    JeroenV

    Ok, I saved a string that contains a few heaps of data put together inside a list. Now I need a way to retrieve this so I can actually use the data.

    Code:
    static List<String> NodeLocation = new ArrayList<String>();
    NodeLocation.add(loc.getWorld()+","+loc.getX()+","+loc.getY()+","+loc.getZ());
    
    So I want a way to get the World, X, Y, Z out of this. How should I go about that?


    Greets,
    Jero
     
  2. Offline

    tommycake50

    do you want to have this data permanently?
    you put not much info xD.
    presuming nodelocation is a list.
    the world would be 1 in the list
    x would be 2
    etc.
    if you want it permanently use bukkit's built in snakeyaml parser.
     
  3. Offline

    JeroenV

    Yeah, I already saved it into a .yml file and everything. It's just that I need to get the data out of there, I don't want to use 4 different lists:
    Worlds(i)
    Xloc(i)
    Yloc(i)
    Zloc(i)
    Just for the sake of making my code messy, so I want to save all the data into one index of a list. So
    Code:
    loc.getWorld()+","+loc.getX()+","+loc.getY()+","+loc.getZ()
    ..is actually one string tied up together and then saved as a single string inside the list. So I wouldnd just be able to use listname(1).. or something cause that would return the full tied up string. I need to get the world(),.. out of that single string.

    Nvm, I believe I found out how to do it after googling for some time on the subject.

    For people who might need this, you can use:
    Code:
    String[] ndsplt = nodeloc.split(",");
    // ndsplt[0] = world
    // ndsplt[1] = X
    // ndsplt[2] = Y
    // ndsplt[3] = Z
    EDIT by Moderator: merged posts, please use the edit button instead of double posting.
     
    Last edited by a moderator: May 30, 2016
  4. Offline

    tommycake50

    you can just.
    Code:
    NodeLocation.set(loc.getWorld().toString()+".X", loc.getX);
    NodeLocation.set(loc.getWorld().toString()+".Y", loc.getY);
    NodeLocation.set(loc.getWorld().toString()+".Z", loc.getZ);
    and when you want to get something
    NodeLocation.get(loc.getWorld().toString() + ".X");
    etc,
     
Thread Status:
Not open for further replies.

Share This Page