Java Code Examples for org.bukkit.event.block.BlockBreakEvent#setCancelled()
The following examples show how to use
org.bukkit.event.block.BlockBreakEvent#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: WarpSigns.java From askyblock with GNU General Public License v2.0 | 5 votes |
/** * Checks to see if a sign has been broken * @param e - event */ @EventHandler(priority = EventPriority.NORMAL) public void onSignBreak(BlockBreakEvent e) { Block b = e.getBlock(); Player player = e.getPlayer(); if (b.getWorld().equals(ASkyBlock.getIslandWorld()) || b.getWorld().equals(ASkyBlock.getNetherWorld())) { if (b.getType().equals(Material.SIGN_POST) || b.getType().equals(Material.WALL_SIGN)) { Sign s = (Sign) b.getState(); if (s != null) { //plugin.getLogger().info("DEBUG: sign found at location " + s.toString()); if (s.getLine(0).equalsIgnoreCase(ChatColor.GREEN + plugin.myLocale().warpswelcomeLine)) { // Do a quick check to see if this sign location is in //plugin.getLogger().info("DEBUG: welcome sign"); // the list of warp signs if (warpList.containsValue(s.getLocation())) { //plugin.getLogger().info("DEBUG: warp sign is in list"); // Welcome sign detected - check to see if it is // this player's sign if ((warpList.containsKey(player.getUniqueId()) && warpList.get(player.getUniqueId()).equals(s.getLocation()))) { // Player removed sign removeWarp(s.getLocation()); Bukkit.getPluginManager().callEvent(new WarpRemoveEvent(plugin, s.getLocation(), player.getUniqueId())); } else if (player.isOp() || player.hasPermission(Settings.PERMPREFIX + "mod.removesign")) { // Op or mod removed sign Util.sendMessage(player, ChatColor.GREEN + plugin.myLocale(player.getUniqueId()).warpsremoved); removeWarp(s.getLocation()); Bukkit.getPluginManager().callEvent(new WarpRemoveEvent(plugin, s.getLocation(), player.getUniqueId())); } else { // Someone else's sign - not allowed Util.sendMessage(player, ChatColor.RED + plugin.myLocale(player.getUniqueId()).warpserrorNoRemove); e.setCancelled(true); } } } } } } }
Example 2
Source File: BlockBreak.java From StaffPlus with GNU General Public License v3.0 | 5 votes |
@EventHandler(priority = EventPriority.HIGHEST, ignoreCancelled = true) public void onBreak(BlockBreakEvent event) { Player player = event.getPlayer(); UUID uuid = player.getUniqueId(); if(freezeHandler.isFrozen(uuid)) { event.setCancelled(true); return; } if(options.modeBlockManipulation || !modeCoordinator.isInMode(player.getUniqueId())) { Block block = event.getBlock(); if(options.alertsXrayBlocks.contains(block.getType())) { int start = alertCoordinator.getNotifiedAmount(); int amount = 0; alertCoordinator.addNotified(block.getLocation()); calculateVein(block.getType(), block, false); amount = alertCoordinator.getNotifiedAmount() - start; if(amount > 0) { int lightLevel = player.getLocation().getBlock().getLightLevel(); alertCoordinator.onXray(player.getName(), amount, block.getType(), lightLevel); } } return; } event.setCancelled(true); }
Example 3
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 4
Source File: CannonListener.java From civcraft with GNU General Public License v2.0 | 5 votes |
@EventHandler(priority = EventPriority.NORMAL) public void onBlockBreak(BlockBreakEvent event) { bcoord.setFromLocation(event.getBlock().getLocation()); Cannon cannon = Cannon.cannonBlocks.get(bcoord); if (cannon != null) { cannon.onHit(event); event.setCancelled(true); return; } }
Example 5
Source File: CustomItemManager.java From civcraft with GNU General Public License v2.0 | 5 votes |
@EventHandler(priority = EventPriority.NORMAL) public void onBlockBreakSpawnItems(BlockBreakEvent event) { if (event.getBlock().getType().equals(Material.LAPIS_ORE)) { if (event.getPlayer().getItemInHand().containsEnchantment(Enchantment.SILK_TOUCH)) { return; } event.setCancelled(true); ItemManager.setTypeIdAndData(event.getBlock(), CivData.AIR, (byte)0, true); try { Random rand = new Random(); int min = CivSettings.getInteger(CivSettings.materialsConfig, "tungsten_min_drop"); int max; if (event.getPlayer().getItemInHand().containsEnchantment(Enchantment.LOOT_BONUS_BLOCKS)) { max = CivSettings.getInteger(CivSettings.materialsConfig, "tungsten_max_drop_with_fortune"); } else { max = CivSettings.getInteger(CivSettings.materialsConfig, "tungsten_max_drop"); } int randAmount = rand.nextInt(min + max); randAmount -= min; if (randAmount <= 0) { randAmount = 1; } for (int i = 0; i < randAmount; i++) { ItemStack stack = LoreMaterial.spawn(LoreMaterial.materialMap.get("mat_tungsten_ore")); event.getPlayer().getWorld().dropItemNaturally(event.getBlock().getLocation(), stack); } } catch (InvalidConfiguration e) { e.printStackTrace(); return; } } }
Example 6
Source File: BreakEvent.java From Survival-Games with GNU General Public License v3.0 | 5 votes |
@EventHandler(priority = EventPriority.HIGHEST) public void onBlockBreak(BlockBreakEvent event) { Player p = event.getPlayer(); int pid = GameManager.getInstance().getPlayerGameId(p); if(pid == -1){ int blockgameid = GameManager.getInstance().getBlockGameId(event.getBlock().getLocation()); if(blockgameid != -1){ if(GameManager.getInstance().getGame(blockgameid).getGameMode() != Game.GameMode.DISABLED){ event.setCancelled(true); } } return; } Game g = GameManager.getInstance().getGame(pid); if(g.getMode() == Game.GameMode.DISABLED){ return; } if(g.getMode() != Game.GameMode.INGAME){ event.setCancelled(true); return; } if(allowedBreak.contains(event.getBlock().getType())) { event.setCancelled(false); }else { event.setCancelled(true); } }
Example 7
Source File: BlockListener.java From Carbon with GNU Lesser General Public License v3.0 | 5 votes |
@EventHandler(priority = EventPriority.MONITOR, ignoreCancelled = true) public void onDirtBreakBreak(BlockBreakEvent event) { if (event.getPlayer().getGameMode() == GameMode.CREATIVE) { return; } if (event.getBlock().getState().getData().toString().equals("DIRT(1)")) { event.getBlock().getWorld().dropItemNaturally(event.getBlock().getLocation(), new ItemStack(Material.DIRT, 1, (short) 1)); event.getBlock().setType(Material.AIR); event.setCancelled(true); return; } }
Example 8
Source File: RegionInteractListener.java From NovaGuilds with GNU General Public License v3.0 | 5 votes |
@EventHandler public void onBlockBreak(BlockBreakEvent event) { //BREAKING Player player = event.getPlayer(); NovaPlayer nPlayer = PlayerManager.getPlayer(player); if(RegionManager.get(event.getBlock()) != null && (!plugin.getRegionManager().canInteract(player, event.getBlock()) || (!nPlayer.getPreferences().getBypass() && !nPlayer.hasPermission(GuildPermission.BLOCK_BREAK)))) { event.setCancelled(true); Message.CHAT_REGION_DENY_INTERACT.send(player); } }
Example 9
Source File: FlagSpectate.java From HeavySpleef with GNU General Public License v3.0 | 5 votes |
@EventHandler public void onPlayerBreakBlock(BlockBreakEvent event) { SpleefPlayer player = getHeavySpleef().getSpleefPlayer(event.getPlayer()); if (!isSpectating(player)) { return; } event.setCancelled(true); }
Example 10
Source File: SpectatorEvents.java From Survival-Games with GNU General Public License v3.0 | 5 votes |
@EventHandler(priority = EventPriority.HIGHEST) public void onBlockBreak(BlockBreakEvent event) { Player player = event.getPlayer(); if (GameManager.getInstance().isSpectator(player)) { event.setCancelled(true); } }
Example 11
Source File: FlagObjective.java From CardinalPGM with MIT License | 5 votes |
@EventHandler public void onBlockBreak(BlockBreakEvent event) { if (isOnPost() || isDropped()) { if (event.getBlock().equals(currentFlagBlock)) { event.setCancelled(true); event.getPlayer().sendMessage(ChatColor.RED + new LocalizedChatMessage(ChatConstant.ERROR_BREAK_FLAG).getMessage(event.getPlayer().getLocale())); } else if (event.getBlock().getRelative(BlockFace.UP).equals(currentFlagBlock)) { event.setCancelled(true); event.getPlayer().sendMessage(ChatColor.RED + new LocalizedChatMessage(ChatConstant.ERROR_BREAK_BLOCK_UNDER_FLAG).getMessage(event.getPlayer().getLocale())); } } }
Example 12
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 13
Source File: Transporter.java From AnnihilationPro with MIT License | 5 votes |
@EventHandler(priority = EventPriority.HIGHEST,ignoreCancelled = true) public void TeleporterProtect(BlockBreakEvent event) { Player player = event.getPlayer(); Block b = event.getBlock(); if(b.getType() == Material.QUARTZ_ORE) { event.setCancelled(true); AnniPlayer p = AnniPlayer.getPlayer(player.getUniqueId()); if(p != null) { UUID owner = getBlocksOwner(b); if(owner == null) return; Teleporter tele = teleporters.get(owner); if(p.getID().equals(owner)) { tele.clear(); } else if(p.getTeam() != tele.getOwner().getTeam()) { tele.clear(); tele.getOwner().sendMessage(ChatColor.AQUA+"Your teleporter was broken by "+p.getTeam().getColor()+p.getName()); } } } }
Example 14
Source File: SignListener.java From RandomTeleport with GNU General Public License v3.0 | 5 votes |
@EventHandler(ignoreCancelled = true) public void onSignDestroy(BlockBreakEvent event) { if (event.getBlock().getType().name().contains("SIGN")) { Sign sign = (Sign) event.getBlock().getState(); if (plugin.matchesSignVariable(sign.getLine(1))) { if (!event.getPlayer().hasPermission("randomteleport.sign.destroy")) { event.setCancelled(true); plugin.sendMessage(event.getPlayer(), "sign.no-permission.destroy", "perm", "randomteleport.sign.destroy"); } else { plugin.sendMessage(event.getPlayer(), "sign.destroyed", "preset", sign.getLine(2)); } } } }
Example 15
Source File: TutorialListener.java From ServerTutorial with MIT License | 4 votes |
@EventHandler public void onBreak(BlockBreakEvent event) { if (TutorialManager.getManager().isInTutorial(event.getPlayer().getName())) { event.setCancelled(true); } }
Example 16
Source File: BlockListener.java From AuthMeReloaded with GNU General Public License v3.0 | 4 votes |
@EventHandler(ignoreCancelled = true) public void onBlockBreak(BlockBreakEvent event) { if (listenerService.shouldCancelEvent(event.getPlayer())) { event.setCancelled(true); } }
Example 17
Source File: BukkitPlotListener.java From PlotMe-Core with GNU General Public License v3.0 | 4 votes |
@EventHandler(priority = EventPriority.HIGH, ignoreCancelled = true) public void onBlockBreak(BlockBreakEvent event) { IPlayer player = plugin.wrapPlayer(event.getPlayer()); org.bukkit.Location bloc = event.getBlock().getLocation(); Location location = BukkitUtil.adapt(bloc); if (manager.isPlotWorld(location)) { if (player.hasPermission(PermissionNames.ADMIN_BUILDANYWHERE)) { return; } Plot plot = manager.getPlot(location); if (plot == null) { player.sendMessage(api.C("CannotBuild")); event.setCancelled(true); } else { if (plot.getOwnerId().equals(player.getUniqueId())) { return; } Optional<Plot.AccessLevel> member = plot.isMember(player.getUniqueId()); if (member.isPresent()) { if (member.get().equals(Plot.AccessLevel.TRUSTED) && !api.getServerBridge().getOfflinePlayer(plot.getOwnerId()).isOnline()) { player.sendMessage(api.C("CannotBuild")); event.setCancelled(true); return; } else if (api.isPlotLocked(plot.getId())) { player.sendMessage(api.C("PlotLocked")); event.setCancelled(true); } if (plot.getExpiredDate() != null) { Calendar instance = Calendar.getInstance(); instance.add(Calendar.DAY_OF_YEAR, manager.getMap(player).getDaysToExpiration()); if (!plot.getExpiredDate().equals(instance.getTime())) { plot.resetExpire(manager.getMap(player).getDaysToExpiration()); plugin.getAPI().getSqlManager().savePlot(plot); } } } else { player.sendMessage(api.C("CannotBuild")); event.setCancelled(true); } } } }
Example 18
Source File: BlockListener.java From MineTinker with GNU General Public License v3.0 | 4 votes |
@EventHandler(priority = EventPriority.HIGHEST, ignoreCancelled = true) public void onBlockBreak(BlockBreakEvent event) { Player player = event.getPlayer(); ItemStack tool = player.getInventory().getItemInMainHand(); if (Lists.WORLDS.contains(player.getWorld().getName())) { return; } if (event.getBlock().getType().getHardness() == 0 && !(tool.getType() == Material.SHEARS || ToolType.HOE.contains(tool.getType()))) { return; } if (!modManager.isToolViable(tool)) { return; } FileConfiguration config = MineTinker.getPlugin().getConfig(); //--------------------------------------EXP-CALCULATIONS-------------------------------------------- if (player.getGameMode() != GameMode.CREATIVE) { long cooldown = MineTinker.getPlugin().getConfig().getLong("BlockExpCooldownInSeconds", 60) * 1000; boolean eligible = true; if (cooldown > 0) { List<MetadataValue> blockPlaced = event.getBlock().getMetadata("blockPlaced"); for(MetadataValue val : blockPlaced) { if (val == null) continue; if (!MineTinker.getPlugin().equals(val.getOwningPlugin())) continue; //Not MTs value Object value = val.value(); if (value instanceof Long) { long time = (long) value; eligible = System.currentTimeMillis() - cooldown > time; break; } } } if (eligible) { int expAmount = config.getInt("ExpPerBlockBreak"); if (!(!config.getBoolean("ExtraExpPerBlock.ApplicableToSilkTouch") && modManager.hasMod(tool, SilkTouch.instance()))) { expAmount += config.getInt("ExtraExpPerBlock." + event.getBlock().getType().toString()); //adds 0 if not in found in config (negative values are also fine) } modManager.addExp(player, tool, expAmount); } } //-------------------------------------------POWERCHECK--------------------------------------------- if (Power.HAS_POWER.get(player).get() && !ToolType.PICKAXE.contains(tool.getType()) && event.getBlock().getDrops(tool).isEmpty() && event.getBlock().getType() != Material.NETHER_WART) { //Necessary for EasyHarvest NetherWard-Break event.setCancelled(true); return; } MTBlockBreakEvent breakEvent = new MTBlockBreakEvent(tool, event); Bukkit.getPluginManager().callEvent(breakEvent); //Event-Trigger for Modifiers }
Example 19
Source File: FreezeMatchModule.java From PGM with GNU Affero General Public License v3.0 | 4 votes |
@EventHandler(priority = EventPriority.LOW, ignoreCancelled = true) public void onBlockBreak(final BlockBreakEvent event) { if (freeze.isFrozen(event.getPlayer())) { event.setCancelled(true); } }
Example 20
Source File: WoolObjective.java From CardinalPGM with MIT License | 4 votes |
@EventHandler public void onBlockBreak(BlockBreakEvent event) { if (event.getBlock().equals(place.getBlock())) { event.setCancelled(true); } }