Very strange problem with EntityDamageEvent

Discussion in 'Plugin Development' started by Sking3000, May 22, 2016.

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

    Sking3000

    hi!

    When used EntityDamageEvent I had a strange problem ... with this code:

    Code:
    @EventHandler
        public void onPlaerDemageEvent(EntityDamageEvent e){
           
               
                    entity = e.getEntity();
                    Killer = ((Player) entity).getKiller();
                   
                    Bukkit.broadcastMessage("entity: " + entity.getName() + " killer: " + Killer.getName());
           
        }

    Not every time it worked, and when that did not work in the console showed:

    I do not know what the problem is, but my ultimate goal is that every time a player hits a player from his team, he will get hurt. All players names of the players from that team are on their own ArrayList:

    Code:
        public static ArrayList<String> redTeam = new ArrayList<String>();
        public static ArrayList<String> blueTeam = new ArrayList<String>();

    I would be happy if you can help me!

    Thanks,
    Sking3000
     
  2. Offline

    magicced01

    Why aren't you using PlayerDeathEvent? You get a NullPointerException because the target is still alive so it doesnt have a Killer
     
  3. you are casting without checking if the entity is a player...
     
  4. Offline

    Sking3000


    @magicced01


    Hey, I want that every time a player hits a player in the same team, he will not hurt ...
    I think PlayerDeathEvent not help me in this case.

    @FisheyLP



    There are still errors, it does not work

    EDIT by Moderator: merged posts, please use the edit button instead of double posting.
     
  5. Offline

    MisterErwin

    @Sking3000 Have a look at the EntityDamageByEntityEvent.
    Because a living player usually does not have a killer.
    To get the damager use the #getDamager() method of EntityDamageByEntityEvent
     
Thread Status:
Not open for further replies.

Share This Page