From b4bec983ac56b15120467266295de83ccb192a80 Mon Sep 17 00:00:00 2001 From: RednedEpic Date: Mon, 8 Jul 2024 18:45:37 -0500 Subject: [PATCH] Fix team stats for collective player stats --- .../victory/types/HighestStatCondition.java | 31 ++++++++++++++++--- 1 file changed, 27 insertions(+), 4 deletions(-) diff --git a/plugin/src/main/java/org/battleplugins/arena/competition/victory/types/HighestStatCondition.java b/plugin/src/main/java/org/battleplugins/arena/competition/victory/types/HighestStatCondition.java index 60db426b..ffe1c6f5 100644 --- a/plugin/src/main/java/org/battleplugins/arena/competition/victory/types/HighestStatCondition.java +++ b/plugin/src/main/java/org/battleplugins/arena/competition/victory/types/HighestStatCondition.java @@ -39,15 +39,38 @@ public void onStatChange(ArenaStatChangeEvent event) { // after the team has collectively retrieved a stat, or a stat that is // incremented by team (i.e. control points). StatHolder statHolder = event.getStatHolder(); - if (this.teamStats && statHolder instanceof TeamStatHolder teamHolder) { - if (this.winAfter != -1 && event.getNewValue().intValue() >= this.winAfter) { - this.advanceToNextPhase(this.competition.getTeamManager().getPlayersOnTeam(teamHolder.getTeam())); + if (this.teamStats) { + if (statHolder instanceof TeamStatHolder teamHolder) { + if (this.winAfter != -1 && event.getNewValue().intValue() >= this.winAfter) { + this.advanceToNextPhase(this.competition.getTeamManager().getPlayersOnTeam(teamHolder.getTeam())); + } + } else if (statHolder instanceof ArenaPlayer player) { + // Check for stats across all players on the team + ArenaTeam team = player.getTeam(); + if (team == null) { + return; + } + + Set players = this.competition.getTeamManager().getPlayersOnTeam(team); + int score = 0; + for (ArenaPlayer teamPlayer : players) { + if (teamPlayer == player) { + score += event.getNewValue().intValue(); + continue; + } + + score += teamPlayer.stat(this.stat).orElse(0).intValue(); + } + + if (score >= this.winAfter) { + this.advanceToNextPhase(players); + } } return; } - if (!this.teamStats && statHolder instanceof ArenaPlayer player) { + if (statHolder instanceof ArenaPlayer player) { if (this.winAfter != -1 && event.getNewValue().intValue() >= this.winAfter) { // Still need to check if the player is on a team, since we grant // the victory based on whether the team one. If the player is to