Skip to content

Instantly share code, notes, and snippets.

@keepoff07
Last active August 29, 2015 14:07
Show Gist options
  • Save keepoff07/62da1f407c0fb5dec31a to your computer and use it in GitHub Desktop.
Save keepoff07/62da1f407c0fb5dec31a to your computer and use it in GitHub Desktop.
@EventHandler
public void onPlayerDeath(PlayerDeathEvent e){
//死亡したプレイヤーの取得
Player player = e.getEntity();
//最後のダメージイベントがnullでなければ
if(player.getLastDamageCause() != null){
//最後のダメージイベントを取得
EntityDamageEvent damageE = player.getLastDamageCause();
//EntityDamageEventがEntityDamageByEntityEventの場合
if(damageE instanceof EntityDamageByEntityEvent){
//EntityDamageByEntityEventにキャスト
EntityDamageByEntityEvent damagebyEntE = (EntityDamageByEntityEvent)damageE;
//ダメージを与えたエンティティの取得
Entity damager = damagebyEntE.getDamager();
//ダメージを与えたのが雪玉の場合
if(damager instanceof Snowball){
//Snowballにキャスト
Snowball snow = (Snowball)damager;
//投げたモノの取得
ProjectileSource shoter = snow.getShooter();
//投げたモノがプレイヤーの場合(スノーマンやディスペンサーの可能性もあるので)
if(shoter instanceof Player){
//プレイヤーにキャスト
Player attacker = (Player)shoter;
//あとは任意のデスメッセージに変える
e.setDeathMessage(player.getName()+" was killed by "+attacker.getName());
}
}
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment