org.bukkit.scheduler.BukkitScheduler Java Examples
The following examples show how to use
org.bukkit.scheduler.BukkitScheduler.
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: ListenerRiptide.java From CombatLogX with GNU General Public License v3.0 | 6 votes |
private void sendMessage(Player player) { if(player == null) return; UUID uuid = player.getUniqueId(); if(messageCooldownList.contains(uuid)) return; String message = this.plugin.getLanguageMessageColoredWithPrefix("cheat-prevention.no-riptide"); this.plugin.sendMessage(player, message); messageCooldownList.add(uuid); BukkitScheduler scheduler = Bukkit.getScheduler(); Runnable task = () -> messageCooldownList.remove(uuid); FileConfiguration config = this.expansion.getConfig("cheat-prevention.yml"); long messageCooldown = 20L * config.getLong("message-cooldown"); scheduler.runTaskLater(this.plugin.getPlugin(), task, messageCooldown); }
Example #2
Source File: PurgeTaskTest.java From AuthMeReloaded with GNU General Public License v3.0 | 6 votes |
@Test public void shouldStopTaskAndInformConsoleUser() { // given Set<String> names = newHashSet("name1", "name2"); PurgeTask task = new PurgeTask(purgeService, permissionsManager, null, names, new OfflinePlayer[0]); BukkitTask bukkitTask = mock(BukkitTask.class); given(bukkitTask.getTaskId()).willReturn(10049); ReflectionTestUtils.setField(BukkitRunnable.class, task, "task", bukkitTask); Server server = mock(Server.class); BukkitScheduler scheduler = mock(BukkitScheduler.class); given(server.getScheduler()).willReturn(scheduler); ReflectionTestUtils.setField(Bukkit.class, null, "server", server); ConsoleCommandSender consoleSender = mock(ConsoleCommandSender.class); given(server.getConsoleSender()).willReturn(consoleSender); task.run(); // Run for the first time -> results in empty names list // when task.run(); // then verify(scheduler).cancelTask(task.getTaskId()); verify(consoleSender).sendMessage(argThat(containsString("Database has been purged successfully"))); }
Example #3
Source File: LukkitCommand.java From Lukkit with MIT License | 6 votes |
@Override public boolean execute(CommandSender sender, String command, String[] args) { if (!this.testPermissionSilent(sender)) { sender.sendMessage(ERROR_NO_PERMISSION); return true; } try { if (args.length > maxArgs && maxArgs >= 0) { sender.sendMessage(ERROR_TOO_MANY_ARGS); } else if (args.length < minArgs) { sender.sendMessage(ERROR_MISSING_ARGS); } else { if (runAsync) { BukkitScheduler scheduler = Bukkit.getScheduler(); scheduler.runTaskAsynchronously(plugin, () -> function.invoke(new LuaValue[]{new CommandEvent(sender, command, args)})); } else { function.invoke(new LuaValue[]{new CommandEvent(sender, command, args)}); } } } catch (LukkitPluginException e) { e.printStackTrace(); LuaEnvironment.addError(e); } return true; }
Example #4
Source File: PerWorldInventoryInitializationTest.java From PerWorldInventory with GNU General Public License v3.0 | 6 votes |
@Before public void setUpPlugin() throws IOException { dataFolder = temporaryFolder.newFolder(); // Wire various Bukkit components setField(Bukkit.class, "server", null, server); given(server.getLogger()).willReturn(mock(Logger.class)); given(server.getScheduler()).willReturn(mock(BukkitScheduler.class)); given(server.getPluginManager()).willReturn(pluginManager); given(server.getVersion()).willReturn("1.9.4-RC1"); // SettingsManager always returns the default given(settings.getProperty(any(Property.class))).willAnswer(new Answer<Object>() { @Override public Object answer(InvocationOnMock invocation) throws Throwable { return ((Property<?>) invocation.getArguments()[0]).getDefaultValue(); } }); // PluginDescriptionFile is final and so cannot be mocked PluginDescriptionFile descriptionFile = new PluginDescriptionFile( "PerWorldInventory", "N/A", PerWorldInventory.class.getCanonicalName()); JavaPluginLoader pluginLoader = new JavaPluginLoader(server); plugin = new PerWorldInventory(pluginLoader, descriptionFile, dataFolder, null); setField(JavaPlugin.class, "logger", plugin, mock(PluginLogger.class)); }
Example #5
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 #6
Source File: SkullCommand.java From ChangeSkin with MIT License | 6 votes |
@Override public boolean onCommand(CommandSender sender, Command command, String label, String[] args) { if (!(sender instanceof Player)) { plugin.sendMessage(sender, "no-console"); return true; } if (args.length == 0) { plugin.sendMessage(sender, "select-noargs"); } else { String targetName = args[0].toLowerCase().replace("skin-", ""); try { Player player = (Player) sender; int targetId = Integer.parseInt(targetName); BukkitScheduler scheduler = Bukkit.getScheduler(); scheduler.runTaskAsynchronously(plugin, () -> applySkin(player, plugin.getStorage().getSkin(targetId))); } catch (NumberFormatException numberFormatException) { plugin.sendMessage(sender, "invalid-skin-name"); } } return true; }
Example #7
Source File: LagMonitor.java From LagMonitor with MIT License | 6 votes |
private void setupMonitoringDatabase() { try { String host = getConfig().getString("host"); int port = getConfig().getInt("port"); String database = getConfig().getString("database"); boolean usessl = getConfig().getBoolean("usessl"); String username = getConfig().getString("username"); String password = getConfig().getString("password"); String tablePrefix = getConfig().getString("tablePrefix"); Storage storage = new Storage(getLogger(), host, port, database, usessl, username, password, tablePrefix); storage.createTables(); BukkitScheduler scheduler = getServer().getScheduler(); scheduler.runTaskTimerAsynchronously(this, new TPSSaveTask(tpsHistoryTask, storage), 20L, getConfig().getInt("tps-save-interval") * 20L); //this can run async because it runs independently from the main thread scheduler.runTaskTimerAsynchronously(this, new MonitorSaveTask(this, storage), 20L,getConfig().getInt("monitor-save-interval") * 20L); scheduler.runTaskTimerAsynchronously(this, new NativeSaveTask(this, storage), 20L,getConfig().getInt("native-save-interval") * 20L); } catch (SQLException sqlEx) { getLogger().log(Level.SEVERE, "Failed to setup monitoring database", sqlEx); } }
Example #8
Source File: PerWorldInventoryInitializationTest.java From PerWorldInventory with GNU General Public License v3.0 | 6 votes |
@Before public void setUpPlugin() throws IOException { dataFolder = temporaryFolder.newFolder(); // Wire various Bukkit components setField(Bukkit.class, "server", null, server); given(server.getLogger()).willReturn(mock(Logger.class)); given(server.getScheduler()).willReturn(mock(BukkitScheduler.class)); given(server.getPluginManager()).willReturn(pluginManager); given(server.getVersion()).willReturn("1.9.4-RC1"); // SettingsManager always returns the default given(settings.getProperty(any(Property.class))).willAnswer(new Answer<Object>() { @Override public Object answer(InvocationOnMock invocation) throws Throwable { return ((Property<?>) invocation.getArguments()[0]).getDefaultValue(); } }); // PluginDescriptionFile is final and so cannot be mocked PluginDescriptionFile descriptionFile = new PluginDescriptionFile( "PerWorldInventory", "N/A", PerWorldInventory.class.getCanonicalName()); JavaPluginLoader pluginLoader = new JavaPluginLoader(server); plugin = new PerWorldInventory(pluginLoader, descriptionFile, dataFolder, null); setField(JavaPlugin.class, "logger", plugin, mock(PluginLogger.class)); }
Example #9
Source File: LagMonitor.java From LagMonitor with MIT License | 6 votes |
private void setupMonitoringDatabase() { try { String host = getConfig().getString("host"); int port = getConfig().getInt("port"); String database = getConfig().getString("database"); boolean usessl = getConfig().getBoolean("usessl"); String username = getConfig().getString("username"); String password = getConfig().getString("password"); String tablePrefix = getConfig().getString("tablePrefix"); Storage storage = new Storage(getLogger(), host, port, database, usessl, username, password, tablePrefix); storage.createTables(); BukkitScheduler scheduler = getServer().getScheduler(); scheduler.runTaskTimerAsynchronously(this, new TPSSaveTask(tpsHistoryTask, storage), 20L, getConfig().getInt("tps-save-interval") * 20L); //this can run async because it runs independently from the main thread scheduler.runTaskTimerAsynchronously(this, new MonitorSaveTask(this, storage), 20L,getConfig().getInt("monitor-save-interval") * 20L); scheduler.runTaskTimerAsynchronously(this, new NativeSaveTask(this, storage), 20L,getConfig().getInt("native-save-interval") * 20L); } catch (SQLException sqlEx) { getLogger().log(Level.SEVERE, "Failed to setup monitoring database", sqlEx); } }
Example #10
Source File: NoEntryExpansion.java From CombatLogX with GNU General Public License v3.0 | 6 votes |
public final void sendNoEntryMessage(Player player, LivingEntity enemy) { if(player == null || enemy == null) return; UUID uuid = player.getUniqueId(); if(noEntryMessageCooldownList.contains(uuid)) return; NoEntryHandler handler = getNoEntryHandler(); TagType tagType = (enemy instanceof Player ? TagType.PLAYER : TagType.MOB); String messagePath = handler.getNoEntryMessagePath(tagType); ICombatLogX plugin = getPlugin(); String message = plugin.getLanguageMessageColoredWithPrefix(messagePath); plugin.sendMessage(player, message); noEntryMessageCooldownList.add(uuid); long cooldown = handler.getNoEntryMessageCooldown(); long delay = (cooldown * 20L); BukkitScheduler scheduler = Bukkit.getScheduler(); scheduler.runTaskLaterAsynchronously(plugin.getPlugin(), () -> noEntryMessageCooldownList.remove(uuid), delay); }
Example #11
Source File: ListenerNewItemPickup.java From CombatLogX with GNU General Public License v3.0 | 6 votes |
private void sendMessage(Player player) { if(player == null) return; UUID uuid = player.getUniqueId(); if(messageCooldownList.contains(uuid)) return; String message = this.plugin.getLanguageMessageColoredWithPrefix("cheat-prevention.items.no-pickup"); this.plugin.sendMessage(player, message); messageCooldownList.add(uuid); BukkitScheduler scheduler = Bukkit.getScheduler(); Runnable task = () -> messageCooldownList.remove(uuid); FileConfiguration config = this.expansion.getConfig("cheat-prevention.yml"); long messageCooldown = 20L * config.getLong("message-cooldown"); scheduler.runTaskLater(this.plugin.getPlugin(), task, messageCooldown); }
Example #12
Source File: ListenerBlocks.java From CombatLogX with GNU General Public License v3.0 | 6 votes |
private void sendMessageWithCooldown(Player player, String path) { if(player == null || path == null || path.isEmpty()) return; List<UUID> messageCooldownList = messagePathToCooldownList.getOrDefault(path, Util.newList()); UUID uuid = player.getUniqueId(); if(messageCooldownList.contains(uuid)) return; String message = this.plugin.getLanguageMessageColoredWithPrefix(path); this.plugin.sendMessage(player, message); messageCooldownList.add(uuid); messagePathToCooldownList.put(path, messageCooldownList); BukkitScheduler scheduler = Bukkit.getScheduler(); Runnable task = () -> removeCooldown(player, path); FileConfiguration config = this.expansion.getConfig("cheat-prevention.yml"); long messageCooldown = 20L * config.getLong("message-cooldown"); scheduler.runTaskLater(this.plugin.getPlugin(), task, messageCooldown); }
Example #13
Source File: ListenerLegacyItemPickup.java From CombatLogX with GNU General Public License v3.0 | 6 votes |
private void sendMessage(Player player) { if(player == null) return; UUID uuid = player.getUniqueId(); if(messageCooldownList.contains(uuid)) return; String message = this.plugin.getLanguageMessageColoredWithPrefix("cheat-prevention.items.no-pickup"); this.plugin.sendMessage(player, message); messageCooldownList.add(uuid); BukkitScheduler scheduler = Bukkit.getScheduler(); Runnable task = () -> messageCooldownList.remove(uuid); FileConfiguration config = this.expansion.getConfig("cheat-prevention.yml"); long messageCooldown = 20L * config.getLong("message-cooldown"); scheduler.runTaskLater(this.plugin.getPlugin(), task, messageCooldown); }
Example #14
Source File: BossBarManager.java From CombatLogX with GNU General Public License v3.0 | 6 votes |
public void removeBossBar(Player player, boolean onDisable) { ICombatLogX plugin = this.expansion.getPlugin(); MultiVersionHandler<?> multiVersionHandler = plugin.getMultiVersionHandler(); AbstractNMS nmsHandler = multiVersionHandler.getInterface(); BossBarHandler bossBarHandler = nmsHandler.getBossBarHandler(); if(onDisable || isDisabledGlobally() || isDisabled(player)) { bossBarHandler.removeBossBar(player); return; } String message = getEndedMessage(player); String color = getColor(); String style = getStyle(); bossBarHandler.updateBossBar(player, message, 0.0D, color, style); Runnable task = () -> bossBarHandler.removeBossBar(player); BukkitScheduler scheduler = Bukkit.getScheduler(); scheduler.runTaskLater(plugin.getPlugin(), task, 20L); }
Example #15
Source File: TraitCombatLogX.java From CombatLogX with GNU General Public License v3.0 | 6 votes |
@Override public void run() { if(this.ticksUntilRemove > 0) { this.ticksUntilRemove--; return; } long survivalSeconds = getSurvivalSeconds(); if(survivalSeconds < 0) return; Player enemy = getEnemy(); ICombatLogX plugin = this.expansion.getPlugin(); if(enemy != null && waitUntilEnemyEscape()) { ICombatManager combatManager = plugin.getCombatManager(); if(combatManager.isInCombat(enemy)) return; } Runnable task = () -> { NPC npc = getNPC(); npc.despawn(DespawnReason.PLUGIN); }; JavaPlugin javaPlugin = plugin.getPlugin(); BukkitScheduler scheduler = Bukkit.getScheduler(); scheduler.runTaskLater(javaPlugin, task, 1L); }
Example #16
Source File: ListenerLogin.java From CombatLogX with GNU General Public License v3.0 | 6 votes |
@EventHandler(priority=EventPriority.MONITOR, ignoreCancelled=true) public void onJoin(PlayerJoinEvent e) { Player player = e.getPlayer(); player.setCanPickupItems(false); NPCManager npcManager = this.expansion.getNPCManager(); NPC npc = npcManager.getNPC(player); if(npc != null) npc.despawn(DespawnReason.PLUGIN); Runnable task = () -> { punish(player); player.setCanPickupItems(true); }; JavaPlugin plugin = this.expansion.getPlugin().getPlugin(); BukkitScheduler scheduler = Bukkit.getScheduler(); scheduler.runTaskLater(plugin, task, 1L); }
Example #17
Source File: PlanBukkitMocker.java From Plan with GNU Lesser General Public License v3.0 | 6 votes |
PlanBukkitMocker withServer() { Server serverMock = Mockito.mock(Server.class); doReturn("").when(serverMock).getIp(); doReturn("Bukkit").when(serverMock).getName(); doReturn("Bukkit").when(serverMock).getServerName(); doReturn(25565).when(serverMock).getPort(); doReturn("1.12.2").when(serverMock).getVersion(); doReturn("32423").when(serverMock).getBukkitVersion(); doReturn(TestConstants.SERVER_MAX_PLAYERS).when(serverMock).getMaxPlayers(); ConsoleCommandSender sender = Mockito.mock(ConsoleCommandSender.class); doReturn(sender).when(serverMock).getConsoleSender(); BukkitScheduler bukkitScheduler = Mockito.mock(BukkitScheduler.class); doReturn(bukkitScheduler).when(serverMock).getScheduler(); doReturn(serverMock).when(planMock).getServer(); return this; }
Example #18
Source File: ViolationLogger.java From Hawk with GNU General Public License v3.0 | 6 votes |
public void updateFile() { if (!enabled) return; if (buffer.size() == 0) return; List<String> asyncList = new ArrayList<>(buffer); buffer.clear(); BukkitScheduler hawkLogger = Bukkit.getServer().getScheduler(); hawkLogger.runTaskAsynchronously(hawk, () -> { try (FileWriter fw = new FileWriter(storageFile, true); BufferedWriter bw = new BufferedWriter(fw); PrintWriter out = new PrintWriter(bw)) { for (String aBuffer : asyncList) { out.println(aBuffer); } } catch (IOException e) { e.printStackTrace(); } }); }
Example #19
Source File: PWIPlayerManagerTest.java From PerWorldInventory with GNU General Public License v3.0 | 5 votes |
@BeforeInjecting public void initSettings() { given(settings.getProperty(PwiProperties.SAVE_INTERVAL)).willReturn(300); // Add mocks for Bukkit.getScheduler, called in @PostConstruct method Server server = mock(Server.class); TestHelper.setField(Bukkit.class, "server", null, server); BukkitScheduler scheduler = mock(BukkitScheduler.class); given(server.getScheduler()).willReturn(scheduler); }
Example #20
Source File: Island.java From IridiumSkyblock with GNU General Public License v2.0 | 5 votes |
public void forceInitBlocks(CommandSender sender, int blocksPerTick, String name) { final Config config = IridiumSkyblock.getConfiguration(); final Messages messages = IridiumSkyblock.getMessages(); if (sender != null) sender.sendMessage(Utils.color(messages.updateStarted .replace("%player%", name) .replace("%prefix%", config.prefix))); updating = true; final IridiumSkyblock plugin = IridiumSkyblock.getInstance(); final BukkitScheduler scheduler = Bukkit.getScheduler(); final Runnable task = new InitIslandBlocksWithSenderRunnable(this, blocksPerTick, sender, name, () -> { if (sender != null) sender.sendMessage(Utils.color(messages.updateFinished .replace("%player%", name) .replace("%prefix%", config.prefix))); scheduler.cancelTask(initBlocks); initBlocks = -1; updating = false; valuableBlocks.clear(); spawners.clear(); for (Location location : tempValues) { final Block block = location.getBlock(); if (!(Utils.isBlockValuable(block) || !(block.getState() instanceof CreatureSpawner))) continue; final Material material = block.getType(); final XMaterial xmaterial = XMaterial.matchXMaterial(material); valuableBlocks.compute(xmaterial.name(), (xmaterialName, original) -> { if (original == null) return 1; return original + 1; }); } tempValues.clear(); calculateIslandValue(); }); initBlocks = scheduler.scheduleSyncRepeatingTask(plugin, task, 0, 1); }
Example #21
Source File: PurgeTaskTest.java From AuthMeReloaded with GNU General Public License v3.0 | 5 votes |
@Test public void shouldStopTaskAndInformSenderUponCompletion() { // given Set<String> names = newHashSet("name1", "name2"); Player sender = mock(Player.class); UUID uuid = UUID.randomUUID(); given(sender.getUniqueId()).willReturn(uuid); PurgeTask task = new PurgeTask(purgeService, permissionsManager, sender, names, new OfflinePlayer[0]); BukkitTask bukkitTask = mock(BukkitTask.class); given(bukkitTask.getTaskId()).willReturn(10049); ReflectionTestUtils.setField(BukkitRunnable.class, task, "task", bukkitTask); Server server = mock(Server.class); BukkitScheduler scheduler = mock(BukkitScheduler.class); given(server.getScheduler()).willReturn(scheduler); ReflectionTestUtils.setField(Bukkit.class, null, "server", server); given(server.getPlayer(uuid)).willReturn(sender); task.run(); // Run for the first time -> results in empty names list // when task.run(); // then verify(scheduler).cancelTask(task.getTaskId()); verify(sender).sendMessage(argThat(containsString("Database has been purged successfully"))); }
Example #22
Source File: AuthMeInitializationTest.java From AuthMeReloaded with GNU General Public License v3.0 | 5 votes |
@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 verify(scheduler).getActiveWorkers(); // via TaskCloser }
Example #23
Source File: AuthMe.java From AuthMeReloaded with GNU General Public License v3.0 | 5 votes |
/** * Initialize the plugin and all the services. */ private void initialize() { // Create plugin folder getDataFolder().mkdir(); // Create injector, provide elements from the Bukkit environment and register providers injector = new InjectorBuilder() .addDefaultHandlers("fr.xephi.authme") .create(); injector.register(AuthMe.class, this); injector.register(Server.class, getServer()); injector.register(PluginManager.class, getServer().getPluginManager()); injector.register(BukkitScheduler.class, getServer().getScheduler()); injector.provide(DataFolder.class, getDataFolder()); injector.registerProvider(Settings.class, SettingsProvider.class); injector.registerProvider(DataSource.class, DataSourceProvider.class); // Get settings and set up logger settings = injector.getSingleton(Settings.class); ConsoleLoggerFactory.reloadSettings(settings); OnStartupTasks.setupConsoleFilter(getLogger()); // Set all service fields on the AuthMe class instantiateServices(injector); // Convert deprecated PLAINTEXT hash entries MigrationService.changePlainTextToSha256(settings, database, new Sha256()); // If the server is empty (fresh start) just set all the players as unlogged if (bukkitService.getOnlinePlayers().isEmpty()) { database.purgeLogged(); } // Register event listeners registerEventListeners(injector); // Start Email recall task if needed OnStartupTasks onStartupTasks = injector.newInstance(OnStartupTasks.class); onStartupTasks.scheduleRecallEmailTask(); }
Example #24
Source File: ReplaceManagerTest.java From ScoreboardStats with MIT License | 5 votes |
@Test public void testUnregister() throws Exception { PowerMockito.mockStatic(Bukkit.class); Mockito.when(Bukkit.getPluginManager()).thenReturn(PowerMockito.mock(SimplePluginManager.class)); Mockito.when(Bukkit.getMessenger()).thenReturn(PowerMockito.mock(StandardMessenger.class)); Mockito.when(Bukkit.getScheduler()).thenReturn(PowerMockito.mock(BukkitScheduler.class)); Plugin plugin = PowerMockito.mock(Plugin.class); ReplaceManager replaceManager = new ReplaceManager(null, plugin, LoggerFactory.getLogger("test")); replaceManager.register(new Replacer(plugin, "test").scoreSupply(() -> 1)); }
Example #25
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 #26
Source File: SpringSpigotTestInitializer.java From mcspring-boot with MIT License | 5 votes |
private static Server mockServer() { Server server = mock(Server.class); PluginManager pluginManager = mock(PluginManager.class); when(server.getPluginManager()).thenReturn(pluginManager); BukkitScheduler scheduler = mock(BukkitScheduler.class); when(server.getScheduler()).thenReturn(scheduler); setServer(server); return server; }
Example #27
Source File: PWIPlayerManagerTest.java From PerWorldInventory with GNU General Public License v3.0 | 5 votes |
@BeforeInjecting public void initSettings() { given(settings.getProperty(PwiProperties.SAVE_INTERVAL)).willReturn(300); // Add mocks for Bukkit.getScheduler, called in @PostConstruct method Server server = mock(Server.class); TestHelper.setField(Bukkit.class, "server", null, server); BukkitScheduler scheduler = mock(BukkitScheduler.class); given(server.getScheduler()).willReturn(scheduler); }
Example #28
Source File: ChatEventsTest.java From uSkyBlock with GNU General Public License v3.0 | 5 votes |
@Before public void setUp() { uSkyBlock fakePlugin = mock(uSkyBlock.class); Server fakeServer = mock(Server.class); when(fakePlugin.getServer()).thenReturn(fakeServer); fakeScheduler = mock(BukkitScheduler.class); when(fakeScheduler.runTask(any(Plugin.class), any(Runnable.class))).thenReturn(mock(BukkitTask.class)); when(fakeServer.getScheduler()).thenReturn(fakeScheduler); fakeLogic = spy(mock(ChatLogic.class)); doNothing().when(fakeLogic).sendMessage(any(), any(), any()); listener = new ChatEvents(fakeLogic, fakePlugin); }
Example #29
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 #30
Source File: ExploitFixer.java From ExploitFixer with GNU General Public License v3.0 | 5 votes |
@Override public void onDisable() { final Server server = this.getServer(); final BukkitScheduler scheduler = server.getScheduler(); scheduler.cancelTasks(this); this.listenerInitializer.unregister(); if (checkHamsterAPI()) { this.hamsterAPIListenerInitializer.unregister(); } }