Package dev.cwhead.GravesX.api.util
Class UtilAPI
java.lang.Object
dev.cwhead.GravesX.api.util.UtilAPI
General utilities (permissions, XP, colors, files, YAML, paste, etc.).
-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionbase64ToObject
(@NotNull String base64String) Decodes a Base64 string to an object using Base64Util.void
Deprecated.void
copyResources
(@NotNull String inputPath, @NotNull String outputPath) Copies resources from the plugin's JAR file to the specified output path.void
copyResources
(@NotNull String inputPath, @NotNull String outputPath, boolean overwrite) Copies resources from the plugin's JAR file to the specified output path, with an option to overwrite existing files.int
dropPercent
(int experience, float percent) Calculates the drop percentage of experience using ExperienceUtil.org.bukkit.Particle.DustOptions
dustFromHex
(@NotNull String hexColor, float size) Creates a Particle.DustOptions object using a hex color code.org.bukkit.Color
Gets the Color corresponding to the given color name using ColorUtil.org.bukkit.Color
getColorFromHex
(@NotNull String hex) Parses a hex color code to a Color using ColorUtil.boolean
hasPermission
(@NotNull org.bukkit.entity.Entity entity, @NotNull String permission) Checks if the specified entity has the given permission using EntityUtil.double
highestDouble
(@NotNull org.bukkit.entity.Player player, String permission) Gets the highest double value associated with a specific permission prefix for the player.int
highestInt
(@NotNull org.bukkit.entity.Player player, @Nullable String permission) Gets the highest integer value associated with a specific permission prefix for the player.boolean
isAir
(@NotNull org.bukkit.Material material) Checks if the given material is an air block.boolean
isLava
(@NotNull org.bukkit.Material material) Checks if the given material is lava.boolean
isPlayerHead
(@NotNull String material) Checks if the given material is a player head.boolean
isPlayerHead
(@NotNull org.bukkit.Material material) Checks if the given material is a player head.boolean
isSafeNotSolid
(@NotNull org.bukkit.Material material) Checks if the given material is not solid and is safe (i.e., not lava).boolean
isSafeSolid
(@NotNull org.bukkit.Material material) Checks if the given material is solid and safe (i.e., not lava).boolean
isValidYaml
(@NotNull File file) Checks if a given file is a valid YAML file.boolean
isWater
(@NotNull org.bukkit.Material material) Checks if the given material is water.latestSpigotVersion
(int resourceId) Gets the latest version of a resource from SpigotMC.long
levelFromXp
(long experience) Calculates the level from a given amount of experience using ExperienceUtil.Convenience to get/update libraries.void
Loads a class with the specified name using ClassUtil.void
Moves a file to a new location with a new name using FileUtil.objectToBase64
(@NotNull Object object) Encodes an object to a Base64 string using Base64Util.int
playerDropXp
(@NotNull org.bukkit.entity.Player player, float expStorePercent) Deprecated.int
playerTotalXp
(@NotNull org.bukkit.entity.Player player) Gets the total experience of the specified player using ExperienceUtil.Posts the given log content to mclo.gs and returns the URL of the posted log.skinSignature
(@NotNull org.bukkit.entity.Entity entity) Shortcuts used during creation (texture/signature).skinTexture
(@NotNull org.bukkit.entity.Entity entity) void
swingMainHand
(@NotNull org.bukkit.entity.Player player) Triggers the main hand swing animation for the specified player.Converts a string to a UUID.int
xpAtLevel
(int level) Gets the experience required to reach a specific level using ExperienceUtil.
-
Constructor Details
-
UtilAPI
-
-
Method Details
-
objectToBase64
Encodes an object to a Base64 string using Base64Util.- Parameters:
object
- The object to encode.- Returns:
- The Base64 encoded string, or null if encoding fails.
-
base64ToObject
Decodes a Base64 string to an object using Base64Util.- Parameters:
base64String
- The Base64 string to decode.- Returns:
- The decoded object, or null if decoding fails.
-
loadClass
Loads a class with the specified name using ClassUtil.- Parameters:
className
- The fully qualified name of the class to be loaded.
-
getColor
Gets the Color corresponding to the given color name using ColorUtil.- Parameters:
colorName
- The name of the color as a string.- Returns:
- The Color corresponding to the given name, or null if no match is found.
-
getColorFromHex
Parses a hex color code to a Color using ColorUtil.- Parameters:
hex
- The hex color code as a string (e.g., "#FF5733").- Returns:
- The Color corresponding to the hex color code, or null if the code is invalid.
-
dustFromHex
Creates a Particle.DustOptions object using a hex color code.- Parameters:
hexColor
- The hex color code as a string (e.g., "#FF5733").size
- The size of the dust particle.- Returns:
- A Particle.DustOptions object with the specified color and size, or null if the color code is invalid.
-
hasPermission
public boolean hasPermission(@NotNull @NotNull org.bukkit.entity.Entity entity, @NotNull @NotNull String permission) Checks if the specified entity has the given permission using EntityUtil.- Parameters:
entity
- The entity to check.permission
- The permission to check for.- Returns:
true
if the entity has the specified permission,true
if the method is not found, orfalse
if an exception occurs.
-
playerTotalXp
public int playerTotalXp(@NotNull @NotNull org.bukkit.entity.Player player) Gets the total experience of the specified player using ExperienceUtil.- Parameters:
player
- The player to get the experience from.- Returns:
- The total experience of the player.
-
xpAtLevel
public int xpAtLevel(int level) Gets the experience required to reach a specific level using ExperienceUtil.- Parameters:
level
- The level to get the experience for.- Returns:
- The experience required to reach the specified level.
-
levelFromXp
public long levelFromXp(long experience) Calculates the level from a given amount of experience using ExperienceUtil.- Parameters:
experience
- The experience to calculate the level from.- Returns:
- The level corresponding to the given experience.
-
dropPercent
public int dropPercent(int experience, float percent) Calculates the drop percentage of experience using ExperienceUtil.- Parameters:
experience
- The total experience.percent
- The percentage to drop.- Returns:
- The experience drop amount.
-
playerDropXp
@Deprecated public int playerDropXp(@NotNull @NotNull org.bukkit.entity.Player player, float expStorePercent) Deprecated.Gets the amount of experience a player will drop upon death based on a percentage.- Parameters:
player
- The player to get the drop experience from.expStorePercent
- The percentage of experience to drop.- Returns:
- The amount of experience to drop.
-
moveFile
Moves a file to a new location with a new name using FileUtil.- Parameters:
file
- The file to be moved.name
- The new name for the file.
-
copyFile
Deprecated.Copies a file to a new location with a new name using FileUtil.- Parameters:
file
- The file to be copied.name
- The new name for the copied file.
-
isAir
public boolean isAir(@NotNull @NotNull org.bukkit.Material material) Checks if the given material is an air block.- Parameters:
material
- The material to check.- Returns:
- True if the material is air, false otherwise.
-
isLava
public boolean isLava(@NotNull @NotNull org.bukkit.Material material) Checks if the given material is lava.- Parameters:
material
- The material to check.- Returns:
- True if the material is lava, false otherwise.
-
isSafeNotSolid
public boolean isSafeNotSolid(@NotNull @NotNull org.bukkit.Material material) Checks if the given material is not solid and is safe (i.e., not lava).- Parameters:
material
- The material to check.- Returns:
- True if the material is not solid and safe, false otherwise.
-
isSafeSolid
public boolean isSafeSolid(@NotNull @NotNull org.bukkit.Material material) Checks if the given material is solid and safe (i.e., not lava).- Parameters:
material
- The material to check.- Returns:
- True if the material is solid and safe, false otherwise.
-
isWater
public boolean isWater(@NotNull @NotNull org.bukkit.Material material) Checks if the given material is water.- Parameters:
material
- The material to check.- Returns:
- True if the material is water, false otherwise.
-
isPlayerHead
public boolean isPlayerHead(@NotNull @NotNull org.bukkit.Material material) Checks if the given material is a player head.- Parameters:
material
- The material to check.- Returns:
- True if the material is a player head, false otherwise.
-
isPlayerHead
Checks if the given material is a player head.- Parameters:
material
- The material to check via string.- Returns:
- True if the material is a player head, false otherwise.
-
postLog
Posts the given log content to mclo.gs and returns the URL of the posted log.- Parameters:
content
- The log content to be posted.- Returns:
- The URL of the posted log, or null if the post was unsuccessful.
-
highestInt
public int highestInt(@NotNull @NotNull org.bukkit.entity.Player player, @Nullable @Nullable String permission) Gets the highest integer value associated with a specific permission prefix for the player.- Parameters:
player
- The player whose permissions are being checked.permission
- The permission prefix to search for.- Returns:
- The highest integer value found for the specified permission prefix. Returns 0 if no such permission is found.
-
highestDouble
Gets the highest double value associated with a specific permission prefix for the player.- Parameters:
player
- The player whose permissions are being checked.permission
- The permission prefix to search for.- Returns:
- The highest double value found for the specified permission prefix. Returns 0 if no such permission is found.
-
swingMainHand
public void swingMainHand(@NotNull @NotNull org.bukkit.entity.Player player) Triggers the main hand swing animation for the specified player.- Parameters:
player
- The player whose main hand swing animation is to be triggered.
-
copyResources
Copies resources from the plugin's JAR file to the specified output path.- Parameters:
inputPath
- The path inside the JAR file to copy from.outputPath
- The path on the file system to copy to.
-
copyResources
public void copyResources(@NotNull @NotNull String inputPath, @NotNull @NotNull String outputPath, boolean overwrite) Copies resources from the plugin's JAR file to the specified output path, with an option to overwrite existing files.- Parameters:
inputPath
- The path inside the JAR file to copy from.outputPath
- The path on the file system to copy to.overwrite
- Whether to overwrite existing files.
-
libraryLoader
Convenience to get/update libraries. -
skinSignature
Shortcuts used during creation (texture/signature). -
skinTexture
-
uuidOf
Converts a string to a UUID.- Parameters:
string
- The string to convert to a UUID.- Returns:
- The UUID if the string is a valid UUID format, otherwise null.
-
latestSpigotVersion
Gets the latest version of a resource from SpigotMC.- Parameters:
resourceId
- The ID of the resource on SpigotMC.- Returns:
- The latest version of the resource as a String, or null if an error occurs.
-
isValidYaml
Checks if a given file is a valid YAML file.- Parameters:
file
- The file to check.- Returns:
- True if the file is a valid YAML file, otherwise false.
-