org.bukkit.Bukkit.getScheduler()方法的使用及代码示例

x33g5p2x  于2022-01-16 转载在 其他  
字(8.1k)|赞(0)|评价(0)|浏览(294)

本文整理了Java中org.bukkit.Bukkit.getScheduler()方法的一些代码示例,展示了Bukkit.getScheduler()的具体用法。这些代码示例主要来源于Github/Stackoverflow/Maven等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。Bukkit.getScheduler()方法的具体详情如下:
包路径:org.bukkit.Bukkit
类名称:Bukkit
方法名:getScheduler

Bukkit.getScheduler介绍

暂无

代码示例

代码示例来源:origin: EngineHub/WorldEdit

@Override
public int schedule(long delay, long period, Runnable task) {
  return Bukkit.getScheduler().scheduleSyncRepeatingTask(plugin, task, delay, period);
}

代码示例来源:origin: Bukkit/Bukkit

/**
 * Attempts to cancel this task.
 *
 * @throws IllegalStateException if task was not scheduled yet
 */
public synchronized void cancel() throws IllegalStateException {
  Bukkit.getScheduler().cancelTask(getTaskId());
}

代码示例来源:origin: Bukkit/Bukkit

/**
 * Schedules this in the Bukkit scheduler to run on next tick.
 *
 * @param plugin the reference to the plugin scheduling task
 * @return a BukkitTask that contains the id number
 * @throws IllegalArgumentException if plugin is null
 * @throws IllegalStateException if this was already scheduled
 * @see BukkitScheduler#runTask(Plugin, Runnable)
 */
public synchronized BukkitTask runTask(Plugin plugin) throws IllegalArgumentException, IllegalStateException {
  checkState();
  return setupId(Bukkit.getScheduler().runTask(plugin, (Runnable) this));
}

代码示例来源:origin: Bukkit/Bukkit

/**
 * Schedules this to run after the specified number of server ticks.
 *
 * @param plugin the reference to the plugin scheduling task
 * @param delay the ticks to wait before running the task
 * @return a BukkitTask that contains the id number
 * @throws IllegalArgumentException if plugin is null
 * @throws IllegalStateException if this was already scheduled
 * @see BukkitScheduler#runTaskLater(Plugin, Runnable, long)
 */
public synchronized BukkitTask runTaskLater(Plugin plugin, long delay) throws IllegalArgumentException, IllegalStateException  {
  checkState();
  return setupId(Bukkit.getScheduler().runTaskLater(plugin, (Runnable) this, delay));
}

代码示例来源:origin: Bukkit/Bukkit

/**
 * Schedules this to repeatedly run until cancelled, starting after the
 * specified number of server ticks.
 *
 * @param plugin the reference to the plugin scheduling task
 * @param delay the ticks to wait before running the task
 * @param period the ticks to wait between runs
 * @return a BukkitTask that contains the id number
 * @throws IllegalArgumentException if plugin is null
 * @throws IllegalStateException if this was already scheduled
 * @see BukkitScheduler#runTaskTimer(Plugin, Runnable, long, long)
 */
public synchronized BukkitTask runTaskTimer(Plugin plugin, long delay, long period) throws IllegalArgumentException, IllegalStateException  {
  checkState();
  return setupId(Bukkit.getScheduler().runTaskTimer(plugin, (Runnable) this, delay, period));
}

代码示例来源:origin: Bukkit/Bukkit

/**
 * <b>Asynchronous tasks should never access any API in Bukkit. Great care
 * should be taken to assure the thread-safety of asynchronous tasks.</b>
 * <p>
 * Schedules this in the Bukkit scheduler to run asynchronously.
 *
 * @param plugin the reference to the plugin scheduling task
 * @return a BukkitTask that contains the id number
 * @throws IllegalArgumentException if plugin is null
 * @throws IllegalStateException if this was already scheduled
 * @see BukkitScheduler#runTaskAsynchronously(Plugin, Runnable)
 */
public synchronized BukkitTask runTaskAsynchronously(Plugin plugin) throws IllegalArgumentException, IllegalStateException  {
  checkState();
  return setupId(Bukkit.getScheduler().runTaskAsynchronously(plugin, (Runnable) this));
}

代码示例来源:origin: Bukkit/Bukkit

/**
 * <b>Asynchronous tasks should never access any API in Bukkit. Great care
 * should be taken to assure the thread-safety of asynchronous tasks.</b>
 * <p>
 * Schedules this to run asynchronously after the specified number of
 * server ticks.
 *
 * @param plugin the reference to the plugin scheduling task
 * @param delay the ticks to wait before running the task
 * @return a BukkitTask that contains the id number
 * @throws IllegalArgumentException if plugin is null
 * @throws IllegalStateException if this was already scheduled
 * @see BukkitScheduler#runTaskLaterAsynchronously(Plugin, Runnable, long)
 */
public synchronized BukkitTask runTaskLaterAsynchronously(Plugin plugin, long delay) throws IllegalArgumentException, IllegalStateException  {
  checkState();
  return setupId(Bukkit.getScheduler().runTaskLaterAsynchronously(plugin, (Runnable) this, delay));
}

代码示例来源:origin: Bukkit/Bukkit

