org.bukkit.scheduler.BukkitTask Java Examples
The following examples show how to use
org.bukkit.scheduler.BukkitTask.
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: TeleportLogic.java From uSkyBlock with GNU General Public License v3.0 | 6 votes |
/** * Teleport the given {@link Player} to the given {@link Location}, loading the {@link org.bukkit.Chunk} before * teleporting and with the configured teleport delay if applicable. * @param player Player to teleport. * @param targetLocation Location to teleport the player to. * @param force True to override teleport delay, false otherwise. */ public void safeTeleport(@NotNull Player player, @NotNull Location targetLocation, boolean force) { Validate.notNull(player, "Player cannot be null"); Validate.notNull(targetLocation, "TargetLocation cannot be null"); log.log(Level.FINER, "safeTeleport " + player + " to " + targetLocation + (force ? " with force" : "")); final Location targetLoc = LocationUtil.centerOnBlock(targetLocation.clone()); if (player.hasPermission("usb.mod.bypassteleport") || (teleportDelay == 0) || force) { PaperLib.teleportAsync(player, targetLoc); } else { player.sendMessage(tr("\u00a7aYou will be teleported in {0} seconds.", teleportDelay)); BukkitTask tpTask = plugin.sync(() -> { pendingTeleports.remove(player.getUniqueId()); PaperLib.teleportAsync(player, targetLoc); }, TimeUtil.secondsAsMillis(teleportDelay)); pendingTeleports.put(player.getUniqueId(), new PendingTeleport(player.getLocation(), tpTask)); } }
Example #2
Source File: TasksCommand.java From LagMonitor with MIT License | 6 votes |
private BaseComponent[] formatTask(BukkitTask pendingTask) { Plugin owner = pendingTask.getOwner(); int taskId = pendingTask.getTaskId(); boolean sync = pendingTask.isSync(); String id = Integer.toString(taskId); if (sync) { id += "-Sync"; } else if (Bukkit.getScheduler().isCurrentlyRunning(taskId)) { id += "-Running"; } return new ComponentBuilder(owner.getName()) .color(PRIMARY_COLOR.asBungee()) .append('-' + id) .color(SECONDARY_COLOR.asBungee()) .create(); }
Example #3
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 #4
Source File: GDPlayerData.java From GriefDefender with MIT License | 6 votes |
public void revertClaimVisual(GDClaim claim, UUID visualUniqueId) { final Player player = this.getSubject().getOnlinePlayer(); if (player == null) { return; } for (Map.Entry<UUID, BukkitTask> mapEntry : this.claimVisualRevertTasks.entrySet()) { if (visualUniqueId.equals(mapEntry.getKey())) { mapEntry.getValue().cancel(); break; } } if (GriefDefenderPlugin.getInstance().getWorldEditProvider() != null) { GriefDefenderPlugin.getInstance().getWorldEditProvider().revertClaimCUIVisual(visualUniqueId, this.playerID); } this.revertVisualBlocks(player, claim, visualUniqueId); }
Example #5
Source File: XParticle.java From XSeries with MIT License | 6 votes |
/** * This will rotate the shape around in an area randomly. * The position of the shape will be randomized positively and negatively by the offset parameters on each axis. * * @param plugin the schedule handler. * @param update the timer period in ticks. * @param rate the distance between each location. Recommended value is 5. * @param runnable the particles to spawn. * @param displays the displays references used to spawn particles in the runnable. * @return the async task handling the movement. * @see #moveRotatingAround(JavaPlugin, long, double, double, double, double, Runnable, ParticleDisplay...) * @see #guard(JavaPlugin, long, double, double, double, double, Runnable, ParticleDisplay...) * @since 1.0.0 */ public static BukkitTask rotateAround(JavaPlugin plugin, long update, double rate, double offsetx, double offsety, double offsetz, Runnable runnable, ParticleDisplay... displays) { return new BukkitRunnable() { double rotation = 180; @Override public void run() { rotation += rate; double x = Math.toRadians((90 + rotation) * offsetx); double y = Math.toRadians((60 + rotation) * offsety); double z = Math.toRadians((30 + rotation) * offsetz); Vector vector = new Vector(x, y, z); for (ParticleDisplay display : displays) display.rotate(vector); runnable.run(); } }.runTaskTimerAsynchronously(plugin, 0L, update); }
Example #6
Source File: TasksCommand.java From LagMonitor with MIT License | 6 votes |
private BaseComponent[] formatTask(BukkitTask pendingTask) { Plugin owner = pendingTask.getOwner(); int taskId = pendingTask.getTaskId(); boolean sync = pendingTask.isSync(); String id = Integer.toString(taskId); if (sync) { id += "-Sync"; } else if (Bukkit.getScheduler().isCurrentlyRunning(taskId)) { id += "-Running"; } return new ComponentBuilder(owner.getName()) .color(PRIMARY_COLOR.asBungee()) .append('-' + id) .color(SECONDARY_COLOR.asBungee()) .create(); }
Example #7
Source File: XParticle.java From XSeries with MIT License | 6 votes |
/** * Display a rendered image repeatedly. * * @param plugin the scheduler handler. * @param render the rendered image map. * @param location the dynamic location to display the image at. * @param repeat amount of times to repeat displaying the image. * @param period the perioud between each repeats. * @param quality the quality of the image is exactly the number of particles display for each pixel. Recommended value is 1 * @param speed the speed is exactly the same value as the speed of particles. Recommended amount is 0 * @param size the size of the particle. Recommended amount is 0.8 * @return the async bukkit task displaying the image. * @since 1.0.0 */ public static BukkitTask displayRenderedImage(JavaPlugin plugin, Map<Location, Color> render, Callable<Location> location, int repeat, long period, int quality, int speed, float size) { return new BukkitRunnable() { int times = repeat; @Override public void run() { try { displayRenderedImage(render, location.call(), quality, speed, size); } catch (Exception e) { e.printStackTrace(); } if (times-- < 1) cancel(); } }.runTaskTimerAsynchronously(plugin, 0L, period); }
Example #8
Source File: SimpleHoloManager.java From HoloAPI with GNU General Public License v3.0 | 6 votes |
@Override public Hologram createSimpleHologram(Location location, int secondsUntilRemoved, final Vector velocity, String... lines) { int simpleId = TagIdGenerator.next(lines.length); final Hologram hologram = new HologramFactory(HoloAPI.getCore()).withFirstTagId(simpleId).withSaveId(simpleId + "").withText(lines).withLocation(location).withSimplicity(true).build(); for (Entity e : hologram.getDefaultLocation().getWorld().getEntities()) { if (e instanceof Player) { hologram.show((Player) e, true); } } BukkitTask t = HoloAPI.getCore().getServer().getScheduler().runTaskTimer(HoloAPI.getCore(), new Runnable() { @Override public void run() { Location l = hologram.getDefaultLocation(); l.add(velocity); hologram.move(l.toVector()); } }, 1L, 1L); new HologramRemoveTask(hologram, t).runTaskLater(HoloAPI.getCore(), secondsUntilRemoved * 20); return hologram; }
Example #9
Source File: LimboPlayerTaskManagerTest.java From AuthMeReloaded with GNU General Public License v3.0 | 6 votes |
@Test public void shouldCancelExistingTimeoutTask() { // given Player player = mock(Player.class); LimboPlayer limboPlayer = new LimboPlayer(null, false, Collections.emptyList(), true, 0.3f, 0.1f); BukkitTask existingTask = mock(BukkitTask.class); limboPlayer.setTimeoutTask(existingTask); given(settings.getProperty(RestrictionSettings.TIMEOUT)).willReturn(18); BukkitTask bukkitTask = mock(BukkitTask.class); given(bukkitService.runTaskLater(any(TimeoutTask.class), anyLong())).willReturn(bukkitTask); // when limboPlayerTaskManager.registerTimeoutTask(player, limboPlayer); // then verify(existingTask).cancel(); assertThat(limboPlayer.getTimeoutTask(), equalTo(bukkitTask)); verify(bukkitService).runTaskLater(any(TimeoutTask.class), eq(360L)); // 18 * TICKS_PER_SECOND verify(messages).retrieveSingle(player, MessageKey.LOGIN_TIMEOUT_ERROR); }
Example #10
Source File: NametagHandler.java From NametagEdit with GNU General Public License v3.0 | 5 votes |
private BukkitTask createTask(String path, BukkitTask existing, Runnable runnable) { if (existing != null) { existing.cancel(); } if (config.getInt(path, -1) <= 0) return null; return Bukkit.getScheduler().runTaskTimer(plugin, runnable, 0, 20 * config.getInt(path)); }
Example #11
Source File: LimboPlayerTaskManager.java From AuthMeReloaded with GNU General Public License v3.0 | 5 votes |
/** * Registers a {@link TimeoutTask} for the given player according to the configuration. * * @param player the player to register a timeout task for * @param limbo the associated limbo player */ void registerTimeoutTask(Player player, LimboPlayer limbo) { final int timeout = settings.getProperty(RestrictionSettings.TIMEOUT) * TICKS_PER_SECOND; if (timeout > 0) { String message = messages.retrieveSingle(player, MessageKey.LOGIN_TIMEOUT_ERROR); BukkitTask task = bukkitService.runTaskLater(new TimeoutTask(player, message, playerCache), timeout); limbo.setTimeoutTask(task); } }
Example #12
Source File: TaskMaster.java From civcraft with GNU General Public License v2.0 | 5 votes |
public static void cancelTimer(String name) { BukkitTask timer = tasks.get(name); if (timer != null) { timer.cancel(); } //RJ.out("cancel timer:"+name); timers.remove(name); }
Example #13
Source File: CrazyCrates.java From Crazy-Crates with MIT License | 5 votes |
/** * Ends the tasks running by a player. * @param player The player using the crate. */ public void endQuadCrate(Player player) { if (currentQuadTasks.containsKey(player.getUniqueId())) { for (BukkitTask task : currentQuadTasks.get(player.getUniqueId())) { task.cancel(); } currentQuadTasks.remove(player.getUniqueId()); } }
Example #14
Source File: TasksCommand.java From LagMonitor with MIT License | 5 votes |
@Override public boolean onCommand(CommandSender sender, Command command, String label, String[] args) { if (!canExecute(sender, command)) { return true; } List<BaseComponent[]> lines = new ArrayList<>(); List<BukkitTask> pendingTasks = Bukkit.getScheduler().getPendingTasks(); for (BukkitTask pendingTask : pendingTasks) { lines.add(formatTask(pendingTask)); Class<?> runnableClass = getRunnableClass(pendingTask); if (runnableClass != null) { lines.add(new ComponentBuilder(" Task: ") .color(PRIMARY_COLOR.asBungee()) .append(runnableClass.getSimpleName()) .color(SECONDARY_COLOR.asBungee()) .create()); } } Pages pagination = new Pages("Stacktrace", lines); pagination.send(sender); plugin.getPageManager().setPagination(sender.getName(), pagination); return true; }
Example #15
Source File: Game.java From BedwarsRel with GNU General Public License v3.0 | 5 votes |
public void stopWorkers() { for (BukkitTask task : this.runningTasks) { try { task.cancel(); } catch (Exception ex) { BedwarsRel.getInstance().getBugsnag().notify(ex); // already cancelled } } this.runningTasks.clear(); }
Example #16
Source File: CraftScheduler.java From Thermos with GNU General Public License v3.0 | 5 votes |
public BukkitTask runTaskTimer(Plugin plugin, Runnable runnable, long delay, long period) { validate(plugin, runnable); if (delay < 0l) { delay = 0; } if (period == 0l) { period = 1l; } else if (period < -1l) { period = -1l; } return handle(new CraftTask(plugin, runnable, nextId(), period), delay); }
Example #17
Source File: TasksCommand.java From LagMonitor with MIT License | 5 votes |
private Class<?> getRunnableClass(BukkitTask task) { try { return taskHandle.invokeExact(task).getClass(); } catch (Exception ex) { //ignore } catch (Throwable throwable) { throw (Error) throwable; } return null; }
Example #18
Source File: SkyBlockMenu.java From uSkyBlock with GNU General Public License v3.0 | 5 votes |
private void updateRestartMenuTimer(final Player p, final Inventory inventory) { final BukkitTask[] hackySharing = new BukkitTask[1]; hackySharing[0] = plugin.sync(() -> { if (inventory.getViewers().contains(p)) { updateRestartMenu(inventory, p, plugin.getIslandGenerator().getSchemeNames()); } if (plugin.getConfirmHandler().millisLeft(p, "/is restart") <= 0 || !inventory.getViewers().contains(p)) { if (hackySharing.length > 0 && hackySharing[0] != null) { hackySharing[0].cancel(); } } }, 0, 1000); }
Example #19
Source File: WorldEditSelectionVisualizer.java From WorldEditSelectionVisualizer with MIT License | 5 votes |
private void loadConfig() { particlesTasks.forEach(BukkitTask::cancel); particlesTasks.clear(); for (SelectionType type : SelectionType.values()) { GlobalSelectionConfig config = configurationHelper.loadGlobalSelectionConfig(type); configurations.put(type, config); particlesTasks.add(new ParticlesTask(this, type, true, config.primary()).start()); particlesTasks.add(new ParticlesTask(this, type, false, config.secondary()).start()); } }
Example #20
Source File: BukkitServiceTest.java From AuthMeReloaded with GNU General Public License v3.0 | 5 votes |
@Test public void shouldRunTask() { // given Runnable task = () -> {/* noop */}; BukkitTask bukkitTask = mock(BukkitTask.class); given(scheduler.runTask(authMe, task)).willReturn(bukkitTask); // when BukkitTask resultingTask = bukkitService.runTask(task); // then assertThat(resultingTask, equalTo(bukkitTask)); verify(scheduler, only()).runTask(authMe, task); }
Example #21
Source File: LoggedScheduler.java From VoxelGamesLibv2 with MIT License | 5 votes |
@Override public BukkitTask runTaskLaterAsynchronously(Plugin plugin, BukkitRunnable bukkitRunnable, long l) throws IllegalArgumentException { TaskedRunnable wrapped = new TaskedRunnable(bukkitRunnable); BukkitTask bukkitTask = delegate.runTaskLaterAsynchronously(plugin, wrapped, l); wrapped.setTaskID(bukkitTask.getTaskId()); return bukkitTask; }
Example #22
Source File: LoggedScheduler.java From VoxelGamesLibv2 with MIT License | 5 votes |
@Override public BukkitTask runTaskLaterAsynchronously(Plugin plugin, Runnable runnable, long l) throws IllegalArgumentException { TaskedRunnable wrapped = new TaskedRunnable(runnable); BukkitTask bukkitTask = delegate.runTaskLaterAsynchronously(plugin, wrapped, l); wrapped.setTaskID(bukkitTask.getTaskId()); return bukkitTask; }
Example #23
Source File: CraftScheduler.java From Thermos with GNU General Public License v3.0 | 5 votes |
public BukkitTask runTaskTimerAsynchronously(Plugin plugin, Runnable runnable, long delay, long period) { validate(plugin, runnable); if (delay < 0l) { delay = 0; } if (period == 0l) { period = 1l; } else if (period < -1l) { period = -1l; } return handle(new CraftAsyncTask(runners, plugin, runnable, nextId(), period), delay); }
Example #24
Source File: LoggedScheduler.java From VoxelGamesLibv2 with MIT License | 5 votes |
@Override public BukkitTask runTaskLater(Plugin plugin, BukkitRunnable bukkitRunnable, long l) throws IllegalArgumentException { TaskedRunnable wrapped = new TaskedRunnable(bukkitRunnable); BukkitTask bukkitTask = delegate.runTaskLater(plugin, wrapped, l); wrapped.setTaskID(bukkitTask.getTaskId()); return bukkitTask; }
Example #25
Source File: TasksCommand.java From LagMonitor with MIT License | 5 votes |
private Class<?> getRunnableClass(BukkitTask task) { try { return taskHandle.invokeExact(task).getClass(); } catch (Exception ex) { //ignore } catch (Throwable throwable) { throw (Error) throwable; } return null; }
Example #26
Source File: GDPlayerData.java From GriefDefender with MIT License | 5 votes |
@Override public void revertAllVisuals() { this.lastShovelLocation = null; this.claimResizing = null; this.claimSubdividing = null; final Player player = this.getSubject().getOnlinePlayer(); if (player == null) { return; } if (this.visualClaimBlocks.isEmpty()) { return; } for (Map.Entry<UUID, BukkitTask> mapEntry : this.claimVisualRevertTasks.entrySet()) { mapEntry.getValue().cancel(); } final List<UUID> visualIds = new ArrayList<>(this.visualClaimBlocks.keySet()); for (UUID visualUniqueId : visualIds) { final Claim claim = GriefDefenderPlugin.getInstance().dataStore.getClaim(player.getWorld().getUID(), visualUniqueId); this.revertVisualBlocks(player, (GDClaim) claim, visualUniqueId); } if (GriefDefenderPlugin.getInstance().getWorldEditProvider() != null) { GriefDefenderPlugin.getInstance().getWorldEditProvider().revertAllVisuals(this.playerID); } // Revert any temp visuals this.revertTempVisuals(); }
Example #27
Source File: LoggedScheduler.java From VoxelGamesLibv2 with MIT License | 5 votes |
@Override public BukkitTask runTask(Plugin plugin, Runnable runnable) throws IllegalArgumentException { TaskedRunnable wrapped = new TaskedRunnable(runnable); BukkitTask bukkitTask = delegate.runTask(plugin, wrapped); wrapped.setTaskID(bukkitTask.getTaskId()); return bukkitTask; }
Example #28
Source File: BukkitSchedulerBackend.java From ProjectAres with GNU Affero General Public License v3.0 | 5 votes |
@Override public BukkitTask startTask(Task.Parameters schedule, Runnable runnable) { final Duration delay = schedule.delay(); final Duration interval = schedule.interval(); return bukkit.runTaskTimer(plugin, runnable, delay == null ? 0 : TimeUtils.toTicks(delay), interval == null ? -1 : TimeUtils.toTicks(interval)); }
Example #29
Source File: LoggedScheduler.java From VoxelGamesLibv2 with MIT License | 5 votes |
@Override public BukkitTask runTask(Plugin plugin, BukkitRunnable bukkitRunnable) throws IllegalArgumentException { TaskedRunnable wrapped = new TaskedRunnable(bukkitRunnable); BukkitTask bukkitTask = delegate.runTask(plugin, wrapped); wrapped.setTaskID(bukkitTask.getTaskId()); return bukkitTask; }
Example #30
Source File: Slimefun.java From Slimefun4 with GNU General Public License v3.0 | 5 votes |
public static BukkitTask runSync(Runnable r) { if (SlimefunPlugin.getMinecraftVersion() == MinecraftVersion.UNIT_TEST) { r.run(); return null; } return Bukkit.getScheduler().runTask(SlimefunPlugin.instance, r); }