Class FlareUtil

java.lang.Object
space.maxus.flare.util.FlareUtil

public final class FlareUtil extends Object
A utility class containing different utilities for Flare
  • Nested Class Summary

    Nested Classes
    Modifier and Type
    Class
    Description
    static class 
    Thrown inside of acquireThrowing(Callable) to indicate an error was encountered while acquiring a value
  • Field Summary

    Fields
    Modifier and Type
    Field
    Description
    static final net.kyori.adventure.text.minimessage.MiniMessage
    Flare MiniMessage instance.
  • Method Summary

    Modifier and Type
    Method
    Description
    static <V> V
    Acquires result of a callable, returning null if an error was encountered
    static <V> V
    Acquires result of a callable, throwing a runtime error if an error was encountered
    static @NotNull com.destroystokyo.paper.profile.PlayerProfile
    Creates a new player profile with provided skin
    static void
    execute(Runnable executable)
    Executes a task on the general flare executor service
    static void
    executeNTimesAsync(Runnable task, int times, long period)
    Executes a task asynchronously using Bukkit scheduler.
    executor(int threads)
    Constructs a new executor service with the given number of threads
    static String
    formatFloat(float f)
    Formats a float to a string
    static <G> Class<G>
    Attempts to get a class for a generic type parameter
    static boolean
    isNullOrAir(@Nullable org.bukkit.inventory.ItemStack stack)
    Checks if a stack is null or air
    static <K> K
    keyFromComposable(@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 map
    static <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 keys
    static <I, O> org.apache.commons.lang3.concurrent.Computable<I,O>
    memoize(org.apache.commons.lang3.concurrent.Computable<I,O> producer)
    Memoizes a computable
    static List<String>
    partitionString(@NotNull String input)
    Partitions a string into chunks of size ~30 characters
    static List<String>
    partitionString(@NotNull String input, int length)
    Partitions a string into chunks of roughly size length
    static boolean
    reduceBoolStream(@NotNull Stream<Boolean> stream, BinaryOperator<Boolean> operator)
    Reduces a java stream of Booleans to a single boolean
    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
    static net.kyori.adventure.text.Component
    text(String miniMessage)
    Parses a string into a MiniMessage component
    static net.kyori.adventure.text.Component
    text(String miniMessage, @Nullable org.bukkit.entity.Player player)
    Parses a sstring into a MiniMessage component with PlaceholderAPI support

    Methods inherited from class java.lang.Object

    clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
  • Field Details

    • MINI_MESSAGE

      public static final net.kyori.adventure.text.minimessage.MiniMessage MINI_MESSAGE
      Flare MiniMessage instance.
      See Also:
  • Method Details

    • execute

      public static void execute(Runnable executable)
      Executes a task on the general flare executor service
      Parameters:
      executable - Task to be executed
    • executor

      public static ExecutorService executor(int threads)
      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

      public static void executeNTimesAsync(Runnable task, int times, long period)
      Executes a task asynchronously using Bukkit scheduler. The task will be run `times` times with `period` period
      Parameters:
      task - Task to be run
      times - Number of times to run the task
      period - Period between each run of the task in ticks
    • text

      public static net.kyori.adventure.text.Component text(String miniMessage)
      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 parsed
      player - Player to be used for placeholder resolution. May be null
      Returns:
      Parsed component
    • genericClass

      public static <G> Class<G> 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 type
      O - 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 keys
      V - Type of values
      Parameters:
      map - Map to be used
      keySet - 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 reduced
      operator - 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

      public static List<String> partitionString(@NotNull @NotNull String input)
      Partitions a string into chunks of size ~30 characters
      Parameters:
      input - String to be partitioned
      Returns:
      List of partitioned chunks
    • partitionString

      public static List<String> partitionString(@NotNull @NotNull String input, int length)
      Partitions a string into chunks of roughly size length
      Parameters:
      input - String to be partitioned
      length - Approximate length of chunks
      Returns:
      List of partitioned chunks
    • formatFloat

      public static String formatFloat(float f)
      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 1
      scale - Scale of the progress bar
      dotted - Whether the bar should be rendered dotted
      Returns:
    • acquireCatching

      @Nullable public static <V> V acquireCatching(Callable<V> producer)
      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

      @NotNull public static <V> V acquireThrowing(Callable<V> producer)
      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

      @Nullable public static <K, V> K keyFromValue(@NotNull @NotNull Map<K,V> map, @NotNull V value)
      Attempts to find key from value inside a map
      Type Parameters:
      K - Type of key
      V - Type of value
      Parameters:
      map - Map to be searched
      value - 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