Skip to content

Commit 2b4b698

Browse files
authored
Merge pull request #34 from SpigotMC/master
[pull] master from SpigotMC:master
2 parents 3f4b3da + 1279cca commit 2b4b698

File tree

5 files changed

+33
-30
lines changed

5 files changed

+33
-30
lines changed

protocol/src/main/java/net/md_5/bungee/protocol/MinecraftDecoder.java

Lines changed: 20 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -12,12 +12,17 @@
1212
public class MinecraftDecoder extends MessageToMessageDecoder<ByteBuf>
1313
{
1414

15+
public MinecraftDecoder(Protocol protocol, boolean server, int protocolVersion)
16+
{
17+
this( protocol, server, protocolVersion, shouldCopyBuffer( protocol, protocolVersion ) );
18+
}
19+
1520
@Getter
16-
@Setter
1721
private Protocol protocol;
1822
private final boolean server;
1923
@Setter
2024
private int protocolVersion;
25+
private boolean copyBuffer;
2126

2227
@Override
2328
protected void decode(ChannelHandlerContext ctx, ByteBuf in, List<Object> out) throws Exception
@@ -30,8 +35,7 @@ protected void decode(ChannelHandlerContext ctx, ByteBuf in, List<Object> out) t
3035
}
3136

3237
Protocol.DirectionData prot = ( server ) ? protocol.TO_SERVER : protocol.TO_CLIENT;
33-
ByteBuf slice = in.copy(); // Can't slice this one due to EntityMap :(
34-
38+
ByteBuf slice = ( copyBuffer ) ? in.copy() : in.retainedSlice();
3539
try
3640
{
3741
int packetId = DefinedPacket.readVarInt( in );
@@ -60,4 +64,17 @@ protected void decode(ChannelHandlerContext ctx, ByteBuf in, List<Object> out) t
6064
}
6165
}
6266
}
67+
68+
public void setProtocol(Protocol protocol)
69+
{
70+
this.protocol = protocol;
71+
this.copyBuffer = shouldCopyBuffer( protocol, protocolVersion );
72+
}
73+
74+
private static boolean shouldCopyBuffer(Protocol protocol, int protocolVersion)
75+
{
76+
// We only use the entity map in game state, we can avoid many buffer copies by checking this
77+
// EntityMap is removed for 1.20.2 and up
78+
return protocol == Protocol.GAME && protocolVersion < ProtocolConstants.MINECRAFT_1_20_2;
79+
}
6380
}

proxy/src/main/java/net/md_5/bungee/connection/DownstreamBridge.java

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,7 @@
5555
import net.md_5.bungee.protocol.ProtocolConstants;
5656
import net.md_5.bungee.protocol.packet.BossBar;
5757
import net.md_5.bungee.protocol.packet.Commands;
58+
import net.md_5.bungee.protocol.packet.FinishConfiguration;
5859
import net.md_5.bungee.protocol.packet.KeepAlive;
5960
import net.md_5.bungee.protocol.packet.Kick;
6061
import net.md_5.bungee.protocol.packet.Login;
@@ -801,6 +802,16 @@ public void handle(Login login) throws Exception
801802
throw CancelSendSignal.INSTANCE;
802803
}
803804

805+
@Override
806+
public void handle(FinishConfiguration finishConfiguration) throws Exception
807+
{
808+
// the clients protocol will change to GAME after this packet
809+
con.unsafe().sendPacket( finishConfiguration );
810+
// send queued packets as early as possible
811+
con.sendQueuedPackets();
812+
throw CancelSendSignal.INSTANCE;
813+
}
814+
804815
@Override
805816
public String toString()
806817
{

proxy/src/main/java/net/md_5/bungee/connection/UpstreamBridge.java

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,6 @@
3333
import net.md_5.bungee.protocol.packet.ClientCommand;
3434
import net.md_5.bungee.protocol.packet.ClientSettings;
3535
import net.md_5.bungee.protocol.packet.CookieResponse;
36-
import net.md_5.bungee.protocol.packet.FinishConfiguration;
3736
import net.md_5.bungee.protocol.packet.KeepAlive;
3837
import net.md_5.bungee.protocol.packet.LoginAcknowledged;
3938
import net.md_5.bungee.protocol.packet.LoginPayloadResponse;
@@ -367,12 +366,6 @@ private void configureServer()
367366
}
368367
}
369368

370-
@Override
371-
public void handle(FinishConfiguration finishConfiguration) throws Exception
372-
{
373-
con.sendQueuedPackets();
374-
}
375-
376369
@Override
377370
public void handle(CookieResponse cookieResponse) throws Exception
378371
{

proxy/src/main/java/net/md_5/bungee/entitymap/EntityMap.java

Lines changed: 2 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -82,21 +82,9 @@ public static EntityMap getEntityMap(int version)
8282
case ProtocolConstants.MINECRAFT_1_19_4:
8383
case ProtocolConstants.MINECRAFT_1_20:
8484
return EntityMap_1_16_2.INSTANCE_1_19_4;
85-
case ProtocolConstants.MINECRAFT_1_20_2:
86-
return EntityMap_1_16_2.INSTANCE_1_20_2;
87-
case ProtocolConstants.MINECRAFT_1_20_3:
88-
return EntityMap_1_16_2.INSTANCE_1_20_3;
89-
case ProtocolConstants.MINECRAFT_1_20_5:
90-
case ProtocolConstants.MINECRAFT_1_21:
91-
return EntityMap_1_16_2.INSTANCE_1_20_5;
92-
case ProtocolConstants.MINECRAFT_1_21_2:
93-
return EntityMap_1_16_2.INSTANCE_1_21_2;
94-
case ProtocolConstants.MINECRAFT_1_21_4:
95-
return EntityMap_1_16_2.INSTANCE_1_21_4;
96-
case ProtocolConstants.MINECRAFT_1_21_5:
97-
return EntityMap_1_16_2.INSTANCE_1_21_5;
85+
default:
86+
return null;
9887
}
99-
throw new RuntimeException( "Version " + version + " has no entity map" );
10088
}
10189

10290
protected void addRewrite(int id, ProtocolConstants.Direction direction, boolean varint)

proxy/src/main/java/net/md_5/bungee/entitymap/EntityMap_1_16_2.java

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -20,12 +20,6 @@ class EntityMap_1_16_2 extends EntityMap
2020
static final EntityMap_1_16_2 INSTANCE_1_19 = new EntityMap_1_16_2( 0x02, 0x2F );
2121
static final EntityMap_1_16_2 INSTANCE_1_19_1 = new EntityMap_1_16_2( 0x02, 0x30 );
2222
static final EntityMap_1_16_2 INSTANCE_1_19_4 = new EntityMap_1_16_2( 0x03, 0x30 );
23-
static final EntityMap_1_16_2 INSTANCE_1_20_2 = new EntityMap_1_16_2( -1, 0x33 );
24-
static final EntityMap_1_16_2 INSTANCE_1_20_3 = new EntityMap_1_16_2( -1, 0x34 );
25-
static final EntityMap_1_16_2 INSTANCE_1_20_5 = new EntityMap_1_16_2( -1, 0x37 );
26-
static final EntityMap_1_16_2 INSTANCE_1_21_2 = new EntityMap_1_16_2( -1, 0x39 );
27-
static final EntityMap_1_16_2 INSTANCE_1_21_4 = new EntityMap_1_16_2( -1, 0x3B );
28-
static final EntityMap_1_16_2 INSTANCE_1_21_5 = new EntityMap_1_16_2( -1, 0x3C );
2923
//
3024
private final int spawnPlayerId;
3125
private final int spectateId;

0 commit comments

Comments
 (0)