Package fr.andross.banitem.utils
Class Utils
java.lang.Object
fr.andross.banitem.utils.Utils
Utility class
- Version:
- 3.3.1
- Author:
- Andross
-
Constructor Summary
-
Method Summary
Modifier and TypeMethodDescriptionstatic boolean
areAllEquals
(Collection<?> c) Check if all elements are equalsstatic int
firstEmpty
(org.bukkit.inventory.PlayerInventory inv) A method that get the first slot empty from a player inventory.getAllEnchants
(org.bukkit.inventory.ItemStack item) Get an unmodifiable map of all enchantments on an item, considering stored enchants on enchanted bookgetAllPotionEffects
(org.bukkit.inventory.ItemStack item) Try to get potion effects on an itemgetChangedSlots
(org.bukkit.inventory.PlayerInventory inv, org.bukkit.inventory.ItemStack newItem) Get the affected slots if an item will be added to the inventorystatic 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 emptystatic org.bukkit.inventory.ItemStack
getItemInHand
(org.bukkit.entity.Player p) Get the item from the player hand, even AIR, regardless the versionstatic boolean
Used to check if a String is not null nor emptystatic boolean
isNullOrAir
(org.bukkit.inventory.ItemStack item) Quick utils to check if the item is null or if its type is Material.AIRstatic boolean
isNullOrEmpty
(Object[] a) Used to check if an array is null or empty.
-
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
- theItemStack
- Returns:
- true if the ItemStack is null or AIR, otherwise false
-
isNullOrEmpty
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
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
- thePlayer
- Returns:
- the ItemStack in the player's hand, possibly AIR
-
getItemDisplayname
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
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 inventorynewItem
- 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 viewslot
- the raw slot clicked- Returns:
- the inventory clicked
-