Advertisement
Guest User

AltLoginThread

a guest
Mar 25th, 2018
148
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.49 KB | None | 0 0
  1. import java.net.Proxy;
  2.  
  3. import com.mojang.authlib.Agent;
  4. import com.mojang.authlib.exceptions.AuthenticationException;
  5. import com.mojang.authlib.yggdrasil.YggdrasilAuthenticationService;
  6. import com.mojang.authlib.yggdrasil.YggdrasilUserAuthentication;
  7.  
  8. import net.minecraft.client.Minecraft;
  9. import net.minecraft.util.EnumChatFormatting;
  10. import net.minecraft.util.Session;
  11.  
  12. public final class AltLoginThread
  13. extends Thread {
  14. private final String password;
  15. private String status;
  16. private final String username;
  17. private Minecraft mc = Minecraft.getMinecraft();
  18.  
  19. public AltLoginThread(String username, String password) {
  20. super("Alt Login Thread");
  21. this.username = username;
  22. this.password = password;
  23. this.status = (Object)((Object)EnumChatFormatting.GRAY) + "Waiting...";
  24. }
  25.  
  26. private Session createSession(String username, String password) {
  27. YggdrasilAuthenticationService service = new YggdrasilAuthenticationService(Proxy.NO_PROXY, "");
  28. YggdrasilUserAuthentication auth = (YggdrasilUserAuthentication)service.createUserAuthentication(Agent.MINECRAFT);
  29. auth.setUsername(username);
  30. auth.setPassword(password);
  31. try {
  32. auth.logIn();
  33. return new Session(auth.getSelectedProfile().getName(), auth.getSelectedProfile().getId().toString(), auth.getAuthenticatedToken(), "mojang");
  34. }
  35. catch (AuthenticationException localAuthenticationException) {
  36. localAuthenticationException.printStackTrace();
  37. return null;
  38. }
  39. }
  40.  
  41. public String getStatus() {
  42. return this.status;
  43. }
  44.  
  45. @Override
  46. public void run() {
  47. if (this.password.equals("")) {
  48. this.mc.session = new Session(this.username, "", "", "mojang");
  49. this.status = (Object)((Object)EnumChatFormatting.GREEN) + "Logged in. (" + this.username + " - offline name)";
  50. return;
  51. }
  52. this.status = (Object)((Object)EnumChatFormatting.YELLOW) + "Logging in...";
  53. Session auth = this.createSession(this.username, this.password);
  54. if (auth == null) {
  55. this.status = (Object)((Object)EnumChatFormatting.RED) + "Login failed!";
  56. } else {
  57. this.status = (Object)((Object)EnumChatFormatting.GREEN) + "Logged in. (" + auth.getUsername() + ")";
  58. this.mc.session = auth;
  59. }
  60. }
  61.  
  62. public void setStatus(String status) {
  63. this.status = status;
  64. }
  65. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement