Java Code Examples for org.bukkit.event.player.PlayerInteractEvent#isCancelled()

The following examples show how to use org.bukkit.event.player.PlayerInteractEvent#isCancelled() . 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: AntiGriefListener.java    From PGM with GNU Affero General Public License v3.0 6 votes vote down vote up
@EventHandler(priority = EventPriority.MONITOR)
public void cloneCraftingWindow(final PlayerInteractEvent event) {
  if (!event.isCancelled()
      && event.getAction() == Action.RIGHT_CLICK_BLOCK
      && event.getPlayer().getOpenInventory().getType()
          == InventoryType.CRAFTING /* nothing open */) {
    Block block = event.getClickedBlock();
    if (block != null
        && block.getType() == Material.WORKBENCH
        && !event.getPlayer().isSneaking()) {
      // create the window ourself
      event.setCancelled(true);
      event.getPlayer().openWorkbench(null, true); // doesn't check reachable
    }
  }
}
 
Example 2
Source File: SpawnEvents.java    From uSkyBlock with GNU General Public License v3.0 6 votes vote down vote up
@EventHandler
public void onSpawnEggEvent(PlayerInteractEvent event) {
    Player player = event != null ? event.getPlayer() : null;
    if (player == null || event.isCancelled() || !plugin.getWorldManager().isSkyWorld(player.getWorld())) {
        return; // Bail out, we don't care
    }
    if (player.hasPermission("usb.mod.bypassprotection") || player.isOp()) {
        return;
    }
    ItemStack item = event.getItem();
    if (RIGHT_CLICKS.contains(event.getAction()) && item != null && isSpawnEgg(item)) {
        if (!plugin.playerIsOnIsland(player)) {
            event.setCancelled(true);
            plugin.notifyPlayer(player, tr("\u00a7eYou can only use spawn-eggs on your own island."));
            return;
        }
        SpawnEgg spawnEgg = (SpawnEgg) item.getData();
        checkLimits(event, spawnEgg.getSpawnedType(), player.getLocation());
        if (event.isCancelled()) {
            plugin.notifyPlayer(player, tr("\u00a7cYou have reached your spawn-limit for your island."));
            event.setUseItemInHand(Event.Result.DENY);
            event.setUseInteractedBlock(Event.Result.DENY);
        }
    }
}
 
Example 3
Source File: ToolMenuEvents.java    From uSkyBlock with GNU General Public License v3.0 6 votes vote down vote up
@EventHandler(priority = EventPriority.LOW, ignoreCancelled = true)
public void onBlockHit(PlayerInteractEvent e) {
    if (e == null || e.getClickedBlock() == null
            || e.getAction() != Action.LEFT_CLICK_BLOCK || e.getPlayer().getGameMode() != GameMode.SURVIVAL) {
        return;
    }
    Player player = e.getPlayer();
    if (!plugin.getWorldManager().isSkyAssociatedWorld(player.getWorld()) || !isTool(e.getItem())) {
        return;
    }

    // We are in a skyworld, a block has been hit, with the tool
    Material block = e.getClickedBlock().getType();
    short data = e.getClickedBlock().getData();
    String itemId = ItemStackUtil.asString(new ItemStack(block, 1, data));
    if (commandMap.containsKey(itemId)) {
        doCmd(e, player, itemId);
    }
    if (!e.isCancelled()) {
        itemId = ItemStackUtil.asString(new ItemStack(block, 1));
        if (commandMap.containsKey(itemId)) {
            doCmd(e, player, itemId);
        }
    }
}
 
Example 4
Source File: SignEvents.java    From uSkyBlock with GNU General Public License v3.0 6 votes vote down vote up
@EventHandler(priority = EventPriority.HIGH)
public void onPlayerHitSign(PlayerInteractEvent e) {
    if (e.isCancelled()
            || e.getPlayer() == null
            || (e.getAction() != Action.RIGHT_CLICK_BLOCK && e.getAction() != Action.LEFT_CLICK_BLOCK)
            || e.getClickedBlock() == null
            || e.getClickedBlock().getType() != SkyBlockMenu.WALL_SIGN_MATERIAL
            || !(e.getClickedBlock().getState() instanceof Sign)
            || !e.getPlayer().hasPermission("usb.island.signs.use")
            || !plugin.getWorldManager().isSkyAssociatedWorld(e.getPlayer().getWorld())
            || !(plugin.playerIsOnOwnIsland(e.getPlayer()))
            ) {
        return;
    }
    if (e.getAction() == Action.LEFT_CLICK_BLOCK) {
        logic.updateSign(e.getClickedBlock().getLocation());
    } else {
        logic.signClicked(e.getPlayer(), e.getClickedBlock().getLocation());
    }
}
 
