Java Code Examples for org.bukkit.event.block.BlockPlaceEvent#setCancelled()

The following examples show how to use org.bukkit.event.block.BlockPlaceEvent#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: Scaffold.java    From AACAdditionPro with GNU General Public License v3.0 6 votes vote down vote up
@EventHandler(priority = EventPriority.LOWEST, ignoreCancelled = true)
public void onPreBlockPlace(final BlockPlaceEvent event)
{
    final User user = UserManager.getUser(event.getPlayer().getUniqueId());

    // Not bypassed
    if (User.isUserInvalid(user, this.getModuleType())) {
        return;
    }

    // To prevent too fast scaffolding -> Timeout
    if (user.getTimestampMap().recentlyUpdated(TimestampKey.SCAFFOLD_TIMEOUT, timeout)) {
        event.setCancelled(true);
        InventoryUtils.syncUpdateInventory(user.getPlayer());
    }
}
 
Example 2
Source File: RegionManager.java    From Civs with GNU General Public License v3.0 6 votes vote down vote up
private boolean regionNotAllowedInFeudalTown(BlockPlaceEvent event, Player player, Town town) {
    if (town != null) {
        Government government = GovernmentManager.getInstance().getGovernment(town.getGovernmentType());
        if (government.getGovernmentType() == GovernmentType.FEUDALISM) {
            boolean isOwner = town.getRawPeople().containsKey(player.getUniqueId()) &&
                    town.getRawPeople().get(player.getUniqueId()).contains(Constants.OWNER);
            if (!isOwner) {
                player.sendMessage(Civs.getPrefix() + LocaleManager.getInstance()
                        .getTranslationWithPlaceholders(player, "cant-build-feudal"));
                event.setCancelled(true);
                return true;
            }
        }
    }
    return false;
}
 
Example 3
Source File: PlayerEvents.java    From uSkyBlock with GNU General Public License v3.0 5 votes vote down vote up
@EventHandler(ignoreCancelled = true)
public void onBlockPlaceEvent(BlockPlaceEvent event)
{
    final Player player = event.getPlayer();
    if (!blockLimitsEnabled || !plugin.getWorldManager().isSkyAssociatedWorld(player.getWorld())) {
        return; // Skip
    }

    IslandInfo islandInfo = plugin.getIslandInfo(event.getBlock().getLocation());
    if (islandInfo == null) {
        return;
    }
    Material type = event.getBlock().getType();
    BlockLimitLogic.CanPlace canPlace = plugin.getBlockLimitLogic().canPlace(type, islandInfo);
    if (canPlace == BlockLimitLogic.CanPlace.UNCERTAIN) {
        event.setCancelled(true);
        final String key = "usb.block-limits";
        if (!PatienceTester.isRunning(player, key)) {
            PatienceTester.startRunning(player, key);
            player.sendMessage(tr("\u00a74{0} is limited. \u00a7eScanning your island to see if you are allowed to place more, please be patient", ItemStackUtil.getItemName(new ItemStack(type))));
            plugin.fireAsyncEvent(new IslandInfoEvent(player, islandInfo.getIslandLocation(), new Callback<IslandScore>() {
                @Override
                public void run() {
                    player.sendMessage(tr("\u00a7e... Scanning complete, you can try again"));
                    PatienceTester.stopRunning(player, key);
                }
            }));
        }
        return;
    }
    if (canPlace == BlockLimitLogic.CanPlace.NO) {
        event.setCancelled(true);
        player.sendMessage(tr("\u00a74You''ve hit the {0} limit!\u00a7e You can''t have more of that type on your island!\u00a79 Max: {1,number}", ItemStackUtil.getItemName(new ItemStack(type)), plugin.getBlockLimitLogic().getLimit(type)));
        return;
    }
    plugin.getBlockLimitLogic().incBlockCount(islandInfo.getIslandLocation(), type);
}
 
