Java Code Examples for org.bukkit.event.Event.Result#DENY

The following examples show how to use org.bukkit.event.Event.Result#DENY . 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: SlimefunGuideListener.java    From Slimefun4 with GNU General Public License v3.0 6 votes vote down vote up
private Result openGuide(PlayerRightClickEvent e, SlimefunGuideLayout layout) {
    Player p = e.getPlayer();
    ItemStack item = e.getItem();

    if (SlimefunUtils.isItemSimilar(item, SlimefunGuide.getItem(layout), true)) {
        e.cancel();

        if (!SlimefunPlugin.getWorldSettingsService().isWorldEnabled(p.getWorld())) {
            SlimefunPlugin.getLocalization().sendMessage(p, "messages.disabled-item", true);
            return Result.DENY;
        }

        return Result.ALLOW;
    }

    return Result.DEFAULT;
}
 
Example 2
Source File: SignShopListener.java    From Shopkeepers with GNU General Public License v3.0 6 votes vote down vote up
@EventHandler(priority = EventPriority.HIGHEST, ignoreCancelled = false)
void onPlayerInteract(PlayerInteractEvent event) {
	Player player = event.getPlayer();
	Block block = event.getClickedBlock();

	// check for sign shop
	if (event.getAction() == Action.RIGHT_CLICK_BLOCK && Utils.isSign(block.getType())) {
		Shopkeeper shopkeeper = plugin.getShopkeeperByBlock(block);
		if (shopkeeper != null) {
			// only trigger shopkeeper interaction for main-hand events:
			if (NMSManager.getProvider().isMainHandInteraction(event)) {
				Log.debug("Player " + player.getName() + " is interacting with sign shopkeeper at " + block.getWorld().getName() + "," + block.getX() + "," + block.getY() + "," + block.getZ());
				if (event.useInteractedBlock() == Result.DENY) {
					Log.debug("  Cancelled by another plugin");
				} else {
					shopkeeper.onPlayerInteraction(player);
				}
			}

			// always cancel interactions with shopkeepers, to prevent any default behavior:
			event.setCancelled(true);
		}
	}
}
 
Example 3
Source File: AncientAltarListener.java    From Slimefun4 with GNU General Public License v3.0 5 votes vote down vote up
@EventHandler
public void onInteract(PlayerRightClickEvent e) {
    if (altar == null || altar.isDisabled() || e.useBlock() == Result.DENY) {
        return;
    }

    Optional<Block> blockOptional = e.getClickedBlock();
    if (!blockOptional.isPresent()) {
        return;
    }

    Block b = blockOptional.get();
    if (b.getType() != Material.ENCHANTING_TABLE && b.getType() != Material.DISPENSER) {
        return;
    }

    Optional<SlimefunItem> slimefunBlock = e.getSlimefunBlock();
    if (!slimefunBlock.isPresent()) {
        return;
    }

    String id = slimefunBlock.get().getID();

    if (id.equals(SlimefunItems.ANCIENT_PEDESTAL.getItemId())) {
        e.cancel();
        usePedestal(b, e.getPlayer());
    }
    else if (id.equals(SlimefunItems.ANCIENT_ALTAR.getItemId())) {
        if (!Slimefun.hasUnlocked(e.getPlayer(), SlimefunItems.ANCIENT_ALTAR.getItem(), true) || altarsInUse.contains(b.getLocation())) {
            e.cancel();
            return;
        }

        // Make altarinuse simply because that was the last block clicked.
        altarsInUse.add(b.getLocation());
        e.cancel();

        useAltar(b, e.getPlayer());
    }
}
 
Example 4
Source File: SlimefunItemListener.java    From Slimefun4 with GNU General Public License v3.0 5 votes vote down vote up
@EventHandler
public void onRightClick(PlayerInteractEvent e) {
    if (e.getAction() == Action.RIGHT_CLICK_AIR || e.getAction() == Action.RIGHT_CLICK_BLOCK) {
        if (SlimefunUtils.isItemSimilar(e.getItem(), SlimefunItems.DEBUG_FISH, true)) {
            return;
        }

        PlayerRightClickEvent event = new PlayerRightClickEvent(e);
        Bukkit.getPluginManager().callEvent(event);

        boolean itemUsed = e.getHand() == EquipmentSlot.OFF_HAND;

        if (event.useItem() != Result.DENY) {
            rightClickItem(e, event, itemUsed);
        }

        if (!itemUsed && event.useBlock() != Result.DENY && !rightClickBlock(e, event)) {
            return;
        }

        if (e.useInteractedBlock() != Result.DENY) {
            e.setUseInteractedBlock(event.useBlock());
        }

        if (e.useItemInHand() != Result.DENY) {
            e.setUseItemInHand(event.useItem());
        }
    }
}