Get all items from the config

Discussion in 'Spigot Plugin Development' started by Teh_Matt_GRyt, May 28, 2018.

Thread Status:
Not open for further replies.
  1. So basically I want to make a plugin and idk how to get the spawners from the config!
    I want to do on config:
    Code:
    Code (Text):

    Spawners:
      Zombie:
       One:
         x: 0
         y: 64
         z: 0
       Two:
         x: 0
         y: 64
         z: 0
     
    and the names doesn't know the console! I add the spawners in-game so it starting like this:
    Code:
    Code (Text):

    Spawners:
      Zombie:
     
    How I can get the names one per one? I want to get by typing a command ex: /commandhere getfirst and says you which is the first string etc. Can you help me?
     
  2. You can get your value like this
    Code (Java):

    FileConfiguration config = getConfig();
    for (String key : config.getConfigurationSection("Spawners.Zombie").getKeys(false)) {
        // here key equals one, two...
        int x, y, z;
        x = config.getInt("Spawners.Zombie." + key + ".x");
        y = config.getInt("Spawners.Zombie." + key + ".y");
        z = config.getInt("Spawners.Zombie." + key + ".z");
    }
     
     
  3. Thanks!1 Works awesome!
     
Thread Status:
Not open for further replies.