Class XItemStack

java.lang.Object
com.cryptomorin.xseries.XItemStack

public final class XItemStack extends Object
XItemStack - YAML Item Serializer
Using ConfigurationSection Example:
     ConfigurationSection section = plugin.getConfig().getConfigurationSection("staffs.dragon-staff");
     ItemStack item = XItemStack.deserialize(section);
 
ItemStack
Version:
7.3.3
Author:
Crypto Morin
See Also:
  • Nested Class Summary

    Nested Classes
    Modifier and Type
    Class
    Description
    static class 
     
    static final class 
     
    static final class 
     
  • Field Summary

    Fields
    Modifier and Type
    Field
    Description
    static final org.bukkit.inventory.ItemFlag[]
     
  • Method Summary

    Modifier and Type
    Method
    Description
    static List<org.bukkit.inventory.ItemStack>
    addItems(org.bukkit.inventory.Inventory inventory, boolean split, Predicate<Integer> modifiableSlots, org.bukkit.inventory.ItemStack... items)
    Optimized version of Inventory.addItem(ItemStack...) CraftInventory
    static List<org.bukkit.inventory.ItemStack>
    addItems(org.bukkit.inventory.Inventory inventory, boolean split, org.bukkit.inventory.ItemStack... items)
     
    static org.bukkit.inventory.ItemStack
    deserialize(Map<String,Object> serializedItem)
    Deserialize an ItemStack from a Map.
    static org.bukkit.inventory.ItemStack
    deserialize(Map<String,Object> serializedItem, Function<String,String> translator)
    Deserialize an ItemStack from a Map.
    static org.bukkit.inventory.ItemStack
    deserialize(org.bukkit.configuration.ConfigurationSection config)
    Deserialize an ItemStack from the config.
    static org.bukkit.inventory.ItemStack
    deserialize(org.bukkit.configuration.ConfigurationSection config, Function<String,String> translator)
     
    static org.bukkit.inventory.ItemStack
    deserialize(org.bukkit.configuration.ConfigurationSection config, Function<String,String> translator, Consumer<Exception> restart)
    Deserialize an ItemStack from the config.
    static org.bukkit.inventory.ItemStack
    edit(org.bukkit.inventory.ItemStack item, org.bukkit.configuration.ConfigurationSection config, Function<String,String> translator, Consumer<Exception> restart)
    Deserialize an ItemStack from the config.
    static int
    firstEmpty(org.bukkit.inventory.Inventory inventory, int beginIndex)
     
    static int
    firstEmpty(org.bukkit.inventory.Inventory inventory, int beginIndex, Predicate<Integer> modifiableSlots)
    Gets the first item slot in the inventory that is empty or matches the given item argument.
    static int
    firstPartial(org.bukkit.inventory.Inventory inventory, org.bukkit.inventory.ItemStack item, int beginIndex)
     
    static int
    firstPartial(org.bukkit.inventory.Inventory inventory, org.bukkit.inventory.ItemStack item, int beginIndex, Predicate<Integer> modifiableSlots)
    Gets the item slot in the inventory that matches the given item argument.
    static int
    firstPartialOrEmpty(org.bukkit.inventory.Inventory inventory, org.bukkit.inventory.ItemStack item, int beginIndex)
    Gets the first empty slot or partial item in the inventory from an index.
    static List<org.bukkit.inventory.ItemStack>
    giveOrDrop(org.bukkit.entity.Player player, boolean split, org.bukkit.inventory.ItemStack... items)
    Adds a list of items to the player's inventory and drop the items that did not fit.
    static List<org.bukkit.inventory.ItemStack>
    giveOrDrop(org.bukkit.entity.Player player, org.bukkit.inventory.ItemStack... items)
    Adds a list of items to the player's inventory and drop the items that did not fit.
    static boolean
    isDefaultItem(org.bukkit.inventory.ItemStack item)
     
    static org.bukkit.Color
    Parses RGB color codes from a string.
    static Map<String,Object>
    serialize(org.bukkit.inventory.ItemStack item)
    Writes an ItemStack properties into a Map.
    static void
    serialize(org.bukkit.inventory.ItemStack item, org.bukkit.configuration.ConfigurationSection config)
    Writes an ItemStack object into a config.
    static List<org.bukkit.inventory.ItemStack>
    stack(Collection<org.bukkit.inventory.ItemStack> items)
     
    static List<org.bukkit.inventory.ItemStack>
    stack(Collection<org.bukkit.inventory.ItemStack> items, BiPredicate<org.bukkit.inventory.ItemStack,org.bukkit.inventory.ItemStack> similarity)
    Stacks up the items in the given item collection that are pass the similarity check.

    Methods inherited from class java.lang.Object

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

    • ITEM_FLAGS

      public static final org.bukkit.inventory.ItemFlag[] ITEM_FLAGS
  • Method Details

    • isDefaultItem

      public static boolean isDefaultItem(org.bukkit.inventory.ItemStack item)
    • serialize

      public static void serialize(@Nonnull org.bukkit.inventory.ItemStack item, @Nonnull org.bukkit.configuration.ConfigurationSection config)
      Writes an ItemStack object into a config. The config file will not save after the object is written.
      Parameters:
      item - the ItemStack to serialize.
      config - the config section to write this item to.
      Since:
      1.0.0
    • serialize

      public static Map<String,Object> serialize(@Nonnull org.bukkit.inventory.ItemStack item)
      Writes an ItemStack properties into a Map.
      Parameters:
      item - the ItemStack to serialize.
      Returns:
      a Map containing the serialized ItemStack properties.
    • deserialize

      @Nonnull public static org.bukkit.inventory.ItemStack deserialize(@Nonnull org.bukkit.configuration.ConfigurationSection config)
      Deserialize an ItemStack from the config.
      Parameters:
      config - the config section to deserialize the ItemStack object from.
      Returns:
      a deserialized ItemStack.
      Since:
      1.0.0
    • deserialize

      @Nonnull public static org.bukkit.inventory.ItemStack deserialize(@Nonnull Map<String,Object> serializedItem)
      Deserialize an ItemStack from a Map.
      Parameters:
      serializedItem - the map holding the item configurations to deserialize the ItemStack object from.
      Returns:
      a deserialized ItemStack.
    • deserialize

      @Nonnull public static org.bukkit.inventory.ItemStack deserialize(@Nonnull org.bukkit.configuration.ConfigurationSection config, @Nonnull Function<String,String> translator)
    • deserialize

      @Nonnull public static org.bukkit.inventory.ItemStack deserialize(@Nonnull org.bukkit.configuration.ConfigurationSection config, @Nonnull Function<String,String> translator, @Nullable Consumer<Exception> restart)
      Deserialize an ItemStack from the config.
      Parameters:
      config - the config section to deserialize the ItemStack object from.
      Returns:
      an edited ItemStack.
      Since:
      7.2.0
    • deserialize

      @Nonnull public static org.bukkit.inventory.ItemStack deserialize(@Nonnull Map<String,Object> serializedItem, @Nonnull Function<String,String> translator)
      Deserialize an ItemStack from a Map.
      Parameters:
      serializedItem - the map holding the item configurations to deserialize the ItemStack object from.
      translator - the translator to use for translating the item's name.
      Returns:
      a deserialized ItemStack.
    • edit

      @Nonnull public static org.bukkit.inventory.ItemStack edit(@Nonnull org.bukkit.inventory.ItemStack item, @Nonnull org.bukkit.configuration.ConfigurationSection config, @Nonnull Function<String,String> translator, @Nullable Consumer<Exception> restart)
      Deserialize an ItemStack from the config.
      Parameters:
      config - the config section to deserialize the ItemStack object from.
      Returns:
      an edited ItemStack.
      Since:
      1.0.0
    • parseColor

      @Nonnull public static org.bukkit.Color parseColor(@Nullable String str)
      Parses RGB color codes from a string. This only works for 1.13 and above.
      Parameters:
      str - the RGB string.
      Returns:
      a color based on the RGB.
      Since:
      1.1.0
    • giveOrDrop

      @Nonnull public static List<org.bukkit.inventory.ItemStack> giveOrDrop(@Nonnull org.bukkit.entity.Player player, @Nullable org.bukkit.inventory.ItemStack... items)
      Adds a list of items to the player's inventory and drop the items that did not fit.
      Parameters:
      player - the player to give the items to.
      items - the items to give.
      Returns:
      the items that did not fit and were dropped.
      Since:
      2.0.1
    • giveOrDrop

      @Nonnull public static List<org.bukkit.inventory.ItemStack> giveOrDrop(@Nonnull org.bukkit.entity.Player player, boolean split, @Nullable org.bukkit.inventory.ItemStack... items)
      Adds a list of items to the player's inventory and drop the items that did not fit.
      Parameters:
      player - the player to give the items to.
      items - the items to give.
      split - same as addItems(Inventory, boolean, ItemStack...)
      Returns:
      the items that did not fit and were dropped.
      Since:
      2.0.1
    • addItems

      public static List<org.bukkit.inventory.ItemStack> addItems(@Nonnull org.bukkit.inventory.Inventory inventory, boolean split, @Nonnull org.bukkit.inventory.ItemStack... items)
    • addItems

      @Nonnull public static List<org.bukkit.inventory.ItemStack> addItems(@Nonnull org.bukkit.inventory.Inventory inventory, boolean split, @Nullable Predicate<Integer> modifiableSlots, @Nonnull org.bukkit.inventory.ItemStack... items)
      Optimized version of Inventory.addItem(ItemStack...) CraftInventory
      Parameters:
      inventory - the inventory to add the items to.
      split - false if it should check for the inventory stack size Inventory.getMaxStackSize() or true for item's max stack size ItemStack.getMaxStackSize() when putting items. This is useful when you're adding stacked tools such as swords that you'd like to split them to other slots.
      modifiableSlots - the slots that are allowed to be used for adding the items, otherwise null to allow all slots.
      items - the items to add.
      Returns:
      items that didn't fit in the inventory.
      Since:
      4.0.0
    • firstPartial

      public static int firstPartial(@Nonnull org.bukkit.inventory.Inventory inventory, @Nullable org.bukkit.inventory.ItemStack item, int beginIndex)
    • firstPartial

      public static int firstPartial(@Nonnull org.bukkit.inventory.Inventory inventory, @Nullable org.bukkit.inventory.ItemStack item, int beginIndex, @Nullable Predicate<Integer> modifiableSlots)
      Gets the item slot in the inventory that matches the given item argument. The matched item must be ItemStack.isSimilar(ItemStack) and has not reached its ItemStack.getMaxStackSize() for the inventory.
      Parameters:
      inventory - the inventory to match the item from.
      item - the item to match.
      beginIndex - the index which to start the search from in the inventory.
      modifiableSlots - the slots that can be used to share items.
      Returns:
      the first matched item slot, otherwise -1
      Throws:
      IndexOutOfBoundsException - if the beginning index is less than 0 or greater than the inventory storage size.
      Since:
      4.0.0
    • stack

      public static List<org.bukkit.inventory.ItemStack> stack(@Nonnull Collection<org.bukkit.inventory.ItemStack> items)
    • stack

      @Nonnull public static List<org.bukkit.inventory.ItemStack> stack(@Nonnull Collection<org.bukkit.inventory.ItemStack> items, @Nonnull BiPredicate<org.bukkit.inventory.ItemStack,org.bukkit.inventory.ItemStack> similarity)
      Stacks up the items in the given item collection that are pass the similarity check. This means that if you have a collection that consists of separate items with the same material, you can reduce them using the following:
      
         List<ItemStack> items = Arrays.asList(XMaterial.STONE.parseItem(), XMaterial.STONE.parseItem(), XMaterial.AIR.parseItem());
         items = XItemStack.stack(items, (first, second) -> first.getType == second.getType());
         // items -> [STONE x2, AIR x1]
       
      Parameters:
      items - the items to stack.
      Returns:
      stacked up items.
      Since:
      4.0.0
    • firstEmpty

      public static int firstEmpty(@Nonnull org.bukkit.inventory.Inventory inventory, int beginIndex)
    • firstEmpty

      public static int firstEmpty(@Nonnull org.bukkit.inventory.Inventory inventory, int beginIndex, @Nullable Predicate<Integer> modifiableSlots)
      Gets the first item slot in the inventory that is empty or matches the given item argument. The matched item must be ItemStack.isSimilar(ItemStack) and has not reached its ItemStack.getMaxStackSize() for the inventory.
      Parameters:
      inventory - the inventory to search from.
      beginIndex - the item slot to start the search from in the inventory.
      modifiableSlots - the slots that can be used.
      Returns:
      first empty item slot, otherwise -1
      Throws:
      IndexOutOfBoundsException - if the beginning index is less than 0 or greater than the inventory storage size.
      Since:
      4.0.0
    • firstPartialOrEmpty

      public static int firstPartialOrEmpty(@Nonnull org.bukkit.inventory.Inventory inventory, @Nullable org.bukkit.inventory.ItemStack item, int beginIndex)
      Gets the first empty slot or partial item in the inventory from an index.
      Parameters:
      inventory - the inventory to search from.
      beginIndex - the item slot to start the search from in the inventory.
      Returns:
      first empty or partial item slot, otherwise -1
      Throws:
      IndexOutOfBoundsException - if the beginning index is less than 0 or greater than the inventory storage size.
      Since:
      4.2.0
      See Also: