org.bukkit.block.Block Java Examples

The following examples show how to use org.bukkit.block.Block. 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: ExoticGardenFruit.java    From ExoticGarden with GNU General Public License v3.0 6 votes vote down vote up
public ItemUseHandler onRightClick() {
    return e -> {
        Optional<Block> block = e.getClickedBlock();

        if (block.isPresent()) {
            Material material = block.get().getType();

            // Cancel the Block placement if the Player sneaks or the Block is not interactable
            if (e.getPlayer().isSneaking() || !isInteractable(material)) {
                e.cancel();
            }
            else {
                return;
            }
        }

        if (edible && e.getPlayer().getFoodLevel() < 20) {
            restoreHunger(e.getPlayer());
            ItemUtils.consumeItem(e.getItem(), false);
        }
    };
}
 
Example #2
Source File: PlantsListener.java    From ExoticGarden with GNU General Public License v3.0 6 votes vote down vote up
private void dropFruitFromTree(Block block) {
    for (int x = -1; x < 2; x++) {
        for (int y = -1; y < 2; y++) {
            for (int z = -1; z < 2; z++) {
                // inspect a cube at the reference
                Block fruit = block.getRelative(x, y, z);
                if (fruit.isEmpty()) continue;

                Location loc = fruit.getLocation();
                SlimefunItem check = BlockStorage.check(loc);
                if (check == null) continue;

                for (Tree tree : ExoticGarden.getTrees()) {
                    if (check.getID().equalsIgnoreCase(tree.getFruitID())) {
                        BlockStorage.clearBlockInfo(loc);
                        ItemStack fruits = check.getItem();
                        fruit.getWorld().playEffect(loc, Effect.STEP_SOUND, Material.OAK_LEAVES);
                        fruit.getWorld().dropItemNaturally(loc, fruits);
                        fruit.setType(Material.AIR);
                        break;
                    }
                }
            }
        }
    }
}
 
Example #3
Source File: LWC.java    From Modern-LWC with MIT License 6 votes vote down vote up
/**
 * Find a protection that is adjacent to another block on any of the block's 6
 * sides
 *
 * @param block
 * @param ignore
 * @return
 */
public List<Protection> findAdjacentProtectionsOnAllSides(Block block, Block... ignore) {
    BlockFace[] faces = new BlockFace[]{BlockFace.NORTH, BlockFace.SOUTH, BlockFace.EAST, BlockFace.WEST,
            BlockFace.UP, BlockFace.DOWN};
    List<Block> ignoreList = Arrays.asList(ignore);
    List<Protection> found = new ArrayList<Protection>();

    for (BlockFace face : faces) {
        Protection protection;
        Block adjacentBlock = block.getRelative(face);

        if (!ignoreList.contains(adjacentBlock.getLocation())
                && (protection = findProtection(adjacentBlock.getLocation())) != null) {
            found.add(protection);
        }
    }

    return found;
}
 
Example #4
Source File: CraftBlockState.java    From Thermos with GNU General Public License v3.0 6 votes vote down vote up
public CraftBlockState(final Block block) {
    this.world = (CraftWorld) block.getWorld();
    this.x = block.getX();
    this.y = block.getY();
    this.z = block.getZ();
    this.type = block.getTypeId();
    this.light = block.getLightLevel();
    this.chunk = (CraftChunk) block.getChunk();
    this.flag = 3;
    // Cauldron start - save TE data
    TileEntity te = world.getHandle().getTileEntity(x, y, z);
    if (te != null)
    {
        nbt = new NBTTagCompound();
        te.writeToNBT(nbt);
    }
    else nbt = null;
    // Cauldron end

    createData(block.getData());
}
 
