Skip to content

Commit

Permalink
make count atomic
Browse files Browse the repository at this point in the history
  • Loading branch information
Outfluencer authored Oct 28, 2023
1 parent a6323b0 commit 689f094
Showing 1 changed file with 4 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
import java.util.Locale;
import java.util.Map;
import java.util.Set;
import java.util.concurrent.atomic.AtomicInteger;
import net.md_5.bungee.api.Callback;
import net.md_5.bungee.api.ChatColor;
import net.md_5.bungee.api.CommandSender;
Expand All @@ -31,7 +32,7 @@ protected static class SendCallback

private final Map<ServerConnectRequest.Result, List<String>> results = new HashMap<>();
private final CommandSender sender;
private int count = 0;
private final AtomicInteger count = new AtomicInteger( 0 );

public SendCallback(CommandSender sender)
{
Expand Down Expand Up @@ -75,7 +76,7 @@ public Entry(SendCallback callback, ProxiedPlayer player, ServerInfo target)
this.callback = callback;
this.player = player;
this.target = target;
this.callback.count++;
this.callback.count.incrementAndGet();
}

@Override
Expand All @@ -87,7 +88,7 @@ public void done(ServerConnectRequest.Result result, Throwable error)
player.sendMessage( ProxyServer.getInstance().getTranslation( "you_got_summoned", target.getName(), callback.sender.getName() ) );
}

if ( --callback.count == 0 )
if ( callback.count.decrementAndGet() == 0 )
{
callback.lastEntryDone();
}
Expand Down

0 comments on commit 689f094

Please sign in to comment.