Open Jaren8r opened 2 years ago
In fact, I would very much welcome this change. If you use them, but forget to call Optional#empty
, you just get NullPointerException
's, which you can just save. I would clearly be in favor of removing optionals if there isn't a good use case for them - such as with the current wrappers.
With the change, you could also start documenting the getters and setters and annotate them with @Nullable
& @NotNull
so that the difference is very clear and it is also very clear which method is for which server version.
If possible I always try to avoid having methods for separate versions. Like bringing everything to one form. Sometimes that isn't always possible. I'll consider this.
I prefer the following scenario for the one time to use optional over null, but it breaks convention:
This preserves information.
I'd suggest just sticking with null for readability reasons. We aren't here to convert packets between versions and any attempts to do so should be considered out of scope and avoided for maintainability reasons.
A more user proof method would be to throw an exception if the field doesn't exist on the server version like PE 1.8 did
Currently, PacketEvents stores packet fields that may not exist across all supported versions as Optionals. This isn't great for several reasons:
Optional.empty()
in a packet wrapper constructor, leading to NullPointerExceptions anyways.I'm thinking that it would be better to convert all of these usages of Optional to nullable, but it would require an API breakage. I'm interested to hear thoughts on this.