Add cli functionality to set the world loaded by the client on startup: --world <id> | id must be > 300
This commit is contained in:
@@ -192,7 +192,9 @@ public class RuneLite
|
||||
final ArgumentAcceptingOptionSpec<String> proxyInfo = parser
|
||||
.accepts("proxy")
|
||||
.withRequiredArg().ofType(String.class);
|
||||
|
||||
final ArgumentAcceptingOptionSpec<Integer> worldInfo = parser
|
||||
.accepts("world")
|
||||
.withRequiredArg().ofType(Integer.class);
|
||||
final ArgumentAcceptingOptionSpec<ClientUpdateCheckMode> updateMode = parser
|
||||
.accepts("rs", "Select client type")
|
||||
.withRequiredArg()
|
||||
@@ -252,10 +254,16 @@ public class RuneLite
|
||||
}
|
||||
}
|
||||
|
||||
Integer world = null;
|
||||
if(options.has("world"))
|
||||
{
|
||||
world = options.valueOf(worldInfo);
|
||||
}
|
||||
|
||||
SentryClient client = Sentry.init("https://fa31d674e44247fa93966c69a903770f@sentry.io/1811856");
|
||||
client.setRelease(RuneLiteProperties.getPlusVersion());
|
||||
|
||||
final ClientLoader clientLoader = new ClientLoader(options.valueOf(updateMode));
|
||||
final ClientLoader clientLoader = new ClientLoader(options.valueOf(updateMode), world);
|
||||
Completable.fromAction(clientLoader::get)
|
||||
.subscribeOn(Schedulers.computation())
|
||||
.subscribe();
|
||||
|
||||
@@ -49,14 +49,16 @@ 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)
|
||||
public ClientLoader(ClientUpdateCheckMode updateCheckMode, Integer worldNumber)
|
||||
{
|
||||
this.updateCheckMode = updateCheckMode;
|
||||
this.worldNumber = worldNumber;
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -126,6 +128,18 @@ 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)
|
||||
@@ -222,4 +236,4 @@ public class ClientLoader implements Supplier<Applet>
|
||||
rs.setStub(new RSAppletStub(config));
|
||||
return rs;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -31,8 +31,11 @@ import java.util.EnumSet;
|
||||
import java.util.List;
|
||||
import java.util.Queue;
|
||||
import java.util.Random;
|
||||
import java.util.function.Function;
|
||||
import java.util.function.Predicate;
|
||||
import java.util.function.Supplier;
|
||||
import java.util.stream.Collectors;
|
||||
import javax.annotation.Nullable;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import net.runelite.http.api.RuneLiteAPI;
|
||||
import net.runelite.http.api.worlds.World;
|
||||
@@ -83,4 +86,30 @@ 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;
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user