修复spigot无法生成地图画的问题
This commit is contained in:
parent
71bf3ed675
commit
b8a3dbddd5
@ -26,6 +26,74 @@ public class Scheduler {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Run a task later
|
||||||
|
*
|
||||||
|
* @param task The task to run
|
||||||
|
* @param delay The delay in ticks (20 ticks = 1 second)
|
||||||
|
* @return The scheduled task
|
||||||
|
*/
|
||||||
|
public static void runTaskLater(Runnable task, long delay) {
|
||||||
|
if (delay <= 0) {
|
||||||
|
runTask(task);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
if (instance.isPaper) {
|
||||||
|
instance.plugin.getServer().getGlobalRegionScheduler().runDelayed(instance.plugin, (plugin) -> task.run(), delay);
|
||||||
|
} else {
|
||||||
|
instance.plugin.getServer().getScheduler().runTaskLater(instance.plugin, task, delay);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Run a task
|
||||||
|
*
|
||||||
|
* @param task The task to run
|
||||||
|
* @return The scheduled task
|
||||||
|
*/
|
||||||
|
public static void runTask(Runnable task) {
|
||||||
|
if (instance.isPaper) {
|
||||||
|
instance.plugin.getServer().getGlobalRegionScheduler().run(instance.plugin, (plugin) -> task.run());
|
||||||
|
} else {
|
||||||
|
instance.plugin.getServer().getScheduler().runTask(instance.plugin, task);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Run a task repeatedly
|
||||||
|
*
|
||||||
|
* @param task The task to run
|
||||||
|
* @param delay The delay in ticks (20 ticks = 1 second)
|
||||||
|
* @param period The period in ticks (20 ticks = 1 second)
|
||||||
|
* @return The scheduled task
|
||||||
|
*/
|
||||||
|
public static void runTaskRepeat(Runnable task, long delay, long period) {
|
||||||
|
if (instance.isPaper) {
|
||||||
|
instance.plugin.getServer().getGlobalRegionScheduler().runAtFixedRate(instance.plugin, (plugin) -> task.run(), delay, period);
|
||||||
|
} else {
|
||||||
|
instance.plugin.getServer().getScheduler().runTaskTimer(instance.plugin, task, delay, period);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Run a task later asynchronously
|
||||||
|
*
|
||||||
|
* @param task The task to run
|
||||||
|
* @param delay The delay in milliseconds
|
||||||
|
* @return The scheduled task
|
||||||
|
*/
|
||||||
|
public static void runTaskLaterAsync(Runnable task, long delay) {
|
||||||
|
if (delay <= 0) {
|
||||||
|
runTaskAsync(task);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
if (instance.isPaper) {
|
||||||
|
instance.plugin.getServer().getAsyncScheduler().runDelayed(instance.plugin, (plugin) -> task.run(), delay * 50, TimeUnit.MILLISECONDS);
|
||||||
|
} else {
|
||||||
|
instance.plugin.getServer().getScheduler().runTaskLaterAsynchronously(instance.plugin, task, delay);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Run a task asynchronously
|
* Run a task asynchronously
|
||||||
*
|
*
|
||||||
@ -39,4 +107,20 @@ public class Scheduler {
|
|||||||
instance.plugin.getServer().getScheduler().runTask(instance.plugin, task);
|
instance.plugin.getServer().getScheduler().runTask(instance.plugin, task);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Run a task repeatedly asynchronously
|
||||||
|
*
|
||||||
|
* @param task The task to run
|
||||||
|
* @param delay The delay in milliseconds
|
||||||
|
* @param period The period in milliseconds
|
||||||
|
* @return The scheduled task
|
||||||
|
*/
|
||||||
|
public static void runTaskRepeatAsync(Runnable task, long delay, long period) {
|
||||||
|
if (instance.isPaper) {
|
||||||
|
instance.plugin.getServer().getAsyncScheduler().runAtFixedRate(instance.plugin, (plugin) -> task.run(), delay * 50, period * 50, TimeUnit.MILLISECONDS);
|
||||||
|
} else {
|
||||||
|
instance.plugin.getServer().getScheduler().runTaskTimerAsynchronously(instance.plugin, task, delay, period);
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user