Java Code Examples for org.bukkit.event.inventory.InventoryClickEvent#getSlotType()

The following examples show how to use org.bukkit.event.inventory.InventoryClickEvent#getSlotType() . 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: DataUpdaterEvents.java    From AACAdditionPro with GNU General Public License v3.0 6 votes vote down vote up
@EventHandler(priority = EventPriority.LOW)
public void onInventoryClick(final InventoryClickEvent event)
{
    final User user = UserManager.getUser(event.getWhoClicked().getUniqueId());

    if (user != null &&
        // Quickbar actions can be performed outside the inventory.
        event.getSlotType() != InventoryType.SlotType.QUICKBAR)
    {
        // Only update if the inventory is currently closed to not interfere with opening time checks.
        if (!user.hasOpenInventory()) {
            user.getTimestampMap().updateTimeStamp(TimestampKey.INVENTORY_OPENED);
        }

        user.getTimestampMap().updateTimeStamp(TimestampKey.LAST_INVENTORY_CLICK);
        if (event.getCurrentItem() != null) {
            user.getTimestampMap().updateTimeStamp(TimestampKey.LAST_INVENTORY_CLICK_ON_ITEM);
        }

        user.getDataMap().setValue(DataKey.LAST_RAW_SLOT_CLICKED, event.getRawSlot());
        user.getDataMap().setValue(DataKey.LAST_MATERIAL_CLICKED, event.getCurrentItem() == null ?
                                                                  Material.AIR :
                                                                  event.getCurrentItem().getType());
    }
}
 
Example 2
Source File: ServerListener.java    From ZombieEscape with GNU General Public License v2.0 5 votes vote down vote up
@EventHandler
public void onClick(InventoryClickEvent event) {
    switch (event.getSlotType()) {
        case CRAFTING:
        case ARMOR:
        case FUEL:
            event.setCancelled(true);
    }
}
 
Example 3
Source File: IntegerEditMenu.java    From uSkyBlock with GNU General Public License v3.0 5 votes vote down vote up
@Override
public boolean onClick(InventoryClickEvent event) {
    if (!(event.getInventory().getHolder() instanceof UltimateHolder) ||
            ((UltimateHolder) event.getInventory().getHolder()).getTitle() == null ||
            !stripFormatting(((UltimateHolder) event.getInventory().getHolder()).getTitle()).contains(stripFormatting(getTitle()))) {
        return false;
    }
    if (event.getSlotType() != InventoryType.SlotType.CONTAINER) {
        return true;
    }
    Player player = (Player) event.getWhoClicked();
    Inventory menu = event.getInventory();
    ItemStack returnItem = menu.getItem(getIndex(5, 0));
    String configName = returnItem.getItemMeta().getLore().get(0);
    String path = returnItem.getItemMeta().getLore().get(1);
    int page = getPage(returnItem.getItemMeta().getLore().get(2));
    int slot = event.getSlot();
    int row = slot / 9;
    int col = slot % 9;
    ItemStack clickedItem = event.getCurrentItem();
    if (slot >= getIndex(3, 0) && slot <= getIndex(3, 8)) {
        // increment buttons
        YmlConfiguration config = FileUtil.getYmlConfiguration(configName);
        int value = config.getInt(path, 0);
        int increment = getDisplayNameAsInt(clickedItem);
        if (event.getClick() == ClickType.LEFT) {
            value += increment;
        } else if (event.getClick() == ClickType.RIGHT) {
            value = increment;
        }
        config.set(path, value);
        config.set("dirty", true);
    }
    if (slot != getIndex(5,0)) {
        player.openInventory(createEditMenu(configName, path, page));
    } else {
        player.openInventory(parent.createEditMenu(configName, path, page));
    }
    return true;
}
 
Example 4
Source File: EvtCraftClick.java    From skRayFall with GNU General Public License v3.0 5 votes vote down vote up
@Override
public boolean check(Event evt) {
    final InventoryClickEvent e = (InventoryClickEvent) evt;
    if (InventoryType.CRAFTING == e.getInventory().getType()) {
        if (e.getSlotType() != InventoryType.SlotType.QUICKBAR
                && e.getSlotType() != InventoryType.SlotType.CONTAINER) {
            if (evtslotclick == null) {
                return true;
            } else return e.getSlot() == evtslotclick.getSingle().intValue();
        }
        return false;
    }
    return false;
}