Package me.despical.inventoryframework
Class HumanEntityCache
java.lang.Object
me.despical.inventoryframework.HumanEntityCache
A class for containing players and their inventory state for later use
- Since:
- 1.0.1
Created at 04.09.2020
- Author:
- Despical
-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionprotected intadd(@NotNull org.bukkit.entity.HumanEntity humanEntity, @NotNull org.bukkit.inventory.ItemStack item) Adds the given item stack to the human entity's cached inventory.voidThis clears the cache.voidclearCache(@NotNull org.bukkit.entity.HumanEntity humanEntity) Clear the cache for the specified human entityvoidrestore(@NotNull org.bukkit.entity.HumanEntity humanEntity) Restores the contents of the specified human entity.voidRestores all players' contents into their inventory.voidrestoreAndForget(@NotNull org.bukkit.entity.HumanEntity humanEntity) Restores the contents of the specified human entity, clearing the cache afterwards.voidRestores all players' contents into their inventory, clearing the cache afterwards.voidstore(@NotNull org.bukkit.entity.HumanEntity humanEntity) Stores this player's inventory in the cache.voidstoreAndClear(@NotNull org.bukkit.entity.HumanEntity humanEntity) Stores this player's inventory in the cache.
-
Constructor Details
-
HumanEntityCache
public HumanEntityCache()
-
-
Method Details
-
add
protected 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:
- 1.0.3
-
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
-
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:
- 1.0.1
-
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:
- 1.0.1
-
restoreAndForgetAll
public void restoreAndForgetAll()Restores all players' contents into their inventory, clearing the cache afterwards.- Since:
- 1.0.1
-
restore
public void restore(@NotNull @NotNull org.bukkit.entity.HumanEntity humanEntity) Restores the contents of the specified human entity. This method will fail silently if no cache is available. The cache will not be cleared.- Parameters:
humanEntity- the human entity to restore its cache for- Since:
- 1.0.1
-
restoreAll
public void restoreAll()Restores all players' contents into their inventory. The cache will not be cleared.- Since:
- 1.0.1
-
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:
- 1.0.1
-
clearCache
public void clearCache()This clears the cache.- Since:
- 1.0.1
-