Solved The gapple isn't giving the specified effects, just the normal effects.

Discussion in 'Plugin Development' started by mrdude123, Nov 23, 2015.

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

    mrdude123

    When I tried this with regular golden apples, it worked. Why isn't it working now? Thanks.
    Code:
    package me.thecerealkill3r.gapple;
    
    import org.bukkit.Bukkit;
    import org.bukkit.Material;
    import org.bukkit.entity.Player;
    import org.bukkit.event.EventHandler;
    import org.bukkit.event.Listener;
    import org.bukkit.event.player.PlayerItemConsumeEvent;
    import org.bukkit.inventory.ItemStack;
    import org.bukkit.plugin.java.JavaPlugin;
    import org.bukkit.potion.PotionEffect;
    import org.bukkit.potion.PotionEffectType;
    
    public class Main extends JavaPlugin implements Listener{
    
        public void onEnable(){
            System.out.print("Gapple is up and running!");
              Bukkit.getPluginManager().registerEvents(this, this);
        }
       
        @SuppressWarnings("deprecation")
        @EventHandler
       
        public void onEat(PlayerItemConsumeEvent e){
            final Player p = e.getPlayer();
            ItemStack NotchApple = new ItemStack(Material.GOLDEN_APPLE, 1, (short)1);
                if(e.getItem() == NotchApple){
                    getServer().getScheduler().scheduleAsyncDelayedTask(this, new Runnable() {
                        public void run() {
                    p.removePotionEffect(PotionEffectType.ABSORPTION);
                    p.removePotionEffect(PotionEffectType.REGENERATION);
                    p.addPotionEffect(new PotionEffect(PotionEffectType.REGENERATION, (20*30), 3));
                    p.addPotionEffect(new PotionEffect(PotionEffectType.ABSORPTION, (20*30), 1));
                    p.addPotionEffect(new PotionEffect(PotionEffectType.DAMAGE_RESISTANCE, (20*30), 0));
                    p.addPotionEffect(new PotionEffect(PotionEffectType.FIRE_RESISTANCE, (20*30), 0));
            }
           
       
    }, 1L);
                   
    }
    }
    }
    
     
  2. Offline

    Scimiguy

    First of all, you compare objects with .equals()

    Second, itemstack prefers you use .isSimilar()

    Thirdly, don't create a new itemstack and compare it, just check the material and durability of the stack., less things to get wrong then
     
  3. Offline

    mrdude123

    Thanks.
     
Thread Status:
Not open for further replies.

Share This Page