Closing Crafting Table Inventory

Discussion in 'Plugin Development' started by SandKastle, Jul 6, 2013.

Thread Status:
Not open for further replies.
  1. Offline

    SandKastle

    Is there something in the api that would fit this, where "CLOSE" would be something to close the inventory?

    Code:java
    1. @EventHandler(priority=EventPriority.HIGHEST)
    2. public void onItemEvent6(PrepareItemCraftEvent e) {
    3. if(e.getInventory().getResult() == (null)) {
    4. e.getInventory().CLOSE;
    5. }
    6. }
     
  2. Offline

    sayaad

    There's a method in HumanEntity for it.
    Code:java
    1. @EventHandler(priority=EventPriority.HIGHEST)
    2. public void onItemEvent6(PrepareItemCraftEvent e) {
    3. if(e.getInventory().getResult() == (null)) {
    4. e.getPlayer().closeInventory();
    5. }
    6. }
     
  3. Offline

    SandKastle

    sayaad i changed it up a bit so its like this.
    Code:java
    1. @EventHandler(priority=EventPriority.HIGHEST)
    2. public void onItemEvent5(CraftItemEvent e) {
    3. Player p = (Player)e.getView().getPlayer();
    4. if ((!p.hasPermission("cha.tag")) && (e.getInventory().getResult().getTypeId() == 421)) {
    5. p.sendMessage(ChatColor.RED + "You don't have permission to craft a nametag!");
    6. e.getPlayer().closeInventory();


    but it says "the method "getPlayer()" is undefined for craftitemevent" ?
     
  4. Offline

    sayaad

    SandKastle
    That was pseudocode.
    You need to somehow get the player crafting the items and then execute player.closeInventory();

    Don't know if this would work:
    Code:java
    1. for(HumanEntity he: e.getViewers())
    2. he.closeInventory();
     
Thread Status:
Not open for further replies.

Share This Page