Java Code Examples for org.bukkit.event.block.BlockBreakEvent

The following are top voted examples for showing how to use org.bukkit.event.block.BlockBreakEvent. These examples are extracted from open source projects. You can vote up the examples you like and your votes will be used in our system to generate more good examples.
Example 1
Project: bskyblock   File: NetherEvents.java   View source code 7 votes vote down vote up
/**
 * Prevents blocks from being broken
 *
 * @param e
 */
@EventHandler(priority = EventPriority.LOW)
public void onBlockBreak(final BlockBreakEvent e) {
    if (DEBUG)
        plugin.getLogger().info("DEBUG: " + e.getEventName());
    // plugin.getLogger().info("Block break");
    if ((e.getPlayer().getWorld().getName().equalsIgnoreCase(Settings.worldName + "_nether") && !Settings.netherIslands)
            || e.getPlayer().getWorld().getName().equalsIgnoreCase(Settings.worldName + "_the_end")) {
        if (VaultHelper.hasPerm(e.getPlayer(), Settings.PERMPREFIX + "mod.bypassprotect")) {
            return;
        }
        if (DEBUG)
            plugin.getLogger().info("Block break in island nether");
        if (!awayFromSpawn(e.getPlayer()) && !e.getPlayer().isOp()) {
            Util.sendMessage(e.getPlayer(), plugin.getLocale(e.getPlayer().getUniqueId()).get("nether.spawnisprotected"));
            e.setCancelled(true);
        }
    }

}
 
Example 2
Project: HCFCore   File: DeathSignListener.java   View source code 7 votes vote down vote up
@EventHandler(ignoreCancelled = true, priority = EventPriority.HIGHEST)
public void onBlockBreak(BlockBreakEvent event) {
    Block block = event.getBlock();
    if (isDeathSign(block)) {
        BlockState state = block.getState();
        Sign sign = (Sign) state;
        ItemStack stack = new ItemStack(Material.SIGN, 1);
        ItemMeta meta = stack.getItemMeta();
        meta.setDisplayName(DEATH_SIGN_ITEM_NAME);
        meta.setLore(Arrays.asList(sign.getLines()));
        stack.setItemMeta(meta);

        Player player = event.getPlayer();
        World world = player.getWorld();
        if (player.getGameMode() != GameMode.CREATIVE && world.isGameRule("doTileDrops")) {
            world.dropItemNaturally(block.getLocation(), stack);
        }

        // Manually handle the dropping
        event.setCancelled(true);
        block.setType(Material.AIR);
        state.update();
    }
}
 
Example 3
Project: CropControl   File: CropControlEventHandler.java   View source code 6 votes vote down vote up
/**
 * So far specifically handles these cases:
 * 
 * 1) Block broken is tracked
 * 2) Block breaks by not-players
 * 3) Block breaks by players
 * 4) Indirect block breaks -- destroying block supporting a crop or collapsible tree, or under mushrooms
 * 5) Indirect block break of cocoa bearing logs
 * 6) Block broken had mushroom on top and cocoa on the sides
 * 
 * @param e The event
 */
@EventHandler(priority=EventPriority.HIGHEST, ignoreCancelled = true)
public void onBlockBreak(BlockBreakEvent e) {
	Block block = e.getBlock();
	Player player = e.getPlayer();
	BreakType type = player != null ? BreakType.PLAYER : BreakType.NATURAL;
	UUID uuid = player != null ? player.getUniqueId() : null;
	if (maybeSideTracked(block)) {
		trySideBreak(block, type, uuid);
	}
	if (maybeBelowTracked(block)) {
		block = block.getRelative(BlockFace.UP);
	}
	Location loc = block.getLocation();
	if (!pendingChecks.contains(loc)) {
		pendingChecks.add(loc);
		handleBreak(block, type, uuid, null);
	}
}
 
Example 4
Project: Warzone   File: BuildFilterType.java   View source code 6 votes vote down vote up
@EventHandler
public void onBlockBreak(BlockBreakEvent event) {
    for (Region region : regions) {
        if (region.contains(event.getBlock().getLocation())) {
            for (MatchTeam matchTeam : teams) {
                if (matchTeam.containsPlayer(event.getPlayer())) {
                    FilterResult filterResult = evaluator.evaluate(event.getPlayer());
                    if (filterResult == FilterResult.DENY) {
                        event.setCancelled(true);
                        event.getPlayer().sendMessage(message);
                    } else if (filterResult == FilterResult.ALLOW) {
                        event.setCancelled(false);
                    }
                }
            }
        }
    }
}
 
Example 5
Project: Slimefun4-Chinese-Version   File: TalismanListener.java   View source code 6 votes vote down vote up
/**
 *
 * @param e BlockBreakEvent
 * @since 4.2.0
 */
@EventHandler
public void onBlockBreak(BlockBreakEvent e) {
	List<ItemStack> drops = new ArrayList<ItemStack>();
	ItemStack item = e.getPlayer().getInventory().getItemInMainHand();
	int fortune = 1;

	if (item != null) {
		if (item.getEnchantments().containsKey(Enchantment.LOOT_BONUS_BLOCKS) && !item.getEnchantments().containsKey(Enchantment.SILK_TOUCH)) {
			fortune = SlimefunStartup.randomize(item.getEnchantmentLevel(Enchantment.LOOT_BONUS_BLOCKS) + 2) - 1;
			if (fortune <= 0) fortune = 1;
			fortune = (e.getBlock().getType() == Material.LAPIS_ORE ? 4 + SlimefunStartup.randomize(5) : 1) * (fortune + 1);
		}

		if (!item.getEnchantments().containsKey(Enchantment.SILK_TOUCH) && e.getBlock().getType().toString().endsWith("_ORE")) {
			if (Talisman.checkFor(e, SlimefunItem.getByID("MINER_TALISMAN"))) {
				if (drops.isEmpty()) drops = (List<ItemStack>) e.getBlock().getDrops();
				for (ItemStack drop : new ArrayList<ItemStack>(drops)) {
					if (!drop.getType().isBlock()) drops.add(new CustomItem(drop, fortune * 2));
				}
			}
		}
	}
}
 
Example 6
Project: SuperiorCraft   File: CustomBlock.java   View source code 6 votes vote down vote up
public void removeBlock(BlockBreakEvent e) {
		for (Entity en : e.getBlock().getWorld().getEntities()) {
			if (en.getCustomName() != null && en.getCustomName().equals(getName()) && en.getLocation().add(-0.5, 0, -0.5).equals(e.getBlock().getLocation())) {
				en.remove();
				en.getWorld().getBlockAt(en.getLocation().add(-0.5, 0, -0.5)).setType(Material.AIR);
				
				ItemStack block = new ItemStack(Material.MONSTER_EGG, 1);
				
				ItemMeta bmeta = block.getItemMeta();
				
				bmeta.setDisplayName(name);
				
				block.setItemMeta(bmeta);
				
				if (e.getPlayer() != null && e.getPlayer().getGameMode().equals(GameMode.CREATIVE)) {
					e.getPlayer().getInventory().addItem(block);
				} else {
					e.getBlock().getWorld().dropItemNaturally(en.getLocation().add(-0.5, 0, -0.5), block);
				}
			}
		}
	//}
}
 
Example 7
Project: SuperiorCraft   File: CustomTexturedBlock.java   View source code 6 votes vote down vote up
@Override
public void removeBlock(BlockBreakEvent e) {
		if (e.getPlayer() == null) {return;}
		for (Entity en : e.getPlayer().getNearbyEntities(10, 10, 10)) {
			System.out.println("Removal has Begun");
			if (en.getCustomName() != null && en.getCustomName().equals(getName()) && /*en.getLocation().add(-0.5, 0, -0.5).equals(e.getBlock().getLocation())*/ en.getLocation().distance(e.getBlock().getLocation()) < 2) {
				for (Entity ent : en.getNearbyEntities(0.5, 0.5, 0.5)) {
					if (ent.getCustomName().equals("CustomBlock")) {
						ent.remove();
						break;
					}
				}
				en.remove();
				//en.getWorld().getBlockAt(en.getLocation().add(-0.5, 0, -0.5)).setType(Material.AIR);
				if (e.getPlayer() != null && e.getPlayer().getGameMode().equals(GameMode.CREATIVE)) {
					e.getPlayer().getInventory().addItem(getItem());
				} else {
					e.getBlock().getWorld().dropItemNaturally(en.getLocation().add(-0.5, 0, -0.5), getItem());
				}
				
				return;
			}
		}
}
 