Example #5
Source File: TilesCustomNBTInjectorTest.java    From Item-NBT-API with MIT License 6 votes vote down vote up
@Override
public void test() throws Exception {
	if(!NBTInjector.isInjected())return;
	if (!Bukkit.getWorlds().isEmpty()) {
		World world = Bukkit.getWorlds().get(0);
		try {
			Block block = world.getBlockAt(world.getSpawnLocation().getBlockX(), 255,
					world.getSpawnLocation().getBlockZ());
			if (block.getType() == Material.AIR) {
				block.setType(Material.CHEST);
				NBTCompound comp = NBTInjector.getNbtData(block.getState());
				comp.setString("Foo", "Bar");
				if (!new NBTTileEntity(block.getState()).toString().contains("__extraData:{Foo:\"Bar\"}")) {
					block.setType(Material.AIR);
					throw new NbtApiException("Custom Data did not save to the Tile!");
				}
				block.setType(Material.AIR);
			}
		} catch (Exception ex) {
			throw new NbtApiException("Wasn't able to use NBTTiles!", ex);
		}
	}
}
 
Example #6
Source File: CargoNet.java    From Slimefun4 with GNU General Public License v3.0 6 votes vote down vote up
public void tick(Block b) {
    if (!regulator.equals(b.getLocation())) {
        SimpleHologram.update(b, "&4Multiple Cargo Regulators connected");
        return;
    }

    super.tick();

    if (connectorNodes.isEmpty() && terminusNodes.isEmpty()) {
        SimpleHologram.update(b, "&cNo Cargo Nodes found");
    }
    else {
        SimpleHologram.update(b, "&7Status: &a&lONLINE");
        Map<Integer, List<Location>> output = mapOutputNodes();

        // Chest Terminal Stuff
        Set<Location> destinations = new HashSet<>();
        List<Location> output16 = output.get(16);

        if (output16 != null) {
            destinations.addAll(output16);
        }

        Slimefun.runSync(() -> run(b, destinations, output));
    }
}
 
Example #7
Source File: Destroyable.java    From ProjectAres with GNU Affero General Public License v3.0 6 votes vote down vote up
/**
 * Calculate maximum/current health
 */
protected void recalculateHealth() {
    // We only need blockMaterialHealth if there are destroyable blocks that are
    // replaced by other destroyable blocks when broken.
    if(this.isAffectedByBlockReplacementRules()) {
        this.blockMaterialHealth = new HashMap<>();
        this.buildMaterialHealthMap();
    } else {
        this.blockMaterialHealth = null;
        this.maxHealth = (int) this.blockRegion.blockVolume();
        this.health = 0;
        for(Block block : this.blockRegion.getBlocks(match.getWorld())) {
            if(this.hasMaterial(block.getState().getData())) {
                this.health++;
            }
        }
    }
}
 
Example #8
Source File: MultiBlockMachine.java    From Slimefun4 with GNU General Public License v3.0 6 votes vote down vote up
protected Inventory findOutputChest(Block b, ItemStack output) {
    for (BlockFace face : outputFaces) {
        Block potentialOutput = b.getRelative(face);

        if (potentialOutput.getType() == Material.CHEST) {
            String id = BlockStorage.checkID(potentialOutput);

            if (id != null && id.equals("OUTPUT_CHEST")) {
                // Found the output chest! Now, let's check if we can fit the product in it.
                Inventory inv = ((Chest) potentialOutput.getState()).getInventory();

                if (InvUtils.fits(inv, output)) {
                    return inv;
                }
            }
        }
    }

    return null;
}
 
Example #9
Source File: Template.java    From civcraft with GNU General Public License v2.0 6 votes vote down vote up
public void previewEntireTemplate(Template tpl, Block cornerBlock, Player player) {
		//HashMap<Chunk, Chunk> chunkUpdates = new HashMap<Chunk, Chunk>();
	//	NMSHandler nms = new NMSHandler();
		PlayerBlockChangeUtil util = new PlayerBlockChangeUtil();
		for (int x = 0; x < tpl.size_x; x++) {
			for (int y = 0; y < tpl.size_y; y++) {
				for (int z = 0; z < tpl.size_z; z++) {
					Block b = cornerBlock.getRelative(x, y, z);
						//b.setTypeIdAndData(tpl.blocks[x][y][z].getType(), (byte)tpl.blocks[x][y][z].getData(), false);
						try {
							util.addUpdateBlock("", new BlockCoord(b), tpl.blocks[x][y][z].getType(), tpl.blocks[x][y][z].getData());
							
//							nms.setBlockFast(b.getWorld(), b.getX(), b.getY(), b.getZ(), tpl.blocks[x][y][z].getType(), 
//								(byte)tpl.blocks[x][y][z].getData());
						} catch (Exception e) {
							e.printStackTrace();
							//throw new CivException("Couldn't build undo template unknown error:"+e.getMessage());
						}
				}
			}
		}
		
		util.sendUpdate(player.getName());
	}
 
