org.bukkit.Location#getBlock ( )源码实例Demo

下面列出了org.bukkit.Location#getBlock ( ) 实例代码,或者点击链接到github查看源代码,也可以在右侧发表评论。

源代码1 项目: ProjectAres   文件: PlayerMovementListener.java
/**
 * Modify the to location of the given event to prevent the movement and
 * move the player so they are standing on the center of the block at the
 * from location.
 */
private static void resetPosition(final PlayerMoveEvent event) {
    Location newLoc;
    double yValue = event.getFrom().getY();

    if(yValue <= 0 || event instanceof PlayerTeleportEvent) {
        newLoc = event.getFrom();
    } else {
        newLoc = BlockUtils.center(event.getFrom()).subtract(new Vector(0, 0.5, 0));
        if(newLoc.getBlock() != null) {
            switch(newLoc.getBlock().getType()) {
            case STEP:
            case WOOD_STEP:
                newLoc.add(new Vector(0, 0.5, 0));
                break;
            default: break;
            }
        }
    }

    newLoc.setPitch(event.getTo().getPitch());
    newLoc.setYaw(event.getTo().getYaw());
    event.setCancelled(false);
    event.setTo(newLoc);
}
 
源代码2 项目: FastAsyncWorldedit   文件: FaweAdapter_1_11.java
public BaseBlock getBlock(Location location)
{
    Preconditions.checkNotNull(location);

    CraftWorld craftWorld = (CraftWorld)location.getWorld();
    int x = location.getBlockX();
    int y = location.getBlockY();
    int z = location.getBlockZ();

    Block bukkitBlock = location.getBlock();
    BaseBlock block = new BaseBlock(bukkitBlock.getTypeId(), bukkitBlock.getData());

    TileEntity te = craftWorld.getHandle().getTileEntity(new BlockPosition(x, y, z));
    if (te != null)
    {
        NBTTagCompound tag = new NBTTagCompound();
        readTileEntityIntoTag(te, tag);
        block.setNbtData((CompoundTag)toNative(tag));
    }
    return block;
}
 
源代码3 项目: FastAsyncWorldedit   文件: FaweAdapter_1_10.java
public BaseBlock getBlock(Location location)
{
    Preconditions.checkNotNull(location);

    CraftWorld craftWorld = (CraftWorld)location.getWorld();
    int x = location.getBlockX();
    int y = location.getBlockY();
    int z = location.getBlockZ();

    Block bukkitBlock = location.getBlock();
    BaseBlock block = new BaseBlock(bukkitBlock.getTypeId(), bukkitBlock.getData());

    TileEntity te = craftWorld.getHandle().getTileEntity(new BlockPosition(x, y, z));
    if (te != null)
    {
        NBTTagCompound tag = new NBTTagCompound();
        readTileEntityIntoTag(te, tag);
        block.setNbtData((CompoundTag)toNative(tag));
    }
    return block;
}
 
源代码4 项目: HeavySpleef   文件: FlagShowBarriers.java
private void calculateSpawnLocations() {
	spawningBarriers.clear();
	
	for (Floor floor : game.getFloors()) {
		Region region = floor.getRegion();
		RegionIterator iterator = new RegionIterator(region);
		
		while (iterator.hasNext()) {
			BlockVector vector = iterator.next();
			Location location = BukkitUtil.toLocation(game.getWorld(), vector);
			Block block = location.getBlock();
			if (block.getType() != Material.BARRIER) {
				continue;
			}
			
			spawningBarriers.add(vector.add(0.5, 0.5, 0.5));
		}
	}
	
	Collections.shuffle(spawningBarriers);
}
 
源代码5 项目: ProjectAres   文件: LaneMatchModule.java
private static boolean isIllegallyOutsideLane(Region lane, Location loc) {
    Block feet = loc.getBlock();
    if(feet == null) return false;

    if(isIllegalBlock(lane, feet)) {
        return true;
    }

    Block head = feet.getRelative(BlockFace.UP);
    if(head == null) return false;

    if(isIllegalBlock(lane, head)) {
        return true;
    }

    return false;
}
 