/**
 * <b>Asynchronous tasks should never access any API in Bukkit. Great care
 * should be taken to assure the thread-safety of asynchronous tasks.</b>
 * <p>
 * Schedules this to repeatedly run asynchronously until cancelled,
 * starting after the specified number of server ticks.
 *
 * @param plugin the reference to the plugin scheduling task
 * @param delay the ticks to wait before running the task for the first
 *     time
 * @param period the ticks to wait between runs
 * @return a BukkitTask that contains the id number
 * @throws IllegalArgumentException if plugin is null
 * @throws IllegalStateException if this was already scheduled
 * @see BukkitScheduler#runTaskTimerAsynchronously(Plugin, Runnable, long,
 *     long)
 */
public synchronized BukkitTask runTaskTimerAsynchronously(Plugin plugin, long delay, long period) throws IllegalArgumentException, IllegalStateException  {
  checkState();
  return setupId(Bukkit.getScheduler().runTaskTimerAsynchronously(plugin, (Runnable) this, delay, period));
}

代码示例来源:origin: GlowstoneMC/Glowstone

/**
 * Saves the players current location, health, inventory, motion, and other information into the
 * username.dat file, in the world/player folder.
 *
 * @param async if true, save asynchronously; if false, block until saved
 */
public void saveData(boolean async) {
  if (async) {
    Bukkit.getScheduler().runTaskAsynchronously(null, () -> {
      server.getPlayerDataService().writeData(GlowPlayer.this);
      server.getPlayerStatisticIoService().writeStatistics(GlowPlayer.this);
    });
  } else {
    server.getPlayerDataService().writeData(this);
    server.getPlayerStatisticIoService().writeStatistics(this);
  }
}

代码示例来源:origin: GlowstoneMC/Glowstone

&& !knownEntities.contains(entity)
    && !hiddenEntities.contains(entity.getUniqueId()))
.forEach((entity) -> Bukkit.getScheduler()
    .runTaskAsynchronously(null, () -> {
      worldLock.readLock().lock();

代码示例来源:origin: NoCheatPlus/NoCheatPlus

/**
 * Cancel.
 */
public static void cancel() {
  if (taskId == -1) {
    return;
  }
  Bukkit.getScheduler().cancelTask(taskId);
  taskId = -1;
}

代码示例来源:origin: TheBusyBiscuit/Slimefun4

public static void update(final Block b, final String name) {
  Bukkit.getScheduler().scheduleSyncDelayedTask(SlimefunStartup.instance, new Runnable() {
    
    @Override
    public void run() {
      ArmorStand hologram = getArmorStand(b);
      hologram.setCustomName(ChatColor.translateAlternateColorCodes('&', name));
    }
  });
}

代码示例来源:origin: ProSavage/SavageFactions

public static void checkTaskState() {
  if (flyMap.keySet().size() == 0) {
    Bukkit.getScheduler().cancelTask(flyid);
    flyid = - 1;
  }
}

代码示例来源:origin: nsporillo/GlobalWarming

public void unregisterEffect(ClimateEffectType effectType) {
  ClimateEffect effect = effects.get(effectType);
  if (effect instanceof Listener) {
    HandlerList.unregisterAll((ListenerClimateEffect) effect);
  }
  if (effect instanceof ScheduleClimateEffect) {
    Bukkit.getScheduler().cancelTask(((ScheduleClimateEffect) effect).getTaskId());
  }
  effectClasses.remove(effectType);
  effects.remove(effectType);
}

代码示例来源:origin: FunnyGuilds/FunnyGuilds

public void start() {
  if (this.repeater != null) {
    return;
  }
  
  this.repeater = Bukkit.getScheduler().runTaskTimerAsynchronously(FunnyGuilds.getInstance(), this, 100, 20);
}

代码示例来源:origin: PyvesB/AdvancedAchievements

public void addFirework(Firework firework) {
    fireworksLaunchedByPlugin.add(firework.getUniqueId());

    // Schedule for removal to avoid creating memory leaks.
    Bukkit.getScheduler().runTaskLaterAsynchronously(advancedAchievements,
        () -> fireworksLaunchedByPlugin.remove(firework.getUniqueId()), 100);
  }
}

代码示例来源:origin: games647/ChangeSkin

@Override
  protected void scheduleChangeTask(String oldSkinUrl) {
    Runnable task = new SkinChanger(plugin, owner, url, oldSkinUrl, invoker);
    Bukkit.getScheduler().runTaskLaterAsynchronously(plugin, task, 60 * 20L);
  }
}

代码示例来源:origin: me.lucko/helper

private void executeDelayedSync(@Nonnull Runnable runnable, long delayTicks) {
  if (delayTicks <= 0) {
    executeSync(runnable);
  } else {
    Bukkit.getScheduler().runTaskLater(LoaderUtils.getPlugin(), HelperExecutors.wrapRunnable(runnable), delayTicks);
  }
}

代码示例来源:origin: MilkBowl/Vault

@Override
public void onDisable() {
  // Remove all Service Registrations
  getServer().getServicesManager().unregisterAll(this);
  Bukkit.getScheduler().cancelTasks(this);
}

代码示例来源:origin: games647/LagMonitor

@EventHandler
public void onPlayerJoin(PlayerJoinEvent joinEvent) {
  Player player = joinEvent.getPlayer();
  Bukkit.getScheduler().runTaskLater(plugin, () -> {
    if (player.isOnline()) {
      addPlayer(player);
    }
  }, PING_INTERVAL);
}

相关文章