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

The following examples show how to use org.bukkit.event.inventory.InventoryClickEvent#isLeftClick() . 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: TradingPlayerShopkeeper.java    From Shopkeepers with GNU General Public License v3.0 5 votes vote down vote up
@Override
protected void onInventoryClick(InventoryClickEvent event, Player player) {
	final TradingPlayerShopkeeper shopkeeper = this.getShopkeeper();
	event.setCancelled(true);
	final int slot = event.getRawSlot();
	if (slot >= 0 && slot <= 7) {
		// handle changing sell stack size:
		this.handleUpdateItemAmountOnClick(event, 1);
	} else if ((slot >= 9 && slot <= 16) || (slot >= 18 && slot <= 25)) {
		if (shopkeeper.clickedItem != null) {
			// placing item:
			final Inventory inventory = event.getInventory();
			Bukkit.getScheduler().runTaskLater(ShopkeepersPlugin.getInstance(), new Runnable() {
				public void run() {
					inventory.setItem(slot, shopkeeper.clickedItem);
					shopkeeper.clickedItem = null;
				}
			}, 1);
		} else {
			// changing stack size of clicked item:
			this.handleUpdateItemAmountOnClick(event, 0);
		}
	} else if (slot >= 27) {
		// clicking in player inventory:
		if (event.isShiftClick() || !event.isLeftClick()) {
			return;
		}
		ItemStack cursor = event.getCursor();
		if (!Utils.isEmpty(cursor)) {
			return;
		}
		ItemStack current = event.getCurrentItem();
		if (!Utils.isEmpty(current)) {
			shopkeeper.clickedItem = current.clone();
			shopkeeper.clickedItem.setAmount(1);
		}
	} else {
		super.onInventoryClick(event, player);
	}
}