From d7db64da844ff6a4b1d2b8df597f70abb891ca6f Mon Sep 17 00:00:00 2001 From: Alexander Meech Date: Thu, 31 May 2018 22:06:12 -0400 Subject: [PATCH] Make the SlackAPI thread-safe in its current implementation --- .../src/mineplex/core/slack/SlackAPI.java | 15 ++++++--------- 1 file changed, 6 insertions(+), 9 deletions(-) diff --git a/Plugins/Mineplex.Core/src/mineplex/core/slack/SlackAPI.java b/Plugins/Mineplex.Core/src/mineplex/core/slack/SlackAPI.java index 570319d79..a06027325 100644 --- a/Plugins/Mineplex.Core/src/mineplex/core/slack/SlackAPI.java +++ b/Plugins/Mineplex.Core/src/mineplex/core/slack/SlackAPI.java @@ -23,13 +23,14 @@ public class SlackAPI public static final String DEFAULT_ICON = ":mineplex:"; // Singular instance. - private static SlackAPI _instance; + private static final SlackAPI _instance = new SlackAPI(); // Don't allow instantiation elsewhere. private SlackAPI() {} /** - * Sends a message asynchronously to a Slack channel. + *

Sends a message to a Slack channel

+ *

Will be run asynchronously if called from the main thread, else it will execute immediately on the current thread

* * @param team The team which contains the target channel. * @param channel The target channel for the message. @@ -59,7 +60,8 @@ public class SlackAPI if (Bukkit.isPrimaryThread()) { ThreadPool.ASYNC.execute(send); - } else + } + else { send.run(); } @@ -132,11 +134,6 @@ public class SlackAPI */ public static SlackAPI getInstance() { - if (_instance == null) - { - _instance = new SlackAPI(); - } - return _instance; } -} \ No newline at end of file +}