Paper
Paper copied to clipboard
Make PlayerList more thread safe
This PR makes online player lookups by unique ID and name thread safe, which can be useful for e.g. sending messages in an asynchronous context but it also improves thread safety of various other methods that do player lookups internally, such as some methods of OfflinePlayer.
Although visibility is often no issue because of a present happens-before relationship and I have heard several times that concurrent reads are fail-safe in the most HashMap implementations nowadays, the docs do not guarantee any behavior regarding this. Therefore I have replaced the HashMaps by ConcurrentHashMaps.
Note that HashMap and ConcurrentHashMap have different contracts for null keys, which also affects behavior of API methods. However, those are all annotated with @NotNull anyway and no null keys are used internally as far as I can see.
I don't know if this has any noticeable effects performance wise.
This breaks some plugins, i tested this patch
can you give any concrete details?
Rebased, updated and tested.
This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions.
This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions.
Rebased and tested.
Seeing as though there hasn't been much activity on this, and there has not been much that warranted a need for this, I will be closing this.
There are in general a lot of places where players can be retrieved, which may be considered "unsafe" when done async, and if you want to access them in an async manner, it would most likely be better to upkeep your own kind of safe collection.
Feel free to leave a comment if you disagree.