@EventHandler public void onPlayerDeath(PlayerDiedEvent event) { if (event.getGame() != this.game) return; Player player = event.getPlayer(); if (deadPlayers.containsKey(player)) return; DeadPlayer deadPlayer = new DeadPlayer(player, this.game); deadPlayers.put(player, deadPlayer); deadPlayer.spawn(); for (PotionEffect effect : player.getActivePotionEffects()) { player.removePotionEffect(effect.getType()); } game.broadcast(ChatColor.BOLD.toString() + ChatColor.DARK_RED + event.getDeathMessage()); for (Player p : game.getPlayers()) { plugin.sendActionbarMessage( p, ChatColor.YELLOW.toString() + ChatColor.BOLD.toString() + player.getName() + " has been downed! Go revive them!"); } if (deadPlayers.size() == game.getPlayers().size()) safelyEndGame(); }
@EventHandler public void onRoundAdvance(RoundAdvanceEvent event) { if (event.getGame() != game) return; for (DeadPlayer deadPlayer : deadPlayers.values()) deadPlayer.respawn(); deadPlayers.clear(); }
@EventHandler public void onGameTick(GameTickEvent event) { if (event.getGame() != game) return; Iterator<DeadPlayer> iterator = deadPlayers.values().iterator(); while (iterator.hasNext()) { DeadPlayer deadPlayer = iterator.next(); if (deadPlayer.isExpired()) deadPlayer.removeSign(); else deadPlayer.updateSign(); } }
@EventHandler public void onGameEnd(GameEndEvent event) { if (event.getGame() != game) return; for (DeadPlayer deadPlayer : deadPlayers.values()) { deadPlayer.removeSign(); deadPlayer.spawn(); } deadPlayers.clear(); }
@EventHandler public void onBlockBreak(BlockBreakEvent event) { Block block = event.getBlock(); if (block.getType() != Material.SIGN_POST) return; Sign sign = (Sign) block.getState(); if (!sign.getLine(0).equals(DeadPlayer.SIGN_HEADER)) return; Iterator<DeadPlayer> iterator = deadPlayers.values().iterator(); while (iterator.hasNext()) { DeadPlayer deadPlayer = iterator.next(); if (!deadPlayer.getPlayer().getName().startsWith(ChatColor.stripColor(sign.getLine(1)))) continue; deadPlayer.revive(); iterator.remove(); game.callEvent(new PlayerReviveEvent(deadPlayer.getPlayer(), event.getPlayer())); } }