[BUG] Registering custom admin flags throws an UnsupportedOperationException
eirikh1996 opened this issue ยท 7 comments
Before open an issue, checkout this steps:
- If you are running the plugin at first time, try to run again to see if the problem persists.
- Check if your build is the latest on our Jenkins. Click Here: http://host.areaz12server.net.br:8081/job/RedProtect
- Its important to you include the plugin jar name, because version and build info.
Describe the bug
When trying to register a custom admin flag through a third party plugin, an UnsupportedOperationException is being thrown
To Reproduce
Steps to reproduce the behavior:
- Make your plugin register a custom flag to the RedProtect API
- Run your plugin on a server with RedProtect installed
- Notice the error in console
Expected behavior
No error should be thrown
Screenshots and LOGs
Error log: https://gist.github.com/eirikh1996/d77833eefdb1e6c7eb2efd70dd09d497
Code that registers custom flag: https://gist.github.com/eirikh1996/6cc18998a4620cbd11785324cbfa6373
Server and plugins versions (please complete the following information):
- Server: This server is running Paper version git-Paper-379 (MC: 1.15.2) (Implementing API version 1.15.2-R0.1-SNAPSHOT)
- Plugin Version: [e.g. RedProtect-7.7.2-b362-Universal.jar]
- Java Version: [e.g. Java 1.8]
Additional context
Add any other context about the problem here.
You can take look at this addon to see how to add a custom flag: https://github.com/FabioZumbi12/RedProtect/tree/master/Addons/KillerProjectiles
You code seems to be ok, but you dont need create an instance of br.net.fabiozumbi12.RedProtect.Bukkit.listeners.BlockListener()
, you need register your own listener, maybe this is the problem.
I looked into the code of the list Arrays.asList()
creates, and add() in that list throws an UnsupportedOperationException. And the flag I am registering is supposed to be one only admins can set
I am also having this issue, and I think @eirikh1996 's analysis was correct, Arrays.asList returns an immutable list, which is why we get the UnsupportedOperationException when calling addFlag.
This is only a problem for custom admin flags, which is why KillerProjectiles doesn't run into it.
I submitted a very shallow PR to fix, but I wasn't actually able to test it so there could certainly be other issues too.
Thank you for your time!
Thank you for accepting my PR!
This did fix the error. However, I'm seeing that custom flags I've added get lost on load. I think this is because my plugin hasn't had a chance to register the flag yet when the region files get loaded.
I tried adding load-before: RedProtect
to my plugin as well as registering flags earlier (onEnable versus onLoad), but I could not find a spot where I could register before region files were loaded but after RedProtect.get() was non-null.
I'm wondering how this works for KillerProjectiles?
I also have a thought that even if I could register them at the right time, it is not ideal (in my opinion) that we should lose all custom flags on a region if the plugin registering them has gone away. Sometimes plugins fail to load, config issues, server owners temporarily disable them, etc.
Would it be acceptable to change it so that any unrecognized flags are saved to the Region.flags map as-is?
If so, I tried my hand at a PR: #691
The MySQL region manager looks pretty different, but I don't think it would have this issue- this is only a problem in the flat file storage.
added on #691