Ejemplo n.º 1
0
 @EventHandler(ignoreCancelled = true, priority = EventPriority.HIGHEST)
 public void onInventoryOpen(final InventoryOpenEvent e) {
   if (e.getView() instanceof LocaleInventory) return;
   if (e.getInventory().getType() != InventoryType.CHEST || !useLocaleInv) {
     Inventory in = e.getInventory();
     Iterator<ItemStack> it = in.iterator();
     String locale = Locale.getPlayerLocale((Player) e.getPlayer());
     try {
       while (it.hasNext()) {
         ItemStack item = it.next();
         if (ItemManager.toRPGItem(item) != null) RPGItem.updateItem(item, locale);
       }
     } catch (ArrayIndexOutOfBoundsException ex) {
       // Fix for the bug with anvils in craftbukkit
     }
   } else if (useLocaleInv) {
     LocaleInventory localeInv = new LocaleInventory((Player) e.getPlayer(), e.getView());
     e.setCancelled(true);
     e.getPlayer().openInventory(localeInv);
     localeInventories.add(localeInv);
   }
 }
  @EventHandler
  public void onInventoryOpen(InventoryOpenEvent event) {
    Player player = (Player) event.getPlayer();
    Mage apiMage = controller.getRegisteredMage(player);

    if (apiMage == null || !(apiMage instanceof com.elmakers.mine.bukkit.magic.Mage)) return;
    com.elmakers.mine.bukkit.magic.Mage mage = (com.elmakers.mine.bukkit.magic.Mage) apiMage;

    Wand wand = mage.getActiveWand();
    GUIAction gui = mage.getActiveGUI();
    if (wand != null && gui == null) {
      // NOTE: The type will never actually be CRAFTING, at least for now.
      // But we can hope for server-side player inventory open notification one day, right?
      // Anyway, check for opening another inventory and close the wand.
      if (event.getView().getType() != InventoryType.CRAFTING) {
        if (wand.getMode() == WandMode.INVENTORY || !wand.isInventoryOpen()) {
          wand.deactivate();
        }
      }
    }
  }