Skip to content

Scheduler Mock

MockBukkit allows the testing of timers and delays that are normally created using the Bukkit scheduler.This schedulers is used in the same way as a normal scheduler except that it adds several extra methods.

Executing Ticks

The scheduler can be asked to perform a single tick

java
ServerMock server = Mockbukkit.getMock();
server.getScheduler().performOneTick();
kotlin
val server = Mockbukkit.getMock()
server.scheduler.performOneTick()

If more ticks need to be executed in quick succession, it’s possible to execute many ticks at once. The following code will perform a hundred ticks.

java
ServerMock server = Mockbukkit.getMock();
server.getScheduler().performTicks(100L);
kotlin
val server = Mockbukkit.getMock()
server.scheduler.performTicks(100L)

Using this method executes all ticks in order, as if they were executed on a real server.

Getting the current tick

MockBukkit has an extra method that allows to get the number of ticks since MockBukkit was last started.

java
long tick = server.getScheduler().getCurrentTick();
kotlin
val tick: Long = server.scheduler.getCurrentTick();

Released under the MIT License.