Java Code Examples for org.bukkit.event.inventory.InventoryDragEvent#setCancelled()
The following examples show how to use
org.bukkit.event.inventory.InventoryDragEvent#setCancelled() .
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: LoreGuiItemListener.java From civcraft with GNU General Public License v2.0 | 6 votes |
@EventHandler(priority = EventPriority.LOW) public void OnInventoryDragEvent(InventoryDragEvent event) { if (event.isCancelled()) { return; } for (int slot : event.getRawSlots()) { if (slot < event.getView().getTopInventory().getSize()) { if (guiInventories.containsKey(event.getView().getTopInventory().getName())) { event.setCancelled(true); return; } } } }
Example 2
Source File: Recipes.java From ProRecipes with GNU General Public License v2.0 | 6 votes |
@EventHandler public void onDrag(InventoryDragEvent event){ // int counter = 0; if(event.getInventory().getName() != null && event.getInventory().getName().equalsIgnoreCase(ProRecipes.getPlugin().ms.getMessage("Multi_Craft_GUI", ChatColor.GOLD + "Multi-Craft Table"))){ for(int b : event.getInventorySlots()){ if(((b-1) % 9 == 0 || (b-2) % 9 == 0 || (b-3) % 9 == 0 || (b-4) % 9 == 0) && event.getInventorySlots().size() > 1){ if(empty(event.getInventory(), null) && !emptyResults(event.getInventory())){ event.setCancelled(true); return; }else{ callClick(b, event.getView()); } continue; }else{ event.setCancelled(true); break; } } } }
Example 3
Source File: ArmorStandGUI.java From ArmorStandTools with MIT License | 6 votes |
@EventHandler public void onInventoryDrag(InventoryDragEvent event) { if(!event.getInventory().equals(i) || !(event.getWhoClicked() instanceof Player)) return; Player p = (Player) event.getWhoClicked(); boolean invModified = false; for(int slot : event.getRawSlots()) { if(slot < i.getSize()) { if(invSlots.contains(slot)) { invModified = true; } else { event.setCancelled(true); return; } } } if(invModified) { if(plugin.checkBlockPermission(p, as.getLocation().getBlock())) { updateInventory(); } else { event.setCancelled(true); p.sendMessage(ChatColor.RED + Config.wgNoPerm); } } }
Example 4
Source File: ItemFilter.java From Minepacks with GNU General Public License v3.0 | 5 votes |
@EventHandler(priority = EventPriority.HIGHEST, ignoreCancelled = true) public void onItemDrag(InventoryDragEvent event) { if(event.getInventory().getHolder() instanceof Backpack && (isItemBlocked(event.getOldCursor()) || isItemBlocked(event.getCursor())) && event.getRawSlots().containsAll(event.getInventorySlots())) { messageNotAllowedInBackpack.send(event.getView().getPlayer(), itemNameResolver.getName(event.getOldCursor())); event.setCancelled(true); } }
Example 5
Source File: InventoryForItemStorage.java From NBTEditor with GNU General Public License v3.0 | 5 votes |
@Override protected void inventoryDrag(InventoryDragEvent event) { InventoryView view = event.getView(); for (int slot : event.getRawSlots()) { if (view.getInventory(slot).getType() != InventoryType.PLAYER) { event.setCancelled(true); return; } } }
Example 6
Source File: QuestItemHandler.java From BetonQuest with GNU General Public License v3.0 | 5 votes |
@EventHandler(ignoreCancelled = true) public void onItemDrag(final InventoryDragEvent event) { if (!(event.getWhoClicked() instanceof Player)) { return; } if (event.getWhoClicked().getGameMode() == GameMode.CREATIVE) { return; } final String playerID = PlayerConverter.getID((Player) event.getWhoClicked()); if (Journal.isJournal(playerID, event.getOldCursor()) || Utils.isQuestItem(event.getOldCursor())) { event.setCancelled(true); } }
Example 7
Source File: Listeners.java From PlayerVaults with GNU General Public License v3.0 | 5 votes |
@EventHandler(ignoreCancelled = true) public void onDrag(InventoryDragEvent event) { if (!(event.getWhoClicked() instanceof Player)) { return; } Player player = (Player) event.getWhoClicked(); Inventory clickedInventory = event.getInventory(); if (clickedInventory != null) { VaultViewInfo info = PlayerVaults.getInstance().getInVault().get(player.getUniqueId().toString()); if (info != null) { int num = info.getNumber(); String inventoryTitle = event.getView().getTitle(); String title = Lang.VAULT_TITLE.toString().replace("%number", String.valueOf(num)).replace("%p", info.getVaultName()); if ((inventoryTitle != null && inventoryTitle.equalsIgnoreCase(title)) && event.getNewItems() != null) { for (ItemStack item : event.getNewItems().values()) { try { item.toString(); } catch (Exception e) { player.sendMessage(Lang.TITLE.toString() + Lang.BLOCKED_BAD_ITEM); event.setCancelled(true); continue; } if (!player.hasPermission("playervaults.bypassblockeditems") && PlayerVaults.getInstance().isBlockedMaterial(item.getType())) { event.setCancelled(true); player.sendMessage(Lang.TITLE.toString() + Lang.BLOCKED_ITEM.toString().replace("%m", item.getType().name())); return; } } } } } }
Example 8
Source File: MenuManager.java From ZombieEscape with GNU General Public License v2.0 | 5 votes |
@EventHandler public void onClick(InventoryDragEvent e) { Inventory inv = e.getWhoClicked().getOpenInventory().getTopInventory(); for (Menu menu : menus.values()) { if (menu.getInventory().getName().equals(inv.getName())) { e.setCancelled(true); } } }
Example 9
Source File: IconInventory.java From UHC with MIT License | 5 votes |
@EventHandler public void on(InventoryDragEvent event) { final Inventory inventory = event.getInventory(); if (!inventory.getTitle().equals(title)) return; event.setCancelled(true); }
Example 10
Source File: HorseArmourModule.java From UHC with MIT License | 5 votes |
@EventHandler(ignoreCancelled = true) public void on(InventoryDragEvent event) { if (isEnabled()) return; if (!(event.getView().getTopInventory() instanceof HorseInventory)) return; // if it's not a disabled type do nothing if (!DISABLED.contains(event.getOldCursor().getType())) return; event.getWhoClicked().sendMessage(messages.getRaw("disabled message")); event.setCancelled(true); }
Example 11
Source File: PotionFuelsListener.java From UHC with MIT License | 5 votes |
@EventHandler(ignoreCancelled = true) public void on(InventoryDragEvent event) { if (event.getInventory().getType() != InventoryType.BREWING) return; // if it's not a disabled type do nothing if (!disabled.contains(event.getOldCursor().getType())) return; // check if they dragged over the ingredient if (event.getRawSlots().contains(INGREDIENT_SLOT_ID)) { event.getWhoClicked().sendMessage(messages.get(event.getOldCursor().getType())); event.setCancelled(true); } }
Example 12
Source File: MainListener.java From ArmorStandTools with MIT License | 5 votes |
@EventHandler public void onInventoryDrag(InventoryDragEvent event) { if (event.isCancelled() || !(event.getWhoClicked() instanceof Player)) return; final Player p = (Player) event.getWhoClicked(); if (event.getInventory().getHolder() != p && Utils.containsItems(event.getNewItems().values())) { event.setCancelled(true); //noinspection deprecation p.updateInventory(); } }
Example 13
Source File: ItemBuilder.java From ProRecipes with GNU General Public License v2.0 | 5 votes |
@EventHandler public void inventoryDrag(InventoryDragEvent event){ if(!event.getInventory().getType().equals(InventoryType.WORKBENCH))return; if(!event.getWhoClicked().hasMetadata("itemBuilder"))return; String step = event.getWhoClicked().getMetadata("itemBuilder").get(0).asString(); if(step.equalsIgnoreCase("itemRequest")){ event.setCancelled(true); } }
Example 14
Source File: RecipeBuilder.java From ProRecipes with GNU General Public License v2.0 | 5 votes |
@EventHandler public void inventoryDrag(InventoryDragEvent event){ if(!event.getInventory().getType().equals(InventoryType.WORKBENCH))return; if(!event.getWhoClicked().hasMetadata("recipeBuilder"))return; String step = event.getWhoClicked().getMetadata("recipeBuilder").get(0).asString(); if(step.contains("itemRequest")){ event.setCancelled(true); } }
Example 15
Source File: AnvilGUI.java From AnvilGUI with MIT License | 5 votes |
@EventHandler public void onInventoryDrag(InventoryDragEvent event) { if (event.getInventory().equals(inventory)) { for (int slot : Slot.values()) { if (event.getRawSlots().contains(slot)) { event.setCancelled(true); break; } } } }
Example 16
Source File: CivilianListener.java From Civs with GNU General Public License v3.0 | 5 votes |
@EventHandler(ignoreCancelled = true) public void onCivilianDragItem(InventoryDragEvent event) { if (event.getView().getTopInventory().getHolder() instanceof Chest) { Location inventoryLocation = ((Chest) event.getView().getTopInventory().getHolder()).getLocation(); UnloadedInventoryHandler.getInstance().updateInventoryAtLocation(inventoryLocation); } if (ConfigManager.getInstance().getAllowSharingCivsItems()) { return; } ItemStack dragged = event.getOldCursor(); if (!CVItem.isCivsItem(dragged) || MenuManager.getInstance().hasMenuOpen(event.getWhoClicked().getUniqueId())) { return; } int inventorySize = event.getInventory().getSize(); for (int i : event.getRawSlots()) { if (i < inventorySize) { event.setCancelled(true); HumanEntity humanEntity = event.getWhoClicked(); humanEntity.sendMessage(Civs.getPrefix() + LocaleManager.getInstance().getTranslationWithPlaceholders((Player) humanEntity, LocaleConstants.PREVENT_CIVS_ITEM_SHARE)); return; } } }
Example 17
Source File: CEListener.java From ce with GNU Lesser General Public License v3.0 | 5 votes |
@EventHandler(priority = EventPriority.HIGHEST) public void inventoryMenuPrevention(InventoryDragEvent event) { if (event.getView().getTopInventory().getTitle().startsWith("CE")) event.setCancelled(true); else if (useRuneCrafting) if (event.getView().getTopInventory().getName().equals( ChatColor.LIGHT_PURPLE + "" + ChatColor.MAGIC + "abc" + ChatColor.RESET + ChatColor.DARK_PURPLE + " Runecrafting " + ChatColor.LIGHT_PURPLE + "" + ChatColor.MAGIC + "cba")) { CEventHandler.updateRunecraftingInventory(event.getInventory()); return; } }
Example 18
Source File: ItemTransferListener.java From ProjectAres with GNU Affero General Public License v3.0 | 5 votes |
@EventHandler(ignoreCancelled = true) public void onPlayerDragInventory(InventoryDragEvent event) { // This is when you spread items evenly across slots by dragging if(!(event.getWhoClicked() instanceof Player)) { return; } Player player = (Player) event.getWhoClicked(); ItemStack transferred = event.getOldCursor().clone(); transferred.setAmount(0); Inventory externalInventory = null; for(Map.Entry<Integer, ItemStack> entry : event.getNewItems().entrySet()) { Inventory inventory = getLocalInventory(event.getView(), entry.getKey()); if(inventory.getHolder() != player) { // Add stacks to the total if they are dragged over an external inventory externalInventory = inventory; transferred.setAmount(transferred.getAmount() + entry.getValue().getAmount()); } } if(externalInventory != null) { int initialQuantity = transferred.getAmount(); PlayerItemTransferEvent transferEvent = new PlayerItemTransferEvent( event, ItemTransferEvent.Type.PLACE, player, Optional.empty(), Optional.of(new InventorySlot<>(externalInventory)), transferred, null, initialQuantity, event.getOldCursor() ); this.callEvent(transferEvent); if(initialQuantity != transferEvent.getQuantity()) { // If the quantity changes, we have to cancel the entire drag, // because bukkit does not let us modify the dragged stacks. event.setCancelled(true); } } }
Example 19
Source File: Recipes.java From ProRecipes with GNU General Public License v2.0 | 4 votes |
@EventHandler public void onDraggy(InventoryDragEvent event){ if(event.getInventory().getType().equals(InventoryType.FURNACE)){ event.setCancelled(true); } }
Example 20
Source File: CustomInventoryListener.java From QuickShop-Reremake with GNU General Public License v3.0 | 4 votes |
@EventHandler(ignoreCancelled = true) public void invEvent(InventoryDragEvent e) { if (e.getInventory().getHolder() instanceof QuickShopPreviewInventoryHolder) { e.setCancelled(true); } }