Set items in GUI by Items in Config

Discussion in 'Plugin Development' started by S1ant, Sep 26, 2017.

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

    S1ant

    I don't get how you'd get the items in the config and put them into a GUI, I'm not good at for loops, so I'd need some help.
     
  2. Can you show what the config looks like
     
  3. Offline

    S1ant

    Well I haven't made it but I'd like it to look like:
    Code:
    GUI:
    - Clay, 2
    - Apple, 4
    - Glass, 40
    
     
  4. Are the numbers amounts or the slot numbers. Sorry for late replies im at work and get breaks every 2hrs i go home soon
     
  5. Offline

    Minesuchtiiii

    I guess it's something like Material.getMaterial(ConfigString);
     
  6. Offline

    S1ant

    They are slots for in the Inventory, I'll just subtract one from those and get the actual slot.

    Haha, funny.
     
  7. i would change the config to look like this
    Code:
    GUI:
      APPLE:
        slot: 0
      CLAY:
        slot: 2
    etc...
    to use the for loop i would do
    for(String m : config.getConfigurationSection("GUI").getKeys(false)
    {

    }
    what this will do is return CLAY, APPLE, etc p.s i would change all of them to uppercase ill tell you why
    then you can do inside that loop is
    Material mat = Material.getMaterial(m);
    then create an itemstack from that doing
    ItemStack item = new ItemStack(mat);
    then get the inventory and do
    inv.setItem(config.get(m + ".slot"), item);
     
  8. Offline

    Caderape2

    @S1ant Would be better to put the slot as key. When you loop the configuration section, you just have to parseint the string.
     
  9. Offline

    Minesuchtiiii

    What's so funny?
     
  10. Offline

    Reflxction

    @S1ant what Minesuchtiiii mentioned above is right. It should be like this:
    Code:
    Material yourmaterial = Material.getMaterial(getConfig().yourstuffs);
    ItemStack yourstack = new ItemStack(yourmaterial);
    yourinventory.setItem(slot, yourstack);
    sorry for the bad formatting, it wasn't written in the development enviroment
     
    Minesuchtiiii likes this.
  11. Offline

    S1ant

    EWait material for an item in game. oh..
     
  12. Offline

    Minesuchtiiii

    Just look at what @xTechno_ wrote before.
     
    2 people like this.
  13. Offline

    S1ant

    Ok, I will see about this when I get home from school.
     
Thread Status:
Not open for further replies.

Share This Page