Configurable staff mod
This page is a tutorial that allows developers to learn how to create a configurable staff mod using StaffModLib.
Last updated
Was this helpful?
This page is a tutorial that allows developers to learn how to create a configurable staff mod using StaffModLib.
Last updated
Was this helpful?
In this page, you'll learn how to create a configurable staff mod using StaffModLib
. This kind of staff mod is very useful when you want to modify the items, their position or their data without modifying code and redeploying your plugin.
We'll build this tutorial on the previous one so if you have not already read it, we recommend you to do so.
First of all, we'll implement the Configurable interface
which will allow us to set our staff mod configurable. So, let's do this in the SimpleStaffMod
class.
The configure(ConfigurationSection parent)
method will iterate through all the registered items and configure the ones that implement the Configurable
interface.
Now, at the end of the registerItems(Player player)
method, add the following code which we'll use the default configuration file of the plugin to configure the staff mod. You can notice that in this tutorial, all the information about our staff mod are stored in the staffmod
section.
In this part, we'll go back to the FreezeItem
class and we'll set it as configurable. So go ahead and implements the Configurable interface as in the SimpleStaffMod
class and redefine the configure()
method. We'll also create an instance variable which will store an ItemStack
retrieved when configuring the item and we'll reimplement the getItem()
method to access it.
Now, let's write the configure(ConfigurationSection parent)
method body. First, we'll retrieve into a variable the section in which the item is stored. Then, we'll initialize our item by retrieving it from this section and we'll also define its slot in the player inventory.
Now, your staff mod and its items can be configured from a configuration file.
In this part, we'll see how to store our staff mod and its items in a configuration file. In this tutorial, we'll use the default configuration file of a plugin but you can also use your own if you want. So, in the main class of your plugin, add the following code :
Now, create a file called config.yml
in your resources directory. Open it and write the following code :
It's done ! Now, do the same for all the items you want to be configurable and you'll have an amazing and easily configurable staff mod.
In the next tutorial, we'll see how to create a more advanced staff mod than this one by setting it as configurable and pageable.