From e66b81ba8975f2ed24da06a96007920616d0f181 Mon Sep 17 00:00:00 2001 From: Outfluencer <48880402+Outfluencer@users.noreply.github.com> Date: Mon, 9 Oct 2023 11:56:47 +0200 Subject: [PATCH 1/4] synchronize while iterating syncronizedList in CommandSend --- .../java/net/md_5/bungee/module/cmd/send/CommandSend.java | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/module/cmd-send/src/main/java/net/md_5/bungee/module/cmd/send/CommandSend.java b/module/cmd-send/src/main/java/net/md_5/bungee/module/cmd/send/CommandSend.java index 01cab61072..e7af0d78dc 100644 --- a/module/cmd-send/src/main/java/net/md_5/bungee/module/cmd/send/CommandSend.java +++ b/module/cmd-send/src/main/java/net/md_5/bungee/module/cmd/send/CommandSend.java @@ -50,8 +50,12 @@ public void lastEntryDone() ComponentBuilder builder = new ComponentBuilder( "" ); if ( !entry.getValue().isEmpty() ) { - builder.event( new HoverEvent( HoverEvent.Action.SHOW_TEXT, - new ComponentBuilder( Joiner.on( ", " ).join( entry.getValue() ) ).color( ChatColor.YELLOW ).create() ) ); + String text; + synchronized ( entry.getValue() ) + { + text = Joiner.on( ", " ).join( entry.getValue() ); + } + builder.event( new HoverEvent( HoverEvent.Action.SHOW_TEXT, new ComponentBuilder( text ).color( ChatColor.YELLOW ).create() ) ); } builder.append( entry.getKey().name() + ": " ).color( ChatColor.GREEN ); builder.append( "" + entry.getValue().size() ).bold( true ); From a6323b045d018b78dabfb1b5dd5ebe438b40135b Mon Sep 17 00:00:00 2001 From: Outfluencer <48880402+Outfluencer@users.noreply.github.com> Date: Mon, 9 Oct 2023 12:44:06 +0200 Subject: [PATCH 2/4] Update CommandSend.java --- .../main/java/net/md_5/bungee/module/cmd/send/CommandSend.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/module/cmd-send/src/main/java/net/md_5/bungee/module/cmd/send/CommandSend.java b/module/cmd-send/src/main/java/net/md_5/bungee/module/cmd/send/CommandSend.java index e7af0d78dc..6e8f67a83f 100644 --- a/module/cmd-send/src/main/java/net/md_5/bungee/module/cmd/send/CommandSend.java +++ b/module/cmd-send/src/main/java/net/md_5/bungee/module/cmd/send/CommandSend.java @@ -55,7 +55,7 @@ public void lastEntryDone() { text = Joiner.on( ", " ).join( entry.getValue() ); } - builder.event( new HoverEvent( HoverEvent.Action.SHOW_TEXT, new ComponentBuilder( text ).color( ChatColor.YELLOW ).create() ) ); + builder.event( new HoverEvent( HoverEvent.Action.SHOW_TEXT, new ComponentBuilder( text ).color( ChatColor.YELLOW ).create() ) ); } builder.append( entry.getKey().name() + ": " ).color( ChatColor.GREEN ); builder.append( "" + entry.getValue().size() ).bold( true ); From 689f094d9926dd16a349bba9ab42bef9f828a5af Mon Sep 17 00:00:00 2001 From: Outfluencer <48880402+Outfluencer@users.noreply.github.com> Date: Sat, 28 Oct 2023 21:43:05 +0200 Subject: [PATCH 3/4] make count atomic --- .../java/net/md_5/bungee/module/cmd/send/CommandSend.java | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/module/cmd-send/src/main/java/net/md_5/bungee/module/cmd/send/CommandSend.java b/module/cmd-send/src/main/java/net/md_5/bungee/module/cmd/send/CommandSend.java index 6e8f67a83f..86d0563447 100644 --- a/module/cmd-send/src/main/java/net/md_5/bungee/module/cmd/send/CommandSend.java +++ b/module/cmd-send/src/main/java/net/md_5/bungee/module/cmd/send/CommandSend.java @@ -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; @@ -31,7 +32,7 @@ protected static class SendCallback private final Map> results = new HashMap<>(); private final CommandSender sender; - private int count = 0; + private final AtomicInteger count = new AtomicInteger( 0 ); public SendCallback(CommandSender sender) { @@ -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 @@ -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(); } From 605da4a3dc78d2a129f488560b770edba69eb715 Mon Sep 17 00:00:00 2001 From: Outfluencer <48880402+Outfluencer@users.noreply.github.com> Date: Sat, 28 Oct 2023 21:56:33 +0200 Subject: [PATCH 4/4] synchronize full use of the value --- .../md_5/bungee/module/cmd/send/CommandSend.java | 13 ++++++------- 1 file changed, 6 insertions(+), 7 deletions(-) diff --git a/module/cmd-send/src/main/java/net/md_5/bungee/module/cmd/send/CommandSend.java b/module/cmd-send/src/main/java/net/md_5/bungee/module/cmd/send/CommandSend.java index 86d0563447..66e45fb38c 100644 --- a/module/cmd-send/src/main/java/net/md_5/bungee/module/cmd/send/CommandSend.java +++ b/module/cmd-send/src/main/java/net/md_5/bungee/module/cmd/send/CommandSend.java @@ -49,17 +49,16 @@ public void lastEntryDone() for ( Map.Entry> entry : results.entrySet() ) { ComponentBuilder builder = new ComponentBuilder( "" ); - if ( !entry.getValue().isEmpty() ) + List list = entry.getValue(); + synchronized ( list ) { - String text; - synchronized ( entry.getValue() ) + if ( !list.isEmpty() ) { - text = Joiner.on( ", " ).join( entry.getValue() ); + builder.event( new HoverEvent( HoverEvent.Action.SHOW_TEXT, new ComponentBuilder( Joiner.on( ", " ).join( list ) ).color( ChatColor.YELLOW ).create() ) ); } - builder.event( new HoverEvent( HoverEvent.Action.SHOW_TEXT, new ComponentBuilder( text ).color( ChatColor.YELLOW ).create() ) ); + builder.append( entry.getKey().name() + ": " ).color( ChatColor.GREEN ); + builder.append( "" + list.size() ).bold( true ); } - builder.append( entry.getKey().name() + ": " ).color( ChatColor.GREEN ); - builder.append( "" + entry.getValue().size() ).bold( true ); sender.sendMessage( builder.create() ); } }