Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import java.io.IOException;
- import java.net.Proxy;
- import java.util.UUID;
- import org.lwjgl.input.Keyboard;
- import com.mojang.authlib.Agent;
- import com.mojang.authlib.exceptions.AuthenticationException;
- import com.mojang.authlib.exceptions.InvalidCredentialsException;
- import com.mojang.authlib.exceptions.UserMigratedException;
- import com.mojang.authlib.yggdrasil.YggdrasilAuthenticationService;
- import com.mojang.authlib.yggdrasil.YggdrasilUserAuthentication;
- import net.minecraft.client.Minecraft;
- import net.minecraft.client.gui.Gui;
- import net.minecraft.client.gui.GuiButton;
- import net.minecraft.client.gui.GuiMainMenu;
- import net.minecraft.client.gui.GuiScreen;
- import net.minecraft.client.gui.GuiTextField;
- import net.minecraft.client.gui.ScaledResolution;
- import net.minecraft.util.ResourceLocation;
- import net.minecraft.util.Session;
- public class AccountManager extends GuiScreen {
- boolean logged = false;
- boolean premium;
- public GuiScreen parent;
- public GuiTextField usernameBox;
- public GuiTextField passwordBox;
- public GuiTextField sessionBox;
- public static String lastusername = "";
- public static String lastpassword = "";
- public void onGuiClosed() {
- Keyboard.enableRepeatEvents(false);
- }
- protected void actionPerformed(GuiButton par1GuiButton) {
- if (par1GuiButton.id == 1) {
- if (this.usernameBox.getText().length() > 0) {
- new Thread() {
- public void run() {
- lastusername = AccountManager.this.usernameBox.getText();
- lastpassword = AccountManager.this.passwordBox.getText();
- premium = login(AccountManager.this.usernameBox.getText(),
- AccountManager.this.passwordBox.getText());
- }
- }.start();
- }
- logged = true;
- } else if (par1GuiButton.id == 2) {
- Minecraft.getMinecraft().displayGuiScreen(new GuiMainMenu());
- } else if (par1GuiButton.id == 4) {
- }
- }
- public void keyTyped(char ch, int key) {
- if (key == 1) {
- Minecraft.getMinecraft().displayGuiScreen(this.parent);
- }
- this.usernameBox.textboxKeyTyped(ch, key);
- this.passwordBox.textboxKeyTyped(ch, key);
- if (key == 15) {
- if (this.usernameBox.isFocused()) {
- this.usernameBox.setFocused(false);
- this.passwordBox.setFocused(true);
- } else {
- this.usernameBox.setFocused(true);
- this.passwordBox.setFocused(false);
- }
- }
- if (key == 28) {
- actionPerformed((GuiButton) this.buttonList.get(0));
- }
- if (key == 13) {
- actionPerformed((GuiButton) this.buttonList.get(0));
- }
- ((GuiButton) this.buttonList.get(0)).enabled = (this.usernameBox.getText().length() > 3);
- }
- public void mouseClicked(int x, int y, int b) {
- this.usernameBox.mouseClicked(x, y, b);
- this.passwordBox.mouseClicked(x, y, b);
- try {
- super.mouseClicked(x, y, b);
- } catch (IOException e) {
- e.printStackTrace();
- }
- }
- public void initGui() {
- premium = false;
- Keyboard.enableRepeatEvents(true);
- this.buttonList.add(new Darkbuttons2(1, this.width / 2 - 100, this.height / 4 + 96 + 12, "Login"));
- this.buttonList.add(new Darkbuttons2(3, this.width / 2 - 100, this.height / 4 + 96 + 36, "Generate"));
- this.buttonList.add(new Darkbuttons2(2, this.width / 2 - 100, this.height / 4 + 96 + 106, "Back"));
- this.usernameBox = new GuiTextField(3, this.mc.fontRendererObj, this.width / 2 - 100, 51, 200, 20);
- this.passwordBox = new GuiTextField(4, this.mc.fontRendererObj, this.width / 2 - 100, 91, 200, 20);
- }
- public void drawScreen(int x, int y, float f) {
- ScaledResolution scaledRes = new ScaledResolution(this.mc, mc.displayWidth, mc.displayHeight);
- this.mc.getTextureManager().bindTexture(new ResourceLocation("Xera/Login.jpg"));
- Gui.drawModalRectWithCustomSizedTexture(0, 0, 0.0F, 0.0F, scaledRes.getScaledWidth(), scaledRes.getScaledHeight(), mc.displayWidth, mc.displayHeight);
- Gui.drawRect(1, 1, width, height, 0x80000000);
- drawString(this.mc.fontRendererObj, "Username", this.width / 2 - 100, 38, 10526880);
- drawString(this.mc.fontRendererObj, "§4*", this.width / 2 - 106, 38, 10526880);
- drawString(this.mc.fontRendererObj, "Password", this.width / 2 - 100, 79, 10526880);
- Gui.drawScaledCustomSizeModalRect(0, 0, 0.0F, 0.0F, scaledRes.getScaledWidth(), scaledRes.getScaledHeight(),
- this.width, this.height, scaledRes.getScaledWidth(), scaledRes.getScaledHeight());
- this.mc.fontRendererObj.drawString("§aLogged in: §7" + this.mc.session.getUsername(), 3, 3, 16777215);
- try {
- this.usernameBox.drawTextBox();
- this.passwordBox.drawTextBox();
- } catch (Exception e) {
- }
- super.drawScreen(x, y, f);
- }
- public static boolean login(String username, String password) {
- YggdrasilUserAuthentication auth = new YggdrasilUserAuthentication(
- new YggdrasilAuthenticationService(Proxy.NO_PROXY, UUID.randomUUID().toString()), Agent.MINECRAFT);
- auth.setUsername(username);
- auth.setPassword(password);
- try {
- auth.logIn();
- Minecraft.getMinecraft().session = new Session(auth.getSelectedProfile().getName(),
- auth.getSelectedProfile().getId().toString(), auth.getAuthenticatedToken(), "legacy");
- return true;
- } catch (AuthenticationException e) {
- if (((e instanceof UserMigratedException)) || ((e instanceof InvalidCredentialsException))) {
- Minecraft.getMinecraft().session = new Session(username, UUID.randomUUID().toString(), "-", "legacy");
- return false;
- }
- Minecraft.getMinecraft().session = new Session(username, UUID.randomUUID().toString(), "-", "legacy");
- System.out.println("Couldn't login, is mojang down?");
- }
- return true;
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement