http-api: Use observables for world api
This commit is contained in:
@@ -61,7 +61,7 @@ public class WorldClient
|
|||||||
if (!response.isSuccessful())
|
if (!response.isSuccessful())
|
||||||
{
|
{
|
||||||
logger.debug("Error looking up worlds: {}", response);
|
logger.debug("Error looking up worlds: {}", response);
|
||||||
return null;
|
return Observable.just(null);
|
||||||
}
|
}
|
||||||
|
|
||||||
InputStream in = response.body().byteStream();
|
InputStream in = response.body().byteStream();
|
||||||
@@ -69,7 +69,7 @@ public class WorldClient
|
|||||||
}
|
}
|
||||||
catch (JsonParseException ex)
|
catch (JsonParseException ex)
|
||||||
{
|
{
|
||||||
throw new IOException(ex);
|
return Observable.error(ex);
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -25,6 +25,7 @@
|
|||||||
package net.runelite.client.plugins.defaultworld;
|
package net.runelite.client.plugins.defaultworld;
|
||||||
|
|
||||||
import com.google.inject.Provides;
|
import com.google.inject.Provides;
|
||||||
|
import io.reactivex.schedulers.Schedulers;
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
import javax.inject.Inject;
|
import javax.inject.Inject;
|
||||||
import javax.inject.Singleton;
|
import javax.inject.Singleton;
|
||||||
@@ -32,6 +33,7 @@ import lombok.extern.slf4j.Slf4j;
|
|||||||
import net.runelite.api.Client;
|
import net.runelite.api.Client;
|
||||||
import net.runelite.api.GameState;
|
import net.runelite.api.GameState;
|
||||||
import net.runelite.api.events.GameStateChanged;
|
import net.runelite.api.events.GameStateChanged;
|
||||||
|
import net.runelite.client.callback.ClientThread;
|
||||||
import net.runelite.client.config.ConfigManager;
|
import net.runelite.client.config.ConfigManager;
|
||||||
import net.runelite.client.eventbus.EventBus;
|
import net.runelite.client.eventbus.EventBus;
|
||||||
import net.runelite.client.events.SessionOpen;
|
import net.runelite.client.events.SessionOpen;
|
||||||
@@ -60,6 +62,9 @@ public class DefaultWorldPlugin extends Plugin
|
|||||||
@Inject
|
@Inject
|
||||||
private EventBus eventBus;
|
private EventBus eventBus;
|
||||||
|
|
||||||
|
@Inject
|
||||||
|
private ClientThread clientThread;
|
||||||
|
|
||||||
private final WorldClient worldClient = new WorldClient();
|
private final WorldClient worldClient = new WorldClient();
|
||||||
private int worldCache;
|
private int worldCache;
|
||||||
private boolean worldChangeRequired;
|
private boolean worldChangeRequired;
|
||||||
@@ -122,39 +127,39 @@ public class DefaultWorldPlugin extends Plugin
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
try
|
worldClient.lookupWorlds()
|
||||||
{
|
.subscribeOn(Schedulers.io())
|
||||||
final WorldResult worldResult = worldClient.lookupWorlds();
|
.observeOn(Schedulers.from(clientThread))
|
||||||
|
.subscribe(
|
||||||
|
(worldResult) ->
|
||||||
|
{
|
||||||
|
if (worldResult == null)
|
||||||
|
{
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
if (worldResult == null)
|
final World world = worldResult.findWorld(correctedWorld);
|
||||||
{
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
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(WorldUtil.toWorldTypes(world.getTypes()));
|
||||||
|
|
||||||
if (world != null)
|
client.changeWorld(rsWorld);
|
||||||
{
|
log.debug("Applied new world {}", correctedWorld);
|
||||||
final net.runelite.api.World rsWorld = client.createWorld();
|
}
|
||||||
rsWorld.setActivity(world.getActivity());
|
else
|
||||||
rsWorld.setAddress(world.getAddress());
|
{
|
||||||
rsWorld.setId(world.getId());
|
log.warn("World {} not found.", correctedWorld);
|
||||||
rsWorld.setPlayerCount(world.getPlayers());
|
}
|
||||||
rsWorld.setLocation(world.getLocation());
|
},
|
||||||
rsWorld.setTypes(WorldUtil.toWorldTypes(world.getTypes()));
|
(e) -> log.warn("Error looking up world {}. Error: {}", correctedWorld, e)
|
||||||
|
);
|
||||||
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);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private void applyWorld()
|
private void applyWorld()
|
||||||
|
|||||||
@@ -29,6 +29,7 @@ import com.google.common.base.Stopwatch;
|
|||||||
import com.google.common.collect.ImmutableList;
|
import com.google.common.collect.ImmutableList;
|
||||||
import com.google.common.collect.ObjectArrays;
|
import com.google.common.collect.ObjectArrays;
|
||||||
import com.google.inject.Provides;
|
import com.google.inject.Provides;
|
||||||
|
import io.reactivex.schedulers.Schedulers;
|
||||||
import java.awt.image.BufferedImage;
|
import java.awt.image.BufferedImage;
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
import java.time.Duration;
|
import java.time.Duration;
|
||||||
@@ -502,22 +503,21 @@ public class WorldHopperPlugin extends Plugin
|
|||||||
{
|
{
|
||||||
log.debug("Fetching worlds");
|
log.debug("Fetching worlds");
|
||||||
|
|
||||||
try
|
new WorldClient().lookupWorlds()
|
||||||
{
|
.subscribeOn(Schedulers.io())
|
||||||
WorldResult worldResult = new WorldClient().lookupWorlds();
|
.subscribe(
|
||||||
|
(worldResult) ->
|
||||||
if (worldResult != null)
|
{
|
||||||
{
|
if (worldResult != null)
|
||||||
worldResult.getWorlds().sort(Comparator.comparingInt(World::getId));
|
{
|
||||||
this.worldResult = worldResult;
|
worldResult.getWorlds().sort(Comparator.comparingInt(World::getId));
|
||||||
this.lastFetch = Instant.now();
|
this.worldResult = worldResult;
|
||||||
updateList();
|
this.lastFetch = Instant.now();
|
||||||
}
|
updateList();
|
||||||
}
|
}
|
||||||
catch (IOException ex)
|
},
|
||||||
{
|
(ex) -> log.warn("Error looking up worlds", ex)
|
||||||
log.warn("Error looking up worlds", ex);
|
);
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|||||||
Reference in New Issue
Block a user