Is your feature request related to a problem?
I absolutely love SignGUI as it allows me to provide users a clean interface for short-form text. It is also easy to work with. That said, the SignGUI class throws an exception in the static initializer block if the API does not support the current server version. Due to throwing in a static initializer block, the java runtime throws a "ExceptionInInitializerError," which cannot be caught.
I would love to make it so that if the current version of signGUI does not support the version, my plugin could then move onto a backup Chat system. This is not currently possible. Instead, since I call SignGUI from an inventory click, the SignGUI errors without being caught and allows players to take the item that was clicked on. Depending on the scenario in which SignGUI is used, this could open up dupes or other problems for plugins utilizing this API.
What solution would you like?
Move the contents of the static block to a private, static method called "getWrapperIfSupportedVersion". This method would return the wrapper (or null if unsupported version). Set the static final WRAPPER variable to be the result of calling said method. This should allow you to initialize it to either null or the correct VersionWrapper depending on if the version is supported.
In the SignGUI.builder() method, check if WRAPPER is null. If so, throw a SignGUIException with the "unsupported server version" message. No other methods should need to be changed.
This should make it so we can catch the SignGUIException and perform an alternative solution (or simply message that the feature is unavailable right now). I know it sucks having to mark SignGUI.builder() with a throws declaration, but the alternative is not being able to catch this issue and plugins using it being broken while awaiting an update. This solution also doesn't require any change on the part of dev's implementing SignGUI since, despite what your IDE will yell at you, catching exceptions from a method with a throws declaration is optional.
Describe alternatives you've considered
I have considered copying and pasting the code straight from de/rapha149/signgui/SignGUI.java's static block to create my own class that does nothing but check if SignGUI is valid. I just figured this would be a shoddy solution, especially if the contents of that static block were to change in future releases of the API.
Any additional comments?
I may have overlooked an easier solution to checking if the version is not supported. I apologize if I had.
Is your feature request related to a problem?
What solution would you like?
Move the contents of the static block to a private, static method called "getWrapperIfSupportedVersion". This method would return the wrapper (or null if unsupported version). Set the static final WRAPPER variable to be the result of calling said method. This should allow you to initialize it to either null or the correct VersionWrapper depending on if the version is supported.
In the SignGUI.builder() method, check if WRAPPER is null. If so, throw a SignGUIException with the "unsupported server version" message. No other methods should need to be changed.
This should make it so we can catch the SignGUIException and perform an alternative solution (or simply message that the feature is unavailable right now). I know it sucks having to mark SignGUI.builder() with a throws declaration, but the alternative is not being able to catch this issue and plugins using it being broken while awaiting an update. This solution also doesn't require any change on the part of dev's implementing SignGUI since, despite what your IDE will yell at you, catching exceptions from a method with a throws declaration is optional.
Describe alternatives you've considered
I have considered copying and pasting the code straight from de/rapha149/signgui/SignGUI.java's static block to create my own class that does nothing but check if SignGUI is valid. I just figured this would be a shoddy solution, especially if the contents of that static block were to change in future releases of the API.
Any additional comments?
I may have overlooked an easier solution to checking if the version is not supported. I apologize if I had.