Example 4
Source File: PlayerBlockModifyEventHandler.java    From SuperVanish with Mozilla Public License 2.0 5 votes vote down vote up
@EventHandler(priority = EventPriority.HIGH)
public void onPlace(BlockPlaceEvent e) {
    try {
        if (plugin.getSettings().getBoolean("RestrictiveOptions.PreventBlockPlacing")) {
            Player p = e.getPlayer();
            Collection<UUID> vanishedPlayers = plugin.getVanishStateMgr().getOnlineVanishedPlayers();
            if (vanishedPlayers.contains(p.getUniqueId()) && !p.hasPermission("sv.placeblocks")) {
                e.setCancelled(true);
                plugin.sendMessage(e.getPlayer(), "BlockPlaceDenied", e.getPlayer());
            }
        }
    } catch (Exception er) {
        plugin.logException(er);
    }
}
 
Example 5
Source File: PaperPatch.java    From ViaVersion with MIT License 5 votes vote down vote up
@EventHandler(ignoreCancelled = true, priority = EventPriority.HIGHEST)
public void onPlace(BlockPlaceEvent e) {
    if (isOnPipe(e.getPlayer())) {
        Location location = e.getPlayer().getLocation();
        Location diff = location.clone().subtract(e.getBlock().getLocation().add(0.5D, 0, 0.5D));
        Material block = e.getBlockPlaced().getType();
        if (isPlacable(block)) {
            return;
        }
        if (location.getBlock().equals(e.getBlock())) {
            e.setCancelled(true);
        } else {
            if (location.getBlock().getRelative(BlockFace.UP).equals(e.getBlock())) {
                e.setCancelled(true);
            } else {
                // Within radius of block
                if (Math.abs(diff.getX()) <= 0.8 && Math.abs(diff.getZ()) <= 0.8D) {
                    // Are they on the edge / shifting ish
                    if (diff.getY() <= 0.1D && diff.getY() >= -0.1D) {
                        e.setCancelled(true);
                        return;
                    }
                    BlockFace relative = e.getBlockAgainst().getFace(e.getBlock());
                    // Are they towering up, (handles some latency)
                    if (relative == BlockFace.UP) {
                        if (diff.getY() < 1D && diff.getY() >= 0D) {
                            e.setCancelled(true);
                        }
                    }
                }
            }
        }
    }
}
 
Example 6
Source File: CargoNodeListener.java    From Slimefun4 with GNU General Public License v3.0 5 votes vote down vote up
@EventHandler(ignoreCancelled = true)
public void onCargoNodePlace(BlockPlaceEvent e) {
    if (e.getBlock().getY() != e.getBlockAgainst().getY() && isCargoNode(new ItemStackWrapper(e.getItemInHand()))) {
        SlimefunPlugin.getLocalization().sendMessage(e.getPlayer(), "machines.CARGO_NODES.must-be-placed", true);
        e.setCancelled(true);
    }
}
 
Example 7
Source File: Game.java    From HeavySpleef with GNU General Public License v3.0 5 votes vote down vote up
public void onPlayerPlaceBlock(BlockPlaceEvent event, SpleefPlayer player) {
	PlayerBlockPlaceEvent spleefEvent = new PlayerBlockPlaceEvent(this, player, event.getBlock());
	eventBus.callEvent(spleefEvent);
	
	if (spleefEvent.isCancelled()) {
		event.setCancelled(true);
		return;
	}
	
	boolean disableBuild = getPropertyValue(GameProperty.DISABLE_BUILD);
	
	if (disableBuild) {
		event.setCancelled(true);
	}
}
 
Example 8
Source File: BlockPlaceAgainstRegion.java    From CardinalPGM with MIT License 5 votes vote down vote up
@EventHandler
public void onBlockPlace(BlockPlaceEvent event) {
    if (!event.isCancelled() && region.contains(new BlockRegion(null, event.getBlock().getLocation().toVector())) && filter.evaluate(event.getPlayer(), event.getBlockPlaced(), event).equals(FilterState.DENY)) {
        event.setCancelled(true);
        event.getPlayer().closeInventory();
        ChatUtil.sendWarningMessage(event.getPlayer(), message);
    }
}
 
Example 9
Source File: GameMap.java    From AnnihilationPro with MIT License 5 votes vote down vote up
@SuppressWarnings("deprecation")
@EventHandler(priority = EventPriority.HIGHEST, ignoreCancelled = true)
public void blockPlaceCheck(BlockPlaceEvent event)
{
	if(event.getPlayer().getGameMode() != GameMode.CREATIVE)
	{
		Block b = event.getBlock();
		UnplaceableBlock block = this.unplaceableBlocks.get(b.getType());
		if(block != null)
		{
			if(block.isData((byte)-1) || block.isData(b.getData()))
				event.setCancelled(true);
		}
	}
}
 
