Java Code Examples for org.bukkit.event.inventory.InventoryClickEvent#getCursor()
The following examples show how to use
org.bukkit.event.inventory.InventoryClickEvent#getCursor() .
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: EnhancedItemListener.java From EnchantmentsEnhance with GNU General Public License v3.0 | 6 votes |
/** * Prevents enhanced item from glitching. * * @param inventoryClickEvent */ @EventHandler(ignoreCancelled = true, priority = EventPriority.HIGH) public void onItemGlitch(InventoryClickEvent inventoryClickEvent) { ItemStack currentItem = inventoryClickEvent.getCurrentItem(); ItemStack cursor = inventoryClickEvent.getCursor(); try { if (inventoryClickEvent.getClickedInventory() != null && inventoryClickEvent.getClickedInventory().firstEmpty() == -1) { if (currentItem != null && currentItem.hasItemMeta() && (currentItem.getItemMeta().hasLore())) { if (currentItem.getItemMeta().getLore().contains(Util.UNIQUEID + Util.toColor(SettingsManager.lang.getString("lore.untradeableLore")))) { inventoryClickEvent.setCancelled(true); Util.sendMessage(SettingsManager.lang.getString("messages.noDrop"), inventoryClickEvent.getWhoClicked()); } } if (cursor != null && cursor.hasItemMeta() && (cursor.getItemMeta().hasLore())) { if (cursor.getItemMeta().getLore().contains(Util.UNIQUEID + Util.toColor(SettingsManager.lang.getString("lore.untradeableLore")))) { inventoryClickEvent.setCancelled(true); Util.sendMessage(SettingsManager.lang.getString("messages.noDrop"), inventoryClickEvent.getWhoClicked()); } } } } catch (NoSuchMethodError ex) { // craftbukkit } }
Example 2
Source File: AnvilGUI.java From AnvilGUI with MIT License | 6 votes |
@EventHandler public void onInventoryClick(InventoryClickEvent event) { if ( ((event.getInventory().equals(inventory)) && (event.getRawSlot() < 3)) || (event.getAction().equals(InventoryAction.MOVE_TO_OTHER_INVENTORY)) || ((event.getRawSlot() < 3) && ((event.getAction().equals(InventoryAction.PLACE_ALL)) || (event.getAction().equals(InventoryAction.PLACE_ONE)) || (event.getAction().equals(InventoryAction.PLACE_SOME)) || (event.getCursor() != null))) ){ event.setCancelled(true); final Player clicker = (Player) event.getWhoClicked(); if (event.getRawSlot() == Slot.OUTPUT) { final ItemStack clicked = inventory.getItem(Slot.OUTPUT); if (clicked == null || clicked.getType() == Material.AIR) return; final Response response = completeFunction.apply(clicker, clicked.hasItemMeta() ? clicked.getItemMeta().getDisplayName() : ""); if(response.getText() != null) { final ItemMeta meta = clicked.getItemMeta(); meta.setDisplayName(response.getText()); clicked.setItemMeta(meta); inventory.setItem(Slot.INPUT_LEFT, clicked); } else { closeInventory(); } } } }
Example 3
Source File: CreativeModeListener.java From ShopChest with MIT License | 6 votes |
@EventHandler(priority = EventPriority.HIGHEST) public void onInventoryClick(InventoryClickEvent e) { HumanEntity entity = e.getWhoClicked(); if (!(entity instanceof Player)) return; Player p = (Player) entity; ClickType clickType = ClickType.getPlayerClickType(p); if (clickType instanceof SelectClickType) { e.setCancelled(true); if (e.getCursor() == null || e.getCursor().getType() == Material.AIR) return; ClickType.removePlayerClickType(p); ((SelectClickType) clickType).setItem(e.getCursor()); p.closeInventory(); p.sendMessage(LanguageUtils.getMessage(Message.ITEM_SELECTED, new Replacement(Placeholder.ITEM_NAME, LanguageUtils.getItemName(e.getCursor())))); plugin.getShopCommand().createShopAfterSelected(p, (SelectClickType) clickType); } }
Example 4
Source File: InventoryForSingleItem.java From NBTEditor with GNU General Public License v3.0 | 6 votes |
@Override protected void inventoryClick(InventoryClickEvent event) { super.inventoryClick(event); int slot = event.getRawSlot(); boolean isShift = event.isShiftClick(); ItemStack item = null; if (isShift && slot > 8 && event.getInventory().firstEmpty() == 4) { item = event.getCurrentItem(); } else if (slot == 4 && !isShift && event.getCursor().getType() != Material.AIR) { item = event.getCursor(); } if (item != null) { if (!isValidItem((Player) event.getWhoClicked(), item)) { event.setCancelled(true); } } }
Example 5
Source File: PlayerEventHandler.java From GriefDefender with MIT License | 5 votes |
@EventHandler(priority = EventPriority.LOWEST) public void onPlayerInteractInventoryClick(InventoryClickEvent event) { final HumanEntity player = event.getWhoClicked(); GDCauseStackManager.getInstance().pushCause(player); if (!GDFlags.INTERACT_INVENTORY_CLICK || event.getClickedInventory() == null || !GriefDefenderPlugin.getInstance().claimsEnabledForWorld(player.getWorld().getUID())) { return; } GDTimings.PLAYER_INTERACT_INVENTORY_CLICK_EVENT.startTiming(); final Location location = player.getLocation(); final GDClaim claim = this.dataStore.getClaimAt(location); final ItemStack cursorItem = event.getCursor(); final Inventory source = event.getInventory(); final ItemStack target = event.getCurrentItem(); if (GriefDefenderPlugin.isTargetIdBlacklisted(Flags.INTERACT_INVENTORY_CLICK.getName(), target, player.getWorld().getUID())) { GDTimings.PLAYER_INTERACT_INVENTORY_CLICK_EVENT.stopTiming(); return; } final GDPermissionUser user = PermissionHolderCache.getInstance().getOrCreateUser(player.getUniqueId()); final Tristate result = GDPermissionManager.getInstance().getFinalPermission(event, location, claim, Flags.INTERACT_INVENTORY_CLICK, source, target, user, TrustTypes.CONTAINER, true); if (result == Tristate.FALSE) { final Component message = GriefDefenderPlugin.getInstance().messageData.getMessage(MessageStorage.PERMISSION_INTERACT_ITEM, ImmutableMap.of( "player", claim.getOwnerDisplayName(), "item", ItemTypeRegistryModule.getInstance().getNMSKey(target))); GriefDefenderPlugin.sendClaimDenyMessage(claim, player, message); event.setCancelled(true); } GDTimings.PLAYER_INTERACT_INVENTORY_CLICK_EVENT.stopTiming(); }
Example 6
Source File: Observing.java From PGM with GNU Affero General Public License v3.0 | 5 votes |
@Override public void onEvent(InventoryClickEvent event) { super.onEvent(event); if (!(event.getClickedInventory() instanceof PlayerInventory) || event.getCursor() == null) return; ItemStack item = event.getCursor(); if (BAD_TYPES.contains(item.getType()) || item.getData() instanceof Door) { event.setCancelled(true); } }
Example 7
Source File: QuestItemHandler.java From BetonQuest with GNU General Public License v3.0 | 5 votes |
@EventHandler(ignoreCancelled = true) public void onItemMove(final InventoryClickEvent event) { if (!(event.getWhoClicked() instanceof Player)) { return; } if (event.getWhoClicked().getGameMode() == GameMode.CREATIVE) { return; } final String playerID = PlayerConverter.getID((Player) event.getWhoClicked()); ItemStack item; switch (event.getAction()) { case MOVE_TO_OTHER_INVENTORY: item = event.getCurrentItem(); break; case PLACE_ALL: case PLACE_ONE: case PLACE_SOME: case SWAP_WITH_CURSOR: if (event.getClickedInventory().getType() != InventoryType.PLAYER) { item = event.getCursor(); } else { item = null; } break; case HOTBAR_MOVE_AND_READD: case HOTBAR_SWAP: if (event.getClickedInventory().getType() != InventoryType.PLAYER) { item = event.getWhoClicked().getInventory().getItem(event.getHotbarButton()); } else { item = null; } break; default: item = null; break; } if (item != null && (Journal.isJournal(playerID, item) || Utils.isQuestItem(item))) { event.setCancelled(true); } }
Example 8
Source File: InventoryForSingleItem.java From NBTEditor with GNU General Public License v3.0 | 5 votes |
protected ItemStack getItemToCheck(InventoryClickEvent event) { int slot = event.getRawSlot(); boolean isShift = event.isShiftClick(); if (isShift && slot > 8 && event.getInventory().firstEmpty() == 4) { return event.getCurrentItem(); } else if (slot == 4 && !isShift && event.getCursor().getType() != Material.AIR) { return event.getCursor(); } return null; }
Example 9
Source File: TradingPlayerShopkeeper.java From Shopkeepers with GNU General Public License v3.0 | 5 votes |
@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); } }
Example 10
Source File: AnvilListener.java From MineTinker with GNU General Public License v3.0 | 4 votes |
@EventHandler(priority = EventPriority.NORMAL, ignoreCancelled = true) public void onInventoryClick(InventoryClickEvent event) { HumanEntity he = event.getWhoClicked(); if (!(he instanceof Player && event.getClickedInventory() instanceof AnvilInventory)) { return; } AnvilInventory inv = (AnvilInventory) event.getClickedInventory(); Player player = (Player) he; ItemStack tool = inv.getItem(0); ItemStack modifier = inv.getItem(1); ItemStack newTool = inv.getItem(2); if (tool == null || modifier == null || newTool == null) { return; } if (event.getSlot() != 2) { return; } if (Lists.WORLDS.contains(player.getWorld().getName())) { return; } if (!(modManager.isToolViable(tool) || modManager.isArmorViable(tool))) { return; } //boolean deleteAllItems = false; if (event.getCursor() != null && !event.getCursor().getType().equals(Material.AIR)) { return; } if (!modManager.isModifierItem(modifier)) { //upgrade if (tool.getType().equals(newTool.getType())) return; //Not an upgrade if (new Random().nextInt(100) < MineTinker.getPlugin().getConfig().getInt("ChanceToFailToolUpgrade")) { newTool = tool; Bukkit.getPluginManager().callEvent(new ToolUpgradeEvent(player, newTool, false)); } else { Bukkit.getPluginManager().callEvent(new ToolUpgradeEvent(player, newTool, true)); } // ------ upgrade if (event.isShiftClick()) { if (player.getInventory().addItem(newTool).size() != 0) { //adds items to (full) inventory and then case if inventory is full event.setCancelled(true); //cancels the event if the player has a full inventory return; } // no else as it gets added in if-clause inv.clear(); return; } player.setItemOnCursor(newTool); inv.clear(); } else { //is modifier Modifier mod = modManager.getModifierFromItem(modifier); if (mod == null) { return; } modifier.setAmount(modifier.getAmount() - 1); if (new Random().nextInt(100) < MineTinker.getPlugin().getConfig().getInt("ChanceToFailModifierApply")) { newTool = tool; Bukkit.getPluginManager().callEvent(new ModifierFailEvent(player, tool, mod, ModifierFailCause.PLAYER_FAILURE, false)); } else { Bukkit.getPluginManager().callEvent(new ModifierApplyEvent(player, tool, mod, modManager.getFreeSlots(newTool), false)); } if (event.isShiftClick()) { if (player.getInventory().addItem(newTool).size() != 0) { //adds items to (full) inventory and then case if inventory is full event.setCancelled(true); //cancels the event if the player has a full inventory return; } // no else as it gets added in if-clause inv.clear(); inv.setItem(1, modifier); return; } player.setItemOnCursor(newTool); inv.clear(); inv.setItem(1, modifier); } }
Example 11
Source File: CivilianListener.java From Civs with GNU General Public License v3.0 | 4 votes |
@EventHandler(ignoreCancelled = true) @SuppressWarnings("unused") public void onCivilianClickItem(InventoryClickEvent event) { if (event.getClickedInventory() != null) { Location inventoryLocation = event.getClickedInventory().getLocation(); UnloadedInventoryHandler.getInstance().updateInventoryAtLocation(inventoryLocation); } handleCustomItem(event.getCurrentItem(), event.getWhoClicked().getUniqueId()); if (ConfigManager.getInstance().getAllowSharingCivsItems()) { return; } boolean shiftClick = event.getClick().isShiftClick() && event.getClickedInventory() != null && event.getClickedInventory().equals(event.getWhoClicked().getInventory()); boolean dragToChest = event.getClickedInventory() != null && !event.getClickedInventory().equals(event.getWhoClicked().getInventory()); if (event.getView().getTopInventory().getHolder() instanceof DoubleChest) { DoubleChest doubleChest = (DoubleChest) event.getView().getTopInventory().getHolder(); Location leftLocation = ((Chest) doubleChest.getLeftSide()).getLocation(); Location rightLocation = ((Chest) doubleChest.getRightSide()).getLocation(); RegionManager.getInstance().removeCheckedRegion(leftLocation); RegionManager.getInstance().removeCheckedRegion(rightLocation); } else { if (event.getClickedInventory() != null && event.getClickedInventory().getType() != InventoryType.ENDER_CHEST && event.getView().getTopInventory().getType() != InventoryType.ENDER_CHEST) { try { RegionManager.getInstance().removeCheckedRegion(event.getView().getTopInventory().getLocation()); } catch (NullPointerException npe) { // Doesn't matter if there's an error here } } } ItemStack stackInQuestion = shiftClick ? event.getCurrentItem() : event.getCursor(); if (stackInQuestion == null || (!shiftClick && !dragToChest)) { return; } if (!CVItem.isCivsItem(stackInQuestion) || MenuManager.getInstance().hasMenuOpen(event.getWhoClicked().getUniqueId())) { return; } HumanEntity humanEntity = event.getWhoClicked(); event.setCancelled(true); humanEntity.sendMessage(Civs.getPrefix() + LocaleManager.getInstance().getTranslationWithPlaceholders((Player) humanEntity, LocaleConstants.PREVENT_CIVS_ITEM_SHARE)); }
Example 12
Source File: Recipes.java From ProRecipes with GNU General Public License v2.0 | 4 votes |
@EventHandler public void noClickFurnace(InventoryClickEvent event){ if(event.getClickedInventory() != null && event.getClickedInventory().getType().equals(InventoryType.FURNACE)){ //System.out.println(event.getAction()); if(event.getRawSlot() == 0){ //System.out.println(event.getRawSlot()); //System.out.println(event.getAction()); switch(event.getAction()){ case PLACE_ONE: case PLACE_SOME: case PLACE_ALL: case UNKNOWN: case DROP_ALL_CURSOR: case DROP_ALL_SLOT: case DROP_ONE_CURSOR: case DROP_ONE_SLOT: case MOVE_TO_OTHER_INVENTORY: case SWAP_WITH_CURSOR: boolean match = false; RecipeFurnace rec = null; if(event.getCursor() == null || event.getCursor().getType() == Material.AIR){ return; } ItemStack c = event.getCursor().clone(); for(RecipeFurnace r : fur){ if(r.match(c)){ if(r.hasPermission()){ if(!((Player)event.getWhoClicked()).hasPermission(r.getPermission())){ event.setCancelled(true); event.getWhoClicked().sendMessage(ProRecipes.getPlugin().ms.getMessage("no_permission_smelt", ChatColor.RED + "You do not have permission to smelt this item.")); return; } } } } } } } }
Example 13
Source File: CustomItemManager.java From civcraft with GNU General Public License v2.0 | 4 votes |
@EventHandler(priority = EventPriority.HIGHEST) public void OnInventoryClick(InventoryClickEvent event) { boolean currentEmpty = (event.getCurrentItem() == null) || (ItemManager.getId(event.getCurrentItem()) == CivData.AIR); boolean cursorEmpty = (event.getCursor() == null) || (ItemManager.getId(event.getCursor()) == CivData.AIR); if (currentEmpty && cursorEmpty) { return; } convertLegacyItem(event); if (event.getRawSlot() < 0) { //I guess this means "drop the item?" //CivLog.debug("GET RAW WAS NEGATIVE, cancel this event it should be invalid."); //event.setResult(Result.DENY); //event.setCancelled(true); //try { // Player player = CivGlobal.getPlayer(event.getWhoClicked().getName()); // player.updateInventory(); //} catch (CivException e) { //} return; } InventoryView view = event.getView(); Inventory clickedInv; Inventory otherInv; if (view.getType().equals(InventoryType.CRAFTING)) { //This is the player's own inventory. For some reason it requires //special treatment. The 'top' inventory is the 2x2 crafting //area plus the output. During shift click, items do not go there //so the otherInv should always be the player's inventory aka the bottom. if (event.getRawSlot() <= 4) { clickedInv = view.getTopInventory(); otherInv = view.getBottomInventory(); } else { clickedInv = view.getBottomInventory(); otherInv = view.getBottomInventory(); } } else { if (event.getRawSlot() == view.convertSlot(event.getRawSlot())) { //Clicked in the top holder clickedInv = view.getTopInventory(); otherInv = view.getBottomInventory(); } else { clickedInv = view.getBottomInventory(); otherInv = view.getTopInventory(); } } LoreMaterial current = LoreMaterial.getMaterial(event.getCurrentItem()); LoreMaterial cursor = LoreMaterial.getMaterial(event.getCursor()); if (event.isShiftClick()) { // Shift click is _always_ current item. // CustomItemStack is = new CustomItemStack(event.getCurrentItem()); if (current != null) { //if (is.isCustomItem() && (is.getMaterial() instanceof CustomMaterialExtended)) { // Calling onInvShiftClick Event. //((CustomMaterialExtended)is.getMaterial()).onInvShiftClick(event, clickedInv, otherInv, is.getItem()); current.onInvShiftClick(event, clickedInv, otherInv, event.getCurrentItem()); //} } } else { if (!currentEmpty && !cursorEmpty) { //CustomItemStack currentIs = new CustomItemStack(event.getCurrentItem()); //CustomItemStack cursorIs = new CustomItemStack(event.getCursor()); if (current != null) { current.onInvItemSwap(event, clickedInv, event.getCursor(), event.getCurrentItem()); } if (cursor != null) { cursor.onInvItemSwap(event, clickedInv, event.getCursor(), event.getCurrentItem()); } } else if (!currentEmpty) { // This is a pickup event. //CustomItemStack is = new CustomItemStack(event.getCurrentItem()); if (current != null) { // Calling onInvItemPickup Event. current.onInvItemPickup(event, clickedInv, event.getCurrentItem()); } } else { // Implied !cursorEmpty if (cursor != null) { // Calling onInvItemDrop Event. cursor.onInvItemDrop(event, clickedInv, event.getCursor()); } } } }