Java Code Examples for org.bukkit.event.inventory.ClickType#LEFT
The following examples show how to use
org.bukkit.event.inventory.ClickType#LEFT .
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: ButtonManager.java From ProjectAres with GNU Affero General Public License v3.0 | 6 votes |
@EventHandler(priority = EventPriority.LOW) public void onInteract(PlayerInteractEvent event) { if(!event.hasItem()) return; final ClickType click; switch(event.getAction()) { case LEFT_CLICK_AIR: case LEFT_CLICK_BLOCK: click = ClickType.LEFT; break; case RIGHT_CLICK_AIR: case RIGHT_CLICK_BLOCK: click = ClickType.RIGHT; break; default: return; } if(onButtonClick(event.getItem(), event.getActor(), click, event)) { event.setUseItemInHand(Event.Result.DENY); event.setUseInteractedBlock(Event.Result.DENY); } }
Example 2
Source File: EventFilterMatchModule.java From PGM with GNU Affero General Public License v3.0 | 5 votes |
@Nullable ClickType convertClick(Action action, Player player) { switch (action) { case LEFT_CLICK_BLOCK: case LEFT_CLICK_AIR: return ClickType.LEFT; case RIGHT_CLICK_BLOCK: case RIGHT_CLICK_AIR: return convertClick(ClickType.RIGHT, player); default: return null; } }
Example 3
Source File: PickerMatchModule.java From PGM with GNU Affero General Public License v3.0 | 5 votes |
@EventHandler(priority = EventPriority.HIGHEST) public void rightClickIcon(final ObserverInteractEvent event) { final boolean right = event.getClickType() == ClickType.RIGHT; final boolean left = event.getClickType() == ClickType.LEFT; if ((!right && !left) || InventoryUtils.isNothing(event.getClickedItem())) return; final ItemStack hand = event.getClickedItem(); String displayName = hand.getItemMeta().getDisplayName(); if (displayName == null) return; final MatchPlayer player = event.getPlayer(); if (!canUse(player)) return; boolean handled = false; final JoinMatchModule jmm = match.needModule(JoinMatchModule.class); if (hand.getType() == Button.JOIN.material) { handled = true; if (right && canOpenWindow(player) && settingEnabled(player, true)) { showWindow(player); } else { // If there is nothing to pick or setting is disabled, just join immediately jmm.join(player, null); } } else if (hand.getType() == Button.LEAVE.material && left) { jmm.leave(player); } if (handled) { event.setCancelled(true); // Unfortunately, not opening the window seems to cause the player to put the helmet // on their head, no matter what we do server-side. So, we have to force an inventory // update to resync them. player.getBukkit().updateInventory(); } }
Example 4
Source File: EventFilterMatchModule.java From ProjectAres with GNU Affero General Public License v3.0 | 5 votes |
@Nullable ClickType convertClick(Action action, Player player) { switch(action) { case LEFT_CLICK_BLOCK: case LEFT_CLICK_AIR: return ClickType.LEFT; case RIGHT_CLICK_BLOCK: case RIGHT_CLICK_AIR: return convertClick(ClickType.RIGHT, player); default: return null; } }
Example 5
Source File: IntegerEditMenu.java From uSkyBlock with GNU General Public License v3.0 | 5 votes |
@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 6
Source File: MenuEventsTest.java From uSkyBlock with GNU General Public License v3.0 | 5 votes |
private InventoryClickEvent getEvent(InventoryHolder holder) { // These values are not checked anywhere. InventoryView inventoryView = mock(InventoryView.class); InventoryType.SlotType slotType = InventoryType.SlotType.QUICKBAR; ClickType clickType = ClickType.LEFT; InventoryAction inventoryAction = InventoryAction.NOTHING; Inventory fakeInventory = mock(Inventory.class); doReturn(holder).when(fakeInventory).getHolder(); doReturn(fakeInventory).when(inventoryView).getTopInventory(); return new InventoryClickEvent(inventoryView, slotType, 1, clickType, inventoryAction); }
Example 7
Source File: TestBackpackListener.java From Slimefun4 with GNU General Public License v3.0 | 5 votes |
private boolean isAllowed(String id, ItemStack item) throws InterruptedException { Player player = server.addPlayer(); Inventory inv = openMockBackpack(player, id, 9).getInventory(); int slot = 7; inv.setItem(slot, item); InventoryClickEvent event = new InventoryClickEvent(player.getOpenInventory(), SlotType.CONTAINER, slot, ClickType.LEFT, InventoryAction.PICKUP_ONE); listener.onClick(event); return !event.isCancelled(); }
Example 8
Source File: TestVanillaMachinesListener.java From Slimefun4 with GNU General Public License v3.0 | 5 votes |
private InventoryClickEvent mockGrindStoneEvent(ItemStack item) { Player player = server.addPlayer(); Inventory inv = TestUtilities.mockInventory(InventoryType.GRINDSTONE, item, null); InventoryView view = player.openInventory(inv); InventoryClickEvent event = new InventoryClickEvent(view, SlotType.CONTAINER, 2, ClickType.LEFT, InventoryAction.PICKUP_ONE); listener.onGrindstone(event); return event; }
Example 9
Source File: TestVanillaMachinesListener.java From Slimefun4 with GNU General Public License v3.0 | 5 votes |
private InventoryClickEvent mockAnvilEvent(ItemStack item) { Player player = server.addPlayer(); Inventory inv = TestUtilities.mockInventory(InventoryType.ANVIL, item, null, new ItemStack(Material.IRON_CHESTPLATE)); InventoryView view = player.openInventory(inv); InventoryClickEvent event = new InventoryClickEvent(view, SlotType.CONTAINER, 2, ClickType.LEFT, InventoryAction.PICKUP_ONE); listener.onAnvil(event); return event; }
Example 10
Source File: TestVanillaMachinesListener.java From Slimefun4 with GNU General Public License v3.0 | 5 votes |
private InventoryClickEvent mockBrewingEvent(ItemStack item) { Player player = server.addPlayer(); Inventory inv = TestUtilities.mockInventory(InventoryType.BREWING); Mockito.when(inv.getHolder()).thenReturn(Mockito.mock(BrewingStand.class)); Mockito.when(inv.getSize()).thenReturn(5); InventoryView view = player.openInventory(inv); view.setCursor(item); InventoryClickEvent event = new InventoryClickEvent(view, SlotType.CONTAINER, 1, ClickType.LEFT, InventoryAction.PICKUP_ONE); listener.onPreBrew(event); return event; }
Example 11
Source File: TestVanillaMachinesListener.java From Slimefun4 with GNU General Public License v3.0 | 5 votes |
private CraftItemEvent mockCraftingEvent(ItemStack item) { Recipe recipe = new ShapedRecipe(new NamespacedKey(plugin, "test_recipe"), new ItemStack(Material.EMERALD)); Player player = server.addPlayer(); CraftingInventory inv = Mockito.mock(CraftingInventory.class); Mockito.when(inv.getContents()).thenReturn(new ItemStack[] { item, null, null, null, null, null, null, null, null }); InventoryView view = player.openInventory(inv); CraftItemEvent event = new CraftItemEvent(recipe, view, SlotType.RESULT, 9, ClickType.LEFT, InventoryAction.PICKUP_ALL); listener.onCraft(event); return event; }
Example 12
Source File: ExtractionPipeSettingsInventory.java From Transport-Pipes with MIT License | 4 votes |
@Override protected boolean click(Player p, int rawSlot, ClickType ct) { ExtractionPipe pipe = (ExtractionPipe) duct; // clicked change extract direction if (rawSlot == 2) { save(p); pipe.updateExtractDirection(true); return true; } // clicked change extract amount if (rawSlot == 4) { save(p); pipe.setExtractAmount(pipe.getExtractAmount().next()); populate(); return true; } // clicked change extract condition if (rawSlot == 6) { save(p); pipe.setExtractCondition(pipe.getExtractCondition().next()); populate(); return true; } // clicked filtering mode wool if (rawSlot == 18) { if (ct == ClickType.LEFT || ct == ClickType.SHIFT_LEFT) { pipe.getItemFilter().setFilterMode(pipe.getItemFilter().getFilterMode().next()); } else if (ct == ClickType.RIGHT || ct == ClickType.SHIFT_RIGHT) { pipe.getItemFilter().setFilterStrictness(pipe.getItemFilter().getFilterStrictness().next()); } save(p); populate(); return true; } // clicked scroll left if (rawSlot == 19) { save(p); if (scrollValue > 0) { scrollValue--; } populate(); return true; } // clicked scroll right if (rawSlot == 26) { save(p); if (scrollValue < ItemFilter.MAX_ITEMS_PER_ROW - 6) { scrollValue++; } populate(); return true; } return false; }