Example #10
Source File: LookingAtCondition.java    From BetonQuest with GNU General Public License v3.0 6 votes vote down vote up
@Override
protected Boolean execute(String playerID) throws QuestRuntimeException {
    Player p = PlayerConverter.getPlayer(playerID);
    Block lookingAt = p.getTargetBlock(null, 6);
    if (loc != null) {
        Location location = loc.getLocation(playerID);
        Location to = lookingAt.getLocation();
        if (location.getBlockX() != to.getBlockX()
                || location.getBlockY() != to.getBlockY()
                || location.getBlockZ() != to.getBlockZ()) return false;
    }
    if (selector != null) {
        return selector.match(lookingAt);
    }
    return true;
}
 
Example #11
Source File: XBlock.java    From IridiumSkyblock with GNU General Public License v2.0 6 votes vote down vote up
public static boolean setDirection(Block block, BlockFace facing) {
    if (XMaterial.ISFLAT) {
        if (!(block.getBlockData() instanceof Directional)) return false;
        Directional direction = (Directional) block.getBlockData();
        direction.setFacing(facing);
        return true;
    }

    BlockState state = block.getState();
    MaterialData data = state.getData();
    if (data instanceof org.bukkit.material.Directional) {
        ((org.bukkit.material.Directional) data).setFacingDirection(facing);
        state.update(true);
        return true;
    }
    return false;
}
 
Example #12
Source File: Uncarried.java    From PGM with GNU Affero General Public License v3.0 6 votes vote down vote up
public Uncarried(Flag flag, Post post, @Nullable Location location) {
  super(flag, post);
  if (location == null) location = flag.getReturnPoint(post);
  this.location =
      new Location(
          location.getWorld(),
          location.getBlockX() + 0.5,
          location.getBlockY(),
          location.getBlockZ() + 0.5,
          location.getYaw(),
          location.getPitch());

  Block block = this.location.getBlock();
  if (block.getType() == Material.STANDING_BANNER) {
    // Banner may already be here at match start
    this.oldBlock = BlockStates.cloneWithMaterial(block, Material.AIR);
  } else {
    this.oldBlock = block.getState();
  }
  this.oldBase = block.getRelative(BlockFace.DOWN).getState();
}
 
Example #13
Source File: SkullBlock.java    From askyblock with GNU General Public License v2.0 6 votes vote down vote up
@SuppressWarnings("deprecation")
public boolean set(Block block) {
    Skull skull = (Skull) block.getState();
    if(skullOwnerName != null){
        skull.setOwner(skullOwnerName);
    }
    skull.setSkullType(skullType);
    skull.setRotation(skullRotation);
    skull.setRawData((byte) skullStanding);
    // Texture update
    if(skullTextureValue != null){
        setSkullWithNonPlayerProfile(skullTextureValue, skullTextureSignature, skullOwnerUUID, skullOwnerName, skull);
    }
    skull.update(true, false);
    return true;
}
 
Example #14
Source File: BlockListener.java    From civcraft with GNU General Public License v2.0 6 votes vote down vote up
public BlockCoord generatesCobble(int id, Block b)
{
    int mirrorID1 = (id == CivData.WATER_RUNNING || id == CivData.WATER ? CivData.LAVA_RUNNING : CivData.WATER_RUNNING);
    int mirrorID2 = (id == CivData.WATER_RUNNING || id == CivData.WATER ? CivData.LAVA : CivData.WATER);
    for(BlockFace face : faces)
    {
        Block r = b.getRelative(face, 1);
        if(ItemManager.getId(r) == mirrorID1 || ItemManager.getId(r) == mirrorID2)
        {
        	
        	return new BlockCoord(r);
        }
    }
    
    return null;
}
 
