Kristian Knarvik a3de8a9f6c
All checks were successful
KnarCraft/Minecraft-Server-Launcher/pipeline/head This commit looks good
Changes a lot of things to make everything cleaner. Closes #3
Drops the idea of using serializable
Adds a new controller object which takes care of profiles and saving
Moves profile independent settings to its own file
Makes saving and loading from file a lot cleaner
Fixes the bug preventing lastly used profile from loading
Makes the profile object only do profile things
Moves gui initialization to the controller object
Updates vanilla version from 1.16.1 to 1.16.2
Moves backup to common functions
2020-08-17 21:41:38 +02:00

87 lines
2.5 KiB
Java

package net.knarcraft.minecraftserverlauncher.profile;
import net.knarcraft.minecraftserverlauncher.server.Server;
import net.knarcraft.minecraftserverlauncher.userinterface.Console;
import net.knarcraft.minecraftserverlauncher.userinterface.ServerConsoles;
import net.knarcraft.minecraftserverlauncher.userinterface.ServerTab;
import javax.naming.ConfigurationException;
/**
* Acts as a wrapper for objects necessary for each server.
*
* @author Kristian Knarvik <kristian.knarvik@knett.no>
* @version 1.0.0
* @since 1.0.0
*/
public class Collection {
private final Server server;
private final ServerTab serverTab;
private final Console serverConsole;
private final String name;
/**
* Creates a new collection with the given name
*
* @param name <p>The name identifying the server, server tab, collection and server console</p>
*/
Collection(String name) throws ConfigurationException {
this.serverTab = new ServerTab(name);
this.server = new Server(name);
this.serverConsole = ServerConsoles.addConsoleTab(name);
this.name = name;
}
/**
* Creates a new collection with the given server
*
* @param server <p>The server used for as part of the collection</p>
* @throws ConfigurationException <p>If unable to configure the collection</p>
*/
Collection(Server server) throws ConfigurationException {
String serverName = server.getName();
this.serverTab = new ServerTab(serverName);
this.server = server;
this.serverConsole = ServerConsoles.addConsoleTab(serverName);
this.name = serverName;
this.serverTab.setData(server.getPath(), server.isEnabled(), server.getTypeName(), server.getServerVersion(),
server.getMaxRam());
}
/**
* Gets the name of the collection
*
* @return <p>Collection name</p>
*/
public String getName() {
return this.name;
}
/**
* Gets the server of the collection
*
* @return <p>Collection server</p>
*/
public Server getServer() {
return this.server;
}
/**
* Gets the server tab of the collection
*
* @return <p>Collection server tab</p>
*/
public ServerTab getServerTab() {
return this.serverTab;
}
/**
* Gets the server console of the collection
*
* @return <p>Collection server console</p>
*/
public Console getServerConsole() {
return this.serverConsole;
}
}