Class Cause
java.lang.Object
com.sk89q.worldguard.bukkit.cause.Cause
An instance of this object describes the actors that played a role in
causing an event, with the ability to describe a situation where one actor
controls several other actors to create the event.
For example, if a player fires an arrow that hits an item frame, the player is the initiator, while the arrow is merely controlled by the player to hit the item frame.
-
Method Summary
Modifier and TypeMethodDescriptionstatic Cause
Create a new instance with the given objects as the cause, where the first-most object is the initial initiator and those following it are controlled by the previous entry.org.bukkit.entity.EntityType
find
(org.bukkit.entity.EntityType... types) Find the first type matching one in the given array.org.bukkit.block.Block
org.bukkit.entity.Entity
org.bukkit.entity.Entity
org.bukkit.entity.Player
boolean
Test whether the traced cause is indirect.boolean
isKnown()
Return whether a cause is known.toString()
static void
trackParentCause
(org.bukkit.metadata.Metadatable target, Object parent) Add a parent cause to aMetadatable
object.static Cause
unknown()
Create a new instance that indicates that the cause is not known.static void
untrackParentCause
(org.bukkit.metadata.Metadatable target) Remove a parent cause from aMetadatable
object.
-
Method Details
-
isIndirect
public boolean isIndirect()Test whether the traced cause is indirect.If the cause is indirect, then the root cause may not be notified, for example.
- Returns:
- true if the cause is indirect
-
isKnown
public boolean isKnown()Return whether a cause is known. This method will return false if the list of causes is empty or the root cause is really not known (e.g. primed TNT).- Returns:
- true if known
-
getRootCause
-
getFirstPlayer
@Nullable public org.bukkit.entity.Player getFirstPlayer() -
getFirstEntity
@Nullable public org.bukkit.entity.Entity getFirstEntity() -
getFirstNonPlayerEntity
@Nullable public org.bukkit.entity.Entity getFirstNonPlayerEntity() -
getFirstBlock
@Nullable public org.bukkit.block.Block getFirstBlock() -
find
@Nullable public org.bukkit.entity.EntityType find(org.bukkit.entity.EntityType... types) Find the first type matching one in the given array.- Parameters:
types
- an array of types- Returns:
- a found type or null
-
toString
-
create
Create a new instance with the given objects as the cause, where the first-most object is the initial initiator and those following it are controlled by the previous entry.- Parameters:
cause
- an array of causing objects- Returns:
- a cause
-
unknown
Create a new instance that indicates that the cause is not known.- Returns:
- a cause
-
trackParentCause
Add a parent cause to aMetadatable
object.Note that
target
cannot be an instance ofBlock
becausecreate(Object...)
will not bother checking for such data on blocks (because it is relatively costly to do so).- Parameters:
target
- the targetparent
- the parent cause- Throws:
IllegalArgumentException
- thrown iftarget
is an instance ofBlock
-
untrackParentCause
public static void untrackParentCause(org.bukkit.metadata.Metadatable target) Remove a parent cause from aMetadatable
object.- Parameters:
target
- the target
-