Solved More than 1 runnable in a class?

Discussion in 'Plugin Development' started by akabarblake, May 3, 2014.

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

    akabarblake

    Hey guys, I don't think this is possible, but I wonder.. . can you name them?
    Also, if It isn't possible, Can you create one separate for each class?
    thanks.
     
  2. Offline

    rfsantos1996



    public class Runnables {

    public class runnable1 extends BukkitRunnable {
    public void run() {
    getLogger().info("I don't know if this is what you want");
    }
    }
    }
     
  3. Offline

    akabarblake

    Thats one, but more than one In 1 plugin?
     
  4. Offline

    rfsantos1996

    Well, to use runnables, I always use:
    Code:java
    1. new BukkitRunnable() {
    2. public void run() {
    3. // Stuff
    4. }
    5. }.runTask<Timer/Later>(arguments);
    6.  
    7. /*
    8. * Check arguments here: [url]http://jd.bukkit.org/rb/apidocs/org/bukkit/scheduler/BukkitRunnable.html[/url]
    9. */
     
  5. Offline

    akabarblake

    I know that, but you Can't have more than 1 in a class? Like public void run(runnablerun1) and public void run(runnablerun2)
     
  6. Offline

    rfsantos1996

    Don't extends a Unnable, just make what I did inside a void/declaring a variable.

    Code:java
    1. public class MainPlugin {
    2.  
    3. private BukkitRunnable runnable1 = {
    4. public void run() {
    5. // Runnable 1
    6. }
    7. };
    8. private BukkitRunnable runnable2 = {
    9. public void run() {
    10. // Runnable 2
    11. }
    12. };
    13.  
    14. public void onEnable() {
    15.  
    16. runnable1.runTaskLater(this, 20);
    17. BukkitTask taskRunnable2 = runnable2.runTaskTimer(this, 1, 20);
    18.  
    19. new BukkitRunnable() {
    20. public void run() {
    21. taskRunnable2.cancel();
    22. }
    23. }.runTaskLater(this, 20*60);
    24.  
    25. }
    26.  
    27. }
     
  7. Offline

    coasterman10

    You can always have more than one in one class. This is Java.

    If you want multiple runnables, you can define those with two "new Runnable() { ... }".
     
  8. Offline

    akabarblake

    Thanks for all the help!
    Solwed!
     
  9. Offline

    RawCode

    void run()
    {
    if fieldA = true subrunA
    }

    learn basics before trying to use bukkit API
     
Thread Status:
Not open for further replies.

Share This Page