Class SlimefunUtils

java.lang.Object
io.github.thebusybiscuit.slimefun4.utils.SlimefunUtils

public final class SlimefunUtils extends Object
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 Type
    Method
    Description
    static boolean
    canPlayerUseItem(org.bukkit.entity.Player p, org.bukkit.inventory.ItemStack item, boolean sendMessage)
    This checks whether the Player is able to use the given ItemStack.
    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
    This method returns an ItemStack for the given texture.
    static boolean
    hasNoPickupFlag(org.bukkit.entity.Item item)
    This method quickly returns whether an Item 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 given ItemStack is radioactive.
    static boolean
    isSoulbound(org.bukkit.inventory.ItemStack item)
    This method checks whether the given ItemStack is considered Soulbound.
    static boolean
    isSoulbound(org.bukkit.inventory.ItemStack item, org.bukkit.World world)
    This method checks whether the given ItemStack is considered Soulbound.
    static void
    markAsNoPickup(org.bukkit.entity.Item item, String context)
    This will prevent the given Item from being picked up.
    static void
    setSoulbound(org.bukkit.inventory.ItemStack item, boolean makeSoulbound)
    Toggles an ItemStack to be Soulbound.
    If true is passed, this will add the SOULBOUND_LORE and add a NamespacedKey to the item so it can be quickly identified by isSoulbound(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 an ItemStack.
    static org.bukkit.entity.Item
    spawnItem(org.bukkit.Location loc, org.bukkit.inventory.ItemStack item, ItemSpawnReason reason, boolean addRandomOffset)
    Helper method to spawn an ItemStack.
    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 an ItemStack.
    static void
    updateCapacitorTexture(org.bukkit.Location l, int charge, int capacity)
     

    Methods inherited from class java.lang.Object

    clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
  • Method Details

    • hasNoPickupFlag

      public static boolean hasNoPickupFlag(@Nonnull org.bukkit.entity.Item item)
      This method quickly returns whether an Item was marked as "no_pickup" by a Slimefun device.
      Parameters:
      item - The Item to query
      Returns:
      Whether the Item is excluded from being picked up
    • markAsNoPickup

      public static void markAsNoPickup(@Nonnull org.bukkit.entity.Item item, @Nonnull String context)
      This will prevent the given Item from being picked up. This is useful for display items which the AncientPedestal uses.
      Parameters:
      item - The Item to prevent from being picked up
      context - The context in which this Item was flagged
    • isSoulbound

      public static boolean isSoulbound(@Nullable org.bukkit.inventory.ItemStack item)
      This method checks whether the given ItemStack is considered Soulbound.
      Parameters:
      item - The ItemStack 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 given ItemStack is considered Soulbound. If the provided item is a SlimefunItem then this method will also check that the item is enabled in the provided World. If the provided item is Soulbound through the SlimefunItems.SOULBOUND_RUNE, then this method will also check that the SlimefunItems.SOULBOUND_RUNE is enabled in the provided World
      Parameters:
      item - The ItemStack to check for
      world - The World to check if the SlimefunItem is enabled in if applicable. If null 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 an ItemStack to be Soulbound.
      If true is passed, this will add the SOULBOUND_LORE and add a NamespacedKey to the item so it can be quickly identified by isSoulbound(ItemStack).
      If false is passed, this property will be removed.
      Parameters:
      item - The ItemStack 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 given ItemStack is radioactive.
      Parameters:
      item - The ItemStack to check
      Returns:
      Whether this ItemStack is radioactive or not
    • getCustomHead

      @Nonnull public static org.bukkit.inventory.ItemStack getCustomHead(@Nonnull String texture)
      This method returns an ItemStack 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

      public static boolean equalsLore(@Nonnull List<String> lore1, @Nonnull List<String> lore2)
      This checks if the two provided lores are equal. This method will ignore any lines such as the soulbound one.
      Parameters:
      lore1 - The first lore
      lore2 - 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 the Player is able to use the given ItemStack. It will always return true for non-Slimefun items.

      If you already have an instance of SlimefunItem, please use SlimefunItem.canUse(Player, boolean).

      Parameters:
      p - The Player
      item - The ItemStack to check
      sendMessage - Whether to send a message response to the Player
      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 an ItemStack. This method automatically calls a SlimefunItemSpawnEvent to allow other plugins to catch the item being dropped.
      Parameters:
      loc - The Location where to drop the item
      item - The ItemStack to drop
      reason - The ItemSpawnReason why the item is being dropped
      addRandomOffset - Whether a random offset should be added (see World.dropItemNaturally(Location, ItemStack))
      player - The player that caused this SlimefunItemSpawnEvent
      Returns:
      The dropped Item (or null if the SlimefunItemSpawnEvent 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 an ItemStack. This method automatically calls a SlimefunItemSpawnEvent to allow other plugins to catch the item being dropped.
      Parameters:
      loc - The Location where to drop the item
      item - The ItemStack to drop
      reason - The ItemSpawnReason why the item is being dropped
      addRandomOffset - Whether a random offset should be added (see World.dropItemNaturally(Location, ItemStack))
      Returns:
      The dropped Item (or null if the SlimefunItemSpawnEvent 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 an ItemStack. This method automatically calls a SlimefunItemSpawnEvent to allow other plugins to catch the item being dropped.
      Parameters:
      loc - The Location where to drop the item
      item - The ItemStack to drop
      reason - The ItemSpawnReason why the item is being dropped
      Returns:
      The dropped Item (or null if the SlimefunItemSpawnEvent 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 call Inventory.isEmpty() (Which calls MC code resulting in a faster method).
      Parameters:
      inventory - The Inventory 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