Java API
class

FoliaScheduler

me.tamkungz.signals.folia.FoliaScheduler

Version
0.2.1-SNAPSHOT
Java
21
Source file
me/tamkungz/signals/folia/FoliaScheduler.java
Repository
View source ↗

Small wrapper over the Folia schedulers for one plugin.

<p>

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; {@link #ownsRegion(Location)},

{@link #ownsEntity(Entity)} and {@link #isGlobalThread()} tell whether the current thread already is that

thread. Outside Folia, Paper runs the same schedulers on the main thread.

public final class FoliaScheduler

Constructors 1

FoliaScheduler

public FoliaScheduler(Plugin plugin)

Creates a scheduler for a plugin.

@param
plugin plugin that owns the scheduled tasks

Methods 10

isFolia

public static boolean isFolia()

Tells whether the server is Folia.

@return
{@code true} when regionised multithreading is active

plugin

public Plugin plugin()

Returns the plugin that owns the scheduled tasks.

@return
the owning plugin

isGlobalThread

public boolean isGlobalThread()

Tells whether the current thread is the global region thread (the main thread outside Folia).

@return
{@code true} on the global tick thread

ownsRegion

public boolean ownsRegion(Location location)

Tells whether the current thread owns the region around a location.

@param
location location to check
@return
{@code true} if the current region owns it

ownsEntity

public boolean ownsEntity(Entity entity)

Tells whether the current thread owns an entity.

@param
entity entity to check
@return
{@code true} if the current region owns it

global

public void global(Runnable task)

Runs a task on the next tick of the global region.

@param
task task to run

region

public void region(Location location, Runnable task)

Runs a task on the next tick of the region that owns a location.

@param
location location whose region runs the task
@param
task task to run

region

public void region(World world, int chunkX, int chunkZ, Runnable task)

Runs a task on the next tick of the region that owns a chunk.

@param
world world of the chunk
@param
chunkX chunk X coordinate
@param
chunkZ chunk Z coordinate
@param
task task to run

entity

public boolean entity(Entity entity, Runnable task, Runnable retired)

Runs a task on the next tick of the region that owns an entity, following the entity if it moves.

@param
entity entity whose region runs the task
@param
task task to run
@param
retired called instead of {@code task} if the entity was removed first, may be {@code null}
@return
{@code false} if the entity was already removed and the task was not scheduled

async

public void async(Runnable task)

Runs a task right away on a thread that is not tied to any region.

@param
task task to run