EventHelp

Discussion in 'Plugin Development' started by Rick221, Jan 23, 2015.

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

    Rick221

    I can not for the life of me figure this out. The plugin doesn't work, and I'm not sure why. I want it to be if you drop a d sword it gives u invis for 10 seconds

    Code:
    package me.rick2211133;
    
    
    
    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.PlayerDropItemEvent;
    import org.bukkit.plugin.java.JavaPlugin;
    import org.bukkit.potion.PotionEffect;
    import org.bukkit.potion.PotionEffectType;
    
    public class Practice extends JavaPlugin implements Listener {
       
        public void onEnable() {
            Bukkit.getPluginManager().registerEvents(this, this);
    
           
        }
       
       
       
        @EventHandler
        public void testEvent(PlayerDropItemEvent e) {
            Player p = e.getPlayer();
            if(e.equals(Material.DIAMOND_SWORD)) {
               
                p.addPotionEffect(new PotionEffect(PotionEffectType.INVISIBILITY,10,1));
           
        }
       
        }
    }
    
     
  2. Offline

    teej107

    Your if statement is will never be true. You are doing if PlayerDropItemEvent is equal to a Material
     
  3. Offline

    Rick221

    @teej107 well how do I make it true
     
  4. @Rick221 Like @teej107 said, you're comparing a PlayerItemDropEvent to a Material. That would never work. I think that the best way to do it would be:
    Code:
    if(event.getItemDrop() == new ItemStack(Material.DIAMOND_SWORD)) {
                            // Do stuff here.
                        }
     
  5. Offline

    teej107

    to compare the item Material
     
  6. Offline

    Rick221

    @CodePlaysMinecraft that doesnt work either
    Code:
    package me.rick2211133;
    
    
    
    import org.bukkit.Material;
    import org.bukkit.entity.Player;
    import org.bukkit.event.EventHandler;
    import org.bukkit.event.Listener;
    import org.bukkit.event.player.PlayerDropItemEvent;
    import org.bukkit.inventory.ItemStack;
    import org.bukkit.plugin.java.JavaPlugin;
    import org.bukkit.potion.PotionEffect;
    import org.bukkit.potion.PotionEffectType;
    
    public class Practice extends JavaPlugin implements Listener {
       
       
        public void onEnable() {
            getServer().getPluginManager().registerEvents(this, this);
    
           
        }
       
       
       
        @EventHandler
        public void testEvent(PlayerDropItemEvent e) {
            Player p = e.getPlayer();
            if(e.getItemDrop() == new ItemStack(Material.DIAMOND_SWORD)) {
               
                p.addPotionEffect(new PotionEffect(PotionEffectType.INVISIBILITY,10,1));
           
        }
       
    }
    }
    
     
  7. Offline

    WesJD

    @Rick221
    Code:
    if(e.getDropItem().getType() == Material.DIAMOND_SWORD) { //do stuff }
     
  8. Offline

    SuperOriginal

    You're comparing an ItemStack to a Material... That would never work either...
     
Thread Status:
Not open for further replies.

Share This Page