I am trying to change the name of an item before it is crafted. The first time the event runs it works, but after that, the if statement is not executed. There are no errors. Code: @EventHandler public void onCraftView(PrepareItemCraftEvent e) { for(ItemStack x : swords) { if(e.getInventory().getResult().equals(x)) { ItemStack z = x; ItemMeta i = x.getItemMeta(); Random r = new Random(); int c = r.nextInt(9) + 1; i.setDisplayName("ยง" + c + ChatColor.BOLD.toString() + "??????? | Unknown"); z.setItemMeta(i); e.getInventory().setResult(z); } } }
I would recommend to use isSimilar instead equals in the if statement. isSimilar checks the attributes of the items, and I think equals checks if the instance is the same.
@Bram0101 The documentation for .equals checks if the stack and amount are the same. The instance has nothing to do with .equals(), typically, just with ==