Fix enchantments in smithing table crafting

- Enchantments on the second item in the smithing table were not taken into account for the end result.
This commit is contained in:
Pim van der Loos 2021-04-29 19:50:53 +02:00
parent 73ad900387
commit bea45dde30
No known key found for this signature in database
GPG Key ID: C16F020ADAE6D5A8
2 changed files with 12 additions and 5 deletions

View File

@ -16,13 +16,13 @@ import java.util.logging.Level;
abstract class SmithingTableListener extends ArmoredElytraHandler implements Listener abstract class SmithingTableListener extends ArmoredElytraHandler implements Listener
{ {
public SmithingTableListener(ArmoredElytra plugin, boolean creationEnabled) protected SmithingTableListener(ArmoredElytra plugin, boolean creationEnabled)
{ {
super(plugin, creationEnabled); super(plugin, creationEnabled);
} }
public SmithingTableListener(ArmoredElytra plugin) protected SmithingTableListener(ArmoredElytra plugin)
{ {
this(plugin, false); this(plugin, false);
} }
@ -39,12 +39,15 @@ abstract class SmithingTableListener extends ArmoredElytraHandler implements Lis
if (newTier == ArmorTier.NONE) if (newTier == ArmorTier.NONE)
return; return;
EnchantmentContainer enchantments = EnchantmentContainer.getEnchantments(itemStackA, plugin);
final Player player = (Player) event.getView().getPlayer(); final Player player = (Player) event.getView().getPlayer();
final ItemStack result; final ItemStack result;
if (plugin.playerHasCraftPerm(player, newTier)) if (plugin.playerHasCraftPerm(player, newTier))
{ {
EnchantmentContainer enchantments = EnchantmentContainer.getEnchantments(itemStackA, plugin);
enchantments.merge(EnchantmentContainer.getEnchantments(itemStackB, plugin));
result = ArmoredElytra.getInstance().getNbtEditor() result = ArmoredElytra.getInstance().getNbtEditor()
.addArmorNBTTags(new ItemStack(Material.ELYTRA, 1), newTier, .addArmorNBTTags(new ItemStack(Material.ELYTRA, 1), newTier,
plugin.getConfigLoader().unbreakable()); plugin.getConfigLoader().unbreakable());

View File

@ -7,6 +7,7 @@ import org.bukkit.inventory.ItemStack;
import org.bukkit.inventory.meta.EnchantmentStorageMeta; import org.bukkit.inventory.meta.EnchantmentStorageMeta;
import java.util.Collection; import java.util.Collection;
import java.util.Collections;
import java.util.HashMap; import java.util.HashMap;
import java.util.Map; import java.util.Map;
@ -24,7 +25,7 @@ public class EnchantmentContainer
public EnchantmentContainer(final Map<Enchantment, Integer> enchantments, final ArmoredElytra plugin) public EnchantmentContainer(final Map<Enchantment, Integer> enchantments, final ArmoredElytra plugin)
{ {
this(enchantments); this(enchantments);
this.filter(plugin.getConfigLoader().allowedEnchantments()); filter(plugin.getConfigLoader().allowedEnchantments());
} }
private EnchantmentContainer(final Map<Enchantment, Integer> enchantments) private EnchantmentContainer(final Map<Enchantment, Integer> enchantments)
@ -41,6 +42,9 @@ public class EnchantmentContainer
*/ */
public static EnchantmentContainer getEnchantments(final ItemStack is, final ArmoredElytra plugin) 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 ? return is.getType() == Material.ENCHANTED_BOOK ?
getEnchantmentsFromBook(is, plugin) : getEnchantmentsFromBook(is, plugin) :
getEnchantmentsFromItem(is, plugin); getEnchantmentsFromItem(is, plugin);
@ -113,7 +117,7 @@ public class EnchantmentContainer
*/ */
public void merge(EnchantmentContainer other) public void merge(EnchantmentContainer other)
{ {
enchantments = merge(this.enchantments, other.enchantments); enchantments = merge(enchantments, other.enchantments);
} }
/** /**