Implement synchronous execution for BukkitSchedulerAdapter;
Add javadoc for SchedulerAdapter interface;
(cherry picked from commit 919a249eb5
)
This commit is contained in:
parent
dbe1a4e0c6
commit
ce7b623c71
|
@ -27,6 +27,7 @@ import org.bukkit.scheduler.BukkitScheduler;
|
|||
public class BukkitSchedulerAdapter implements SchedulerAdapter {
|
||||
|
||||
private final Plugin plugin;
|
||||
@SuppressWarnings("deprecation")
|
||||
private final BukkitScheduler scheduler;
|
||||
|
||||
public BukkitSchedulerAdapter(final Plugin plugin) {
|
||||
|
@ -34,33 +35,28 @@ public class BukkitSchedulerAdapter implements SchedulerAdapter {
|
|||
this.scheduler = plugin.getServer().getScheduler();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void runAsync(final Runnable runnable) {
|
||||
scheduler.runTaskAsynchronously(plugin, runnable);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void runAsyncRate(Runnable runnable, long delay, long period) {
|
||||
scheduler.runTaskTimerAsynchronously(plugin, runnable, delay, period);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void runAtEntity(Entity entity, Runnable runnable) {
|
||||
|
||||
public void executeAtEntity(Entity entity, Runnable runnable) {
|
||||
scheduler.runTask(plugin, runnable);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void runAtEntityLater(final Entity entity, final Runnable runnable, final long delay) {
|
||||
public void runAtEntityDelayed(final Entity entity, final Runnable runnable, final long delay) {
|
||||
scheduler.runTaskLater(plugin, runnable, delay);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void runAtRegion(Location location, Runnable runnable) {
|
||||
|
||||
public void executeAtRegion(Location location, Runnable runnable) {
|
||||
scheduler.runTask(plugin, runnable);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void cancelTasks() {
|
||||
|
||||
scheduler.cancelTasks(plugin);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -53,28 +53,23 @@ public class FoliaSchedulerAdapter implements SchedulerAdapter {
|
|||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void runAsync(final Runnable runnable) {
|
||||
asyncScheduler.runNow(plugin, task -> runnable.run());
|
||||
}
|
||||
|
||||
@Override
|
||||
public void runAsyncRate(final Runnable runnable, final long delay, final long period) {
|
||||
asyncScheduler.runAtFixedRate(plugin, task -> runnable.run(), delay * 50, period * 50, TimeUnit.MILLISECONDS);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void runAtEntity(final Entity entity, final Runnable runnable) {
|
||||
public void executeAtEntity(final Entity entity, final Runnable runnable) {
|
||||
entity.getScheduler().run(plugin, task -> runnable.run(), null);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void runAtEntityLater(final Entity entity, final Runnable runnable, final long delay) {
|
||||
public void runAtEntityDelayed(final Entity entity, final Runnable runnable, final long delay) {
|
||||
entity.getScheduler().execute(plugin, runnable, null, delay);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void runAtRegion(final Location location, final Runnable runnable) {
|
||||
public void executeAtRegion(final Location location, final Runnable runnable) {
|
||||
regionScheduler.execute(plugin, location, runnable);
|
||||
}
|
||||
|
||||
|
|
|
@ -24,15 +24,59 @@ import org.bukkit.entity.Entity;
|
|||
|
||||
public interface SchedulerAdapter {
|
||||
|
||||
void runAsync(Runnable runnable);
|
||||
/**
|
||||
* Schedules the specified task to be executed asynchronously after the delay has passed,
|
||||
* and then periodically executed with the specified period.
|
||||
*
|
||||
* @param runnable The task to execute.
|
||||
* @param delay The time delay to pass before the task should be executed.
|
||||
* @param period The time between task executions after the first execution of the task.
|
||||
*/
|
||||
void runAsyncRate(Runnable runnable, long delay, long period);
|
||||
|
||||
void runAsyncRate(Runnable runnable, long delay, long period);
|
||||
/**
|
||||
* Schedules a task. If the task failed to schedule because the scheduler is retired (entity removed),
|
||||
* then returns {@code false}. Otherwise, either the run callback will be invoked after the specified delay,
|
||||
* or the retired callback will be invoked if the scheduler is retired.
|
||||
* Note that the retired callback is invoked in critical code, so it should not attempt to remove the entity,
|
||||
* remove other entities, load chunks, load worlds, modify ticket levels, etc.
|
||||
*
|
||||
* <p>
|
||||
* It is guaranteed that the task and retired callback are invoked on the region which owns the entity.
|
||||
* </p>
|
||||
*
|
||||
* @param entity The entity relative to which the scheduler is obtained.
|
||||
* @param runnable The task to execute.
|
||||
*/
|
||||
void executeAtEntity(Entity entity, Runnable runnable);
|
||||
|
||||
void runAtEntity(Entity entity, Runnable runnable);
|
||||
/**
|
||||
* Schedules a task with the given delay. If the task failed to schedule because the scheduler is retired (entity removed),
|
||||
* then returns {@code false}. Otherwise, either the run callback will be invoked after the specified delay,
|
||||
* or the retired callback will be invoked if the scheduler is retired.
|
||||
* Note that the retired callback is invoked in critical code, so it should not attempt to remove the entity,
|
||||
* remove other entities, load chunks, load worlds, modify ticket levels, etc.
|
||||
*
|
||||
* <p>
|
||||
* It is guaranteed that the task and retired callback are invoked on the region which owns the entity.
|
||||
* </p>
|
||||
*
|
||||
* @param entity The entity relative to which the scheduler is obtained.
|
||||
* @param runnable The task to execute.
|
||||
* @param delay The time delay to pass before the task should be executed, in ticks.
|
||||
*/
|
||||
void runAtEntityDelayed(Entity entity, Runnable runnable, long delay);
|
||||
|
||||
void runAtEntityLater(Entity entity, Runnable runnable, long delay);
|
||||
/**
|
||||
* Schedules a task to be executed on the region which owns the location.
|
||||
*
|
||||
* @param location The location at which the region executing should own.
|
||||
* @param runnable The task to execute.
|
||||
*/
|
||||
void executeAtRegion(Location location, Runnable runnable);
|
||||
|
||||
void runAtRegion(Location location, Runnable runnable);
|
||||
|
||||
void cancelTasks();
|
||||
/**
|
||||
* Attempts to cancel all tasks scheduled by the plugin.
|
||||
*/
|
||||
void cancelTasks();
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue