Java Code Examples for org.bukkit.event.block.BlockBreakEvent#getPlayer()
The following examples show how to use
org.bukkit.event.block.BlockBreakEvent#getPlayer() .
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: GlobalProtectionListener.java From DungeonsXL with GNU General Public License v3.0 | 6 votes |
@EventHandler(ignoreCancelled = true, priority = EventPriority.HIGHEST) public void onBlockBreakWithSignOnIt(BlockBreakEvent event) { Block block = event.getBlock(); Player player = event.getPlayer(); Block blockAbove = block.getRelative(BlockFace.UP); //get the above block and return if there is nothing if (blockAbove == null) { return; } //return if above block is not a sign if (!Category.SIGNS.containsBlock(blockAbove)) { return; } //let onBreak() method to handle the sign BlockBreakEvent bbe = new BlockBreakEvent(blockAbove, player); onBlockBreak(bbe); //follow the onBreak() event.setCancelled(bbe.isCancelled()); }
Example 2
Source File: PlayerBlockModifyEventHandler.java From SuperVanish with Mozilla Public License 2.0 | 5 votes |
@EventHandler(priority = EventPriority.HIGH) public void onBreak(BlockBreakEvent e) { try { if (plugin.getSettings().getBoolean("RestrictiveOptions.PreventBlockBreaking")) { Player p = e.getPlayer(); if (plugin.getVanishStateMgr().isVanished(p.getUniqueId()) && !p.hasPermission("sv.breakblocks")) { e.setCancelled(true); plugin.sendMessage(e.getPlayer(), "BlockBreakDenied", e.getPlayer()); } } } catch (Exception er) { plugin.logException(er); } }
Example 3
Source File: BuildEvent.java From MCAuthenticator with GNU General Public License v3.0 | 5 votes |
@EventHandler(priority = EventPriority.LOWEST) public void onBlockBreak(BlockBreakEvent event) { Player player = event.getPlayer(); User u = instance.getCache().get(player.getUniqueId()); if (u != null && u.authenticated()) return; event.setCancelled(true); }
Example 4
Source File: InvisibilityListeners.java From AnnihilationPro with MIT License | 5 votes |
@EventHandler(priority = EventPriority.MONITOR, ignoreCancelled = true) public void blockBreakingChecker(final BlockBreakEvent event) { Player player = event.getPlayer(); AnniPlayer p = AnniPlayer.getPlayer(player.getUniqueId()); if(p != null) checkInvis(player); }
Example 5
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 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: BlockBreak.java From AdditionsAPI with MIT License | 5 votes |
@EventHandler(priority = EventPriority.MONITOR) public void onBlockBreak(BlockBreakEvent event) { Player player = event.getPlayer(); ItemStack item = player.getInventory().getItemInMainHand(); if (AdditionsAPI.isCustomItem(item)) { CustomItemBlockBreakEvent customEvent = new CustomItemBlockBreakEvent(event, new CustomItemStack(item)); Bukkit.getServer().getPluginManager().callEvent(customEvent); } }
Example 8
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 9
Source File: RescuePlatformListener.java From BedWars with GNU Lesser General Public License v3.0 | 5 votes |
@EventHandler public void onBlockBreak(BlockBreakEvent event) { Player player = event.getPlayer(); if (!Main.isPlayerInGame(player)) { return; } GamePlayer gPlayer = Main.getPlayerGameProfile(player); Game game = gPlayer.getGame(); if (gPlayer.isSpectator) { return; } Block block = event.getBlock(); for (RescuePlatform checkedPlatform : getCreatedPlatforms(game, player)) { if (checkedPlatform != null) { for (Block platformBlock : checkedPlatform.getPlatformBlocks()) { if (platformBlock.equals(block) && !checkedPlatform.canBreak()) { event.setCancelled(true); } } } } }
Example 10
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 11
Source File: ChestProtectListener.java From Shopkeepers with GNU General Public License v3.0 | 5 votes |
@EventHandler(ignoreCancelled = true) void onBlockBreak(BlockBreakEvent event) { Block block = event.getBlock(); if (!Utils.isChest(block.getType())) return; Player player = event.getPlayer(); if (Utils.hasPermission(player, ShopkeepersAPI.BYPASS_PERMISSION)) return; if (plugin.getProtectedChests().isChestProtected(block, player)) { Log.debug("Cancelled breaking of chest block by '" + player.getName() + "' at '" + Utils.getLocationString(block) + "': Protected chest"); event.setCancelled(true); } }
Example 12
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 13
Source File: BlockListener.java From MineTinker with GNU General Public License v3.0 | 5 votes |
@EventHandler(priority = EventPriority.LOWEST, ignoreCancelled = true) public void onBlockBreak_DurabilityCheck(BlockBreakEvent event) { Player player = event.getPlayer(); ItemStack tool = player.getInventory().getItemInMainHand(); if (modManager.isToolViable(tool)) { modManager.durabilityCheck(event, player, tool); } }
Example 14
Source File: NetherTerraFormEvents.java From uSkyBlock with GNU General Public License v3.0 | 5 votes |
@EventHandler(priority = EventPriority.LOW, ignoreCancelled = true) public void onBlockBreak(BlockBreakEvent event) { if (event == null || !terraformEnabled) { return; } Block block = event.getBlock(); Player player = event.getPlayer(); if (!plugin.getWorldManager().isSkyNether(block.getWorld()) || !plugin.getWorldManager().isSkyNether(player.getWorld())) { return; // Bail out, not our problem } if (player.getGameMode() != GameMode.SURVIVAL) { return; } if (!plugin.playerIsOnIsland(player)) { return; } if (!terraFormMap.containsKey(block.getType())) { return; // Not a block we terra-form on. } // TODO: 10/07/2016 - R4zorax: Handle dual-wielding (would break 1.8 compatibility) ItemStack tool = event.getPlayer().getItemInHand(); if (event.getBlock().getDrops(tool).isEmpty()) { return; // Only terra-form when stuff is mined correctly } double toolWeight = getToolWeight(tool); Location playerLocation = player.getEyeLocation(); Location blockLocation = LocationUtil.centerInBlock(block.getLocation()); Vector v = new Vector(blockLocation.getX(), blockLocation.getY(), blockLocation.getZ()); v.subtract(new Vector(playerLocation.getX(), playerLocation.getY(), playerLocation.getZ())); v.normalize(); // Disable spawning above the player... enabling the player to clear a region if (playerLocation.getPitch() >= minPitch && playerLocation.getPitch() <= maxPitch) { ProtectedCuboidRegion islandRegion = WorldGuardHandler.getIslandRegion(playerLocation); List<Material> yield = getYield(block.getType(), toolWeight); for (Material mat : yield) { spawnBlock(mat, blockLocation, v, islandRegion); } } }
Example 15
Source File: VaultListener.java From NovaGuilds with GNU General Public License v3.0 | 5 votes |
@EventHandler(priority = EventPriority.HIGH) public void onBlockBreak(BlockBreakEvent event) { Player player = event.getPlayer(); NovaPlayer nPlayer = PlayerManager.getPlayer(player); if(plugin.getGuildManager().isVaultBlock(event.getBlock())) { if(nPlayer.getPreferences().getBypass()) { return; } Chest chest = (Chest) event.getBlock().getState(); if(InventoryUtils.isEmpty(chest.getInventory())) { event.setCancelled(true); if(!nPlayer.hasPermission(GuildPermission.VAULT_BREAK)) { Message.CHAT_GUILD_NOGUILDPERM.send(player); return; } if(nPlayer.getGuild().getVaultHologram() != null) { nPlayer.getGuild().getVaultHologram().delete(); nPlayer.getGuild().setVaultHologram(null); } event.getBlock().setType(Material.AIR); event.getBlock().getWorld().dropItemNaturally(event.getBlock().getLocation(), Config.VAULT_ITEM.getItemStack()); nPlayer.getGuild().setVaultLocation(null); Message.CHAT_GUILD_VAULT_BREAK_SUCCESS.send(player); } else { event.setCancelled(true); Message.CHAT_GUILD_VAULT_BREAK_NOTEMPTY.send(player); } } }
Example 16
Source File: DGameWorld.java From DungeonsXL with GNU General Public License v3.0 | 4 votes |
/** * Handles what happens when a player breaks a block. * * @param event the passed Bukkit event * @return if the event is cancelled */ public boolean onBreak(BlockBreakEvent event) { Player player = event.getPlayer(); Block block = event.getBlock(); for (DungeonSign sign : getDungeonSigns()) { if (sign == null) { continue; } if ((block.equals(sign.getSign().getBlock()) || block.equals(BlockUtil.getAttachedBlock(sign.getSign().getBlock()))) && sign.isProtected()) { return true; } } for (GameBlock gameBlock : gameBlocks) { if (block.equals(gameBlock.getBlock())) { if (gameBlock.onBreak(event)) { return true; } } else if (gameBlock instanceof MultiBlock) { if (block.equals(((MultiBlock) gameBlock).getAttachedBlock())) { if (gameBlock.onBreak(event)) { return true; } } } } Game game = getGame(); if (game == null) { return true; } if (!getRules().getState(GameRule.BREAK_BLOCKS) && !getRules().getState(GameRule.BREAK_PLACED_BLOCKS)) { return true; } // Cancel if a protected entity is attached for (Entity entity : getWorld().getNearbyEntities(block.getLocation(), 2, 2, 2)) { if (!(entity instanceof Hanging)) { continue; } if (entity.getLocation().getBlock().getRelative(((Hanging) entity).getAttachedFace()).equals(block)) { Hanging hanging = (Hanging) entity; if (getRules().getState(GameRule.DAMAGE_PROTECTED_ENTITIES).contains(caliburn.getExMob(hanging))) { event.setCancelled(true); break; } } } Map<ExItem, HashSet<ExItem>> whitelist = getRules().getState(GameRule.BREAK_WHITELIST); ExItem material = VanillaItem.get(block.getType()); ExItem breakTool = caliburn.getExItem(player.getItemInHand()); if (getRules().getState(GameRule.BREAK_PLACED_BLOCKS) && placedBlocks.contains(block)) { return false; } if (whitelist != null && whitelist.containsKey(material) && (whitelist.get(material) == null || whitelist.get(material).isEmpty() || whitelist.get(material).contains(breakTool))) { return false; } return true; }
Example 17
Source File: LWCBlockListener.java From Modern-LWC with MIT License | 4 votes |
@EventHandler public void onBlockBreak(BlockBreakEvent event) { if (!LWC.ENABLED || event.isCancelled()) { return; } LWC lwc = plugin.getLWC(); Player player = event.getPlayer(); Block block = event.getBlock(); boolean ignoreBlockDestruction = Boolean .parseBoolean(lwc.resolveProtectionConfiguration(block, "ignoreBlockDestruction")); if (ignoreBlockDestruction) { return; } ProtectionCache cache = lwc.getProtectionCache(); String cacheKey = cache.cacheKey(block.getLocation()); // In the event they place a block, remove any known nulls there if (cache.isKnownNull(cacheKey)) { cache.remove(cacheKey); } Protection protection = lwc.findProtection(block.getLocation()); if (protection == null) { return; } boolean canAccess = lwc.canAccessProtection(player, protection); boolean canAdmin = lwc.canAdminProtection(player, protection); // when destroying a chest, it's possible they are also destroying a // double chest // in the event they're trying to destroy a double chest, we should just // move // the protection to the chest that is not destroyed, if it is not that // one already. if (protection.isOwner(player) && DoubleChestMatcher.PROTECTABLES_CHESTS.contains(block.getType())) { Block doubleChest = lwc.findAdjacentDoubleChest(block); if (doubleChest != null) { // if they destroyed the protected block we want to move it aye? if (lwc.blockEquals(protection.getBlock(), block)) { // correct the block BlockCache blockCache = BlockCache.getInstance(); protection.setBlockId(blockCache.getBlockId(doubleChest)); protection.setX(doubleChest.getX()); protection.setY(doubleChest.getY()); protection.setZ(doubleChest.getZ()); protection.saveNow(); } // Repair the cache protection.radiusRemoveCache(); if (protection.getProtectionFinder() != null) { protection.getProtectionFinder().removeBlock(block.getState()); } lwc.getProtectionCache().addProtection(protection); return; } } try { LWCProtectionDestroyEvent evt = new LWCProtectionDestroyEvent(player, protection, LWCProtectionDestroyEvent.Method.BLOCK_DESTRUCTION, canAccess, canAdmin); lwc.getModuleLoader().dispatchEvent(evt); if (evt.isCancelled() || !canAccess) { event.setCancelled(true); } } catch (Exception e) { event.setCancelled(true); lwc.sendLocale(player, "protection.internalerror", "id", "BLOCK_BREAK"); e.printStackTrace(); } }
Example 18
Source File: PlayerDetails.java From NBTEditor with GNU General Public License v3.0 | 4 votes |
PlayerDetails(BlockBreakEvent event) { super(event.getPlayer().getInventory().getItemInMainHand()); _player = event.getPlayer(); }
Example 19
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); } }
Example 20
Source File: TeamBed.java From DungeonsXL with GNU General Public License v3.0 | 3 votes |
@Override public boolean onBreak(BlockBreakEvent event) { Player breaker = event.getPlayer(); if (owner.getMembers().contains(breaker)) { MessageUtil.sendMessage(breaker, DMessage.ERROR_BLOCK_OWN_TEAM.getMessage()); return true; } for (DGamePlayer player : owner.getDGamePlayers()) { player.setLives(1); } owner.setLives(0); owner.getGameWorld().sendMessage(DMessage.GROUP_BED_DESTROYED.getMessage(owner.getName(), api.getPlayerCache().getGamePlayer(breaker).getName())); Block block1 = event.getBlock(); if (DungeonsXL.BLOCK_ADAPTER.isBedHead(block)) { Block block2 = getAttachedBlock(block1); if (block2 != null) { block2.setType(VanillaItem.AIR.getMaterial()); } } block1.setType(VanillaItem.AIR.getMaterial()); return true; }