源代码6 项目: Crazy-Crates   文件: NMS_v1_10_R1.java
@Override
public void pasteSchematic(File f, Location loc) {
    loc = loc.subtract(2, 1, 2);
    try {
        FileInputStream fis = new FileInputStream(f);
        NBTTagCompound nbt = NBTCompressedStreamTools.a(fis);
        short width = nbt.getShort("Width");
        short height = nbt.getShort("Height");
        short length = nbt.getShort("Length");
        byte[] blocks = nbt.getByteArray("Blocks");
        byte[] data = nbt.getByteArray("Data");
        fis.close();
        //paste
        for (int x = 0; x < width; ++x) {
            for (int y = 0; y < height; ++y) {
                for (int z = 0; z < length; ++z) {
                    int index = y * width * length + z * width + x;
                    final Location l = new Location(loc.getWorld(), x + loc.getX(), y + loc.getY(), z + loc.getZ());
                    int b = blocks[index] & 0xFF;//make the block unsigned, so that blocks with an id over 127, like quartz and emerald, can be pasted
                    final Block block = l.getBlock();
                    block.setType(Material.getMaterial(b));
                    block.setData(data[index]);
                    //you can check what type the block is here, like if(m.equals(Material.BEACON)) to check if it's a beacon
                }
            }
        }
    } catch (Exception e) {
        e.printStackTrace();
    }
}
 
源代码7 项目: ZombieEscape   文件: Section.java
/**
 * Clears any and all blocks between the corners. NOTE: This
 * can be a very expensive call. However, we anticipate most
 * doors to be small, and therefore inexpensive by and large.
 */
public void clear() {
    for (int x = minX; x <= maxX; x++) {
        for (int y = minY; y <= maxY; y++) {
            for (int z = minZ; z <= this.maxZ; z++) {
                Location loc = new Location(world, x, y, z);
                Block block = loc.getBlock();
                if (block != null) {
                    blocks.put(loc, new SectionBlock(block.getType(), block.getData()));
                    loc.getBlock().setType(Material.AIR);
                }
            }
        }
    }
}
 
源代码8 项目: CombatLogX   文件: ForceField.java
@SuppressWarnings("deprecation")
private void resetBlock(Player player, Location location) {
    Block block = location.getBlock();
    if(VersionUtil.getMinorVersion() >= 13) {
        player.sendBlockChange(location, block.getBlockData());
        return;
    }

    player.sendBlockChange(location, block.getType(), block.getData());
}
 
源代码9 项目: PGM   文件: FireworkMatchModule.java
public static Location getOpenSpaceAbove(Location location) {
  Preconditions.checkNotNull(location, "location");

  Location result = location.clone();
  while (true) {
    Block block = result.getBlock();
    if (block == null || block.getType() == Material.AIR) break;

    result.setY(result.getY() + 1);
  }

  return result;
}
 
源代码10 项目: PGM   文件: Flag.java
public boolean canDropAt(Location location) {
  Block block = location.getBlock();
  Block below = block.getRelative(BlockFace.DOWN);
  if (!canDropOn(below.getState())) return false;
  if (block.getRelative(BlockFace.UP).getType() != Material.AIR) return false;

  switch (block.getType()) {
    case AIR:
    case LONG_GRASS:
      return true;
    default:
      return false;
  }
}
 
源代码11 项目: civcraft   文件: Template.java
public void buildConstructionScaffolding(Location center, Player player) 
{
	//this.buildScaffolding(center);
	
	Block block = center.getBlock();
	ItemManager.setTypeIdAndData(block, ItemManager.getId(Material.CHEST), 0, false);
}
 
源代码12 项目: worldedit-adapters   文件: Spigot_v1_15_R2.java
@Override
public BaseBlock getBlock(Location location) {
    checkNotNull(location);

    CraftWorld craftWorld = ((CraftWorld) location.getWorld());
    int x = location.getBlockX();
    int y = location.getBlockY();
    int z = location.getBlockZ();

    final WorldServer handle = craftWorld.getHandle();
    Chunk chunk = handle.getChunkAt(x >> 4, z >> 4);
    final BlockPosition blockPos = new BlockPosition(x, y, z);
    final IBlockData blockData = chunk.getType(blockPos);
    int internalId = Block.getCombinedId(blockData);
    BlockState state = BlockStateIdAccess.getBlockStateById(internalId);
    if (state == null) {
        org.bukkit.block.Block bukkitBlock = location.getBlock();
        state = BukkitAdapter.adapt(bukkitBlock.getBlockData());
    }

    // Read the NBT data
    TileEntity te = chunk.a(blockPos, Chunk.EnumTileEntityState.CHECK);
    if (te != null) {
        NBTTagCompound tag = new NBTTagCompound();
        readTileEntityIntoTag(te, tag); // Load data
        return state.toBaseBlock((CompoundTag) toNative(tag));
    }

    return state.toBaseBlock();
}
 
