Installation
Last updated
Was this helpful?
Last updated
Was this helpful?
(COMING SOON) Here is an Installation Video (here) (COMING SOON)
On this Page of the Wiki, we will talk about how to install and add the Library to your Plugin and to set it up correctly.
To start Things off: This Library needs PlaceholderAPI right now to replace the Placeholders, but it wont throw errors, if you dont have it and still replace the custom ones from the Language Manager.
Also small Sidenote: As you need the Language Manager for the Library to function right there is a few Messages And Items that need to be in a Language File by default (Their Values can be changed, just not their Paths). These Items are for the Border and Interface Items.
Latest Version here: Link
Maven:
Gradle:
or
This Step is a bit more complicated as you need to you the CoolStuffLibBuilder Class to build your Instance of the CoolStuffLib.
Everything in this Step will be done mostly in your onEnable Method.
There are a few Values of the Builder that need to be set, so that the Library can function right.
The first would be the Language Manager, as this handles all the Messages/Items/MenuTitles, that my Library uses, hence we need to set that Instance.
Also for the Language Manager to function right, in every Language File there have to be a few default Values (I talked about them in the Introduction). They need to be added to every Language File and while their Values can change, their paths can't.
Then if you want to use the PerPlayerLanguage Feature you need to create a DataFile and give the Library the Instance.
And then you just need to set the Things you want to use.
In This Tutorial, we will want to use everything in this Library, but if you don't want to use a part of the Library, just don't set it and don't use it. It's that simple.
The available Methods are the following:
The first thing todo before even using the Builder and its Method is to get an Instance of the Builder and straightaway add an Instance of your Plugin to its Constructor. And that should look like this now and throw an Error that the Method doesn't return a CoolStuffLib Object. We will fix that later.
The only really important Thing to set is the Language Manager. So lets start with that.
Language Manager
This is how the Constructor of the Language Manager looks:
So we need four Arguments to fill into this Instance of the Language Manager.
The First one will be an Instance of your Plugin. The second one is the Language Folder, where the Languages will be saved and searched for. The Third one is the Resource Directory in your Plugin JAR in which the Language Files are stored. And the Fourth Arg is your Plugins Prefix, that will be replace with %prefix% in every Message and Item and MenuTitle.
Now lets take that Instance and use it in the setLanguageManager Method of the Builder and add that Method call after its Constructor. Now it should look like this:
Note that in this Tutorial I am gonna spread out the Methods a bit more so that it's easier to see, read and understand them.
The Utils.chat Method just replaces the ColorCodes in the Prefix, that we get from the Config or a Default one, when there is no Prefix in the Config to be found.
This should add the Language Manager to the Library.
For the more advanced users, there are Methods to change the Starting Code for the Language Manager, that gets executed, when calling the Setup Method of the CoolStuffLib Main Class. This can also be changed for the Command Manager and the MenuAddonManager. If you have questions regarding that, you can always join my Discord Server or DM me directly.
Data File and PerPlayerLanguageHandler
For this we will use the following Methods of the Builder:
In the First Method, we will just put a File Instance to store the PerPlayerLanguage Data
Note that you have to create this File first.
Now the whole Thing should look like this:
Now lets tell the Builder, that we want to use the PerPlayerLanguage Feature by setting the Boolean to true in the setusePlayerLangHandler Method. Like this:
Command Manager Registry/Command Manager System
Now lets get to the Command Manager System part. First we also need to create an Instance of the Registry, but that is fairly easy and doesn't require much as this is its Constructor.
As i said it is fairly easy as it just needs an Instance of your Plugin. So now we need to use that Instance of the Registry, that you got with new CommandManagerRegistry(this)
in the setCommandManagerRegistry Method of the Builder. It's best if you dont create a seperate Instance of the Registry in your Plugin Main Class till later after the Setup Method got called.
Now the Builder should look like this:
Menu Addon Manager
Almost Done. Now we get to the Menu Addon Part. Let's not confuse it with the Menu System, that works even when all the other Systems, except the Language Manager, are disabled, as this doesn't require much setup and just needs a Listener for the Events.
For this we don't even need a Constructor as the Class doesn't have a custom one.
You can just create a new Instance of it with new MenuAddonManager()
and use it in the setMenuAddonManager Method of the Builder like this:
Plugin File Logger
Last but not least, we reached the end of the Builder. This is the Class for logging Things to a File or the Config.
This also has just a Constructor which needs an Instance of your Plugin.
So this would be how it looks now:
Creating the CoolStuffLib Instance
Now we just need to call one more Method. The createCoolStuffLib Method. This Method will create a new Instance of the CoolStuffLib with all the Values you just set.
The complete Instance Creation with the Builder should now look like this:
Now that we have the complete CoolStuffLib Instance, we can call it's setup Method to set everything up and let the Library do it's things. It should look like this:
You should now have a complete Method and a CoolStuffLib Instance ready to use.
Here is a few Things you could do with it:
Add a Default Language File
This is fairly straightforward and easy. You just have to get an instance of the LanguageManager through the Library and then call the AddLang Method with a LanguageFile Object.
The Filename is always the LanguageName + .yml at the end.
And most of the Time i just use a short Version of the Name and write the full Name into the Config at the start.
Here is the full Code:
Set the Currently used Language from the Config
You can also use the LanguageManager Instance and its setCurrentLang method which also requires a LanguageFile Object. You can get that with the getLang Method, which requires a Name and a Boolean, if it should log into the Console.
Here is the full Code:
Register a Command Manager through the Registry
Get the Instance of the Registry from the Library and then call its register Method with a new Instance of your Command Manager. My Library will handle the rest. And you don't even need to add a Command to your plugin.yml as my Library also handles that.
Get your first Message out of the Language Manager
Here we send a Message to the Console with no Player involved. So you can take an Instance of the Language Manager and use its getMessage Method. If you want to get another Language then the Current one, then use the Method with the four Arguments.
The First Argument is the Path to the Message. Here you don't need to add "Messages." at the start as my Library does that automatically. The Second Arg is the Player to use for the PlaceholderAPI Placeholders and it can be null. And the last Argument is a boolean, if you want to reset the Custom Placeholders and remove them from the Placeholder List after getting this Message and replacing them.
Add a Menu Addon
Straightforward and easy. We need an Instance of the MenuAddonManager from the Library and then we can just call the addMenuAddon Method from the MenuAddonManager Class with a new Instance of your Menu Addon.
This is the End and you should have a working Instance of the CoolStuffLib ready to go.