Class InventoryMock

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

public class InventoryMock extends Object implements org.bukkit.inventory.Inventory
Mock implementation of an Inventory.
  • Constructor Summary

    Constructors
    Constructor
    Description
    InventoryMock(@Nullable org.bukkit.inventory.InventoryHolder holder, int size, @NotNull org.bukkit.event.inventory.InventoryType type)
    Constructs a new InventoryMock for the given holder, with a specific size and InventoryType.
    InventoryMock(@Nullable org.bukkit.inventory.InventoryHolder holder, @NotNull org.bukkit.event.inventory.InventoryType type)
    Constructs a new InventoryMock for the given holder with a specific InventoryType.
  • Method Summary

    Modifier and Type
    Method
    Description
    @Nullable org.bukkit.inventory.ItemStack
    addItem(@NotNull org.bukkit.inventory.ItemStack item)
    Adds a single item to the inventory.
    @NotNull HashMap<Integer,org.bukkit.inventory.ItemStack>
    addItem(org.bukkit.inventory.ItemStack @NotNull ... items)
     
    void
    addViewer(@NotNull org.bukkit.entity.HumanEntity viewer)
    Adds a viewer to this inventory.
    void
    addViewers(@NotNull List<org.bukkit.entity.HumanEntity> viewers)
    Adds the given viewers to this inventory.
    void
    addViewers(@NotNull org.bukkit.entity.HumanEntity... viewers)
    Adds the given viewers to this inventory.
    @NotNull HashMap<Integer,? extends org.bukkit.inventory.ItemStack>
    all(@NotNull org.bukkit.Material material)
     
    @NotNull HashMap<Integer,? extends org.bukkit.inventory.ItemStack>
    all(@Nullable org.bukkit.inventory.ItemStack item)
     
    void
    assertContainsAny(@NotNull org.bukkit.inventory.ItemStack item)
    Asserts that the inventory contains at least one itemstack that is compatible with the given itemstack.
    void
    assertContainsAtLeast(@NotNull org.bukkit.inventory.ItemStack item, int amount)
    Asserts that the inventory contains at least a specific amount of items that are compatible with the given itemstack.
    void
    assertTrueForAll(@NotNull Predicate<org.bukkit.inventory.ItemStack> condition)
    Asserts that a certain condition is true for all items, even nulls, in this inventory.
    void
    assertTrueForNonNulls(@NotNull Predicate<org.bukkit.inventory.ItemStack> condition)
    Assets that a certain condition is true for all items in this inventory that aren't null.
    void
    assertTrueForSome(@NotNull Predicate<org.bukkit.inventory.ItemStack> condition)
    Asserts that a certain condition is true for at least one item in this inventory.
    void
     
    void
    clear(int index)
     
    int
     
    boolean
    contains(@Nullable org.bukkit.Material material)
     
    boolean
    contains(@Nullable org.bukkit.Material material, int amount)
     
    boolean
    contains(@NotNull org.bukkit.inventory.ItemStack item, int amount)
     
    boolean
    contains(org.bukkit.inventory.ItemStack item)
     
    boolean
    containsAtLeast(@NotNull org.bukkit.inventory.ItemStack item, int amount)
     
    int
    first(@NotNull org.bukkit.Material material)
     
    int
    first(@NotNull org.bukkit.inventory.ItemStack item)
     
    int
     
    org.bukkit.inventory.ItemStack @NotNull []
     
    @Nullable org.bukkit.inventory.InventoryHolder
     
    @Nullable org.bukkit.inventory.InventoryHolder
    getHolder(boolean useSnapshot)
     
    org.bukkit.inventory.ItemStack
    getItem(int index)
     
    org.bukkit.Location
     
    int
     
    int
    getNumberOfItems(@NotNull org.bukkit.inventory.ItemStack item)
    Get the number of times a certain item is in the inventory.
    int
     
    @NotNull org.bukkit.inventory.Inventory
    Creates a snapshot of the inventory.
    org.bukkit.inventory.ItemStack @NotNull []
     
    @NotNull org.bukkit.event.inventory.InventoryType
     
    @NotNull List<org.bukkit.entity.HumanEntity>
     
    boolean
     
    @NotNull ListIterator<org.bukkit.inventory.ItemStack>
     
    @NotNull ListIterator<org.bukkit.inventory.ItemStack>
    iterator(int index)
     
    void
    remove(@NotNull org.bukkit.Material material)
     
    void
    remove(@NotNull org.bukkit.inventory.ItemStack item)
     
    @NotNull HashMap<Integer,org.bukkit.inventory.ItemStack>
    removeItem(org.bukkit.inventory.ItemStack... items)
     
    @NotNull HashMap<Integer,org.bukkit.inventory.ItemStack>
    removeItemAnySlot(@NotNull org.bukkit.inventory.ItemStack... items)
     
    void
    removeViewer(@NotNull org.bukkit.entity.HumanEntity viewer)
    Removes a viewer from this inventory.
    void
    setContents(org.bukkit.inventory.ItemStack @NotNull [] items)
     
    void
    setItem(int index, @Nullable org.bukkit.inventory.ItemStack item)
     
    void
    setMaxStackSize(int size)
     
    void
    setStorageContents(org.bukkit.inventory.ItemStack @NotNull [] items)
     

    Methods inherited from class java.lang.Object

    clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait

    Methods inherited from interface java.lang.Iterable

    forEach, spliterator
  • Constructor Details

    • InventoryMock

      public InventoryMock(@Nullable @Nullable org.bukkit.inventory.InventoryHolder holder, int size, @NotNull @NotNull org.bukkit.event.inventory.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 org.bukkit.inventory.InventoryHolder holder, @NotNull @NotNull org.bukkit.event.inventory.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.
  • Method Details

    • assertTrueForAll

      public void assertTrueForAll(@NotNull @NotNull Predicate<org.bukkit.inventory.ItemStack> condition)
      Asserts that a certain condition is true for all items, even nulls, in this inventory.
      Parameters:
      condition - The condition to check for.
    • assertTrueForNonNulls

      public void assertTrueForNonNulls(@NotNull @NotNull Predicate<org.bukkit.inventory.ItemStack> condition)
      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

      public void assertTrueForSome(@NotNull @NotNull Predicate<org.bukkit.inventory.ItemStack> condition)
      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

      public void assertContainsAny(@NotNull @NotNull org.bukkit.inventory.ItemStack item)
      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

      public void assertContainsAtLeast(@NotNull @NotNull org.bukkit.inventory.ItemStack item, int amount)
      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 org.bukkit.inventory.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 org.bukkit.entity.HumanEntity viewer)
      Adds a viewer to this inventory.
      Parameters:
      viewer - The viewer to add.
    • addViewers

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

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

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

      public int getSize()
      Specified by:
      getSize in interface org.bukkit.inventory.Inventory
    • getItem

      public org.bukkit.inventory.ItemStack getItem(int index)
      Specified by:
      getItem in interface org.bukkit.inventory.Inventory
    • setItem

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

      @Nullable public @Nullable org.bukkit.inventory.ItemStack addItem(@NotNull @NotNull org.bukkit.inventory.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,org.bukkit.inventory.ItemStack> addItem(org.bukkit.inventory.ItemStack @NotNull ... items) throws IllegalArgumentException
      Specified by:
      addItem in interface org.bukkit.inventory.Inventory
      Throws:
      IllegalArgumentException
    • getContents

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

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

      @Nullable public @Nullable org.bukkit.inventory.InventoryHolder getHolder()
      Specified by:
      getHolder in interface org.bukkit.inventory.Inventory
    • getHolder

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

      @NotNull public @NotNull ListIterator<org.bukkit.inventory.ItemStack> iterator()
      Specified by:
      iterator in interface org.bukkit.inventory.Inventory
      Specified by:
      iterator in interface Iterable<org.bukkit.inventory.ItemStack>
    • getType

      @NotNull public @NotNull org.bukkit.event.inventory.InventoryType getType()
      Specified by:
      getType in interface org.bukkit.inventory.Inventory
    • getMaxStackSize

      public int getMaxStackSize()
      Specified by:
      getMaxStackSize in interface org.bukkit.inventory.Inventory
    • setMaxStackSize

      public void setMaxStackSize(int size)
      Specified by:
      setMaxStackSize in interface org.bukkit.inventory.Inventory
    • removeItem

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

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

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

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

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

      public boolean contains(org.bukkit.inventory.ItemStack item)
      Specified by:
      contains in interface org.bukkit.inventory.Inventory
    • contains

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

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

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

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

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

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

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

      public int firstEmpty()
      Specified by:
      firstEmpty in interface org.bukkit.inventory.Inventory
    • remove

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

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

      public void clear(int index)
      Specified by:
      clear in interface org.bukkit.inventory.Inventory
    • clear

      public void clear()
      Specified by:
      clear in interface org.bukkit.inventory.Inventory
    • close

      public int close()
      Specified by:
      close in interface org.bukkit.inventory.Inventory
    • getViewers

      @NotNull public @NotNull List<org.bukkit.entity.HumanEntity> getViewers()
      Specified by:
      getViewers in interface org.bukkit.inventory.Inventory
    • iterator

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

      public org.bukkit.Location getLocation()
      Specified by:
      getLocation in interface org.bukkit.inventory.Inventory
    • isEmpty

      public boolean isEmpty()
      Specified by:
      isEmpty in interface org.bukkit.inventory.Inventory
    • getSnapshot

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