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 {
|
public class ServerRunner {
|
||||||
private static final String SERVER_VERSION = "1.9.2";
|
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...");
|
System.out.println("Starting server...");
|
||||||
Process p = Runtime.getRuntime().exec(
|
Process p = Runtime.getRuntime().exec(new String[] { "java", "-Xms512M", "-Xmx1024M", "-XX:MaxPermSize=128M",
|
||||||
new String[] { "java", "-Xms512M", "-Xmx1024M", "-XX:MaxPermSize=128M", "-jar", "spigot-1.9.2.jar" });
|
"-jar", "spigot-" + SERVER_VERSION + ".jar" });
|
||||||
Thread t = new Thread() {
|
Thread t = new Thread() {
|
||||||
@Override
|
@Override
|
||||||
public void run() {
|
public void run() {
|
||||||
BufferedWriter output = new BufferedWriter(new OutputStreamWriter(p.getOutputStream()));
|
BufferedWriter output = new BufferedWriter(new OutputStreamWriter(p.getOutputStream()));
|
||||||
BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
|
BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
|
||||||
String outline;
|
|
||||||
try {
|
try {
|
||||||
while ((outline = br.readLine()) != null)
|
while (!stop)
|
||||||
output.write(outline + "\n");
|
output.write(br.readLine() + "\n\r");
|
||||||
} catch (IOException e) {
|
} catch (IOException e) {
|
||||||
e.printStackTrace();
|
e.printStackTrace();
|
||||||
}
|
}
|
||||||
|
stop = true;
|
||||||
|
System.out.println("Stopped " + Thread.currentThread().getName());
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
t.setName("InputThread");
|
t.setName("InputThread");
|
||||||
t.start();
|
t.start();
|
||||||
|
t = new Thread() {
|
||||||
|
@Override
|
||||||
|
public void run() {
|
||||||
|
try {
|
||||||
BufferedReader input = new BufferedReader(new InputStreamReader(p.getInputStream()));
|
BufferedReader input = new BufferedReader(new InputStreamReader(p.getInputStream()));
|
||||||
String line;
|
String line;
|
||||||
while ((line = input.readLine()) != null) {
|
while ((line = input.readLine()) != null && !stop) {
|
||||||
System.out.println(line);
|
System.out.println(line);
|
||||||
}
|
}
|
||||||
input.close();
|
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");
|
||||||
|
}
|
||||||
|
System.out.println("Stopped " + Thread.currentThread().getName());
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue