Don't attempt reconnect while shutting down

This commit is contained in:
ME1312 2019-09-26 12:41:04 -04:00
parent 27806b91f9
commit a5c5a532a0
No known key found for this signature in database
GPG Key ID: FEFFE2F698E88FA8
6 changed files with 22 additions and 11 deletions

View File

@ -46,7 +46,7 @@ public class PacketExDownloadTemplates implements PacketIn, PacketStreamOut {
@Override
public void receive(SubDataClient client) {
if (client.getHandler() != null && client.getHandler() instanceof ExternalHost && plugin.config.get().getMap("Hosts").getKeys().contains(((ExternalHost) client.getHandler()).getName())) {
if (client.getHandler() != null && client.getHandler() instanceof ExternalHost) {
client.sendPacket(new PacketExDownloadTemplates(plugin, (ExternalHost) client.getHandler()));
}
}

View File

@ -166,8 +166,10 @@ public class SubProtocol extends SubDataProtocol {
if (plugin.isEnabled()) Bukkit.getPluginManager().callEvent(event);
map.put(0, null);
if (plugin.isEnabled()) {
Bukkit.getLogger().info("SubData > Attempting reconnect in " + plugin.config.get().getMap("Settings").getMap("SubData").getInt("Reconnect", 30) + " seconds");
Util.isException(() -> Util.reflect(SubPlugin.class.getDeclaredMethod("connect", NamedContainer.class), plugin, client));
}
});
return subdata;

View File

@ -177,9 +177,11 @@ public class SubProtocol extends SubDataProtocol {
Sponge.getEventManager().post(event);
map.put(0, null);
if (Util.getDespiteException(() -> Util.reflect(SubPlugin.class.getDeclaredField("running"), plugin), true)) {
Logger log = Util.getDespiteException(() -> Util.reflect(SubDataClient.class.getDeclaredField("log"), client.get()), null);
log.info("Attempting reconnect in " + plugin.config.get().getMap("Settings").getMap("SubData").getInt("Reconnect", 30) + " seconds");
Util.isException(() -> Util.reflect(SubPlugin.class.getDeclaredMethod("connect", NamedContainer.class), plugin, client));
}
});
return subdata;

View File

@ -58,6 +58,7 @@ public final class SubPlugin {
@Inject public PluginContainer plugin;
@Inject public Game game;
private boolean running = false;
private long resetDate = 0;
private boolean reconnect = false;
@ -97,6 +98,7 @@ public final class SubPlugin {
Files.move(new UniversalFile(new File(System.getProperty("user.dir")), "subdata.rsa.key").toPath(), new UniversalFile(dir, "subdata.rsa.key").toPath());
}
running = true;
subprotocol = SubProtocol.get();
reload(false);
@ -218,6 +220,7 @@ public final class SubPlugin {
*/
@Listener
public void disable(GameStoppingEvent event) {
running = false;
if (subdata != null) try {
reconnect = false;

View File

@ -163,9 +163,11 @@ public class SubProtocol extends SubDataProtocol {
host.engine.getPluginManager().executeEvent(event);
map.put(0, null);
if (Util.getDespiteException(() -> Util.reflect(ExHost.class.getDeclaredField("running"), host), true)) {
Logger log = Util.getDespiteException(() -> Util.reflect(SubDataClient.class.getDeclaredField("log"), client.get()), null);
log.info("Attempting reconnect in " + host.config.get().getMap("Settings", new YAMLSection()).getMap("SubData", new YAMLSection()).getInt("Reconnect", 30) + " seconds");
Util.isException(() -> Util.reflect(ExHost.class.getDeclaredMethod("connect", Logger.class, NamedContainer.class), host, log, client));
}
});
return subdata;

View File

@ -166,8 +166,10 @@ public class SubProtocol extends SubDataProtocol {
plugin.getPluginManager().callEvent(event);
map.put(0, null);
if (plugin.isRunning) {
net.ME1312.SubServers.Sync.Library.Compatibility.Logger.get("SubData").info("Attempting reconnect in " + plugin.config.get().getMap("Settings").getMap("SubData").getInt("Reconnect", 30) + " seconds");
Util.isException(() -> Util.reflect(ExProxy.class.getDeclaredMethod("connect", NamedContainer.class), plugin, client));
}
});
return subdata;