執行 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.