Skip to content

Commit c53ec3d

Browse files
committedJul 27, 2023
Added Arena Augment Support, fixed Bugs when no champion was banned, added equals Methods
·
v1.4.1v1.3
1 parent 95c7ef9 commit c53ec3d

File tree

12 files changed

+388
-155
lines changed

12 files changed

+388
-155
lines changed
 
Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
package net.petersil98.thresh.collection;
2+
3+
import net.petersil98.thresh.data.ArenaAugment;
4+
5+
import java.util.ArrayList;
6+
import java.util.List;
7+
import java.util.Map;
8+
9+
public class ArenaAugments {
10+
11+
private static Map<Integer, ArenaAugment> arenaAugments;
12+
13+
public static ArenaAugment getArenaAugment(int id) {
14+
return arenaAugments.get(id);
15+
}
16+
17+
public static List<ArenaAugment> getArenaAugments() {
18+
return new ArrayList<>(arenaAugments.values());
19+
}
20+
}
Lines changed: 71 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,71 @@
1+
package net.petersil98.thresh.data;
2+
3+
import com.fasterxml.jackson.annotation.JsonIgnoreProperties;
4+
import com.fasterxml.jackson.annotation.JsonProperty;
5+
6+
import java.util.Map;
7+
import java.util.Objects;
8+
9+
@JsonIgnoreProperties(ignoreUnknown = true)
10+
public class ArenaAugment {
11+
12+
private int id;
13+
private String name;
14+
private int rarity;
15+
private String tooltip;
16+
@JsonProperty("desc")
17+
private String description;
18+
private String iconLarge;
19+
private String iconSmall;
20+
private Map<String, Double> dataValues;
21+
22+
public int getId() {
23+
return id;
24+
}
25+
26+
public String getName() {
27+
return name;
28+
}
29+
30+
public int getRarity() {
31+
return rarity;
32+
}
33+
34+
public String getTooltip() {
35+
return tooltip;
36+
}
37+
38+
public String getDescription() {
39+
return description;
40+
}
41+
42+
public String getIconLarge() {
43+
return iconLarge;
44+
}
45+
46+
public String getIconSmall() {
47+
return iconSmall;
48+
}
49+
50+
public Map<String, Double> getDataValues() {
51+
return dataValues;
52+
}
53+
54+
@Override
55+
public String toString() {
56+
return this.name;
57+
}
58+
59+
@Override
60+
public boolean equals(Object o) {
61+
if (this == o) return true;
62+
if (o == null || getClass() != o.getClass()) return false;
63+
ArenaAugment that = (ArenaAugment) o;
64+
return id == that.id;
65+
}
66+
67+
@Override
68+
public int hashCode() {
69+
return Objects.hash(id);
70+
}
71+
}

‎src/main/java/net/petersil98/thresh/data/Challenge.java

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44

55
import java.util.List;
66
import java.util.Map;
7+
import java.util.Objects;
78