Example 8
Project: SurvivalPlus   File: Chairs.java   View source code 6 votes vote down vote up
@EventHandler(priority = EventPriority.HIGHEST)
public void onBlockBreak(BlockBreakEvent event)
{
	if(event.isCancelled()) return;
	if(Survival.allowedBlocks.contains(event.getBlock().getType()))
	{
		ArmorStand drop = dropSeat(event.getBlock(), (Stairs)event.getBlock().getState().getData());
		
		for(Entity e : drop.getNearbyEntities(0.5, 0.5, 0.5))
		{
			if(e != null && e instanceof ArmorStand && e.getCustomName() == "Chair")
				e.remove();
		}
		
		drop.remove();
	}
}
 
Example 9
Project: Stats4   File: BlockBreakStat.java   View source code 6 votes vote down vote up
@EventHandler
private void onBlockBreak(final BlockBreakEvent event) {
    Material material = event.getBlock().getType();
    byte data = event.getBlock().getData();
    ItemStack mainHandItem = event.getPlayer().getInventory().getItemInMainHand();
    DatabaseQueryWorker.getInstance().submit(() -> {
        try {
            BlockBreakDAO.storeRecord(
                    event.getPlayer().getUniqueId(), event.getPlayer().getType().name(),
                    material, data,
                    event.getBlock().getLocation(), mainHandItem
            );
        } catch (SQLException e) {
            e.printStackTrace();
        }
    });
}
 
Example 10
Project: mczone   File: KitEvents.java   View source code 6 votes vote down vote up
@EventHandler
public void Woodcutter(BlockBreakEvent event) {
	if (State.PRE)
		return;

	Player p = event.getPlayer();
	if (Kit.getKit(p).getName().equalsIgnoreCase("woodcutter")
			&& event.getBlock().getType().equals(Material.LOG)
			&& (p.getItemInHand().getType().toString().contains("AXE"))) {
		for (int i = 0; i <= 50; i++) {
			Location loc = event.getBlock().getLocation();
			loc.setY(loc.getY() + i);
			if (loc.getBlock().getType().equals(Material.LOG))
				loc.getBlock().breakNaturally();
			else
				break;
		}
	}
}
 
Example 11
Project: HCFCore   File: GlowstoneListener.java   View source code 6 votes vote down vote up
@EventHandler
public void onBlockBreak(BlockBreakEvent e) {
	Player p = e.getPlayer();
	Faction faction = hcf.getFactionManager().getFactionAt(e.getBlock());
	if(e.getBlock().getType().equals(Material.GLOWSTONE) && e.getBlock().getLocation().getWorld().getName().equalsIgnoreCase("world_nether")) {
		if(faction.getName().equalsIgnoreCase("GlowstoneMountain")) {
			e.setCancelled(true);
			e.getBlock().setType(Material.BEDROCK);
			Bukkit.getScheduler().scheduleSyncDelayedTask(hcf, new Runnable() {
				public void run() {
					if(e.getBlock().getType().equals(Material.BEDROCK)) {
						e.getBlock().setType(Material.GLOWSTONE);
					}
				}
			}, 20L*60L*10L);
			p.getInventory().addItem(new ItemStack(Material.GLOWSTONE));
		}
	}
}
 
Example 12
Project: Mega-Walls   File: BlockBreakListener.java   View source code 6 votes vote down vote up
@EventHandler
public void onBlockBreak(BlockBreakEvent e)
{
    User user = MWAPI.getUserHandler().findById(e.getPlayer().getUniqueId());

    if (user.getGame() != null)
    {
        if (user.getGame().getSpectators().contains(user) || user.getGame().getState().equals(GameState.LOBBY))
        {
            e.setCancelled(true);
            return;
        }

        // TODO handle other stuff like the castles and walls
    }
}
 
