use of net.runelite.http.api.worlds.WorldResult in project runelite by runelite.
the class WorldsService method listWorlds.
@RequestMapping
public WorldResult listWorlds() throws IOException {
Request okrequest = new Request.Builder().url(url).build();
byte[] b;
try (Response okresponse = RuneLiteAPI.CLIENT.newCall(okrequest).execute()) {
b = okresponse.body().bytes();
}
List<World> worlds = new ArrayList<>();
ByteBuffer buf = ByteBuffer.wrap(b);
int length = buf.getInt();
buf.limit(length + 4);
int num = buf.getShort() & 0xFFFF;
for (int i = 0; i < num; ++i) {
final World.WorldBuilder worldBuilder = World.builder().id(buf.getShort() & 0xFFFF).types(getTypes(buf.getInt())).address(readString(buf)).activity(readString(buf)).location(buf.get() & 0xFF).players(buf.getShort() & 0xFFFF);
worlds.add(worldBuilder.build());
}
WorldResult result = new WorldResult();
result.setWorlds(worlds);
return result;
}
use of net.runelite.http.api.worlds.WorldResult in project runelite by runelite.
the class WorldsServiceTest method testListWorlds.
@Test
public void testListWorlds() throws Exception {
WorldsService worlds = new WorldsService();
worlds.setUrl(server.url("/"));
WorldResult worldResult = worlds.listWorlds();
assertEquals(82, worldResult.getWorlds().size());
World world = worldResult.findWorld(385);
assertNotNull(world);
assertTrue(world.getTypes().contains(WorldType.SKILL_TOTAL));
}
use of net.runelite.http.api.worlds.WorldResult in project runelite by runelite.
the class UpdateCheckService method randomWorld.
private World randomWorld() {
try {
WorldResult worldResult = worldsService.listWorlds();
List<World> worlds = worldResult.getWorlds();
Random rand = new Random();
return worlds.get(rand.nextInt(worlds.size()));
} catch (IOException ex) {
logger.warn(null, ex);
return null;
}
}
use of net.runelite.http.api.worlds.WorldResult in project runelite by runelite.
the class DefaultWorldPlugin method changeWorld.
private void changeWorld(int newWorld) {
if (!worldChangeRequired || client.getGameState() != GameState.LOGIN_SCREEN) {
return;
}
worldChangeRequired = false;
int correctedWorld = newWorld < 300 ? newWorld + 300 : newWorld;
// and also do not try to set world if we are already on it
if (correctedWorld <= 300 || client.getWorld() == correctedWorld) {
return;
}
try {
final WorldResult worldResult = worldClient.lookupWorlds();
final World world = worldResult.findWorld(correctedWorld);
if (world != null) {
final net.runelite.api.World rsWorld = client.createWorld();
rsWorld.setActivity(world.getActivity());
rsWorld.setAddress(world.getAddress());
rsWorld.setId(world.getId());
rsWorld.setPlayerCount(world.getPlayers());
rsWorld.setLocation(world.getLocation());
rsWorld.setTypes(toWorldTypes(world.getTypes()));
client.changeWorld(rsWorld);
log.debug("Applied new world {}", correctedWorld);
} else {
log.warn("World {} not found.", correctedWorld);
}
} catch (IOException e) {
log.warn("Error looking up world {}. Error: {}", correctedWorld, e);
}
}
Aggregations