org.bukkit.event.inventory.InventoryDragEvent Java Examples

The following examples show how to use org.bukkit.event.inventory.InventoryDragEvent. 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: Recipes.java    From ProRecipes with GNU General Public License v2.0 6 votes vote down vote up
@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 #2
Source File: LoreGuiItemListener.java    From civcraft with GNU General Public License v2.0 6 votes vote down vote up
@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 #3
Source File: ArmorStandGUI.java    From ArmorStandTools with MIT License 6 votes vote down vote up
@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: MainListener.java    From ArmorStandTools with MIT License 5 votes vote down vote up
@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 #5
Source File: ItemFilter.java    From Minepacks with GNU General Public License v3.0 5 votes vote down vote up
@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 #6
Source File: AnvilGUI.java    From AnvilGUI with MIT License 5 votes vote down vote up
@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 #7
Source File: RecipeBuilder.java    From ProRecipes with GNU General Public License v2.0 5 votes vote down vote up
@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 #8
Source File: ItemBuilder.java    From ProRecipes with GNU General Public License v2.0 5 votes vote down vote up
@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 #9
Source File: ExtraBackpackListener.java    From NyaaUtils with MIT License 5 votes vote down vote up
@EventHandler
public void onInventoryDrag(InventoryDragEvent event) {
    if (event.getInventory().getHolder() instanceof ExtraBackpackGUI) {
        ((ExtraBackpackGUI) event.getInventory().getHolder()).taint();
        ((ExtraBackpackGUI) event.getInventory().getHolder()).onInventoryDrag(event);
    }
}
 
Example #10
Source File: InventoryEvent.java    From MCAuthenticator with GNU General Public License v3.0 5 votes vote down vote up
@EventHandler
public void onInventoryChange(InventoryDragEvent e) {
    if (!(e.getWhoClicked() instanceof Player)) return;
    if (isInQR((Player) e.getWhoClicked())) {
        e.setResult(Event.Result.DENY);
        e.getWhoClicked().closeInventory();//Should be viewing map
    }
}
 
Example #11
Source File: ATM.java    From TimeIsMoney with GNU General Public License v3.0 5 votes vote down vote up
@EventHandler
public void onInventoryDrag(InventoryDragEvent e) {
	if (e == null || e.getInventory() == null) return;

	if (openATMs.contains(e.getView().getTopInventory())) {
		e.setResult(Result.DENY);
	}
}
 
Example #12
Source File: DragTarget.java    From black with GNU General Public License v3.0 5 votes vote down vote up
@Override
public void handle(final InventoryInteractEvent event) {
    if (event instanceof InventoryDragEvent &&
            Arrays.stream(reqs).allMatch(req -> req.control(event))) {

        handler.accept(new ElementDragEvent((InventoryDragEvent) event));
    }
}
 
Example #13
Source File: PotionFuelsListener.java    From UHC with MIT License 5 votes vote down vote up
@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 #14
Source File: HorseArmourModule.java    From UHC with MIT License 5 votes vote down vote up
@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 #15
Source File: IconInventory.java    From UHC with MIT License 5 votes vote down vote up
@EventHandler
public void on(InventoryDragEvent event) {
    final Inventory inventory = event.getInventory();
    if (!inventory.getTitle().equals(title)) return;

    event.setCancelled(true);
}
 
Example #16
Source File: MenuManager.java    From ZombieEscape with GNU General Public License v2.0 5 votes vote down vote up
@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 #17
Source File: CreativeModeListener.java    From ShopChest with MIT License 5 votes vote down vote up
@EventHandler(priority = EventPriority.HIGHEST)
public void onInventoryDrag(InventoryDragEvent e) {
    // Cancel any inventory drags if SelectClickType is set
    HumanEntity entity = e.getWhoClicked();
    if (!(entity instanceof Player))
        return;

    ClickType clickType = ClickType.getPlayerClickType((Player) entity);
    if (clickType instanceof SelectClickType)
        e.setCancelled(true);
}
 
Example #18
Source File: QuestItemHandler.java    From BetonQuest with GNU General Public License v3.0 5 votes vote down vote up
@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 #19
Source File: TradeInventoryListener.java    From civcraft with GNU General Public License v2.0 5 votes vote down vote up
@EventHandler(priority = EventPriority.LOW)
public void onInventoryDragEvent(InventoryDragEvent event) {
	if (!(event.getWhoClicked() instanceof Player)) {
		return;
	}
	Player player = (Player)event.getWhoClicked();
	Resident resident = CivGlobal.getResident(player);
	TradeInventoryPair pair = tradeInventories.get(getTradeInventoryKey(resident));
	if (pair == null) {
		return;
	}
	
	Inventory savedTradeInventory = pair.inv;
	if (savedTradeInventory == null) {
		return;
	}
	
	if (!savedTradeInventory.getName().equals(event.getInventory().getName())) {
		return;
	}
	
	for (int slot : event.getRawSlots()) {
		if (!handleSlotChange(slot, pair)) {
			event.setCancelled(true);
			return;
		}
	}
}
 
Example #20
Source File: DragTypeReq.java    From black with GNU General Public License v3.0 5 votes vote down vote up
@Override
public boolean control(final InventoryInteractEvent event) {
    if (event instanceof InventoryDragEvent) {
        return ((InventoryDragEvent) event).getType() == dragType;
    } else {
        return false;
    }
}
 
Example #21
Source File: InventoryForItemStorage.java    From NBTEditor with GNU General Public License v3.0 5 votes vote down vote up
@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 #22
Source File: InventoryGui.java    From InventoryGui with MIT License 5 votes vote down vote up
public void unregister() {
    InventoryClickEvent.getHandlerList().unregister(this);
    InventoryDragEvent.getHandlerList().unregister(this);
    InventoryCloseEvent.getHandlerList().unregister(this);
    InventoryMoveItemEvent.getHandlerList().unregister(this);
    BlockDispenseEvent.getHandlerList().unregister(this);
    BlockBreakEvent.getHandlerList().unregister(this);
    EntityDeathEvent.getHandlerList().unregister(this);
}
 
Example #23
Source File: Listeners.java    From PlayerVaults with GNU General Public License v3.0 5 votes vote down vote up
@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 #24
Source File: ItemTransferListener.java    From ProjectAres with GNU Affero General Public License v3.0 5 votes vote down vote up
@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 #25
Source File: DuctSettingsInventory.java    From Transport-Pipes with MIT License 5 votes vote down vote up
@EventHandler
public void onDrag(InventoryDragEvent e) {
    if (e.getInventory() != null && e.getInventory().equals(inv) && e.getWhoClicked() instanceof Player) {
        if (drag((Player) e.getWhoClicked(), e.getRawSlots(), e.getType())) {
            e.setCancelled(true);
        }
    }
}
 
Example #26
Source File: MenuManager.java    From Civs with GNU General Public License v3.0 5 votes vote down vote up
@EventHandler(ignoreCancelled = true) @SuppressWarnings("unused")
public void onInventoryDrag(InventoryDragEvent event) {
    UUID uuid = event.getWhoClicked().getUniqueId();
    if (!openMenus.containsKey(uuid)) {
        return;
    }
    menus.get(openMenus.get(uuid)).onInventoryDrag(event);
}
 
Example #27
Source File: CivilianListener.java    From Civs with GNU General Public License v3.0 5 votes vote down vote up
@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 #28
Source File: InventoryDragListener.java    From black with GNU General Public License v3.0 5 votes vote down vote up
/**
 * the listener that listens for inventory drags and informs the pages associated with them.
 *
 * @param event the event that happened
 * @see InventoryDragEvent
 */
@EventHandler
public void listener(final InventoryDragEvent event) {
    if (event.getInventory().getHolder() instanceof Page &&
            !(event.getInventory() instanceof PlayerInventory)) {

        ((Page) event.getInventory().getHolder()).accept(event);
    }
}
 
Example #29
Source File: AddedElementReq.java    From black with GNU General Public License v3.0 5 votes vote down vote up
@Override
public boolean control(final InventoryInteractEvent event) {
    if (event instanceof InventoryDragEvent) {
        return ((InventoryDragEvent) event).getNewItems().values()
            .stream().anyMatch(element::is);
    }
    return false;
}
 
Example #30
Source File: DraggedItemReq.java    From black with GNU General Public License v3.0 5 votes vote down vote up
@Override
public boolean control(final InventoryInteractEvent event) {
    if (event instanceof InventoryClickEvent) {
        return false;
    } else {
        return ((InventoryDragEvent) event).getOldCursor().equals(item);
    }
}