Java Code Examples for org.bukkit.inventory.InventoryView#getType()

The following examples show how to use org.bukkit.inventory.InventoryView#getType() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: ListenerInventories.java    From CombatLogX with GNU General Public License v3.0 6 votes vote down vote up
@EventHandler(priority=EventPriority.HIGH, ignoreCancelled=true)
public void onTag(PlayerTagEvent e) {
    Player player = e.getPlayer();
    InventoryView openView = player.getOpenInventory();
    if(openView == null) return;

    Inventory topInv = openView.getTopInventory();
    if(topInv == null) return;

    InventoryType type = openView.getType();
    if(type == InventoryType.CRAFTING) return;

    player.closeInventory();
    String message = this.plugin.getLanguageMessageColoredWithPrefix("cheat-prevention.inventory.force-closed");
    this.plugin.sendMessage(player, message);
}
 
Example 2
Source File: ClearInventoryAction.java    From UHC with MIT License 6 votes vote down vote up
@Override
protected void run(Player player) {
    final PlayerInventory inv = player.getInventory();

    // clear main inventory
    contents = inv.getContents();
    inv.clear();

    // clear armour slots
    armourContents = inv.getArmorContents();
    inv.setArmorContents(null);

    // clear if they have something on their cursour currently
    onCursor = player.getItemOnCursor();
    player.setItemOnCursor(new ItemStack(Material.AIR));

    // if they have a crafting inventory open clear items from it too
    // stops storing items in crafting slots bypassing clear inventories
    final InventoryView openInventory = player.getOpenInventory();
    if (openInventory.getType() == InventoryType.CRAFTING) {
        crafting = Optional.of(openInventory.getTopInventory().getContents());
        openInventory.getTopInventory().clear();
    } else {
        crafting = Optional.absent();
    }
}
 
Example 3
Source File: CraftContainer.java    From Kettle with GNU General Public License v3.0 5 votes vote down vote up
public CraftContainer(InventoryView view, EntityPlayer player, int id) {
    this.view = view;
    this.windowId = id;
    // TODO: Do we need to check that it really is a CraftInventory?
    IInventory top = ((CraftInventory) view.getTopInventory()).getInventory();
    InventoryPlayer bottom = (InventoryPlayer) ((CraftInventory) view.getBottomInventory()).getInventory();
    cachedType = view.getType();
    cachedTitle = view.getTitle();
    cachedSize = getSize();
    setupSlots(top, bottom, player);
}
 
Example 4
Source File: CraftContainer.java    From Thermos with GNU General Public License v3.0 5 votes vote down vote up
public CraftContainer(InventoryView view, int id) {
    this.view = view;
    this.windowId = id;
    // TODO: Do we need to check that it really is a CraftInventory?
    net.minecraft.inventory.IInventory top = ((CraftInventory)view.getTopInventory()).getInventory();
    net.minecraft.inventory.IInventory bottom = ((CraftInventory)view.getBottomInventory()).getInventory();
    cachedType = view.getType();
    cachedTitle = view.getTitle();
    cachedSize = getSize();
    setupSlots(top, bottom);
}
 
Example 5
Source File: SilentOpenChest.java    From SuperVanish with Mozilla Public License 2.0 5 votes vote down vote up
private boolean isShulkerBox(InventoryView inv) {
    try {
        return inv.getType() == InventoryType.SHULKER_BOX;
    } catch (NoSuchFieldError e) {
        return false;
    }
}
 
Example 6
Source File: CraftInventoryView.java    From Kettle with GNU General Public License v3.0 4 votes vote down vote up
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 || slot == -1) {
            type = SlotType.OUTSIDE;
        } else if (inventory.getType() == InventoryType.CRAFTING) { // Also includes creative inventory
            if (slot < 9) {
                type = SlotType.ARMOR;
            } else if (slot > 35) {
                type = SlotType.QUICKBAR;
            }
        } else if (slot >= (inventory.countSlots() - (9 + 4 + 1))) { // Quickbar, Armor, Offhand
            type = SlotType.QUICKBAR;
        }
    }
    return type;
}
 
Example 7
Source File: CraftInventoryView.java    From Thermos with GNU General Public License v3.0 4 votes vote down vote up
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;
}