Search in sources :

Example 1 with BukkitScheduler

use of org.bukkit.scheduler.BukkitScheduler in project MagicPlugin by elBukkit.

the class Mage method showHoloText.

@Override
public void showHoloText(Location location, String text, int duration) {
    // TODO: Broadcast
    if (!isPlayer())
        return;
    final Player player = getPlayer();
    if (hologram == null) {
        hologram = HoloUtils.createHoloText(location, text);
    } else {
        if (hologramIsVisible) {
            hologram.hide(player);
        }
        hologram.teleport(location);
        hologram.setLabel(text);
    }
    hologram.show(player);
    BukkitScheduler scheduler = Bukkit.getScheduler();
    if (duration > 0) {
        scheduler.scheduleSyncDelayedTask(controller.getPlugin(), new Runnable() {

            @Override
            public void run() {
                hologram.hide(player);
                hologramIsVisible = false;
            }
        }, duration);
    }
}
Also used : Player(org.bukkit.entity.Player) BukkitScheduler(org.bukkit.scheduler.BukkitScheduler)

Example 2 with BukkitScheduler

use of org.bukkit.scheduler.BukkitScheduler in project TokenManager by RealizedMC.

the class DataManager method handleUnload.

@Override
public void handleUnload() throws Exception {
    if (task != null) {
        final BukkitScheduler scheduler = Bukkit.getScheduler();
        if (scheduler.isCurrentlyRunning(task) || scheduler.isQueued(task)) {
            scheduler.cancelTask(task);
        }
    }
    database.save();
    database = null;
}
Also used : BukkitScheduler(org.bukkit.scheduler.BukkitScheduler)

Example 3 with BukkitScheduler

use of org.bukkit.scheduler.BukkitScheduler in project NoCheatPlus by NoCheatPlus.

the class NoCheatPlus method scheduleConsistencyCheckers.

private void scheduleConsistencyCheckers() {
    BukkitScheduler sched = getServer().getScheduler();
    if (consistencyCheckerTaskId != -1) {
        sched.cancelTask(consistencyCheckerTaskId);
    }
    ConfigFile config = ConfigManager.getConfigFile();
    if (!config.getBoolean(ConfPaths.DATA_CONSISTENCYCHECKS_CHECK, true)) {
        return;
    }
    // Schedule task in seconds.
    final long delay = 20L * config.getInt(ConfPaths.DATA_CONSISTENCYCHECKS_INTERVAL, 1, 3600, 10);
    consistencyCheckerTaskId = sched.scheduleSyncRepeatingTask(this, new Runnable() {

        @Override
        public void run() {
            runConsistencyChecks();
        }
    }, delay, delay);
}
Also used : ConfigFile(fr.neatmonster.nocheatplus.config.ConfigFile) IPostRegisterRunnable(fr.neatmonster.nocheatplus.components.registry.feature.IPostRegisterRunnable) BukkitScheduler(org.bukkit.scheduler.BukkitScheduler)

Example 4 with BukkitScheduler

use of org.bukkit.scheduler.BukkitScheduler in project AuthMeReloaded by AuthMe.

the class AuthMeInitializationTest method shouldHandlePrematureShutdownGracefully.

@Test
public void shouldHandlePrematureShutdownGracefully() {
    // given
    BukkitScheduler scheduler = mock(BukkitScheduler.class);
    given(server.getScheduler()).willReturn(scheduler);
    // Make sure ConsoleLogger has no logger reference since that may happen on unexpected stops
    ReflectionTestUtils.setField(ConsoleLogger.class, null, "logger", null);
    // when
    authMe.onDisable();
    // then - no exceptions
    // via TaskCloser
    verify(scheduler).getActiveWorkers();
}
Also used : BukkitScheduler(org.bukkit.scheduler.BukkitScheduler) Test(org.junit.Test)

Example 5 with BukkitScheduler

use of org.bukkit.scheduler.BukkitScheduler in project Prism-Bukkit by prism.

the class InternalAffairs method run.

@Override
public void run() {
    if (plugin.recordingTask != null) {
        final int taskId = plugin.recordingTask.getTaskId();
        final BukkitScheduler scheduler = Bukkit.getScheduler();
        // is recording task running?
        if (scheduler.isCurrentlyRunning(taskId) || scheduler.isQueued(taskId)) {
            Prism.debug("[InternalAffairs] Recorder is currently active. All is good.");
            return;
        }
    }
    Prism.log("[InternalAffairs] Recorder is NOT active... checking database");
    // is db connection valid?
    try (Connection conn = Prism.getPrismDataSource().getConnection()) {
        if (conn == null) {
            Prism.log("[InternalAffairs] Pool returned NULL instead of a valid connection.");
        } else if (conn.isClosed()) {
            Prism.log("[InternalAffairs] Pool returned an already closed connection.");
        } else if (conn.isValid(5)) {
            Prism.log("[InternalAffairs] Pool returned valid connection!");
            Prism.log("[InternalAffairs] Restarting scheduled recorder tasks");
            plugin.actionRecorderTask();
        }
    } catch (final SQLException e) {
        Prism.debug("[InternalAffairs] Error: " + e.getMessage());
        e.printStackTrace();
    }
}
Also used : SQLException(java.sql.SQLException) Connection(java.sql.Connection) BukkitScheduler(org.bukkit.scheduler.BukkitScheduler)

Aggregations

BukkitScheduler (org.bukkit.scheduler.BukkitScheduler)14 Server (org.bukkit.Server)4 BukkitTask (org.bukkit.scheduler.BukkitTask)3 Test (org.junit.Test)3 Player (org.bukkit.entity.Player)2 PluginDescriptionFile (org.bukkit.plugin.PluginDescriptionFile)2 Matchers.containsString (org.hamcrest.Matchers.containsString)2 ArgumentMatchers.anyString (org.mockito.ArgumentMatchers.anyString)2 IDisableListener (fr.neatmonster.nocheatplus.components.registry.feature.IDisableListener)1 IPostRegisterRunnable (fr.neatmonster.nocheatplus.components.registry.feature.IPostRegisterRunnable)1 ConfigFile (fr.neatmonster.nocheatplus.config.ConfigFile)1 Counters (fr.neatmonster.nocheatplus.stats.Counters)1 File (java.io.File)1 MalformedURLException (java.net.MalformedURLException)1 NoSuchAlgorithmException (java.security.NoSuchAlgorithmException)1 Connection (java.sql.Connection)1 SQLException (java.sql.SQLException)1 ArrayList (java.util.ArrayList)1 UUID (java.util.UUID)1 CancellationException (java.util.concurrent.CancellationException)1