Class SlimefunUtils
java.lang.Object
io.github.thebusybiscuit.slimefun4.utils.SlimefunUtils
This utility class holds method that are directly linked to Slimefun.
It provides a very crucial method for
ItemStack
comparison, as well as a simple method
to check if an ItemStack
is Soulbound
or not.- Author:
- TheBusyBiscuit, Walshy, Sfiguz7
-
Method Summary
Modifier and TypeMethodDescriptionstatic boolean
canPlayerUseItem
(org.bukkit.entity.Player p, org.bukkit.inventory.ItemStack item, boolean sendMessage) This checks whether thePlayer
is able to use the givenItemStack
.static boolean
containsSimilarItem
(org.bukkit.inventory.Inventory inventory, org.bukkit.inventory.ItemStack item, boolean checkLore) static boolean
equalsLore
(List<String> lore1, List<String> lore2) This checks if the two provided lores are equal.static org.bukkit.inventory.ItemStack
getCustomHead
(String texture) This method returns anItemStack
for the given texture.static boolean
hasNoPickupFlag
(org.bukkit.entity.Item item) This method quickly returns whether anItem
was marked as "no_pickup" by a Slimefun device.static boolean
isDust
(org.bukkit.inventory.ItemStack item) Check whether the item is a kind of Dust or not.static boolean
isInventoryEmpty
(org.bukkit.inventory.Inventory inventory) Helper method to check if an Inventory is empty (has no items in "storage").static boolean
isItemSimilar
(org.bukkit.inventory.ItemStack item, org.bukkit.inventory.ItemStack sfitem, boolean checkLore) static boolean
isItemSimilar
(org.bukkit.inventory.ItemStack item, org.bukkit.inventory.ItemStack sfitem, boolean checkLore, boolean checkAmount) static boolean
isItemSimilar
(org.bukkit.inventory.ItemStack item, org.bukkit.inventory.ItemStack sfitem, boolean checkLore, boolean checkAmount, boolean checkDistinctiveItem) static boolean
isItemSimilar
(org.bukkit.inventory.ItemStack item, org.bukkit.inventory.ItemStack sfitem, boolean checkLore, boolean checkAmount, boolean checkDistinctiveItem, boolean checkCustomModelData) static boolean
isRadioactive
(org.bukkit.inventory.ItemStack item) This method checks whether the givenItemStack
is radioactive.static boolean
isSoulbound
(org.bukkit.inventory.ItemStack item) This method checks whether the givenItemStack
is consideredSoulbound
.static boolean
isSoulbound
(org.bukkit.inventory.ItemStack item, org.bukkit.World world) This method checks whether the givenItemStack
is consideredSoulbound
.static void
markAsNoPickup
(org.bukkit.entity.Item item, String context) This will prevent the givenItem
from being picked up.static void
setSoulbound
(org.bukkit.inventory.ItemStack item, boolean makeSoulbound) Toggles anItemStack
to be Soulbound.
If true is passed, this will add theSOULBOUND_LORE
and add aNamespacedKey
to the item so it can be quickly identified byisSoulbound(ItemStack)
.
If false is passed, this property will be removed.static org.bukkit.entity.Item
spawnItem
(org.bukkit.Location loc, org.bukkit.inventory.ItemStack item, ItemSpawnReason reason) Helper method to spawn anItemStack
.static org.bukkit.entity.Item
spawnItem
(org.bukkit.Location loc, org.bukkit.inventory.ItemStack item, ItemSpawnReason reason, boolean addRandomOffset) Helper method to spawn anItemStack
.static org.bukkit.entity.Item
spawnItem
(org.bukkit.Location loc, org.bukkit.inventory.ItemStack item, ItemSpawnReason reason, boolean addRandomOffset, org.bukkit.entity.Player player) Helper method to spawn anItemStack
.static void
updateCapacitorTexture
(org.bukkit.Location l, int charge, int capacity)
-
Method Details
-
hasNoPickupFlag
public static boolean hasNoPickupFlag(@Nonnull org.bukkit.entity.Item item) This method quickly returns whether anItem
was marked as "no_pickup" by a Slimefun device.- Parameters:
item
- TheItem
to query- Returns:
- Whether the
Item
is excluded from being picked up
-
markAsNoPickup
This will prevent the givenItem
from being picked up. This is useful for display items which theAncientPedestal
uses.- Parameters:
item
- TheItem
to prevent from being picked upcontext
- The context in which thisItem
was flagged
-
isSoulbound
public static boolean isSoulbound(@Nullable org.bukkit.inventory.ItemStack item) This method checks whether the givenItemStack
is consideredSoulbound
.- Parameters:
item
- TheItemStack
to check for- Returns:
- Whether the given item is soulbound
-
isSoulbound
public static boolean isSoulbound(@Nullable org.bukkit.inventory.ItemStack item, @Nullable org.bukkit.World world) This method checks whether the givenItemStack
is consideredSoulbound
. If the provided item is aSlimefunItem
then this method will also check that the item is enabled in the providedWorld
. If the provided item isSoulbound
through theSlimefunItems.SOULBOUND_RUNE
, then this method will also check that theSlimefunItems.SOULBOUND_RUNE
is enabled in the providedWorld
- Parameters:
item
- TheItemStack
to check forworld
- TheWorld
to check if theSlimefunItem
is enabled in if applicable. Ifnull
then this will not do a world check.- Returns:
- Whether the given item is soulbound
-
setSoulbound
public static void setSoulbound(@Nullable org.bukkit.inventory.ItemStack item, boolean makeSoulbound) Toggles anItemStack
to be Soulbound.
If true is passed, this will add theSOULBOUND_LORE
and add aNamespacedKey
to the item so it can be quickly identified byisSoulbound(ItemStack)
.
If false is passed, this property will be removed.- Parameters:
item
- TheItemStack
you want to add/remove Soulbound from.makeSoulbound
- If the item should be soulbound.- See Also:
-
isRadioactive
public static boolean isRadioactive(@Nullable org.bukkit.inventory.ItemStack item) This method checks whether the givenItemStack
is radioactive.- Parameters:
item
- TheItemStack
to check- Returns:
- Whether this
ItemStack
is radioactive or not
-
getCustomHead
This method returns anItemStack
for the given texture. The result will be a Player Head with this texture.- Parameters:
texture
- The texture for this head (base64 or hash)- Returns:
- An
ItemStack
with this Head texture
-
containsSimilarItem
public static boolean containsSimilarItem(org.bukkit.inventory.Inventory inventory, org.bukkit.inventory.ItemStack item, boolean checkLore) -
isItemSimilar
public static boolean isItemSimilar(@Nullable org.bukkit.inventory.ItemStack item, @Nullable org.bukkit.inventory.ItemStack sfitem, boolean checkLore) -
isItemSimilar
public static boolean isItemSimilar(@Nullable org.bukkit.inventory.ItemStack item, @Nullable org.bukkit.inventory.ItemStack sfitem, boolean checkLore, boolean checkAmount) -
isItemSimilar
public static boolean isItemSimilar(@Nullable org.bukkit.inventory.ItemStack item, @Nullable org.bukkit.inventory.ItemStack sfitem, boolean checkLore, boolean checkAmount, boolean checkDistinctiveItem) -
isItemSimilar
public static boolean isItemSimilar(@Nullable org.bukkit.inventory.ItemStack item, @Nullable org.bukkit.inventory.ItemStack sfitem, boolean checkLore, boolean checkAmount, boolean checkDistinctiveItem, boolean checkCustomModelData) -
equalsLore
This checks if the two provided lores are equal. This method will ignore any lines such as the soulbound one.- Parameters:
lore1
- The first lorelore2
- The second lore- Returns:
- Whether the two lores are equal
-
updateCapacitorTexture
public static void updateCapacitorTexture(@Nonnull org.bukkit.Location l, int charge, int capacity) -
canPlayerUseItem
public static boolean canPlayerUseItem(@Nonnull org.bukkit.entity.Player p, @Nullable org.bukkit.inventory.ItemStack item, boolean sendMessage) This checks whether thePlayer
is able to use the givenItemStack
. It will always returntrue
for non-Slimefun items.If you already have an instance of
SlimefunItem
, please useSlimefunItem.canUse(Player, boolean)
.- Parameters:
p
- ThePlayer
item
- TheItemStack
to checksendMessage
- Whether to send a message response to thePlayer
- Returns:
- Whether the
Player
is able to use that item.
-
spawnItem
@ParametersAreNonnullByDefault @Nullable public static org.bukkit.entity.Item spawnItem(org.bukkit.Location loc, org.bukkit.inventory.ItemStack item, ItemSpawnReason reason, boolean addRandomOffset, @Nullable org.bukkit.entity.Player player) Helper method to spawn anItemStack
. This method automatically calls aSlimefunItemSpawnEvent
to allow other plugins to catch the item being dropped.- Parameters:
loc
- TheLocation
where to drop the itemitem
- TheItemStack
to dropreason
- TheItemSpawnReason
why the item is being droppedaddRandomOffset
- Whether a random offset should be added (seeWorld.dropItemNaturally(Location, ItemStack)
)player
- The player that caused thisSlimefunItemSpawnEvent
- Returns:
- The dropped
Item
(or null if theSlimefunItemSpawnEvent
was cancelled)
-
spawnItem
@ParametersAreNonnullByDefault @Nullable public static org.bukkit.entity.Item spawnItem(org.bukkit.Location loc, org.bukkit.inventory.ItemStack item, ItemSpawnReason reason, boolean addRandomOffset) Helper method to spawn anItemStack
. This method automatically calls aSlimefunItemSpawnEvent
to allow other plugins to catch the item being dropped.- Parameters:
loc
- TheLocation
where to drop the itemitem
- TheItemStack
to dropreason
- TheItemSpawnReason
why the item is being droppedaddRandomOffset
- Whether a random offset should be added (seeWorld.dropItemNaturally(Location, ItemStack)
)- Returns:
- The dropped
Item
(or null if theSlimefunItemSpawnEvent
was cancelled)
-
spawnItem
@ParametersAreNonnullByDefault @Nullable public static org.bukkit.entity.Item spawnItem(org.bukkit.Location loc, org.bukkit.inventory.ItemStack item, ItemSpawnReason reason) Helper method to spawn anItemStack
. This method automatically calls aSlimefunItemSpawnEvent
to allow other plugins to catch the item being dropped.- Parameters:
loc
- TheLocation
where to drop the itemitem
- TheItemStack
to dropreason
- TheItemSpawnReason
why the item is being dropped- Returns:
- The dropped
Item
(or null if theSlimefunItemSpawnEvent
was cancelled)
-
isInventoryEmpty
public static boolean isInventoryEmpty(@Nonnull org.bukkit.inventory.Inventory inventory) Helper method to check if an Inventory is empty (has no items in "storage"). If the MC version is 1.16 or above this will callInventory.isEmpty()
(Which calls MC code resulting in a faster method).- Parameters:
inventory
- TheInventory
to check.- Returns:
- True if the inventory is empty and false otherwise
-
isDust
public static boolean isDust(@Nonnull org.bukkit.inventory.ItemStack item) Check whether the item is a kind of Dust or not.- Parameters:
item
- The item need to check.- Returns:
- Is the item a kind of Dust
-