getStringList() and semicolons

Discussion in 'Plugin Development' started by Superckl1, Mar 24, 2013.

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

    Superckl1

    Sorry about the title, I meant colon :p

    Hey everyone,

    I'm having something strange happening with me configuration. When calling getStringList() on this list:
    Code:
      - 657:2
      - 383:1
      - 263:1
      - 323
      - 17:1
    and then iterating through the list, I get this:
    [​IMG]
    It seems like the colons are screwing up the getStringList() somehow. Does anyone know why this is happening and a way to fix it? (I'd prefer to not use a different symbol)
     
  2. Offline

    skipperguy12

    Show us code used for looping, and how you're getting the list.

    Code:
    String id = "122:5";
    String[] splits = id.split(":");
    for(String s: id){
    System.out.println(s);
    }
    Out Put
    122
    5

    What i'd do is use an advanced for loop, loop through the list which contains the items and ids, split each one and follow up with your code.

    How do you turn an ID into a block anyways?

    EDIT by Moderator: merged posts, please use the edit button instead of double posting.
     
    Last edited by a moderator: May 31, 2016
  3. Offline

    Superckl1

    Here's my code:
    Code:
    for(String wname:worldnames){
                        String path = "Disable Item In Inventory.".concat(wname);
                        if(this.getConfig().contains(path)){
                            List<String> ids = this.getConfig().getStringList(path);
                            for(String id:ids){
                                Bukkit.broadcastMessage(id);
                            }
                            inventory.put(wname, ids);
                            Bukkit.broadcastMessage(wname);
                        }
                    }
    worldnames is a predefined list of world names (duh).
     
  4. Offline

    fireblast709

    it is because YAML does not really see the : in the String list. Put '' around your Strings, so like
    Code:
    list:
      - 'key:val'
      - 'key2:val'
    and it will be read properly
     
  5. Offline

    Superckl1

    Love you <3
     
Thread Status:
Not open for further replies.

Share This Page