Advertisement
Guest User

Untitled

a guest
Feb 25th, 2017
84
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 5.51 KB | None | 0 0
  1. import java.io.IOException;
  2. import java.net.Proxy;
  3. import java.util.UUID;
  4.  
  5. import org.lwjgl.input.Keyboard;
  6.  
  7. import com.mojang.authlib.Agent;
  8. import com.mojang.authlib.exceptions.AuthenticationException;
  9. import com.mojang.authlib.exceptions.InvalidCredentialsException;
  10. import com.mojang.authlib.exceptions.UserMigratedException;
  11. import com.mojang.authlib.yggdrasil.YggdrasilAuthenticationService;
  12. import com.mojang.authlib.yggdrasil.YggdrasilUserAuthentication;
  13.  
  14. import net.minecraft.client.Minecraft;
  15. import net.minecraft.client.gui.Gui;
  16. import net.minecraft.client.gui.GuiButton;
  17. import net.minecraft.client.gui.GuiMainMenu;
  18. import net.minecraft.client.gui.GuiScreen;
  19. import net.minecraft.client.gui.GuiTextField;
  20. import net.minecraft.client.gui.ScaledResolution;
  21. import net.minecraft.util.ResourceLocation;
  22. import net.minecraft.util.Session;
  23.  
  24. public class AccountManager extends GuiScreen {
  25.  
  26. boolean logged = false;
  27. boolean premium;
  28. public GuiScreen parent;
  29. public GuiTextField usernameBox;
  30. public GuiTextField passwordBox;
  31. public GuiTextField sessionBox;
  32. public static String lastusername = "";
  33. public static String lastpassword = "";
  34.  
  35. public void onGuiClosed() {
  36. Keyboard.enableRepeatEvents(false);
  37. }
  38.  
  39. protected void actionPerformed(GuiButton par1GuiButton) {
  40. if (par1GuiButton.id == 1) {
  41. if (this.usernameBox.getText().length() > 0) {
  42. new Thread() {
  43. public void run() {
  44. lastusername = AccountManager.this.usernameBox.getText();
  45. lastpassword = AccountManager.this.passwordBox.getText();
  46. premium = login(AccountManager.this.usernameBox.getText(),
  47. AccountManager.this.passwordBox.getText());
  48. }
  49. }.start();
  50. }
  51. logged = true;
  52. } else if (par1GuiButton.id == 2) {
  53. Minecraft.getMinecraft().displayGuiScreen(new GuiMainMenu());
  54. } else if (par1GuiButton.id == 4) {
  55. }
  56. }
  57.  
  58. public void keyTyped(char ch, int key) {
  59. if (key == 1) {
  60. Minecraft.getMinecraft().displayGuiScreen(this.parent);
  61. }
  62. this.usernameBox.textboxKeyTyped(ch, key);
  63. this.passwordBox.textboxKeyTyped(ch, key);
  64. if (key == 15) {
  65. if (this.usernameBox.isFocused()) {
  66. this.usernameBox.setFocused(false);
  67. this.passwordBox.setFocused(true);
  68. } else {
  69. this.usernameBox.setFocused(true);
  70. this.passwordBox.setFocused(false);
  71. }
  72. }
  73. if (key == 28) {
  74. actionPerformed((GuiButton) this.buttonList.get(0));
  75. }
  76. if (key == 13) {
  77. actionPerformed((GuiButton) this.buttonList.get(0));
  78. }
  79. ((GuiButton) this.buttonList.get(0)).enabled = (this.usernameBox.getText().length() > 3);
  80. }
  81. public void mouseClicked(int x, int y, int b) {
  82. this.usernameBox.mouseClicked(x, y, b);
  83. this.passwordBox.mouseClicked(x, y, b);
  84. try {
  85. super.mouseClicked(x, y, b);
  86. } catch (IOException e) {
  87. e.printStackTrace();
  88. }
  89. }
  90.  
  91. public void initGui() {
  92. premium = false;
  93. Keyboard.enableRepeatEvents(true);
  94. this.buttonList.add(new Darkbuttons2(1, this.width / 2 - 100, this.height / 4 + 96 + 12, "Login"));
  95. this.buttonList.add(new Darkbuttons2(3, this.width / 2 - 100, this.height / 4 + 96 + 36, "Generate"));
  96. this.buttonList.add(new Darkbuttons2(2, this.width / 2 - 100, this.height / 4 + 96 + 106, "Back"));
  97. this.usernameBox = new GuiTextField(3, this.mc.fontRendererObj, this.width / 2 - 100, 51, 200, 20);
  98. this.passwordBox = new GuiTextField(4, this.mc.fontRendererObj, this.width / 2 - 100, 91, 200, 20);
  99. }
  100.  
  101. public void drawScreen(int x, int y, float f) {
  102.  
  103.  
  104. ScaledResolution scaledRes = new ScaledResolution(this.mc, mc.displayWidth, mc.displayHeight);
  105. this.mc.getTextureManager().bindTexture(new ResourceLocation("Xera/Login.jpg"));
  106. Gui.drawModalRectWithCustomSizedTexture(0, 0, 0.0F, 0.0F, scaledRes.getScaledWidth(), scaledRes.getScaledHeight(), mc.displayWidth, mc.displayHeight);
  107. Gui.drawRect(1, 1, width, height, 0x80000000);
  108. drawString(this.mc.fontRendererObj, "Username", this.width / 2 - 100, 38, 10526880);
  109. drawString(this.mc.fontRendererObj, "§4*", this.width / 2 - 106, 38, 10526880);
  110. drawString(this.mc.fontRendererObj, "Password", this.width / 2 - 100, 79, 10526880);
  111. Gui.drawScaledCustomSizeModalRect(0, 0, 0.0F, 0.0F, scaledRes.getScaledWidth(), scaledRes.getScaledHeight(),
  112. this.width, this.height, scaledRes.getScaledWidth(), scaledRes.getScaledHeight());
  113. this.mc.fontRendererObj.drawString("§aLogged in: §7" + this.mc.session.getUsername(), 3, 3, 16777215);
  114. try {
  115. this.usernameBox.drawTextBox();
  116. this.passwordBox.drawTextBox();
  117. } catch (Exception e) {
  118.  
  119. }
  120.  
  121. super.drawScreen(x, y, f);
  122. }
  123.  
  124. public static boolean login(String username, String password) {
  125. YggdrasilUserAuthentication auth = new YggdrasilUserAuthentication(
  126. new YggdrasilAuthenticationService(Proxy.NO_PROXY, UUID.randomUUID().toString()), Agent.MINECRAFT);
  127. auth.setUsername(username);
  128. auth.setPassword(password);
  129. try {
  130. auth.logIn();
  131. Minecraft.getMinecraft().session = new Session(auth.getSelectedProfile().getName(),
  132. auth.getSelectedProfile().getId().toString(), auth.getAuthenticatedToken(), "legacy");
  133. return true;
  134. } catch (AuthenticationException e) {
  135. if (((e instanceof UserMigratedException)) || ((e instanceof InvalidCredentialsException))) {
  136. Minecraft.getMinecraft().session = new Session(username, UUID.randomUUID().toString(), "-", "legacy");
  137. return false;
  138. }
  139. Minecraft.getMinecraft().session = new Session(username, UUID.randomUUID().toString(), "-", "legacy");
  140. System.out.println("Couldn't login, is mojang down?");
  141. }
  142. return true;
  143. }
  144. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement