Solved Need Help - Custom Golden Apple effects

Discussion in 'Plugin Development' started by MyNames97, Apr 19, 2014.

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

    MyNames97

    Hey guys so let's just get to the point I've used a Delayed task to remove potion effect when eating golden apple but it dont work yes the event is registerd:

    Code:java
    1. @SuppressWarnings("deprecation")
    2. @EventHandler
    3. public void onAppleEat(PlayerItemConsumeEvent event) {
    4. if (event.getItem().equals(Material.GOLDEN_APPLE)) {
    5. final Player p = event.getPlayer();
    6. this.getServer().getScheduler().scheduleAsyncDelayedTask(this, new Runnable() {
    7. public void run() {
    8. p.removePotionEffect(PotionEffectType.ABSORPTION);
    9. p.removePotionEffect(PotionEffectType.REGENERATION);
    10. p.addPotionEffect(new PotionEffect(PotionEffectType.REGENERATION, 20, 2));
    11. p.addPotionEffect(new PotionEffect(PotionEffectType.SPEED, 20, 1));
    12. }
    13. }, 3);
    14. }
    15. }
     
    GrandmaJam likes this.
  2. Offline

    The Fancy Whale

  3. Offline

    MyNames97


    DOn't work I have tried to setCanelled true it won't work just acts like the code never was there
     
  4. Offline

    bennie3211

    what doesn't work? adding new potion effects, removing old potion effects or both?
     
  5. Offline

    TryB4

    MyNames97
    Did you register your events?

    Also, try: event.getItem().getType() == Material.GOLDEN_APPLE
     
    The Fancy Whale likes this.
  6. Offline

    The Fancy Whale

    ^^ That's the issue
    Right now you are comparing an item stack to a material
     
  7. Offline

    Captain Dory

    getItem() returns an ItemStack, not a material.
    You can return a material by using getType() on an ItemStack.
     
  8. Offline

    sipsi133

    MyNames97 Use this:
    Code:
    if(e.getItem().getType().equals(Material.GOLDEN_APPLE)) {
    because e.getItem().getType() returns Material.
     
    GrandmaJam likes this.
Thread Status:
Not open for further replies.

Share This Page