Search in sources :

Example 1 with WorldResult

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;
}
Also used : Response(okhttp3.Response) WorldResult(net.runelite.http.api.worlds.WorldResult) Request(okhttp3.Request) ArrayList(java.util.ArrayList) World(net.runelite.http.api.worlds.World) ByteBuffer(java.nio.ByteBuffer) RequestMapping(org.springframework.web.bind.annotation.RequestMapping)

Example 2 with WorldResult

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));
}
Also used : WorldResult(net.runelite.http.api.worlds.WorldResult) World(net.runelite.http.api.worlds.World) Test(org.junit.Test)

Example 3 with WorldResult

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;
    }
}
Also used : WorldResult(net.runelite.http.api.worlds.WorldResult) Random(java.util.Random) IOException(java.io.IOException) World(net.runelite.http.api.worlds.World)

Example 4 with WorldResult

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);
    }
}
Also used : WorldResult(net.runelite.http.api.worlds.WorldResult) IOException(java.io.IOException) World(net.runelite.http.api.worlds.World)

Aggregations

World (net.runelite.http.api.worlds.World)4 WorldResult (net.runelite.http.api.worlds.WorldResult)4 IOException (java.io.IOException)2 ByteBuffer (java.nio.ByteBuffer)1 ArrayList (java.util.ArrayList)1 Random (java.util.Random)1 Request (okhttp3.Request)1 Response (okhttp3.Response)1 Test (org.junit.Test)1 RequestMapping (org.springframework.web.bind.annotation.RequestMapping)1