Example 5
Source File: PlayerListener.java    From civcraft with GNU General Public License v2.0 6 votes vote down vote up
@EventHandler(priority = EventPriority.HIGHEST)
public void onInventoryOpenEvent(InventoryOpenEvent event) {
	if (event.getInventory() instanceof DoubleChestInventory) {
		DoubleChestInventory doubleInv = (DoubleChestInventory)event.getInventory();
					
		Chest leftChest = (Chest)doubleInv.getHolder().getLeftSide();			
		/*Generate a new player 'switch' event for the left and right chests. */
		PlayerInteractEvent interactLeft = new PlayerInteractEvent((Player)event.getPlayer(), Action.RIGHT_CLICK_BLOCK, null, leftChest.getBlock(), null);
		BlockListener.OnPlayerSwitchEvent(interactLeft);
		
		if (interactLeft.isCancelled()) {
			event.setCancelled(true);
			return;
		}
		
		Chest rightChest = (Chest)doubleInv.getHolder().getRightSide();
		PlayerInteractEvent interactRight = new PlayerInteractEvent((Player)event.getPlayer(), Action.RIGHT_CLICK_BLOCK, null, rightChest.getBlock(), null);
		BlockListener.OnPlayerSwitchEvent(interactRight);
		
		if (interactRight.isCancelled()) {
			event.setCancelled(true);
			return;
		}			
	}
}
 
Example 6
Source File: JumpPads.java    From HubBasics with GNU Lesser General Public License v3.0 6 votes vote down vote up
@EventHandler
public void onPlayerInteract(PlayerInteractEvent event) {
    if (!needsPressurePlate(event.getPlayer())) return;
    Player player = event.getPlayer();
    if (event.getAction() == Action.PHYSICAL && !event.isCancelled() && isEnabledInWorld(player.getWorld())) {
        if (event.getClickedBlock().getType() == getPlateType(player)) {
            boolean apply = true;
            if (isBlockRequired(player)) {
                Location loc = event.getClickedBlock().getLocation().subtract(0, 1, 0);
                apply = loc.getWorld().getBlockAt(loc).getType() == getMaterial(player);
            }
            if (apply) {
                player.setVelocity(calculateVector(player));
                if (getSound(player) != null) {
                    player.playSound(player.getLocation(), getSound(player), 1, 1);
                }
                if (getEffect(player) != null) {
                    Effect effect = this.getEffect(player);
                    ReflectionUtils.invokeMethod(player.spigot(), this.playEffectMethod, player.getLocation(),
                            getEffect(player), effect.getId(), 0, 1, 1, 1, 1, 40, 3);
                }
                event.setCancelled(true);
            }
        }
    }
}
 
Example 7
Source File: JumpPads.java    From HubBasics with GNU Lesser General Public License v3.0 6 votes vote down vote up
@EventHandler
public void onPlayerInteract(PlayerInteractEvent event) {
    if (!needsPressurePlate(event.getPlayer())) return;
    Player player = event.getPlayer();
    if (event.getAction() == Action.PHYSICAL && !event.isCancelled() && isEnabledInWorld(player.getWorld())) {
        if (event.getClickedBlock().getType() == getPlateType(player)) {
            boolean apply = true;
            if (isBlockRequired(player)) {
                Location loc = event.getClickedBlock().getLocation().subtract(0, 1, 0);
                apply = loc.getWorld().getBlockAt(loc).getType() == getMaterial(player);
            }
            if (apply) {
                player.setVelocity(calculateVector(player));
                if (getSound(player) != null) {
                    player.playSound(player.getLocation(), getSound(player), 1, 1);
                }
                if (getEffect(player) != null) {
                    particleEffect.display(getEffect(player), player.getLocation(), 1, 1, 1, 1, 40);
                }
                event.setCancelled(true);
            }
        }
    }
}
 
Example 8
Source File: CraftingProtect.java    From ProjectAres with GNU Affero General Public License v3.0 5 votes vote down vote up
@EventHandler(priority = EventPriority.MONITOR)
public void cloneCraftingWindow(final PlayerInteractEvent event) {
    if(!AntiGrief.CraftProtect.enabled()) {
        return;
    }

    if(!event.isCancelled() && event.getAction() == Action.RIGHT_CLICK_BLOCK && event.getPlayer().getOpenInventory().getType() == InventoryType.CRAFTING /* nothing open */) {
        Block block = event.getClickedBlock();
        if(block != null && block.getType() == Material.WORKBENCH && !event.getPlayer().isSneaking()) {
            // create the window ourself
            event.setCancelled(true);
            event.getPlayer().openWorkbench(null, true); // doesn't check reachable
        }
    }
}
 
