1.14.4 How would I (for example) get the 4th item from a ConfigurationSection?

Discussion in 'Spigot Plugin Development' started by PartyMC, Mar 27, 2020.

  1. So I'm currently making a GUI where it makes items from a file. Which all works. But those items also have a certain warp connected to them, which I want to activate when they click. In the file where I add my items for the GUI one of the things I define is the warp. But I'm having struggles with activating those warps. My guess was when you click on the first slot, it would get the warp string from the first item, etc. But how can I make it so that it gets a certain item from a ConfigurationSection? And how would I also get a string located under that item?
  2. Hello,

    I think the best solution would be to create a Map<Integer, Whatever>, where the integer is the slot of your GUI:

    - When loading your GUI, you load the datas into your map (the slot, the object you need...)
    - When player click on the slot in your inventory, you can get your Whatever object (can be a String, your ConfigurationSection, or.. Whatever. :)).
    #2 Andross, Mar 27, 2020
    Last edited: Mar 27, 2020
  3. You don't (or at least should not) get values from configurations via indexes (numerics).
    Configurations use keys to identify their values - yes, while these -can- be numbers, they are in fact handled as String inside configuration context.

    So if you really need numeric keys for your values (which is still legit):
    Code (Text):
    // Pseudo code
    config.set(index, value)

    value = config.get(index)
    This creates your value under the index key you use (e.g. if you use index 4, it would be "4: <your value>").
  4. Code (Text):
        displayname: Volvara
        type: Axis Coaster
        warp: volvara
        material: diamond_sword
        ridecounterName: volvara
        status: open
        damage: 1
        displayname: Remnant
        type: Launch Coaster
        warp: remnant
        material: diamond_sword
        ridecounterName: remnant
        status: open
        damage: 2
        description: Visit the ruins of the old city of Vasgar
    So this is the file im getting the data from. As you can see it contains those 'warp' strings. I want to make it so that when I click the first slot, it gets the warp from 'volvara' and when I press the second it gets the warp from 'remnant'. How would I do this using the Map technique? I dont really understand that technique, but I'm still doing research to it.
  5. https://hub.spigotmc.org/javadocs/s...on/ConfigurationSection.html#getKeys-boolean-
    Will return you the set of keys for your configuration section (in your case the "rides" configuration section) which you can use for that but since it returns a set you'll have to convert it first if you really want to access entries index based (based on the clicked slot number). It would probably be better to just store the associated warps in a map when the plugin (re)loads as already mentioned before.