QuesterPreCompleteQuestEvent can also be triggered sync, fixes #1662

This commit is contained in:
PikaMug 2021-04-01 01:24:47 -04:00
parent 58213cec1d
commit 92412a89ff

View File

@ -524,10 +524,25 @@ public class Quest implements Comparable<Quest> {
public void completeQuest(final Quester q, final boolean allowMultiplayer) {
final OfflinePlayer player = q.getOfflinePlayer();
if (player.isOnline()) {
final QuesterPreCompleteQuestEvent preEvent = new QuesterPreCompleteQuestEvent(q, this, true);
plugin.getServer().getPluginManager().callEvent(preEvent);
if (preEvent.isCancelled()) {
return;
if (Bukkit.isPrimaryThread()) {
final QuesterPreCompleteQuestEvent preEvent = new QuesterPreCompleteQuestEvent(q, this, false);
plugin.getServer().getPluginManager().callEvent(preEvent);
if (preEvent.isCancelled()) {
return;
}
} else {
Bukkit.getScheduler().runTask(plugin, new Runnable() {
@Override
public void run() {
final QuesterPreCompleteQuestEvent preEvent
= new QuesterPreCompleteQuestEvent(q, Quest.this, true);
plugin.getServer().getPluginManager().callEvent(preEvent);
if (preEvent.isCancelled()) {
return;
}
}
});
}
}
q.hardQuit(this);