Skip to content

Schedule tasks

Endstone provides a task scheduling system that allows plugins to schedule tasks for future execution, possibly at regular intervals. In this tutorial, we'll guide you on scheduling a straightforward task.

Here, we want an on-screen popup displaying "Hi!" to appear for every online player at a 1-second interval.

src/endstone_my_plugin/my_plugin.py
 fromendstone.pluginimport Plugin

 classMyPlugin(Plugin):
 api_version = "0.10"

 # ...

 defon_enable(self) -> None:
 self.logger.info("on_enable is called!")
  self.server.scheduler.run_task(self, self.say_hi, delay=0, period=20)

  defsay_hi(self) -> None:
  for player in self.server.online_players:
  player.send_popup("Hi!")
include/my_plugin.h
 #include<endstone/endstone.hpp>

 classMyPlugin:publicendstone::Plugin{
 public:
 // ...

 voidonEnable()override
 {
 getLogger().info("onEnable is called");
 getServer().getScheduler().runTaskTimer([&](){sayHi();},0,20);
 }

 voidsayHi()
 {
 for(auto&player:getServer().getOnlinePlayers())
 {
 player->sendPopup("Hi");
 }
 }
 };

πŸ₯³ And that's it! The server will now send a "Hi" message to all players online at an interval of 20 ticks or approximately every second.

AltStyle γ«γ‚ˆγ£γ¦ε€‰ζ›γ•γ‚ŒγŸγƒšγƒΌγ‚Έ (->γ‚ͺγƒͺγ‚ΈγƒŠγƒ«) /