Solved getConfig() error in CommandExecutor class

Discussion in 'Plugin Development' started by MineCrypt, Nov 24, 2012.

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

    MineCrypt

    I am making a plugin, and I can not seem to get use the getConfig(). in another class. I have been trying for over a day now and i need some help. Anything would be appreciated.

    I put the getConfig on the CommandExecutor on line 42 of the pastebin, it is there just for testing.

    Main Class:
    http://pastebin.com/zz8VbQ3p
    CommandExecutor:
    http://pastebin.com/mPiJk4s8
    config.yml:
    # Default Config
    Test: Complete

    ~MineCrypt
     
  2. Offline

    Tzeentchful

    Try using a constructor to pass the instance of the main class into the executor.

    Code:
    private CTFMain plugin;
         
    public CTFArenaJoin(CTFMain plugin){
        this.plugin = plugin;
    }
    And in the line where you initialize the class. Pass the instance into the declaration.

    Code:
    this.getCommand("ctf").setExecutor(new CTFArenaJoin(this));
     
  3. Offline

    DirtyStarfish

    Unless I missed it, it looks like the plugin variable you are using to access the getConfig() method is never set to anything. Try setting it in the onEnable() method, or pass an instance of CTFMain in a constructor.

    Code:
    onEnable()
    {
        // ...
     
        CTFArenaJoin.plugin = this;
    }
     
  4. Offline

    MineCrypt

    Wow i feel so stupid! See I tried that:
    Code:
    private CTFMain plugin;
         
    public CTFArenaJoin(CTFMain plugin){
        this.plugin = plugin;
    }
    Before when I used this.getCommand("ctf").setExecutor(new CTFArenaJoin(this)); , I had it so it was this.getCommand("ctf").setExecutor(new CTFArenaJoin(null)); . So anyways thanks!

    So I added that new code, and its working perfectly thanks everyone!

    EDIT by Moderator: merged posts, please use the edit button instead of double posting.
     
    Last edited by a moderator: May 30, 2016
Thread Status:
Not open for further replies.

Share This Page