onPlayerConsumeEvent problem

Discussion in 'Plugin Development' started by AfAf, Apr 21, 2014.

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

    AfAf

    Hey. I was planning to play with events when player consumes food. I have seen another thread where it was explained how to use onPlayerConsumeEvent and PlayerItemConsumeEvent. Tutorial included a link to DVs for potions but I would like to use Milk for it. However, which ID is it (there is 3 provided). Is it even possible ? Here is what I have got so far.
    Code:java
    1. public class AlcoMilk extends JavaPlugin implements Listener
    2. {
    3. @EventHandler
    4. public void onPlayerConsumeEvent(PlayerItemConsumeEvent event)
    5. {
    6. ItemStack foodID = event.getItem();
    7. if(foodID == /*MILK*/)
    8. {
    9. //stuff here
    10. }
    11. }
    12. }
    13.  

    Thanks for help:rolleyes:
     
  2. Offline

    Gater12

    AfAf
    foodID is an ItemStack. Get the type of the ItemStack which a Material enum. Then check if the enum is equalled to Material.MILK_BUCKET. PROFIT. (And only have your Main extends JavaPlugin unless this is your Main class and register your events, if you didn't already)
     
  3. Offline

    GeorgeeeHD

    Material.MILK_BUCKET, no?

    //Ninja'd
     
  4. Offline

    AfAf

    Should it be something like:
    Code:
    if(ItemStack == Metrial.MILK_BUCKET)
    or
    Code:
    if(ItemStack.equals().Material.MILK_BUCKET)
    Sorry, I am a beginner. Also, not sure for which version of bukkit the tutorial was made, but I use 1.2.5 r5.0 (its for a Tekkit Classics server) and the public void onPlayerConsumeEvent(PlayerItemConsumeEvent event) seems to not work. Is there an alternative ?
     
  5. Offline

    Gater12

    AfAf
    Do you know the basics of Java? There is tons of tutorials out there to explain the basics and you should know them before heading into the Bukkit API.

    You should be getting the type which is a Material and then compare it to MILK_BUCKET
     
  6. Offline

    AfAf

    K, I have got this:
    Code:
        @EventHandler
        public void drinkMilk(PlayerItemConsumeEvent event)
        {
            Player player = event.getPlayer();
            if (event.getItem().getType().equals(Material.MILK_BUCKET))
            {
                player.addPotionEffect(new PotionEffect(PotionEffectType.HUNGER, 600, 3));
                player.addPotionEffect(new PotionEffect(PotionEffectType.CONFUSION, 600, 3));
                player.addPotionEffect(new PotionEffect(PotionEffectType.SLOW, 900, 3));
                player.addPotionEffect(new PotionEffect(PotionEffectType.WEAKNESS, 600, 3));
            }
        }
    
    Eclipse sees PlayerItemConsumeEvent as an error. Possible fix ?
     
  7. AfAf whats your error in eclipse says?
     
  8. Offline

    Maurdekye

    AfAf Well, you can replace event.getItem().getType().equals(Material.MILK_BUCKET); with event.getItem().getType() == Material.MILK_BUCKET; it's faster. Also, you have to import your event properly.
     
  9. Offline

    AfAf

    Someone_Like_You
    PlayerItemConsumeEvent cannot be resolved to a type

    The plugin is being made for 1.2.5 R5.0 and it seems like this version does not support it.

    Maurdekye
    Thanks for the tip.
     
  10. Offline

    Badeye

    AfAf if you ahve to cancel it be aware that that is going to ahve alot of bugs, ther eis going to be item ghosting and teh food is eventually going to hop into your armor slots (i know, weird).
     
Thread Status:
Not open for further replies.

Share This Page