当前位置: 首页>>代码示例>>Java>>正文


Java Block.isEmpty方法代码示例

本文整理汇总了Java中org.bukkit.block.Block.isEmpty方法的典型用法代码示例。如果您正苦于以下问题:Java Block.isEmpty方法的具体用法?Java Block.isEmpty怎么用?Java Block.isEmpty使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在org.bukkit.block.Block的用法示例。


在下文中一共展示了Block.isEmpty方法的10个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: getLocationNearPlayer

import org.bukkit.block.Block; //导入方法依赖的package包/类
public static Location getLocationNearPlayer(Player player, int radius) {
    Block playerBlock = player.getLocation().getBlock();
    List<Location> availableLocations = new ArrayList<>();

    World world = player.getWorld();
    for (int x = playerBlock.getX() - radius; x < playerBlock.getX() + radius; x++) {
        for (int y = playerBlock.getY() - radius; y < playerBlock.getY() + radius; y++) {
            for (int z = playerBlock.getZ() - radius; z < playerBlock.getZ() + radius; z++) {
                Location loc = getBlockCenter(new Location(world, x, y, z));
                if (loc.getBlock().isEmpty()) {
                    Block underBlock = loc.clone().subtract(0, 1, 0).getBlock();
                    if (!underBlock.isEmpty() && !underBlock.isLiquid()) {
                        loc.setYaw((float) (-180 + Math.random() * 360));
                        availableLocations.add(loc);
                    }
                }
            }
        }
    }

    if (availableLocations.size() == 0) {
        return getBlockCenter(playerBlock.getLocation().clone());
    }

    return availableLocations.get(new Random().nextInt(availableLocations.size()));
}
 
开发者ID:EndlessCodeGroup,项目名称:RPGInventory,代码行数:27,代码来源:LocationUtils.java

示例2: getHighestLocation

import org.bukkit.block.Block; //导入方法依赖的package包/类
public static Location getHighestLocation(final Location origin, final Location def) {
    Preconditions.checkNotNull((Object) origin, (Object) "The location cannot be null");
    final Location cloned = origin.clone();
    final World world = cloned.getWorld();
    final int x = cloned.getBlockX();
    int y = world.getMaxHeight();
    final int z = cloned.getBlockZ();
    while (y > origin.getBlockY()) {
        final Block block = world.getBlockAt(x, --y, z);
        if (!block.isEmpty()) {
            final Location next = block.getLocation();
            next.setPitch(origin.getPitch());
            next.setYaw(origin.getYaw());
            return next;
        }
    }
    return def;
}
 
开发者ID:funkemunky,项目名称:HCFCore,代码行数:19,代码来源:BukkitUtils.java

示例3: onStickyPistonRetract

import org.bukkit.block.Block; //导入方法依赖的package包/类
@EventHandler(ignoreCancelled = true, priority = EventPriority.NORMAL)
public void onStickyPistonRetract(BlockPistonRetractEvent event) {
    if (!event.isSticky())
        return; // If not a sticky piston, retraction should be fine.

    // If potentially retracted block is just AIR/WATER/LAVA, no worries
    Location retractLocation = event.getRetractLocation();
    Block retractBlock = retractLocation.getBlock();
    if (!retractBlock.isEmpty() && !retractBlock.isLiquid()) {
        Block block = event.getBlock();
        Faction targetFaction = plugin.getFactionManager().getFactionAt(retractLocation);
        if (targetFaction instanceof Raidable && !((Raidable) targetFaction).isRaidable() && targetFaction != plugin.getFactionManager().getFactionAt(block)) {
            event.setCancelled(true);
        }
    }
}
 
开发者ID:funkemunky,项目名称:HCFCore,代码行数:17,代码来源:ProtectionListener.java

示例4: averageLightLevel

import org.bukkit.block.Block; //导入方法依赖的package包/类
/**
 * Get the average light level of all empty (air) blocks in the Cuboid.  Returns 0
 * if there are no empty blocks.
 *
 * @return	the average light level of this Cuboid
 */
public byte averageLightLevel() {
	long total = 0;
	int n = 0;
	for (Block b : this) {
		if (b.isEmpty()) {
			total += b.getLightLevel();
			++n;
		}
	}
	return n > 0 ? (byte) (total / n) : 0;
}
 
开发者ID:ArcadiaPlugins,项目名称:Arcadia-Spigot,代码行数:18,代码来源:Cuboid.java

示例5: isSafe

import org.bukkit.block.Block; //导入方法依赖的package包/类
/**
 * Indicates whether or not this spawn is safe.
 *
 * @param location Location to check for.
 * @return True or false depending on whether this is a safe spawn point.
 */
