geforkt von SteamWar/PersistentBungeeCore
Merge branch 'new_serverstart' of SteamWar/PersistentBungeeCore into master
Dieser Commit ist enthalten in:
Commit
97e5d54e68
@ -39,7 +39,7 @@ public class Subserver implements Runnable {
|
||||
|
||||
private final String serverName;
|
||||
private final Runnable shutdownCallback;
|
||||
private final Process p;
|
||||
private final Process process;
|
||||
private final PrintWriter writer;
|
||||
private final ServerInfo server;
|
||||
private final Servertype type;
|
||||
@ -52,23 +52,25 @@ public class Subserver implements Runnable {
|
||||
}
|
||||
|
||||
public Subserver(Servertype type, String serverName, int port, Runnable shutdownCallback, String... command){
|
||||
this(type, serverName, port, new ProcessBuilder(command), shutdownCallback);
|
||||
}
|
||||
|
||||
public Subserver(Servertype type, String serverName, int port, ProcessBuilder processBuilder, Runnable shutdownCallback){
|
||||
this.started = false;
|
||||
this.serverName = serverName;
|
||||
this.type = type;
|
||||
this.shutdownCallback = shutdownCallback;
|
||||
|
||||
ProcessBuilder pb = new ProcessBuilder(command);
|
||||
InetSocketAddress address = new InetSocketAddress("127.0.0.1", port);
|
||||
|
||||
try{
|
||||
this.p = pb.start();
|
||||
this.process = processBuilder.start();
|
||||
}catch(IOException e){
|
||||
throw new SecurityException("Server could not be started", e);
|
||||
}
|
||||
|
||||
InetSocketAddress address = new InetSocketAddress("127.0.0.1", port);
|
||||
this.server = ProxyServer.getInstance().constructServerInfo(
|
||||
serverName, address, "SteamWar.de - Subserver", false);
|
||||
this.writer = new PrintWriter(p.getOutputStream(), true);
|
||||
this.writer = new PrintWriter(process.getOutputStream(), true);
|
||||
|
||||
ProxyServer.getInstance().getScheduler().runAsync(Persistent.getInstance(), this);
|
||||
}
|
||||
@ -92,8 +94,8 @@ public class Subserver implements Runnable {
|
||||
public void stop(){
|
||||
writer.println("stop");
|
||||
try {
|
||||
if(!p.waitFor(1, TimeUnit.MINUTES))
|
||||
p.destroy();
|
||||
if(!process.waitFor(1, TimeUnit.MINUTES))
|
||||
process.destroy();
|
||||
}catch(InterruptedException e){
|
||||
logger.log(Level.SEVERE, "Subserver stop interrupted!", e);
|
||||
Thread.currentThread().interrupt();
|
||||
@ -122,7 +124,7 @@ public class Subserver implements Runnable {
|
||||
ProxyServer.getInstance().getServers().put(serverName, server);
|
||||
serverList.add(this);
|
||||
|
||||
try(BufferedReader reader = new BufferedReader(new InputStreamReader(p.getInputStream()))){
|
||||
try(BufferedReader reader = new BufferedReader(new InputStreamReader(process.getInputStream()))){
|
||||
String line = "";
|
||||
while (!started && (line = reader.readLine()) != null) {
|
||||
started = line.contains("ViaVersion detected server version");
|
||||
@ -142,7 +144,7 @@ public class Subserver implements Runnable {
|
||||
}
|
||||
cachedPlayers.clear();
|
||||
|
||||
p.waitFor();
|
||||
process.waitFor();
|
||||
} catch(IOException e) {
|
||||
logger.log(Level.SEVERE, "Server " + serverName + " was interrupted!", e);
|
||||
fatalError();
|
||||
|
In neuem Issue referenzieren
Einen Benutzer sperren