Skip to content

Microbot.hopToWorld() method returns false even for successful world hops #1550

@Caleb-Lite

Description

@Caleb-Lite

Bug description

The current implementation of hopToWorld returns the value of Microbot.isHopping() immediately after issuing the client-thread hop request, so it often reports false once the client transitions from the “HOPPING” state to the login screen or straight into the destination world. We probably need to sleepUntilTrue somewhere.

public static boolean hopToWorld(int worldNumber) {
        if (!Microbot.isLoggedIn()) {
            return false;
        }
        if (Microbot.isHopping()) {
            log.error("Already hopping world");
            return true;
        }
        if (Microbot.cantHopWorld) {
            log.error("Can't hop world, already trying to hop");
            return false;
        }
        boolean isHopping = Microbot.getClientThread().runOnClientThreadOptional(() -> {
            if (Microbot.getClient().getLocalPlayer() != null && Microbot.getClient().getLocalPlayer().isInteracting()) {
                log.error("Local player is interacting, cannot hop worlds");
                return false;
            }
            if (quickHopTargetWorld != null || Microbot.getClient().getGameState() != GameState.LOGGED_IN) {
                log.error("Quick hop target world is not null or game state is not logged in");
                return false;
            }
            if (Microbot.getClient().getWorld() == worldNumber) {
                return false;
            }
            World newWorld = Microbot.getWorldService().getWorlds().findWorld(worldNumber);
            if (newWorld == null) {
                Microbot.getNotifier().notify("Invalid World");
                System.out.println("Tried to hop to an invalid world");
                return false;
            }
            final net.runelite.api.World rsWorld = Microbot.getClient().createWorld();
            if (rsWorld == null) return false;

            quickHopTargetWorld = rsWorld;
            rsWorld.setActivity(newWorld.getActivity());
            rsWorld.setAddress(newWorld.getAddress());
            rsWorld.setId(newWorld.getId());
            rsWorld.setPlayerCount(newWorld.getPlayers());
            rsWorld.setLocation(newWorld.getLocation());
            rsWorld.setTypes(WorldUtil.toWorldTypes(newWorld.getTypes()));

            Microbot.getClient().openWorldHopper();
            Microbot.getClient().hopToWorld(rsWorld);
            quickHopTargetWorld = null;
            sleep(600);
            sleepUntil(() -> Microbot.isHopping() || Rs2Widget.getWidget(193, 0) != null, 2000);
            return Microbot.isHopping();
        }).orElse(false);
        if (!isHopping) {
            Widget confirmRoot = Rs2Widget.getWidget(193, 0);
            if (confirmRoot != null) {
                List<Widget> children = Arrays.stream(confirmRoot.getDynamicChildren()).collect(Collectors.toList());
                Widget switchWorldWidget =
                        sleepUntilNotNull(() -> Rs2Widget.findWidget("Switch world", children, true), 2000);
                if (switchWorldWidget != null) {
                    boolean clicked = Rs2Widget.clickWidget(switchWorldWidget);
                    if (clicked) {
                        sleepUntil(Microbot::isHopping, 4000);
                        return Microbot.isHopping();
                    }
                }
            }
        }
        if (!isHopping) {
            log.error("Failed to hop to world {}", worldNumber);
        }
        return false;
    }

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions