From 6324c7d527c809e4c440711acb06bbb79a3c2f1c Mon Sep 17 00:00:00 2001 From: Outfluencer <48880402+Outfluencer@users.noreply.github.com> Date: Sat, 10 Jun 2023 10:06:37 +0200 Subject: [PATCH] #3401: Only synchronize necessary parts of the BungeeServerInfo#sendData method --- .../net/md_5/bungee/BungeeServerInfo.java | 22 +++++++++++-------- 1 file changed, 13 insertions(+), 9 deletions(-) diff --git a/proxy/src/main/java/net/md_5/bungee/BungeeServerInfo.java b/proxy/src/main/java/net/md_5/bungee/BungeeServerInfo.java index 65948257..671cf96f 100644 --- a/proxy/src/main/java/net/md_5/bungee/BungeeServerInfo.java +++ b/proxy/src/main/java/net/md_5/bungee/BungeeServerInfo.java @@ -103,26 +103,30 @@ public class BungeeServerInfo implements ServerInfo sendData( channel, data, true ); } - // TODO: Don't like this method @Override public boolean sendData(String channel, byte[] data, boolean queue) { Preconditions.checkNotNull( channel, "channel" ); Preconditions.checkNotNull( data, "data" ); - synchronized ( packetQueue ) + Server server; + synchronized ( players ) { - Server server = ( players.isEmpty() ) ? null : players.iterator().next().getServer(); - if ( server != null ) - { - server.sendData( channel, data ); - return true; - } else if ( queue ) + server = ( players.isEmpty() ) ? null : players.iterator().next().getServer(); + } + + if ( server != null ) + { + server.sendData( channel, data ); + return true; + } else if ( queue ) + { + synchronized ( packetQueue ) { packetQueue.add( new PluginMessage( channel, data, false ) ); } - return false; } + return false; } private long lastPing;