diff --git a/src/main/java/tech/nevets/jaml/util/Config.java b/src/main/java/tech/nevets/jaml/Config.java similarity index 97% rename from src/main/java/tech/nevets/jaml/util/Config.java rename to src/main/java/tech/nevets/jaml/Config.java index 1d3831c..14ca7ac 100644 --- a/src/main/java/tech/nevets/jaml/util/Config.java +++ b/src/main/java/tech/nevets/jaml/Config.java @@ -1,16 +1,14 @@ -package tech.nevets.jaml.util; +package tech.nevets.jaml; import org.simpleyaml.configuration.file.YamlFile; -import tech.nevets.jaml.JAML; import java.io.IOException; public class Config { private static final YamlFile YML_FILE = new YamlFile(JAML.path + "\\config.yml"); -// private static final YamlFile YML_FILE = new YamlFile("C:\\Users\\svtra\\AppData\\Roaming\\.jaml"); public static void loadConfig() { - YML_FILE.setConfigurationFile("C:\\Users\\svtra\\AppData\\Roaming\\.jaml\\config.yml"); + YML_FILE.setConfigurationFile(JAML.path + "\\config.yml"); try { if (!YML_FILE.exists()) { System.out.println("Config file not found, creating new one..."); diff --git a/src/main/java/tech/nevets/jaml/util/DiscordRP.java b/src/main/java/tech/nevets/jaml/DiscordRP.java similarity index 97% rename from src/main/java/tech/nevets/jaml/util/DiscordRP.java rename to src/main/java/tech/nevets/jaml/DiscordRP.java index fa1c676..8036a9f 100644 --- a/src/main/java/tech/nevets/jaml/util/DiscordRP.java +++ b/src/main/java/tech/nevets/jaml/DiscordRP.java @@ -1,4 +1,4 @@ -package tech.nevets.jaml.util; +package tech.nevets.jaml; import net.arikia.dev.drpc.DiscordEventHandlers; import net.arikia.dev.drpc.DiscordRPC; diff --git a/src/main/java/tech/nevets/jaml/JAML.java b/src/main/java/tech/nevets/jaml/JAML.java index 9854065..2d5a139 100644 --- a/src/main/java/tech/nevets/jaml/JAML.java +++ b/src/main/java/tech/nevets/jaml/JAML.java @@ -1,16 +1,11 @@ package tech.nevets.jaml; -import org.simpleyaml.configuration.file.YamlFile; import tech.nevets.jaml.gui.GuiHandler; -import tech.nevets.jaml.util.Config; -import tech.nevets.jaml.util.DiscordRP; -import tech.nevets.jaml.util.LoaderUtils; -import tech.nevets.jaml.util.ProfileUtils; +import tech.nevets.jaml.util.*; import java.nio.file.Path; public class JAML { - //public static YamlFile config = Config.getConfig(); public static Path path; public static GuiHandler guiHandler; @@ -24,6 +19,7 @@ public class JAML { DiscordRP.update("", ""); guiHandler = new GuiHandler(); + // try { // System.out.println(VersionFetcher.getLatestVersion("release")); // } catch (IOException e) { @@ -72,5 +68,14 @@ public class JAML { } catch (Exception e) { e.printStackTrace(); } + + try { + Path skinsPath = Path.of(path + "\\data\\skins\\"); + if (!skinsPath.toFile().exists()) { + skinsPath.toFile().mkdirs(); + } + } catch (Exception e) { + e.printStackTrace(); + } } } \ No newline at end of file diff --git a/src/main/java/tech/nevets/jaml/util/Launch.java b/src/main/java/tech/nevets/jaml/Launch.java similarity index 98% rename from src/main/java/tech/nevets/jaml/util/Launch.java rename to src/main/java/tech/nevets/jaml/Launch.java index d63cbfa..460283d 100644 --- a/src/main/java/tech/nevets/jaml/util/Launch.java +++ b/src/main/java/tech/nevets/jaml/Launch.java @@ -1,4 +1,6 @@ -package tech.nevets.jaml.util; +package tech.nevets.jaml; + +import tech.nevets.jaml.util.ProfileUtils; import java.io.BufferedReader; import java.io.IOException; diff --git a/src/main/java/tech/nevets/jaml/gui/FirstLaunchGui.java b/src/main/java/tech/nevets/jaml/gui/FirstLaunchGui.java index f8b7259..0c625dc 100644 --- a/src/main/java/tech/nevets/jaml/gui/FirstLaunchGui.java +++ b/src/main/java/tech/nevets/jaml/gui/FirstLaunchGui.java @@ -1,10 +1,9 @@ package tech.nevets.jaml.gui; -import tech.nevets.jaml.util.FirstLaunch; +import tech.nevets.jaml.init.FirstLaunch; import tech.nevets.jaml.JAML; import tech.nevets.jaml.objects.Profile; import tech.nevets.jaml.util.ProfileUtils; -import tech.nevets.jaml.util.Encryptor; import javax.swing.*; import java.awt.*; diff --git a/src/main/java/tech/nevets/jaml/gui/FirstLoginGui.java b/src/main/java/tech/nevets/jaml/gui/FirstLoginGui.java new file mode 100644 index 0000000..7f003d5 --- /dev/null +++ b/src/main/java/tech/nevets/jaml/gui/FirstLoginGui.java @@ -0,0 +1,93 @@ +package tech.nevets.jaml.gui; + +import tech.nevets.jaml.objects.Profile; +import tech.nevets.jaml.util.LoaderUtils; +import tech.nevets.jaml.util.ProfileUtils; + +import javax.swing.*; +import javax.swing.border.EmptyBorder; +import java.io.File; +import java.io.IOException; + +public class FirstLoginGui extends JFrame { + private JPanel contentPane; + + public FirstLoginGui() { + setResizable(false); + setDefaultCloseOperation(JFrame.DISPOSE_ON_CLOSE); + setBounds(100, 100, 360, 330); + contentPane = new JPanel(); + contentPane.setBorder(new EmptyBorder(5, 5, 5, 5)); + setContentPane(contentPane); + contentPane.setLayout(null); + + JLabel profileNameLabel = new JLabel("Profile Name:"); + profileNameLabel.setBounds(10, 14, 84, 31); + contentPane.add(profileNameLabel); + JTextField profileNameField = new JTextField(20); + profileNameField.setBounds(94, 18, 231, 23); + contentPane.add(profileNameField); + + JLabel gamePathLabel = new JLabel("Game Path:"); + gamePathLabel.setBounds(10, 56, 84, 31); + contentPane.add(gamePathLabel); + + JButton gamePathButton = new JButton("..."); + gamePathButton.setBounds(302, 60, 23, 23); + JTextField gamePathField = new JTextField(20); + gamePathField.setBounds(94, 60, 209, 23); + gamePathButton.addActionListener(ae -> { + JFileChooser fileChooser = new JFileChooser(System.getenv("APPDATA") + "\\.minecraft\\"); + fileChooser.setFileSelectionMode(JFileChooser.DIRECTORIES_ONLY); + fileChooser.showSaveDialog(null); + if (fileChooser.getSelectedFile() == null) { return; } + gamePathField.setText(fileChooser.getSelectedFile().toString()); + fileChooser.setVisible(false); + }); + contentPane.add(gamePathField); + contentPane.add(gamePathButton); + + JLabel versionLabel = new JLabel("Version:"); + versionLabel.setBounds(10, 98, 84, 31); + contentPane.add(versionLabel); + JTextField versionField = new JTextField(20); + versionField.setBounds(94, 102, 231, 23); + contentPane.add(versionField); + + JLabel loaderLabel = new JLabel("Loader:"); + loaderLabel.setBounds(10, 140, 84, 31); + contentPane.add(loaderLabel); + + JComboBox loaderDropdown = new JComboBox(LoaderUtils.loaders); + loaderDropdown.setBounds(94, 144, 231, 23); + contentPane.add(loaderDropdown); + + JLabel offlineModeLabel = new JLabel("Offline Mode:"); + offlineModeLabel.setBounds(10, 182, 84, 31); + contentPane.add(offlineModeLabel); + JCheckBox offlineModeBox = new JCheckBox(""); + offlineModeBox.setBounds(94, 185, 21, 23); + contentPane.add(offlineModeBox); + + JButton button = new JButton("Create Profile"); + button.setBounds(64, 234, 217, 37); + button.addActionListener(al -> { + Profile profile = new Profile(); + profile.setProfileName(profileNameField.getText()); + + profile.setGamePath(new File(gamePathField.getText())); + profile.setVersion(versionField.getText()); + profile.setLoader(loaderDropdown.getSelectedItem().toString()); + profile.setOfflineMode(offlineModeBox.isSelected()); + try { + ProfileUtils.createProfile(profile); + } catch (IOException e) { + e.printStackTrace(); + } + ProfileUtils.getProfileList(); + + this.dispose(); + }); + contentPane.add(button); + } +} diff --git a/src/main/java/tech/nevets/jaml/gui/GuiHandler.java b/src/main/java/tech/nevets/jaml/gui/GuiHandler.java index c503258..ddbf11b 100644 --- a/src/main/java/tech/nevets/jaml/gui/GuiHandler.java +++ b/src/main/java/tech/nevets/jaml/gui/GuiHandler.java @@ -1,6 +1,6 @@ package tech.nevets.jaml.gui; -import tech.nevets.jaml.util.Config; +import tech.nevets.jaml.Config; import tech.nevets.jaml.JAML; import javax.swing.*; diff --git a/src/main/java/tech/nevets/jaml/gui/HomeGui.java b/src/main/java/tech/nevets/jaml/gui/HomeGui.java index 750411b..51837e6 100644 --- a/src/main/java/tech/nevets/jaml/gui/HomeGui.java +++ b/src/main/java/tech/nevets/jaml/gui/HomeGui.java @@ -10,11 +10,10 @@ import javax.swing.border.EmptyBorder; public class HomeGui extends JFrame { - //private JPanel contentPane; private JTabbedPane tabPanel; private JPanel homePanel; - - //private JPanel contentPane; + private JPanel userPanel; + private JPanel profilePanel; public HomeGui() { setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); diff --git a/src/main/java/tech/nevets/jaml/gui/NewProfileGui.java b/src/main/java/tech/nevets/jaml/gui/NewProfileGui.java index 5bc5be4..84bdd54 100644 --- a/src/main/java/tech/nevets/jaml/gui/NewProfileGui.java +++ b/src/main/java/tech/nevets/jaml/gui/NewProfileGui.java @@ -8,13 +8,13 @@ import javax.swing.*; import javax.swing.border.EmptyBorder; import java.io.File; import java.io.IOException; -import java.util.ArrayList; public class NewProfileGui extends JFrame { private JPanel contentPane; public NewProfileGui() { + setUndecorated(true); setResizable(false); setDefaultCloseOperation(JFrame.DISPOSE_ON_CLOSE); setBounds(100, 100, 360, 330); @@ -90,7 +90,6 @@ public class NewProfileGui extends JFrame { this.dispose(); }); - contentPane.add(button); } } diff --git a/src/main/java/tech/nevets/jaml/gui/panels/BackgroundPanel.java b/src/main/java/tech/nevets/jaml/gui/panels/BackgroundPanel.java deleted file mode 100644 index 1365ed9..0000000 --- a/src/main/java/tech/nevets/jaml/gui/panels/BackgroundPanel.java +++ /dev/null @@ -1,15 +0,0 @@ -package tech.nevets.jaml.gui.panels; - -import tech.nevets.jaml.JAML; - -import javax.swing.*; -import java.awt.*; - -public class BackgroundPanel extends JPanel { - @Override - protected void paintComponent(Graphics g) { - super.paintComponent(g); - ImageIcon img = new ImageIcon(JAML.path + "\\assets\\background.png"); - g.drawImage(img.getImage(), 0, 0, this.getWidth(), this.getHeight(), null); - } -} diff --git a/src/main/java/tech/nevets/jaml/util/FirstLaunch.java b/src/main/java/tech/nevets/jaml/init/FirstLaunch.java similarity index 93% rename from src/main/java/tech/nevets/jaml/util/FirstLaunch.java rename to src/main/java/tech/nevets/jaml/init/FirstLaunch.java index 0880732..a3b8f05 100644 --- a/src/main/java/tech/nevets/jaml/util/FirstLaunch.java +++ b/src/main/java/tech/nevets/jaml/init/FirstLaunch.java @@ -1,6 +1,7 @@ -package tech.nevets.jaml.util; +package tech.nevets.jaml.init; import org.apache.commons.io.FileUtils; +import tech.nevets.jaml.Config; import tech.nevets.jaml.JAML; import java.io.File; diff --git a/src/main/java/tech/nevets/jaml/objects/User.java b/src/main/java/tech/nevets/jaml/objects/User.java index 18c5a04..905d854 100644 --- a/src/main/java/tech/nevets/jaml/objects/User.java +++ b/src/main/java/tech/nevets/jaml/objects/User.java @@ -9,6 +9,22 @@ public class User { private String key; private String salt; + public String getUsername() { + return username; + } + + public void setUsername(String username) { + this.username = username; + } + + public UUID getUuid() { + return uuid; + } + + public void setUuid(UUID uuid) { + this.uuid = uuid; + } + public String getAccessToken() { return accessToken; } diff --git a/src/main/java/tech/nevets/jaml/util/ProfileUtils.java b/src/main/java/tech/nevets/jaml/util/ProfileUtils.java index c17c441..0691dbd 100644 --- a/src/main/java/tech/nevets/jaml/util/ProfileUtils.java +++ b/src/main/java/tech/nevets/jaml/util/ProfileUtils.java @@ -2,6 +2,7 @@ package tech.nevets.jaml.util; import com.google.gson.*; import org.apache.commons.io.FilenameUtils; +import tech.nevets.jaml.Config; import tech.nevets.jaml.JAML; import tech.nevets.jaml.objects.Profile; diff --git a/src/main/java/tech/nevets/jaml/util/SkinFetcher.java b/src/main/java/tech/nevets/jaml/util/SkinFetcher.java new file mode 100644 index 0000000..37a1a81 --- /dev/null +++ b/src/main/java/tech/nevets/jaml/util/SkinFetcher.java @@ -0,0 +1,48 @@ +package tech.nevets.jaml.util; + +import org.apache.commons.io.FileUtils; +import tech.nevets.jaml.JAML; + +import java.io.File; +import java.io.IOException; +import java.net.URL; +import java.net.http.HttpClient; +import java.net.http.HttpRequest; +import java.net.http.HttpResponse; +import java.util.HashMap; +import java.util.Map; + +public class SkinFetcher { + + public static File getSkinImage() { + try { + URL imageUrl = new URL("https://minotar.net/armor/body/" + UserUtils.getActiveUser().getUuid().toString() + "/400.png"); + FileUtils.copyURLToFile(imageUrl, new File(JAML.path + "\\data\\skins\\" + UserUtils.getActiveUser().getUuid() + "-rendered.png")); + return new File(JAML.path + "\\data\\skins\\" + UserUtils.getActiveUser().getUuid() + "-rendered.png"); + } catch (IOException e) { + e.printStackTrace(); + return null; + } + } + + public static void uploadSkinImage(File skin) { + Map data = new HashMap<>(); + data.put("username", "abc"); + data.put("password", "123"); + data.put("custom", "secret"); + data.put("ts", System.currentTimeMillis()); + +// try { +// HttpClient client = HttpClient.newHttpClient(); +// HttpRequest request = HttpRequest.newBuilder() +// .POST(buildFormDataFromMap(data)) +// .uri("https://authserver.mojang.com") +// .build(); +// HttpResponse response = client.send(request, HttpResponse.BodyHandlers.ofString()); +// +// String data = response.body(); +// } catch (IOException | InterruptedException e) { +// e.printStackTrace(); +// } + } +} diff --git a/src/main/java/tech/nevets/jaml/util/SkinUtils.java b/src/main/java/tech/nevets/jaml/util/SkinUtils.java deleted file mode 100644 index 72b8412..0000000 --- a/src/main/java/tech/nevets/jaml/util/SkinUtils.java +++ /dev/null @@ -1,18 +0,0 @@ -package tech.nevets.jaml.util; - -import java.io.File; -import java.net.MalformedURLException; -import java.net.URL; - -public class SkinUtils { - - public static File getSkinImage() { - try { - URL imageUrl = new URL("https://minotar.net/armor/body/"); - } catch (MalformedURLException e) { - e.printStackTrace(); - } - - return null; - } -} diff --git a/src/main/java/tech/nevets/jaml/util/UserUtils.java b/src/main/java/tech/nevets/jaml/util/UserUtils.java new file mode 100644 index 0000000..11229d2 --- /dev/null +++ b/src/main/java/tech/nevets/jaml/util/UserUtils.java @@ -0,0 +1,23 @@ +package tech.nevets.jaml.util; + +import tech.nevets.jaml.objects.User; + +public class UserUtils { + private static User activeUser; + + public static void createUser() { + + } + + public static User getUser() { + return new User(); + } + + public static void setActiveUser(User user) { + activeUser = user; + } + + public static User getActiveUser() { + return activeUser; + } +}