當前位置: 首頁>>代碼示例>>Java>>正文


Java BukkitTask類代碼示例

本文整理匯總了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();
				}
			}
		}
	}
}
 
開發者ID:GelandiAssociation,項目名稱:EscapeLag,代碼行數:18,代碼來源:SchedulerTaskInjector.java

示例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;
}
 
開發者ID:GelandiAssociation,項目名稱:EscapeLag,代碼行數:24,代碼來源:MonitorUtils.java

示例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();
				}
			}
		}
	}
}
 
開發者ID:GelandiAssociation,項目名稱:EscapeLag,代碼行數:21,代碼來源:SchedulerTaskInjector.java

示例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();
}
 
開發者ID:SamaGames,項目名稱:Hub,代碼行數:18,代碼來源:BalloonCosmetic.java

示例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());
}
 
開發者ID:seeseemelk,項目名稱:MockBukkit,代碼行數:22,代碼來源:BukkitSchedulerMockTest.java

示例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);
}
 
開發者ID:Kneesnap,項目名稱:Kineticraft,代碼行數:15,代碼來源:ActionEntityPathfind.java

示例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;
}
 
開發者ID:jiongjionger,項目名稱:NeverLag,代碼行數:23,代碼來源:MonitorUtils.java

示例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);
}
 
開發者ID:MyzelYam,項目名稱:SuperVanish,代碼行數:24,代碼來源:UpdateNotifier.java

示例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);
}
 
開發者ID:BedwarsRel,項目名稱:BedwarsRel,代碼行數:22,代碼來源:Tracker.java

示例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);
}
 
開發者ID:Thomaz2Fast,項目名稱:Ultra-Hardcore-1.8,代碼行數:23,代碼來源:GameManager.java

示例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);
}
 
開發者ID:UraniumMC,項目名稱:Uranium,代碼行數:13,代碼來源:CraftScheduler.java

示例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);
}
 
開發者ID:UraniumMC,項目名稱:Uranium,代碼行數:13,代碼來源:CraftScheduler.java

示例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);
}
 
開發者ID:SamaGames,項目名稱:SamaGamesAPI,代碼行數:12,代碼來源:ProximityUtils.java

示例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));
}
 
開發者ID:OvercastNetwork,項目名稱:ProjectAres,代碼行數:10,代碼來源:BukkitSchedulerBackend.java

示例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;
}
 
開發者ID:seeseemelk,項目名稱:MockBukkit,代碼行數:8,代碼來源:BukkitSchedulerMock.java


注:本文中的org.bukkit.scheduler.BukkitTask類示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。