3
0
Mirror von https://github.com/ViaVersion/ViaVersion.git synchronisiert 2024-11-08 17:20:24 +01:00

Replace Unpooled.buffer()

(cherry picked from commit e9159cb2de)
Dieser Commit ist enthalten in:
creeper123123321 2018-07-24 13:06:35 -03:00
Ursprung c9dab5402e
Commit 7518f8b98b
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,7 +2,6 @@ package us.myles.ViaVersion.api;
import com.google.common.base.Preconditions;
import io.netty.buffer.ByteBuf;
import io.netty.buffer.Unpooled;
import io.netty.channel.ChannelFuture;
import lombok.Getter;
import lombok.Setter;
@ -331,7 +330,7 @@ public class PacketWrapper {
// Apply other protocols
apply(Direction.OUTGOING, user().get(ProtocolInfo.class).getState(), index, protocols);
// Send
ByteBuf output = inputBuffer == null ? Unpooled.buffer() : inputBuffer.alloc().buffer();
ByteBuf output = inputBuffer == null ? user().getChannel().alloc().buffer() : inputBuffer.alloc().buffer();
writeToBuffer(output);
return output;
@ -379,7 +378,7 @@ public class PacketWrapper {
public void send() throws Exception {
if (!isCancelled()) {
// Send
ByteBuf output = inputBuffer == null ? Unpooled.buffer() : inputBuffer.alloc().buffer();
ByteBuf output = inputBuffer == null ? user().getChannel().alloc().buffer() : inputBuffer.alloc().buffer();
writeToBuffer(output);
user().sendRawPacket(output);
}
@ -474,7 +473,7 @@ public class PacketWrapper {
*/
public void sendToServer() throws Exception {
if (!isCancelled()) {
ByteBuf output = inputBuffer == null ? Unpooled.buffer() : inputBuffer.alloc().buffer();
ByteBuf output = inputBuffer == null ? user().getChannel().alloc().buffer() : inputBuffer.alloc().buffer();
writeToBuffer(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 io.netty.buffer.ByteBuf;
import io.netty.buffer.Unpooled;
import us.myles.ViaVersion.api.Via;
import us.myles.ViaVersion.api.minecraft.Environment;
import us.myles.ViaVersion.api.minecraft.chunks.Chunk;
@ -83,7 +82,7 @@ public class Chunk1_13Type extends PartialType<Chunk, ClientWorld> {
output.writeBoolean(chunk.isGroundUp());
Type.VAR_INT.write(output, chunk.getBitmask());
ByteBuf buf = Unpooled.buffer();
ByteBuf buf = output.alloc().buffer();
for (int i = 0; i < 16; i++) {
ChunkSection section = chunk.getSections()[i];
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 io.netty.buffer.ByteBuf;
import io.netty.buffer.Unpooled;
import us.myles.ViaVersion.api.minecraft.chunks.ChunkSection;
import us.myles.ViaVersion.api.minecraft.chunks.NibbleArray;
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 {
// Count amount of bytes that would be sent if the value were sent as a VarInt
ByteBuf buf = Unpooled.buffer();
Type.VAR_INT.write(buf, value);
buf.readerIndex(0);
int bitCount = buf.readableBytes();
buf.release();
return bitCount;
if ((value & (~0 << 7)) == 0)
return 1;
if ((value & (~0 << 14)) == 0)
return 2;
if ((value & (~0 << 21)) == 0)
return 3;
if ((value & (~0 << 28)) == 0)
return 4;
return 5;
}
@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 io.netty.buffer.ByteBuf;
import io.netty.buffer.Unpooled;
import us.myles.ViaVersion.api.Via;
import us.myles.ViaVersion.api.minecraft.Environment;
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());
Type.VAR_INT.write(output, chunk.getBitmask());
ByteBuf buf = Unpooled.buffer();
ByteBuf buf = output.alloc().buffer();
for (int i = 0; i < 16; i++) {
ChunkSection section = chunk.getSections()[i];
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 io.netty.buffer.ByteBuf;
import io.netty.buffer.Unpooled;
import us.myles.ViaVersion.api.minecraft.chunks.ChunkSection;
import us.myles.ViaVersion.api.minecraft.chunks.NibbleArray;
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 {
// Count amount of bytes that would be sent if the value were sent as a VarInt
ByteBuf buf = Unpooled.buffer();
Type.VAR_INT.write(buf, value);
buf.readerIndex(0);
int bitCount = buf.readableBytes();
buf.release();
return bitCount;
if ((value & (~0 << 7)) == 0)
return 1;
if ((value & (~0 << 14)) == 0)
return 2;
if ((value & (~0 << 21)) == 0)
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 io.netty.buffer.ByteBuf;
import io.netty.buffer.Unpooled;
import us.myles.ViaVersion.api.Via;
import us.myles.ViaVersion.api.minecraft.Environment;
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());
Type.VAR_INT.write(output, chunk.getBitmask());
ByteBuf buf = Unpooled.buffer();
ByteBuf buf = output.alloc().buffer();
for (int i = 0; i < 16; i++) {
ChunkSection section = chunk.getSections()[i];
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 io.netty.buffer.ByteBuf;
import io.netty.buffer.Unpooled;
import us.myles.ViaVersion.api.minecraft.chunks.ChunkSection;
import us.myles.ViaVersion.api.minecraft.chunks.NibbleArray;
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 {
// Count amount of bytes that would be sent if the value were sent as a VarInt
ByteBuf buf = Unpooled.buffer();
Type.VAR_INT.write(buf, value);
buf.readerIndex(0);
int bitCount = buf.readableBytes();
buf.release();
return bitCount;
if ((value & (~0 << 7)) == 0)
return 1;
if ((value & (~0 << 14)) == 0)
return 2;
if ((value & (~0 << 21)) == 0)
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.google.common.base.Optional;
import io.netty.buffer.ByteBuf;
import io.netty.buffer.Unpooled;
import us.myles.ViaVersion.api.PacketWrapper;
import us.myles.ViaVersion.api.Via;
import us.myles.ViaVersion.api.minecraft.Position;
@ -158,7 +157,7 @@ public class WorldPackets {
throw new IOException("transformMapChunkBulk returned the wrong object type");
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.writeToBuffer(buffer);
PacketWrapper chunkPacket = new PacketWrapper(0x21, buffer, wrapper.user());

Datei anzeigen

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