89
public class Challenge {
910

@@ -93,4 +94,17 @@ public String getTitle() {
9394
public String toString() {
9495
return this.name;
9596
}
97+
98+
@Override
99+
public boolean equals(Object o) {
100+
if (this == o) return true;
101+
if (o == null || getClass() != o.getClass()) return false;
102+
Challenge challenge = (Challenge) o;
103+
return id == challenge.id;
104+
}
105+
106+
@Override
107+
public int hashCode() {
108+
return Objects.hash(id);
109+
}
96110
}

‎src/main/java/net/petersil98/thresh/data/Map.java

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,11 +4,26 @@
44
import net.petersil98.stcommons.data.Sprite;
55
import net.petersil98.thresh.model.Deserializers;
66

7+
import java.util.Objects;
8+
79
@JsonDeserialize(using = Deserializers.MapDeserializer.class)
810
public record Map(int id, String name, String fullImage, Sprite sprite) {
911

1012
@Override
1113
public String toString() {
1214
return this.name;
1315
}
16+
17+
@Override
18+
public boolean equals(Object o) {
19+
if (this == o) return true;
20+
if (o == null || getClass() != o.getClass()) return false;
21+
Map map = (Map) o;
22+
return id == map.id;
23+
}
24+
25+
@Override
26+
public int hashCode() {
27+
return Objects.hash(id);
28+
}
1429
}
Lines changed: 26 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -1,42 +1,50 @@
11
package net.petersil98.thresh.data;
22

3-
import com.fasterxml.jackson.annotation.JsonProperty;
3+
import java.util.Objects;
44

55
public class QueueType {
66

7-
@JsonProperty("queueId")
87
private int id;
9-
private String map;
8+
private String name;
9+
private String shortName;
1010
private String description;
11-
private String notes;
12-
13-
public QueueType(int id, String map, String description, String notes) {
14-
this.id = id;
15-
this.map = map;
16-
this.description = description;
17-
this.notes = notes;
18-
}
19-
20-
public QueueType() {}
11+
private String detailedDescription;
2112

2213
public int getId() {
2314
return id;
2415
}
2516

26-
public String getMap() {
27-
return map;
17+
public String getName() {
18+
return name;
19+
}
20+
21+
public String getShortName() {
22+
return shortName;
2823
}
2924

3025
public String getDescription() {
3126
return description;
3227
}
3328

34-
public String getNotes() {
35-
return notes;
29+
public String getDetailedDescription() {
30+
return detailedDescription;
3631
}
3732

3833
@Override
3934
public String toString() {
40-
return this.description;
35+
return this.name;
36+
}
37+
38+
@Override
39+
public boolean equals(Object o) {
40+
if (this == o) return true;
41+
if (o == null || getClass() != o.getClass()) return false;
42+
QueueType queueType = (QueueType) o;
43+
return id == queueType.id;
44+
}
45+
46+
@Override
47+
public int hashCode() {
48+
return Objects.hash(id);
4149
}
4250
}

‎src/main/java/net/petersil98/thresh/data/SummonerSpell.java

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
import net.petersil98.thresh.model.Deserializers;
66

77
import java.util.List;
8+
import java.util.Objects;
89

910
@JsonDeserialize(using = Deserializers.SummonerSpellDeserializer.class)
1011
public class SummonerSpell {
@@ -71,4 +72,17 @@ public String getImage() {
7172
public String toString() {
7273
return this.name;
7374
}
75+
76+
@Override
77+
public boolean equals(Object o) {
78+
if (this == o) return true;
79+
if (o == null || getClass() != o.getClass()) return false;
80+
SummonerSpell that = (SummonerSpell) o;
81+
return id == that.id;
82+
}
83+
84+
@Override
85+
public int hashCode() {
86+
return Objects.hash(id);
87+
}
7488
}

‎src/main/java/net/petersil98/thresh/data/champion/Champion.java

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
import net.petersil98.thresh.model.Deserializers;
66

77
import java.util.List;
8+
import java.util.Objects;
89

910
@JsonDeserialize(using = Deserializers.ChampionDeserializer.class)
1011
public class Champion {
@@ -95,4 +96,17 @@ public Stats getBaseStats() {
9596
public String toString() {
9697
return this.name;
9798
}
99+
100+
@Override
101+
public boolean equals(Object o) {
102+
if (this == o) return true;
103+
if (o == null || getClass() != o.getClass()) return false;
104+
Champion champion = (Champion) o;
105+
return id == champion.id;
106+
}
107+
108+
@Override
109+
public int hashCode() {
110+
return Objects.hash(id);
111+
}
98112
}

‎src/main/java/net/petersil98/thresh/data/champion/Skin.java

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,8 @@
33
import com.fasterxml.jackson.databind.annotation.JsonDeserialize;
44
import net.petersil98.thresh.model.Deserializers;
55

6+
import java.util.Objects;
7+
68
@JsonDeserialize(using = Deserializers.SkinDeserializer.class)
79
public class Skin {
810

@@ -38,4 +40,17 @@ public boolean hasChromas() {
3840
public String toString() {
3941
return this.name;
4042
}
43+
44+
@Override
45+
public boolean equals(Object o) {
46+
if (this == o) return true;
47+
if (o == null || getClass() != o.getClass()) return false;
48+
Skin skin = (Skin) o;
49+
return id == skin.id;
50+
}
51+
52+
@Override
53+
public int hashCode() {
54+
return Objects.hash(id);
55+
}
4156
}

‎src/main/java/net/petersil98/thresh/data/rune/BaseRune.java

Lines changed: 5 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -44,16 +44,14 @@ public String toString() {
4444
}
4545

4646
@Override
47-
public boolean equals(Object obj) {
48-
if (obj == this) return true;
49-
if (obj == null || obj.getClass() != this.getClass()) return false;
50-
var that = (BaseRune) obj;
51-
return this.id == that.id;
47+
public boolean equals(Object o) {
48+
if (this == o) return true;
49+
if (!(o instanceof BaseRune baseRune)) return false;
50+
return id == baseRune.id;
5251
}
5352

5453
@Override
5554
public int hashCode() {
56-
return Objects.hash(this.id);
55+
return Objects.hash(id);
5756
}
58-
5957
}

‎src/main/java/net/petersil98/thresh/model/Deserializers.java

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -156,7 +156,14 @@ public MatchParticipant deserialize(JsonParser jp, DeserializationContext ctxt)
156156
root.get("timePlayed").asInt(), root.get("totalDamageShieldedOnTeammates").asInt(), root.get("totalHealsOnTeammates").asInt(),
157157
root.get("totalTimeSpentDead").asInt(), root.get("turretTakedowns").asInt(), root.get("turretsLost").asInt(),
158158
root.get("win").asBoolean(), pingStats, root.get("detectorWardsPlaced").asInt(),
159-
root.get("eligibleForProgression").asBoolean(false), challengeStats);
159+
root.get("eligibleForProgression").asBoolean(false), challengeStats,
160+
root.has("placement") ? root.get("placement").asInt() : -1,
161+
root.has("playerAugment1") ? ArenaAugments.getArenaAugment(root.get("playerAugment1").asInt()) : null,
162+
root.has("playerAugment2") ? ArenaAugments.getArenaAugment(root.get("playerAugment2").asInt()) : null,
163+
root.has("playerAugment3") ? ArenaAugments.getArenaAugment(root.get("playerAugment3").asInt()) : null,
164+
root.has("playerAugment4") ? ArenaAugments.getArenaAugment(root.get("playerAugment4").asInt()) : null,
165+
root.has("playerSubteamId") ? root.get("playerSubteamId").asInt() : -1,
166+
root.has("subteamPlacement") ? root.get("subteamPlacement").asInt() : -1);
160167
}
161168
}
162169

@@ -363,7 +370,7 @@ public Team deserialize(JsonParser jp, DeserializationContext ctxt) throws IOExc
363370
JsonNode objectives = root.get("objectives");
364371

365372
Map<Integer, Champion> bans = StreamSupport.stream(root.get("bans").spliterator(), false)
366-
.collect(Collectors.toMap(node -> node.get("pickTurn").asInt(), node -> Champions.getChampion(node.get("championId").asInt())));
373+
.collect(HashMap::new, (map, node) -> map.put(node.get("pickTurn").asInt(), Champions.getChampion(node.get("championId").asInt())), HashMap::putAll);
367374
return new Team(root.get("teamId").asInt(), root.get("win").asBoolean(), reader.readValue(objectives.get("baron")),
368375
reader.readValue(objectives.get("champion")), reader.readValue(objectives.get("dragon")),
369376
reader.readValue(objectives.get("inhibitor")), reader.readValue(objectives.get("riftHerald")),

‎src/main/java/net/petersil98/thresh/model/match/participant/MatchParticipant.java

Lines changed: 165 additions & 120 deletions
Large diffs are not rendered by default.

‎src/main/java/net/petersil98/thresh/util/LoLLoader.java

Lines changed: 20 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -9,11 +9,7 @@
99
import net.petersil98.stcommons.constants.STConstants;
1010
import net.petersil98.thresh.Thresh;
1111
import net.petersil98.thresh.collection.*;
12-
import net.petersil98.thresh.constants.LoLConstants;
13-
import net.petersil98.thresh.data.Challenge;
14-
import net.petersil98.thresh.data.Item;
15-
import net.petersil98.thresh.data.QueueType;
16-
import net.petersil98.thresh.data.SummonerSpell;
12+
import net.petersil98.thresh.data.*;
1713
import net.petersil98.thresh.data.champion.Champion;
1814
import net.petersil98.thresh.data.rune.Rune;
1915
import net.petersil98.thresh.data.rune.RuneStat;
@@ -53,6 +49,7 @@ protected void load() {
5349
loadItems();
5450
loadSummonerSpells();
5551
loadChallenges();
52+
loadArenaAugments();
5653
}
5754

5855
@Override
@@ -160,9 +157,15 @@ private void loadChampions() {
160157
}
161158

162159
private void loadQueueTypes() {
163-
try(InputStream in = new URI(String.format("%squeues.json", LoLConstants.STATIC_DATA_BASE_PATH)).toURL().openStream()) {
164-
List<QueueType> queueTypes = MAPPER.readerForListOf(QueueType.class).readValue(in);
165-
setFieldInCollection(QueueTypes.class, queueTypes.stream().collect(Collectors.toMap(QueueType::getId, queueType -> queueType)));
160+
try(InputStream in = new URI("https://raw.communitydragon.org/latest/plugins/rcp-be-lol-game-data/global/default/v1/queues.json").toURL().openStream()) {
161+
JsonNode root = MAPPER.readTree(in);
162+
Map<Integer, QueueType> queueTypes = new HashMap<>();
163+
root.properties().forEach(entry -> ((ObjectNode)entry.getValue()).put("id", entry.getKey()));
164+
for(JsonNode node: root) {
165+
QueueType queueType = MAPPER.readerFor(QueueType.class).readValue(node);
166+
queueTypes.put(queueType.getId(), queueType);
167+
}
168+
setFieldInCollection(QueueTypes.class, queueTypes);
166169
} catch (IOException | URISyntaxException e) {
167170
e.printStackTrace();
168171
}
@@ -218,6 +221,15 @@ private void loadChallenges() {
218221
}
219222
}
220223

224+
private void loadArenaAugments() {
225+
try(InputStream in = new URI(String.format("https://raw.communitydragon.org/latest/cdragon/arena/%s.json", Settings.getLanguage().toString().toLowerCase())).toURL().openStream()) {
226+
List<ArenaAugment> arenaAugments = MAPPER.readerForListOf(ArenaAugment.class).readValue(MAPPER.readTree(in).get("augments"));
227+
setFieldInCollection(ArenaAugments.class, arenaAugments.stream().collect(Collectors.toMap(ArenaAugment::getId, augment -> augment)));
228+
} catch (IOException | URISyntaxException e) {
229+
e.printStackTrace();
230+
}
231+
}
232+
221233
private void setFieldInCollection(Class<?> collectionClass, Map<?, ?> elements) {
222234
try {
223235
char[] fieldName = collectionClass.getSimpleName().toCharArray();

0 commit comments

Comments
 (0)
Please sign in to comment.