I cant get the entity of killed a player :/ player.getKiller() only return a player Any way to get the entity?
Code (Text): @EventHandler public void onDeath(PlayerDeathEvent e){ Player killed = e.getEntity(); Player killer = e.getEntity().getKiller(); Entity entityKiller = e.getEntity().getKiller(); } Hope this helped
Let me see if I've got this correctly. You're wanting to get when something besides a Player kills someone, yes? If so, I don't think PlayerDeathEvent supports that. You may have to use EntityDamageByEntityEvent and test if their health minus the damage will be less than 0 and go from there.
He is checking if a player is getting killed, it would not be damage. I have just showed him how to get it if it is an entity, or if its a player that is the killer. Also you might need to do the following Code (Text): if (e.getEntity().getKiller() intanceof Entity){ //do the following }
By seems of it (with excuse it's late and on mobile) You would use the snippet @MrBandit gave and then convert Entity to Player. You may need to cast also.
Code (Text): @EventHandler public void onDeath(PlayerDeathEvent e){ Player killed = e.getEntity(); String killedsname = killed.getName(); Player killer = e.getEntity().getKiller(); String killersname = killer.getName(); Entity entityKiller = e.getEntity().getKiller(); String entitysname = entityKiller.getName(); e.setDeathMessage(null); Bukkit.broadcastMessage(ChatColor.RED+killedsname+ChatColor.WHITE+" Was killed by "+killersname); } This is so that none of the e.getEntity() return null and you can use thier names
Yes, but you can effectively use the damage event as a death event also. The getKiller method returns a Player object. I don't see how that could possibly be used to get an entity which isn't a player. You can't just cast a Wither or something to Player and pass it in, they're different things... There would be no reason for OP to be asking this if they were just looking for what you're providing. The player class extends LivingEntity, which extends Entity. Having a player object is basically the same as having an Entity object. So I assume they are trying to listen for when ANY entity kills a player, which I believe is not possible with this event, leading to the suggestion I gave.