Skip to content

Commit

Permalink
Add BoltRanking and Ranking classes
Browse files Browse the repository at this point in the history
  • Loading branch information
Pugzy committed Jan 1, 2022
1 parent f1d2967 commit 50514a7
Show file tree
Hide file tree
Showing 5 changed files with 105 additions and 25 deletions.
7 changes: 5 additions & 2 deletions src/main/java/rip/bolt/ingame/api/APIManager.java
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package rip.bolt.ingame.api;

import com.fasterxml.jackson.databind.MapperFeature;
import com.fasterxml.jackson.databind.ObjectMapper;
import java.util.UUID;
import okhttp3.OkHttpClient;
Expand All @@ -18,6 +19,9 @@ public class APIManager {
public APIManager() {
serverId = AppData.API.getServerName();

ObjectMapper objectMapper = new ObjectMapper().registerModule(new DateModule());
objectMapper.enable(MapperFeature.ACCEPT_CASE_INSENSITIVE_ENUMS);

OkHttpClient.Builder httpClient = new OkHttpClient.Builder();
httpClient.addInterceptor(
chain ->
Expand All @@ -31,8 +35,7 @@ public APIManager() {
Retrofit retrofit =
new Retrofit.Builder()
.baseUrl(AppData.API.getURL())
.addConverterFactory(
JacksonConverterFactory.create(new ObjectMapper().registerModule(new DateModule())))
.addConverterFactory(JacksonConverterFactory.create(objectMapper))
.addCallAdapterFactory(new DefaultCallAdapterFactory<>())
.client(httpClient.build())
.build();
Expand Down
34 changes: 34 additions & 0 deletions src/main/java/rip/bolt/ingame/api/definitions/BoltRank.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
package rip.bolt.ingame.api.definitions;

import java.util.Locale;

public enum BoltRank {
S("S"),
A_PLUS("A+"),
A("A"),
B_PLUS("B"),
B("B"),
C_PLUS("C+"),
C("C"),
D_PLUS("D+"),
D("D"),
UNRANKED("Unranked");

private final String displayName;

BoltRank(String name) {
this.displayName = name;
}

public String getDisplayName() {
return this.displayName;
}

public String getId() {
return this.name().toLowerCase(Locale.ROOT);
}

public String toString() {
return this.name();
}
}
45 changes: 45 additions & 0 deletions src/main/java/rip/bolt/ingame/api/definitions/Ranking.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
package rip.bolt.ingame.api.definitions;

import com.fasterxml.jackson.annotation.JsonIgnoreProperties;

@JsonIgnoreProperties(ignoreUnknown = true)
public class Ranking {

private Integer rating;
private Double score;
private Double sigma;

private BoltRank rank;

public Integer getRating() {
return rating;
}

public void setRating(Integer rating) {
this.rating = rating;
}

public Double getScore() {
return score;
}

public void setScore(Double score) {
this.score = score;
}

public Double getSigma() {
return sigma;
}

public void setSigma(Double sigma) {
this.sigma = sigma;
}

public BoltRank getRank() {
return rank;
}

public void setRank(BoltRank rank) {
this.rank = rank;
}
}
32 changes: 14 additions & 18 deletions src/main/java/rip/bolt/ingame/api/definitions/User.java
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,7 @@
public class User implements TournamentPlayer {

private UUID uuid;
private String rank;
private Integer mmr;
private Ranking ranking;

@JsonProperty(access = Access.WRITE_ONLY)
private List<MatchResult> history;
Expand All @@ -28,22 +27,6 @@ public void setUuid(UUID uuid) {
this.uuid = uuid;
}

public String getRank() {
return rank;
}

public void setRank(String rank) {
this.rank = rank;
}

public Integer getMmr() {
return mmr;
}

public void setMmr(Integer mmr) {
this.mmr = mmr;
}

public List<MatchResult> getHistory() {
return history;
}
Expand All @@ -59,6 +42,19 @@ public UUID getUUID() {
return uuid;
}

public Ranking getRanking() {
return ranking;
}

public void setRanking(Ranking ranking) {
this.ranking = ranking;
}

@JsonIgnore
public String getRank() {
return this.getRanking().getRank().getId();
}

@Override
public boolean canVeto() {
return true;
Expand Down
12 changes: 7 additions & 5 deletions src/main/java/rip/bolt/ingame/ranked/RankManager.java
Original file line number Diff line number Diff line change
Expand Up @@ -105,10 +105,12 @@ public void notifyUpdate(@Nonnull User old, @Nonnull User user, @Nonnull MatchPl
updatePlayer(player, player.getParty());

Component rank = RANK_PREFIX;
if (!old.getRank().equals(user.getRank())) rank = rank.append(getRank(old)).append(ARROW);
if (!old.getRanking().getRank().equals(user.getRanking().getRank()))
rank = rank.append(getRank(old)).append(ARROW);
rank = rank.append(getRank(user)).append(text("("));

if (old.getMmr() != null && old.getMmr() < user.getMmr())
if (old.getRanking().getRating() != null
&& old.getRanking().getRating() < user.getRanking().getRating())
rank = rank.append(mmr(old)).append(text(" ")).append(ARROW);
rank = rank.append(mmr(user)).append(text(")"));

Expand Down Expand Up @@ -152,7 +154,7 @@ private Component getRank(User user) {
.filter(g -> g.getId().equals(rank))
.map(c -> c.getFlair().getComponent(true))
.findFirst()
.orElse(text("Unknown", NamedTextColor.DARK_GRAY));
.orElse(text("Unknown ", NamedTextColor.DARK_GRAY));
}

private TextColor getRankColor(User user) {
Expand All @@ -166,7 +168,7 @@ private TextColor getRankColor(User user) {
}

private Component mmr(User user) {
if (user.getMmr() == null) return text(" - ", NamedTextColor.DARK_GRAY);
return text(user.getMmr(), getRankColor(user));
if (user.getRanking().getRating() == null) return text(" - ", NamedTextColor.DARK_GRAY);
return text(user.getRanking().getRating(), getRankColor(user));
}
}

0 comments on commit 50514a7

Please sign in to comment.