运行 BukkitRunnable

BukkitRunnable 是 Bukkit 中的 Runnable。可以直接从 BukkitRunnable 安排任务,也可以从内部取消它。

重要提示:任务的时间以 Ticks 衡量。第二个有 20 个刻度。

非 RepeatingTask:

JavaPlugin plugin;    //Your plugin instance    
Long timeInSeconds = 10;
Long timeInTicks = 20 * timeInSeconds;
new BukkitRunnable() {
        
    @Override
    public void run() {
        //The code inside will be executed in {timeInTicks} ticks.
        
    }
}.runTaskLater(plugin, timeInTicks);   // Your plugin instance, the time to be delayed.

重复任务:

JavaPlugin plugin;    //Your plugin instance    
Long timeInSeconds = 10;
Long timeInTicks = 20 * timeInSeconds;
new BukkitRunnable() {
        
    @Override
    public void run() {
        //The code inside will be executed in {timeInTicks} ticks.
       //After that, it'll be re-executed every {timeInTicks} ticks;
      //Task can also cancel itself from running, if you want to.

       if (boolean) {
           this.cancel();
       }
        
    }
}.runTaskTimer(plugin, timeInTicks, timeInTicks);   //Your plugin instance, 
                                                   //the time to wait until first execution,
                                                  //the time inbetween executions.