Package valorless.havenbags.api
Class HavenBagsAPI
java.lang.Object
valorless.havenbags.api.HavenBagsAPI
Public API for interacting with HavenBags.
Provides helpers to inspect items, fetch and mutate bag data,
manage ethereal bags, and create tokens.
I also threw in a bunch of random methods.
Have fun!
-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionstatic classGUI-related utilities for HavenBags. -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionstatic booleanChecks whether a bag exists in storage.static org.bukkit.entity.PlayerGets the player who has the bag open.static intbagSlotsEmpty(org.bukkit.inventory.ItemStack bag) Counts the number of empty slots in the specified bag item.static StringbagState(org.bukkit.inventory.ItemStack item) Retrieves the current state of the bag.static booleanChecks if the global configuration is set to treat the blacklist as a whitelist.static booleanblacklistAsWhitelist(Data bagData) Checks if the specified bag's configuration is set to treat its blacklist as a whitelist.static booleancanCarry(org.bukkit.inventory.ItemStack item, org.bukkit.inventory.ItemStack bag) Checks if the specified item can be carried in the given bag, considering weight limits.static booleancanCarryMoreBags(org.bukkit.entity.Player player) Checks if the player can carry more bags based on configured limits.static StringcapacityTexture(org.bukkit.inventory.ItemStack bag) Determines the appropriate texture for a bag based on its used capacity.static StringconvertUrlToBase64(String url) Converts a texture URL to a Base64-encoded string.static DatacreateBag(BagCreationObject creationObject) Creates and persists a new bag from the provided creation descriptor.static DataCreates and persists a new bag from the provided Data object.static org.bukkit.inventory.ItemStackcreateEffectToken(String value) Creates an effect token for the given effect identifier.static booleancreateEtherealBag(String bagId, org.bukkit.entity.Player player, int size) Creates an ethereal bag entry for a player.static org.bukkit.inventory.ItemStackcreateToken(String value, TokenType type) Creates a skin token ItemStack for the given value and type.static org.bukkit.inventory.ItemStackcreateUnusedBagItem(int size, boolean binding) Creates an unused bag ItemStack with specified size and binding status.static org.bukkit.inventory.ItemStackcreteHeadFromBase64(String base64) Creates a player head ItemStack with a custom texture from a Base64 string.static booleanDeletes a bag by UUID.static StringextractUrlFromBase64(String base64) Extracts the URL from a Base64-encoded texture string.static voidForces the closure of all open bags for all players.static org.bukkit.inventory.ItemStackgenerateBagItem(Data bagData) Generates a bag item from the provided Data.static DataFetches Data for a bag by UUID.static DatagetBagData(org.bukkit.inventory.ItemStack item) Resolves the live Data object for the given bag item.static StringgetBagOwner(String uuid) Gets the owner UUID of a bag.static intgetBagSlotsInInventory(org.bukkit.entity.Player player) Calculates the total number of bag slots in a player's inventory.getBagsOnPlayer(org.bukkit.entity.Player player) Lists all bag Data instances present in a player's inventory.static StringgetBagUUID(org.bukkit.inventory.ItemStack item) Gets the UUID stored on a bag item.static doublegetBagWeight(List<org.bukkit.inventory.ItemStack> bagContents) Calculates the total weight of a list of ItemStacks, typically representing bag contents.static doublegetBagWeight(org.bukkit.inventory.ItemStack bag) Calculates the total weight of items contained within the specified bag item.static StringReturns the active database type used by HavenBags.static List<org.bukkit.inventory.ItemStack>getEtherealBags(String bagId, org.bukkit.entity.Player player) Gets the contents of an ethereal bag for a player.static EtherealBagSettingsgetEtherealBagSettings(String bagId, org.bukkit.entity.Player player) Retrieves settings for a player's ethereal bag.static org.bukkit.plugin.java.JavaPluginGets the main plugin instance.static doublegetItemWeight(org.bukkit.inventory.ItemStack item) Retrieves the weight of a single ItemStack.Returns Data objects for all currently open bags.getPlayerBags(String playerUUID) Lists all bags owned by a player.static StringgetTexture(org.bukkit.inventory.ItemStack bag) Retrieves the custom texture Base64 string from the specified bag item.static valorless.valorlessutils.translate.TranslatorGets the Translator instance used by HavenBags.static booleanhasEtherialBag(String bagId, org.bukkit.entity.Player player) Checks if the player has the specified ethereal bag.static booleanhasEtherialBags(String bagId, org.bukkit.entity.Player player) Checks if the player has any ethereal bags.static booleanhasOthersBag(org.bukkit.entity.Player player) Checks if the player has any bags belonging to other players.static booleanisBag(org.bukkit.inventory.ItemStack item) Checks whether the given item is a HavenBag.static booleanChecks if the bag with the specified UUID is full (no empty slots).static booleanChecks if the bag with the specified UUID is full (no empty slots).static booleanisBagFull(org.bukkit.inventory.ItemStack bag) Checks if the specified bag is full (no empty slots).static booleanChecks if a bag is currently open by any viewer.static booleanisEtherealBagOpen(String bagId, org.bukkit.entity.Player player) Checks if the specified ethereal bag is currently open.static booleanisItemBlacklisted(org.bukkit.inventory.ItemStack item, Data bagData) Checks if the specified item is blacklisted from being stored in HavenBags.static booleanisToken(org.bukkit.inventory.ItemStack item) Checks whether the given item is a valid skin token.static voidrefreshBagLore(org.bukkit.inventory.ItemStack bag) Refreshes the lore of the specified bag item to reflect its current state.static voidrefreshBagLore(org.bukkit.inventory.ItemStack bag, org.bukkit.entity.Player player) Refreshes the lore of the specified bag item to reflect its current state.static booleanremoveEtherealBag(String bagId, org.bukkit.entity.Player player) Removes an ethereal bag entry from a player.static booleansetEtherealBagContents(String bagId, org.bukkit.entity.Player player, List<org.bukkit.inventory.ItemStack> contents) Replaces the contents of an ethereal bag for a player.static voidsetTexture(org.bukkit.inventory.ItemStack bag, String base64Texture) Sets a custom texture on the specified bag item.static org.bukkit.inventory.ItemStackupgradeBag(org.bukkit.inventory.ItemStack bag) Upgrades the given bag ItemStack to the next size tier.static doubleusedCapacity(org.bukkit.inventory.ItemStack bag) Calculates how full the specified bag is.
-
Constructor Details
-
HavenBagsAPI
public HavenBagsAPI()
-
-
Method Details
-
getInstance
public static org.bukkit.plugin.java.JavaPlugin getInstance()Gets the main plugin instance.- Returns:
- HavenBags JavaPlugin instance
-
forceCloseAllBags
public static void forceCloseAllBags()Forces the closure of all open bags for all players. -
getTranslator
public static valorless.valorlessutils.translate.Translator getTranslator()Gets the Translator instance used by HavenBags.- Returns:
- Translator instance
-
isBag
public static boolean isBag(org.bukkit.inventory.ItemStack item) Checks whether the given item is a HavenBag.- Parameters:
item- item to check- Returns:
- true if the item represents a bag
-
getBagUUID
Gets the UUID stored on a bag item.- Parameters:
item- bag item- Returns:
- bag UUID string, or null if not a bag
-
getBagData
Resolves the live Data object for the given bag item.- Parameters:
item- bag item- Returns:
- Data for the bag, or null if not a bag
-
generateBagItem
Generates a bag item from the provided Data.- Parameters:
bagData- Data for the bag- Returns:
- ItemStack representing the bag
-
bagExists
Checks whether a bag exists in storage.- Parameters:
uuid- bag UUID- Returns:
- true if the bag exists
-
getBag
Fetches Data for a bag by UUID.- Parameters:
uuid- bag UUID- Returns:
- Data for the bag or null if not found
-
getBagOwner
Gets the owner UUID of a bag.- Parameters:
uuid- bag UUID- Returns:
- owner UUID string
-
getPlayerBags
Lists all bags owned by a player.- Parameters:
playerUUID- player UUID- Returns:
- list of Data for the player's bags
-
getBagsOnPlayer
Lists all bag Data instances present in a player's inventory.- Parameters:
player- player to inspect- Returns:
- list of Data for bags found
-
isBagOpen
Checks if a bag is currently open by any viewer.- Parameters:
uuid- bag UUID- Returns:
- true if open
-
bagOpenBy
Gets the player who has the bag open.- Parameters:
uuid- bag UUID- Returns:
- Player who opened the bag, or null if not open
-
getOpenBagsUUIDs
Returns Data objects for all currently open bags.- Returns:
- list of open bag Data
-
getDatabaseType
Returns the active database type used by HavenBags.- Returns:
- database type as string. i.e, "FILES", "SQLITE", etc.
-
createBag
Creates and persists a new bag from the provided creation descriptor.- Parameters:
creationObject- bag creation parameters- Returns:
- Data for the created bag
-
createBag
Creates and persists a new bag from the provided Data object.- Parameters:
bagData- bag Data- Returns:
- Data for the created bag
-
deleteBag
Deletes a bag by UUID.- Parameters:
uuid- bag UUID- Returns:
- true if deletion succeeded
-
createToken
Creates a skin token ItemStack for the given value and type.- Parameters:
value- token payload (e.g., texture or model key)type- token type- Returns:
- token item
-
createEffectToken
Creates an effect token for the given effect identifier.- Parameters:
value- effect id- Returns:
- token item
-
isToken
public static boolean isToken(org.bukkit.inventory.ItemStack item) Checks whether the given item is a valid skin token.- Parameters:
item- item to test- Returns:
- true if the item is a skin token
-
createEtherealBag
Creates an ethereal bag entry for a player.- Parameters:
bagId- bag identifierplayer- target playersize- inventory size (implementation dependent)- Returns:
- true on success
-
removeEtherealBag
Removes an ethereal bag entry from a player.- Parameters:
bagId- bag identifierplayer- target player- Returns:
- true on success
-
getEtherealBags
public static List<org.bukkit.inventory.ItemStack> getEtherealBags(String bagId, org.bukkit.entity.Player player) Gets the contents of an ethereal bag for a player.- Parameters:
bagId- bag identifierplayer- player owning the bag- Returns:
- contents as a list of ItemStacks, or null if not found
-
hasEtherialBag
Checks if the player has the specified ethereal bag.- Parameters:
bagId- bag identifierplayer- player to check- Returns:
- true if present
-
hasEtherialBags
Checks if the player has any ethereal bags.- Parameters:
bagId- ignored identifierplayer- player to check- Returns:
- true if the player has one or more ethereal bags
-
isEtherealBagOpen
Checks if the specified ethereal bag is currently open.- Parameters:
bagId- bag identifierplayer- player owning the bag- Returns:
- true if open
-
setEtherealBagContents
public static boolean setEtherealBagContents(String bagId, org.bukkit.entity.Player player, List<org.bukkit.inventory.ItemStack> contents) Replaces the contents of an ethereal bag for a player.- Parameters:
bagId- bag identifierplayer- player owning the bagcontents- new contents list- Returns:
- true on success
-
getEtherealBagSettings
public static EtherealBagSettings getEtherealBagSettings(String bagId, org.bukkit.entity.Player player) Retrieves settings for a player's ethereal bag.- Parameters:
bagId- bag identifierplayer- player owning the bag- Returns:
- the bag's settings, or null if absent
-
upgradeBag
public static org.bukkit.inventory.ItemStack upgradeBag(org.bukkit.inventory.ItemStack bag) Upgrades the given bag ItemStack to the next size tier. Increases the bag size by 9 slots, updates weight limit if applicable, and changes texture based on new size and owner status.- Parameters:
bag- The ItemStack representing the bag to upgrade.- Returns:
- A new ItemStack representing the upgraded bag, or the original bag if already at max size.
-
setTexture
Sets a custom texture on the specified bag item.- Parameters:
bag- The ItemStack representing the bag to modify.base64Texture- A valid Base64-encoded string representing the new texture.- Throws:
IllegalArgumentException- if the provided texture is not valid Base64.
-
getTexture
Retrieves the custom texture Base64 string from the specified bag item.- Parameters:
bag- The ItemStack representing the bag to inspect.- Returns:
- A Base64-encoded string representing the bag's texture.
-
refreshBagLore
public static void refreshBagLore(org.bukkit.inventory.ItemStack bag) Refreshes the lore of the specified bag item to reflect its current state.- Parameters:
bag- The ItemStack representing the bag to refresh.
-
refreshBagLore
public static void refreshBagLore(org.bukkit.inventory.ItemStack bag, org.bukkit.entity.Player player) Refreshes the lore of the specified bag item to reflect its current state.- Parameters:
bag- The ItemStack representing the bag to refresh.player- The player used in placeholder parsing.
-
getBagWeight
public static double getBagWeight(org.bukkit.inventory.ItemStack bag) Calculates the total weight of items contained within the specified bag item.- Parameters:
bag- The ItemStack representing the bag to evaluate.- Returns:
- The total weight of the bag's contents.
-
getBagWeight
Calculates the total weight of a list of ItemStacks, typically representing bag contents.- Parameters:
bagContents- A list of ItemStacks to evaluate.- Returns:
- The total weight of the provided items.
-
getItemWeight
public static double getItemWeight(org.bukkit.inventory.ItemStack item) Retrieves the weight of a single ItemStack.- Parameters:
item- The ItemStack to evaluate.- Returns:
- The weight of the specified item.
-
canCarry
public static boolean canCarry(org.bukkit.inventory.ItemStack item, org.bukkit.inventory.ItemStack bag) Checks if the specified item can be carried in the given bag, considering weight limits.- Parameters:
item- The ItemStack to check.bag- The ItemStack representing the bag.- Returns:
- true if bag cannot hold more weight, false otherwise.
-
isItemBlacklisted
public static boolean isItemBlacklisted(org.bukkit.inventory.ItemStack item, @Nullable Data bagData) Checks if the specified item is blacklisted from being stored in HavenBags.Takes into account if using blacklist or whitelist mode.
Please check theblacklistAsWhitelist(Data bagData)before calling this method to ensure correct context.
For global context refer toblacklistAsWhitelist().- Parameters:
item- The ItemStack to check.bagData- (Optional) The Data object of the bag for context-specific checks; can be null.- Returns:
- true if the item is blacklisted, false otherwise.
-
blacklistAsWhitelist
public static boolean blacklistAsWhitelist()Checks if the global configuration is set to treat the blacklist as a whitelist.- Returns:
- true if blacklist is used as whitelist, false otherwise.
-
blacklistAsWhitelist
Checks if the specified bag's configuration is set to treat its blacklist as a whitelist.- Parameters:
bagData- The Data object of the bag to check.- Returns:
- true if blacklist is used as whitelist for this bag, false otherwise.
-
canCarryMoreBags
public static boolean canCarryMoreBags(org.bukkit.entity.Player player) Checks if the player can carry more bags based on configured limits.- Parameters:
player- The player to check.- Returns:
- true if the player can carry more bags, false otherwise.
-
isBagFull
public static boolean isBagFull(org.bukkit.inventory.ItemStack bag) Checks if the specified bag is full (no empty slots).- Parameters:
bag- The ItemStack representing the bag to check.- Returns:
- true if the bag is full, false otherwise.
-
isBagFull
Checks if the bag with the specified UUID is full (no empty slots).- Parameters:
uuid- The UUID string of the bag to check.- Returns:
- true if the bag is full, false otherwise.
-
isBagFull
Checks if the bag with the specified UUID is full (no empty slots).- Parameters:
uuid- The UUID string of the bag to check.- Returns:
- true if the bag is full, false otherwise.
-
bagSlotsEmpty
public static int bagSlotsEmpty(org.bukkit.inventory.ItemStack bag) Counts the number of empty slots in the specified bag item.- Parameters:
bag- The ItemStack representing the bag to check.- Returns:
- The number of empty slots in the bag.
-
usedCapacity
public static double usedCapacity(org.bukkit.inventory.ItemStack bag) Calculates how full the specified bag is.- Parameters:
bag- The ItemStack representing the bag to evaluate.- Returns:
- The percentage of used capacity in the bag (0.0 to 100.0).
-
getBagSlotsInInventory
public static int getBagSlotsInInventory(org.bukkit.entity.Player player) Calculates the total number of bag slots in a player's inventory.- Parameters:
player- The player whose inventory to check.- Returns:
- The total number of bag slots.
-
hasOthersBag
public static boolean hasOthersBag(org.bukkit.entity.Player player) Checks if the player has any bags belonging to other players.- Parameters:
player- The player to check.- Returns:
- true if the player has bags owned by others, false otherwise.
-
capacityTexture
Determines the appropriate texture for a bag based on its used capacity. (e.g., changes texture as the bag fills up)- Parameters:
bag- The ItemStack representing the bag to evaluate.- Returns:
- A Base64-encoded string representing the texture for the bag's current capacity.
If no special texture is defined in the configuration, returns the bag's current texture.
-
bagState
Retrieves the current state of the bag.- Parameters:
item- The ItemStack representing the bag to evaluate.- Returns:
- "NEW" if the bag is empty, "USED" otherwise.
May return "NULL" if the item is not a valid bag.
-
extractUrlFromBase64
Extracts the URL from a Base64-encoded texture string.- Parameters:
base64- The Base64-encoded texture string.- Returns:
- The extracted URL.
-
convertUrlToBase64
Converts a texture URL to a Base64-encoded string.- Parameters:
url- The texture URL.- Returns:
- The Base64-encoded texture string.
-
creteHeadFromBase64
Creates a player head ItemStack with a custom texture from a Base64 string.- Parameters:
base64- The Base64-encoded texture string.- Returns:
- The custom player head ItemStack.
-
createUnusedBagItem
public static org.bukkit.inventory.ItemStack createUnusedBagItem(int size, boolean binding) Creates an unused bag ItemStack with specified size and binding status.- Parameters:
size- The size of the bag (number of slots, to the power of 9).binding- Whether the bag should be bound to an owner upon creation.- Returns:
- The created unused bag ItemStack.
-