Checking the item a player consumes

Discussion in 'Plugin Development' started by crushh87, Apr 4, 2013.

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

    crushh87

    So I have this PlayerItemConsume event and I am trying to check and see if the item the consume is a Arcrid Potion
    Code:


    Code:
        @EventHandler
     
        public void onPlayerItemConsumeEvent(PlayerItemConsumeEvent ev){
     
            final Player p = ev.getPlayer();
     
            ItemStack i = ev.getItem();
     
            p.sendMessage(" " + i.getItemMeta().getDisplayName());
     
           
     
            if(/*Check if item is Acrid Potion*/){
     
                p.sendMessage("test");
     
                task1 = Bukkit.getScheduler().scheduleSyncRepeatingTask(this, new Runnable()
     
                {
     
                    int count = 5;
     
                    public void run()
     
                          {
     
                        p.sendMessage("test2");
     
                              if(count == 0){
     
                                  p.setHealth(0);
     
                                  Bukkit.getScheduler().cancelTask(task1);
     
                              }
     
                              count--;
     
                          }
     
                }, 0L, 20L);
     
            }
     
        }
     
     
     
    }
     
    

    [​IMG]
    Just to prevent people from questioning the acrid potion.
     
  2. Offline

    chasechocolate

    After a quick Google search, I came up with this:
    Code:java
    1. ItemStack hand = player.getItemInHand();
    2. if(hand.getType() == Material.POTION && hand.getDurability() == (short) 59){
    3. //They are holding an acrid potion
    4. }
     
  3. Offline

    crushh87

    Never thought about trying that. Let me try it out and I'll see how it works.

    Yes! Thanks chasechocolate, works like a charm!

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

    ZeusAllMighty11

    That will throw a lot of NPE's, just sayin' that not all items have meta.
     
  5. Offline

    crushh87

    Have not got any yet.


    and while I'm here any thoughts on renaming a potion, I have looked around and I'm not sure weather I should be looking a PotionMeta of ItemMeta. And that every potion thread is about adding different effects and not renaming the actual potion.
     
Thread Status:
Not open for further replies.

Share This Page