Added the title and icon again
This commit is contained in:
parent
559e7bb38a
commit
89f0962c2d
@ -1,7 +1,9 @@
|
||||
package net.knarcraft.serverlauncher.profile;
|
||||
|
||||
import net.knarcraft.serverlauncher.server.Server;
|
||||
import net.knarcraft.serverlauncher.server.ServerType;
|
||||
import net.knarcraft.serverlauncher.userinterface.GUI;
|
||||
import net.knarcraft.serverlauncher.userinterface.ServerTab;
|
||||
|
||||
import javax.swing.*;
|
||||
import java.io.IOException;
|
||||
@ -173,4 +175,16 @@ public class Profile {
|
||||
return "";
|
||||
}
|
||||
}
|
||||
|
||||
public void save(ArrayList<ServerTab> serverTabs) {
|
||||
for (int i = 0; i < this.servers.size(); i++) {
|
||||
Server server = servers.get(i);
|
||||
ServerTab serverTab = serverTabs.get(i);
|
||||
server.setPath(serverTab.getPath());
|
||||
server.setMaxRam(serverTab.getMaxRam());
|
||||
server.setType(ServerType.getByName(serverTab.getType()));
|
||||
server.setServerVersion(serverTab.getVersion());
|
||||
server.toggle(serverTab.enabled());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -85,6 +85,9 @@ public class Server {
|
||||
public void toggle() {
|
||||
this.enabled = !this.enabled;
|
||||
}
|
||||
public void toggle(boolean value) {
|
||||
this.enabled = value;
|
||||
}
|
||||
|
||||
public void setPath(String path) {
|
||||
this.path = path;
|
||||
@ -140,7 +143,7 @@ public class Server {
|
||||
* Runs all enabled servers with their settings.
|
||||
*/
|
||||
public static void startServers() {
|
||||
System.out.println("Starting servers.");
|
||||
GUI.getGUI().setStatus("Starting servers");
|
||||
for (Server server : GUI.getGUI().currentProfile().getServers()) {
|
||||
if (!server.run()) {
|
||||
GUI.getGUI().setStatus("An error occurred. Start aborted");
|
||||
@ -169,7 +172,8 @@ public class Server {
|
||||
"-Djline.terminal=jline.UnsupportedTerminal",
|
||||
"-Dcom.mojang.eula.agree=true",
|
||||
"-jar",
|
||||
"\"" + this.path + "\\" + this.getType() + "\""
|
||||
"\"" + this.path + "\\" + this.getType() + "\"",
|
||||
"nogui"
|
||||
);
|
||||
builder.directory(new File(this.path));
|
||||
builder.redirectErrorStream(true);
|
||||
|
@ -51,6 +51,15 @@ public class ServerType {
|
||||
return serverTypes;
|
||||
}
|
||||
|
||||
public static ServerType getByName(String name) {
|
||||
for (ServerType serverType : serverTypes) {
|
||||
if (serverType.getName().equals(name)) {
|
||||
return serverType;
|
||||
}
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
/**
|
||||
* Reads valid server types and version from a file, and creates their objects.
|
||||
*
|
||||
|
@ -3,6 +3,7 @@ package net.knarcraft.serverlauncher.userinterface;
|
||||
import net.knarcraft.serverlauncher.server.Server;
|
||||
import net.knarcraft.serverlauncher.profile.Profile;
|
||||
|
||||
import javax.imageio.ImageIO;
|
||||
import javax.swing.*;
|
||||
import java.awt.event.ActionEvent;
|
||||
import java.awt.event.ActionListener;
|
||||
@ -94,10 +95,6 @@ public class GUI implements ActionListener {
|
||||
return gui;
|
||||
}
|
||||
|
||||
public ArrayList<ServerTab> getServerTabs() {
|
||||
return this.serverTabs;
|
||||
}
|
||||
|
||||
/**
|
||||
* Removes a server's tab, removes it from the list of tabs, and removes the server from Profile.java
|
||||
*
|
||||
@ -125,10 +122,17 @@ public class GUI implements ActionListener {
|
||||
e.printStackTrace();
|
||||
}
|
||||
|
||||
frame = new JFrame();
|
||||
frame = new JFrame("Minecraft server launcher");
|
||||
frame.setBounds(100, 100, 398, 219);
|
||||
frame.setDefaultCloseOperation(WindowConstants.EXIT_ON_CLOSE);
|
||||
frame.setResizable(false);
|
||||
ImageIcon img;
|
||||
try {
|
||||
img = new ImageIcon(ImageIO.read(GUI.class.getResourceAsStream("/files/GUIIcon.png")));
|
||||
} catch (IOException | IllegalArgumentException e) {
|
||||
img = new ImageIcon("files/GUIIcon.png");
|
||||
}
|
||||
frame.setIconImage(img.getImage());
|
||||
|
||||
frame.addWindowListener(new WindowAdapter() {
|
||||
public void windowClosing(WindowEvent e) {
|
||||
@ -394,7 +398,6 @@ public class GUI implements ActionListener {
|
||||
if (selectedPlayer != null) {
|
||||
selectedPlayerValue = selectedPlayer.toString();
|
||||
}
|
||||
|
||||
if (e.getSource() == chckbxmntmRunInBackground) {
|
||||
background();
|
||||
} else if (e.getSource() == chckbxmntmDelayStartup) {
|
||||
@ -418,7 +421,7 @@ public class GUI implements ActionListener {
|
||||
} else if (e.getSource() == mntmStory) {
|
||||
goToURL("https://knarcraft.net/Bungeeminecraftserverlauncher/Story/");
|
||||
} else if (e.getSource() == btnStartServer) {
|
||||
save();
|
||||
this.save();
|
||||
Server.startServers();
|
||||
} else if (e.getSource() == btnStopServer) {
|
||||
stop();
|
||||
@ -475,8 +478,7 @@ public class GUI implements ActionListener {
|
||||
* Reads all combo boxes, updates variables and saves to disk
|
||||
*/
|
||||
private void save() {
|
||||
//TODO: Finish save
|
||||
|
||||
currentProfile().save(serverTabs);
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -7,7 +7,7 @@ import javax.swing.*;
|
||||
import java.awt.event.ActionEvent;
|
||||
import java.awt.event.ActionListener;
|
||||
|
||||
class ServerTab implements ActionListener {
|
||||
public class ServerTab implements ActionListener {
|
||||
private final JComboBox<String> serverTypes;
|
||||
private final JComboBox<String> serverVersions;
|
||||
private final JComboBox<String> maxRam;
|
||||
@ -16,8 +16,6 @@ class ServerTab implements ActionListener {
|
||||
private final JButton btnBrowse;
|
||||
private final JTextField directory;
|
||||
|
||||
//TODO: Add custom input field + update combo boxes on version change.
|
||||
|
||||
public ServerTab(String name) {
|
||||
JPanel panel = new JPanel();
|
||||
GUI.getGUI().getPane().addTab(name, null, panel, null);
|
||||
@ -101,6 +99,41 @@ class ServerTab implements ActionListener {
|
||||
btnBrowse.addActionListener(this);
|
||||
}
|
||||
|
||||
public String getPath() {
|
||||
return this.directory.getText();
|
||||
}
|
||||
|
||||
public String getMaxRam() {
|
||||
Object selected = this.maxRam.getSelectedItem();
|
||||
if (selected != null) {
|
||||
return selected.toString();
|
||||
} else {
|
||||
return "512M";
|
||||
}
|
||||
}
|
||||
|
||||
public String getType() {
|
||||
Object selected = this.serverTypes.getSelectedItem();
|
||||
if (selected != null) {
|
||||
return selected.toString();
|
||||
} else {
|
||||
return "Vanilla";
|
||||
}
|
||||
}
|
||||
|
||||
public String getVersion() {
|
||||
Object selected = this.serverVersions.getSelectedItem();
|
||||
if (selected != null) {
|
||||
return selected.toString();
|
||||
} else {
|
||||
return "Vanilla";
|
||||
}
|
||||
}
|
||||
|
||||
public boolean enabled() {
|
||||
return this.chckbxEnabled.isSelected();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void actionPerformed(ActionEvent e) {
|
||||
if (e.getSource() == btnRemoveServer) {
|
||||
|
Loading…
Reference in New Issue
Block a user