public void openInventory(InventoryView inventory) {
    if (!(getHandle() instanceof EntityPlayer)) return; // TODO: NPC support?
    if (((EntityPlayer) getHandle()).playerConnection == null) return;
    if (getHandle().activeContainer != getHandle().defaultContainer) {
      // fire INVENTORY_CLOSE if one already open
      ((EntityPlayer) getHandle())
          .playerConnection.handleContainerClose(
              new Packet101CloseWindow(getHandle().activeContainer.windowId));
    }
    EntityPlayer player = (EntityPlayer) getHandle();
    Container container;
    if (inventory instanceof CraftInventoryView) {
      container = ((CraftInventoryView) inventory).getHandle();
    } else {
      container = new CraftContainer(inventory, player.nextContainerCounter());
    }

    // Trigger an INVENTORY_OPEN event
    container = CraftEventFactory.callInventoryOpenEvent(player, container);
    if (container == null) {
      return;
    }

    // Now open the window
    InventoryType type = inventory.getType();
    int windowType = CraftContainer.getNotchInventoryType(type);
    String title = inventory.getTitle();
    int size = inventory.getTopInventory().getSize();
    player.playerConnection.sendPacket(
        new Packet100OpenWindow(container.windowId, windowType, title, size, false));
    player.activeContainer = container;
    player.activeContainer.addSlotListener(player);
  }
 public static SlotType getSlotType(InventoryView inventory, int slot) {
   SlotType type = SlotType.CONTAINER;
   if (inventory == null) return type; // Cauldron - modded inventories with no Bukkit wrapper
   if (slot >= 0 && slot < inventory.getTopInventory().getSize()) {
     switch (inventory.getType()) {
       case FURNACE:
         if (slot == 2) {
           type = SlotType.RESULT;
         } else if (slot == 1) {
           type = SlotType.FUEL;
         } else {
           type = SlotType.CRAFTING;
         }
         break;
       case BREWING:
         if (slot == 3) {
           type = SlotType.FUEL;
         } else {
           type = SlotType.CRAFTING;
         }
         break;
       case ENCHANTING:
         type = SlotType.CRAFTING;
         break;
       case WORKBENCH:
       case CRAFTING:
         if (slot == 0) {
           type = SlotType.RESULT;
         } else {
           type = SlotType.CRAFTING;
         }
         break;
       case MERCHANT:
         if (slot == 2) {
           type = SlotType.RESULT;
         } else {
           type = SlotType.CRAFTING;
         }
         break;
       case BEACON:
         type = SlotType.CRAFTING;
         break;
       case ANVIL:
         if (slot == 2) {
           type = SlotType.RESULT;
         } else {
           type = SlotType.CRAFTING;
         }
         break;
       default:
         // Nothing to do, it's a CONTAINER slot
     }
   } else {
     if (slot == -999) {
       type = SlotType.OUTSIDE;
     } else if (inventory.getType() == InventoryType.CRAFTING) {
       if (slot < 9) {
         type = SlotType.ARMOR;
       } else if (slot > 35) {
         type = SlotType.QUICKBAR;
       }
     } else if (slot >= (inventory.countSlots() - 9)) {
       type = SlotType.QUICKBAR;
     }
   }
   return type;
 }