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

Revert "Replace Unpooled.buffer()"

This reverts commit e9159cb
Dieser Commit ist enthalten in:
creeper123123321 2018-07-29 08:56:26 -03:00
Ursprung ca23750c28
Commit e5169378fc
Es konnte kein GPG-Schlüssel zu dieser Signatur gefunden werden
GPG-Schlüssel-ID: 0AC57D54786721D1
9 geänderte Dateien mit 35 neuen und 35 gelöschten Zeilen

Datei anzeigen

@ -2,6 +2,7 @@ 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;
@ -330,7 +331,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 ? user().getChannel().alloc().buffer() : inputBuffer.alloc().buffer(); ByteBuf output = inputBuffer == null ? Unpooled.buffer() : inputBuffer.alloc().buffer();
writeToBuffer(output); writeToBuffer(output);
return output; return output;
@ -378,7 +379,7 @@ public class PacketWrapper {
public void send() throws Exception { public void send() throws Exception {
if (!isCancelled()) { if (!isCancelled()) {
// Send // Send
ByteBuf output = inputBuffer == null ? user().getChannel().alloc().buffer() : inputBuffer.alloc().buffer(); ByteBuf output = inputBuffer == null ? Unpooled.buffer() : inputBuffer.alloc().buffer();
writeToBuffer(output); writeToBuffer(output);
user().sendRawPacket(output); user().sendRawPacket(output);
} }
@ -473,7 +474,7 @@ public class PacketWrapper {
*/ */
public void sendToServer() throws Exception { public void sendToServer() throws Exception {
if (!isCancelled()) { if (!isCancelled()) {
ByteBuf output = inputBuffer == null ? user().getChannel().alloc().buffer() : inputBuffer.alloc().buffer(); ByteBuf output = inputBuffer == null ? Unpooled.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,6 +2,7 @@ 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;
@ -82,7 +83,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 = output.alloc().buffer(); ByteBuf buf = Unpooled.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,6 +2,7 @@ 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;
@ -350,15 +351,12 @@ 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
if ((value & (~0 << 7)) == 0) ByteBuf buf = Unpooled.buffer();
return 1; Type.VAR_INT.write(buf, value);
if ((value & (~0 << 14)) == 0) buf.readerIndex(0);
return 2; int bitCount = buf.readableBytes();
if ((value & (~0 << 21)) == 0) buf.release();
return 3; return bitCount;
if ((value & (~0 << 28)) == 0)
return 4;
return 5;
} }
@Override @Override

Datei anzeigen

@ -2,6 +2,7 @@ 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;
@ -80,7 +81,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 = output.alloc().buffer(); ByteBuf buf = Unpooled.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,6 +2,7 @@ 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;
@ -347,14 +348,11 @@ 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
if ((value & (~0 << 7)) == 0) ByteBuf buf = Unpooled.buffer();
return 1; Type.VAR_INT.write(buf, value);
if ((value & (~0 << 14)) == 0) buf.readerIndex(0);
return 2; int bitCount = buf.readableBytes();
if ((value & (~0 << 21)) == 0) buf.release();
return 3; return bitCount;
if ((value & (~0 << 28)) == 0)
return 4;
return 5;
} }
} }

Datei anzeigen

@ -2,6 +2,7 @@ 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;
@ -78,7 +79,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 = output.alloc().buffer(); ByteBuf buf = Unpooled.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,6 +2,7 @@ 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;
@ -250,14 +251,11 @@ 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
if ((value & (~0 << 7)) == 0) ByteBuf buf = Unpooled.buffer();
return 1; Type.VAR_INT.write(buf, value);
if ((value & (~0 << 14)) == 0) buf.readerIndex(0);
return 2; int bitCount = buf.readableBytes();
if ((value & (~0 << 21)) == 0) buf.release();
return 3; return bitCount;
if ((value & (~0 << 28)) == 0)
return 4;
return 5;
} }
} }

Datei anzeigen

@ -4,6 +4,7 @@ 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;
@ -157,7 +158,7 @@ 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 = wrapper.user().getChannel().alloc().buffer(); ByteBuf buffer = Unpooled.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());

Datei anzeigen

@ -2,6 +2,7 @@ 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;
@ -153,7 +154,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 = output.alloc().buffer(); ByteBuf buf = Unpooled.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