Class InventoryMock

java.lang.Object
org.mockbukkit.mockbukkit.inventory.InventoryMock
All Implemented Interfaces:
Iterable<ItemStack>, Inventory
Direct Known Subclasses:
AbstractHorseInventoryMock, AnvilInventoryMock, BarrelInventoryMock, BeaconInventoryMock, BrewerInventoryMock, CartographyInventoryMock, ChestInventoryMock, CrafterInventoryMock, DispenserInventoryMock, DropperInventoryMock, EnchantingInventoryMock, EnderChestInventoryMock, FurnaceInventoryMock, GrindstoneInventoryMock, HopperInventoryMock, LecternInventoryMock, LoomInventoryMock, MerchantInventoryMock, PlayerInventoryMock, ShulkerBoxInventoryMock, SmithingInventoryMock, StonecutterInventoryMock, WorkbenchInventoryMock

public class InventoryMock extends Object implements Inventory
Mock implementation of an Inventory.
  • Constructor Details

    • InventoryMock

      public InventoryMock(@Nullable @Nullable InventoryHolder holder, int size, @NotNull @NotNull InventoryType type)
      Constructs a new InventoryMock for the given holder, with a specific size and InventoryType.
      Parameters:
      holder - The holder of the inventory.
      size - The size of the inventory. Must be 2, or a multiple of 9 between 9 and 54.
      type - The type of the inventory.
    • InventoryMock

      public InventoryMock(@Nullable @Nullable InventoryHolder holder, @NotNull @NotNull InventoryType type)
      Constructs a new InventoryMock for the given holder with a specific InventoryType. The size will be InventoryType.getDefaultSize().
      Parameters:
      holder - The holder of the inventory.
      type - The type of the inventory.
    • InventoryMock

      protected InventoryMock(InventoryMock inventory)
    • InventoryMock

      public InventoryMock(@NotNull @NotNull Inventory other)
      Copy constructor. Holder is copied by reference, inventory contents are cloned.
      Parameters:
      other - Inventory to copy.
  • Method Details

    • assertTrueForAll

      @Deprecated(forRemoval=true) public void assertTrueForAll(@NotNull @NotNull Predicate<ItemStack> condition)
      Deprecated, for removal: This API element is subject to removal in a future version.
      Asserts that a certain condition is true for all items, even nulls, in this inventory.
      Parameters:
      condition - The condition to check for.
    • assertTrueForNonNulls

      @Deprecated(forRemoval=true) public void assertTrueForNonNulls(@NotNull @NotNull Predicate<ItemStack> condition)
      Deprecated, for removal: This API element is subject to removal in a future version.
      Assets that a certain condition is true for all items in this inventory that aren't null.
      Parameters:
      condition - The condition to check for.
    • assertTrueForSome

      @Deprecated(forRemoval=true) public void assertTrueForSome(@NotNull @NotNull Predicate<ItemStack> condition)
      Deprecated, for removal: This API element is subject to removal in a future version.
      Asserts that a certain condition is true for at least one item in this inventory. It will skip any null items.
      Parameters:
      condition - The condition to check for.
    • assertContainsAny

      @Deprecated(forRemoval=true) public void assertContainsAny(@NotNull @NotNull ItemStack item)
      Deprecated, for removal: This API element is subject to removal in a future version.
      Asserts that the inventory contains at least one itemstack that is compatible with the given itemstack.
      Parameters:
      item - The itemstack to compare everything to.
    • assertContainsAtLeast

      @Deprecated(forRemoval=true) public void assertContainsAtLeast(@NotNull @NotNull ItemStack item, int amount)
      Deprecated, for removal: This API element is subject to removal in a future version.
      Asserts that the inventory contains at least a specific amount of items that are compatible with the given itemstack.
      Parameters:
      item - The itemstack to search for.
      amount - The minimum amount of items that one should have.
    • getNumberOfItems

      public int getNumberOfItems(@NotNull @NotNull ItemStack item)
      Get the number of times a certain item is in the inventory.
      Parameters:
      item - The item to check for.
      Returns:
      The number of times the item is present in this inventory.
    • addViewer

      public void addViewer(@NotNull @NotNull HumanEntity viewer)
      Adds a viewer to this inventory.
      Parameters:
      viewer - The viewer to add.
    • addViewers

      public void addViewers(@NotNull @NotNull HumanEntity... viewers)
      Adds the given viewers to this inventory.
      Parameters:
      viewers - The viewers to add.
    • addViewers

      public void addViewers(@NotNull @NotNull List<HumanEntity> viewers)
      Adds the given viewers to this inventory.
      Parameters:
      viewers - The List of viewers to add.
    • removeViewer

      public void removeViewer(@NotNull @NotNull HumanEntity viewer)
      Removes a viewer from this inventory.
      Parameters:
      viewer - The viewer to remove.
    • getSize

      public int getSize()
      Specified by:
      getSize in interface Inventory
    • getItem

      public ItemStack getItem(int index)
      Specified by:
      getItem in interface Inventory
    • setItem

      public void setItem(int index, @Nullable @Nullable ItemStack item)
      Specified by:
      setItem in interface Inventory
    • addItem

      @Nullable public @Nullable ItemStack addItem(@NotNull @NotNull ItemStack item)
      Adds a single item to the inventory. Returns whatever item it couldn't add.
      Parameters:
      item - The item to add.
      Returns:
      The remaining stack that couldn't be added. If it's empty it just returns null.
    • addItem

      @NotNull public @NotNull HashMap<Integer,ItemStack> addItem(ItemStack @NotNull ... items) throws IllegalArgumentException
      Specified by:
      addItem in interface Inventory
      Throws:
      IllegalArgumentException
    • getContents

      public ItemStack @NotNull [] getContents()
      Specified by:
      getContents in interface Inventory
    • setContents

      public void setContents(ItemStack @NotNull [] items)
      Specified by:
      setContents in interface Inventory
    • getHolder

      @Nullable public @Nullable InventoryHolder getHolder()
      Specified by:
      getHolder in interface Inventory
    • getHolder

      @Nullable public @Nullable InventoryHolder getHolder(boolean useSnapshot)
      Specified by:
      getHolder in interface Inventory
    • iterator

      @NotNull public @NotNull ListIterator<ItemStack> iterator()
      Specified by:
      iterator in interface Inventory
      Specified by:
      iterator in interface Iterable<ItemStack>
    • stream

      @NotNull public @NotNull Stream<ItemStack> stream()
    • getType

      @NotNull public @NotNull InventoryType getType()
      Specified by:
      getType in interface Inventory
    • getMaxStackSize

      public int getMaxStackSize()
      Specified by:
      getMaxStackSize in interface Inventory
    • setMaxStackSize

      public void setMaxStackSize(int size)
      Specified by:
      setMaxStackSize in interface Inventory
    • removeItem

      @NotNull public @NotNull HashMap<Integer,ItemStack> removeItem(ItemStack... items) throws IllegalArgumentException
      Specified by:
      removeItem in interface Inventory
      Throws:
      IllegalArgumentException
    • removeItemAnySlot

      @NotNull public @NotNull HashMap<Integer,ItemStack> removeItemAnySlot(@NotNull @NotNull ItemStack... items) throws IllegalArgumentException
      Specified by:
      removeItemAnySlot in interface Inventory
      Throws:
      IllegalArgumentException
    • getStorageContents

      public ItemStack @NotNull [] getStorageContents()
      Specified by:
      getStorageContents in interface Inventory
    • setStorageContents

      public void setStorageContents(ItemStack @NotNull [] items) throws IllegalArgumentException
      Specified by:
      setStorageContents in interface Inventory
      Throws:
      IllegalArgumentException
    • contains

      public boolean contains(@Nullable @Nullable Material material) throws IllegalArgumentException
      Specified by:
      contains in interface Inventory
      Throws:
      IllegalArgumentException
    • contains

      public boolean contains(ItemStack item)
      Specified by:
      contains in interface Inventory
    • contains

      public boolean contains(@Nullable @Nullable Material material, int amount) throws IllegalArgumentException
      Specified by:
      contains in interface Inventory
      Throws:
      IllegalArgumentException
    • contains

      public boolean contains(@NotNull @NotNull ItemStack item, int amount)
      Specified by:
      contains in interface Inventory
    • containsAtLeast

      public boolean containsAtLeast(@NotNull @NotNull ItemStack item, int amount)
      Specified by:
      containsAtLeast in interface Inventory
    • all

      @NotNull public @NotNull HashMap<Integer,? extends ItemStack> all(@NotNull @NotNull Material material) throws IllegalArgumentException
      Specified by:
      all in interface Inventory
      Throws:
      IllegalArgumentException
    • all

      @NotNull public @NotNull HashMap<Integer,? extends ItemStack> all(@Nullable @Nullable ItemStack item)
      Specified by:
      all in interface Inventory
    • first

      public int first(@NotNull @NotNull Material material) throws IllegalArgumentException
      Specified by:
      first in interface Inventory
      Throws:
      IllegalArgumentException
    • first

      public int first(@NotNull @NotNull ItemStack item)
      Specified by:
      first in interface Inventory
    • firstEmpty

      public int firstEmpty()
      Specified by:
      firstEmpty in interface Inventory
    • remove

      public void remove(@NotNull @NotNull Material material) throws IllegalArgumentException
      Specified by:
      remove in interface Inventory
      Throws:
      IllegalArgumentException
    • remove

      public void remove(@NotNull @NotNull ItemStack item)
      Specified by:
      remove in interface Inventory
    • clear

      public void clear(int index)
      Specified by:
      clear in interface Inventory
    • clear

      public void clear()
      Specified by:
      clear in interface Inventory
    • close

      public int close()
      Specified by:
      close in interface Inventory
    • getViewers

      @NotNull public @NotNull List<HumanEntity> getViewers()
      Specified by:
      getViewers in interface Inventory
    • iterator

      @NotNull public @NotNull ListIterator<ItemStack> iterator(int index)
      Specified by:
      iterator in interface Inventory
    • getLocation

      public Location getLocation()
      Specified by:
      getLocation in interface Inventory
    • isEmpty

      public boolean isEmpty()
      Specified by:
      isEmpty in interface Inventory
    • getSnapshot

      @NotNull public @NotNull Inventory getSnapshot()
      Creates a snapshot of the inventory.
      Returns:
      An inventory snapshot.
    • getTitle

      @Internal @NotNull public @NotNull net.kyori.adventure.text.Component getTitle()
      Get the name for this inventory. Uses the value in getCustomTitle() if set, otherwise uses the default name for the inventory type.
      Returns:
      The inventory name.
      See Also:
    • getCustomTitle

      @Internal @Nullable public @Nullable net.kyori.adventure.text.Component getCustomTitle()
      Get the custom title to be used in this inventory when set.
      Returns:
      The title to be used, or null.
    • setCustomTitle

      @Internal public void setCustomTitle(@Nullable @Nullable net.kyori.adventure.text.Component customTitle)
      Set the custom title to be used in this inventory.
      Parameters:
      customTitle - The title to be used, or null.
    • isIdentical

      @Internal public boolean isIdentical(@Nullable @Nullable Inventory inventory)
      Check if two inventories are identical.

      An inventory is considered as identical if the following properties match:

      • Has the same inventory type.
      • Has the same inventory holder.
      • Has the same items and quantities.
      • Has the same maximum stack size.
      • Has the same custom title
      Parameters:
      inventory - The other inventory to compare.
      Returns:
      true when identical, otherwise false
    • equals

      public boolean equals(Object o)
      Note: does not compare holder or viewers (matches spigot/paper).
      Overrides:
      equals in class Object
    • hashCode

      public int hashCode()
      Overrides:
      hashCode in class Object
    • toString

      public String toString()
      Overrides:
      toString in class Object