3
0
Mirror von https://github.com/ViaVersion/ViaVersion.git synchronisiert 2024-12-27 00:22:51 +01:00

Merge pull request #942 from creeper123123321/buffer-changes

Replace Unpooled.buffer()
Dieser Commit ist enthalten in:
Myles 2018-08-12 20:27:44 +01:00 committet von GitHub
Commit e4a99c4a3d
Es konnte kein GPG-Schlüssel zu dieser Signatur gefunden werden
GPG-Schlüssel-ID: 4AEE18F83AFDEB23
9 geänderte Dateien mit 36 neuen und 35 gelöschten Zeilen

Datei anzeigen

@ -2,7 +2,6 @@ package us.myles.ViaVersion.api;
import com.google.common.base.Preconditions; import com.google.common.base.Preconditions;
import io.netty.buffer.ByteBuf; import io.netty.buffer.ByteBuf;
import io.netty.buffer.Unpooled;
import io.netty.channel.ChannelFuture; import io.netty.channel.ChannelFuture;
import lombok.Getter; import lombok.Getter;
import lombok.Setter; import lombok.Setter;
@ -331,7 +330,7 @@ public class PacketWrapper {
// Apply other protocols // Apply other protocols
apply(Direction.OUTGOING, user().get(ProtocolInfo.class).getState(), index, protocols); apply(Direction.OUTGOING, user().get(ProtocolInfo.class).getState(), index, protocols);
// Send // Send
ByteBuf output = inputBuffer == null ? Unpooled.buffer() : inputBuffer.alloc().buffer(); ByteBuf output = inputBuffer == null ? user().getChannel().alloc().buffer() : inputBuffer.alloc().buffer();
writeToBuffer(output); writeToBuffer(output);
return output; return output;
@ -379,7 +378,7 @@ public class PacketWrapper {
public void send() throws Exception { public void send() throws Exception {
if (!isCancelled()) { if (!isCancelled()) {
// Send // Send
ByteBuf output = inputBuffer == null ? Unpooled.buffer() : inputBuffer.alloc().buffer(); ByteBuf output = inputBuffer == null ? user().getChannel().alloc().buffer() : inputBuffer.alloc().buffer();
writeToBuffer(output); writeToBuffer(output);
user().sendRawPacket(output); user().sendRawPacket(output);
} }
@ -474,7 +473,7 @@ public class PacketWrapper {
*/ */
public void sendToServer() throws Exception { public void sendToServer() throws Exception {
if (!isCancelled()) { if (!isCancelled()) {
ByteBuf output = inputBuffer == null ? Unpooled.buffer() : inputBuffer.alloc().buffer(); ByteBuf output = inputBuffer == null ? user().getChannel().alloc().buffer() : inputBuffer.alloc().buffer();
writeToBuffer(output); writeToBuffer(output);
user().getChannel().pipeline().context(Via.getManager().getInjector().getDecoderName()).fireChannelRead(output); user().getChannel().pipeline().context(Via.getManager().getInjector().getDecoderName()).fireChannelRead(output);

Datei anzeigen

@ -2,7 +2,6 @@ package us.myles.ViaVersion.protocols.protocol1_13to1_12_2.types;
import com.github.steveice10.opennbt.tag.builtin.CompoundTag; import com.github.steveice10.opennbt.tag.builtin.CompoundTag;
import io.netty.buffer.ByteBuf; import io.netty.buffer.ByteBuf;
import io.netty.buffer.Unpooled;
import us.myles.ViaVersion.api.Via; import us.myles.ViaVersion.api.Via;
import us.myles.ViaVersion.api.minecraft.Environment; import us.myles.ViaVersion.api.minecraft.Environment;
import us.myles.ViaVersion.api.minecraft.chunks.Chunk; import us.myles.ViaVersion.api.minecraft.chunks.Chunk;
@ -83,7 +82,7 @@ public class Chunk1_13Type extends PartialType<Chunk, ClientWorld> {
output.writeBoolean(chunk.isGroundUp()); output.writeBoolean(chunk.isGroundUp());
Type.VAR_INT.write(output, chunk.getBitmask()); Type.VAR_INT.write(output, chunk.getBitmask());
ByteBuf buf = Unpooled.buffer(); ByteBuf buf = output.alloc().buffer();
for (int i = 0; i < 16; i++) { for (int i = 0; i < 16; i++) {
ChunkSection section = chunk.getSections()[i]; ChunkSection section = chunk.getSections()[i];
if (section == null) continue; // Section not set if (section == null) continue; // Section not set

Datei anzeigen

@ -2,7 +2,6 @@ package us.myles.ViaVersion.protocols.protocol1_9_1_2to1_9_3_4.chunks;
import com.google.common.collect.Lists; import com.google.common.collect.Lists;
import io.netty.buffer.ByteBuf; import io.netty.buffer.ByteBuf;
import io.netty.buffer.Unpooled;
import us.myles.ViaVersion.api.minecraft.chunks.ChunkSection; import us.myles.ViaVersion.api.minecraft.chunks.ChunkSection;
import us.myles.ViaVersion.api.minecraft.chunks.NibbleArray; import us.myles.ViaVersion.api.minecraft.chunks.NibbleArray;
import us.myles.ViaVersion.api.type.Type; import us.myles.ViaVersion.api.type.Type;
@ -351,12 +350,15 @@ public class ChunkSection1_9_3_4 implements ChunkSection {
private int countBytes(int value) throws Exception { private int countBytes(int value) throws Exception {
// Count amount of bytes that would be sent if the value were sent as a VarInt // Count amount of bytes that would be sent if the value were sent as a VarInt
ByteBuf buf = Unpooled.buffer(); if ((value & (~0 << 7)) == 0)
Type.VAR_INT.write(buf, value); return 1;
buf.readerIndex(0); if ((value & (~0 << 14)) == 0)
int bitCount = buf.readableBytes(); return 2;
buf.release(); if ((value & (~0 << 21)) == 0)
return bitCount; return 3;
if ((value & (~0 << 28)) == 0)
return 4;
return 5;
} }
@Override @Override

Datei anzeigen

@ -2,7 +2,6 @@ package us.myles.ViaVersion.protocols.protocol1_9_1_2to1_9_3_4.types;
import com.github.steveice10.opennbt.tag.builtin.CompoundTag; import com.github.steveice10.opennbt.tag.builtin.CompoundTag;
import io.netty.buffer.ByteBuf; import io.netty.buffer.ByteBuf;
import io.netty.buffer.Unpooled;
import us.myles.ViaVersion.api.Via; import us.myles.ViaVersion.api.Via;
import us.myles.ViaVersion.api.minecraft.Environment; import us.myles.ViaVersion.api.minecraft.Environment;
import us.myles.ViaVersion.api.minecraft.chunks.Chunk; import us.myles.ViaVersion.api.minecraft.chunks.Chunk;
@ -81,7 +80,7 @@ public class Chunk1_9_3_4Type extends PartialType<Chunk, ClientWorld> {
output.writeBoolean(chunk.isGroundUp()); output.writeBoolean(chunk.isGroundUp());
Type.VAR_INT.write(output, chunk.getBitmask()); Type.VAR_INT.write(output, chunk.getBitmask());
ByteBuf buf = Unpooled.buffer(); ByteBuf buf = output.alloc().buffer();
for (int i = 0; i < 16; i++) { for (int i = 0; i < 16; i++) {
ChunkSection section = chunk.getSections()[i]; ChunkSection section = chunk.getSections()[i];
if (section == null) continue; // Section not set if (section == null) continue; // Section not set

Datei anzeigen

@ -2,7 +2,6 @@ package us.myles.ViaVersion.protocols.protocol1_9_3to1_9_1_2.chunks;
import com.google.common.collect.Lists; import com.google.common.collect.Lists;
import io.netty.buffer.ByteBuf; import io.netty.buffer.ByteBuf;
import io.netty.buffer.Unpooled;
import us.myles.ViaVersion.api.minecraft.chunks.ChunkSection; import us.myles.ViaVersion.api.minecraft.chunks.ChunkSection;
import us.myles.ViaVersion.api.minecraft.chunks.NibbleArray; import us.myles.ViaVersion.api.minecraft.chunks.NibbleArray;
import us.myles.ViaVersion.api.type.Type; import us.myles.ViaVersion.api.type.Type;
@ -348,11 +347,14 @@ public class ChunkSection1_9_1_2 implements ChunkSection {
private int countBytes(int value) throws Exception { private int countBytes(int value) throws Exception {
// Count amount of bytes that would be sent if the value were sent as a VarInt // Count amount of bytes that would be sent if the value were sent as a VarInt
ByteBuf buf = Unpooled.buffer(); if ((value & (~0 << 7)) == 0)
Type.VAR_INT.write(buf, value); return 1;
buf.readerIndex(0); if ((value & (~0 << 14)) == 0)
int bitCount = buf.readableBytes(); return 2;
buf.release(); if ((value & (~0 << 21)) == 0)
return bitCount; return 3;
if ((value & (~0 << 28)) == 0)
return 4;
return 5;
} }
} }

Datei anzeigen

@ -2,7 +2,6 @@ package us.myles.ViaVersion.protocols.protocol1_9_3to1_9_1_2.types;
import com.github.steveice10.opennbt.tag.builtin.CompoundTag; import com.github.steveice10.opennbt.tag.builtin.CompoundTag;
import io.netty.buffer.ByteBuf; import io.netty.buffer.ByteBuf;
import io.netty.buffer.Unpooled;
import us.myles.ViaVersion.api.Via; import us.myles.ViaVersion.api.Via;
import us.myles.ViaVersion.api.minecraft.Environment; import us.myles.ViaVersion.api.minecraft.Environment;
import us.myles.ViaVersion.api.minecraft.chunks.Chunk; import us.myles.ViaVersion.api.minecraft.chunks.Chunk;
@ -79,7 +78,7 @@ public class Chunk1_9_1_2Type extends PartialType<Chunk, ClientWorld> {
output.writeBoolean(chunk.isGroundUp()); output.writeBoolean(chunk.isGroundUp());
Type.VAR_INT.write(output, chunk.getBitmask()); Type.VAR_INT.write(output, chunk.getBitmask());
ByteBuf buf = Unpooled.buffer(); ByteBuf buf = output.alloc().buffer();
for (int i = 0; i < 16; i++) { for (int i = 0; i < 16; i++) {
ChunkSection section = chunk.getSections()[i]; ChunkSection section = chunk.getSections()[i];
if (section == null) continue; // Section not set if (section == null) continue; // Section not set

Datei anzeigen

@ -2,7 +2,6 @@ package us.myles.ViaVersion.protocols.protocol1_9to1_8.chunks;
import com.google.common.collect.Lists; import com.google.common.collect.Lists;
import io.netty.buffer.ByteBuf; import io.netty.buffer.ByteBuf;
import io.netty.buffer.Unpooled;
import us.myles.ViaVersion.api.minecraft.chunks.ChunkSection; import us.myles.ViaVersion.api.minecraft.chunks.ChunkSection;
import us.myles.ViaVersion.api.minecraft.chunks.NibbleArray; import us.myles.ViaVersion.api.minecraft.chunks.NibbleArray;
import us.myles.ViaVersion.api.type.Type; import us.myles.ViaVersion.api.type.Type;
@ -251,11 +250,14 @@ public class ChunkSection1_9to1_8 implements ChunkSection {
private int countBytes(int value) throws Exception { private int countBytes(int value) throws Exception {
// Count amount of bytes that would be sent if the value were sent as a VarInt // Count amount of bytes that would be sent if the value were sent as a VarInt
ByteBuf buf = Unpooled.buffer(); if ((value & (~0 << 7)) == 0)
Type.VAR_INT.write(buf, value); return 1;
buf.readerIndex(0); if ((value & (~0 << 14)) == 0)
int bitCount = buf.readableBytes(); return 2;
buf.release(); if ((value & (~0 << 21)) == 0)
return bitCount; return 3;
if ((value & (~0 << 28)) == 0)
return 4;
return 5;
} }
} }

Datei anzeigen

@ -4,7 +4,6 @@ import com.github.steveice10.opennbt.tag.builtin.CompoundTag;
import com.github.steveice10.opennbt.tag.builtin.StringTag; import com.github.steveice10.opennbt.tag.builtin.StringTag;
import com.google.common.base.Optional; import com.google.common.base.Optional;
import io.netty.buffer.ByteBuf; import io.netty.buffer.ByteBuf;
import io.netty.buffer.Unpooled;
import us.myles.ViaVersion.api.PacketWrapper; import us.myles.ViaVersion.api.PacketWrapper;
import us.myles.ViaVersion.api.Via; import us.myles.ViaVersion.api.Via;
import us.myles.ViaVersion.api.minecraft.Position; import us.myles.ViaVersion.api.minecraft.Position;
@ -158,11 +157,12 @@ public class WorldPackets {
throw new IOException("transformMapChunkBulk returned the wrong object type"); throw new IOException("transformMapChunkBulk returned the wrong object type");
PacketWrapper output = (PacketWrapper) obj; PacketWrapper output = (PacketWrapper) obj;
ByteBuf buffer = Unpooled.buffer(); ByteBuf buffer = wrapper.user().getChannel().alloc().buffer();
output.setId(-1); // -1 for no writing of id output.setId(-1); // -1 for no writing of id
output.writeToBuffer(buffer); output.writeToBuffer(buffer);
PacketWrapper chunkPacket = new PacketWrapper(0x21, buffer, wrapper.user()); PacketWrapper chunkPacket = new PacketWrapper(0x21, buffer, wrapper.user());
chunkPacket.send(Protocol1_9TO1_8.class, false, true); chunkPacket.send(Protocol1_9TO1_8.class, false, true);
buffer.release();
} }
} }
}); });

Datei anzeigen

@ -2,7 +2,6 @@ package us.myles.ViaVersion.protocols.protocol1_9to1_8.types;
import com.github.steveice10.opennbt.tag.builtin.CompoundTag; import com.github.steveice10.opennbt.tag.builtin.CompoundTag;
import io.netty.buffer.ByteBuf; import io.netty.buffer.ByteBuf;
import io.netty.buffer.Unpooled;
import us.myles.ViaVersion.api.Via; import us.myles.ViaVersion.api.Via;
import us.myles.ViaVersion.api.minecraft.chunks.Chunk; import us.myles.ViaVersion.api.minecraft.chunks.Chunk;
import us.myles.ViaVersion.api.type.PartialType; import us.myles.ViaVersion.api.type.PartialType;
@ -154,7 +153,7 @@ public class ChunkType extends PartialType<Chunk, ClientChunks> {
output.writeByte(chunk.isGroundUp() ? 0x01 : 0x00); output.writeByte(chunk.isGroundUp() ? 0x01 : 0x00);
Type.VAR_INT.write(output, chunk.getPrimaryBitmask()); Type.VAR_INT.write(output, chunk.getPrimaryBitmask());
ByteBuf buf = Unpooled.buffer(); ByteBuf buf = output.alloc().buffer();
for (int i = 0; i < SECTION_COUNT; i++) { for (int i = 0; i < SECTION_COUNT; i++) {
ChunkSection1_9to1_8 section = chunk.getSections()[i]; ChunkSection1_9to1_8 section = chunk.getSections()[i];
if (section == null) continue; // Section not set if (section == null) continue; // Section not set