Example 10
Source File: TrapListener.java    From BedwarsRel with GNU General Public License v3.0 5 votes vote down vote up
@EventHandler(priority = EventPriority.HIGH)
public void onPlace(BlockPlaceEvent place) {
  if (place.isCancelled()) {
    return;
  }

  Player player = place.getPlayer();
  Game game = BedwarsRel.getInstance().getGameManager().getGameOfPlayer(player);

  if (game == null) {
    return;
  }

  if (game.getState() != GameState.RUNNING) {
    return;
  }

  Team team = game.getPlayerTeam(player);
  if (team == null) {
    place.setCancelled(true);
    place.setBuild(false);
    return;
  }

  Trap trap = new Trap();
  trap.create(game, team, place.getBlockPlaced().getLocation());
  game.getRegion().addPlacedUnbreakableBlock(place.getBlockPlaced(), null);
}
 
Example 11
Source File: Tower.java    From AACAdditionPro with GNU General Public License v3.0 4 votes vote down vote up
@EventHandler(priority = EventPriority.HIGHEST, ignoreCancelled = true)
public void onBlockPlace(final BlockPlaceEvent event)
{
    final User user = UserManager.getUser(event.getPlayer().getUniqueId());

    // Not bypassed
    if (User.isUserInvalid(user, this.getModuleType())) {
        return;
    }

    // To prevent too fast towering -> Timeout
    if (user.getTimestampMap().recentlyUpdated(TimestampKey.TOWER_TIMEOUT, timeout)) {
        event.setCancelled(true);
        InventoryUtils.syncUpdateInventory(user.getPlayer());
        return;
    }

    // Not flying
    if (!user.getPlayer().isFlying()) {
        final Block blockPlaced = event.getBlockPlaced();

        // Levitation effect
        final Integer levitation;
        switch (ServerVersion.getActiveServerVersion()) {
            case MC188:
                levitation = null;
                break;
            case MC112:
            case MC113:
            case MC114:
            case MC115:
                levitation = PotionUtil.getAmplifier(PotionUtil.getPotionEffect(user.getPlayer(), PotionEffectType.LEVITATION));
                break;
            default:
                throw new UnknownMinecraftVersion();
        }

        // User must stand above the block (placed from above)1
        // Check if the block is tower-placed (Block belows)
        if (event.getBlock().getFace(event.getBlockAgainst()) == BlockFace.DOWN &&
            // The block is placed inside a 2 - block y-radius, this prevents false positives when building from a higher level
            user.getPlayer().getLocation().getY() - blockPlaced.getY() < 2D &&
            // Check if this check applies to the block
            blockPlaced.getType().isSolid() &&
            // Check if the block is placed against one block (face) only
            // Only one block that is not a liquid is allowed (the one which the Block is placed against).
            BlockUtils.getBlocksAround(blockPlaced, false).stream().filter(block -> !BlockUtils.LIQUIDS.contains(block.getType())).count() == 1 &&
            // User is not in water which can cause false positives due to faster swimming on newer versions.
            !EntityUtil.isHitboxInLiquids(user.getPlayer().getLocation(), user.getHitbox()) &&
            // Buffer the block place, continue the check only when we a certain number of block places in check
            user.getTowerData().getBlockPlaces().bufferObject(
                    new TowerBlockPlace(
                            blockPlaced,
                            //Jump boost effect is important
                            PotionUtil.getAmplifier(PotionUtil.getPotionEffect(user.getPlayer(), PotionEffectType.JUMP)),
                            levitation)))
        {
            // [0] = Expected time; [1] = Real time
            final double[] results = user.getTowerData().calculateTimes();

            // Real check
            if (results[1] < results[0]) {
                final int vlToAdd = (int) Math.min(1 + Math.floor((results[0] - results[1]) / 16), 100);

                // Violation-Level handling
                vlManager.flag(event.getPlayer(), vlToAdd, cancelVl, () ->
                {
                    event.setCancelled(true);
                    user.getTimestampMap().updateTimeStamp(TimestampKey.TOWER_TIMEOUT);
                    InventoryUtils.syncUpdateInventory(user.getPlayer());
                    // If not cancelled run the verbose message with additional data
                }, () -> VerboseSender.getInstance().sendVerboseMessage("Tower-Verbose | Player: " + user.getPlayer().getName() + " expected time: " + results[0] + " | real: " + results[1]));
            }
        }
    }
}
 
