Bukkit Scheduler in External Class

Discussion in 'Plugin Development' started by AngryCupcake274, May 27, 2015.

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

    AngryCupcake274

    Hello all,
    I am creating a plugin for my server, and I am trying to keep it as neat as possible. I need to be able to put my schedulers in another class, because my Main class is getting very cluttered with code. Is there any way to put a scheduler in an external class and register it in my Main class?

    NOTE - I already have used the "private final Main plugin" and the constructor to access my Main class.
     
  2. Offline

    caderape

    @AngryCupcake274
    Create a variable of the new class in your main class. And register it on your onenable. You will be able to acces it from your main class. A constructor in your new class for get back data from your mainclass and it will be good.

    MyClass myclass;
    myclass = new MyClass(this);
     
  3. Offline

    SrNicks_

    You can create schedulers in their main class and enforce codes in different classes.
    Already other for main do not know.
    Want to know how ?
     
  4. Offline

    AngryCupcake274

    @SrNicks_ sure! The problem is that I'm trying to keep the code as neat as possible. do you just have to register the scheduler in the main class, but have it run a method in another class?
     
  5. Offline

    Zombie_Striker

    @AngryCupcake274
    If by "neat", you mean to not have that much code in once class, then you're trying to have it look nice at the cost of more memory. This is a bad way to do this, but if you want it to be neat, then heres what you would do.
    • Create a getter for the main instance in the Main class
    • Create a new class with a constructor that takes in a class field.
    • Create a Instance of the Main that is equal to null in the new class.
    • Set the null instance of main in the new config to the Main field in the constructor of the new class.
    Now you can get methods by using the new Main Instance to get the #getSchedular or whatever methods you want.
     
Thread Status:
Not open for further replies.

Share This Page