Java Code Examples for org.bukkit.event.block.BlockPlaceEvent#isCancelled()
The following examples show how to use
org.bukkit.event.block.BlockPlaceEvent#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: BlockEventTracker.java From GriefDefender with MIT License | 5 votes |
@EventHandler(priority = EventPriority.MONITOR, ignoreCancelled = true) public void onBlockPlaceMonitor(BlockPlaceEvent event) { if (!event.isCancelled()) { final GDClaimManager claimWorldManager = GriefDefenderPlugin.getInstance().dataStore.getClaimWorldManager(event.getBlock().getWorld().getUID()); final GDChunk gpChunk = claimWorldManager.getChunk(event.getBlock().getChunk()); gpChunk.addTrackedBlockPosition(event.getBlock(), event.getPlayer().getUniqueId(), PlayerTracker.Type.OWNER); } }
Example 2
Source File: TrapListener.java From BedwarsRel with GNU General Public License v3.0 | 5 votes |
@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 3
Source File: BuildHeight.java From CardinalPGM with MIT License | 5 votes |
@EventHandler public void onBlockPlace(BlockPlaceEvent event) { if (event.getBlock().getY() >= height && !event.isCancelled()) { event.setCancelled(true); event.getPlayer().closeInventory(); ChatUtil.sendWarningMessage(event.getPlayer(), "You have reached the maximum build height (" + ChatColor.AQUA + height + ChatColor.RED + " blocks)"); } if ((event.getBlock().getType().equals(Material.ACACIA_DOOR) || event.getBlock().getType().equals(Material.BIRCH_DOOR) || event.getBlock().getType().equals(Material.DARK_OAK_DOOR) || event.getBlock().getType().equals(Material.IRON_DOOR_BLOCK) || event.getBlock().getType().equals(Material.JUNGLE_DOOR) || event.getBlock().getType().equals(Material.SPRUCE_DOOR) || event.getBlock().getType().equals(Material.WOOD_DOOR) || event.getBlock().getType().equals(Material.WOODEN_DOOR) || event.getBlock().getType().equals(Material.LONG_GRASS)) && event.getBlock().getY() + 1 >= height) { event.setCancelled(true); event.getPlayer().closeInventory(); ChatUtil.sendWarningMessage(event.getPlayer(), "You have reached the maximum build height (" + ChatColor.AQUA + height + ChatColor.RED + " blocks)"); } }
Example 4
Source File: BlockPlaceRegion.java From CardinalPGM with MIT License | 5 votes |
@EventHandler public void onBlockPlace(BlockPlaceEvent event) { if (!event.isCancelled() && region.contains(new BlockRegion(null, event.getBlockPlaced().getLocation().toVector())) && filter.evaluate(event.getPlayer(), event.getBlockPlaced(), event).equals(FilterState.DENY)) { event.setCancelled(true); event.getPlayer().closeInventory(); ChatUtil.sendWarningMessage(event.getPlayer(), message); } if ((event.getBlock().getType().equals(Material.ACACIA_DOOR) || event.getBlock().getType().equals(Material.BIRCH_DOOR) || event.getBlock().getType().equals(Material.DARK_OAK_DOOR) || event.getBlock().getType().equals(Material.IRON_DOOR) || event.getBlock().getType().equals(Material.JUNGLE_DOOR) || event.getBlock().getType().equals(Material.SPRUCE_DOOR) || event.getBlock().getType().equals(Material.WOOD_DOOR) || event.getBlock().getType().equals(Material.WOODEN_DOOR) || event.getBlock().getType().equals(Material.LONG_GRASS)) && region.contains(new BlockRegion(null, event.getBlock().getLocation().add(0, 1, 0).toVector())) && !event.isCancelled() && filter.evaluate(event.getPlayer(), event.getBlockPlaced(), event).equals(FilterState.DENY)) { event.setCancelled(true); event.getPlayer().closeInventory(); ChatUtil.sendWarningMessage(event.getPlayer(), message); } }
Example 5
Source File: BlockEventRegion.java From CardinalPGM with MIT License | 5 votes |
@EventHandler public void onBlockPlace(BlockPlaceEvent event) { if (!event.isCancelled() && filter.evaluate(event.getPlayer(), event.getBlockPlaced(), event).equals(FilterState.DENY) && region.contains(new BlockRegion(null, event.getBlock().getLocation().toVector()))) { event.setCancelled(true); event.getPlayer().closeInventory(); ChatUtil.sendWarningMessage(event.getPlayer(), message); } if ((event.getBlock().getType().equals(Material.ACACIA_DOOR) || event.getBlock().getType().equals(Material.BIRCH_DOOR) || event.getBlock().getType().equals(Material.DARK_OAK_DOOR) || event.getBlock().getType().equals(Material.IRON_DOOR) || event.getBlock().getType().equals(Material.JUNGLE_DOOR) || event.getBlock().getType().equals(Material.SPRUCE_DOOR) || event.getBlock().getType().equals(Material.WOOD_DOOR) || event.getBlock().getType().equals(Material.WOODEN_DOOR) || event.getBlock().getType().equals(Material.LONG_GRASS)) && region.contains(new BlockRegion(null, event.getBlock().getLocation().add(0, 1, 0).toVector())) && !event.isCancelled() && filter.evaluate(event.getPlayer(), event.getBlockPlaced(), event).equals(FilterState.DENY)) { event.setCancelled(true); event.getPlayer().closeInventory(); ChatUtil.sendWarningMessage(event.getPlayer(), message); } }
Example 6
Source File: BlockPlaceAgainstRegion.java From CardinalPGM with MIT License | 5 votes |
@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 7
Source File: Tnt.java From CardinalPGM with MIT License | 5 votes |
@EventHandler(priority = EventPriority.HIGHEST) public void onBlockPlace(BlockPlaceEvent event) { Block block = event.getBlock(); if (block.getType().equals(Material.TNT) && instantIgnite && !event.isCancelled()) { event.getBlock().setType(Material.AIR); TNTPrimed tnt = (TNTPrimed) GameHandler.getGameHandler().getMatchWorld().spawnEntity(block.getLocation().add(new Vector(0.5, 0.5, 0.5)), EntityType.PRIMED_TNT); Bukkit.getServer().getPluginManager().callEvent(new ExplosionPrimeEvent(tnt)); } }
Example 8
Source File: PlayerInteractListener.java From IridiumSkyblock with GNU General Public License v2.0 | 4 votes |
@EventHandler public void onPlayerInteract(PlayerInteractEvent event) { try { final Player player = event.getPlayer(); final Location playerLocation = player.getLocation(); final IslandManager islandManager = IridiumSkyblock.getIslandManager(); if (!islandManager.isIslandWorld(playerLocation)) return; final User user = User.getUser(player); final Block block = event.getClickedBlock(); if (event.getAction().toString().startsWith("RIGHT_CLICK")) { if (player.getItemInHand() != null) { int crystals = Utils.getCrystals(player.getItemInHand()) * player.getItemInHand().getAmount(); if (crystals != 0) { player.setItemInHand(null); user.getIsland().setCrystals(user.getIsland().getCrystals() + crystals); player.sendMessage(Utils.color(IridiumSkyblock.getMessages().depositedCrystals.replace("%amount%", crystals + "").replace("%prefix%", IridiumSkyblock.getConfiguration().prefix))); } } } if (block != null) { final Location location = block.getLocation(); final Island island = islandManager.getIslandViaLocation(location); if (island != null) { if (!island.getPermissions(user).interact) { event.setCancelled(true); return; } final ItemStack itemInHand = player.getItemInHand(); if (itemInHand.getType().equals(Material.BUCKET) && island.failedGenerators.remove(location)) { if (itemInHand.getAmount() == 1) itemInHand.setType(Material.LAVA_BUCKET); else { player.getInventory().addItem(new ItemStack(Material.LAVA_BUCKET)); player.getItemInHand().setAmount(itemInHand.getAmount() - 1); } block.setType(Material.AIR); } } else if (!user.bypassing) { event.setCancelled(true); return; } } final ItemStack item = event.getItem(); if (IridiumSkyblock.getConfiguration().allowWaterInNether && event.getAction().equals(Action.RIGHT_CLICK_BLOCK) && item != null && block != null) { final World world = block.getWorld(); if (!world.getEnvironment().equals(World.Environment.NETHER)) return; if (!item.getType().equals(Material.WATER_BUCKET)) return; event.setCancelled(true); final BlockFace face = event.getBlockFace(); block.getRelative(face).setType(Material.WATER); final Block relative = block.getRelative(face); final BlockPlaceEvent blockPlaceEvent = new BlockPlaceEvent(relative, relative.getState(), block, item, player, false); if (blockPlaceEvent.isCancelled()) { block.getRelative(face).setType(Material.AIR); } else if (player.getGameMode().equals(GameMode.SURVIVAL)) { if (item.getAmount() == 1) { item.setType(Material.BUCKET); } else { item.setAmount(item.getAmount() - 1); player.getInventory().addItem(new ItemStack(Material.BUCKET)); } } } } catch (Exception e) { IridiumSkyblock.getInstance().sendErrorMessage(e); } }
Example 9
Source File: EasyHarvestListener.java From MineTinker with GNU General Public License v3.0 | 4 votes |
@EventHandler public void onHarvestTry(PlayerInteractEvent event) { if (event.getAction() != Action.RIGHT_CLICK_BLOCK) { return; } Player player = event.getPlayer(); if (Lists.WORLDS_EASYHARVEST.contains(player.getWorld().getName())) { return; } if (!(player.getGameMode() == GameMode.SURVIVAL || player.getGameMode() == GameMode.ADVENTURE || player.getGameMode() == GameMode.CREATIVE)) { return; } ItemStack tool = player.getInventory().getItemInMainHand(); if (!ToolType.HOE.contains(tool.getType())) { return; } if (!modManager.isToolViable(tool)) { return; } if (event.getClickedBlock() == null) { return; } if (event.getItem() == null) { return; } Block block = event.getClickedBlock(); if (!(block.getBlockData() instanceof Ageable)) { return; } //triggers a pseudoevent to find out if the Player can build BlockPlaceEvent placeEvent = new BlockPlaceEvent(block, block.getState(), block, event.getItem(), player, true, EquipmentSlot.HAND); Bukkit.getPluginManager().callEvent(placeEvent); //check the pseudoevent if (!placeEvent.canBuild() || placeEvent.isCancelled()) { return; } harvestCrops(player, tool, block); }
Example 10
Source File: BuildersWandListener.java From MineTinker with GNU General Public License v3.0 | 4 votes |
private boolean placeBlock(Block b, Player player, Location l, Location loc, ItemStack item, Vector vector) { if (!b.getWorld().getBlockAt(l).getType().equals(b.getType())) { return false; } Material type = b.getWorld().getBlockAt(loc).getType(); if (!(type == Material.AIR || type == Material.CAVE_AIR || type == Material.WATER || type == Material.BUBBLE_COLUMN || type == Material.LAVA || type == Material.GRASS)) { return false; } //triggers a pseudoevent to find out if the Player can build Block block = b.getWorld().getBlockAt(loc); BlockPlaceEvent placeEvent = new BlockPlaceEvent(block, block.getState(), b, item, player, true, EquipmentSlot.HAND); Bukkit.getPluginManager().callEvent(placeEvent); //check the pseudoevent if (!placeEvent.canBuild() || placeEvent.isCancelled()) { return false; } Block nb = b.getWorld().getBlockAt(loc); Block behind = nb.getWorld().getBlockAt(loc.clone().subtract(vector)); if (behind.getBlockData() instanceof Slab) { if (((Slab) behind.getBlockData()).getType().equals(Slab.Type.DOUBLE)) { if (item.getAmount() - 2 < 0) { return false; } } } nb.setType(item.getType()); BlockData bd = nb.getBlockData(); if (bd instanceof Directional) { ((Directional) bd).setFacing(((Directional) behind.getBlockData()).getFacing()); } if (bd instanceof Slab) { ((Slab) bd).setType(((Slab) behind.getBlockData()).getType()); } nb.setBlockData(bd); return true; }
Example 11
Source File: BlockListener.java From BedwarsRel with GNU General Public License v3.0 | 4 votes |
@EventHandler(priority = EventPriority.NORMAL) public void onPlace(BlockPlaceEvent bpe) { Player player = bpe.getPlayer(); Game game = BedwarsRel.getInstance().getGameManager().getGameOfPlayer(player); if (game == null) { return; } if (game.getState() == GameState.STOPPED) { return; } if (game.getState() == GameState.WAITING) { bpe.setCancelled(true); bpe.setBuild(false); return; } if (game.getState() == GameState.RUNNING) { if (game.isSpectator(player)) { bpe.setCancelled(true); bpe.setBuild(false); return; } Block placeBlock = bpe.getBlockPlaced(); BlockState replacedBlock = bpe.getBlockReplacedState(); if (placeBlock.getType() == game.getTargetMaterial()) { bpe.setCancelled(true); bpe.setBuild(false); return; } if (!game.getRegion().isInRegion(placeBlock.getLocation())) { bpe.setCancelled(true); bpe.setBuild(false); return; } if (replacedBlock != null && !BedwarsRel .getInstance().getBooleanConfig("place-in-liquid", true) && (replacedBlock.getType().equals(Material.WATER) || replacedBlock.getType().equals(Material.STATIONARY_WATER) || replacedBlock.getType().equals(Material.LAVA) || replacedBlock.getType().equals(Material.STATIONARY_LAVA))) { bpe.setCancelled(true); bpe.setBuild(false); return; } if (replacedBlock != null && placeBlock.getType().equals(Material.WEB) && (replacedBlock.getType().equals(Material.WATER) || replacedBlock.getType().equals(Material.STATIONARY_WATER) || replacedBlock.getType().equals(Material.LAVA) || replacedBlock.getType().equals(Material.STATIONARY_LAVA))) { bpe.setCancelled(true); bpe.setBuild(false); return; } if (placeBlock.getType() == Material.ENDER_CHEST) { Team playerTeam = game.getPlayerTeam(player); if (playerTeam.getInventory() == null) { playerTeam.createTeamInventory(); } playerTeam.addChest(placeBlock); } if (!bpe.isCancelled()) { game.getRegion().addPlacedBlock(placeBlock, (replacedBlock.getType().equals(Material.AIR) ? null : replacedBlock)); } } }
Example 12
Source File: WarListener.java From civcraft with GNU General Public License v2.0 | 4 votes |
@SuppressWarnings("deprecation") @EventHandler(priority = EventPriority.HIGH) public void onBlockPlace(BlockPlaceEvent event) { if (event.isCancelled()) { return; } if (!War.isWarTime()) { return; } coord.setFromLocation(event.getBlock().getLocation()); CultureChunk cc = CivGlobal.getCultureChunk(coord); if (cc == null) { return; } if (!cc.getCiv().getDiplomacyManager().isAtWar()) { return; } if (event.getBlock().getType().equals(Material.DIRT) || event.getBlock().getType().equals(Material.GRASS) || event.getBlock().getType().equals(Material.SAND) || event.getBlock().getType().equals(Material.GRAVEL) || event.getBlock().getType().equals(Material.TORCH) || event.getBlock().getType().equals(Material.REDSTONE_TORCH_OFF) || event.getBlock().getType().equals(Material.REDSTONE_TORCH_ON) || event.getBlock().getType().equals(Material.REDSTONE) || event.getBlock().getType().equals(Material.LADDER) || event.getBlock().getType().equals(Material.VINE) || event.getBlock().getType().equals(Material.TNT)) { if (event.getBlock().getLocation().subtract(0, 1, 0).getBlock().getType() != Material.AIR) { return; } event.getBlock().getWorld().spawnFallingBlock(event.getBlock().getLocation(), event.getBlock().getType(), (byte) 0); event.getBlock().setType(Material.AIR); return; } CivMessage.sendError(event.getPlayer(), "Can only place grass, dirt, and TNT blocks in at-war civilization cultures during WarTime."); event.setCancelled(true); }
Example 13
Source File: LoggingManager.java From Survival-Games with GNU General Public License v3.0 | 3 votes |
@EventHandler(priority = EventPriority.MONITOR) public void blockChanged(BlockPlaceEvent e){ if(e.isCancelled())return; logBlockCreated(e.getBlock()); i.put("BPLACE", i.get("BPLACE")+1); // System.out.println(2); }