Example #15
Source File: OreWasher.java    From Slimefun4 with GNU General Public License v3.0 5 votes vote down vote up
private void removeItem(Player p, Block b, Inventory inputInv, Inventory outputInv, ItemStack input, ItemStack output, int amount) {
    if (outputInv != null) {
        ItemStack removing = input.clone();
        removing.setAmount(amount);
        inputInv.removeItem(removing);
        outputInv.addItem(output.clone());

        b.getWorld().playEffect(b.getLocation(), Effect.STEP_SOUND, Material.WATER);
        b.getWorld().playSound(b.getLocation(), Sound.ENTITY_PLAYER_SPLASH, 1, 1);
    }
    else {
        SlimefunPlugin.getLocalization().sendMessage(p, "machines.full-inventory", true);
    }
}
 
Example #16
Source File: EvtMoveOn.java    From Skript with GNU General Public License v3.0 5 votes vote down vote up
@Nullable
final static Block getOnBlock(final Location l) {
	Block block = l.getWorld().getBlockAt(l.getBlockX(), (int) (Math.ceil(l.getY()) - 1), l.getBlockZ());
	if (block.getType() == Material.AIR && Math.abs((l.getY() - l.getBlockY()) - 0.5) < Skript.EPSILON) { // Fences
		block = l.getWorld().getBlockAt(l.getBlockX(), l.getBlockY() - 1, l.getBlockZ());
		if (!fencePart.isOfType(block))
			return null;
	}
	return block;
}
 
Example #17
Source File: EntityListener.java    From WorldGuardExtraFlagsPlugin with MIT License 5 votes vote down vote up
@EventHandler(ignoreCancelled = true)
public void onPortalCreateEvent(PortalCreateEvent event)
{
	for(Block block : event.getBlocks())
	{
		//Unable to get the player who created it....
		
		ApplicableRegionSet regions = this.plugin.getWorldGuardCommunicator().getRegionContainer().createQuery().getApplicableRegions(block.getLocation());
		if (regions.queryValue(null, Flags.NETHER_PORTALS) == State.DENY)
		{
			event.setCancelled(true);
			break;
		}
	}
}
 
Example #18
Source File: CutCleanListener.java    From UhcCore with GNU General Public License v3.0 5 votes vote down vote up
@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 #19
Source File: Composter.java    From Slimefun4 with GNU General Public License v3.0 5 votes vote down vote up
@Override
public BlockUseHandler getItemHandler() {
    return e -> {
        Optional<Block> block = e.getClickedBlock();

        if (block.isPresent()) {
            e.cancel();

            Player p = e.getPlayer();
            Block b = block.get();

            if (p.hasPermission("slimefun.inventory.bypass") || SlimefunPlugin.getProtectionManager().hasPermission(p, b.getLocation(), ProtectableAction.ACCESS_INVENTORIES)) {
                ItemStack input = e.getItem();
                ItemStack output = getOutput(p, input);

                if (output != null) {
                    TaskQueue tasks = new TaskQueue();

                    tasks.thenRepeatEvery(30, 10, () -> {
                        Material material = input.getType().isBlock() ? input.getType() : Material.HAY_BLOCK;
                        b.getWorld().playEffect(b.getLocation(), Effect.STEP_SOUND, material);
                    });

                    tasks.thenRun(20, () -> {
                        p.getWorld().playSound(p.getLocation(), Sound.ENTITY_ARROW_HIT_PLAYER, 1F, 1F);
                        pushItem(b, output.clone());
                    });

                    tasks.execute(SlimefunPlugin.instance);
                }
                else {
                    SlimefunPlugin.getLocalization().sendMessage(p, "machines.wrong-item", true);
                }
            }
        }
    };
}
 
Example #20
Source File: VersionHelper18.java    From RedProtect with GNU General Public License v3.0 5 votes vote down vote up
public Block getBlockRelative(Block block) {
    if (block.getState() instanceof Sign) {
        org.bukkit.material.Sign s = (org.bukkit.material.Sign) block.getState().getData();
        return block.getRelative(s.getAttachedFace());
    }
    return null;
}
 
