Allow specifying default world in [0-9]{2} format

Automatically append 300 to every world that is lower than 300 to
support both f.e. 22 and 322 formats for specifying the world.

Signed-off-by: Tomas Slusny <slusnucky@gmail.com>
This commit is contained in:
Tomas Slusny
2018-03-09 15:03:16 +01:00
parent 23203343af
commit 3e4f8ba99a

View File

@@ -91,15 +91,17 @@ public class DefaultWorldPlugin extends Plugin
private void changeWorld(int newWorld) private void changeWorld(int newWorld)
{ {
if (!worldChangeRequired || client.getGameState() != GameState.LOGIN_SCREEN || client.getWorld() == newWorld) if (!worldChangeRequired || client.getGameState() != GameState.LOGIN_SCREEN)
{ {
return; return;
} }
worldChangeRequired = false; worldChangeRequired = false;
int correctedWorld = newWorld < 300 ? newWorld + 300 : newWorld;
// Old School RuneScape worlds start for 301 so don't even bother trying to find lower id ones // Old School RuneScape worlds start on 301 so don't even bother trying to find lower id ones
if (client.getWorld() <= 300) // and also do not try to set world if we are already on it
if (correctedWorld <= 300 || client.getWorld() == correctedWorld)
{ {
return; return;
} }
@@ -107,7 +109,7 @@ public class DefaultWorldPlugin extends Plugin
try try
{ {
final WorldResult worldResult = worldClient.lookupWorlds(); final WorldResult worldResult = worldClient.lookupWorlds();
final World world = worldResult.findWorld(newWorld); final World world = worldResult.findWorld(correctedWorld);
if (world != null) if (world != null)
{ {
@@ -120,16 +122,16 @@ public class DefaultWorldPlugin extends Plugin
rsWorld.setTypes(toWorldTypes(world.getTypes())); rsWorld.setTypes(toWorldTypes(world.getTypes()));
client.changeWorld(rsWorld); client.changeWorld(rsWorld);
log.debug("Applied new world {}", newWorld); log.debug("Applied new world {}", correctedWorld);
} }
else else
{ {
log.warn("World {} not found.", newWorld); log.warn("World {} not found.", correctedWorld);
} }
} }
catch (IOException e) catch (IOException e)
{ {
log.warn("Error looking up world {}. Error: {}", newWorld, e); log.warn("Error looking up world {}. Error: {}", correctedWorld, e);
} }
} }