diff --git a/nukkit/src/main/java/alemiz/sgu/nukkit/StarGateUniverse.java b/nukkit/src/main/java/alemiz/sgu/nukkit/StarGateUniverse.java index 25aa357..8a4d691 100644 --- a/nukkit/src/main/java/alemiz/sgu/nukkit/StarGateUniverse.java +++ b/nukkit/src/main/java/alemiz/sgu/nukkit/StarGateUniverse.java @@ -17,6 +17,7 @@ import alemiz.sgu.nukkit.events.ClientCreationEvent; import alemiz.sgu.nukkit.utils.NukkitLogger; +import alemiz.sgu.nukkit.utils.ReconnectTask; import alemiz.stargate.client.StarGateClient; import alemiz.stargate.codec.StarGatePackets; import alemiz.stargate.protocol.ServerInfoRequestPacket; @@ -60,6 +61,7 @@ public void onEnable() { for (String clientName : this.getConfig().getSection("connections").getKeys(false)){ this.createClient(clientName); } + this.getServer().getScheduler().scheduleDelayedRepeatingTask(new ReconnectTask(), 20*60, 20*60, false); } @Override @@ -108,6 +110,10 @@ public void onClientCreation(String clientName, StarGateClient client){ this.clients.put(clientName, client); } + public boolean isAutoStart() { + return autoStart; + } + public static StarGateUniverse getInstance() { return instance; } diff --git a/nukkit/src/main/java/alemiz/sgu/nukkit/utils/ReconnectTask.java b/nukkit/src/main/java/alemiz/sgu/nukkit/utils/ReconnectTask.java new file mode 100644 index 0000000..a2151e3 --- /dev/null +++ b/nukkit/src/main/java/alemiz/sgu/nukkit/utils/ReconnectTask.java @@ -0,0 +1,20 @@ +package alemiz.sgu.nukkit.utils; + +import alemiz.sgu.nukkit.StarGateUniverse; +import alemiz.stargate.client.StarGateClient; +import cn.nukkit.scheduler.Task; +import cn.nukkit.utils.TextFormat; + +public class ReconnectTask extends Task { + + @Override + public void onRun(int currentTick) { + StarGateUniverse instance = StarGateUniverse.getInstance(); + for (StarGateClient client : instance.getClientsCopy()) { + if (!client.isConnected() && instance.isAutoStart()) { + instance.getLogger().info(TextFormat.AQUA + "Reconnecting to StarGate"); + client.run(); + } + } + } +}