Advertisement
Guest User

Untitled

a guest
May 21st, 2016
66
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 3.36 KB | None | 0 0
  1. class AccountChangerRunnable implements Runnable {
  2.  
  3.     private final Script S;
  4.     private final String username, password;
  5.  
  6.     public AccountChangerRunnable(final Script S, final String username, final String password) {
  7.         this.S = S;
  8.         this.username = username;
  9.         this.password = password;
  10.     }
  11.  
  12.     @Override
  13.     public void run() {
  14.  
  15.         S.getBot().getRandomExecutor().interrupt();
  16.         S.getBot().getRandomExecutor().terminate();
  17.        
  18.         int loginAttempts = 0;
  19.         logStatus("Login attempt " + (loginAttempts + 1));
  20.  
  21.         while(loginAttempts < 3) {
  22.  
  23.             if (isWorldSelectorOpen()) {
  24.                 logStatus("Closing world selector");
  25.                 closeWorldSelector();
  26.             } else {
  27.                 switch (S.client.getLoginUIState()) {
  28.                     case 0:
  29.                         logStatus("Selecting Existing User");
  30.                         selectExistingUser();
  31.                         break;
  32.                     case 1:
  33.                         logStatus("Selecting Log In");
  34.                         selectLogin();
  35.                         break;
  36.                     case 2:
  37.                         logStatus("Entering user details");
  38.                         login();
  39.                         break;
  40.                     case 3:
  41.                         logStatus("Selecting try again");
  42.                         loginAttempts++;
  43.                         logStatus("Login attempt " + (loginAttempts + 1));
  44.                         selectTryAgain();
  45.                         break;
  46.                 }
  47.             }
  48.             if(S.getClient().getLoginState() == Client.LoginState.LOGGED_IN) {
  49.                 logStatus("User is logged in, exiting");
  50.                 new Thread(S.getBot().getRandomExecutor()).start();
  51.                 return;
  52.             }
  53.         }
  54.  
  55.         logStatus("Login failed after 3 attempts, exiting");
  56.     }
  57.  
  58.     private void closeWorldSelector() {
  59.         if(S.getMouse().click(new RectangleDestination(S.bot, new Rectangle(712, 7, 42, 8)))) {
  60.             new ConditionalSleep(4000) {
  61.                 @Override
  62.                 public boolean condition() throws InterruptedException {
  63.                     return !isWorldSelectorOpen();
  64.                 }
  65.             }.sleep();
  66.         }
  67.     }
  68.  
  69.     private boolean isWorldSelectorOpen() {
  70.         return S.colorPicker.isColorAt(24, 471, Color.BLACK);
  71.     }
  72.  
  73.     private void selectTryAgain() {
  74.         S.getMouse().click(new RectangleDestination(S.bot, new Rectangle(320, 265, 120, 20)));
  75.     }
  76.  
  77.     private void selectExistingUser() {
  78.         S.getMouse().click(new RectangleDestination(S.bot, new Rectangle(400, 280, 120, 20)));
  79.     }
  80.  
  81.     private void selectLogin() {
  82.         S.getMouse().click(new RectangleDestination(S.bot, new Rectangle(240, 310, 120, 20)));
  83.     }
  84.  
  85.     private void login() {
  86.         if (S.getKeyboard().typeString(username) && S.getKeyboard().typeString(password)) {
  87.             new ConditionalSleep(100_000) {
  88.                 @Override
  89.                 public boolean condition() throws InterruptedException {
  90.                     return S.getClient().getLoginState() == Client.LoginState.LOGGED_IN;
  91.                 }
  92.             }.sleep();
  93.         }
  94.     }
  95.  
  96.     private void logStatus(final String message) {
  97.         S.log("[Explv's Account Switcher] - " + message);
  98.     }
  99. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement