Solved getConfig()

Discussion in 'Plugin Development' started by Forseth11, Mar 28, 2013.

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

    Forseth11

    How do I getConfig() from within another class? Like get it from a class that uses events.
     
  2. Offline

    ZeusAllMighty11

    Use a constructor and reference the class that extends javaplugin
     
  3. Offline

    Rprrr

    Don't want to be an idiot, but there's seriously a thousand topics about this, can't you just take a look at one of those?
     
  4. Offline

    Forseth11

    ZeusAllMighty11 Can you show me an example please, because I don't know how to do those things. (well I don't know the word.) - BAD VOCABULARY.

    Rprrr I tried using other forms, but I couldn't figure it out.
     
  5. Offline

    KoffiePatje

    Something like this should work ;)

    Code:
    public class PluginClass extends JavaPlugin
    {
        public void OnEnable()
        {
            // Register the Listener & pass Instance of this class
            this.getServer().getPluginManager().registerEvents( new ListenerClass( this ), this );
        }
    }
    _______________________________________
     
    public class ListenerClass
    {
        PluginClass m_Instance;
     
        public ListenerClass( PluginClass a_Instance )
        {
            m_Instance = a_Instance;
        }
     
        public Foo()
        {
            m_Instance.getConfig();
        }
    }
     
  6. Offline

    ZeusAllMighty11

    [CODE[

    private ClassThatExtendsJavaPlugin plugin;

    public ClassYouAreInRightNowProbablyTheEventOne(ClassThatExtendsJavaPlugin plugin){
    this.plugin = plugin;
    }
    [/CODE]
     
  7. Offline

    Forseth11

    ZeusAllMighty11 I tried that before and it keeps showing an error in the onEnable():
    Code:
    public void onEnable(){
            PluginDescriptionFile pdfFile = this.getDescription();
            this.logger.info(pdfFile.getName() + "Version " + pdfFile.getVersion() + " Has Been Enabled");
            this.saveDefaultConfig();
            PluginManager m = this.getServer().getPluginManager();
            m.registerEvents(new CommandListener(), this); //This line shows an error.
        }
     
  8. Offline

    ZeusAllMighty11

    Because your constructor init of a new class is wrong, if you highlight it should suggest something
     
  9. Offline

    Forseth11

    Eclipse gave me 3 quick fixes and none of them worked. Do you want me to show you both of my classes?

    KoffiePatje I'll try that tomorrow. My computer is off and I'm not aloud to have it on past 9:00

    EDIT by Moderator: merged posts, please use the edit button instead of double posting.
     
    Last edited by a moderator: May 31, 2016
  10. Offline

    dillyg10

    Code:
    Le easy way
    class Plugin{
     Plugin instance;
     onEnable(){
       instance = this
     }
    }
    //listener class...
    Plugin.instance.getConfig()
    
    Do not just copy and paste this code, it's just dummy code :).
     
  11. Offline

    Forseth11

    It turns out all I had to do was put 'this' inside the parentheses.
    Code:
    m.registerEvents(new CommandListener(this), this);
     
  12. Offline

    KoffiePatje

    Happy to help ;)
     
Thread Status:
Not open for further replies.

Share This Page