Need an Event for Drinking Potions

Discussion in 'Bukkit Discussion' started by foxwillow, Aug 18, 2012.

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

    foxwillow

    I'm not sure where to put this. This seems like the most relevant forum. =]

    I'm having a problem with an RPG-based plugin and after talking with the very great developer (Pylamo!) he said that the problem was that bukkit is currently limited...

    Right now with an RPG plugin, some brewed potions don't seem to have any effect, and he said it was because bukkit doesn't have a "potion drink event," soooo... what are the odds of getting one? :D
     
    Jozeth likes this.
  2. Offline

    Lolmewn

    I'm sure there's a hacky way around it.
    Like, PlayerInteracteEvent or something, rightclicking air and holding a potion.
     
  3. Offline

    foxwillow

    he said that wont do it =/
     
  4. Offline

    foxwillow

    also, is there possibly a better way to go about this request? as i said, this seems like the right forum but i'm not sure. :/
     
  5. Offline

    Lookatmego

    Yeah we also had this problem with one of our plugins we were making for my server, in the end we didnt really use it, so i think this would be a good addition. Im sure THERE IS a way to get around it somehow tbh, but i rather have an actual way for it if possible.
     
  6. Offline

    TnT

    foxwillow
    Submit feature requests to leaky.bukkit.org.

    Pull Requests are very welcome.
     
    lol768 likes this.
  7. Offline

    foxwillow

  8. Offline

    xGhOsTkiLLeRx

  9. Offline

    foxwillow

    i've no idea what combining would do but i'm all for anything that makes RPG plugins better...
     
  10. Offline

    xGhOsTkiLLeRx

    I thought about a global "PlayerConsumeItemEvent"
    Where you can check for potions, normal food and milk buckets for example.
     
  11. Offline

    foxwillow

    sounds great to me :D
     
  12. Offline

    xGhOsTkiLLeRx

    The bad thing is that the ticket is already closed, because we could use the event where the food bar is changed :/
     
  13. Offline

    ZachBora

    A party is a great event for drinking!
     
  14. Offline

    Sleaker

  15. Offline

    xGhOsTkiLLeRx

  16. Offline

    TnT

  17. Offline

    Zidkon

    Why don't you try to make a timer everytime someone right click with potion on hand (i'm not sure if you can check the slot where is atm the item), after timer ends you can check if the item at the hand is an empty bottle? something like that can work
     
  18. It could've been cancelled or they could have deselected the potion while halfway through drinking it!
     
  19. Offline

    Zidkon

    That's the point on the timer to check. That you check after the time you consider he should have drinked it already (of course not too long)
     
  20. Would still be a lot easier with an event though and the event would use less resources.
     
  21. Offline

    Zidkon

    Oh yes, thats true, but I bet that an event will not be implemented any sooner for your project xD, I'm giving a fast solution until they put the event :D
     
  22. Offline

    Mr Burkes

    I created a hack for this; this is the code I used for a drinking aspect in one of my plugins. What I basically do is check if a player has a water bottle in their hands, I call a delayed task that checks the slot and player. Here's my code:
    Code:
    if((e.getAction().equals(Action.RIGHT_CLICK_AIR) || e.getAction().equals(Action.RIGHT_CLICK_BLOCK))){     
                if(User.hasWaterBottle(p))
                    Bukkit.getScheduler().scheduleSyncDelayedTask(PLUGIN.A, new CheckDrink(p, p.getInventory().getHeldItemSlot()), 33L);
    }
    
    As you see, I add the p.getInventory().getHeldItemSlot() to check that the slot is the same. I do this because the player can change their item in hand, and we don't want to say they drank the potion if they switched their item.

    The CheckDrink thread:
    Code:
    public class CheckDrink implements Runnable {
        private Player p;
        private int slot;
     
        public CheckDrink(Player p, int slot){
            this.p = p;
            this.slot = slot;
        }
     
        @Override
        public void run() {
            if(p.getInventory().getHeldItemSlot() == slot
                    && p.getItemInHand().getType().equals(Material.GLASS_BOTTLE)){
                User.drinkFull(p);
                p.sendMessage(ChatColor.AQUA+"You drank water! Your thirst has been replenished!");
            }
        }
    }
    
    This checks that after 33 ticks, the player has NOT changed their item and has in fact drank the potion. Of course, my User.hasWaterBottle() method can be changed to suit your potions and whatever, but there's the idea. ^.^
     
    platyperson likes this.
  23. Offline

    Zidkon

    :) Really thanks for this, as well I haven't programm with bukkit api long time ago so is like I'm a noob right now.

    I think this works (as far as my comprehenssion of the code goes) perfectly , anyways you cannot deny that it would be easier having the event that foxwillow is asking for XD
     
  24. Offline

    Mr Burkes

    An event would be extremely nice :D
     
  25. Offline

    foxwillow

  26. Offline

    xGhOsTkiLLeRx

    It's working, but I need to re-pull ist because I did some mistakes ;)
     
    hawkfalcon likes this.
  27. Offline

    foxwillow

    i'm not sure what the process is, but if/when this is implemented, you are going to have a lot of appreciative people!
     
  28. Offline

    hawkfalcon

    xD
    "You do realize that every food of X type will now have that amount of nutrition right?"
     
  29. Offline

    lol768

    Is there any chance of this functionality being added to the official builds (i.e. when is the request likely to be accepted)?
     
Thread Status:
Not open for further replies.

Share This Page