Fixed and organized things (input still doesn't work)
This commit is contained in:
parent
97217cb0c4
commit
07721b2d6d
1 changed files with 34 additions and 11 deletions
|
@ -9,31 +9,54 @@ import java.io.OutputStreamWriter;
|
|||
public class ServerRunner {
|
||||
private static final String SERVER_VERSION = "1.9.2";
|
||||
|
||||
public static void main(String[] args) throws IOException {
|
||||
private static boolean stop = false;
|
||||
|
||||
public static void main(String[] args) throws IOException, InterruptedException {
|
||||
System.out.println("Starting server...");
|
||||
Process p = Runtime.getRuntime().exec(
|
||||
new String[] { "java", "-Xms512M", "-Xmx1024M", "-XX:MaxPermSize=128M", "-jar", "spigot-1.9.2.jar" });
|
||||
Process p = Runtime.getRuntime().exec(new String[] { "java", "-Xms512M", "-Xmx1024M", "-XX:MaxPermSize=128M",
|
||||
"-jar", "spigot-" + SERVER_VERSION + ".jar" });
|
||||
Thread t = new Thread() {
|
||||
@Override
|
||||
public void run() {
|
||||
BufferedWriter output = new BufferedWriter(new OutputStreamWriter(p.getOutputStream()));
|
||||
BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
|
||||
String outline;
|
||||
try {
|
||||
while ((outline = br.readLine()) != null)
|
||||
output.write(outline + "\n");
|
||||
while (!stop)
|
||||
output.write(br.readLine() + "\n\r");
|
||||
} catch (IOException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
stop = true;
|
||||
System.out.println("Stopped " + Thread.currentThread().getName());
|
||||
}
|
||||
};
|
||||
t.setName("InputThread");
|
||||
t.start();
|
||||
BufferedReader input = new BufferedReader(new InputStreamReader(p.getInputStream()));
|
||||
String line;
|
||||
while ((line = input.readLine()) != null) {
|
||||
System.out.println(line);
|
||||
t = new Thread() {
|
||||
@Override
|
||||
public void run() {
|
||||
try {
|
||||
BufferedReader input = new BufferedReader(new InputStreamReader(p.getInputStream()));
|
||||
String line;
|
||||
while ((line = input.readLine()) != null && !stop) {
|
||||
System.out.println(line);
|
||||
}
|
||||
input.close();
|
||||
} catch (IOException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
stop = true;
|
||||
System.out.println("Stopped " + Thread.currentThread().getName());
|
||||
}
|
||||
};
|
||||
t.setName("OutputThread");
|
||||
t.start();
|
||||
Thread.currentThread().setName("RestarterThread");
|
||||
while (!stop) {
|
||||
Thread.sleep(10000);
|
||||
System.out.println("RESTART");
|
||||
}
|
||||
input.close();
|
||||
System.out.println("Stopped " + Thread.currentThread().getName());
|
||||
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue