Search in sources :

Example 6 with Alt

use of net.wurstclient.altmanager.Alt in project Wurst-MC-1.12 by Wurst-Imperium.

the class AltsConfig method saveToJson.

@Override
protected JsonElement saveToJson() {
    JsonObject json = new JsonObject();
    for (Alt alt : GuiAltList.alts) {
        JsonObject jsonAlt = new JsonObject();
        jsonAlt.addProperty("password", alt.getPassword());
        jsonAlt.addProperty("name", alt.getName());
        jsonAlt.addProperty("starred", alt.isStarred());
        json.add(alt.getEmail(), jsonAlt);
    }
    return json;
}
Also used : Alt(net.wurstclient.altmanager.Alt) JsonObject(com.google.gson.JsonObject)

Example 7 with Alt

use of net.wurstclient.altmanager.Alt in project Wurst-MC-1.12 by Wurst-Imperium.

the class AltManagerScreen method actionPerformed.

@Override
public void actionPerformed(GuiButton button) {
    if (!button.enabled)
        return;
    if (button.id == 0) {
        // "Use" button
        Alt alt = altList.getSelectedAlt();
        if (alt.isCracked()) {
            LoginManager.changeCrackedName(alt.getEmail());
            mc.displayGuiScreen(prevScreen);
        } else {
            String reply = LoginManager.login(alt.getEmail(), alt.getPassword());
            if (reply.isEmpty()) {
                mc.displayGuiScreen(prevScreen);
                alt.setChecked(mc.session.getUsername());
                ConfigFiles.ALTS.save();
            } else
                errorTimer = 8;
        }
    } else if (button.id == 1)
        // "Direct Login" button
        mc.displayGuiScreen(new DirectLoginScreen(this));
    else if (button.id == 2)
        // "Add" button
        mc.displayGuiScreen(new AddAltScreen(this));
    else if (button.id == 3) {
        // "Star" button
        Alt alt = altList.getSelectedAlt();
        alt.setStarred(!alt.isStarred());
        GuiAltList.sortAlts();
        ConfigFiles.ALTS.save();
    } else if (button.id == 4) {
        // "Edit" button
        Alt alt = altList.getSelectedAlt();
        mc.displayGuiScreen(new EditAltScreen(this, alt));
    } else if (button.id == 5)
        // "Delete" button
        mc.displayGuiScreen(new GuiYesNo(this, "Are you sure you want to remove this alt?", "\"" + altList.getSelectedAlt().getNameOrEmail() + "\" will be lost forever! (A long time!)", "Delete", "Cancel", 1));
    else if (button.id == 6)
        // "Cancel" button
        mc.displayGuiScreen(prevScreen);
    else if (button.id == 7)
        // "Import Alts" button
        new Thread(() -> {
            JFileChooser fileChooser = new JFileChooser(WurstFolders.MAIN.toFile()) {

                @Override
                protected JDialog createDialog(Component parent) throws HeadlessException {
                    JDialog dialog = super.createDialog(parent);
                    dialog.setAlwaysOnTop(true);
                    return dialog;
                }
            };
            fileChooser.setFileSelectionMode(JFileChooser.FILES_ONLY);
            fileChooser.setAcceptAllFileFilterUsed(false);
            fileChooser.addChoosableFileFilter(new FileNameExtensionFilter("TXT file (username:password)", "txt"));
            if (fileChooser.showOpenDialog(FrameHook.getFrame()) == JFileChooser.APPROVE_OPTION)
                try {
                    File file = fileChooser.getSelectedFile();
                    BufferedReader load = new BufferedReader(new FileReader(file));
                    for (String line = ""; (line = load.readLine()) != null; ) {
                        String[] data = line.split(":");
                        if (data.length != 2)
                            continue;
                        GuiAltList.alts.add(new Alt(data[0], data[1], null));
                    }
                    load.close();
                    GuiAltList.sortAlts();
                    ConfigFiles.ALTS.save();
                } catch (IOException e) {
                    e.printStackTrace();
                    MiscUtils.simpleError(e, fileChooser);
                }
        }).start();
}
Also used : GuiYesNo(net.minecraft.client.gui.GuiYesNo) HeadlessException(java.awt.HeadlessException) Alt(net.wurstclient.altmanager.Alt) IOException(java.io.IOException) FileNameExtensionFilter(javax.swing.filechooser.FileNameExtensionFilter) JFileChooser(javax.swing.JFileChooser) BufferedReader(java.io.BufferedReader) FileReader(java.io.FileReader) Component(java.awt.Component) File(java.io.File) JDialog(javax.swing.JDialog)

Example 8 with Alt

use of net.wurstclient.altmanager.Alt in project Wurst-MC-1.12 by Wurst-Imperium.

the class AltsConfig method loadFromJson.

@Override
protected void loadFromJson(JsonElement json) {
    GuiAltList.alts.clear();
    for (Entry<String, JsonElement> entry : json.getAsJsonObject().entrySet()) {
        JsonObject jsonAlt = entry.getValue().getAsJsonObject();
        String email = entry.getKey();
        String password = jsonAlt.get("password") == null ? "" : jsonAlt.get("password").getAsString();
        String name = jsonAlt.get("name") == null ? "" : jsonAlt.get("name").getAsString();
        boolean starred = jsonAlt.get("starred") == null ? false : jsonAlt.get("starred").getAsBoolean();
        GuiAltList.alts.add(new Alt(email, password, name, starred));
    }
    GuiAltList.sortAlts();
}
Also used : JsonElement(com.google.gson.JsonElement) Alt(net.wurstclient.altmanager.Alt) JsonObject(com.google.gson.JsonObject)

Aggregations

Alt (net.wurstclient.altmanager.Alt)8 JsonObject (com.google.gson.JsonObject)2 JsonElement (com.google.gson.JsonElement)1 Component (java.awt.Component)1 HeadlessException (java.awt.HeadlessException)1 BufferedReader (java.io.BufferedReader)1 File (java.io.File)1 FileReader (java.io.FileReader)1 IOException (java.io.IOException)1 JDialog (javax.swing.JDialog)1 JFileChooser (javax.swing.JFileChooser)1 FileNameExtensionFilter (javax.swing.filechooser.FileNameExtensionFilter)1 GuiYesNo (net.minecraft.client.gui.GuiYesNo)1 NetworkPlayerInfo (net.minecraft.client.network.NetworkPlayerInfo)1