Skip to content

Commit 951d30e

Browse files
authored
Merge pull request #124 from jwdeveloper/develop-1.10.1
Add additional helper methods back to TikTokLinkMicBattleEvent!
2 parents 4aec20c + 1df912b commit 951d30e

File tree

2 files changed

+37
-0
lines changed

2 files changed

+37
-0
lines changed

API/src/main/java/io/github/jwdeveloper/tiktok/data/events/TikTokLinkMicBattleEvent.java

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -128,4 +128,37 @@ private boolean isTeamsTie() {
128128
int referencePoints = teams.get(0).getTotalPoints();
129129
return teams.stream().allMatch(team -> team.getTotalPoints() == referencePoints);
130130
}
131+
132+
/**
133+
* @param battleHostName name of host to search
134+
* @return Team instance containing name of host or null if no team found */
135+
public Team getTeam(String battleHostName) {
136+
List<Team> list = getTeams(battleHostName);
137+
return list.isEmpty() ? null : list.get(0);
138+
}
139+
140+
/**
141+
* @param battleHostName name of host to search
142+
* @return Team instances not containing name of host */
143+
public List<Team> getOpponentTeams(String battleHostName) {
144+
List<Team> list = getTeams(battleHostName);
145+
return list.isEmpty() ? null : list;
146+
}
147+
148+
/**
149+
* @param battleHostName name of host to search
150+
* @return {@link List<Team>} with host team first, then opponent teams
151+
* <p> If host is in neither or teams is empty, returns empty
152+
* <p> Otherwise always teams.length in length;
153+
*/
154+
public List<Team> getTeams(String battleHostName) {
155+
if (teams.isEmpty() || teams.stream().noneMatch(team -> team.contains(battleHostName)))
156+
return Collections.EMPTY_LIST;
157+
Team hostTeam = teams.stream().filter(team -> team.contains(battleHostName)).findFirst().orElseThrow();
158+
List<Team> opponentTeams = teams.stream().filter(team -> !team.contains(battleHostName)).toList();
159+
List<Team> teams = new ArrayList<>();
160+
teams.add(hostTeam);
161+
teams.addAll(opponentTeams);
162+
return teams;
163+
}
131164
}

API/src/main/java/io/github/jwdeveloper/tiktok/data/models/battles/Team.java

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -81,4 +81,8 @@ public Team(WebcastLinkMicBattle.BattleUserInfo anchorInfo, WebcastLinkMicBattle
8181
this(anchorInfo);
8282
this.winStreak = (int) battleCombo.getComboCount();
8383
}
84+
85+
public boolean contains(String name) {
86+
return hosts.stream().anyMatch(user -> user.getName().equals(name));
87+
}
8488
}

0 commit comments

Comments
 (0)