Potions (1.9)

Discussion in 'Plugin Development' started by Koningpeter, Apr 26, 2016.

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

    Koningpeter

    Hey all
    I've a problem with potions...
    I want to get the type of the potion out the inventory of the player.

    This is what I tried:
    Code:
            for(int i = 0; i < Player.getInventory().getSize(); i++)
            {
                ItemStack is = Player.getInventory().getItem(i);
                if(is != null)
                {
                    if(is.getTypeId() == 373){
                        String p1 = Potion.fromItemStack(is).getType().name();
                           System.out.println(p1);
                    }
                }
            }
    But this says always that the potion is water....
    Does anyone know how to fix this?
     
  2. Offline

    mcdorli

    Potions all have the same type, only they're id are different, you need to check for ItemStack#getData()
     
  3. Offline

    Koningpeter

    @mcdorli
    No that doesn't work....
    Now it always says: POTION(0)

    Code:
            for(int i = 0; i < Player.getInventory().getSize(); i++)
            {
                ItemStack is = Player.getInventory().getItem(i);
                if(is != null)
                {
                    if(is.getTypeId() == 373){
                        System.out.println(is.getData());
                    }
                }
            }
     
  4. Offline

    Lordloss

    Thats because since 1.9 the handling of potions has changed. They now all have the same data.
     
  5. Offline

    Koningpeter

    Last edited: Apr 26, 2016
Thread Status:
Not open for further replies.

Share This Page