Attempted to add Discord RPC, Successfully saved and loaded profiles, Gui loads with icon
This commit is contained in:
parent
3dae87396f
commit
ac9901fa31
@ -21,5 +21,10 @@
|
|||||||
<option name="name" value="maven" />
|
<option name="name" value="maven" />
|
||||||
<option name="url" value="https://jitpack.io" />
|
<option name="url" value="https://jitpack.io" />
|
||||||
</remote-repository>
|
</remote-repository>
|
||||||
|
<remote-repository>
|
||||||
|
<option name="id" value="maven2" />
|
||||||
|
<option name="name" value="maven2" />
|
||||||
|
<option name="url" value="https://repo.nevets.tech/repository/maven-public" />
|
||||||
|
</remote-repository>
|
||||||
</component>
|
</component>
|
||||||
</project>
|
</project>
|
@ -4,13 +4,16 @@ plugins {
|
|||||||
}
|
}
|
||||||
|
|
||||||
group 'tech.nevets.jaml'
|
group 'tech.nevets.jaml'
|
||||||
version '0.1.0'
|
version '0.2.0'
|
||||||
|
|
||||||
repositories {
|
repositories {
|
||||||
mavenCentral()
|
mavenCentral()
|
||||||
maven {
|
maven {
|
||||||
url 'https://jitpack.io'
|
url 'https://jitpack.io'
|
||||||
}
|
}
|
||||||
|
maven {
|
||||||
|
url 'https://repo.nevets.tech/repository/maven-public'
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
sourceCompatibility = targetCompatibility = '17'
|
sourceCompatibility = targetCompatibility = '17'
|
||||||
@ -27,6 +30,7 @@ application {
|
|||||||
dependencies {
|
dependencies {
|
||||||
implementation 'me.carleslc.Simple-YAML:Simple-Yaml:1.7.3'
|
implementation 'me.carleslc.Simple-YAML:Simple-Yaml:1.7.3'
|
||||||
implementation 'com.google.code.gson:gson:2.9.0'
|
implementation 'com.google.code.gson:gson:2.9.0'
|
||||||
|
implementation 'net.arikia.dev:drpc:1.0'
|
||||||
}
|
}
|
||||||
|
|
||||||
jar {
|
jar {
|
||||||
|
@ -23,8 +23,11 @@ public class Config {
|
|||||||
e.printStackTrace();
|
e.printStackTrace();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
ymlFile.addDefault("java.jdk8", "");
|
||||||
|
ymlFile.addDefault("java.jdk16", "");
|
||||||
|
ymlFile.addDefault("java.jdk17", "");
|
||||||
ymlFile.addDefault("launcher.path","default");
|
ymlFile.addDefault("launcher.path","default");
|
||||||
ymlFile.setComment("launcher.path","Path to JAML files\n" + "default: %appdata%\\.jaml\\");
|
ymlFile.setComment("launcher.path","Path to JAML files\n" + "default: " + JAML.path.toString());
|
||||||
ymlFile.addDefault("launcher.verbose", false);
|
ymlFile.addDefault("launcher.verbose", false);
|
||||||
ymlFile.setComment("launcher.verbose", "If true, will print out all the messages");
|
ymlFile.setComment("launcher.verbose", "If true, will print out all the messages");
|
||||||
ymlFile.addDefault("launcher.version", "0.1.0");
|
ymlFile.addDefault("launcher.version", "0.1.0");
|
||||||
|
44
src/main/java/tech/nevets/jaml/DiscordRP.java
Normal file
44
src/main/java/tech/nevets/jaml/DiscordRP.java
Normal file
@ -0,0 +1,44 @@
|
|||||||
|
package tech.nevets.jaml;
|
||||||
|
|
||||||
|
import net.arikia.dev.drpc.DiscordEventHandlers;
|
||||||
|
import net.arikia.dev.drpc.DiscordRPC;
|
||||||
|
import net.arikia.dev.drpc.DiscordRichPresence;
|
||||||
|
|
||||||
|
public class DiscordRP {
|
||||||
|
//TODO Make this actually work
|
||||||
|
|
||||||
|
private boolean running = true;
|
||||||
|
private long created = 0;
|
||||||
|
|
||||||
|
public void start() {
|
||||||
|
this.created = System.currentTimeMillis();
|
||||||
|
|
||||||
|
DiscordEventHandlers handlers = new DiscordEventHandlers.Builder().setReadyEventHandler((user) -> {
|
||||||
|
System.out.println("Welcome " + user.username + "#" + user.discriminator + ".");
|
||||||
|
update("Starting...", "");
|
||||||
|
}).build();
|
||||||
|
|
||||||
|
DiscordRPC.discordInitialize("942986640043941938", handlers, true);
|
||||||
|
//DiscordRPC.discordRegister("942986640043941938", "");
|
||||||
|
|
||||||
|
new Thread(() -> {
|
||||||
|
while (running) {
|
||||||
|
DiscordRPC.discordRunCallbacks();
|
||||||
|
}
|
||||||
|
}).start();
|
||||||
|
}
|
||||||
|
|
||||||
|
public void shutdown() {
|
||||||
|
running = false;
|
||||||
|
DiscordRPC.discordShutdown();
|
||||||
|
}
|
||||||
|
|
||||||
|
public void update(String firstLine, String secondLine) {
|
||||||
|
DiscordRichPresence.Builder b = new DiscordRichPresence.Builder(secondLine);
|
||||||
|
b.setBigImage("large", "");
|
||||||
|
b.setDetails(firstLine);
|
||||||
|
b.setStartTimestamps(created);
|
||||||
|
|
||||||
|
DiscordRPC.discordUpdatePresence(b.build());
|
||||||
|
}
|
||||||
|
}
|
@ -1,21 +1,42 @@
|
|||||||
package tech.nevets.jaml;
|
package tech.nevets.jaml;
|
||||||
|
|
||||||
import org.simpleyaml.configuration.file.YamlFile;
|
import org.simpleyaml.configuration.file.YamlFile;
|
||||||
|
import tech.nevets.jaml.gui.GUI;
|
||||||
|
|
||||||
|
import java.io.IOException;
|
||||||
import java.nio.file.Path;
|
import java.nio.file.Path;
|
||||||
|
|
||||||
public class JAML {
|
public class JAML {
|
||||||
public static YamlFile config;
|
public static YamlFile config;
|
||||||
public static Path path;
|
public static Path path;
|
||||||
|
public static DiscordRP drp = new DiscordRP();
|
||||||
|
|
||||||
public static void main(String[] args) {
|
|
||||||
makeDir();
|
public static void main(String[] args) throws InterruptedException {
|
||||||
|
makeDirs();
|
||||||
Config.loadConfig();
|
Config.loadConfig();
|
||||||
config = Config.getConfig();
|
config = Config.getConfig();
|
||||||
|
|
||||||
|
try {
|
||||||
|
Profiles.loadProfile("test");
|
||||||
|
} catch (IOException e) {
|
||||||
|
e.printStackTrace();
|
||||||
}
|
}
|
||||||
|
|
||||||
private static void makeDir() {
|
// try {
|
||||||
|
// Profiles.createProfile("testing");
|
||||||
|
// } catch (IOException e) {
|
||||||
|
// e.printStackTrace();
|
||||||
|
// }
|
||||||
|
|
||||||
|
drp.start();
|
||||||
|
|
||||||
|
GUI.startGui();
|
||||||
|
|
||||||
|
drp.shutdown();
|
||||||
|
}
|
||||||
|
|
||||||
|
private static void makeDirs() {
|
||||||
if (config == null) {
|
if (config == null) {
|
||||||
path = Path.of(System.getenv("APPDATA") + "\\.jaml\\");
|
path = Path.of(System.getenv("APPDATA") + "\\.jaml\\");
|
||||||
} else {
|
} else {
|
||||||
@ -33,5 +54,33 @@ public class JAML {
|
|||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
System.out.println("Invalid path, please check your config.yml and try again");
|
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();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// public static void initDiscord() {
|
||||||
|
// DiscordEventHandlers handlers = new DiscordEventHandlers.Builder().setReadyEventHandler((user) -> {
|
||||||
|
// System.out.println("Welcome " + user.username + "#" + user.discriminator + ".");
|
||||||
|
// DiscordRichPresence.Builder presence = new DiscordRichPresence.Builder("");
|
||||||
|
// DiscordRPC.discordUpdatePresence(presence.build());
|
||||||
|
// }).build();
|
||||||
|
// DiscordRPC.discordInitialize("942986640043941938", handlers, false);
|
||||||
|
// DiscordRPC.discordRegister("942986640043941938", "");
|
||||||
|
// }
|
||||||
}
|
}
|
18
src/main/java/tech/nevets/jaml/Launch.java
Normal file
18
src/main/java/tech/nevets/jaml/Launch.java
Normal file
@ -0,0 +1,18 @@
|
|||||||
|
package tech.nevets.jaml;
|
||||||
|
|
||||||
|
import java.io.File;
|
||||||
|
import java.io.IOException;
|
||||||
|
|
||||||
|
public class Launch {
|
||||||
|
public static void launch() {
|
||||||
|
String[] command = {"echo", "Hello, World!"};
|
||||||
|
ProcessBuilder builder = new ProcessBuilder(command);
|
||||||
|
builder.directory(new File(JAML.path + "\\process"));
|
||||||
|
try {
|
||||||
|
Process process = builder.start();
|
||||||
|
} catch (IOException ex) {
|
||||||
|
ex.printStackTrace();
|
||||||
|
}
|
||||||
|
System.exit(0);
|
||||||
|
}
|
||||||
|
}
|
76
src/main/java/tech/nevets/jaml/Profile.java
Normal file
76
src/main/java/tech/nevets/jaml/Profile.java
Normal file
@ -0,0 +1,76 @@
|
|||||||
|
package tech.nevets.jaml;
|
||||||
|
|
||||||
|
import java.nio.file.Path;
|
||||||
|
|
||||||
|
public class Profile {
|
||||||
|
private String profileName;
|
||||||
|
private String email;
|
||||||
|
private String hashedPassword;
|
||||||
|
private Path 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;
|
||||||
|
}
|
||||||
|
|
||||||
|
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 Path getGamePath() {
|
||||||
|
return gamePath;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setGamePath(Path gamePath) {
|
||||||
|
this.gamePath = 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 "Profile [ profileName: " + profileName + ", email: " + email + ", hashedPassword: " + hashedPassword + ", gamePath: " + gamePath + ", version: " + version + ", loader: " + loader + ", offlineMode: " + offlineMode + " ]";
|
||||||
|
}
|
||||||
|
}
|
@ -1,22 +1,33 @@
|
|||||||
package tech.nevets.jaml;
|
package tech.nevets.jaml;
|
||||||
|
|
||||||
import com.google.gson.Gson;
|
import com.google.gson.*;
|
||||||
import com.google.gson.GsonBuilder;
|
|
||||||
|
|
||||||
|
import java.io.*;
|
||||||
import java.nio.file.Path;
|
import java.nio.file.Path;
|
||||||
|
|
||||||
public class Profiles {
|
public class Profiles {
|
||||||
|
private static final Path profilePath = Path.of(JAML.path + "\\profiles\\");
|
||||||
|
|
||||||
|
public static void createProfile(String profileName) throws IOException {
|
||||||
|
Writer writer = new FileWriter(profilePath + "\\" + profileName + ".json");
|
||||||
|
String jsonString = "{}";
|
||||||
|
|
||||||
public static void createProfile(String email, String hashedPassword, Path javaPath, Path gamePath, String version, Boolean onlineMode, String username) {
|
|
||||||
GsonBuilder builder = new GsonBuilder();
|
GsonBuilder builder = new GsonBuilder();
|
||||||
builder.setPrettyPrinting();
|
builder.setPrettyPrinting();
|
||||||
|
|
||||||
Gson gson = builder.create();
|
Gson gson = builder.create();
|
||||||
|
Profile profile = gson.fromJson(jsonString, Profile.class);
|
||||||
|
System.out.println(profile);
|
||||||
|
|
||||||
//TODO Create and save profiles
|
jsonString = gson.toJson(profile);
|
||||||
|
System.out.println(jsonString);
|
||||||
|
writer.write(jsonString);
|
||||||
}
|
}
|
||||||
|
|
||||||
public static void loadProfile() {
|
public static void loadProfile(String profileName) throws FileNotFoundException {
|
||||||
//TODO Load Saved Profiles
|
BufferedReader reader = new BufferedReader(new FileReader(profilePath + "\\" + profileName + ".json"));
|
||||||
|
Profile profile = new Gson().fromJson(reader, Profile.class);
|
||||||
|
|
||||||
|
System.out.println(profile.getProfileName());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
49
src/main/java/tech/nevets/jaml/gui/GUI.java
Normal file
49
src/main/java/tech/nevets/jaml/gui/GUI.java
Normal file
@ -0,0 +1,49 @@
|
|||||||
|
package tech.nevets.jaml.gui;
|
||||||
|
|
||||||
|
import tech.nevets.jaml.JAML;
|
||||||
|
import javax.swing.*;
|
||||||
|
import java.awt.*;
|
||||||
|
import java.awt.event.ActionEvent;
|
||||||
|
import java.awt.event.ActionListener;
|
||||||
|
|
||||||
|
public class GUI implements ActionListener {
|
||||||
|
//TODO Add important things on instead of POC
|
||||||
|
|
||||||
|
private int count = 0;
|
||||||
|
JFrame frame;
|
||||||
|
JPanel panel;
|
||||||
|
JButton button;
|
||||||
|
JLabel label;
|
||||||
|
|
||||||
|
public GUI() {
|
||||||
|
frame = new JFrame();
|
||||||
|
|
||||||
|
button = new JButton("Click me!");
|
||||||
|
button.addActionListener(this);
|
||||||
|
|
||||||
|
label = new JLabel("Number of Clicks: 0");
|
||||||
|
|
||||||
|
panel = new JPanel();
|
||||||
|
panel.setBorder(BorderFactory.createEmptyBorder(300, 300, 100, 300));
|
||||||
|
panel.setLayout(new GridLayout(0, 1));
|
||||||
|
panel.add(button);
|
||||||
|
panel.add(label);
|
||||||
|
|
||||||
|
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);
|
||||||
|
}
|
||||||
|
|
||||||
|
public static void startGui() {
|
||||||
|
new GUI();
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void actionPerformed(ActionEvent e) {
|
||||||
|
count++;
|
||||||
|
label.setText("Number of Clicks: " + count);
|
||||||
|
}
|
||||||
|
}
|
Loading…
Reference in New Issue
Block a user