use of net.runelite.http.service.xp.beans.PlayerEntity in project runelite by runelite.
the class XpTrackerService method update.
public void update(String username, HiscoreResult hiscoreResult) {
try (Connection con = sql2o.open()) {
PlayerEntity playerEntity = findOrCreatePlayer(username);
XpEntity currentXp = findXpAtTime(username, Instant.now());
if (currentXp != null) {
XpData hiscoreData = XpMapper.INSTANCE.hiscoreResultToXpData(hiscoreResult);
XpData existingData = XpMapper.INSTANCE.xpEntityToXpData(currentXp);
if (hiscoreData.equals(existingData)) {
log.debug("Hiscore for {} already up to date", username);
return;
}
}
con.createQuery("insert into xp (player,attack_xp,defence_xp,strength_xp,hitpoints_xp,ranged_xp,prayer_xp,magic_xp,cooking_xp,woodcutting_xp," + "fletching_xp,fishing_xp,firemaking_xp,crafting_xp,smithing_xp,mining_xp,herblore_xp,agility_xp,thieving_xp,slayer_xp,farming_xp," + "runecraft_xp,hunter_xp,construction_xp,attack_rank,defence_rank,strength_rank,hitpoints_rank,ranged_rank,prayer_rank,magic_rank," + "cooking_rank,woodcutting_rank,fletching_rank,fishing_rank,firemaking_rank,crafting_rank,smithing_rank,mining_rank,herblore_rank," + "agility_rank,thieving_rank,slayer_rank,farming_rank,runecraft_rank,hunter_rank,construction_rank,overall_rank) values (:player,:attack_xp,:defence_xp," + ":strength_xp,:hitpoints_xp,:ranged_xp,:prayer_xp,:magic_xp,:cooking_xp,:woodcutting_xp,:fletching_xp,:fishing_xp,:firemaking_xp," + ":crafting_xp,:smithing_xp,:mining_xp,:herblore_xp,:agility_xp,:thieving_xp,:slayer_xp,:farming_xp,:runecraft_xp,:hunter_xp," + ":construction_xp,:attack_rank,:defence_rank,:strength_rank,:hitpoints_rank,:ranged_rank,:prayer_rank,:magic_rank,:cooking_rank," + ":woodcutting_rank,:fletching_rank,:fishing_rank,:firemaking_rank,:crafting_rank,:smithing_rank,:mining_rank,:herblore_rank," + ":agility_rank,:thieving_rank,:slayer_rank,:farming_rank,:runecraft_rank,:hunter_rank,:construction_rank,:overall_rank)").addParameter("player", playerEntity.getId()).addParameter("attack_xp", hiscoreResult.getAttack().getExperience()).addParameter("defence_xp", hiscoreResult.getDefence().getExperience()).addParameter("strength_xp", hiscoreResult.getStrength().getExperience()).addParameter("hitpoints_xp", hiscoreResult.getHitpoints().getExperience()).addParameter("ranged_xp", hiscoreResult.getRanged().getExperience()).addParameter("prayer_xp", hiscoreResult.getPrayer().getExperience()).addParameter("magic_xp", hiscoreResult.getMagic().getExperience()).addParameter("cooking_xp", hiscoreResult.getCooking().getExperience()).addParameter("woodcutting_xp", hiscoreResult.getWoodcutting().getExperience()).addParameter("fletching_xp", hiscoreResult.getFletching().getExperience()).addParameter("fishing_xp", hiscoreResult.getFishing().getExperience()).addParameter("firemaking_xp", hiscoreResult.getFiremaking().getExperience()).addParameter("crafting_xp", hiscoreResult.getCrafting().getExperience()).addParameter("smithing_xp", hiscoreResult.getSmithing().getExperience()).addParameter("mining_xp", hiscoreResult.getMining().getExperience()).addParameter("herblore_xp", hiscoreResult.getHerblore().getExperience()).addParameter("agility_xp", hiscoreResult.getAgility().getExperience()).addParameter("thieving_xp", hiscoreResult.getThieving().getExperience()).addParameter("slayer_xp", hiscoreResult.getSlayer().getExperience()).addParameter("farming_xp", hiscoreResult.getFarming().getExperience()).addParameter("runecraft_xp", hiscoreResult.getRunecraft().getExperience()).addParameter("hunter_xp", hiscoreResult.getHunter().getExperience()).addParameter("construction_xp", hiscoreResult.getConstruction().getExperience()).addParameter("attack_rank", hiscoreResult.getAttack().getRank()).addParameter("defence_rank", hiscoreResult.getDefence().getRank()).addParameter("strength_rank", hiscoreResult.getStrength().getRank()).addParameter("hitpoints_rank", hiscoreResult.getHitpoints().getRank()).addParameter("ranged_rank", hiscoreResult.getRanged().getRank()).addParameter("prayer_rank", hiscoreResult.getPrayer().getRank()).addParameter("magic_rank", hiscoreResult.getMagic().getRank()).addParameter("cooking_rank", hiscoreResult.getCooking().getRank()).addParameter("woodcutting_rank", hiscoreResult.getWoodcutting().getRank()).addParameter("fletching_rank", hiscoreResult.getFletching().getRank()).addParameter("fishing_rank", hiscoreResult.getFishing().getRank()).addParameter("firemaking_rank", hiscoreResult.getFiremaking().getRank()).addParameter("crafting_rank", hiscoreResult.getCrafting().getRank()).addParameter("smithing_rank", hiscoreResult.getSmithing().getRank()).addParameter("mining_rank", hiscoreResult.getMining().getRank()).addParameter("herblore_rank", hiscoreResult.getHerblore().getRank()).addParameter("agility_rank", hiscoreResult.getAgility().getRank()).addParameter("thieving_rank", hiscoreResult.getThieving().getRank()).addParameter("slayer_rank", hiscoreResult.getSlayer().getRank()).addParameter("farming_rank", hiscoreResult.getFarming().getRank()).addParameter("runecraft_rank", hiscoreResult.getRunecraft().getRank()).addParameter("hunter_rank", hiscoreResult.getHunter().getRank()).addParameter("construction_rank", hiscoreResult.getConstruction().getRank()).addParameter("overall_rank", hiscoreResult.getOverall().getRank()).executeUpdate();
}
}
use of net.runelite.http.service.xp.beans.PlayerEntity in project runelite by runelite.
the class XpTrackerService method findOrCreatePlayer.
private synchronized PlayerEntity findOrCreatePlayer(String username) {
try (Connection con = sql2o.open()) {
PlayerEntity playerEntity = con.createQuery("select * from player where name = :name").addParameter("name", username).executeAndFetchFirst(PlayerEntity.class);
if (playerEntity != null) {
return playerEntity;
}
Instant now = Instant.now();
int id = con.createQuery("insert into player (name, tracked_since) values (:name, :tracked_since)").addParameter("name", username).addParameter("tracked_since", now).executeUpdate().getKey(int.class);
playerEntity = new PlayerEntity();
playerEntity.setId(id);
playerEntity.setName(username);
playerEntity.setTracked_since(now);
return playerEntity;
}
}
Aggregations