Slight cleanup and docs updating

feat/data-edit-commands 1.3
William 3 years ago
parent 84e04a6440
commit 93f6417471

@ -164,7 +164,7 @@ To fetch PlayerData from a UUID as you need it, create an instance of the HuskSy
HuskSyncAPI huskSyncApi = HuskSyncAPI.getInstance();
try {
CompletableFuture<PlayerData> playerDataCompletableFuture = huskSyncApi.getPlayerData(playerUUID);
// thenAccept blocks the main thread until HuskSync has grabbed the data, so you may wish to run this asynchronously.
// thenAccept blocks the thread until HuskSync has grabbed the data, so you may wish to run this asynchronously (e.g. Bukkit.getScheduler().runTaskAsynchronously(plugin, () -> {});.
playerDataCompletableFuture.thenAccept(playerData -> {
// You now have a PlayerData object which you can get serialized data from and deserialize with the DataSerializer static methods
});

@ -44,17 +44,19 @@ public class HuskSyncAPI {
* @throws IOException If an exception occurs with serializing during processing of the request
*/
public CompletableFuture<PlayerData> getPlayerData(UUID playerUUID) throws IOException {
// Create the request to be completed
final UUID requestUUID = UUID.randomUUID();
CompletableFuture<PlayerData> playerDataCompletableFuture = new CompletableFuture<>();
playerDataCompletableFuture.whenComplete((playerData, throwable) -> apiRequests.remove(requestUUID));
apiRequests.put(requestUUID, new CompletableFuture<>());
// Remove the request from the map on completion
apiRequests.get(requestUUID).whenComplete((playerData, throwable) -> apiRequests.remove(requestUUID));
// Request the data via the proxy
new RedisMessage(RedisMessage.MessageType.API_DATA_REQUEST,
new RedisMessage.MessageTarget(Settings.ServerType.PROXY, null, Settings.cluster),
playerUUID.toString(), requestUUID.toString()).send();
apiRequests.put(requestUUID, playerDataCompletableFuture);
return playerDataCompletableFuture;
return apiRequests.get(requestUUID);
}
/**
@ -64,6 +66,7 @@ public class HuskSyncAPI {
* @throws IOException If an exception occurs with serializing during processing of the update
*/
public void updatePlayerData(PlayerData playerData) throws IOException {
// Serialize and send the updated player data
final String serializedPlayerData = RedisMessage.serialize(playerData);
new RedisMessage(RedisMessage.MessageType.PLAYER_DATA_UPDATE,
new RedisMessage.MessageTarget(Settings.ServerType.PROXY, null, Settings.cluster),

@ -56,7 +56,7 @@ public class DataSerializer {
}
/**
* Returns an array of ItemStacks from serialized inventory data
* Returns an array of ItemStacks from serialized inventory data. Note: empty slots will be represented by {@code null}
*
* @param inventoryData The serialized {@link ItemStack[]} array
* @return The inventory contents as an array of {@link ItemStack}s

Loading…
Cancel
Save