From 5736abc6ba6b532a7fcc263b0801948c06187c70 Mon Sep 17 00:00:00 2001 From: William Date: Wed, 27 Oct 2021 22:42:31 +0100 Subject: [PATCH] Rename the class back to DataSerializer to prevent incompatibility with serialized 1.0.1 data --- ...yerSerializer.java => DataSerializer.java} | 24 +++++------ .../husksync/bukkit/data/DataViewer.java | 6 +-- .../bukkit/migrator/MPDBDeserializer.java | 6 +-- .../husksync/bukkit/util/PlayerSetter.java | 42 +++++++++---------- 4 files changed, 39 insertions(+), 39 deletions(-) rename bukkit/src/main/java/me/william278/husksync/bukkit/data/{PlayerSerializer.java => DataSerializer.java} (89%) diff --git a/bukkit/src/main/java/me/william278/husksync/bukkit/data/PlayerSerializer.java b/bukkit/src/main/java/me/william278/husksync/bukkit/data/DataSerializer.java similarity index 89% rename from bukkit/src/main/java/me/william278/husksync/bukkit/data/PlayerSerializer.java rename to bukkit/src/main/java/me/william278/husksync/bukkit/data/DataSerializer.java index 71e7b120..e93c4814 100644 --- a/bukkit/src/main/java/me/william278/husksync/bukkit/data/PlayerSerializer.java +++ b/bukkit/src/main/java/me/william278/husksync/bukkit/data/DataSerializer.java @@ -19,7 +19,7 @@ import java.io.Serializable; import java.util.*; import java.util.stream.Collectors; -public class PlayerSerializer { +public class DataSerializer { /** * Returns a serialized array of {@link ItemStack}s @@ -181,12 +181,12 @@ public class PlayerSerializer { return serializedPotionEffect != null ? new PotionEffect((Map) serializedPotionEffect) : null; } - public static PlayerSerializer.PlayerLocation deserializePlayerLocationData(String serializedLocationData) throws IOException { + public static DataSerializer.PlayerLocation deserializePlayerLocationData(String serializedLocationData) throws IOException { if (serializedLocationData.isEmpty()) { return null; } try { - return (PlayerSerializer.PlayerLocation) RedisMessage.deserialize(serializedLocationData); + return (DataSerializer.PlayerLocation) RedisMessage.deserialize(serializedLocationData); } catch (ClassNotFoundException e) { throw new IOException("Unable to decode class type.", e); } @@ -194,7 +194,7 @@ public class PlayerSerializer { public static String getSerializedLocation(Player player) throws IOException { final Location playerLocation = player.getLocation(); - return RedisMessage.serialize(new PlayerSerializer.PlayerLocation(playerLocation.getX(), playerLocation.getY(), playerLocation.getZ(), + return RedisMessage.serialize(new DataSerializer.PlayerLocation(playerLocation.getX(), playerLocation.getY(), playerLocation.getZ(), playerLocation.getYaw(), playerLocation.getPitch(), player.getWorld().getName(), player.getWorld().getEnvironment())); } @@ -203,12 +203,12 @@ public class PlayerSerializer { } @SuppressWarnings("unchecked") // Ignore the unchecked cast here - public static ArrayList deserializeAdvancementData(String serializedAdvancementData) throws IOException { + public static ArrayList deserializeAdvancementData(String serializedAdvancementData) throws IOException { if (serializedAdvancementData.isEmpty()) { return new ArrayList<>(); } try { - return (ArrayList) RedisMessage.deserialize(serializedAdvancementData); + return (ArrayList) RedisMessage.deserialize(serializedAdvancementData); } catch (ClassNotFoundException e) { throw new IOException("Unable to decode class type.", e); } @@ -216,13 +216,13 @@ public class PlayerSerializer { public static String getSerializedAdvancements(Player player) throws IOException { Iterator serverAdvancements = Bukkit.getServer().advancementIterator(); - ArrayList advancementData = new ArrayList<>(); + ArrayList advancementData = new ArrayList<>(); while (serverAdvancements.hasNext()) { final AdvancementProgress progress = player.getAdvancementProgress(serverAdvancements.next()); final NamespacedKey advancementKey = progress.getAdvancement().getKey(); final ArrayList awardedCriteria = new ArrayList<>(progress.getAwardedCriteria()); - advancementData.add(new PlayerSerializer.AdvancementRecord(advancementKey.getNamespace() + ":" + advancementKey.getKey(), awardedCriteria)); + advancementData.add(new DataSerializer.AdvancementRecord(advancementKey.getNamespace() + ":" + advancementKey.getKey(), awardedCriteria)); } return RedisMessage.serialize(advancementData); @@ -232,12 +232,12 @@ public class PlayerSerializer { ArrayList awardedAdvancementCriteria) implements Serializable { } - public static PlayerSerializer.StatisticData deserializeStatisticData(String serializedStatisticData) throws IOException { + public static DataSerializer.StatisticData deserializeStatisticData(String serializedStatisticData) throws IOException { if (serializedStatisticData.isEmpty()) { - return new PlayerSerializer.StatisticData(new HashMap<>(), new HashMap<>(), new HashMap<>(), new HashMap<>()); + return new DataSerializer.StatisticData(new HashMap<>(), new HashMap<>(), new HashMap<>(), new HashMap<>()); } try { - return (PlayerSerializer.StatisticData) RedisMessage.deserialize(serializedStatisticData); + return (DataSerializer.StatisticData) RedisMessage.deserialize(serializedStatisticData); } catch (ClassNotFoundException e) { throw new IOException("Unable to decode class type.", e); } @@ -275,7 +275,7 @@ public class PlayerSerializer { } } - PlayerSerializer.StatisticData statisticData = new PlayerSerializer.StatisticData(untypedStatisticValues, blockStatisticValues, itemStatisticValues, entityStatisticValues); + DataSerializer.StatisticData statisticData = new DataSerializer.StatisticData(untypedStatisticValues, blockStatisticValues, itemStatisticValues, entityStatisticValues); return RedisMessage.serialize(statisticData); } diff --git a/bukkit/src/main/java/me/william278/husksync/bukkit/data/DataViewer.java b/bukkit/src/main/java/me/william278/husksync/bukkit/data/DataViewer.java index 4074f5f2..ed0c9f1c 100644 --- a/bukkit/src/main/java/me/william278/husksync/bukkit/data/DataViewer.java +++ b/bukkit/src/main/java/me/william278/husksync/bukkit/data/DataViewer.java @@ -49,7 +49,7 @@ public class DataViewer { // Get and update the PlayerData with the new item data PlayerData playerData = dataView.playerData(); - String serializedItemData = PlayerSerializer.serializeInventory(inventory.getContents()); + String serializedItemData = DataSerializer.serializeInventory(inventory.getContents()); switch (dataView.inventoryType()) { case INVENTORY -> playerData.setSerializedInventory(serializedItemData); case ENDER_CHEST -> playerData.setSerializedEnderChest(serializedItemData); @@ -106,8 +106,8 @@ public class DataViewer { */ public ItemStack[] getDeserializedData() throws IOException, ClassNotFoundException { return switch (inventoryType) { - case INVENTORY -> PlayerSerializer.deserializeInventory(playerData.getSerializedInventory()); - case ENDER_CHEST -> PlayerSerializer.deserializeInventory(playerData.getSerializedEnderChest()); + case INVENTORY -> DataSerializer.deserializeInventory(playerData.getSerializedInventory()); + case ENDER_CHEST -> DataSerializer.deserializeInventory(playerData.getSerializedEnderChest()); }; } } diff --git a/bukkit/src/main/java/me/william278/husksync/bukkit/migrator/MPDBDeserializer.java b/bukkit/src/main/java/me/william278/husksync/bukkit/migrator/MPDBDeserializer.java index 807a6db3..f2709cf9 100644 --- a/bukkit/src/main/java/me/william278/husksync/bukkit/migrator/MPDBDeserializer.java +++ b/bukkit/src/main/java/me/william278/husksync/bukkit/migrator/MPDBDeserializer.java @@ -3,7 +3,7 @@ package me.william278.husksync.bukkit.migrator; import me.william278.husksync.HuskSyncBukkit; import me.william278.husksync.PlayerData; import me.william278.husksync.bukkit.util.PlayerSetter; -import me.william278.husksync.bukkit.data.PlayerSerializer; +import me.william278.husksync.bukkit.data.DataSerializer; import me.william278.husksync.migrator.MPDBPlayerData; import net.craftersland.data.bridge.PD; import org.bukkit.Bukkit; @@ -61,7 +61,7 @@ public class MPDBDeserializer { } // Now apply the contents and clear the temporary inventory variable - playerData.setSerializedInventory(PlayerSerializer.serializeInventory(inventory.getContents())); + playerData.setSerializedInventory(DataSerializer.serializeInventory(inventory.getContents())); // Set ender chest (again, if there is data) ItemStack[] enderChestData; @@ -70,7 +70,7 @@ public class MPDBDeserializer { } else { enderChestData = new ItemStack[0]; } - playerData.setSerializedEnderChest(PlayerSerializer.serializeInventory(enderChestData)); + playerData.setSerializedEnderChest(DataSerializer.serializeInventory(enderChestData)); // Set experience playerData.setExpLevel(mpdbPlayerData.expLevel); diff --git a/bukkit/src/main/java/me/william278/husksync/bukkit/util/PlayerSetter.java b/bukkit/src/main/java/me/william278/husksync/bukkit/util/PlayerSetter.java index 9bf2b7fc..c15e0e9d 100644 --- a/bukkit/src/main/java/me/william278/husksync/bukkit/util/PlayerSetter.java +++ b/bukkit/src/main/java/me/william278/husksync/bukkit/util/PlayerSetter.java @@ -5,7 +5,7 @@ import me.william278.husksync.PlayerData; import me.william278.husksync.Settings; import me.william278.husksync.api.events.SyncCompleteEvent; import me.william278.husksync.api.events.SyncEvent; -import me.william278.husksync.bukkit.data.PlayerSerializer; +import me.william278.husksync.bukkit.data.DataSerializer; import me.william278.husksync.redis.RedisMessage; import org.bukkit.*; import org.bukkit.advancement.Advancement; @@ -37,8 +37,8 @@ public class PlayerSetter { */ private static String getNewSerializedPlayerData(Player player) throws IOException { return RedisMessage.serialize(new PlayerData(player.getUniqueId(), - PlayerSerializer.serializeInventory(player.getInventory().getContents()), - PlayerSerializer.serializeInventory(player.getEnderChest().getContents()), + DataSerializer.serializeInventory(player.getInventory().getContents()), + DataSerializer.serializeInventory(player.getEnderChest().getContents()), player.getHealth(), Objects.requireNonNull(player.getAttribute(Attribute.GENERIC_MAX_HEALTH)).getBaseValue(), player.getHealthScale(), @@ -46,15 +46,15 @@ public class PlayerSetter { player.getSaturation(), player.getExhaustion(), player.getInventory().getHeldItemSlot(), - PlayerSerializer.serializePotionEffects(getPlayerPotionEffects(player)), + DataSerializer.serializePotionEffects(getPlayerPotionEffects(player)), player.getTotalExperience(), player.getLevel(), player.getExp(), player.getGameMode().toString(), - PlayerSerializer.getSerializedStatisticData(player), + DataSerializer.getSerializedStatisticData(player), player.isFlying(), - PlayerSerializer.getSerializedAdvancements(player), - PlayerSerializer.getSerializedLocation(player))); + DataSerializer.getSerializedAdvancements(player), + DataSerializer.getSerializedLocation(player))); } /** @@ -139,14 +139,14 @@ public class PlayerSetter { // Set the player's data from the PlayerData try { if (Settings.syncAdvancements) { - setPlayerAdvancements(player, PlayerSerializer.deserializeAdvancementData(data.getSerializedAdvancements()), data); + setPlayerAdvancements(player, DataSerializer.deserializeAdvancementData(data.getSerializedAdvancements()), data); } if (Settings.syncInventories) { - setPlayerInventory(player, PlayerSerializer.deserializeInventory(data.getSerializedInventory())); + setPlayerInventory(player, DataSerializer.deserializeInventory(data.getSerializedInventory())); player.getInventory().setHeldItemSlot(data.getSelectedSlot()); } if (Settings.syncEnderChests) { - setPlayerEnderChest(player, PlayerSerializer.deserializeInventory(data.getSerializedEnderChest())); + setPlayerEnderChest(player, DataSerializer.deserializeInventory(data.getSerializedEnderChest())); } if (Settings.syncHealth) { player.setHealthScale(data.getHealthScale() <= 0 ? data.getHealthScale() : 20D); @@ -163,17 +163,17 @@ public class PlayerSetter { setPlayerExperience(player, data); } if (Settings.syncPotionEffects) { - setPlayerPotionEffects(player, PlayerSerializer.deserializePotionEffects(data.getSerializedEffectData())); + setPlayerPotionEffects(player, DataSerializer.deserializePotionEffects(data.getSerializedEffectData())); } if (Settings.syncStatistics) { - setPlayerStatistics(player, PlayerSerializer.deserializeStatisticData(data.getSerializedStatistics())); + setPlayerStatistics(player, DataSerializer.deserializeStatisticData(data.getSerializedStatistics())); } if (Settings.syncGameMode) { player.setGameMode(GameMode.valueOf(data.getGameMode())); } if (Settings.syncLocation) { player.setFlying(player.getAllowFlight() && data.isFlying()); - setPlayerLocation(player, PlayerSerializer.deserializePlayerLocationData(data.getSerializedLocation())); + setPlayerLocation(player, DataSerializer.deserializePlayerLocationData(data.getSerializedLocation())); } // Handle the SyncCompleteEvent @@ -240,9 +240,9 @@ public class PlayerSetter { * Update a player's advancements and progress to match the advancementData * * @param player The player to set the advancements of - * @param advancementData The ArrayList of {@link PlayerSerializer.AdvancementRecord}s to set + * @param advancementData The ArrayList of {@link DataSerializer.AdvancementRecord}s to set */ - private static void setPlayerAdvancements(Player player, ArrayList advancementData, PlayerData data) { + private static void setPlayerAdvancements(Player player, ArrayList advancementData, PlayerData data) { // Temporarily disable advancement announcing if needed boolean announceAdvancementUpdate = false; if (Boolean.TRUE.equals(player.getWorld().getGameRuleValue(GameRule.ANNOUNCE_ADVANCEMENTS))) { @@ -260,7 +260,7 @@ public class PlayerSetter { boolean correctExperienceCheck = false; // Determines whether the experience might have changed warranting an update Advancement advancement = serverAdvancements.next(); AdvancementProgress playerProgress = player.getAdvancementProgress(advancement); - for (PlayerSerializer.AdvancementRecord record : advancementData) { + for (DataSerializer.AdvancementRecord record : advancementData) { // If the advancement is one on the data if (record.advancementKey().equals(advancement.getKey().getNamespace() + ":" + advancement.getKey().getKey())) { @@ -303,9 +303,9 @@ public class PlayerSetter { * Set a player's statistics (in the Statistic menu) * * @param player The player to set the statistics of - * @param statisticData The {@link PlayerSerializer.StatisticData} to set + * @param statisticData The {@link DataSerializer.StatisticData} to set */ - private static void setPlayerStatistics(Player player, PlayerSerializer.StatisticData statisticData) { + private static void setPlayerStatistics(Player player, DataSerializer.StatisticData statisticData) { // Set untyped statistics for (Statistic statistic : statisticData.untypedStatisticValues().keySet()) { player.setStatistic(statistic, statisticData.untypedStatisticValues().get(statistic)); @@ -346,12 +346,12 @@ public class PlayerSetter { } /** - * Set a player's location from {@link PlayerSerializer.PlayerLocation} data + * Set a player's location from {@link DataSerializer.PlayerLocation} data * * @param player The {@link Player} to teleport - * @param location The {@link PlayerSerializer.PlayerLocation} + * @param location The {@link DataSerializer.PlayerLocation} */ - private static void setPlayerLocation(Player player, PlayerSerializer.PlayerLocation location) { + private static void setPlayerLocation(Player player, DataSerializer.PlayerLocation location) { // Don't teleport if the location is invalid if (location == null) { return;