Игрок-убийца.

Pasha_Robber

Pioneer
Здравствуйте! Как получить игрока убившего другого игрока?
 

fromgate

Administrator
Нужно у Player есть метод позволяющий узнать причину последнего урона.

Code:
	@EventHandler
	public void onJoin (PlayerJoinEvent event){
		Regions.getSelector().setSelMode(event.getPlayer(),false);
	}
 
	public void onDeath (PlayerDeathEvent event){
		Player damager = getDamager(event.getEntity().getLastDamageCause());
		if (damager==null) return; // Игрок умер не в PVP
	}
 
	private Player getDamager(EntityDamageEvent event){
		Player player = null;
		if (event.getEntity() instanceof Player) player = (Player) event.getEntity();
		else if (event instanceof EntityDamageByEntityEvent) {
			Entity damager = ((EntityDamageByEntityEvent) event).getDamager();
			if (damager instanceof Player) player = (Player) damager;
		} else if (event instanceof EntityDamageByChildEntityEvent) {
			Entity damager = ((EntityDamageByChildEntityEvent) event).getDamager();
			if (damager instanceof Player) player = (Player) damager;
		}
		return player;
	}
 
Top