Java 类org.bukkit.inventory.EnchantingInventory 实例源码

项目:ProtocolSupportLegacySupport    文件:EnchantingTableHandler.java   
@EventHandler(priority=EventPriority.HIGHEST, ignoreCancelled=true)
public void onInvOpen(InventoryClickEvent event) {
    Bukkit.getScheduler().scheduleSyncDelayedTask(ProtocolSupportLegacySupport.getInstance(), () -> {
        Inventory topinv = event.getWhoClicked().getOpenInventory().getTopInventory();
        if (!(topinv instanceof EnchantingInventory)) {
            return;
        }
        EnchantingInventory enchinv = (EnchantingInventory) topinv;
        Player player = (Player) event.getWhoClicked();
        int lapisEnchAmount = enchinv.getSecondary() != null ? enchinv.getSecondary().getAmount() : 0;
        ItemStack[] contents = player.getInventory().getStorageContents();
        for (int i = 0; i < contents.length; i++) {
            ItemStack itemstack = contents[i];
            if (lapis.isSimilar(itemstack)) {
                int lapisPlayerAmount = Math.min(itemstack.getAmount(), Material.INK_SACK.getMaxStackSize() - lapisEnchAmount);
                itemstack.setAmount(itemstack.getAmount() - lapisPlayerAmount);
                if (itemstack.getAmount() == 0) {
                    contents[i] = null;
                }
                lapisEnchAmount += lapisPlayerAmount;
                if (lapisEnchAmount == Material.INK_SACK.getMaxStackSize()) {
                    break;
                }
            }
        }
        player.getInventory().setStorageContents(contents);
        if (lapisEnchAmount != 0) {
            enchinv.setSecondary(new Dye(DyeColor.BLUE).toItemStack(lapisEnchAmount));
        }
        player.updateInventory();
    });
}
项目:ProtocolSupportLegacySupport    文件:EnchantingTableHandler.java   
@EventHandler(priority=EventPriority.HIGHEST, ignoreCancelled=true)
public void onInvClose(InventoryCloseEvent event) {
    Inventory topinv = event.getView().getTopInventory();
    if (!(topinv instanceof EnchantingInventory)) {
        return;
    }
    EnchantingInventory enchinv = (EnchantingInventory) topinv;
    ItemStack lapisEnch = enchinv.getSecondary();
    enchinv.setSecondary(null);
    if (lapisEnch != null) {
        Player player = (Player) event.getPlayer();
        player.getInventory().addItem(lapisEnch).values().forEach(rem -> player.getWorld().dropItem(player.getLocation(), rem));
    }
}
项目:BukkitOldCombatMechanics    文件:ModuleNoLapisEnchantments.java   
@EventHandler
public void onEnchant(EnchantItemEvent e) {
    Block block = e.getEnchantBlock();
    if(!isEnabled(block.getWorld())) return;

    if(!hasPermission(e.getEnchanter())) return;

    EnchantingInventory ei = (EnchantingInventory) e.getInventory(); //Not checking here because how else would event be fired?
    ei.setSecondary(getLapis());
}
项目:BukkitOldCombatMechanics    文件:ModuleNoLapisEnchantments.java   
@EventHandler
public void onInventoryClose(InventoryCloseEvent e) {
    if(!isEnabled(e.getPlayer().getWorld())) return;

    Inventory inv = e.getInventory();
    if(inv == null || inv.getType() != InventoryType.ENCHANTING || !hasPermission((Player) e.getPlayer())) return;
        EnchantingInventory ei = (EnchantingInventory) inv;
        ei.setSecondary(new ItemStack(Material.AIR));
}
项目:BukkitOldCombatMechanics    文件:ModuleNoLapisEnchantments.java   
@EventHandler
public void onInventoryOpen(InventoryOpenEvent e) {
    if(!isEnabled(e.getPlayer().getWorld())) return;

    Inventory inv = e.getInventory();
    if(inv == null || inv.getType() != InventoryType.ENCHANTING || !hasPermission((Player) e.getPlayer())) return;
        ( (EnchantingInventory) inv).setSecondary(getLapis());
}