本文整理匯總了Java中org.bukkit.block.Block.getLocation方法的典型用法代碼示例。如果您正苦於以下問題:Java Block.getLocation方法的具體用法?Java Block.getLocation怎麽用?Java Block.getLocation使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類org.bukkit.block.Block
的用法示例。
在下文中一共展示了Block.getLocation方法的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。
示例1: 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;
}
示例2: 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);
}
}
示例3: onWoodBreak
import org.bukkit.block.Block; //導入方法依賴的package包/類
@EventHandler
public void onWoodBreak(BlockBreakEvent event) {
final Block b = event.getBlock();
if (b != null && (b.getType() == Material.LOG || b.getType() == Material.LOG_2)) {
Material handType = event.getPlayer().getItemInHand().getType();
if (handType == Material.WOOD_AXE || handType == Material.STONE_AXE || handType == Material.IRON_AXE || handType == Material.GOLD_AXE || handType == Material.DIAMOND_AXE) {
dataMap.put(b, b.getData());
b.setType(Material.WOOL);
b.setData(DyeColor.BLACK.getWoolData());
Player p = event.getPlayer();
event.getPlayer().sendMessage("> +1 Woodcutting EXP");
Location loc = b.getLocation();
Vector v = p.getLocation().subtract(loc).toVector().normalize().multiply(0.5);
DropManager.dropItem(new ItemStack(Material.LOG), loc, event.getPlayer().getUniqueId()).setVelocity(v);
RScheduler.schedule(plugin, () -> {
b.setType(Material.LOG);
b.setData(dataMap.getOrDefault(b, (byte) 0));
}, RTicks.seconds(2));
}
}
}
示例4: onBlockBreak
import org.bukkit.block.Block; //導入方法依賴的package包/類
@EventHandler(ignoreCancelled=true, priority=EventPriority.HIGHEST)
public void onBlockBreak(BlockBreakEvent event)
{
Block block = event.getBlock();
if (isEventSign(block))
{
BlockState state = block.getState();
Sign sign = (Sign)state;
ItemStack stack = new ItemStack(Material.SIGN, 1);
ItemMeta meta = stack.getItemMeta();
meta.setDisplayName(EVENT_SIGN_ITEM_NAME);
meta.setLore(Arrays.asList(sign.getLines()));
stack.setItemMeta(meta);
Player player = event.getPlayer();
World world = player.getWorld();
Location blockLocation = block.getLocation();
if ((player.getGameMode() != GameMode.CREATIVE) && (world.isGameRule("doTileDrops"))) {
world.dropItemNaturally(blockLocation, stack);
}
event.setCancelled(true);
block.setType(Material.AIR);
state.update();
}
}
示例5: trySideBreak
import org.bukkit.block.Block; //導入方法依賴的package包/類
/**
* Propagates cocoa breaks
*
* @param block
* @param type
* @param player
*/
private void trySideBreak(Block block, BreakType type, UUID player) {
for (BlockFace face : directions) {
Block faceBlock = block.getRelative(face);
Location loc = faceBlock.getLocation();
if (Material.COCOA.equals(faceBlock.getType()) && !pendingChecks.contains(loc)) {
pendingChecks.add(loc);
handleBreak(faceBlock, type, player, null);
}
}
}
示例6: onLeafDecay
import org.bukkit.block.Block; //導入方法依賴的package包/類
@EventHandler(priority=EventPriority.HIGHEST, ignoreCancelled = true)
public void onLeafDecay(LeavesDecayEvent e) {
Block block = e.getBlock();
Location loc = block.getLocation();
if (!pendingChecks.contains(loc)) {
pendingChecks.add(loc);
handleBreak(block, BreakType.NATURAL, null, null);
}
}
示例7: 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);
}
}
示例8: cast
import org.bukkit.block.Block; //導入方法依賴的package包/類
@Override
public boolean cast(final Player p, final PlayerDataRPG pd, final int level) {
int damage = pd.getDamage(true);
switch (level) {
case 1:
damage *= 1.2;
break;
case 2:
damage *= 1.4;
break;
case 3:
damage *= 1.6;
break;
case 4:
damage *= 1.9;
break;
case 5:
damage *= 2.2;
break;
case 6:
damage *= 2.6;
break;
case 7:
damage *= 3.0;
break;
case 8:
damage *= 3.5;
break;
}
Block b = p.getTargetBlock((Set<Material>) null, 20);
if (b == null) {
p.sendMessage(ChatColor.RED + "Point at a block to cast Lightning Bolt!");
return false;
}
Location loc = b.getLocation();
RParticles.sendLightning(p, loc);
Spell.damageNearby(damage, p, loc, 2.5, new ArrayList<Entity>());
Spell.notify(p, "You summon a bolt of lightning to strike the ground.");
return true;
}
示例9: onBlockBreak
import org.bukkit.block.Block; //導入方法依賴的package包/類
@EventHandler
public void onBlockBreak(BlockBreakEvent e) {
final Player player = e.getPlayer();
final Block block = e.getBlock();
if(player != null) {
DACManager.getBackend().checkFastBreak(player, block);
Distance distance = new Distance(player.getLocation(),block.getLocation());
DACManager.getBackend().checkLongReachBlock(player,distance.getXDifference(), distance
.getYDifference(),distance.getZDifference());
DACManager.getBackend().logBlockBreak(player);
}
}
示例10: onBlockPistonExtend
import org.bukkit.block.Block; //導入方法依賴的package包/類
@EventHandler
public void onBlockPistonExtend(BlockPistonExtendEvent e) {
//Check if there are cauldrons on activity on pushed blocks
for(Block block : e.getBlocks()) {
Location loc = block.getLocation();
for(UUID uuid : plugin.caulLoc.keySet()) {
Location caul = plugin.caulLoc.get(uuid);
if(caul.getBlock().getLocation().distance(loc) == 0) {
e.setCancelled(true);
return;
}
}
}
}
示例11: onBlockBreak
import org.bukkit.block.Block; //導入方法依賴的package包/類
@EventHandler(ignoreCancelled = true, priority = EventPriority.MONITOR)
public void onBlockBreak(final BlockBreakEvent event) {
final Player player = event.getPlayer();
if(player.getGameMode() == GameMode.CREATIVE) {
return;
}
if(player.getItemInHand().getEnchantments().containsKey(Enchantment.SILK_TOUCH)) return;;
final Block block = event.getBlock();
final Location blockLocation = block.getLocation();
if(block.getType() == FoundDiamondsListener.SEARCH_TYPE && this.foundLocations.add(blockLocation.toString())) {
int count = 1;
for(int x = -5; x < 5; ++x) {
for(int y = -5; y < 5; ++y) {
for(int z = -5; z < 5; ++z) {
final Block otherBlock = blockLocation.clone().add((double) x, (double) y, (double) z).getBlock();
if(!otherBlock.equals(block) && otherBlock.getType() == FoundDiamondsListener.SEARCH_TYPE && this.foundLocations.add(otherBlock.getLocation().toString())) {
++count;
}
}
}
}
String message;
for(Player on : Bukkit.getOnlinePlayers()) {
if(plugin.getFactionManager().getPlayerFaction(player.getUniqueId()) != null) {
message = plugin.getFactionManager().getPlayerFaction(player.getUniqueId()).getRelation(on).toChatColour() + player.getName() + ChatColor.GRAY + " has found " + ChatColor.AQUA + count + ChatColor.GRAY + " diamond(s).";
on.sendMessage(message);
}else{
message = ChatColor.AQUA + "[" + ChatColor.GRAY + "♠" + ChatColor.AQUA + "]" + ChatColor.GRAY + " " + ChatColor.AQUA + player.getName() + ChatColor.GRAY + " has just spotted " + ChatColor.BLUE + count + ChatColor.GRAY +" diamonds!";
on.sendMessage(message);
}
}
}
}
示例12: createCraft
import org.bukkit.block.Block; //導入方法依賴的package包/類
public Craft createCraft(Player player, CraftType craftType, int x, int y, int z, String name, float dr, Block signBlock, boolean autoShip) {
//if( npcMerchantThread == null )
//npcMerchantThread();
if (DebugMode == true)
player.sendMessage("Attempting to create " + craftType.name
+ "at coordinates " + Integer.toString(x) + ", "
+ Integer.toString(y) + ", " + Integer.toString(z));
if( signBlock == null )
signBlock = player.getLocation().getBlock();
Craft craft = new Craft(craftType, player, name, dr, signBlock.getLocation(), this);
// auto-detect and create the craft
if (!CraftBuilder.detect(craft, x, y, z, autoShip)) {
return null;
}
if( autoShip )
craft.captainName = null;
CraftMover cm = new CraftMover(craft, this);
cm.structureUpdate(null,false);
Craft.addCraftList.add(craft);
//craft.cloneCraft();
if( craft.type.canFly )
{
craft.type.maxEngineSpeed = 10;
}else if( craft.type.isTerrestrial )
{
craft.type.maxEngineSpeed = 4;
}else
{
craft.type.maxEngineSpeed = 6;
}
if( checkSpawnRegion(new Location(craft.world, craft.minX, craft.minY, craft.minZ)) || checkSpawnRegion(new Location(craft.world, craft.maxX, craft.maxY, craft.maxZ)) )
{
craft.speedChange(player, true);
}
if( !autoShip )
{
craft.driverName = craft.captainName;
if(craft.type.listenItem == true)
player.sendMessage(ChatColor.GRAY + "With a gold sword in your hand, right-click in the direction you want to go.");
if(craft.type.listenAnimation == true)
player.sendMessage(ChatColor.GRAY + "Swing your arm in the direction you want to go.");
if(craft.type.listenMovement == true)
player.sendMessage(ChatColor.GRAY + "Move in the direction you want to go.");
}
return craft;
}
示例13: returnUpwardsBlocks
import org.bukkit.block.Block; //導入方法依賴的package包/類
public Set<Location> returnUpwardsBlocks(Block startBlock, Material upwardBlockMaterial) {
Set<Location> checkedLocations = new HashSet<Location>();
Set<Location> uncheckedLocations = new HashSet<Location>();
Crop crop = CropControl.getDAO().getChunk(startBlock.getChunk()).getCrop(startBlock.getX(), startBlock.getY(), startBlock.getZ());
if (crop != null) {
if (getTrackedCropMaterial(crop.getCropType()) == upwardBlockMaterial) {
uncheckedLocations.add(startBlock.getLocation());
}
} else {
return checkedLocations; // failfast
}
Set<Location> toAddLocations = new HashSet<Location>();
do {
for (Location unchecked : uncheckedLocations) {
if (CropControl.getDAO().isTracked(unchecked.getBlock())
&& !checkedLocations.contains(unchecked)) {
checkedLocations.add(unchecked);
}
}
for (Location location : uncheckedLocations) {
Block upBlock = location.getBlock().getRelative(BlockFace.UP);
Location up = upBlock.getLocation();
if (CropControl.getDAO().isTracked(upBlock)
&& !toAddLocations.contains(up)
&& !checkedLocations.contains(up)) {
if (getTrackedCropMaterial(
CropControl.getDAO().getChunk(upBlock.getChunk()).getCrop(upBlock.getX(), upBlock.getY(), upBlock.getZ())
.getCropType()) == upwardBlockMaterial)
toAddLocations.add(up);
}
}
uncheckedLocations.clear();
uncheckedLocations.addAll(toAddLocations);
toAddLocations.clear();
} while (!uncheckedLocations.isEmpty());
return checkedLocations;
}
示例14: from
import org.bukkit.block.Block; //導入方法依賴的package包/類
public static Position from(Block block) {
return new Position(block.getLocation());
}
示例15: pasteSchematic
import org.bukkit.block.Block; //導入方法依賴的package包/類
private static ArrayList<Object[]> pasteSchematic(Player p, World world, Location loc, Schematic schematic, int xoffset, int yoffset, int zoffset, boolean air) {
short[] blocks = schematic.getBlocks();
byte[] blockData = schematic.getData();
short width = schematic.getWidth();
short length = schematic.getLength();
short height = schematic.getHeight();
loc.setX(loc.getX() - width / 2);
loc.setZ(loc.getZ() - length / 2);
ArrayList<Object[]> hist = new ArrayList<Object[]>();
for (int x = 0; x < width; ++x) {
for (int y = 0; y < height; ++y) {
for (int z = 0; z < length; ++z) {
try {
int index = (y * length + z) * width + x;
Block block = new Location(world, loc.getX() + x + xoffset, loc.getY() + y + yoffset, loc.getZ() + z + zoffset).getBlock();
// if (!air && blocks[index] == 0)
// continue;
if (getConfig(p).filter.contains(Material.getMaterial(blocks[index])))
continue;
Object[] o = new Object[6];
o[0] = block.getWorld();
o[1] = block.getLocation();
o[2] = block.getType();
o[3] = block.getData();
block.setType(Material.AIR);
block.setType(Material.getMaterial(blocks[index]));
block.setData(blockData[index]);
o[4] = block.getType();
o[5] = block.getData();
hist.add(o);
} catch (Exception e) {
e.printStackTrace();
}
}
}
}
return hist;
}