Add default world plugin override when CLI world argument is present

This commit is contained in:
Jason
2020-01-30 23:46:56 -05:00
parent 8d9e9e6f16
commit 539312ef1d
4 changed files with 58 additions and 44 deletions

View File

@@ -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;
@@ -254,16 +261,16 @@ public class RuneLite
}
}
Integer world = null;
if (options.has("world"))
{
world = options.valueOf(worldInfo);
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());
final ClientLoader clientLoader = new ClientLoader(options.valueOf(updateMode), world);
final ClientLoader clientLoader = new ClientLoader(options.valueOf(updateMode));
Completable.fromAction(clientLoader::get)
.subscribeOn(Schedulers.computation())
.subscribe();
@@ -364,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<Integer> worldArg = Optional.ofNullable(System.getProperty("cli.world")).map(Integer::parseInt);
worldArg.ifPresent(this::setWorld);
// Initialize Discord service
discordService.init();
@@ -412,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();

View File

@@ -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);
}

View File

@@ -49,16 +49,14 @@ public class ClientLoader implements Supplier<Applet>
private static final int NUM_ATTEMPTS = 10;
private final ClientUpdateCheckMode updateCheckMode;
private final Integer worldNumber;
private Object client = null;
private WorldSupplier worldSupplier = new WorldSupplier();
private RSConfig config;
public ClientLoader(ClientUpdateCheckMode updateCheckMode, Integer worldNumber)
public ClientLoader(ClientUpdateCheckMode updateCheckMode)
{
this.updateCheckMode = updateCheckMode;
this.worldNumber = worldNumber;
}
private static Applet loadRLPlus(final RSConfig config)
@@ -187,18 +185,6 @@ public class ClientLoader implements Supplier<Applet>
throw new IOException("Invalid or missing jav_config");
}
if (worldNumber != null)
{
final World world = worldSupplier.get(w -> w.getId() == worldNumber);
if (world == null)
{
log.warn("The provided world: {} could not be found. Reverting to random P2P world.", worldNumber);
return;
}
log.info("Set world to: {}", worldNumber);
config.getAppletProperties().replace("12", worldNumber.toString());
}
return;
}
catch (IOException e)

View File

@@ -85,30 +85,4 @@ class WorldSupplier implements Supplier<World>
return worlds.poll();
}
@Nullable
public World get(Predicate<World> filter)
{
try
{
List<World> filteredWorlds = new WorldClient(RuneLiteAPI.CLIENT)
.lookupWorlds()
.getWorlds()
.stream()
.filter(filter)
.collect(Collectors.toList());
Collections.shuffle(filteredWorlds, random);
if (filteredWorlds.size() > 0)
{
return filteredWorlds.get(0);
}
}
catch (IOException e)
{
log.warn("Unable to retrieve world list", e);
}
return null;
}
}