Paper icon indicating copy to clipboard operation
Paper copied to clipboard

AbstractChatEvent viewers should be mutable in all cases

Open davidmayr opened this issue 1 year ago • 6 comments

Is your feature request related to a problem?

When writing plugins that contain e.g. a team chat the obvious solution would proably be to modify the viewers in AbstractChatEvent with for example removeIf. But when looking at the viewers() method in the event the javadocs say the following:

"Listeners should be aware that modifying the list may throw UnsupportedOperationException if the event caller provides an unmodifiable set."

But you could just cancel the event and send the message to the appropriete players with sendMessage right? Sadly this is not really a good solution since the message will be displayed as a system messsage to the players. And for other plugins monitoring the outcome of the event it will be unclear what players will recieve the message.

Describe the solution you'd like.

I fully understand that there isn't a good method to check if a set or list is mutable. But with how the javadoc is written its really unclear if paper itself calls it with an unmutable set or if its just third party plugins and it does not encurrage developers to provide a mutable set because it could break plugins when they dont.

I think the javadocs should state that a mutable set should be provided because it can cause incompatability if an immutable one is given. And the docs should also say wheather paper itself provides immutable sets in specific cases.

Describe alternatives you've considered.

Catching the exception and using sendMessage in case of faliure. But in my opinion thats not really a good way to solve the issue

Other

No response

davidmayr avatar Oct 12 '22 10:10 davidmayr