Checking Size + Material in Hand

Discussion in 'Plugin Development' started by iWareWolf, Jan 17, 2013.

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

    iWareWolf

    I am currently trying to check the Size + Material in my hand and remove it if it is true. It doesn't seem to work.
    Code:
                        ItemStack item = player.getInventory().getItemInHand();
                        int size = item.getAmount();
                        if(item == new ItemStack(new ItemStack(367)) && size == 30){
                            player.getInventory().removeItem(new ItemStack(367, 30));
                            magicApi.setMageLevel(player, 20);
                        }
                        else{
                            player.sendMessage(ChatColor.RED + "You need 30 Rotten Flesh to recharge your mana!");
                        }
     
  2. Offline

    CubixCoders

    Try debug messages
     
  3. Offline

    fireblast709

    don't compare ItemStacks with ==. Use .equals() if they have the same ItemMeta
     
  4. Offline

    iWareWolf

    fireblast709
    if(item.equals(Material.ROTTEN_FLESH) && size == 30){
    ?
    Edit: It still does not work.
     
  5. Offline

    fireblast709

    stack1.equals(stack2) is what I ment. It even checks if the ItemMeta is the same
     
  6. Offline

    iWareWolf

    Do you mean this?
    Code:
                        ItemStack item = player.getInventory().getItemInHand();
                        ItemStack rotten = new ItemStack(367, 30);
                        if(item.equals(rotten)){
                            player.getInventory().removeItem(new ItemStack(367, 30));
                            magicApi.setMageLevel(player, 20);
                        }
    It still doesn't work.

    fireblast709 ^

    EDIT by Moderator: merged posts, please use the edit button instead of double posting.
     
    Last edited by a moderator: May 30, 2016
  7. Offline

    CubixCoders

    Add a test message to see if it's being run right before you make the ItemStacks
     
  8. Offline

    iWareWolf

    CubixCoders
    It does run correct because it keeps doing this
    else{
    player.sendMessage(ChatColor.RED + "You need 30 Rotten Flesh to recharge your mana!");
    }
     
  9. Offline

    CubixCoders

    Okay, then the problem is the itemstacks arn't matching up
     
  10. Offline

    iWareWolf

    CubixCoders
    I rightclick the sign with 30 rotten flesh in my hand, but it doesn't work.
     
  11. Offline

    H2NCH2COOH

    item.getTypeId()==367
     
  12. Offline

    iWareWolf

    Thank you.
     
Thread Status:
Not open for further replies.

Share This Page