public boolean handleDeath(WarPlayer player, String deathMessage) { WarGame game = warzone.getGame().orElseThrow(IllegalStateException::new); plugin.delayTask( 3, () -> { if (player.isPlayingWar()) game.resetPlayerState(player); }); return true; }
public boolean handleDamage(WarPlayer defender, double damage, WarDamageCause cause) { WarGame game = warzone.getGame().orElseThrow(IllegalStateException::new); if (cause instanceof WarDamageCause.Combat) { WarPlayer attacker = ((WarDamageCause.Combat) cause).getAttacker(); if (game.getPlayerTeam(defender) == game.getPlayerTeam(attacker)) { attacker.sendMessage("Do not target your own team!"); return true; } game.addAttack(attacker, defender); } // prevent skeletons from shooting players in zones if (cause instanceof WarDamageCause.Creature) { return true; } // player would die by this blow if (defender.getHealth() - damage < 1) { // send the death message for the most recent damage cause game.broadcast(cause.getDeathMessage()); // find a recent attack from a player Optional<WarGame.Attack> first = game.getAttacks() .stream() .filter(a -> a.getDefender() == defender) .filter(a -> System.currentTimeMillis() - a.getTime() < LAST_ATTACK_DELAY_MS) .findFirst(); if (first.isPresent()) { WarGame.Team beneficiary = game.getPlayerTeam(first.get().getAttacker()); beneficiary.addPoints(1); game.broadcast(MessageFormat.format("Team {0} gains 1 point.", beneficiary.getName())); } game.checkForEndRound(); game.resetPlayerState(defender); game.resetPlayerState(defender); return true; } return false; }