From 5de81f06d6426c99a11d38c419b4735bb36a5bda Mon Sep 17 00:00:00 2001 From: William Date: Tue, 7 Jun 2022 23:16:05 +0100 Subject: [PATCH] Remove MPDB dependency requirement. Now uses a library I made. --- bukkit/build.gradle | 4 ++- .../bukkit/migrator/MPDBDeserializer.java | 33 ++++++------------- 2 files changed, 13 insertions(+), 24 deletions(-) diff --git a/bukkit/build.gradle b/bukkit/build.gradle index 75855dfa..40c5902b 100644 --- a/bukkit/build.gradle +++ b/bukkit/build.gradle @@ -3,8 +3,8 @@ dependencies { implementation 'org.bstats:bstats-bukkit:3.0.0' implementation 'de.themoep:minedown:1.7.1-SNAPSHOT' + implementation 'net.william278:mpdbdataconverter:1.0' - compileOnly 'net.craftersland.data:bridge:4.0.1' compileOnly 'org.spigotmc:spigot-api:1.16.5-R0.1-SNAPSHOT' compileOnly 'org.jetbrains:annotations:23.0.0' } @@ -14,4 +14,6 @@ shadowJar { relocate 'org.bstats', 'net.william278.husksync.libraries.bstats' relocate 'redis.clients', 'net.william278.husksync.libraries' relocate 'org.apache', 'net.william278.husksync.libraries' + relocate 'net.william278.mpdbdataconverter', 'net.william278.husksync.libraries.mpdbdataconverter' + } \ No newline at end of file diff --git a/bukkit/src/main/java/net/william278/husksync/bukkit/migrator/MPDBDeserializer.java b/bukkit/src/main/java/net/william278/husksync/bukkit/migrator/MPDBDeserializer.java index cdaa4a5e..3a7598ec 100644 --- a/bukkit/src/main/java/net/william278/husksync/bukkit/migrator/MPDBDeserializer.java +++ b/bukkit/src/main/java/net/william278/husksync/bukkit/migrator/MPDBDeserializer.java @@ -2,16 +2,16 @@ package net.william278.husksync.bukkit.migrator; import net.william278.husksync.HuskSyncBukkit; import net.william278.husksync.PlayerData; -import net.william278.husksync.bukkit.util.PlayerSetter; import net.william278.husksync.bukkit.data.DataSerializer; +import net.william278.husksync.bukkit.util.PlayerSetter; import net.william278.husksync.migrator.MPDBPlayerData; -import net.craftersland.data.bridge.PD; +import net.william278.mpdbconverter.MPDBConverter; import org.bukkit.Bukkit; import org.bukkit.event.inventory.InventoryType; import org.bukkit.inventory.Inventory; import org.bukkit.inventory.ItemStack; +import org.bukkit.plugin.Plugin; -import java.lang.reflect.InvocationTargetException; import java.util.logging.Level; public class MPDBDeserializer { @@ -19,10 +19,12 @@ public class MPDBDeserializer { private static final HuskSyncBukkit plugin = HuskSyncBukkit.getInstance(); // Instance of MySqlPlayerDataBridge - private static PD mySqlPlayerDataBridge; + private static MPDBConverter mpdbConverter; public static void setMySqlPlayerDataBridge() { - mySqlPlayerDataBridge = (PD) Bukkit.getPluginManager().getPlugin("MySqlPlayerDataBridge"); + Plugin mpdbPlugin = Bukkit.getPluginManager().getPlugin("MySqlPlayerDataBridge"); + assert mpdbPlugin != null; + mpdbConverter = MPDBConverter.getInstance(mpdbPlugin); } /** @@ -44,13 +46,13 @@ public class MPDBDeserializer { // Set inventory contents Inventory inventory = Bukkit.createInventory(null, InventoryType.PLAYER); if (!mpdbPlayerData.inventoryData.isEmpty() && !mpdbPlayerData.inventoryData.equalsIgnoreCase("none")) { - PlayerSetter.setInventory(inventory, getItemStackArrayFromMPDBBase64String(mpdbPlayerData.inventoryData)); + PlayerSetter.setInventory(inventory, mpdbConverter.getItemStackFromSerializedData(mpdbPlayerData.inventoryData)); } // Set armor (if there is data; MPDB stores empty data with literally the word "none". Obviously.) int armorSlot = 36; if (!mpdbPlayerData.armorData.isEmpty() && !mpdbPlayerData.armorData.equalsIgnoreCase("none")) { - ItemStack[] armorItems = getItemStackArrayFromMPDBBase64String(mpdbPlayerData.armorData); + ItemStack[] armorItems = mpdbConverter.getItemStackFromSerializedData(mpdbPlayerData.armorData); for (ItemStack armorPiece : armorItems) { if (armorPiece != null) { inventory.setItem(armorSlot, armorPiece); @@ -66,7 +68,7 @@ public class MPDBDeserializer { // Set ender chest (again, if there is data) ItemStack[] enderChestData; if (!mpdbPlayerData.enderChestData.isEmpty() && !mpdbPlayerData.enderChestData.equalsIgnoreCase("none")) { - enderChestData = getItemStackArrayFromMPDBBase64String(mpdbPlayerData.enderChestData); + enderChestData = mpdbConverter.getItemStackFromSerializedData(mpdbPlayerData.enderChestData); } else { enderChestData = new ItemStack[0]; } @@ -82,19 +84,4 @@ public class MPDBDeserializer { } return playerData; } - - /** - * Returns an ItemStack array from a decoded base 64 string in MySQLPlayerDataBridge's format - * - * @param data The encoded ItemStack[] string from MySQLPlayerDataBridge - * @return The {@link ItemStack[]} array - * @throws InvocationTargetException If an error occurs during decoding - * @throws IllegalAccessException If an error occurs during decoding - */ - public static ItemStack[] getItemStackArrayFromMPDBBase64String(String data) throws InvocationTargetException, IllegalAccessException { - if (data.isEmpty()) { - return new ItemStack[0]; - } - return mySqlPlayerDataBridge.getItemStackSerializer().fromBase64(data); - } }