Fire event after consuming an item.

Discussion in 'Plugin Development' started by javaguy78, Sep 10, 2012.

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

    javaguy78

    So, I've been googling this like crazy and I can't find an answer that I'm satisfied with.

    I'm building a MineZ Clone plugin for bukkit, and in MineZ, you have to drink water to quench your thirst. I've replicated the thirst system pretty well, but I am using PlayerInteractEvent to drink the water. The event fires at the beginning of the drink animation, not at the end.

    In MineZ, you see the entire drink animation before your thirst is quenched. Is there a way to replicate this? I can quench the thrist before the drink animation, but how do I process the event after the animation?

    I'm at a loss. The event at the beginning of the animation is fine, but to be more MineZ -esque, it'd be better to fire the event at the end of the drink animation. Thanks.
     
  2. Offline

    QuantumDev

    Maybe wait for the item to be removed from the player's inventory.
     
  3. Offline

    Malikk

    You could figure out how long it takes to drink it and run a scheduler, then check the item again. At that point, if they did in fact drink it all the way //do stuff
     
  4. Offline

    rominos2

    Yeah that's should do the trick using a Scheduler (I use that)

    Code:
    final Player player = event.getPlayer();
    plugin.getServer.getScheduler().scheduleSyncDelayedTask(plugin, new Runnable() {
          @Override
          public void run() {
                      player.sendMessage("Youhou !");
                      //do what you want to the player
          }
    }, 0);
    
    Use 0 ticks after permits to run the runnable the ticks after, so the item is consumed[/code]
     
  5. Offline

    javaguy78

    Thank you, guys. I'll try the schedule and see how it works.
     
  6. Offline

    Woobie

    Why are you re-creating the thirst plugin, when theres already few.
     
    Zidkon likes this.
  7. Offline

    javaguy78

    I'm not recreating the thirst plugin - I'm recreating as much of the entire MineZ functionality as possible. Grouping all the functionality into one easy-to-use plugin.
     
  8. Offline

    CookCreeperz

    oh btw the thirst is 30L i got mine working!
     
    javaguy78 likes this.
  9. Offline

    TheSmallBones

    You have got to be kidding me... L is the variable they put on the example page for the schedular to let people like you know that you need to put a value there(replace the L with an int) . Stop trying to copy MineZ, and learn to use basic java syntax before making a bukkit plugin.
     
  10. Offline

    travja

    So, I've never actually seen a drink animation.. Neither have I been able to replicate it, javaguy78 can you show me how I'd come about making animations on different things.
     
  11. Offline

    javaguy78

    You obviously don't know how to properly implement long primitive data types in Java. long != int. Go do some research on primitive data types before you start spouting incorrect information about Java.
     
    CookCreeperz likes this.
  12. Offline

    javaguy78

    Thanks everyone! I set mine to 31L because 30L was failing about 25% of the time, but that extra tick makes it work almost perfectly. The only time it would fail is if you switch to another inventory slot within 1 tick of finishing drinking.
     
    CookCreeperz likes this.
  13. and why u bump back an old thread?
     
  14. Offline

    chasechocolate

    And no need for this anymore, we now have PlayerItemConsumeEvent.
     
  15. really? Even didn't noticed it...
     
  16. Offline

    chasechocolate

    Yup, I think it was added in the 1.4.7 update.
     
    CaptainBern likes this.
  17. finally...
     
  18. haha
     
Thread Status:
Not open for further replies.

Share This Page