Why plugin.getConfig().getBoolean() returns NULL

Discussion in 'Plugin Development' started by UltraMC, Dec 26, 2013.

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

    UltraMC

    Why
    Code:java
    1. plugin.getConfig().getBoolean("test.debugmode")

    in
    Code:java
    1. Test();

    is
    Code:java
    1. NULL
    ?

    ---

    My code:

    Code:java
    1. public void onEnable() {
    2. loadConfig();
    3. }
    4.  
    5. private void loadConfig() {
    6. getConfig().addDefault("test.debugmode", Boolean.valueOf(false));
    7. getConfig().options().copyDefaults(true);
    8. saveConfig();
    9. }
    10.  
    11. public Test() {
    12. this.plugin = plugin;
    13. this.debugMode = plugin.getConfig().getBoolean("test.debugmode");
    14. }
    15.  


    ---

    Note:

    Code:java
    1. plugin.getConfig()

    returns
    Code:java
    1. YamlConfiguration[path='', root='YamlConfiguration']
     
  2. Offline

    maciekmm

    And how your config looks like?
    I believe here's an error
     
  3. Offline

    UltraMC

    Config is as default creation method creates it:
    Code:
    test:
      debugmode: true
    Here's where?
     
  4. Offline

    maciekmm

    Can you post more code?
     
  5. Offline

    UltraMC

    Like what part? Cant post whole thing.
     
  6. Offline

    xTrollxDudex

    Orly ._.
     
  7. Offline

    maciekmm

    config related
     
  8. Offline

    UltraMC

    I did.

    Lets try that:
    Code:java
    1. this.plugin.getConfig().contains("test")

    returns false

    K got it

    Code:java
    1. getConfig().addDefault("test.debugmode")
    2.  
    3. //"test." had a typo


    EDIT by Moderator: merged posts, please use the edit button instead of double posting.
     
    Last edited by a moderator: Jun 5, 2016
  9. Offline

    maciekmm

    Next type copy paste your code :D
     
  10. Offline

    sgavster

    plugin is probably null. It should be like this:
    PHP:
    private final Plugin plugin;
    public 
    YOUR_LISTENER_CLASS(Plugin plugin) {
    this.plugin plugin;
    }
    You can replace Plugin with your main class.




    EDIT: WOAH. If this is in your main class just use getConfig(), not plugin.getConfig()...
     
  11. Offline

    UltraMC

    sgavster it was not in Main, and as said 2 posts before it was a typo in YAML path.
     
Thread Status:
Not open for further replies.

Share This Page