diff --git a/src/main/java/nl/pim16aap2/armoredElytra/handlers/SmithingTableListener.java b/src/main/java/nl/pim16aap2/armoredElytra/handlers/SmithingTableListener.java index 16804c5..2cafdaa 100644 --- a/src/main/java/nl/pim16aap2/armoredElytra/handlers/SmithingTableListener.java +++ b/src/main/java/nl/pim16aap2/armoredElytra/handlers/SmithingTableListener.java @@ -16,13 +16,13 @@ import java.util.logging.Level; abstract class SmithingTableListener extends ArmoredElytraHandler implements Listener { - public SmithingTableListener(ArmoredElytra plugin, boolean creationEnabled) + protected SmithingTableListener(ArmoredElytra plugin, boolean creationEnabled) { super(plugin, creationEnabled); } - public SmithingTableListener(ArmoredElytra plugin) + protected SmithingTableListener(ArmoredElytra plugin) { this(plugin, false); } @@ -39,12 +39,15 @@ abstract class SmithingTableListener extends ArmoredElytraHandler implements Lis if (newTier == ArmorTier.NONE) return; - EnchantmentContainer enchantments = EnchantmentContainer.getEnchantments(itemStackA, plugin); final Player player = (Player) event.getView().getPlayer(); final ItemStack result; if (plugin.playerHasCraftPerm(player, newTier)) { + + EnchantmentContainer enchantments = EnchantmentContainer.getEnchantments(itemStackA, plugin); + enchantments.merge(EnchantmentContainer.getEnchantments(itemStackB, plugin)); + result = ArmoredElytra.getInstance().getNbtEditor() .addArmorNBTTags(new ItemStack(Material.ELYTRA, 1), newTier, plugin.getConfigLoader().unbreakable()); diff --git a/src/main/java/nl/pim16aap2/armoredElytra/util/EnchantmentContainer.java b/src/main/java/nl/pim16aap2/armoredElytra/util/EnchantmentContainer.java index 3c41052..eecc127 100644 --- a/src/main/java/nl/pim16aap2/armoredElytra/util/EnchantmentContainer.java +++ b/src/main/java/nl/pim16aap2/armoredElytra/util/EnchantmentContainer.java @@ -7,6 +7,7 @@ import org.bukkit.inventory.ItemStack; import org.bukkit.inventory.meta.EnchantmentStorageMeta; import java.util.Collection; +import java.util.Collections; import java.util.HashMap; import java.util.Map; @@ -24,7 +25,7 @@ public class EnchantmentContainer public EnchantmentContainer(final Map enchantments, final ArmoredElytra plugin) { this(enchantments); - this.filter(plugin.getConfigLoader().allowedEnchantments()); + filter(plugin.getConfigLoader().allowedEnchantments()); } private EnchantmentContainer(final Map enchantments) @@ -41,6 +42,9 @@ public class EnchantmentContainer */ public static EnchantmentContainer getEnchantments(final ItemStack is, final ArmoredElytra plugin) { + if (is == null) + return new EnchantmentContainer(Collections.emptyMap(), plugin); + return is.getType() == Material.ENCHANTED_BOOK ? getEnchantmentsFromBook(is, plugin) : getEnchantmentsFromItem(is, plugin); @@ -113,7 +117,7 @@ public class EnchantmentContainer */ public void merge(EnchantmentContainer other) { - enchantments = merge(this.enchantments, other.enchantments); + enchantments = merge(enchantments, other.enchantments); } /**