Example #21
Source File: BlockAdapterBlockData.java    From DungeonsXL with GNU General Public License v3.0 5 votes vote down vote up
@Override
public BlockFace getFacing(Block block) {
    if (block.getBlockData() instanceof Directional) {
        return ((Directional) block.getBlockData()).getFacing();
    } else if (block.getBlockData() instanceof Rotatable) {
        return ((Rotatable) block.getBlockData()).getRotation();
    } else {
        throw new IllegalArgumentException("Block is not Directional or Rotatable");
    }
}
 
Example #22
Source File: GlobalListener.java    From RedProtect with GNU General Public License v3.0 5 votes vote down vote up
@EventHandler(priority = EventPriority.LOWEST, ignoreCancelled = true)
public void onBlockPlace(BlockPlaceEvent e) {
    RedProtect.get().logger.debug(LogLevel.DEFAULT, "GlobalListener - Is BlockPlaceEvent event!");

    Block b = e.getBlock();
    Player p = e.getPlayer();
    Material item = e.getItemInHand().getType();
    Region r = RedProtect.get().rm.getTopRegion(e.getBlock().getLocation());
    if (r != null) {
        return;
    }

    if (!RedProtect.get().getUtil().canBuildNear(p, b.getLocation())) {
        e.setCancelled(true);
        return;
    }

    if (item.name().contains("MINECART") || item.name().contains("BOAT")) {
        if (!RedProtect.get().config.globalFlagsRoot().worlds.get(p.getWorld().getName()).use_minecart && !p.hasPermission("redprotect.bypass.world")) {
            e.setCancelled(true);
            RedProtect.get().logger.debug(LogLevel.DEFAULT, "GlobalListener - Can't place minecart/boat!");
        }
    } else {
        if (!bypassBuild(p, b, 1)) {
            e.setCancelled(true);
            RedProtect.get().logger.debug(LogLevel.DEFAULT, "GlobalListener - Can't Build!");
        }
    }
}
 
Example #23
Source File: InteractTrigger.java    From DungeonsXL with GNU General Public License v3.0 5 votes vote down vote up
public static InteractTrigger getByBlock(Block block, DGameWorld gameWorld) {
    for (Trigger uncasted : gameWorld.getTriggers(TriggerTypeDefault.INTERACT)) {
        InteractTrigger trigger = (InteractTrigger) uncasted;
        if (trigger.interactBlock != null) {
            if (trigger.interactBlock.equals(block)) {
                return trigger;
            }
        }
    }
    return null;
}
 
Example #24
Source File: BlockDataChanger.java    From FunnyGuilds with Apache License 2.0 5 votes vote down vote up
public static void applyChanges(Block targetBlock, byte newData) {
    if (!Reflections.USE_PRE_13_METHODS) {
        return;
    }
    
    try {
        setDataMethod.invoke(targetBlock, newData);
    }
    catch (IllegalAccessException | IllegalArgumentException | InvocationTargetException ex) {
        FunnyGuilds.getInstance().getPluginLogger().error("Failed to change block data for a block at: " + LocationUtils.toString(targetBlock.getLocation()), ex);
    }
}
 
Example #25
Source File: VersionHelper18.java    From RedProtect with GNU General Public License v3.0 5 votes vote down vote up
public void toggleDoor(Block b) {
    BlockState state = b.getState();
    if (state instanceof Door) {
        Door op = (Door) state.getData();
        if (!op.isOpen())
            op.setOpen(true);
        else
            op.setOpen(false);
        state.setData(op);
        state.update();
    }
}
 
Example #26
Source File: CraftEventFactory.java    From Kettle with GNU General Public License v3.0 5 votes vote down vote up
public static PlayerInteractEvent callPlayerInteractEvent(EntityPlayer who, Action action, BlockPos position, EnumFacing direction, ItemStack itemstack, boolean cancelledBlock, EnumHand hand) {
    Player player = (who == null) ? null : (Player) who.getBukkitEntity();
    CraftItemStack itemInHand = CraftItemStack.asCraftMirror(itemstack);

    CraftWorld craftWorld = (CraftWorld) player.getWorld();
    CraftServer craftServer = (CraftServer) player.getServer();

    Block blockClicked = null;
    if (position != null) {
        blockClicked = craftWorld.getBlockAt(position.getX(), position.getY(), position.getZ());
    } else {
        switch (action) {
            case LEFT_CLICK_BLOCK:
                action = Action.LEFT_CLICK_AIR;
                break;
            case RIGHT_CLICK_BLOCK:
                action = Action.RIGHT_CLICK_AIR;
                break;
        }
    }
    BlockFace blockFace = CraftBlock.notchToBlockFace(direction);

    if (itemInHand.getType() == Material.AIR || itemInHand.getAmount() == 0) {
        itemInHand = null;
    }

    PlayerInteractEvent event = new PlayerInteractEvent(player, action, itemInHand, blockClicked, blockFace, (hand == null) ? null : ((hand == EnumHand.OFF_HAND) ? EquipmentSlot.OFF_HAND : EquipmentSlot.HAND));
    if (cancelledBlock) {
        event.setUseInteractedBlock(Event.Result.DENY);
    }
    craftServer.getPluginManager().callEvent(event);

    return event;
}
 
