# Custom Enchants

## Main class

```java
package com.edwardbelt.edprisonapi;

import org.bukkit.Bukkit;
import org.bukkit.plugin.Plugin;
import org.bukkit.plugin.java.JavaPlugin;

import com.edwardbelt.edprison.EdPrison;
import com.edwardbelt.edprisonapi.enchantments.TestEnchant;


public class Main extends JavaPlugin {

	private static Plugin instance;
	
	@Override
	public void onEnable() {
		
		instance = this;
		
		EdPrison api = (EdPrison) Bukkit.getPluginManager().getPlugin("EdPrison");
		if(api == null) {
			getServer().getPluginManager().disablePlugin(this);
			return;
		}
		
		/*
		 *  REGISTER THE CUSTOM TEST ENCHANT
		 */
		getServer().getPluginManager().registerEvents(new TestEnchant(this), instance);
		
	}
	
	
	
	public void onDisable() {
		System.out.println("Disabling");
	}
	

}
	
```

## Test Enchant class

```java
package com.edwardbelt.edprisonapi.enchantments;

import org.bukkit.entity.Player;
import org.bukkit.event.EventHandler;
import org.bukkit.event.Listener;
import org.bukkit.event.block.BlockBreakEvent;

import com.edwardbelt.edprison.utils.enchantUtils;
import com.edwardbelt.edprisonapi.Main;

public class TestEnchant implements Listener {

	private static Main plugin;
	
	
	public TestEnchant(Main main) {
		this.plugin = main;
	}

	@EventHandler
	public void onBreakEvent(BlockBreakEvent e)
	{	
		Player player = e.getPlayer();
		String playerName = player.getName();
		
		/*
		 * Get all the variables
		 */
		int enchantLevel = enchantUtils.getEnchantLevel(player, "testenchant");
		double percent = enchantUtils.getEnchantPercent(player, "testenchant");
		
		// GET THE RANDOM NUMBER //
		
		double random = 0 + Math.random() * (100 - 0);
	        
	        // TRIGGER THE ENCHANT IF THE RANDOM NUMBER IS LESS OR EQUAL THAN THE PERCENT //
	        if(random <= percent && enchantLevel > 0) {	
			player.sendMessage("Test Enchant triggered");
	        }


	 }
}

```


---

# Agent Instructions: Querying This Documentation

If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://edwardbelt.gitbook.io/edprison-core-documentation/developer-api/custom-enchants.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
