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 class BuildTask implements Runnable { public int getX() { return x; } public void setX(int x) { this.x = x; } public int getY() { return y; } public void setY(int y) { this.y = y; } private int id, x, y, n; private Model model; public int getId() { return id; } public void setId(int id) { this.id = id; } public Model getModel() { return model; } public void setModel(Model m) { this.model = m; } @Override public void run() { Bukkit.broadcastMessage("Creating a layer"); model.buildLayerAt(new Location(Bukkit.getWorlds().get(0), x*8, 18, y*8)); Bukkit.broadcastMessage("Layer: "+n); if(n > 14); { Bukkit.broadcastMessage("Cancelling Task "+n); Bukkit.getScheduler().cancelTask(id); } n++; }} 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.
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!
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)