Solved Checking a configs elements

Discussion in 'Plugin Development' started by harvmaster, Aug 14, 2015.

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

    harvmaster

    Hi I have been trying to loop through a config for a variable's x coordinate then if it finds that, goes to y and then to z. But I have no clue how I would loop through it and find it.

    I feel like it would be something like this but I have no clue

    Code:
    Object[] dungeonS = CustomEnchants.plugin.getConfig().getConfigurationSection("dungeons").getKeys(true).toArray();
                   
                    for (int i = 0; i < dungeonS.length; i++ ) {
                       
                       
                       
                    }
    The config variables are created by the player so I don't know how to check the names and the children nodes.
    And it looks like this;

    Dungeons: '#Create the dungeons ingame with /Dungeon Create Chest'
    dungeons:
    dungeon:
    x: -283
    y: 69
    z: 198
    world: world
    Difficulty: 4
    dungeon2:
    x: -280
    y: 69
    z: 195
    world: world
    Difficulty: 5

    Any help is appreciated.
    Thanks in advanced,
    Harvmaster
     
  2. Offline

    Larsn

    Could you be more specific; what are you trying to do, what purpose has it?
     
  3. Offline

    harvmaster

    Sorry, I guess I haven't really given much information.

    I am trying to make a loot chest plugin where the user of the plugin will create various chests that can be looted. I want a way to go through the config file and check if a chest a player has just opened, is a loot chest. Since these are going to be saved in the config with a random name I have no idea how to get to the child nodes for the coordinates of the chest if I don't know what the chest is named. I was originally using a method where the player has to name the chest in an anvil but after trying to set up multiple of these it became extremely annoying and inconvenient.

    I am looking for a way to determine if it's a loot able chest.
    Thanks
     
  4. @harvmaster Can you please tell me what is returned when you do
    Code:
    player.sendMessage(dungeons.get(i));
    ?

    This will help me helping you!
     
  5. Offline

    caderape

    @harvmaster
    Code:
    for (String GameName : getConfig().getConfigurationSection("dungeons").getKeys(false) {
                for (String variable : getConfig().getConfigurationSection("dungeons."+GameName).getKeys(false) {
                    if (variable.equalsIgnoreCase("x") {
                        int x = getConfig().getInt("dungeons."+GameName+"."+"variable");
                        //do the same for y z difficulty world etc...
                    }
                }
            }
    
    Code:
    dungeons:
      GameName:
        x:
        y:
        z:
    If your config file looks like that, the method above should help you.
     
  6. Offline

    harvmaster

    Thank you @caderape, your code worked great and my plugin is working a lot better.
    Really appreciate it. Thanks
     
Thread Status:
Not open for further replies.

Share This Page