Im sure Im doing this the hard/wrong way...

Discussion in 'Plugin Development' started by dxwarlock, Jun 25, 2012.

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

    dxwarlock

    As my new plugin gets bigger, I decided "I'll move methods into thier own classes..to sort this out, one Main class 1000 lines is getting unruly"

    So I went to sort them out, got them all organized into different packages and classes so I can find one to edit it easier (with ferrybig giving a few tips).

    But now, it seems there must be a simpler way to do this...as I get a lot of sudo-redundant code going on here..like so:
    Code:java
    1.  
    2. public class Main extends JavaPlugin implements Runnable {
    3. private static Main instance;
    4. public final Main playerListener = this;
    5. public final SpawnM Mobs = new SpawnM(this);
    6. public final cLoad cLoad = new cLoad(this);
    7. public final Bonuses Bonus = new Bonuses(this);
    8. public final Colors C = new Colors(this);
    9. public final Ticker Ticker = new Ticker(this);
    10. public final FishingItems fItems = new FishingItems(this);
    11. MobListener OnS = new MobListener(this);
    12. Lis lis = new Lis(this);
    13. BlockBreakListener lis1 = new BlockBreakListener(this);
    14. public Logger log = Logger.getLogger("Minecraft");
    15.  

    and my in onEnable()
    Code:java
    1.  
    2. PluginManager pm = getServer().getPluginManager();
    3. pm.registerEvents(new Lis(playerListener), this);
    4. pm.registerEvents(new MobListener(playerListener), this);
    5. pm.registerEvents(new BlockBreakListener(playerListener), this);
    6.  


    THEN inside every one of my Listener classes something like:
    Code:java
    1.  
    2. public class MobListener implements Listener {
    3. private final Main plugin;
    4. public MobListener(Main plugin) {
    5. this.plugin = plugin;
    6. }
    7.  


    Just seems messy and cumbersome..to add a
    public final <something> Name = new <something>(this);

    to the Main for every class I make, so I can call variables and methods that are inside it, and Also call variables and methods from other classes to use in it.
     
  2. Offline

    ItsHarry

    There's nothing wrong with a class with 1000 lines, just wanted to make that clear beforehand.

    But ehm, yeah all those variables, that's just the way java works. And if you insist on removing them, you can make the class have a private constructor to make it static. Then simply add static methods.
     
    ZeusAllMighty11 likes this.
  3. Offline

    dxwarlock

    Not saying over 1000 was bad, just was harder to find those one shot method of 3-5 lines that did something, to change them..

    Or when moving/making a new class, having to go and add all that to the main, THEN adding the other this.plugin = plugin to the new class...and then referring to anything inside of it as"plugin.<whatever>.<method>(variables)" seemed a bit "round aboutish".

    Time to start poking around to figure out how to do as you suggested.
     
Thread Status:
Not open for further replies.

Share This Page