use of no.stelar7.api.r4j.basic.utils.Pair in project L4J8 by stelar7.
the class LCUApi method customUrl.
/**
* Makes a call to a url not specifically supported in the api
*
* @param url the url to call
* @param postData null if not a POST call
* @param method the http method to use
* @return whatever the api returns
*/
public static Object customUrl(String url, String postData, String method) {
Pair<String, String> header = LCUConnection.getAuthorizationHeader();
DataCallBuilder obj = new DataCallBuilder().withLimiters(false).withProxy(LCUConnection.getConnectionString() + url).withPostData(postData).withRequestMethod(method).withHeader(header.getKey(), header.getValue());
return obj.build();
}
use of no.stelar7.api.r4j.basic.utils.Pair in project L4J8 by stelar7.
the class LCUApi method setLobbyPositions.
/**
* Sets your roles in the lobby
* @param primary first role
* @param secondary second role
*/
public static void setLobbyPositions(LCULobbyPositionType primary, LCULobbyPositionType secondary) {
Pair<String, String> header = LCUConnection.getAuthorizationHeader();
StringWriter sw = new StringWriter();
try {
JsonWriter jw = new JsonWriter(sw);
jw.beginObject().name("firstPreference").value(primary.name()).name("secondPreference").value(secondary.name()).endObject();
} catch (IOException e) {
e.printStackTrace();
}
String postData = sw.toString();
JsonObject obj = (JsonObject) new DataCallBuilder().withLimiters(false).withProxy(LCUConnection.getConnectionString() + Constants.GSVR).withEndpoint(URLEndpoint.LCU_LOBBY_POSITION).withRequestMethod("PUT").withPostData(postData).withHeader(header.getKey(), header.getValue()).build();
}
use of no.stelar7.api.r4j.basic.utils.Pair in project L4J8 by stelar7.
the class MasteryAPI method getChampionMastery.
/**
* The response object contains the summoners mastery of a champion.
* Only championid and summonerid is present if the level == 0
*
* @param server the region to execute against
* @param summonerId the summonerId
* @param championId the championId
* @return Optional ChampionMastery
*/
public ChampionMastery getChampionMastery(LeagueShard server, String summonerId, int championId) {
DataCallBuilder builder = new DataCallBuilder().withURLParameter(Constants.SUMMONER_ID_PLACEHOLDER, summonerId).withURLParameter(Constants.CHAMPION_ID_PLACEHOLDER, String.valueOf(championId)).withEndpoint(URLEndpoint.V4_MASTERY_BY_CHAMPION).withPlatform(server);
Map<String, Object> data = new TreeMap<>();
data.put("platform", server);
data.put("id", summonerId);
data.put("champion", championId);
Optional<?> chl = DataCall.getCacheProvider().get(URLEndpoint.V4_MASTERY_BY_CHAMPION, data);
if (chl.isPresent()) {
return (ChampionMastery) chl.get();
}
Object masteryObj = builder.build();
if (masteryObj instanceof Pair) {
try {
ChampionMastery mastery = new ChampionMastery();
Field player = mastery.getClass().getDeclaredField("playerId");
player.setAccessible(true);
player.set(mastery, summonerId);
Field champ = mastery.getClass().getDeclaredField("championId");
champ.setAccessible(true);
champ.set(mastery, championId);
Field level = mastery.getClass().getDeclaredField("championLevel");
level.setAccessible(true);
level.set(mastery, 0);
data.put("value", mastery);
DataCall.getCacheProvider().store(URLEndpoint.V4_MASTERY_BY_CHAMPION, data);
return mastery;
} catch (NoSuchFieldException | IllegalAccessException e) {
Logger.getGlobal().warning("Class has changed, please fix me");
}
}
data.put("value", masteryObj);
DataCall.getCacheProvider().store(URLEndpoint.V4_MASTERY_BY_CHAMPION, data);
return (ChampionMastery) masteryObj;
}
use of no.stelar7.api.r4j.basic.utils.Pair in project L4J8 by stelar7.
the class LCUApi method restart.
/**
* Restarts the client after waitTimeout seconds
* @param waitTimeout the time to wait in seconds
*/
public static void restart(int waitTimeout) {
Pair<String, String> header = LCUConnection.getAuthorizationHeader();
new DataCallBuilder().withLimiters(false).withProxy(LCUConnection.getConnectionString() + Constants.GSVR).withEndpoint(URLEndpoint.LCU_RESTART).withHeader(header.getKey(), header.getValue()).withQueryParameter("delaySeconds", String.valueOf(waitTimeout)).withRequestMethod("POST").build();
}
use of no.stelar7.api.r4j.basic.utils.Pair in project L4J8 by stelar7.
the class LCUApi method inviteSummoner.
/**
* Invites the summoner to your game
* @param name the name
*/
public static void inviteSummoner(String name) {
StringWriter sw = new StringWriter();
try {
JsonWriter jw = new JsonWriter(sw);
JsonObject obj = getSummoner(name);
jw.beginArray().beginObject().name("toSummonerId").value(obj.get("summonerId").getAsString()).name("toSummonerName").value(obj.get("internalName").getAsString()).endObject().endArray();
} catch (IOException e) {
e.printStackTrace();
}
String postData = sw.toString();
Pair<String, String> header = LCUConnection.getAuthorizationHeader();
JsonArray obj = (JsonArray) new DataCallBuilder().withLimiters(false).withProxy(LCUConnection.getConnectionString() + Constants.GSVR).withEndpoint(URLEndpoint.LCU_LOBBY_INVITE).withRequestMethod("POST").withHeader(header.getKey(), header.getValue()).withPostData(postData).build();
}
Aggregations