Skip to content

Commit 8aa8b63

Browse files
committed
Adapted to changes in Core. Updated to Java Version 20. Updated readme
1 parent 1371cb0 commit 8aa8b63

File tree

17 files changed

+104
-129
lines changed

17 files changed

+104
-129
lines changed

README.md

Lines changed: 19 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,12 @@
11
# Thresh
22

33
Thresh is an Object-Oriented Java Library, which takes over the Communication
4-
with the League of Legends API. It makes retrieving Summoner Data, Match History,
4+
with the League of Legends API. It supports In-Memory caching and uses a (blocking) Rate Limiter. It makes retrieving Summoner Data, Match History,
55
etc. much easier. For Teamfight Tactics take a look at [Spatula](https://github.com/Petersil1998/Spatula)
66

77
## Usage
88

9-
In Order for Thresh to work properly there are a few things you need to set up/call
9+
In Order for Thresh to work properly there are a few things you need to set up
1010
at the beginning of your application.
1111

1212
```JAVA
@@ -16,11 +16,10 @@ public class Example {
1616
Settings.setAPIKey(() -> EncryptionUtil.encrypt(System.getenv("API_KEY")));
1717
// If the provided API Key is encrypted, we need to provide a function to decrypt the API Key
1818
Settings.setDecryptor(EncryptionUtil::decrypt);
19-
// We also need to set a Server Configuration consisting of a platform (e.g. EUW) and a region (e.g. EUROPE).
20-
// Some predefined Configurations can be found in the ServerConfig class
21-
Settings.setServerConfig(ServerConfig.EUW_CONFIG);
2219
// We also need to provide a language. The language is used to static Data like Champions, Item, etc.
2320
Settings.setLanguage(Language.EN_US);
21+
// If we want to use caching we can enable it in the Settings. Caching is disabled by default
22+
Settings.useCache(true);
2423
// We also need to add the Loader for the static LoL Data
2524
Loader.addLoader(new LoLLoader());
2625
// Lastly we need to initialize the static Data
@@ -40,12 +39,12 @@ Now Thresh is ready and set up!
4039
public static void main(String[] args) {
4140
// Setup code...
4241

43-
Summoner faker = Summoner.getSummonerByName("Faker");
42+
Summoner faker = Summoner.getSummonerByName("Faker", Platform.KR);
4443
int summonerLevel = faker.getSummonerLevel();
4544
// Get the URL for the profile Icon
4645
String profileIconURL = Util.getProfileIconURL(faker.getProfileIcon());
4746
// Get Account
48-
Account account = faker.getAccount();
47+
Account account = Account.getAccountByPuuid(faker.getPuuid(), Region.ASIA);
4948
// Get the Tag (e.g. Faker#KR1)
5049
String tag = account.toString();
5150
}
@@ -59,8 +58,8 @@ Now Thresh is ready and set up!
5958
public static void main(String[] args) {
6059
// Setup code...
6160

62-
Summoner faker = Summoner.getSummonerByName("Faker");
63-
ChampionMasteries masteries = ChampionMasteries.getChampionMasteriesOfSummoner(faker.getId());
61+
Summoner faker = Summoner.getSummonerByName("Faker", Platform.KR);
62+
ChampionMasteries masteries = ChampionMasteries.getChampionMasteriesOfSummoner(faker.getId(), Platform.KR);
6463
// Get Mastery Score
6564
int masteryScore = masteries.getTotalMasteryPoints();
6665
// Get Mastery Points on all Champions Combined
@@ -86,24 +85,24 @@ Now Thresh is ready and set up!
8685
public static void main(String[] args) {
8786
// Setup code...
8887

89-
Summoner faker = Summoner.getSummonerByName("Faker");
88+
Summoner faker = Summoner.getSummonerByName("Faker", Platform.KR);
9089
// Get Solo/Duo and Flex Rank
91-
LoLRanked ranked = LoLRanked.getLoLRanksOfSummoner(faker.getId());
90+
LoLRanked ranked = LoLRanked.getLoLRanksOfSummoner(faker.getId(), Platform.KR);
9291
RankEntry soloDuo = ranked.getRankSoloDuo();
9392
int lp = soloDuo.getLeaguePoints();
9493
RankEntry flex = ranked.getRankFlex5v5();
9594

9695
// Get Challenger Solo Queue Players
97-
League challengers = LoLRanked.getChallengerLeague(RankedQueue.SOLO_DUO);
96+
League challengers = LoLRanked.getChallengerLeague(RankedQueue.SOLO_DUO, Platform.EUW);
9897
for(LeagueEntry leagueEntry: challengers.getEntries()) {
9998
// Get all players and their LP
100-
Summoner player = leagueEntry.getSummoner();
99+
Summoner player = Summoner.getSummonerByID(leagueEntry.getSummonerId(), Platform.EUW)
101100
int playerLp = leagueEntry.getLeaguePoints();
102101
}
103102

104103
// Get a list of Gold 1 Flex Players
105-
List<RankEntry> firstPage = LoLRanked.getRankEntries(RankedDivision.I, RankedTier.GOLD, RankedQueue.FLEX);
106-
List<RankEntry> secondPage = LoLRanked.getRankEntries(RankedDivision.I, RankedTier.GOLD, RankedQueue.FLEX, 2);
104+
List<RankEntry> firstPage = LoLRanked.getRankEntries(RankedDivision.I, RankedTier.GOLD, RankedQueue.FLEX, Platform.NA);
105+
List<RankEntry> secondPage = LoLRanked.getRankEntries(RankedDivision.I, RankedTier.GOLD, RankedQueue.FLEX, Platform.NA, 2);
107106
}
108107
}
109108
```
@@ -115,14 +114,14 @@ Now Thresh is ready and set up!
115114
public static void main(String[] args) {
116115
// Setup code...
117116

118-
Summoner faker = Summoner.getSummonerByName("Faker");
117+
Summoner faker = Summoner.getSummonerByName("Faker", Platform.NA);
119118
// Get Active Game of a given Summoner
120-
ActiveGame game = ActiveGame.ofSummoner(faker.getId());
119+
ActiveGame game = ActiveGame.ofSummoner(faker.getId(), Platform.NA);
121120
Map map = game.getMap();
122121
String gameMode = game.getGameMode();
123122
int duration = game.getDuration();
124123
// Get all Players of the blue Side Team
125-
List<Participants> blueTeam = game.getBlueSideTeam();
124+
List<Participant> blueTeam = game.getBlueSideTeam();
126125
// Get a String, that can be entered in the Windows Commandline to spectate the Game
127126
String cmd = game.getSpectatorCommandWindows("C:\\");
128127
}
@@ -136,9 +135,9 @@ Now Thresh is ready and set up!
136135
public static void main(String[] args) {
137136
// Setup code...
138137

139-
Summoner faker = Summoner.getSummonerByName("Faker");
138+
Summoner faker = Summoner.getSummonerByName("Faker", Platform.NA);
140139
// Get the Player's Match History. The Seconds Parameter is a Filter.
141-
List<MatchDetails> matchHistory = MatchDetails.getMatchHistory(me, Map.of());
140+
List<MatchDetails> matchHistory = MatchDetails.getMatchHistory(faker.getId(), Region.ASIA, Map.of());
142141
MatchDetails latestGame = matchHistory.get(0);
143142
int duration = latestGame.getGameDuration();
144143
// Get Team-based Info like bans, barons killed, turrets killed, etc.

build.gradle

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ plugins {
33
}
44

55
group 'net.petersil98'
6-
version '1.0'
6+
version '1.1'
77

88
allprojects {
99
repositories {

data/lol/champions.json

Lines changed: 1 addition & 1 deletion
Large diffs are not rendered by default.

data/lol/items.json

Lines changed: 1 addition & 1 deletion
Large diffs are not rendered by default.

data/lol/maps.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
{"type":"map","version":"13.12.1","data":{"11":{"MapName":"Summoner's Rift","MapId":"11","image":{"full":"map11.png","sprite":"map0.png","group":"map","x":0,"y":0,"w":48,"h":48}},"12":{"MapName":"Howling Abyss","MapId":"12","image":{"full":"map12.png","sprite":"map0.png","group":"map","x":48,"y":0,"w":48,"h":48}},"21":{"MapName":"Nexus Blitz","MapId":"21","image":{"full":"map21.png","sprite":"map0.png","group":"map","x":96,"y":0,"w":48,"h":48}},"22":{"MapName":"Teamfight Tactics","MapId":"22","image":{"full":"map22.png","sprite":"map0.png","group":"map","x":144,"y":0,"w":48,"h":48}}}}
1+
{"type":"map","version":"13.13.1","data":{"11":{"MapName":"Summoner's Rift","MapId":"11","image":{"full":"map11.png","sprite":"map0.png","group":"map","x":0,"y":0,"w":48,"h":48}},"12":{"MapName":"Howling Abyss","MapId":"12","image":{"full":"map12.png","sprite":"map0.png","group":"map","x":48,"y":0,"w":48,"h":48}},"21":{"MapName":"Nexus Blitz","MapId":"21","image":{"full":"map21.png","sprite":"map0.png","group":"map","x":96,"y":0,"w":48,"h":48}},"22":{"MapName":"Teamfight Tactics","MapId":"22","image":{"full":"map22.png","sprite":"map0.png","group":"map","x":144,"y":0,"w":48,"h":48}}}}

data/settings.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
{"ddragonVersion":"13.12.1","language":"en_US"}
1+
{"ddragonVersion":"13.13.1","language":"en_US"}
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
distributionBase=GRADLE_USER_HOME
22
distributionPath=wrapper/dists
3-
distributionUrl=https\://services.gradle.org/distributions/gradle-8.0-bin.zip
3+
distributionUrl=https\://services.gradle.org/distributions/gradle-8.1-bin.zip
44
zipStoreBase=GRADLE_USER_HOME
55
zipStorePath=wrapper/dists

src/main/java/net/petersil98/thresh/Thresh.java

Lines changed: 11 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,9 @@
11
package net.petersil98.thresh;
22

3-
import net.petersil98.core.constant.RankedDivision;
4-
import net.petersil98.core.constant.RankedQueue;
5-
import net.petersil98.core.constant.RankedTier;
3+
import net.petersil98.core.constant.*;
64
import net.petersil98.core.util.EncryptionUtil;
75
import net.petersil98.core.util.Loader;
86
import net.petersil98.core.util.settings.Language;
9-
import net.petersil98.core.util.settings.ServerConfig;
107
import net.petersil98.core.util.settings.Settings;
118
import net.petersil98.stcommons.model.Summoner;
129
import net.petersil98.stcommons.model.league.League;
@@ -31,29 +28,26 @@ public class Thresh {
3128
public static void main(String[] args) {
3229
Settings.setAPIKey(() -> EncryptionUtil.encrypt(System.getenv("API_KEY")));
3330
Settings.setDecryptor(EncryptionUtil::decrypt);
34-
Settings.setServerConfig(ServerConfig.EUW_CONFIG);
3531
Settings.setLanguage(Language.EN_US);
32+
Settings.useCache(true);
3633
Loader.addLoader(new LoLLoader());
3734
Loader.init();
38-
Summoner me = Summoner.getSummonerByName("Petersil98");
39-
List<MatchDetails> matchHistory = MatchDetails.getMatchHistory(me, Map.of());
35+
Summoner me = Summoner.getSummonerByName("Petersil98", Platform.EUW);
36+
List<MatchDetails> matchHistory = MatchDetails.getMatchHistory(me.getPuuid(), Region.EUROPE, Map.of());
4037
matchHistory.stream().map(MatchDetails::getQueueType).forEach(System.out::println);
41-
System.out.println(me.getPuuid());
42-
ChampionMasteries masteries = ChampionMasteries.getChampionMasteriesOfSummoner(me.getId());
38+
ChampionMasteries masteries = ChampionMasteries.getChampionMasteriesOfSummoner(me.getId(), Platform.EUW);
4339
System.out.println(masteries.getTotalMasteryPoints());
4440
System.out.println(masteries.getTotalMasteryPointsCombined());
4541
System.out.println(masteries.getChampionMasteries());
46-
LoLRanked ranked = LoLRanked.getLoLRanksOfSummoner(me.getId());
42+
LoLRanked ranked = LoLRanked.getLoLRanksOfSummoner(me.getId(), Platform.EUW);
4743
System.out.println(ranked.getRankFlex5v5());
4844
System.out.println(ranked.getRankSoloDuo());
49-
System.out.println(me.getAccount());
50-
System.out.println(me);
51-
League league = LoLRanked.getLeagueById(ranked.getRankSoloDuo().getLeagueId());
52-
League challengers = LoLRanked.getChallengerLeague(RankedQueue.FLEX);
53-
List<RankEntry> leagueEntries = LoLRanked.getRankEntries(RankedDivision.I, RankedTier.BRONZE, RankedQueue.FLEX, 2);
54-
MatchDetails details = MatchDetails.getMatchDetails("EUW1_987654321");
45+
League league = LoLRanked.getLeagueById(ranked.getRankSoloDuo().getLeagueId(), Platform.EUW);
46+
League challengers = LoLRanked.getChallengerLeague(RankedQueue.SOLO_DUO, Platform.EUW);
47+
List<RankEntry> leagueEntries = LoLRanked.getRankEntries(RankedDivision.I, RankedTier.BRONZE, RankedQueue.FLEX, Platform.EUW);
48+
MatchDetails details = MatchDetails.getMatchDetails("EUW1_987654321", Region.EUROPE);
5549
System.out.println(Util.getChallengeIconURL(Challenges.getChallenges().stream().filter(challenge -> !challenge.getLevelToIconPath().isEmpty()).findAny().get(), RankedTier.BRONZE));
56-
ActiveGame game = ActiveGame.ofSummoner(Summoner.getSummonerByName("madlife"));
50+
ActiveGame game = ActiveGame.ofSummoner(Summoner.getSummonerByName("katikaze", Platform.EUW).getId(), Platform.EUW);
5751
System.out.println(game.getSpectatorCommandWindows("C:\\"));
5852
System.out.println(Util.getProfileIconURL(me.getProfileIcon()));
5953
System.out.println(Util.getChampionIconURL(Champions.getChampionByName("Thresh")));

src/main/java/net/petersil98/thresh/model/ChampionMasteries.java

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,8 @@
22

33
import com.fasterxml.jackson.databind.annotation.JsonDeserialize;
44
import com.fasterxml.jackson.databind.type.TypeFactory;
5-
import net.petersil98.core.http.RiotAPIRequest;
5+
import net.petersil98.core.constant.Platform;
6+
import net.petersil98.core.http.RiotAPI;
67
import net.petersil98.thresh.data.champion.Champion;
78

89
import java.util.List;
@@ -11,27 +12,29 @@
1112
public class ChampionMasteries {
1213

1314
private final String summonerId;
15+
private final Platform platform;
1416
private List<Mastery> masteries;
1517
private int totalMasteryPoints = -1;
1618

17-
private ChampionMasteries(String summonerId) {
19+
private ChampionMasteries(String summonerId, Platform platform) {
1820
this.summonerId = summonerId;
21+
this.platform = platform;
1922
}
2023

21-
public static ChampionMasteries getChampionMasteriesOfSummoner(String summonerId) {
22-
return new ChampionMasteries(summonerId);
24+
public static ChampionMasteries getChampionMasteriesOfSummoner(String summonerId, Platform platform) {
25+
return new ChampionMasteries(summonerId, platform);
2326
}
2427

2528
public int getTotalMasteryPoints() {
2629
if(this.totalMasteryPoints == -1) {
27-
this.totalMasteryPoints = RiotAPIRequest.requestLoLChampionMasteryEndpoint("scores/by-summoner/" + this.summonerId, Integer.class);
30+
this.totalMasteryPoints = RiotAPI.requestLoLChampionMasteryEndpoint("scores/by-summoner/", this.summonerId, this.platform, Integer.class);
2831
}
2932
return this.totalMasteryPoints;
3033
}
3134

3235
public List<Mastery> getChampionMasteries() {
3336
if(this.masteries == null) {
34-
this.masteries = RiotAPIRequest.requestLoLChampionMasteryEndpoint("champion-masteries/by-summoner/" + this.summonerId, TypeFactory.defaultInstance().constructCollectionType(List.class, Mastery.class));
37+
this.masteries = RiotAPI.requestLoLChampionMasteryEndpoint("champion-masteries/by-summoner/", this.summonerId, this.platform, TypeFactory.defaultInstance().constructCollectionType(List.class, Mastery.class));
3538
}
3639
return this.masteries;
3740
}

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

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@
44
import com.fasterxml.jackson.databind.*;
55
import com.fasterxml.jackson.databind.type.TypeFactory;
66
import net.petersil98.core.constant.Platform;
7-
import net.petersil98.stcommons.model.Summoner;
87
import net.petersil98.thresh.collection.*;
98
import net.petersil98.thresh.data.champion.Champion;
109
import net.petersil98.thresh.data.rune.BaseRune;
@@ -53,7 +52,7 @@ public Participant deserialize(JsonParser jp, DeserializationContext ctxt) throw
5352
if (rune == null) rune = RuneStats.getRuneStat(node.asInt());
5453
runes.add(rune);
5554
}
56-
return new Participant(Summoner.getSummonerByID(root.get("summonerId").asText()), root.get("bot").asBoolean(),
55+
return new Participant(root.get("summonerId").asText(), root.get("bot").asBoolean(),
5756
Champions.getChampion(root.get("championId").asInt()), root.get("teamId").asInt(),
5857
SummonerSpells.getSummonerSpell(root.get("spell1Id").asInt()), SummonerSpells.getSummonerSpell(root.get("spell2Id").asInt()),
5958
runes, RuneStyles.getRuneStyle(perks.get("perkStyle").asInt()), RuneStyles.getRuneStyle(perks.get("perkSubStyle").asInt()));
@@ -80,8 +79,9 @@ public ActiveGame deserialize(JsonParser jp, DeserializationContext ctxt) throws
8079
root.get("gameType").asText(), QueueTypes.getQueueType(root.get("gameQueueConfigId").asInt()),
8180
participants.stream().filter(participant -> participant.getTeamId() == 100).toList(),
8281
participants.stream().filter(participant -> participant.getTeamId() == 200).toList(),
83-
participants.size() / 2, bans, root.get("observers").get("encryptionKey").asText(), root.get("platformId").asText(),
84-
root.get("gameStartTime").asInt(), root.get("gameLength").asInt());
82+
participants.size() / 2, bans, root.get("observers").get("encryptionKey").asText(),
83+
Platform.getPlatform(root.get("platformId").asText()), root.get("gameStartTime").asInt(),
84+
root.get("gameLength").asInt());
8585
}
8686
}
8787

0 commit comments

Comments
 (0)