Custom Enchants

You will be able to create custom and unlimited enchants!

Main class

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

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");
	        }


	 }
}

Last updated