源代码13 项目: askyblock   文件: WarpSigns.java
/**
 * Changes the sign to red if it exists
 * @param loc
 */
private void popSign(Location loc) {
    Block b = loc.getBlock();
    if (b.getType().equals(Material.SIGN_POST) || b.getType().equals(Material.WALL_SIGN)) {
        Sign s = (Sign) b.getState();
        if (s != null) {
            if (s.getLine(0).equalsIgnoreCase(ChatColor.GREEN + plugin.myLocale().warpswelcomeLine)) {
                s.setLine(0, ChatColor.RED + plugin.myLocale().warpswelcomeLine);
                s.update(true, false);
            }
        }
    }
}
 
源代码14 项目: Crazy-Crates   文件: NMS_v1_11_R1.java
@Override
public void pasteSchematic(File f, Location loc) {
    loc = loc.subtract(2, 1, 2);
    try {
        FileInputStream fis = new FileInputStream(f);
        NBTTagCompound nbt = NBTCompressedStreamTools.a(fis);
        short width = nbt.getShort("Width");
        short height = nbt.getShort("Height");
        short length = nbt.getShort("Length");
        byte[] blocks = nbt.getByteArray("Blocks");
        byte[] data = nbt.getByteArray("Data");
        fis.close();
        //paste
        for (int x = 0; x < width; ++x) {
            for (int y = 0; y < height; ++y) {
                for (int z = 0; z < length; ++z) {
                    int index = y * width * length + z * width + x;
                    final Location l = new Location(loc.getWorld(), x + loc.getX(), y + loc.getY(), z + loc.getZ());
                    int b = blocks[index] & 0xFF;//make the block unsigned, so that blocks with an id over 127, like quartz and emerald, can be pasted
                    final Block block = l.getBlock();
                    block.setType(Material.getMaterial(b));
                    block.setData(data[index]);
                    //you can check what type the block is here, like if(m.equals(Material.BEACON)) to check if it's a beacon
                }
            }
        }
    } catch (Exception e) {
        e.printStackTrace();
    }
}
 
源代码15 项目: Hawk   文件: BlockInteractOcclusion.java
@Override
protected void check(InteractWorldEvent e) {
    HawkPlayer pp = e.getHawkPlayer();
    Vector eyePos = pp.getPosition().clone().add(new Vector(0, pp.isSneaking() ? 1.54 : 1.62, 0));
    Vector direction = MathPlus.getDirection(pp.getYaw(), pp.getPitch());

    Location bLoc = e.getTargetedBlockLocation();
    Block b = bLoc.getBlock();
    WrappedBlock bNMS = WrappedBlock.getWrappedBlock(b, pp.getClientVersion());
    AABB targetAABB = new AABB(bNMS.getHitBox().getMin(), bNMS.getHitBox().getMax());

    double distance = targetAABB.distanceToPosition(eyePos);
    BlockIterator iter = new BlockIterator(pp.getWorld(), eyePos, direction, 0, (int) distance + 2);
    while (iter.hasNext()) {
        Block bukkitBlock = iter.next();

        if (bukkitBlock.getType() == Material.AIR || bukkitBlock.isLiquid())
            continue;
        if (bukkitBlock.getLocation().equals(bLoc))
            break;

        WrappedBlock iterBNMS = WrappedBlock.getWrappedBlock(bukkitBlock, pp.getClientVersion());
        AABB checkIntersection = new AABB(iterBNMS.getHitBox().getMin(), iterBNMS.getHitBox().getMax());
        Vector occludeIntersection = checkIntersection.intersectsRay(new Ray(eyePos, direction), 0, Float.MAX_VALUE);
        if (occludeIntersection != null) {
            if (occludeIntersection.distance(eyePos) < distance) {
                Placeholder ph = new Placeholder("type", iterBNMS.getBukkitBlock().getType());
                punishAndTryCancelAndBlockRespawn(pp, 1, e, ph);
                return;
            }
        }
    }
}
 
源代码16 项目: PGM   文件: Materials.java
static Material materialAt(Location location) {
  Block block = location.getBlock();
  return block == null ? Material.AIR : block.getType();
}
 
