}
@EventHandler(priority=EventPriority.HIGHEST)
public void playerDeath(PlayerDeathEvent event)
{
AutoRefMatch match = plugin.getMatch(event.getEntity().getWorld());
if (match != null)
{
// get victim, and killer (maybe null) of this player
Player victim = event.getEntity();
AutoRefPlayer vapl = match.getPlayer(victim);
Player killer = victim.getKiller();
AutoRefPlayer kapl = match.getPlayer(killer);
String dmsg = event.getDeathMessage();
EntityDamageEvent lastDmg = victim.getLastDamageCause();
// if the death was due to intervention by the plugin
// let's change the death message to reflect this fact
if (lastDmg == AutoRefPlayer.VOID_DEATH)
{
dmsg = victim.getName() + " entered the void lane";
event.getDrops().clear();
}
Location locKiller = null;
if (lastDmg instanceof EntityDamageByEntityEvent)
{
EntityDamageByEntityEvent ed = (EntityDamageByEntityEvent) lastDmg;
switch (ed.getDamager().getType())
{
case CREEPER:
dmsg = victim.getName() + " was blown up by Creeper";
break;
case PRIMED_TNT:
dmsg = victim.getName() + " was blown up by TNT";
if (plugin.getTNTOwner(ed.getDamager()) != vapl)
{
kapl = plugin.getTNTOwner(ed.getDamager());
if (kapl != null)
dmsg = victim.getName() + " was blown up by " + kapl.getName();
}
break;
default:
// noop
break;
}
if (ed.getDamager() instanceof Projectile)
locKiller = shotArrows.get(ed.getDamager());
}
// update the death message with the changes
event.setDeathMessage(dmsg);
if (match.getCurrentState().inProgress())
{
// register the death and kill
if (vapl != null) vapl.registerDeath(event, locKiller);
if (kapl != null && kapl != vapl) kapl.registerKill(event);
}
// handle respawn modes
if (vapl != null && match.getCurrentState().inProgress())
{
respawn: switch (match.getRespawnMode())
{
case BEDS_ONLY:
// INTENTIONAL FALL-THROUGH HERE!
if (vapl.getTeam() != null)
for (AutoRefPlayer mate : vapl.getTeam().getPlayers())
{
if (mate == vapl) continue;
boolean couldRespawn = mate.isOnline() &&
mate.getPlayer().getBedSpawnLocation() != null;
if (!mate.isDead() || couldRespawn) break respawn;
}
if (victim.getBedSpawnLocation() != null) break respawn;
case DISALLOW:
case ALLOW:
if (match.getCurrentState().inProgress() && !vapl.hasLives())
match.eliminatePlayer(event.getEntity());
break;
// typically, no action should be taken
default: break;
}