org.bukkit.event.block.BlockBreakEvent Java Examples
The following examples show how to use
org.bukkit.event.block.BlockBreakEvent.
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: BlockListener.java From Slimefun4 with GNU General Public License v3.0 | 7 votes |
private void dropItems(BlockBreakEvent e, List<ItemStack> drops) { if (!drops.isEmpty()) { e.getBlock().setType(Material.AIR); if (e.isDropItems()) { for (ItemStack drop : drops) { if (drop != null && drop.getType() != Material.AIR) { e.getBlock().getWorld().dropItemNaturally(e.getBlock().getLocation(), drop); } } } } }
Example #2
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 #3
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 #4
Source File: LobbyListener.java From SkyWarsReloaded with GNU General Public License v3.0 | 6 votes |
@EventHandler public void signRemoved(BlockBreakEvent event) { if (Util.get().isSpawnWorld(event.getBlock().getWorld())) { Location blockLocation = event.getBlock().getLocation(); World w = blockLocation.getWorld(); Block b = w.getBlockAt(blockLocation); if(b.getType() == Material.WALL_SIGN || b.getType() == SkyWarsReloaded.getNMS().getMaterial("SIGN_POST").getType()){ Sign sign = (Sign) b.getState(); Location loc = sign.getLocation(); boolean removed = false; for (GameMap gMap : GameMap.getMaps()) { if (!removed) { removed = gMap.removeSign(loc); } } if (!removed) { removed = SkyWarsReloaded.getLB().removeLeaderSign(loc); } if (removed) { event.getPlayer().sendMessage(new Messaging.MessageFormatter().format("signs.remove")); } } } }
Example #5
Source File: ProtectionsTests.java From Civs with GNU General Public License v3.0 | 6 votes |
@Test public void blockBreakInProtectionShouldBeCancelled() { RegionsTests.loadRegionTypeCobble(); Player player = mock(Player.class); when(player.getGameMode()).thenReturn(GameMode.SURVIVAL); UUID uuid = new UUID(1, 2); when(player.getUniqueId()).thenReturn(uuid); Player player2 = mock(Player.class); when(player2.getGameMode()).thenReturn(GameMode.SURVIVAL); UUID uuid2 = new UUID(1, 3); when(player2.getUniqueId()).thenReturn(uuid2); HashMap<UUID, String> owners = new HashMap<>(); owners.put(uuid2, Constants.OWNER); Location regionLocation = new Location(Bukkit.getWorld("world"), 0,0,0); HashMap<String, String> effects = new HashMap<>(); effects.put("block_break", null); effects.put("block_build", null); RegionManager.getInstance().addRegion(new Region("cobble", owners, regionLocation, RegionsTests.getRadii(), effects,0)); ProtectionHandler protectionHandler = new ProtectionHandler(); BlockBreakEvent event = new BlockBreakEvent(TestUtil.block3, player); protectionHandler.onBlockBreak(event); assertTrue(event.isCancelled()); }
Example #6
Source File: IslandGuard.java From askyblock with GNU General Public License v2.0 | 6 votes |
/** * Prevents blocks from being broken * * @param e - event */ @EventHandler(priority = EventPriority.LOW, ignoreCancelled = true) public void onBlockBreak(final BlockBreakEvent e) { if (DEBUG) { plugin.getLogger().info(e.getEventName()); } if (Settings.allowedFakePlayers.contains(e.getPlayer().getName())) return; if (inWorld(e.getPlayer())) { if (actionAllowed(e.getPlayer(), e.getBlock().getLocation(), SettingsFlag.BREAK_BLOCKS)) { return; } // Everyone else - not allowed Util.sendMessage(e.getPlayer(), ChatColor.RED + plugin.myLocale(e.getPlayer().getUniqueId()).islandProtected); e.setCancelled(true); } }
Example #7
Source File: RegionsTests.java From Civs with GNU General Public License v3.0 | 6 votes |
@Test public void regionShouldBeDestroyedAndRebuilt() { loadRegionTypeCobble(); HashMap<UUID, String> owners = new HashMap<>(); UUID uuid = new UUID(1, 4); owners.put(uuid, Constants.OWNER); Location location1 = new Location(Bukkit.getWorld("world"), 4, 0, 0); RegionManager.getInstance().addRegion(new Region("cobble", owners, location1, getRadii(), new HashMap<>(),0)); BlockBreakEvent event = new BlockBreakEvent(TestUtil.blockUnique, TestUtil.player); CivilianListener civilianListener = new CivilianListener(); civilianListener.onCivilianBlockBreak(event); ProtectionHandler protectionHandler = new ProtectionHandler(); protectionHandler.onBlockBreak(event); BlockPlaceEvent event1 = mock(BlockPlaceEvent.class); Block block2 = TestUtil.createUniqueBlock(Material.CHEST, "Civs cobble", location1, false); when(event1.getBlockPlaced()).thenReturn(block2); ItemStack itemStack = TestUtil.createUniqueItemStack(Material.CHEST, "Civs Cobble"); when(event1.getItemInHand()).thenReturn(itemStack); when(event1.getPlayer()).thenReturn(TestUtil.player); RegionListener regionListener = new RegionListener(); regionListener.onBlockPlace(event1); assertNotNull(RegionManager.getInstance().getRegionAt(location1)); }
Example #8
Source File: BlockObjective.java From BetonQuest with GNU General Public License v3.0 | 6 votes |
@EventHandler(ignoreCancelled = true) public void onBlockBreak(BlockBreakEvent event) { String playerID = PlayerConverter.getID(event.getPlayer()); // if the player has this objective, the event isn't canceled, // the block is correct and conditions are met if (containsPlayer(playerID) && selector.match(event.getBlock()) && checkConditions(playerID)) { // remove the block from the total amount BlockData playerData = (BlockData) dataMap.get(playerID); playerData.remove(); // complete the objective if (playerData.getAmount() == neededAmount) { completeObjective(playerID); } else if (notify && playerData.getAmount() % notifyInterval == 0) { // or maybe display a notification if (playerData.getAmount() > neededAmount) { Config.sendNotify(playerID, "blocks_to_break", new String[]{String.valueOf(playerData.getAmount() - neededAmount)}, "blocks_to_break,info"); } else { Config.sendNotify(playerID, "blocks_to_place", new String[]{String.valueOf(neededAmount - playerData.getAmount())}, "blocks_to_place,info"); } } } }
Example #9
Source File: EffCancelDrops.java From Skript with GNU General Public License v3.0 | 6 votes |
@Override public boolean init(Expression<?>[] exprs, int matchedPattern, Kleenean isDelayed, ParseResult parseResult) { cancelItems = parseResult.mark == 0 || parseResult.mark == 1; cancelExps = parseResult.mark == 0 || parseResult.mark == 2; if (ScriptLoader.isCurrentEvent(BlockBreakEvent.class)) { if (cancelItems && !CAN_CANCEL_BLOCK_ITEM_DROPS) { Skript.error("Cancelling drops of items in a block break event requires Minecraft 1.12 or newer"); return false; } } else if (!ScriptLoader.isCurrentEvent(EntityDeathEvent.class)) { Skript.error("The cancel drops effect can't be used outside of a death" + (CAN_CANCEL_BLOCK_ITEM_DROPS ? " or block break" : "") + " event"); return false; } if (isDelayed.isTrue()) { Skript.error("Can't cancel the drops anymore after the event has already passed"); return false; } return true; }
Example #10
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 #11
Source File: BlockListener.java From Carbon with GNU Lesser General Public License v3.0 | 6 votes |
@EventHandler(priority = EventPriority.MONITOR, ignoreCancelled = true) public void onIndirectDoorBreak(BlockBreakEvent event) { if (event.getBlock().getType().toString().contains("DOOR")) return; Material mat = event.getBlock().getRelative(BlockFace.UP).getType(); if (mat == Carbon.injector().spruceDoorBlockMat) event.getBlock().getWorld().dropItemNaturally(event.getBlock().getRelative(BlockFace.UP).getLocation(), new ItemStack(Carbon.injector().spruceDoorMat, 1)); else if (mat == Carbon.injector().birchDoorBlockMat) event.getBlock().getWorld().dropItemNaturally(event.getBlock().getRelative(BlockFace.UP).getLocation(), new ItemStack(Carbon.injector().birchDoorMat, 1)); else if (mat == Carbon.injector().jungleDoorBlockMat) event.getBlock().getWorld().dropItemNaturally(event.getBlock().getRelative(BlockFace.UP).getLocation(), new ItemStack(Carbon.injector().jungleDoorMat, 1)); else if (mat == Carbon.injector().acaciaDoorBlockMat) event.getBlock().getWorld().dropItemNaturally(event.getBlock().getRelative(BlockFace.UP).getLocation(), new ItemStack(Carbon.injector().acaciaDoorMat, 1)); else if (mat == Carbon.injector().darkOakDoorBlockMat) event.getBlock().getWorld().dropItemNaturally(event.getBlock().getRelative(BlockFace.UP).getLocation(), new ItemStack(Carbon.injector().darkOakDoorMat, 1)); }
Example #12
Source File: DoubleGoldListener.java From UhcCore with GNU General Public License v3.0 | 6 votes |
@EventHandler public void onBlockBreak(BlockBreakEvent e) { if (isActivated(Scenario.CUTCLEAN) || isActivated(Scenario.TRIPLEORES) || isActivated(Scenario.VEINMINER)){ return; } Block block = e.getBlock(); Location loc = e.getBlock().getLocation().add(0.5, 0, 0.5); if (block.getType() == Material.GOLD_ORE){ block.setType(Material.AIR); loc.getWorld().dropItem(loc,new ItemStack(Material.GOLD_INGOT, 2)); UhcItems.spawnExtraXp(loc,6); } }
Example #13
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 #14
Source File: SignBreak.java From WildernessTp with MIT License | 6 votes |
@EventHandler public void BlockBreakEvent(BlockBreakEvent e) { String noPerm = wild.getConfig().getString("No-Break"); if (e.getBlock().getState() instanceof Sign) { Sign sign = (Sign) e.getBlock().getState(); if (sign.getLine(0).equalsIgnoreCase("§4====================") && sign.getLine(1).equalsIgnoreCase("[§1Wild§0]") && sign.getLine(2).equalsIgnoreCase("§4====================")) { if (!e.getPlayer().hasPermission("wild.wildtp.break.sign")) { e.getPlayer().sendMessage(ChatColor.translateAlternateColorCodes( '&', noPerm)); e.setCancelled(true); } else { e.getPlayer().sendMessage(ChatColor.GREEN + "You have broken a wildtp sign"); } } } }
Example #15
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 #16
Source File: SignManager.java From factions-top with MIT License | 6 votes |
@EventHandler(priority = EventPriority.HIGH, ignoreCancelled = true) public void unregisterSign(BlockBreakEvent event) { // Do nothing if block is not a registered sign. BlockPos pos = BlockPos.of(event.getBlock()); if (!signs.containsValue(pos)) { return; } if (!(event.getBlock().getState() instanceof Sign)) { removeSign(pos); return; } if (!event.getPlayer().hasPermission("factionstop.sign.break")) { event.getPlayer().sendMessage(plugin.getSettings().getPermissionMessage()); event.setCancelled(true); return; } removeSign(pos); }
Example #17
Source File: TreeVaporizer.java From NBTEditor with GNU General Public License v3.0 | 6 votes |
@Override public void onBlockBreak(BlockBreakEvent event, PlayerDetails details) { Block root = event.getBlock(); if (isLog(root.getType())) { // Find the blocks Set<Block> blocks = getTreeBlocks(root); if (blocks.size() > 0) { root.getWorld().playSound(root.getLocation(), Sound.ENTITY_ZOMBIE_BREAK_WOODEN_DOOR, 0.5f, 1); } // Destroy them. for (Block block : blocks) { block.breakNaturally(); } // Apply durability. if (event.getPlayer().getGameMode() != GameMode.CREATIVE) { UtilsMc.offsetItemStackDamage(details.getItem(), blocks.size()); } } }
Example #18
Source File: PlayerEvents.java From uSkyBlock with GNU General Public License v3.0 | 6 votes |
@EventHandler(priority = EventPriority.LOW, ignoreCancelled = true) public void onLeafBreak(BlockBreakEvent event) { if (!plugin.getWorldManager().isSkyWorld(event.getPlayer().getWorld())) { return; } if (event.getBlock().getType() != Material.OAK_LEAVES || (event.getBlock().getData() & 0x3) != 0) { return; } // Ok, a player broke an OAK LEAF in the Skyworld String islandName = WorldGuardHandler.getIslandNameAt(event.getPlayer().getLocation()); IslandInfo islandInfo = plugin.getIslandInfo(islandName); if (islandInfo != null && islandInfo.getLeafBreaks() == 0) { // Add an oak-sapling event.getBlock().getWorld().dropItemNaturally(event.getBlock().getLocation(), new ItemStack(Material.OAK_SAPLING, 1)); islandInfo.setLeafBreaks(islandInfo.getLeafBreaks() + 1); } }
Example #19
Source File: CEListener.java From ce with GNU Lesser General Public License v3.0 | 6 votes |
@EventHandler(priority = EventPriority.HIGHEST, ignoreCancelled = true) public void BlockBreakEvent(BlockBreakEvent e) { if (e.getBlock().hasMetadata("ce.Ice")) e.setCancelled(true); CEventHandler.handleEvent(e.getPlayer(), e, blockBroken); if (e.getBlock().hasMetadata("ce.mine")) { Block b = e.getBlock(); b.removeMetadata("ce.mine", Main.plugin); Block[] blocks = { b.getRelative(0, 1, 0), b.getRelative(1, 0, 0), b.getRelative(-1, 0, 0), b.getRelative(0, 0, 1), b.getRelative(0, 0, -1) }; for (Block block : blocks) { if (block.hasMetadata("ce.mine.secondary")) { String[] s = block.getMetadata("ce.mine.secondary").get(0).asString().split(" "); Location loc = new Location(e.getPlayer().getWorld(), Integer.parseInt(s[0]), Integer.parseInt(s[1]), Integer.parseInt(s[2])); Location blockLoc = b.getLocation(); if (loc.getBlockX() == blockLoc.getBlockX() && loc.getBlockY() == blockLoc.getBlockY() && loc.getBlockZ() == blockLoc.getBlockZ()) block.removeMetadata("ce.mine.secondary", Main.plugin); } } } }
Example #20
Source File: TalismanListener.java From Slimefun4 with GNU General Public License v3.0 | 6 votes |
@EventHandler(priority = EventPriority.MONITOR, ignoreCancelled = true) public void onBlockBreak(BlockBreakEvent e) { ItemStack item = e.getPlayer().getInventory().getItemInMainHand(); if (item.getType() != Material.AIR && item.getAmount() > 0) { List<ItemStack> drops = new ArrayList<>(e.getBlock().getDrops(item)); int dropAmount = 1; if (item.getEnchantments().containsKey(Enchantment.LOOT_BONUS_BLOCKS) && !item.getEnchantments().containsKey(Enchantment.SILK_TOUCH)) { Random random = ThreadLocalRandom.current(); dropAmount = random.nextInt(item.getEnchantmentLevel(Enchantment.LOOT_BONUS_BLOCKS) + 2) - 1; dropAmount = Math.max(dropAmount, 1); dropAmount = (e.getBlock().getType() == Material.LAPIS_ORE ? 4 + random.nextInt(5) : 1) * (dropAmount + 1); } if (!item.getEnchantments().containsKey(Enchantment.SILK_TOUCH) && MaterialCollections.getAllOres().contains(e.getBlock().getType()) && Talisman.checkFor(e, SlimefunItems.TALISMAN_MINER)) { for (ItemStack drop : drops) { if (!drop.getType().isBlock()) { int amount = Math.max(1, (dropAmount * 2) - drop.getAmount()); e.getBlock().getWorld().dropItemNaturally(e.getBlock().getLocation(), new CustomItem(drop, amount)); } } } } }
Example #21
Source File: BlockListeners.java From CratesPlus with GNU General Public License v3.0 | 5 votes |
@EventHandler(ignoreCancelled = true) public void onBlockBreak(BlockBreakEvent event) { if (event.getBlock().getMetadata("CrateType") == null || event.getBlock().getMetadata("CrateType").isEmpty()) { return; } String crateType = event.getBlock().getMetadata("CrateType").get(0).asString(); Crate crate = cratesPlus.getConfigHandler().getCrates().get(crateType.toLowerCase()); if (crate == null) // TODO Better handling of crates removed from the config return; if (!(crate instanceof KeyCrate)) { return; } KeyCrate keyCrate = (KeyCrate) crate; Location location = event.getBlock().getLocation(); if (event.getPlayer().isSneaking() && (cratesPlus.getConfig().getBoolean("Crate Protection") && !event.getPlayer().hasPermission("cratesplus.admin"))) { event.getPlayer().sendMessage(cratesPlus.getPluginPrefix() + ChatColor.RED + "You do not have permission to remove this crate"); event.setCancelled(true); return; } else if (!event.getPlayer().isSneaking()) { event.getPlayer().sendMessage(cratesPlus.getPluginPrefix() + ChatColor.RED + "Sneak to break crates"); event.setCancelled(true); return; } location.getBlock().removeMetadata("CrateType", cratesPlus); keyCrate.removeFromConfig(location); keyCrate.removeHolograms(location.getBlock().getLocation()); }
Example #22
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 #23
Source File: CutCleanListener.java From UhcCore with GNU General Public License v3.0 | 5 votes |
@EventHandler (priority = EventPriority.HIGH) public void onBlockBreak(BlockBreakEvent e){ if (isActivated(Scenario.TRIPLEORES) || (isActivated(Scenario.VEINMINER) && e.getPlayer().isSneaking())){ return; } Block block = e.getBlock(); if (checkTool && !UniversalMaterial.isCorrectTool(block.getType(), e.getPlayer().getItemInHand().getType())){ return; } Location loc = e.getBlock().getLocation().add(0.5, 0, 0.5); switch (block.getType()){ case IRON_ORE: block.setType(Material.AIR); loc.getWorld().dropItem(loc,new ItemStack(Material.IRON_INGOT)); UhcItems.spawnExtraXp(loc,2); break; case GOLD_ORE: block.setType(Material.AIR); loc.getWorld().dropItem(loc,new ItemStack(Material.GOLD_INGOT)); if (isActivated(Scenario.DOUBLEGOLD)){ loc.getWorld().dropItem(loc,new ItemStack(Material.GOLD_INGOT)); } UhcItems.spawnExtraXp(loc,3); break; case SAND: block.setType(Material.AIR); loc.getWorld().dropItem(loc,new ItemStack(Material.GLASS)); break; case GRAVEL: block.setType(Material.AIR); loc.getWorld().dropItem(loc,new ItemStack(Material.FLINT)); break; } }
Example #24
Source File: CustomItemListener.java From NBTEditor with GNU General Public License v3.0 | 5 votes |
@EventHandler private void playerInteract(BlockBreakEvent event) { ItemStack item = event.getPlayer().getInventory().getItemInMainHand(); CustomItem customItem = CustomItemManager.getCustomItem(item); if (customItem != null) { if (verifyCustomItem(customItem, event.getPlayer(), false)) { customItem.onBlockBreak(event, new PlayerDetails(event)); } else { event.setCancelled(true); } } }
Example #25
Source File: TripleOresListener.java From UhcCore with GNU General Public License v3.0 | 5 votes |
@EventHandler public void onBlockBreak(BlockBreakEvent e) { if (isActivated(Scenario.VEINMINER)) { return; } Block block = e.getBlock(); Location loc = e.getBlock().getLocation().add(0.5, 0, 0.5); switch (block.getType()) { case IRON_ORE: block.setType(Material.AIR); loc.getWorld().dropItem(loc, new ItemStack(Material.IRON_INGOT,3)); UhcItems.spawnExtraXp(loc,2); break; case GOLD_ORE: block.setType(Material.AIR); loc.getWorld().dropItem(loc, new ItemStack(Material.GOLD_INGOT,3)); if (isActivated(Scenario.DOUBLEGOLD)){ loc.getWorld().dropItem(loc, new ItemStack(Material.GOLD_INGOT,3)); } UhcItems.spawnExtraXp(loc,3); break; case DIAMOND_ORE: block.setType(Material.AIR); loc.getWorld().dropItem(loc, new ItemStack(Material.DIAMOND,3)); UhcItems.spawnExtraXp(loc,4); break; case SAND: block.setType(Material.AIR); loc.getWorld().dropItem(loc, new ItemStack(Material.GLASS)); break; case GRAVEL: block.setType(Material.AIR); loc.getWorld().dropItem(loc,new ItemStack(Material.FLINT)); break; } }
Example #26
Source File: HerculesPickaxe.java From Slimefun4 with GNU General Public License v3.0 | 5 votes |
@Override public BlockBreakHandler getItemHandler() { return new BlockBreakHandler() { @Override public boolean isPrivate() { return false; } @Override public boolean onBlockBreak(BlockBreakEvent e, ItemStack item, int fortune, List<ItemStack> drops) { if (e.getBlock().getType().toString().endsWith("_ORE") && isItem(item)) { if (!Slimefun.hasUnlocked(e.getPlayer(), HerculesPickaxe.this, true)) { return true; } if (e.getBlock().getType() == Material.IRON_ORE) { drops.add(new CustomItem(SlimefunItems.IRON_DUST, 2)); } else if (e.getBlock().getType() == Material.GOLD_ORE) { drops.add(new CustomItem(SlimefunItems.GOLD_DUST, 2)); } else { for (ItemStack drop : e.getBlock().getDrops(getItem())) { drops.add(new CustomItem(drop, drop.getAmount() * 2)); } } return true; } else return false; } }; }
Example #27
Source File: FreeBuildRegion.java From FastAsyncWorldedit with GNU General Public License v3.0 | 5 votes |
public FreeBuildRegion() { super("freebuild"); this.listeners = new ArrayList<>(); RegisteredListener[] listeners = BlockBreakEvent.getHandlerList().getRegisteredListeners(); for (RegisteredListener listener : listeners) { if (listener.getPriority() == EventPriority.MONITOR) continue; if (!listener.isIgnoringCancelled()) continue; this.listeners.add(listener); } }
Example #28
Source File: ProtectionsTests.java From Civs with GNU General Public License v3.0 | 5 votes |
@Test public void blockBreakInProtectionShouldNotBeCancelled() { ProtectionHandler protectionHandler = new ProtectionHandler(); Player player = mock(Player.class); BlockBreakEvent event = new BlockBreakEvent(block, player); protectionHandler.onBlockBreak(event); assertFalse(event.isCancelled()); }
Example #29
Source File: RegionsTests.java From Civs with GNU General Public License v3.0 | 5 votes |
@Test public void offCenterRegionShouldDestroy() { loadRegionTypeCobbleQuarry(); HashMap<UUID, String> owners = new HashMap<>(); owners.put(new UUID(1, 6), Constants.OWNER); Location location1 = new Location(Bukkit.getWorld("world"), 300, 100, 0); Region region = new Region("cobblequarry", owners, location1, getRadii(9,5,7,7,7,7), new HashMap<>(),0); RegionManager.getInstance().addRegion(region); BlockBreakEvent blockBreakEvent = new BlockBreakEvent(TestUtil.blockUnique8, TestUtil.player); ProtectionHandler protectionHandler = new ProtectionHandler(); protectionHandler.onBlockBreak(blockBreakEvent); assertNull(RegionManager.getInstance().getRegionAt(location1)); }
Example #30
Source File: Areas.java From AnnihilationPro with MIT License | 5 votes |
@EventHandler(priority = EventPriority.LOWEST,ignoreCancelled = true) public void checkBreaks(BlockBreakEvent e) { if(e.getPlayer().getGameMode() != GameMode.CREATIVE) { Area a = this.getArea(new Loc(e.getBlock().getLocation(),false)); if(a != null) { e.setCancelled(true); } } }