Solved Reading from a config.yml

Discussion in 'Plugin Development' started by Koobaczech, Feb 9, 2015.

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

    Koobaczech

    Hello. I have a config.yml with this. Im using Eclipse, and Bukkit 1.7.9-R0.2, Java 1.7
    AREA:
    List:
    - Area1
    - Area2
    - Area3
    - Area4

    I would like to do a command /arealist and have the program print out the list to a user like a loop or something
    Loop through
    p.sendMessage(ChatColor.GOLD + "IDK WHAT GOES HERE");

    I would then like to remove elements from the list, so if someone does /areadelete Area2 it will remove it from the config.yml

    Please help! Thank you. I have no idea what code to write.
     
  2. Offline

    Koobaczech

    Thank you, I've read that. I was hoping for a more in depth coded answer :p
     
  3. Online

    timtower Administrator Administrator Moderator

    @Koobaczech You get the list, loop through it, send all items to the player
     
  4. Get the list with getConfig().getStringList("Path.to.list");
     
  5. Offline

    Koobaczech

    Ok i have the list. Now how would i print the list to a players screen?? Is it
    p.sendMessage(ChatColor.GOLD + "????");
     
  6. Offline

    SuperOriginal

  7. Learn Java!! Bukkit is just an API and requires to know Java! You don't event know the basics and want to program plugins ... :confused:
     
  8. Offline

    Koobaczech

    Thank you for the help guys. I figured it out. Heres what i had to do.
    List<String> mylist= new ArrayList<String>();
    mylist = getConfig().getStringList("List.Path");
    String[] mylist2 = mylist.toArray(new String[mylist.size()]); ///This is what no one, or any other thread could tell me
    for (int listloop = 0; listloop < mylist.size(); listloop++)
    {
    p.sendMessage(mylist2[listloop]);
    }

    Anyways thanks for the help.
     
  9. Offline

    Konato_K

    @Koobaczech If you're making an Array then you could just put the array as the parameter of sendMessage
     
  10. Offline

    Koobaczech

    Thanks Konato, but i figured it out:p I just had trouble casting and stuff
     
  11. why not just
    Code:Java
    1.  
    2. for(String line : getConfig().getStringList("List.Path")) {
    3. p.sendMessage(line);
    4. }
    5.  
     
  12. Offline

    Koobaczech

    That is what i was waiting for^^^^^
     
Thread Status:
Not open for further replies.

Share This Page