How to use ScheduledTask method of be.seeseemelk.mockbukkit.scheduler.ScheduledTask class

Best MockBukkit code snippet using be.seeseemelk.mockbukkit.scheduler.ScheduledTask.ScheduledTask

Source:BukkitSchedulerMock.java Github

copy

Full Screen

...25 private final AtomicReference<Exception> asyncException = new AtomicReference<>();26 private long currentTick = 0;27 private int id = 0;28 private long executorTimeout = 60000;29 private static Runnable wrapTask(ScheduledTask task)30 {31 return () ->32 {33 task.setRunning(true);34 task.run();35 task.setRunning(false);36 };37 }38 public void setShutdownTimeout(long timeout)39 {40 this.executorTimeout = timeout;41 }42 /**43 * Shuts the scheduler down. Note that this function will throw exception that where thrown by old asynchronous44 * tasks.45 */46 public void shutdown()47 {48 waitAsyncTasksFinished();49 pool.shutdown();50 if (asyncException.get() != null)51 throw new AsyncTaskException(asyncException.get());52 asyncEventExecutor.shutdownNow();53 }54 public Future<?> executeAsyncEvent(Event event)55 {56 Validate.notNull(event, "Cannot schedule an Event that is null!");57 return asyncEventExecutor.submit(() -> MockBukkit.getMock().getPluginManager().callEvent(event));58 }59 /**60 * Get the current tick of the server.61 *62 * @return The current tick of the server.63 */64 public long getCurrentTick()65 {66 return currentTick;67 }68 /**69 * Perform one tick on the server.70 */71 public void performOneTick()72 {73 currentTick++;74 List<ScheduledTask> oldTasks = scheduledTasks.getCurrentTaskList();75 for (ScheduledTask task : oldTasks)76 {77 if (task.getScheduledTick() == currentTick && !task.isCancelled())78 {79 if (task.isSync())80 {81 wrapTask(task).run();82 }83 else84 {85 pool.submit(wrapTask(task));86 }87 if (task instanceof RepeatingTask && !task.isCancelled())88 {89 ((RepeatingTask) task).updateScheduledTick();90 scheduledTasks.addTask(task);91 }92 }93 }94 }95 /**96 * Perform a number of ticks on the server.97 *98 * @param ticks The number of ticks to executed.99 */100 public void performTicks(long ticks)101 {102 for (long i = 0; i < ticks; i++)103 {104 performOneTick();105 }106 }107 /**108 * Gets the number of async tasks which are awaiting execution.109 *110 * @return The number of async tasks which are pending execution.111 */112 public int getNumberOfQueuedAsyncTasks()113 {114 int queuedAsync = 0;115 for (ScheduledTask task : scheduledTasks.getCurrentTaskList())116 {117 if (task.isSync() || task.isCancelled() || task.isRunning())118 {119 continue;120 }121 queuedAsync++;122 }123 return queuedAsync;124 }125 /**126 * Waits until all asynchronous tasks have finished executing. If you have an asynchronous task that runs127 * indefinitely, this function will never return.128 */129 public void waitAsyncTasksFinished()130 {131 // Make sure all tasks get to execute. (except for repeating asynchronous tasks, they only will fire once)132 while (scheduledTasks.getScheduledTaskCount() > 0)133 {134 performOneTick();135 }136 // Wait for all tasks to finish executing.137 long systemTime = System.currentTimeMillis();138 while (pool.getActiveCount() > 0)139 {140 try141 {142 Thread.sleep(10L);143 }144 catch (InterruptedException e)145 {146 Thread.currentThread().interrupt();147 return;148 }149 if (System.currentTimeMillis() > (systemTime + executorTimeout))150 {151 // If a plugin has left a a runnable going and not cancelled it we could call this bad practice.152 // we should now force interrupt all these runnables forcing them to throw Interrupted Exceptions.153 // if they handle that154 for (ScheduledTask task : scheduledTasks.getCurrentTaskList())155 {156 if (task.isRunning())157 {158 task.cancel();159 cancelTask(task.getTaskId());160 throw new RuntimeException("Forced Cancellation of task owned by "161 + task.getOwner().getName());162 }163 }164 pool.shutdownNow();165 }166 }167 }168 @Override169 public BukkitTask runTask(Plugin plugin, Runnable task)170 {171 return runTaskLater(plugin, task, 1L);172 }173 @Override174 public BukkitTask runTask(Plugin plugin, BukkitRunnable task)175 {176 return runTask(plugin, (Runnable) task);177 }178 @Override179 public BukkitTask runTaskLater(Plugin plugin, Runnable task, long delay)180 {181 delay = Math.max(delay, 1);182 ScheduledTask scheduledTask = new ScheduledTask(id++, plugin, true, currentTick + delay, task);183 scheduledTasks.addTask(scheduledTask);184 return scheduledTask;185 }186 @Override187 public BukkitTask runTaskTimer(Plugin plugin, Runnable task, long delay, long period)188 {189 delay = Math.max(delay, 1);190 RepeatingTask repeatingTask = new RepeatingTask(id++, plugin, true, currentTick + delay, period, task);191 scheduledTasks.addTask(repeatingTask);192 return repeatingTask;193 }194 @Override195 public BukkitTask runTaskTimer(Plugin plugin, BukkitRunnable task, long delay, long period)196 {197 return runTaskTimer(plugin, (Runnable) task, delay, period);198 }199 @Override200 public int scheduleSyncDelayedTask(Plugin plugin, Runnable task, long delay)201 {202 Logger.getLogger(LOGGER_NAME).warning("Consider using runTaskLater instead of scheduleSyncDelayTask");203 return runTaskLater(plugin, task, delay).getTaskId();204 }205 @Override206 public int scheduleSyncDelayedTask(Plugin plugin, BukkitRunnable task, long delay)207 {208 Logger.getLogger(LOGGER_NAME).warning("Consider using runTaskLater instead of scheduleSyncDelayTask");209 return runTaskLater(plugin, (Runnable) task, delay).getTaskId();210 }211 @Override212 public int scheduleSyncDelayedTask(Plugin plugin, Runnable task)213 {214 Logger.getLogger(LOGGER_NAME).warning("Consider using runTask instead of scheduleSyncDelayTask");215 return runTask(plugin, task).getTaskId();216 }217 @Override218 public int scheduleSyncDelayedTask(Plugin plugin, BukkitRunnable task)219 {220 Logger.getLogger(LOGGER_NAME).warning("Consider using runTask instead of scheduleSyncDelayTask");221 return runTask(plugin, (Runnable) task).getTaskId();222 }223 @Override224 public int scheduleSyncRepeatingTask(Plugin plugin, Runnable task, long delay, long period)225 {226 Logger.getLogger(LOGGER_NAME).warning("Consider using runTaskTimer instead of scheduleSyncRepeatingTask");227 return runTaskTimer(plugin, task, delay, period).getTaskId();228 }229 @Override230 public int scheduleSyncRepeatingTask(Plugin plugin, BukkitRunnable task, long delay, long period)231 {232 Logger.getLogger(LOGGER_NAME).warning("Consider using runTaskTimer instead of scheduleSyncRepeatingTask");233 return runTaskTimer(plugin, (Runnable) task, delay, period).getTaskId();234 }235 @Override236 public int scheduleAsyncDelayedTask(Plugin plugin, Runnable task, long delay)237 {238 Logger.getLogger(LOGGER_NAME)239 .warning("Consider using runTaskLaterAsynchronously instead of scheduleAsyncDelayedTask");240 return runTaskLaterAsynchronously(plugin, task, delay).getTaskId();241 }242 @Override243 public int scheduleAsyncDelayedTask(Plugin plugin, Runnable task)244 {245 Logger.getLogger(LOGGER_NAME)246 .warning("Consider using runTaskAsynchronously instead of scheduleAsyncDelayedTask");247 return runTaskAsynchronously(plugin, task).getTaskId();248 }249 @Override250 public int scheduleAsyncRepeatingTask(Plugin plugin, Runnable task, long delay, long period)251 {252 Logger.getLogger(LOGGER_NAME)253 .warning("Consider using runTaskTimerAsynchronously instead of scheduleAsyncRepeatingTask");254 return runTaskTimerAsynchronously(plugin, task, delay, period).getTaskId();255 }256 @Override257 public <T> Future<T> callSyncMethod(Plugin plugin, Callable<T> task)258 {259 // TODO Auto-generated method stub260 throw new UnimplementedOperationException();261 }262 @Override263 public void cancelTask(int taskId)264 {265 scheduledTasks.cancelTask(taskId);266 }267 @Override268 public void cancelTasks(Plugin plugin)269 {270 for (ScheduledTask task : scheduledTasks.getCurrentTaskList())271 {272 if (task.getOwner() != null)273 {274 if (task.getOwner().equals(plugin))275 {276 task.cancel();277 }278 }279 }280 }281 @Override282 public void cancelAllTasks() {283 // TODO Auto-generated method stub284 throw new UnimplementedOperationException();285 }286 @Override287 public boolean isCurrentlyRunning(int taskId)288 {289 // TODO Auto-generated method stub290 throw new UnimplementedOperationException();291 }292 @Override293 public boolean isQueued(int taskId)294 {295 for (ScheduledTask task : scheduledTasks.getCurrentTaskList())296 {297 if (task.getTaskId() == taskId)298 return !task.isCancelled();299 }300 return false;301 }302 @Override303 public List<BukkitWorker> getActiveWorkers()304 {305 // TODO Auto-generated method stub306 throw new UnimplementedOperationException();307 }308 @Override309 public List<BukkitTask> getPendingTasks()310 {311 // TODO Auto-generated method stub312 throw new UnimplementedOperationException();313 }314 @Override315 public BukkitTask runTaskAsynchronously(Plugin plugin, Runnable task)316 {317 ScheduledTask scheduledTask = new ScheduledTask(id++, plugin, false, currentTick, new AsyncRunnable(task));318 pool.execute(wrapTask(scheduledTask));319 return scheduledTask;320 }321 @Override322 public BukkitTask runTaskAsynchronously(Plugin plugin, BukkitRunnable task)323 {324 return runTaskAsynchronously(plugin, (Runnable) task);325 }326 @Override327 public BukkitTask runTaskLater(Plugin plugin, BukkitRunnable task, long delay)328 {329 return runTaskLater(plugin, (Runnable) task, delay);330 }331 @Override332 public BukkitTask runTaskLaterAsynchronously(Plugin plugin, Runnable task, long delay)333 {334 ScheduledTask scheduledTask = new ScheduledTask(id++, plugin, false, currentTick + delay,335 new AsyncRunnable(task));336 scheduledTasks.addTask(scheduledTask);337 return scheduledTask;338 }339 @Override340 public BukkitTask runTaskLaterAsynchronously(Plugin plugin, BukkitRunnable task, long delay)341 {342 return runTaskLaterAsynchronously(plugin, (Runnable) task, delay);343 }344 @Override345 public BukkitTask runTaskTimerAsynchronously(Plugin plugin, Runnable task, long delay, long period)346 {347 RepeatingTask scheduledTask = new RepeatingTask(id++, plugin, false, currentTick + delay, period,348 new AsyncRunnable(task));349 scheduledTasks.addTask(scheduledTask);350 return scheduledTask;351 }352 @Override353 public BukkitTask runTaskTimerAsynchronously(Plugin plugin, BukkitRunnable task, long delay, long period)354 {355 return runTaskTimerAsynchronously(plugin, (Runnable) task, delay, period);356 }357 class AsyncRunnable implements Runnable358 {359 private final Runnable task;360 private AsyncRunnable(Runnable runnable)361 {362 task = runnable;363 }364 @Override365 public void run()366 {367 try368 {369 task.run();370 }371 catch (Exception t)372 {373 asyncException.set(t);374 }375 }376 }377 protected int getActiveRunningCount()378 {379 return pool.getActiveCount();380 }381 private static class TaskList382 {383 private final Map<Integer, ScheduledTask> tasks;384 private TaskList()385 {386 tasks = new ConcurrentHashMap<>();387 }388 /**389 * Add a task but locks the Task list to other writes while adding it.390 *391 * @param task the task to remove.392 * @return true on success.393 */394 private boolean addTask(ScheduledTask task)395 {396 if (task == null)397 {398 return false;399 }400 tasks.put(task.getTaskId(), task);401 return true;402 }403 protected final List<ScheduledTask> getCurrentTaskList()404 {405 List<ScheduledTask> out = new ArrayList<>();406 if (tasks.size() != 0)407 {408 out.addAll(tasks.values());409 }410 return out;411 }412 protected int getScheduledTaskCount()413 {414 int scheduled = 0;415 if (tasks.size() == 0)416 {417 return 0;418 }419 for (ScheduledTask task : tasks.values())420 {421 if (task.isCancelled() || task.isRunning())422 continue;423 scheduled++;424 }425 return scheduled;426 }427 protected boolean cancelTask(int taskID)428 {429 if (tasks.containsKey(taskID))430 {431 ScheduledTask task = tasks.get(taskID);432 task.cancel();433 tasks.put(taskID, task);434 return true;435 }436 return false;437 }438 }439}...

Full Screen

Full Screen

Source:ScheduledTaskTest.java Github

copy

Full Screen

2import static org.junit.Assert.*;3import java.util.concurrent.CancellationException;4import java.util.concurrent.atomic.AtomicBoolean;5import org.junit.Test;6public class ScheduledTaskTest7{8 @Test9 public void getScheduledTick_GetsScheduledTick()10 {11 ScheduledTask task = new ScheduledTask(0, null, true, 5, null);12 assertEquals(5, task.getScheduledTick());13 }14 15 @Test16 public void getRunnable_GetsRunnable()17 {18 Runnable runnable = () -> {};19 ScheduledTask task = new ScheduledTask(0, null, true, 0, runnable);20 assertSame(runnable, task.getRunnable());21 }22 23 @Test24 public void getTaskId_GetsTaskId()25 {26 ScheduledTask task = new ScheduledTask(5, null, true, 0, null);27 assertEquals(5, task.getTaskId());28 }29 @Test30 public void isSync()31 {32 ScheduledTask task = new ScheduledTask(0, null, true, 0, null);33 assertTrue(task.isSync());34 task = new ScheduledTask(0, null, false, 0, null);35 assertFalse(task.isSync());36 }37 38 @Test39 public void setScheduledTick_OtherTick_TickSetExactly()40 {41 ScheduledTask task = new ScheduledTask(0, null, true, 5, null);42 assertEquals(5, task.getScheduledTick());43 task.setScheduledTick(20);44 assertEquals(20, task.getScheduledTick());45 }46 47 @Test48 public void cancel()49 {50 ScheduledTask task = new ScheduledTask(0, null, true, 0, null);51 assertEquals(false, task.isCancelled());52 task.cancel();53 assertEquals(true, task.isCancelled());54 }55 56 @Test57 public void run_NotCancelled_Executed()58 {59 AtomicBoolean executed = new AtomicBoolean(false);60 ScheduledTask task = new ScheduledTask(0, null, true, 0, () -> {61 executed.set(true);62 });63 task.run();64 assertTrue(executed.get());65 }66 67 @Test(expected = CancellationException.class)68 public void run_Cancelled_ThrowsException()69 {70 AtomicBoolean executed = new AtomicBoolean(false);71 ScheduledTask task = new ScheduledTask(0, null, true, 0, () -> {72 executed.set(true);73 });74 task.cancel();75 task.run();76 }77 78}...

Full Screen

Full Screen

ScheduledTask

Using AI Code Generation

copy

Full Screen

1import org.bukkit.plugin.java.JavaPlugin;2import be.seeseemelk.mockbukkit.scheduler.ScheduledTask;3public class MyPlugin extends JavaPlugin {4 public void onEnable() {5 ScheduledTask task = new ScheduledTask(this, () -> {6 System.out.println("Hello world!");7 });8 task.runTaskTimer(20, 20);9 }10}11import org.bukkit.plugin.java.JavaPlugin;12import be.seeseemelk.mockbukkit.scheduler.ScheduledTask;13public class MyPlugin extends JavaPlugin {14 public void onEnable() {15 ScheduledTask task = new ScheduledTask(this, () -> {16 System.out.println("Hello world!");17 });18 task.runTaskLater(20);19 }20}21import org.bukkit.plugin.java.JavaPlugin;22import be.seeseemelk.mockbukkit.scheduler.ScheduledTask;23public class MyPlugin extends JavaPlugin {24 public void onEnable() {25 ScheduledTask task = new ScheduledTask(this, () -> {26 System.out.println("Hello world!");27 });28 task.runTaskAsynchronously();29 }30}31import org.bukkit.plugin.java.JavaPlugin;32import be.seeseemelk.mockbukkit.scheduler.ScheduledTask;33public class MyPlugin extends JavaPlugin {34 public void onEnable() {35 ScheduledTask task = new ScheduledTask(this, () -> {36 System.out.println("Hello world!");37 });38 task.runTaskTimerAsynchronously(20, 20);39 }40}41import org.bukkit.plugin.java.JavaPlugin;42import be.seeseemelk.mockbukkit.scheduler.ScheduledTask;43public class MyPlugin extends JavaPlugin {44 public void onEnable() {45 ScheduledTask task = new ScheduledTask(this, () -> {46 System.out.println("Hello world!");47 });

Full Screen

Full Screen

ScheduledTask

Using AI Code Generation

copy

Full Screen

1import org.junit.Test;2import org.junit.Before;3import org.junit.After;4import org.junit.runner.RunWith;5import org.junit.runners.JUnit4;6import org.junit.Rule;7import org.junit.rules.ExpectedException;8import org.junit.rules.Timeout;9import java.util.concurrent.TimeUnit;10import java.util.concurrent.TimeoutException;11import java.util.concurrent.Callable;12import java.util.concurrent.ExecutionException;13import java.util.concurrent.Future;14import java.util.concurrent.Executors;15import java.util.concurrent.ExecutorService;16import java.util.concurrent.ScheduledExecutorService;17import java.util.concurrent.ScheduledFuture;18import java.util.concurrent.ScheduledThreadPoolExecutor;19import java.util.concurrent.ThreadFactory;20import java.util.concurrent.ThreadPoolExecutor;21import java.util.concurrent.atomic.AtomicInteger;22import java.util.concurrent.atomic.AtomicBoolean;23import java.util.concurrent.locks.Lock;24import java.util.concurrent.locks.ReentrantLock;25import java.util.concurrent.locks.Condition;26import java.util.concurrent.locks.ReentrantReadWriteLock;27import java.util.concurrent.locks.ReadWriteLock;28import java.util.concurrent.locks.ReentrantLock;29import java.util.concurrent.locks.ReentrantReadWriteLock;30import java.util.concurrent.locks.Lock;31import java.util.concurrent.locks.Condition;32import java.util.concurrent.locks.ReentrantLock;33import java.util.concurrent.locks.ReentrantReadWriteLock;34import java.util.concurrent.locks.ReadWriteLock;35import java.util.concurrent.locks.Lock;36import java.util.concurrent.locks.Condition;37import java.util.concurrent.locks.ReentrantLock;38import java.util.concurrent.locks.ReentrantReadWriteLock;39import java.util.concurrent.locks.ReadWriteLock;40import java.util.concurrent.locks.Lock;41import java.util.concurrent.locks.Condition;42import java.util.concurrent.locks.ReentrantLock;43import java.util.concurrent.locks.ReentrantReadWriteLock;44import java.util.concurrent.locks.ReadWriteLock;45import java.util.concurrent.locks.Lock;46import java.util.concurrent.locks.Condition;47import java.util.concurrent.locks.ReentrantLock;48import java.util.concurrent.locks.ReentrantReadWriteLock;49import java.util.concurrent.locks.ReadWriteLock;50import java.util.concurrent.locks.Lock;51import java.util.concurrent.locks.Condition;52import java.util.concurrent.locks.ReentrantLock;53import java.util.concurrent.locks.ReentrantReadWriteLock;54import java.util.concurrent.locks.ReadWriteLock;55import java.util.concurrent.locks.Lock;56import java.util.concurrent.locks.Condition;57import java.util.concurrent.locks.ReentrantLock;58import java.util.concurrent.locks.ReentrantReadWrite

Full Screen

Full Screen

ScheduledTask

Using AI Code Generation

copy

Full Screen

1public class Test extends JavaPlugin implements Listener {2 private ScheduledTask task;3 private int count = 0;4 public void onEnable() {5 getServer().getPluginManager().registerEvents(this, this);6 task = getServer().getScheduler().runTaskTimer(this, () -> {7 getServer().broadcastMessage("Count: " + count++);8 }, 0, 1);9 }10 public void onPlayerJoin(PlayerJoinEvent event) {11 task.cancel();12 }13}14public class Test extends JavaPlugin implements Listener {15 private ScheduledTask task;16 private int count = 0;17 public void onEnable() {18 getServer().getPluginManager().registerEvents(this, this);19 task = getServer().getScheduler().runTaskTimer(this, () -> {20 getServer().broadcastMessage("Count: " + count++);21 }, 0, 1);22 }23 public void onPlayerJoin(PlayerJoinEvent event) {24 task.cancel();25 }26}27public class Test extends JavaPlugin implements Listener {28 private ScheduledTask task;29 private int count = 0;30 public void onEnable() {31 getServer().getPluginManager().registerEvents(this, this);32 task = getServer().getScheduler().runTaskTimer(this, () -> {33 getServer().broadcastMessage("Count: " + count++);34 }, 0, 1);35 }36 public void onPlayerJoin(PlayerJoinEvent event) {37 task.cancel();38 }39}40public class Test extends JavaPlugin implements Listener {

Full Screen

Full Screen

ScheduledTask

Using AI Code Generation

copy

Full Screen

1package com.example;2import be.seeseemelk.mockbukkit.scheduler.ScheduledTask;3import org.junit.jupiter.api.BeforeEach;4import org.junit.jupiter.api.Test;5import org.junit.jupiter.api.extension.ExtendWith;6import org.mockito.Mock;7import org.mockito.junit.jupiter.MockitoExtension;8import org.mockito.junit.jupiter.MockitoSettings;9import org.mockito.quality.Strictness;10import org.mockito.stubbing.Answer;11import static org.junit.jupiter.api.Assertions.assertEquals;12import static org.junit.jupiter.api.Assertions.assertTrue;13import static org.mockito.Mockito.*;14@ExtendWith(MockitoExtension.class)15@MockitoSettings(strictness = Strictness.LENIENT)16public class ExampleTest {17 private Server server;18 private Plugin plugin;19 private Player player;20 private ScheduledTask task;21 public void setUp() {22 PluginManager pluginManager = mock(PluginManager.class);23 when(server.getPluginManager()).thenReturn(pluginManager);24 Scheduler scheduler = mock(Scheduler.class);25 when(server.getScheduler()).thenReturn(scheduler);26 when(player.getName()).thenReturn("MockPlayer");27 when(plugin.getServer()).thenReturn(server);28 when(plugin.getName()).thenReturn("MockPlugin");29 when(task.getTaskId()).thenReturn(0);30 }31 public void test() {32 server.addPlayer(player);33 server.getPluginManager().registerEvents(new Listener(), plugin);34 server.getScheduler().runTask(plugin, () -> {35 });36 verify(task).run();37 assertTrue(server.getOnlinePlayers().contains(player));38 assertEquals("MockPlayer", player.getName());39 }40}41package com.example;42import be.seeseemelk.mockbukkit.scheduler.ScheduledTask;43import org.junit.jupiter.api.BeforeEach;44import org.junit.jupiter.api.Test;45import org.junit.jupiter.api.extension.Extend

Full Screen

Full Screen

ScheduledTask

Using AI Code Generation

copy

Full Screen

1import org.bukkit.scheduler.BukkitTask;2import org.junit.Test;3import static org.junit.Assert.*;4import be.seeseemelk.mockbukkit.MockBukkit;5import be.seeseemelk.mockbukkit.scheduler.ScheduledTask;6import be.seeseemelk.mockbukkit.scheduler.SchedulerMock;7public class Test2 {8 public void test() {9 MockBukkit mockbukkit = MockBukkit.mock();10 SchedulerMock scheduler = mockbukkit.getScheduler();11 BukkitTask task = scheduler.runTaskLater(null, () -> {12 System.out.println("Hello, world!");13 }, 100);14 int taskId = ((ScheduledTask) task).getTaskId();15 System.out.println("taskId = " + taskId);16 assertEquals(0, taskId);17 mockbukkit.unmock();18 }19}20BUILD SUCCESSFUL (total time: 0 seconds)

Full Screen

Full Screen

ScheduledTask

Using AI Code Generation

copy

Full Screen

1import be.seeseemelk.mockbukkit.scheduler.ScheduledTask;2public class 2 extends JavaPlugin {3 public void onEnable() {4 ScheduledTask task = new ScheduledTask(() -> {5 getLogger().info("Hello World!");6 }, 5, 5, TimeUnit.SECONDS);7 task.runTaskLater(this, 10);8 }9}10import be.seeseemelk.mockbukkit.scheduler.ScheduledTask;11public class 3 extends JavaPlugin {12 public void onEnable() {13 ScheduledTask task = new ScheduledTask(() -> {14 getLogger().info("Hello World!");15 }, 5, 5, TimeUnit.SECONDS);16 task.runTaskLater(this, 10);17 task.cancel();18 }19}20import be.seeseemelk.mockbukkit.scheduler.ScheduledTask;21public class 4 extends JavaPlugin {22 public void onEnable() {23 ScheduledTask task = new ScheduledTask(() -> {24 getLogger().info("Hello World!");25 }, 5, 5, TimeUnit.SECONDS);26 task.runTaskLater(this, 10);27 task.cancel();28 task.runTask(this);29 }30}

Full Screen

Full Screen

ScheduledTask

Using AI Code Generation

copy

Full Screen

1import be.seeseemelk.mockbukkit.scheduler.ScheduledTask;2import org.bukkit.Bukkit;3import org.bukkit.WeatherType;4import org.bukkit.command.Command;5import org.bukkit.command.CommandSender;6import org.bukkit.entity.Player;7import org.bukkit.plugin.java.JavaPlugin;8public class 2 extends JavaPlugin {9 public void onEnable() {10 }11 public void onDisable() {12 }13 public boolean onCommand(CommandSender sender, Command command, String label, String[] args) {14 if (command.getName().equalsIgnoreCase("settime")) {15 if (args.length == 1) {16 long time = Long.parseLong(args[0]);17 Bukkit.getScheduler().scheduleSyncDelayedTask(this, () -> {18 for (Player player : Bukkit.getOnlinePlayers()) {19 player.setPlayerTime(time, false);20 }21 });22 }23 }24 if (command.getName().equalsIgnoreCase("setweather")) {25 if (args.length == 1) {26 if (args[0].equalsIgnoreCase("clear")) {27 Bukkit.getScheduler().scheduleSyncDelayedTask(this, () -> {28 for (Player player : Bukkit.getOnlinePlayers()) {29 player.setPlayerWeather(WeatherType.CLEAR);30 }31 });32 }33 if (args[0].equalsIgnoreCase("rain")) {34 Bukkit.getScheduler().scheduleSyncDelayedTask(this, () -> {35 for (Player player : Bukkit.getOnlinePlayers()) {36 player.setPlayerWeather(WeatherType.DOWNFALL);37 }38 });39 }40 }41 }42 return true;43 }44}45import be.seeseemelk.mockbukkit.scheduler.ScheduledTask;46import org.bukkit.Bukkit;47import org.bukkit.WeatherType;48import org.bukkit.command.Command;49import org.bukkit.command

Full Screen

Full Screen

Automation Testing Tutorials

Learn to execute automation testing from scratch with LambdaTest Learning Hub. Right from setting up the prerequisites to run your first automation test, to following best practices and diving deeper into advanced test scenarios. LambdaTest Learning Hubs compile a list of step-by-step guides to help you be proficient with different test automation frameworks i.e. Selenium, Cypress, TestNG etc.

LambdaTest Learning Hubs:

YouTube

You could also refer to video tutorials over LambdaTest YouTube channel to get step by step demonstration from industry experts.

Run MockBukkit automation tests on LambdaTest cloud grid

Perform automation testing on 3000+ real desktop and mobile devices online.

Try LambdaTest Now !!

Get 100 minutes of automation test minutes FREE!!

Next-Gen App & Browser Testing Cloud

Was this article helpful?

Helpful

NotHelpful