Add support for custom server jars

This commit is contained in:
Norbi Peti 2019-08-22 16:07:32 +02:00
parent 2dac8eb9f5
commit 8310e0889b
No known key found for this signature in database
GPG key ID: DBA4C4549A927E56
11 changed files with 361 additions and 284 deletions

2
.idea/.gitignore vendored Normal file
View file

@ -0,0 +1,2 @@
# Default ignored files
/workspace.xml

View file

@ -0,0 +1,15 @@
<?xml version="1.0" encoding="UTF-8"?>
<module org.jetbrains.idea.maven.project.MavenProjectsManager.isMavenModule="true" type="JAVA_MODULE" version="4">
<component name="NewModuleRootManager" LANGUAGE_LEVEL="JDK_1_8">
<output url="file://$MODULE_DIR$/target/classes" />
<output-test url="file://$MODULE_DIR$/target/test-classes" />
<content url="file://$MODULE_DIR$">
<sourceFolder url="file://$MODULE_DIR$/src" isTestSource="false" />
<excludeFolder url="file://$MODULE_DIR$/target" />
</content>
<orderEntry type="inheritedJdk" />
<orderEntry type="sourceFolder" forTests="false" />
<orderEntry type="library" name="Maven: jline:jline:2.12" level="project" />
<orderEntry type="library" name="Maven: org.yaml:snakeyaml:1.21" level="project" />
</component>
</module>

4
.idea/encodings.xml Normal file
View file

@ -0,0 +1,4 @@
<?xml version="1.0" encoding="UTF-8"?>
<project version="4">
<component name="Encoding" addBOMForNewFiles="with NO BOM" />
</project>

View file

@ -0,0 +1,11 @@
<component name="InspectionProjectProfileManager">
<profile version="1.0">
<option name="myName" value="Project Default" />
<inspection_tool class="WeakerAccess" enabled="true" level="WARNING" enabled_by_default="true">
<option name="SUGGEST_PACKAGE_LOCAL_FOR_MEMBERS" value="false" />
<option name="SUGGEST_PACKAGE_LOCAL_FOR_TOP_CLASSES" value="false" />
<option name="SUGGEST_PRIVATE_FOR_INNERS" value="false" />
<disabledExtension id="moduleInfo" />
</inspection_tool>
</profile>
</component>

View file

@ -0,0 +1,13 @@
<component name="libraryTable">
<library name="Maven: org.yaml:snakeyaml:1.21">
<CLASSES>
<root url="jar://$MAVEN_REPOSITORY$/org/yaml/snakeyaml/1.21/snakeyaml-1.21.jar!/" />
</CLASSES>
<JAVADOC>
<root url="jar://$MAVEN_REPOSITORY$/org/yaml/snakeyaml/1.21/snakeyaml-1.21-javadoc.jar!/" />
</JAVADOC>
<SOURCES>
<root url="jar://$MAVEN_REPOSITORY$/org/yaml/snakeyaml/1.21/snakeyaml-1.21-sources.jar!/" />
</SOURCES>
</library>
</component>

View file

@ -0,0 +1,3 @@
<component name="MarkdownNavigator.ProfileManager">
<settings default="" pdf-export="" />
</component>

8
.idea/modules.xml Normal file
View file

@ -0,0 +1,8 @@
<?xml version="1.0" encoding="UTF-8"?>
<project version="4">
<component name="ProjectModuleManager">
<modules>
<module fileurl="file://$PROJECT_DIR$/MCServerRunner.iml" filepath="$PROJECT_DIR$/MCServerRunner.iml" />
</modules>
</component>
</project>

15
MCServerRunner.iml Normal file
View file

@ -0,0 +1,15 @@
<?xml version="1.0" encoding="UTF-8"?>
<module org.jetbrains.idea.maven.project.MavenProjectsManager.isMavenModule="true" type="JAVA_MODULE" version="4">
<component name="NewModuleRootManager" LANGUAGE_LEVEL="JDK_1_8">
<output url="file://$MODULE_DIR$/target/classes" />
<output-test url="file://$MODULE_DIR$/target/test-classes" />
<content url="file://$MODULE_DIR$">
<sourceFolder url="file://$MODULE_DIR$/src" isTestSource="false" />
<excludeFolder url="file://$MODULE_DIR$/target" />
</content>
<orderEntry type="inheritedJdk" />
<orderEntry type="sourceFolder" forTests="false" />
<orderEntry type="library" name="Maven: jline:jline:2.12" level="project" />
<orderEntry type="library" name="Maven: org.yaml:snakeyaml:1.21" level="project" />
</component>
</module>

View file

@ -6,6 +6,7 @@
<version>0.0.1-SNAPSHOT</version>
<build>
<sourceDirectory>src</sourceDirectory>
<finalName>ServerRunner</finalName>
<plugins>
<plugin>
<artifactId>maven-compiler-plugin</artifactId>

View file

@ -4,6 +4,7 @@ public class Config {
public String serverVersion;
public String serverParams;
public int restartAt;
public String customJar;
public Config(String serverVersion, String serverParams, int restartAt) {
this.serverVersion = serverVersion;
@ -14,5 +15,6 @@ public class Config {
this.serverVersion = "1.12.2";
this.serverParams = "-Djline.terminal=jline.UnixTerminal -Xms4G -Xmx6G";
this.restartAt = 12;
this.customJar = "";
}
}

View file

@ -36,7 +36,10 @@ public class ServerRunner {
Files.write(f.toPath(), Collections.singleton(yaml.dump(config = new Config())));
else
config = yaml.load(new FileInputStream(f));
if (!new File("spigot-" + config.serverVersion + ".jar").exists()) {
final File serverJar = new File(config.customJar == null || config.customJar.length() == 0
? "spigot-" + config.serverVersion + ".jar"
: config.customJar);
if (!serverJar.exists()) {
System.out.println("The server JAR for " + config.serverVersion + " cannot be found!");
return;
}
@ -44,7 +47,7 @@ public class ServerRunner {
reader.setPrompt("Runner>");
runnerout = new PrintWriter(reader.getOutput());
writeToScreen("Starting server...");
serverprocess = startServer(config);
serverprocess = startServer(config, serverJar);
serveroutput = new PrintWriter(serverprocess.getOutputStream());
rt = Thread.currentThread();
final Thread it = new Thread() {
@ -104,7 +107,7 @@ public class ServerRunner {
e.printStackTrace();
}
writeToScreen("Server stopped! Restarting...");
serverprocess = startServer(config);
serverprocess = startServer(config, serverJar);
serverinput = new BufferedReader(new InputStreamReader(serverprocess.getInputStream()));
serveroutput = new PrintWriter(serverprocess.getOutputStream());
restartcounter = RESTART_MESSAGE_COUNT;
@ -166,8 +169,8 @@ public class ServerRunner {
writeToScreen("Stopped " + Thread.currentThread().getName());
}
private static Process startServer(Config config) throws IOException {
return Runtime.getRuntime().exec(("java "+config.serverParams+" -jar spigot-" + config.serverVersion + ".jar").split(" "));
private static Process startServer(Config config, File serverJar) throws IOException {
return Runtime.getRuntime().exec(new String[]{"java", config.serverParams, "-jar", serverJar.getPath()});
}
private static void sendMessage(PrintWriter output, String color, String text) {