Package fr.andross.banitem.utils
Class Utils
java.lang.Object
fr.andross.banitem.utils.Utils
Utility class.
- Version:
- 3.4.1
- Author:
- Andross
-
Method Summary
Modifier and TypeMethodDescriptionstatic boolean
areAllEquals
(@NotNull Collection<?> c) 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.getAllEnchants
(@NotNull org.bukkit.inventory.ItemStack item) Get an unmodifiable map of all enchantments on an item, considering stored enchants on enchanted book.getAllPotionEffects
(@NotNull org.bukkit.inventory.ItemStack item) Try to get potion effects on an item.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.static org.bukkit.inventory.Inventory
getClickedInventory
(org.bukkit.inventory.InventoryView view, int slot) Get the clicked inventory from a view.static @NotNull String
getItemDisplayName
(@NotNull org.bukkit.inventory.ItemStack item) Get the display name of the item, empty string if empty.static @NotNull org.bukkit.inventory.ItemStack
getItemInHand
(@NotNull org.bukkit.entity.Player p) Get the item from the player hand, even AIR, regardless the version.static boolean
isNotNullOrEmpty
(@Nullable String s) Used to check if a String is not null nor empty.static boolean
isNullOrAir
(@Nullable org.bukkit.inventory.ItemStack item) Check if the item is null or if its type is Material.AIR.static boolean
isNullOrEmpty
(@Nullable Object[] a) Used to check if an array is null or empty.
-
Method Details
-
isNullOrAir
public static boolean isNullOrAir(@Nullable @Nullable org.bukkit.inventory.ItemStack item) 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.- 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 @NotNull org.bukkit.inventory.ItemStack getItemInHand(@NotNull @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
@NotNull public static @NotNull String getItemDisplayName(@NotNull @NotNull org.bukkit.inventory.ItemStack item) Get the display name of the item, empty string if empty.- Parameters:
item
- the item stack- 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 @NotNull List<Integer> getChangedSlots(@NotNull @NotNull org.bukkit.inventory.PlayerInventory inv, @NotNull @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:
-
getAllEnchants
@NotNull public static @NotNull Map<org.bukkit.enchantments.Enchantment,Integer> getAllEnchants(@NotNull @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 @NotNull Map<org.bukkit.potion.PotionEffectType,Integer> getAllPotionEffects(@NotNull @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
-