.contains counts only 1 item in slot

Discussion in 'Spigot Plugin Development' started by Th3Wh1teG0d, Jan 8, 2020.

  1. Hello, im trying to check if the player has 1 or more specific item in his inventory but it only continues
    when the player has 1 item in one slot. Can anyone help me ?
  2. What exactly do you mean?
    if you did something like this:

    Code (Java):
    if (inventory.contains(new ItemStack(Material.WHATEVER)))
    it will try to match exactly the ItemStack, especially taking into account the count of items (in other words: 1)

    Do it like this:
    Code (Java):
    if (inventory.contains(Material.WHATEVER))
    and it will match the material only, not taking into account the count of items.
  3. I did this:

    Code (Java):

                                ItemStack ammoitem = new ItemStack(Material.SNOW_BALL);
                                ItemMeta ammometa = ammoitem.getItemMeta();
                                ammometa.setDisplayName("§8«§7Softair Munition§8»");
                                if (player.getInventory().contains(ammoitem)) {
  4. use ammoitem.getType()
  5. Ah, you want to check for the name too. In that case:
    Code (Java):
    int index;
    final Inventory inventory = player.getInventory()
    if ((index = inventory.first(Material.SNOWBALL)) > -1) {
        final ItemMeta meta = inventory.getItem(index).getItemMeta();
        if (meta != null && meta.getDisplayName().equals("§8«§7Softair Munition§8»")) {
            // code...
    • Winner Winner x 1
  6. Yeah i have got it with
    Code (Java):
     if (player.getInventory().contains(ammoitem.getType() )) {
    Thank You:)

    Edit: Oops have forgot to reload the page