Fix the reconnect timer

This commit is contained in:
ME1312 2019-10-19 16:38:44 -04:00
parent bfcb076cfd
commit 611b59f2c8
No known key found for this signature in database
GPG Key ID: FEFFE2F698E88FA8
16 changed files with 50 additions and 64 deletions

View File

@ -43,7 +43,7 @@
<dependency>
<groupId>net.ME1312.SubData</groupId>
<artifactId>Server</artifactId>
<version>19w42c</version>
<version>19w42d</version>
<scope>compile</scope>
<optional>true</optional>
</dependency>

View File

@ -146,18 +146,14 @@ public class ExternalSubCreator extends SubCreator {
if (template.getBuildOptions().getBoolean("Run-On-Finish", true))
subserver.start();
if (callback != null) try {
callback.run(subserver);
} catch (Throwable e) {
Throwable ew = new InvocationTargetException(e);
ew.setStackTrace(origin);
ew.printStackTrace();
}
callback(origin, callback, subserver);
} else {
Logger.get(prefix).info(data.getString(0x0004));
callback(origin, callback, null);
}
} catch (Exception e) {
e.printStackTrace();
callback(origin, callback, null);
}
logger.stop();
this.thread.remove(name.toLowerCase());
@ -190,10 +186,18 @@ public class ExternalSubCreator extends SubCreator {
} private String replace(String string, NamedContainer<String, String>... replacements) {
for (NamedContainer<String, String> replacement : replacements) string = string.replace(replacement.name(), replacement.get());
return string;
} private <T> void callback(StackTraceElement[] origin, Callback<T> callback, T value) {
if (callback != null) try {
callback.run(value);
} catch (Throwable e) {
Throwable ew = new InvocationTargetException(e);
ew.setStackTrace(origin);
ew.printStackTrace();
}
}
@Override
public boolean update(UUID player, SubServer server, Version version, Callback<SubServer> callback) {
public boolean update(UUID player, SubServer server, Version version, Callback<Boolean> callback) {
if (Util.isNull(server)) throw new NullPointerException();
if (host.isAvailable() && host.isEnabled() && host == server.getHost() && server.isAvailable() && !server.isRunning() && server.getTemplate() != null && server.getTemplate().isEnabled() && server.getTemplate().canUpdate() && (version != null || !server.getTemplate().requiresVersion())) {
StackTraceElement[] origin = new Exception().getStackTrace();
@ -210,22 +214,19 @@ public class ExternalSubCreator extends SubCreator {
logger.start();
host.queue(new PacketExCreateServer(server, version, logger.getExternalAddress(), data -> {
Util.isException(() -> Util.reflect(SubServerContainer.class.getDeclaredField("updating"), server, false));
try {
if (data.getInt(0x0001) == 0) {
Logger.get(prefix).info("Saving...");
} else {
Logger.get(prefix).info(data.getString(0x0004));
}
if (callback != null) try {
callback.run(server);
callback.run(data.getInt(0x0001) == 0);
} catch (Throwable e) {
Throwable ew = new InvocationTargetException(e);
ew.setStackTrace(origin);
ew.printStackTrace();
}
} else {
Logger.get(prefix).info(data.getString(0x0004));
}
} catch (Exception e) {
e.printStackTrace();
}
logger.stop();
this.thread.remove(name.toLowerCase());
}));

View File

@ -266,9 +266,11 @@ public class InternalSubCreator extends SubCreator {
callback.run(subserver);
} catch (Exception e) {
e.printStackTrace();
callback.run(null);
}
} else {
Logger.get(prefix).info("Couldn't build the server jar. Check the SubCreator logs for more detail.");
callback.run(null);
}
InternalSubCreator.this.thread.remove(name.toLowerCase());
} private Object convert(Object value, NamedContainer<String, String>... replacements) {
@ -354,7 +356,7 @@ public class InternalSubCreator extends SubCreator {
}
CreatorTask task = new CreatorTask(player, name, template, version, port, server -> {
if (callback != null && server != null) try {
if (callback != null) try {
callback.run(server);
} catch (Throwable e) {
Throwable ew = new InvocationTargetException(e);
@ -378,7 +380,7 @@ public class InternalSubCreator extends SubCreator {
@SuppressWarnings("deprecation")
@Override
public boolean update(UUID player, SubServer server, Version version, Callback<SubServer> callback) {
public boolean update(UUID player, SubServer server, Version version, Callback<Boolean> callback) {
if (Util.isNull(server)) throw new NullPointerException();
if (host.isAvailable() && host.isEnabled() && host == server.getHost() && server.isAvailable() && !server.isRunning() && server.getTemplate() != null && server.getTemplate().isEnabled() && server.getTemplate().canUpdate() && (version != null || !server.getTemplate().requiresVersion())) {
StackTraceElement[] origin = new Exception().getStackTrace();
@ -387,8 +389,8 @@ public class InternalSubCreator extends SubCreator {
CreatorTask task = new CreatorTask(player, server, version, x -> {
Util.isException(() -> Util.reflect(SubServerContainer.class.getDeclaredField("updating"), server, false));
if (callback != null && x != null) try {
callback.run(x);
if (callback != null) try {
callback.run(x != null);
} catch (Throwable e) {
Throwable ew = new InvocationTargetException(e);
ew.setStackTrace(origin);

View File

@ -256,7 +256,7 @@ public abstract class SubCreator {
* @param callback Callback
* @return Success Status
*/
public abstract boolean update(UUID player, SubServer server, Version version, Callback<SubServer> callback);
public abstract boolean update(UUID player, SubServer server, Version version, Callback<Boolean> callback);
/**
* Update a SubServer
@ -278,7 +278,7 @@ public abstract class SubCreator {
* @param callback Callback
* @return Success Status
*/
public boolean update(SubServer server, Version version, Callback<SubServer> callback) {
public boolean update(SubServer server, Version version, Callback<Boolean> callback) {
return update(null, server, version, callback);
}

View File

@ -77,19 +77,10 @@ public class PacketCreateServer implements PacketObjectIn<Integer>, PacketObject
} else if (port != null && (port <= 0 || port > 65535)) {
client.sendPacket(new PacketCreateServer(11, tracker));
} else {
if (plugin.hosts.get(host.toLowerCase()).getCreator().create(player, name, plugin.hosts.get(host.toLowerCase()).getCreator().getTemplate(template), version, port)) {
if (waitfor) {
new Thread(() -> {
try {
plugin.hosts.get(host.toLowerCase()).getCreator().waitFor();
client.sendPacket(new PacketCreateServer(0, tracker));
} catch (InterruptedException e) {
e.printStackTrace();
}
}, "SubServers.Bungee::SubData_SubCreator_Handler(" + client.getAddress().toString() + ')').start();
} else {
client.sendPacket(new PacketCreateServer(0, tracker));
}
if (plugin.hosts.get(host.toLowerCase()).getCreator().create(player, name, plugin.hosts.get(host.toLowerCase()).getCreator().getTemplate(template), version, port, server -> {
if (waitfor) client.sendPacket(new PacketCreateServer((server == null)?12:0, tracker));
})) {
if (!waitfor) client.sendPacket(new PacketCreateServer(0, tracker));
} else {
client.sendPacket(new PacketCreateServer(1, tracker));
}

View File

@ -79,17 +79,10 @@ public class PacketUpdateServer implements PacketObjectIn<Integer>, PacketObject
} else if (version == null && ((SubServer) servers.get(name.toLowerCase())).getTemplate().requiresVersion()) {
client.sendPacket(new PacketUpdateServer(12, tracker));
} else {
if (((SubServer) servers.get(name.toLowerCase())).getHost().getCreator().update(player, (SubServer) servers.get(name.toLowerCase()), version)) {
if (waitfor) {
new Thread(() -> {
try {
((SubServer) servers.get(name.toLowerCase())).getHost().getCreator().waitFor();
client.sendPacket(new PacketUpdateServer(0, tracker));
} catch (InterruptedException e) {
e.printStackTrace();
}
}, "SubServers.Bungee::SubData_SubCreator_Update_Handler(" + client.getAddress().toString() + ')').start();
} else {
if (((SubServer) servers.get(name.toLowerCase())).getHost().getCreator().update(player, (SubServer) servers.get(name.toLowerCase()), version, success -> {
if (waitfor) client.sendPacket(new PacketUpdateServer((!success)?13:0, tracker));
})) {
if (!waitfor) {
client.sendPacket(new PacketUpdateServer(0, tracker));
}
} else {

View File

@ -55,7 +55,7 @@
<dependency>
<groupId>net.ME1312.SubData</groupId>
<artifactId>Client</artifactId>
<version>19w42c</version>
<version>19w42d</version>
<scope>compile</scope>
<optional>true</optional>
</dependency>

View File

@ -161,9 +161,9 @@ public class SubProtocol extends SubDataProtocol {
subdata.on.ready(client -> Bukkit.getPluginManager().callEvent(new SubNetworkConnectEvent((SubDataClient) client)));
subdata.on.closed(client -> {
SubNetworkDisconnectEvent event = new SubNetworkDisconnectEvent(client.get(), client.name());
if (plugin.isEnabled()) Bukkit.getPluginManager().callEvent(event);
if (plugin.isEnabled()) {
Bukkit.getPluginManager().callEvent(event);
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));
} else map.put(0, null);

View File

@ -182,7 +182,7 @@ public final class SubPlugin extends JavaPlugin {
@Override
public void run() {
try {
if (reset == resetDate && subdata.getOrDefault(0, null) == null) {
if (reset == resetDate && (subdata.getOrDefault(0, null) == null || subdata.get(0).isClosed())) {
SubDataClient open = subprotocol.open((config.get().getMap("Settings").getMap("SubData").getRawString("Address", "127.0.0.1:4391").split(":")[0].equals("0.0.0.0"))?
null:InetAddress.getByName(config.get().getMap("Settings").getMap("SubData").getRawString("Address", "127.0.0.1:4391").split(":")[0]),
Integer.parseInt(config.get().getMap("Settings").getMap("SubData").getRawString("Address", "127.0.0.1:4391").split(":")[1]));

View File

@ -37,7 +37,7 @@
<dependency>
<groupId>net.ME1312.SubData</groupId>
<artifactId>Client</artifactId>
<version>19w42c</version>
<version>19w42d</version>
<scope>compile</scope>
<optional>true</optional>
</dependency>

View File

@ -201,7 +201,7 @@ public final class SubPlugin {
@Override
public void run() {
try {
if (reset == resetDate && subdata.getOrDefault(0, null) == null) {
if (reset == resetDate && (subdata.getOrDefault(0, null) == null || subdata.get(0).isClosed())) {
SubDataClient open = subprotocol.open((config.get().getMap("Settings").getMap("SubData").getRawString("Address", "127.0.0.1:4391").split(":")[0].equals("0.0.0.0"))?
null:InetAddress.getByName(config.get().getMap("Settings").getMap("SubData").getRawString("Address", "127.0.0.1:4391").split(":")[0]),
Integer.parseInt(config.get().getMap("Settings").getMap("SubData").getRawString("Address", "127.0.0.1:4391").split(":")[1]));

View File

@ -27,7 +27,7 @@
<dependency>
<groupId>net.ME1312.SubData</groupId>
<artifactId>Client</artifactId>
<version>19w42c</version>
<version>19w42d</version>
<scope>compile</scope>
<optional>true</optional>
</dependency>

View File

@ -299,7 +299,7 @@ public final class ExHost {
@Override
public void run() {
try {
if (reset == resetDate && subdata.getOrDefault(0, null) == null) {
if (reset == resetDate && (subdata.getOrDefault(0, null) == null || subdata.get(0).isClosed())) {
SubDataClient open = subprotocol.open((config.get().getMap("Settings").getMap("SubData").getRawString("Address", "127.0.0.1:4391").split(":")[0].equals("0.0.0.0"))?
null:InetAddress.getByName(config.get().getMap("Settings").getMap("SubData").getRawString("Address", "127.0.0.1:4391").split(":")[0]),
Integer.parseInt(config.get().getMap("Settings").getMap("SubData").getRawString("Address", "127.0.0.1:4391").split(":")[1]));

View File

@ -95,7 +95,6 @@ public class SubLoggerImpl {
} else try {
SubDataClient open = (SubDataClient) SubAPI.getInstance().getSubDataNetwork()[0].openChannel();
open.on.closed(run);
channel.reconnect(channel);
channel = open;
timer.cancel();
} catch (NullPointerException | IOException e) {}

View File

@ -43,7 +43,7 @@
<dependency>
<groupId>net.ME1312.SubData</groupId>
<artifactId>Client</artifactId>
<version>19w42c</version>
<version>19w42d</version>
<scope>compile</scope>
<optional>true</optional>
</dependency>

View File

@ -164,7 +164,7 @@ public final class ExProxy extends BungeeCord implements Listener {
@Override
public void run() {
try {
if (reset == resetDate && subdata.getOrDefault(0, null) == null) {
if (reset == resetDate && (subdata.getOrDefault(0, null) == null || subdata.get(0).isClosed())) {
SubDataClient open = subprotocol.open((config.get().getMap("Settings").getMap("SubData").getRawString("Address", "127.0.0.1:4391").split(":")[0].equals("0.0.0.0"))?
null:InetAddress.getByName(config.get().getMap("Settings").getMap("SubData").getRawString("Address", "127.0.0.1:4391").split(":")[0]),
Integer.parseInt(config.get().getMap("Settings").getMap("SubData").getRawString("Address", "127.0.0.1:4391").split(":")[1]));