Example 9
Source File: JumpPadFeature.java    From VoxelGamesLibv2 with MIT License 5 votes vote down vote up
@GameEvent
public void onStep(@Nonnull PlayerInteractEvent event) {
    if (event.getAction() == Action.PHYSICAL) {

        if (!Tag.WOODEN_PRESSURE_PLATES.isTagged(event.getClickedBlock().getType()) &&
                event.getClickedBlock().getType() != Material.STONE_PRESSURE_PLATE) {
            return;
        }
        if (event.isCancelled()) {
            return;
        }
        double strength = 1.5;
        double up = 1;
        if (event.getClickedBlock().getRelative(BlockFace.DOWN, 2).getState() instanceof Sign) {
            Sign sign = (Sign) event.getClickedBlock().getRelative(BlockFace.DOWN, 2).getState();
            if (sign.getLine(0).contains("[Boom]")) {
                try {
                    strength = Double.parseDouble(sign.getLine(1));
                    up = Double.parseDouble(sign.getLine(2));
                } catch (final Exception ex) {
                    log.warning("Invalid boom sign at " + sign.getLocation());
                }
            }
        }

        event.getPlayer().playSound(event.getPlayer().getLocation(), Sound.ENTITY_ENDER_DRAGON_SHOOT, 10.0F, 1.0F);
        event.getPlayer().playEffect(event.getPlayer().getLocation(), Effect.SMOKE, 10);
        Vector v = event.getPlayer().getLocation().getDirection().multiply(strength / 2).setY(up / 2);
        event.getPlayer().setVelocity(v);
        event.setCancelled(true);
    }
}
 
Example 10
Source File: LoggingManager.java    From Survival-Games with GNU General Public License v3.0 5 votes vote down vote up
@EventHandler(priority = EventPriority.MONITOR)
public void blockChanged(PlayerInteractEvent e) {
	if(e.isCancelled())return;
	if(e.getClickedBlock() == null) return;
	Block b = e.getClickedBlock();
	String[] type = b.getType().toString().split("_");
	if(type.length >= 2) {
		if(type[type.length-1].equalsIgnoreCase("button") || (type.length >= 3 && (type[type.length-1]+"_"+type[type.length-2]).equalsIgnoreCase("pressure_plate"))) return;
		
		if(type[type.length-1].equalsIgnoreCase("door")) {
			Block down = b.getRelative(0, -1, 0);
			String[] downType = down.getType().toString().split("_");
			if(downType[downType.length-1].equalsIgnoreCase("door")) {
				logBlockChanged(down);
				i.put("BCHANGE", i.get("BCHANGE")+1);
			}
		}
	}
	if(b.getState() instanceof Jukebox) {
		if(GameManager.getInstance().getBlockGameId(b.getLocation()) == -1)	return;
		if(GameManager.getInstance().getGameMode(GameManager.getInstance().getBlockGameId(b.getLocation())) == Game.GameMode.DISABLED)	return;
		e.setCancelled(true);
		return;
	}

	logBlockChanged(e.getClickedBlock());
	i.put("BCHANGE", i.get("BCHANGE")+1);
}
 
Example 11
Source File: ItemUseListener.java    From CS-CoreLib with GNU General Public License v3.0 5 votes vote down vote up
@EventHandler
public void onRightClick(PlayerInteractEvent e) throws Exception {
	if (e.getAction() == Action.RIGHT_CLICK_AIR || e.getAction() == Action.RIGHT_CLICK_BLOCK) {
		ItemUseEvent event = new ItemUseEvent(e, e.getAction() == Action.RIGHT_CLICK_BLOCK ? e.getClickedBlock(): null);
		Bukkit.getPluginManager().callEvent(event);
		if (!e.isCancelled()) e.setCancelled(event.isCancelled());
	}
}
 
Example 12
Source File: UseRegion.java    From CardinalPGM with MIT License 5 votes vote down vote up
@EventHandler(priority = EventPriority.HIGH)
public void onPlayerInteract(PlayerInteractEvent event) {
    if (event.isCancelled() || event.getClickedBlock() == null || !event.getAction().equals(Action.RIGHT_CLICK_BLOCK)) return;
    if (region.contains(new BlockRegion(null, event.getClickedBlock().getLocation().toVector())) && filter.evaluate(event.getPlayer(), event.getClickedBlock(), event).equals(FilterState.DENY)) {
        event.setUseItemInHand(Event.Result.ALLOW);
        event.setUseInteractedBlock(Event.Result.DENY);
        ChatUtil.sendWarningMessage(event.getPlayer(), message);
    }
}
 
Example 13
Source File: BukkitImageListener.java    From FastAsyncWorldedit with GNU General Public License v3.0 4 votes vote down vote up
@EventHandler(priority = EventPriority.LOWEST)
public void onPlayerInteract(PlayerInteractEvent event) {
    if (event.useItemInHand() == Event.Result.DENY) return;

    Player player = event.getPlayer();
    FawePlayer<Object> fp = FawePlayer.wrap(player);
    if (fp.getMeta("CFISettings") == null) return;
    try {
        if (event.getHand() == EquipmentSlot.OFF_HAND) return;
    } catch (NoSuchFieldError | NoSuchMethodError ignored) {}

    List<Block> target = player.getLastTwoTargetBlocks((Set<Material>) null, 100);
    if (target.isEmpty()) return;

    Block targetBlock = target.get(0);
    World world = player.getWorld();
    mutable.setWorld(world);
    mutable.setX(targetBlock.getX() + 0.5);
    mutable.setY(targetBlock.getY() + 0.5);
    mutable.setZ(targetBlock.getZ() + 0.5);
    Collection<Entity> entities = world.getNearbyEntities(mutable, 0.46875, 0, 0.46875);

    if (!entities.isEmpty()) {
        Action action = event.getAction();
        boolean primary = action == Action.RIGHT_CLICK_AIR || action == Action.RIGHT_CLICK_BLOCK;

        double minDist = Integer.MAX_VALUE;
        ItemFrame minItemFrame = null;

        for (Entity entity : entities) {
            if (entity instanceof ItemFrame) {
                ItemFrame itemFrame = (ItemFrame) entity;
                Location loc = itemFrame.getLocation();
                double dx = loc.getX() - mutable.getX();
                double dy = loc.getY() - mutable.getY();
                double dz = loc.getZ() - mutable.getZ();
                double dist = dx * dx + dy * dy + dz * dz;
                if (dist < minDist) {
                    minItemFrame = itemFrame;
                    minDist = dist;
                }
            }
        }
        if (minItemFrame != null) {
            handleInteract(event, minItemFrame, primary);
            if (event.isCancelled()) return;
        }
    }
}
 
Example 14
Source File: ShopInteractListener.java    From ShopChest with MIT License 3 votes vote down vote up
@EventHandler(priority = EventPriority.HIGH)
public void onPlayerInteractCreate(PlayerInteractEvent e) {
    Player p = e.getPlayer();
    Block b = e.getClickedBlock();

    if (e.getAction() != Action.RIGHT_CLICK_BLOCK)
        return;

    if (!(ClickType.getPlayerClickType(p) instanceof CreateClickType))
        return;

    if (b.getType() != Material.CHEST && b.getType() != Material.TRAPPED_CHEST)
        return;

    if (ClickType.getPlayerClickType(p).getClickType() != ClickType.EnumClickType.CREATE)
        return;

    if (Config.enableAuthMeIntegration && plugin.hasAuthMe() && !AuthMeApi.getInstance().isAuthenticated(p))
        return;

    if (e.isCancelled() && !p.hasPermission(Permissions.CREATE_PROTECTED)) {
        p.sendMessage(LanguageUtils.getMessage(Message.NO_PERMISSION_CREATE_PROTECTED));
        plugin.debug(p.getName() + " is not allowed to create a shop on the selected chest");
    } else if (shopUtils.isShop(b.getLocation())) {
        p.sendMessage(LanguageUtils.getMessage(Message.CHEST_ALREADY_SHOP));
        plugin.debug("Chest is already a shop");
    } else if (!ItemUtils.isAir(b.getRelative(BlockFace.UP).getType())) {
        p.sendMessage(LanguageUtils.getMessage(Message.CHEST_BLOCKED));
        plugin.debug("Chest is blocked");
    } else {
        CreateClickType clickType = (CreateClickType) ClickType.getPlayerClickType(p);
        ShopProduct product = clickType.getProduct();
        double buyPrice = clickType.getBuyPrice();
        double sellPrice = clickType.getSellPrice();
        ShopType shopType = clickType.getShopType();

        create(p, b.getLocation(), product, buyPrice, sellPrice, shopType);
    }

    e.setCancelled(true);
    ClickType.removePlayerClickType(p);
}