private boolean isSafe(Location location) {
    if(!WorldBorderUtils.isInsideBorder(location)) return false;

    Block block = location.getBlock();
    Block above = block.getRelative(BlockFace.UP);
    Block below = block.getRelative(BlockFace.DOWN);

    return block.isEmpty() && above.isEmpty() && Materials.isColliding(below.getType());
}
 
开发者ID:OvercastNetwork,项目名称:ProjectAres,代码行数:16,代码来源:RegionPointProvider.java

示例6: getAverageLightLevel

import org.bukkit.block.Block; //导入方法依赖的package包/类
/**
 * Get the average light level of all empty (air) blocks in the Cuboid.
 * Returns 0 if there are no empty blocks.
 *
 * @return The average light level of this Cuboid
 */
public byte getAverageLightLevel() {
    long total = 0;
    int n = 0;
    for (Block b : this) {
        if (b.isEmpty()) {
            total += b.getLightLevel();
            ++n;
        }
    }
    return n > 0 ? (byte) (total / n) : 0;
}
 
开发者ID:AlphaHelixDev,项目名称:AlphaLibary,代码行数:18,代码来源:Cuboid.java

示例7: isUnderAnyBlock

import org.bukkit.block.Block; //导入方法依赖的package包/类
public static boolean isUnderAnyBlock(Block block, int distance) {
    for (int i = 1; i <= distance; i++) {
        Block blockUnderPlayer = block.getRelative(BlockFace.DOWN, i);
        if (!blockUnderPlayer.isEmpty()) {
            return true;
        }
    }

    return false;
}
 
开发者ID:EndlessCodeGroup,项目名称:RPGInventory,代码行数:11,代码来源:LocationUtils.java

示例8: onStickyPistonExtend

import org.bukkit.block.Block; //导入方法依赖的package包/类
@EventHandler(ignoreCancelled = true, priority = EventPriority.NORMAL)
public void onStickyPistonExtend(final BlockPistonExtendEvent event) {
    final Block block = event.getBlock();
    final Block targetBlock = block.getRelative(event.getDirection(), event.getLength() + 1);
    if (targetBlock.isEmpty() || targetBlock.isLiquid()) {
        final Faction targetFaction = this.plugin.getFactionManager().getFactionAt(targetBlock.getLocation());
        if (targetFaction instanceof Raidable && !((Raidable)targetFaction).isRaidable() && !targetFaction.equals(this.plugin.getFactionManager().getFactionAt(block))) {
            event.setCancelled(true);
        }
    }
}
 
开发者ID:funkemunky,项目名称:HCFCore,代码行数:12,代码来源:CoreListener.java

示例9: onStickyPistonExtend

import org.bukkit.block.Block; //导入方法依赖的package包/类
@EventHandler(ignoreCancelled = true, priority = EventPriority.NORMAL)
public void onStickyPistonExtend(BlockPistonExtendEvent event) {
    Block block = event.getBlock();

    // Targets end-of-the-line empty (AIR) block which is being pushed into, including if piston itself would extend into air.
    Block targetBlock = block.getRelative(event.getDirection(), event.getLength() + 1);
    if (targetBlock.isEmpty() || targetBlock.isLiquid()) { // If potentially pushing into AIR/WATER/LAVA in another territory, check it out.
        Faction targetFaction = plugin.getFactionManager().getFactionAt(targetBlock.getLocation());
        if (targetFaction instanceof Raidable && !((Raidable) targetFaction).isRaidable() && targetFaction != plugin.getFactionManager().getFactionAt(block)) {
            event.setCancelled(true);
        }
    }
}
 
开发者ID:funkemunky,项目名称:HCFCore,代码行数:14,代码来源:ProtectionListener.java

示例10: getAverageLightLevel

import org.bukkit.block.Block; //导入方法依赖的package包/类
/**
 * Get the average light level of all empty (air) blocks in the Cuboid.  Returns 0 if there are no empty blocks.
 *
 * @return The average light level of this Cuboid
 */
public byte getAverageLightLevel() {
    long total = 0;
    int n = 0;
    for (Block b : this) {
        if (b.isEmpty()) {
            total += b.getLightLevel();
            ++n;
        }
    }
    return n > 0 ? (byte) (total / n) : 0;
}
 
开发者ID:ijoeleoli,项目名称:ZorahPractice,代码行数:17,代码来源:Cuboid.java


注:本文中的org.bukkit.block.Block.isEmpty方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。