11 Commits

Author SHA1 Message Date
365d08f2e2 Changes download URLs of Paper to papermc.io
All checks were successful
KnarCraft/Minecraft-Server-Launcher/pipeline/head This commit looks good
Updates software version
Stores version of downloaded Paper .jar files
Completes #8
2021-08-23 14:53:39 +02:00
9d8531535d Updates software version to 1.3.4
All checks were successful
KnarCraft/Minecraft-Server-Launcher/pipeline/head This commit looks good
2021-08-21 15:28:28 +02:00
30de4b2139 Clarifies an error message 2021-08-21 14:01:22 +02:00
133e335905 Fixes a bug causing the software to be stuck in the Stopping Servers state
Fixes the case where the software tries to stop servers while no servers are actually running.
This also fixes #10
2021-08-21 13:53:41 +02:00
44d8d6ee6b Extracts a ServerHandler from the Server class to reduce complexity 2021-08-21 13:43:27 +02:00
cd396eee6b Fixes a NullPointerException caused by cancelling an input prompt 2021-08-21 13:09:18 +02:00
c67f3bdd2c Closes issue #9
All checks were successful
KnarCraft/Minecraft-Server-Launcher/pipeline/head This commit looks good
Adds a catch to prevent the software from crashing when checking for an update fails
2021-08-17 19:42:18 +02:00
8476c78589 Makes sure never to add a newline when writing an empty string to a file 2021-08-17 19:32:47 +02:00
a79300732d Splits the code for reading the software version into its own function 2021-08-17 19:32:11 +02:00
b6baa9ad6f Updates software version to 1.3.3
All checks were successful
KnarCraft/Minecraft-Server-Launcher/pipeline/head This commit looks good
2021-08-17 01:08:14 +02:00
c2f12a1a49 Adds the underscore character to regexes for player detection
This fixes a bug where players with underscores in their names won't be added to the player list
2021-08-17 01:07:20 +02:00
16 changed files with 297 additions and 170 deletions

View File

