Prevent potential synchronization issue while removing client cache

This commit is contained in:
themode 2020-11-17 01:33:12 +01:00
parent 8b526bcabe
commit ddaa3a6678
3 changed files with 5 additions and 5 deletions

View File

@ -268,7 +268,7 @@ public final class ConnectionManager {
*
* @param player the player to add
*/
public void createPlayer(@NotNull Player player) {
public synchronized void createPlayer(@NotNull Player player) {
this.players.add(player);
this.connectionPlayerMap.put(player.getPlayerConnection(), player);
}
@ -296,7 +296,7 @@ public final class ConnectionManager {
* @param connection the player connection
* @see PlayerConnection#disconnect() to properly disconnect a player
*/
public void removePlayer(@NotNull PlayerConnection connection) {
public synchronized void removePlayer(@NotNull PlayerConnection connection) {
final Player player = this.connectionPlayerMap.get(connection);
if (player == null)
return;

View File

@ -16,7 +16,7 @@ public class ClientChannel extends SimpleChannelInboundHandler<InboundPacket> {
private final static Logger LOGGER = LoggerFactory.getLogger(ClientChannel.class);
private final ConnectionManager connectionManager = MinecraftServer.getConnectionManager();
private final static ConnectionManager CONNECTION_MANAGER = MinecraftServer.getConnectionManager();
private final PacketProcessor packetProcessor;
public ClientChannel(@NotNull PacketProcessor packetProcessor) {
@ -55,7 +55,7 @@ public class ClientChannel extends SimpleChannelInboundHandler<InboundPacket> {
Player player = playerConnection.getPlayer();
if (player != null) {
player.remove();
connectionManager.removePlayer(playerConnection);
CONNECTION_MANAGER.removePlayer(playerConnection);
}
packetProcessor.removePlayerConnection(ctx);
}

View File

@ -119,7 +119,7 @@ public class NettyPlayerConnection extends PlayerConnection {
@Override
public void disconnect() {
getChannel().close();
channel.close();
}
@NotNull