本文整理匯總了Java中org.bukkit.scheduler.BukkitTask類的典型用法代碼示例。如果您正苦於以下問題:Java BukkitTask類的具體用法?Java BukkitTask怎麽用?Java BukkitTask使用的例子?那麽, 這裏精選的類代碼示例或許可以為您提供幫助。
BukkitTask類屬於org.bukkit.scheduler包,在下文中一共展示了BukkitTask類的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。
示例1: uninject
import org.bukkit.scheduler.BukkitTask; //導入依賴的package包/類
public static void uninject(Plugin plg) {
if (plg != null) {
for (BukkitTask pendingTask : Bukkit.getScheduler().getPendingTasks()) {
if (pendingTask.isSync() && pendingTask.getOwner().equals(plg)) {
try {
FieldAccessor<Runnable> field = Reflection.getField(pendingTask.getClass(), "task", Runnable.class);
Runnable runnable = field.get(pendingTask);
if (runnable instanceof SchedulerTaskInjector) {
field.set(pendingTask, ((SchedulerTaskInjector) runnable).getRunnable());
}
} catch (Exception e) {
e.printStackTrace();
}
}
}
}
}
示例2: getTaskTimingsByPlugin
import org.bukkit.scheduler.BukkitTask; //導入依賴的package包/類
public static MonitorRecord getTaskTimingsByPlugin(Plugin plg) {
MonitorRecord monitorRecord = getMonitorRecord("Scheduler", 0L, 0L, 0L);
if (plg == null) {
return monitorRecord;
}
for (BukkitTask pendingTask : Bukkit.getScheduler().getPendingTasks()) {
if (pendingTask.isSync() && pendingTask.getOwner().equals(plg)) {
try {
FieldAccessor<Runnable> field = Reflection.getField(pendingTask.getClass(), "task", Runnable.class);
Runnable runnable = field.get(pendingTask);
if (runnable instanceof SchedulerTaskInjector) {
SchedulerTaskInjector schedulerTaskInjector = (SchedulerTaskInjector) runnable;
monitorRecord = monitorRecord.merge(getMonitorRecord("Scheduler",
schedulerTaskInjector.getTotalTime(), schedulerTaskInjector.getTotalCount(),
schedulerTaskInjector.getMaxExecuteTime()));
}
} catch (Exception e) {
e.printStackTrace();
}
}
}
return monitorRecord;
}
示例3: inject
import org.bukkit.scheduler.BukkitTask; //導入依賴的package包/類
/**
*
* @author jiongjionger,Vlvxingze
*/
// 替換原本的Runnable為帶性能統計的版本
public static void inject(Plugin plg) {
if (plg != null) {
for (BukkitTask pendingTask : Bukkit.getScheduler().getPendingTasks()) {
if (pendingTask.isSync() && pendingTask.getOwner().equals(plg)) {
try {
FieldAccessor<Runnable> field = Reflection.getField(pendingTask.getClass(), "task", Runnable.class);
field.set(pendingTask, new SchedulerTaskInjector(plg, field.get(pendingTask)));
} catch (Exception e) {
e.printStackTrace();
}
}
}
}
}
示例4: remove
import org.bukkit.scheduler.BukkitTask; //導入依賴的package包/類
public void remove(Player player)
{
BukkitTask bukkitTask = this.destroyTasks.get(player.getUniqueId());
if (bukkitTask != null)
bukkitTask.cancel();
LivingEntity[] livingEntities = this.balloons.get(player.getUniqueId());
if (livingEntities == null)
return;
this.balloons.remove(player.getUniqueId());
for (LivingEntity livingEntity : livingEntities)
livingEntity.remove();
}
示例5: runTaskTimer
import org.bukkit.scheduler.BukkitTask; //導入依賴的package包/類
@Test
public void runTaskTimer()
{
AtomicInteger count = new AtomicInteger(0);
Runnable callback = () -> {
count.incrementAndGet();
};
BukkitTask task = scheduler.runTaskTimer(null, callback, 10L, 2L);
assertNotNull(task);
scheduler.performTicks(9L);
assertEquals(0, count.get());
scheduler.performOneTick();
assertEquals(1, count.get());
scheduler.performOneTick();
assertEquals(1, count.get());
scheduler.performOneTick();
assertEquals(2, count.get());
task.cancel();
scheduler.performOneTick();
assertEquals(2, count.get());
}
示例6: execute
import org.bukkit.scheduler.BukkitTask; //導入依賴的package包/類
@Override
public void execute() {
if (this.target == null)
return;
Entity e = getEntity();
Location goal = this.target.clone();
goal.setWorld(e.getWorld());
BukkitTask[] task = new BukkitTask[1];
final double walkSpeed = e.getLocation().distance(goal) / (double) getEvent().getTickDelay();
task[0] = Bukkit.getScheduler().runTaskTimer(Core.getInstance(), () -> stepLocation(e, goal, walkSpeed), 0L, 1L); // Move the entity closer every tick.
Bukkit.getScheduler().runTaskLater(Core.getInstance(), task[0]::cancel, getEvent().getTickDelay() - 1);
}
示例7: getTaskTimingsByPlugin
import org.bukkit.scheduler.BukkitTask; //導入依賴的package包/類
public static MonitorRecord getTaskTimingsByPlugin(Plugin plg) {
MonitorRecord monitorRecord = getMonitorRecord("Scheduler", 0L, 0L, 0L);
if (plg == null) {
return monitorRecord;
}
for (BukkitTask pendingTask : Bukkit.getScheduler().getPendingTasks()) {
if (pendingTask.isSync() && pendingTask.getOwner().equals(plg)) {
try {
FieldAccessor<Runnable> field = Reflection.getField(pendingTask.getClass(), "task", Runnable.class);
Runnable runnable = field.get(pendingTask);
if (runnable instanceof SchedulerTaskInjector) {
SchedulerTaskInjector schedulerTaskInjector = (SchedulerTaskInjector) runnable;
monitorRecord = monitorRecord
.merge(getMonitorRecord("Scheduler", schedulerTaskInjector.getTotalTime(), schedulerTaskInjector.getTotalCount(), schedulerTaskInjector.getMaxExecuteTime()));
}
} catch (Exception e) {
e.printStackTrace();
}
}
}
return monitorRecord;
}
示例8: start
import org.bukkit.scheduler.BukkitTask; //導入依賴的package包/類
private BukkitTask start() {
if (checkTask != null) throw new IllegalStateException("Task is already running");
return new BukkitRunnable() {
@Override
public void run() {
String latestVersion = fetchLatestVersion();
UpdateNotifier.this.latestVersion = latestVersion.equals("Error")
? UpdateNotifier.this.latestVersion == null
? currentVersion
: UpdateNotifier.this.latestVersion
: latestVersion;
if (!isUpToDate())
new BukkitRunnable() {
@Override
public void run() {
notifyConsole();
if (plugin.getSettings().getBoolean(
"MiscellaneousOptions.UpdateChecker.NotifyAdmins")) notifyAdmins();
}
}.runTask(plugin);
}
}.runTaskTimerAsynchronously(plugin, 0, CHECK_INTERVAL);
}
示例9: createTask
import org.bukkit.scheduler.BukkitTask; //導入依賴的package包/類
public void createTask() {
final Game game = this.game;
BukkitTask task = new BukkitRunnable() {
@Override
public void run() {
for (Player player : game.getTeamPlayers()) {
if (player.getInventory().contains(getItemMaterial())) {
Player target = findTargetPlayer(player);
if (target != null) {
player.setCompassTarget(target.getLocation());
continue;
}
}
player.setCompassTarget(game.getPlayerTeam(player).getSpawnLocation());
}
}
}.runTaskTimer(BedwarsRel.getInstance(), 20L, 20L);
this.game.addRunningTask(task);
}
示例10: gmOfflineNewTimer
import org.bukkit.scheduler.BukkitTask; //導入依賴的package包/類
public void gmOfflineNewTimer(String a) {
BukkitTask b = gA.getServer().getScheduler().runTaskLater(gA, new Runnable() {
@Override
public void run() {
if (gA.mC.cGa) {
Team c = gA.getServer().getScoreboardManager().getMainScoreboard().getEntryTeam(a);
gmBroadcastMsg(gA.mC.cPb.replace("{0}", c.getPrefix() + a + "\u00A7r"));
c.removeEntry(a);
if (c.getSize() == 0) {
gHa.remove(c.getName());
c.unregister();
}
} else {
gmBroadcastMsg(gA.mC.cPb.replace("{0}", a));
}
gHb.remove(a);
gHc.remove(a);
gmStatusCheck();
}
}, ((60 * gA.mC.cPa) * 20) + (gA.mA.i() == 7 ? 0 : gJ[0]));
gHc.put(a, b);
}
示例11: runTaskTimer
import org.bukkit.scheduler.BukkitTask; //導入依賴的package包/類
public BukkitTask runTaskTimer(Plugin plugin, Runnable runnable, long delay, long period) {
validate(plugin, runnable);
if (delay < 0l) {
delay = 0;
}
if (period == 0l) {
period = 1l;
} else if (period < -1l) {
period = -1l;
}
return handle(new CraftTask(plugin, runnable, nextId(), period), delay);
}
示例12: runTaskTimerAsynchronously
import org.bukkit.scheduler.BukkitTask; //導入依賴的package包/類
public BukkitTask runTaskTimerAsynchronously(Plugin plugin, Runnable runnable, long delay, long period) {
validate(plugin, runnable);
if (delay < 0l) {
delay = 0;
}
if (period == 0l) {
period = 1l;
} else if (period < -1l) {
period = -1l;
}
return handle(new CraftAsyncTask(runners, plugin, runnable, nextId(), period), delay);
}
示例13: onNearbyOf
import org.bukkit.scheduler.BukkitTask; //導入依賴的package包/類
public static <ENTITY extends Entity> BukkitTask onNearbyOf(JavaPlugin plugin, Entity entity, double offsetX, double offsetY, double offsetZ, Class<ENTITY> filter, Consumer<ENTITY> callback)
{
return plugin.getServer().getScheduler().runTaskTimerAsynchronously(plugin, () ->
{
entity.getNearbyEntities(offsetX, offsetY, offsetZ).forEach(found ->
{
if (filter == null || filter.isAssignableFrom(found.getClass()))
plugin.getServer().getScheduler().runTask(plugin, () -> callback.accept((ENTITY) found));
});
}, 2L, 2L);
}
示例14: startTask
import org.bukkit.scheduler.BukkitTask; //導入依賴的package包/類
@Override
public BukkitTask startTask(Task.Parameters schedule, Runnable runnable) {
final Duration delay = schedule.delay();
final Duration interval = schedule.interval();
return bukkit.runTaskTimer(plugin,
runnable,
delay == null ? 0 : TimeUtils.toTicks(delay),
interval == null ? -1 : TimeUtils.toTicks(interval));
}
示例15: runTaskLater
import org.bukkit.scheduler.BukkitTask; //導入依賴的package包/類
@Override
public BukkitTask runTaskLater(Plugin plugin, Runnable task, long delay) throws IllegalArgumentException
{
ScheduledTask scheduledTask = new ScheduledTask(id++, plugin, true, currentTick + delay, task);
tasks.add(scheduledTask);
return scheduledTask;
}