Only instantiate packets for the required versions

This commit is contained in:
Jesse Boyd 2016-12-15 18:32:19 +11:00
parent 1b07dbae1d
commit bde4749e2c
No known key found for this signature in database
GPG Key ID: 59F1DE6293AF6E1F

View File

@ -275,45 +275,49 @@ public class BukkitQueue17 extends BukkitQueue_0<Chunk, ChunkSection[], ChunkSec
return; return;
} }
// Send chunks // Send chunks
int version = -1;
PacketPlayOutMapChunk packet = null;
Map<Integer, PacketPlayOutMapChunk> packets = null;
int mask = fc.getBitMask(); int mask = fc.getBitMask();
if (mask == 0 || mask == 65535 && hasEntities(nmsChunk)) { if (mask == 0 || mask == 65535 && hasEntities(nmsChunk)) {
PacketPlayOutMapChunk packet = new PacketPlayOutMapChunk(nmsChunk, false, 65280, 5);
HashMap<Integer, PacketPlayOutMapChunk> customPackets = null;
for (EntityPlayer player : players) { for (EntityPlayer player : players) {
int version = player.playerConnection.networkManager.getVersion(); int currentVersion = player.playerConnection.networkManager.getVersion();
if (version != 5) { if (currentVersion != version) {
if (customPackets == null) { if (packet != null) {
customPackets = new HashMap<>(); if (packets == null) {
packets = new HashMap<>();
}
packets.put(version, packet);
packet = packets.get(currentVersion);
} }
PacketPlayOutMapChunk customPacket = customPackets.get(version); version = currentVersion;
if (customPacket == null) { if (packet == null) {
customPacket = new PacketPlayOutMapChunk(nmsChunk, false, 65280, version); packet = new PacketPlayOutMapChunk(nmsChunk, false, 65280, version);
customPackets.put(version, customPacket);
} }
player.playerConnection.sendPacket(customPacket);
} else {
player.playerConnection.sendPacket(packet);
} }
}
mask = 255;
}
PacketPlayOutMapChunk packet = new PacketPlayOutMapChunk(nmsChunk, false, mask, 5);
HashMap<Integer, PacketPlayOutMapChunk> customPackets = null;
for (EntityPlayer player : players) {
int version = player.playerConnection.networkManager.getVersion();
if (version != 5) {
if (customPackets == null) {
customPackets = new HashMap<>();
}
PacketPlayOutMapChunk customPacket = customPackets.get(version);
if (customPacket == null) {
customPacket = new PacketPlayOutMapChunk(nmsChunk, false, mask, version);
customPackets.put(version, customPacket);
}
player.playerConnection.sendPacket(customPacket);
} else {
player.playerConnection.sendPacket(packet); player.playerConnection.sendPacket(packet);
} }
mask = 255;
version = -1;
packet = null;
packets = null;
}
for (EntityPlayer player : players) {
int currentVersion = player.playerConnection.networkManager.getVersion();
if (currentVersion != version) {
if (packet != null) {
if (packets == null) {
packets = new HashMap<>();
}
packets.put(version, packet);
packet = packets.get(currentVersion);
}
version = currentVersion;
if (packet == null) {
packet = new PacketPlayOutMapChunk(nmsChunk, false, mask, version);
}
}
player.playerConnection.sendPacket(packet);
} }
} catch (Throwable e) { } catch (Throwable e) {
MainUtil.handleError(e); MainUtil.handleError(e);