More gui buttons work in theory

This commit is contained in:
2018-01-30 00:44:03 +01:00
parent 0267961eff
commit 1c00ae9bab
5 changed files with 158 additions and 45 deletions

View File

@ -3,6 +3,8 @@ package net.knarcraft.serverlauncher.profile;
import net.knarcraft.serverlauncher.server.Server;
import net.knarcraft.serverlauncher.userinterface.GUI;
import javax.swing.*;
import java.io.IOException;
import java.util.ArrayList;
/**
@ -13,13 +15,17 @@ import java.util.ArrayList;
* @since 0.0.0.1
*/
public class Profile {
private static final GUI gui = Server.getGUI();
private static final ArrayList<Profile> profiles = new ArrayList<>();
private final ArrayList<Server> servers;
private final String name;
private boolean runInBackground;
private int delayStartup;
private boolean downloadJars;
private String vanillaVersion;
private String snapshotVersion;
private String spongeVanillaVersion;
private String bungeeVersion;
private Profile(String name) {
this.servers = new ArrayList<>();
@ -35,7 +41,25 @@ public class Profile {
}
public void removeServer(int i) {
servers.remove(i);
this.servers.remove(i);
}
private Server getServer(String name) {
for (Server server : this.servers) {
if (server.getName().equals(name)) {
return server;
}
}
return null;
}
public boolean serverExists(String name) {
for (Server server : this.servers) {
if (server.getName().equals(name)) {
return true;
}
}
return false;
}
public ArrayList<Server> getServers() {
@ -43,16 +67,21 @@ public class Profile {
}
public static void addProfile(String name) {
if (name == null) { //If a user cancels or crosses out window
return;
}
if (name.equals("")) {
JOptionPane.showMessageDialog(null, "Profile name can't be blank.", "Error", JOptionPane.ERROR_MESSAGE);
return;
}
for (Profile profile : profiles) {
if (profile.name.equals(name)) {
JOptionPane.showMessageDialog(null, "There is already a profile with this name.", "Error", JOptionPane.ERROR_MESSAGE);
return;
}
}
new Profile(name);
gui.addProfile(name);
GUI.getGUI().addProfile(name);
}
public static Profile getProfile(String name) {
@ -69,7 +98,7 @@ public class Profile {
for (int i = 0; i < profiles.size(); i++) {
if (profiles.get(i).name.equals((name))) {
profiles.remove(i);
gui.removeProfile(i);
GUI.getGUI().removeProfile(i);
}
}
}
@ -88,4 +117,27 @@ public class Profile {
public void setDownloadJars(boolean value) {
this.downloadJars = value;
}
public void sendCommand(String serverName, String command) {
if (serverName.equals("All")) {
for (Server server : this.servers) {
try {
server.sendCommand(command);
} catch (IOException e) {
JOptionPane.showMessageDialog(null, "Server " + server.getName() + " caused an exception.", "Error", JOptionPane.ERROR_MESSAGE);
}
}
} else {
Server target = getServer(serverName);
if (target != null) {
try {
target.sendCommand(command);
} catch (IOException e) {
JOptionPane.showMessageDialog(null, "Server " + target.getName() + " caused an exception.", "Error", JOptionPane.ERROR_MESSAGE);
}
} else {
JOptionPane.showMessageDialog(null, "Server " + serverName + " is invalid.", "Error", JOptionPane.ERROR_MESSAGE);
}
}
}
}