Lots and Lots of work done

This commit is contained in:
Steven Tracey 2022-03-16 10:26:20 -04:00
parent d2a524a6fe
commit f994a5a419
29 changed files with 646 additions and 390 deletions

5
.gitignore vendored
View File

@ -142,3 +142,8 @@ fabric.properties
config.yml
src/test
.classpath
.project
bin/
.settings/

View File

@ -3,7 +3,7 @@
<option name="myName" value="Project Default" />
<inspection_tool class="DuplicatedCode" enabled="true" level="WEAK WARNING" enabled_by_default="true">
<Languages>
<language minSize="88" name="Java" />
<language minSize="108" name="Java" />
</Languages>
</inspection_tool>
</profile>

View File

@ -4,7 +4,8 @@ plugins {
}
group 'tech.nevets.jaml'
version '0.5.0'
version '0.6.0'
def build = 'stable'
repositories {
mavenCentral()

View File

@ -1,77 +0,0 @@
package tech.nevets.jaml;
import org.simpleyaml.configuration.file.YamlFile;
import java.io.IOException;
public class Config {
private static final YamlFile YML_FILE = new YamlFile(JAML.path + "\\config.yml");
public static void loadConfig() {
try {
if (!YML_FILE.exists()) {
System.out.println("Config file not found, creating new one...");
YML_FILE.createNewFile(true);
System.out.println("Config file created!");
} else {
System.out.println("Loading Config file...");
YML_FILE.loadWithComments();
System.out.println("Config file loaded!");
}
} catch (final Exception e) {
System.out.println("Error while loading config file!");
e.printStackTrace();
}
YML_FILE.setComment("java",
"\n"
+ " JJJJJJJJJJJ AAA MMMMMMMM MMMMMMMM LLLLLLLLLLL \n"
+ " J:::::::::J A:::A M:::::::M M:::::::M L:::::::::L \n"
+ " J:::::::::J A:::::A M::::::::M M::::::::M L:::::::::L \n"
+ " JJ:::::::JJ A:::::::A M:::::::::M M:::::::::M LL:::::::LL \n"
+ " J:::::J A:::::::::A M::::::::::M M::::::::::M L:::::L \n"
+ " J:::::J A:::::A:::::A M:::::::::::M M:::::::::::M L:::::L \n"
+ " J:::::J A:::::A A:::::A M:::::::M::::M M::::M:::::::M L:::::L \n"
+ " J:::::j A:::::A A:::::A M::::::M M::::M M::::M M::::::M L:::::L \n"
+ " J:::::J A:::::A A:::::A M::::::M M::::M::::M M::::::M L:::::L \n"
+ " JJJJJJJ J:::::J A:::::AAAAAAAAA:::::A M::::::M M:::::::M M::::::M L:::::L \n"
+ " J:::::J J:::::J A:::::::::::::::::::::A M::::::M M:::::M M::::::M L:::::L \n"
+ " J::::::J J::::::J A:::::AAAAAAAAAAAAA:::::A M::::::M MMMMM M::::::M L:::::L LLLLLL\n"
+ " J:::::::JJJ:::::::J A:::::A A:::::A M::::::M M::::::M LL:::::::LLLLLLLLL:::::L\n"
+ " JJ:::::::::::::JJ A:::::A A:::::A M::::::M M::::::M L::::::::::::::::::::::L\n"
+ " JJ:::::::::JJ A:::::A A:::::A M::::::M M::::::M L::::::::::::::::::::::L\n"
+ " JJJJJJJJJ AAAAAAA AAAAAAA MMMMMMMM MMMMMMMM LLLLLLLLLLLLLLLLLLLLLLLL\n"
);
YML_FILE.addDefault("java.jdk8", "");
YML_FILE.setComment("java.jdk8", "Set these to the bin directory of each JDK version");
YML_FILE.addDefault("java.jdk16", "");
YML_FILE.addDefault("java.jdk17", "");
YML_FILE.addDefault("launcher.default-profile", "default");
YML_FILE.setComment("launcher.default-profile", "Set's the profile that will be loaded automatically");
YML_FILE.addDefault("launcher.path","default");
YML_FILE.setComment("launcher.path","Path to JAML files\n" + "default: " + JAML.path.toString());
YML_FILE.addDefault("launcher.first-launch", true);
YML_FILE.setComment("launcher.first-launch", "Do Not Change, will regenerate files");
YML_FILE.addDefault("launcher.verbose", false);
YML_FILE.setComment("launcher.verbose", "If true, will print out all the messages");
YML_FILE.addDefault("launcher.version", "0.1.0");
YML_FILE.setComment("launcher.version", "Jaml version, don't change it!");
try {
YML_FILE.save();
} catch (IOException e) {
e.printStackTrace();
}
}
public static YamlFile getConfig() {
return YML_FILE;
}
public static void reloadConfig() {
CONFIG = getConfig();
}
public static YamlFile CONFIG = getConfig();
}

View File

@ -1,16 +0,0 @@
package tech.nevets.jaml;
import java.io.IOException;
public class FirstLaunch {
public FirstLaunch() {
System.out.println("First Launch!");
Config.CONFIG.set("launcher.first-launch", false);
try {
Config.CONFIG.save();
} catch (IOException e) {
e.printStackTrace();
}
}
}

View File

@ -1,28 +1,26 @@
package tech.nevets.jaml;
import org.apache.commons.io.FileUtils;
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 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 JAML {
public static YamlFile config = Config.CONFIG;
//public static YamlFile config = Config.getConfig();
public static Path path;
public static GuiHandler guiHandler;
public static Profile activeProfile;
public static void main(String[] args) {
DiscordRP.start();
makeDirs();
Config.loadConfig();
ProfileUtils.getProfileList();
ProfileUtils.getActiveProfile();
LoaderUtils.getLoaders();
DiscordRP.update("", "");
guiHandler = new GuiHandler();
@ -31,13 +29,6 @@ public class JAML {
// } catch (IOException e) {
// e.printStackTrace();
// }
try {
activeProfile = ProfileUtils.loadProfile(config.getString("launcher.default-profile"));
} catch (IOException e) {
System.out.println("Unable to load default profile: " + e.getMessage());
}
}
private static void makeDirs() {
@ -81,20 +72,5 @@ public class JAML {
} catch (Exception e) {
e.printStackTrace();
}
try {
copyAssets();
} catch (Exception e) {
e.printStackTrace();
}
}
public static void copyAssets() throws IOException, URISyntaxException {
URL resource = JAML.class.getResource("/assets/");
File assets = Paths.get(resource.toURI()).toFile();
if (!Path.of(path + "\\data\\").toFile().exists()) {
FileUtils.copyDirectory(assets, new File(path + "\\assets\\"));
}
}
}

View File

@ -1,94 +0,0 @@
package tech.nevets.jaml;
import java.nio.file.Path;
public class Profile {
private String profileName;
private String email;
private String hashedPassword;
private String key;
private String salt;
private String gamePath;
private String version;
private String loader;
private Boolean offlineMode;
public Profile(){
}
public String getProfileName() {
return profileName;
}
public void setProfileName(String profileName) {
this.profileName = profileName.toLowerCase();
}
public String getEmail() {
return email;
}
public void setEmail(String email) {
this.email = email;
}
public String getHashedPassword() {
return hashedPassword;
}
public void setHashedPassword(String hashedPassword) {
this.hashedPassword = hashedPassword;
}
public String getKey() {
return key;
}
public void setKey(String key) {
this.key = key;
}
public String getSalt() {
return salt;
}
public void setSalt(String salt) {
this.salt = salt;
}
public Path getGamePath() {
return Path.of(gamePath);
}
public void setGamePath(Path gamePath) {
this.gamePath = String.valueOf(gamePath);
}
public String getVersion() {
return version;
}
public void setVersion(String version) {
this.version = version;
}
public String getLoader() {
return loader;
}
public void setLoader (String loader) {
this.loader = loader;
}
public Boolean getOfflineMode() {
return offlineMode;
}
public void setOfflineMode(Boolean offlineMode) {
this.offlineMode = offlineMode;
}
public String toString() {
return "{ profileName: " + profileName + ", email: " + email + ", hashedPassword: " + hashedPassword + ", key: " + key + ", salt: " + salt + ", gamePath: " + gamePath + ", version: " + version + ", loader: " + loader + ", offlineMode: " + offlineMode + " }";
}
}

View File

@ -1,8 +1,8 @@
package tech.nevets.jaml.gui;
import tech.nevets.jaml.FirstLaunch;
import tech.nevets.jaml.util.FirstLaunch;
import tech.nevets.jaml.JAML;
import tech.nevets.jaml.Profile;
import tech.nevets.jaml.objects.Profile;
import tech.nevets.jaml.util.ProfileUtils;
import tech.nevets.jaml.util.Encryptor;
@ -10,16 +10,14 @@ import javax.swing.*;
import java.awt.*;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.io.File;
import java.io.IOException;
import java.nio.file.Path;
public class FirstLaunchGui implements Runnable, ActionListener {
//TODO Formatting
private JFrame frame;
private JPanel panel;
private JTextField emailField;
private JPasswordField passwordField;
private JTextField gamePathField;
private JTextField versionField;
private JTextField loaderField;
@ -28,14 +26,6 @@ public class FirstLaunchGui implements Runnable, ActionListener {
public void startGui() {
frame = new JFrame("Create First Profile");
JLabel emailLabel = new JLabel("Email:");
emailLabel.setBounds(10, 50, 80, 25);
emailField = new JTextField(20);
JLabel passwordLabel = new JLabel("Password:");
passwordLabel.setBounds(100, 50, 165, 25);
passwordField = new JPasswordField(20);
JLabel gamePathLabel = new JLabel("Game Path:");
gamePathLabel.setBounds(10, 80, 80, 25);
gamePathField = new JTextField(20);
@ -69,10 +59,6 @@ public class FirstLaunchGui implements Runnable, ActionListener {
panel = new JPanel();
panel.setBorder(BorderFactory.createEmptyBorder(300, 300, 100, 300));
panel.setLayout(new GridLayout(0, 1));
panel.add(emailLabel);
panel.add(emailField);
panel.add(passwordLabel);
panel.add(passwordField);
panel.add(gamePathLabel);
panel.add(gamePathField);
panel.add(gamePathButton);
@ -97,15 +83,8 @@ public class FirstLaunchGui implements Runnable, ActionListener {
public void actionPerformed(ActionEvent ae) {
Profile profile = new Profile();
profile.setProfileName("default");
profile.setEmail(emailField.getText());
if (passwordField.getPassword().length > 0){
profile.setHashedPassword(Encryptor.encrypt(String.valueOf(passwordField.getPassword())).getData());
profile.setKey(Encryptor.encrypt(String.valueOf(passwordField.getPassword())).getKey());
profile.setSalt(Encryptor.encrypt(String.valueOf(passwordField.getPassword())).getSalt());
}
profile.setGamePath(Path.of(gamePathField.getText()));
profile.setGamePath(new File(gamePathField.getText()));
profile.setVersion(versionField.getText());
profile.setLoader(loaderField.getText());
profile.setOfflineMode(Boolean.parseBoolean(offlineModeField.getText()));

View File

@ -1,24 +1,36 @@
package tech.nevets.jaml.gui;
import tech.nevets.jaml.Config;
import tech.nevets.jaml.util.Config;
import tech.nevets.jaml.JAML;
import javax.swing.*;
public class GuiHandler {
public GuiHandler() {
if (Config.CONFIG.getBoolean("launcher.first-launch")) {
if (Config.getConfig().getBoolean("launcher.first-launch")) {
FirstLaunchGui firstLaunchGui = new FirstLaunchGui();
Thread firstLaunchThread = new Thread(firstLaunchGui);
firstLaunchThread.start();
}
HomeGui homeGui = new HomeGui();
Thread homeGuiThread = new Thread(homeGui);
Thread homeGuiThread = new Thread(() -> {
HomeGui frame = new HomeGui();
frame.setTitle("JAML");
frame.setIconImage(new ImageIcon(JAML.path + "\\assets\\icon.png").getImage());
frame.setVisible(true);
});
homeGuiThread.start();
}
public void startNewProfileGui() {
NewProfileGui newProfileGui = new NewProfileGui();
Thread newProfileGuiThread = new Thread(newProfileGui);
Thread newProfileGuiThread = new Thread(() -> {
NewProfileGui frame = new NewProfileGui();
frame.setTitle("Create New Profile");
frame.setIconImage(new ImageIcon(JAML.path + "\\assets\\icon.png").getImage());
frame.setVisible(true);
});
newProfileGuiThread.start();
}

View File

@ -1,44 +1,75 @@
package tech.nevets.jaml.gui;
import tech.nevets.jaml.JAML;
import tech.nevets.jaml.listeners.RightClickListener;
import tech.nevets.jaml.util.ImageUtils;
import tech.nevets.jaml.util.ProfileUtils;
import javax.swing.*;
import java.awt.*;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import javax.swing.border.EmptyBorder;
public class HomeGui implements Runnable, ActionListener {
public class HomeGui extends JFrame {
private JFrame frame;
private JPanel panel;
//private JPanel contentPane;
private JTabbedPane tabPanel;
private JPanel homePanel;
public void startGui() {
frame = new JFrame();
//private JPanel contentPane;
JButton button = new JButton("Create New Profile");
button.addActionListener(this);
public HomeGui() {
setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
setBounds(100, 100, 1280, 720);
SpringLayout springLayout = new SpringLayout();
getContentPane().setLayout(springLayout);
addMouseListener(new RightClickListener());
panel = new JPanel();
panel.setBorder(BorderFactory.createEmptyBorder(300, 300, 100, 300));
panel.setLayout(new GridLayout(0, 1));
tabPanel = new JTabbedPane();
springLayout.putConstraint(SpringLayout.NORTH, tabPanel, 0, SpringLayout.NORTH, getContentPane());
springLayout.putConstraint(SpringLayout.WEST, tabPanel, 0, SpringLayout.WEST, getContentPane());
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);
panel.add(button);
frame.add(panel, BorderLayout.CENTER);
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
frame.setTitle("JAML");
frame.setIconImage(new ImageIcon(JAML.path + "\\assets\\icon.png").getImage());
frame.pack();
frame.setVisible(true);
}
homePanel = new JPanel();
tabPanel.add("Home", homePanel);
getContentPane().add(tabPanel);
@Override
public void actionPerformed(ActionEvent e) {
JAML.guiHandler.startNewProfileGui();
}
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);
tabPanel.addMouseListener(new RightClickListener());
@Override
public void run() {
startGui();
}
}

View File

@ -1,51 +1,43 @@
package tech.nevets.jaml.gui;
import tech.nevets.jaml.JAML;
import tech.nevets.jaml.Profile;
import tech.nevets.jaml.objects.Profile;
import tech.nevets.jaml.util.LoaderUtils;
import tech.nevets.jaml.util.ProfileUtils;
import tech.nevets.jaml.util.Encryptor;
import javax.swing.*;
import java.awt.*;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import javax.swing.border.EmptyBorder;
import java.io.File;
import java.io.IOException;
import java.nio.file.Path;
import java.util.ArrayList;
public class NewProfileGui implements Runnable, ActionListener {
//TODO Formatting
private JFrame frame;
private JPanel panel;
public class NewProfileGui extends JFrame {
private JTextField profileNameField;
private JTextField emailField;
private JPasswordField passwordField;
private JTextField gamePathField;
private JTextField versionField;
private JTextField loaderField;
private JTextField offlineModeField;
private JPanel contentPane;
public void startGui() {
frame = new JFrame("New Profile");
public NewProfileGui() {
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, 20, 80, 25);
profileNameField = new JTextField(20);
JLabel emailLabel = new JLabel("Email:");
emailLabel.setBounds(10, 50, 80, 25);
emailField = new JTextField(20);
JLabel passwordLabel = new JLabel("Password:");
passwordLabel.setBounds(100, 50, 165, 25);
passwordField = new JPasswordField(20);
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, 80, 80, 25);
gamePathField = new JTextField(20);
gamePathLabel.setBounds(10, 56, 84, 31);
contentPane.add(gamePathLabel);
JButton gamePathButton = new JButton("Choose Path");
gamePathButton.setBounds(200, 80, 25, 25);
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);
@ -54,78 +46,53 @@ public class NewProfileGui implements Runnable, ActionListener {
gamePathField.setText(fileChooser.getSelectedFile().toString());
fileChooser.setVisible(false);
});
contentPane.add(gamePathField);
contentPane.add(gamePathButton);
JLabel versionLabel = new JLabel("Version:");
versionLabel.setBounds(100, 80, 165, 25);
versionField = new JTextField(20);
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, 110, 80, 25);
loaderField = new JTextField(20);
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(100, 110, 165, 25);
offlineModeField = new JTextField(20);
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.addActionListener(this);
button.setBounds(64, 234, 217, 37);
button.addActionListener(al -> {
Profile profile = new Profile();
profile.setProfileName(profileNameField.getText());
panel = new JPanel();
panel.setBorder(BorderFactory.createEmptyBorder(300, 300, 100, 300));
panel.setLayout(new GridLayout(0, 1));
panel.add(profileNameLabel);
panel.add(profileNameField);
panel.add(emailLabel);
panel.add(emailField);
panel.add(passwordLabel);
panel.add(passwordField);
panel.add(gamePathLabel);
panel.add(gamePathField);
panel.add(gamePathButton);
panel.add(versionLabel);
panel.add(versionField);
panel.add(loaderLabel);
panel.add(loaderField);
panel.add(offlineModeLabel);
panel.add(offlineModeField);
panel.add(button);
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();
frame.add(panel, BorderLayout.CENTER);
frame.setSize(500, 500);
frame.setDefaultCloseOperation(JFrame.DISPOSE_ON_CLOSE);
frame.setTitle("JAML");
frame.setIconImage(new ImageIcon(JAML.path + "\\assets\\icon.png").getImage());
frame.pack();
frame.setVisible(true);
}
this.dispose();
});
@Override
public void actionPerformed(ActionEvent ae) {
Profile profile = new Profile();
profile.setProfileName(profileNameField.getText());
profile.setEmail(emailField.getText());
if (passwordField.getPassword().length > 0){
profile.setHashedPassword(Encryptor.encrypt(String.valueOf(passwordField.getPassword())).getData());
profile.setKey(Encryptor.encrypt(String.valueOf(passwordField.getPassword())).getKey());
profile.setSalt(Encryptor.encrypt(String.valueOf(passwordField.getPassword())).getSalt());
}
profile.setGamePath(Path.of(gamePathField.getText()));
profile.setVersion(versionField.getText());
profile.setLoader(loaderField.getText());
profile.setOfflineMode(Boolean.parseBoolean(offlineModeField.getText()));
try {
ProfileUtils.createProfile(profile);
} catch (IOException e) {
e.printStackTrace();
}
frame.dispose();
}
@Override
public void run() {
startGui();
contentPane.add(button);
}
}

View File

@ -0,0 +1,15 @@
package tech.nevets.jaml.gui;
import javax.swing.*;
public class RightClickGui extends JPopupMenu {
JMenuItem test;
public RightClickGui() {
test = new JMenuItem("This works");
test.addActionListener(al -> {
System.out.println("This worked!");
});
add(test);
}
}

View File

@ -0,0 +1,15 @@
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);
}
}

View File

@ -0,0 +1,26 @@
package tech.nevets.jaml.listeners;
import tech.nevets.jaml.gui.RightClickGui;
import java.awt.*;
import java.awt.event.MouseAdapter;
import java.awt.event.MouseEvent;
public class RightClickListener extends MouseAdapter {
public void mousePressed(MouseEvent e) {
if (e.isPopupTrigger()) {
doPop(e);
}
}
public void mouseReleased(MouseEvent e) {
if (e.isPopupTrigger()) {
doPop(e);
}
}
private void doPop(MouseEvent e) {
RightClickGui menu = new RightClickGui();
menu.show(e.getComponent(), e.getX(), e.getY());
}
}

View File

@ -0,0 +1,13 @@
package tech.nevets.jaml.objects;
public class Loader {
private String id;
public void setId(String id) {
this.id = id;
}
public String getId() {
return id;
}
}

View File

@ -0,0 +1,58 @@
package tech.nevets.jaml.objects;
import java.io.File;
public class Profile {
private String profileName;
private String gamePath;
private String version;
private String loader;
private Boolean offlineMode;
public Profile(){
}
public String getProfileName() {
return profileName;
}
public void setProfileName(String profileName) {
this.profileName = profileName.toLowerCase();
}
public File getGamePath() {
return new File(gamePath);
}
public void setGamePath(File gamePath) {
this.gamePath = String.valueOf(gamePath);
}
public String getVersion() {
return version;
}
public void setVersion(String version) {
this.version = version;
}
public String getLoader() {
return loader;
}
public void setLoader (String loader) {
this.loader = loader;
}
public Boolean getOfflineMode() {
return offlineMode;
}
public void setOfflineMode(Boolean offlineMode) {
this.offlineMode = offlineMode;
}
public String toString() {
return "{ profileName: " + profileName + ", gamePath: " + gamePath + ", version: " + version + ", loader: " + loader + ", offlineMode: " + offlineMode + " }";
}
}

View File

@ -0,0 +1,35 @@
package tech.nevets.jaml.objects;
import java.util.UUID;
public class User {
private String username;
private UUID uuid;
private String accessToken;
private String key;
private String salt;
public String getAccessToken() {
return accessToken;
}
public void setAccessToken(String accessToken) {
this.accessToken = accessToken;
}
public String getKey() {
return key;
}
public void setKey(String key) {
this.key = key;
}
public String getSalt() {
return salt;
}
public void setSalt(String salt) {
this.salt = salt;
}
}

View File

@ -1,4 +1,4 @@
package tech.nevets.jaml;
package tech.nevets.jaml.objects;
import java.net.URL;

View File

@ -0,0 +1,180 @@
package tech.nevets.jaml.util;
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");
try {
if (!YML_FILE.exists()) {
System.out.println("Config file not found, creating new one...");
YML_FILE.createNewFile(true);
System.out.println("Config file created!");
} else {
System.out.println("Loading Config file...");
YML_FILE.loadWithComments();
System.out.println("Config file loaded!");
}
} catch (final Exception e) {
System.out.println("Error while loading config file!");
e.printStackTrace();
}
YML_FILE.setComment("java",
"\n"
+ " JJJJJJJJJJJ AAA MMMMMMMM MMMMMMMM LLLLLLLLLLL \n"
+ " J:::::::::J A:::A M:::::::M M:::::::M L:::::::::L \n"
+ " J:::::::::J A:::::A M::::::::M M::::::::M L:::::::::L \n"
+ " JJ:::::::JJ A:::::::A M:::::::::M M:::::::::M LL:::::::LL \n"
+ " J:::::J A:::::::::A M::::::::::M M::::::::::M L:::::L \n"
+ " J:::::J A:::::A:::::A M:::::::::::M M:::::::::::M L:::::L \n"
+ " J:::::J A:::::A A:::::A M:::::::M::::M M::::M:::::::M L:::::L \n"
+ " J:::::j A:::::A A:::::A M::::::M M::::M M::::M M::::::M L:::::L \n"
+ " J:::::J A:::::A A:::::A M::::::M M::::M::::M M::::::M L:::::L \n"
+ " JJJJJJJ J:::::J A:::::AAAAAAAAA:::::A M::::::M M:::::::M M::::::M L:::::L \n"
+ " J:::::J J:::::J A:::::::::::::::::::::A M::::::M M:::::M M::::::M L:::::L \n"
+ " J::::::J J::::::J A:::::AAAAAAAAAAAAA:::::A M::::::M MMMMM M::::::M L:::::L LLLLLL\n"
+ " J:::::::JJJ:::::::J A:::::A A:::::A M::::::M M::::::M LL:::::::LLLLLLLLL:::::L\n"
+ " JJ:::::::::::::JJ A:::::A A:::::A M::::::M M::::::M L::::::::::::::::::::::L\n"
+ " JJ:::::::::JJ A:::::A A:::::A M::::::M M::::::M L::::::::::::::::::::::L\n"
+ " JJJJJJJJJ AAAAAAA AAAAAAA MMMMMMMM MMMMMMMM LLLLLLLLLLLLLLLLLLLLLLLL\n"
);
YML_FILE.addDefault("java.jdk8", "");
YML_FILE.setComment("java.jdk8", "Set these to the bin directory of each JDK version");
YML_FILE.addDefault("java.jdk16", "");
YML_FILE.addDefault("java.jdk17", "");
YML_FILE.addDefault("launcher.default-profile", "default");
YML_FILE.setComment("launcher.default-profile", "Set's the profile that will be loaded automatically");
YML_FILE.addDefault("launcher.path","default");
YML_FILE.setComment("launcher.path","Path to JAML files\n" + "default: " + JAML.path.toString());
YML_FILE.addDefault("launcher.first-launch", true);
YML_FILE.setComment("launcher.first-launch", "Do Not Change, will regenerate files");
YML_FILE.addDefault("launcher.verbose", false);
YML_FILE.setComment("launcher.verbose", "If true, will print out all the messages");
YML_FILE.addDefault("launcher.version", "0.1.0");
YML_FILE.setComment("launcher.version", "Jaml version, don't change it!");
try {
YML_FILE.save();
} catch (IOException e) {
e.printStackTrace();
}
}
public static YamlFile getConfig() {
return YML_FILE;
}
public static void reloadConfig() {
CONFIG = getConfig();
}
public static YamlFile CONFIG = getConfig();
public static void saveConfig() {
try {
YML_FILE.save();
} catch (IOException e) {
e.printStackTrace();
}
}
public static void setValue(String path, Object data) {
YML_FILE.set(path, data);
}
}
//package tech.nevets.jaml.util;
//
//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");
//
// public static void loadConfig() {
// try {
// if (!YML_FILE.exists()) {
// System.out.println("Config file not found, creating new one...");
// YML_FILE.createNewFile(true);
// System.out.println("Config file created!");
// } else {
// System.out.println("Loading Config file...");
// YML_FILE.loadWithComments();
// System.out.println("Config file loaded!");
// }
// } catch (final Exception e) {
// System.out.println("Error while loading config file!");
// e.printStackTrace();
// }
//
// YML_FILE.setComment("java",
// "\n"
// + " JJJJJJJJJJJ AAA MMMMMMMM MMMMMMMM LLLLLLLLLLL \n"
// + " J:::::::::J A:::A M:::::::M M:::::::M L:::::::::L \n"
// + " J:::::::::J A:::::A M::::::::M M::::::::M L:::::::::L \n"
// + " JJ:::::::JJ A:::::::A M:::::::::M M:::::::::M LL:::::::LL \n"
// + " J:::::J A:::::::::A M::::::::::M M::::::::::M L:::::L \n"
// + " J:::::J A:::::A:::::A M:::::::::::M M:::::::::::M L:::::L \n"
// + " J:::::J A:::::A A:::::A M:::::::M::::M M::::M:::::::M L:::::L \n"
// + " J:::::j A:::::A A:::::A M::::::M M::::M M::::M M::::::M L:::::L \n"
// + " J:::::J A:::::A A:::::A M::::::M M::::M::::M M::::::M L:::::L \n"
// + " JJJJJJJ J:::::J A:::::AAAAAAAAA:::::A M::::::M M:::::::M M::::::M L:::::L \n"
// + " J:::::J J:::::J A:::::::::::::::::::::A M::::::M M:::::M M::::::M L:::::L \n"
// + " J::::::J J::::::J A:::::AAAAAAAAAAAAA:::::A M::::::M MMMMM M::::::M L:::::L LLLLLL\n"
// + " J:::::::JJJ:::::::J A:::::A A:::::A M::::::M M::::::M LL:::::::LLLLLLLLL:::::L\n"
// + " JJ:::::::::::::JJ A:::::A A:::::A M::::::M M::::::M L::::::::::::::::::::::L\n"
// + " JJ:::::::::JJ A:::::A A:::::A M::::::M M::::::M L::::::::::::::::::::::L\n"
// + " JJJJJJJJJ AAAAAAA AAAAAAA MMMMMMMM MMMMMMMM LLLLLLLLLLLLLLLLLLLLLLLL\n"
// );
//
// YML_FILE.addDefault("java.jdk8", "");
// YML_FILE.setComment("java.jdk8", "Set these to the bin directory of each JDK version");
// YML_FILE.addDefault("java.jdk16", "");
// YML_FILE.addDefault("java.jdk17", "");
// YML_FILE.addDefault("game.skin", "");
// YML_FILE.setComment("game.skin", "Current skin being used, DO NOT change this");
// YML_FILE.addDefault("launcher.default-profile", "default");
// YML_FILE.setComment("launcher.default-profile", "Set's the profile that will be loaded automatically");
// YML_FILE.addDefault("launcher.path","default");
// YML_FILE.setComment("launcher.path","Path to JAML files\n" + "default: " + JAML.path.toString());
// YML_FILE.addDefault("launcher.first-launch", true);
// YML_FILE.setComment("launcher.first-launch", "Do Not Change, will regenerate files");
// YML_FILE.addDefault("launcher.verbose", false);
// YML_FILE.setComment("launcher.verbose", "If true, will print out all the messages");
// YML_FILE.addDefault("launcher.version", "0.1.0");
// YML_FILE.setComment("launcher.version", "Jaml version, don't change it!");
//
// try {
// YML_FILE.save();
// } catch (IOException e) {
// e.printStackTrace();
// }
// }
//
// public static YamlFile getConfig() {
// return YML_FILE;
// }
//
// public static void saveConfig() {
// try {
// YML_FILE.save();
// } catch (IOException e) {
// e.printStackTrace();
// }
// }
//
// public static void setValue(String path, Object data) {
// YML_FILE.set(path, data);
// }
//}

View File

@ -1,4 +1,4 @@
package tech.nevets.jaml;
package tech.nevets.jaml.util;
import net.arikia.dev.drpc.DiscordEventHandlers;
import net.arikia.dev.drpc.DiscordRPC;

View File

@ -0,0 +1,34 @@
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.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();
}
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\\"));
}
}
}

