Plugin Development Question

Discussion in 'Plugin Development' started by Michael Briggs, Mar 29, 2012.

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

    Michael Briggs

    Hi,

    I've taken two years of Java in college, but haven't had any experience with OOA&D yet. Currently I'm working on a fairly extensive suite of plugins for my server and I've come across a significant hurdle I could use some advice on. I'm having a hard time determining how I should interconnect the different parts of my plugins. I have the following features that all need to share data. A reputation system, a job system, a region based build protection system, and a fast travel system. So far I'm storing two hashmaps in my "main" class, one with a Player name and player data class and one with a region name and a region data class.

    Currently I have the whole suite as one plugin, my biggest issue is that I have about two dozen listeners in this "main" class and would like to break them down into more manageable parts. How would I share my hashmaps with all the other plugins if I do? I read somewhere that I can do a getServer().getPluginManager().getPlugin() of sorts and get instances of plugins, so should I just use a getter and setter for the hashmaps? If I were to use this method, how would I know if / when an instance has been instantiated before continuing? I'd need a way to make sure the data storage plugin has been registered with the plugin manager before I try to get an instance for my other plugins, how would I go about that?

    I can see many many ways to acomplish my ultimate goal, but I don't have the analysis and design experience to know the right way to do it. Any help would be greatly appreciated, direct assistance or referral to some good design resource would be great. Thanks for your time.

    Michael
     
  2. Offline

    Sorroko

    Essentials is a good example of this, my way would be to make public methods in my main plugin that sets/gets data from the hashmaps. Then get an instance of your plugin from another and use the get/set methods. I would write a longer reply but im afraid I don't have time right now. Ill post later if you like. Do checkout essentials, it may seem complex but it has a good structure.
    Hope this helps.
     
  3. Offline

    Michael Briggs

    Ryan,

    Thanks for your post, I'll give them a look. When you get a moment, if you could explain how I'd get an instance of the primary class? would I just put a while(getServer().getPluginManager().getPlugin() == null) loop in my onEnable() and wait for the primary class to be instantiated? Or is there an event I can listen for that bukkit fires when it creates a class instance? I'm going to take a look at essentials, thanks for the lead, I'll see how that looks.

    Michael
     
  4. Offline

    Sorroko

    Hello Michael, By just getting the plugin should be fine, if you add a dependancy in your plugin.yml it will try to make the plugin load before yours, so that it should return a plugin instance without the need for while loop. The problem with a while loop would be that your plugin will get stuck if the other plugin is not installed. You've pretty much got the idea of how it should work, Good Luck with your plugin.
     
  5. Offline

    Michael Briggs

    Ryan,

    Thanks, I'll give that a try. I'm not too worried about a loop, because first of all, it wouldn't work without the other plugin regardless, and second, it's really a personal use plugin, I'm not expecting to release it to the public since there are only about a hundred other plugins that do what I want. This is more a learning thing for me than anything, but it's still something I want. I'll look into setting dependencies and see how that works out. Thanks.

    Michael
     
Thread Status:
Not open for further replies.

Share This Page