Java Code Examples for org.bukkit.event.inventory.InventoryMoveItemEvent#setCancelled()

The following examples show how to use org.bukkit.event.inventory.InventoryMoveItemEvent#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: BlockEventHandler.java    From GriefDefender with MIT License 6 votes vote down vote up
@EventHandler(priority = EventPriority.LOWEST)
public void onInventoryMoveItemEvent(InventoryMoveItemEvent event) {
    if (!GDFlags.INVENTORY_ITEM_MOVE || !GriefDefenderPlugin.getGlobalConfig().getConfig().economy.rentSystem) {
        return;
    }
    final World world = event.getSource().getLocation().getWorld();
    if (!GriefDefenderPlugin.getInstance().claimsEnabledForWorld(world.getUID()) || GriefDefenderPlugin.getInstance().getVaultProvider() == null) {
        return;
    }

    final Inventory sourceInventory = event.getSource();
    final Inventory targetInventory = event.getDestination();
    final Location sourceLocation = sourceInventory.getLocation();
    final Location targetLocation = targetInventory.getLocation();
    final GDClaim sourceClaim = GriefDefenderPlugin.getInstance().dataStore.getClaimAt(sourceLocation);
    final GDClaim targetClaim = GriefDefenderPlugin.getInstance().dataStore.getClaimAt(targetLocation);
    if (sourceClaim.isWilderness() && targetClaim.isWilderness() || (GriefDefenderPlugin.getInstance().getVaultProvider() == null)) {
        return;
    }
    if (sourceClaim.getEconomyData().isRented() || targetClaim.getEconomyData().isRented()) {
        event.setCancelled(true);
        return;
    }
}
 
Example 2
Source File: LWCPlayerListener.java    From Modern-LWC with MIT License 6 votes vote down vote up
@EventHandler(ignoreCancelled = true)
public void onMoveItem(InventoryMoveItemEvent event) {
    boolean result;

    // if the initiator is the same as the source it is a dropper i.e.
    // depositing items
    if (event.getInitiator() == event.getSource()) {
        result = handleMoveItemEvent(event.getInitiator(), event.getDestination());
    } else {
        result = handleMoveItemEvent(event.getInitiator(), event.getSource());
    }

    if (result) {
        event.setCancelled(true);
    }
}
 
Example 3
Source File: CivilianListener.java    From Civs with GNU General Public License v3.0 6 votes vote down vote up
@EventHandler(ignoreCancelled = true)
public void onInventoryMoveEvent(InventoryMoveItemEvent event) {
    if (ConfigManager.getInstance().getAllowSharingCivsItems()) {
        return;
    }
    if (!CVItem.isCivsItem(event.getItem())) {
        return;
    }
    if (!(event.getDestination() instanceof PlayerInventory)) {
        event.setCancelled(true);
        if (!event.getSource().getViewers().isEmpty()) {
            HumanEntity humanEntity = event.getSource().getViewers().get(0);
            humanEntity.sendMessage(Civs.getPrefix() +
                    LocaleManager.getInstance().getTranslationWithPlaceholders((Player) humanEntity,
                            LocaleConstants.PREVENT_CIVS_ITEM_SHARE));
        }
    }
}
 
Example 4
Source File: ChestProtectListener.java    From ShopChest with MIT License 6 votes vote down vote up
@EventHandler(priority = EventPriority.HIGH, ignoreCancelled = true)
public void onItemMove(InventoryMoveItemEvent e) {
    if ((e.getSource().getType().equals(InventoryType.CHEST)) && (!e.getInitiator().getType().equals(InventoryType.PLAYER))) {

        if (e.getSource().getHolder() instanceof DoubleChest) {
            DoubleChest dc = (DoubleChest) e.getSource().getHolder();
            Chest r = (Chest) dc.getRightSide();
            Chest l = (Chest) dc.getLeftSide();

            if (shopUtils.isShop(r.getLocation()) || shopUtils.isShop(l.getLocation())) e.setCancelled(true);

        } else if (e.getSource().getHolder() instanceof Chest) {
            Chest c = (Chest) e.getSource().getHolder();

            if (shopUtils.isShop(c.getLocation())) e.setCancelled(true);
        }
    }
}
 
Example 5
Source File: BlockListeners.java    From CratesPlus with GNU General Public License v3.0 6 votes vote down vote up
@EventHandler
public void onInventoryMove(InventoryMoveItemEvent event) {
    if (!cratesPlus.getConfigHandler().isDisableKeySwapping())
        return;
    String title;
    ItemStack item = event.getItem();

    for (Map.Entry<String, Crate> crate : cratesPlus.getConfigHandler().getCrates().entrySet()) {
        if (!(crate.getValue() instanceof KeyCrate)) {
            continue;
        }
        KeyCrate keyCrate = (KeyCrate) crate.getValue();
        Key key = keyCrate.getKey();
        if (key == null)
            continue;
        title = key.getName();

        if (item.hasItemMeta() && item.getItemMeta().hasDisplayName() && item.getItemMeta().getDisplayName().contains(title)) {
            // Send message?
            event.setCancelled(true);
            return;
        }
    }
}
 
