Made sendMessage async (#12)
This commit is contained in:
parent
4f2c33add7
commit
b3153847b0
2 changed files with 4 additions and 1 deletions
|
@ -37,11 +37,13 @@ public class DiscordPlugin extends JavaPlugin implements IListener<ReadyEvent> {
|
||||||
private static final String SubredditURL = "https://www.reddit.com/r/ChromaGamers";
|
private static final String SubredditURL = "https://www.reddit.com/r/ChromaGamers";
|
||||||
private static boolean stop = false;
|
private static boolean stop = false;
|
||||||
public static IDiscordClient dc;
|
public static IDiscordClient dc;
|
||||||
|
public static DiscordPlugin plugin;
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void onEnable() {
|
public void onEnable() {
|
||||||
try {
|
try {
|
||||||
Bukkit.getLogger().info("Initializing DiscordPlugin...");
|
Bukkit.getLogger().info("Initializing DiscordPlugin...");
|
||||||
|
plugin = this;
|
||||||
final File file = new File("TBMC", "DiscordRedditLastAnnouncement.txt");
|
final File file = new File("TBMC", "DiscordRedditLastAnnouncement.txt");
|
||||||
if (file.exists()) {
|
if (file.exists()) {
|
||||||
BufferedReader reader = Files.newReader(file, StandardCharsets.UTF_8);
|
BufferedReader reader = Files.newReader(file, StandardCharsets.UTF_8);
|
||||||
|
|
|
@ -101,7 +101,8 @@ public class DiscordSender implements CommandSender {
|
||||||
@Override
|
@Override
|
||||||
public void sendMessage(String message) {
|
public void sendMessage(String message) {
|
||||||
try {
|
try {
|
||||||
DiscordPlugin.sendMessageToChannel(channel, message);
|
Bukkit.getScheduler().runTaskAsynchronously(DiscordPlugin.plugin,
|
||||||
|
() -> DiscordPlugin.sendMessageToChannel(channel, message));
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
TBMCCoreAPI.SendException("An error occured while sending message to DiscordSender", e);
|
TBMCCoreAPI.SendException("An error occured while sending message to DiscordSender", e);
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue