[Solved] Checking if a node has subnodes?

Discussion in 'Spigot Plugin Development' started by RandomPanda30, May 8, 2015.

  1. Alright so I'm working on a new config system that relies in Enum values and basically, when loading the config file and putting the new enum value into a hashmap, it will get the name of the node and then the value.

    However, this will not work if a node has subnodes so I need to check basically if a node has a subnode. Anyone got any ideas how to do this?

    ~ Panda
     
  2. I don't understand your question :p
     
    #2 mattrick, May 8, 2015
    Last edited: May 8, 2015
  3. Ok I'll explain it more simple. How do I check if a node has children values coming from it in a config?
     
  4. Check if the node is an instance of a hashmap/linkedhashmap or a String?
    Code (Text):
    if (yourMap.get(node1) instanceof String) {
    //do stuff
    }
    If it's an instance of a string (or int, or whatever the value is supposed to be), it doesn't have subnodes. If it's an instance of a hashmap/linkedhashmap, it has subnodes.
     
  5. Uh whut? How would I do this when looping through the configuration section? That's how I'm checking all the nodes.
     
    • Like Like x 1
  6. @RandomPanda30 check if it's a config section, and if that config section's getKeys(false) is not empty.
     
    • Like Like x 1
  7. Ahhhhh thank you guys very much for helping. It was just as simple as doing this -

    Code (Text):
        if (fileConfiguration.isConfigurationSection(rawNode)) {
                    if (fileConfiguration.getConfigurationSection(rawNode).getKeys(
                            true) != null) {
    Thank you guys again!
     
    • Like Like x 1