Make the SlackAPI thread-safe in its current implementation
This commit is contained in:
parent
e47df41225
commit
d7db64da84
@ -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;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user