本文整理汇总了Java中org.bukkit.block.Block.getRelative方法的典型用法代码示例。如果您正苦于以下问题:Java Block.getRelative方法的具体用法?Java Block.getRelative怎么用?Java Block.getRelative使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类org.bukkit.block.Block
的用法示例。
在下文中一共展示了Block.getRelative方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: onBlockBreak
import org.bukkit.block.Block; //导入方法依赖的package包/类
/**
* So far specifically handles these cases:
*
* 1) Block broken is tracked
* 2) Block breaks by not-players
* 3) Block breaks by players
* 4) Indirect block breaks -- destroying block supporting a crop or collapsible tree, or under mushrooms
* 5) Indirect block break of cocoa bearing logs
* 6) Block broken had mushroom on top and cocoa on the sides
*
* @param e The event
*/
@EventHandler(priority=EventPriority.HIGHEST, ignoreCancelled = true)
public void onBlockBreak(BlockBreakEvent e) {
Block block = e.getBlock();
Player player = e.getPlayer();
BreakType type = player != null ? BreakType.PLAYER : BreakType.NATURAL;
UUID uuid = player != null ? player.getUniqueId() : null;
if (maybeSideTracked(block)) {
trySideBreak(block, type, uuid);
}
if (maybeBelowTracked(block)) {
block = block.getRelative(BlockFace.UP);
}
Location loc = block.getLocation();
if (!pendingChecks.contains(loc)) {
pendingChecks.add(loc);
handleBreak(block, type, uuid, null);
}
}
示例2: 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);
}
}
示例3: isShopBlockNearby
import org.bukkit.block.Block; //导入方法依赖的package包/类
private boolean isShopBlockNearby(Block b) {
if (b == null) {
return false;
}
Block nearChest = null;
if (b.getType() == Material.CHEST) {
nearChest = getBlockNearby(b, Material.CHEST);
} else if (b.getType() == Material.TRAPPED_CHEST) {
nearChest = getBlockNearby(b, Material.TRAPPED_CHEST);
}
if (nearChest == null) {
return false;
}
for (BlockFace face : BLOCKFACE) {
Block maybeSign = nearChest.getRelative(face);
if (maybeSign != null && Material.WALL_SIGN == maybeSign.getType()) {
Sign sign = (Sign) maybeSign.getState();
if (sign.getLines().length > 0 && sign.getLines()[0].contains(cm.quickshopSignFlag)) {
return true;
}
}
}
return false;
}
示例4: 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);
}
}
}
示例5: updateSign
import org.bukkit.block.Block; //导入方法依赖的package包/类
public void updateSign(int gameNumber) {
GameSign gameSign = signJoinGames.get(gameNumber);
if (gameSign != null) {
World world = SkyWarsReloaded.get().getServer().getWorld(gameSign.getWorld());
if (world != null) {
Block b = world.getBlockAt(gameSign.getX(), gameSign.getY(), gameSign.getZ());
if(b.getType() == Material.WALL_SIGN || b.getType() == Material.SIGN_POST) {
Sign s = (Sign) b.getState();
meteSign = (org.bukkit.material.Sign) b.getState().getData();
Block attachedBlock = b.getRelative(meteSign.getAttachedFace());
String state = getStatusName(getGame(gameNumber));
setMaterial(getStatus(getGame(gameNumber)), attachedBlock);
int max = getGame(gameNumber).getNumberOfSpawns();
int count = getGame(gameNumber).getPlayers().size();
if (s != null) {
s.getBlock().getChunk().load();
s.setLine(0, new Messaging.MessageFormatter().format("signJoinSigns.line1"));
s.setLine(1, new Messaging.MessageFormatter().setVariable("mapName", gameSign.getName().toUpperCase()).format("signJoinSigns.line2"));
s.setLine(2, new Messaging.MessageFormatter().setVariable("gameStatus", state).format("signJoinSigns.line3"));
s.setLine(3, new Messaging.MessageFormatter().setVariable("count", "" + count).setVariable("max", "" + max).format("signJoinSigns.line4"));
s.update();
}
}
}
}
}
示例6: onBlockClick
import org.bukkit.block.Block; //导入方法依赖的package包/类
@SuppressWarnings("deprecation")
@Override
public void onBlockClick(PlayerInteractEvent evt, Block bk, boolean rightClick) {
if (!canTrigger() || MetadataManager.updateCooldownSilently(evt.getPlayer(), "lazerBk", 2))
return;
int y = getGateLocation().getBlockY();
Block above = bk.getRelative(BlockFace.UP);
if (isPuzzle(bk, y, Material.WOOL) && above.getType() == Material.AIR && rightClick) {
above.setType(Material.DIODE_BLOCK_OFF);
above.setData((byte) 0);
}
// Remove the next
if (isPuzzle(bk, y + 1, Material.DIODE_BLOCK_OFF)) {
if (!rightClick) {
bk.setType(Material.AIR);
return;
}
bk.setData((byte) (bk.getData() >= 3 ? 0 : bk.getData() + 1));
evt.setCancelled(true);
}
}
示例7: getAttachedBlock
import org.bukkit.block.Block; //导入方法依赖的package包/类
private Block getAttachedBlock(Block block) {
MaterialData data = block.getState().getData();
if (data instanceof Attachable) {
return block.getRelative(((Attachable) data).getAttachedFace());
}
return null;
}
示例8: onEntityChangeBlock
import org.bukkit.block.Block; //导入方法依赖的package包/类
@EventHandler(priority=EventPriority.HIGHEST, ignoreCancelled = true)
public void onEntityChangeBlock(EntityChangeBlockEvent e) {
Block block = e.getBlock();
if (maybeSideTracked(block)) {
trySideBreak(block, BreakType.NATURAL, null);
}
if (maybeBelowTracked(block)) {
block = block.getRelative(BlockFace.UP);
}
Location loc = block.getLocation();
if (!pendingChecks.contains(loc)) {
pendingChecks.add(loc);
handleBreak(block, BreakType.NATURAL, null, null);
}
}
示例9: onPlayerLeaverInteract
import org.bukkit.block.Block; //导入方法依赖的package包/类
@EventHandler
public void onPlayerLeaverInteract(PlayerInteractEvent e) {
Player p = e.getPlayer();
Block clicked = e.getClickedBlock();
if (clicked == null)
return;
Block underneath = clicked.getRelative(BlockFace.DOWN);
Location underneathLoc = underneath.getLocation();
if (e.getAction() != Action.RIGHT_CLICK_BLOCK || e.getHand() == EquipmentSlot.OFF_HAND)
return;
if (clicked.getType() != Material.LEVER || underneath == null)
return;
String chunk = clicked.getLocation().getChunk().getX() + ";" + clicked.getLocation().getChunk().getZ();
if (underneath.getType() == Material.SPONGE && !underneath.isBlockPowered()) {
if (!main.getGeckManager().isGeckBuildCorrect(underneath)) {
p.sendMessage(ChatColor.RED + "You must build the GECK correctly!");
// Check if the geck is inside the powerables list
} else if (main.getGenListener().getPowerable().get(clicked.getWorld().getName()).getList(chunk)
.contains(underneathLoc)) {
main.getGeckObjectManager().addGeckLocation(underneathLoc);
main.getGeckObjectManager().getGeckObject(underneathLoc).setCorrect(true);
main.getGeckObjectManager().getGeckObject(underneathLoc).setPowered(true);
p.sendMessage(ChatColor.GREEN + "GECK Enabled!");
return;
}
} else if (main.getGeckObjectManager().getGeckObject(underneathLoc) != null && underneath.isBlockPowered()) {
main.getGeckObjectManager().getGeckObject(underneathLoc).setPowered(false);
main.getGeckObjectManager().removeGeckLocation(underneathLoc);
p.sendMessage(ChatColor.RED + "GECK Disabled!");
}
}
示例10: onBlockPistonRetract
import org.bukkit.block.Block; //导入方法依赖的package包/类
@EventHandler(priority = EventPriority.MONITOR, ignoreCancelled = true)
public void onBlockPistonRetract(BlockPistonRetractEvent event) {
if(!this.tracker.isEnabled(event.getBlock().getWorld())) return;
if(event.isSticky()) {
Block newBlock = event.getBlock().getRelative(event.getDirection());
Block oldBlock = newBlock.getRelative(event.getDirection());
Player player = this.tracker.getPlacer(oldBlock);
if(player != null) {
this.tracker.setPlacer(oldBlock, null);
this.tracker.setPlacer(newBlock, player);
}
}
}
示例11: 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);
}
}
}
示例12: onPlayerMove
import org.bukkit.block.Block; //导入方法依赖的package包/类
@EventHandler(ignoreCancelled = true)
public void onPlayerMove(PlayerMoveEvent event) {
Player p = event.getPlayer();
Location to = event.getTo();
Location from = event.getFrom();
World world = to.getWorld();
if (to.clone().add(0, -1, 0).getBlock().getType() != Material.REDSTONE_LAMP_ON)
return;
if (from.clone().add(0, -1, 0).getBlock().getType() == Material.REDSTONE_LAMP_ON)
return;
for (Block block : getPortalNear(world, to.getBlockX(), to.getBlockY(), to.getBlockZ())) {
for (BlockFace bf : BlockFace.values()) {
Block relative = block.getRelative(bf);
if (relative.getTypeId() == SIGN) {
// Specific server
Sign sign = (Sign) relative.getState();
Portal portal = null;
for (Portal po : Portal.getList()) {
if (WorldUtil.sameBlock(po.getSign().getBlock(), sign.getBlock())) {
portal = po;
break;
}
}
if (portal == null)
return;
if (portal.getCurrent().getStatus() == Status.CLOSED)
Chat.player(p, "&cThat server is currently unavailable!");
else
portal.getCurrent().connect(event.getPlayer());
portal.updateSign();
}
}
}
}
示例13: getAttachedBlock
import org.bukkit.block.Block; //导入方法依赖的package包/类
public static Block getAttachedBlock(Block block) {
if (isSign(block)) {
org.bukkit.material.Sign sign = (org.bukkit.material.Sign) block.getState().getData();
return block.getRelative(sign.getAttachedFace());
}
return null;
}
示例14: 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());
}
示例15: getRelativeBlockOfDuct
import org.bukkit.block.Block; //导入方法依赖的package包/类
/**
* gets the neighbor block of the duct (where a block would be placed if right clicked) (calculated by the player direction ray
* and the duct hitbox)
*/
public static Block getRelativeBlockOfDuct(Player p, Block ductLoc) {
Duct duct = DuctUtils.getDuctAtLocation(ductLoc.getLocation());
if(duct == null) {
return null;
}
WrappedDirection pd = TransportPipes.instance.ductManager.getPlayerRenderSystem(p, duct.getDuctType()).getClickedDuctFace(p, duct);
return pd != null ? ductLoc.getRelative(pd.toBlockFace()) : null;
}