Java API
class

FoliaSignals

me.tamkungz.signals.folia.FoliaSignals

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

{@link BukkitSignals} for Folia: the same signals, plus listeners that hop to the thread they need.

<p>

On Folia a Bukkit event is fired on the thread of the region that owns it, and a listener may only touch

blocks, chunks and entities of that region. When a listener has to work on something owned by another region

(the world around a location, another player, ...), connect it with {@link #connectRegion},

{@link #connectEntity}, {@link #connectGlobal} or {@link #connectAsync}. Those run the listener inline when

the current thread already is the right one and schedule it otherwise.

<p>

Signals and connections are thread-safe, so plain {@code connect} calls from any region thread are fine.

public final class FoliaSignals implements EventSignalSource

Methods 19

create

public static FoliaSignals create(Plugin plugin)

Creates a bridge with its own signal bus.

@param
plugin plugin that owns the Bukkit listeners and the scheduled tasks
@return
a new bridge

create

public static FoliaSignals create(Plugin plugin, SignalBus bus)

Creates a bridge on an existing signal bus.

@param
plugin plugin that owns the Bukkit listeners and the scheduled tasks
@param
bus bus the signals live on
@return
a new bridge

shared

public static FoliaSignals shared()

Returns a bridge over the one shared by every plugin through the installed SignalsLib plugin. <p> Events and listeners are shared with {@link BukkitSignals#shared()}; scheduled tasks belong to SignalsLib.

@return
a bridge over the shared signals

bukkit

public BukkitSignals bukkit()

Returns the Bukkit bridge behind this one.

@return
the Bukkit bridge

bus

public SignalBus bus()

Returns the signal bus behind this bridge.

@return
the signal bus

scheduler

public FoliaScheduler scheduler()

Returns the scheduler wrapper of this bridge.

@return
the scheduler

signal

@Override public <T extends Event> Signal<T> signal(Class<T> eventType, EventPriority priority, boolean ignoreCancelled)

players

public PlayerSignals players()

Returns shortcuts for player events.

@return
player signals

blocks

public BlockSignals blocks()

Returns shortcuts for block events.

@return
block signals

entities

public EntitySignals entities()

Returns shortcuts for entity events.

@return
entity signals

inventories

public InventorySignals inventories()

Returns shortcuts for inventory events.

@return
inventory signals

connectGlobal

public <T> Connection connectGlobal(Signal<T> signal, Consumer<T> listener)

Connects a listener that runs on the global region thread.

@param
signal signal to listen to
@param
listener listener to call
@param
<T> payload type
@return
the connection for this listener

connectGlobal

public <T> Connection connectGlobal(ConnectionGroup group, Signal<T> signal, Consumer<T> listener)

Connects a listener that runs on the global region thread and tracks it in a group.

@param
group group that will disconnect the listener
@param
signal signal to listen to
@param
listener listener to call
@param
<T> payload type
@return
the connection for this listener

connectAsync

public <T> Connection connectAsync(Signal<T> signal, Consumer<T> listener)

Connects a listener that always runs on an async thread, never on a region thread.

@param
signal signal to listen to
@param
listener listener to call
@param
<T> payload type
@return
the connection for this listener

connectAsync

public <T> Connection connectAsync(ConnectionGroup group, Signal<T> signal, Consumer<T> listener)

Connects a listener that always runs on an async thread and tracks it in a group.

@param
group group that will disconnect the listener
@param
signal signal to listen to
@param
listener listener to call
@param
<T> payload type
@return
the connection for this listener

connectRegion

public <T> Connection connectRegion( Signal<T> signal, Function<? super T, ? extends Location> locator, Consumer<T> listener )

Connects a listener that runs on the thread of the region that owns a location taken from the payload.

@param
signal signal to listen to
@param
locator picks the location from the payload, must not return {@code null}
@param
listener listener to call
@param
<T> payload type
@return
the connection for this listener

connectRegion

public <T> Connection connectRegion( ConnectionGroup group, Signal<T> signal, Function<? super T, ? extends Location> locator, Consumer<T> listener )

Connects a listener that runs on the region thread of a location taken from the payload and tracks it in a group.

@param
group group that will disconnect the listener
@param
signal signal to listen to
@param
locator picks the location from the payload, must not return {@code null}
@param
listener listener to call
@param
<T> payload type
@return
the connection for this listener

connectEntity

public <T> Connection connectEntity( Signal<T> signal, Function<? super T, ? extends Entity> locator, Consumer<T> listener )

Connects a listener that runs on the thread of the region that owns an entity taken from the payload. <p> If the entity is removed before the listener gets to run, that call is dropped.

@param
signal signal to listen to
@param
locator picks the entity from the payload, must not return {@code null}
@param
listener listener to call
@param
<T> payload type
@return
the connection for this listener

connectEntity

public <T> Connection connectEntity( ConnectionGroup group, Signal<T> signal, Function<? super T, ? extends Entity> locator, Consumer<T> listener )

Connects a listener that runs on the region thread of an entity taken from the payload and tracks it in a group.

@param
group group that will disconnect the listener
@param
signal signal to listen to
@param
locator picks the entity from the payload, must not return {@code null}
@param
listener listener to call
@param
<T> payload type
@return
the connection for this listener