本文整理汇总了Java中org.bukkit.block.Block类的典型用法代码示例。如果您正苦于以下问题:Java Block类的具体用法?Java Block怎么用?Java Block使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
Block类属于org.bukkit.block包,在下文中一共展示了Block类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: onPistonExtend
import org.bukkit.block.Block; //导入依赖的package包/类
@EventHandler(priority = EventPriority.LOW)
public void onPistonExtend(BlockPistonExtendEvent e) {
if (DEBUG) {
plugin.getLogger().info(e.getEventName());
}
Location pistonLoc = e.getBlock().getLocation();
if (Settings.allowPistonPush || !Util.inWorld(pistonLoc)) {
//plugin.getLogger().info("DEBUG: Not in world");
return;
}
Island island = plugin.getIslands().getProtectedIslandAt(pistonLoc);
if (island == null || !island.onIsland(pistonLoc)) {
//plugin.getLogger().info("DEBUG: Not on is island protection zone");
return;
}
// We need to check where the blocks are going to go, not where they are
for (Block b : e.getBlocks()) {
if (!island.onIsland(b.getRelative(e.getDirection()).getLocation())) {
//plugin.getLogger().info("DEBUG: Block is outside protected area");
e.setCancelled(true);
return;
}
}
}
示例2: walkedOnFence
import org.bukkit.block.Block; //导入依赖的package包/类
/**
* @return if we have walked onto a fence.
*/
public static boolean walkedOnFence(Location location) {
// check if were already under that block.
Location subtracted = location.clone().subtract(0, 1, 0);
Block groundBlock = subtracted.getBlock();
if (MaterialHelper.isFence(groundBlock.getType()) || MaterialHelper.isFenceGate(groundBlock.getType())) {
return true;
}
LocationBit bit = new LocationBit(0.5);
for (int i = 1; i <= 4; i++) {
Location newLocation = location.clone().add(bit.getX(), -1, bit.getZ());
Block block = newLocation.getBlock();
if (MaterialHelper.isFence(block.getType()) || MaterialHelper.isFenceGate(block.getType())) {
return true;
}
bit.shift(i);
}
return false;
}
示例3: onPlayerInteract
import org.bukkit.block.Block; //导入依赖的package包/类
@EventHandler(ignoreCancelled = true, priority = EventPriority.NORMAL)
public void onPlayerInteract(PlayerInteractEvent event) {
if (event.getAction() == Action.RIGHT_CLICK_BLOCK && event.hasItem() && event.getItem().getType() == Material.ENDER_PEARL) {
Block block = event.getClickedBlock();
// Don't prevent opening chests, etc, as these won't throw the Enderpearls anyway
if (block.getType().isSolid() && !(block.getState() instanceof InventoryHolder)) {
Faction factionAt = HCF.getPlugin().getFactionManager().getFactionAt(block.getLocation());
if (!(factionAt instanceof ClaimableFaction)) {
return;
}
event.setCancelled(true);
Player player = event.getPlayer();
player.setItemInHand(event.getItem()); // required to update Enderpearl count
}
}
}
示例4: onBlockBurn
import org.bukkit.block.Block; //导入依赖的package包/类
/**
* So far specifically handles these cases:
*
* 1) Block burnt is tracked
* 2) Block burnt is under a tracked block (probably only mushrooms eligible)
* 3) Block burnt was a jungle tree, checks for cocoa.
* 4) Burnt block had mushroom on top and cocoa on the sides
*
* @param e The event
*/
@EventHandler(priority=EventPriority.HIGHEST, ignoreCancelled = true)
public void onBlockBurn(BlockBurnEvent e) {
Block block = e.getBlock();
if (maybeSideTracked(block)) {
trySideBreak(block, BreakType.FIRE, null);
}
if (maybeBelowTracked(block)) {
block = block.getRelative(BlockFace.UP);
}
Location loc = block.getLocation();
if (!pendingChecks.contains(loc)) {
pendingChecks.add(loc);
handleBreak(block, BreakType.FIRE, null, null);
}
}
示例5: Arena
import org.bukkit.block.Block; //导入依赖的package包/类
public Arena(String name, String worldName, int id, Block sign, List<Map> maps) {
this.name = name;
this.id = id;
this.worldName = worldName;
this.maps = maps;
this.index = 0;
this.signBlock = sign;
this.state = ArenaState.WAITING;
this.schedule = new ArenaSchedule(this);
this.schedule.runTaskTimerAsynchronously(Walls.getInstance(), 0, 20);
registerTeams();
loadWorld();
list.add(this);
}
示例6: reloadWeapons
import org.bukkit.block.Block; //导入依赖的package包/类
@SuppressWarnings("deprecation")
public void reloadWeapons(Player p) {
for (DataBlock dataBlock : craft.dataBlocks) {
Block theBlock = getWorldBlock(dataBlock.x, dataBlock.y, dataBlock.z);
if (theBlock.getTypeId() == 23) {
for (OneCannon onec : AimCannon.getCannons()) {
if (onec.isThisCannon(theBlock.getLocation(), false)) {
onec.reload(p);
}
}
}
}
}
示例7: upElevator
import org.bukkit.block.Block; //导入依赖的package包/类
@EventHandler(priority = EventPriority.HIGH)
public void upElevator(PlayerMoveEvent e) {
Player p = e.getPlayer();
Block b = e.getTo().getBlock().getRelative(BlockFace.DOWN);
if (p.hasPermission("ironelevators.use") && e.getFrom().getY() < e.getTo().getY()
&& b.getType() == elevatorMaterial) {
b = b.getRelative(BlockFace.UP, minElevation);
int i = maxElevation;
while (i > 0 && !(
b.getType() == elevatorMaterial
&& b.getRelative(BlockFace.UP).getType().isTransparent()
&& b.getRelative(BlockFace.UP, 2).getType().isTransparent()
)
) {
i--;
b = b.getRelative(BlockFace.UP);
}
if (i > 0) {
Location l = p.getLocation();
l.setY(l.getY() + maxElevation + 3 - i);
p.teleport(l);
p.getWorld().playSound(p.getLocation(), Sound.ENTITY_IRONGOLEM_ATTACK, 1, 1);
}
}
}
示例8: onPlayerInteract2
import org.bukkit.block.Block; //导入依赖的package包/类
@EventHandler
public void onPlayerInteract2(PlayerInteractEvent e) {
Player player = e.getPlayer();
PlayerInventory inventory = player.getInventory();
if(e.getAction() == Action.RIGHT_CLICK_AIR || e.getAction() == Action.RIGHT_CLICK_BLOCK) {
Material material = inventory.getItemInHand().getType();
if(material == Material.BOW) {
DynamicAC.getManager().getBackend().logBowWindUp(player, System.currentTimeMillis());
} else if(Utilities.isFood(material)) {
DynamicAC.getManager().getBackend().logEatingStart(player);
}
}
Block block = e.getClickedBlock();
if(block != null) {
Distance distance = new Distance(player.getLocation(), block.getLocation());
DynamicAC.getManager().getBackend().checkLongReachBlock(player,distance.getXDifference(),distance
.getYDifference(),distance.getZDifference());
}
}
示例9: onBlockBreak
import org.bukkit.block.Block; //导入依赖的package包/类
@EventHandler
public void onBlockBreak(BlockBreakEvent event) {
if (Walls.getSpectators().contains(event.getPlayer().getName())) {
event.setCancelled(true);
return;
}
if (State.PVP)
return;
Block b = event.getBlock();
if (b == null)
return;
Team team = Team.getTeam(event.getPlayer());
if (b.getX() < team.getMin().getX() + 1 || b.getZ() < team.getMin().getZ() + 1) {
event.setCancelled(true);
}
if (b.getX() > team.getMax().getX() - 1 || b.getZ() > team.getMax().getZ() - 1) {
event.setCancelled(true);
}
}
示例10: clearVisualBlock
import org.bukkit.block.Block; //导入依赖的package包/类
/**
* Clears a visual block at a given location for a player.
*
* @param player
* the player to clear for
* @param location
* the location to clear at
* @param sendRemovalPacket
* if a packet to send a block change should be sent (this is used to prevent unnecessary packets sent when disconnecting or changing worlds, for example)
* @return if the visual block was shown in the first place
*/
public boolean clearVisualBlock(Player player, Location location, boolean sendRemovalPacket) {
synchronized (storedVisualises) {
VisualBlock visualBlock = this.storedVisualises.remove(player.getUniqueId(), location);
if (sendRemovalPacket && visualBlock != null) {
// Have to send a packet to the original block type, don't send if the fake block has the same data properties though.
Block block = location.getBlock();
VisualBlockData visualBlockData = visualBlock.getBlockData();
if (visualBlockData.getBlockType() != block.getType() || visualBlockData.getData() != block.getData()) {
player.sendBlockChange(location, block.getType(), block.getData());
}
return true;
}
}
return false;
}
示例11: hitBlock
import org.bukkit.block.Block; //导入依赖的package包/类
public static boolean hitBlock(Player player, Block block) {
if (player.getGameMode() == GameMode.CREATIVE)
return true;
PlayerBlockTracking playerBlockTracking = getPlayerBlockTracking(player);
if (playerBlockTracking.isBlock(block)) {
return true;
}
long time = playerBlockTracking.getTimeDifference();
playerBlockTracking.incrementHackingIndicator();
playerBlockTracking.setBlock(block);
playerBlockTracking.updateTime();
int decrement = (int) (time / OrebfuscatorConfig.AntiHitHackDecrementFactor);
playerBlockTracking.decrementHackingIndicator(decrement);
if (playerBlockTracking.getHackingIndicator() == OrebfuscatorConfig.AntiHitHackMaxViolation)
playerBlockTracking.incrementHackingIndicator(OrebfuscatorConfig.AntiHitHackMaxViolation);
if (playerBlockTracking.getHackingIndicator() > OrebfuscatorConfig.AntiHitHackMaxViolation)
return false;
return true;
}
示例12: downElevator
import org.bukkit.block.Block; //导入依赖的package包/类
@EventHandler(priority = EventPriority.HIGH)
public void downElevator(PlayerToggleSneakEvent e) {
Player p = e.getPlayer();
Block b = p.getLocation().getBlock().getRelative(BlockFace.DOWN);
if (p.hasPermission("ironelevators.use") && !p.isSneaking()
&& b.getType() == elevatorMaterial) {
b = b.getRelative(BlockFace.DOWN, minElevation);
int i = maxElevation; //16
while (i > 0 && !(
b.getType() == elevatorMaterial
&& b.getRelative(BlockFace.UP).getType().isTransparent()
&& b.getRelative(BlockFace.UP, 2).getType().isTransparent()
)
) {
//e.getPlayer().sendMessage("" + b.getLocation() + b.getType());
i--;
b = b.getRelative(BlockFace.DOWN);
}
if (i > 0) {
Location l = p.getLocation();
l.setY(l.getY() - maxElevation - 3 + i);
p.teleport(l);
p.getWorld().playSound(p.getLocation(), Sound.ENTITY_IRONGOLEM_ATTACK, 1, 1);
}
}
}
示例13: openWorkbench
import org.bukkit.block.Block; //导入依赖的package包/类
public InventoryView openWorkbench(Location location, boolean force) {
if (!force) {
Block block = location.getBlock();
if (block.getType() != Material.WORKBENCH) {
return null;
}
}
if (location == null) {
location = getLocation();
}
getHandle().displayGUIWorkbench(location.getBlockX(), location.getBlockY(), location.getBlockZ());
if (force) {
getHandle().openContainer.checkReachable = false;
}
return getHandle().openContainer.getBukkitView();
}
示例14: countUnsupportedNeighbors
import org.bukkit.block.Block; //导入依赖的package包/类
/**
* Return the number of unsupported blocks connected to any blocks neighboring the given location.
* An air block is placed there temporarily if it is not already air. The search may bail out early
* when the count is >= the given limit, though this cannot be guaranteed.
*/
public int countUnsupportedNeighbors(Block block, int limit) {
BlockState state = null;
if(block.getType() != Material.AIR) {
state = block.getState();
block.setTypeIdAndData(0, (byte) 0, false);
}
int count = countUnsupportedNeighbors(encodePos(block), limit);
if(state != null) {
block.setTypeIdAndData(state.getTypeId(), state.getRawData(), false);
}
return count;
}
示例15: getLineOfSight
import org.bukkit.block.Block; //导入依赖的package包/类
private List<Block> getLineOfSight(HashSet<Byte> transparent, int maxDistance, int maxLength) {
if (maxDistance > 120) {
maxDistance = 120;
}
ArrayList<Block> blocks = new ArrayList<Block>();
Iterator<Block> itr = new BlockIterator(this, maxDistance);
while (itr.hasNext()) {
Block block = itr.next();
blocks.add(block);
if (maxLength != 0 && blocks.size() > maxLength) {
blocks.remove(0);
}
byte id = (byte)block.getTypeId();
if (transparent == null) {
if (id != 0) {
break;
}
} else {
if (!transparent.contains(id)) {
break;
}
}
}
return blocks;
}