Example 6
Source File: ShopProtectionListener.java    From QuickShop-Reremake with GNU General Public License v3.0 5 votes vote down vote up
@EventHandler(ignoreCancelled = true, priority = EventPriority.HIGH)
public void onInventoryMove(InventoryMoveItemEvent event) {
    if (!plugin.getConfig().getBoolean("protect.hopper")) {
        return;
    }
    final Location loc = event.getSource().getLocation();

    if (loc == null) {
        return;
    }
    final Shop shop = getShopRedstone(loc, true);

    if (shop == null) {
        return;
    }

    event.setCancelled(true);

    final Location location = event.getInitiator().getLocation();

    if (location == null) {
        return;
    }

    final InventoryHolder holder = event.getInitiator().getHolder();

    if (holder instanceof Entity) {
        ((Entity) holder).remove();
    } else if (holder instanceof Block) {
        location.getBlock().breakNaturally();
    } else {
        Util.debugLog("Unknown location = " + loc);
    }

    if (sendProtectionAlert) {
        MsgUtil.sendGlobalAlert("[DisplayGuard] Defened a item steal action at" + location);
    }
}
 
Example 7
Source File: QAListener.java    From QualityArmory with GNU General Public License v3.0 5 votes vote down vote up
@EventHandler
public void onHopper(InventoryMoveItemEvent e) {
	if (e.isCancelled())
		return;
	if (e.getSource().getType() == InventoryType.HOPPER || e.getSource().getType() == InventoryType.DISPENSER
			|| e.getSource().getType() == InventoryType.DROPPER)
		if (QualityArmory.isGun(e.getItem()))
			e.setCancelled(true);
}
 
Example 8
Source File: ATM.java    From TimeIsMoney with GNU General Public License v3.0 5 votes vote down vote up
@EventHandler
public void onMove(InventoryMoveItemEvent e) {
	if (e.getSource() == null || e.getSource().getViewers().size() == 0 || e.getSource().getViewers().get(0).getOpenInventory() == null) return;
	if (openATMs.contains(e.getSource().getViewers().get(0).getOpenInventory().getTopInventory())) {
		e.setCancelled(true);
	}
}
 
Example 9
Source File: PotionFuelsListener.java    From UHC with MIT License 5 votes vote down vote up
@EventHandler(ignoreCancelled = true)
public void on(InventoryMoveItemEvent event) {
    if (event.getDestination().getType() != InventoryType.BREWING) return;

    if (disabled.contains(event.getItem().getType())) {
        event.setCancelled(true);
    }
}
 
Example 10
Source File: CreativeModeListener.java    From ShopChest with MIT License 5 votes vote down vote up
@EventHandler(priority = EventPriority.HIGHEST)
public void onInventoryMove(InventoryMoveItemEvent e) {
    // Cancel any inventory movement if SelectClickType is set
    if (e.getSource().getHolder() instanceof Player) {
        Player p = (Player) e.getSource().getHolder();

        ClickType clickType = ClickType.getPlayerClickType(p);
        if (clickType instanceof SelectClickType)
            e.setCancelled(true);
    }
}
 
Example 11
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 onItemMove(InventoryMoveItemEvent event)
{
	if(event.getDestination().getHolder() instanceof Backpack && isItemBlocked(event.getItem()))
	{
		if(event.getSource().getHolder() instanceof Player)
		{
			sendNotAllowedMessage((Player) event.getSource().getHolder(), event.getItem());
		}
		event.setCancelled(true);
	}
}
 
Example 12
Source File: ChestProtectListener.java    From Shopkeepers with GNU General Public License v3.0 5 votes vote down vote up
@EventHandler(ignoreCancelled = true)
void onInventoryMoveItem(InventoryMoveItemEvent event) {
	if (event.getSource() != null) {
		InventoryHolder holder = event.getSource().getHolder();
		if (holder != null && holder instanceof Chest) {
			Block block = ((Chest) holder).getBlock();
			if (plugin.getProtectedChests().isChestProtected(block, null)) {
				event.setCancelled(true);
			}
		}
	}
}
 
Example 13
Source File: CustomInventoryListener.java    From QuickShop-Reremake with GNU General Public License v3.0 4 votes vote down vote up
@EventHandler(ignoreCancelled = true)
public void invEvent(InventoryMoveItemEvent e) {
    if (e.getDestination().getHolder() instanceof QuickShopPreviewInventoryHolder || e.getSource().getHolder() instanceof QuickShopPreviewInventoryHolder) {
        e.setCancelled(true);
    }
}