APIEnchant Class
To create an API enchant you should create an instance of this class:
package es.edwardbelt.edgens.iapi.enchant;
import org.bukkit.entity.Player;
public interface APIEnchant {
void onProc(Player player, EnchantData data);
}
You don't need to check for chances, levels, etc. - just implement the enchant method. At the moment, enchants only proc when a block is broken, so the implementation of the EnchantData
object will always be a CustomEnchantData
object. Therefore, in the onProc
method, cast the EnchantData
object to a CustomEnchantData
object.
CustomEnchantData Class
CustomEnchantData Class
@Getter
public class CustomEnchantData extends EnchantData {
private Material material;
private Vector position;
private String sellItem;
}
Usage
As you can see, you will be able to get:
The material that was broken
The position where it was broken
The sold item (if the player doesn't have autosell enabled, the item will go to the backpack)
Example Implementation
public class MyCustomEnchant implements APIEnchant {
@Override
public void onProc(Player player, EnchantData data) {
// Cast to CustomEnchantData to access specific properties
CustomEnchantData customData = (CustomEnchantData) data;
Material brokenMaterial = customData.getMaterial();
Vector blockPosition = customData.getPosition();
String soldItem = customData.getSellItem();
// Your enchant logic here
}
}
Important Warning
The onProc
method is called asynchronously! This means that any Bukkit methods that modify the game state (such as spawning entities, setting blocks, etc.) must be called synchronously using the Bukkit scheduler.
Last updated
Was this helpful?