Search in sources :

Example 1 with CraftWildInventory

use of com.bgsoftware.wildchests.objects.inventory.CraftWildInventory in project WildChests by BG-Software-LLC.

the class WRegularChest method getWildContents.

@Override
public WildItemStack<?, ?>[] getWildContents() {
    WildItemStack<?, ?>[] contents = new WildItemStack[0];
    int pagesAmount = getPagesAmount();
    if (pagesAmount == 0)
        return contents;
    for (int page = 0; page < pagesAmount; page++) {
        CraftWildInventory inventory = inventories.get(page);
        int oldLength = contents.length;
        contents = Arrays.copyOf(contents, contents.length + inventory.getSize());
        System.arraycopy(inventory.getWildContents(), 0, contents, oldLength, inventory.getSize());
    }
    return contents;
}
Also used : WildItemStack(com.bgsoftware.wildchests.objects.inventory.WildItemStack) CraftWildInventory(com.bgsoftware.wildchests.objects.inventory.CraftWildInventory)

Example 2 with CraftWildInventory

use of com.bgsoftware.wildchests.objects.inventory.CraftWildInventory in project WildChests by BG-Software-LLC.

the class WRegularChest method setPage.

@Override
public Inventory setPage(int page, int size, String title) {
    ChestData chestData = getData();
    checkCapacity(page + 1, chestData.getDefaultSize(), chestData.getDefaultTitle());
    CraftWildInventory inventory = plugin.getNMSInventory().createInventory(this, size, title, page);
    inventories.set(page, inventory);
    updateTitles();
    return inventory;
}
Also used : ChestData(com.bgsoftware.wildchests.api.objects.data.ChestData) CraftWildInventory(com.bgsoftware.wildchests.objects.inventory.CraftWildInventory)

Example 3 with CraftWildInventory

use of com.bgsoftware.wildchests.objects.inventory.CraftWildInventory in project WildChests by BG-Software-LLC.

the class WRegularChest method getWildItem.

@Override
public WildItemStack<?, ?> getWildItem(int i) {
    Inventory firstPage = getPage(0);
    if (firstPage == null)
        return WildItemStack.AIR.cloneItemStack();
    int pageSize = firstPage.getSize();
    int page = i / pageSize;
    int slot = i % pageSize;
    CraftWildInventory actualPage = (CraftWildInventory) getPage(page);
    if (actualPage == null)
        return WildItemStack.AIR.cloneItemStack();
    return actualPage.getWildItem(slot);
}
Also used : CraftWildInventory(com.bgsoftware.wildchests.objects.inventory.CraftWildInventory) CraftWildInventory(com.bgsoftware.wildchests.objects.inventory.CraftWildInventory) Inventory(org.bukkit.inventory.Inventory)

Example 4 with CraftWildInventory

use of com.bgsoftware.wildchests.objects.inventory.CraftWildInventory in project WildChests by BG-Software-LLC.

the class WRegularChest method setItem.

@Override
public void setItem(int i, WildItemStack<?, ?> itemStack) {
    Inventory firstPage = getPage(0);
    if (firstPage == null)
        return;
    int pageSize = firstPage.getSize();
    int page = i / pageSize;
    int slot = i % pageSize;
    CraftWildInventory actualPage = (CraftWildInventory) getPage(page);
    if (actualPage == null)
        return;
    actualPage.setItem(slot, itemStack);
}
Also used : CraftWildInventory(com.bgsoftware.wildchests.objects.inventory.CraftWildInventory) CraftWildInventory(com.bgsoftware.wildchests.objects.inventory.CraftWildInventory) Inventory(org.bukkit.inventory.Inventory)

Example 5 with CraftWildInventory

use of com.bgsoftware.wildchests.objects.inventory.CraftWildInventory in project WildChests by BG-Software-LLC.

the class InventoryListener method onChestInteract.

@EventHandler(priority = EventPriority.HIGHEST, ignoreCancelled = true)
public void onChestInteract(InventoryClickEvent e) {
    Inventory clickedInventory = e.getView().getTopInventory();
    if (!(clickedInventory instanceof CraftWildInventory))
        return;
    Chest chest = ((CraftWildInventory) clickedInventory).getOwner();
    chest.onInteract(e);
}
Also used : WChest(com.bgsoftware.wildchests.objects.chests.WChest) Chest(com.bgsoftware.wildchests.api.objects.chests.Chest) CraftWildInventory(com.bgsoftware.wildchests.objects.inventory.CraftWildInventory) CraftWildInventory(com.bgsoftware.wildchests.objects.inventory.CraftWildInventory) Inventory(org.bukkit.inventory.Inventory) EventHandler(org.bukkit.event.EventHandler)

Aggregations

CraftWildInventory (com.bgsoftware.wildchests.objects.inventory.CraftWildInventory)5 Inventory (org.bukkit.inventory.Inventory)3 Chest (com.bgsoftware.wildchests.api.objects.chests.Chest)1 ChestData (com.bgsoftware.wildchests.api.objects.data.ChestData)1 WChest (com.bgsoftware.wildchests.objects.chests.WChest)1 WildItemStack (com.bgsoftware.wildchests.objects.inventory.WildItemStack)1 EventHandler (org.bukkit.event.EventHandler)1