Advertisement
Guest User

Untitled

a guest
Jan 5th, 2017
91
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 4.46 KB | None | 0 0
  1. package me.danny.peso.gui.ingame;
  2.  
  3. import java.io.IOException;
  4. import java.net.Proxy;
  5.  
  6. import org.lwjgl.input.Keyboard;
  7. import org.lwjgl.opengl.Display;
  8.  
  9. import com.mojang.authlib.Agent;
  10. import com.mojang.authlib.yggdrasil.YggdrasilAuthenticationService;
  11. import com.mojang.authlib.yggdrasil.YggdrasilUserAuthentication;
  12.  
  13. import net.minecraft.client.Minecraft;
  14. import net.minecraft.client.gui.GuiButton;
  15. import net.minecraft.client.gui.GuiMainMenu;
  16. import net.minecraft.client.gui.GuiScreen;
  17. import net.minecraft.client.gui.GuiTextField;
  18. import net.minecraft.client.resources.I18n;
  19. import net.minecraft.util.Session;
  20.  
  21. public class Altmanager extends GuiScreen{
  22.  
  23. public GuiTextField character;
  24. public GuiTextField pwd;
  25. public GuiScreen eventscreen;
  26. public GuiButton back;
  27. public GuiButton addalt;
  28.  
  29. public Altmanager(GuiScreen event) {
  30. eventscreen = event;
  31. }
  32.  
  33.  
  34. public void initGUI() {
  35. Keyboard.enableRepeatEvents(true);
  36. this.buttonList.add(addalt = new GuiButton(1, this.width/2-100, this.height/4+96+36, "Add Alt"));
  37. this.buttonList.add(back = new GuiButton(2, this.width/2-100, this.height/4+96+12, "Back"));
  38.  
  39. character = new GuiTextField(3, fontRendererObj, width/2-100, 76, 200, 20);
  40. pwd = new GuiTextField(4, fontRendererObj, width/2-100, 116, 200, 20);
  41.  
  42. character.setMaxStringLength(25);
  43. pwd.setMaxStringLength(25);
  44.  
  45. }
  46.  
  47. public void updateScreen() {
  48.  
  49. if(character != null && pwd != null) {
  50. character.updateCursorCounter();
  51. pwd.updateCursorCounter();
  52. } else {
  53. character = new GuiTextField(3, fontRendererObj, width/2-100, 76, 200, 20);
  54. pwd = new GuiTextField(4, fontRendererObj, width/2-100, 116, 200, 20);
  55. }
  56.  
  57. character.updateCursorCounter();
  58. pwd.updateCursorCounter();
  59.  
  60. }
  61.  
  62. public void onGuiClosed() {
  63. Keyboard.enableRepeatEvents(false);
  64. }
  65.  
  66. public void mouseClicked(int x, int y, int m) {
  67. character.mouseClicked(x, y, m);
  68. pwd.mouseClicked(x, y, m);
  69. try {
  70. super.mouseClicked(x, y, m);
  71. } catch (Exception e) {
  72. e.printStackTrace();
  73. }
  74. }
  75. protected void keyTyped(char c, int i) {
  76. character.textboxKeyTyped(c, i);
  77. pwd.textboxKeyTyped(c, i);
  78.  
  79. if(c == '\t'){
  80. if(character.isFocused()) {
  81. character.setFocused(false);
  82. pwd.setFocused(true);
  83. } else {
  84. character.setFocused(true);
  85. pwd.setFocused(false);
  86. }
  87. }
  88. if(c == '\r') {
  89. try {
  90. actionPerformed((GuiButton)buttonList.get(0));
  91. } catch (Exception e) {
  92. e.printStackTrace();
  93. }
  94. }
  95.  
  96. }
  97. public String status = "Ready..";
  98.  
  99. public void drawScreen(int mouseX, int mouseY, float partialTicks) {
  100. drawDefaultBackground();
  101. character.drawTextBox();
  102. pwd.drawTextBox();
  103. super.drawScreen(mouseX, mouseY, partialTicks);
  104. this.drawCenteredString(this.fontRendererObj, I18n.format("Alt Manager", new Object[0]), this.width / 2, 20, 16777215);
  105. this.drawCenteredString(this.fontRendererObj, I18n.format(status, new Object[0]), this.width / 2, 30, 16777215);
  106. this.drawCenteredString(fontRendererObj, "Username:", width / 2 - 130, 81, 16777215);
  107. this.drawCenteredString(fontRendererObj, "Password:", width / 2 - 130, 122, 16777215);
  108. if(back != null && addalt != null) {
  109. back.drawButton(mc, mouseX, mouseY);
  110. addalt.drawButton(mc, mouseX, mouseY);
  111. } else {
  112. this.buttonList.add(addalt = new GuiButton(1, width/2-100, height/4+96+12, "Login"));
  113. this.buttonList.add(back = new GuiButton(2, width/2-100, height/4+96+36, "Back"));
  114. }
  115. }
  116.  
  117. protected void actionPerformed(GuiButton button) throws IOException {
  118. if(button.id == 2) {
  119. mc.displayGuiScreen(new GuiMainMenu());
  120. } else {
  121. if(pwd.getText().trim().isEmpty()) {
  122. if(!character.getText().trim().isEmpty()) {
  123. mc.session = new Session (character.getText().trim(), "-", "-", "Legacy");
  124. status = "§2Alt was Succesfull!";
  125. } else {
  126. status = "§4Alt failed!";
  127. }
  128. } else {
  129. if(character.getText().trim().isEmpty()) {
  130. YggdrasilUserAuthentication a = (YggdrasilUserAuthentication) new YggdrasilAuthenticationService(Proxy.NO_PROXY, "").createUserAuthentication(Agent.MINECRAFT);
  131. a.setUsername(character.getText().trim());
  132. a.setPassword(pwd.getText().trim());
  133.  
  134. try {
  135. a.logIn();
  136. mc.session = new Session(a.getSelectedProfile().getName(), a.getSelectedProfile().getId().toString(), a.getAuthenticatedToken(), "mojang");
  137. } catch (Exception e) {
  138. e.printStackTrace();
  139. }
  140. }
  141. }
  142. }
  143. }
  144. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement