-
Notifications
You must be signed in to change notification settings - Fork 4
Developer Guide (2 Creating the Addon)
This is the second Part of our Developer Guide, you can find a full overview on our main page.
If you haven't checked out the first Part of this Guide, then please do that.
Alright, now that your workspace and project is set up properly, we can start to dive into some code.
Open up the class file of your project that you can find under your renamed package in src/main/java/
.
It should look a little bit like this:
package ...;
import ...;
public class SlimefunAddon extends JavaPlugin implements SlimefunAddon {
@Override
public void onEnable() {
// ...
}
@Override
public void onDisable() {
// Logic for disabling the plugin...
}
@Override
public JavaPlugin getJavaPlugin() {
// This is a method that links your SlimefunAddon to your Plugin.
// Just return "this" in this case, so they are linked
return this;
}
@Override
public String getBugTrackerURL() {
// Here you can return a link to your Bug Tracker.
// This link will be displayed to Server Owners if there is an issue
// with this Addon. Return null if you have no bug tracker.
// Normally you can just use GitHub's Issues tab:
// https://github.com/YOURNAME/YOURPROJECT/issues
return null;
}
}
The package
token at the top simply describes the package this file is in.
The import
token tells Java to import classes from other projects, you will probably see a lot of those importing from io.github.thebusybiscuit.slimefun4...
or org.bukkit...
.
This is because you are referencing those classes, as you will work with them.
After that your own class will start it should have the same name as its file (without the file ending) and is followed by extends JavaPlugin
.
This basically tells Java to treat it like a Bukkit Plugin (in Java).
implements SlimefunAddon
tells Slimefun to treat your Plugin like an Addon.
This class also contains two methods
.
onEnable()
is called whenever the plugin is enabled. This is where you would do any initializations.
onDisable()
is called when the plugin is disabled, due to a server shutdown for example. You can ignore this one for now.
The onEnable
method is already filled with a bunch of stuff in our template.
We will go over each thing individually, but let's start with something basic.
@Override
public void onEnable() {
// Read something from your config.yml
Config cfg = new Config(this);
}
You can use a Config
class and new Config(this)
to reference your plugin's config.
You can find your default config under src/main/resources/config.yml
.
This Config
class comes from Slimefun / dough. So you won't see this in any non-Slimefun Projects.
You can read values directly from this class using the appropriate getters:
cfg.getBoolean("path.to.your.boolean");
cfg.getString("path.to.your.string");
You can use your Config to set up values that Server Owners should be able to configure.
Important hint: If your IDE nags about not being able to find Config
, then make sure to import the Config class from the io.github.thebusybiscuit.slimefun4.libraries.dough.config
package.
You will need to import each external class you will use.
未標記的資料來源都是從官方Wiki進行翻譯的, 可能會有很多 句子不順、句子很怪、錯字、翻譯錯誤等等!
歡迎來幫忙翻譯Wiki! 這將會加快Wiki的完整翻譯度. 加入非官方的Discord獲取更多訊息!
此Wiki由社區製作. 您可以透過下列幾種方式來幫助解決問題:
官方Wiki (請都照著Slimefun Wiki內的內容進行回報, 並使用英文!)
目前還正在進行中 歡迎幫助 透過下面的非官方Discord連結加入並討論!
如果您有任何疑問, 也可以加入Slimefun Discord伺服器並提問 :) 左邊是官方伺服器, 右邊是非官方繁體伺服器
- 甚麼是黏液科技?
- 如何安裝黏液科技
- 入門
- Common Issues and Problems
- How to report bugs
- Help us expand the Wiki!
- Help us translate Slimefun!
- FAQ