Package space.maxus.flare.util
Class FlareUtil
java.lang.Object
space.maxus.flare.util.FlareUtil
A utility class containing different utilities for Flare
-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionstatic classThrown inside ofacquireThrowing(Callable)to indicate an error was encountered while acquiring a value -
Field Summary
FieldsModifier and TypeFieldDescriptionstatic final net.kyori.adventure.text.minimessage.MiniMessageFlare MiniMessage instance. -
Method Summary
Modifier and TypeMethodDescriptionstatic <V> VacquireCatching(Callable<V> producer) Acquires result of a callable, returning null if an error was encounteredstatic <V> VacquireThrowing(Callable<V> producer) Acquires result of a callable, throwing a runtime error if an error was encounteredstatic @NotNull com.destroystokyo.paper.profile.PlayerProfilecreateProfile(String withSkin) Creates a new player profile with provided skinstatic voidExecutes a task on the general flare executor servicestatic voidexecuteNTimesAsync(Runnable task, int times, long period) Executes a task asynchronously using Bukkit scheduler.static ExecutorServiceexecutor(int threads) Constructs a new executor service with the given number of threadsstatic StringformatFloat(float f) Formats a float to a stringstatic <G> Class<G>Attempts to get a class for a generic type parameterstatic booleanisNullOrAir(@Nullable org.bukkit.inventory.ItemStack stack) Checks if a stack is null or airstatic <K> KkeyFromComposable(@NotNull Map<K, Composable> map, @NotNull Composable value) static <K,V> K keyFromValue(@NotNull Map<K, V> map, V value) Attempts to find key from value inside a mapstatic <K,V> @NotNull Map<K, V> map2setIntersect(@NotNull Map<K, V> map, @NotNull Set<K> keySet) Finds an intersection between map keys and provided set, returning part of map with matched keysstatic <I,O> org.apache.commons.lang3.concurrent.Computable<I, O> memoize(org.apache.commons.lang3.concurrent.Computable<I, O> producer) Memoizes a computablepartitionString(@NotNull String input) Partitions a string into chunks of size ~30 characterspartitionString(@NotNull String input, int length) Partitions a string into chunks of roughly size lengthstatic booleanreduceBoolStream(@NotNull Stream<Boolean> stream, BinaryOperator<Boolean> operator) Reduces a java stream of Booleans to a single booleanstatic net.kyori.adventure.text.ComponentrenderBarText(@org.jetbrains.annotations.Range(from=0L, to=1L) float ratio, int scale, boolean dotted) Renders a progress bar componentstatic net.kyori.adventure.text.ComponentParses a string into a MiniMessage componentstatic net.kyori.adventure.text.ComponentParses a sstring into a MiniMessage component with PlaceholderAPI support
-
Field Details
-
MINI_MESSAGE
public static final net.kyori.adventure.text.minimessage.MiniMessage MINI_MESSAGEFlare MiniMessage instance.- See Also:
-
-
Method Details
-
execute
Executes a task on the general flare executor service- Parameters:
executable- Task to be executed
-
executor
Constructs a new executor service with the given number of threads- Parameters:
threads- Number of threads to be used- Returns:
- ExecutorService with the given number of threads
-
executeNTimesAsync
Executes a task asynchronously using Bukkit scheduler. The task will be run `times` times with `period` period- Parameters:
task- Task to be runtimes- Number of times to run the taskperiod- Period between each run of the task in ticks
-
text
Parses a string into a MiniMessage component- Parameters:
miniMessage- String to be parsed- Returns:
- Parsed component
-
text
public static net.kyori.adventure.text.Component text(String miniMessage, @Nullable @Nullable org.bukkit.entity.Player player) Parses a sstring into a MiniMessage component with PlaceholderAPI support- Parameters:
miniMessage- String to be parsedplayer- Player to be used for placeholder resolution. May be null- Returns:
- Parsed component
-
genericClass
Attempts to get a class for a generic type parameter- Type Parameters:
G- Type parameter to be resolved into class- Returns:
- Class of a generic type parameter
-
memoize
public static <I,O> org.apache.commons.lang3.concurrent.Computable<I,O> memoize(org.apache.commons.lang3.concurrent.Computable<I, O> producer) Memoizes a computable- Type Parameters:
I- Input parameter typeO- Output parameter type- Parameters:
producer- Producer to be memoized- Returns:
- Memoized producer
- See Also:
-
map2setIntersect
@Contract("_,_ -> new") @NotNull public static <K,V> @NotNull Map<K,V> map2setIntersect(@NotNull @NotNull Map<K, V> map, @NotNull @NotNull Set<K> keySet) Finds an intersection between map keys and provided set, returning part of map with matched keys- Type Parameters:
K- Type of keysV- Type of values- Parameters:
map- Map to be usedkeySet- Keys to be used- Returns:
- Map with matched keys
-
reduceBoolStream
public static boolean reduceBoolStream(@NotNull @NotNull Stream<Boolean> stream, BinaryOperator<Boolean> operator) Reduces a java stream of Booleans to a single boolean- Parameters:
stream- Stream to be reducedoperator- Operator to be applied on each pair- Returns:
- Result of the reduction
-
createProfile
@NotNull public static @NotNull com.destroystokyo.paper.profile.PlayerProfile createProfile(String withSkin) Creates a new player profile with provided skin- Parameters:
withSkin- Skin to be used for profile- Returns:
- New player profile
-
partitionString
Partitions a string into chunks of size ~30 characters- Parameters:
input- String to be partitioned- Returns:
- List of partitioned chunks
-
partitionString
Partitions a string into chunks of roughly size length- Parameters:
input- String to be partitionedlength- Approximate length of chunks- Returns:
- List of partitioned chunks
-
formatFloat
Formats a float to a string- Parameters:
f- Float to be formatted- Returns:
- Formatted string
-
renderBarText
public static net.kyori.adventure.text.Component renderBarText(@org.jetbrains.annotations.Range(from=0L, to=1L) float ratio, int scale, boolean dotted) Renders a progress bar component- Parameters:
ratio- Current progress ration. Must be between 0 and 1scale- Scale of the progress bardotted- Whether the bar should be rendered dotted- Returns:
-
acquireCatching
Acquires result of a callable, returning null if an error was encountered- Type Parameters:
V- Type of return value- Parameters:
producer- Producer to be called- Returns:
- Result of the callable, or null if an error was encountered
-
acquireThrowing
Acquires result of a callable, throwing a runtime error if an error was encountered- Type Parameters:
V- Type of return value- Parameters:
producer- Producer to be called- Returns:
- Result of the callable
-
keyFromValue
Attempts to find key from value inside a map- Type Parameters:
K- Type of keyV- Type of value- Parameters:
map- Map to be searchedvalue- Value to be searched for- Returns:
- Found key, or null if not found
-
keyFromComposable
@Internal @Nullable public static <K> K keyFromComposable(@NotNull @NotNull Map<K, Composable> map, @NotNull @NotNull Composable value) -
isNullOrAir
@Contract(value="null -> true", pure=true) public static boolean isNullOrAir(@Nullable @Nullable org.bukkit.inventory.ItemStack stack) Checks if a stack is null or air- Parameters:
stack- Stack to be checked- Returns:
- True if
Material.isAir()or if stack is null
-