Search in sources :

Example 6 with BukkitScheduler

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

the class AbstractCommand method checkRecorderActive.

@SuppressWarnings("WeakerAccess")
protected static boolean checkRecorderActive(Prism plugin) {
    boolean recorderActive = false;
    if (plugin.recordingTask != null) {
        final int taskId = plugin.recordingTask.getTaskId();
        final BukkitScheduler scheduler = Bukkit.getScheduler();
        if (scheduler.isCurrentlyRunning(taskId) || scheduler.isQueued(taskId)) {
            recorderActive = true;
        }
    }
    return recorderActive;
}
Also used : BukkitScheduler(org.bukkit.scheduler.BukkitScheduler)

Example 7 with BukkitScheduler

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

the class ThrustSpell method onDeactivate.

@Override
public void onDeactivate() {
    if (taskId != null) {
        BukkitScheduler scheduler = Bukkit.getScheduler();
        scheduler.cancelTask(taskId);
    }
    taskId = null;
}
Also used : BukkitScheduler(org.bukkit.scheduler.BukkitScheduler)

Example 8 with BukkitScheduler

use of org.bukkit.scheduler.BukkitScheduler in project EffectLib by Slikey.

the class EffectManager method start.

public void start(Effect effect) {
    if (disposed) {
        throw new IllegalStateException("EffectManager is disposed and not able to accept any effects.");
    }
    if (disposeOnTermination) {
        throw new IllegalStateException("EffectManager is awaiting termination to dispose and not able to accept any effects.");
    }
    if (effects.containsKey(effect)) {
        effect.cancel(false);
    }
    if (!owningPlugin.isEnabled())
        return;
    BukkitScheduler s = Bukkit.getScheduler();
    BukkitTask task = null;
    switch(effect.getType()) {
        case INSTANT:
            if (effect.isAsynchronous()) {
                task = s.runTaskAsynchronously(owningPlugin, effect);
            } else {
                task = s.runTask(owningPlugin, effect);
            }
            break;
        case DELAYED:
            if (effect.isAsynchronous()) {
                task = s.runTaskLaterAsynchronously(owningPlugin, effect, effect.getDelay());
            } else {
                task = s.runTaskLater(owningPlugin, effect, effect.getDelay());
            }
            break;
        case REPEATING:
            if (effect.isAsynchronous()) {
                task = s.runTaskTimerAsynchronously(owningPlugin, effect, effect.getDelay(), effect.getPeriod());
            } else {
                task = s.runTaskTimer(owningPlugin, effect, effect.getDelay(), effect.getPeriod());
            }
            break;
    }
    synchronized (this) {
        effects.put(effect, task);
    }
}
Also used : BukkitTask(org.bukkit.scheduler.BukkitTask) BukkitScheduler(org.bukkit.scheduler.BukkitScheduler)

Example 9 with BukkitScheduler

use of org.bukkit.scheduler.BukkitScheduler in project Bukkit_Bungee_PluginLib by GeorgH93.

the class TestObjects method initMockedJavaPlugin.

public static void initMockedJavaPlugin() throws Exception {
    BukkitScheduler mockedScheduler = mock(BukkitScheduler.class);
    when(mockedScheduler.runTask(any(org.bukkit.plugin.Plugin.class), any(Runnable.class))).thenAnswer(new Answer<Object>() {

        @Override
        public Object answer(InvocationOnMock invocationOnMock) throws Throwable {
            ((Runnable) invocationOnMock.getArguments()[1]).run();
            return null;
        }
    });
    Server mockedServer = mock(Server.class);
    when(mockedServer.getScheduler()).thenReturn(mockedScheduler);
    mockedJavaPlugin = PowerMockito.mock(JavaPlugin.class);
    when(mockedJavaPlugin.getLogger()).thenReturn(Logger.getLogger("TestLogger"));
    when(mockedJavaPlugin.getDataFolder()).thenReturn(new File(""));
    when(mockedJavaPlugin.getServer()).thenReturn(mockedServer);
}
Also used : Server(org.bukkit.Server) ProxyServer(net.md_5.bungee.api.ProxyServer) InvocationOnMock(org.mockito.invocation.InvocationOnMock) BukkitScheduler(org.bukkit.scheduler.BukkitScheduler) JavaPlugin(org.bukkit.plugin.java.JavaPlugin) File(java.io.File) PluginDescriptionFile(org.bukkit.plugin.PluginDescriptionFile) JavaPlugin(org.bukkit.plugin.java.JavaPlugin) Plugin(net.md_5.bungee.api.plugin.Plugin)

Example 10 with BukkitScheduler

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

the class NoCheatPlus method onDisable.

/**
 * (Called on the plugin getting disabled.)
 * <hr>
 * Rough order of disabling:<br>
 * <ul>
 * <li>Prevent further registration. For now also disable listeners, though
 * this might get shifted still.</li>
 * <li><b>Call onDisable for IDisableListener instances, in reversed
 * order of registration.</b> This includes clearing all data (Needs extensions for sorting
 * by priority for IDisableListener instances.).</li>
 * <li>Random sequence of cleanup calls for other registries and logging
 * statistics.</li>
 * <li>Call removeComponent for all registered components.</li>
 * <li>Cleanup BlockProperties and clear most internal mappings for
 * components (needs a more clean registry approach).</li>
 * <li>(Command changes cleanup: currently disabled due to compatibility
 * issues, could cause other issues with dynamic plugin managers.)</li>
 * <li>Cleanup ConfigManager.</li>
 * <li>Shutdown LogManager.</li>
 * </ul>
 */
