To split, or not to split?

Discussion in 'Plugin Development' started by Scizzr, Apr 14, 2013.

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

    Scizzr

    Hey guys. I'm working on a plugin that's nearing 10,000 lines of code. I would like some advice on this. Please, no "lrn 2 Java" or whatever; I know how to program. I am asking for some serious, mature advice; else I wouldn't have posted here.

    Information:
    • It has an object that is similar to a Player, but that I have added additional information to. It's called Member.
    • It has several classes that act as managers, such as MemberManager, LootManager and KitManager
    ○ With these managers, there is a List of all of the loot, kits, etc that gets loaded from MySQL on OnEnable() and can be reloaded by using a command​
    ○ The managers also have methods such as MemberManager.getMemberByName(String name) that return information, such as the proper Member object for each Player.​
    • It has several objects that the Manager classes use, such as LootClass, LootItem, KitClass, and KitItem.
    ○ In each of these objects, there are fields and getters/setters such as Member having getPlayTime() and setPlayTime(int time), and LootClass having getLootItems()​

    If I do elect to split, I'm thinking that a good place to split would be at the Manager level (since each manager would essentially be a plugin that would perform a task). If I were to split this plugin into smaller sub-plugins though, I would have to re-use a lot of the same initialization code (such as instantiating the managers and objects for each plugin) and Util code, but that can be solved by using a library plugin. The only problem with that is that, for example, I would be using a lot of the same code in all of the plugins.

    For example, my plugin has tasks that need to be completed at a given interval. Let's say every minute. If each of the plugins had a task that needed to be completed every minute, that would mean that all of the plugins would have the same exact code.

    Also another concern that I have is that with my Member functionality, I would have a HUGE problem splitting that up. Examples:
    1) Each Member needs a link to a KitClass; each KitClass needs a link to several KitItems.
    2) Each CustomZombie needs a link to a LootClass; each LootClass needs a link to several LootItems.
    I know the term 'link' is incorrect, but I'm sure you get the point. My concern is that when splitting the big plugin into smaller ones, I don't want to have spaghetti plugins (plugins where A calls B.c(), B calls C.d(), C calls A.e(), and so forth). Is there any way that I could avoid this? All I can think of is just dealing with it.

    Also, as a side question (but one that seems to be driving me nuts), I am passing the instance of my main class to each of my objects, as a constructor. Am I doing this the best way possible, or is there a better way to allow one object to call code from another? I suppose I could make the instance of my main plugin a public static variable, however that opens up security concerns from what I've read.
    Here's an example of what I mean:

    Code:
    //Main.class
    public class MainPlugin extends JavaPlugin() {
        ClassOne one;
        ClassTwo two;
     
        public void onEnable() {
            one = new ClassOne(this);
            two = new ClassTwo(this);
            one.init();
            two.init();
        }
    }
     
    //Object One
    public class ClassOne() {
        Main plugin;
        public ClassOne(Main plugin) {
            this.plugin = plugin;
        }
     
        public void methodA() {
            plugin.two.methodB();
        }
    }
     
    //Object Two
    public class ClassTwo() {
        Main plugin;
        public ClassTwo() {
            this.plugin = plugin;
        }
     
        public void methodB() {
            //code
        }
    }
    
    Anyways, without more information (as it's 1:00 AM and I have to be at work at 8:00 AM), here is my complete project setup. All advice is welcome and appreciated.

    Code:
    com.scizzr.main
        Manager
        Perms
        ScizzrCraft
        Constants
        .cmds
            Cmd_Cls
            Cmd_DropParty
            Cmd_GM
            Cmd_Grant
            Cmd_Group
            Cmd_Hat
            Cmd_Ping
            Cmd_Playtime
            Cmd_RunAs
            Cmd_RunC
            Cmd_RunOp
            Cmd_SpawnZ
        .config
            Config
            ConfigLoader
            Files
        .enums
            ItemColor
        .events
            EntityMoveEvent
        .listeners
            BlockListener
            EntityListener
            InventoryListener
            PlayerListener
            ServerListener
        .managers
            AliasManager
            EntityManager
            GroupManager
            HealingManager
            KitManager
            LootManager
            MemberManager
            MessageManager
            PopManager
            ZombieManager
        .nms
            DistanceComparator
            EntityAINearestAttackableTarget
            EntityGiant
            EntityZombie
            Navigation
        .objects
            CustomZombie
            DBMySQL
            FireworkPop
            Group
            ItemSerializer
            KitClass
            KitItem
            LogFilter
            LootChest
            LootItem
            Member
            MySQLWriter
            Pop
            WebsitePoster
            WeightedRandomNumberGenerator
        .util
            EntityUtils
            InventoryUtils
            LocationUtils
            MathUtils
            MiscUtils
            PlayerUtils
            ReflectionUtils
            StringUtils
            Util
    plugin.yml
    
    PS: Thanks a lot for bearing with me on that long wall of text that took 20 minutes to write. :)
     
  2. Offline

    microgeek

    I would not split up the plugin if I where you, if it's such a hassle. To your question about passing instances of your plugin in constructors, I hate doing that, so I just have a class called MainWrapper that holds a few static variables.
     
Thread Status:
Not open for further replies.

Share This Page