CustomEnchantment API
Summary
Want to create custom enchantments like those of minecraft vanilla? This plugin is for you.
EnchantmentAPI allows you to:
- Create custom enchantments
- Set enchantment's name, id, trigger ...
- Create custom enchantment effect
Installation
Put the file in your plugin folder.
To import the API, add it to your build path (like bukkit) and add this line in your plugin.yml:
depend: [EchantmentAPI]
Usage
To create custom enchantment, use CustomEnchantment class.
Constructors:
new CustomEnchantment(int id, String name, int lvl, EnchantmentTarget target)
new CustomEnchantment(int id, String name, int lvl, EnchantmentTarget target, int start, boolean cursed, boolean treasure, List<Enchantment> conf, EventTrigger eventtrigger, boolean visible)
Constructor args:
- Integer id: Enchantment ID in Minecraft (do not use a vanilla enchantment ID ex=1 ex=100)
- String name: Enchantment display name
- EnchantmentTarget target: The enchantment type. Example: ALL, BREAKABLE, ARMOR, FEET, LEGS...
- Integer start: The minimal enchantment level (default: 0)
- Boolean cursed: Is the enchantment a curse ?
- Boolean treasure: Is the enchantment a treasure enchatment ? (as mending, frost walk ect...)
- List<Enchantment> conf: Enchantment in conflict with that one (Example: Mending cannot be used with Infinity
- EventTrigger trigger: The trigger event (Example: EntityDamageEvent, BlockBreakEvent...)
- Boolean visible: Is the enchantment is visible in the item lore ?
You can also create a file that extends the CustomEnchantment class:
public class MyEnchant extends CustomEnchantment{
public MyEnchant(int id, String name, int lvl, EnchantmentTarget target, int start, boolean cursed, boolean treasure, List<Enchantment> conf, EventTrigger eventtrigger, boolean visible) {
super(id, name, lvl, target, start, cursed, treasure, conf, damagetrigger, eventtrigger, visible); // TODO Auto-generated constructor stub }
@Override
public void enchantmentEffect(Event event, int lvl) {
// TODO Auto-generated method stub
}
}
Supported events:
Register custom enchantment: EntityDamageEvent, EntityDamageByEntityEvent, EntityDamageByBlockEvent, EntityAirChangeEvent, EntityCombustEvent, PlayerFishEvent, PlayerAnimationEvent, PlayerDeathEvent, BlockBreakEvent
Register custom enchantments:
EnchAPI.loadEnchantment(CustomEnchantment)
Set enchantment effect:
public void enchantmentEffect(Event event, int lvl) { //TODO Enchantment effect here }
Enchant an item:
YourEnchantment.enchant(ItemStack item, int level)
Set Enchantment Effect, use abstract method enchantmentEffect(Event, int):
public void enchantmentEffect(Event event, int lvl){
//TODO Code here
}
1.13 please bro please!!! :C
Another thing: In the description, you ask users to add this line to the plugin.yml:
But the line should be:
(Fixed missing 'n' and brackets)
Also, the plugin throws this when trying to disable the server (ex: when restarting):
Glad to help ^^
In reply to cristichi:
According to the console, you are using MC 1.13 which is not fully compatible with the plugin. In addition, the error that occurs is a "security" and more to ensure the stability of the plugin.
What should I do if I want the enchanted item to do something when it breaks a block using the BlockBreakEvent?
In reply to cristichi:
new CustomEnchantment(int yourId, String YourEnchName, int YourEnchLvlMax, EnchantmentTarget target, int start, boolean cursed, boolean treasure, List<Enchantment> conf, EventTrigger BlockBreakEvent, boolean visible)
BlockBreakEvent is the event trigger.
Then register your enchantement as marked above
And this is an example of effect:
new CustomEnchantment(int yourId, String YourEnchName, int YourEnchLvlMax, EnchantmentTarget target, int start, boolean cursed, boolean treasure, List<Enchantment> conf, EventTrigger BlockBreakEvent, boolean visible){
public void enchantmentEffect(Event event, int lvl){
Player player = event.getPlayer();
player.chat("I break a block of §b" + event.getBlock().getType());
}
}
PS: Sorry for the late awser and thank you for pointing out that I forgot to say that on the page
In reply to Forge_User_50434340:
In reply to cristichi: