Solved How can i send packet to a player?

Lexize

New member
Feb 4, 2022
11
1
0
1
17
I need to send a PacketPlayOutEntityEffect to a player.
I tried four ways:
Sending packet trough ProtocolLib
Sending packet trough NMS
Sending packet trough PacketEvents
And sending packet trought player.sendPluginMessage()
No one of above doesn't work
Here's my current code.
Java:
public static void CreateFakeEffectForClient(Player packetReciever, LivingEntity entity, PotionEffect effect) {

        CraftPlayer reciever = (CraftPlayer) packetReciever;

        PacketPlayOutEntityEffect fakeEffect = new PacketPlayOutEntityEffect(entity.getEntityId(), CraftPotionUtil.fromBukkit(effect));

        reciever.getHandle().b.a(fakeEffect);

        ByteBuf buffer = Unpooled.buffer();
        PacketDataSerializer serializer = new PacketDataSerializer(buffer);
        fakeEffect.a(serializer);
        byte[] message = serializer.array();
        packetReciever.sendPluginMessage(UltraViolence.GetInstance(), "ultraviolence:stc", message);
        
        //ProtocolManager manager = ProtocolLibrary.getProtocolManager();
        //PacketContainer packet = manager.createPacket(PacketType.Play.Server.ENTITY_EFFECT);
        //byte flags = 0;
        //flags += effect.isAmbient() ? 0x01 : 0;
        //flags += effect.hasParticles() ? 0x02 : 0;
        //flags += effect.hasIcon() ? 0x04 : 0;
        //packet.getIntegers().write(0, entity.getEntityId());
        //packet.getBytes().write(0, (byte) (1 + ArrayUtils.indexOf(PotionEffectType.values(), effect.getType())));
        //packet.getBytes().write(1, (byte) effect.getAmplifier());
        //packet.getIntegers().write(1, effect.getDuration());
        //packet.getBytes().write(2, flags);
//
        //try {
        //    manager.sendServerPacket(packetReciever, packet);
        //} catch (InvocationTargetException e) {
        //    e.printStackTrace();
        //}
    }
What am i doing wrong?
 
Solution
easy option is to clone the test plugin repo and move your stuff into that or to basically copy the build/settings changes over to your own gradle build config (maven is not supported for internals)

Machine Maker

Paper Developer
Staff member
Dec 17, 2021
132
6
19
18
California
Well, it doesn't look like you are using a supported way of accessing NMS. we only support 1.17+ here and nms via paperweight which deobfuscates all fields/methods/classes to their correct mojang names.
 
  • Like
Reactions: Lexize

electronicboy

Administrator
Staff member
Dec 11, 2021
216
10
34
28
easy option is to clone the test plugin repo and move your stuff into that or to basically copy the build/settings changes over to your own gradle build config (maven is not supported for internals)
 
  • Like
Reactions: Lexize
Solution