SpaciousLib - Create a custom anvil
-
First, create a new anvil
Code (Text):
// player: the player who you want to show anvil
// customanvil: the id of anvil
Anvil a = new Anvil(player, "customanvil");
// set item to this anvil
a.setSlot(AnvilSlot.INPUT_LEFT, new ItemStack(Material.DIAMOND, 1));
// open
a.open();
Code (Text):
@EventHandler
public void clickAnvil(AnvilClickEvent e){
// check the anvil id
if(e.getAnvil().getAnvilID().equals("customanvil")){
// get the slot which player's clicked
if(e.getSlot().equals(AnvilSlot.OUTPUT)){
// destroy the anvil (close it and no more open)
e.getPlayer().sendMessage("Success! Your input: "+e.getInput()); // get the input
e.setDestory(true);
}
}
}
@EventHandler
public void closeAnvil(AnvilCloseEvent event){
// check the anvil id
if(event.getAnvil().getAnvilID().equals("customanvil")){
// reopen it
event.getAnvil().open();
}
}
- Loading...
- Loading...
XenCarta PRO
© Jason Axelrod from 8WAYRUN.COM