Class Utils

java.lang.Object
fr.andross.banitem.utils.Utils

public final class Utils extends Object
Utility class
Version:
3.3.1
Author:
Andross
  • Constructor Summary

    Constructors
    Constructor
    Description
     
  • Method Summary

    Modifier and Type
    Method
    Description
    static boolean
    Check if all elements are equals
    static int
    firstEmpty(org.bukkit.inventory.PlayerInventory inv)
    A method that get the first slot empty from a player inventory.
    static Map<org.bukkit.enchantments.Enchantment,Integer>
    getAllEnchants(org.bukkit.inventory.ItemStack item)
    Get an unmodifiable map of all enchantments on an item, considering stored enchants on enchanted book
    static Map<org.bukkit.potion.PotionEffectType,Integer>
    getAllPotionEffects(org.bukkit.inventory.ItemStack item)
    Try to get potion effects on an item
    static List<Integer>
    getChangedSlots(org.bukkit.inventory.PlayerInventory inv, org.bukkit.inventory.ItemStack newItem)
    Get the affected slots if an item will be added to the inventory
    static org.bukkit.inventory.Inventory
    getClickedInventory(org.bukkit.inventory.InventoryView view, int slot)
    Get the clicked inventory from a view.
    static String
    getItemDisplayname(org.bukkit.inventory.ItemStack item)
    Get the display name of the item, empty string if empty
    static org.bukkit.inventory.ItemStack
    getItemInHand(org.bukkit.entity.Player p)
    Get the item from the player hand, even AIR, regardless the version
    static boolean
    Used to check if a String is not null nor empty
    static boolean
    isNullOrAir(org.bukkit.inventory.ItemStack item)
    Quick utils to check if the item is null or if its type is Material.AIR
    static boolean
    Used to check if an array is null or empty.

    Methods inherited from class java.lang.Object

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

    • Utils

      public Utils()
  • Method Details

    • isNullOrAir

      public static boolean isNullOrAir(@Nullable org.bukkit.inventory.ItemStack item)
      Quick utils to check if the item is null or if its type is Material.AIR
      Parameters:
      item - the ItemStack
      Returns:
      true if the ItemStack is null or AIR, otherwise false
    • isNullOrEmpty

      public static boolean isNullOrEmpty(@Nullable Object[] a)
      Used to check if an array is null or empty. Mainly used to check varargs.
      Parameters:
      a - array
      Returns:
      true is the array is null or empty, otherwise false
    • isNotNullOrEmpty

      public static boolean isNotNullOrEmpty(@Nullable String s)
      Used to check if a String is not null nor empty
      Parameters:
      s - the string to check
      Returns:
      true if the string is not null nor empty, otherwise false
    • getItemInHand

      @NotNull public static org.bukkit.inventory.ItemStack getItemInHand(@NotNull org.bukkit.entity.Player p)
      Get the item from the player hand, even AIR, regardless the version
      Parameters:
      p - the Player
      Returns:
      the ItemStack in the player's hand, possibly AIR
    • getItemDisplayname

      @NotNull public static String getItemDisplayname(@NotNull org.bukkit.inventory.ItemStack item)
      Get the display name of the item, empty string if empty
      Parameters:
      item - the itemstack
      Returns:
      the display name of the item, otherwise an empty string
    • areAllEquals

      public static boolean areAllEquals(@NotNull Collection<?> c)
      Check if all elements are equals
      Parameters:
      c - the collection
      Returns:
      true if all elements are equals, otherwise false
    • getChangedSlots

      @NotNull public static List<Integer> getChangedSlots(@NotNull org.bukkit.inventory.PlayerInventory inv, @NotNull org.bukkit.inventory.ItemStack newItem)
      Get the affected slots if an item will be added to the inventory
      Parameters:
      inv - an inventory
      newItem - the item
      Returns:
      a non-null list of affected slots
    • firstEmpty

      public static int firstEmpty(org.bukkit.inventory.PlayerInventory inv)
      A method that get the first slot empty from a player inventory. This method will first focus on stored items, then will check on hotbar.
      Parameters:
      inv - the player inventory
      Returns:
      first empty slot
      See Also:
      • Inventory.firstEmpty()
    • getAllEnchants

      @NotNull public static Map<org.bukkit.enchantments.Enchantment,Integer> getAllEnchants(@NotNull org.bukkit.inventory.ItemStack item)
      Get an unmodifiable map of all enchantments on an item, considering stored enchants on enchanted book
      Parameters:
      item - the item
      Returns:
      non-null unmodifiable map of enchantments and level on the item
    • getAllPotionEffects

      @NotNull public static Map<org.bukkit.potion.PotionEffectType,Integer> getAllPotionEffects(@NotNull org.bukkit.inventory.ItemStack item)
      Try to get potion effects on an item
      Parameters:
      item - the item
      Returns:
      non-null unmodifiable map of potion effect and level on the item
    • getClickedInventory

      public static org.bukkit.inventory.Inventory getClickedInventory(org.bukkit.inventory.InventoryView view, int slot)
      Get the clicked inventory from a view. This method is used to support multiple Bukkit API versions.
      Parameters:
      view - the inventory view
      slot - the raw slot clicked
      Returns:
      the inventory clicked