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: https://hub.spigotmc.org/javadocs/spigot/org/bukkit/inventory/ItemStack.html
Version:
4.0.1.1
Author:
Crypto Morin
See Also:
XMaterial, XPotion, SkullUtils, XEnchantment, ItemStack
  • Method Summary

    Modifier and Type Method Description
    static List<org.bukkit.inventory.ItemStack> addItems​(org.bukkit.inventory.Inventory inventory, boolean split, org.bukkit.inventory.ItemStack... items)
    Optimized version of Inventory.addItem(ItemStack...) https://hub.spigotmc.org/stash/projects/SPIGOT/repos/craftbukkit/browse/src/main/java/org/bukkit/craftbukkit/inventory/CraftInventory.java
    static org.bukkit.inventory.ItemStack deserialize​(org.bukkit.configuration.ConfigurationSection config)
    Deserialize an ItemStack from the config.
    static int firstEmpty​(org.bukkit.inventory.Inventory inventory, int beginIndex)
    Gets the first empty slot in the inventory from an index.
    static int firstPartial​(org.bukkit.inventory.Inventory inventory, org.bukkit.inventory.ItemStack item, int beginIndex)
    Gets the item index in the inventory that matches the given item argument.
    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 org.bukkit.Color parseColor​(String str)
    Parses RGB color codes from a string.
    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)
    Stacks up the items in the given item collection that are ItemStack.isSimilar(ItemStack).

    Methods inherited from class java.lang.Object

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

    • 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
    • deserialize

      @Nullable 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
    • 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

      @Nonnull public static List<org.bukkit.inventory.ItemStack> addItems​(@Nonnull org.bukkit.inventory.Inventory inventory, boolean split, @Nonnull org.bukkit.inventory.ItemStack... items)
      Optimized version of Inventory.addItem(ItemStack...) https://hub.spigotmc.org/stash/projects/SPIGOT/repos/craftbukkit/browse/src/main/java/org/bukkit/craftbukkit/inventory/CraftInventory.java
      Parameters:
      inventory - the inventory to add the items to.
      split - if it should check for the inventory stack size Inventory.getMaxStackSize() or 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.
      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)
      Gets the item index 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.
      Returns:
      the index of the matched item, otherwise -1
      Throws:
      IndexOutOfBoundsException - if the beginning index is less than 0 or greater than the inventory storage size.
      Since:
      4.0.0
    • stack

      @Nonnull public static List<org.bukkit.inventory.ItemStack> stack​(@Nonnull Collection<org.bukkit.inventory.ItemStack> items)
      Stacks up the items in the given item collection that are ItemStack.isSimilar(ItemStack).
      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)
      Gets the first empty slot in the inventory from an index.
      Parameters:
      inventory - the inventory to search from.
      beginIndex - the item index to start our search from in the inventory.
      Returns:
      first empty item index, otherwise -1
      Throws:
      IndexOutOfBoundsException - if the beginning index is less than 0 or greater than the inventory storage size.
      Since:
      4.0.0