From 9cf57ca929934fb58463a1e654e81ec72451d894 Mon Sep 17 00:00:00 2001 From: minecraftshamrock Date: Mon, 30 Mar 2015 18:40:34 +0200 Subject: [PATCH] Fix AsyncEvent callback triggering. Before this, two concurrent postCall() and completeIntent() calls might cause the callback to be called more than once. --- .../java/net/md_5/bungee/api/event/AsyncEvent.java | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) diff --git a/api/src/main/java/net/md_5/bungee/api/event/AsyncEvent.java b/api/src/main/java/net/md_5/bungee/api/event/AsyncEvent.java index e85c4cd2..e907fb13 100644 --- a/api/src/main/java/net/md_5/bungee/api/event/AsyncEvent.java +++ b/api/src/main/java/net/md_5/bungee/api/event/AsyncEvent.java @@ -33,11 +33,11 @@ public class AsyncEvent extends Event @SuppressWarnings("unchecked") public void postCall() { - fired.set( true ); if ( latch.get() == 0 ) { done.done( (T) this, null ); } + fired.set( true ); } /** @@ -67,9 +67,14 @@ public class AsyncEvent extends Event { Preconditions.checkState( intents.contains( plugin ), "Plugin %s has not registered intent for event %s", plugin, this ); intents.remove( plugin ); - if ( latch.decrementAndGet() == 0 && fired.get() ) + if ( fired.get() ) { - done.done( (T) this, null ); + if ( latch.decrementAndGet() == 0 ) + { + done.done( (T) this, null ); + } + } else { + latch.decrementAndGet(); } } }