Looping through keys looking for certain value in config

Discussion in 'Plugin Development' started by Kingbluesapphire, Nov 24, 2015.

Thread Status:
Not open for further replies.
  1. I need help looping through all the keys to find a value

    Lets say my config looks like
    Code:
    Map1:
      ID: 1
    Map2:
      ID: 2
    Map3:
      ID: 3
    How can i loop through all the keys to find a certain value

    I tried using
    Code:
        public String getMap(){
            int id = 1;
            //Loops through all keys in the config
            for(String maps : ConfigManager.getConfig().getKeys()){
                //Looks for arena with ID matching id value
                Arena arena = ConfigManager.getConfig().get(maps + ".ID" + id);
                //Returns arena's name
                return arena.getName();
            }
            return "";
        }
    When i try testing it the console returns an error at "return arena.getName();"
     
  2. Offline

    Zombie_Striker

    @Kingbluesapphire
    Gee, would be nice to actually see the error

    BTW, it's most likely an NPE. Just make sure arena is not null.
     
    Kingbluesapphire likes this.
  3. @Zombie_Striker
    The console says
    "Unexpected exception while parsing console command "test""
    ...
    "Caused by: java.lang.NullPointerException"
    So... Yes its a NPE i guess

    Also am i getting the field right using "maps + ".rotationID" + id"?
     
  4. Offline

    Scimiguy

    No, you should be doing "Map" + id + ".ID"
     
Thread Status:
Not open for further replies.

Share This Page