public interface CauseStackManager
For example a plugin may wish to push a player into the cause stack before spawning an entity to expose to any plugin listening for SpawnEntityEvents that the player is the reason that the entity was spawned.
This system will automatically handle associating a plugin with actions performed inside of event listeners, command executors, and scheduled tasks.
Modifier and Type | Interface and Description |
---|---|
static interface |
CauseStackManager.StackFrame |
Modifier and Type | Method and Description |
---|---|
<T> CauseStackManager |
addContext(EventContextKey<T> key,
T value)
Adds the given object to the current context under the given key.
|
<T> Optional<T> |
getContext(EventContextKey<T> key)
Gets the context value with the given key.
|
Cause |
getCurrentCause()
Gets the current
Cause object from the current cause stack. |
EventContext |
getCurrentContext()
Gets an
EventContext object on the current contextual
information. |
Object |
peekCause()
Retrieves but does not remove the most recently pushed cause object.
|
Object |
popCause()
Pops the most recently pushed cause object off of the stack and returns
it.
|
void |
popCauseFrame(CauseStackManager.StackFrame handle)
Replaces the current cause stack and context with the cause frame at the
top of the frame stack.
|
void |
popCauses(int n)
Pops the most recently n pushed cause objects off of the stack.
|
CauseStackManager |
pushCause(Object obj)
Pushes an object to the current cause stack which will associate it with
all events through from api actions until it is popped off again.
|
CauseStackManager.StackFrame |
pushCauseFrame()
Pushes a frame of the current cause stack and context state.
|
<T> Optional<T> |
removeContext(EventContextKey<T> key)
Removes the given context key from the current context.
|
default <T> T |
requireContext(EventContextKey<T> key)
Gets the context value with the given key.
|
Cause getCurrentCause()
Cause
object from the current cause stack.EventContext getCurrentContext()
EventContext
object on the current contextual
information.CauseStackManager pushCause(Object obj)
obj
- The object to push to the stackObject popCause()
void popCauses(int n)
n
- The number of causes to popObject peekCause()
CauseStackManager.StackFrame pushCauseFrame()
void popCauseFrame(CauseStackManager.StackFrame handle)
The frame handle is required to ensure that frames are popped of in order and are not left in the stack. If an attempt is made to pop a frame which is not the head of the frame stack then an error will be thrown as this indicates that a frame was not popped properly.
handle
- The frame handle to pop<T> CauseStackManager addContext(EventContextKey<T> key, T value)
T
- The type of the value stored with the event context keykey
- The context keyvalue
- The objectEventContextKeys
<T> Optional<T> getContext(EventContextKey<T> key)
T
- The type of the value stored with the event context keykey
- The context keydefault <T> T requireContext(EventContextKey<T> key)
If the key is not available, NoSuchElementException
will be
thrown.
T
- The type of the value stored with the event context keykey
- The context key<T> Optional<T> removeContext(EventContextKey<T> key)
T
- The type of the value stored with the event context keykey
- The key to clearEventContextKeys