Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- class AccountChangerRunnable implements Runnable {
- private final Script S;
- private final String username, password;
- public AccountChangerRunnable(final Script S, final String username, final String password) {
- this.S = S;
- this.username = username;
- this.password = password;
- }
- @Override
- public void run() {
- S.getBot().getRandomExecutor().interrupt();
- S.getBot().getRandomExecutor().terminate();
- int loginAttempts = 0;
- logStatus("Login attempt " + (loginAttempts + 1));
- while(loginAttempts < 3) {
- if (isWorldSelectorOpen()) {
- logStatus("Closing world selector");
- closeWorldSelector();
- } else {
- switch (S.client.getLoginUIState()) {
- case 0:
- logStatus("Selecting Existing User");
- selectExistingUser();
- break;
- case 1:
- logStatus("Selecting Log In");
- selectLogin();
- break;
- case 2:
- logStatus("Entering user details");
- login();
- break;
- case 3:
- logStatus("Selecting try again");
- loginAttempts++;
- logStatus("Login attempt " + (loginAttempts + 1));
- selectTryAgain();
- break;
- }
- }
- if(S.getClient().getLoginState() == Client.LoginState.LOGGED_IN) {
- logStatus("User is logged in, exiting");
- new Thread(S.getBot().getRandomExecutor()).start();
- return;
- }
- }
- logStatus("Login failed after 3 attempts, exiting");
- }
- private void closeWorldSelector() {
- if(S.getMouse().click(new RectangleDestination(S.bot, new Rectangle(712, 7, 42, 8)))) {
- new ConditionalSleep(4000) {
- @Override
- public boolean condition() throws InterruptedException {
- return !isWorldSelectorOpen();
- }
- }.sleep();
- }
- }
- private boolean isWorldSelectorOpen() {
- return S.colorPicker.isColorAt(24, 471, Color.BLACK);
- }
- private void selectTryAgain() {
- S.getMouse().click(new RectangleDestination(S.bot, new Rectangle(320, 265, 120, 20)));
- }
- private void selectExistingUser() {
- S.getMouse().click(new RectangleDestination(S.bot, new Rectangle(400, 280, 120, 20)));
- }
- private void selectLogin() {
- S.getMouse().click(new RectangleDestination(S.bot, new Rectangle(240, 310, 120, 20)));
- }
- private void login() {
- if (S.getKeyboard().typeString(username) && S.getKeyboard().typeString(password)) {
- new ConditionalSleep(100_000) {
- @Override
- public boolean condition() throws InterruptedException {
- return S.getClient().getLoginState() == Client.LoginState.LOGGED_IN;
- }
- }.sleep();
- }
- }
- private void logStatus(final String message) {
- S.log("[Explv's Account Switcher] - " + message);
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement