Advertisement
GeforceR

Altlogin

Nov 10th, 2016
156
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.18 KB | None | 0 0
  1. package de.puja.gui.altman;
  2.  
  3. import java.io.IOException;
  4. import java.net.Proxy;
  5.  
  6. import com.mojang.authlib.Agent;
  7. import com.mojang.authlib.yggdrasil.YggdrasilAuthenticationService;
  8. import com.mojang.authlib.yggdrasil.YggdrasilUserAuthentication;
  9.  
  10. import net.minecraft.client.gui.Gui;
  11. import net.minecraft.client.gui.GuiButton;
  12. import net.minecraft.client.gui.GuiMainMenu;
  13. import net.minecraft.client.gui.GuiScreen;
  14. import net.minecraft.client.gui.GuiTextField;
  15. import net.minecraft.util.Session;
  16.  
  17. public class AltLogin extends GuiScreen {
  18.  
  19. public GuiTextField email;
  20. public GuiTextField passw;
  21.  
  22. @Override
  23. public void initGui() {
  24.  
  25. email = new GuiTextField(2, mc.fontRendererObj, width / 2 - 100, height / 4 + 30, 200, 20);
  26. passw = new GuiTextField(3, mc.fontRendererObj, width / 2 - 100, height / 4 + 90, 200, 20);
  27.  
  28. }
  29.  
  30. @Override
  31. public void updateScreen() {
  32. email.updateCursorCounter();
  33. passw.updateCursorCounter();
  34. }
  35.  
  36. @Override
  37. protected void mouseClicked(int mouseX, int mouseY, int mouseButton) throws IOException {
  38. email.mouseClicked(mouseX, mouseY, mouseButton);
  39. passw.mouseClicked(mouseX, mouseY, mouseButton);
  40.  
  41. try {
  42. super.mouseClicked(mouseX, mouseY, mouseButton);
  43. } catch(Exception e) {
  44.  
  45. }
  46.  
  47. }
  48.  
  49. @Override
  50. protected void keyTyped(char typedChar, int keyCode) throws IOException {
  51. email.textboxKeyTyped(typedChar, keyCode);
  52. passw.textboxKeyTyped(typedChar, keyCode);
  53.  
  54. if(typedChar == '\t') {
  55. if(email.isFocused()) {
  56. email.setFocused(false);
  57. passw.setFocused(true);
  58. } else {
  59. email.setFocused(true);
  60. passw.setFocused(false);
  61. }
  62. }
  63.  
  64. if(typedChar == '\r') {
  65. actionPerformed((GuiButton)buttonList.get(0));
  66. }
  67.  
  68. }
  69.  
  70. @Override
  71. public void drawScreen(int mouseX, int mouseY, float partialTicks) {
  72. drawDefaultBackground();
  73. email.drawTextBox();
  74. passw.drawTextBox();
  75.  
  76. drawString(fontRendererObj, "Email/Username:", width / 2 - 100, height / 4 + 20, 0xFFFFFFFF);
  77. drawString(fontRendererObj, "Password:", width / 2 - 100, height / 4 + 80, 0xFFFFFFFF);
  78.  
  79. buttonList.add(new GuiButton(0, width / 2 - 100, 250, "Login"));
  80. buttonList.add(new GuiButton(1, width / 2 - 100, 270, "Back"));
  81.  
  82. super.drawScreen(mouseX, mouseY, partialTicks);
  83.  
  84. }
  85.  
  86. @Override
  87. protected void actionPerformed(GuiButton button) throws IOException {
  88. if(button.id == 1) {
  89. mc.displayGuiScreen(new GuiMainMenu());
  90. }
  91.  
  92. if(button.id == 0) {
  93. if(passw.getText().isEmpty()) {
  94. if(!email.getText().isEmpty()) {
  95. mc.session = new Session(email.getText().trim(), "-", "-", "Legacy");
  96. }
  97. } else {
  98. if(!email.getText().isEmpty()) {
  99. YggdrasilUserAuthentication g = (YggdrasilUserAuthentication) new YggdrasilAuthenticationService(Proxy.NO_PROXY, "").createUserAuthentication(Agent.MINECRAFT);
  100.  
  101. g.setUsername(email.getText().trim());
  102. g.setPassword(passw.getText().trim());
  103.  
  104. try {
  105. g.logIn();
  106. mc.session = new Session(g.getSelectedProfile().getName(), g.getSelectedProfile().getId().toString(), g.getAuthenticatedToken(), "mojang");
  107. } catch(Exception e) {
  108.  
  109. }
  110.  
  111. }
  112. }
  113. }
  114.  
  115. }
  116.  
  117. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement