private BukkitTask setupId(final BukkitTask task) { this.taskId = task.getTaskId(); return task; } }
@Override @Deprecated public int scheduleSyncRepeatingTask(Plugin plugin, BukkitRunnable task, long delay, long period) { return task.runTaskTimer(plugin, delay, period).getTaskId(); }
@Override @Deprecated public int scheduleSyncDelayedTask(Plugin plugin, BukkitRunnable task, long delay) { return task.runTaskLater(plugin, delay).getTaskId(); }
/** * Schedules this in the Bukkit scheduler to run on next tick. * * @param plugin the reference to the plugin scheduling task * @return a BukkitTask that contains the id number * @throws IllegalArgumentException if plugin is null * @throws IllegalStateException if this was already scheduled * @see BukkitScheduler#runTask(Plugin, Runnable) */ public synchronized BukkitTask runTask(Plugin plugin) throws IllegalArgumentException, IllegalStateException { checkState(); return setupId(Bukkit.getScheduler().runTask(plugin, (Runnable) this)); }
/** * <b>Asynchronous tasks should never access any API in Bukkit. Great care * should be taken to assure the thread-safety of asynchronous tasks.</b> * <p> * Schedules this in the Bukkit scheduler to run asynchronously. * * @param plugin the reference to the plugin scheduling task * @return a BukkitTask that contains the id number * @throws IllegalArgumentException if plugin is null * @throws IllegalStateException if this was already scheduled * @see BukkitScheduler#runTaskAsynchronously(Plugin, Runnable) */ public synchronized BukkitTask runTaskAsynchronously(Plugin plugin) throws IllegalArgumentException, IllegalStateException { checkState(); return setupId(Bukkit.getScheduler().runTaskAsynchronously(plugin, (Runnable) this)); }
/** * Schedules this to run after the specified number of server ticks. * * @param plugin the reference to the plugin scheduling task * @param delay the ticks to wait before running the task * @return a BukkitTask that contains the id number * @throws IllegalArgumentException if plugin is null * @throws IllegalStateException if this was already scheduled * @see BukkitScheduler#runTaskLater(Plugin, Runnable, long) */ public synchronized BukkitTask runTaskLater(Plugin plugin, long delay) throws IllegalArgumentException, IllegalStateException { checkState(); return setupId(Bukkit.getScheduler().runTaskLater(plugin, (Runnable) this, delay)); }
/** * Starts an inactivity timer. */ private void startTimer() { taskId = plugin.getServer().getScheduler().scheduleSyncDelayedTask(plugin, new Runnable() { public void run() { if (conversation.getState() == Conversation.ConversationState.UNSTARTED) { startTimer(); } else if (conversation.getState() == Conversation.ConversationState.STARTED) { cancelling(conversation); conversation.abandon(new ConversationAbandonedEvent(conversation, InactivityConversationCanceller.this)); } } }, timeoutSeconds * 20); }
/** * <b>Asynchronous tasks should never access any API in Bukkit. Great care * should be taken to assure the thread-safety of asynchronous tasks.</b> * <p> * Schedules this to repeatedly run asynchronously until cancelled, * starting after the specified number of server ticks. * * @param plugin the reference to the plugin scheduling task * @param delay the ticks to wait before running the task for the first * time * @param period the ticks to wait between runs * @return a BukkitTask that contains the id number * @throws IllegalArgumentException if plugin is null * @throws IllegalStateException if this was already scheduled * @see BukkitScheduler#runTaskTimerAsynchronously(Plugin, Runnable, long, * long) */ public synchronized BukkitTask runTaskTimerAsynchronously(Plugin plugin, long delay, long period) throws IllegalArgumentException, IllegalStateException { checkState(); return setupId(Bukkit.getScheduler().runTaskTimerAsynchronously(plugin, (Runnable) this, delay, period)); }
/** * Schedules this to repeatedly run until cancelled, starting after the * specified number of server ticks. * * @param plugin the reference to the plugin scheduling task * @param delay the ticks to wait before running the task * @param period the ticks to wait between runs * @return a BukkitTask that contains the id number * @throws IllegalArgumentException if plugin is null * @throws IllegalStateException if this was already scheduled * @see BukkitScheduler#runTaskTimer(Plugin, Runnable, long, long) */ public synchronized BukkitTask runTaskTimer(Plugin plugin, long delay, long period) throws IllegalArgumentException, IllegalStateException { checkState(); return setupId(Bukkit.getScheduler().runTaskTimer(plugin, (Runnable) this, delay, period)); }
@Override public int schedule(long delay, long period, Runnable task) { return Bukkit.getScheduler().scheduleSyncRepeatingTask(plugin, task, delay, period); }
/** * Attempts to cancel this task. * * @throws IllegalStateException if task was not scheduled yet */ public synchronized void cancel() throws IllegalStateException { Bukkit.getScheduler().cancelTask(getTaskId()); }
/** * <b>Asynchronous tasks should never access any API in Bukkit. Great care * should be taken to assure the thread-safety of asynchronous tasks.</b> * <p> * Schedules this to run asynchronously after the specified number of * server ticks. * * @param plugin the reference to the plugin scheduling task * @param delay the ticks to wait before running the task * @return a BukkitTask that contains the id number * @throws IllegalArgumentException if plugin is null * @throws IllegalStateException if this was already scheduled * @see BukkitScheduler#runTaskLaterAsynchronously(Plugin, Runnable, long) */ public synchronized BukkitTask runTaskLaterAsynchronously(Plugin plugin, long delay) throws IllegalArgumentException, IllegalStateException { checkState(); return setupId(Bukkit.getScheduler().runTaskLaterAsynchronously(plugin, (Runnable) this, delay)); }
/** * Stops the active inactivity timer. */ private void stopTimer() { if (taskId != -1) { plugin.getServer().getScheduler().cancelTask(taskId); taskId = -1; } }
@Override @Deprecated public BukkitTask runTaskTimer(Plugin plugin, BukkitRunnable task, long delay, long period) throws IllegalArgumentException { return task.runTaskTimer(plugin, delay, period); }
@Override @Deprecated public BukkitTask runTaskLater(Plugin plugin, BukkitRunnable task, long delay) throws IllegalArgumentException { return task.runTaskLater(plugin, delay); }
@Override @Deprecated public BukkitTask runTaskAsynchronously(Plugin plugin, BukkitRunnable task) throws IllegalArgumentException { return task.runTaskAsynchronously(plugin); }
@Override @Deprecated public BukkitTask runTaskTimerAsynchronously(Plugin plugin, BukkitRunnable task, long delay, long period) throws IllegalArgumentException { return task.runTaskTimerAsynchronously(plugin, delay, period); }
@Override @Deprecated public BukkitTask runTaskLaterAsynchronously(Plugin plugin, BukkitRunnable task, long delay) throws IllegalArgumentException { return task.runTaskLaterAsynchronously(plugin, delay); }
@Override @Deprecated public BukkitTask runTask(Plugin plugin, BukkitRunnable task) throws IllegalArgumentException { return task.runTask(plugin); }