Skip to content

Commit

Permalink
Fix potion meta serialisation
Browse files Browse the repository at this point in the history
  • Loading branch information
fullwall committed Jul 25, 2016
1 parent 349dca1 commit cb5cd12
Showing 1 changed file with 9 additions and 0 deletions.
9 changes: 9 additions & 0 deletions src/main/java/net/citizensnpcs/api/util/ItemStorage.java
Expand Up @@ -27,8 +27,10 @@
import org.bukkit.inventory.meta.PotionMeta;
import org.bukkit.inventory.meta.Repairable;
import org.bukkit.inventory.meta.SkullMeta;
import org.bukkit.potion.PotionData;
import org.bukkit.potion.PotionEffect;
import org.bukkit.potion.PotionEffectType;
import org.bukkit.potion.PotionType;

import com.google.common.collect.Lists;

Expand Down Expand Up @@ -170,6 +172,9 @@ private static void deserialiseMeta(DataKey root, ItemStack res) {

if (root.keyExists("potion")) {
PotionMeta meta = ensureMeta(res);
PotionData data = new PotionData(PotionType.valueOf(root.getString("potion.data.type")),
root.getBoolean("potion.data.extended"), root.getBoolean("potion.data.upgraded"));
meta.setBasePotionData(data);
for (DataKey sub : root.getRelative("potion.effects").getIntegerSubKeys()) {
int duration = sub.getInt("duration");
int amplifier = sub.getInt("amplifier");
Expand Down Expand Up @@ -365,7 +370,11 @@ private static void serialiseMeta(DataKey key, ItemMeta meta) {

if (meta instanceof PotionMeta) {
PotionMeta potion = (PotionMeta) meta;
PotionData data = potion.getBasePotionData();
List<PotionEffect> effects = potion.getCustomEffects();
key.setBoolean("potion.data.extended", data.isExtended());
key.setBoolean("potion.data.upgraded", data.isUpgraded());
key.setString("potion.data.type", data.getType().name());
key.removeKey("potion.effects");
DataKey effectKey = key.getRelative("potion.effects");
for (int i = 0; i < effects.size(); i++) {
Expand Down

0 comments on commit cb5cd12

Please sign in to comment.