Skip to content

Commit

Permalink
Call ChattyPreMessageEvent asynchronously in main thread
Browse files Browse the repository at this point in the history
  • Loading branch information
Brikster committed Feb 5, 2024
1 parent b88aa9f commit 15522ff
Showing 1 changed file with 12 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@

import javax.inject.Inject;
import java.util.*;
import java.util.concurrent.CompletableFuture;
import java.util.concurrent.ConcurrentHashMap;
import java.util.function.Predicate;
import java.util.logging.Level;
Expand Down Expand Up @@ -177,7 +178,17 @@ public void handleFinishedEarlyContextEvent(AsyncPlayerChatEvent event) {
List.copyOf(middleContext.getRecipients())
);

Bukkit.getPluginManager().callEvent(preMessageEvent);
Runnable callEventRunnable = () -> Bukkit.getPluginManager().callEvent(preMessageEvent);
if (Bukkit.isPrimaryThread()) {
CompletableFuture.runAsync(callEventRunnable)
.exceptionally(e -> {
logger.log(Level.SEVERE, "Error while calling ChattyPreMessageEvent", e);
return null;
});
} else {
callEventRunnable.run();
}

middleContext.setFormat(preMessageEvent.getFormat());
middleContext.setMessage(preMessageEvent.getMessage());

Expand Down

0 comments on commit 15522ff

Please sign in to comment.