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(); HuskSyncAPI huskSyncApi = HuskSyncAPI.getInstance();
try { try {
CompletableFuture<PlayerData> playerDataCompletableFuture = huskSyncApi.getPlayerData(playerUUID); 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 -> { playerDataCompletableFuture.thenAccept(playerData -> {
// You now have a PlayerData object which you can get serialized data from and deserialize with the DataSerializer static methods // 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 * @throws IOException If an exception occurs with serializing during processing of the request
*/ */
public CompletableFuture<PlayerData> getPlayerData(UUID playerUUID) throws IOException { public CompletableFuture<PlayerData> getPlayerData(UUID playerUUID) throws IOException {
// Create the request to be completed
final UUID requestUUID = UUID.randomUUID(); final UUID requestUUID = UUID.randomUUID();
CompletableFuture<PlayerData> playerDataCompletableFuture = new CompletableFuture<>(); apiRequests.put(requestUUID, new CompletableFuture<>());
playerDataCompletableFuture.whenComplete((playerData, throwable) -> apiRequests.remove(requestUUID));
// Remove the request from the map on completion
apiRequests.get(requestUUID).whenComplete((playerData, throwable) -> apiRequests.remove(requestUUID));
// Request the data via the proxy // Request the data via the proxy
new RedisMessage(RedisMessage.MessageType.API_DATA_REQUEST, new RedisMessage(RedisMessage.MessageType.API_DATA_REQUEST,
new RedisMessage.MessageTarget(Settings.ServerType.PROXY, null, Settings.cluster), new RedisMessage.MessageTarget(Settings.ServerType.PROXY, null, Settings.cluster),
playerUUID.toString(), requestUUID.toString()).send(); playerUUID.toString(), requestUUID.toString()).send();
apiRequests.put(requestUUID, playerDataCompletableFuture); return apiRequests.get(requestUUID);
return playerDataCompletableFuture;
} }
/** /**
@ -64,6 +66,7 @@ public class HuskSyncAPI {
* @throws IOException If an exception occurs with serializing during processing of the update * @throws IOException If an exception occurs with serializing during processing of the update
*/ */
public void updatePlayerData(PlayerData playerData) throws IOException { public void updatePlayerData(PlayerData playerData) throws IOException {
// Serialize and send the updated player data
final String serializedPlayerData = RedisMessage.serialize(playerData); final String serializedPlayerData = RedisMessage.serialize(playerData);
new RedisMessage(RedisMessage.MessageType.PLAYER_DATA_UPDATE, new RedisMessage(RedisMessage.MessageType.PLAYER_DATA_UPDATE,
new RedisMessage.MessageTarget(Settings.ServerType.PROXY, null, Settings.cluster), 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 * @param inventoryData The serialized {@link ItemStack[]} array
* @return The inventory contents as an array of {@link ItemStack}s * @return The inventory contents as an array of {@link ItemStack}s

Loading…
Cancel
Save