Multiple Class Registration Help

Discussion in 'Plugin Development' started by GianlucaPMC, May 11, 2014.

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

    GianlucaPMC

    Hey guys,

    I'm having quite an issue coding this plugin! I've got the outline of the guns working, but, because I want more than just one gun, I had to write up others in seperate classes, which I have done. However, as you can see in the main class, when I try and register the other ones in, it's giving an error which is causing the plugin not to work! Below is a list of all my classes!

    Thank you if you are able to help!


    Guns.java (Main class): here
    StoneGun.java: here
    GoldGun.java: here
    IronGun.java: here
    DiamondGun.java: here
     
  2. GianlucaPMC WHOA! How many JavaPlugins do you have there mate?! (You've literally turned every since class into a main class)

    To fix this, remove 'JavaPlugin' from each class (except Guns.java)
    and put a 'constructor' (e.g. in the StoneGun class, put something like this:)
    Code:
    public StoneGun {
        Bukkit.getServer().getPluginManager().registerEvents(this, this);
    }
    and in the Main class (onEnable method), use:
    Code:
    new StoneGun();
    new GoldGun();
    new IronGun();
    new DiamondGun();
     
  3. Offline

    GianlucaPMC

    DJSkepter

    I tried that! I think I may've done something wrong! My friend suggested I change all to main classes..

    Do you think you can give me an example with one class?
     
  4. GianlucaPMC Firstly, NEVER change it all to the main class - it's just something that's not really done (and I've never seen it been done before!)

    What you can do, if 'merge' some your listeners and put it into one method and put that into the main class.

    http://pastebin.com/ivqr0QhT
     
  5. Offline

    GianlucaPMC

    DJSkepter

    Are all the methods in the main class? So, are the others not needed?
     
  6. GianlucaPMC The other classes are not required, since that main class contains all of the events (compressed nicely). You can compile that, put a plugin.yml file and you've got yourself a gun plugin :)
     
  7. Offline

    GianlucaPMC

    DJSkepter Wow thanks! And thanks for the follow!

    Here you go: here
     
Thread Status:
Not open for further replies.

Share This Page