Class InventoryState

java.lang.Object
wbs.utils.util.entities.state.tracker.InventoryState
All Implemented Interfaces:
org.bukkit.configuration.serialization.ConfigurationSerializable, EntityState<org.bukkit.entity.Player>

public class InventoryState extends Object implements EntityState<org.bukkit.entity.Player>, org.bukkit.configuration.serialization.ConfigurationSerializable
An EntityState that captures the current PlayerInventory of a Player.
See Also:
  • HumanEntity.getInventory()
  • PlayerInventory.getHeldItemSlot()
  • Constructor Details

    • InventoryState

      public InventoryState()
      Creates the state with no items or item slot configured.
    • InventoryState

      public InventoryState(org.bukkit.inventory.ItemStack[] contents)
      Parameters:
      contents - The items to track
    • InventoryState

      public InventoryState(org.bukkit.inventory.ItemStack[] contents, int itemSlot)
      Parameters:
      contents - The items to track
      itemSlot - The item slot (0-8, representing slots 1-9 in the hotbar) to track.
  • Method Details

    • captureState

      public void captureState(org.bukkit.entity.Player target)
      Description copied from interface: EntityState
      Capture the state of an instance of EntityState according to the implementation, and store it until EntityState.restoreState(T) is called.
      Specified by:
      captureState in interface EntityState<org.bukkit.entity.Player>
      Parameters:
      target - The EntityState from which to capture.
    • restoreState

      public void restoreState(org.bukkit.entity.Player target)
      Description copied from interface: EntityState
      Restore the state of an instance of EntityState according to the implementation.
      Specified by:
      restoreState in interface EntityState<org.bukkit.entity.Player>
      Parameters:
      target - The EntityState for which to the stored state.
    • getContents

      @Nullable public @Nullable org.bukkit.inventory.ItemStack[] getContents()
      Returns:
      The items to track
    • setContents

      public void setContents(org.bukkit.inventory.ItemStack[] contents)
      Parameters:
      contents - The items to track
    • getItemSlot

      public int getItemSlot()
      Returns:
      The item slot (0-8, representing slots 1-9 in the hotbar) to track.
    • setItemSlot

      public void setItemSlot(int itemSlot)
      Parameters:
      itemSlot - The item slot (0-8, representing slots 1-9 in the hotbar) to track.
    • restoreAfter

      @NotNull public @NotNull Set<Class<? extends EntityState<?>>> restoreAfter()
      Description copied from interface: EntityState
      Used to build a graph of captured states, allowing states to be restored in the appropriate order, such as restoring AllowFlightState after GameModeState, to prevent a change to GameMode.SURVIVAL from overriding the Player.getAllowFlight() state.
      Specified by:
      restoreAfter in interface EntityState<org.bukkit.entity.Player>
      Returns:
      A set of classes to restore after, if present in a given SavedEntityState.
    • deserialize

      public static InventoryState deserialize(Map<String,Object> args)
      Deserializer method for converting a Map into this object, for use in EntityStateManager
      Parameters:
      args - The partially deserialized Map.
      Returns:
      An instance of this class, deserialized from args.
    • serialize

      @NotNull public @NotNull Map<String,Object> serialize()
      Specified by:
      serialize in interface org.bukkit.configuration.serialization.ConfigurationSerializable