Run scheduled events outside of main class

Discussion in 'Plugin Development' started by robbo5899, Feb 14, 2014.

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

    robbo5899

    I'm trying to make a countdown timer but it is outside of the main class.

    My main class is called Main, and the class I am trying to schedule from is Game.

    Code for Main class:
    Code:java
    1. this.getScheduler().scheduleSyncRepeatingTask(this, new Runnable(){
    2. public void run(){
    3. int i = 3;
    4. if(i > 0){
    5. Bukkit.broadcastMessage("" + i);
    6. i--;
    7. }else{
    8. Bukkit.broadcastMessage("GO!");
    9. }
    10. }
    11. }, 0L, 20L);


    I'm not sure what I have to replace the "this" terms with.

    The first one I know to change to Bukkit but what should I change the second one to?

    Thanks and excuse my stupidity I'm sure this is something really simple.
     
  2. Offline

    1Rogue

    Just make the class yourself:

    Code:java
    1. public class YourClass implements Runnable {
    2.  
    3. public void run() {...}
    4.  
    5. }


    Code:java
    1. plugin.getScheduler().scheduleSyncRepeatingTask(plugin, new YourClass());
     
  3. Offline

    robbo5899

    1Rogue

    In eclipse it says "plugin cannot be resolved". Do I need to declare "plugin" as something first?
     
  4. Offline

    1Rogue


    plugin would be the instance of your main class
     
  5. Offline

    qlimax5000

    robbo5899

    Code:java
    1. //Top of class
    2. public static NAME_OF_MAIN_CLASS instance;
    3.  
    4. //In onEnable
    5. public void onEnable() {
    6. instance = this;
    7. }
    8.  
    9. //Then later just do
    10. NAME_OF_MAIN_CLASS.instance.getServer().getScheduler().WHATEVER
     
  6. Offline

    robbo5899

  7. Offline

    1Rogue

    ZeusAllMighty11 likes this.
  8. Offline

    robbo5899

  9. Offline

    1Rogue


    Please refer to any word linked above.
     
Thread Status:
Not open for further replies.

Share This Page