diff --git a/.gitignore b/.gitignore index c175124..ebea6a1 100644 --- a/.gitignore +++ b/.gitignore @@ -146,4 +146,7 @@ src/test .classpath .project bin/ -.settings/ \ No newline at end of file +.settings/ +!packr/packr-all-4.0.0.jar +!packr/PackrConfig.json +packr/ \ No newline at end of file diff --git a/build.gradle b/build.gradle index b00d22e..fe72e24 100644 --- a/build.gradle +++ b/build.gradle @@ -1,6 +1,9 @@ +//import edu.sc.seis.launch4j.tasks.Launch4jLibraryTask + plugins { id 'java' id 'com.github.johnrengelman.shadow' version '5.2.0' +// id 'edu.sc.seis.launch4j' version '2.5.1' } group 'tech.nevets.jaml' @@ -36,4 +39,30 @@ shadowJar { 'Main-Class': 'tech.nevets.jaml.JAML' ) } -} \ No newline at end of file +} + +//launch4j { +// mainClassName = 'tech.nevets.jaml.JAML' +// outfile = 'JAML.exe' +// jarTask = project.tasks.shadowJar +// fileDescription = 'Just Another Minecraft Launcher' +// +//} +// +//task Build(type: Launch4jLibraryTask) { +// mainClassName = 'tech.nevets.jaml.JAML' +// outfile = 'JAML.exe' +// jarTask = project.tasks.shadowJar +// fileDescription = 'Just Another Minecraft Launcher' +// bundledJre64Bit = true +// bundledJrePath = '' +//} +// +//task winBuild(type: Launch4jLibraryTask) { +// mainClassName = 'tech.nevets.jaml.JAML' +// outfile = 'JAML.exe' +// jarTask = project.tasks.shadowJar +// fileDescription = 'Just Another Minecraft Launcher' +// bundledJre64Bit = true +// bundledJrePath = '' +//} \ No newline at end of file diff --git a/packr/PackrConfig.json b/packr/PackrConfig.json new file mode 100644 index 0000000..ee5c85c --- /dev/null +++ b/packr/PackrConfig.json @@ -0,0 +1,15 @@ +{ + "platform": "windows64", + "jdk": "https://github.com/adoptium/temurin17-binaries/releases/download/jdk-17.0.2%2B8/OpenJDK17U-jdk_x64_windows_hotspot_17.0.2_8.zip", + "executable": "JAML", + "jrePath": "", + "mainclass": "tech.nevets.jaml.JAML", + "vmargs": [ + "Xmx2G" + ], + "resources": [ + "../src/main/resources" + ], + "minimizejre": "soft", + "output": "packr-out" +} \ No newline at end of file diff --git a/packr/packr-all-4.0.0.jar b/packr/packr-all-4.0.0.jar new file mode 100644 index 0000000..4fcf201 Binary files /dev/null and b/packr/packr-all-4.0.0.jar differ diff --git a/src/main/java/tech/nevets/jaml/JAML.java b/src/main/java/tech/nevets/jaml/JAML.java index 2d5a139..7bb4417 100644 --- a/src/main/java/tech/nevets/jaml/JAML.java +++ b/src/main/java/tech/nevets/jaml/JAML.java @@ -1,7 +1,6 @@ package tech.nevets.jaml; import tech.nevets.jaml.gui.GuiHandler; -import tech.nevets.jaml.util.*; import java.nio.file.Path; @@ -10,12 +9,13 @@ public class JAML { public static GuiHandler guiHandler; public static void main(String[] args) { + //TODO Create logic to check for first launch without the use of config + //TODO make guiHandler run first with the initial splash screen while backend is starting, then start homeGui when done. (Possibly multithreaded) + + GuiHandler.startup(); + DiscordRP.start(); - makeDirs(); - Config.loadConfig(); - ProfileUtils.getProfileList(); - ProfileUtils.getActiveProfile(); - LoaderUtils.getLoaders(); + DiscordRP.update("", ""); guiHandler = new GuiHandler(); @@ -26,56 +26,4 @@ public class JAML { // e.printStackTrace(); // } } - - private static void makeDirs() { - if (System.getenv("JAML_HOME") == null) { - path = Path.of(System.getenv("APPDATA") + "\\.jaml\\"); - } else { - path = Path.of(System.getenv("JAML_HOME")); - } - - try { - if (!path.toFile().exists()) { - path.toFile().mkdirs(); - } - } catch (Exception e) { - System.out.println("Invalid path, please check your config.yml and try again"); - } - - try { - Path profilePath = Path.of(path + "\\profiles\\"); - if (!profilePath.toFile().exists()) { - profilePath.toFile().mkdirs(); - } - } catch (Exception e) { - e.printStackTrace(); - } - - try { - Path profilePath = Path.of(path + "\\assets\\"); - if (!profilePath.toFile().exists()) { - profilePath.toFile().mkdirs(); - } - } catch (Exception e) { - e.printStackTrace(); - } - - try { - Path dataPath = Path.of(path + "\\data\\"); - if (!dataPath.toFile().exists()) { - dataPath.toFile().mkdirs(); - } - } 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/auth/AuthRequests.java b/src/main/java/tech/nevets/jaml/auth/AuthRequests.java new file mode 100644 index 0000000..8963a7d --- /dev/null +++ b/src/main/java/tech/nevets/jaml/auth/AuthRequests.java @@ -0,0 +1,25 @@ +package tech.nevets.jaml.auth; + +import tech.nevets.jaml.util.HttpUtils; + +import java.net.URI; +import java.net.URISyntaxException; +import java.util.HashMap; +import java.util.Map; + +public class AuthRequests { + + public static void login() { + String accountName = "account_name"; + String accountPassword = "password123"; + + try { + Map headers = new HashMap<>(); + + String json = "{ \"agent\": { \"name\": \"Minecraft\", \"version\": 1 }, \"username\": \"" + accountName + "\", \"password\": \"" + accountPassword + "\" }"; + HttpUtils.post(new URI("https://authserver.mojang.com/authenticate"), headers, json); + } catch (URISyntaxException e) { + e.printStackTrace(); + } + } +} diff --git a/src/main/java/tech/nevets/jaml/gui/GuiHandler.java b/src/main/java/tech/nevets/jaml/gui/GuiHandler.java index ddbf11b..1368199 100644 --- a/src/main/java/tech/nevets/jaml/gui/GuiHandler.java +++ b/src/main/java/tech/nevets/jaml/gui/GuiHandler.java @@ -4,9 +4,15 @@ import tech.nevets.jaml.Config; import tech.nevets.jaml.JAML; import javax.swing.*; +import java.awt.*; public class GuiHandler { + public static final int SCREEN_WIDTH = (int) Toolkit.getDefaultToolkit().getScreenSize().getWidth(); + public static final int SCREEN_HEIGHT = (int) Toolkit.getDefaultToolkit().getScreenSize().getHeight(); + + private static StartupGui startupFrame; + public GuiHandler() { if (Config.getConfig().getBoolean("launcher.first-launch")) { FirstLaunchGui firstLaunchGui = new FirstLaunchGui(); @@ -14,16 +20,23 @@ public class GuiHandler { firstLaunchThread.start(); } + startupFrame.dispose(); + Thread homeGuiThread = new Thread(() -> { HomeGui frame = new HomeGui(); frame.setTitle("JAML"); frame.setIconImage(new ImageIcon(JAML.path + "\\assets\\icon.png").getImage()); + frame.setLocationRelativeTo(null); frame.setVisible(true); }); homeGuiThread.start(); } + public static void startup() { + startupFrame = new StartupGui(); + } + public void startNewProfileGui() { Thread newProfileGuiThread = new Thread(() -> { NewProfileGui frame = new NewProfileGui(); diff --git a/src/main/java/tech/nevets/jaml/gui/HomeGui.java b/src/main/java/tech/nevets/jaml/gui/HomeGui.java index 51837e6..8d8cbcf 100644 --- a/src/main/java/tech/nevets/jaml/gui/HomeGui.java +++ b/src/main/java/tech/nevets/jaml/gui/HomeGui.java @@ -1,6 +1,9 @@ package tech.nevets.jaml.gui; import tech.nevets.jaml.JAML; +import tech.nevets.jaml.gui.panels.HomePanel; +import tech.nevets.jaml.gui.panels.ProfilePanel; +import tech.nevets.jaml.gui.panels.UsersPanel; import tech.nevets.jaml.listeners.RightClickListener; import tech.nevets.jaml.util.ImageUtils; import tech.nevets.jaml.util.ProfileUtils; @@ -11,13 +14,14 @@ import javax.swing.border.EmptyBorder; public class HomeGui extends JFrame { private JTabbedPane tabPanel; - private JPanel homePanel; - private JPanel userPanel; - private JPanel profilePanel; + private HomePanel homePanel; + private ProfilePanel profilePanel; + private UsersPanel userPanel; + public HomeGui() { setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); - setBounds(100, 100, 1280, 720); + setSize((int) (GuiHandler.SCREEN_WIDTH / 1.5), (int) (GuiHandler.SCREEN_HEIGHT / 1.5)); SpringLayout springLayout = new SpringLayout(); getContentPane().setLayout(springLayout); addMouseListener(new RightClickListener()); @@ -28,45 +32,18 @@ public class HomeGui extends JFrame { springLayout.putConstraint(SpringLayout.SOUTH, tabPanel, 720, SpringLayout.NORTH, getContentPane()); springLayout.putConstraint(SpringLayout.EAST, tabPanel, 1280, SpringLayout.WEST, getContentPane()); tabPanel.setBorder(new EmptyBorder(5, 5, 5, 5)); - //setContentPane(tabPanel); - homePanel = new JPanel(); + homePanel = new HomePanel(); tabPanel.add("Home", homePanel); - getContentPane().add(tabPanel); - JButton newProfileButton = new JButton("Create New Profile"); - newProfileButton.setBounds(920, 601, 134, 36); - newProfileButton.addActionListener(al -> { - JAML.guiHandler.startNewProfileGui(); - }); - homePanel.add(newProfileButton); - - JButton launchButton = new JButton("Launch"); - launchButton.setBounds(512, 619, 196, 51); - homePanel.add(launchButton); - - JComboBox activeProfileDropdown = new JComboBox(ProfileUtils.profileList); - activeProfileDropdown.setBounds(858, 648, 196, 22); - homePanel.add(activeProfileDropdown); - - JButton reloadProfileButton = new JButton("Reload Profiles"); - reloadProfileButton.setBounds(800, 608, 106, 23); - reloadProfileButton.addActionListener(al -> { - ProfileUtils.getProfileList(); - activeProfileDropdown.removeAllItems(); - for (int i = 0; i < ProfileUtils.profileList.length; i++) { - activeProfileDropdown.addItem(ProfileUtils.profileList[i]); - } - }); - homePanel.add(reloadProfileButton); - - JLabel backgroundIcon = new JLabel(""); - backgroundIcon.setBounds(0, 25, 1264, 542); - ImageIcon backgroundImg = new ImageIcon(JAML.path + "\\assets\\background.png"); - backgroundImg = ImageUtils.resizeIcon(backgroundImg, backgroundIcon.getWidth(), backgroundIcon.getHeight()); - backgroundIcon.setIcon(backgroundImg); - homePanel.add(backgroundIcon); + profilePanel = new ProfilePanel(); + tabPanel.add("Profiles", profilePanel); + + userPanel = new UsersPanel(); + tabPanel.add("Users", userPanel); + + getContentPane().add(tabPanel); tabPanel.addMouseListener(new RightClickListener()); diff --git a/src/main/java/tech/nevets/jaml/gui/StartupGui.java b/src/main/java/tech/nevets/jaml/gui/StartupGui.java new file mode 100644 index 0000000..c23e873 --- /dev/null +++ b/src/main/java/tech/nevets/jaml/gui/StartupGui.java @@ -0,0 +1,145 @@ +package tech.nevets.jaml.gui; + +import tech.nevets.jaml.Config; +import tech.nevets.jaml.JAML; +import tech.nevets.jaml.gui.panels.CustomProgressBarPanel; +import tech.nevets.jaml.util.ImageUtils; +import tech.nevets.jaml.util.LoaderUtils; +import tech.nevets.jaml.util.ProfileUtils; + +import javax.swing.*; +import javax.swing.border.EmptyBorder; +import java.nio.file.Path; + +public class StartupGui extends JFrame { + JPanel contentPane; + + public StartupGui() { + setUndecorated(true); + setResizable(false); + setDefaultCloseOperation(JFrame.DISPOSE_ON_CLOSE); + setSize(GuiHandler.SCREEN_WIDTH / 3, GuiHandler.SCREEN_HEIGHT / 3); + contentPane = new JPanel(); + contentPane.setBorder(new EmptyBorder(5, 5, 5, 5)); + setContentPane(contentPane); + contentPane.setLayout(null); + setLocationRelativeTo(null); + + int pbWidth = (int) (getWidth() / 1.1); + int pbHeight = getHeight() / 24; + int pbX = (getWidth() - pbWidth) / 2; + int pbY = getHeight() - (pbHeight * 2); + + JLabel progressBarOutline = new JLabel(); + progressBarOutline.setBounds(pbX, pbY - 10, pbWidth, pbHeight + 20); + ImageIcon pgOutline = new ImageIcon(getClass().getClassLoader().getResource("assets/progressbaroutline.png")); + pgOutline = ImageUtils.resizeIcon(pgOutline, pbWidth + 20, pbHeight); + progressBarOutline.setIcon(pgOutline); + contentPane.add(progressBarOutline); + + CustomProgressBarPanel progressBar = new CustomProgressBarPanel(pbWidth, pbHeight); + progressBar.setBounds(pbX, pbY, pbWidth, pbHeight); + contentPane.add(progressBar); + + JLabel splashIcon = new JLabel(""); + splashIcon.setSize(getWidth(), getHeight()); + ImageIcon backgroundImg = new ImageIcon(getClass().getClassLoader().getResource("assets/background.png")); + backgroundImg = ImageUtils.resizeIcon(backgroundImg, splashIcon.getWidth(), splashIcon.getHeight()); + splashIcon.setIcon(backgroundImg); + contentPane.add(splashIcon); + + setVisible(true); + + + progressBar.setProgress(0); + makeDirs(); + smoothIncrease(progressBar, 20); + Config.loadConfig(); + sleep(); + smoothIncrease(progressBar, 40); + ProfileUtils.getProfileList(); + sleep(); + smoothIncrease(progressBar, 60); + ProfileUtils.getActiveProfile(); + sleep(); + smoothIncrease(progressBar, 80); + LoaderUtils.getLoaders(); + sleep(); + smoothIncrease(progressBar, 100); + + + } + + private static void sleep() { + try { + Thread.sleep(500); + } catch (InterruptedException ignored) { + + } + } + + private static void makeDirs() { + if (System.getenv("JAML_HOME") == null) { + JAML.path = Path.of(System.getenv("APPDATA") + "\\.jaml\\"); + } else { + JAML.path = Path.of(System.getenv("JAML_HOME")); + } + + try { + if (!JAML.path.toFile().exists()) { + JAML.path.toFile().mkdirs(); + } + } catch (Exception e) { + System.out.println("Invalid path, please check your config.yml and try again"); + } + + try { + Path profilePath = Path.of(JAML.path + "\\profiles\\"); + if (!profilePath.toFile().exists()) { + profilePath.toFile().mkdirs(); + } + } catch (Exception e) { + e.printStackTrace(); + } + + try { + Path profilePath = Path.of(JAML.path + "\\assets\\"); + if (!profilePath.toFile().exists()) { + profilePath.toFile().mkdirs(); + } + } catch (Exception e) { + e.printStackTrace(); + } + + try { + Path dataPath = Path.of(JAML.path + "\\data\\"); + if (!dataPath.toFile().exists()) { + dataPath.toFile().mkdirs(); + } + } catch (Exception e) { + e.printStackTrace(); + } + + try { + Path skinsPath = Path.of(JAML.path + "\\data\\skins\\"); + if (!skinsPath.toFile().exists()) { + skinsPath.toFile().mkdirs(); + } + } catch (Exception e) { + e.printStackTrace(); + } + } + + private static void smoothIncrease(CustomProgressBarPanel pb, int to) { + int i = pb.getProgress(); + while (i <= to) { + pb.setProgress(i); + try { + Thread.sleep(10); + } catch (InterruptedException e) { + e.printStackTrace(); + } + i += 1; + } + } +} diff --git a/src/main/java/tech/nevets/jaml/gui/icons/Icons.java b/src/main/java/tech/nevets/jaml/gui/icons/Icons.java new file mode 100644 index 0000000..fa83f48 --- /dev/null +++ b/src/main/java/tech/nevets/jaml/gui/icons/Icons.java @@ -0,0 +1,9 @@ +package tech.nevets.jaml.gui.icons; + +import tech.nevets.jaml.JAML; + +import javax.swing.*; + +public class Icons { + public static final ImageIcon BUTTON = new ImageIcon(JAML.path + "\\assets\\icons\\button.png"); +} diff --git a/src/main/java/tech/nevets/jaml/gui/panels/CustomProgressBarPanel.java b/src/main/java/tech/nevets/jaml/gui/panels/CustomProgressBarPanel.java new file mode 100644 index 0000000..87ddee6 --- /dev/null +++ b/src/main/java/tech/nevets/jaml/gui/panels/CustomProgressBarPanel.java @@ -0,0 +1,33 @@ +package tech.nevets.jaml.gui.panels; + +import tech.nevets.jaml.util.ImageUtils; + +import javax.swing.*; + +public class CustomProgressBarPanel extends JPanel { + private int progress = 0; + private int width; + private int height; + + public CustomProgressBarPanel(int width, int height) { + this.width = width; + this.height = height; + + JLabel progressBar = new JLabel(); + progressBar.setSize(getWidth(), getHeight()); + ImageIcon image = new ImageIcon(getClass().getClassLoader().getResource("assets/progressbar.png")); + image = ImageUtils.resizeIcon(image, width, height); + progressBar.setIcon(image); + add(progressBar); + } + + public int getProgress() { + return progress; + } + + public void setProgress(int progress) { + this.progress = progress; + setSize(((progress * width) / 100), height); + repaint(); + } +} diff --git a/src/main/java/tech/nevets/jaml/gui/panels/HomePanel.java b/src/main/java/tech/nevets/jaml/gui/panels/HomePanel.java new file mode 100644 index 0000000..2a804b9 --- /dev/null +++ b/src/main/java/tech/nevets/jaml/gui/panels/HomePanel.java @@ -0,0 +1,46 @@ +package tech.nevets.jaml.gui.panels; + + +import tech.nevets.jaml.JAML; +import tech.nevets.jaml.util.ImageUtils; +import tech.nevets.jaml.util.ProfileUtils; + +import javax.swing.*; + +public class HomePanel extends JPanel { + public HomePanel() { + JButton newProfileButton = new JButton("Create New Profile"); + newProfileButton.setBounds(920, 601, 134, 36); + newProfileButton.addActionListener(al -> { + JAML.guiHandler.startNewProfileGui(); + }); + add(newProfileButton); + + JButton launchButton = new JButton("Launch"); + launchButton.setBounds(512, 619, 196, 51); + //launchButton.setIcon(); //TODO Create nice looking buttons and apply them to project + add(launchButton); + + JComboBox activeProfileDropdown = new JComboBox(ProfileUtils.profileList); + activeProfileDropdown.setBounds(858, 648, 196, 22); + add(activeProfileDropdown); + + JButton reloadProfileButton = new JButton("Reload Profiles"); + reloadProfileButton.setBounds(800, 608, 106, 23); + reloadProfileButton.addActionListener(al -> { + ProfileUtils.getProfileList(); + activeProfileDropdown.removeAllItems(); + for (int i = 0; i < ProfileUtils.profileList.length; i++) { + activeProfileDropdown.addItem(ProfileUtils.profileList[i]); + } + }); + add(reloadProfileButton); + + JLabel backgroundIcon = new JLabel(""); + backgroundIcon.setBounds(0, 25, 1264, 542); + ImageIcon backgroundImg = new ImageIcon(JAML.path + "\\assets\\background.png"); + backgroundImg = ImageUtils.resizeIcon(backgroundImg, backgroundIcon.getWidth(), backgroundIcon.getHeight()); + backgroundIcon.setIcon(backgroundImg); + add(backgroundIcon); + } +} diff --git a/src/main/java/tech/nevets/jaml/gui/panels/ProfilePanel.java b/src/main/java/tech/nevets/jaml/gui/panels/ProfilePanel.java new file mode 100644 index 0000000..e0234a1 --- /dev/null +++ b/src/main/java/tech/nevets/jaml/gui/panels/ProfilePanel.java @@ -0,0 +1,9 @@ +package tech.nevets.jaml.gui.panels; + +import javax.swing.*; + +public class ProfilePanel extends JPanel { + public ProfilePanel() { + + } +} diff --git a/src/main/java/tech/nevets/jaml/gui/panels/UsersPanel.java b/src/main/java/tech/nevets/jaml/gui/panels/UsersPanel.java new file mode 100644 index 0000000..77c51fc --- /dev/null +++ b/src/main/java/tech/nevets/jaml/gui/panels/UsersPanel.java @@ -0,0 +1,10 @@ +package tech.nevets.jaml.gui.panels; + + +import javax.swing.*; + +public class UsersPanel extends JPanel { + public UsersPanel() { + + } +} diff --git a/src/main/java/tech/nevets/jaml/init/FirstLaunch.java b/src/main/java/tech/nevets/jaml/init/FirstLaunch.java index a3b8f05..96a38f3 100644 --- a/src/main/java/tech/nevets/jaml/init/FirstLaunch.java +++ b/src/main/java/tech/nevets/jaml/init/FirstLaunch.java @@ -1,35 +1,17 @@ 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; -import java.io.IOException; -import java.net.URISyntaxException; -import java.net.URL; -import java.nio.file.Path; -import java.nio.file.Paths; public class FirstLaunch { public FirstLaunch() { - try { - copyAssets(); - } catch (IOException | URISyntaxException e) { - e.printStackTrace(); - } + + //TODO Make this force login + System.out.println("First Launch!"); Config.setValue("launcher.first-launch", false); Config.saveConfig(); } - public static void copyAssets() throws IOException, URISyntaxException { - URL resource = JAML.class.getResource("/assets/"); - File assets = Paths.get(resource.toURI()).toFile(); - if (!Path.of(JAML.path + "\\assets\\").toFile().exists()) { - FileUtils.copyDirectory(assets, new File(JAML.path + "\\assets\\")); - } - } } diff --git a/src/main/java/tech/nevets/jaml/util/HttpUtils.java b/src/main/java/tech/nevets/jaml/util/HttpUtils.java new file mode 100644 index 0000000..7dc1284 --- /dev/null +++ b/src/main/java/tech/nevets/jaml/util/HttpUtils.java @@ -0,0 +1,79 @@ +package tech.nevets.jaml.util; + +import java.io.IOException; +import java.net.URI; +import java.net.URLEncoder; +import java.net.http.HttpClient; +import java.net.http.HttpRequest; +import java.net.http.HttpResponse; +import java.nio.charset.StandardCharsets; +import java.util.Map; + +public class HttpUtils { + public static String get(URI uri, Map headers) { + try { + HttpClient client = HttpClient.newHttpClient(); + HttpRequest.Builder requestBuilder = HttpRequest.newBuilder() + .GET() + .uri(uri); + for (Map.Entry pair : headers.entrySet()) { + requestBuilder.setHeader(pair.getKey(), pair.getValue()); + } + HttpRequest request = requestBuilder.build(); + HttpResponse response = client.send(request, HttpResponse.BodyHandlers.ofString()); + return response.body(); + } catch (IOException | InterruptedException e) { + e.printStackTrace(); + return null; + } + } + + public static String post(URI uri, Map headers, String data) { + try { + HttpClient client = HttpClient.newHttpClient(); + HttpRequest.Builder requestBuilder = HttpRequest.newBuilder() + .POST(HttpRequest.BodyPublishers.ofString(data)) + .uri(uri); + for (Map.Entry pair : headers.entrySet()) { + requestBuilder.setHeader(pair.getKey(), pair.getValue()); + } + HttpRequest request = requestBuilder.build(); + HttpResponse response = client.send(request, HttpResponse.BodyHandlers.ofString()); + return response.body(); + } catch (IOException | InterruptedException e) { + e.printStackTrace(); + return null; + } + } + + public static String post(URI uri, Map headers, Map data) { + try { + HttpClient client = HttpClient.newHttpClient(); + HttpRequest.Builder requestBuilder = HttpRequest.newBuilder() + .POST(buildBodyPubFromMap(data)) + .uri(uri); + for (Map.Entry pair : headers.entrySet()) { + requestBuilder.setHeader(pair.getKey(), pair.getValue()); + } + HttpRequest request = requestBuilder.build(); + HttpResponse response = client.send(request, HttpResponse.BodyHandlers.ofString()); + return response.body(); + } catch (IOException | InterruptedException e) { + e.printStackTrace(); + return null; + } + } + + private static HttpRequest.BodyPublisher buildBodyPubFromMap(Map data) { + StringBuilder builder = new StringBuilder(); + for (Map.Entry pair : data.entrySet()) { + if (builder.length() > 0) { + builder.append("&"); + } + builder.append(URLEncoder.encode(pair.getKey().toString(), StandardCharsets.UTF_8)); + builder.append("="); + builder.append(URLEncoder.encode(pair.getValue().toString(), StandardCharsets.UTF_8)); + } + return HttpRequest.BodyPublishers.ofString(builder.toString()); + } +} diff --git a/src/main/java/tech/nevets/jaml/util/ImageUtils.java b/src/main/java/tech/nevets/jaml/util/ImageUtils.java index bd10449..7ade640 100644 --- a/src/main/java/tech/nevets/jaml/util/ImageUtils.java +++ b/src/main/java/tech/nevets/jaml/util/ImageUtils.java @@ -6,9 +6,7 @@ import java.awt.*; public class ImageUtils { public static ImageIcon resizeIcon(ImageIcon icon, int width, int height) { Image image = icon.getImage(); - Image newImg = image.getScaledInstance(width, height, java.awt.Image.SCALE_SMOOTH); + Image newImg = image.getScaledInstance(width, height, java.awt.Image.SCALE_SMOOTH); return new ImageIcon(newImg); } - - } diff --git a/src/main/java/tech/nevets/jaml/util/LoaderUtils.java b/src/main/java/tech/nevets/jaml/util/LoaderUtils.java index e6cb107..8733310 100644 --- a/src/main/java/tech/nevets/jaml/util/LoaderUtils.java +++ b/src/main/java/tech/nevets/jaml/util/LoaderUtils.java @@ -9,6 +9,7 @@ import tech.nevets.jaml.objects.Loader; import java.io.File; import java.io.IOException; +import java.net.URL; import java.nio.charset.StandardCharsets; public class LoaderUtils { @@ -17,7 +18,7 @@ public class LoaderUtils { public static String[] getLoaders() { try { Gson gson = new Gson(); - File loadersFile = new File(JAML.path + "\\data\\loaders.json"); + File loadersFile = getLoadersList(); JsonObject loadersJson = gson.fromJson(FileUtils.readFileToString(loadersFile, StandardCharsets.UTF_8), JsonObject.class); JsonArray loadersJsonArray = loadersJson.getAsJsonArray("loaders"); Loader[] loadersArray = gson.fromJson(loadersJsonArray, Loader[].class); @@ -35,4 +36,16 @@ public class LoaderUtils { return new String[]{"Vanilla", "Fabric", "Forge"}; // Fallback variable } } + + private static File getLoadersList() { + File loadersFile; + try { + loadersFile = new File(JAML.path + "\\data\\loaders.json"); + FileUtils.copyURLToFile(new URL("https://api.nevets.tech/jaml/loaders.json"), loadersFile); + } catch (IOException e) { + e.printStackTrace(); + loadersFile = new File(""); + } + return loadersFile; + } } diff --git a/src/main/resources/assets/background.png b/src/main/resources/assets/background.png index 623120b..17e2f55 100644 Binary files a/src/main/resources/assets/background.png and b/src/main/resources/assets/background.png differ diff --git a/src/main/resources/assets/icon.ico b/src/main/resources/assets/icon.ico index 2fc8243..877721f 100644 Binary files a/src/main/resources/assets/icon.ico and b/src/main/resources/assets/icon.ico differ diff --git a/src/main/resources/assets/icon.png b/src/main/resources/assets/icon.png index 2fc8243..2423da8 100644 Binary files a/src/main/resources/assets/icon.png and b/src/main/resources/assets/icon.png differ diff --git a/src/main/resources/assets/progressbar.png b/src/main/resources/assets/progressbar.png new file mode 100644 index 0000000..391d526 Binary files /dev/null and b/src/main/resources/assets/progressbar.png differ diff --git a/src/main/resources/assets/progressbaroutline.png b/src/main/resources/assets/progressbaroutline.png new file mode 100644 index 0000000..a42f095 Binary files /dev/null and b/src/main/resources/assets/progressbaroutline.png differ