public abstract class Cause extends Object
For example, if a block of sand is placed where it drops, the block of sand would create a falling sand entity, which then would place another block of sand. The block place event for the final block of sand would have the cause chain of the block of sand -> falling sand entity.
It is not possible to accurately the describe the chain of causes in all scenarios so a best effort approach is generally acceptable. For example, a player might press a lever, activating a complex Redstone circuit, which would then launch TNT and cause the destruction of some blocks, but tracing this event would be too complicated and thus may not be attempted.
Modifier and Type | Method and Description |
---|---|
abstract Optional<?> |
after(Class<?> clazz)
Gets the object immediately after the object that is an instance of
the
Class passed in. |
abstract List<Object> |
all()
|
abstract <T> List<T> |
allOf(Class<T> target)
|
abstract boolean |
any(Class<?> target)
Returns whether the target class matches any object of this
Cause . |
abstract Optional<?> |
before(Class<?> clazz)
Gets the object immediately before the object that is an instance of
the
Class passed in. |
static Cause |
empty()
Gets the "empty"
Cause . |
abstract boolean |
equals(Object object)
Returns
true if object is a Cause instance, and
either the contained references are equal to
each other or both are absent. |
abstract <T> Optional<T> |
first(Class<T> target)
Gets the first
T object of this Cause , if
available. |
abstract int |
hashCode()
Returns a hash code for this instance.
|
abstract boolean |
isEmpty()
Gets whether this
Cause is empty of any causes or not. |
abstract <T> Optional<T> |
last(Class<T> target)
Gets the last object instance of the
Class of type
T . |
abstract List<Object> |
noneOf(Class<?> ignoredClass)
|
static Cause |
of(Object... objects)
|
static Cause |
ofNullable(Object... objects) |
abstract Optional<?> |
root()
Gets the root
Object of this cause. |
abstract Cause |
with(Iterable<?> iterable)
Creates a new
Cause where the objects are added at the end of
the cause array of objects. |
abstract Cause |
with(Object... additional)
Creates a new
Cause where the objects are added at the end of
the cause array of objects. |
public static Cause empty()
Cause
. If a Cause
is required, but
there is no Object
that can be stated as the direct "cause" of
an Event
, an "empty" Cause
can be used.public static Cause of(Object... objects)
Cause
of the provided Object
s. Note that
none of the provided Object
s can be null
. The order
of the objects should represent the "priority" that the object aided in
the "cause" of an Event
. The first Object
should be the
direct "cause" of the Event
.
Usually, in most cases, some Event
s will have "helper"
objects to interface with their direct causes, such as
DamageSource
for an DamageEntityEvent
, or a
SpawnCause
for an SpawnEntityEvent
.
objects
- The objects being the causepublic abstract boolean isEmpty()
Cause
is empty of any causes or not. An empty
cause may mean the Cause
is not originating from any vanilla
interactions, or it may mean the cause is simply not known.public abstract Optional<?> root()
Object
of this cause. The root can be anything,
including but not limited to: DamageSource
, Entity
,
SpawnCause
, etc.public abstract <T> Optional<T> first(Class<T> target)
T
object of this Cause
, if
available.T
- The type of object being queried fortarget
- The class of the target typepublic abstract <T> Optional<T> last(Class<T> target)
Class
of type
T
.T
- The type of object being queried fortarget
- The class of the target typepublic abstract Optional<?> before(Class<?> clazz)
Class
passed in.clazz
- The class of the objectpublic abstract Optional<?> after(Class<?> clazz)
Class
passed in.clazz
- public abstract boolean any(Class<?> target)
Cause
.target
- The class of the target typepublic abstract <T> List<T> allOf(Class<T> target)
T
- The type of objects to query fortarget
- The class of the target typepublic abstract List<Object> noneOf(Class<?> ignoredClass)
ignoredClass
- The class of object types to ignorepublic abstract Cause with(Object... additional)
Cause
where the objects are added at the end of
the cause array of objects.additional
- The additional objects to addpublic abstract Cause with(Iterable<?> iterable)
Cause
where the objects are added at the end of
the cause array of objects.iterable
- The additional objectspublic abstract boolean equals(@Nullable Object object)
true
if object
is a Cause
instance, and
either the contained references are equal to
each other or both are absent.