Class HumanEntityCache
java.lang.Object
com.github.stefvanschie.inventoryframework.HumanEntityCache
A class for containing players and their inventory state for later use
- Since:
- 0.4.0
-
Constructor Summary
-
Method Summary
Modifier and TypeMethodDescriptionint
add
(@NotNull HumanEntity humanEntity, @NotNull ItemStack item) Adds the given item stack to the human entity's cached inventory.void
clearCache
(@NotNull HumanEntity humanEntity) Clear the cache for the specified human entityvoid
restoreAndForget
(@NotNull HumanEntity humanEntity) Restores the contents of the specified human entity, clearing the cache afterwards.void
Restores all players' contents into their inventory, clearing the cache afterwards.void
store
(@NotNull HumanEntity humanEntity) Stores this player's inventory in the cache.void
storeAndClear
(@NotNull HumanEntity humanEntity) Stores this player's inventory in the cache.
-
Constructor Details
-
HumanEntityCache
public HumanEntityCache()
-
-
Method Details
-
storeAndClear
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
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
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
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
Clear the cache for the specified human entity- Parameters:
humanEntity
- the human entity to clear the cache for- Since:
- 0.4.0
-