Example 13
Project: ArchersBattle   File: WorldListener.java   View source code 6 votes vote down vote up
@EventHandler
public void onBreak(BlockBreakEvent e) {
    if (e.isCancelled()) {
        return;
    }
    if (!Utils.isInArena(e.getPlayer())) {
        return;
    }
    if (!Utils.isArenaWorld(e.getBlock().getWorld())) {
        return;
    }
    if (e.getPlayer().isOp()) {
        return;
    }
    e.setCancelled(true);
}
 
Example 14
Project: SurvivalAPI   File: PersonalBlocksModule.java   View source code 6 votes vote down vote up
/**
 * Private block breaking handling
 *
 * @param event Event
 */
@EventHandler(ignoreCancelled = true, priority = EventPriority.HIGH)
public void onBlockBreak(BlockBreakEvent event)
{
    if (this.blocksOwner.containsKey(event.getBlock().getLocation()) && this.blocksOwner.get(event.getBlock().getLocation()) != event.getPlayer().getUniqueId())
    {
        UUID id = this.blocksOwner.get(event.getBlock().getLocation());

        if (id == null || id.equals(event.getPlayer().getUniqueId()) || (this.game instanceof SurvivalTeamGame && ((SurvivalTeamGame) this.game).getPlayerTeam(id) == ((SurvivalTeamGame) this.game).getPlayerTeam(event.getPlayer().getUniqueId())))
        {
            this.blocksOwner.remove(event.getBlock().getLocation());
        }
        else if (!this.game.isPvPActivated())
        {
            event.getPlayer().sendMessage(ChatColor.RED + "Ce bloc appartient à " + Bukkit.getOfflinePlayer(this.blocksOwner.get(event.getBlock().getLocation())).getName()  + ". Vous ne pouvez pas le casser actuellement !");
            event.setCancelled(true);
        }
    }
}
 
Example 15
Project: SurvivalAPI   File: ParanoidModule.java   View source code 6 votes vote down vote up
/**
 * Write a message when a player mine a diamond
 *
 * @param event Event
 */
@EventHandler(ignoreCancelled = true)
public void onBlockBreak(BlockBreakEvent event)
{
    if (event.getBlock().getType() != Material.DIAMOND_ORE)
        return;

    Location location = event.getBlock().getLocation();

    StringBuilder builder = new StringBuilder();
    builder.append(ChatColor.GOLD).append("[").append(ChatColor.YELLOW);
    builder.append("Paranoïa");
    builder.append(ChatColor.GOLD).append("]").append(ChatColor.YELLOW);
    builder.append(" Le joueur ").append(ChatColor.GOLD).append(event.getPlayer().getName()).append(ChatColor.YELLOW);
    builder.append(" a miné un bloc de diamant aux coordonnées ").append(ChatColor.GOLD);
    builder.append(location.getBlockX()).append("; ").append(location.getBlockY()).append("; ").append(location.getBlockZ());
    builder.append(ChatColor.YELLOW).append(" !");

    Bukkit.broadcastMessage(builder.toString());
}
 
Example 16
Project: Kineticraft   File: Xray.java   View source code 6 votes vote down vote up
@EventHandler(priority = EventPriority.LOW)
public void onBlockBreak(BlockBreakEvent evt) {
    Location at = evt.getBlock().getLocation();
    if (at.getY() > 20 || !at.getWorld().equals(Core.getMainWorld()))
        return;

    // Remember mined blocks.
    BrokenBlock bk = new BrokenBlock(evt.getPlayer(), evt.getBlock());
    blocks.add(bk);
    if ((bk.getType() == Material.DIAMOND_ORE || Utils.randChance(20))
            && (getBlockScore(evt.getPlayer()) >= 20 || getTimeScore(evt.getPlayer()) >= 20))
            blocks.detect(bk);

    // Handle suspicious ascending / descending.
    if (elevation.getDetections(evt.getPlayer()).stream().noneMatch(b -> b.getLocation().getY() == at.getY()))
        elevation.detect(bk);
}
 
