geforkt von SteamWar/PersistentBungeeCore
Adding shutdown callback, adapting startup
Dieser Commit ist enthalten in:
Ursprung
d48e2af54a
Commit
37eba7a6f9
1
pom.xml
1
pom.xml
@ -41,6 +41,7 @@
|
||||
</configuration>
|
||||
</plugin>
|
||||
</plugins>
|
||||
<finalName>persistentbungeecore</finalName>
|
||||
</build>
|
||||
|
||||
<dependencies>
|
||||
|
@ -9,7 +9,6 @@ import java.io.IOException;
|
||||
import java.io.InputStreamReader;
|
||||
import java.io.PrintWriter;
|
||||
import java.net.InetSocketAddress;
|
||||
import java.util.ArrayList;
|
||||
import java.util.LinkedList;
|
||||
import java.util.List;
|
||||
import java.util.concurrent.TimeUnit;
|
||||
@ -39,18 +38,24 @@ public class Subserver implements Runnable {
|
||||
}
|
||||
|
||||
private final String serverName;
|
||||
private Process p;
|
||||
private PrintWriter writer;
|
||||
private ServerInfo server;
|
||||
private Servertype type;
|
||||
private final Runnable shutdownCallback;
|
||||
private final Process p;
|
||||
private final PrintWriter writer;
|
||||
private final ServerInfo server;
|
||||
private final Servertype type;
|
||||
private boolean started;
|
||||
|
||||
private final List<ProxiedPlayer> cachedPlayers = new ArrayList<>();
|
||||
private final List<ProxiedPlayer> cachedPlayers = new LinkedList<>();
|
||||
|
||||
public Subserver(Servertype type, String serverName, int port, String... command){
|
||||
this(type, serverName, port, () -> {}, command);
|
||||
}
|
||||
|
||||
public Subserver(Servertype type, String serverName, int port, Runnable shutdownCallback, String... command){
|
||||
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);
|
||||
@ -58,8 +63,7 @@ public class Subserver implements Runnable {
|
||||
try{
|
||||
this.p = pb.start();
|
||||
}catch(IOException e){
|
||||
logger.log(Level.SEVERE, "Server could not be started", e);
|
||||
return;
|
||||
throw new SecurityException("Server could not be started", e);
|
||||
}
|
||||
|
||||
this.server = ProxyServer.getInstance().constructServerInfo(
|
||||
@ -108,12 +112,10 @@ public class Subserver implements Runnable {
|
||||
}
|
||||
|
||||
private void fatalError(){
|
||||
for(ProxiedPlayer cached : cachedPlayers){
|
||||
for(ProxiedPlayer cached : cachedPlayers)
|
||||
cached.sendMessage(Persistent.getPrefix() + "§cUnerwarteter Fehler beim Serverstart.");
|
||||
}
|
||||
for(ProxiedPlayer player : server.getPlayers()){
|
||||
for(ProxiedPlayer player : server.getPlayers())
|
||||
player.sendMessage(Persistent.getPrefix() + "§cUnerwarteter Fehler im Server.");
|
||||
}
|
||||
}
|
||||
|
||||
public void run(){
|
||||
@ -123,7 +125,7 @@ public class Subserver implements Runnable {
|
||||
try(BufferedReader reader = new BufferedReader(new InputStreamReader(p.getInputStream()))){
|
||||
String line = "";
|
||||
while (!started && (line = reader.readLine()) != null) {
|
||||
started = line.contains("Done ("); //Problematisch
|
||||
started = line.contains("ViaVersion detected server version");
|
||||
}
|
||||
|
||||
if(line == null){
|
||||
@ -132,7 +134,7 @@ public class Subserver implements Runnable {
|
||||
return;
|
||||
}
|
||||
|
||||
Thread.sleep(800);
|
||||
Thread.sleep(300);
|
||||
|
||||
for(ProxiedPlayer cachedPlayer : cachedPlayers){
|
||||
Thread.sleep(200);
|
||||
@ -151,6 +153,7 @@ public class Subserver implements Runnable {
|
||||
} finally {
|
||||
serverList.remove(this);
|
||||
ProxyServer.getInstance().getServers().remove(serverName);
|
||||
shutdownCallback.run();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
In neuem Issue referenzieren
Einen Benutzer sperren