From d94c120f978d4827986c4c392ef13742e5458071 Mon Sep 17 00:00:00 2001 From: Daniel V Date: Fri, 2 Aug 2024 21:03:38 -0400 Subject: [PATCH] Fixes for potiondata 1.21 --- Bukkit/pom.xml | 4 +- BukkitBase/pom.xml | 4 +- .../bukkitbase/data/BukkitPotionData.java | 34 +++++++++++++--- Core/pom.xml | 2 +- .../net/tnemc/item/data/SerialPotionData.java | 39 +++++++++++++------ Paper/pom.xml | 4 +- TNIL-Sponge/pom.xml | 4 +- TNIL-Sponge7/pom.xml | 4 +- pom.xml | 2 +- 9 files changed, 68 insertions(+), 29 deletions(-) diff --git a/Bukkit/pom.xml b/Bukkit/pom.xml index f39a448..52ab7e4 100644 --- a/Bukkit/pom.xml +++ b/Bukkit/pom.xml @@ -7,7 +7,7 @@ net.tnemc TNIL - 0.1.7.6-Pre-12 + 0.1.7.6-Pre-122 ../pom.xml @@ -107,7 +107,7 @@ net.tnemc TNIL-BukkitBase - 0.1.7.6-Pre-12 + 0.1.7.6-Pre-122 compile diff --git a/BukkitBase/pom.xml b/BukkitBase/pom.xml index 7e7d157..7296342 100644 --- a/BukkitBase/pom.xml +++ b/BukkitBase/pom.xml @@ -7,7 +7,7 @@ net.tnemc TNIL - 0.1.7.6-Pre-12 + 0.1.7.6-Pre-122 ../pom.xml @@ -101,7 +101,7 @@ net.tnemc TNIL-Core - 0.1.7.6-Pre-12 + 0.1.7.6-Pre-122 compile diff --git a/BukkitBase/src/net/tnemc/item/bukkitbase/data/BukkitPotionData.java b/BukkitBase/src/net/tnemc/item/bukkitbase/data/BukkitPotionData.java index efe011e..933aa7c 100644 --- a/BukkitBase/src/net/tnemc/item/bukkitbase/data/BukkitPotionData.java +++ b/BukkitBase/src/net/tnemc/item/bukkitbase/data/BukkitPotionData.java @@ -25,6 +25,8 @@ import net.tnemc.item.data.SerialPotionData; import net.tnemc.item.data.potion.PotionEffectData; import org.bukkit.Color; +import org.bukkit.NamespacedKey; +import org.bukkit.Registry; import org.bukkit.inventory.ItemStack; import org.bukkit.inventory.meta.PotionMeta; import org.bukkit.potion.PotionData; @@ -47,9 +49,23 @@ public void of(ItemStack stack) { if(meta != null) { if(meta.hasColor()) colorRGB = meta.getColor().asRGB(); - type = meta.getBasePotionData().getType().name(); - extended = meta.getBasePotionData().isExtended(); - upgraded = meta.getBasePotionData().isUpgraded(); + + try { + + if(meta.hasBasePotionType()) { + updated = true; + type = meta.getBasePotionType().getKey().getKey(); + extended = meta.getBasePotionType().isExtendable(); + upgraded = meta.getBasePotionType().isUpgradeable(); + } + + } catch(Exception ignore) { + if(meta.getBasePotionData() != null) { + type = meta.getBasePotionData().getType().name(); + extended = meta.getBasePotionData().isExtended(); + upgraded = meta.getBasePotionData().isUpgraded(); + } + } for(final PotionEffect effect : meta.getCustomEffects()) { @@ -82,8 +98,16 @@ public ItemStack apply(ItemStack stack) { effect.isAmbient(), effect.hasParticles(), effect.hasIcon()), true)); - final PotionData data = new PotionData(PotionType.valueOf(type), extended, upgraded); - meta.setBasePotionData(data); + + if(updated) { + try { + final PotionType potionType = Registry.POTION.get(NamespacedKey.fromString(type)); + meta.setBasePotionType(potionType); + } catch(Exception ignore) {} + } else { + final PotionData data = new PotionData(PotionType.valueOf(type), extended, upgraded); + meta.setBasePotionData(data); + } stack.setItemMeta(meta); return stack; } diff --git a/Core/pom.xml b/Core/pom.xml index 56043cf..2bab3c9 100644 --- a/Core/pom.xml +++ b/Core/pom.xml @@ -7,7 +7,7 @@ net.tnemc TNIL - 0.1.7.6-Pre-12 + 0.1.7.6-Pre-122 ../pom.xml diff --git a/Core/src/net/tnemc/item/data/SerialPotionData.java b/Core/src/net/tnemc/item/data/SerialPotionData.java index d6e4b40..78965a1 100644 --- a/Core/src/net/tnemc/item/data/SerialPotionData.java +++ b/Core/src/net/tnemc/item/data/SerialPotionData.java @@ -31,10 +31,11 @@ public abstract class SerialPotionData implements SerialItemData { protected final List customEffects = new ArrayList<>(); - protected String type; + protected String type = null; protected int colorRGB = -1; protected boolean extended; protected boolean upgraded; + protected boolean updated = false; //magic value for bukkit fuckiness /** * Converts the {@link SerialItemData} to a JSON object. @@ -45,12 +46,16 @@ public abstract class SerialPotionData implements SerialItemData { public JSONObject toJSON() { final JSONObject json = new JSONObject(); json.put("name", "potion"); - json.put("type", type); if(colorRGB != -1) json.put("colour", colorRGB); - json.put("extended", extended); - json.put("upgraded", upgraded); - if(customEffects.size() > 0) { + if(type != null) { + json.put("type", type); + json.put("updated", updated); + json.put("extended", extended); + json.put("upgraded", upgraded); + } + + if(!customEffects.isEmpty()) { final JSONObject effects = new JSONObject(); for(PotionEffectData effect : customEffects) { @@ -68,11 +73,17 @@ public JSONObject toJSON() { */ @Override public void readJSON(JSONHelper json) { - type = json.getString("type"); - if(json.has("colour")) colorRGB = json.getInteger("colour"); - extended = json.getBoolean("extended"); - upgraded = json.getBoolean("upgraded"); + + if(json.has("type")) { + type = json.getString("type"); + extended = json.getBoolean("extended"); + upgraded = json.getBoolean("upgraded"); + + if(json.has("updated")) { + updated = json.getBoolean("updated"); + } + } if(json.has("effects")) { final JSONHelper effects = json.getHelper("effects"); @@ -94,9 +105,13 @@ public void readJSON(JSONHelper json) { @Override public boolean equals(SerialItemData data) { if(data instanceof SerialPotionData compare) { - return customEffects.equals(compare.customEffects) && type.equalsIgnoreCase(compare.type) - && colorRGB == compare.colorRGB && extended == compare.extended - && upgraded == compare.upgraded; + + if(type != null) { + return customEffects.equals(compare.customEffects) && type.equalsIgnoreCase(compare.type) + && colorRGB == compare.colorRGB && extended == compare.extended + && upgraded == compare.upgraded; + } + return customEffects.equals(compare.customEffects) && colorRGB == compare.colorRGB; } return false; } diff --git a/Paper/pom.xml b/Paper/pom.xml index e76e42b..10b7606 100644 --- a/Paper/pom.xml +++ b/Paper/pom.xml @@ -7,7 +7,7 @@ net.tnemc TNIL - 0.1.7.6-Pre-12 + 0.1.7.6-Pre-122 ../pom.xml @@ -108,7 +108,7 @@ net.tnemc TNIL-BukkitBase - 0.1.7.6-Pre-12 + 0.1.7.6-Pre-122 compile diff --git a/TNIL-Sponge/pom.xml b/TNIL-Sponge/pom.xml index 2ea7c7c..4dc9d14 100644 --- a/TNIL-Sponge/pom.xml +++ b/TNIL-Sponge/pom.xml @@ -5,7 +5,7 @@ TNIL net.tnemc - 0.1.7.6-Pre-12 + 0.1.7.6-Pre-122 4.0.0 @@ -105,7 +105,7 @@ net.tnemc TNIL-Core - 0.1.7.6-Pre-12 + 0.1.7.6-Pre-122 compile diff --git a/TNIL-Sponge7/pom.xml b/TNIL-Sponge7/pom.xml index 408470e..6cb528b 100644 --- a/TNIL-Sponge7/pom.xml +++ b/TNIL-Sponge7/pom.xml @@ -5,7 +5,7 @@ TNIL net.tnemc - 0.1.7.6-Pre-12 + 0.1.7.6-Pre-122 4.0.0 @@ -56,7 +56,7 @@ net.tnemc TNIL-Core - 0.1.7.6-Pre-12 + 0.1.7.6-Pre-122 compile diff --git a/pom.xml b/pom.xml index 78821ed..5654311 100644 --- a/pom.xml +++ b/pom.xml @@ -2,7 +2,7 @@ 4.0.0 net.tnemc TNIL - 0.1.7.6-Pre-12 + 0.1.7.6-Pre-122 pom The New Item Library