@ -2,7 +2,7 @@ package net.knarcraft.minecraftserverlauncher;
import net.knarcraft.minecraftserverlauncher.profile.Collection;
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.ServerLauncherGUI;
import net.knarcraft.minecraftserverlauncher.utility.CommonFunctions;
@ -21,7 +21,7 @@ import java.util.concurrent.TimeUnit;
* A software for managing Minecraft servers.
*
* @author Kristian Knarvik <kristian.knarvik@knett.no>
* @version 1.0.0
* @version b1.3.4
* @since 1.0.0
*/
@ -34,8 +34,14 @@ public class Main {
private static ServerLauncherGUI gui;
public static void main(String[] args) throws IOException {
Updater.checkForUpdate(updateURL, updateChannel);
CommonFunctions.writeFile(Main.getApplicationWorkDirectory() + File.separator + "latestrun.log", "");
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);
} catch (IOException e) {
CommonFunctions.appendFile(logFile, "[Warning]: Unable to complete update procedure: " + e.getMessage());
}
EventQueue.invokeLater(() -> {
try {
ServerConsoles.instantiate();
@ -82,7 +88,7 @@ public class Main {
boolean runningNew = serversRunning();
if (serversAreRunning && !runningNew) {
//Servers stopped running
Server.serversStopped();
ServerHandler.serversStopped();
gui.updateGUIElementsWhenServersStartOrStop(false);
gui.setStatus("Servers are stopped");
} else if (!serversAreRunning && runningNew) {

View File

@ -2,6 +2,7 @@ package net.knarcraft.minecraftserverlauncher.profile;
import net.knarcraft.minecraftserverlauncher.Main;
import net.knarcraft.minecraftserverlauncher.server.Server;
import net.knarcraft.minecraftserverlauncher.server.ServerHandler;
import net.knarcraft.minecraftserverlauncher.userinterface.ServerConsoles;
import net.knarcraft.minecraftserverlauncher.userinterface.ServerLauncherGUI;
import net.knarcraft.minecraftserverlauncher.utility.CommonFunctions;
@ -239,10 +240,10 @@ public class Profile {
if (data[1].contains("!")) {
String[] servers = data[1].split("!", -1);
for (String server : servers) {
profile.collections.add(new Collection(Server.fromString(server)));
profile.collections.add(new Collection(ServerHandler.fromString(server)));
}
} else {
profile.collections.add(new Collection(Server.fromString(data[1])));
profile.collections.add(new Collection(ServerHandler.fromString(data[1])));
}
} else {
profile = parseProfile(profileString.split(";", -1));

View File

@ -2,6 +2,7 @@ package net.knarcraft.minecraftserverlauncher.profile;
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.userinterface.ServerLauncherGUI;
import net.knarcraft.minecraftserverlauncher.userinterface.ServerTab;
@ -392,7 +393,7 @@ public class ServerLauncherController {
});
}
if (this.currentProfile.getRunInBackground()) {
Executors.newSingleThreadExecutor().execute(Server::startServers);
Executors.newSingleThreadExecutor().execute(ServerHandler::startServers);
this.serverLauncherGUI.hideToTray();
}
}

View File

@ -1,9 +1,9 @@
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.server.servertypes.ServerType;
import net.knarcraft.minecraftserverlauncher.userinterface.ServerLauncherGUI;
import net.knarcraft.minecraftserverlauncher.utility.CommonFunctions;
import javax.naming.ConfigurationException;
@ -31,14 +31,9 @@ import java.util.regex.Pattern;
* @since 1.0.0
*/
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" +
File.separator + "Jars" + File.separator;
private final String name;
private final ArrayList<String> playerList;
private String path;
@ -51,7 +46,7 @@ public class Server {
private BufferedReader reader;
private boolean started;
private ScheduledExecutorService consoleOutputExecutor;
private static boolean stoppingServers = false;
private final ServerLauncherGUI gui = Main.getController().getGUI();
/**
* Initializes a new server with default values
@ -65,7 +60,7 @@ public class Server {
this.playerList = new ArrayList<>();
this.type = null;
this.serverVersion = "";
this.maxRam = ramList[0];
this.maxRam = ServerHandler.getRamList()[0];
this.process = null;
this.writer = null;
this.reader = null;
@ -91,15 +86,6 @@ public class Server {
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
*
@ -109,101 +95,6 @@ public class Server {
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
*
@ -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
*
@ -374,7 +301,7 @@ public class Server {
*/
private void addPlayer(String 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) {
playerList.removeIf(player -> player.equals(name));
Main.getController().getGUI().getServerControlTab().removePlayer(name);
gui.getServerControlTab().removePlayer(name);
}
/**
@ -401,8 +328,9 @@ public class Server {
*
* @return <p>True if nothing went wrong</p>
*/
private boolean runServer(boolean isFirstServer) {
if (stoppingServers) {
public boolean runServer(boolean isFirstServer) {
if (ServerHandler.stoppingServers()) {
gui.logMessage("Stopping servers. Cannot start yet.");
return false;
}
//Ignore a disabled server
@ -412,20 +340,21 @@ public class Server {
}
//Tries to do necessary pre-start work
if (!initializeJarDownload() || (!isFirstServer && !delayStartup())) {
gui.logError("Failed to perform startup tasks.");
this.started = false;
return false;
}
if (stoppingServers) {
if (ServerHandler.stoppingServers()) {
return false;
}
//Starts the server if possible
try {
startServerProcess();
Main.getController().getGUI().setStatus("Servers are running");
gui.setStatus("Servers are running");
this.started = true;
return true;
} catch (IOException e) {
Main.getController().getGUI().setStatus("Could not start server");
gui.setStatus("Could not start server");
this.started = false;
return false;
}
@ -529,11 +458,11 @@ public class Server {
private String getPlayer(String text, boolean joined) {
String playerName;
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 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 logoutPattern1 = "INFO]: ([A-Z0-9a-z]+) lost connection";
String logoutPattern2 = " ([A-Z0-9a-z]+) left the game";
String logoutPattern1 = "INFO]: ([A-Z0-9a-z_]+) lost connection";
String logoutPattern2 = " ([A-Z0-9a-z_]+) left the game";
if (joined) {
playerName = getFirstRegexCaptureGroup(loginPattern1, text);
@ -573,7 +502,7 @@ public class Server {
*/
private boolean delayStartup() {
try {
Main.getController().getGUI().setStatus("Delaying startup");
gui.setStatus("Delaying startup");
TimeUnit.SECONDS.sleep(Main.getController().getCurrentProfile().getDelayStartup());
return true;
} catch (InterruptedException e) {
@ -589,18 +518,15 @@ public class Server {
* @return <p>True if nothing went wrong</p>
*/
private boolean initializeJarDownload() {
ServerLauncherController controller = Main.getController();
if (!controller.getDownloadAllJars()) {
try {
controller.getGUI().setStatus("Downloading jar...");
this.downloadJar();
controller.getGUI().setStatus("File downloaded");
} catch (IOException e) {
controller.getGUI().setStatus("Error: Jar file not found");
e.printStackTrace();
this.started = false;
return false;
}
try {
gui.setStatus("Downloading jar...");
this.downloadJar();
gui.setStatus("File downloaded");
} catch (IOException e) {
gui.setStatus("Error: Jar file could not be found, downloaded or built.");
gui.logError("Unable to get required .jar file: " + e.getMessage());
this.started = false;
return false;
}
return true;
}

View File

@ -0,0 +1,146 @@
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");
int serverNum = 0;
for (Collection collection : controller.getCurrentProfile().getCollections()) {
if (!collection.getServer().runServer(serverNum++ == 0)) {
gui.showError("An error occurred. Start aborted. Please check relevant log files.");
try {
stop();
} catch (IOException | InterruptedException e) {
e.printStackTrace();
}
gui.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]);
}
}

View File

@ -134,7 +134,7 @@ public class ServerTypeHandler {
break;
case "Paper":
newType = new Paper("Paper", false, serverVersions, serverTypeInfo[2],
serverTypeInfo[3]);
serverTypeInfo[3], serverTypeInfo[4], serverTypeInfo[5]);
break;
case "Bungee":
newType = new BungeeCord("Bungee", true, serverVersions, serverTypeInfo[2],

View File

@ -22,6 +22,7 @@ public class ServerVersionContainer {
private String bungeeVersion;
private Map<String, String> waterfallVersions;
private Map<String, String> travertineVersions;
private Map<String, String> paperVersions;
private Map<String, String> spongeVanillaVersions;
private Map<String, String> spongeForgeVersions;
private String downloadedBuildToolsVersion;
@ -32,6 +33,7 @@ public class ServerVersionContainer {
private ServerVersionContainer() {
this.waterfallVersions = new HashMap<>();
this.travertineVersions = new HashMap<>();
this.paperVersions = new HashMap<>();
this.spongeVanillaVersions = new HashMap<>();
this.spongeForgeVersions = new HashMap<>();
loadState();
@ -58,6 +60,7 @@ public class ServerVersionContainer {
this.bungeeVersion = null;
this.waterfallVersions = new HashMap<>();
this.travertineVersions = new HashMap<>();
this.paperVersions = new HashMap<>();
this.spongeVanillaVersions = new HashMap<>();
this.spongeForgeVersions = new HashMap<>();
this.downloadedBuildToolsVersion = null;
@ -70,6 +73,7 @@ public class ServerVersionContainer {
"bungeeVersion;" + bungeeVersion + "\n" +
"waterfallVersions;" + mapToString(waterfallVersions) + "\n" +
"travertineVersions;" + mapToString(travertineVersions) + "\n" +
"paperVersions;" + mapToString(paperVersions) + "\n" +
"spongeVanillaVersions;" + mapToString(spongeVanillaVersions) + "\n" +
"spongeForgeVersions;" + mapToString(spongeForgeVersions) + "\n" +
"downloadedBuildToolsVersion;" + downloadedBuildToolsVersion;
@ -163,6 +167,9 @@ public class ServerVersionContainer {
case "travertineVersions":
parseVersionsToMap(travertineVersions, variableValue);
break;
case "paperVersions":
parseVersionsToMap(paperVersions, variableValue);
break;
case "spongeVanillaVersions":
parseVersionsToMap(spongeVanillaVersions, variableValue);
break;
@ -291,6 +298,27 @@ public class ServerVersionContainer {
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
*

View File

@ -3,19 +3,25 @@ package net.knarcraft.minecraftserverlauncher.server.servertypes;
/**
* This class represents the Paper Minecraft server type
*/
public class Paper extends Spigot {
public class Paper extends Waterfall {
/**
* Instantiates a new Paper server type
*
* @param typeName <p>The name of the server type</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 downloadURL <p>The URL used for downloading .jar files</p>
* @param downloadURLPart <p>A string used after the download url as an additional part of the URL</p>
* @param typeName <p>The name of the server type</p>
* @param isProxy <p>Whether this server type is a proxy server</p>
* @param versions <p>The available versions for the server type</p>
* @param versionURL <p>The URL used to finding the newest version</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) {
super(typeName, isProxy, versions, downloadURL, downloadURLPart);
public Paper(String typeName, boolean isProxy, String[] versions, String versionURL, String srcStart,
String srcEnd, String downloadURL) {
super(typeName, isProxy, versions, versionURL, srcStart, srcEnd, downloadURL);
this.oldVersionFunction = serverVersionContainer::getPaperVersion;
this.versionUpdateFunction = serverVersionContainer::setPaperVersion;
}
}

View File

@ -3,7 +3,7 @@ package net.knarcraft.minecraftserverlauncher.userinterface;
import net.knarcraft.minecraftserverlauncher.Main;
import net.knarcraft.minecraftserverlauncher.profile.Collection;
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 javax.imageio.ImageIO;
@ -327,7 +327,7 @@ public class ServerLauncherGUI extends MessageHandler implements ActionListener,
private void handleMainTabButtons(Object actionSource) {
if (actionSource == startServerButton) {
controller.saveState();
Executors.newSingleThreadExecutor().execute(Server::startServers);
Executors.newSingleThreadExecutor().execute(ServerHandler::startServers);
} else if (actionSource == stopServerButton) {
stopServers();
} else if (actionSource == addServerButton) {
@ -404,7 +404,7 @@ public class ServerLauncherGUI extends MessageHandler implements ActionListener,
public void stopServers() {
try {
setStatus("Servers are stopping...");
Server.stop();
ServerHandler.stop();
} catch (IOException e1) {
showError("Could not stop server.");
e1.printStackTrace();

View File

@ -1,7 +1,7 @@
package net.knarcraft.minecraftserverlauncher.userinterface;
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.servertypes.ServerType;
@ -76,7 +76,7 @@ public class ServerTab implements ActionListener {
sl_panel_3.putConstraint(SpringLayout.WEST, lblMaxRam, 6, SpringLayout.EAST, serverTypes);
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.WEST, maxRam, 6, SpringLayout.EAST, lblMaxRam);
sl_panel_3.putConstraint(SpringLayout.EAST, maxRam, -10, SpringLayout.EAST, panel);

View File

@ -158,7 +158,7 @@ public final class CommonFunctions {
* @throws IOException <p>If unable to write to the file</p>
*/
public static void writeFile(String path, String text) throws IOException {
writeFile(path, text, true);
writeFile(path, text, !text.equals(""));
}
/**
@ -331,7 +331,7 @@ public final class CommonFunctions {
* @return <p>True if the name is valid</p>
*/
public static boolean nameIsValid(String name) {
return !name.equals("") && name.matches("[^!?;,]+");
return name != null && !name.equals("") && name.matches("[^!?;,]+");
}
/**

View File

@ -29,13 +29,12 @@ public final class Updater {
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>
* @param updateChannel <p>The release channel to use</p>
* @throws IOException <p>If the update data cannot be read</p>
* @return <p>An array of Channel, Version</p>
* @throws FileNotFoundException <p>If unable to find or read currentversion.csv</p>
*/
public static void checkForUpdate(String updateURL, String updateChannel) throws IOException {
public static String[] getCurrentVersion() throws FileNotFoundException {
Scanner file = getResourceAsScanner("currentversion.csv");
if (!file.hasNextLine()) {
throw new FileNotFoundException("File currentversion.csv is invalid");
@ -46,6 +45,20 @@ public final class Updater {
}
String oldVer = file.nextLine();
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);
JsonObject jsonObject = new JsonParser().parse(data).getAsJsonObject();

View File

@ -1,2 +1,2 @@
beta
1.3.2
1.3.5
1 beta
2 1.3.2 1.3.5

View File

@ -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/
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-
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-

Can't render this file because it contains an unexpected character in line 1 and column 200.

View File

@ -11,7 +11,7 @@ public class ServerTest {
@Test
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("/home/", server.getPath());
assertFalse(server.isEnabled());

View File

@ -38,7 +38,7 @@ public class ServerVersionContainerTest {
serverVersionContainer.reset();
System.out.println(serverVersionContainer.toString());
assertEquals("vanillaVersion;null\nsnapshotVersion;null\nbungeeVersion;null\nwaterfallVersions;\n" +
"travertineVersions;\nspongeVanillaVersions;\nspongeForgeVersions;\ndownloadedBuildToolsVersion;null",
"travertineVersions;\npaperVersions;\nspongeVanillaVersions;\nspongeForgeVersions;\ndownloadedBuildToolsVersion;null",
serverVersionContainer.toString());
}