Move hiscore client to rl-client
Thie removes the http-service hiscore api, which we haven't used in awhile and doesn't work in practice due to upstream rate limits, as well as the xp tracker which also hasn't been used in a long time since there are now multiple quality community run xptrackers.
This commit is contained in:
@@ -118,13 +118,6 @@ public class SpringBootWebApplication extends SpringBootServletInitializer
|
||||
return new DataSourceProperties();
|
||||
}
|
||||
|
||||
@ConfigurationProperties(prefix = "datasource.runelite-tracker")
|
||||
@Bean("dataSourceRuneLiteTracker")
|
||||
public DataSourceProperties dataSourcePropertiesTracker()
|
||||
{
|
||||
return new DataSourceProperties();
|
||||
}
|
||||
|
||||
@Bean(value = "runelite", destroyMethod = "")
|
||||
public DataSource runeliteDataSource(@Qualifier("dataSourceRuneLite") DataSourceProperties dataSourceProperties)
|
||||
{
|
||||
@@ -137,12 +130,6 @@ public class SpringBootWebApplication extends SpringBootServletInitializer
|
||||
return getDataSource(dataSourceProperties);
|
||||
}
|
||||
|
||||
@Bean(value = "runelite-tracker", destroyMethod = "")
|
||||
public DataSource runeliteTrackerDataSource(@Qualifier("dataSourceRuneLiteTracker") DataSourceProperties dataSourceProperties)
|
||||
{
|
||||
return getDataSource(dataSourceProperties);
|
||||
}
|
||||
|
||||
@Bean("Runelite SQL2O")
|
||||
public Sql2o sql2o(@Qualifier("runelite") DataSource dataSource)
|
||||
{
|
||||
@@ -155,12 +142,6 @@ public class SpringBootWebApplication extends SpringBootServletInitializer
|
||||
return createSql2oFromDataSource(dataSource);
|
||||
}
|
||||
|
||||
@Bean("Runelite XP Tracker SQL2O")
|
||||
public Sql2o trackerSql2o(@Qualifier("runelite-tracker") DataSource dataSource)
|
||||
{
|
||||
return createSql2oFromDataSource(dataSource);
|
||||
}
|
||||
|
||||
@Bean(destroyMethod = "")
|
||||
public MongoClient mongoClient(@Value("${mongo.host:}") String host, @Value("${mongo.jndiName:}") String jndiName) throws NamingException
|
||||
{
|
||||
|
||||
@@ -1,96 +0,0 @@
|
||||
/*
|
||||
* Copyright (c) 2017, Adam <Adam@sigterm.info>
|
||||
* All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions are met:
|
||||
*
|
||||
* 1. Redistributions of source code must retain the above copyright notice, this
|
||||
* list of conditions and the following disclaimer.
|
||||
* 2. Redistributions in binary form must reproduce the above copyright notice,
|
||||
* this list of conditions and the following disclaimer in the documentation
|
||||
* and/or other materials provided with the distribution.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
|
||||
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
|
||||
* WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
|
||||
* DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR
|
||||
* ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
|
||||
* (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
|
||||
* LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
|
||||
* ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
||||
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
|
||||
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
*/
|
||||
package net.runelite.http.service.hiscore;
|
||||
|
||||
import java.util.concurrent.ExecutionException;
|
||||
import net.runelite.http.api.hiscore.HiscoreEndpoint;
|
||||
import net.runelite.http.api.hiscore.HiscoreResult;
|
||||
import net.runelite.http.api.hiscore.HiscoreSkill;
|
||||
import net.runelite.http.api.hiscore.SingleHiscoreSkillResult;
|
||||
import net.runelite.http.api.hiscore.Skill;
|
||||
import net.runelite.http.service.util.HiscoreEndpointEditor;
|
||||
import net.runelite.http.service.xp.XpTrackerService;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.web.bind.WebDataBinder;
|
||||
import org.springframework.web.bind.annotation.GetMapping;
|
||||
import org.springframework.web.bind.annotation.InitBinder;
|
||||
import org.springframework.web.bind.annotation.PathVariable;
|
||||
import org.springframework.web.bind.annotation.RequestMapping;
|
||||
import org.springframework.web.bind.annotation.RequestParam;
|
||||
import org.springframework.web.bind.annotation.RestController;
|
||||
|
||||
@RestController
|
||||
@RequestMapping("/hiscore")
|
||||
public class HiscoreController
|
||||
{
|
||||
@Autowired
|
||||
private HiscoreService hiscoreService;
|
||||
|
||||
@Autowired
|
||||
private XpTrackerService xpTrackerService;
|
||||
|
||||
@GetMapping("/{endpoint}")
|
||||
public HiscoreResult lookup(@PathVariable HiscoreEndpoint endpoint, @RequestParam String username) throws ExecutionException
|
||||
{
|
||||
HiscoreResult result = hiscoreService.lookupUsername(username, endpoint);
|
||||
|
||||
// Submit to xp tracker?
|
||||
switch (endpoint)
|
||||
{
|
||||
case NORMAL:
|
||||
case IRONMAN:
|
||||
case ULTIMATE_IRONMAN:
|
||||
case HARDCORE_IRONMAN:
|
||||
xpTrackerService.update(username, result);
|
||||
}
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
@GetMapping("/{endpoint}/{skillName}")
|
||||
public SingleHiscoreSkillResult singleSkillLookup(@PathVariable HiscoreEndpoint endpoint, @PathVariable String skillName, @RequestParam String username) throws ExecutionException
|
||||
{
|
||||
HiscoreSkill skill = HiscoreSkill.valueOf(skillName.toUpperCase());
|
||||
|
||||
// RS api only supports looking up all stats
|
||||
HiscoreResult result = hiscoreService.lookupUsername(username, endpoint);
|
||||
|
||||
// Find the skill to return
|
||||
Skill requested = result.getSkill(skill);
|
||||
|
||||
SingleHiscoreSkillResult skillResult = new SingleHiscoreSkillResult();
|
||||
skillResult.setPlayer(username);
|
||||
skillResult.setSkillName(skillName);
|
||||
skillResult.setSkill(requested);
|
||||
|
||||
return skillResult;
|
||||
}
|
||||
|
||||
@InitBinder
|
||||
public void initBinder(WebDataBinder binder)
|
||||
{
|
||||
binder.registerCustomEditor(HiscoreEndpoint.class, new HiscoreEndpointEditor());
|
||||
}
|
||||
}
|
||||
@@ -1,36 +0,0 @@
|
||||
/*
|
||||
* Copyright (c) 2018, Adam <Adam@sigterm.info>
|
||||
* All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions are met:
|
||||
*
|
||||
* Redistributions of source code must retain the above copyright notice, this
|
||||
* list of conditions and the following disclaimer.
|
||||
*
|
||||
* Redistributions in binary form must reproduce the above copyright notice,
|
||||
* this list of conditions and the following disclaimer in the documentation
|
||||
* and/or other materials provided with the distribution.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
|
||||
* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
||||
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
|
||||
* DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
|
||||
* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
|
||||
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
|
||||
* SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
|
||||
* CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
|
||||
* OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
|
||||
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
*/
|
||||
package net.runelite.http.service.hiscore;
|
||||
|
||||
import lombok.Value;
|
||||
import net.runelite.http.api.hiscore.HiscoreEndpoint;
|
||||
|
||||
@Value
|
||||
class HiscoreKey
|
||||
{
|
||||
String username;
|
||||
HiscoreEndpoint endpoint;
|
||||
}
|
||||
@@ -1,68 +0,0 @@
|
||||
/*
|
||||
* Copyright (c) 2017, Adam <Adam@sigterm.info>
|
||||
* All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions are met:
|
||||
*
|
||||
* 1. Redistributions of source code must retain the above copyright notice, this
|
||||
* list of conditions and the following disclaimer.
|
||||
* 2. Redistributions in binary form must reproduce the above copyright notice,
|
||||
* this list of conditions and the following disclaimer in the documentation
|
||||
* and/or other materials provided with the distribution.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
|
||||
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
|
||||
* WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
|
||||
* DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR
|
||||
* ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
|
||||
* (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
|
||||
* LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
|
||||
* ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
||||
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
|
||||
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
*/
|
||||
package net.runelite.http.service.hiscore;
|
||||
|
||||
import com.google.common.annotations.VisibleForTesting;
|
||||
import com.google.common.cache.CacheBuilder;
|
||||
import com.google.common.cache.CacheLoader;
|
||||
import com.google.common.cache.LoadingCache;
|
||||
import java.io.IOException;
|
||||
import java.util.concurrent.ExecutionException;
|
||||
import java.util.concurrent.TimeUnit;
|
||||
import net.runelite.http.api.RuneLiteAPI;
|
||||
import net.runelite.http.api.hiscore.HiscoreClient;
|
||||
import net.runelite.http.api.hiscore.HiscoreEndpoint;
|
||||
import net.runelite.http.api.hiscore.HiscoreResult;
|
||||
import okhttp3.HttpUrl;
|
||||
import org.springframework.stereotype.Service;
|
||||
|
||||
@Service
|
||||
public class HiscoreService
|
||||
{
|
||||
private final HiscoreClient hiscoreClient = new HiscoreClient(RuneLiteAPI.CLIENT);
|
||||
private final LoadingCache<HiscoreKey, HiscoreResult> hiscoreCache = CacheBuilder.newBuilder()
|
||||
.maximumSize(128)
|
||||
.expireAfterWrite(1, TimeUnit.MINUTES)
|
||||
.build(
|
||||
new CacheLoader<HiscoreKey, HiscoreResult>()
|
||||
{
|
||||
@Override
|
||||
public HiscoreResult load(HiscoreKey key) throws IOException
|
||||
{
|
||||
return hiscoreClient.lookup(key.getUsername(), key.getEndpoint());
|
||||
}
|
||||
});
|
||||
|
||||
@VisibleForTesting
|
||||
HiscoreResult lookupUsername(String username, HttpUrl httpUrl) throws IOException
|
||||
{
|
||||
return hiscoreClient.lookup(username, httpUrl);
|
||||
}
|
||||
|
||||
public HiscoreResult lookupUsername(String username, HiscoreEndpoint endpoint) throws ExecutionException
|
||||
{
|
||||
return hiscoreCache.get(new HiscoreKey(username, endpoint));
|
||||
}
|
||||
}
|
||||
@@ -1,40 +0,0 @@
|
||||
/*
|
||||
* Copyright (c) 2017, Adam <Adam@sigterm.info>
|
||||
* All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions are met:
|
||||
*
|
||||
* Redistributions of source code must retain the above copyright notice, this
|
||||
* list of conditions and the following disclaimer.
|
||||
*
|
||||
* Redistributions in binary form must reproduce the above copyright notice,
|
||||
* this list of conditions and the following disclaimer in the documentation
|
||||
* and/or other materials provided with the distribution.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
|
||||
* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
||||
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
|
||||
* DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
|
||||
* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
|
||||
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
|
||||
* SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
|
||||
* CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
|
||||
* OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
|
||||
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
*/
|
||||
|
||||
package net.runelite.http.service.util;
|
||||
|
||||
import net.runelite.http.api.hiscore.HiscoreEndpoint;
|
||||
|
||||
import java.beans.PropertyEditorSupport;
|
||||
|
||||
public class HiscoreEndpointEditor extends PropertyEditorSupport
|
||||
{
|
||||
@Override
|
||||
public void setAsText(String text) throws IllegalArgumentException
|
||||
{
|
||||
setValue(HiscoreEndpoint.valueOf(text.toUpperCase()));
|
||||
}
|
||||
}
|
||||
@@ -1,92 +0,0 @@
|
||||
/*
|
||||
* Copyright (c) 2018, Adam <Adam@sigterm.info>
|
||||
* All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions are met:
|
||||
*
|
||||
* 1. Redistributions of source code must retain the above copyright notice, this
|
||||
* list of conditions and the following disclaimer.
|
||||
* 2. Redistributions in binary form must reproduce the above copyright notice,
|
||||
* this list of conditions and the following disclaimer in the documentation
|
||||
* and/or other materials provided with the distribution.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
|
||||
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
|
||||
* WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
|
||||
* DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR
|
||||
* ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
|
||||
* (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
|
||||
* LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
|
||||
* ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
||||
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
|
||||
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
*/
|
||||
package net.runelite.http.service.xp;
|
||||
|
||||
import net.runelite.http.api.hiscore.HiscoreResult;
|
||||
import net.runelite.http.api.xp.XpData;
|
||||
import net.runelite.http.service.xp.beans.XpEntity;
|
||||
import org.mapstruct.Mapper;
|
||||
import org.mapstruct.Mapping;
|
||||
import org.mapstruct.factory.Mappers;
|
||||
|
||||
@Mapper
|
||||
public interface XpMapper
|
||||
{
|
||||
XpMapper INSTANCE = Mappers.getMapper(XpMapper.class);
|
||||
|
||||
XpData xpEntityToXpData(XpEntity xpEntity);
|
||||
|
||||
@Mapping(target = "time", ignore = true)
|
||||
|
||||
@Mapping(source = "attack.experience", target = "attack_xp")
|
||||
@Mapping(source = "defence.experience", target = "defence_xp")
|
||||
@Mapping(source = "strength.experience", target = "strength_xp")
|
||||
@Mapping(source = "hitpoints.experience", target = "hitpoints_xp")
|
||||
@Mapping(source = "ranged.experience", target = "ranged_xp")
|
||||
@Mapping(source = "prayer.experience", target = "prayer_xp")
|
||||
@Mapping(source = "magic.experience", target = "magic_xp")
|
||||
@Mapping(source = "cooking.experience", target = "cooking_xp")
|
||||
@Mapping(source = "woodcutting.experience", target = "woodcutting_xp")
|
||||
@Mapping(source = "fletching.experience", target = "fletching_xp")
|
||||
@Mapping(source = "fishing.experience", target = "fishing_xp")
|
||||
@Mapping(source = "firemaking.experience", target = "firemaking_xp")
|
||||
@Mapping(source = "crafting.experience", target = "crafting_xp")
|
||||
@Mapping(source = "smithing.experience", target = "smithing_xp")
|
||||
@Mapping(source = "mining.experience", target = "mining_xp")
|
||||
@Mapping(source = "herblore.experience", target = "herblore_xp")
|
||||
@Mapping(source = "agility.experience", target = "agility_xp")
|
||||
@Mapping(source = "thieving.experience", target = "thieving_xp")
|
||||
@Mapping(source = "slayer.experience", target = "slayer_xp")
|
||||
@Mapping(source = "farming.experience", target = "farming_xp")
|
||||
@Mapping(source = "runecraft.experience", target = "runecraft_xp")
|
||||
@Mapping(source = "hunter.experience", target = "hunter_xp")
|
||||
@Mapping(source = "construction.experience", target = "construction_xp")
|
||||
|
||||
@Mapping(source = "overall.rank", target = "overall_rank")
|
||||
@Mapping(source = "attack.rank", target = "attack_rank")
|
||||
@Mapping(source = "defence.rank", target = "defence_rank")
|
||||
@Mapping(source = "strength.rank", target = "strength_rank")
|
||||
@Mapping(source = "hitpoints.rank", target = "hitpoints_rank")
|
||||
@Mapping(source = "ranged.rank", target = "ranged_rank")
|
||||
@Mapping(source = "prayer.rank", target = "prayer_rank")
|
||||
@Mapping(source = "magic.rank", target = "magic_rank")
|
||||
@Mapping(source = "cooking.rank", target = "cooking_rank")
|
||||
@Mapping(source = "woodcutting.rank", target = "woodcutting_rank")
|
||||
@Mapping(source = "fletching.rank", target = "fletching_rank")
|
||||
@Mapping(source = "fishing.rank", target = "fishing_rank")
|
||||
@Mapping(source = "firemaking.rank", target = "firemaking_rank")
|
||||
@Mapping(source = "crafting.rank", target = "crafting_rank")
|
||||
@Mapping(source = "smithing.rank", target = "smithing_rank")
|
||||
@Mapping(source = "mining.rank", target = "mining_rank")
|
||||
@Mapping(source = "herblore.rank", target = "herblore_rank")
|
||||
@Mapping(source = "agility.rank", target = "agility_rank")
|
||||
@Mapping(source = "thieving.rank", target = "thieving_rank")
|
||||
@Mapping(source = "slayer.rank", target = "slayer_rank")
|
||||
@Mapping(source = "farming.rank", target = "farming_rank")
|
||||
@Mapping(source = "runecraft.rank", target = "runecraft_rank")
|
||||
@Mapping(source = "hunter.rank", target = "hunter_rank")
|
||||
@Mapping(source = "construction.rank", target = "construction_rank")
|
||||
XpData hiscoreResultToXpData(HiscoreResult hiscoreResult);
|
||||
}
|
||||
@@ -1,59 +0,0 @@
|
||||
/*
|
||||
* Copyright (c) 2018, Adam <Adam@sigterm.info>
|
||||
* All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions are met:
|
||||
*
|
||||
* 1. Redistributions of source code must retain the above copyright notice, this
|
||||
* list of conditions and the following disclaimer.
|
||||
* 2. Redistributions in binary form must reproduce the above copyright notice,
|
||||
* this list of conditions and the following disclaimer in the documentation
|
||||
* and/or other materials provided with the distribution.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
|
||||
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
|
||||
* WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
|
||||
* DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR
|
||||
* ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
|
||||
* (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
|
||||
* LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
|
||||
* ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
||||
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
|
||||
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
*/
|
||||
package net.runelite.http.service.xp;
|
||||
|
||||
import java.time.Instant;
|
||||
import net.runelite.http.api.xp.XpData;
|
||||
import net.runelite.http.service.xp.beans.XpEntity;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.web.bind.annotation.GetMapping;
|
||||
import org.springframework.web.bind.annotation.RequestMapping;
|
||||
import org.springframework.web.bind.annotation.RequestParam;
|
||||
import org.springframework.web.bind.annotation.RestController;
|
||||
|
||||
@RestController
|
||||
@RequestMapping("/xp")
|
||||
public class XpTrackerController
|
||||
{
|
||||
@Autowired
|
||||
private XpTrackerService xpTrackerService;
|
||||
|
||||
@GetMapping("/update")
|
||||
public void update(@RequestParam String username)
|
||||
{
|
||||
xpTrackerService.tryUpdate(username);
|
||||
}
|
||||
|
||||
@GetMapping("/get")
|
||||
public XpData get(@RequestParam String username, @RequestParam(required = false) Instant time)
|
||||
{
|
||||
if (time == null)
|
||||
{
|
||||
time = Instant.now();
|
||||
}
|
||||
XpEntity xpEntity = xpTrackerService.findXpAtTime(username, time);
|
||||
return XpMapper.INSTANCE.xpEntityToXpData(xpEntity);
|
||||
}
|
||||
}
|
||||
@@ -1,307 +0,0 @@
|
||||
/*
|
||||
* Copyright (c) 2018, Adam <Adam@sigterm.info>
|
||||
* All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions are met:
|
||||
*
|
||||
* 1. Redistributions of source code must retain the above copyright notice, this
|
||||
* list of conditions and the following disclaimer.
|
||||
* 2. Redistributions in binary form must reproduce the above copyright notice,
|
||||
* this list of conditions and the following disclaimer in the documentation
|
||||
* and/or other materials provided with the distribution.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
|
||||
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
|
||||
* WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
|
||||
* DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR
|
||||
* ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
|
||||
* (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
|
||||
* LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
|
||||
* ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
||||
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
|
||||
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
*/
|
||||
package net.runelite.http.service.xp;
|
||||
|
||||
import com.google.common.hash.BloomFilter;
|
||||
import com.google.common.hash.Funnels;
|
||||
import java.nio.charset.Charset;
|
||||
import java.time.Duration;
|
||||
import java.time.Instant;
|
||||
import java.util.ArrayDeque;
|
||||
import java.util.Queue;
|
||||
import java.util.concurrent.ExecutionException;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import net.runelite.http.api.hiscore.HiscoreEndpoint;
|
||||
import net.runelite.http.api.hiscore.HiscoreResult;
|
||||
import net.runelite.http.api.xp.XpData;
|
||||
import net.runelite.http.service.hiscore.HiscoreService;
|
||||
import net.runelite.http.service.xp.beans.PlayerEntity;
|
||||
import net.runelite.http.service.xp.beans.XpEntity;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.beans.factory.annotation.Qualifier;
|
||||
import org.springframework.scheduling.annotation.Scheduled;
|
||||
import org.springframework.stereotype.Service;
|
||||
import org.sql2o.Connection;
|
||||
import org.sql2o.Sql2o;
|
||||
|
||||
@Service
|
||||
@Slf4j
|
||||
public class XpTrackerService
|
||||
{
|
||||
private static final int QUEUE_LIMIT = 32768;
|
||||
private static final int BLOOMFILTER_EXPECTED_INSERTIONS = 100_000;
|
||||
|
||||
@Autowired
|
||||
@Qualifier("Runelite XP Tracker SQL2O")
|
||||
private Sql2o sql2o;
|
||||
|
||||
@Autowired
|
||||
private HiscoreService hiscoreService;
|
||||
|
||||
private final Queue<String> usernameUpdateQueue = new ArrayDeque<>();
|
||||
private BloomFilter<String> usernameFilter = createFilter();
|
||||
|
||||
public void update(String username) throws ExecutionException
|
||||
{
|
||||
HiscoreResult hiscoreResult = hiscoreService.lookupUsername(username, HiscoreEndpoint.NORMAL);
|
||||
update(username, hiscoreResult);
|
||||
}
|
||||
|
||||
public void tryUpdate(String username)
|
||||
{
|
||||
if (usernameFilter.mightContain(username))
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
try (Connection con = sql2o.open())
|
||||
{
|
||||
PlayerEntity playerEntity = findOrCreatePlayer(con, username);
|
||||
Duration frequency = updateFrequency(playerEntity);
|
||||
Instant now = Instant.now();
|
||||
Duration timeSinceLastUpdate = Duration.between(playerEntity.getLast_updated(), now);
|
||||
if (timeSinceLastUpdate.toMillis() < frequency.toMillis())
|
||||
{
|
||||
log.debug("User {} updated too recently", username);
|
||||
usernameFilter.put(username);
|
||||
return;
|
||||
}
|
||||
|
||||
synchronized (usernameUpdateQueue)
|
||||
{
|
||||
if (usernameUpdateQueue.size() >= QUEUE_LIMIT)
|
||||
{
|
||||
log.warn("Username update queue is full ({})", QUEUE_LIMIT);
|
||||
return;
|
||||
}
|
||||
|
||||
usernameUpdateQueue.add(username);
|
||||
}
|
||||
}
|
||||
|
||||
usernameFilter.put(username);
|
||||
}
|
||||
|
||||
public void update(String username, HiscoreResult hiscoreResult)
|
||||
{
|
||||
try (Connection con = sql2o.open())
|
||||
{
|
||||
PlayerEntity playerEntity = findOrCreatePlayer(con, username);
|
||||
|
||||
Instant now = Instant.now();
|
||||
XpEntity currentXp = findXpAtTime(con, username, 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();
|
||||
|
||||
con.createQuery("update player set rank = :rank, last_updated = CURRENT_TIMESTAMP where id = :id")
|
||||
.addParameter("id", playerEntity.getId())
|
||||
.addParameter("rank", hiscoreResult.getOverall().getRank())
|
||||
.executeUpdate();
|
||||
}
|
||||
}
|
||||
|
||||
private synchronized PlayerEntity findOrCreatePlayer(Connection con, String username)
|
||||
{
|
||||
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);
|
||||
playerEntity.setLast_updated(now);
|
||||
return playerEntity;
|
||||
}
|
||||
|
||||
private XpEntity findXpAtTime(Connection con, String username, Instant time)
|
||||
{
|
||||
return con.createQuery("select * from xp join player on player.id=xp.player where player.name = :username and time <= :time order by time desc limit 1")
|
||||
.throwOnMappingFailure(false)
|
||||
.addParameter("username", username)
|
||||
.addParameter("time", time)
|
||||
.executeAndFetchFirst(XpEntity.class);
|
||||
}
|
||||
|
||||
public XpEntity findXpAtTime(String username, Instant time)
|
||||
{
|
||||
try (Connection con = sql2o.open())
|
||||
{
|
||||
return findXpAtTime(con, username, time);
|
||||
}
|
||||
}
|
||||
|
||||
@Scheduled(fixedDelay = 1000)
|
||||
public void update() throws ExecutionException
|
||||
{
|
||||
String next;
|
||||
synchronized (usernameUpdateQueue)
|
||||
{
|
||||
next = usernameUpdateQueue.poll();
|
||||
}
|
||||
|
||||
if (next == null)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
update(next);
|
||||
}
|
||||
|
||||
@Scheduled(fixedDelay = 6 * 60 * 60 * 1000) // 6 hours
|
||||
public void clearFilter()
|
||||
{
|
||||
usernameFilter = createFilter();
|
||||
}
|
||||
|
||||
private BloomFilter<String> createFilter()
|
||||
{
|
||||
final BloomFilter<String> filter = BloomFilter.create(
|
||||
Funnels.stringFunnel(Charset.defaultCharset()),
|
||||
BLOOMFILTER_EXPECTED_INSERTIONS
|
||||
);
|
||||
|
||||
synchronized (usernameUpdateQueue)
|
||||
{
|
||||
for (String toUpdate : usernameUpdateQueue)
|
||||
{
|
||||
filter.put(toUpdate);
|
||||
}
|
||||
}
|
||||
|
||||
return filter;
|
||||
}
|
||||
|
||||
/**
|
||||
* scale how often to check hiscore updates for players based on their rank
|
||||
* @param playerEntity
|
||||
* @return
|
||||
*/
|
||||
private static Duration updateFrequency(PlayerEntity playerEntity)
|
||||
{
|
||||
Integer rank = playerEntity.getRank();
|
||||
if (rank == null || rank == -1)
|
||||
{
|
||||
return Duration.ofDays(7);
|
||||
}
|
||||
else if (rank < 10_000)
|
||||
{
|
||||
return Duration.ofHours(6);
|
||||
}
|
||||
else if (rank < 50_000)
|
||||
{
|
||||
return Duration.ofDays(2);
|
||||
}
|
||||
else if (rank < 100_000)
|
||||
{
|
||||
return Duration.ofDays(5);
|
||||
}
|
||||
else
|
||||
{
|
||||
return Duration.ofDays(7);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,38 +0,0 @@
|
||||
/*
|
||||
* Copyright (c) 2018, Adam <Adam@sigterm.info>
|
||||
* All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions are met:
|
||||
*
|
||||
* 1. Redistributions of source code must retain the above copyright notice, this
|
||||
* list of conditions and the following disclaimer.
|
||||
* 2. Redistributions in binary form must reproduce the above copyright notice,
|
||||
* this list of conditions and the following disclaimer in the documentation
|
||||
* and/or other materials provided with the distribution.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
|
||||
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
|
||||
* WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
|
||||
* DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR
|
||||
* ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
|
||||
* (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
|
||||
* LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
|
||||
* ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
||||
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
|
||||
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
*/
|
||||
package net.runelite.http.service.xp.beans;
|
||||
|
||||
import java.time.Instant;
|
||||
import lombok.Data;
|
||||
|
||||
@Data
|
||||
public class PlayerEntity
|
||||
{
|
||||
private Integer id;
|
||||
private String name;
|
||||
private Instant tracked_since;
|
||||
private Instant last_updated;
|
||||
private Integer rank;
|
||||
}
|
||||
@@ -1,85 +0,0 @@
|
||||
/*
|
||||
* Copyright (c) 2018, Adam <Adam@sigterm.info>
|
||||
* All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions are met:
|
||||
*
|
||||
* 1. Redistributions of source code must retain the above copyright notice, this
|
||||
* list of conditions and the following disclaimer.
|
||||
* 2. Redistributions in binary form must reproduce the above copyright notice,
|
||||
* this list of conditions and the following disclaimer in the documentation
|
||||
* and/or other materials provided with the distribution.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
|
||||
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
|
||||
* WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
|
||||
* DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR
|
||||
* ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
|
||||
* (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
|
||||
* LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
|
||||
* ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
||||
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
|
||||
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
*/
|
||||
package net.runelite.http.service.xp.beans;
|
||||
|
||||
import java.time.Instant;
|
||||
import lombok.Data;
|
||||
|
||||
@Data
|
||||
public class XpEntity
|
||||
{
|
||||
private Integer id;
|
||||
private Instant time;
|
||||
private Integer player;
|
||||
private int overall_xp;
|
||||
private int attack_xp;
|
||||
private int defence_xp;
|
||||
private int strength_xp;
|
||||
private int hitpoints_xp;
|
||||
private int ranged_xp;
|
||||
private int prayer_xp;
|
||||
private int magic_xp;
|
||||
private int cooking_xp;
|
||||
private int woodcutting_xp;
|
||||
private int fletching_xp;
|
||||
private int fishing_xp;
|
||||
private int firemaking_xp;
|
||||
private int crafting_xp;
|
||||
private int smithing_xp;
|
||||
private int mining_xp;
|
||||
private int herblore_xp;
|
||||
private int agility_xp;
|
||||
private int thieving_xp;
|
||||
private int slayer_xp;
|
||||
private int farming_xp;
|
||||
private int runecraft_xp;
|
||||
private int hunter_xp;
|
||||
private int construction_xp;
|
||||
|
||||
private int overall_rank;
|
||||
private int attack_rank;
|
||||
private int defence_rank;
|
||||
private int strength_rank;
|
||||
private int hitpoints_rank;
|
||||
private int ranged_rank;
|
||||
private int prayer_rank;
|
||||
private int magic_rank;
|
||||
private int cooking_rank;
|
||||
private int woodcutting_rank;
|
||||
private int fletching_rank;
|
||||
private int fishing_rank;
|
||||
private int firemaking_rank;
|
||||
private int crafting_rank;
|
||||
private int smithing_rank;
|
||||
private int mining_rank;
|
||||
private int herblore_rank;
|
||||
private int agility_rank;
|
||||
private int thieving_rank;
|
||||
private int slayer_rank;
|
||||
private int farming_rank;
|
||||
private int runecraft_rank;
|
||||
private int hunter_rank;
|
||||
private int construction_rank;
|
||||
}
|
||||
@@ -18,13 +18,6 @@ datasource:
|
||||
url: jdbc:mariadb://localhost:3306/cache
|
||||
username: runelite
|
||||
password: runelite
|
||||
runelite-tracker:
|
||||
jndiName:
|
||||
driverClassName: org.mariadb.jdbc.Driver
|
||||
type: org.mariadb.jdbc.MariaDbDataSource
|
||||
url: jdbc:mariadb://localhost:3306/xptracker
|
||||
username: runelite
|
||||
password: runelite
|
||||
|
||||
# Development mongo
|
||||
mongo:
|
||||
|
||||
@@ -3,8 +3,6 @@ datasource:
|
||||
jndiName: java:comp/env/jdbc/runelite
|
||||
runelite-cache:
|
||||
jndiName: java:comp/env/jdbc/runelite-cache2
|
||||
runelite-tracker:
|
||||
jndiName: java:comp/env/jdbc/runelite-tracker
|
||||
|
||||
# By default Spring tries to register the datasource as an MXBean,
|
||||
# so if multiple apis are deployed on one web container with
|
||||
|
||||
@@ -1,135 +0,0 @@
|
||||
-- MySQL dump 10.16 Distrib 10.2.18-MariaDB, for Linux (x86_64)
|
||||
--
|
||||
-- Host: localhost Database: xptracker
|
||||
-- ------------------------------------------------------
|
||||
-- Server version 10.2.18-MariaDB
|
||||
|
||||
/*!40101 SET @OLD_CHARACTER_SET_CLIENT=@@CHARACTER_SET_CLIENT */;
|
||||
/*!40101 SET @OLD_CHARACTER_SET_RESULTS=@@CHARACTER_SET_RESULTS */;
|
||||
/*!40101 SET @OLD_COLLATION_CONNECTION=@@COLLATION_CONNECTION */;
|
||||
/*!40101 SET NAMES utf8 */;
|
||||
/*!40103 SET @OLD_TIME_ZONE=@@TIME_ZONE */;
|
||||
/*!40103 SET TIME_ZONE='+00:00' */;
|
||||
/*!40014 SET @OLD_UNIQUE_CHECKS=@@UNIQUE_CHECKS, UNIQUE_CHECKS=0 */;
|
||||
/*!40014 SET @OLD_FOREIGN_KEY_CHECKS=@@FOREIGN_KEY_CHECKS, FOREIGN_KEY_CHECKS=0 */;
|
||||
/*!40101 SET @OLD_SQL_MODE=@@SQL_MODE, SQL_MODE='NO_AUTO_VALUE_ON_ZERO' */;
|
||||
/*!40111 SET @OLD_SQL_NOTES=@@SQL_NOTES, SQL_NOTES=0 */;
|
||||
|
||||
--
|
||||
-- Table structure for table `player`
|
||||
--
|
||||
|
||||
DROP TABLE IF EXISTS `player`;
|
||||
/*!40101 SET @saved_cs_client = @@character_set_client */;
|
||||
/*!40101 SET character_set_client = utf8 */;
|
||||
CREATE TABLE `player` (
|
||||
`id` int(11) NOT NULL AUTO_INCREMENT,
|
||||
`name` varchar(32) NOT NULL,
|
||||
`tracked_since` timestamp NOT NULL DEFAULT current_timestamp(),
|
||||
`last_updated` timestamp NOT NULL DEFAULT current_timestamp(),
|
||||
`rank` int(11) DEFAULT NULL,
|
||||
PRIMARY KEY (`id`),
|
||||
UNIQUE KEY `name` (`name`)
|
||||
) ENGINE=InnoDB DEFAULT CHARSET=latin1;
|
||||
/*!40101 SET character_set_client = @saved_cs_client */;
|
||||
|
||||
--
|
||||
-- Table structure for table `xp`
|
||||
--
|
||||
|
||||
DROP TABLE IF EXISTS `xp`;
|
||||
/*!40101 SET @saved_cs_client = @@character_set_client */;
|
||||
/*!40101 SET character_set_client = utf8 */;
|
||||
CREATE TABLE `xp` (
|
||||
`id` int(11) NOT NULL AUTO_INCREMENT,
|
||||
`time` timestamp NOT NULL DEFAULT current_timestamp(),
|
||||
`player` int(11) NOT NULL,
|
||||
`attack_xp` int(11) NOT NULL,
|
||||
`defence_xp` int(11) NOT NULL,
|
||||
`strength_xp` int(11) NOT NULL,
|
||||
`hitpoints_xp` int(11) NOT NULL,
|
||||
`ranged_xp` int(11) NOT NULL,
|
||||
`prayer_xp` int(11) NOT NULL,
|
||||
`magic_xp` int(11) NOT NULL,
|
||||
`cooking_xp` int(11) NOT NULL,
|
||||
`woodcutting_xp` int(11) NOT NULL,
|
||||
`fletching_xp` int(11) NOT NULL,
|
||||
`fishing_xp` int(11) NOT NULL,
|
||||
`firemaking_xp` int(11) NOT NULL,
|
||||
`crafting_xp` int(11) NOT NULL,
|
||||
`smithing_xp` int(11) NOT NULL,
|
||||
`mining_xp` int(11) NOT NULL,
|
||||
`herblore_xp` int(11) NOT NULL,
|
||||
`agility_xp` int(11) NOT NULL,
|
||||
`thieving_xp` int(11) NOT NULL,
|
||||
`slayer_xp` int(11) NOT NULL,
|
||||
`farming_xp` int(11) NOT NULL,
|
||||
`runecraft_xp` int(11) NOT NULL,
|
||||
`hunter_xp` int(11) NOT NULL,
|
||||
`construction_xp` int(11) NOT NULL,
|
||||
`overall_xp` int(11) GENERATED ALWAYS AS (`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`) VIRTUAL,
|
||||
`attack_level` int(11) GENERATED ALWAYS AS (level_for_xp(`attack_xp` AS `attack_xp`)) VIRTUAL,
|
||||
`defence_level` int(11) GENERATED ALWAYS AS (level_for_xp(`defence_xp` AS `defence_xp`)) VIRTUAL,
|
||||
`strength_level` int(11) GENERATED ALWAYS AS (level_for_xp(`strength_xp` AS `strength_xp`)) VIRTUAL,
|
||||
`hitpoints_level` int(11) GENERATED ALWAYS AS (level_for_xp(`hitpoints_xp` AS `hitpoints_xp`)) VIRTUAL,
|
||||
`ranged_level` int(11) GENERATED ALWAYS AS (level_for_xp(`ranged_xp` AS `ranged_xp`)) VIRTUAL,
|
||||
`prayer_level` int(11) GENERATED ALWAYS AS (level_for_xp(`prayer_xp` AS `prayer_xp`)) VIRTUAL,
|
||||
`magic_level` int(11) GENERATED ALWAYS AS (level_for_xp(`magic_xp` AS `magic_xp`)) VIRTUAL,
|
||||
`cooking_level` int(11) GENERATED ALWAYS AS (level_for_xp(`cooking_xp` AS `cooking_xp`)) VIRTUAL,
|
||||
`woodcutting_level` int(11) GENERATED ALWAYS AS (level_for_xp(`woodcutting_xp` AS `woodcutting_xp`)) VIRTUAL,
|
||||
`fletching_level` int(11) GENERATED ALWAYS AS (level_for_xp(`fletching_xp` AS `fletching_xp`)) VIRTUAL,
|
||||
`fishing_level` int(11) GENERATED ALWAYS AS (level_for_xp(`fishing_xp` AS `fishing_xp`)) VIRTUAL,
|
||||
`firemaking_level` int(11) GENERATED ALWAYS AS (level_for_xp(`firemaking_xp` AS `firemaking_xp`)) VIRTUAL,
|
||||
`crafting_level` int(11) GENERATED ALWAYS AS (level_for_xp(`crafting_xp` AS `crafting_xp`)) VIRTUAL,
|
||||
`smithing_level` int(11) GENERATED ALWAYS AS (level_for_xp(`smithing_xp` AS `smithing_xp`)) VIRTUAL,
|
||||
`mining_level` int(11) GENERATED ALWAYS AS (level_for_xp(`mining_xp` AS `mining_xp`)) VIRTUAL,
|
||||
`herblore_level` int(11) GENERATED ALWAYS AS (level_for_xp(`herblore_xp` AS `herblore_xp`)) VIRTUAL,
|
||||
`agility_level` int(11) GENERATED ALWAYS AS (level_for_xp(`agility_xp` AS `agility_xp`)) VIRTUAL,
|
||||
`thieving_level` int(11) GENERATED ALWAYS AS (level_for_xp(`thieving_xp` AS `thieving_xp`)) VIRTUAL,
|
||||
`slayer_level` int(11) GENERATED ALWAYS AS (level_for_xp(`slayer_xp` AS `slayer_xp`)) VIRTUAL,
|
||||
`farming_level` int(11) GENERATED ALWAYS AS (level_for_xp(`farming_xp` AS `farming_xp`)) VIRTUAL,
|
||||
`runecraft_level` int(11) GENERATED ALWAYS AS (level_for_xp(`runecraft_xp` AS `runecraft_xp`)) VIRTUAL,
|
||||
`hunter_level` int(11) GENERATED ALWAYS AS (level_for_xp(`hunter_xp` AS `hunter_xp`)) VIRTUAL,
|
||||
`construction_level` int(11) GENERATED ALWAYS AS (level_for_xp(`construction_xp` AS `construction_xp`)) VIRTUAL,
|
||||
`overall_level` int(11) GENERATED ALWAYS AS (`attack_level` + `defence_level` + `strength_level` + `hitpoints_level` + `ranged_level` + `prayer_level` + `magic_level` + `cooking_level` + `woodcutting_level` + `fletching_level` + `fishing_level` + `firemaking_level` + `crafting_level` + `smithing_level` + `mining_level` + `herblore_level` + `agility_level` + `thieving_level` + `slayer_level` + `farming_level` + `runecraft_level` + `hunter_level` + `construction_level`) VIRTUAL,
|
||||
`attack_rank` int(11) NOT NULL,
|
||||
`defence_rank` int(11) NOT NULL,
|
||||
`strength_rank` int(11) NOT NULL,
|
||||
`hitpoints_rank` int(11) NOT NULL,
|
||||
`ranged_rank` int(11) NOT NULL,
|
||||
`prayer_rank` int(11) NOT NULL,
|
||||
`magic_rank` int(11) NOT NULL,
|
||||
`cooking_rank` int(11) NOT NULL,
|
||||
`woodcutting_rank` int(11) NOT NULL,
|
||||
`fletching_rank` int(11) NOT NULL,
|
||||
`fishing_rank` int(11) NOT NULL,
|
||||
`firemaking_rank` int(11) NOT NULL,
|
||||
`crafting_rank` int(11) NOT NULL,
|
||||
`smithing_rank` int(11) NOT NULL,
|
||||
`mining_rank` int(11) NOT NULL,
|
||||
`herblore_rank` int(11) NOT NULL,
|
||||
`agility_rank` int(11) NOT NULL,
|
||||
`thieving_rank` int(11) NOT NULL,
|
||||
`slayer_rank` int(11) NOT NULL,
|
||||
`farming_rank` int(11) NOT NULL,
|
||||
`runecraft_rank` int(11) NOT NULL,
|
||||
`hunter_rank` int(11) NOT NULL,
|
||||
`construction_rank` int(11) NOT NULL,
|
||||
`overall_rank` int(11) NOT NULL,
|
||||
PRIMARY KEY (`id`),
|
||||
UNIQUE KEY `player_time` (`player`,`time`),
|
||||
KEY `idx_time` (`time`),
|
||||
CONSTRAINT `fk_player` FOREIGN KEY (`player`) REFERENCES `player` (`id`)
|
||||
) ENGINE=InnoDB DEFAULT CHARSET=latin1;
|
||||
/*!40101 SET character_set_client = @saved_cs_client */;
|
||||
/*!40103 SET TIME_ZONE=@OLD_TIME_ZONE */;
|
||||
|
||||
/*!40101 SET SQL_MODE=@OLD_SQL_MODE */;
|
||||
/*!40014 SET FOREIGN_KEY_CHECKS=@OLD_FOREIGN_KEY_CHECKS */;
|
||||
/*!40014 SET UNIQUE_CHECKS=@OLD_UNIQUE_CHECKS */;
|
||||
/*!40101 SET CHARACTER_SET_CLIENT=@OLD_CHARACTER_SET_CLIENT */;
|
||||
/*!40101 SET CHARACTER_SET_RESULTS=@OLD_CHARACTER_SET_RESULTS */;
|
||||
/*!40101 SET COLLATION_CONNECTION=@OLD_COLLATION_CONNECTION */;
|
||||
/*!40111 SET SQL_NOTES=@OLD_SQL_NOTES */;
|
||||
|
||||
-- Dump completed on 2019-02-15 21:01:17
|
||||
@@ -1,162 +0,0 @@
|
||||
/*
|
||||
* Copyright (c) 2017, Adam <Adam@sigterm.info>
|
||||
* All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions are met:
|
||||
*
|
||||
* 1. Redistributions of source code must retain the above copyright notice, this
|
||||
* list of conditions and the following disclaimer.
|
||||
* 2. Redistributions in binary form must reproduce the above copyright notice,
|
||||
* this list of conditions and the following disclaimer in the documentation
|
||||
* and/or other materials provided with the distribution.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
|
||||
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
|
||||
* WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
|
||||
* DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR
|
||||
* ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
|
||||
* (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
|
||||
* LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
|
||||
* ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
||||
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
|
||||
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
*/
|
||||
package net.runelite.http.service.hiscore;
|
||||
|
||||
import java.io.IOException;
|
||||
import net.runelite.http.api.hiscore.HiscoreEndpoint;
|
||||
import net.runelite.http.api.hiscore.HiscoreResult;
|
||||
import okhttp3.mockwebserver.MockResponse;
|
||||
import okhttp3.mockwebserver.MockWebServer;
|
||||
import org.junit.Assert;
|
||||
import org.junit.Before;
|
||||
import org.junit.Rule;
|
||||
import org.junit.Test;
|
||||
|
||||
public class HiscoreServiceTest
|
||||
{
|
||||
private static final String RESPONSE = "654683,705,1304518\n"
|
||||
+ "679419,50,107181\n"
|
||||
+ "550667,48,85764\n"
|
||||
+ "861497,50,101366\n"
|
||||
+ "891591,48,87843\n"
|
||||
+ "-1,1,4\n"
|
||||
+ "840255,27,10073\n"
|
||||
+ "1371912,10,1310\n"
|
||||
+ "432193,56,199795\n"
|
||||
+ "495638,56,198304\n"
|
||||
+ "514466,37,27502\n"
|
||||
+ "456981,54,159727\n"
|
||||
+ "459159,49,93010\n"
|
||||
+ "1028855,8,823\n"
|
||||
+ "862906,29,12749\n"
|
||||
+ "795020,31,16097\n"
|
||||
+ "673591,5,495\n"
|
||||
+ "352676,51,112259\n"
|
||||
+ "428419,40,37235\n"
|
||||
+ "461887,43,51971\n"
|
||||
+ "598582,1,10\n"
|
||||
+ "638177,1,0\n"
|
||||
+ "516239,9,1000\n"
|
||||
+ "492790,1,0\n"
|
||||
+ "2,2460\n" // leagues
|
||||
+ "-1,-1\n"
|
||||
+ "73,1738\n"
|
||||
+ "531,1432\n"
|
||||
+ "324,212\n"
|
||||
+ "8008,131\n"
|
||||
+ "1337,911\n"
|
||||
+ "42,14113\n"
|
||||
+ "1,777\n"
|
||||
+ "254,92\n"
|
||||
+ "-1,-1\n" // lms
|
||||
+ "1,241\n" // soul wars
|
||||
+ "24870,37\n"
|
||||
+ "15020,388\n"
|
||||
+ "50463,147\n"
|
||||
+ "-1,-1\n"
|
||||
+ "92357,1\n"
|
||||
+ "22758,637\n"
|
||||
+ "22744,107\n"
|
||||
+ "-1,-1\n"
|
||||
+ "20150,17\n"
|
||||
+ "29400,18\n"
|
||||
+ "13465,172\n"
|
||||
+ "1889,581\n"
|
||||
+ "42891,11\n"
|
||||
+ "1624,1957\n"
|
||||
+ "1243,2465\n"
|
||||
+ "1548,2020\n"
|
||||
+ "-1,-1\n"
|
||||
+ "16781,327\n"
|
||||
+ "19004,149\n"
|
||||
+ "-1,-1\n"
|
||||
+ "72046,5\n"
|
||||
+ "5158,374\n"
|
||||
+ "20902,279\n"
|
||||
+ "702,6495\n"
|
||||
+ "10170,184\n"
|
||||
+ "8064,202\n"
|
||||
+ "6936,2\n" // Mimic
|
||||
+ "1,4920\n" // Nex
|
||||
+ "2335,9\n" // Nightmare
|
||||
+ "2336,10\n" // Phosanis Nightmare
|
||||
+ "-1,-1\n"
|
||||
+ "-1,-1\n"
|
||||
+ "19779,22\n"
|
||||
+ "58283,10\n"
|
||||
+ "1234,5678\n" // Tempoross
|
||||
+ "-1,-1\n"
|
||||
+ "-1,-1\n"
|
||||
+ "-1,-1\n" // TOB
|
||||
+ "42,42\n" // TOB: Hard Mode
|
||||
+ "29347,130\n"
|
||||
+ "723,4\n"
|
||||
+ "1264,38\n"
|
||||
+ "44595,4\n"
|
||||
+ "24820,4\n"
|
||||
+ "12116,782\n"
|
||||
+ "2299,724\n"
|
||||
+ "19301,62\n"
|
||||
+ "1498,5847\n";
|
||||
|
||||
@Rule
|
||||
public final MockWebServer server = new MockWebServer();
|
||||
|
||||
@Before
|
||||
public void before() throws IOException
|
||||
{
|
||||
server.enqueue(new MockResponse().setBody(RESPONSE));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testNormalLookup() throws Exception
|
||||
{
|
||||
HiscoreTestService hiscores = new HiscoreTestService(server.url("/"));
|
||||
|
||||
HiscoreResult result = hiscores.lookupUsername("zezima", HiscoreEndpoint.NORMAL.getHiscoreURL());
|
||||
|
||||
Assert.assertEquals(50, result.getAttack().getLevel());
|
||||
Assert.assertEquals(159727L, result.getFishing().getExperience());
|
||||
Assert.assertEquals(492790, result.getConstruction().getRank());
|
||||
Assert.assertEquals(1432, result.getClueScrollAll().getLevel());
|
||||
Assert.assertEquals(324, result.getClueScrollBeginner().getRank());
|
||||
Assert.assertEquals(8008, result.getClueScrollEasy().getRank());
|
||||
Assert.assertEquals(911, result.getClueScrollMedium().getLevel());
|
||||
Assert.assertEquals(42, result.getClueScrollHard().getRank());
|
||||
Assert.assertEquals(777, result.getClueScrollElite().getLevel());
|
||||
Assert.assertEquals(254, result.getClueScrollMaster().getRank());
|
||||
Assert.assertEquals(-1, result.getLastManStanding().getLevel());
|
||||
Assert.assertEquals(241, result.getSoulWarsZeal().getLevel());
|
||||
Assert.assertEquals(2460, result.getLeaguePoints().getLevel());
|
||||
Assert.assertEquals(37, result.getAbyssalSire().getLevel());
|
||||
Assert.assertEquals(92357, result.getCallisto().getRank());
|
||||
Assert.assertEquals(4920, result.getNex().getLevel());
|
||||
Assert.assertEquals(2336, result.getPhosanisNightmare().getRank());
|
||||
Assert.assertEquals(5678, result.getTempoross().getLevel());
|
||||
Assert.assertEquals(42, result.getTheatreOfBloodHardMode().getLevel());
|
||||
Assert.assertEquals(5847, result.getZulrah().getLevel());
|
||||
}
|
||||
|
||||
}
|
||||
@@ -1,46 +0,0 @@
|
||||
/*
|
||||
* Copyright (c) 2017, Adam <Adam@sigterm.info>
|
||||
* All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions are met:
|
||||
*
|
||||
* Redistributions of source code must retain the above copyright notice, this
|
||||
* list of conditions and the following disclaimer.
|
||||
*
|
||||
* Redistributions in binary form must reproduce the above copyright notice,
|
||||
* this list of conditions and the following disclaimer in the documentation
|
||||
* and/or other materials provided with the distribution.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
|
||||
* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
||||
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
|
||||
* DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
|
||||
* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
|
||||
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
|
||||
* SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
|
||||
* CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
|
||||
* OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
|
||||
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
*/
|
||||
package net.runelite.http.service.hiscore;
|
||||
|
||||
import java.io.IOException;
|
||||
import net.runelite.http.api.hiscore.HiscoreResult;
|
||||
import okhttp3.HttpUrl;
|
||||
|
||||
class HiscoreTestService extends HiscoreService
|
||||
{
|
||||
private final HttpUrl testUrl;
|
||||
|
||||
HiscoreTestService(HttpUrl testUrl)
|
||||
{
|
||||
this.testUrl = testUrl;
|
||||
}
|
||||
|
||||
@Override
|
||||
public HiscoreResult lookupUsername(String username, HttpUrl endpoint) throws IOException
|
||||
{
|
||||
return super.lookupUsername(username, testUrl);
|
||||
}
|
||||
}
|
||||
@@ -1,59 +0,0 @@
|
||||
/*
|
||||
* Copyright (c) 2018, Adam <Adam@sigterm.info>
|
||||
* All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions are met:
|
||||
*
|
||||
* 1. Redistributions of source code must retain the above copyright notice, this
|
||||
* list of conditions and the following disclaimer.
|
||||
* 2. Redistributions in binary form must reproduce the above copyright notice,
|
||||
* this list of conditions and the following disclaimer in the documentation
|
||||
* and/or other materials provided with the distribution.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
|
||||
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
|
||||
* WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
|
||||
* DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR
|
||||
* ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
|
||||
* (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
|
||||
* LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
|
||||
* ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
||||
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
|
||||
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
*/
|
||||
package net.runelite.http.service.xp;
|
||||
|
||||
import net.runelite.http.api.hiscore.HiscoreResult;
|
||||
import net.runelite.http.api.hiscore.Skill;
|
||||
import net.runelite.http.api.xp.XpData;
|
||||
import net.runelite.http.service.xp.beans.XpEntity;
|
||||
import static org.junit.Assert.assertEquals;
|
||||
import org.junit.Test;
|
||||
|
||||
public class XpMapperTest
|
||||
{
|
||||
@Test
|
||||
public void testXpEntityToXpData()
|
||||
{
|
||||
XpEntity xpEntity = new XpEntity();
|
||||
xpEntity.setAgility_rank(42);
|
||||
xpEntity.setAgility_xp(9001);
|
||||
|
||||
XpData xpData = XpMapper.INSTANCE.xpEntityToXpData(xpEntity);
|
||||
assertEquals(42, xpData.getAgility_rank());
|
||||
assertEquals(9001, xpData.getAgility_xp());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testHiscoreResultToXpData()
|
||||
{
|
||||
HiscoreResult hiscoreResult = new HiscoreResult();
|
||||
hiscoreResult.setAgility(new Skill(42, 9, 9001));
|
||||
|
||||
XpData xpData = XpMapper.INSTANCE.hiscoreResultToXpData(hiscoreResult);
|
||||
assertEquals(42, xpData.getAgility_rank());
|
||||
assertEquals(9001, xpData.getAgility_xp());
|
||||
}
|
||||
|
||||
}
|
||||
Reference in New Issue
Block a user