Beispiel #1
0
  /**
   * Expand an cause object.
   *
   * @param list the list to add elements to
   * @param element an array of objects
   */
  private static void expand(List<Object> list, @Nullable Object... element) {
    if (element != null) {
      for (Object o : element) {
        if (o == null) {
          continue;
        }

        if (o instanceof TNTPrimed) {
          expand(list, ((TNTPrimed) o).getSource());
        } else if (o instanceof Projectile) {
          expand(list, ((Projectile) o).getShooter());
        } else if (o instanceof Vehicle) {
          expand(list, ((Vehicle) o).getPassenger());
        } else if (o instanceof Tameable) {
          expand(list, ((Tameable) o).getOwner());
        }

        // Add manually tracked parent causes
        Object source = o;
        int index = list.size();
        while (source instanceof Metadatable && !(source instanceof Block)) {
          source = WGMetadata.getIfPresent((Metadatable) source, CAUSE_KEY, Object.class);
          if (source != null) {
            list.add(index, source);
          }
        }

        list.add(o);
      }
    }
  }
Beispiel #2
0
  /**
   * Add a parent cause to a {@code Metadatable} object.
   *
   * <p>Note that {@code target} cannot be an instance of {@link Block} because {@link
   * #create(Object...)} will not bother checking for such data on blocks (because it is relatively
   * costly to do so).
   *
   * @param target the target
   * @param parent the parent cause
   * @throws IllegalArgumentException thrown if {@code target} is an instance of {@link Block}
   */
  public static void trackParentCause(Metadatable target, Object parent) {
    if (target instanceof Block) {
      throw new IllegalArgumentException(
          "Can't track causes on Blocks because Cause doesn't check block metadata");
    }

    WGMetadata.put(target, CAUSE_KEY, parent);
  }