Version 2.0 - ParzivalExe/guiapi GitHub Wiki
Version 2.0 of GuiAPI has a completely new way to create all your Guis: Through XML!
This process makes creating a Gui even easier, testing them even more convenient and makes code way more readable because Logic and UI are now separated into different files.
In addition to this, the whole GuiAPI-Code has been rewritten in Kotlin, removing many of the edges that previously could lead to unwanted results. Through Kotlin itself, the code is now much more modern and compact BUT compatibility with Java has of course been kept for all the developers who have already and/or will in the future still use this API for their Java-Code
You can now use only XML for defining a GUI and must then only use two functions to open it for the player: Gui.createGuiFromProjectFile(…).openGui(player)
All the XML-Code for Guis is stored in files of the type *.mgui
which stands for MinecraftGui. This file can be stored inside the project itself or outside in any other file. You can even change the FileType if you really want to. If you want to learn how to write Guis based on XML, here is explained how to create a Gui and populate it with all available components only using XML. You can even transform your own components to support XML within a few minutes and without changing any significant code by following this tutorial.
Once you have learned how to create Guis based on XML and have converted your own components to support XML you can enjoy many advantages:
- It is simply easier to write Guis in XML because you can already imagine how the final Gui will look like by just looking at the code
- Your code is much more organized. Now your code for the UI is inside a separate file from your Logic-Code
- The XML files are loaded every time you want to open the Gui making it much easier to see changes straight away. As long as the .mgui-File is located outside your project (the GuiAPI already provides a folder for simple testing), you can simply save the file after changes and these changes will automatically apply to the Gui the next time it is loaded. NO recompiling of the plugin, NO Server-Reloads
As you can see, there are lots of benefits for chaining your Gui-Creation to XML. The only scenario in which Guis based on XML-Code doesn't work is for Guis that are dynamically created based on runtime-data as there is no option yet to fill runtime-data into properties defined in XML. It is however possible to create the basic Gui in XML first and then edit it in code later. If everything in your Gui is based on RuntimeData it is of course also possible to create your Gui entirely in Java or Kotlin-Code as it was before.
The Code-Overhaul has changed most of the critical systems behind the GuiAPI to be much more thought-out and fool-prove. The most noticable improvements are in:
- Changes to Component- and Gui-Tracking making it much more reliable. This helps with ensuring that no Component is finalized before it should be because after finalizing a component, it will not work but behave like an ordinary item again. At the same time, it also helps with preventing an input of one player to trigger the components of another player and finalizing Components the moment they aren't needed anymore, saving precious memory
-
Changes to Events by introduction the methods
isGuiOpenedInClass(Class<?> clazz) {…}
andisGuiOpenedInThisClass() {…}
which helps by filtering out calls fromComponentClickEvents
which shouldn't be handled by the specific EventMethod. More on that in the chapter Event-Logic. -
Changes to Component-Placement, making it possible to change components of a Gui while it is opened and overall better positioning of Components with and without defined
place
.
This is such a new version of GuiAPI, that NO code from 1.x-Version has been used in v2.0 (already seen in the fact that it is now written in an entirely different programming-language). Therefore updating to v2.0 could seem impossible at first, needing completely new code. However this might not be the case as many variables and functions needed for final usage have been kept the same, though there are still mayor differences that everybody has to deal with BUT, even if you are not considering using any of the new features it is still adviced to use the new version since there are so many changes to the backend-code that could all have a positive impact on stability and eliminate many potential bugs in the older versions (or in other words: since I wrote this API in 2017, I have learned a lot 😉)
So, here are the most significant changes I could find that should be kept in mind when updating to 2.0:
This is by far the biggest change since at first it would seem that every class you used is not findable anymore, but don't panic, most of the classes are still there, they are just based in another package now. Instead of the old com.bluebird.api.gui
they are now located in io.github.parzivalExe.guiApi
. Overall, this change in packages is mostly a rebranding and nothing more. Even the sub-packages after that are mostly the same.
In the Gui-Class there are several minor renaming's and one more prominent change. Let's start with the renaming's:
-
int size
is now calledint forcedSize
andboolean useSize
has been removed. As long asforcedSize <= 0
(for example -1) it will act likeuseSize = false
(which is also the default). The moment you setforcedSize > 0
(for example 9), it will act likeuseSize = true
-
getComponents()
is now changed togetAllComponents()
- While
Gui.closeGui(player)
still works, it is now also possible, to simply close a specific Gui-Instance by callinggui.closeGui()
which is now the recommended function to use since you can be shure that you closed the correct Gui and not a different Gui the Player had already opened
- It isn't possible anymore to use the variable
look
to get the ItemStack this Component will show when opened in a Gui. Instead you now need to call the functiongetGuiItem()
which will then build you the right ItemStack - The Component-ID
id
is now anint id
and notlong id
- To add a ClickAction you now have to call the method
addClickListener(ComponentClickListener) {…}
and not set the fieldclickAction
because Components now support multiple ClickListeners at the same time. You might have also already noticed that the Interface for the ClickAction is nowComponentClickListener
and notRunnable
which is a custom Interface designed to be used for ClickActions - FINALIZE_ACTION (not written yet)
- the
finalize() {…}
-Method is now calledfinalizeComponent() {…}
-
getGuiComponentMeta() {…}
is now calledgetMeta() {…}
andsetGuiComponentMeta() {…}
is now calledsetMeta() {…}
-
abstract Component setGuiComponent() {…}
and abstract StringsetGuiComponentType() {…}
are now not needed anymore for creating your own Components
-
String name
is now calledString title
- void
addDescription(String) {...}
to add a line to the description is now calledaddDescriptionLine(String) {...}
-
OptionOpen
is now calledOpenOption
-
underInventory
is now calledUNDER_INVENTORY
-
newInventory
is now calledNEW_INVENTORY
-
SettingOption[] option
is now calledArrayList<SettingOption> options
and an ArrayList and not an Array
-
yesNoOptionTitle
is now callednewInvTitle
-
set/getYesOptionMeta
is now calledset/getYesMeta
-
set/getNoOptionMeta
is now calledset/getNoMeta
-
reloadYes/NoOption
is not needed anymore
-
option1String
andoption1Item
are now both combined inyesSettingMeta
(like this:new ComponentMeta(option1String, option1Item)
). To setyesSettingMeta
callsetYesSettingMeta(ComponentMeta) {...}
-
option2String
andoption2Item
are now both combined innoSettingMeta
(like this: newComponentMeta(option2String, option2Item)
). To setnoSettingMeta
callsetNoSettingMeta(ComponentMeta) {...}
-
NoOptionClickEvent
->NoOptionClickedEvent
-
YesOptionClickEvent
->YesOptionClickedEvent
-
YesNoSettingClickedEvent
&YesSettingChooseEvent
&NoSettingChooseEvent
->YesNoSettingChosenEvent
And this concludes all the mayor outward-facing changes I could find. If you have more, I would be more than happy for you to post it as an issue so that I can add it to this list and potentially even help you solve the compatibility-issue if you can't find a solution by yourself 😉
Now you know everything there is to know about GuiAPI v2.0 and you can start looking at the more specific tutorials or start updating your current implementation to v2.0. If you find any more issues with v2.0 you can of course also post these as an issue or you can simply give feedback over the Plugin-Comments.
I HOPE YOU CAN REALIZE EVERYTHING YOU WANT TO WITH GUIAPI v2.0 🎉🎊