ProtocolLib

3M Downloads

Cannot invoke "java.lang.Class.getConstructors()" because "com.comphenix.protocol.wrappers.WrappedDataValue.HANDLE_TYPE" is null

abcdef-007 opened this issue ยท 0 comments

commented

Make sure you're doing the following

  • You're using the latest build for your server version
  • This isn't an issue caused by another plugin
  • You've checked for duplicate issues
  • You didn't use /reload

Describe the question
How can I change a players' skin using packets? I am getting the following error: NullPointerException: Cannot invoke "java.lang.Class.getConstructors()" because "com.comphenix.protocol.wrappers.WrappedDataValue.HANDLE_TYPE" is null

Expected behavior
Not getting an error.

Code

public static PacketContainer changeSkinPacket(Player player) {
    PacketContainer packet = new PacketContainer(PacketType.Play.Server.ENTITY_METADATA);
    packet.getIntegers().write(0, player.getEntityId());
    WrappedDataWatcher watcher = new WrappedDataWatcher();
    Serializer serializer = Registry.get(Byte.class);
    if (player != null) {
        watcher.setEntity(player);
    }

    // Show all skin overlays.
    watcher.setObject(17, serializer, (byte) (0x01 | 0x02 | 0x04 | 0x08 | 0x10 | 0x20 | 0x40));

    final List<WrappedDataValue> wrappedDataValueList = Lists.newArrayList();
    watcher.getWatchableObjects().stream().filter(Objects::nonNull).forEach(entry -> {
        final WrappedDataWatcher.WrappedDataWatcherObject dataWatcherObject = entry.getWatcherObject();
        wrappedDataValueList.add(new WrappedDataValue(dataWatcherObject.getIndex(), dataWatcherObject.getSerializer(), entry.getRawValue()));
    });
    packet.getDataValueCollectionModifier().write(0, wrappedDataValueList);
    return packet;
}

ProtocolLibrary.getProtocolManager().sendServerPacket(player, this.changeSkinPacket(hiddenPlayer));

Additional context
Server version 1.19 and plugin version 5.1.0