Package net.william278.husksync.api
Class HuskSyncAPI
java.lang.Object
net.william278.husksync.api.BaseHuskSyncAPI
net.william278.husksync.api.HuskSyncAPI
public class HuskSyncAPI
extends net.william278.husksync.api.BaseHuskSyncAPI
The HuskSync API implementation for the Bukkit platform, providing methods to access and modify player
UserData
held by User
s.
Retrieve an instance of the API class via getInstance()
.-
Field Summary
Fields inherited from class net.william278.husksync.api.BaseHuskSyncAPI
plugin
-
Method Summary
Modifier and TypeMethodDescriptiondeserializeInventory(String serializedInventory)
Deserialize a serializedItemStack
array of player inventory contents into aBukkitInventoryMap
CompletableFuture<org.bukkit.inventory.ItemStack[]>
deserializeItemStackArray(String serializedItemStackArray)
Deserialize a Base-64 encoded inventory array string into aItemStack
array.CompletableFuture<org.bukkit.potion.PotionEffect[]>
deserializePotionEffectArray(String serializedPotionEffectArray)
Deserialize a Base-64 encoded potion effect array string into aPotionEffect
array.static HuskSyncAPI
Entrypoint to the HuskSync API - returns an instance of the APICompletableFuture<Optional<org.bukkit.inventory.ItemStack[]>>
getPlayerEnderChest(net.william278.husksync.player.User user)
Returns theItemStack
s array contents of the givenUser
's Ender Chest datagetPlayerInventory(net.william278.husksync.player.User user)
Returns aBukkitInventoryMap
for the givenUser
, containing their current inventory item datanet.william278.husksync.player.OnlineUser
getUser(org.bukkit.entity.Player player)
Returns aUser
instance for the given bukkitPlayer
.serializeItemStackArray(org.bukkit.inventory.ItemStack[] itemStacks)
Serialize anItemStack
array into a Base-64 encoded string.serializePotionEffectArray(org.bukkit.potion.PotionEffect[] potionEffects)
Serialize aPotionEffect
array into a Base-64 encoded string.setEnderChestData(net.william278.husksync.player.User user, org.bukkit.inventory.ItemStack[] enderChestContents)
Set the Ender Chest in the database of the givenUser
to the givenItemStack
contentssetInventoryData(net.william278.husksync.player.User user, BukkitInventoryMap inventoryMap)
Set the inventory in the database of the givenUser
to the givenBukkitInventoryMap
contentssetInventoryData(net.william278.husksync.player.User user, org.bukkit.inventory.ItemStack[] inventoryContents)
Set the inventory in the database of the givenUser
to the givenItemStack
contentsMethods inherited from class net.william278.husksync.api.BaseHuskSyncAPI
getSavedUserData, getUser, getUser, getUserData, getUserDataJson, saveUserData, setUserData
-
Method Details
-
getInstance
Entrypoint to the HuskSync API - returns an instance of the API- Returns:
- instance of the HuskSync API
-
getUser
@NotNull public net.william278.husksync.player.OnlineUser getUser(@NotNull org.bukkit.entity.Player player)Returns aUser
instance for the given bukkitPlayer
.- Parameters:
player
- the bukkit player to get theUser
instance for- Returns:
- the
User
instance for the given bukkitPlayer
- Since:
- 2.0
-
setInventoryData
public CompletableFuture<Void> setInventoryData(@NotNull net.william278.husksync.player.User user, @NotNull org.bukkit.inventory.ItemStack[] inventoryContents)Set the inventory in the database of the givenUser
to the givenItemStack
contents- Parameters:
user
- theUser
to set the inventory ofinventoryContents
- theItemStack
contents to set the inventory to- Returns:
- future returning void when complete
- Since:
- 2.0
-
setInventoryData
public CompletableFuture<Void> setInventoryData(@NotNull net.william278.husksync.player.User user, @NotNull BukkitInventoryMap inventoryMap)Set the inventory in the database of the givenUser
to the givenBukkitInventoryMap
contents- Parameters:
user
- theUser
to set the inventory ofinventoryMap
- theBukkitInventoryMap
contents to set the inventory to- Returns:
- future returning void when complete
- Since:
- 2.0
-
setEnderChestData
public CompletableFuture<Void> setEnderChestData(@NotNull net.william278.husksync.player.User user, @NotNull org.bukkit.inventory.ItemStack[] enderChestContents)Set the Ender Chest in the database of the givenUser
to the givenItemStack
contents- Parameters:
user
- theUser
to set the Ender Chest ofenderChestContents
- theItemStack
contents to set the Ender Chest to- Returns:
- future returning void when complete
- Since:
- 2.0
-
getPlayerInventory
public CompletableFuture<Optional<BukkitInventoryMap>> getPlayerInventory(@NotNull net.william278.husksync.player.User user)Returns aBukkitInventoryMap
for the givenUser
, containing their current inventory item data- Parameters:
user
- theUser
to get theBukkitInventoryMap
for- Returns:
- future returning the
BukkitInventoryMap
for the givenUser
if they exist, otherwise an emptyOptional
- Since:
- 2.0
-
getPlayerEnderChest
public CompletableFuture<Optional<org.bukkit.inventory.ItemStack[]>> getPlayerEnderChest(@NotNull net.william278.husksync.player.User user)Returns theItemStack
s array contents of the givenUser
's Ender Chest data- Parameters:
user
- theUser
to get the Ender Chest contents of- Returns:
- future returning the
ItemStack
array of Ender Chest items for the user if they exist, otherwise an emptyOptional
- Since:
- 2.0
-
deserializeItemStackArray
public CompletableFuture<org.bukkit.inventory.ItemStack[]> deserializeItemStackArray(@NotNull String serializedItemStackArray) throws net.william278.husksync.data.DataSerializationExceptionDeserialize a Base-64 encoded inventory array string into aItemStack
array.- Parameters:
serializedItemStackArray
- The Base-64 encoded inventory array string.- Returns:
- The deserialized
ItemStack
array. - Throws:
net.william278.husksync.data.DataSerializationException
- If an error occurs during deserialization.- Since:
- 2.0
-
deserializeInventory
public CompletableFuture<BukkitInventoryMap> deserializeInventory(@NotNull String serializedInventory) throws net.william278.husksync.data.DataSerializationExceptionDeserialize a serializedItemStack
array of player inventory contents into aBukkitInventoryMap
- Parameters:
serializedInventory
- The serializedItemStack
array of player inventory contents.- Returns:
- A
BukkitInventoryMap
of the deserializedItemStack
contents array - Throws:
net.william278.husksync.data.DataSerializationException
- If an error occurs during deserialization.- Since:
- 2.0
-
serializeItemStackArray
public CompletableFuture<String> serializeItemStackArray(@NotNull org.bukkit.inventory.ItemStack[] itemStacks) throws net.william278.husksync.data.DataSerializationExceptionSerialize anItemStack
array into a Base-64 encoded string.- Parameters:
itemStacks
- TheItemStack
array to serialize.- Returns:
- The serialized Base-64 encoded string.
- Throws:
net.william278.husksync.data.DataSerializationException
- If an error occurs during serialization.- Since:
- 2.0
- See Also:
deserializeItemStackArray(String)
,ItemData
-
deserializePotionEffectArray
public CompletableFuture<org.bukkit.potion.PotionEffect[]> deserializePotionEffectArray(@NotNull String serializedPotionEffectArray) throws net.william278.husksync.data.DataSerializationExceptionDeserialize a Base-64 encoded potion effect array string into aPotionEffect
array.- Parameters:
serializedPotionEffectArray
- The Base-64 encoded potion effect array string.- Returns:
- The deserialized
PotionEffect
array. - Throws:
net.william278.husksync.data.DataSerializationException
- If an error occurs during deserialization.- Since:
- 2.0
-
serializePotionEffectArray
public CompletableFuture<String> serializePotionEffectArray(@NotNull org.bukkit.potion.PotionEffect[] potionEffects) throws net.william278.husksync.data.DataSerializationExceptionSerialize aPotionEffect
array into a Base-64 encoded string.- Parameters:
potionEffects
- ThePotionEffect
array to serialize.- Returns:
- The serialized Base-64 encoded string.
- Throws:
net.william278.husksync.data.DataSerializationException
- If an error occurs during serialization.- Since:
- 2.0
- See Also:
deserializePotionEffectArray(String)
,PotionEffectData
-