Help with ItemStack

Discussion in 'Plugin Development' started by ewrs, Jun 27, 2018.

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

    ewrs

    Hello everybody! I have a question for you. How to make sure that if the player in the inventory has even 64 things, the event happened?
    The thing is, if getItem (). Equals ((ItemStack) in the player in inventory 1, everything works, if more than 1, then he waits until the player eats the last meal. I will give you my code.

    Sorry for my english, he's not the best. I started programming recently, and maybe this question is boring.

    My Code:


    ItemStack Bread = new ItemStack(Material.BREAD);
    ItemMeta meta = Bread.getItemMeta();
    meta.setDisplayName("§f§lTest");
    List<String> lore = new ArrayList<String>();
    lore.add("§eTest");
    meta.setLore(lore);
    Bread.setItemMeta(meta);
    if(e.getItem().equals((Bread))) {
    //TEST
    }
     
  2. Offline

    CommonSenze

    @ewrs
    By checking if an item that is already made is equal to an item that you just created that if statement will never be called.
     
  3. Offline

    MightyOne

    @CommonSenze I think if he already states that it works with a stacksize of 1 then .equals() already fullfills it's purpose.

    @ewrs equals() qill check if all variables of both items are set to equal values. That way you are checking if the player has exactly 1 bread in their inventory. Use ItemStack#isSimilar() to ignore the stack size
     
  4. Offline

    CommonSenze

Thread Status:
Not open for further replies.

Share This Page