Class FoliaScheduler
java.lang.Object
me.tamkungz.signals.folia.FoliaScheduler
Small wrapper over the Folia schedulers for one plugin.
On Folia every region ticks on its own thread, so code that touches a block, chunk or entity must run on the
thread that owns it. The methods here pick the matching scheduler; ownsRegion(Location),
ownsEntity(Entity) and isGlobalThread() tell whether the current thread already is that
thread. Outside Folia, Paper runs the same schedulers on the main thread.
-
Constructor Summary
ConstructorsConstructorDescriptionFoliaScheduler(org.bukkit.plugin.Plugin plugin) Creates a scheduler for a plugin. -
Method Summary
Modifier and TypeMethodDescriptionvoidRuns a task right away on a thread that is not tied to any region.booleanRuns a task on the next tick of the region that owns an entity, following the entity if it moves.voidRuns a task on the next tick of the global region.static booleanisFolia()Tells whether the server is Folia.booleanTells whether the current thread is the global region thread (the main thread outside Folia).booleanownsEntity(org.bukkit.entity.Entity entity) Tells whether the current thread owns an entity.booleanownsRegion(org.bukkit.Location location) Tells whether the current thread owns the region around a location.org.bukkit.plugin.Pluginplugin()Returns the plugin that owns the scheduled tasks.voidRuns a task on the next tick of the region that owns a location.voidRuns a task on the next tick of the region that owns a chunk.
-
Constructor Details
-
FoliaScheduler
public FoliaScheduler(org.bukkit.plugin.Plugin plugin) Creates a scheduler for a plugin.- Parameters:
plugin- plugin that owns the scheduled tasks
-
-
Method Details
-
isFolia
public static boolean isFolia()Tells whether the server is Folia.- Returns:
truewhen regionised multithreading is active
-
plugin
public org.bukkit.plugin.Plugin plugin()Returns the plugin that owns the scheduled tasks.- Returns:
- the owning plugin
-
isGlobalThread
public boolean isGlobalThread()Tells whether the current thread is the global region thread (the main thread outside Folia).- Returns:
trueon the global tick thread
-
ownsRegion
public boolean ownsRegion(org.bukkit.Location location) Tells whether the current thread owns the region around a location.- Parameters:
location- location to check- Returns:
trueif the current region owns it
-
ownsEntity
public boolean ownsEntity(org.bukkit.entity.Entity entity) Tells whether the current thread owns an entity.- Parameters:
entity- entity to check- Returns:
trueif the current region owns it
-
global
Runs a task on the next tick of the global region.- Parameters:
task- task to run
-
region
Runs a task on the next tick of the region that owns a location.- Parameters:
location- location whose region runs the tasktask- task to run
-
region
Runs a task on the next tick of the region that owns a chunk.- Parameters:
world- world of the chunkchunkX- chunk X coordinatechunkZ- chunk Z coordinatetask- task to run
-
entity
Runs a task on the next tick of the region that owns an entity, following the entity if it moves.- Parameters:
entity- entity whose region runs the tasktask- task to runretired- called instead oftaskif the entity was removed first, may benull- Returns:
falseif the entity was already removed and the task was not scheduled
-
async
Runs a task right away on a thread that is not tied to any region.- Parameters:
task- task to run
-