Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- @EventHandler
- public void onBreak(BlockBreakEvent e) {
- if (e.getBlock().getType().name().contains("ORE")) {
- Player p = e.getPlayer();
- if ((ScenarioManager.getIns().ScenarioManagerCheck(ScenarioEnum.VEIN_MINER))) {
- if (p.isSneaking()) {
- Bukkit.broadcastMessage("test");
- Set types = getMatchingTypesAtLocation(e.getBlock());
- Block block = (Block)types;
- block.breakNaturally();
- block.getWorld().playEffect(block.getLocation(), Effect.STEP_SOUND, 1);
- if (block.getType().equals(Material.IRON_ORE)){
- p.getInventory().addItem(new ItemStack(Material.IRON_INGOT, types.size()));
- p.giveExp((3*types.size()));
- }
- if (block.getType().equals(Material.GOLD_ORE)){
- p.getInventory().addItem(new ItemStack(Material.GOLD_INGOT, types.size()));
- p.giveExp((4*types.size()));
- }
- if (block.getType().equals(Material.DIAMOND_ORE)){
- p.getInventory().addItem(new ItemStack(Material.DIAMOND, types.size()));
- p.giveExp((6*types.size()));
- }
- if (block.getType().equals(Material.REDSTONE_ORE)){
- p.getInventory().addItem(new ItemStack(Material.REDSTONE, types.size()));
- p.giveExp((4*types.size()));
- }
- if (block.getType().equals(Material.LAPIS_ORE)){
- p.getInventory().addItem(new ItemStack(Material.INK_SACK, types.size()));
- p.giveExp((4*types.size()));
- }
- if (block.getType().equals(Material.COAL_ORE)){
- p.getInventory().addItem(new ItemStack(Material.COAL, types.size()));
- p.giveExp((1*types.size()));
- }
- return;
- }
- }
- }else if (e.getBlock().getType().name().contains("GRAVEL")){
- Player p = e.getPlayer();
- if ((ScenarioManager.getIns().ScenarioManagerCheck(ScenarioEnum.VEIN_MINER))) {
- if (p.isSneaking()) {
- Set types = getMatchingTypesAtLocation(e.getBlock());
- Block block = (Block) types;
- block.breakNaturally();
- Random rand = new Random();
- if (block.getType().equals(Material.GRAVEL)) {
- if (rand.nextInt(99) < GameUtils.getFlintRates()) {
- p.getInventory().addItem(new ItemStack(Material.FLINT, types.size()));
- }
- }
- }
- }
- }
- }
- protected Material convertType(Material type) {
- switch(type) {
- case GLOWING_REDSTONE_ORE:
- return Material.REDSTONE_ORE;
- default:
- return type;
- }
- }
- public Set<Block> getMatchingTypesAtLocation(Block block) {
- Material type = this.convertType(block.getType());
- Set<Block> matching = Sets.newHashSet(block);
- LinkedList<Block> waitingForChecks = Lists.newLinkedList();
- waitingForChecks.add(block);
- Block current, check;
- int x, y, z;
- while (waitingForChecks.size() > 0) {
- current = waitingForChecks.poll();
- for (x = -1; x <= 1; x++) {
- for (y = 1; y <= 1; y++) {
- for (z = 1; z <=1; z++ ){
- // get block at the location
- check = current.getRelative(x, y, z);
- // skip outside world and wrong types
- if (check == null || type != convertType(check.getType()))
- continue;
- // add to matching set
- if (matching.add(check)) {
- // if the location wasn't already found add to list and quit if we're at max size
- waitingForChecks.add(check);
- }
- }
- }
- }
- }
- return matching;
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment