Xezard / XGlow

Simple ProtocolLib based API for Spigot to create glow on your entities.
Apache License 2.0
35 stars 12 forks source link

I found a fix for the 1.19.3 packet 78 error #29

Open GilanRanger opened 1 year ago

GilanRanger commented 1 year ago

I was recently trying to use XGlow in 1.19.3, but it was crashing when the client received a packet due to a cast exception.

The solution seems to be to change the setMetadata() in WrapperPlayServerEntityMetadata to this

public void setMetadata(List<WrappedWatchableObject> value) {
        final List<WrappedDataValue> wrappedDataValueList = new ArrayList<>();
        value.stream().filter(Objects::nonNull).forEach(entry -> {
            final WrappedDataWatcher.WrappedDataWatcherObject dataWatcherObject = entry.getWatcherObject();
            wrappedDataValueList.add(new WrappedDataValue(dataWatcherObject.getIndex(), dataWatcherObject.getSerializer(), entry.getRawValue()));
        });
        handle.getDataValueCollectionModifier().write(0, wrappedDataValueList);
    }

And the onPacketSending in GlowAPI to this

public void onPacketSending(PacketEvent event) {
                PacketContainer packet = event.getPacket();
                Entity entity = packet.getEntityModifier(event).read(0);

                GlowsManager.getInstance().getGlowByEntity(entity).ifPresent((glow) -> {
                    final List<WrappedDataValue> wrappedDataValueList = new ArrayList<>();
                    GlowProcessor.getInstance().createDataWatcher(entity, glow.sees(event.getPlayer()))
                            .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);

                    event.setPacket(packet);
                });
            }

I was having trouble getting a pull request/fork to work (and this solution is quite messy), so in the meantime, I'll just post this here so that if anyone needs to fix it they can.

Xezard commented 1 year ago

Thank you. As soon as I get a chance, I will update the plugin.

Dymeth commented 1 year ago

Made this changes in #30, thank you. Just waiting for @Xezard review for now

Varunda commented 1 year ago

i've found another fix based on: https://www.spigotmc.org/threads/unable-to-modify-entity-metadata-packet-using-protocollib-1-19-3.582442/

implemented it in my fork: https://github.com/Varunda/XGlow

only tested with 1.20, but it seems a bit simpler to implement for me than #30