Search code examples
bukkit

See if key exists in a .yml file with bukkit plugin


I want to be able to see if a specific key exists in a .yml file so I don't write the same key multiple times in the same file. Here's how it looks right now:

if (config.getString("coins","") == "") {
    p.sendMessage("no coins key ):");
} else {
    p.sendMessage("a coins key :D");
}

Solution

  • config.getString("path", "")
    

    returns "", if the path does not exist. You should be good by checking it like that, but you should use .equals() to compare 2 strings.