public final class Cause extends Object implements Iterable<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 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 | Class and Description |
---|---|
static class |
Cause.Builder |
Modifier and Type | Method and Description |
---|---|
Optional<?> |
after(Class<?> clazz)
Gets the object immediately after the object that is an instance of the
Class passed in. |
List<Object> |
all()
|
<T> List<T> |
allOf(Class<T> target)
|
Optional<?> |
before(Class<?> clazz)
Gets the object immediately before the object that is an instance of the
Class passed in. |
static Cause.Builder |
builder()
Creates a new
Cause.Builder to make a new Cause . |
boolean |
contains(Object object)
Checks if this cause contains of any of the provided
Object . |
boolean |
containsType(Class<?> target)
Returns whether the target class matches any object of this
Cause
. |
boolean |
equals(Object object) |
<T> Optional<T> |
first(Class<T> target)
Gets the first
T object of this Cause , if available. |
EventContext |
getContext()
Gets the event context relating to this cause.
|
int |
hashCode() |
Iterator<Object> |
iterator() |
<T> Optional<T> |
last(Class<T> target)
Gets the last object instance of the
Class of type
T . |
List<Object> |
noneOf(Class<?> ignoredClass)
|
static Cause |
of(EventContext ctx,
Iterable<Object> iterable)
Constructs a new cause with the specified event context and causes.
|
static Cause |
of(EventContext ctx,
Object cause)
Constructs a new cause with the specified event context and cause.
|
static Cause |
of(EventContext ctx,
Object cause,
Object... causes)
Constructs a new cause with the specified event context and causes.
|
Object |
root()
Gets the root
Object of this cause. |
String |
toString() |
Cause |
with(Cause cause)
Merges this cause with the other cause.
|
Cause |
with(Iterable<Object> iterable)
Creates a new
Cause where the objects are added at the end of the
cause array of objects. |
Cause |
with(Object additional)
Creates a new
Cause where the objects are added at the end of the
cause array of objects. |
Cause |
with(Object additional,
Object... additionals)
Creates a new
Cause where the objects are added at the end of the
cause array of objects. |
clone, finalize, getClass, notify, notifyAll, wait, wait, wait
forEach, spliterator
public static Cause.Builder builder()
Cause.Builder
to make a new Cause
.public static Cause of(EventContext ctx, Object cause)
ctx
- The event contextcause
- The direct object causepublic static Cause of(EventContext ctx, Object cause, Object... causes)
ctx
- The event contextcause
- The direct object causecauses
- Other associated causespublic static Cause of(EventContext ctx, Iterable<Object> iterable)
ctx
- The event contextiterable
- The associated causespublic EventContext getContext()
public Object root()
Object
of this cause.public <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 <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 Optional<?> before(Class<?> clazz)
Class
passed in.clazz
- The class of the objectpublic Optional<?> after(Class<?> clazz)
Class
passed in.clazz
- The class to type checkpublic boolean containsType(Class<?> target)
Cause
.target
- The class of the target typepublic boolean contains(Object object)
Object
. This
is the equivalent to checking based on equals(Object)
for each
object in this cause.object
- The object to check if it is containedpublic <T> List<T> allOf(Class<T> target)
T
- The type of objects to query fortarget
- The class of the target typepublic List<Object> noneOf(Class<?> ignoredClass)
ignoredClass
- The class of object types to ignorepublic Cause with(Object additional)
Cause
where the objects are added at the end of the
cause array of objects.additional
- The additional object to addpublic Cause with(Object additional, Object... additionals)
Cause
where the objects are added at the end of the
cause array of objects.additional
- The additional object to addadditionals
- The remaining objects to addpublic Cause with(Iterable<Object> iterable)
Cause
where the objects are added at the end of the
cause array of objects.iterable
- The additional objectspublic Cause with(Cause cause)
cause
- The cause to merge with this