Add support for custom server jars
This commit is contained in:
parent
2dac8eb9f5
commit
8310e0889b
11 changed files with 361 additions and 284 deletions
2
.idea/.gitignore
vendored
Normal file
2
.idea/.gitignore
vendored
Normal file
|
@ -0,0 +1,2 @@
|
||||||
|
# Default ignored files
|
||||||
|
/workspace.xml
|
15
.idea/ButtonServerRunner.iml
Normal file
15
.idea/ButtonServerRunner.iml
Normal 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
4
.idea/encodings.xml
Normal file
|
@ -0,0 +1,4 @@
|
||||||
|
<?xml version="1.0" encoding="UTF-8"?>
|
||||||
|
<project version="4">
|
||||||
|
<component name="Encoding" addBOMForNewFiles="with NO BOM" />
|
||||||
|
</project>
|
11
.idea/inspectionProfiles/Project_Default.xml
Normal file
11
.idea/inspectionProfiles/Project_Default.xml
Normal 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>
|
13
.idea/libraries/Maven__org_yaml_snakeyaml_1_21.xml
Normal file
13
.idea/libraries/Maven__org_yaml_snakeyaml_1_21.xml
Normal 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>
|
3
.idea/markdown-navigator/profiles_settings.xml
Normal file
3
.idea/markdown-navigator/profiles_settings.xml
Normal file
|
@ -0,0 +1,3 @@
|
||||||
|
<component name="MarkdownNavigator.ProfileManager">
|
||||||
|
<settings default="" pdf-export="" />
|
||||||
|
</component>
|
8
.idea/modules.xml
Normal file
8
.idea/modules.xml
Normal 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
15
MCServerRunner.iml
Normal 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>
|
1
pom.xml
1
pom.xml
|
@ -6,6 +6,7 @@
|
||||||
<version>0.0.1-SNAPSHOT</version>
|
<version>0.0.1-SNAPSHOT</version>
|
||||||
<build>
|
<build>
|
||||||
<sourceDirectory>src</sourceDirectory>
|
<sourceDirectory>src</sourceDirectory>
|
||||||
|
<finalName>ServerRunner</finalName>
|
||||||
<plugins>
|
<plugins>
|
||||||
<plugin>
|
<plugin>
|
||||||
<artifactId>maven-compiler-plugin</artifactId>
|
<artifactId>maven-compiler-plugin</artifactId>
|
||||||
|
|
|
@ -4,6 +4,7 @@ public class Config {
|
||||||
public String serverVersion;
|
public String serverVersion;
|
||||||
public String serverParams;
|
public String serverParams;
|
||||||
public int restartAt;
|
public int restartAt;
|
||||||
|
public String customJar;
|
||||||
|
|
||||||
public Config(String serverVersion, String serverParams, int restartAt) {
|
public Config(String serverVersion, String serverParams, int restartAt) {
|
||||||
this.serverVersion = serverVersion;
|
this.serverVersion = serverVersion;
|
||||||
|
@ -14,5 +15,6 @@ public class Config {
|
||||||
this.serverVersion = "1.12.2";
|
this.serverVersion = "1.12.2";
|
||||||
this.serverParams = "-Djline.terminal=jline.UnixTerminal -Xms4G -Xmx6G";
|
this.serverParams = "-Djline.terminal=jline.UnixTerminal -Xms4G -Xmx6G";
|
||||||
this.restartAt = 12;
|
this.restartAt = 12;
|
||||||
|
this.customJar = "";
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -29,14 +29,17 @@ public class ServerRunner {
|
||||||
|
|
||||||
public static void main(String[] args) throws IOException {
|
public static void main(String[] args) throws IOException {
|
||||||
Yaml yaml = new Yaml();
|
Yaml yaml = new Yaml();
|
||||||
File f=new File("plugins/ServerRunner/config.yml");
|
File f = new File("plugins/ServerRunner/config.yml");
|
||||||
f.getParentFile().mkdirs();
|
f.getParentFile().mkdirs();
|
||||||
final Config config;
|
final Config config;
|
||||||
if(!f.exists())
|
if (!f.exists())
|
||||||
Files.write(f.toPath(), Collections.singleton(yaml.dump(config = new Config())));
|
Files.write(f.toPath(), Collections.singleton(yaml.dump(config = new Config())));
|
||||||
else
|
else
|
||||||
config=yaml.load(new FileInputStream(f));
|
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!");
|
System.out.println("The server JAR for " + config.serverVersion + " cannot be found!");
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
@ -44,7 +47,7 @@ public class ServerRunner {
|
||||||
reader.setPrompt("Runner>");
|
reader.setPrompt("Runner>");
|
||||||
runnerout = new PrintWriter(reader.getOutput());
|
runnerout = new PrintWriter(reader.getOutput());
|
||||||
writeToScreen("Starting server...");
|
writeToScreen("Starting server...");
|
||||||
serverprocess = startServer(config);
|
serverprocess = startServer(config, serverJar);
|
||||||
serveroutput = new PrintWriter(serverprocess.getOutputStream());
|
serveroutput = new PrintWriter(serverprocess.getOutputStream());
|
||||||
rt = Thread.currentThread();
|
rt = Thread.currentThread();
|
||||||
final Thread it = new Thread() {
|
final Thread it = new Thread() {
|
||||||
|
@ -104,7 +107,7 @@ public class ServerRunner {
|
||||||
e.printStackTrace();
|
e.printStackTrace();
|
||||||
}
|
}
|
||||||
writeToScreen("Server stopped! Restarting...");
|
writeToScreen("Server stopped! Restarting...");
|
||||||
serverprocess = startServer(config);
|
serverprocess = startServer(config, serverJar);
|
||||||
serverinput = new BufferedReader(new InputStreamReader(serverprocess.getInputStream()));
|
serverinput = new BufferedReader(new InputStreamReader(serverprocess.getInputStream()));
|
||||||
serveroutput = new PrintWriter(serverprocess.getOutputStream());
|
serveroutput = new PrintWriter(serverprocess.getOutputStream());
|
||||||
restartcounter = RESTART_MESSAGE_COUNT;
|
restartcounter = RESTART_MESSAGE_COUNT;
|
||||||
|
@ -166,8 +169,8 @@ public class ServerRunner {
|
||||||
writeToScreen("Stopped " + Thread.currentThread().getName());
|
writeToScreen("Stopped " + Thread.currentThread().getName());
|
||||||
}
|
}
|
||||||
|
|
||||||
private static Process startServer(Config config) throws IOException {
|
private static Process startServer(Config config, File serverJar) throws IOException {
|
||||||
return Runtime.getRuntime().exec(("java "+config.serverParams+" -jar spigot-" + config.serverVersion + ".jar").split(" "));
|
return Runtime.getRuntime().exec(new String[]{"java", config.serverParams, "-jar", serverJar.getPath()});
|
||||||
}
|
}
|
||||||
|
|
||||||
private static void sendMessage(PrintWriter output, String color, String text) {
|
private static void sendMessage(PrintWriter output, String color, String text) {
|
||||||
|
|
Loading…
Reference in a new issue