[TUTORIAL] Getting a drunk potion through PlayerItemConsumeEvent

Discussion in 'Resources' started by Cryptite, May 20, 2013.

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

    Cryptite

    Doesn't seem that there's an up-to-date solve of this on the forums anywhere, so with a little help from #bukkitdev, here's how you can both catch a player drinking a potion event and also figure out which potion was drunk.

    Wherever you have your PlayerListener in your plugin, toss this in there.

    Code:
    @EventHandler
            public void onPlayerConsumeEvent(PlayerItemConsumeEvent event) {
                short potionID = event.getItem().getDurability();
                if (potionID == 8261) {
                    //Player drank a Potion of Healing I
                } else if (potionID == 8229) {
                    //Player drank a Potion of Healing II
                }
            }
    The table of DV's for potions can be found here. Anyway, thought this might turn up useful for somebody in the future. Also, there might be better ways to do this, but it's a start.
     
    Pink__Slime likes this.
  2. Offline

    Necrodoom

  3. Offline

    np98765

    Moved to Plugin Development Resources.
     
Thread Status:
Not open for further replies.

Share This Page