This is the API for my project UnderscoreEnchants. UnderscoreEnchantsAPI is hosted in Maven Central, so it's trivially easy to use it in your projects!
<dependency>
<groupId>io.github.zbll-cuber.enchantsapi</groupId>
<artifactId>UnderscoreEnchantsAPI</artifactId>
<version>2.1.2</version> <!-- Make sure to always use the latest version! -->
<scope>provided</scope>
</dependency>
// 1) Create an undeclared UEnchantsAPI instance
public UEnchantsAPI ueAPI;
@Override
public void onEnable() {
// 2) Make sure that UnderscoreEnchants is installed
Plugin plugin = getServer().getPluginManager().getPlugin("UnderscoreEnchants");
if (plugin == null) {
getLogger().severe("UnderscoreEnchants is not installed!");
return;
}
// 3) Cast
ueAPI = (UEnchantsAPI) plugin;
// How to use the methods?
ueAPI.enchant();
// Easy as that.
}
If you want to use the methods from other classes, access this very instance with dependency injection of the main class.
class AnotherClass {
private final MainClass mc;
public AnotherClass(MainClass mc) {
this.mc = mc;
}
public void usage() {
mc.ueAPI.enchant();
}
}
Listening to events is nothing new.
@EventHandler
public void onAnvilCombine(EnchantmentsCombineEvent ev) {
}