Example 12
Source File: GlobalProtectionListener.java    From DungeonsXL with GNU General Public License v3.0 4 votes vote down vote up
@EventHandler(ignoreCancelled = true, priority = EventPriority.HIGHEST)
public void onBlockPlace(BlockPlaceEvent event) {
    if (DPortal.getByBlock(plugin, event.getBlock()) != null) {
        event.setCancelled(true);
    }
}
 
Example 13
Source File: BlockListener.java    From AuthMeReloaded with GNU General Public License v3.0 4 votes vote down vote up
@EventHandler(ignoreCancelled = true)
public void onBlockPlace(BlockPlaceEvent event) {
    if (listenerService.shouldCancelEvent(event.getPlayer())) {
        event.setCancelled(true);
    }
}
 
Example 14
Source File: ChestProtectListener.java    From ShopChest with MIT License 4 votes vote down vote up
@EventHandler(ignoreCancelled = true)
public void onBlockPlace(BlockPlaceEvent e) {
    final Player p = e.getPlayer();
    final Block b = e.getBlockPlaced();

    if (!b.getType().equals(Material.CHEST) && !b.getType().equals(Material.TRAPPED_CHEST)) {
        return;
    }
    
    Chest c = (Chest) b.getState();
    Block b2;

    // Can't use Utils::getChestLocations since inventory holder
    // has not been updated yet in this event (for 1.13+)

    if (Utils.getMajorVersion() < 13) {
        InventoryHolder ih = c.getInventory().getHolder();
        if (!(ih instanceof DoubleChest)) {
            return;
        }

        DoubleChest dc = (DoubleChest) ih;
        Chest l = (Chest) dc.getLeftSide();
        Chest r = (Chest) dc.getRightSide();

        if (b.getLocation().equals(l.getLocation())) {
            b2 = r.getBlock();
        } else {
            b2 = l.getBlock();
        }
    } else {
        org.bukkit.block.data.type.Chest data = (org.bukkit.block.data.type.Chest) c.getBlockData();

        if (data.getType() == Type.SINGLE) {
            return;
        }

        BlockFace neighborFacing;

        switch (data.getFacing()) {
            case NORTH:
                neighborFacing = data.getType() == Type.LEFT ? BlockFace.EAST : BlockFace.WEST;
                break;
            case EAST:
                neighborFacing = data.getType() == Type.LEFT ? BlockFace.SOUTH : BlockFace.NORTH;
                break;
            case SOUTH:
                neighborFacing = data.getType() == Type.LEFT ? BlockFace.WEST : BlockFace.EAST;
                break;
            case WEST:
                neighborFacing = data.getType() == Type.LEFT ? BlockFace.NORTH : BlockFace.SOUTH;
                break;
            default:
                neighborFacing = null;
        }

        b2 = b.getRelative(neighborFacing);
    }

    final Shop shop = shopUtils.getShop(b2.getLocation());
    if (shop == null)
        return;

    plugin.debug(String.format("%s tries to extend %s's shop (#%d)", p.getName(), shop.getVendor().getName(), shop.getID()));

    ShopExtendEvent event = new ShopExtendEvent(p, shop, b.getLocation());
    Bukkit.getPluginManager().callEvent(event);
    if (event.isCancelled() && !p.hasPermission(Permissions.EXTEND_PROTECTED)) {
        e.setCancelled(true);
        p.sendMessage(LanguageUtils.getMessage(Message.NO_PERMISSION_EXTEND_PROTECTED));
        return;
    }

    if (!p.getUniqueId().equals(shop.getVendor().getUniqueId()) && !p.hasPermission(Permissions.EXTEND_OTHER)) {
        e.setCancelled(true);
        p.sendMessage(LanguageUtils.getMessage(Message.NO_PERMISSION_EXTEND_OTHERS));
        return;
    }

    if (!ItemUtils.isAir(b.getRelative(BlockFace.UP).getType())) {
        e.setCancelled(true);
        p.sendMessage(LanguageUtils.getMessage(Message.CHEST_BLOCKED));
        return;
    }

    final Shop newShop = new Shop(shop.getID(), plugin, shop.getVendor(), shop.getProduct(), shop.getLocation(), shop.getBuyPrice(), shop.getSellPrice(), shop.getShopType());

    shopUtils.removeShop(shop, true, new Callback<Void>(plugin) {
        @Override
        public void onResult(Void result) {
            newShop.create(true);
            shopUtils.addShop(newShop, true);
            plugin.debug(String.format("%s extended %s's shop (#%d)", p.getName(), shop.getVendor().getName(), shop.getID()));
        }
    });
}
 
