stop a task

Discussion in 'Plugin Development' started by enzoff40, Jan 30, 2016.

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

    enzoff40

    Hello
    I'am trying to make a plugin that fallingblocks 60 ticks gives a vector. But i don't know how I can stop the task after 60 ticks.

    Can someone help me?
    Thanks for any help!
     
  2. Offline

    teej107

    @enzoff40 What have you tried? Post your code attempt so we have something to work with.
     
  3. Offline

    javipepe

    Well you could try something like this, it should work.

    Code:
    /**
    * @author Javi
    */
    public class MyClass {
    
        int task;
       
        public void doTask() {
            this.task = Bukkit.getScheduler().scheduleSyncRepeatingTask(getPluginInstance(), new Runnable() {
                public void run() {
                    int i = 0;
                   
                    while (i<60) {
                        //do the things you need
                        i++;
                    }
                   
                    endTask();
                }
            }, x, y);
        }
       
        public void endTask() {
            Bukkit.getScheduler().cancelTask(this.task);
        }
    }
    
     
  4. Offline

    Zombie_Striker

    @javipepe
    Can you post your main class? When do you reference do task?
     
  5. Offline

    mythbusterma

    @javipepe

    Just use a BukkitRunnable and call the cancel() method inside it. Done.
     
  6. Offline

    javipepe

    What do you mean? I'm just providing a method by which he could " how I can stop the task after 60 ticks.". You could then call it from anywhere or just create a MyClass instance with an empty constructor and call it from there.

    Yeah I suppose you can do it like that too

    EDIT by Moderator: merged posts, please use the edit button instead of double posting.
     
    Last edited by a moderator: Jan 31, 2016
Thread Status:
Not open for further replies.

Share This Page