源代码17 项目: HeavySpleef   文件: FlagFireworks.java
@Subscribe
public void onPlayerWinGame(PlayerWinGameEvent event) {
	for (Location location : getValue()) {
		int amount = random.nextInt(3) + 3;
		
		for (int i = 0; i < amount; i++) {
			Location spawn;
			
			int trys = 0;
			do {
				int x = random.nextInt(8) - 4;
				int y = random.nextInt(8) - 4;
				int z = random.nextInt(8) - 4;
				
				spawn = location.clone().add(x, y, z);
				Block block = spawn.getBlock();
				
				if (!block.isLiquid() && block.getType() != Material.AIR) {
					//Do another search
					spawn = null;
				}
			} while (spawn == null && ++trys < MAX_TRYS);
			
			if (spawn == null) {
				continue;
			}
			
			Firework firework = (Firework) spawn.getWorld().spawnEntity(spawn, EntityType.FIREWORK);
			FireworkMeta meta = firework.getFireworkMeta();
			
			Type type = typeValues.get(random.nextInt(typeValues.size()));
			Color c1 = colorValues.get(random.nextInt(colorValues.size()));
			Color c2 = colorValues.get(random.nextInt(colorValues.size()));

			FireworkEffect effect = FireworkEffect.builder()
					.flicker(random.nextBoolean())
					.withColor(c1)
					.withFade(c2)
					.with(type)
					.trail(random.nextBoolean())
					.build();

			meta.addEffect(effect);

			int rp = random.nextInt(3);
			meta.setPower(rp);

			firework.setFireworkMeta(meta);  
		}
	}
}
 
源代码18 项目: ArmorStandTools   文件: Utils.java
static Block findAnAirBlock(Location l) {
    while(l.getY() < 255 && l.getBlock().getType() != Material.AIR) {
        l.add(0, 1, 0);
    }
    return l.getY() < 255 && l.getBlock().getType() == Material.AIR ? l.getBlock() : null;
}
 
源代码19 项目: Hawk   文件: ServerUtils.java
public static Block getBlockAsync(Location loc) {
    if (loc.getWorld().isChunkLoaded(loc.getBlockX() >> 4, loc.getBlockZ() >> 4))
        return loc.getBlock();
    return null;
}
 
源代码20 项目: ce   文件: Explosive.java
@Override
public void effect(Event e, ItemStack item, int level) {
    BlockBreakEvent event = (BlockBreakEvent) e;
    Player player = event.getPlayer();

    if (!isUsable(player.getItemInHand().getType().toString(), event.getBlock().getType().toString()))
        return;

    List<Location> locations = new ArrayList<Location>();

    int locRad = Radius;
    if (LargerRadius && Tools.random.nextInt(100) < level * 5)
        locRad += 2;
    int r = locRad - 1;
    int start = r / 2;

    Location sL = event.getBlock().getLocation();

    player.getWorld().createExplosion(sL, 0f); // Create a fake explosion

    sL.setX(sL.getX() - start);
    sL.setY(sL.getY() - start);
    sL.setZ(sL.getZ() - start);

    for (int x = 0; x < locRad; x++)
        for (int y = 0; y < locRad; y++)
            for (int z = 0; z < locRad; z++)
                if ((!(x == 0 && y == 0 && z == 0)) && (!(x == r && y == 0 && z == 0)) && (!(x == 0 && y == r && z == 0)) && (!(x == 0 && y == 0 && z == r)) && (!(x == r && y == r && z == 0))
                        && (!(x == 0 && y == r && z == r)) && (!(x == r && y == 0 && z == r)) && (!(x == r && y == r && z == r)))
                    locations.add(new Location(sL.getWorld(), sL.getX() + x, sL.getY() + y, sL.getZ() + z));

    for (Location loc : locations) {
        String iMat = item.getType().toString();
        Block b = loc.getBlock();
        String bMat = b.getType().toString();

        if (isUsable(iMat, bMat))
            if (!loc.getBlock().getDrops(item).isEmpty())
                if (Tools.checkWorldGuard(loc, player, "BUILD", false))
                    if (DropItems)
                        loc.getBlock().breakNaturally(item);
                    else
                        for (ItemStack i : loc.getBlock().getDrops(item)) {
                            player.getInventory().addItem(i);
                            loc.getBlock().setType(Material.AIR);
                        }
    }

}