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(org.bukkit.entity.Player p, org.bukkit.inventory.ItemStack item, boolean sendMessage) This checks whether thePlayeris able to use the givenItemStack.static booleancontainsSimilarItem(org.bukkit.inventory.Inventory inventory, org.bukkit.inventory.ItemStack item, boolean checkLore) static booleanequalsLore(List<String> lore1, List<String> lore2) This checks if the two provided lores are equal.static org.bukkit.inventory.ItemStackgetCustomHead(String texture) This method returns anItemStackfor the given texture.static booleanhasNoPickupFlag(org.bukkit.entity.Item item) This method quickly returns whether anItemwas marked as "no_pickup" by a Slimefun device.static booleanisDust(org.bukkit.inventory.ItemStack item) Check whether the item is a kind of Dust or not.static booleanisInventoryEmpty(org.bukkit.inventory.Inventory inventory) Helper method to check if an Inventory is empty (has no items in "storage").static booleanisItemSimilar(org.bukkit.inventory.ItemStack item, org.bukkit.inventory.ItemStack sfitem, boolean checkLore) static booleanisItemSimilar(org.bukkit.inventory.ItemStack item, org.bukkit.inventory.ItemStack sfitem, boolean checkLore, boolean checkAmount) static booleanisItemSimilar(org.bukkit.inventory.ItemStack item, org.bukkit.inventory.ItemStack sfitem, boolean checkLore, boolean checkAmount, boolean checkDistinctiveItem) static booleanisItemSimilar(org.bukkit.inventory.ItemStack item, org.bukkit.inventory.ItemStack sfitem, boolean checkLore, boolean checkAmount, boolean checkDistinctiveItem, boolean checkCustomModelData) static booleanisRadioactive(org.bukkit.inventory.ItemStack item) This method checks whether the givenItemStackis radioactive.static booleanisSoulbound(org.bukkit.inventory.ItemStack item) This method checks whether the givenItemStackis consideredSoulbound.static booleanisSoulbound(org.bukkit.inventory.ItemStack item, org.bukkit.World world) This method checks whether the givenItemStackis consideredSoulbound.static voidmarkAsNoPickup(org.bukkit.entity.Item item, String context) This will prevent the givenItemfrom being picked up.static voidsetSoulbound(org.bukkit.inventory.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 org.bukkit.entity.ItemspawnItem(org.bukkit.Location loc, org.bukkit.inventory.ItemStack item, ItemSpawnReason reason) Helper method to spawn anItemStack.static org.bukkit.entity.ItemspawnItem(org.bukkit.Location loc, org.bukkit.inventory.ItemStack item, ItemSpawnReason reason, boolean addRandomOffset) Helper method to spawn anItemStack.static org.bukkit.entity.ItemspawnItem(org.bukkit.Location loc, org.bukkit.inventory.ItemStack item, ItemSpawnReason reason, boolean addRandomOffset, org.bukkit.entity.Player player) Helper method to spawn anItemStack.static voidupdateCapacitorTexture(org.bukkit.Location l, double percentage) static voidupdateCapacitorTexture(org.bukkit.Location l, int charge, int capacity) Deprecated, for removal: This API element is subject to removal in a future version.
-
Method Details
-
hasNoPickupFlag
public static boolean hasNoPickupFlag(@Nonnull org.bukkit.entity.Item item) This method quickly returns whether anItemwas marked as "no_pickup" by a Slimefun device.- Parameters:
item- TheItemto query- Returns:
- Whether the
Itemis excluded from being picked up
-
markAsNoPickup
This will prevent the givenItemfrom being picked up. This is useful for display items which theAncientPedestaluses.- Parameters:
item- TheItemto prevent from being picked upcontext- The context in which thisItemwas flagged
-
isSoulbound
public static boolean isSoulbound(@Nullable org.bukkit.inventory.ItemStack item) This method checks whether the givenItemStackis consideredSoulbound.- Parameters:
item- TheItemStackto 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 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
public static void setSoulbound(@Nullable org.bukkit.inventory.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.- Parameters:
item- TheItemStackyou 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 givenItemStackis radioactive.- Parameters:
item- TheItemStackto check- Returns:
- Whether this
ItemStackis radioactive or not
-
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
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
@Deprecated(forRemoval=true) public static void updateCapacitorTexture(@Nonnull org.bukkit.Location l, int charge, int capacity) Deprecated, for removal: This API element is subject to removal in a future version. -
updateCapacitorTexture
public static void updateCapacitorTexture(@Nonnull org.bukkit.Location l, double percentage) -
canPlayerUseItem
public static boolean canPlayerUseItem(@Nonnull org.bukkit.entity.Player p, @Nullable org.bukkit.inventory.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).- Parameters:
p- ThePlayeritem- TheItemStackto checksendMessage- Whether to send a message response to thePlayer- Returns:
- Whether the
Playeris 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 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 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 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 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 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
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- TheInventoryto 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
-