Developers

Hooking into and using ElderWands

Hooking into ElderWands

To start using ElderWands you need to check if the plugin is on the server, you also need to depend on it.

@Override
public void onEnable(){
    if(getServer().getPluginManager().getPlugin("ElderWands") != null){
        //Add everything here
    }else{
        getServer().getPluginManager().disablePlugin(this);
    }
}

Creating a wand

To create a wand you need to create a new class and implement Wand. Once you have done that and implemented the methods your code will look like this

package me.person.example;

import org.bukkit.inventory.ItemStack;
import org.bukkit.inventory.Recipe;

import com.bwfcwalshy.elderwands.api.Wand;

public class ExampleWand implements Wand{

	@Override
	public int getDurability() {
		// TODO Auto-generated method stub
		return 0;
	}

	@Override
	public String getId() {
		// TODO Auto-generated method stub
		return null;
	}

	@Override
	public ItemStack getItemStack() {
		// TODO Auto-generated method stub
		return null;
	}

	@Override
	public String getName() {
		// TODO Auto-generated method stub
		return null;
	}

	@Override
	public Recipe getRecipe() {
		// TODO Auto-generated method stub
		return null;
	}
	
}

Then fill out the methods. You will need to use the JavaDocs for this. For example, the durability you will need to use the #durability or if you wand unbreakable you need to do #unbreakable

Here is what the class should look like

package me.person.example;

import org.bukkit.ChatColor;
import org.bukkit.Material;
import org.bukkit.inventory.ItemStack;
import org.bukkit.inventory.Recipe;
import org.bukkit.inventory.ShapedRecipe;
import org.bukkit.inventory.meta.ItemMeta;

import com.bwfcwalshy.elderwands.api.Wand;
import com.bwfcwalshy.elderwands.api.Wands;

public class ExampleWand implements Wand{

	Wands wands = Wands.getInstance();

	public ExampleWand(Wands wands){
		this.wands = wands;
	}
	
	//Name of the wand
	public String getName() {
		return ChatColor.RED + "ExampleWand"; 
	}

	//Durability of the wand
	public int getDurability() {
		return 30;
	}

	/*
	 * The itemstack of the wand.
	 * #durability(ItemStack, int) to set the durability. It is recommended to do getDurability() for the second argument.
	 * #unbreakable(ItemMeta) to set the wand as unbreakable.
	*/
	public ItemStack getItemStack() {
		ItemStack is = new ItemStack(Material.BLAZE_ROD);
		ItemMeta im = is.getItemMeta();
		im.setDisplayName(getName());
		wands.durability(im, getDurability());
		is.setItemMeta(im);
		return is;
	}

	//The recipe of the wand
	public Recipe getRecipe() {
		ShapedRecipe recipe = new ShapedRecipe(getItemStack());
		recipe.shape(new String[] {"***", "*R*", "***"});
		recipe.setIngredient('*', Material.GOLD_NUGGET);
		recipe.setIngredient('R', Material.ANVIL);
		return recipe;	
	}

	//The id of the wand. This cannot be 2 words!
	public String getId() {
		return "ExampleWand";
	}
}

Registering your wand

To register your wand to be used in ElderWands you need to go back to your main class and initialize the Wands class. To do this you need to do Wands wands = Wands.getInstance(); Then to register in onEnable do #registerWand(Wands wands)

Example

package me.person.example;

import org.bukkit.plugin.java.JavaPlugin;

import com.bwfcwalshy.elderwands.api.Wands;

public class Main extends JavaPlugin {

	Wands wands = Wands.getInstance();
	
	public void onEnable(){
		wands.registerWand(new ExampleWand(wands));
	}
}

Comments

Posts Quoted:
Reply
Clear All Quotes