當前位置: 首頁>>代碼示例>>Java>>正文


Java InventoryView.countSlots方法代碼示例

本文整理匯總了Java中org.bukkit.inventory.InventoryView.countSlots方法的典型用法代碼示例。如果您正苦於以下問題:Java InventoryView.countSlots方法的具體用法?Java InventoryView.countSlots怎麽用?Java InventoryView.countSlots使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在org.bukkit.inventory.InventoryView的用法示例。


在下文中一共展示了InventoryView.countSlots方法的3個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。

示例1: buildWindowClickPacket

import org.bukkit.inventory.InventoryView; //導入方法依賴的package包/類
public Object buildWindowClickPacket(Player p, ItemTransaction storage) {
    if (!supported) {
        return null;
    }
    InventoryView inv = p.getOpenInventory();
    short slotId = storage.getSlotId();
    if (slotId > inv.countSlots()) {
        return null; // wrong container open?
    }
    ItemStack itemstack = inv.getItem(slotId);
    if (itemstack == null) {
        return null;
    }
    Object packet = null;
    try {
        packet = windowClickPacketClass.newInstance();
        Object nmsItem = nmsItemMethod.invoke(null, itemstack);
        ReflectionUtil.set(packet, "a", (int) storage.getWindowId());
        ReflectionUtil.set(packet, "slot", (int) slotId);
        ReflectionUtil.set(packet, "button", 0); // shift + left mouse click
        ReflectionUtil.set(packet, "d", storage.getActionId());
        ReflectionUtil.set(packet, "item", nmsItem);
        int protocolId = ProtocolRegistry.SERVER_PROTOCOL;
        if (protocolId == ProtocolVersion.v1_8.getId()) {
            ReflectionUtil.set(packet, "shift", 1);
        } else if (protocolId >= ProtocolVersion.v1_9.getId()) { // 1.9+
            ReflectionUtil.set(packet, "shift", clickTypeEnum);
        }
    } catch (Exception e) {
        e.printStackTrace();
    }
    return packet;
}
 
開發者ID:MylesIsCool,項目名稱:ViaVersion,代碼行數:34,代碼來源:BukkitInventoryQuickMoveProvider.java

示例2: getSlotType

import org.bukkit.inventory.InventoryView; //導入方法依賴的package包/類
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;
}
 
開發者ID:UraniumMC,項目名稱:Uranium,代碼行數:68,代碼來源:CraftInventoryView.java

示例3: getSlotType

import org.bukkit.inventory.InventoryView; //導入方法依賴的package包/類
public static SlotType getSlotType(InventoryView inventory, int slot) {
    SlotType type = SlotType.CONTAINER;
    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;
}
 
開發者ID:OvercastNetwork,項目名稱:CraftBukkit,代碼行數:67,代碼來源:CraftInventoryView.java


注:本文中的org.bukkit.inventory.InventoryView.countSlots方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。