diff --git a/proxy/src/main/java/net/md_5/bungee/ServerConnector.java b/proxy/src/main/java/net/md_5/bungee/ServerConnector.java index fa8bbb6d..a9dfcabd 100644 --- a/proxy/src/main/java/net/md_5/bungee/ServerConnector.java +++ b/proxy/src/main/java/net/md_5/bungee/ServerConnector.java @@ -117,67 +117,64 @@ public class ServerConnector extends PacketHandler ch.write( user.getSettings() ); } - synchronized ( user.getSwitchMutex() ) + if ( user.getServer() == null ) { - if ( user.getServer() == null ) + // Once again, first connection + user.setClientEntityId( login.getEntityId() ); + user.setServerEntityId( login.getEntityId() ); + + // Set tab list size, this sucks balls, TODO: what shall we do about packet mutability + Login modLogin = new Login( login.getEntityId(), login.getGameMode(), (byte) login.getDimension(), login.getDifficulty(), + (byte) user.getPendingConnection().getListener().getTabListSize(), login.getLevelType() ); + + user.unsafe().sendPacket( modLogin ); + + MinecraftOutput out = new MinecraftOutput(); + out.writeStringUTF8WithoutLengthHeaderBecauseDinnerboneStuffedUpTheMCBrandPacket( ProxyServer.getInstance().getName() + " (" + ProxyServer.getInstance().getVersion() + ")" ); + user.unsafe().sendPacket( new PluginMessage( "MC|Brand", out.toArray() ) ); + } else + { + user.getTabList().onServerChange(); + + Scoreboard serverScoreboard = user.getServerSentScoreboard(); + for ( Objective objective : serverScoreboard.getObjectives() ) { - // Once again, first connection - user.setClientEntityId( login.getEntityId() ); - user.setServerEntityId( login.getEntityId() ); - - // Set tab list size, this sucks balls, TODO: what shall we do about packet mutability - Login modLogin = new Login( login.getEntityId(), login.getGameMode(), (byte) login.getDimension(), login.getDifficulty(), - (byte) user.getPendingConnection().getListener().getTabListSize(), login.getLevelType() ); - - user.unsafe().sendPacket( modLogin ); - - MinecraftOutput out = new MinecraftOutput(); - out.writeStringUTF8WithoutLengthHeaderBecauseDinnerboneStuffedUpTheMCBrandPacket( ProxyServer.getInstance().getName() + " (" + ProxyServer.getInstance().getVersion() + ")" ); - user.unsafe().sendPacket( new PluginMessage( "MC|Brand", out.toArray() ) ); - } else - { - user.getTabList().onServerChange(); - - Scoreboard serverScoreboard = user.getServerSentScoreboard(); - for ( Objective objective : serverScoreboard.getObjectives() ) - { - user.unsafe().sendPacket( new ScoreboardObjective( objective.getName(), objective.getValue(), (byte) 1 ) ); - } - for ( Team team : serverScoreboard.getTeams() ) - { - user.unsafe().sendPacket( new net.md_5.bungee.protocol.packet.Team( team.getName() ) ); - } - serverScoreboard.clear(); - - user.sendDimensionSwitch(); - - user.setServerEntityId( login.getEntityId() ); - user.unsafe().sendPacket( new Respawn( login.getDimension(), login.getDifficulty(), login.getGameMode(), login.getLevelType() ) ); - - // Remove from old servers - user.getServer().setObsolete( true ); - user.getServer().disconnect( "Quitting" ); + user.unsafe().sendPacket( new ScoreboardObjective( objective.getName(), objective.getValue(), (byte) 1 ) ); } - - // TODO: Fix this? - if ( !user.isActive() ) + for ( Team team : serverScoreboard.getTeams() ) { - server.disconnect( "Quitting" ); - // Silly server admins see stack trace and die - bungee.getLogger().warning( "No client connected for pending server!" ); - return; + user.unsafe().sendPacket( new net.md_5.bungee.protocol.packet.Team( team.getName() ) ); } + serverScoreboard.clear(); - // Add to new server - // TODO: Move this to the connected() method of DownstreamBridge - target.addPlayer( user ); - user.getPendingConnects().remove( target ); - user.setDimensionChange( false ); + user.sendDimensionSwitch(); - user.setServer( server ); - ch.getHandle().pipeline().get( HandlerBoss.class ).setHandler( new DownstreamBridge( bungee, user, server ) ); + user.setServerEntityId( login.getEntityId() ); + user.unsafe().sendPacket( new Respawn( login.getDimension(), login.getDifficulty(), login.getGameMode(), login.getLevelType() ) ); + + // Remove from old servers + user.getServer().setObsolete( true ); + user.getServer().disconnect( "Quitting" ); } + // TODO: Fix this? + if ( !user.isActive() ) + { + server.disconnect( "Quitting" ); + // Silly server admins see stack trace and die + bungee.getLogger().warning( "No client connected for pending server!" ); + return; + } + + // Add to new server + // TODO: Move this to the connected() method of DownstreamBridge + target.addPlayer( user ); + user.getPendingConnects().remove( target ); + user.setDimensionChange( false ); + + user.setServer( server ); + ch.getHandle().pipeline().get( HandlerBoss.class ).setHandler( new DownstreamBridge( bungee, user, server ) ); + bungee.getPluginManager().callEvent( new ServerSwitchEvent( user ) ); thisState = State.FINISHED; diff --git a/proxy/src/main/java/net/md_5/bungee/UserConnection.java b/proxy/src/main/java/net/md_5/bungee/UserConnection.java index 52418d0d..92db22ad 100644 --- a/proxy/src/main/java/net/md_5/bungee/UserConnection.java +++ b/proxy/src/main/java/net/md_5/bungee/UserConnection.java @@ -67,8 +67,6 @@ public final class UserConnection implements ProxiedPlayer @Setter private boolean dimensionChange = true; @Getter - private final Object switchMutex = new Object(); - @Getter private final Collection pendingConnects = new HashSet<>(); /*========================================================================*/ @Getter