1.13.2 RightArmPose with ProtocolLib

Discussion in 'Spigot Plugin Development' started by Lorenz_, Jan 12, 2020.

  1. Hello,

    I want to change the "right arm pose" of an armorstand entity.
    When using the bukkit method setRightArmPose everything works fine.
    Now, i want this change to be visible only for certain players.
    I understand that this causes the minecraft server to send the packet ENTITY_METADATA with a vector inside a datawatcher object. The index 14 is for the right arm pose slot.
    Now i try to imitage this behaviour with ProtocolLib.

    This is my code:
    Code (Java):
    private void sendRightArmPose(ProtocolManager protocolManager, int entityId, Vector3F vector, Player player) {
            PacketContainer packet = protocolManager.createPacket(PacketType.Play.Server.ENTITY_METADATA);
            WrapperPlayServerEntityMetadata metadata = new WrapperPlayServerEntityMetadata(packet);
            metadata.setEntityID(entityId);
            List<WrappedWatchableObject> list = new ArrayList<>();
            WrappedWatchableObject object = new WrappedWatchableObject(14, vector);
            object.setDirtyState(true);
            list.add(object);
            metadata.setMetadata(list);
            try {
                protocolManager.sendServerPacket(player, packet);
            } catch (InvocationTargetException e) {
                e.printStackTrace();
            }
        }
    Unfortunally, this throws a NullPointerException and the player gets kicked from the server.

    The stack trace of the error is:
    Code (Java):
    java.lang.NullPointerException
           at net.minecraft.server.v1_13_R2.DataWatcher.a(DataWatcher.java:225)
           at net.minecraft.server.v1_13_R2.DataWatcher.a(DataWatcher.java:148)
           at net.minecraft.server.v1_13_R2.PacketPlayOutEntityMetadata.b(SourceFile:37)
           at net.minecraft.server.v1_13_R2.PacketEncoder.encode(PacketEncoder.java:42)
           at net.minecraft.server.v1_13_R2.PacketEncoder.encode(PacketEncoder.java:12)
           at sun.reflect.GeneratedMethodAccessor13.invoke(Unknown Source)
           at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
           at java.lang.reflect.Method.invoke(Method.java:498)
           at com.comphenix.protocol.injector.netty.ChannelInjector.encode(ChannelInjector.java:473)
           at com.comphenix.protocol.injector.netty.ChannelInjector.access$100(ChannelInjector.java:64)
           at com.comphenix.protocol.injector.netty.ChannelInjector$1.encode(ChannelInjector.java:243)
           at io.netty.handler.codec.MessageToByteEncoder.write(MessageToByteEncoder.java:107)
           at com.comphenix.protocol.injector.netty.ChannelInjector$1.write(ChannelInjector.java:249)
           at io.netty.channel.AbstractChannelHandlerContext.invokeWrite0(AbstractChannelHandlerContext.java:738)
           at io.netty.channel.AbstractChannelHandlerContext.invokeWrite(AbstractChannelHandlerContext.java:730)
           at io.netty.channel.AbstractChannelHandlerContext.write(AbstractChannelHandlerContext.java:816)
           at io.netty.channel.AbstractChannelHandlerContext.write(AbstractChannelHandlerContext.java:723)
           at io.netty.channel.ChannelDuplexHandler.write(ChannelDuplexHandler.java:106)
           at gvlfm78.plugin.OldCombatMechanics.utilities.packet.PacketInjector.write(PacketInjector.java:171)
           at io.netty.channel.AbstractChannelHandlerContext.invokeWrite0(AbstractChannelHandlerContext.java:738)
           at io.netty.channel.AbstractChannelHandlerContext.invokeWriteAndFlush(AbstractChannelHandlerContext.java:801)
           at io.netty.channel.AbstractChannelHandlerContext.write(AbstractChannelHandlerContext.java:814)
           at io.netty.channel.AbstractChannelHandlerContext.writeAndFlush(AbstractChannelHandlerContext.java:794)
           at io.netty.channel.AbstractChannelHandlerContext.writeAndFlush(AbstractChannelHandlerContext.java:831)
           at io.netty.channel.DefaultChannelPipeline.writeAndFlush(DefaultChannelPipeline.java:1071)
           at io.netty.channel.AbstractChannel.writeAndFlush(AbstractChannel.java:300)
           at com.comphenix.protocol.injector.netty.ChannelProxy.writeAndFlush(ChannelProxy.java:327)
           at net.minecraft.server.v1_13_R2.NetworkManager.lambda$b$4(NetworkManager.java:214)
           at com.comphenix.protocol.injector.netty.ChannelInjector$3.lambda$onMessageScheduled$1(ChannelInjector.java:321)
           at io.netty.util.concurrent.AbstractEventExecutor.safeExecute(AbstractEventExecutor.java:163)
           at io.netty.util.concurrent.SingleThreadEventExecutor.runAllTasks(SingleThreadEventExecutor.java:404)
           at io.netty.channel.epoll.EpollEventLoop.run(EpollEventLoop.java:313)
           at io.netty.util.concurrent.SingleThreadEventExecutor$5.run(SingleThreadEventExecutor.java:884)
           at java.lang.Thread.run(Thread.java:748)
    I am using Paper 1.13.2 and ProtocolLib version 4.5.0.

    I appreciate any help or suggestions.

    Lorenz
     
  2. FrostedSnowman

    Resource Staff

    What’s line 171?
     
  3. FrostedSnowman

    Resource Staff

  4. Code (Text):

    [04:45:11 WARN]: java.lang.NullPointerException
    [04:45:11 WARN]:        at net.minecraft.server.v1_13_R2.DataWatcher.a(DataWatcher.java:225)
    [04:45:11 WARN]:        at net.minecraft.server.v1_13_R2.DataWatcher.a(DataWatcher.java:148)
    [04:45:11 WARN]:        at net.minecraft.server.v1_13_R2.PacketPlayOutEntityMetadata.b(SourceFile:37)
    [04:45:11 WARN]:        at net.minecraft.server.v1_13_R2.PacketEncoder.encode(PacketEncoder.java:42)
    [04:45:11 WARN]:        at net.minecraft.server.v1_13_R2.PacketEncoder.encode(PacketEncoder.java:12)
    [04:45:11 WARN]:        at sun.reflect.GeneratedMethodAccessor51.invoke(Unknown Source)
    [04:45:11 WARN]:        at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
    [04:45:11 WARN]:        at java.lang.reflect.Method.invoke(Method.java:498)
    [04:45:11 WARN]:        at com.comphenix.protocol.injector.netty.ChannelInjector.encode(ChannelInjector.java:473)
    [04:45:11 WARN]:        at com.comphenix.protocol.injector.netty.ChannelInjector.access$100(ChannelInjector.java:64)
    [04:45:11 WARN]:        at com.comphenix.protocol.injector.netty.ChannelInjector$1.encode(ChannelInjector.java:243)
    [04:45:11 WARN]:        at io.netty.handler.codec.MessageToByteEncoder.write(MessageToByteEncoder.java:107)
    [04:45:11 WARN]:        at com.comphenix.protocol.injector.netty.ChannelInjector$1.write(ChannelInjector.java:249)
    [04:45:11 WARN]:        at io.netty.channel.AbstractChannelHandlerContext.invokeWrite0(AbstractChannelHandlerContext.java:738)
    [04:45:11 WARN]:        at io.netty.channel.AbstractChannelHandlerContext.invokeWriteAndFlush(AbstractChannelHandlerContext.java:801)
    [04:45:11 WARN]:        at io.netty.channel.AbstractChannelHandlerContext.write(AbstractChannelHandlerContext.java:814)
    [04:45:11 WARN]:        at io.netty.channel.AbstractChannelHandlerContext.writeAndFlush(AbstractChannelHandlerContext.java:794)
    [04:45:11 WARN]:        at io.netty.channel.AbstractChannelHandlerContext.writeAndFlush(AbstractChannelHandlerContext.java:831)
    [04:45:11 WARN]:        at io.netty.channel.DefaultChannelPipeline.writeAndFlush(DefaultChannelPipeline.java:1071)
    [04:45:11 WARN]:        at io.netty.channel.AbstractChannel.writeAndFlush(AbstractChannel.java:300)
    [04:45:11 WARN]:        at com.comphenix.protocol.injector.netty.ChannelProxy.writeAndFlush(ChannelProxy.java:327)
    [04:45:11 WARN]:        at net.minecraft.server.v1_13_R2.NetworkManager.lambda$b$4(NetworkManager.java:214)
    [04:45:11 WARN]:        at com.comphenix.protocol.injector.netty.ChannelInjector$3.lambda$onMessageScheduled$1(ChannelInjector.java:321)
    [04:45:11 WARN]:        at io.netty.util.concurrent.AbstractEventExecutor.safeExecute(AbstractEventExecutor.java:163)
    [04:45:11 WARN]:        at io.netty.util.concurrent.SingleThreadEventExecutor.runAllTasks(SingleThreadEventExecutor.java:404)
    [04:45:11 WARN]:        at io.netty.channel.epoll.EpollEventLoop.run(EpollEventLoop.java:313)
    [04:45:11 WARN]:        at io.netty.util.concurrent.SingleThreadEventExecutor$5.run(SingleThreadEventExecutor.java:884)
    [04:45:11 WARN]:        at java.lang.Thread.run(Thread.java:748)