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