Example #27
Source File: ProtectionsTests.java    From Civs with GNU General Public License v3.0 5 votes vote down vote up
private void explodeInProtectedRegion(Location regionLocation, boolean useTown) {
    Region region;
    HashMap<UUID, String> people = new HashMap<>();
    people.put(TestUtil.player.getUniqueId(), Constants.OWNER);
    HashMap<String, String> effects = new HashMap<>();
    if (useTown) {
        RegionsTests.loadRegionTypeCobble();
        region = new Region("cobble", people,
                regionLocation,
                RegionsTests.getRadii(),
                effects,0);
        TownTests.loadTownTypeHamlet2();
        TownTests.loadTown("testTown", "hamlet2", regionLocation);
    } else {
        RegionsTests.loadRegionTypeShelter();
        effects.put("block_explosion", "");
        region = new Region("cobble", people,
                regionLocation,
                RegionsTests.getRadii(),
                effects,0);
    }
    try {
        when(Bukkit.getServer().getScheduler()).thenThrow(new SuccessException());
    } catch (SuccessException e) {
        // Do nothing
    }
    RegionManager.getInstance().addRegion(region);
    TNTPrimed tntPrimed = mock(TNTPrimed.class);
    ArrayList<Block> blockList = new ArrayList<>();
    EntityExplodeEvent event = new EntityExplodeEvent(tntPrimed,
            regionLocation.add(0, 1,0),
            blockList,
            (float) 2);
    ProtectionHandler protectionHandler = new ProtectionHandler();
    protectionHandler.onEntityExplode(event);
}
 
Example #28
Source File: BlockTracker.java    From PGM with GNU Affero General Public License v3.0 5 votes vote down vote up
@EventHandler(priority = EventPriority.MONITOR, ignoreCancelled = true)
public void onTransform(BlockTransformEvent event) {
  if (event.getCause() instanceof BlockPistonEvent) return;

  Block block = event.getOldState().getBlock();
  TrackerInfo info = blocks.get(block);
  if (info != null && !isPlaced(event.getNewState())) {
    clearBlock(block);
  }
}
 
Example #29
Source File: LWCBlockListener.java    From Modern-LWC with MIT License 5 votes vote down vote up
@EventHandler
public void onBlockPistonExtend(BlockPistonExtendEvent event) {
    if (!LWC.ENABLED || event.isCancelled()) {
        return;
    }
    LWC lwc = this.plugin.getLWC();
    for (Block block : event.getBlocks()) {
        Protection protection = lwc.findProtection(block);
        if (protection != null) {
            event.setCancelled(true);
            return;
        }
    }
}
 
Example #30
Source File: PickaxeOfTheSeeker.java    From Slimefun4 with GNU General Public License v3.0 5 votes vote down vote up
private Block findClosestOre(Player p) {
    Block closest = null;

    for (int x = -4; x <= 4; x++) {
        for (int y = -4; y <= 4; y++) {
            for (int z = -4; z <= 4; z++) {
                if (MaterialCollections.getAllOres().contains(p.getLocation().add(x, y, z).getBlock().getType()) && (closest == null || p.getLocation().distanceSquared(closest.getLocation()) > p.getLocation().distanceSquared(p.getLocation().add(x, y, z)))) {
                    closest = p.getLocation().getBlock().getRelative(x, y, z);
                }
            }
        }
    }

    return closest;
}