Skip to content

SchedulesπŸ”—

API State: Unfinished

Unfinished

This part of the API is brand-new. It will be changed if there are any bugs, missing features or usability improvements.

It is not recommended relying on this part of the API, it will most likely change.

Draft

Our own usage and testing has shown that this part of the API is complete and seems bug free. However, other plugins may have other use cases which are not covered by our testing. Therefore, please go ahead and use this API part. Let us know if there are missing features or bugs. This API part will be changed if there are more bugs, missing features or usability improvements.

Please use this part of the API and give us feedback!

Stable

Both our own and third party testing showed that this part of the API is complete. Only bugs and major conceptual problems would lead to more changes.

This part of the API should be safe to use. We try to keep it compatible with previous versions if changes are needed.

If the native schedule types are not enough for you, this API enables you to create your own type.

API OverviewπŸ”—

Creating a new schedule typeπŸ”—

To implement a new schedule type you have to create both the Schedule and the Scheduler class.

About this guide

This guide will show you how to create a custom schedule that runs every x ticks, just like a redstone clock.
While this does not make that much sense, it is a super simple example to show the principle.

Schedule ClassπŸ”—

The schedule class must hold all the schedules' data. When reloading BetonQuest will try to parse all packages and construct new instances of this class.

Have a look at this example to see how to implement your own schedule.

Example Schedule
 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
public class MyCustomSchedule extends Schedule {

    private final int ticks, rebootSleep;

    
    public MyCustomSchedule(ScheduleID scheduleID, ConfigurationSection instruction) throws InstructionParseException { 
        super(scheduleID, instruction);
        try {
            ticks = Integer.parseInt(getTime());
        } catch (NumberFormatException e) {
            throw new InstructionParseException("Time is not a number");
        }

        if (getCatchup() != CatchupStrategy.NONE) {
            throw new InstructionParseException("Catchup " + getCatchup() + " is not supported by this schedule type");
        }

        rebootSleep = instruction.getInt("options.rebootSleep");
    }

    public int getTicks() { return ticks; }
    public int getRebootSleep() { return rebootSleep; }
}

Scheduler ClassπŸ”—

The scheduler will receive parsed schedules using addSchedule(S) and hold them in the schedules map.
It should contain all the scheduling & schedule execution logic.
It is also responsible for catching up missed schedules, if they have a catchup strategy other than NONE defined.

Here is a pretty basic example, that does not provide any catchup logic:

Example Scheduler
 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
public class MyCustomScheduler extends Scheduler<MyCustomSchedule> {

    private List<BukkitTask> tasks;

    @Override
    public void start() {
        super.start();

        tasks = new ArrayList<>();
        for (MyCustomSchedule schedule : schedules.values()) {
            
            BukkitTask task = new BukkitRunnable() {
                @Override
                public void run() {
                    executeEvents(schedule);
                }
            }.runTaskTimer(MyPlugin.getInstance(), schedule.getRebootSleep(), schedule.getTicks());

            tasks.add(task);
        }
    }

    @Override
    public void stop() {
        super.stop();

        for (BukkitTask task : tasks) {
            task.cancel();
        }
    }
} 

Register the typeπŸ”—

To register the new schedule type to BetonQuest, use the following method:

BetonQuest.getInstance().registerScheduleType("redstoneScheduler",
  MyCustomSchedule.class,new MyCustomScheduler());

You'll need to call it after BetonQuest was enabled.