Class Cause

java.lang.Object
com.sk89q.worldguard.bukkit.cause.Cause

public final class Cause extends Object
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 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

      @Nullable public Object 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

      public String toString()
      Overrides:
      toString in class Object
    • create

      public static Cause create(@Nullable Object... 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.
      Parameters:
      cause - an array of causing objects
      Returns:
      a cause
    • unknown

      public static Cause unknown()
      Create a new instance that indicates that the cause is not known.
      Returns:
      a cause
    • trackParentCause

      public static void trackParentCause(org.bukkit.metadata.Metadatable target, Object parent)
      Add a parent cause to a Metadatable object.

      Note that target cannot be an instance of Block because create(Object...) will not bother checking for such data on blocks (because it is relatively costly to do so).

      Parameters:
      target - the target
      parent - the parent cause
      Throws:
      IllegalArgumentException - thrown if target is an instance of Block
    • untrackParentCause

      public static void untrackParentCause(org.bukkit.metadata.Metadatable target)
      Remove a parent cause from a Metadatable object.
      Parameters:
      target - the target