Last active
August 29, 2015 14:07
-
-
Save keepoff07/62da1f407c0fb5dec31a to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
@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