Solved ArrayList In Config

Discussion in 'Plugin Development' started by Jumb_1907, Mar 26, 2017.

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

    Jumb_1907

    hey,

    I'm making a prisons plugin (I know no one is waiting for this but I had some free time so yeah...)
    and i'm saving locations in my config. How can I get a <Location> array list that I can get from my config file?
    Thank you
     
  2. Offline

    mine-care

    @Jumb_1907 You will have to think of a format that will allow you to turn a location to String and a String back to a location, and then save the Strings to config.
    An acceptable format would be 'worldname,x,y,z,yaw,pich' so you need a way to turn the location to this format, save it and then load it back and turn the string to a location ;)
     
  3. Offline

    Jumb_1907

    This is what I'm asking for, How the hell do I do this. I've been thinking about this for almost a week and I can't find a solution. Please help :/
     
  4. Offline

    mine-care

    @Jumb_1907
    Soooo Lets take it step by step...
    The string format is going to be: "WorldName,x,y,z,yaw,pich"
    so to turn a location to that string its pretty simple:
    Code:
    Location LOC = ...
    String STR = LOC.world.name+","+LOC.intX+","+LOC.intY+","+LOC.intZ+","+LOC.yaw+","+LOC.pitch
    //Add it to the String list. 
    //Once you are done, save the String list to config ;)
    
    And to turn the String from that format into a location is also simple:
    Code:
    Array of <String> STR = stringFromConfig#split(",");
    World W = Bukkit#getWorld(STR[0]);
    Int X = parseInt(STR[1])
    Int Y = parseInt(STR[2])
    Int Z = parseInt(STR[3])
    Float YAW = parseFloat(STR[4]);
    Float PITCH = parseFloat(STR[5]);
    Location LOC = Location(W,X,Y,Z,YAW,PICH);
    //There you have it!
    
    So by reading the pseudocode above you should be able to figure it ;)
    Feel free to ask any question.
     
    Jumb_1907 likes this.
  5. Offline

    Jumb_1907

    You . . . Are . . . The . . . Best . . . @mine-care
     
    mine-care likes this.
  6. Offline

    mine-care

    @Jumb_1907 xD Hahaha
    I . . . Dont . . . Think . . . I . . . Am . . . @Jumb_1907
    Thanks though :- ) Happy i helped!
     
Thread Status:
Not open for further replies.

Share This Page