Class Common

java.lang.Object
com.github.pinont.singularitylib.api.utils.Common

public class Common extends Object
Utility class providing common operations and helper methods. This class contains various static methods for working with items, players, materials, and text formatting.
  • Constructor Summary

    Constructors
    Constructor
    Description
    Default constructor for Common utility class.
  • Method Summary

    Modifier and Type
    Method
    Description
    static boolean
    checkAirInSlot(PlayerInventorySlotType type, org.bukkit.entity.Player player)
    Checks if a specific inventory slot contains air for a player.
    static void
    checkBoolean(boolean expression, String falseMessage, Object... replacements)
    Checks if a boolean expression is true, logs a message if false.
    static @NotNull net.kyori.adventure.text.Component
    colorize(@NotNull String message)
    Colorizes a string message using MiniMessage format without disabling italic.
    static @NotNull net.kyori.adventure.text.Component
    colorize(@NotNull String message, boolean noItalic)
    Colorizes a string message using MiniMessage format.
    static org.bukkit.Material[]
    Gets all valid item materials, filtering out invalid or non-item materials.
    static String
    Gets the current API version.
    static org.bukkit.inventory.ItemStack
    getItem(String itemName)
    Creates an ItemStack from a material name string.
    static org.bukkit.inventory.ItemStack
    getItemInSlot(PlayerInventorySlotType type, org.bukkit.entity.Player player)
    Gets the ItemStack in a specific inventory slot for a player.
    static org.bukkit.entity.Player
    getNearestPlayer(org.bukkit.Location location, int radius)
    Gets the nearest player to a location within a specified radius.
    static Collection<? extends org.bukkit.entity.Player>
    Gets all online players.
    static List<String>
    Gets the names of all online players.
    static String
    Converts an integer to Roman numeral representation.
    static Boolean
    isAir(org.bukkit.inventory.ItemStack item)
    Checks if the given ItemStack is air or null.
    static Boolean
    isItemIsMaterial(org.bukkit.Material material)
    Checks if the given material is a valid item material.
    static Boolean
    isMainHandEmpty(org.bukkit.entity.Player player)
    Checks if a player's main hand is empty.
    static String
    Normalizes a string name by converting underscores to spaces and capitalizing words.
    static String
    Removes color codes from a string.
    static String
    resetStringColor(net.kyori.adventure.text.Component component)
    Converts a Component to its MiniMessage string representation.
    static void
    Logs an error message from a throwable.
    static long
    toTicks(long amount, TimeUnit unit)
     

    Methods inherited from class Object

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

    • Common

      public Common()
      Default constructor for Common utility class.
  • Method Details

    • getAPIVersion

      public static String getAPIVersion()
      Gets the current API version.
      Returns:
      the API version string
    • colorize

      @NotNull public static @NotNull net.kyori.adventure.text.Component colorize(@NotNull @NotNull String message, boolean noItalic)
      Colorizes a string message using MiniMessage format.
      Parameters:
      message - the message to colorize
      noItalic - whether to disable italic formatting
      Returns:
      the colorized Component
    • colorize

      @NotNull public static @NotNull net.kyori.adventure.text.Component colorize(@NotNull @NotNull String message)
      Colorizes a string message using MiniMessage format without disabling italic.
      Parameters:
      message - the message to colorize
      Returns:
      the colorized Component
    • getAllItemsMaterials

      public static org.bukkit.Material[] getAllItemsMaterials()
      Gets all valid item materials, filtering out invalid or non-item materials.
      Returns:
      array of valid item materials
    • isItemIsMaterial

      public static Boolean isItemIsMaterial(org.bukkit.Material material)
      Checks if the given material is a valid item material.
      Parameters:
      material - the material to check
      Returns:
      true if the material is a valid item, false otherwise
    • isAir

      public static Boolean isAir(org.bukkit.inventory.ItemStack item)
      Checks if the given ItemStack is air or null.
      Parameters:
      item - the ItemStack to check
      Returns:
      true if the item is air or null, false otherwise
    • checkBoolean

      public static void checkBoolean(boolean expression, String falseMessage, Object... replacements)
      Checks if a boolean expression is true, logs a message if false.
      Parameters:
      expression - the boolean expression to check
      falseMessage - the message to log if expression is false
      replacements - optional parameters for string formatting
    • getItem

      public static org.bukkit.inventory.ItemStack getItem(String itemName)
      Creates an ItemStack from a material name string.
      Parameters:
      itemName - the name of the material
      Returns:
      the created ItemStack
      Throws:
      IllegalArgumentException - if the material name is invalid
    • sneaky

      public static void sneaky(Throwable t)
      Logs an error message from a throwable.
      Parameters:
      t - the throwable to log
    • getOnlinePlayers

      public static Collection<? extends org.bukkit.entity.Player> getOnlinePlayers()
      Gets all online players.
      Returns:
      collection of online players
    • getOnlinePlayersNames

      public static List<String> getOnlinePlayersNames()
      Gets the names of all online players.
      Returns:
      list of online player names
    • normalizeStringName

      public static String normalizeStringName(String string)
      Normalizes a string name by converting underscores to spaces and capitalizing words.
      Parameters:
      string - the string to normalize
      Returns:
      the normalized string
    • isMainHandEmpty

      public static Boolean isMainHandEmpty(org.bukkit.entity.Player player)
      Checks if a player's main hand is empty.
      Parameters:
      player - the player to check
      Returns:
      true if the main hand is empty, false otherwise
    • IntegerToRomanNumeral

      public static String IntegerToRomanNumeral(int input)
      Converts an integer to Roman numeral representation.
      Parameters:
      input - the integer to convert (must be between 1 and 3999)
      Returns:
      the Roman numeral string, or "Invalid Roman Number Value" if out of range
    • getNearestPlayer

      public static org.bukkit.entity.Player getNearestPlayer(org.bukkit.Location location, int radius)
      Gets the nearest player to a location within a specified radius.
      Parameters:
      location - the location to search from
      radius - the search radius
      Returns:
      the nearest player, or null if none found
    • checkAirInSlot

      public static boolean checkAirInSlot(PlayerInventorySlotType type, org.bukkit.entity.Player player)
      Checks if a specific inventory slot contains air for a player.
      Parameters:
      type - the slot type to check
      player - the player whose inventory to check
      Returns:
      true if the slot contains air, false otherwise
    • getItemInSlot

      public static org.bukkit.inventory.ItemStack getItemInSlot(PlayerInventorySlotType type, org.bukkit.entity.Player player)
      Gets the ItemStack in a specific inventory slot for a player.
      Parameters:
      type - the slot type to get the item from
      player - the player whose inventory to check
      Returns:
      the ItemStack in the specified slot, or air if slot is empty
    • resetStringColor

      public static String resetStringColor(String text)
      Removes color codes from a string.
      Parameters:
      text - the text to remove colors from
      Returns:
      the text without color codes
    • resetStringColor

      public static String resetStringColor(net.kyori.adventure.text.Component component)
      Converts a Component to its MiniMessage string representation.
      Parameters:
      component - the component to convert
      Returns:
      the MiniMessage string representation
    • toTicks

      public static long toTicks(long amount, TimeUnit unit)