Working with the API
UnderscoreEnchants provides an API for developers to hook into the plugin.
Adding the dependency
The API can be used with Maven or Gradle.
Getting started
Make sure that your plugin depends on UnderscoreEnchants so that it loads after UnderscoreEnchants does.
To start working with UnderscoreEnchants API, obtain the instance of the API via the Bukkit's services manager.
The code snippets will be shown in both Java and Kotlin, but if possible please use Kotlin when working with UEAPI, since it is written in Kotlin and some interoperability issues may arise when using Java.
UEAPI ueApi = null;
@Override
public void onEnable() {
RegisteredServiceProvider<UEAPI> rsp = Bukkit.getServicesManager().getRegistration(UEAPI.class);
if (rsp != null) {
ueApi = rsp.getProvider();
}
if (ueApi == null) {
Bukkit.getLogger().severe("No UnderscoreEnchants API implementation found!");
return;
}
}
The Javadocs (Dokka) for the API can be found here.
Common use cases
Enchanting/disenchanting an item
val enchanter = ueApi.enchanter
// Enchanting an item
val response = enchanter.enchant(item, enchantmentKey, level, listOf(
// Ignored restrictions
EnchantingRestriction.CONFLICT_RESTRICTION, EnchantingRestriction.UNAPPLICABLE_RESTRICTION
))
if (response.type == ItemStackEnchantResponseType.SUCCESS) {
val item = response.item
}
// Disenchanting an item
val newItem = enchanter.fullyDisenchant(item)
UEEnchanter enchanter = ueApi.getEnchanter();
// Enchanting an item
ItemStackEnchantResponse response = enchanter.enchant(item, enchantmentKey, level, Arrays.asList(
// Ignored restrictions
EnchantingRestriction.CONFLICT_RESTRICTION, EnchantingRestriction.UNAPPLICABLE_RESTRICTION
));
if (response.type == ItemStackEnchantResponseType.SUCCESS) {
ItemStack item = response.getItem();
}
// Disenchanting an item
ItemStack newItem = enchanter.fullyDisenchant(item);
Toggling an enchantment for a player
Loading content from a file
Adding registrables
Please refer to the creating registrables guide to learn how to create and add registrables.