Example 15
Source File: CoreObjective.java    From CardinalPGM with MIT License 4 votes vote down vote up
@EventHandler
public void onBlockPlace(BlockPlaceEvent event) {
    if (lava.contains(event.getBlock())) {
        event.setCancelled(true);
    }
}
 
Example 16
Source File: QAListener.java    From QualityArmory with GNU General Public License v3.0 4 votes vote down vote up
@EventHandler
public void onHeadPlace(BlockPlaceEvent e) {
	if (QualityArmory.isCustomItem(e.getItemInHand()))
		e.setCancelled(true);
}
 
Example 17
Source File: ServerListener.java    From ZombieEscape with GNU General Public License v2.0 4 votes vote down vote up
@EventHandler
public void onPlace(BlockPlaceEvent event) {
    event.setCancelled(event.getPlayer().getItemInHand().getType() == Material.SKULL_ITEM || !event.getPlayer().isOp());
}
 
Example 18
Source File: EntityLimits.java    From askyblock with GNU General Public License v2.0 4 votes vote down vote up
/**
 * Prevents placing of blocks
 *
 * @param e - event
 */
@EventHandler(priority = EventPriority.LOWEST, ignoreCancelled = true)
public void onPlayerBlockPlace(final BlockPlaceEvent e) {
    if (DEBUG) {
        plugin.getLogger().info("DEBUG: " + e.getEventName());
        if (e.getPlayer() == null) {
            plugin.getLogger().info("DEBUG: player is null");
        } else {
            plugin.getLogger().info("DEBUG: block placed by " + e.getPlayer().getName());
        }
        plugin.getLogger().info("DEBUG: Block is " + e.getBlock().toString());
    }

    if (Settings.allowedFakePlayers.contains(e.getPlayer().getName())) return;

    // plugin.getLogger().info(e.getEventName());
    if (IslandGuard.inWorld(e.getPlayer())) {
        // This permission bypasses protection
        if (e.getPlayer().isOp() || VaultHelper.checkPerm(e.getPlayer(), Settings.PERMPREFIX + "mod.bypassprotect")) {
            return;
        }
        //plugin.getLogger().info("DEBUG: checking is inside protection area");
        Island island = plugin.getGrid().getProtectedIslandAt(e.getBlock().getLocation());
        // Outside of island protection zone
        if (island == null) {
            if (!Settings.defaultWorldSettings.get(SettingsFlag.PLACE_BLOCKS)) {
                Util.sendMessage(e.getPlayer(), ChatColor.RED + plugin.myLocale(e.getPlayer().getUniqueId()).islandProtected);
                e.setCancelled(true);
            }
            return;
        }
        if (actionAllowed(e.getPlayer(), e.getBlock().getLocation(), SettingsFlag.PLACE_BLOCKS))  {
            // Check how many placed
            //plugin.getLogger().info("DEBUG: block placed " + e.getBlock().getType());
            String type = e.getBlock().getType().toString();
            if (!e.getBlock().getState().getClass().getName().endsWith("CraftBlockState")
                    // Not all blocks have that type of class, so we have to do some explicit checking...
                    || e.getBlock().getType().equals(Material.REDSTONE_COMPARATOR_OFF)
                    || type.endsWith("BANNER") // Avoids V1.7 issues
                    || e.getBlock().getType().equals(Material.ENDER_CHEST)
                    || e.getBlock().getType().equals(Material.ENCHANTMENT_TABLE)
                    || e.getBlock().getType().equals(Material.DAYLIGHT_DETECTOR)
                    || e.getBlock().getType().equals(Material.FLOWER_POT)){
                // tile entity placed
                if (Settings.limitedBlocks.containsKey(type) && Settings.limitedBlocks.get(type) > -1) {
                    int count = island.getTileEntityCount(e.getBlock().getType(),e.getBlock().getWorld());
                    //plugin.getLogger().info("DEBUG: count is "+ count);
                    if (Settings.limitedBlocks.get(type) <= count) {
                        Util.sendMessage(e.getPlayer(), ChatColor.RED + (plugin.myLocale(e.getPlayer().getUniqueId()).entityLimitReached.replace("[entity]",
                                Util.prettifyText(type))).replace("[number]", String.valueOf(Settings.limitedBlocks.get(type))));
                        e.setCancelled(true);
                        return;
                    }
                }
            }
        } else {
            // Visitor
            Util.sendMessage(e.getPlayer(), ChatColor.RED + plugin.myLocale(e.getPlayer().getUniqueId()).islandProtected);
            e.setCancelled(true);
        }
    }
}
 
