Compare commits
22 Commits
1.3.2-beta
...
v1.4.0-bet
Author | SHA1 | Date | |
---|---|---|---|
a1ae162b07 | |||
b2ee22eb7b | |||
65ede11ab5 | |||
c26a3bc3b5 | |||
71e47acbb0 | |||
60fdcf5ddc | |||
bf77c13072 | |||
849655bfc6 | |||
e8ecee1cd0 | |||
5e24d5daa8 | |||
9532683301 | |||
365d08f2e2 | |||
9d8531535d | |||
30de4b2139 | |||
133e335905 | |||
44d8d6ee6b | |||
cd396eee6b | |||
c67f3bdd2c | |||
8476c78589 | |||
a79300732d | |||
b6baa9ad6f | |||
c2f12a1a49 |
13
README.md
13
README.md
@ -1,6 +1,13 @@
|
|||||||
# Minecraft-Server-Launcher
|
# Minecraft-Server-Launcher
|
||||||
I originally created this software in 2013 using AutoIt. Since I am now learning Java, I have recreated it in Java.
|
I originally created this software in 2013 using AutoIt. After learning Java, I recreated it in Java.
|
||||||
The original version can be found at: https://archive.knarcraft.net/Scripts/BungeeMinecraftServerLauncher/
|
The original version can be found at: https://archive.knarcraft.net/Scripts/BungeeMinecraftServerLauncher/
|
||||||
Its goal is to do everything the original does, just better. The original is 1595 lines of code repetition and dirty code. I had no prior programming experience when I first started working on the original, which is why it became such a mess.
|
This version's goal is to do everything the original does, just better. The original is 1595 lines of code repetition
|
||||||
|
and dirty code. I had no prior programming experience when I first started working on the original, which is why it
|
||||||
|
became such a mess.
|
||||||
|
|
||||||
The code is now in a fully working state. It is still missing an auto update feature, but it can be used, and is fully functional.
|
The software is in a fully working stage with a functional updater. The software is still in beta because there are still
|
||||||
|
a lot of things I want to change and small annoyances. The software is fully portable. Make sure to put it in its own
|
||||||
|
folder as it will create lots of files.
|
||||||
|
|
||||||
|
The updater will move the new version to minecraft-server-launcher.jar, so you should rename the downloaded
|
||||||
|
file to this if it's named something else to avoid confusion.
|
@ -2,7 +2,7 @@ package net.knarcraft.minecraftserverlauncher;
|
|||||||
|
|
||||||
import net.knarcraft.minecraftserverlauncher.profile.Collection;
|
import net.knarcraft.minecraftserverlauncher.profile.Collection;
|
||||||
import net.knarcraft.minecraftserverlauncher.profile.ServerLauncherController;
|
import net.knarcraft.minecraftserverlauncher.profile.ServerLauncherController;
|
||||||
import net.knarcraft.minecraftserverlauncher.server.Server;
|
import net.knarcraft.minecraftserverlauncher.server.ServerHandler;
|
||||||
import net.knarcraft.minecraftserverlauncher.userinterface.ServerConsoles;
|
import net.knarcraft.minecraftserverlauncher.userinterface.ServerConsoles;
|
||||||
import net.knarcraft.minecraftserverlauncher.userinterface.ServerLauncherGUI;
|
import net.knarcraft.minecraftserverlauncher.userinterface.ServerLauncherGUI;
|
||||||
import net.knarcraft.minecraftserverlauncher.utility.CommonFunctions;
|
import net.knarcraft.minecraftserverlauncher.utility.CommonFunctions;
|
||||||
@ -21,7 +21,7 @@ import java.util.concurrent.TimeUnit;
|
|||||||
* A software for managing Minecraft servers.
|
* A software for managing Minecraft servers.
|
||||||
*
|
*
|
||||||
* @author Kristian Knarvik <kristian.knarvik@knett.no>
|
* @author Kristian Knarvik <kristian.knarvik@knett.no>
|
||||||
* @version 1.0.0
|
* @version b1.3.4
|
||||||
* @since 1.0.0
|
* @since 1.0.0
|
||||||
*/
|
*/
|
||||||
|
|
||||||
@ -34,8 +34,14 @@ public class Main {
|
|||||||
private static ServerLauncherGUI gui;
|
private static ServerLauncherGUI gui;
|
||||||
|
|
||||||
public static void main(String[] args) throws IOException {
|
public static void main(String[] args) throws IOException {
|
||||||
|
String logFile = Main.getApplicationWorkDirectory() + File.separator + "latestrun.log";
|
||||||
|
CommonFunctions.writeFile(logFile, "[Info]: Starting Minecraft Server Launcher v." +
|
||||||
|
Updater.getCurrentVersion()[1]);
|
||||||
|
try {
|
||||||
Updater.checkForUpdate(updateURL, updateChannel);
|
Updater.checkForUpdate(updateURL, updateChannel);
|
||||||
CommonFunctions.writeFile(Main.getApplicationWorkDirectory() + File.separator + "latestrun.log", "");
|
} catch (IOException e) {
|
||||||
|
CommonFunctions.appendFile(logFile, "[Warning]: Unable to complete update procedure: " + e.getMessage());
|
||||||
|
}
|
||||||
EventQueue.invokeLater(() -> {
|
EventQueue.invokeLater(() -> {
|
||||||
try {
|
try {
|
||||||
ServerConsoles.instantiate();
|
ServerConsoles.instantiate();
|
||||||
@ -82,7 +88,7 @@ public class Main {
|
|||||||
boolean runningNew = serversRunning();
|
boolean runningNew = serversRunning();
|
||||||
if (serversAreRunning && !runningNew) {
|
if (serversAreRunning && !runningNew) {
|
||||||
//Servers stopped running
|
//Servers stopped running
|
||||||
Server.serversStopped();
|
ServerHandler.serversStopped();
|
||||||
gui.updateGUIElementsWhenServersStartOrStop(false);
|
gui.updateGUIElementsWhenServersStartOrStop(false);
|
||||||
gui.setStatus("Servers are stopped");
|
gui.setStatus("Servers are stopped");
|
||||||
} else if (!serversAreRunning && runningNew) {
|
} else if (!serversAreRunning && runningNew) {
|
||||||
|
@ -2,6 +2,7 @@ package net.knarcraft.minecraftserverlauncher.profile;
|
|||||||
|
|
||||||
import net.knarcraft.minecraftserverlauncher.Main;
|
import net.knarcraft.minecraftserverlauncher.Main;
|
||||||
import net.knarcraft.minecraftserverlauncher.server.Server;
|
import net.knarcraft.minecraftserverlauncher.server.Server;
|
||||||
|
import net.knarcraft.minecraftserverlauncher.server.ServerHandler;
|
||||||
import net.knarcraft.minecraftserverlauncher.userinterface.ServerConsoles;
|
import net.knarcraft.minecraftserverlauncher.userinterface.ServerConsoles;
|
||||||
import net.knarcraft.minecraftserverlauncher.userinterface.ServerLauncherGUI;
|
import net.knarcraft.minecraftserverlauncher.userinterface.ServerLauncherGUI;
|
||||||
import net.knarcraft.minecraftserverlauncher.utility.CommonFunctions;
|
import net.knarcraft.minecraftserverlauncher.utility.CommonFunctions;
|
||||||
@ -10,6 +11,7 @@ import javax.naming.ConfigurationException;
|
|||||||
import javax.swing.*;
|
import javax.swing.*;
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Keeps track of a set of servers and some user settings
|
* Keeps track of a set of servers and some user settings
|
||||||
@ -21,7 +23,7 @@ import java.util.ArrayList;
|
|||||||
public class Profile {
|
public class Profile {
|
||||||
|
|
||||||
private static final ServerLauncherGUI serverLauncherGui = Main.getController().getGUI();
|
private static final ServerLauncherGUI serverLauncherGui = Main.getController().getGUI();
|
||||||
private final ArrayList<Collection> collections;
|
private final List<Collection> collections;
|
||||||
private final String name;
|
private final String name;
|
||||||
private boolean runInBackground;
|
private boolean runInBackground;
|
||||||
private int delayStartup;
|
private int delayStartup;
|
||||||
@ -105,7 +107,7 @@ public class Profile {
|
|||||||
*
|
*
|
||||||
* @return <p>All collections stored by this profile</p>
|
* @return <p>All collections stored by this profile</p>
|
||||||
*/
|
*/
|
||||||
public ArrayList<Collection> getCollections() {
|
public List<Collection> getCollections() {
|
||||||
return this.collections;
|
return this.collections;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -239,10 +241,10 @@ public class Profile {
|
|||||||
if (data[1].contains("!")) {
|
if (data[1].contains("!")) {
|
||||||
String[] servers = data[1].split("!", -1);
|
String[] servers = data[1].split("!", -1);
|
||||||
for (String server : servers) {
|
for (String server : servers) {
|
||||||
profile.collections.add(new Collection(Server.fromString(server)));
|
profile.collections.add(new Collection(ServerHandler.fromString(server)));
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
profile.collections.add(new Collection(Server.fromString(data[1])));
|
profile.collections.add(new Collection(ServerHandler.fromString(data[1])));
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
profile = parseProfile(profileString.split(";", -1));
|
profile = parseProfile(profileString.split(";", -1));
|
||||||
|
@ -2,6 +2,7 @@ package net.knarcraft.minecraftserverlauncher.profile;
|
|||||||
|
|
||||||
import net.knarcraft.minecraftserverlauncher.Main;
|
import net.knarcraft.minecraftserverlauncher.Main;
|
||||||
import net.knarcraft.minecraftserverlauncher.server.Server;
|
import net.knarcraft.minecraftserverlauncher.server.Server;
|
||||||
|
import net.knarcraft.minecraftserverlauncher.server.ServerHandler;
|
||||||
import net.knarcraft.minecraftserverlauncher.server.ServerTypeHandler;
|
import net.knarcraft.minecraftserverlauncher.server.ServerTypeHandler;
|
||||||
import net.knarcraft.minecraftserverlauncher.userinterface.ServerLauncherGUI;
|
import net.knarcraft.minecraftserverlauncher.userinterface.ServerLauncherGUI;
|
||||||
import net.knarcraft.minecraftserverlauncher.userinterface.ServerTab;
|
import net.knarcraft.minecraftserverlauncher.userinterface.ServerTab;
|
||||||
@ -392,7 +393,7 @@ public class ServerLauncherController {
|
|||||||
});
|
});
|
||||||
}
|
}
|
||||||
if (this.currentProfile.getRunInBackground()) {
|
if (this.currentProfile.getRunInBackground()) {
|
||||||
Executors.newSingleThreadExecutor().execute(Server::startServers);
|
Executors.newSingleThreadExecutor().execute(ServerHandler::startServers);
|
||||||
this.serverLauncherGUI.hideToTray();
|
this.serverLauncherGUI.hideToTray();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -1,9 +1,9 @@
|
|||||||
package net.knarcraft.minecraftserverlauncher.server;
|
package net.knarcraft.minecraftserverlauncher.server;
|
||||||
|
|
||||||
import net.knarcraft.minecraftserverlauncher.Main;
|
import net.knarcraft.minecraftserverlauncher.Main;
|
||||||
import net.knarcraft.minecraftserverlauncher.profile.Collection;
|
|
||||||
import net.knarcraft.minecraftserverlauncher.profile.ServerLauncherController;
|
import net.knarcraft.minecraftserverlauncher.profile.ServerLauncherController;
|
||||||
import net.knarcraft.minecraftserverlauncher.server.servertypes.ServerType;
|
import net.knarcraft.minecraftserverlauncher.server.servertypes.ServerType;
|
||||||
|
import net.knarcraft.minecraftserverlauncher.userinterface.ServerLauncherGUI;
|
||||||
import net.knarcraft.minecraftserverlauncher.utility.CommonFunctions;
|
import net.knarcraft.minecraftserverlauncher.utility.CommonFunctions;
|
||||||
|
|
||||||
import javax.naming.ConfigurationException;
|
import javax.naming.ConfigurationException;
|
||||||
@ -31,14 +31,9 @@ import java.util.regex.Pattern;
|
|||||||
* @since 1.0.0
|
* @since 1.0.0
|
||||||
*/
|
*/
|
||||||
public class Server {
|
public class Server {
|
||||||
/**
|
|
||||||
* Available ram sizes. For ServerLauncherGUI combo
|
|
||||||
*/
|
|
||||||
private static final String[] ramList = {"512M", "1G", "2G", "3G", "4G", "5G", "6G", "7G", "8G", "9G", "10G",
|
|
||||||
"11G", "12G", "13G", "14G", "15G", "16G"};
|
|
||||||
private static final String jarDirectory = Main.getApplicationWorkDirectory() + File.separator + "files" +
|
private static final String jarDirectory = Main.getApplicationWorkDirectory() + File.separator + "files" +
|
||||||
File.separator + "Jars" + File.separator;
|
File.separator + "Jars" + File.separator;
|
||||||
|
|
||||||
private final String name;
|
private final String name;
|
||||||
private final ArrayList<String> playerList;
|
private final ArrayList<String> playerList;
|
||||||
private String path;
|
private String path;
|
||||||
@ -51,7 +46,7 @@ public class Server {
|
|||||||
private BufferedReader reader;
|
private BufferedReader reader;
|
||||||
private boolean started;
|
private boolean started;
|
||||||
private ScheduledExecutorService consoleOutputExecutor;
|
private ScheduledExecutorService consoleOutputExecutor;
|
||||||
private static boolean stoppingServers = false;
|
private final ServerLauncherGUI gui = Main.getController().getGUI();
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Initializes a new server with default values
|
* Initializes a new server with default values
|
||||||
@ -65,7 +60,7 @@ public class Server {
|
|||||||
this.playerList = new ArrayList<>();
|
this.playerList = new ArrayList<>();
|
||||||
this.type = null;
|
this.type = null;
|
||||||
this.serverVersion = "";
|
this.serverVersion = "";
|
||||||
this.maxRam = ramList[0];
|
this.maxRam = ServerHandler.getRamList()[0];
|
||||||
this.process = null;
|
this.process = null;
|
||||||
this.writer = null;
|
this.writer = null;
|
||||||
this.reader = null;
|
this.reader = null;
|
||||||
@ -91,15 +86,6 @@ public class Server {
|
|||||||
this.playerList = new ArrayList<>();
|
this.playerList = new ArrayList<>();
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* Gets the list of available RAM choices allowed
|
|
||||||
*
|
|
||||||
* @return <p>All available RAM choices</p>
|
|
||||||
*/
|
|
||||||
public static String[] getRamList() {
|
|
||||||
return ramList;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Gets the buffered reader used to read from this server
|
* Gets the buffered reader used to read from this server
|
||||||
*
|
*
|
||||||
@ -109,101 +95,6 @@ public class Server {
|
|||||||
return this.reader;
|
return this.reader;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* Marks the servers as finished stopping when a stop is confirmed
|
|
||||||
*/
|
|
||||||
public static void serversStopped() {
|
|
||||||
if (stoppingServers) {
|
|
||||||
stoppingServers = false;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Tries to stop all enabled servers
|
|
||||||
*
|
|
||||||
* @throws IOException <p>If a writer's process is already closed but not null</p>
|
|
||||||
*/
|
|
||||||
public static void stop() throws IOException, InterruptedException {
|
|
||||||
if (stoppingServers) {
|
|
||||||
killServers();
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
stoppingServers = true;
|
|
||||||
for (Collection collection : Main.getController().getCurrentProfile().getCollections()) {
|
|
||||||
Server server = collection.getServer();
|
|
||||||
if (server.writer != null) {
|
|
||||||
if (server.type.isProxy()) {
|
|
||||||
server.writer.write("end\n");
|
|
||||||
} else {
|
|
||||||
server.writer.write("stop\n");
|
|
||||||
}
|
|
||||||
server.writer.flush();
|
|
||||||
server.writer = null;
|
|
||||||
server.started = false;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Kills all server processes
|
|
||||||
*
|
|
||||||
* @throws InterruptedException <p>If interrupted waiting for any of the servers to stop</p>
|
|
||||||
*/
|
|
||||||
private static void killServers() throws InterruptedException {
|
|
||||||
for (Collection collection : Main.getController().getCurrentProfile().getCollections()) {
|
|
||||||
Server server = collection.getServer();
|
|
||||||
killServer(server);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Kills the given server after waiting 30 seconds for it to terminate normally
|
|
||||||
*
|
|
||||||
* @param server <p>The server to kill</p>
|
|
||||||
* @throws InterruptedException <p>If interrupted waiting for the server to stop</p>
|
|
||||||
*/
|
|
||||||
private static void killServer(Server server) throws InterruptedException {
|
|
||||||
if (server.process != null) {
|
|
||||||
if (!server.process.waitFor(30, TimeUnit.SECONDS)) {
|
|
||||||
server.process.destroyForcibly();
|
|
||||||
server.process.waitFor();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Runs all enabled servers with their settings
|
|
||||||
*/
|
|
||||||
public static void startServers() {
|
|
||||||
ServerLauncherController controller = Main.getController();
|
|
||||||
controller.getGUI().setStatus("Starting servers");
|
|
||||||
int serverNum = 0;
|
|
||||||
for (Collection collection : controller.getCurrentProfile().getCollections()) {
|
|
||||||
if (!collection.getServer().runServer(serverNum++ == 0)) {
|
|
||||||
controller.getGUI().showError("An error occurred. Start aborted. Please check the BuildTools log.");
|
|
||||||
try {
|
|
||||||
Server.stop();
|
|
||||||
} catch (IOException | InterruptedException e) {
|
|
||||||
e.printStackTrace();
|
|
||||||
}
|
|
||||||
controller.getGUI().updateGUIElementsWhenServersStartOrStop(false);
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Gets a server object from a server save string
|
|
||||||
*
|
|
||||||
* @param saveString <p>The string containing necessary data regarding the server</p>
|
|
||||||
* @return <p>A server in the same state it was saved in</p>
|
|
||||||
*/
|
|
||||||
public static Server fromString(String saveString) throws ConfigurationException {
|
|
||||||
String[] data = saveString.split(";");
|
|
||||||
return new Server(data[0], data[1], Boolean.parseBoolean(data[2]), data[3], data[4], data[5]);
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Gets the name of the server
|
* Gets the name of the server
|
||||||
*
|
*
|
||||||
@ -269,6 +160,42 @@ public class Server {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Gets whether this server is a proxy server
|
||||||
|
*
|
||||||
|
* <p>A proxy server is a server running BungeeCord, Waterfall or Travertine.</p>
|
||||||
|
*
|
||||||
|
* @return <p>True if this server is a proxy server</p>
|
||||||
|
*/
|
||||||
|
public boolean isProxy() {
|
||||||
|
return this.type.isProxy();
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Marks this server as stopped
|
||||||
|
*/
|
||||||
|
public void setStopped() {
|
||||||
|
this.started = false;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Gets the writer used to write to this server
|
||||||
|
*
|
||||||
|
* @return <p>The writer used.</p>
|
||||||
|
*/
|
||||||
|
public BufferedWriter getWriter() {
|
||||||
|
return this.writer;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Sets the writer used to write to this server
|
||||||
|
*
|
||||||
|
* @param writer <p>The new writer to use.</p>
|
||||||
|
*/
|
||||||
|
public void setWriter(BufferedWriter writer) {
|
||||||
|
this.writer = writer;
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Gets the path for this server's files
|
* Gets the path for this server's files
|
||||||
*
|
*
|
||||||
@ -374,7 +301,7 @@ public class Server {
|
|||||||
*/
|
*/
|
||||||
private void addPlayer(String name) {
|
private void addPlayer(String name) {
|
||||||
this.playerList.add(name);
|
this.playerList.add(name);
|
||||||
Main.getController().getGUI().getServerControlTab().addPlayer(name);
|
gui.getServerControlTab().addPlayer(name);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -384,7 +311,7 @@ public class Server {
|
|||||||
*/
|
*/
|
||||||
private void removePlayer(String name) {
|
private void removePlayer(String name) {
|
||||||
playerList.removeIf(player -> player.equals(name));
|
playerList.removeIf(player -> player.equals(name));
|
||||||
Main.getController().getGUI().getServerControlTab().removePlayer(name);
|
gui.getServerControlTab().removePlayer(name);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -399,10 +326,12 @@ public class Server {
|
|||||||
/**
|
/**
|
||||||
* Runs a Minecraft server
|
* Runs a Minecraft server
|
||||||
*
|
*
|
||||||
|
* @param skipDelay <p>Whether to skip the startup delay for this server</p>
|
||||||
* @return <p>True if nothing went wrong</p>
|
* @return <p>True if nothing went wrong</p>
|
||||||
*/
|
*/
|
||||||
private boolean runServer(boolean isFirstServer) {
|
public boolean runServer(boolean skipDelay) {
|
||||||
if (stoppingServers) {
|
if (ServerHandler.stoppingServers()) {
|
||||||
|
gui.logMessage("Stopping servers. Cannot start yet.");
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
//Ignore a disabled server
|
//Ignore a disabled server
|
||||||
@ -411,21 +340,23 @@ public class Server {
|
|||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
//Tries to do necessary pre-start work
|
//Tries to do necessary pre-start work
|
||||||
if (!initializeJarDownload() || (!isFirstServer && !delayStartup())) {
|
if (!initializeJarDownload() || (!skipDelay && !delayStartup())) {
|
||||||
|
gui.logError("Failed to perform startup tasks.");
|
||||||
this.started = false;
|
this.started = false;
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
if (stoppingServers) {
|
if (ServerHandler.stoppingServers()) {
|
||||||
|
gui.logMessage("Stopping servers. Cannot start yet.");
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
//Starts the server if possible
|
//Starts the server if possible
|
||||||
try {
|
try {
|
||||||
startServerProcess();
|
startServerProcess();
|
||||||
Main.getController().getGUI().setStatus("Servers are running");
|
gui.setStatus("Servers are running");
|
||||||
this.started = true;
|
this.started = true;
|
||||||
return true;
|
return true;
|
||||||
} catch (IOException e) {
|
} catch (IOException e) {
|
||||||
Main.getController().getGUI().setStatus("Could not start server");
|
gui.setStatus("Could not start server");
|
||||||
this.started = false;
|
this.started = false;
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
@ -438,14 +369,17 @@ public class Server {
|
|||||||
*/
|
*/
|
||||||
private String getJavaCommand() {
|
private String getJavaCommand() {
|
||||||
ServerLauncherController controller = ServerLauncherController.getInstance();
|
ServerLauncherController controller = ServerLauncherController.getInstance();
|
||||||
|
|
||||||
if (serverVersion.toLowerCase().contains("latest")) {
|
if (serverVersion.toLowerCase().contains("latest")) {
|
||||||
return controller.getJavaCommand();
|
return controller.getJavaCommand();
|
||||||
} else if (serverVersion.contains(".") && serverVersion.split("\\.").length >= 2 &&
|
} else if (serverVersion.contains(".") && serverVersion.split("\\.").length >= 2) {
|
||||||
Integer.parseInt(serverVersion.split("\\.")[1]) >= 17) {
|
try {
|
||||||
|
if (Integer.parseInt(serverVersion.split("\\.")[1]) >= 17) {
|
||||||
return controller.getJavaCommand();
|
return controller.getJavaCommand();
|
||||||
} else {
|
|
||||||
return controller.getOldJavaCommand();
|
|
||||||
}
|
}
|
||||||
|
} catch (NumberFormatException ignored) {}
|
||||||
|
}
|
||||||
|
return controller.getOldJavaCommand();
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -529,11 +463,11 @@ public class Server {
|
|||||||
private String getPlayer(String text, boolean joined) {
|
private String getPlayer(String text, boolean joined) {
|
||||||
String playerName;
|
String playerName;
|
||||||
|
|
||||||
String loginPattern1 = " ([A-Z0-9a-z]+)\\[/[0-9]+\\.[0-9]+\\.[0-9]+\\.[0-9]+:[0-9]+] logged in";
|
String loginPattern1 = " ([A-Z0-9a-z_]+)\\[/[0-9]+\\.[0-9]+\\.[0-9]+\\.[0-9]+:[0-9]+] logged in";
|
||||||
String loginPattern2 = "UUID of player ([A-Z0-9a-z]+) is";
|
String loginPattern2 = "UUID of player ([A-Z0-9a-z_]+) is";
|
||||||
|
|
||||||
String logoutPattern1 = "INFO]: ([A-Z0-9a-z]+) lost connection";
|
String logoutPattern1 = "INFO]: ([A-Z0-9a-z_]+) lost connection";
|
||||||
String logoutPattern2 = " ([A-Z0-9a-z]+) left the game";
|
String logoutPattern2 = " ([A-Z0-9a-z_]+) left the game";
|
||||||
|
|
||||||
if (joined) {
|
if (joined) {
|
||||||
playerName = getFirstRegexCaptureGroup(loginPattern1, text);
|
playerName = getFirstRegexCaptureGroup(loginPattern1, text);
|
||||||
@ -573,7 +507,7 @@ public class Server {
|
|||||||
*/
|
*/
|
||||||
private boolean delayStartup() {
|
private boolean delayStartup() {
|
||||||
try {
|
try {
|
||||||
Main.getController().getGUI().setStatus("Delaying startup");
|
gui.setStatus("Delaying startup");
|
||||||
TimeUnit.SECONDS.sleep(Main.getController().getCurrentProfile().getDelayStartup());
|
TimeUnit.SECONDS.sleep(Main.getController().getCurrentProfile().getDelayStartup());
|
||||||
return true;
|
return true;
|
||||||
} catch (InterruptedException e) {
|
} catch (InterruptedException e) {
|
||||||
@ -589,19 +523,16 @@ public class Server {
|
|||||||
* @return <p>True if nothing went wrong</p>
|
* @return <p>True if nothing went wrong</p>
|
||||||
*/
|
*/
|
||||||
private boolean initializeJarDownload() {
|
private boolean initializeJarDownload() {
|
||||||
ServerLauncherController controller = Main.getController();
|
|
||||||
if (!controller.getDownloadAllJars()) {
|
|
||||||
try {
|
try {
|
||||||
controller.getGUI().setStatus("Downloading jar...");
|
gui.setStatus("Downloading jar...");
|
||||||
this.downloadJar();
|
this.downloadJar();
|
||||||
controller.getGUI().setStatus("File downloaded");
|
gui.setStatus("File downloaded");
|
||||||
} catch (IOException e) {
|
} catch (IOException e) {
|
||||||
controller.getGUI().setStatus("Error: Jar file not found");
|
gui.setStatus("Error: Jar file could not be found, downloaded or built.");
|
||||||
e.printStackTrace();
|
gui.logError("Unable to get required .jar file: " + e.getMessage());
|
||||||
this.started = false;
|
this.started = false;
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
}
|
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -0,0 +1,151 @@
|
|||||||
|
package net.knarcraft.minecraftserverlauncher.server;
|
||||||
|
|
||||||
|
import net.knarcraft.minecraftserverlauncher.Main;
|
||||||
|
import net.knarcraft.minecraftserverlauncher.profile.Collection;
|
||||||
|
import net.knarcraft.minecraftserverlauncher.profile.ServerLauncherController;
|
||||||
|
import net.knarcraft.minecraftserverlauncher.userinterface.ServerLauncherGUI;
|
||||||
|
|
||||||
|
import javax.naming.ConfigurationException;
|
||||||
|
import java.io.BufferedWriter;
|
||||||
|
import java.io.IOException;
|
||||||
|
import java.util.concurrent.TimeUnit;
|
||||||
|
|
||||||
|
public class ServerHandler {
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Available ram sizes. For ServerLauncherGUI combo
|
||||||
|
*/
|
||||||
|
private static final String[] ramList = {"512M", "1G", "2G", "3G", "4G", "5G", "6G", "7G", "8G", "9G", "10G",
|
||||||
|
"11G", "12G", "13G", "14G", "15G", "16G"};
|
||||||
|
|
||||||
|
private static boolean stoppingServers = false;
|
||||||
|
private static final ServerLauncherGUI gui = Main.getController().getGUI();
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Gets the list of available RAM choices allowed
|
||||||
|
*
|
||||||
|
* @return <p>All available RAM choices</p>
|
||||||
|
*/
|
||||||
|
public static String[] getRamList() {
|
||||||
|
return ramList;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Gets whether the servers are currently in the process of stopping
|
||||||
|
*
|
||||||
|
* @return <p>True if the servers are in the process of stopping.</p>
|
||||||
|
*/
|
||||||
|
public static boolean stoppingServers() {
|
||||||
|
return stoppingServers;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Marks the servers as finished stopping when a stop is confirmed
|
||||||
|
*/
|
||||||
|
public static void serversStopped() {
|
||||||
|
if (stoppingServers) {
|
||||||
|
stoppingServers = false;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Tries to stop all enabled servers
|
||||||
|
*
|
||||||
|
* @throws IOException <p>If a writer's process is already closed but not null</p>
|
||||||
|
*/
|
||||||
|
public static void stop() throws IOException, InterruptedException {
|
||||||
|
if (stoppingServers) {
|
||||||
|
killServers();
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
stoppingServers = true;
|
||||||
|
int serversRunning = 0;
|
||||||
|
|
||||||
|
for (Collection collection : Main.getController().getCurrentProfile().getCollections()) {
|
||||||
|
Server server = collection.getServer();
|
||||||
|
BufferedWriter writer = server.getWriter();
|
||||||
|
if (writer != null) {
|
||||||
|
serversRunning++;
|
||||||
|
if (server.isProxy()) {
|
||||||
|
writer.write("end\n");
|
||||||
|
} else {
|
||||||
|
writer.write("stop\n");
|
||||||
|
}
|
||||||
|
writer.flush();
|
||||||
|
server.setWriter(null);
|
||||||
|
server.setStopped();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if (serversRunning == 0) {
|
||||||
|
stoppingServers = false;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Kills all server processes
|
||||||
|
*
|
||||||
|
* @throws InterruptedException <p>If interrupted waiting for any of the servers to stop</p>
|
||||||
|
*/
|
||||||
|
private static void killServers() throws InterruptedException {
|
||||||
|
for (Collection collection : Main.getController().getCurrentProfile().getCollections()) {
|
||||||
|
Server server = collection.getServer();
|
||||||
|
killServer(server);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Kills the given server after waiting 30 seconds for it to terminate normally
|
||||||
|
*
|
||||||
|
* @param server <p>The server to kill</p>
|
||||||
|
* @throws InterruptedException <p>If interrupted waiting for the server to stop</p>
|
||||||
|
*/
|
||||||
|
private static void killServer(Server server) throws InterruptedException {
|
||||||
|
Process serverProcess = server.getProcess();
|
||||||
|
if (serverProcess != null) {
|
||||||
|
if (!serverProcess.waitFor(30, TimeUnit.SECONDS)) {
|
||||||
|
serverProcess.destroyForcibly();
|
||||||
|
serverProcess.waitFor();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Runs all enabled servers with their settings
|
||||||
|
*/
|
||||||
|
public static void startServers() {
|
||||||
|
ServerLauncherController controller = Main.getController();
|
||||||
|
gui.setStatus("Starting servers");
|
||||||
|
Server previouslyStartedServer = null;
|
||||||
|
|
||||||
|
for (Collection collection : controller.getCurrentProfile().getCollections()) {
|
||||||
|
Server server = collection.getServer();
|
||||||
|
if (!server.runServer(previouslyStartedServer == null || previouslyStartedServer.isProxy())) {
|
||||||
|
gui.showError("An error occurred. Start aborted. Please check relevant log files.");
|
||||||
|
try {
|
||||||
|
stop();
|
||||||
|
} catch (IOException | InterruptedException e) {
|
||||||
|
e.printStackTrace();
|
||||||
|
}
|
||||||
|
gui.updateGUIElementsWhenServersStartOrStop(false);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
if (server.isEnabled()) {
|
||||||
|
previouslyStartedServer = server;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Gets a server object from a server save string
|
||||||
|
*
|
||||||
|
* @param saveString <p>The string containing necessary data regarding the server</p>
|
||||||
|
* @return <p>A server in the same state it was saved in</p>
|
||||||
|
*/
|
||||||
|
public static Server fromString(String saveString) throws ConfigurationException {
|
||||||
|
String[] data = saveString.split(";");
|
||||||
|
return new Server(data[0], data[1], Boolean.parseBoolean(data[2]), data[3], data[4], data[5]);
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
@ -134,7 +134,7 @@ public class ServerTypeHandler {
|
|||||||
break;
|
break;
|
||||||
case "Paper":
|
case "Paper":
|
||||||
newType = new Paper("Paper", false, serverVersions, serverTypeInfo[2],
|
newType = new Paper("Paper", false, serverVersions, serverTypeInfo[2],
|
||||||
serverTypeInfo[3]);
|
serverTypeInfo[3], serverTypeInfo[4], serverTypeInfo[5]);
|
||||||
break;
|
break;
|
||||||
case "Bungee":
|
case "Bungee":
|
||||||
newType = new BungeeCord("Bungee", true, serverVersions, serverTypeInfo[2],
|
newType = new BungeeCord("Bungee", true, serverVersions, serverTypeInfo[2],
|
||||||
|
@ -22,6 +22,7 @@ public class ServerVersionContainer {
|
|||||||
private String bungeeVersion;
|
private String bungeeVersion;
|
||||||
private Map<String, String> waterfallVersions;
|
private Map<String, String> waterfallVersions;
|
||||||
private Map<String, String> travertineVersions;
|
private Map<String, String> travertineVersions;
|
||||||
|
private Map<String, String> paperVersions;
|
||||||
private Map<String, String> spongeVanillaVersions;
|
private Map<String, String> spongeVanillaVersions;
|
||||||
private Map<String, String> spongeForgeVersions;
|
private Map<String, String> spongeForgeVersions;
|
||||||
private String downloadedBuildToolsVersion;
|
private String downloadedBuildToolsVersion;
|
||||||
@ -32,6 +33,7 @@ public class ServerVersionContainer {
|
|||||||
private ServerVersionContainer() {
|
private ServerVersionContainer() {
|
||||||
this.waterfallVersions = new HashMap<>();
|
this.waterfallVersions = new HashMap<>();
|
||||||
this.travertineVersions = new HashMap<>();
|
this.travertineVersions = new HashMap<>();
|
||||||
|
this.paperVersions = new HashMap<>();
|
||||||
this.spongeVanillaVersions = new HashMap<>();
|
this.spongeVanillaVersions = new HashMap<>();
|
||||||
this.spongeForgeVersions = new HashMap<>();
|
this.spongeForgeVersions = new HashMap<>();
|
||||||
loadState();
|
loadState();
|
||||||
@ -58,6 +60,7 @@ public class ServerVersionContainer {
|
|||||||
this.bungeeVersion = null;
|
this.bungeeVersion = null;
|
||||||
this.waterfallVersions = new HashMap<>();
|
this.waterfallVersions = new HashMap<>();
|
||||||
this.travertineVersions = new HashMap<>();
|
this.travertineVersions = new HashMap<>();
|
||||||
|
this.paperVersions = new HashMap<>();
|
||||||
this.spongeVanillaVersions = new HashMap<>();
|
this.spongeVanillaVersions = new HashMap<>();
|
||||||
this.spongeForgeVersions = new HashMap<>();
|
this.spongeForgeVersions = new HashMap<>();
|
||||||
this.downloadedBuildToolsVersion = null;
|
this.downloadedBuildToolsVersion = null;
|
||||||
@ -70,6 +73,7 @@ public class ServerVersionContainer {
|
|||||||
"bungeeVersion;" + bungeeVersion + "\n" +
|
"bungeeVersion;" + bungeeVersion + "\n" +
|
||||||
"waterfallVersions;" + mapToString(waterfallVersions) + "\n" +
|
"waterfallVersions;" + mapToString(waterfallVersions) + "\n" +
|
||||||
"travertineVersions;" + mapToString(travertineVersions) + "\n" +
|
"travertineVersions;" + mapToString(travertineVersions) + "\n" +
|
||||||
|
"paperVersions;" + mapToString(paperVersions) + "\n" +
|
||||||
"spongeVanillaVersions;" + mapToString(spongeVanillaVersions) + "\n" +
|
"spongeVanillaVersions;" + mapToString(spongeVanillaVersions) + "\n" +
|
||||||
"spongeForgeVersions;" + mapToString(spongeForgeVersions) + "\n" +
|
"spongeForgeVersions;" + mapToString(spongeForgeVersions) + "\n" +
|
||||||
"downloadedBuildToolsVersion;" + downloadedBuildToolsVersion;
|
"downloadedBuildToolsVersion;" + downloadedBuildToolsVersion;
|
||||||
@ -163,6 +167,9 @@ public class ServerVersionContainer {
|
|||||||
case "travertineVersions":
|
case "travertineVersions":
|
||||||
parseVersionsToMap(travertineVersions, variableValue);
|
parseVersionsToMap(travertineVersions, variableValue);
|
||||||
break;
|
break;
|
||||||
|
case "paperVersions":
|
||||||
|
parseVersionsToMap(paperVersions, variableValue);
|
||||||
|
break;
|
||||||
case "spongeVanillaVersions":
|
case "spongeVanillaVersions":
|
||||||
parseVersionsToMap(spongeVanillaVersions, variableValue);
|
parseVersionsToMap(spongeVanillaVersions, variableValue);
|
||||||
break;
|
break;
|
||||||
@ -291,6 +298,27 @@ public class ServerVersionContainer {
|
|||||||
saveState();
|
saveState();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Gets a specific paper version
|
||||||
|
*
|
||||||
|
* @param versionKey <p>The version to check the current version of</p>
|
||||||
|
* @return <p>The current paper version</p>
|
||||||
|
*/
|
||||||
|
public String getPaperVersion(String versionKey) {
|
||||||
|
return this.paperVersions.get(versionKey);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Sets the current version for a given paper version
|
||||||
|
*
|
||||||
|
* @param mapKey <p>The version key to set version for</p>
|
||||||
|
* @param newValue <p>The new current version</p>
|
||||||
|
*/
|
||||||
|
public void setPaperVersion(String mapKey, String newValue) {
|
||||||
|
this.paperVersions.put(mapKey, newValue);
|
||||||
|
saveState();
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Gets a specific sponge vanilla version
|
* Gets a specific sponge vanilla version
|
||||||
*
|
*
|
||||||
|
@ -3,19 +3,25 @@ package net.knarcraft.minecraftserverlauncher.server.servertypes;
|
|||||||
/**
|
/**
|
||||||
* This class represents the Paper Minecraft server type
|
* This class represents the Paper Minecraft server type
|
||||||
*/
|
*/
|
||||||
public class Paper extends Spigot {
|
public class Paper extends Waterfall {
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Instantiates a new Paper server type
|
* Instantiates a new Paper server type
|
||||||
*
|
*
|
||||||
* @param typeName <p>The name of the server type</p>
|
* @param typeName <p>The name of the server type</p>
|
||||||
* @param isProxy <p>Whether this server type is a proxy server</p>
|
* @param isProxy <p>Whether this server type is a proxy server</p>
|
||||||
* @param versions <p>A list of one or more server versions for the type</p>
|
* @param versions <p>The available versions for the server type</p>
|
||||||
* @param downloadURL <p>The URL used for downloading .jar files</p>
|
* @param versionURL <p>The URL used to finding the newest version</p>
|
||||||
* @param downloadURLPart <p>A string used after the download url as an additional part of the URL</p>
|
* @param srcStart <p>The string after which the version id starts</p>
|
||||||
|
* @param srcEnd <p>The string marking the end of the version id</p>
|
||||||
|
* @param downloadURL <p>The URL used for downloading the latest version</p>
|
||||||
*/
|
*/
|
||||||
public Paper(String typeName, boolean isProxy, String[] versions, String downloadURL, String downloadURLPart) {
|
public Paper(String typeName, boolean isProxy, String[] versions, String versionURL, String srcStart,
|
||||||
super(typeName, isProxy, versions, downloadURL, downloadURLPart);
|
String srcEnd, String downloadURL) {
|
||||||
|
super(typeName, isProxy, versions, versionURL, srcStart, srcEnd, downloadURL);
|
||||||
|
|
||||||
|
this.oldVersionFunction = serverVersionContainer::getPaperVersion;
|
||||||
|
this.versionUpdateFunction = serverVersionContainer::setPaperVersion;
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -0,0 +1,95 @@
|
|||||||
|
package net.knarcraft.minecraftserverlauncher.userinterface;
|
||||||
|
|
||||||
|
import net.knarcraft.minecraftserverlauncher.utility.BackupUtil;
|
||||||
|
|
||||||
|
import javax.swing.*;
|
||||||
|
import java.awt.*;
|
||||||
|
import java.awt.event.ActionEvent;
|
||||||
|
import java.awt.event.ActionListener;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* The Backup GUI is used to display backup progress
|
||||||
|
*/
|
||||||
|
public class BackupGUI implements ActionListener {
|
||||||
|
private static JFrame frame;
|
||||||
|
private static JTextArea progressTextArea;
|
||||||
|
private static JProgressBar progressBar;
|
||||||
|
private static JButton cancelButton;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Instantiates a new GUI
|
||||||
|
*/
|
||||||
|
public BackupGUI() {
|
||||||
|
instantiate();
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Initializes the server consoles frame
|
||||||
|
*/
|
||||||
|
public void instantiate() {
|
||||||
|
if (frame != null) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
frame = new JFrame("Running backup...");
|
||||||
|
frame.setBounds(100, 100, 500, 140);
|
||||||
|
frame.setDefaultCloseOperation(JFrame.DO_NOTHING_ON_CLOSE);
|
||||||
|
progressTextArea = new JTextArea();
|
||||||
|
progressTextArea.setEditable(false);
|
||||||
|
progressBar = new JProgressBar();
|
||||||
|
cancelButton = new JButton("Cancel");
|
||||||
|
JPanel panel = new JPanel();
|
||||||
|
panel.setLayout(new BoxLayout(panel, BoxLayout.PAGE_AXIS));
|
||||||
|
panel.add(progressTextArea);
|
||||||
|
panel.add(Box.createRigidArea(new Dimension(0,5)));
|
||||||
|
panel.add(progressBar);
|
||||||
|
|
||||||
|
JPanel buttonPane = new JPanel();
|
||||||
|
buttonPane.setLayout(new BoxLayout(buttonPane, BoxLayout.LINE_AXIS));
|
||||||
|
buttonPane.setBorder(BorderFactory.createEmptyBorder(0, 10, 10, 10));
|
||||||
|
buttonPane.add(Box.createHorizontalGlue());
|
||||||
|
buttonPane.add(cancelButton);
|
||||||
|
cancelButton.addActionListener(BackupGUI.this);
|
||||||
|
|
||||||
|
panel.setBorder(BorderFactory.createEmptyBorder(10, 10, 10, 10));
|
||||||
|
Container contentPane = frame.getContentPane();
|
||||||
|
contentPane.add(panel, BorderLayout.CENTER);
|
||||||
|
contentPane.add(buttonPane, BorderLayout.PAGE_END);
|
||||||
|
frame.setVisible(true);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Updates information about the backup progress
|
||||||
|
*
|
||||||
|
* @param infoText <p>The text to display</p>
|
||||||
|
* @param progressPercent <p>The new percent of the progress bar</p>
|
||||||
|
*/
|
||||||
|
public static void updateProgress(String infoText, int progressPercent) {
|
||||||
|
if (progressTextArea != null) {
|
||||||
|
progressTextArea.setText(infoText);
|
||||||
|
}
|
||||||
|
if (progressBar != null) {
|
||||||
|
progressBar.setValue(progressPercent);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Destroys the backup GUI
|
||||||
|
*/
|
||||||
|
public static void destroy() {
|
||||||
|
if (frame != null) {
|
||||||
|
frame.dispose();
|
||||||
|
frame = null;
|
||||||
|
progressBar = null;
|
||||||
|
progressTextArea = null;
|
||||||
|
cancelButton = null;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void actionPerformed(ActionEvent actionEvent) {
|
||||||
|
if (actionEvent.getSource() == cancelButton) {
|
||||||
|
BackupUtil.abortBackup();
|
||||||
|
destroy();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
@ -93,7 +93,7 @@ public class Console extends KeyAdapter implements ActionListener, KeyListener {
|
|||||||
StringBuilder newTextBuilder = new StringBuilder();
|
StringBuilder newTextBuilder = new StringBuilder();
|
||||||
for (String line : oldTextList) {
|
for (String line : oldTextList) {
|
||||||
if (!line.equals("")) {
|
if (!line.equals("")) {
|
||||||
newTextBuilder.append(line);
|
newTextBuilder.append(line).append("\n");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
this.textOutput.setText(newTextBuilder.toString());
|
this.textOutput.setText(newTextBuilder.toString());
|
||||||
|
@ -3,8 +3,8 @@ package net.knarcraft.minecraftserverlauncher.userinterface;
|
|||||||
import net.knarcraft.minecraftserverlauncher.Main;
|
import net.knarcraft.minecraftserverlauncher.Main;
|
||||||
import net.knarcraft.minecraftserverlauncher.profile.Collection;
|
import net.knarcraft.minecraftserverlauncher.profile.Collection;
|
||||||
import net.knarcraft.minecraftserverlauncher.profile.ServerLauncherController;
|
import net.knarcraft.minecraftserverlauncher.profile.ServerLauncherController;
|
||||||
import net.knarcraft.minecraftserverlauncher.server.Server;
|
import net.knarcraft.minecraftserverlauncher.server.ServerHandler;
|
||||||
import net.knarcraft.minecraftserverlauncher.utility.CommonFunctions;
|
import net.knarcraft.minecraftserverlauncher.utility.BackupUtil;
|
||||||
|
|
||||||
import javax.imageio.ImageIO;
|
import javax.imageio.ImageIO;
|
||||||
import javax.naming.ConfigurationException;
|
import javax.naming.ConfigurationException;
|
||||||
@ -33,7 +33,7 @@ import static net.knarcraft.minecraftserverlauncher.utility.CommonFunctions.getR
|
|||||||
*/
|
*/
|
||||||
public class ServerLauncherGUI extends MessageHandler implements ActionListener, GUI {
|
public class ServerLauncherGUI extends MessageHandler implements ActionListener, GUI {
|
||||||
|
|
||||||
private final JLabel lblStatuslabel = new JLabel("Servers are stopped");
|
private final JLabel lblStatusLabel = new JLabel("Servers are stopped");
|
||||||
private final ServerLauncherController controller;
|
private final ServerLauncherController controller;
|
||||||
private Map<String, String> textStrings;
|
private Map<String, String> textStrings;
|
||||||
private Tray applicationTray;
|
private Tray applicationTray;
|
||||||
@ -101,7 +101,7 @@ public class ServerLauncherGUI extends MessageHandler implements ActionListener,
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void setStatus(String text) {
|
public void setStatus(String text) {
|
||||||
this.lblStatuslabel.setText(text);
|
this.lblStatusLabel.setText(text);
|
||||||
this.logMessage(text);
|
this.logMessage(text);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -243,11 +243,11 @@ public class ServerLauncherGUI extends MessageHandler implements ActionListener,
|
|||||||
panelBasic.add(profiles);
|
panelBasic.add(profiles);
|
||||||
profiles.addActionListener(this);
|
profiles.addActionListener(this);
|
||||||
|
|
||||||
sl_panel.putConstraint(SpringLayout.NORTH, lblStatuslabel, 6, SpringLayout.SOUTH, addProfileButton);
|
sl_panel.putConstraint(SpringLayout.NORTH, lblStatusLabel, 6, SpringLayout.SOUTH, addProfileButton);
|
||||||
sl_panel.putConstraint(SpringLayout.SOUTH, lblStatuslabel, -10, SpringLayout.SOUTH, panelBasic);
|
sl_panel.putConstraint(SpringLayout.SOUTH, lblStatusLabel, -10, SpringLayout.SOUTH, panelBasic);
|
||||||
sl_panel.putConstraint(SpringLayout.WEST, lblStatuslabel, 10, SpringLayout.WEST, panelBasic);
|
sl_panel.putConstraint(SpringLayout.WEST, lblStatusLabel, 10, SpringLayout.WEST, panelBasic);
|
||||||
sl_panel.putConstraint(SpringLayout.EAST, lblStatuslabel, -10, SpringLayout.EAST, panelBasic);
|
sl_panel.putConstraint(SpringLayout.EAST, lblStatusLabel, -10, SpringLayout.EAST, panelBasic);
|
||||||
panelBasic.add(lblStatuslabel);
|
panelBasic.add(lblStatusLabel);
|
||||||
|
|
||||||
addServerButton = new JButton("Add server");
|
addServerButton = new JButton("Add server");
|
||||||
sl_panel.putConstraint(SpringLayout.NORTH, addServerButton, 0, SpringLayout.NORTH, startServerButton);
|
sl_panel.putConstraint(SpringLayout.NORTH, addServerButton, 0, SpringLayout.NORTH, startServerButton);
|
||||||
@ -314,7 +314,7 @@ public class ServerLauncherGUI extends MessageHandler implements ActionListener,
|
|||||||
@Override
|
@Override
|
||||||
public void actionPerformed(ActionEvent e) {
|
public void actionPerformed(ActionEvent e) {
|
||||||
Object actionSource = e.getSource();
|
Object actionSource = e.getSource();
|
||||||
//Registers actions on the main tab
|
//Register actions on the main tab
|
||||||
handleMainTabButtons(actionSource);
|
handleMainTabButtons(actionSource);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -327,13 +327,14 @@ public class ServerLauncherGUI extends MessageHandler implements ActionListener,
|
|||||||
private void handleMainTabButtons(Object actionSource) {
|
private void handleMainTabButtons(Object actionSource) {
|
||||||
if (actionSource == startServerButton) {
|
if (actionSource == startServerButton) {
|
||||||
controller.saveState();
|
controller.saveState();
|
||||||
Executors.newSingleThreadExecutor().execute(Server::startServers);
|
Executors.newSingleThreadExecutor().execute(ServerHandler::startServers);
|
||||||
} else if (actionSource == stopServerButton) {
|
} else if (actionSource == stopServerButton) {
|
||||||
stopServers();
|
stopServers();
|
||||||
} else if (actionSource == addServerButton) {
|
} else if (actionSource == addServerButton) {
|
||||||
addServer();
|
addServer();
|
||||||
} else if (actionSource == backupButton) {
|
} else if (actionSource == backupButton) {
|
||||||
CommonFunctions.backup(this);
|
//Run backup in its own thread to prevent locking up
|
||||||
|
Executors.newSingleThreadExecutor().execute(() -> BackupUtil.backup(this));
|
||||||
} else if (actionSource == addProfileButton) {
|
} else if (actionSource == addProfileButton) {
|
||||||
controller.addProfile(JOptionPane.showInputDialog("Profile name: "));
|
controller.addProfile(JOptionPane.showInputDialog("Profile name: "));
|
||||||
updateProfiles();
|
updateProfiles();
|
||||||
@ -404,7 +405,7 @@ public class ServerLauncherGUI extends MessageHandler implements ActionListener,
|
|||||||
public void stopServers() {
|
public void stopServers() {
|
||||||
try {
|
try {
|
||||||
setStatus("Servers are stopping...");
|
setStatus("Servers are stopping...");
|
||||||
Server.stop();
|
ServerHandler.stop();
|
||||||
} catch (IOException e1) {
|
} catch (IOException e1) {
|
||||||
showError("Could not stop server.");
|
showError("Could not stop server.");
|
||||||
e1.printStackTrace();
|
e1.printStackTrace();
|
||||||
|
@ -1,7 +1,7 @@
|
|||||||
package net.knarcraft.minecraftserverlauncher.userinterface;
|
package net.knarcraft.minecraftserverlauncher.userinterface;
|
||||||
|
|
||||||
import net.knarcraft.minecraftserverlauncher.Main;
|
import net.knarcraft.minecraftserverlauncher.Main;
|
||||||
import net.knarcraft.minecraftserverlauncher.server.Server;
|
import net.knarcraft.minecraftserverlauncher.server.ServerHandler;
|
||||||
import net.knarcraft.minecraftserverlauncher.server.ServerTypeHandler;
|
import net.knarcraft.minecraftserverlauncher.server.ServerTypeHandler;
|
||||||
import net.knarcraft.minecraftserverlauncher.server.servertypes.ServerType;
|
import net.knarcraft.minecraftserverlauncher.server.servertypes.ServerType;
|
||||||
|
|
||||||
@ -76,7 +76,7 @@ public class ServerTab implements ActionListener {
|
|||||||
sl_panel_3.putConstraint(SpringLayout.WEST, lblMaxRam, 6, SpringLayout.EAST, serverTypes);
|
sl_panel_3.putConstraint(SpringLayout.WEST, lblMaxRam, 6, SpringLayout.EAST, serverTypes);
|
||||||
panel.add(lblMaxRam);
|
panel.add(lblMaxRam);
|
||||||
|
|
||||||
maxRam = new JComboBox<>(Server.getRamList());
|
maxRam = new JComboBox<>(ServerHandler.getRamList());
|
||||||
sl_panel_3.putConstraint(SpringLayout.NORTH, maxRam, 0, SpringLayout.NORTH, serverTypes);
|
sl_panel_3.putConstraint(SpringLayout.NORTH, maxRam, 0, SpringLayout.NORTH, serverTypes);
|
||||||
sl_panel_3.putConstraint(SpringLayout.WEST, maxRam, 6, SpringLayout.EAST, lblMaxRam);
|
sl_panel_3.putConstraint(SpringLayout.WEST, maxRam, 6, SpringLayout.EAST, lblMaxRam);
|
||||||
sl_panel_3.putConstraint(SpringLayout.EAST, maxRam, -10, SpringLayout.EAST, panel);
|
sl_panel_3.putConstraint(SpringLayout.EAST, maxRam, -10, SpringLayout.EAST, panel);
|
||||||
|
@ -0,0 +1,264 @@
|
|||||||
|
package net.knarcraft.minecraftserverlauncher.utility;
|
||||||
|
|
||||||
|
import net.knarcraft.minecraftserverlauncher.Main;
|
||||||
|
import net.knarcraft.minecraftserverlauncher.profile.Collection;
|
||||||
|
import net.knarcraft.minecraftserverlauncher.server.Server;
|
||||||
|
import net.knarcraft.minecraftserverlauncher.userinterface.BackupGUI;
|
||||||
|
import net.knarcraft.minecraftserverlauncher.userinterface.GUI;
|
||||||
|
|
||||||
|
import java.io.File;
|
||||||
|
import java.io.FileInputStream;
|
||||||
|
import java.io.FileOutputStream;
|
||||||
|
import java.io.IOException;
|
||||||
|
import java.io.InputStream;
|
||||||
|
import java.io.OutputStream;
|
||||||
|
import java.nio.file.Files;
|
||||||
|
import java.nio.file.Path;
|
||||||
|
import java.util.ArrayList;
|
||||||
|
import java.util.Arrays;
|
||||||
|
import java.util.List;
|
||||||
|
import java.util.stream.Stream;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* A helper class for performing server backup
|
||||||
|
*/
|
||||||
|
public class BackupUtil {
|
||||||
|
|
||||||
|
private static boolean backupAborted;
|
||||||
|
private static boolean backupRunning = false;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Aborts the currently running backup
|
||||||
|
*/
|
||||||
|
public static void abortBackup() {
|
||||||
|
backupAborted = true;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Recursively copies a folder to another location
|
||||||
|
*
|
||||||
|
* @param source <p>The folder to copy</p>
|
||||||
|
* @param destination <p>Target destination</p>
|
||||||
|
* @param backupFileSize <p>The total file size of the backup in progress</p>
|
||||||
|
* @param alreadyCopied <p>The amount of bytes already copied</p>
|
||||||
|
* @throws IOException <p>If we can't start a file stream</p>
|
||||||
|
*/
|
||||||
|
private static long backupFolder(File source, File destination, long backupFileSize,
|
||||||
|
long alreadyCopied) throws IOException {
|
||||||
|
if (backupAborted) {
|
||||||
|
return 0L;
|
||||||
|
}
|
||||||
|
if (!source.isDirectory()) {
|
||||||
|
long copiedFileSize = copyFile(source, destination);
|
||||||
|
BackupGUI.updateProgress("Copying " + source + "\n to " + destination,
|
||||||
|
(int) ((alreadyCopied + copiedFileSize) * 100 / backupFileSize));
|
||||||
|
return copiedFileSize;
|
||||||
|
} else {
|
||||||
|
if (!destination.exists() && !destination.mkdir()) {
|
||||||
|
return 0L;
|
||||||
|
}
|
||||||
|
String[] files = source.list();
|
||||||
|
long copiedFilesSize = 0;
|
||||||
|
if (files != null) {
|
||||||
|
for (String file : files) {
|
||||||
|
File srcFile = new File(source, file);
|
||||||
|
File destinationFile = new File(destination, file);
|
||||||
|
copiedFilesSize += backupFolder(srcFile, destinationFile, backupFileSize,
|
||||||
|
alreadyCopied + copiedFilesSize);
|
||||||
|
BackupGUI.updateProgress("Copying " + source + "\n to " + destination,
|
||||||
|
(int) ((alreadyCopied + copiedFilesSize) * 100 / backupFileSize));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return copiedFilesSize;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Copies a file from one location to another
|
||||||
|
*
|
||||||
|
* @param source <p>The file to copy</p>
|
||||||
|
* @param destination <p>The location of the copied file</p>
|
||||||
|
* @throws IOException <p>If reading or writing fails</p>
|
||||||
|
*/
|
||||||
|
private static long copyFile(File source, File destination) throws IOException {
|
||||||
|
InputStream in = new FileInputStream(source);
|
||||||
|
OutputStream out = new FileOutputStream(destination);
|
||||||
|
byte[] buffer = new byte[1024];
|
||||||
|
int length;
|
||||||
|
while ((length = in.read(buffer)) > 0) {
|
||||||
|
out.write(buffer, 0, length);
|
||||||
|
}
|
||||||
|
in.close();
|
||||||
|
out.close();
|
||||||
|
return Files.size(source.toPath());
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Copies all server directories to a folder specified by the user
|
||||||
|
*
|
||||||
|
* @param gui <p>The GUI to use for informing the user</p>
|
||||||
|
*/
|
||||||
|
public static void backup(GUI gui) {
|
||||||
|
backupAborted = false;
|
||||||
|
if (backupRunning) {
|
||||||
|
gui.setStatus("A backup is already running");
|
||||||
|
return;
|
||||||
|
} else {
|
||||||
|
backupRunning = true;
|
||||||
|
}
|
||||||
|
|
||||||
|
//Get the folder to save the backed up files in
|
||||||
|
File path = gui.askForDirectory("Backup folder");
|
||||||
|
if (path == null || !path.isDirectory()) {
|
||||||
|
backupRunning = false;
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
gui.setStatus("Backup running...");
|
||||||
|
List<List<File>> serverFolders = getFoldersOfEnabledServers(path);
|
||||||
|
|
||||||
|
gui.setStatus("Calculating backup size...");
|
||||||
|
long backupFileSize = getFolderSize(gui, serverFolders);
|
||||||
|
|
||||||
|
long locationFreeSpace = path.getFreeSpace();
|
||||||
|
if (locationFreeSpace < (backupFileSize + 2048000000)) {
|
||||||
|
gui.setStatus("Not enough available space. " + (backupFileSize / 1000000) + "MB necessary, but only " +
|
||||||
|
(locationFreeSpace / 1000000) + "MB available");
|
||||||
|
backupRunning = false;
|
||||||
|
backupAborted = true;
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
gui.setStatus("Backing up " + (backupFileSize / 1000000) + "MB");
|
||||||
|
|
||||||
|
performBackup(gui, serverFolders, backupFileSize);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Performs the actual backup after checks have passed and necessary info is available
|
||||||
|
* @param gui <p>The GUI to use for informing the user</p>
|
||||||
|
* @param serverFolders <p>The folders of the servers to backup</p>
|
||||||
|
* @param backupFileSize <p>The total size of the folders to backup</p>
|
||||||
|
*/
|
||||||
|
private static void performBackup(GUI gui, List<List<File>> serverFolders, long backupFileSize) {
|
||||||
|
new BackupGUI();
|
||||||
|
BackupGUI.updateProgress("Backup starting...", 0);
|
||||||
|
long alreadyCopied = 0;
|
||||||
|
for (List<File> serverFolder : serverFolders) {
|
||||||
|
if (backupAborted || !backupRunning) {
|
||||||
|
gui.setStatus("Backup aborted");
|
||||||
|
backupRunning = false;
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
alreadyCopied = backupServerFiles(gui, serverFolder, backupFileSize, alreadyCopied);
|
||||||
|
}
|
||||||
|
backupRunning = false;
|
||||||
|
if (backupAborted) {
|
||||||
|
gui.setStatus("Backup aborted");
|
||||||
|
} else {
|
||||||
|
BackupGUI.destroy();
|
||||||
|
gui.setStatus("Backup finished");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Backs up the files for a single server
|
||||||
|
*
|
||||||
|
* @param gui <p>The GUI to use for informing the user</p>
|
||||||
|
* @param serverFolder <p>The server's input and output folders</p>
|
||||||
|
* @param backupFileSize <p>The total size of the files to backup</p>
|
||||||
|
* @param alreadyCopied <p>The amount of bytes already copied</p>
|
||||||
|
* @return <p>The new amount of bytes copied</p>
|
||||||
|
*/
|
||||||
|
private static long backupServerFiles(GUI gui, List<File> serverFolder, long backupFileSize, long alreadyCopied) {
|
||||||
|
File srcFolder = serverFolder.get(0);
|
||||||
|
File destinationFolder = serverFolder.get(1);
|
||||||
|
|
||||||
|
//Create child folders
|
||||||
|
if (!destinationFolder.exists() && !destinationFolder.mkdirs()) {
|
||||||
|
backupRunning = false;
|
||||||
|
gui.logError("Unable to create necessary sub-folder in the backup folder");
|
||||||
|
throw new IllegalArgumentException("Unable to create necessary sub-folder in the backup folder");
|
||||||
|
}
|
||||||
|
//Backup
|
||||||
|
try {
|
||||||
|
alreadyCopied += backupFolder(srcFolder, destinationFolder, backupFileSize, alreadyCopied);
|
||||||
|
} catch (IOException e) {
|
||||||
|
gui.showError("Backup caused an error: " + e.getMessage());
|
||||||
|
gui.logError(Arrays.toString(e.getStackTrace()));
|
||||||
|
BackupGUI.destroy();
|
||||||
|
backupRunning = false;
|
||||||
|
}
|
||||||
|
return alreadyCopied;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Gets the size of a list of folders
|
||||||
|
*
|
||||||
|
* @param gui <p>The GUI to write any errors to</p>
|
||||||
|
* @param serverFolders <p>The folder to find the size of</p>
|
||||||
|
* @return <p>The size of the given folders</p>
|
||||||
|
*/
|
||||||
|
private static long getFolderSize(GUI gui, List<List<File>> serverFolders) {
|
||||||
|
long folderSize = 0;
|
||||||
|
for (List<File> serverFolder : serverFolders) {
|
||||||
|
File srcFolder = serverFolder.get(0);
|
||||||
|
try (Stream<Path> walk = Files.walk(srcFolder.toPath())) {
|
||||||
|
folderSize += walk.filter(Files::isRegularFile).mapToLong(BackupUtil::getFileSize).sum();
|
||||||
|
} catch (IOException e) {
|
||||||
|
gui.setStatus(String.format("IO errors %s", e));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return folderSize;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Gets the input and output folders for enabled servers
|
||||||
|
*
|
||||||
|
* <p>The input folders are the folders to copy, while the output folders are the folders to write the backup to.
|
||||||
|
* Each list element contains a list of exactly two File items. The first one is the input folder, and the second
|
||||||
|
* one is the output folder</p>
|
||||||
|
*
|
||||||
|
* @param path <p>The path of the backup folder, as given by the user</p>
|
||||||
|
* @return <p>The folders to copy from/to</p>
|
||||||
|
*/
|
||||||
|
private static List<List<File>> getFoldersOfEnabledServers(File path) {
|
||||||
|
List<List<File>> serverFolders = new ArrayList<>();
|
||||||
|
|
||||||
|
//Get folders of servers to back up
|
||||||
|
List<Collection> collections = Main.getController().getCurrentProfile().getCollections();
|
||||||
|
for (Collection collection : collections) {
|
||||||
|
//Ignore disabled and invalid servers
|
||||||
|
if (collection.getServer().getPath().equals("") || !collection.getServer().isEnabled()) {
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
//Decide sub-folders
|
||||||
|
Server targetServer = collection.getServer();
|
||||||
|
String name = targetServer.getName();
|
||||||
|
File srcFolder = new File(targetServer.getPath());
|
||||||
|
File destinationFolder = new File(path, name);
|
||||||
|
|
||||||
|
List<File> serverFolder = new ArrayList<>();
|
||||||
|
serverFolder.add(srcFolder);
|
||||||
|
serverFolder.add(destinationFolder);
|
||||||
|
serverFolders.add(serverFolder);
|
||||||
|
}
|
||||||
|
return serverFolders;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Gets the size of a file given its path
|
||||||
|
*
|
||||||
|
* @param path <p>The path to a file</p>
|
||||||
|
* @return <p>The size of the file in bytes, or 0 if an exception is thrown</p>
|
||||||
|
*/
|
||||||
|
private static long getFileSize(Path path) {
|
||||||
|
try {
|
||||||
|
return Files.size(path);
|
||||||
|
} catch (IOException exception) {
|
||||||
|
System.out.printf("Failed to get size of %s%n%s", path, exception);
|
||||||
|
return 0L;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
@ -1,9 +1,6 @@
|
|||||||
package net.knarcraft.minecraftserverlauncher.utility;
|
package net.knarcraft.minecraftserverlauncher.utility;
|
||||||
|
|
||||||
import net.knarcraft.minecraftserverlauncher.Main;
|
import net.knarcraft.minecraftserverlauncher.Main;
|
||||||
import net.knarcraft.minecraftserverlauncher.profile.Collection;
|
|
||||||
import net.knarcraft.minecraftserverlauncher.server.Server;
|
|
||||||
import net.knarcraft.minecraftserverlauncher.userinterface.GUI;
|
|
||||||
import net.knarcraft.minecraftserverlauncher.userinterface.WebBrowser;
|
import net.knarcraft.minecraftserverlauncher.userinterface.WebBrowser;
|
||||||
|
|
||||||
import java.io.BufferedReader;
|
import java.io.BufferedReader;
|
||||||
@ -16,7 +13,6 @@ import java.io.FileWriter;
|
|||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
import java.io.InputStream;
|
import java.io.InputStream;
|
||||||
import java.io.InputStreamReader;
|
import java.io.InputStreamReader;
|
||||||
import java.io.OutputStream;
|
|
||||||
import java.io.OutputStreamWriter;
|
import java.io.OutputStreamWriter;
|
||||||
import java.net.URI;
|
import java.net.URI;
|
||||||
import java.net.URISyntaxException;
|
import java.net.URISyntaxException;
|
||||||
@ -53,7 +49,7 @@ public final class CommonFunctions {
|
|||||||
* @param folder <p>The folder to create</p>
|
* @param folder <p>The folder to create</p>
|
||||||
* @throws FileNotFoundException <p>If unable to create the folder</p>
|
* @throws FileNotFoundException <p>If unable to create the folder</p>
|
||||||
*/
|
*/
|
||||||
protected static void createFolder(File folder) throws FileNotFoundException {
|
public static void createFolder(File folder) throws FileNotFoundException {
|
||||||
if (!folder.exists()) {
|
if (!folder.exists()) {
|
||||||
if (!folder.mkdirs()) {
|
if (!folder.mkdirs()) {
|
||||||
throw new FileNotFoundException("Cannot create necessary directory.");
|
throw new FileNotFoundException("Cannot create necessary directory.");
|
||||||
@ -158,7 +154,7 @@ public final class CommonFunctions {
|
|||||||
* @throws IOException <p>If unable to write to the file</p>
|
* @throws IOException <p>If unable to write to the file</p>
|
||||||
*/
|
*/
|
||||||
public static void writeFile(String path, String text) throws IOException {
|
public static void writeFile(String path, String text) throws IOException {
|
||||||
writeFile(path, text, true);
|
writeFile(path, text, !text.equals(""));
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -210,55 +206,6 @@ public final class CommonFunctions {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* Recursively copies a folder to another location
|
|
||||||
*
|
|
||||||
* @param source <p>The folder to copy</p>
|
|
||||||
* @param destination <p>Target destination</p>
|
|
||||||
* @throws IOException <p>If we can't start a file stream</p>
|
|
||||||
*/
|
|
||||||
private static void copyFolder(GUI serverLauncherGui, File source, File destination) throws IOException {
|
|
||||||
if (!source.isDirectory()) {
|
|
||||||
copyFile(serverLauncherGui, source, destination);
|
|
||||||
} else {
|
|
||||||
serverLauncherGui.setStatus("Copying directory " + source);
|
|
||||||
if (!destination.exists() && !destination.mkdir()) {
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
String[] files = source.list();
|
|
||||||
if (files != null) {
|
|
||||||
for (String file : files) {
|
|
||||||
File srcFile = new File(source, file);
|
|
||||||
File destinationFile = new File(destination, file);
|
|
||||||
copyFolder(serverLauncherGui, srcFile, destinationFile);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
serverLauncherGui.setStatus("Copied directory " + source);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Copies a file from one location to another
|
|
||||||
*
|
|
||||||
* @param serverLauncherGui <p>The serverLauncherGui to use for alerting the user</p>
|
|
||||||
* @param source <p>The file to copy</p>
|
|
||||||
* @param destination <p>The location of the copied file</p>
|
|
||||||
* @throws IOException <p>If reading or writing fails</p>
|
|
||||||
*/
|
|
||||||
private static void copyFile(GUI serverLauncherGui, File source, File destination) throws IOException {
|
|
||||||
serverLauncherGui.setStatus("Copying file " + source + "...");
|
|
||||||
InputStream in = new FileInputStream(source);
|
|
||||||
OutputStream out = new FileOutputStream(destination);
|
|
||||||
byte[] buffer = new byte[1024];
|
|
||||||
int length;
|
|
||||||
while ((length = in.read(buffer)) > 0) {
|
|
||||||
out.write(buffer, 0, length);
|
|
||||||
}
|
|
||||||
in.close();
|
|
||||||
out.close();
|
|
||||||
serverLauncherGui.setStatus("Copied file " + source);
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Opens an url in the user's default application.
|
* Opens an url in the user's default application.
|
||||||
*
|
*
|
||||||
@ -295,34 +242,7 @@ public final class CommonFunctions {
|
|||||||
return text.toString().trim();
|
return text.toString().trim();
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* Copies all server directories to a folder specified by the user.
|
|
||||||
*/
|
|
||||||
public static void backup(GUI gui) {
|
|
||||||
File path = gui.askForDirectory("Backup folder");
|
|
||||||
for (Collection collection : Main.getController().getCurrentProfile().getCollections()) {
|
|
||||||
//Ignore disabled and invalid servers
|
|
||||||
if (collection.getServer().getPath().equals("") || !collection.getServer().isEnabled()) {
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
//Decide sub-folders
|
|
||||||
Server targetServer = collection.getServer();
|
|
||||||
String name = targetServer.getName();
|
|
||||||
File srcFolder = new File(targetServer.getPath());
|
|
||||||
File destinationFolder = new File(path, name);
|
|
||||||
//Create child folders
|
|
||||||
if (!destinationFolder.exists() && !destinationFolder.mkdirs()) {
|
|
||||||
throw new IllegalArgumentException("Unable to create necessary sub-folder in the backup folder");
|
|
||||||
}
|
|
||||||
//Backup
|
|
||||||
try {
|
|
||||||
CommonFunctions.copyFolder(gui, srcFolder, destinationFolder);
|
|
||||||
} catch (IOException e) {
|
|
||||||
e.printStackTrace();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
gui.setStatus("Backup finished");
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Validates that a name is not empty and does not contain invalid characters
|
* Validates that a name is not empty and does not contain invalid characters
|
||||||
@ -331,7 +251,7 @@ public final class CommonFunctions {
|
|||||||
* @return <p>True if the name is valid</p>
|
* @return <p>True if the name is valid</p>
|
||||||
*/
|
*/
|
||||||
public static boolean nameIsValid(String name) {
|
public static boolean nameIsValid(String name) {
|
||||||
return !name.equals("") && name.matches("[^!?;,]+");
|
return name != null && !name.equals("") && name.matches("[^!?;,]+");
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -29,13 +29,12 @@ public final class Updater {
|
|||||||
private static final String targetFile = "minecraft-server-launcher.jar";
|
private static final String targetFile = "minecraft-server-launcher.jar";
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Checks if a newer version is available
|
* Gets the version channel and version of this software instance
|
||||||
*
|
*
|
||||||
* @param updateURL <p>The URL used for checking for updates</p>
|
* @return <p>An array of Channel, Version</p>
|
||||||
* @param updateChannel <p>The release channel to use</p>
|
* @throws FileNotFoundException <p>If unable to find or read currentversion.csv</p>
|
||||||
* @throws IOException <p>If the update data cannot be read</p>
|
|
||||||
*/
|
*/
|
||||||
public static void checkForUpdate(String updateURL, String updateChannel) throws IOException {
|
public static String[] getCurrentVersion() throws FileNotFoundException {
|
||||||
Scanner file = getResourceAsScanner("currentversion.csv");
|
Scanner file = getResourceAsScanner("currentversion.csv");
|
||||||
if (!file.hasNextLine()) {
|
if (!file.hasNextLine()) {
|
||||||
throw new FileNotFoundException("File currentversion.csv is invalid");
|
throw new FileNotFoundException("File currentversion.csv is invalid");
|
||||||
@ -46,6 +45,20 @@ public final class Updater {
|
|||||||
}
|
}
|
||||||
String oldVer = file.nextLine();
|
String oldVer = file.nextLine();
|
||||||
file.close();
|
file.close();
|
||||||
|
return new String[]{oldType, oldVer};
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Checks if a newer version is available
|
||||||
|
*
|
||||||
|
* @param updateURL <p>The URL used for checking for updates</p>
|
||||||
|
* @param updateChannel <p>The release channel to use</p>
|
||||||
|
* @throws IOException <p>If the update data cannot be read</p>
|
||||||
|
*/
|
||||||
|
public static void checkForUpdate(String updateURL, String updateChannel) throws IOException {
|
||||||
|
String[] oldData = getCurrentVersion();
|
||||||
|
String oldType = oldData[0];
|
||||||
|
String oldVer = oldData[1];
|
||||||
|
|
||||||
String data = readRemoteFile(updateURL);
|
String data = readRemoteFile(updateURL);
|
||||||
JsonObject jsonObject = new JsonParser().parse(data).getAsJsonObject();
|
JsonObject jsonObject = new JsonParser().parse(data).getAsJsonObject();
|
||||||
|
@ -1,2 +1,2 @@
|
|||||||
beta
|
beta
|
||||||
1.3.2
|
1.4.0
|
|
@ -1,6 +1,6 @@
|
|||||||
Vanilla;Latest,Snapshot,1.17.1,1.16.5,1.15.2,1.14.4,1.13.2,1.12.2,1.11.2,1.10.2,1.9.4,1.8.9,1.7.10,1.6.4,1.5.2,1.4.7,1.3.2,1.2.5;https://launchermeta.mojang.com/mc/game/version_manifest.json;"release":";";https://s3.amazonaws.com/Minecraft.Download/versions/
|
Vanilla;Latest,Snapshot,1.17.1,1.16.5,1.15.2,1.14.4,1.13.2,1.12.2,1.11.2,1.10.2,1.9.4,1.8.9,1.7.10,1.6.4,1.5.2,1.4.7,1.3.2,1.2.5;https://launchermeta.mojang.com/mc/game/version_manifest.json;"release":";";https://s3.amazonaws.com/Minecraft.Download/versions/
|
||||||
Spigot;Latest,1.17.1,1.16.5,1.15.2,1.14.4,1.13.2,1.12.2,1.11.2,1.10.2,1.9.4,1.9.4,1.8.8,1.7.10,1.6.4-R2.1,1.5.2-R1.1,1.4.7-R1.1;https://static.knarcraft.net/archive/downloads/minecraftserverjars/Spigot/;spigot-
|
Spigot;Latest,1.17.1,1.16.5,1.15.2,1.14.4,1.13.2,1.12.2,1.11.2,1.10.2,1.9.4,1.9.4,1.8.8,1.7.10,1.6.4-R2.1,1.5.2-R1.1,1.4.7-R1.1;https://static.knarcraft.net/archive/downloads/minecraftserverjars/Spigot/;spigot-
|
||||||
Paper;1.17.1,1.16.5,1.15.2,1.14.4,1.13.2,1.12.2,1.11.2,1.10.2,1.9.4,1.8.8;https://static.knarcraft.net/archive/downloads/minecraftserverjars/Paper/;Paper-
|
Paper;1.17.1,1.16.5,1.15.2,1.14.4,1.13.2,1.12.2,1.11.2,1.10.2,1.9.4,1.8.8;https://papermc.io/api/v1/paper/;"latest":;,;https://papermc.io/api/v1/paper/
|
||||||
#SpongeVanilla;1.12.2,1.11.2,1.10.2,1.8.9;https://dl-api.spongepowered.org/v1/org.spongepowered/spongevanilla/downloads?type=stable&minecraft=;"version":";",;https://repo.spongepowered.org/maven/org/spongepowered/spongevanilla/;/spongevanilla-
|
#SpongeVanilla;1.12.2,1.11.2,1.10.2,1.8.9;https://dl-api.spongepowered.org/v1/org.spongepowered/spongevanilla/downloads?type=stable&minecraft=;"version":";",;https://repo.spongepowered.org/maven/org/spongepowered/spongevanilla/;/spongevanilla-
|
||||||
Craftbukkit;Latest,1.17.1,1.16.5,1.15.2,1.14.4,1.13.2,1.12.2,1.11.2,1.10.2,1.9.4,1.8.8,1.7.10-R0.1,1.6.4-R2.0,1.5.2-R1.0,1.4.6-R0.3,1.3.2-R3.0,1.2.5-R2.0,1.1-R6,1.0.1-R1,b1.8.1,b1.7.3;https://static.knarcraft.net/archive/downloads/minecraftserverjars/Bukkit/;craftbukkit-
|
Craftbukkit;Latest,1.17.1,1.16.5,1.15.2,1.14.4,1.13.2,1.12.2,1.11.2,1.10.2,1.9.4,1.8.8,1.7.10-R0.1,1.6.4-R2.0,1.5.2-R1.0,1.4.6-R0.3,1.3.2-R3.0,1.2.5-R2.0,1.1-R6,1.0.1-R1,b1.8.1,b1.7.3;https://static.knarcraft.net/archive/downloads/minecraftserverjars/Bukkit/;craftbukkit-
|
||||||
#SpongeForge;1.12.2,1.11.2,1.10.2;https://dl-api.spongepowered.org/v1/org.spongepowered/spongeforge/downloads?type=stable&minecraft=;"version":";",;https://repo.spongepowered.org/maven/org/spongepowered/spongeforge/;/spongeforge-
|
#SpongeForge;1.12.2,1.11.2,1.10.2;https://dl-api.spongepowered.org/v1/org.spongepowered/spongeforge/downloads?type=stable&minecraft=;"version":";",;https://repo.spongepowered.org/maven/org/spongepowered/spongeforge/;/spongeforge-
|
||||||
|
Can't render this file because it contains an unexpected character in line 1 and column 200.
|
@ -11,7 +11,7 @@ public class ServerTest {
|
|||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void fromStringTest() throws ConfigurationException {
|
public void fromStringTest() throws ConfigurationException {
|
||||||
Server server = Server.fromString("asd;/home/;false;Bukkit;1.10.2;4G;");
|
Server server = ServerHandler.fromString("asd;/home/;false;Bukkit;1.10.2;4G;");
|
||||||
assertEquals("asd", server.getName());
|
assertEquals("asd", server.getName());
|
||||||
assertEquals("/home/", server.getPath());
|
assertEquals("/home/", server.getPath());
|
||||||
assertFalse(server.isEnabled());
|
assertFalse(server.isEnabled());
|
||||||
|
@ -38,7 +38,7 @@ public class ServerVersionContainerTest {
|
|||||||
serverVersionContainer.reset();
|
serverVersionContainer.reset();
|
||||||
System.out.println(serverVersionContainer.toString());
|
System.out.println(serverVersionContainer.toString());
|
||||||
assertEquals("vanillaVersion;null\nsnapshotVersion;null\nbungeeVersion;null\nwaterfallVersions;\n" +
|
assertEquals("vanillaVersion;null\nsnapshotVersion;null\nbungeeVersion;null\nwaterfallVersions;\n" +
|
||||||
"travertineVersions;\nspongeVanillaVersions;\nspongeForgeVersions;\ndownloadedBuildToolsVersion;null",
|
"travertineVersions;\npaperVersions;\nspongeVanillaVersions;\nspongeForgeVersions;\ndownloadedBuildToolsVersion;null",
|
||||||
serverVersionContainer.toString());
|
serverVersionContainer.toString());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user