Class Util
-
Method Summary
Modifier and TypeMethodDescriptionstatic BlockFacegetBlockFace(MovementDirection movementDirection) Gets theBlockFaceequivalent of aMovementDirectionif it exists.static MovementDirectiongetMovementDirection(BlockFace blockFace) Gets theMovementDirectionequivalent of aBlockFaceif it exists.static ThrowablegetRootCause(Throwable throwable) Gets the root cause of aThrowable.static booleanhasPermissionForAction(UUID uuid, IStructureConst structure, StructureAttribute attribute) Check if a player has permission to perform an action on a structure.static booleanhasPermissionForAction(IPlayer player, IStructureConst structure, StructureAttribute attribute) Check if a player has permission to perform an action on a structure.static @Nullable LevelparseLogLevelStrict(@Nullable String logLevelName) Parses theLevelfrom its name.static <T> TrequireNonNull(@Nullable T obj, String name) Ensures an object is not null.static <T> TvalOrDefault(@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.
-
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
NullPointerExceptionwill 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
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- ASupplierto supply a fallback to return in case the value is null.- Returns:
- The value if it is not null, otherwise the fallback.
-
getMovementDirection
Gets theMovementDirectionequivalent of aBlockFaceif it exists.- Parameters:
blockFace- TheBlockFace.- Returns:
- The
MovementDirectionequivalent of aBlockFaceif it exists and otherwiseMovementDirection.NONE.
-
getBlockFace
Gets theBlockFaceequivalent of aMovementDirectionif it exists.- Parameters:
movementDirection- TheMovementDirection.- Returns:
- The
BlockFaceequivalent of aMovementDirectionif it exists and otherwiseBlockFace.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
Parses theLevelfrom its name.The strict refers to the aspect that only name matches are allowed. See
Level.getName(). Contrary toLevel.parse(String), this method won't define new levels from integer inputs.- Parameters:
logLevelName- The name of the log level.- Returns:
- The
Levelif an exact match could be found, otherwise null.
-
getRootCause
-