Solved Getting each string in a list in a config

Discussion in 'Plugin Development' started by kampai, Jul 10, 2016.

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

    kampai

    I'm currently making a kit plugin and in a config, I need to get a list of strings one by one. What I'm currently trying to do is get the list of strings one by one then set them to the display name of three different blocks. What I'm currently using for the loop
    Code:
    int listsize = config.get().getList("kits").size();
    for(int i = 0; i < listsize;i++) {
                kits.setItem(i, new ItemStack(Material.EMERALD_BLOCK, 1));
    
            }
    And what I'm using to get the list.
    Code:
            String kitlist = config.get().getList("kits").toString();
    
    I think the way I'm doing it, you would check the string and remove any "[", "]" and "," then check for a space and separate the string, but I'm not exactly sure how I would be able to do that.

    EDIT: Solved sorry I found out about getStringList I was stupid I didnt know about this. For anyone wondering how I achieved this, this is what I did.
    Code:
            int listsize = config.get().getList("kits").size();
            ItemStack kitblock = new ItemStack(Material.EMERALD_BLOCK, 1);
            ItemMeta kitblockim = kitblock.getItemMeta();
    
            for(int i = 0; i < listsize;i++) {
               
                String kitname = config.get().getStringList("kits").get(i);
                kitblockim.setDisplayName(ChatColor.GREEN + kitname + "");
                kitblock.setItemMeta(kitblockim);
               
                kits.setItem(i, kitblock);
    
            }
     
    Last edited: Jul 10, 2016
  2. Offline

    ArsenArsen

    Code:
    for(String s : config.getStringList(PaTh)){
    Code here, the current string is s
    }
    There's no need need to join it and then split it again.
     
Thread Status:
Not open for further replies.

Share This Page