当前位置: 首页>>代码示例>>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;未经允许,请勿转载。