Question Need Some Help with an @EventHandler

Discussion in 'Bukkit Help' started by PENGUllN, Jun 22, 2015.

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

    PENGUllN

    Hey all i need help or a @EventHandler For it to run a command or something when a player is tagged by another player i have no clue how i would do it
    please help
     
  2. Offline

    stefvanschie

    Use an EntityDamgeByEntityEvent
    Something like this:

    @EventHandler
    public void onEntityDamagebyEntity (EntityDamgeByEntityEvent e)
    {
    e.getPlayer().performCommand("YOURCOMMAND");
    }
     
  3. Offline

    PENGUllN

    Code:
    package io.github.PENGUllN.PluginFirst;
    
    import org.bukkit.event.Listener;
    import org.bukkit.event.entity.EntityDamageByEntityEvent;
    
    public class PlayerListener implements Listener {
       
        public PlayerListener(EventHandler plugin) {
            plugin.getServer().getPluginManager().registerEvents(this, plugin);
        }
       
        @EventHandler
        public void onEntityDamagedbyEntity(EntityDamageByEntityEvent e)
        {
            e.getPlayer().performCommand("Ouch");
        }
    }
    on line 12 i get "Type mismatch: cannot convert from EventHandler to Annotation"
    and line 15 i get "The method getPlayer() is undefined for the type EntityDamageByEntityEvent"
     
  4. Offline

    stefvanschie

    Change it to this:

    Code:
        @EventHandler
        public void onEntityDamagedbyEntity (EntityDamageByEntityEvent e)
        {
            if (e.getEntity() instanceof Player)
            {
                Player player = (Player) e.getEntity();
                player.performCommand("Ouch");
            }
        }
     
  5. Offline

    PENGUllN

    Code:
    package io.github.PENGUllN.PluginFirst;
    
    import org.bukkit.entity.Player;
    import org.bukkit.event.Listener;
    import org.bukkit.event.entity.EntityDamageByEntityEvent;
    import org.bukkit.event.*;
    
    public class PlayerListener implements Listener {
       
        public PlayerListener(EventHandler plugin) {
            plugin.getServer().getPluginManager().registerEvents(this, plugin);
        }
       
        @EventHandler
        public void onEntityDamagedbyEntity (EntityDamageByEntityEvent e)
        {
            if (e.getEntity() instanceof Player)
            {
                Player player = (Player) e.getEntity();
                player.performCommand("Ouch");
            }
    }}
    im still getting the "Type mismatch: cannot convert from EventHandler to Annotation" on line 14
    Could This Be Down to Another Class called EventHandler ?
     
  6. Offline

    stefvanschie

    Did you import EventHandler? If you did try to renam your Eventhandler class to something different, that might be the problem
     
  7. Offline

    Boomer

    doesn't appear to be in his import list in any form
     
  8. Offline

    stefvanschie

    @Boomer
    Well maybe it's under the org.bukkit.event class. He imported everything from that.
     
  9. Offline

    Boomer

    Good point yeah. Can not convert XXXX to Annotation is almost exclusively due to already having a class imported to your project that has the same name (EventHandler)...
     
  10. Offline

    PENGUllN

    i there anyway to record player while in combat or when they tagged another with an Event ?
     
Thread Status:
Not open for further replies.

Share This Page