Solved Getting all childrens in config

Discussion in 'Plugin Development' started by Betagear, Oct 10, 2015.

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

    Betagear

    Hi.
    I'm trying to make something, and for so need to get all the paths that are in my config from a certain path.
    Is anyone knowing how I can do this ?
     
  2. Offline

    Zombie_Striker

    @Betagear
    What does your path look like? What is the format for the string?

    Can a simple for loop take care of the problem? (E.G. For loop from 0 to 100, and using that loop you can get the path "PATH."+integer)
     
  3. Offline

    Betagear

    Looks like :
    General:
    • Signs:
      • X :X Y :Y Z :Z World :World : true
      • X :X Y :Y Z :Z World :World : true
    So the for loop with int won't work.
     
    Last edited: Oct 10, 2015
  4. Offline

    Zombie_Striker

    @Betagear
    then do the following

    int X = getConfig().getINT("General.Signs.X");
    int Y = getConfig().getINT("General.Signs.Y");
    int Z = getConfig().getINT("General.Signs.Z");
    ect.

    If you are unsure what would be under signs, you can always save the SubSection's name (the X/Y/ZWorld) in an arraylist with a static path (Such as "Utils.SignPathNames") and put all the strings in the arraylist (So if you're adding "Pitch" to config, you would use ArrayList.add("Pitch") )
     
  5. Offline

    FisheyLP

    If it is a StringList, loop through config.getStringList("path"). If it is a configuration section, loop through config.getConfigurationSection("path").getKeys(false)
     
  6. Offline

    Betagear

    @Zombie_Striker The whole line is capted as one thing, because there is no space between X:X etc.

    @FisheyLP Tried to do that :
    Code:
            for (String path : plugin.getConfig().getConfigurationSection("General.Signs").getKeys(false)) {
                String[] path2 = path.split(" ");
                System.out.println(path);
                for (String string : path2) {
                    System.out.println(string);
                }
                path2[2].replace(":", "");
                path2[4].replace(":", "");
                path2[6].replace(":", "");
                int X = Integer.valueOf(path2[2]);
                int Y = Integer.valueOf(path2[4]);
                int Z = Integer.valueOf(path2[6]);
                World world = Bukkit.getWorld(path2[8].replace(":", ""));
                Location Signloc = new Location(world, X, Y, Z);
                System.out.println(Signloc);
            }
    but Integer.valueOf doesn't seems to work...

    EDIT : I just forgot that Lists begins with 0 and not 1

    EDIT by Moderator: merged posts, please use the edit button instead of double posting.
     
    Last edited by a moderator: Oct 29, 2015
Thread Status:
Not open for further replies.

Share This Page