Java Code Examples for org.bukkit.event.block.BlockBreakEvent#isCancelled()
The following examples show how to use
org.bukkit.event.block.BlockBreakEvent#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: SignListener.java From BedWars with GNU Lesser General Public License v3.0 | 7 votes |
@EventHandler public void onBlockBreak(BlockBreakEvent event) { if (event.isCancelled()) { return; } if (event.getBlock().getState() instanceof Sign) { Location loc = event.getBlock().getLocation(); if (manager.isSignRegistered(loc)) { if (event.getPlayer().hasPermission(owner.getSignCreationPermission())) { manager.unregisterSign(loc); } else { event.getPlayer().sendMessage(owner.returnTranslate("sign_can_not_been_destroyed")); event.setCancelled(true); } } } }
Example 2
Source File: SignEvents.java From uSkyBlock with GNU General Public License v3.0 | 6 votes |
@EventHandler(priority = EventPriority.MONITOR) public void onSignOrChestBreak(BlockBreakEvent e) { if (e.isCancelled() || e.getBlock() == null || (e.getBlock().getType() != SkyBlockMenu.WALL_SIGN_MATERIAL && !(e.getBlock().getType() == Material.CHEST || e.getBlock().getType() == Material.TRAPPED_CHEST)) || e.getBlock().getLocation() == null || !plugin.getWorldManager().isSkyAssociatedWorld(e.getBlock().getLocation().getWorld()) ) { return; } if (e.getBlock().getType() == SkyBlockMenu.WALL_SIGN_MATERIAL) { logic.removeSign(e.getBlock().getLocation()); } else { logic.removeChest(e.getBlock().getLocation()); } }
Example 3
Source File: SignsFeature.java From AreaShop with GNU General Public License v3.0 | 6 votes |
@EventHandler(priority = EventPriority.HIGH) public void onSignBreak(BlockBreakEvent event) { if(event.isCancelled()) { return; } Block block = event.getBlock(); // Check if it is a sign if(Materials.isSign(block.getType())) { // Check if the rent sign is really the same as a saved rent RegionSign regionSign = SignsFeature.getSignByLocation(block.getLocation()); if(regionSign == null) { return; } // Remove the sign of the rental region if the player has permission if(event.getPlayer().hasPermission("areashop.delsign")) { regionSign.remove(); plugin.message(event.getPlayer(), "delsign-success", regionSign.getRegion()); } else { // Cancel the breaking of the sign event.setCancelled(true); plugin.message(event.getPlayer(), "delsign-noPermission", regionSign.getRegion()); } } }
Example 4
Source File: Main.java From ArmorStandTools with MIT License | 6 votes |
boolean checkBlockPermission(Player p, Block b) { if(b == null) return true; debug("PlotSquaredHook.api: " + PlotSquaredHook.api); if (PlotSquaredHook.api != null) { Location l = b.getLocation(); debug("PlotSquaredHook.isPlotWorld(l): " + PlotSquaredHook.isPlotWorld(l)); if(PlotSquaredHook.isPlotWorld(l)) { return PlotSquaredHook.checkPermission(p, l); } } if(Config.worldGuardPlugin != null) { if(!Utils.hasPermissionNode(p, "astools.bypass-wg-flag") && !getWorldGuardAstFlag(b.getLocation())) { return false; } return Config.worldGuardPlugin.createProtectionQuery().testBlockBreak(p, b); } BlockBreakEvent breakEvent = new BlockBreakEvent(b, p); Bukkit.getServer().getPluginManager().callEvent(breakEvent); return !breakEvent.isCancelled(); }
Example 5
Source File: BalrogEvent.java From EliteMobs with GNU General Public License v3.0 | 6 votes |
@EventHandler public void onMine(BlockBreakEvent event) { if (event.isCancelled()) return; if (!EliteMobs.validWorldList.contains(event.getPlayer().getWorld())) return; if (event.getPlayer().getGameMode() == GameMode.CREATIVE || event.getPlayer().getGameMode() == GameMode.SPECTATOR) return; if (!event.getPlayer().hasPermission("elitemobs.events.balrog")) return; if (event.getPlayer().getInventory().getItemInMainHand().hasItemMeta() && event.getPlayer().getInventory().getItemInMainHand().getEnchantments().containsKey(Enchantment.SILK_TOUCH)) return; if (!(event.getBlock().getType().equals(Material.DIAMOND_ORE) || event.getBlock().getType().equals(Material.IRON_ORE) || event.getBlock().getType().equals(Material.COAL_ORE) || event.getBlock().getType().equals(Material.REDSTONE_ORE) || event.getBlock().getType().equals(Material.LAPIS_ORE) || event.getBlock().getType().equals(Material.GOLD_ORE))) return; if (ThreadLocalRandom.current().nextDouble() > ConfigValues.eventsConfig.getDouble(EventsConfig.BALROG_CHANCE_ON_MINE)) return; Balrog.spawnBalrog(event.getBlock().getLocation()); }
Example 6
Source File: SpleefTracker.java From CardinalPGM with MIT License | 6 votes |
@EventHandler(priority = EventPriority.MONITOR) public void onBlockBreak(BlockBreakEvent event) { if (event.isCancelled() || GameHandler.getGameHandler().getMatch().getModules().getModule(TitleRespawn.class).isDeadUUID(event.getPlayer().getUniqueId())) return; for (Player player : Bukkit.getOnlinePlayers()) { Location location = event.getBlock().getLocation(); location.setY(location.getY() + 1); Location playerLoc = player.getLocation(); if (playerLoc.getBlockX() == location.getBlockX() && playerLoc.getBlockY() == location.getBlockY() && playerLoc.getBlockZ() == location.getBlockZ()) { Description description = null; if (player.getLocation().add(new Vector(0, 1, 0)).getBlock().getType().equals(Material.LADDER)) { description = Description.OFF_A_LADDER; } else if (player.getLocation().add(new Vector(0, 1, 0)).getBlock().getType().equals(Material.VINE)) { description = Description.OFF_A_VINE; } else if (player.getLocation().getBlock().getType().equals(Material.WATER) || player.getLocation().getBlock().getType().equals(Material.STATIONARY_WATER)) { description = Description.OUT_OF_THE_WATER; } else if (player.getLocation().getBlock().getType().equals(Material.LAVA) || player.getLocation().getBlock().getType().equals(Material.STATIONARY_LAVA)) { description = Description.OUT_OF_THE_LAVA; } Bukkit.getServer().getPluginManager().callEvent(new TrackerDamageEvent(player, event.getPlayer(), event.getPlayer().getItemInHand(), Cause.PLAYER, description, Type.SPLEEFED)); } } }
Example 7
Source File: SignListener.java From BedWars with GNU Lesser General Public License v3.0 | 6 votes |
@EventHandler public void onBlockBreak(BlockBreakEvent event) { if (event.isCancelled()) { return; } if (event.getBlock().getState() instanceof Sign) { Location loc = event.getBlock().getLocation(); if (manager.isSignRegistered(loc)) { if (event.getPlayer().hasPermission(owner.getSignCreationPermission())) { manager.unregisterSign(loc); } else { event.getPlayer().sendMessage(owner.returnTranslate("sign_can_not_been_destroyed")); event.setCancelled(true); } } } }
Example 8
Source File: RegionsTests.java From Civs with GNU General Public License v3.0 | 6 votes |
@Test public void regionShouldBeDestroyedCenter() { loadRegionTypeCobble(); HashMap<UUID, String> owners = new HashMap<>(); owners.put(TestUtil.player.getUniqueId(), Constants.OWNER); Location location1 = new Location(Bukkit.getWorld("world"), 4, 0, 0); RegionType regionType = (RegionType) ItemManager.getInstance().getItemType("cobble"); RegionManager.getInstance().addRegion(new Region("cobble", owners, location1, getRadii(), regionType.getEffects(),0)); BlockBreakEvent event = new BlockBreakEvent(TestUtil.blockUnique, TestUtil.player); CivilianListener civilianListener = new CivilianListener(); ProtectionHandler protectionHandler = new ProtectionHandler(); protectionHandler.onBlockBreak(event); if (!event.isCancelled()) { civilianListener.onCivilianBlockBreak(event); } assertNull(RegionManager.getInstance().getRegionAt(location1)); }
Example 9
Source File: TownTests.java From Civs with GNU General Public License v3.0 | 5 votes |
@Test public void townShouldDestroyWhenCriticalRegionDestroyed3() { RegionsTests.loadRegionTypeCobbleGroup(); RegionsTests.loadRegionTypeCobbleGroup2(); HashMap<UUID, String> people = new HashMap<>(); people.put(TestUtil.player.getUniqueId(), Constants.OWNER); HashMap<String, String> effects = new HashMap<>(); Location regionLocation = new Location(Bukkit.getWorld("world2"), 0,0,0); Location regionLocation2 = new Location(Bukkit.getWorld("world2"), 0,20,0); Region region = new Region("town_hall", people, regionLocation, RegionsTests.getRadii(), effects,0); loadTownTypeTribe(); Location townLocation = new Location(Bukkit.getWorld("world2"), 1,0,0); RegionsTests.createNewRegion("purifier", regionLocation2); RegionManager regionManager = RegionManager.getInstance(); regionManager.addRegion(region); loadTown("Sanmak-kol", "tribe", townLocation); if (TownManager.getInstance().getTowns().isEmpty()) { fail("No town found"); } ProtectionHandler protectionHandler = new ProtectionHandler(); Block block = mock(Block.class); when(block.getLocation()).thenReturn(regionLocation); BlockBreakEvent blockBreakEvent = new BlockBreakEvent(block, TestUtil.player); CivilianListener civilianListener = new CivilianListener(); protectionHandler.onBlockBreak(blockBreakEvent); if (!blockBreakEvent.isCancelled()) { civilianListener.onCivilianBlockBreak(blockBreakEvent); } assertNull(regionManager.getRegionAt(regionLocation)); assertTrue(TownManager.getInstance().getTowns().isEmpty()); }
Example 10
Source File: WarListener.java From civcraft with GNU General Public License v2.0 | 5 votes |
@EventHandler(priority = EventPriority.HIGH) public void onBlockBreak(BlockBreakEvent 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.TNT) || event.getBlock().getType().equals(Material.LADDER) || event.getBlock().getType().equals(Material.VINE) || !event.getBlock().getType().isSolid()) { return; } CivMessage.sendError(event.getPlayer(), "Must use TNT to break blocks in at-war civilization cultures during WarTime."); event.setCancelled(true); }
Example 11
Source File: TrapListener.java From BedwarsRel with GNU General Public License v3.0 | 5 votes |
@EventHandler(priority = EventPriority.HIGH) public void onBreak(BlockBreakEvent br) { if (br.isCancelled()) { return; } Block toDestroy = br.getBlock(); if (br.getBlock().getType() != Material.TRIPWIRE) { Block relative = br.getBlock().getRelative(BlockFace.UP); // check above if (!relative.getType().equals(Material.TRIPWIRE)) { return; } toDestroy = relative; } Player player = br.getPlayer(); Game game = BedwarsRel.getInstance().getGameManager().getGameOfPlayer(player); if (game == null) { return; } if (game.getState() != GameState.RUNNING) { return; } if (br.getBlock().equals(toDestroy)) { br.setCancelled(true); return; } toDestroy.setType(Material.AIR); }
Example 12
Source File: BlockBreakRegion.java From CardinalPGM with MIT License | 5 votes |
@EventHandler public void onBlockBreak(BlockBreakEvent event) { if (!event.isCancelled() && region.contains(new BlockRegion(null, event.getBlock().getLocation().toVector())) && filter.evaluate(event.getPlayer(), event.getBlock(), event).equals(FilterState.DENY)) { event.setCancelled(true); ChatUtil.sendWarningMessage(event.getPlayer(), message); } }
Example 13
Source File: LoggingManager.java From Survival-Games with GNU General Public License v3.0 | 5 votes |
@EventHandler(priority = EventPriority.MONITOR) public void blockChanged(BlockBreakEvent e){ if(e.isCancelled())return; logBlockDestoryed(e.getBlock()); i.put("BCHANGE", i.get("BCHANGE")+1); // Sur(1); }
Example 14
Source File: TownTests.java From Civs with GNU General Public License v3.0 | 5 votes |
@Test public void townShouldDestroyWhenCriticalRegionDestroyed() { RegionsTests.loadRegionTypeCobble(); HashMap<UUID, String> people = new HashMap<>(); people.put(TestUtil.player.getUniqueId(), Constants.OWNER); HashMap<String, String> effects = new HashMap<>(); Location regionLocation = new Location(Bukkit.getWorld("world2"), 0,0,0); Region region = new Region("cobble", people, regionLocation, RegionsTests.getRadii(), effects,0); loadTownTypeTribe(); Location townLocation = new Location(Bukkit.getWorld("world2"), 1,0,0); RegionManager regionManager = RegionManager.getInstance(); regionManager.addRegion(region); loadTown("Sanmak-kol", "tribe", townLocation); if (TownManager.getInstance().getTowns().isEmpty()) { fail("No town found"); } ProtectionHandler protectionHandler = new ProtectionHandler(); Block block = mock(Block.class); when(block.getLocation()).thenReturn(regionLocation); BlockBreakEvent blockBreakEvent = new BlockBreakEvent(block, TestUtil.player); CivilianListener civilianListener = new CivilianListener(); protectionHandler.onBlockBreak(blockBreakEvent); if (!blockBreakEvent.isCancelled()) { civilianListener.onCivilianBlockBreak(blockBreakEvent); } assertNull(regionManager.getRegionAt(regionLocation)); assertTrue(TownManager.getInstance().getTowns().isEmpty()); }
Example 15
Source File: QAListener.java From QualityArmory with GNU General Public License v3.0 | 5 votes |
@SuppressWarnings("deprecation") @EventHandler(priority = EventPriority.MONITOR) public void onBlockBreakMonitor(final BlockBreakEvent e) { if (e.isCancelled()) return; if (CustomItemManager.isUsingCustomData()) return; int k = 0; if (e.getPlayer().getItemInHand() != null) if ((k = Gun.getCalculatedExtraDurib(e.getPlayer().getItemInHand())) != -1) { ItemStack hand = e.getPlayer().getItemInHand(); e.getBlock().breakNaturally(hand); e.setCancelled(true); final ItemStack t; if (k > 0) { t = Gun.decrementCalculatedExtra(hand); } else { t = Gun.removeCalculatedExtra(hand); } new BukkitRunnable() { @Override public void run() { e.getPlayer().setItemInHand(t); } }.runTaskLater(QAMain.getInstance(), 1); } }
Example 16
Source File: QAListener.java From QualityArmory with GNU General Public License v3.0 | 5 votes |
@SuppressWarnings("deprecation") @EventHandler public void onBlockBreak(BlockBreakEvent e) { if (e.isCancelled()) return; if (e.getPlayer().getItemInHand() != null && (QualityArmory.isCustomItem(e.getPlayer().getItemInHand()))) { e.setCancelled(true); return; } }
Example 17
Source File: SignExtension.java From HeavySpleef with GNU General Public License v3.0 | 4 votes |
@EventHandler(priority = EventPriority.MONITOR) public void onBlockBreak(BlockBreakEvent event) { if (event.isCancelled()) { return; } GameManager manager = heavySpleef.getGameManager(); Block block = event.getBlock(); Location blockLoc = block.getLocation(); Game gameFound = null; SignExtension found = null; for (Game game : manager.getGames()) { for (SignExtension extension : game.getExtensionsByType(SignExtension.class)) { Location location = extension.getLocation(); if (blockLoc.equals(location)) { found = extension; gameFound = game; break; } } if (found != null) { break; } } if (found == null) { return; } SpleefPlayer player = heavySpleef.getSpleefPlayer(event.getPlayer()); if (!player.hasPermission(Permissions.PERMISSION_REMOVE_SIGN)) { return; } gameFound.removeExtension(found); player.sendMessage(i18n.getVarString(Messages.Player.SIGN_REMOVED) .setVariable("game", gameFound.getName()) .toString()); heavySpleef.getDatabaseHandler().saveGame(gameFound, null); }
Example 18
Source File: CoreObjective.java From CardinalPGM with MIT License | 4 votes |
@EventHandler(priority = EventPriority.HIGHEST) public void onBlockBreak(BlockBreakEvent event) { if (!event.isCancelled()) { if (getBlocks().contains(event.getBlock())) { if (Teams.getTeamByPlayer(event.getPlayer()).orNull() != team) { boolean touchMessage = false; if (!playersTouched.contains(event.getPlayer().getUniqueId())) { playersTouched.add(event.getPlayer().getUniqueId()); Optional<TeamModule> teamModule = Teams.getTeamByPlayer(event.getPlayer()); if (teamModule.isPresent()) { ChatChannel channel = Teams.getTeamChannel(teamModule); if (this.show && !this.complete) { channel.sendLocalizedMessage(new LocalizedChatMessage(ChatConstant.UI_OBJECTIVE_TOUCHED_FOR, teamModule.get().getColor() + event.getPlayer().getName() + ChatColor.WHITE, name, teamModule.get().getCompleteName() + ChatColor.WHITE)); for (Player player : Bukkit.getOnlinePlayers()) { if (Teams.getTeamByPlayer(player).isPresent() && Teams.getTeamByPlayer(player).get().isObserver()) { player.sendMessage(new LocalizedChatMessage(ChatConstant.UI_OBJECTIVE_TOUCHED_FOR, teamModule.get().getColor() + event.getPlayer().getName() + ChatColor.GRAY, ChatColor.RED + name + ChatColor.GRAY, teamModule.get().getCompleteName() + ChatColor.GRAY).getMessage(player.getLocale())); } } touchMessage = true; } } } if (!playersCompleted.contains(event.getPlayer().getUniqueId())) playersCompleted.add(event.getPlayer().getUniqueId()); this.touched = true; ObjectiveTouchEvent touchEvent = new ObjectiveTouchEvent(this, event.getPlayer(), touchMessage); Bukkit.getServer().getPluginManager().callEvent(touchEvent); event.setCancelled(false); } else { event.setCancelled(true); if (this.show) ChatUtil.sendWarningMessage(event.getPlayer(), new LocalizedChatMessage(ChatConstant.ERROR_OWN_CORE)); return; } } if (core.contains(event.getBlock())) { if (Teams.getTeamByPlayer(event.getPlayer()).orNull() == team) { event.setCancelled(true); if (this.show) ChatUtil.sendWarningMessage(event.getPlayer(), new LocalizedChatMessage(ChatConstant.ERROR_OWN_CORE)); } } } }
Example 19
Source File: DataHandler.java From MineTinker with GNU General Public License v3.0 | 4 votes |
public static boolean playerBreakBlock(@NotNull Player player, Block block, @NotNull ItemStack itemStack) { //Trigger BlockBreakEvent BlockBreakEvent breakEvent = new BlockBreakEvent(block, player); ItemMeta meta = itemStack.getItemMeta(); if (meta != null && !meta.hasEnchant(Enchantment.SILK_TOUCH)) breakEvent.setExpToDrop(calculateExp(block.getType())); Bukkit.getPluginManager().callEvent(breakEvent); //Check if Event got cancelled and if not destroy the block and check if the player can successfully break the blocks (incl. drops) //Block#breakNaturally(ItemStack itemStack) can not be used as it drops Items itself (without Event and we don't want that) if (!breakEvent.isCancelled()) { //Get all drops to drop Collection<ItemStack> items = block.getDrops(itemStack); //Set Block to Material.AIR (effectively breaks the Block) block.setType(Material.AIR); //TODO: Play Sound? //Check if items need to be dropped if (breakEvent.isDropItems()) { List<Item> itemEntities = items.stream() .map(entry -> player.getWorld().dropItemNaturally(block.getLocation(), entry)) //World#spawnEntity() does not work for Items .collect(Collectors.toList()); //Trigger BlockDropItemEvent (internally also used for Directing) BlockDropItemEvent event = new BlockDropItemEvent(block, block.getState(), player, new ArrayList<>(itemEntities)); Bukkit.getPluginManager().callEvent(event); //check if Event got cancelled if (!event.isCancelled()) { //Remove all drops that should be dropped itemEntities.removeIf(element -> event.getItems().contains(element)); } itemEntities.forEach(Item::remove); } //Check if Exp needs to be dropped if (breakEvent.getExpToDrop() > 0) { //Spawn Experience Orb ExperienceOrb orb = (ExperienceOrb) player.getWorld().spawnEntity(block.getLocation(), EntityType.EXPERIENCE_ORB); orb.setExperience(breakEvent.getExpToDrop()); } return true; } return false; }
Example 20
Source File: BlockBreakListener.java From IridiumSkyblock with GNU General Public License v2.0 | 4 votes |
@EventHandler public void onBlockBreak(BlockBreakEvent event) { try { if (event.isCancelled()) return; final Block block = event.getBlock(); final Location location = block.getLocation(); final IslandManager islandManager = IridiumSkyblock.getIslandManager(); final Island island = islandManager.getIslandViaLocation(location); if (island == null) return; final Player player = event.getPlayer(); final User user = User.getUser(player); if (user.islandID == island.getId()) { for (Missions.Mission mission : IridiumSkyblock.getMissions().missions) { final int key = island.getMissionLevels().computeIfAbsent(mission.name, (name) -> 1); final Map<Integer, Missions.MissionData> levels = mission.levels; final Missions.MissionData level = levels.get(key); if (level == null) continue; if (level.type != MissionType.BLOCK_BREAK) continue; final List<String> conditions = level.conditions; if ( conditions.isEmpty() || conditions.contains(XMaterial.matchXMaterial(block.getType()).name()) || ( block.getState().getData() instanceof Crops && conditions.contains(((Crops) block.getState().getData()).getState().toString()) ) ) island.addMission(mission.name, 1); } } if (!island.getPermissions(user).breakBlocks || (!island.getPermissions(user).breakSpawners && XMaterial.matchXMaterial(block.getType()).equals(XMaterial.SPAWNER))) { if (XMaterial.matchXMaterial(block.getType()).equals(XMaterial.SPAWNER)) { player.sendMessage(Utils.color(IridiumSkyblock.getMessages().noPermissionBreakSpawners.replace("%prefix%", IridiumSkyblock.getConfiguration().prefix))); } else { player.sendMessage(Utils.color(IridiumSkyblock.getMessages().noPermissionBuild.replace("%prefix%", IridiumSkyblock.getConfiguration().prefix))); } event.setCancelled(true); } } catch (Exception e) { IridiumSkyblock.getInstance().sendErrorMessage(e); } }