Solved Broken Event

Discussion in 'Plugin Development' started by 277772, Jun 27, 2015.

Thread Status:
Not open for further replies.
  1. Offline

    277772

    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);
                }
            }
        }
     
  2. 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.
     
  3. Offline

    Drkmaster83

    @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 ==
     
  4. Offline

    277772

Thread Status:
Not open for further replies.

Share This Page