Problem with EnderChest lid

Discussion in 'Spigot Plugin Development' started by Grauju, Jan 7, 2020.

  1. Hi,

    right now I'm coding a plugin which opens a custom inventory by opening an enderchest. But if I close the inventory the lid from the enderchest doesn't close...

    My Code:

    Code (Java):
    @EventHandler
        public void onInventoryOpen(InventoryOpenEvent e){
            Player p = (Player) e.getPlayer();
            if(e.getInventory().getType().equals(InventoryType.ENDER_CHEST)){
                e.setCancelled(true);
               
                ItemStack disabled = new ItemStack(Material.RED_STAINED_GLASS_PANE);
                ItemMeta disabledm = disabled.getItemMeta();
                disabledm.setDisplayName("§cNo permissions");
                ArrayList<String> lore = new ArrayList<String>();
                lore.add("§7You don't have the permission to use this slot.");
                disabledm.setLore(lore);
                disabled.setItemMeta(disabledm);
               
                p.playSound(p.getLocation(), Sound.BLOCK_ENDER_CHEST_OPEN, 1, 1);
                Inventory inv = Bukkit.createInventory(null, 9*1, "§bEnderchest");
                if(p.hasPermission("enderchest.use.9")) {
                p.openInventory(inv);
     
  2. Try not canceling the event or open the inventory in the PlayerInteractEvent