Class EtherealBags
Responsibilities:
- Track which bag IDs belong to which player (by UUID).
- Store serialized bag contents by a composite bag key.
- Load data on plugin start (
init()
) and save on shutdown (shutdown()
). - Track open Ethereal GUIs to close them safely during shutdown.
- Provide methods to add, remove, update, and query bags and their contents.
- Normalize bag IDs by stripping or adding the UUID prefix.
- Check and manage open GUIs for players and bag IDs.
- bags: Map keyed by a player's UUID string. Value is a list of raw bag IDs.
- bagData: Map keyed by a composite string "<uuid>-<bagId>".
- bagSettings: Map keyed by the same composite string, storing
EtherealBagSettings
instances. - openGUIs: List of currently open
EtherealGUI
instances.
Config
with JSON-serialized payloads.-
Field Summary
FieldsModifier and TypeFieldDescriptionprotected static valorless.valorlessutils.config.Config
Data file configuration representing bags/etherealbags.yml.static List<EtherealGUI>
Currently open Ethereal GUIs, used to ensure they are closed before saving on shutdown. -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionstatic Boolean
Add a bag to a player with empty initial contents.static Boolean
Add a bag to a player and store initial contents.static Boolean
Close any player's open bag GUI by its composite ID.static Boolean
Close a specific player's open bag GUI by raw bag ID.static String
formatBagId
(UUID uuid, String bagId) Format a raw bag ID by adding the player's "<uuid>-" prefix.static <T> T
static String
getBagAutoPickup
(UUID uuid, String bagId) Get the autoPickup setting of a player's bag or "null" if unknown.static Boolean
getBagAutoSort
(UUID uuid, String bagId) Get the autoSort setting of a player's bag or false if unknown.static List<org.bukkit.inventory.ItemStack>
getBagContentsOrEmpty
(UUID uuid, String bagId) Get the contents of a player's bag or an empty list if unknown.static List<org.bukkit.inventory.ItemStack>
getBagContentsOrNull
(UUID uuid, String bagId) Get the contents of a player's bag or null if unknown.static Boolean
getBagMagnet
(UUID uuid, String bagId) Get the magnet setting of a player's bag or false if unknown.static EtherealBagSettings
getBagSettings
(UUID uuid, String bagId) Get the settings of a player's bag or create default settings if unknown.getPlayerBags
(UUID uuid) Get a player's raw bag IDs.getPlayerBagsFormatted
(UUID uuid) Get a player's bag IDs normalized by stripping any "<uuid>-" prefix.static Boolean
Check if a player owns a specific bag ID.static Boolean
Check whether a player owns any bags.static void
init()
Initialize the Ethereal Bags subsystem.static Boolean
Check if a player's bag is completely full (no empty slots).static Boolean
Check if any player has a specific bag GUI open by its composite ID.static Boolean
Check if any specific player has a specific bag GUI open.static Boolean
Remove a bag ID from a player and delete its stored contents.static void
shutdown()
Persist all bag ownership and contents to disk.static String
stripBagId
(UUID uuid, String bagId) Normalize a bag ID by stripping the player's "<uuid>-" prefix if present.static Boolean
updateBagContents
(UUID uuid, String bagId, List<org.bukkit.inventory.ItemStack> contents) Update stored contents for a player's bag.
-
Field Details
-
config
protected static valorless.valorlessutils.config.Config configData file configuration representing bags/etherealbags.yml. -
openGUIs
Currently open Ethereal GUIs, used to ensure they are closed before saving on shutdown.
-
-
Constructor Details
-
EtherealBags
public EtherealBags()
-
-
Method Details
-
isOpen
Check if any specific player has a specific bag GUI open.- Parameters:
player
- Player to checkbagId
- Raw bag identifier- Returns:
- true if the player has the specified bag GUI open; false otherwise
-
isOpen
Check if any player has a specific bag GUI open by its composite ID.The composite ID is in the format "<uuid>-<bagId>".
- Parameters:
bagId
- Composite bag identifier to check- Returns:
- true if any player has the specified bag GUI open; false otherwise
-
closeGUI
Close a specific player's open bag GUI by raw bag ID.- Parameters:
player
- Player whose GUI to closebagId
- Raw bag identifier- Returns:
- true if the GUI was found and closed; false otherwise
-
closeGUI
Close any player's open bag GUI by its composite ID.The composite ID is in the format "<uuid>-<bagId>".
- Parameters:
bagId
- Composite bag identifier- Returns:
- true if the GUI was found and closed; false otherwise
-
init
public static void init()Initialize the Ethereal Bags subsystem.Ensures storage directories/files exist, loads persisted JSON strings from the YAML config into in-memory maps, clears any tracked open GUIs, and logs load duration.
-
shutdown
public static void shutdown()Persist all bag ownership and contents to disk.Closes any tracked open Ethereal GUIs first, then writes JSON strings for both maps to the YAML file and logs save duration.
-
hasBags
Check whether a player owns any bags.- Parameters:
uuid
- UUID to check- Returns:
- true if the player has at least one bag; false otherwise
-
hasBag
Check if a player owns a specific bag ID.This checks for the existence of the composite key "<uuid>-<bagId>" in
bagData
.- Parameters:
uuid
- UUID to checkbagId
- Bag identifier to look for- Returns:
- true if found; false otherwise
-
addBag
public static Boolean addBag(UUID uuid, String bagId, List<org.bukkit.inventory.ItemStack> contents) Add a bag to a player and store initial contents.Records the raw bag ID under the player in
bags
, and stores contents inbagData
under the composite key "- ". Returns false if this player already has the specified bag ID or if the composite key already exists in
bagData
; otherwise returns true and persists the provided contents.- Parameters:
uuid
- Owner of the bagbagId
- Raw bag identifiercontents
- Initial contents to store (will be saved as-is)- Returns:
- true if the new bag was created; false if it already exists
-
addBag
Add a bag to a player with empty initial contents.Records the raw bag ID under the player in
bags
, and stores empty contents inbagData
under the composite key "- ". The size parameter determines how many rows of 9 slots to create. Empty slots are represented by null
entries.Returns false if this player already has the specified bag ID or if the composite key already exists in
bagData
; otherwise returns true and initializes the contents tosize * 9
slots.- Parameters:
uuid
- Owner of the bagbagId
- Raw bag identifiersize
- Number of rows (of 9 slots each) for the bag's initial contents- Returns:
- true if the new bag was created; false if it already exists
-
removeBag
Remove a bag ID from a player and delete its stored contents.Removes the raw bag ID from
bags
. Also removes the entry frombagData
using the composite key for the player and bag ID. If the player's bag list becomes empty, their entry is removed frombags
.- Parameters:
uuid
- Owner of the bagbagId
- Bag identifier to remove- Returns:
- true if the bag existed and was removed; false otherwise
-
updateBagContents
public static Boolean updateBagContents(UUID uuid, String bagId, List<org.bukkit.inventory.ItemStack> contents) Update stored contents for a player's bag.Contents are saved under the composite key "<uuid>-<bagId>". No-op if the composite key does not exist.
- Parameters:
uuid
- Owner of the bagbagId
- Bag identifiercontents
- New contents to store- Returns:
- true if the bag existed and was updated; false otherwise
-
getBagContentsOrNull
Get the contents of a player's bag or null if unknown.Builds the composite key from the player UUID and bagId and queries
bagData
.- Parameters:
uuid
- Owner of the bagbagId
- Raw bag identifier- Returns:
- List of ItemStack if present; otherwise null
-
getBagContentsOrEmpty
Get the contents of a player's bag or an empty list if unknown.Builds the composite key from the player UUID and bagId and queries
bagData
.- Parameters:
uuid
- Owner of the bagbagId
- Raw bag identifier- Returns:
- Bag contents if present; otherwise an empty list
-
getPlayerBags
Get a player's raw bag IDs.- Parameters:
uuid
- UUID to query- Returns:
- List of raw bag IDs owned by the player; empty if none
-
getPlayerBagsFormatted
Get a player's bag IDs normalized by stripping any "<uuid>-" prefix.If IDs are already raw, the list is returned unchanged.
- Parameters:
uuid
- UUID to query- Returns:
- List of normalized bag IDs
-
getBagSettings
Get the settings of a player's bag or create default settings if unknown.Builds the composite key from the player UUID and bagId and queries
bagFeatures
.
If no settings exist, a new defaultEtherealBagSettings
instance is created, stored, and returned.- Parameters:
uuid
- Owner of the bagbagId
- Raw bag identifier- Returns:
- EtherealBagSettings instance if present; otherwise null
-
getBagAutoPickup
Get the autoPickup setting of a player's bag or "null" if unknown.- Parameters:
uuid
- Owner of the bagbagId
- Raw bag identifier- Returns:
- autoPickup setting if present; otherwise "null"
-
getBagMagnet
Get the magnet setting of a player's bag or false if unknown.- Parameters:
uuid
- Owner of the bagbagId
- Raw bag identifier- Returns:
- magnet setting if present; otherwise false
-
getBagAutoSort
Get the autoSort setting of a player's bag or false if unknown.- Parameters:
uuid
- Owner of the bagbagId
- Raw bag identifier- Returns:
- autoSort setting if present; otherwise false
-
stripBagId
Normalize a bag ID by stripping the player's "<uuid>-" prefix if present.- Parameters:
uuid
- Owner of the bagbagId
- Raw or composite bag identifier- Returns:
- The bagId with the player's "<uuid>-" prefix removed, if it existed
-
formatBagId
Format a raw bag ID by adding the player's "<uuid>-" prefix.- Parameters:
uuid
- Owner of the bagbagId
- Raw bag identifier- Returns:
- The composite bag key "<uuid>-<bagId>"
-
isBagFull
Check if a player's bag is completely full (no empty slots).Uses
getBagContentsOrNull(UUID, String)
to retrieve contents and checks for anynull
entries representing empty slots.- Parameters:
uuid
- Owner of the bagbagId
- Raw bag identifier- Returns:
- true if the bag exists and has no empty slots; false if it has empty slots or does not exist
-
fromJson
-