Tutorial Remove Entries From Configuration File

Discussion in 'Resources' started by ThePandaPlayer, May 28, 2018.

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

    ThePandaPlayer

    I am not asking for help. This question has been answered before and I know very well how to remove config entries. WAIT WAIT!! Don't flag this thread yet! The thread that answered the question is very old and vague. It is difficult to figure out what the true answer was. So, I'm just going to explain it right here. Plain and simple.


    I'm assuming you know how to add things to the config, but just for a refresher, here is how to do it:
    Code:
    MainClassName.getConfig().set("EntryName", value);
    All you need is one line of code to add the entry.

    Reading from the same entry is also just as simple:
    Code:
    MainClassName.getConfig().get("EntryName");
    There are many methods you can use to read (getBoolean(), getString(), etc). I just used the get() for simplicity purposes.

    Now, the actual answer to the question: Removing configuration entries:
    Code:
    MainClassName.getConfig().set("EntryName", null);
    That's it. Simply setting the entry value to null completely removes it from the configuration.

    And just a friendly reminder: USE THE SAVECONFIG() METHOD!!!
    If you don't the server will not actually write to the config file, and the entry will not go away.

    Have a good rest of your day!
    :)

    NOTE: Your MainClassName cannot be used. The configuration methods are not static, and therefore require an instance of the Main plugin class to be used. If you are accessing the configuration straight from your Main plugin class, (the one that extends JavaPlugin) simply use the "this" keyword to reference the class.

    TLDR; Use this method:
    Code:
    MainClassName.getConfig().set("EntryName",null);
    MainClassName.saveConfig();
    By setting the value to null, the server just removes the entry.
    Make sure to save the config! :)

    NOTE: Your MainClassName cannot be used. The configuration methods are not static, and therefore require an instance of the Main plugin class to be used. If you are accessing the configuration straight from your Main plugin class, (the one that extends JavaPlugin) simply use the "this" keyword to reference the class.
     
  2. Online

    timtower Ninja on the waves Moderator

  3. Offline

    ThePandaPlayer

    Thank you timtower!
    (I wasn't 100% sure where to put this...)
     
Thread Status:
Not open for further replies.

Share This Page