Class Util

java.lang.Object
nl.pim16aap2.animatedarchitecture.core.util.Util

public final class Util extends Object
Represents various small and platform-agnostic utility functions.
  • Method Details

    • requireNonNull

      @Contract("null, _ -> fail") public static <T> T requireNonNull(@Nullable T obj, String name) throws NullPointerException
      Ensures an object is not null.

      If the object is null after all, a NullPointerException will be thrown.

      This is basically the same as Objects.requireNonNull(Object, String) with the only difference being that this will create a full "must not be null" message for the provided variable name.

      Type Parameters:
      T - The type of the input object.
      Parameters:
      obj - The object to check.
      name - The name of the input object. This is used in the NPE message with the format "{name} must not be null!".
      Returns:
      The input object, if it is not null.
      Throws:
      NullPointerException - If the input object to check is null.
    • valOrDefault

      public static <T> T valOrDefault(@Nullable T value, Supplier<T> fallback)
      Gets a not-null value from a nullable one, with a provided fallback in case the value is null.
      Type Parameters:
      T - The type of the value.
      Parameters:
      value - The value that may or may not be null.
      fallback - A Supplier to supply a fallback to return in case the value is null.
      Returns:
      The value if it is not null, otherwise the fallback.
    • getMovementDirection

      public static MovementDirection getMovementDirection(BlockFace blockFace)
      Gets the MovementDirection equivalent of a BlockFace if it exists.
      Parameters:
      blockFace - The BlockFace.
      Returns:
      The MovementDirection equivalent of a BlockFace if it exists and otherwise MovementDirection.NONE.
    • getBlockFace

      public static BlockFace getBlockFace(MovementDirection movementDirection)
      Gets the BlockFace equivalent of a MovementDirection if it exists.
      Parameters:
      movementDirection - The MovementDirection.
      Returns:
      The BlockFace equivalent of a MovementDirection if it exists and otherwise BlockFace.NONE.
    • hasPermissionForAction

      public static boolean hasPermissionForAction(UUID uuid, IStructureConst structure, StructureAttribute attribute)
      Check if a player has permission to perform an action on a structure.

      A player has permission to perform an action on a structure if they are an owner of the structure and their permission level is lower than or equal to the permission level of the attribute. See PermissionLevel.isLowerThanOrEquals(PermissionLevel).

      If the provided player is not an owner of the structure, they do not have permission to perform the action.

      Parameters:
      uuid - The UUID of the player to check.
      structure - The structure to check.
      attribute - The attribute to check.
      Returns:
      True if the player has permission to perform the action on the structure.
    • hasPermissionForAction

      public static boolean hasPermissionForAction(IPlayer player, IStructureConst structure, StructureAttribute attribute)
      Check if a player has permission to perform an action on a structure.

      See hasPermissionForAction(UUID, IStructureConst, StructureAttribute).

      Parameters:
      player - The player to check.
      structure - The structure to check.
      attribute - The attribute to check.
      Returns:
      True if the player has permission to perform the action on the structure.
    • parseLogLevelStrict

      public static @Nullable Level parseLogLevelStrict(@Nullable String logLevelName)
      Parses the Level from its name.

      The strict refers to the aspect that only name matches are allowed. See Level.getName(). Contrary to Level.parse(String), this method won't define new levels from integer inputs.

      Parameters:
      logLevelName - The name of the log level.
      Returns:
      The Level if an exact match could be found, otherwise null.
    • getRootCause

      public static Throwable getRootCause(Throwable throwable)
      Gets the root cause of a Throwable.
      Parameters:
      throwable - The Throwable to get the root cause of.
      Returns:
      The root cause of the Throwable.