Solved Config problem

Discussion in 'Spigot Plugin Development' started by Havooc, Dec 28, 2019.

  1. Okay, so this time I want to make a command, that will add new item to config.

    Code (YAML):

    GUI
    :
      name
    :
        enabled
    : true
        rows
    : 5
        GUI-name
    : GUI Name
        items
    :
          1
    :
            block
    : ITEM
            amount
    : AMOUNT
            slot
    : SLOT
            displayName
    : DNAME
            lore
    : LORE
            enabled
    : true
     
    I want to make command that will check how many items there are in the config and add item with +1. So for example if i have items: 1: <...>, 2: <...>, 3:<...> after typing /gui add it will make 4: <...>.
     
  2. well... check if "gui.name.items.1" exists, if it does, set a counter to 1, then recursively do that until it returns the highest count.
     
  3. I would just add a "gui.name.size" value. It's more efficient than iteratively trying to find the last number.
     
  4. Hello @Havooc ,

    You can just get the number of element in the configuration section and add one
    Code (Java):
    getConfig().getConfigurationSection("GUI.items").getKeys(false).size()+1
    Hope it's help !

    LouShunt
     
    • Winner Winner x 2
  5. Utilizing configuration section in detail means you can either loop through the strings and convert them to a integer and then increase the number for the next slot or just go off the size and increase by one setting it as that slot.