Java Code Examples for org.bukkit.scheduler.BukkitScheduler#runTaskTimer()
The following examples show how to use
org.bukkit.scheduler.BukkitScheduler#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: ChunkRegenerator.java From uSkyBlock with GNU General Public License v3.0 | 6 votes |
/** * Regenerates the given list of {@link Chunk}s at the configured chunks/tick speed (default: 4). * @param chunkList List of chunks to regenerate. * @param onCompletion Runnable to schedule on completion, or null to call no runnable. */ public void regenerateChunks(@NotNull List<Chunk> chunkList, @Nullable Runnable onCompletion) { Validate.notNull(chunkList, "ChunkList cannot be empty"); final int CHUNKS_PER_TICK = plugin.getConfig().getInt("options.advanced.chunkRegenSpeed", 4); BukkitScheduler scheduler = plugin.getServer().getScheduler(); task = scheduler.runTaskTimer(plugin, () -> { for (int i = 0; i <= CHUNKS_PER_TICK; i++) { if (!chunkList.isEmpty()) { Chunk chunk = chunkList.remove(0); regenerateChunk(chunk); } else { if (onCompletion != null) { scheduler.runTaskLater(plugin, onCompletion, 1L); } task.cancel(); break; } } }, 0L, 1L); }
Example 2
Source File: ExploitFixer.java From ExploitFixer with GNU General Public License v3.0 | 5 votes |
@Override public void onEnable() { final Server server = this.getServer(); final BukkitScheduler scheduler = server.getScheduler(); this.configurationUtil = new ConfigurationUtil(this); createConfigurations(); final YamlConfiguration configYml = this.configurationUtil.getConfiguration("%datafolder%/config.yml"); final YamlConfiguration messagesYml = this.configurationUtil.getConfiguration("%datafolder%/messages.yml"); VersionUtil.initialize(server); exploitFixer = this; this.moduleManager = new ModuleManager(this, configYml, messagesYml); this.listenerInitializer = new ListenerInitializer(this, moduleManager); registerListeners(); registerCommands(); if (checkHamsterAPI()) { server.getMessenger().registerOutgoingPluginChannel(this, "BungeeCord"); this.hamsterAPIListenerInitializer = new HamsterAPIListenerInitializer(this, moduleManager); registerHamsterApi(); } else { scheduler.runTaskTimer(this, () -> this.getLogger().severe( "ExploitFixer requires HamsterAPI 0.0.8 or newer to work! Download: https://www.spigotmc.org/resources/78831/"), 20L, 20L); } scheduler.runTaskTimerAsynchronously(this, () -> { final ExploitPlayerManager exploitPlayerManager = moduleManager.getExploitPlayerManager(); exploitPlayerManager.clear(); }, 9000L, 9000L); }
Example 3
Source File: FlagAntiCamping.java From HeavySpleef with GNU General Public License v3.0 | 5 votes |
@FlagInit public static void initTask(HeavySpleef heavySpleef) { BukkitScheduler scheduler = Bukkit.getScheduler(); task = new AntiCampingTask(heavySpleef); bukkitTask = scheduler.runTaskTimer(heavySpleef.getPlugin(), task, ONE_SECOND_INTERVAL, ONE_SECOND_INTERVAL); }
Example 4
Source File: CombatLogX.java From CombatLogX with GNU General Public License v3.0 | 4 votes |
private void registerTasks() { BukkitScheduler scheduler = Bukkit.getScheduler(); CombatManager combatManager = getCombatManager(); scheduler.runTaskTimer(this, combatManager, 0L, 10L); }
Example 5
Source File: LagMonitor.java From LagMonitor with MIT License | 4 votes |
@Override public void onEnable() { saveDefaultConfig(); if (Files.notExists(getDataFolder().toPath().resolve("default.jfc"))) { saveResource("default.jfc", false); } //register schedule tasks BukkitScheduler scheduler = getServer().getScheduler(); scheduler.runTaskTimer(this, tpsHistoryTask, 20L, TPSHistoryTask.RUN_INTERVAL); scheduler.runTaskTimer(this, pingManager, 20L, PingManager.PING_INTERVAL); //register listeners PluginManager pluginManager = getServer().getPluginManager(); pluginManager.registerEvents(new GraphListener(), this); pluginManager.registerEvents(pageManager, this); pluginManager.registerEvents(pingManager, this); //add the player to the list in the case the plugin is loaded at runtime Bukkit.getOnlinePlayers().forEach(pingManager::addPlayer); if (getConfig().getBoolean("traffic-counter")) { try { trafficReader = new TrafficReader(this); } catch (Exception ex) { getLogger().log(Level.SEVERE, "Failed to initialize packet reader", ex); } } if (getConfig().getBoolean("thread-safety-check")) { pluginManager.registerEvents(new ThreadSafetyListener(actionManager), this); } if (getConfig().getBoolean("thread-block-detection")) { scheduler.runTask(this, () -> { blockDetectionTimer = new Timer(getName() + "-Thread-Blocking-Detection"); IODetectorTask detectorTask = new IODetectorTask(actionManager, Thread.currentThread()); blockDetectionTimer.scheduleAtFixedRate(detectorTask, DETECTION_THRESHOLD, DETECTION_THRESHOLD); }); } if (getConfig().getBoolean("monitor-database")) { setupMonitoringDatabase(); } if (getConfig().getBoolean("socket-block-detection")) { scheduler.runTask(this, () -> new BlockingConnectionSelector(actionManager).inject()); } if (getConfig().getBoolean("securityMangerBlockingCheck")) { scheduler.runTask(this, () -> new BlockingSecurityManager(actionManager).inject()); } registerCommands(); }
Example 6
Source File: LagMonitor.java From LagMonitor with MIT License | 4 votes |
@Override public void onEnable() { saveDefaultConfig(); if (Files.notExists(getDataFolder().toPath().resolve("default.jfc"))) { saveResource("default.jfc", false); } //register schedule tasks BukkitScheduler scheduler = getServer().getScheduler(); scheduler.runTaskTimer(this, tpsHistoryTask, 20L, TPSHistoryTask.RUN_INTERVAL); scheduler.runTaskTimer(this, pingManager, 20L, PingManager.PING_INTERVAL); //register listeners PluginManager pluginManager = getServer().getPluginManager(); pluginManager.registerEvents(new GraphListener(), this); pluginManager.registerEvents(pageManager, this); pluginManager.registerEvents(pingManager, this); //add the player to the list in the case the plugin is loaded at runtime Bukkit.getOnlinePlayers().forEach(pingManager::addPlayer); if (getConfig().getBoolean("traffic-counter")) { try { trafficReader = new TrafficReader(this); } catch (Exception ex) { getLogger().log(Level.SEVERE, "Failed to initialize packet reader", ex); } } if (getConfig().getBoolean("thread-safety-check")) { pluginManager.registerEvents(new ThreadSafetyListener(actionManager), this); } if (getConfig().getBoolean("thread-block-detection")) { scheduler.runTask(this, () -> { blockDetectionTimer = new Timer(getName() + "-Thread-Blocking-Detection"); IODetectorTask detectorTask = new IODetectorTask(actionManager, Thread.currentThread()); blockDetectionTimer.scheduleAtFixedRate(detectorTask, DETECTION_THRESHOLD, DETECTION_THRESHOLD); }); } if (getConfig().getBoolean("monitor-database")) { setupMonitoringDatabase(); } if (getConfig().getBoolean("socket-block-detection")) { scheduler.runTask(this, () -> new BlockingConnectionSelector(actionManager).inject()); } if (getConfig().getBoolean("securityMangerBlockingCheck")) { scheduler.runTask(this, () -> new BlockingSecurityManager(actionManager).inject()); } registerCommands(); }
Example 7
Source File: EffectManager.java From EffectLib with MIT License | 4 votes |
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); } }