Hopefully fix discord being killed incorrectly

This commit is contained in:
Business Goose 2022-03-29 23:59:58 +01:00
parent b984b700e0
commit d033b96376
No known key found for this signature in database
GPG key ID: 77DCA801362E9645
2 changed files with 11 additions and 0 deletions

View file

@ -51,6 +51,7 @@
<groupId>org.bukkit</groupId> <groupId>org.bukkit</groupId>
<artifactId>craftbukkit</artifactId> <artifactId>craftbukkit</artifactId>
<version>1.8.8-R0.1-SNAPSHOT</version> <version>1.8.8-R0.1-SNAPSHOT</version>
<scope>provided</scope>
</dependency> </dependency>
<dependency> <dependency>

View file

@ -24,6 +24,8 @@ import org.javacord.api.event.message.MessageCreateEvent;
import org.javacord.api.event.message.MessageEvent; import org.javacord.api.event.message.MessageEvent;
import java.util.Optional; import java.util.Optional;
import java.util.concurrent.CountDownLatch;
import java.util.concurrent.TimeUnit;
import java.util.regex.Pattern; import java.util.regex.Pattern;
public class DiscordBridge { public class DiscordBridge {
@ -189,7 +191,15 @@ public class DiscordBridge {
CHANNEL.sendMessage(sanitizeMessage(message)).get(); CHANNEL.sendMessage(sanitizeMessage(message)).get();
} catch (Exception ignored) { } catch (Exception ignored) {
} }
CountDownLatch shutdownWaiter = new CountDownLatch(1);
DISCORD_API.addLostConnectionListener(lostConnectionEvent -> shutdownWaiter.countDown());
DISCORD_API.disconnect(); DISCORD_API.disconnect();
try {
shutdownWaiter.await(30, TimeUnit.SECONDS);
} catch (InterruptedException ignored) {
}
} }
} }