Skip to content

Commit

Permalink
Store and save team colors for posted matches
Browse files Browse the repository at this point in the history
  • Loading branch information
Pugzy committed Oct 7, 2023
1 parent 80d0f8c commit 6e85b8e
Show file tree
Hide file tree
Showing 5 changed files with 63 additions and 4 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
package rip.bolt.ingame.api.definitions;

import dev.pgm.events.EventsPlugin;
import dev.pgm.events.team.TournamentTeam;
import javax.annotation.Nullable;
import tc.oc.pgm.teams.Team;

public interface BoltTournamentTeam extends TournamentTeam {

Integer getTeamId();

default @Nullable Team getPgmTeam() {
return EventsPlugin.get().getTeamManager().fromTournamentTeam(this).orElse(null);
}
}
18 changes: 16 additions & 2 deletions src/main/java/rip/bolt/ingame/api/definitions/Team.java
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@
import com.fasterxml.jackson.annotation.JsonIgnore;
import com.fasterxml.jackson.annotation.JsonIgnoreProperties;
import dev.pgm.events.team.TournamentPlayer;
import dev.pgm.events.team.TournamentTeam;
import java.util.ArrayList;
import java.util.List;
import java.util.Objects;
Expand All @@ -14,11 +13,12 @@

/** A team for a bolt match, has the id & name, as well as the involved participants */
@JsonIgnoreProperties(ignoreUnknown = true)
public class Team implements TournamentTeam {
public class Team implements BoltTournamentTeam {

private Integer id;
private String name;
private String mmr;
private String color;

private Double score;

Expand Down Expand Up @@ -56,6 +56,14 @@ public void setMmr(String mmr) {
this.mmr = mmr;
}

public String getColor() {
return color;
}

public void setColor(String color) {
this.color = color;
}

public Double getScore() {
return score;
}
Expand Down Expand Up @@ -99,6 +107,12 @@ public String toString() {
.collect(Collectors.joining(", "));
}

@Override
@JsonIgnore
public Integer getTeamId() {
return id;
}

@Override
public boolean equals(Object o) {
if (this == o) return true;
Expand Down
1 change: 1 addition & 0 deletions src/main/java/rip/bolt/ingame/managers/MatchManager.java
Original file line number Diff line number Diff line change
Expand Up @@ -274,6 +274,7 @@ private BoltMatch transition(
break;
case ENDED:
statsManager.handleMatchUpdate(boltMatch, match);
PGMMapUtils.setTeamColors(boltMatch);
boltMatch.setEndedAt(transitionAt);
Collection<Competitor> winners = match.getWinners();
if (winners.size() == 1) {
Expand Down
9 changes: 7 additions & 2 deletions src/main/java/rip/bolt/ingame/pugs/ManagedTeam.java
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
package rip.bolt.ingame.pugs;

import dev.pgm.events.team.TournamentTeam;
import java.util.List;
import rip.bolt.ingame.api.definitions.BoltTournamentTeam;
import rip.bolt.ingame.api.definitions.Team;
import rip.bolt.ingame.api.definitions.pug.PugPlayer;
import rip.bolt.ingame.api.definitions.pug.PugTeam;

public class ManagedTeam implements TournamentTeam {
public class ManagedTeam implements BoltTournamentTeam {
private final String pugTeamId;

private PugTeam pugTeam;
Expand Down Expand Up @@ -60,4 +60,9 @@ public String getName() {
public List<PugPlayer> getPlayers() {
return pugTeam.getPlayers();
}

@Override
public Integer getTeamId() {
return boltTeam.getTeamId();
}
}
24 changes: 24 additions & 0 deletions src/main/java/rip/bolt/ingame/utils/PGMMapUtils.java
Original file line number Diff line number Diff line change
@@ -1,8 +1,13 @@
package rip.bolt.ingame.utils;

import dev.pgm.events.EventsPlugin;
import java.util.Map;
import java.util.stream.Collectors;
import rip.bolt.ingame.api.definitions.BoltMatch;
import rip.bolt.ingame.api.definitions.BoltPGMMap;
import rip.bolt.ingame.api.definitions.BoltTournamentTeam;
import tc.oc.pgm.api.match.Match;
import tc.oc.pgm.teams.Team;

public class PGMMapUtils {

Expand All @@ -15,4 +20,23 @@ public static BoltPGMMap getBoltPGMMap(BoltMatch boltMatch, Match match) {

return new BoltPGMMap(pgmMapName);
}

public static void setTeamColors(BoltMatch boltMatch) {
Map<Integer, Team> pgmTeams =
EventsPlugin.get().getTeamManager().teams().stream()
.map(tournamentTeam -> (BoltTournamentTeam) tournamentTeam)
.collect(
Collectors.toMap(BoltTournamentTeam::getTeamId, BoltTournamentTeam::getPgmTeam));

boltMatch
.getTeams()
.forEach(
team -> {
Team pgmTeam = pgmTeams.get(team.getTeamId());
if (pgmTeam != null) {
team.setColor(
"#" + String.format("%06X", 0xFFFFFF & pgmTeam.getFullColor().asRGB()));
}
});
}
}

0 comments on commit 6e85b8e

Please sign in to comment.