SpaciousLib - Create a custom anvil

Jun 5, 2017
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();
     
    Now, create an event handler to execute some code when player click or close it
    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();
        }
    }
     
    All code: https://gist.github.com/anhcraft/92fdae12da1a24c2f3564346558b57cf
  • Loading...
  • Loading...