Example 17
Project: GhostScavengerHunt   File: GhostSkull.java   View source code 6 votes vote down vote up
@EventHandler
public void onSkullBreak(BlockBreakEvent event) {
    if(!LocationUtils.center(event.getBlock().getLocation()).equals(LocationUtils.center(this.location))) return;
    if(!event.getPlayer().hasPermission("ghostskull.break")) {
        event.getPlayer().sendMessage(ChatColor.translateAlternateColorCodes('&', this.getPlugin().getMessageFile().getString("cannot-break-skull-message")));
        event.setCancelled(true);
    } else {
        HandlerList.unregisterAll(this);
        plugin.getGhostSkulls().remove(this);
        plugin.getDataFile().set(this.uuid.toString(), null);
        try {
            plugin.getDataFile().save(plugin.getF_dataFile());
        } catch (IOException e) {
            e.printStackTrace();
        }
        event.getPlayer().sendMessage(ChatColor.GREEN + "Ghost Skull has been deleted.");
    }
}
 
Example 18
Project: MT_Core   File: SupplyDropListener.java   View source code 5 votes vote down vote up
@EventHandler
public void onSupplyDropBreak(BlockBreakEvent e) {
	SupplyDropObject sd = core.getSupplyDropManager().getSupplyDropByLocation(e.getBlock().getLocation());

	if (sd == null)
		return;

	sd.setLooted(true);
	core.getSupplyDropManager().removeSupplyDrop(e.getBlock().getLocation());
}
 
Example 19
Project: CropControl   File: CitadelEventHandler.java   View source code 5 votes vote down vote up
@EventHandler(priority=EventPriority.HIGHEST, ignoreCancelled=true)
public void handleAcidBreak(AcidBlockEvent e) {
	try {
		Location acided = e.getDestroyedBlockReinforcement().getLocation();
		
		CropControl.getPlugin().getEventHandler().onBlockBreak(new BlockBreakEvent( acided.getBlock(), e.getPlayer() ) );
	} catch (Exception g) {
		CropControl.getPlugin().warning("Failed to handle Citadel Acid Block Event:", g);
	}
}
 
Example 20
Project: VoxelGamesLibv2   File: NoBlockBreakFeature.java   View source code 5 votes vote down vote up
@SuppressWarnings({"JavaDoc", "Duplicates"})
@GameEvent
public void onBlockBreak(@Nonnull BlockBreakEvent event) {
    if (blacklist.length != 0) {
        if (Arrays.stream(blacklist).anyMatch(m -> m.equals(event.getBlock().getType()))) {
            event.setCancelled(true);
        }
    } else if (whitelist.length != 0) {
        if (Arrays.stream(whitelist).noneMatch(m -> m.equals(event.getBlock().getType()))) {
            event.setCancelled(true);
        }
    } else {
        event.setCancelled(true);
    }
}
 
Example 21
Project: Warzone   File: WoolChestModule.java   View source code 5 votes vote down vote up
@EventHandler
public void onBreak(BlockBreakEvent event) {
    if (event.getBlock().getType() == Material.CHEST) {
        if (scannedChests.contains(((Chest) event.getBlock().getState()).getBlockInventory().getHolder())) {
            event.setCancelled(true);
            event.getPlayer().sendMessage(ChatColor.RED + "You cannot break the wool chest!");
        }
    }
}
 
Example 22
Project: Warzone   File: DispenserListener.java   View source code 5 votes vote down vote up
@EventHandler(priority = EventPriority.MONITOR, ignoreCancelled = true)
public void onBlockBreak(BlockBreakEvent event) {
    if (!this.tracker.isEnabled(event.getBlock().getWorld())) return;

    if (event.getBlock().getType() == Material.DISPENSER) {
        this.tracker.clearPlacer(event.getBlock());
    }
}
 
Example 23
Project: Warzone   File: AnvilListener.java   View source code 5 votes vote down vote up
@EventHandler(priority = EventPriority.MONITOR, ignoreCancelled = true)
public void onBlockBreak(BlockBreakEvent event) {
    if (!this.tracker.isEnabled(event.getBlock().getWorld())) return;

    if (event.getBlock().getType() == Material.ANVIL) {
        this.tracker.clearPlacer(event.getBlock());
    }
}
 
