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

The following examples show how to use org.bukkit.scheduler.BukkitRunnable#runTaskTimerAsynchronously() . 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: 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 2
Source File: MenuConvIO.java    From BetonQuest with GNU General Public License v3.0 5 votes vote down vote up
/**
 * Displays all data to the player. Should be called after setting all
 * options.
 */
@Override
public void display() {
    if (npcText == null && options.isEmpty()) {
        end();
        return;
    }

    // Only want to hook the player when there are player options
    if (!started && options.size() > 0) {
        start();
    }

    // Update the Display automatically if configRefreshDelay is > 0
    if (configRefreshDelay > 0) {
        displayRunnable = new BukkitRunnable() {

            @Override
            public void run() {
                showDisplay();

                if (ended) {
                    this.cancel();
                }
            }
        };

        displayRunnable.runTaskTimerAsynchronously(BetonQuest.getInstance(), configRefreshDelay, configRefreshDelay);
    }

    updateDisplay();
}
 
Example 3
Source File: JoinsListener.java    From Statz with GNU General Public License v3.0 4 votes vote down vote up
@EventHandler(priority = EventPriority.MONITOR, ignoreCancelled = true)
public void onJoin(final PlayerJoinEvent event) {

	final PlayerStat stat = PlayerStat.JOINS;

	// Get player
	final Player player = event.getPlayer();

	// Do general check
	if (!plugin.doGeneralCheck(player, stat))
		return;

	// Update name in database.
	plugin.getDataManager().setPlayerInfo(player.getUniqueId(), PlayerStat.PLAYERS,
			StatzUtil.makeQuery("uuid", player.getUniqueId().toString(), "playerName", player.getName()));

	// Update value to new stat.
	plugin.getDataManager().setPlayerInfo(player.getUniqueId(), stat,
			StatzUtil.makeQuery("uuid", player.getUniqueId().toString(), "value", 1));

	// Check if player already has a checker running.
	if (!updateID.containsKey(player.getUniqueId())) {
		// Player has joined, so create a timer that runs every minute to add time.
		BukkitRunnable run = new BukkitRunnable() {
			public void run() {
				if (!player.isOnline()) {
                       updateID.remove(player.getUniqueId());
                       this.cancel();
                       return;
                   }

                   // Update value to new stat.
                   plugin.getDataManager().setPlayerInfo(player.getUniqueId(), PlayerStat.TIME_PLAYED,
                           StatzUtil.makeQuery("uuid", player.getUniqueId().toString(), "value", 1, "world",
                                   player.getWorld().getName()));

                   PlayerInfo playerinfo = plugin.getDataManager().getPlayerInfo(player.getUniqueId(),
                           PlayerStat.ITEMS_PICKED_UP);

                   for (Query query : playerinfo.getRows()) {

                   }

               }
		};

		BukkitTask task = run.runTaskTimerAsynchronously(plugin,
				20 * 60 /*If currentValue is 0, schedule a check immediately, otherwise after a minute*/,
				20 * 60 /*Every minute*/);

		updateID.put(player.getUniqueId(), task.getTaskId());
	}
}