@Override
public void onDisable() {
    final boolean verbose = ConfigManager.getConfigFile().getBoolean(ConfPaths.LOGGING_EXTENDED_STATUS);
    // Remove listener references.
    if (verbose) {
        logManager.info(Streams.INIT, "Cleanup event registry (Bukkit)...");
    }
    // TODO: Prevent register feature ?
    eventRegistry.clear();
    BukkitScheduler sched = getServer().getScheduler();
    // Stop data-man task.
    if (dataManTaskId != -1) {
        sched.cancelTask(dataManTaskId);
        dataManTaskId = -1;
    }
    // Stop the tickTask.
    if (verbose) {
        logManager.info(Streams.INIT, "Stop TickTask...");
    }
    TickTask.setLocked(true);
    TickTask.purge();
    TickTask.cancel();
    TickTask.removeAllTickListeners();
    // Stop consistency checking task.
    if (consistencyCheckerTaskId != -1) {
        sched.cancelTask(consistencyCheckerTaskId);
        consistencyCheckerTaskId = -1;
    }
    // Just to be sure nothing gets left out.
    if (verbose) {
        logManager.info(Streams.INIT, "Stop all remaining tasks...");
    }
    sched.cancelTasks(this);
    // DisableListener.onDisable (includes DataManager cleanup.)
    if (verbose) {
        logManager.info(Streams.INIT, "onDisable calls (include DataManager cleanup)...");
    }
    // TODO: Reliable sorting order + sort now (checks and data cleanup late, data manager last, allow plugins to access stuff before data is reset).
    final ArrayList<IDisableListener> disableListeners = new ArrayList<IDisableListener>(this.disableListeners);
    Collections.reverse(disableListeners);
    for (final IDisableListener dl : disableListeners) {
        try {
            dl.onDisable();
        } catch (Throwable t) {
            logManager.severe(Streams.INIT, "IDisableListener (" + dl.getClass().getName() + "): " + t.getClass().getSimpleName() + " / " + t.getMessage());
            logManager.severe(Streams.INIT, t);
        }
    }
    // ExemptionManager cleanup.
    if (verbose) {
        logManager.info(Streams.INIT, "Reset ExemptionManager...");
    }
    NCPExemptionManager.clear();
    // Remove hooks.
    allViolationsHook.unregister();
    NCPHookManager.removeAllHooks();
    // Write some debug/statistics.
    final Counters counters = getGenericInstance(Counters.class);
    if (counters != null) {
        // Ensure we get this kind of information for the time being.
        if (verbose) {
            // Server logger needs info level.
            logManager.info(Streams.INIT, counters.getMergedCountsString(true));
        } else {
            logManager.debug(Streams.TRACE_FILE, counters.getMergedCountsString(true));
        }
    }
    // Unregister all added components explicitly (reverse order).
    if (verbose) {
        logManager.info(Streams.INIT, "Unregister all registered components...");
    }
    final ArrayList<Object> components = new ArrayList<Object>(this.allComponents);
    for (int i = components.size() - 1; i >= 0; i--) {
        removeComponent(components.get(i));
    }
    // Cleanup BlockProperties.
    if (verbose) {
        logManager.info(Streams.INIT, "Cleanup BlockProperties...");
    }
    BlockProperties.cleanup();
    if (verbose) {
        logManager.info(Streams.INIT, "Cleanup some mappings...");
    }
    // Remove IDisableListener instances.
    // Just in case.
    disableListeners.clear();
    // Remove listeners.
    listeners.clear();
    // Remove config listeners.
    notifyReload.clear();
    // Sub registries.
    subRegistries.clear();
    // Just in case: clear the subComponentHolders.
    subComponentholders.clear();
    // Generic instances registry.
    genericInstanceRegistry.clear();
    // Feature tags.
    featureTags.clear();
    // BlockChangeTracker.
    if (blockChangeListener != null) {
        blockChangeListener.setEnabled(false);
        // Only on disable.
        blockChangeListener = null;
    }
    blockChangeTracker.clear();
    // Restore changed commands.
    // if (verbose) LogUtil.logInfo("Undo command changes...");
    // undoCommandChanges();
    // Clear command changes list (compatibility issues with NPCs, leads to recalculation of perms).
    changedCommands.clear();
    // Cleanup the configuration manager.
    if (verbose) {
        logManager.info(Streams.INIT, "Cleanup ConfigManager...");
    }
    ConfigManager.cleanup();
    // Cleanup file logger.
    if (verbose) {
        logManager.info(Streams.INIT, "Shutdown LogManager...");
    }
    StaticLog.setUseLogManager(false);
    StaticLog.setStreamID(Streams.INIT);
    logManager.shutdown();
    // Tell the server administrator that we finished unloading NoCheatPlus.
    if (verbose) {
        // Bukkit logger.
        Bukkit.getLogger().info("[NoCheatPlus] All cleanup done.");
    }
    final PluginDescriptionFile pdfFile = getDescription();
    // Bukkit logger.
    Bukkit.getLogger().info("[NoCheatPlus] Version " + pdfFile.getVersion() + " is disabled.");
}
Also used : IDisableListener(fr.neatmonster.nocheatplus.components.registry.feature.IDisableListener) ArrayList(java.util.ArrayList) BukkitScheduler(org.bukkit.scheduler.BukkitScheduler) PluginDescriptionFile(org.bukkit.plugin.PluginDescriptionFile) Counters(fr.neatmonster.nocheatplus.stats.Counters)

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