diff --git a/runelite-client/src/main/java/net/runelite/client/RuneLite.java b/runelite-client/src/main/java/net/runelite/client/RuneLite.java index 14f93d3cc3..488c2520ce 100644 --- a/runelite-client/src/main/java/net/runelite/client/RuneLite.java +++ b/runelite-client/src/main/java/net/runelite/client/RuneLite.java @@ -40,6 +40,7 @@ import java.lang.management.RuntimeMXBean; import java.net.Authenticator; import java.net.PasswordAuthentication; import java.util.Locale; +import java.util.Optional; import javax.annotation.Nullable; import javax.inject.Provider; import javax.inject.Singleton; @@ -63,6 +64,7 @@ import net.runelite.client.game.ClanManager; import net.runelite.client.game.ItemManager; import net.runelite.client.game.LootManager; import net.runelite.client.game.PlayerManager; +import net.runelite.client.game.WorldService; import net.runelite.client.game.XpDropManager; import net.runelite.client.game.chatbox.ChatboxPanelManager; import net.runelite.client.graphics.ModelOutlineRenderer; @@ -81,7 +83,10 @@ import net.runelite.client.ui.overlay.arrow.ArrowWorldOverlay; import net.runelite.client.ui.overlay.infobox.InfoBoxOverlay; import net.runelite.client.ui.overlay.tooltip.TooltipOverlay; import net.runelite.client.ui.overlay.worldmap.WorldMapOverlay; +import net.runelite.client.util.WorldUtil; import net.runelite.client.ws.PartyService; +import net.runelite.http.api.worlds.World; +import net.runelite.http.api.worlds.WorldResult; import org.slf4j.LoggerFactory; @Singleton @@ -103,6 +108,8 @@ public class RuneLite @Inject public DiscordService discordService; @Inject + private WorldService worldService; + @Inject private PluginManager pluginManager; @Inject private ConfigManager configManager; @@ -192,7 +199,9 @@ public class RuneLite final ArgumentAcceptingOptionSpec proxyInfo = parser .accepts("proxy") .withRequiredArg().ofType(String.class); - + final ArgumentAcceptingOptionSpec worldInfo = parser + .accepts("world") + .withRequiredArg().ofType(Integer.class); final ArgumentAcceptingOptionSpec updateMode = parser .accepts("rs", "Select client type") .withRequiredArg() @@ -252,6 +261,12 @@ public class RuneLite } } + if (options.has("world")) + { + int world = options.valueOf(worldInfo); + System.setProperty("cli.world", String.valueOf(world)); + } + SentryClient client = Sentry.init("https://fa31d674e44247fa93966c69a903770f@sentry.io/1811856"); client.setRelease(RuneLiteProperties.getPlusVersion()); @@ -356,6 +371,10 @@ public class RuneLite RuneLiteSplashScreen.stage(.80, "Initialize UI"); clientUI.init(this); + //Set the world if specified via CLI args - will not work until clientUI.init is called + Optional worldArg = Optional.ofNullable(System.getProperty("cli.world")).map(Integer::parseInt); + worldArg.ifPresent(this::setWorld); + // Initialize Discord service discordService.init(); @@ -404,6 +423,44 @@ public class RuneLite clientUI.show(); } + private void setWorld(int cliWorld) + { + int correctedWorld = cliWorld < 300 ? cliWorld + 300 : cliWorld; + + if (correctedWorld <= 300 || client.getWorld() == correctedWorld) + { + return; + } + + final WorldResult worldResult = worldService.getWorlds(); + + if (worldResult == null) + { + log.warn("Failed to lookup worlds."); + 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())); + + client.changeWorld(rsWorld); + log.debug("Applied new world {}", correctedWorld); + } + else + { + log.warn("World {} not found.", correctedWorld); + } + } + public void shutdown() { configManager.sendConfig(); diff --git a/runelite-client/src/main/java/net/runelite/client/plugins/defaultworld/DefaultWorldPlugin.java b/runelite-client/src/main/java/net/runelite/client/plugins/defaultworld/DefaultWorldPlugin.java index 0f98862c3a..d069019388 100644 --- a/runelite-client/src/main/java/net/runelite/client/plugins/defaultworld/DefaultWorldPlugin.java +++ b/runelite-client/src/main/java/net/runelite/client/plugins/defaultworld/DefaultWorldPlugin.java @@ -157,6 +157,11 @@ public class DefaultWorldPlugin extends Plugin log.debug("Stored old world {}", worldCache); } + if (System.getProperty("cli.world") != null) + { + return; + } + final int newWorld = !config.useLastWorld() ? config.getWorld() : config.lastWorld(); changeWorld(newWorld); } diff --git a/runelite-client/src/main/java/net/runelite/client/rs/ClientLoader.java b/runelite-client/src/main/java/net/runelite/client/rs/ClientLoader.java index 266a0cce8e..d19329652a 100644 --- a/runelite-client/src/main/java/net/runelite/client/rs/ClientLoader.java +++ b/runelite-client/src/main/java/net/runelite/client/rs/ClientLoader.java @@ -59,6 +59,65 @@ public class ClientLoader implements Supplier this.updateCheckMode = updateCheckMode; } + private static Applet loadRLPlus(final RSConfig config) + throws ClassNotFoundException, InstantiationException, IllegalAccessException + { + RuneLiteSplashScreen.stage(.465, "Starting Open Old School RuneScape"); + + ClassLoader rsClassLoader = new ClassLoader(ClientLoader.class.getClassLoader()) + { + @Override + protected Class findClass(String name) throws ClassNotFoundException + { + String path = name.replace('.', '/').concat(".class"); + InputStream inputStream = ClientLoader.class.getResourceAsStream(path); + if (inputStream == null) + { + throw new ClassNotFoundException(name + " " + path); + } + byte[] data; + try + { + data = ByteStreams.toByteArray(inputStream); + } + catch (IOException e) + { + e.printStackTrace(); + RuneLiteSplashScreen.setError("Failed to load!", "Failed to load class: " + name + " " + path); + throw new RuntimeException("Failed to load class: " + name + " " + path); + } + return defineClass(name, data, 0, data.length); + } + }; + Class clientClass = rsClassLoader.loadClass("client"); + return loadFromClass(config, clientClass); + } + + private static Applet loadVanilla(final RSConfig config) + throws IOException, ClassNotFoundException, InstantiationException, IllegalAccessException + { + RuneLiteSplashScreen.stage(.465, "Starting Vanilla Old School RuneScape"); + + final String codebase = config.getCodeBase(); + final String initialJar = config.getInitialJar(); + final String initialClass = config.getInitialClass(); + final URL url = new URL(codebase + initialJar); + + // Must set parent classloader to null, or it will pull from + // this class's classloader first + final URLClassLoader classloader = new URLClassLoader(new URL[]{url}, null); + final Class clientClass = classloader.loadClass(initialClass); + return loadFromClass(config, clientClass); + } + + private static Applet loadFromClass(final RSConfig config, final Class clientClass) + throws IllegalAccessException, InstantiationException + { + final Applet rs = (Applet) clientClass.newInstance(); + rs.setStub(new RSAppletStub(config)); + return rs; + } + @Override public synchronized Applet get() { @@ -163,63 +222,4 @@ public class ClientLoader implements Supplier throw err; // use error from Jagex's servers } } - - private static Applet loadRLPlus(final RSConfig config) - throws ClassNotFoundException, InstantiationException, IllegalAccessException - { - RuneLiteSplashScreen.stage(.465, "Starting Open Old School RuneScape"); - - ClassLoader rsClassLoader = new ClassLoader(ClientLoader.class.getClassLoader()) - { - @Override - protected Class findClass(String name) throws ClassNotFoundException - { - String path = name.replace('.', '/').concat(".class"); - InputStream inputStream = ClientLoader.class.getResourceAsStream(path); - if (inputStream == null) - { - throw new ClassNotFoundException(name + " " + path); - } - byte[] data; - try - { - data = ByteStreams.toByteArray(inputStream); - } - catch (IOException e) - { - e.printStackTrace(); - RuneLiteSplashScreen.setError("Failed to load!", "Failed to load class: " + name + " " + path); - throw new RuntimeException("Failed to load class: " + name + " " + path); - } - return defineClass(name, data, 0, data.length); - } - }; - Class clientClass = rsClassLoader.loadClass("client"); - return loadFromClass(config, clientClass); - } - - private static Applet loadVanilla(final RSConfig config) - throws IOException, ClassNotFoundException, InstantiationException, IllegalAccessException - { - RuneLiteSplashScreen.stage(.465, "Starting Vanilla Old School RuneScape"); - - final String codebase = config.getCodeBase(); - final String initialJar = config.getInitialJar(); - final String initialClass = config.getInitialClass(); - final URL url = new URL(codebase + initialJar); - - // Must set parent classloader to null, or it will pull from - // this class's classloader first - final URLClassLoader classloader = new URLClassLoader(new URL[]{url}, null); - final Class clientClass = classloader.loadClass(initialClass); - return loadFromClass(config, clientClass); - } - - private static Applet loadFromClass(final RSConfig config, final Class clientClass) - throws IllegalAccessException, InstantiationException - { - final Applet rs = (Applet) clientClass.newInstance(); - rs.setStub(new RSAppletStub(config)); - return rs; - } -} \ No newline at end of file +} diff --git a/runelite-client/src/main/java/net/runelite/client/rs/WorldSupplier.java b/runelite-client/src/main/java/net/runelite/client/rs/WorldSupplier.java index 956ce1fbda..6e143b1326 100644 --- a/runelite-client/src/main/java/net/runelite/client/rs/WorldSupplier.java +++ b/runelite-client/src/main/java/net/runelite/client/rs/WorldSupplier.java @@ -83,4 +83,4 @@ class WorldSupplier implements Supplier return worlds.poll(); } -} \ No newline at end of file +}