Solved How Do I Check The Config If Something Exists?

Discussion in 'Plugin Development' started by 16austin16, Jun 29, 2015.

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

    16austin16

    Title Explans It All
     
  2. Offline

    mine-care

    @16austin16 well although the title may be explanatory having a description wouldn't be bad.
    To do that try getting the value of the section you want check and if it returns null that means it doesn't exist
     
  3. You could do a few things:

    1. Check if it exists in the configuration:
    Code:
    if (config.contains("path.to.whatever")) {
    2. Check if it is a class instance:
    Code:
    if (config.isBoolean("path.to.boolean")) {
    3. Check if it is not null:
    Code:
    if (config.getString("path.to.string") != null) {
     
  4. Offline

    16austin16

    @KingFaris11 Numbers 1 And 3 Didn't Work

    Code:
    if(!(Main.user.contains("Players." + p.getName() + ".Nickname"))) {
                Main.user.set("Players." + p.getName() + ".Nickname", p.getName());
            }
     
    Last edited: Jun 29, 2015
  5. That doesn't work? Did you save the config afterwards?
     
Thread Status:
Not open for further replies.

Share This Page