Example 19
Source File: BlockListener.java    From QuickShop-Reremake with GNU General Public License v3.0 4 votes vote down vote up
@EventHandler(ignoreCancelled = true, priority = EventPriority.LOWEST)
public void onPlace(BlockPlaceEvent e) {

    final Material type = e.getBlock().getType();
    final Block placingBlock = e.getBlock();
    final Player player = e.getPlayer();

    if (type != Material.CHEST) {
        return;
    }
    Block chest = null;
    //Chest combine mechanic based checking
    if (player.isSneaking()) {
        Block blockAgainst = e.getBlockAgainst();
        if (blockAgainst.getType() == Material.CHEST && placingBlock.getFace(blockAgainst) != BlockFace.UP && placingBlock.getFace(blockAgainst) != BlockFace.DOWN && !(((Chest) blockAgainst.getState()).getInventory() instanceof DoubleChestInventory)) {
            chest = e.getBlockAgainst();
        } else {
            return;
        }
    } else {
        //Get all chest in vertical Location
        BlockFace placingChestFacing = ((Directional) (placingBlock.getState().getBlockData())).getFacing();
        for (BlockFace face : Util.getVerticalFacing()) {
            //just check the right side and left side
            if (face != placingChestFacing && face != placingChestFacing.getOppositeFace()) {
                Block nearByBlock = placingBlock.getRelative(face);
                if (nearByBlock.getType() == Material.CHEST
                        //non double chest
                        && !(((Chest) nearByBlock.getState()).getInventory() instanceof DoubleChestInventory)
                        //same facing
                        && placingChestFacing == ((Directional) nearByBlock.getState().getBlockData()).getFacing()) {
                    if (chest == null) {
                        chest = nearByBlock;
                    } else {
                        //when multiply chests competed, minecraft will always combine with right side
                        if (placingBlock.getFace(nearByBlock) == Util.getRightSide(placingChestFacing)) {
                            chest = nearByBlock;
                        }
                    }
                }
            }
        }
    }
    if (chest == null) {
        return;
    }

    Shop shop = getShopPlayer(chest.getLocation(), false);
    if (shop != null) {
        if (!QuickShop.getPermissionManager().hasPermission(player, "quickshop.create.double")) {
            e.setCancelled(true);
            MsgUtil.sendMessage(player, MsgUtil.getMessage("no-double-chests", player));

        } else if (!shop.getModerator().isModerator(player.getUniqueId())) {
            e.setCancelled(true);
            MsgUtil.sendMessage(player, MsgUtil.getMessage("not-managed-shop", player));
        }
    }
}
 
Example 20
Source File: TutorialListener.java    From ServerTutorial with MIT License 4 votes vote down vote up
@EventHandler
public void onPlace(BlockPlaceEvent event) {
    if (TutorialManager.getManager().isInTutorial(event.getPlayer().getName())) {
        event.setCancelled(true);
    }
}