Search in sources :

Example 6 with World

use of net.runelite.http.api.worlds.World 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)6 IOException (java.io.IOException)4 WorldResult (net.runelite.http.api.worlds.WorldResult)4 ByteBuffer (java.nio.ByteBuffer)2 Subscribe (com.google.common.eventbus.Subscribe)1 InputStream (java.io.InputStream)1 OutputStream (java.io.OutputStream)1 InetAddress (java.net.InetAddress)1 Socket (java.net.Socket)1 UnknownHostException (java.net.UnknownHostException)1 ArrayList (java.util.ArrayList)1 Random (java.util.Random)1 Player (net.runelite.api.Player)1 Request (okhttp3.Request)1 Response (okhttp3.Response)1 Test (org.junit.Test)1 RequestMapping (org.springframework.web.bind.annotation.RequestMapping)1