Get name of user left clicking (hitting) you?

Discussion in 'Plugin Development' started by RastaLulz, Sep 28, 2012.

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



    I've searched and I can't seem to find anything helpful that would allow me to get the name of the user left clicking (hitting) me (or another user). There's a bunch of threads on right clicking a user, and I managed to do that.

    Any help is appreciated.
  2. Offline


    get the entity who is the damager
    Check if its a player
    IF thats true, cast it to a player, like: Player damager = (Player)event.getDamager(); //something like this
    than, get the users name using damager.getfullname
  3. Offline


    Thanks, got it working.

    Here's a reference for anyone if they have this same question in the future.

        public void onHit(EntityDamageByEntityEvent event) {
            if(event.getDamager() instanceof Player && event.getEntity() instanceof Player) {
                Player attacker =  (Player) event.getDamager();
                Player prey = (Player) event.getEntity();
                Bukkit.getServer().broadcastMessage(attacker.getName() + " is hitting " + prey.getName() + ".");
Thread Status:
Not open for further replies.

Share This Page