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 String serverName;
|
||||||
private final Runnable shutdownCallback;
|
private final Runnable shutdownCallback;
|
||||||
private final Process p;
|
private final Process process;
|
||||||
private final PrintWriter writer;
|
private final PrintWriter writer;
|
||||||
private final ServerInfo server;
|
private final ServerInfo server;
|
||||||
private final Servertype type;
|
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){
|
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.started = false;
|
||||||
this.serverName = serverName;
|
this.serverName = serverName;
|
||||||
this.type = type;
|
this.type = type;
|
||||||
this.shutdownCallback = shutdownCallback;
|
this.shutdownCallback = shutdownCallback;
|
||||||
|
|
||||||
ProcessBuilder pb = new ProcessBuilder(command);
|
|
||||||
InetSocketAddress address = new InetSocketAddress("127.0.0.1", port);
|
|
||||||
|
|
||||||
try{
|
try{
|
||||||
this.p = pb.start();
|
this.process = processBuilder.start();
|
||||||
}catch(IOException e){
|
}catch(IOException e){
|
||||||
throw new SecurityException("Server could not be started", e);
|
throw new SecurityException("Server could not be started", e);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
InetSocketAddress address = new InetSocketAddress("127.0.0.1", port);
|
||||||
this.server = ProxyServer.getInstance().constructServerInfo(
|
this.server = ProxyServer.getInstance().constructServerInfo(
|
||||||
serverName, address, "SteamWar.de - Subserver", false);
|
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);
|
ProxyServer.getInstance().getScheduler().runAsync(Persistent.getInstance(), this);
|
||||||
}
|
}
|
||||||
@ -92,8 +94,8 @@ public class Subserver implements Runnable {
|
|||||||
public void stop(){
|
public void stop(){
|
||||||
writer.println("stop");
|
writer.println("stop");
|
||||||
try {
|
try {
|
||||||
if(!p.waitFor(1, TimeUnit.MINUTES))
|
if(!process.waitFor(1, TimeUnit.MINUTES))
|
||||||
p.destroy();
|
process.destroy();
|
||||||
}catch(InterruptedException e){
|
}catch(InterruptedException e){
|
||||||
logger.log(Level.SEVERE, "Subserver stop interrupted!", e);
|
logger.log(Level.SEVERE, "Subserver stop interrupted!", e);
|
||||||
Thread.currentThread().interrupt();
|
Thread.currentThread().interrupt();
|
||||||
@ -122,7 +124,7 @@ public class Subserver implements Runnable {
|
|||||||
ProxyServer.getInstance().getServers().put(serverName, server);
|
ProxyServer.getInstance().getServers().put(serverName, server);
|
||||||
serverList.add(this);
|
serverList.add(this);
|
||||||
|
|
||||||
try(BufferedReader reader = new BufferedReader(new InputStreamReader(p.getInputStream()))){
|
try(BufferedReader reader = new BufferedReader(new InputStreamReader(process.getInputStream()))){
|
||||||
String line = "";
|
String line = "";
|
||||||
while (!started && (line = reader.readLine()) != null) {
|
while (!started && (line = reader.readLine()) != null) {
|
||||||
started = line.contains("ViaVersion detected server version");
|
started = line.contains("ViaVersion detected server version");
|
||||||
@ -142,7 +144,7 @@ public class Subserver implements Runnable {
|
|||||||
}
|
}
|
||||||
cachedPlayers.clear();
|
cachedPlayers.clear();
|
||||||
|
|
||||||
p.waitFor();
|
process.waitFor();
|
||||||
} catch(IOException e) {
|
} catch(IOException e) {
|
||||||
logger.log(Level.SEVERE, "Server " + serverName + " was interrupted!", e);
|
logger.log(Level.SEVERE, "Server " + serverName + " was interrupted!", e);
|
||||||
fatalError();
|
fatalError();
|
||||||
|
In neuem Issue referenzieren
Einen Benutzer sperren