當前位置: 首頁>>代碼示例>>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;未經允許,請勿轉載。