Java Code Examples for org.bukkit.scheduler.BukkitRunnable#runTaskTimer()

The following examples show how to use org.bukkit.scheduler.BukkitRunnable#runTaskTimer() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: SimpleScoreboard.java    From ScoreboardLib with GNU Lesser General Public License v3.0 6 votes vote down vote up
@Override
public void activate() {
    if (activated) return;
    if (handler == null) throw new IllegalArgumentException("Scoreboard handler not set");
    activated = true;
    // Set to the custom scoreboard
    holder.setScoreboard(scoreboard);
    // And start updating on a desired interval
    updateTask = new BukkitRunnable() {
        @Override
        public void run() {
            update();
        }
    };
    updateTask.runTaskTimer(ScoreboardLib.getPluginInstance(), 0, updateInterval);
}
 
Example 2
Source File: TScheduleLoader.java    From TabooLib with MIT License 5 votes vote down vote up
public static void run(Plugin plugin, BukkitRunnable runnable, int delay, int period, boolean async) {
    if (async) {
        runnable.runTaskTimerAsynchronously(plugin, delay, period);
    } else {
        runnable.runTaskTimer(plugin, delay, period);
    }
}
 
Example 3
Source File: CreateIslandTask.java    From uSkyBlock with GNU General Public License v3.0 5 votes vote down vote up
@Override
public void run() {
    if (!plugin.getIslandGenerator().createIsland(playerPerk, next, cSchem)) {
        player.sendMessage(tr("Unable to locate schematic {0}, contact a server-admin", cSchem));
    }
    GenerateTask generateTask = new GenerateTask(plugin, player, playerPerk.getPlayerInfo(), next, playerPerk, cSchem);
    final int heartBeatTicks = (int) TimeUtil.millisAsTicks(plugin.getConfig().getInt("asyncworldedit.watchDog.heartBeatMs", 2000));
    final BukkitRunnable completionWatchDog = new LocateChestTask(plugin, player, next, generateTask);
    completionWatchDog.runTaskTimer(plugin, 0, heartBeatTicks);
}
 
Example 4
Source File: MobKillNotifier.java    From BetonQuest with GNU General Public License v3.0 5 votes vote down vote up
public MobKillNotifier() {
    instance = this;
    cleaner = new BukkitRunnable() {
        @Override
        public void run() {
            entities.clear();
        }
    };
    cleaner.runTaskTimer(BetonQuest.getInstance(), 1, 1);
}
 
Example 5
Source File: SentinelTrait.java    From Sentinel with MIT License 4 votes vote down vote up
/**
 * Handler for when the NPC died.
 */
public void onDeath() {
    greetedAlready.clear();
    targetingHelper.currentTargets.clear();
    targetingHelper.currentAvoids.clear();
    if (respawnTime < 0) {
        BukkitRunnable removeMe = new BukkitRunnable() {
            @Override
            public void run() {
                npc.destroy();
            }
        };
        removeMe.runTaskLater(SentinelPlugin.instance, 1);
    }
    else if (respawnTime > 0) {
        final long rsT = respawnTime;
        respawnMe = new BukkitRunnable() {
            long timer = 0;

            @Override
            public void run() {
                if (CitizensAPI.getNPCRegistry().getById(npc.getId()) != null) {
                    if (npc.isSpawned()) {
                        this.cancel();
                        respawnMe = null;
                        return;
                    }
                    if (timer >= rsT) {
                        if (spawnPoint == null && npc.getStoredLocation() == null) {
                            SentinelPlugin.instance.getLogger().warning("NPC " + npc.getId() + " has a null spawn point and can't be spawned. Perhaps the world was deleted?");
                            this.cancel();
                            return;
                        }
                        npc.spawn(spawnPoint == null ? npc.getStoredLocation() : spawnPoint);
                        this.cancel();
                        respawnMe = null;
                        return;
                    }
                    timer += 10;
                }
                else {
                    respawnMe = null;
                    this.cancel();
                    return;
                }
            }
        };
        respawnMe.runTaskTimer(SentinelPlugin.instance, 10, 10);
    }
    else { // respawnTime == 0
        npc.getTrait(Spawned.class).setSpawned(false);
    }
}
 
Example 6
Source File: BukkitService.java    From AuthMeReloaded with GNU General Public License v3.0 2 votes vote down vote up
/**
 * Schedules the given task to repeatedly run until cancelled, starting after the
 * specified number of server ticks.
 *
 * @param task the task to schedule
 * @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(org.bukkit.plugin.Plugin, Runnable, long, long)
 */
public BukkitTask runTaskTimer(BukkitRunnable task, long delay, long period) {
    return task.runTaskTimer(authMe, delay, period);
}