本文整理匯總了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()));
}
示例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;
}
示例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);
}
}
}
示例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;
}
示例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());
}
示例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;
}
示例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;
}
示例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);
}
}
}
示例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);
}
}
}
示例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;
}