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;
}
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();
}
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();
}
Aggregations