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
(Player p, ItemStack item, boolean sendMessage) static boolean
containsSimilarItem
(Inventory inventory, ItemStack item, boolean checkLore) static boolean
equalsLore
(List<String> lore1, List<String> lore2) This checks if the two provided lores are equal.static ItemStack
getCustomHead
(String texture) This method returns anItemStack
for the given texture.static boolean
hasNoPickupFlag
(Item item) This method quickly returns whether anItem
was marked as "no_pickup" by a Slimefun device.static boolean
isInventoryEmpty
(Inventory inventory) Helper method to check if an Inventory is empty (has no items in "storage").static boolean
isItemSimilar
(ItemStack item, ItemStack sfitem, boolean checkLore) Compares twoItemStack
s and returns if they are similar or not.static boolean
isItemSimilar
(ItemStack item, ItemStack sfitem, boolean checkLore, boolean checkAmount) Compares twoItemStack
s and returns if they are similar or not.static boolean
isItemSimilar
(ItemStack item, ItemStack sfitem, boolean checkLore, boolean checkAmount, boolean checkDistinction) Compares twoItemStack
s and returns if they are similar or not.static boolean
isRadioactive
(ItemStack item) This method checks whether the givenItemStack
is radioactive.static boolean
isSoulbound
(ItemStack item) static boolean
isSoulbound
(ItemStack item, World world) static void
markAsNoPickup
(Item item, String context) This will prevent the givenItem
from being picked up.static void
setSoulbound
(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 Item
spawnItem
(Location loc, ItemStack item, ItemSpawnReason reason) Helper method to spawn anItemStack
.static Item
spawnItem
(Location loc, ItemStack item, ItemSpawnReason reason, boolean addRandomOffset) Helper method to spawn anItemStack
.static Item
spawnItem
(Location loc, ItemStack item, ItemSpawnReason reason, boolean addRandomOffset, Player player) Helper method to spawn anItemStack
.static void
updateCapacitorTexture
(Location l, int charge, int capacity)
-
Method Details
-
hasNoPickupFlag
This method quickly returns whether anItem
was marked as "no_pickup" by a Slimefun device. -
markAsNoPickup
This will prevent the givenItem
from being picked up. This is useful for display items which theAncientPedestal
uses. -
isSoulbound
- Parameters:
item
- TheItemStack
to check for- Returns:
- Whether the given item is soulbound
-
isSoulbound
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
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
This method checks whether the givenItemStack
is radioactive. -
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
-
isItemSimilar
public static boolean isItemSimilar(@Nullable ItemStack item, @Nullable ItemStack sfitem, boolean checkLore) Compares twoItemStack
s and returns if they are similar or not. Takes into account some shortcut checks specific toSlimefunItem
s for performance. Will check for distintion of items by default and will also confirm the amount is the same. -
isItemSimilar
public static boolean isItemSimilar(@Nullable ItemStack item, @Nullable ItemStack sfitem, boolean checkLore, boolean checkAmount) Compares twoItemStack
s and returns if they are similar or not. Takes into account some shortcut checks specific toSlimefunItem
s for performance. Will check for distintion of items by default- Parameters:
item
- TheItemStack
being tested.sfitem
- TheItemStack
that is being compared against.checkLore
- Whether to include the current lore of either item in the comparisoncheckAmount
- Whether to include the item's amount(s) in the comparison- Returns:
- True if the given
ItemStack
s are similar under the given constraints - See Also:
-
isItemSimilar
public static boolean isItemSimilar(@Nullable ItemStack item, @Nullable ItemStack sfitem, boolean checkLore, boolean checkAmount, boolean checkDistinction) Compares twoItemStack
s and returns if they are similar or not. Takes into account some shortcut checks specific toSlimefunItem
s for performance.- Parameters:
item
- TheItemStack
being tested.sfitem
- TheItemStack
that is being compared against.checkLore
- Whether to include the current lore of either item in the comparisoncheckAmount
- Whether to include the item's amount(s) in the comparisoncheckDistinction
- Whether to check for special distinctive properties of the items.- Returns:
- True if the given
ItemStack
s are similar under the given constraints - See Also:
-
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
-
canPlayerUseItem
public static boolean canPlayerUseItem(@Nonnull Player p, @Nullable 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)
. -
spawnItem
@ParametersAreNonnullByDefault @Nullable public static Item spawnItem(Location loc, ItemStack item, ItemSpawnReason reason, boolean addRandomOffset, @Nullable 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 Item spawnItem(Location loc, 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 Item spawnItem(Location loc, 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
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
-