Example 24
Project: HCFCore   File: BorderListener.java   View source code 5 votes vote down vote up
@EventHandler(ignoreCancelled = true, priority = EventPriority.HIGH)
public void onBlockBreak(final BlockBreakEvent event) {
    if (!isWithinBorder(event.getBlock().getLocation())) {
        event.setCancelled(true);
        event.getPlayer().sendMessage(ChatColor.RED + "You cannot break blocks past the border.");
    }
}
 
Example 25
Project: AntiCheat   File: OrebfuscatorBlockListener.java   View source code 5 votes vote down vote up
@EventHandler(priority = EventPriority.MONITOR)
public void onBlockBreak(BlockBreakEvent event) {
    if (event.isCancelled()) {
        return;
    }

    BlockUpdate.Update(event.getBlock());
    BlockHitManager.breakBlock(event.getPlayer(), event.getBlock());
}
 
Example 26
Project: ZentrelaRPG   File: EnvironmentManager.java   View source code 5 votes vote down vote up
@EventHandler
public void onBlockBreak(BlockBreakEvent event) {
    PlayerDataRPG pd = plugin.getPD(event.getPlayer());
    if (pd == null)
        event.setCancelled(true);
    if (event.getPlayer().getGameMode() != GameMode.CREATIVE)
        event.setCancelled(true);
    if (!canBuild(pd))
        event.setCancelled(true);
}
 
Example 27
Project: HCFCore   File: ExpMultiplierListener.java   View source code 5 votes vote down vote up
@EventHandler(ignoreCancelled = true, priority = EventPriority.NORMAL)
public void onBlockBreak(BlockBreakEvent event) {
    double amount = event.getExpToDrop();
    Player player = event.getPlayer();
    ItemStack stack = player.getItemInHand();
    if (stack != null && stack.getType() != Material.AIR && amount > 0) {
        int enchantmentLevel = stack.getEnchantmentLevel(Enchantment.LOOT_BONUS_BLOCKS);
        if (enchantmentLevel > 0) {
            double multiplier = enchantmentLevel * SettingsYML.EXP_MULTIPLIER_FORTUNE_PER_LEVEL;
            int result = (int) Math.ceil(amount * multiplier);
            event.setExpToDrop(result);
        }
    }
}
 
Example 28
Project: EscapeLag   File: AntiBreakUsingChest.java   View source code 5 votes vote down vote up
@EventHandler
public void CheckNoBreakChest(BlockBreakEvent e) {
    if (ConfigPatch.protectUsingChest) {
        Player p = e.getPlayer();
        if (e.getBlock().getState() instanceof InventoryHolder) {
            InventoryHolder ih = (InventoryHolder) e.getBlock().getState();
            if (ih.getInventory().getViewers().isEmpty() == false) {
                e.setCancelled(true);
                AzureAPI.log(p, ConfigPatch.AntiBreakUsingChestWarnMessage);
            }
        }
    }
}
 
Example 29
Project: Arcadia-Spigot   File: SpleefGame.java   View source code 5 votes vote down vote up
@EventHandler
public void onBlockBreak(BlockBreakEvent event) {
    if(this.getAPI().getGameManager().isAlive(event.getPlayer())) {
        if(event.getBlock().getType() == Material.SNOW_BLOCK) {
            event.getPlayer().getInventory().addItem(new ItemStack(Material.SNOW_BALL, 2));
            event.setDropItems(false);
        }
    }
}
 
Example 30
Project: Arcadia-Spigot   File: WorldListener.java   View source code 5 votes vote down vote up
@EventHandler
public void onBlockBreak(BlockBreakEvent event) {
    ArcadiaAPI api = Arcadia.getPlugin(Arcadia.class).getAPI();
    if(!api.getGameManager().isAlive(event.getPlayer())) event.setCancelled(true);
    if(api.getGameManager().getCurrentGame() != null) {
        MaterialData materialData = new MaterialData(event.getBlock().getType(), event.getBlock().getData());
        if(!api.getGameManager().getCurrentGame().breakableBlocks.contains(materialData)) {
            event.setCancelled(true);
        }
    }
}
 
