Scheduler issues

Discussion in 'Plugin Development' started by Draesia, Dec 6, 2013.

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

    Draesia

    Hello, I am making a Plugin and I need to add a Scheduler which repeats x amount of times.

    Here is my code so far

    Called from
    Code:
    task.setId(Bukkit.getScheduler().scheduleSyncRepeatingTask(game.cc, task, 20, 20));
    Scheduler Class
    Code:java
    1.  
    2. class BuildTask implements Runnable {
    3. public int getX() {
    4. return x;
    5. }
    6. public void setX(int x) {
    7. this.x = x;
    8. }
    9. public int getY() {
    10. return y;
    11. }
    12. public void setY(int y) {
    13. this.y = y;
    14. }
    15. private int id, x, y, n;
    16. private Model model;
    17. public int getId() {
    18. return id;
    19. }
    20. public void setId(int id) {
    21. this.id = id;
    22. }
    23. public Model getModel()
    24. {
    25. return model;
    26. }
    27. public void setModel(Model m)
    28. {
    29. this.model = m;
    30. }
    31. @Override
    32. public void run() {
    33. Bukkit.broadcastMessage("Creating a layer");
    34. model.buildLayerAt(new Location(Bukkit.getWorlds().get(0), x*8, 18, y*8));
    35. Bukkit.broadcastMessage("Layer: "+n);
    36. if(n > 14);
    37. {
    38. Bukkit.broadcastMessage("Cancelling Task "+n);
    39. Bukkit.getScheduler().cancelTask(id);
    40. }
    41. n++;
    42. }
    43. }
    44.  


    Because of the if(n > 14) it should only cancel the task when n > 14 right?! Nope, it cancels it first time around always, if I comment the Bukkit.getScheduler().cancelTask(id); it doesn't cancel, so it is definitely getting through the if statement, if you understand what I mean, it even says "Cancelling Task 0". This makes no sense for me, please could somebody help! Thankyou.
     
  2. Offline

    NathanWolf

    Are you creating a new BuildTask each time, or reusing the same one?

    If it's the latter, you probably need a "reset" method that sets n back to 0 ... otherwise I'm not sure!
     
  3. Offline

    Draesia

    I am creating a new BuildTask each time, however in my tests, I have only been using one.
    (The plugin will create a structure layer by layer, I have only used 1 structure in my tests)
     
Thread Status:
Not open for further replies.

Share This Page