Solved String list's in config

Discussion in 'Plugin Development' started by MAYBE, Jul 22, 2015.

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

    MAYBE

    Hello i wanted to make a game so when you do /newarena (name) it creates a few stuff in the config and also a List so like
    Code:
    TheName:
      loc:
      Players:
        - NathanGrad
        - GIoMioDio
    
    but i dont really know how i could make that without a List<String> or how i could create whole new List<String> with a name as the arena?
     
  2. Offline

    undeaD_D

    @MAYBE

    To retrieve a List from the config.yml you need that line of code:
    Code:
    List<String> list = getConfig().getStringList("TheName.Players")
    To write a List to the config.yml you could write something like this:
    Code:
    List<String> list =Arrays.asList("NathanGrad","GIoMioDio","undeaD_D");
    getConfig().set("TheName.Players", list);
    or:
    Code:
    List<String> list = new List<String>();
    list.add("NathanGrad");
    list.add("GIoMioDio");
    list.add("undeaD_D");
    getConfig().set("TheName.Players", list);
     
  3. Offline

    MAYBE

    @undeaD_D ok thanks i just wanna checka little
    so i could to always usa and create a StringList
    Code:
    List<String> list = new List<String>();
    list.add("NathanGrad");
    list.add("GIoMioDio");
    list.add("undeaD_D");
    getConfig.set("TheName.Players", list);
    
    for one and for another this:
    Code:
    list.clear(); *or how ever you clear a list*
    list.add("NathanGrad");
    list.add("GIoMioDio");
    list.add("undeaD_D");
    getConfig.set("TheName.Players2", list);
    
    and to get from one:
    Code:
    List<String> list = getConfig().getStringList("TheName.Players");
    player.sendMessage(""+list);
    
    and etc.
    and are you sure its list and no ArrayList because List<String> doesnt seem to work by me
     
  4. Offline

    undeaD_D

    Last edited: Jul 22, 2015
  5. Offline

    MAYBE

    @undeaD_D but it doesnt work to make the List<String>(); at the end it doesnt let me an error comes up when i do that can you help me please? and btw does List<Player> work?
    error msg: "Cannot instantiate the type List<String>"
     
Thread Status:
Not open for further replies.

Share This Page