Java Code Examples for org.bukkit.block.Block#equals()
The following examples show how to use
org.bukkit.block.Block#equals() .
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: GenericSuperAxe.java From NBTEditor with GNU General Public License v3.0 | 6 votes |
private void findConnectedLogs(Block start) throws BlockLimitException { HashSet<Block> result = new HashSet<Block>(); HashSet<Block> blocks = new HashSet<Block>(); blocks.add(start); while (blocks.size() > 0) { HashSet<Block> lastBlocks = blocks; blocks = new HashSet<Block>(); for (Block block : lastBlocks) { if (!block.equals(_root)) { if (isLog(block.getType())) { if (result.add(block)) { blocks.addAll(getNeighbourBlocks(block)); checkBlockLimit(result.size()); } } else if (findGround(block)) { // Found ground, discard all and mark as grounded. _groundedBlocks.addAll(result); return; } } } } _finalSet.addAll(result); }
Example 2
Source File: RescuePlatformListener.java From BedWars with GNU Lesser General Public License v3.0 | 6 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 3
Source File: GlobalProtectionListener.java From DungeonsXL with GNU General Public License v3.0 | 6 votes |
@EventHandler public void onPlayerMove(PlayerMoveEvent event) { Player player = event.getPlayer(); if (DPlayerListener.isCitizensNPC(player)) { return; } if (!plugin.getMainConfig().isStrictMovementCheckEnabled()) { Block blockFrom = event.getFrom().getBlock(); Block blockTo = event.getTo().getBlock(); if (blockFrom.equals(blockTo)) { return; } } DPortal dPortal = DPortal.getByLocation(plugin, player.getEyeLocation()); if (dPortal == null) { return; } dPortal.teleport(player); }
Example 4
Source File: ProtectionWallListener.java From BedWars with GNU Lesser General Public License v3.0 | 5 votes |
@EventHandler public void onBlockBreak(BedwarsPlayerBreakBlock event) { final Game game = event.getGame(); final Block block = event.getBlock(); for (ProtectionWall checkedWall : getCreatedWalls(game)) { if (checkedWall != null) { for (Block wallBlock : checkedWall.getWallBlocks()) { if (wallBlock.equals(block) && !checkedWall.canBreak()) { event.setCancelled(true); } } } } }
Example 5
Source File: GenericSuperAxe.java From NBTEditor with GNU General Public License v3.0 | 5 votes |
private HashSet<Block> findSmallLogPatch(Block start) { HashSet<Block> result = new HashSet<Block>(); HashSet<Block> blocks = new HashSet<Block>(); blocks.add(start); while (blocks.size() > 0) { HashSet<Block> lastBlocks = blocks; blocks = new HashSet<Block>(); for (Block block : lastBlocks) { if (!block.equals(_root)) { if (isLog(block.getType())) { if (result.add(block)) { if (result.size() > 3) { // Found more than 3 connected log blocks. // This is not a small patch. // Here _groundedBlocks acts as a blacklist for patch blocks. _groundedBlocks.addAll(result); return new HashSet<Block>(); } blocks.add(block.getRelative(0, -1, 0)); blocks.add(block.getRelative(0, 1, 0)); blocks.add(block.getRelative(-1, 0, 0)); blocks.add(block.getRelative(1, 0, 0)); blocks.add(block.getRelative(0, 0, -1)); blocks.add(block.getRelative(0, 0, 1)); } } else if (findGround(block)) { // Found ground, this is not a disconnected patch. return new HashSet<Block>(); } } } } return result; }
Example 6
Source File: WoolObjective.java From CardinalPGM with MIT License | 5 votes |
@EventHandler(priority = EventPriority.HIGHEST) public void onPistonRetract(BlockPistonRetractEvent event) { if (!event.isCancelled()) { for (Block block : event.getBlocks()) { if (block.equals(place.getBlock()) || block.equals(place.getBlock().getRelative(event.getDirection().getOppositeFace()))) { event.setCancelled(true); } } } }
Example 7
Source File: WoolObjective.java From CardinalPGM with MIT License | 5 votes |
@EventHandler(priority = EventPriority.HIGHEST) public void onPistonPush(BlockPistonExtendEvent event) { if (!event.isCancelled()) { if (event.getBlock().getRelative(event.getDirection()).equals(place.getBlock())) { event.setCancelled(true); } else { for (Block block : event.getBlocks()) { if (block.equals(place.getBlock()) || block.equals(place.getBlock().getRelative(event.getDirection().getOppositeFace()))) { event.setCancelled(true); } } } } }
Example 8
Source File: Uncarried.java From ProjectAres with GNU Affero General Public License v3.0 | 5 votes |
@Override public void onEvent(BlockTransformEvent event) { super.onEvent(event); Block block = event.getOldState().getBlock(); Block flagBlock = this.location.getBlock(); if(block.equals(flagBlock) || block.equals(flagBlock.getRelative(BlockFace.UP))) { event.setCancelled(true, new TranslatableComponent("match.flag.cannotBreak")); } else if(block.equals(flagBlock.getRelative(BlockFace.DOWN))) { event.setCancelled(true, new TranslatableComponent("match.flag.cannotBreakBlockUnder")); } }
Example 9
Source File: ProtectionCache.java From Modern-LWC with MIT License | 5 votes |
/** * Cache a protection * * @param protection */ public void addProtection(Protection protection) { if (protection == null) { return; } counter.increment("addProtection"); // Add the hard reference references.put(protection, null); // Add weak references which are used to lookup protections byCacheKey.put(protection.getCacheKey(), protection); byId.put(protection.getId(), protection); // get the protection's finder if it was found via that if (protection.getProtectionFinder() != null) { Block protectedBlock = protection.getBlock(); for (BlockState state : protection.getProtectionFinder() .getBlocks()) { if (!protectedBlock.equals(state.getBlock())) { String cacheKey = cacheKey(state.getLocation()); byKnownBlock.put(cacheKey, protection); } } } }
Example 10
Source File: WrongBlock.java From Hawk with GNU General Public License v3.0 | 5 votes |
public void check(BlockDigEvent e) { Player p = e.getPlayer(); HawkPlayer pp = e.getHawkPlayer(); Block b = e.getBlock(); if (e.getDigAction() == BlockDigEvent.DigAction.START) { blockinteracted.put(p.getUniqueId(), e.getBlock()); } else if (e.getDigAction() == BlockDigEvent.DigAction.COMPLETE) { if ((!blockinteracted.containsKey(p.getUniqueId()) || !b.equals(blockinteracted.get(p.getUniqueId())))) { punishAndTryCancelAndBlockRespawn(pp, e); } else reward(pp); } }
Example 11
Source File: ProtectionWallListener.java From BedWars with GNU Lesser General Public License v3.0 | 5 votes |
@EventHandler public void onBlockBreak(BedwarsPlayerBreakBlock event) { final Game game = event.getGame(); final Block block = event.getBlock(); for (ProtectionWall checkedWall : getCreatedWalls(game)) { if (checkedWall != null) { for (Block wallBlock : checkedWall.getWallBlocks()) { if (wallBlock.equals(block) && !checkedWall.canBreak()) { event.setCancelled(true); } } } } }
Example 12
Source File: Uncarried.java From PGM with GNU Affero General Public License v3.0 | 5 votes |
@Override public void onEvent(BlockTransformEvent event) { super.onEvent(event); Block block = event.getOldState().getBlock(); Block flagBlock = this.location.getBlock(); if (block.equals(flagBlock) || block.equals(flagBlock.getRelative(BlockFace.UP))) { event.setCancelled(true, TranslatableComponent.of("flag.cannotBreakFlag")); } else if (block.equals(flagBlock.getRelative(BlockFace.DOWN))) { event.setCancelled(true, TranslatableComponent.of("flag.cannotBreakBlockUnder")); } }
Example 13
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 14
Source File: Game.java From BedwarsRel with GNU General Public License v3.0 | 4 votes |
public boolean handleDestroyTargetMaterial(Player p, Block block) { Team team = this.getPlayerTeam(p); if (team == null) { return false; } Team bedDestroyTeam = null; Block bedBlock = team.getHeadTarget(); if (block.getType().equals(Material.BED_BLOCK)) { Block breakBlock = block; Block neighbor = null; Bed breakBed = (Bed) breakBlock.getState().getData(); if (!breakBed.isHeadOfBed()) { neighbor = breakBlock; breakBlock = Utils.getBedNeighbor(neighbor); } else { neighbor = Utils.getBedNeighbor(breakBlock); } if (bedBlock.equals(breakBlock)) { p.sendMessage( ChatWriter .pluginMessage(ChatColor.RED + BedwarsRel._l(p, "ingame.blocks.ownbeddestroy"))); return false; } bedDestroyTeam = this.getTeamOfBed(breakBlock); if (bedDestroyTeam == null) { return false; } this.dropTargetBlock(block); } else { if (bedBlock.equals(block)) { p.sendMessage( ChatWriter .pluginMessage(ChatColor.RED + BedwarsRel._l(p, "ingame.blocks.ownbeddestroy"))); return false; } bedDestroyTeam = this.getTeamOfBed(block); if (bedDestroyTeam == null) { return false; } this.dropTargetBlock(block); } // set statistics if (BedwarsRel.getInstance().statisticsEnabled()) { PlayerStatistic statistic = BedwarsRel.getInstance().getPlayerStatisticManager() .getStatistic(p); statistic.setCurrentDestroyedBeds(statistic.getCurrentDestroyedBeds() + 1); statistic.setCurrentScore(statistic.getCurrentScore() + BedwarsRel.getInstance() .getIntConfig("statistics.scores.bed-destroy", 25)); } // reward when destroy bed if (BedwarsRel.getInstance().getBooleanConfig("rewards.enabled", false)) { List<String> commands = BedwarsRel.getInstance().getConfig().getStringList("rewards.player-destroy-bed"); BedwarsRel.getInstance() .dispatchRewardCommands(commands, ImmutableMap.of("{player}", p.getName(), "{score}", String.valueOf( BedwarsRel.getInstance().getIntConfig("statistics.scores.bed-destroy", 25)))); } BedwarsTargetBlockDestroyedEvent targetBlockDestroyedEvent = new BedwarsTargetBlockDestroyedEvent(this, p, bedDestroyTeam); BedwarsRel.getInstance().getServer().getPluginManager().callEvent(targetBlockDestroyedEvent); for (Player aPlayer : this.getPlayers()) { if (aPlayer.isOnline()) { aPlayer.sendMessage( ChatWriter.pluginMessage(ChatColor.RED + BedwarsRel ._l(aPlayer, "ingame.blocks.beddestroyed", ImmutableMap.of("team", bedDestroyTeam.getChatColor() + bedDestroyTeam.getName() + ChatColor.RED, "player", Game.getPlayerWithTeamString(p, team, ChatColor.RED))))); } } this.broadcastSound( Sound.valueOf( BedwarsRel.getInstance().getStringConfig("bed-sound", "ENDERDRAGON_GROWL") .toUpperCase()), 30.0F, 10.0F); this.updateScoreboard(); return true; }
Example 15
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 16
Source File: DPlayerListener.java From DungeonsXL with GNU General Public License v3.0 | 4 votes |
@EventHandler public void onPlayerInteract(PlayerInteractEvent event) { Player player = event.getPlayer(); if (isCitizensNPC(player)) { return; } Block clickedBlock = event.getClickedBlock(); DGameWorld gameWorld = (DGameWorld) plugin.getGameWorld(player.getWorld()); if (clickedBlock != null) { // Block Enderchests if (gameWorld != null || plugin.getEditWorld(player.getWorld()) != null) { if (event.getAction() != Action.LEFT_CLICK_BLOCK) { if (VanillaItem.ENDER_CHEST.is(clickedBlock)) { if (!DPermission.hasPermission(player, DPermission.BYPASS) && !DPermission.hasPermission(player, DPermission.ENDER_CHEST)) { MessageUtil.sendMessage(player, DMessage.ERROR_ENDERCHEST.getMessage()); event.setCancelled(true); } } else if (Category.BEDS.containsBlock(clickedBlock)) { if (!DPermission.hasPermission(player, DPermission.BYPASS) && !DPermission.hasPermission(player, DPermission.BED)) { MessageUtil.sendMessage(player, DMessage.ERROR_BED.getMessage()); event.setCancelled(true); } } } } // Block Dispensers if (gameWorld != null) { if (event.getAction() != Action.LEFT_CLICK_BLOCK) { if (VanillaItem.DISPENSER.is(clickedBlock)) { if (!DPermission.hasPermission(player, DPermission.BYPASS) && !DPermission.hasPermission(player, DPermission.DISPENSER)) { MessageUtil.sendMessage(player, DMessage.ERROR_DISPENSER.getMessage()); event.setCancelled(true); } } } for (LockedDoor door : gameWorld.getLockedDoors()) { if (clickedBlock.equals(door.getBlock()) || clickedBlock.equals(door.getAttachedBlock())) { event.setCancelled(true); return; } } } } // Check Portals if (event.getItem() != null) { ItemStack item = event.getItem(); // Copy/Paste a Sign and Block-info if (plugin.getEditWorld(player.getWorld()) != null) { if (event.getAction() == Action.RIGHT_CLICK_BLOCK) { if (VanillaItem.STICK.is(item)) { DEditPlayer editPlayer = (DEditPlayer) dPlayers.getEditPlayer(player); if (editPlayer != null) { editPlayer.poke(clickedBlock); event.setCancelled(true); } } } } } }
Example 17
Source File: ExtensionLeaderboardWall.java From HeavySpleef with GNU General Public License v3.0 | 4 votes |
@SuppressWarnings("unchecked") @EventHandler public void onPlayerInteract(PlayerInteractEvent event) { SpleefPlayer player = heavySpleef.getSpleefPlayer(event.getPlayer()); if (!player.hasPermission(Permissions.PERMISSION_STATS_OTHER)) { return; } Block block = event.getClickedBlock(); boolean isWallBlock = false; SignRow clickedRow = null; for (SignRow row : rows) { org.bukkit.util.Vector sv = row.getStart(); org.bukkit.util.Vector ev = row.getEnd(); Block start = row.getWorld().getBlockAt(sv.getBlockX(), sv.getBlockY(), sv.getBlockZ()); Block end = row.getWorld().getBlockAt(ev.getBlockX(), ev.getBlockY(), ev.getBlockZ()); Block current = start; do { if (current.equals(block)) { clickedRow = row; isWallBlock = true; break; } current = current.getRelative(row.getDirection().getBlockFace3D()); } while (!current.equals(end)); if (isWallBlock) { break; } } if (!isWallBlock) { return; } org.bukkit.util.Vector blockVec = block.getLocation().toVector(); Map<String, Object> metadata = clickedRow.getMetadata(blockVec); if (metadata == null) { return; } Entry<String, Statistic> statisticEntry = (Entry<String, Statistic>) metadata.get(METADATA_ID); if (statisticEntry == null) { player.sendMessage(i18n.getString(Messages.Command.ERROR_ON_STATISTIC_LOAD)); return; } Statistic.FullStatisticPrinter printer = new Statistic.FullStatisticPrinter(heavySpleef.getDatabaseHandler(), player.getBukkitPlayer(), statisticEntry.getKey(), heavySpleef.getLogger()); printer.print(); }