Compare commits
6 commits
Author | SHA1 | Date | |
---|---|---|---|
7b4471c606 | |||
3857c85bea | |||
9dcfd600c7 | |||
290aaca11d | |||
8310e0889b | |||
2dac8eb9f5 |
13 changed files with 390 additions and 282 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>
|
|
@ -6,11 +6,12 @@
|
||||||
<sourceOutputDir name="target/generated-sources/annotations" />
|
<sourceOutputDir name="target/generated-sources/annotations" />
|
||||||
<sourceTestOutputDir name="target/generated-test-sources/test-annotations" />
|
<sourceTestOutputDir name="target/generated-test-sources/test-annotations" />
|
||||||
<outputRelativeToContentRoot value="true" />
|
<outputRelativeToContentRoot value="true" />
|
||||||
<module name="ButtonServerRunner" />
|
<module name="MCServerRunner" />
|
||||||
</profile>
|
</profile>
|
||||||
</annotationProcessing>
|
</annotationProcessing>
|
||||||
<bytecodeTargetLevel>
|
<bytecodeTargetLevel>
|
||||||
<module name="ButtonServerRunner" target="1.8" />
|
<module name="ButtonServerRunner" target="1.8" />
|
||||||
|
<module name="MCServerRunner" target="1.8" />
|
||||||
</bytecodeTargetLevel>
|
</bytecodeTargetLevel>
|
||||||
</component>
|
</component>
|
||||||
</project>
|
</project>
|
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,4 +0,0 @@
|
||||||
# ButtonServerRunner
|
|
||||||
A Java console application that controls starting/stopping the server.
|
|
||||||
|
|
||||||
Replaced by a shell script at PluginConfigs / Server/run.sh and Server/start.sh
|
|
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 = "";
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,5 +1,6 @@
|
||||||
package buttondevteam.serverrunner;
|
package buttondevteam.serverrunner;
|
||||||
|
|
||||||
|
import jline.Terminal;
|
||||||
import jline.console.ConsoleReader;
|
import jline.console.ConsoleReader;
|
||||||
import jline.console.CursorBuffer;
|
import jline.console.CursorBuffer;
|
||||||
import org.yaml.snakeyaml.Yaml;
|
import org.yaml.snakeyaml.Yaml;
|
||||||
|
@ -24,6 +25,7 @@ public class ServerRunner {
|
||||||
private static volatile Thread rt;
|
private static volatile Thread rt;
|
||||||
private static volatile ConsoleReader reader;
|
private static volatile ConsoleReader reader;
|
||||||
private static volatile PrintWriter runnerout;
|
private static volatile PrintWriter runnerout;
|
||||||
|
private static volatile Thread it;
|
||||||
|
|
||||||
private static volatile boolean customrestartfailed = false;
|
private static volatile boolean customrestartfailed = false;
|
||||||
|
|
||||||
|
@ -36,7 +38,10 @@ public class ServerRunner {
|
||||||
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,21 +49,28 @@ 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() {
|
it = new Thread() {
|
||||||
@Override
|
@Override
|
||||||
public void run() {
|
public void run() {
|
||||||
try {
|
try {
|
||||||
String readLine;
|
String readLine;
|
||||||
while (!stop && (readLine = reader.readLine()) != null) {
|
while (!stop || serveroutput.) { //TODO: Store if stream got closed (enum for state)?
|
||||||
|
try {
|
||||||
|
if ((readLine = reader.readLine()) == null)
|
||||||
|
continue; //Keep going until we stop
|
||||||
if (readLine.equalsIgnoreCase("stop"))
|
if (readLine.equalsIgnoreCase("stop"))
|
||||||
ServerRunner.stop();
|
ServerRunner.stop();
|
||||||
serveroutput.println(readLine);
|
serveroutput.println(readLine);
|
||||||
serveroutput.flush();
|
serveroutput.flush();
|
||||||
|
} catch (Exception e) {
|
||||||
|
e.printStackTrace();
|
||||||
|
Thread.sleep(100); //Sleep a bit and keep going
|
||||||
}
|
}
|
||||||
} catch (IOException e) {
|
}
|
||||||
|
} catch (InterruptedException e) {
|
||||||
e.printStackTrace();
|
e.printStackTrace();
|
||||||
}
|
}
|
||||||
ServerRunner.stop();
|
ServerRunner.stop();
|
||||||
|
@ -97,7 +109,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;
|
||||||
|
@ -114,9 +126,32 @@ public class ServerRunner {
|
||||||
};
|
};
|
||||||
ot.setName("OutputThread");
|
ot.setName("OutputThread");
|
||||||
ot.start();
|
ot.start();
|
||||||
|
final Thread errt = new Thread() {
|
||||||
|
@Override
|
||||||
|
public void run() {
|
||||||
|
try {
|
||||||
|
BufferedReader serverinput = new BufferedReader(
|
||||||
|
new InputStreamReader(serverprocess.getErrorStream(), StandardCharsets.UTF_8));
|
||||||
|
String line;
|
||||||
|
while (true) {
|
||||||
|
if ((line = serverinput.readLine()) != null) {
|
||||||
|
writeToScreen(line);
|
||||||
|
} else if (stop)
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
serverinput.close();
|
||||||
|
} catch (IOException e) {
|
||||||
|
e.printStackTrace();
|
||||||
|
}
|
||||||
|
ServerRunner.stop();
|
||||||
|
writeToScreen("Stopped " + Thread.currentThread().getName());
|
||||||
|
}
|
||||||
|
};
|
||||||
|
errt.setName("ErrorThread");
|
||||||
|
errt.start();
|
||||||
Thread.currentThread().setName("RestarterThread");
|
Thread.currentThread().setName("RestarterThread");
|
||||||
long starttime = syncStart(config.restartAt);
|
long starttime = syncStart(config.restartAt);
|
||||||
System.out.println("Restart scheduled in " + starttime / 3600000f);
|
writeToScreen("Restart scheduled in " + starttime / 3600000f);
|
||||||
boolean firstrun = true;
|
boolean firstrun = true;
|
||||||
while (!stop) {
|
while (!stop) {
|
||||||
try {
|
try {
|
||||||
|
@ -159,8 +194,9 @@ 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(" "));
|
ProcessBuilder pb = new ProcessBuilder(("java " + config.serverParams + " -jar " + serverJar.getPath()).split(" ")); //Need to use split() because of the supplied params
|
||||||
|
return pb.start();
|
||||||
}
|
}
|
||||||
|
|
||||||
private static void sendMessage(PrintWriter output, String color, String text) {
|
private static void sendMessage(PrintWriter output, String color, String text) {
|
||||||
|
@ -172,6 +208,7 @@ public class ServerRunner {
|
||||||
private static void stop() {
|
private static void stop() {
|
||||||
stop = true;
|
stop = true;
|
||||||
rt.interrupt(); // The restarter thread sleeps for a long time and keeps the program running
|
rt.interrupt(); // The restarter thread sleeps for a long time and keeps the program running
|
||||||
|
it.interrupt(); // The input thread will listen until it's stopped
|
||||||
}
|
}
|
||||||
|
|
||||||
private static void writeToScreen(String line) {
|
private static void writeToScreen(String line) {
|
||||||
|
|
Loading…
Reference in a new issue