Example 31
Project: HCFCore   File: FoundDiamondsListener.java   View source code 5 votes vote down vote up
@EventHandler(ignoreCancelled = true, priority = EventPriority.MONITOR)
public void onBlockBreak(final BlockBreakEvent event) {
    final Player player = event.getPlayer();
    if(player.getGameMode() == GameMode.CREATIVE) {
        return;
    }
    if(player.getItemInHand().getEnchantments().containsKey(Enchantment.SILK_TOUCH)) return;;
    final Block block = event.getBlock();
    final Location blockLocation = block.getLocation();
    if(block.getType() == FoundDiamondsListener.SEARCH_TYPE && this.foundLocations.add(blockLocation.toString())) {
        int count = 1;
        for(int x = -5; x < 5; ++x) {
            for(int y = -5; y < 5; ++y) {
                for(int z = -5; z < 5; ++z) {
                    final Block otherBlock = blockLocation.clone().add((double) x, (double) y, (double) z).getBlock();
                    if(!otherBlock.equals(block) && otherBlock.getType() == FoundDiamondsListener.SEARCH_TYPE && this.foundLocations.add(otherBlock.getLocation().toString())) {
                        ++count;
                    }
                }
            }
        }
       
        String message;
        for(Player on : Bukkit.getOnlinePlayers()) {
            if(plugin.getFactionManager().getPlayerFaction(player.getUniqueId()) != null) {
                 message = plugin.getFactionManager().getPlayerFaction(player.getUniqueId()).getRelation(on).toChatColour() + player.getName() + ChatColor.GRAY + " has found " + ChatColor.AQUA + count + ChatColor.GRAY + " diamond(s).";
                on.sendMessage(message);
            }else{
                message = ChatColor.AQUA + "[" + ChatColor.GRAY + "♠" + ChatColor.AQUA + "]" + ChatColor.GRAY + " " + ChatColor.AQUA + player.getName() + ChatColor.GRAY + " has just spotted " + ChatColor.BLUE + count + ChatColor.GRAY +" diamonds!";
                on.sendMessage(message);
            }
        }
    }
}
 
Example 32
Project: AsgardAscension   File: AbilityListener.java   View source code 5 votes vote down vote up
private void handleLuckyRepair(BlockBreakEvent event) {
	ItemStack item = event.getPlayer().getInventory().getItemInMainHand();
	if(Utility.getRandom(1, 10000) > 2 || item == null ||!ItemStackGenerator.isRepairable(item)) {
		return;
	}
	item.setDurability((short)0);
}
 
Example 33
Project: AddGun   File: RailGun.java   View source code 5 votes vote down vote up
/**
 * Prevent using the gun-item to break blocks
 * @param event the break event
 */
@EventHandler(priority = EventPriority.HIGHEST, ignoreCancelled = true)
public void preventBlockBreakWithGun(BlockBreakEvent event) {
	if (event.getPlayer() != null && isGun(event.getPlayer().getInventory().getItemInMainHand())) {
		event.setCancelled(true);
	}
}
 
Example 34
Project: prisonPicks   File: Events.java   View source code 5 votes vote down vote up
@EventHandler
public void onBlockBreak(BlockBreakEvent event)
{

    Player player = event.getPlayer();
    ItemStack item = player.getInventory().getItemInMainHand();

    if (aoepick)
    {
        //stop our event recurring
        return;
    }

    //Are we using one of our picks
    if (Xpick.isPick(item))
    {
        aoepick = true;
        //this is an Xpick
        Xpick x = new Xpick();
        x.breakBlock(event);
    }else if (Pickoplenty.isPick(item))
    {
        Pickoplenty pop = new Pickoplenty();
        pop.breakBlock(event);
    }else if (XPickoPlenty.isPick(item))
    {
        aoepick = true;
        XPickoPlenty xpop = new XPickoPlenty();
        xpop.breakBlock(event);
    }

    aoepick = false;
}
 
Example 35
Project: prisonPicks   File: Xpickoplentytest.java   View source code 5 votes vote down vote up
@Test
public void testBreakBlock()
{
    //TODO: update this test to be more comprehensive
    BlockBreakEvent bbe = new BlockBreakEvent(block, player);
    XPickoPlenty xpick = new XPickoPlenty();
    
    xpick.breakBlock(bbe);
    verify(block, atLeastOnce()).setType(Material.AIR);
}
 
Example 36
Project: prisonPicks   File: XpickTest.java   View source code 5 votes vote down vote up
@Test
public void testBreakBlock()
{
    BlockBreakEvent bbe = new BlockBreakEvent(block, player);
    Xpick xpick = new Xpick();
    
    xpick.breakBlock(bbe);
    verify(block, atLeastOnce()).setType(Material.AIR);
}
 
Example 37
Project: prisonPicks   File: PickoplentyTest.java   View source code 5 votes vote down vote up
@Test
public void testBreakBlock()
{
    BlockBreakEvent bbe = new BlockBreakEvent(block, player);
    Pickoplenty pickoplenty = new Pickoplenty();
    
    pickoplenty.breakBlock(bbe);
    verify(block, atLeastOnce()).setType(Material.AIR);
}
 
Example 38
Project: SuperiorCraft   File: RealBreakBlock.java   View source code 5 votes vote down vote up
@SuppressWarnings("deprecation")
@EventHandler
public void onBlockbreak(BlockBreakEvent e) {
	if (e.getPlayer().getGameMode().equals(GameMode.CREATIVE)) return;
	
	for (BlockBreakRule r : BlockBreakRule.rules) {
		if (r.getMaterial().equals(e.getBlock().getType()) && (e.getPlayer().getEquipment().getItemInMainHand() == null || !r.getLevel().canBreakWith(e.getPlayer().getEquipment().getItemInMainHand()))) {
			e.setCancelled(true);
			return;
		}
	}
	
	for (CustomItem it : CustomItem.items) {
		if (it instanceof CustomTool) {
			if (e.getPlayer().getItemInHand() != null && e.getPlayer().getItemInHand().getType() != null && e.getPlayer().getItemInHand().hasItemMeta() && e.getPlayer().getItemInHand().getItemMeta().hasDisplayName() && it.getItem().getItemMeta().getDisplayName().equals(e.getPlayer().getItemInHand().getItemMeta().getDisplayName())) {
				if (!e.getPlayer().getItemInHand().getItemMeta().isUnbreakable()) {
					//e.getPlayer().sendMessage(e.getPlayer().getItemInHand().getType().name());
					int maxDamage = e.getPlayer().getItemInHand().getType().getMaxDurability(); // btw, this value is 0 for items that don't have durability bar
					int damage = e.getPlayer().getItemInHand().getDurability() + ((CustomTool) it).getDamagePerUse();

					if(damage > maxDamage) // calculated damage exceeds max damage
					{
						e.getPlayer().getInventory().remove(e.getPlayer().getItemInHand());
					}
					else
					{
						e.getPlayer().getItemInHand().setDurability((short) damage);
					}
				}
			}
		}
	}
}
 
Example 39
Project: SuperiorCraft   File: Flag.java   View source code 5 votes vote down vote up
@Override
public void removeBlock(BlockBreakEvent e) {
		for (Entity en : e.getPlayer().getWorld().getEntities()) {
			if (en.getCustomName() != null && en.getCustomName().equals("flag") && en.getLocation().add(-0.5, 0, -0.5).equals(e.getBlock().getLocation())) {
				en.remove();
				e.getPlayer().sendMessage(ChatColor.GRAY + "Flag removed");
			}
	}
}
 
Example 40
Project: SuperiorCraft   File: Elevator.java   View source code 5 votes vote down vote up
@Override
public CustomBlockInstance getInstance(ArmorStand s) {
	ElevatorInstance ei = new ElevatorInstance(s, getTextureEntity(s), getTexture());
	Bukkit.getScheduler().scheduleSyncRepeatingTask(SuperiorCraft.plugin, new Runnable() {
		@Override
		public void run() {
			if (s.getCustomName() != null && s.getCustomName().equals(getName()) && s.getLocation().add(-0.5, 0, -0.5).getBlock().getType() == Material.AIR) {
				removeBlock(new BlockBreakEvent(s.getLocation().add(-0.5, 0, -0.5).getBlock(), null));
				//System.out.println("A");
			}
		}
	}, 0, 0);
	SuperiorCraft.plugin.getServer().getPluginManager().registerEvents(ei, SuperiorCraft.plugin);
	return ei;
}