Skip to content
This repository has been archived by the owner on Jun 19, 2024. It is now read-only.

Scheduling

Alan Gomes edited this page May 21, 2019 · 1 revision

Creating scheduled tasks is easier than ever, you can simply use the Scheduler bean, which allows you to create the tasks without needing to have a reference to the Plugin or Server. This custom scheduler also keeps the current context during the execution(s), everything just works.

Example:

@Service
class AnnounceService {
   
    @Autowired
    private Scheduler scheduler;
    
    @Autowired
    private Context context;
    
    @Autowired
    private ChatService chatService;

    public void announce(String message, long delay) {
        scheduler.scheduleSyncDelayedTask(() -> {
            chatService.broadcast(context.getPlayer().getName() + " said " + message);
        }, delay);
    }

}