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 booleancanPlayerUseItem(Player p, ItemStack item, boolean sendMessage) static booleancontainsSimilarItem(Inventory inventory, ItemStack item, boolean checkLore) static booleanequalsLore(List<String> lore1, List<String> lore2) This checks if the two provided lores are equal.static ItemStackgetCustomHead(String texture) This method returns anItemStackfor the given texture.static booleanhasNoPickupFlag(Item item) This method quickly returns whether anItemwas marked as "no_pickup" by a Slimefun device.static booleanisInventoryEmpty(Inventory inventory) Helper method to check if an Inventory is empty (has no items in "storage").static booleanisItemSimilar(ItemStack item, ItemStack sfitem, boolean checkLore) Compares twoItemStacks and returns if they are similar or not.static booleanisItemSimilar(ItemStack item, ItemStack sfitem, boolean checkLore, boolean checkAmount) Compares twoItemStacks and returns if they are similar or not.static booleanisItemSimilar(ItemStack item, ItemStack sfitem, boolean checkLore, boolean checkAmount, boolean checkDistinction) Compares twoItemStacks and returns if they are similar or not.static booleanisRadioactive(ItemStack item) This method checks whether the givenItemStackis radioactive.static booleanisSoulbound(ItemStack item) static booleanisSoulbound(ItemStack item, World world) static voidmarkAsNoPickup(Item item, String context) This will prevent the givenItemfrom being picked up.static voidsetSoulbound(ItemStack item, boolean makeSoulbound) Toggles anItemStackto be Soulbound.
If true is passed, this will add theSOULBOUND_LOREand add aNamespacedKeyto the item so it can be quickly identified byisSoulbound(ItemStack).
If false is passed, this property will be removed.static ItemspawnItem(Location loc, ItemStack item, ItemSpawnReason reason) Helper method to spawn anItemStack.static ItemspawnItem(Location loc, ItemStack item, ItemSpawnReason reason, boolean addRandomOffset) Helper method to spawn anItemStack.static ItemspawnItem(Location loc, ItemStack item, ItemSpawnReason reason, boolean addRandomOffset, Player player) Helper method to spawn anItemStack.static voidupdateCapacitorTexture(Location l, int charge, int capacity)
-
Method Details
-
hasNoPickupFlag
This method quickly returns whether anItemwas marked as "no_pickup" by a Slimefun device. -
markAsNoPickup
This will prevent the givenItemfrom being picked up. This is useful for display items which theAncientPedestaluses. -
isSoulbound
- Parameters:
item- TheItemStackto check for- Returns:
- Whether the given item is soulbound
-
isSoulbound
This method checks whether the givenItemStackis consideredSoulbound. If the provided item is aSlimefunItemthen this method will also check that the item is enabled in the providedWorld. If the provided item isSoulboundthrough theSlimefunItems.SOULBOUND_RUNE, then this method will also check that theSlimefunItems.SOULBOUND_RUNEis enabled in the providedWorld- Parameters:
item- TheItemStackto check forworld- TheWorldto check if theSlimefunItemis enabled in if applicable. Ifnullthen this will not do a world check.- Returns:
- Whether the given item is soulbound
-
setSoulbound
Toggles anItemStackto be Soulbound.
If true is passed, this will add theSOULBOUND_LOREand add aNamespacedKeyto the item so it can be quickly identified byisSoulbound(ItemStack).
If false is passed, this property will be removed.- Parameters:
item- TheItemStackyou want to add/remove Soulbound from.makeSoulbound- If the item should be soulbound.- See Also:
-
isRadioactive
This method checks whether the givenItemStackis radioactive. -
getCustomHead
This method returns anItemStackfor 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
ItemStackwith this Head texture
-
containsSimilarItem
-
isItemSimilar
public static boolean isItemSimilar(@Nullable ItemStack item, @Nullable ItemStack sfitem, boolean checkLore) Compares twoItemStacks and returns if they are similar or not. Takes into account some shortcut checks specific toSlimefunItems 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 twoItemStacks and returns if they are similar or not. Takes into account some shortcut checks specific toSlimefunItems for performance. Will check for distintion of items by default- Parameters:
item- TheItemStackbeing tested.sfitem- TheItemStackthat 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
ItemStacks 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 twoItemStacks and returns if they are similar or not. Takes into account some shortcut checks specific toSlimefunItems for performance.- Parameters:
item- TheItemStackbeing tested.sfitem- TheItemStackthat 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
ItemStacks 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 thePlayeris able to use the givenItemStack. It will always returntruefor 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 aSlimefunItemSpawnEventto allow other plugins to catch the item being dropped.- Parameters:
loc- TheLocationwhere to drop the itemitem- TheItemStackto dropreason- TheItemSpawnReasonwhy 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 theSlimefunItemSpawnEventwas 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 aSlimefunItemSpawnEventto allow other plugins to catch the item being dropped.- Parameters:
loc- TheLocationwhere to drop the itemitem- TheItemStackto dropreason- TheItemSpawnReasonwhy the item is being droppedaddRandomOffset- Whether a random offset should be added (seeWorld.dropItemNaturally(Location, ItemStack))- Returns:
- The dropped
Item(or null if theSlimefunItemSpawnEventwas cancelled)
-
spawnItem
@ParametersAreNonnullByDefault @Nullable public static Item spawnItem(Location loc, ItemStack item, ItemSpawnReason reason) Helper method to spawn anItemStack. This method automatically calls aSlimefunItemSpawnEventto allow other plugins to catch the item being dropped.- Parameters:
loc- TheLocationwhere to drop the itemitem- TheItemStackto dropreason- TheItemSpawnReasonwhy the item is being dropped- Returns:
- The dropped
Item(or null if theSlimefunItemSpawnEventwas 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- TheInventoryto check.- Returns:
- True if the inventory is empty and false otherwise
-