Class HumanEntityCache
- java.lang.Object
-
- com.github.stefvanschie.inventoryframework.HumanEntityCache
-
public class HumanEntityCache extends Object
A class for containing players and their inventory state for later use- Since:
- 0.4.0
-
-
Constructor Summary
Constructors Constructor Description HumanEntityCache()
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description int
add(@NotNull org.bukkit.entity.HumanEntity humanEntity, @NotNull org.bukkit.inventory.ItemStack item)
Adds the given item stack to the human entity's cached inventory.void
clearCache(@NotNull org.bukkit.entity.HumanEntity humanEntity)
Clear the cache for the specified human entityvoid
restoreAndForget(@NotNull org.bukkit.entity.HumanEntity humanEntity)
Restores the contents of the specified human entity, clearing the cache afterwards.void
restoreAndForgetAll()
Restores all players' contents into their inventory, clearing the cache afterwards.void
store(@NotNull org.bukkit.entity.HumanEntity humanEntity)
Stores this player's inventory in the cache.void
storeAndClear(@NotNull org.bukkit.entity.HumanEntity humanEntity)
Stores this player's inventory in the cache.
-
-
-
Method Detail
-
storeAndClear
public void storeAndClear(@NotNull @NotNull org.bukkit.entity.HumanEntity humanEntity)
Stores this player's inventory in the cache. If the player was already stored, their cache will be overwritten. Clears the player's inventory afterwards.- Parameters:
humanEntity
- the human entity to keep in the cache
-
restoreAndForget
public void restoreAndForget(@NotNull @NotNull org.bukkit.entity.HumanEntity humanEntity)
Restores the contents of the specified human entity, clearing the cache afterwards. This method will fail silently if no cache is available.- Parameters:
humanEntity
- the human entity to restore its cache for- Since:
- 0.5.19
-
restoreAndForgetAll
public void restoreAndForgetAll()
Restores all players' contents into their inventory, clearing the cache afterwards.- Since:
- 0.5.19
-
add
public int add(@NotNull @NotNull org.bukkit.entity.HumanEntity humanEntity, @NotNull @NotNull org.bukkit.inventory.ItemStack item)
Adds the given item stack to the human entity's cached inventory. The returned amount is the amount of items of the provided item stack that could not be put into the cached inventory. This number will always be equal or less than the amount of items in the provided item stack, but no less than zero. The item stack provided will not be updated with this leftover amount. If the human entity provided is not in the human entity cache, this method will return anIllegalStateException
. The items will be added to the inventory in the same way as the items are stored. The items may be added to an already existing item stack, but the item stack's amount will never go over the maximum stack size.- Parameters:
humanEntity
- the human entity to add the item toitem
- the item to add to the cached inventory- Returns:
- the amount of leftover items that couldn't be fit in the cached inventory
- Throws:
IllegalStateException
- if the human entity's inventory is not cached- Since:
- 0.6.1
-
store
public void store(@NotNull @NotNull org.bukkit.entity.HumanEntity humanEntity)
Stores this player's inventory in the cache. If the player was already stored, their cache will be overwritten.- Parameters:
humanEntity
- the human entity to keep in the cache- Since:
- 0.4.0
-
clearCache
public void clearCache(@NotNull @NotNull org.bukkit.entity.HumanEntity humanEntity)
Clear the cache for the specified human entity- Parameters:
humanEntity
- the human entity to clear the cache for- Since:
- 0.4.0
-
-