Make the SlackAPI thread-safe in its current implementation

This commit is contained in:
Alexander Meech 2018-05-31 22:06:12 -04:00
parent e47df41225
commit d7db64da84

View File

@ -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.
* <p>Sends a message to a Slack channel</p>
* <p>Will be run asynchronously if called from the main thread, else it will execute immediately on the current thread</p>
*
* @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;
}
}