ProtocolLib

3M Downloads

What is the difference between WrappedDataWatcher, WrappedDataWatcherObject and WrappedWatchableObject?

LaserSlime opened this issue ยท 1 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
I'm trying to listen to entity metadata and modify it. This works fine for the entity metadata packet, however in versions below 1.15 there is also entity metadata sent through the spawn mob and spawn player packets. Since my modifications didn't consistently work for those, I looked at the nms code and saw that those packets contain both a DataWatcher and a list of WrappedWatchableObjects and that made me wonder if I need to modify the Datawatcher as well. It's hard to find information regarding what all these classes do. The javadocs seem outdated and don't give much information. Can someone please explain?

API methods used
I'm currently using the watchablecollectionmodifier to remove some watchable objects from the list. How do I do the same for the WrappedDataWatcher?

commented

Please not that - as the name indicates - all these Classes are wrappers for the corresponding classes in NMS code.

  • (Wrapped)DataWatcher: Manages the metadata for a specific entity and contains a list of Items (WRappedWatchableObject)
  • (Wrapped)DataWatcherObject: Stores the metadata index and the serializer for this index but not the actual metadata value
  • (Wrapped)WatchableObject: Represents a metadata value with its index and the serializer

Regarding the use of the API: To remove a metadata entry with a specific index, just use the WrappedDataWatcher.remove(int) method which takes the index of the metadata to remove and returns the removed WrappedWatchableObject or null nothing has been deleted. Please note that this possibly also deletes the metadata from the actual entity so you might want to clone the WrappedDataWatcher using deepClone() before modifying it.