Connecting Classes, Class Listeners, Files to the Main

Discussion in 'Plugin Development' started by NewDevOnTheBlock, May 15, 2015.

Thread Status:
Not open for further replies.
  1. So it's late at night, and I'm completely frustrated at this point. I've always put all of my logic in plugins in just one class file, but the files are starting to get too big, and I want to organize them into other classes. Which I know is a good practice already, but going from console programs in C and Java to Java OOP is quite different.

    Anyways, I've been trying for hours now to get this to work, and have seen countless tutorials that all show accomplishing this a different way. Say I have my main class called Main, and a listener called Listener and another file called Sub which will use some global variables from Main.

    I have some Java OOP experience, and from what I've learned is to create the object sub in my Main class by doing:
    Code:
    Sub sub = new Sub();
    Then I can call methods in my Main class with sub.[Method].

    Since I will be using the default config file in my Sub class I'll need an instance of Main class and hook into that using (from a tutorial):
    Code:
        Main main;
        public Sub( Main instance ) {
            main = instance;
        }
    This then allows me to use:
    Code:
    main.getConfig().getString( ... );
    So my problem is coming up when I'm hooking my Sub class into the Main class. I am getting a The constructor Sub() is undefined error. Now I have a work around for this, and it compiles, but it doesn't work and an error is through because of an issue similar to this.

    As for the Listener, I am registering it with:
    Code:
    PluginManager pm = getServer().getPluginManager();
    pm.registerEvents( new Listener(this), this);
    Not getting any errors with the Listener and the Main class hook.

    Thank you everyone for taking the time to read. I appreciate help, tips, notes and tutorials.
     
    Last edited: May 16, 2015
  2. Offline

    mine-care

  3. Offline

    Reynergodoy

    pm.registerEvents( new Listener(this), this);
    i dont register Listener(this)
    i just register Listener()
     
  4. @Reynergodoy Are you using the config file at all in your Listeners when you do that?

    @mine-care I'm in the process of reading through those java documents right now. I'll get back to you if it works for me.
     
Thread Status:
Not open for further replies.

Share This Page