#3401: Only synchronize necessary parts of the BungeeServerInfo#sendData method

This commit is contained in:
Outfluencer 2023-06-10 10:06:37 +02:00 committed by GitHub
parent 6263fe283b
commit 6324c7d527
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -103,26 +103,30 @@ public class BungeeServerInfo implements ServerInfo
sendData( channel, data, true ); sendData( channel, data, true );
} }
// TODO: Don't like this method
@Override @Override
public boolean sendData(String channel, byte[] data, boolean queue) public boolean sendData(String channel, byte[] data, boolean queue)
{ {
Preconditions.checkNotNull( channel, "channel" ); Preconditions.checkNotNull( channel, "channel" );
Preconditions.checkNotNull( data, "data" ); Preconditions.checkNotNull( data, "data" );
synchronized ( packetQueue ) Server server;
synchronized ( players )
{ {
Server server = ( players.isEmpty() ) ? null : players.iterator().next().getServer(); server = ( players.isEmpty() ) ? null : players.iterator().next().getServer();
}
if ( server != null ) if ( server != null )
{ {
server.sendData( channel, data ); server.sendData( channel, data );
return true; return true;
} else if ( queue ) } else if ( queue )
{
synchronized ( packetQueue )
{ {
packetQueue.add( new PluginMessage( channel, data, false ) ); packetQueue.add( new PluginMessage( channel, data, false ) );
} }
return false;
} }
return false;
} }
private long lastPing; private long lastPing;