Itemlist in config

Discussion in 'Plugin Development' started by dram, Mar 26, 2015.

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

    dram

    Hello.

    Could you show me an example to keep ItemList in configuration file?

    I mean ID:TYPE, count


    Of course I can make arrays
    [ID,type,count]
    ...
    But there is no other better option ?
     
  2. Offline

    mine-care

    @dram you can make a configuration manager class to load it from the list of strings and parse ids, datavalues ect.
    The other, better way is to use a configurationSection as so:

    items:
    ...ItemOne
    ......itemname: name
    ......itemData: data
    and so on...
     
  3. Offline

    TeddyDev

    If your wanting a list of items in config with a percentage, i usually use this method,

    Items:
    - 'ID:dataValue:rare'

    the rare works with an arrayList. for example the 'rare' is 10.
    that item will be added to the arrayList 10 times.
    then a random item will be picked from that arrayList.
    the way it works:

    Code:
                for (String items : Main.getInstance().getConfig().getStringList("Items")) {
                    String[] str = items.split(":");
                    int rare = Integer.parseInt(str[2]);
                    for (int i = 0; i < rare; i++) {
                        itemsList.add(str[0] + ":" + str[1]);
                    }
                }
    then you can get the item id/value with this,

    Code:
                    Random random = new Random();
                    int r = random.nextInt(itemsList.size());
    
                    String[] choice = itemsList.get(r).split(":");
                    player.getInventory().addItem(new ItemStack(Material.getMaterial(choice[0]), 1, Short.parseShort(choice[1])));
     
    dram likes this.
Thread Status:
Not open for further replies.

Share This Page