-
Bug
-
Resolution: Fixed
-
Minor
-
None
-
None
-
None
-
4242-Spigot-0a642bd-515fe49 (MC: 1.21) (Implementing API version 1.21-R0.1-SNAPSHOT)
-
Yes
Hello there,
I have run into an issue with the containsValue method for my HashMap. It seems to have broke after 3763-Spigot-7d7b241-5a5e43e (MC: 1.19.4).
The following boolean "giveRecipe.containsValue(inv.getResult())" below returns true in 1.19.4 and prior versions; however, returns false in the newer versions.
The HashMap contains the ItemStack that is showing in the inventory result in all versions tested, yet produces a different boolean result in 1.20 & 1.21.
https://www.spigotmc.org/threads/hashmap-help.664547
The culprit:
im.addItemFlags(ItemFlag.HIDE_ENCHANTS);
The code:
public class Main extends JavaPlugin implements Listener { HashMap<String, ItemStack> giveRecipe = new HashMap<String, ItemStack>(); @Override public void onEnable() { Bukkit.clearRecipes(); addItems(); Bukkit.getPluginManager().registerEvents(this, this); getLogger().log(Level.INFO, "Loaded " + giveRecipe.values().size() + " recipes."); } public void addItems() { ItemStack sword = new ItemStack(Material.DIAMOND); ItemMeta im = sword.getItemMeta(); im.setDisplayName("Enchanted Diamond"); im.addItemFlags(ItemFlag.HIDE_ENCHANTS); sword.setItemMeta(im); NamespacedKey key = new NamespacedKey(this, "EnchantedDiamond"); ShapedRecipe recipe = new ShapedRecipe(key, sword); recipe.shape(" E ", "EEE", " E "); recipe.setIngredient('E', Material.DIAMOND); Bukkit.getServer().addRecipe(recipe); giveRecipe.put("test", sword); } @EventHandler void handleShiftClicks(CraftItemEvent e) { CraftingInventory inv = e.getInventory(); e.getWhoClicked() .sendMessage("[Debug] Boolean Result: " + String.valueOf(giveRecipe.containsValue(inv.getResult()))); } }