From 46cb14fc0ad3a17ff9a86a62ab4696499be5d190 Mon Sep 17 00:00:00 2001 From: Tim203 Date: Thu, 10 Oct 2019 23:16:07 +0200 Subject: [PATCH] Removed unused class and made PlayerList show every player again --- .../player/JavaPlayerListEntryTranslator.java | 7 +- .../geysermc/connector/utils/GeyserUtils.java | 401 ------------------ .../connector/utils/SkinProvider.java | 4 +- 3 files changed, 7 insertions(+), 405 deletions(-) delete mode 100644 connector/src/main/java/org/geysermc/connector/utils/GeyserUtils.java diff --git a/connector/src/main/java/org/geysermc/connector/network/translators/java/entity/player/JavaPlayerListEntryTranslator.java b/connector/src/main/java/org/geysermc/connector/network/translators/java/entity/player/JavaPlayerListEntryTranslator.java index d9877e4f..fc6f58f8 100644 --- a/connector/src/main/java/org/geysermc/connector/network/translators/java/entity/player/JavaPlayerListEntryTranslator.java +++ b/connector/src/main/java/org/geysermc/connector/network/translators/java/entity/player/JavaPlayerListEntryTranslator.java @@ -8,6 +8,7 @@ import com.nukkitx.protocol.bedrock.packet.PlayerListPacket; import org.geysermc.connector.entity.PlayerEntity; import org.geysermc.connector.network.session.GeyserSession; import org.geysermc.connector.network.translators.PacketTranslator; +import org.geysermc.connector.utils.SkinUtils; public class JavaPlayerListEntryTranslator extends PacketTranslator { @Override @@ -15,7 +16,7 @@ public class JavaPlayerListEntryTranslator extends PacketTranslator> 38), (int) (l & 0xFFF), (int) ((l << 26) >> 38) - ); - } - - public static void readPEPosition(ByteBuf from) { - readSVarInt(from); - readVarInt(from); - readSVarInt(from); - } - - public static Vector3d readLegacyPositionI(ByteBuf from) { - return Vector3d.from(from.readInt(), from.readInt(), from.readInt()); - } - - public static void writePosition(ByteBuf to, Vector3i position) { - to.writeLong(((position.getX() & 0x3FFFFFFL) << 38) | ((position.getZ() & 0x3FFFFFFL) << 12) | (position.getY() & 0xFFFL)); - } - - public static void writeLegacyPositionL(ByteBuf to, Vector3d position) { - to.writeLong((((int) position.getX() & 0x3FFFFFFL) << 38) | (((int) position.getY() & 0xFFFL) << 26) | ((int) position.getZ() & 0x3FFFFFFL)); - } - - public static void writePEPosition(ByteBuf to, Vector3d position) { - writeSVarInt(to, (int) position.getX()); - writeVarInt(to, (int) position.getY()); - writeSVarInt(to, (int) position.getZ()); - } - - public static void writeLegacyPositionB(ByteBuf to, Vector3d position) { - to.writeInt((int) position.getX()); - to.writeByte((int) position.getY()); - to.writeInt((int) position.getZ()); - } - - public static void writeLegacyPositionS(ByteBuf to, Vector3d position) { - to.writeInt((int) position.getX()); - to.writeShort((int) position.getY()); - to.writeInt((int) position.getZ()); - } - - public static void writeLegacyPositionI(ByteBuf to, Vector3d position) { - to.writeInt((int) position.getX()); - to.writeInt((int) position.getY()); - to.writeInt((int) position.getZ()); - } - - public static Vector2i readIntChunkCoord(ByteBuf from) { - return Vector2i.from(from.readInt(), from.readInt()); - } - - public static Vector2i readVarIntChunkCoord(ByteBuf from) { - return Vector2i.from(readVarInt(from), readVarInt(from)); - } - - public static void writeIntChunkCoord(ByteBuf to, Vector2i chunk) { - to.writeInt(chunk.getX()); - to.writeInt(chunk.getY()); - } - - public static Vector2i readPEChunkCoord(ByteBuf from) { - return Vector2i.from(readSVarInt(from), readSVarInt(from)); - } - - public static void writePEChunkCoord(ByteBuf to, Vector2i chunk) { - writeSVarInt(to, chunk.getX()); - writeSVarInt(to, chunk.getY()); - } - - public static int readLocalCoord(ByteBuf from) { - return from.readUnsignedShort(); - } - - public static void writeLocalCoord(ByteBuf to, int coord) { - to.writeShort(coord); - } - - public static void writeVarIntChunkCoord(ByteBuf to, Vector2i chunk) { - writeVarInt(to, chunk.getX()); - writeVarInt(to, chunk.getY()); - } - - public static final int MAX_VARINT_LENGTH = 5; - - public static void writeFixedSizeVarInt(ByteBuf to, int i) { - int writerIndex = to.writerIndex(); - while ((i & 0xFFFFFF80) != 0x0) { - to.writeByte(i | 0x80); - i >>>= 7; - - } - int paddingBytes = MAX_VARINT_LENGTH - (to.writerIndex() - writerIndex) - 1; - - if (paddingBytes == 0) { - to.writeByte(i); - } else { - to.writeByte(i | 0x80); - while (--paddingBytes > 0) { - to.writeByte(0x80); - } - to.writeByte(0); - } - } - - public static int readVarInt(ByteBuf from) { - int value = 0; - int length = 0; - - byte part; - do { - part = from.readByte(); - value |= (part & 0x7F) << (length++ * 7); - if (length > MAX_VARINT_LENGTH) { - throw new DecoderException("VarInt too big"); - } - } while (part < 0); - return value; - } - - public static void writeVarInt(ByteBuf to, int i) { - while ((i & 0xFFFFFF80) != 0x0) { - to.writeByte(i | 0x80); - i >>>= 7; - } - to.writeByte(i); - } - - public static int readSVarInt(ByteBuf from) { - int varint = readVarInt(from); - return (varint >> 1) ^ -(varint & 1); - } - - - public static void writeSVarInt(ByteBuf to, int varint) { - writeVarInt(to, (varint << 1) ^ (varint >> 31)); - } - - public static long readVarLong(ByteBuf from) { - long varlong = 0L; - int length = 0; - - byte part; - do { - part = from.readByte(); - varlong |= (part & 0x7F) << (length++ * 7); - - if (length > 10) { - throw new RuntimeException("VarLong too big"); - } - } while ((part & 0x80) == 0x80); - return varlong; - } - - public static void writeVarLong(ByteBuf to, long varlong) { - while ((varlong & 0xFFFFFFFFFFFFFF80L) != 0x0L) { - to.writeByte((int) (varlong & 0x7FL) | 0x80); - varlong >>>= 7; - } - to.writeByte((int) varlong); - } - - public static long readSVarLong(ByteBuf from) { - long varlong = readVarLong(from); - return (varlong >> 1) ^ -(varlong & 1); - } - - - public static void writeSVarLong(ByteBuf to, long varlong) { - writeVarLong(to, (varlong << 1) ^ (varlong >> 63)); - - } - - public static ByteBuf readShortByteArraySlice(ByteBuf from, int limit) { - int length = from.readShort(); - checkLimit(length, limit); - return from.readSlice(length); - - } - - @SuppressWarnings("unchecked") - public static T[] readShortTArray(ByteBuf from, Class tclass, Function elementReader) { - T[] array = (T[]) Array.newInstance(tclass, from.readShort()); - for (int i = 0; i < array.length; i++) { - array[i] = elementReader.apply(from); - } - return array; - } - - public static byte[] readVarIntByteArray(ByteBuf from) { - return readBytes(from, readVarInt(from)); - } - - public static ByteBuf readVarIntByteArraySlice(ByteBuf from, int limit) { - int length = readVarInt(from); - checkLimit(length, limit); - return from.readSlice(length); - } - - public static ByteBuf readVarIntByteArraySlice(ByteBuf from) { - return from.readSlice(readVarInt(from)); - } - - @SuppressWarnings("unchecked") - public static T[] readVarIntTArray(ByteBuf from, Class tclass, Function elementReader) { - T[] array = (T[]) Array.newInstance(tclass, readVarInt(from)); - for (int i = 0; i < array.length; i++) { - array[i] = elementReader.apply(from); - } - return array; - } - - public static int[] readVarIntVarIntArray(ByteBuf from) { - int[] array = new int[readVarInt(from)]; - for (int i = 0; i < array.length; i++) { - array[i] = readVarInt(from); - } - return array; - } - - public static void writeShortByteArray(ByteBuf to, ByteBuf data) { - to.writeShort(data.readableBytes()); - to.writeBytes(data); - } - - public static void writeShortByteArray(ByteBuf to, byte[] data) { - to.writeShort(data.length); - to.writeBytes(data); - } - - public static void writeShortByteArray(ByteBuf to, Consumer dataWriter) { - writeLengthPrefixedBytes(to, ByteBuf::writeShort, dataWriter); - } - - - public static void writeShortTArray(ByteBuf to, T[] array, BiConsumer elementWriter) { - to.writeShort(array.length); - for (T element : array) { - elementWriter.accept(to, element); - } - } - - public static void writeVarIntByteArray(ByteBuf to, ByteBuf data) { - writeVarInt(to, data.readableBytes()); - to.writeBytes(data); - } - - - public static void writeVarIntByteArray(ByteBuf to, byte[] data) { - writeVarInt(to, data.length); - to.writeBytes(data); - } - - public static void writeVarIntByteArray(ByteBuf to, Consumer dataWriter) { - writeLengthPrefixedBytes(to, GeyserUtils::writeFixedSizeVarInt, dataWriter); - } - - public static void writeVarIntTArray(ByteBuf to, ToIntFunction arrayWriter) { - writeSizePrefixedData(to, GeyserUtils::writeFixedSizeVarInt, arrayWriter); - } - - public static void writeVarIntTArray(ByteBuf to, T[] array, BiConsumer elementWriter) { - writeVarInt(to, array.length); - for (T element : array) { - elementWriter.accept(to, element); - } - } - - public static void writeVarIntTArray(ByteBuf to, List array, BiConsumer elementWriter) { - writeVarInt(to, array.size()); - for (T element : array) { - elementWriter.accept(to, element); - } - } - - public static void writeVarIntEnum(ByteBuf to, Enum e) { - writeVarInt(to, e.ordinal()); - } - - public static void writeByteEnum(ByteBuf to, Enum e) { - to.writeByte(e.ordinal()); - } - - public static UUID readUUID(ByteBuf from) { - return new UUID(from.readLong(), from.readLong()); - } - - public static void writeUUID(ByteBuf to, UUID uuid) { - to.writeLong(uuid.getMostSignificantBits()); - to.writeLong(uuid.getLeastSignificantBits()); - } - - public static void writePEUUID(ByteBuf to, UUID uuid) { - to.writeLongLE(uuid.getMostSignificantBits()); - to.writeLongLE(uuid.getLeastSignificantBits()); - } - - public static byte[] readAllBytes(ByteBuf buf) { - return readBytes(buf, buf.readableBytes()); - } - - public static ByteBuf readAllBytesSlice(ByteBuf from) { - return from.readSlice(from.readableBytes()); - } - - public static ByteBuf readAllBytesSlice(ByteBuf buf, int limit) { - checkLimit(buf.readableBytes(), limit); - return readAllBytesSlice(buf); - } - - public static byte[] readBytes(ByteBuf buf, int length) { - byte[] result = new byte[length]; - buf.readBytes(result); - return result; - } - - protected static void checkLimit(int length, int limit) { - if (length > limit) { - throw new DecoderException(MessageFormat.format("Size {0} is bigger than allowed {1}", length, limit)); - } - } - - public static void writeLengthPrefixedBytes(ByteBuf to, ObjIntConsumer lengthWriter, Consumer dataWriter) { - int lengthWriterIndex = to.writerIndex(); - lengthWriter.accept(to, 0); - int writerIndexDataStart = to.writerIndex(); - dataWriter.accept(to); - int writerIndexDataEnd = to.writerIndex(); - to.writerIndex(lengthWriterIndex); - lengthWriter.accept(to, writerIndexDataEnd - writerIndexDataStart); - to.writerIndex(writerIndexDataEnd); - } - - public static void writeSizePrefixedData(ByteBuf to, ObjIntConsumer sizeWriter, ToIntFunction dataWriter) { - int sizeWriterIndex = to.writerIndex(); - sizeWriter.accept(to, 0); - int size = dataWriter.applyAsInt(to); - int writerIndexDataEnd = to.writerIndex(); - to.writerIndex(sizeWriterIndex); - sizeWriter.accept(to, size); - to.writerIndex(writerIndexDataEnd); - } - - - private static int getAnvilIndex(int x, int y, int z) { - return (y << 8) + (z << 4) + x; - } - - public static boolean instanceOf(Class clazz, Object o) { - try { - T t = (T) o; - return true; - } catch (Exception e) { - return false; - } - } -} diff --git a/connector/src/main/java/org/geysermc/connector/utils/SkinProvider.java b/connector/src/main/java/org/geysermc/connector/utils/SkinProvider.java index 3483a927..2d2aceab 100644 --- a/connector/src/main/java/org/geysermc/connector/utils/SkinProvider.java +++ b/connector/src/main/java/org/geysermc/connector/utils/SkinProvider.java @@ -42,11 +42,11 @@ public class SkinProvider { } public static Skin getCachedSkin(UUID uuid) { - return cachedSkins.get(uuid); + return cachedSkins.getOrDefault(uuid, EMPTY_SKIN); } public static Cape getCachedCape(String capeUrl) { - return cachedCapes.get(capeUrl); + return capeUrl != null ? cachedCapes.getOrDefault(capeUrl, EMPTY_CAPE) : EMPTY_CAPE; } public static CompletableFuture requestSkinAndCape(UUID playerId, String skinUrl, String capeUrl) {