View File

@ -0,0 +1,14 @@
package tech.nevets.jaml.util;
import javax.swing.*;
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);
return new ImageIcon(newImg);
}
}

View File

@ -1,4 +1,4 @@
package tech.nevets.jaml;
package tech.nevets.jaml.util;
import java.io.BufferedReader;
import java.io.IOException;
@ -7,7 +7,8 @@ import java.util.ArrayList;
public class Launch {
public Launch(ArrayList<String> commandArray, boolean printConsole) throws IOException {
public Launch(int jdkVersion, int memoryAmount, String garbageCollection, boolean printConsole) throws IOException {
ArrayList<String> commandArray = parseCommand(jdkVersion, memoryAmount, garbageCollection);
StringBuilder sb = new StringBuilder();
for (String commandString : commandArray) {
@ -19,23 +20,26 @@ public class Launch {
System.out.println(command);
Process process = Runtime.getRuntime().exec(command);
ProcessBuilder process = new ProcessBuilder();
process.directory(ProfileUtils.activeProfile.getGamePath());
process.command(command);
Process processVar = process.start();
if (printConsole) {
printResults(process);
printResults(processVar);
}
process.destroy();
processVar.destroy();
}
public static ArrayList<String> parseCommand(int jdkVersion, int memoryAmount, String garbageCollection) {
ArrayList<String> cmd = new ArrayList<String>();
if (jdkVersion == 8) {
cmd.add(("\"" + Config.CONFIG.getString("java.jdk8") + "\\javaw.exe\""));
cmd.add(("\"" + Config.getConfig().getString("java.jdk8") + "\\javaw.exe\""));
} else if (jdkVersion == 16) {
cmd.add(("\"" + Config.CONFIG.getString("java.jdk16") + "\\javaw.exe\""));
cmd.add(("\"" + Config.getConfig().getString("java.jdk16") + "\\javaw.exe\""));
} else if (jdkVersion == 17) {
cmd.add(("\"" + Config.CONFIG.getString("java.jdk17") + "\\java.exe\""));
cmd.add(("\"" + Config.getConfig().getString("java.jdk17") + "\\java.exe\""));
}
cmd.add(("-Xmx" + memoryAmount + "M"));

View File

@ -0,0 +1,38 @@
package tech.nevets.jaml.util;
import com.google.gson.Gson;
import com.google.gson.JsonArray;
import com.google.gson.JsonObject;
import org.apache.commons.io.FileUtils;
import tech.nevets.jaml.JAML;
import tech.nevets.jaml.objects.Loader;
import java.io.File;
import java.io.IOException;
import java.nio.charset.StandardCharsets;
public class LoaderUtils {
public static String[] loaders;
public static String[] getLoaders() {
try {
Gson gson = new Gson();
File loadersFile = new File(JAML.path + "\\data\\loaders.json");
JsonObject loadersJson = gson.fromJson(FileUtils.readFileToString(loadersFile, StandardCharsets.UTF_8), JsonObject.class);
JsonArray loadersJsonArray = loadersJson.getAsJsonArray("loaders");
Loader[] loadersArray = gson.fromJson(loadersJsonArray, Loader[].class);
String[] loadersArrayList = new String[loadersArray.length];
for (int i = 0; i < loadersArrayList.length; i++) {
loadersArrayList[i] = loadersArray[i].getId();
}
loaders = loadersArrayList;
return loadersArrayList;
} catch (IOException e) {
e.printStackTrace();
return new String[]{"Vanilla", "Fabric", "Forge"}; // Fallback variable
}
}
}

View File

@ -1,14 +1,17 @@
package tech.nevets.jaml.util;
import com.google.gson.*;
import org.apache.commons.io.FilenameUtils;
import tech.nevets.jaml.JAML;
import tech.nevets.jaml.Profile;
import tech.nevets.jaml.objects.Profile;
import java.io.*;
import java.nio.file.Path;
public class ProfileUtils {
private static final Path PROFILE_PATH = Path.of(JAML.path + "\\profiles\\");
public static Profile activeProfile;
public static String[] profileList;
public static void createProfile(Profile profile) throws IOException {
String profileName = profile.getProfileName();
@ -29,4 +32,24 @@ public class ProfileUtils {
return new Gson().fromJson(reader, Profile.class);
}
public static String[] getProfileList() {
File profileDir = new File(JAML.path + "\\profiles\\");
String[] profileFiles = profileDir.list();
String[] profileNames = new String[profileFiles.length];
for (int i = 0; i < profileFiles.length; i++) {
profileNames[i] = FilenameUtils.removeExtension(profileFiles[i]);
}
profileList = profileNames;
return profileNames;
}
public static Profile getActiveProfile() {
try {
activeProfile = ProfileUtils.loadProfile(Config.getConfig().getString("launcher.default-profile"));
} catch (IOException e) {
System.out.println("Unable to load default profile: " + e.getMessage());
}
return activeProfile;
}
}

View File

@ -0,0 +1,18 @@
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;
}
}

View File

@ -5,11 +5,12 @@ import com.google.gson.JsonArray;
import com.google.gson.JsonObject;
import org.apache.commons.io.FileUtils;
import tech.nevets.jaml.JAML;
import tech.nevets.jaml.Version;
import tech.nevets.jaml.objects.Version;
import java.io.File;
import java.io.IOException;
import java.net.URL;
import java.nio.charset.StandardCharsets;
public class VersionFetcher {
@ -20,8 +21,6 @@ public class VersionFetcher {
Version[] versionArray = gson.fromJson(versionsJsonArray, Version[].class);
for (Version value : versionArray) {
System.out.println(value.getId());
if (value.getId().equalsIgnoreCase(version)) {
return value;
}
@ -66,7 +65,7 @@ public class VersionFetcher {
File versionManifestFile = new File(JAML.path + "\\data\\version.json");
return new Gson().fromJson(FileUtils.readFileToString(versionManifestFile), JsonObject.class);
return new Gson().fromJson(FileUtils.readFileToString(versionManifestFile, StandardCharsets.UTF_8), JsonObject.class);
} catch (IOException e) {
e.printStackTrace();
return null;

Binary file not shown.

After

Width:  |  Height:  |  Size: 538 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 210 KiB