Java Code Examples for org.bukkit.Location#getBlockY()

The following examples show how to use org.bukkit.Location#getBlockY() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: SpleefTracker.java    From CardinalPGM with MIT License 6 votes vote down vote up
@EventHandler(priority = EventPriority.MONITOR)
public void onBlockBreak(BlockBreakEvent event) {
    if (event.isCancelled() || GameHandler.getGameHandler().getMatch().getModules().getModule(TitleRespawn.class).isDeadUUID(event.getPlayer().getUniqueId())) return;
    for (Player player : Bukkit.getOnlinePlayers()) {
        Location location = event.getBlock().getLocation();
        location.setY(location.getY() + 1);
        Location playerLoc = player.getLocation();
        if (playerLoc.getBlockX() == location.getBlockX() && playerLoc.getBlockY() == location.getBlockY() && playerLoc.getBlockZ() == location.getBlockZ()) {
            Description description = null;
            if (player.getLocation().add(new Vector(0, 1, 0)).getBlock().getType().equals(Material.LADDER)) {
                description = Description.OFF_A_LADDER;
            } else if (player.getLocation().add(new Vector(0, 1, 0)).getBlock().getType().equals(Material.VINE)) {
                description = Description.OFF_A_VINE;
            } else if (player.getLocation().getBlock().getType().equals(Material.WATER) || player.getLocation().getBlock().getType().equals(Material.STATIONARY_WATER)) {
                description = Description.OUT_OF_THE_WATER;
            } else if (player.getLocation().getBlock().getType().equals(Material.LAVA) || player.getLocation().getBlock().getType().equals(Material.STATIONARY_LAVA)) {
                description = Description.OUT_OF_THE_LAVA;
            }
            Bukkit.getServer().getPluginManager().callEvent(new TrackerDamageEvent(player, event.getPlayer(), event.getPlayer().getItemInHand(), Cause.PLAYER, description, Type.SPLEEFED));
        }
    }
}
 
Example 2
Source File: MoveEvent.java    From MCAuthenticator with GNU General Public License v3.0 6 votes vote down vote up
@EventHandler(priority = EventPriority.LOWEST)
public void onPlayerMove(PlayerMoveEvent event) {
    Location from = event.getFrom();
    Location to = event.getTo();

    if (from.getBlockX() == to.getBlockX()
            && from.getBlockY() == to.getBlockY()
            && from.getBlockZ() == to.getBlockZ()) {
        return;
    }

    Player player = event.getPlayer();
    User u = instance.getCache().get(player.getUniqueId());

    if (u != null && u.authenticated()) return;

    event.setTo(from);
}
 
Example 3
Source File: SelectionHolder.java    From AstralEdit with Apache License 2.0 6 votes vote down vote up
/**
 * Calculates the downLocation
 *
 * @param corner1 corner1
 * @param corner2 corner2
 */
private void calculateDownLocation(Location corner1, Location corner2) {
    final int x;
    if (corner1.getBlockX() < corner2.getBlockX()) {
        x = corner1.getBlockX();
    } else {
        x = corner2.getBlockX();
    }
    final int y;
    if (corner1.getBlockY() < corner2.getBlockY()) {
        y = corner1.getBlockY();
    } else {
        y = corner2.getBlockY();
    }
    final int z;
    if (corner1.getBlockZ() < corner2.getBlockZ()) {
        z = corner1.getBlockZ();
    } else {
        z = corner2.getBlockZ();
    }
    this.downCorner = new LocationBuilder(new Location(corner1.getWorld(), x, y, z));
}
 
Example 4
Source File: CEListener.java    From ce with GNU Lesser General Public License v3.0 6 votes vote down vote up
@EventHandler(priority = EventPriority.HIGHEST, ignoreCancelled = true)
public void BlockBreakEvent(BlockBreakEvent e) {

    if (e.getBlock().hasMetadata("ce.Ice"))
        e.setCancelled(true);

    CEventHandler.handleEvent(e.getPlayer(), e, blockBroken);
    if (e.getBlock().hasMetadata("ce.mine")) {
        Block b = e.getBlock();
        b.removeMetadata("ce.mine", Main.plugin);
        Block[] blocks = { b.getRelative(0, 1, 0), b.getRelative(1, 0, 0), b.getRelative(-1, 0, 0), b.getRelative(0, 0, 1), b.getRelative(0, 0, -1) };

        for (Block block : blocks) {
            if (block.hasMetadata("ce.mine.secondary")) {
                String[] s = block.getMetadata("ce.mine.secondary").get(0).asString().split(" ");
                Location loc = new Location(e.getPlayer().getWorld(), Integer.parseInt(s[0]), Integer.parseInt(s[1]), Integer.parseInt(s[2]));
                Location blockLoc = b.getLocation();
                if (loc.getBlockX() == blockLoc.getBlockX() && loc.getBlockY() == blockLoc.getBlockY() && loc.getBlockZ() == blockLoc.getBlockZ())
                    block.removeMetadata("ce.mine.secondary", Main.plugin);
            }
        }
    }

}
 
Example 5
Source File: SelectionHolder.java    From AstralEdit with Apache License 2.0 6 votes vote down vote up
/**
 * Calculates the upLocation
 *
 * @param corner1 corner1
 * @param corner2 corner2
 */
private void calculateUpLocation(Location corner1, Location corner2) {
    final int x;
    if (corner1.getBlockX() > corner2.getBlockX()) {
        x = corner1.getBlockX();
    } else {
        x = corner2.getBlockX();
    }
    final int y;
    if (corner1.getBlockY() > corner2.getBlockY()) {
        y = corner1.getBlockY();
    } else {
        y = corner2.getBlockY();
    }
    final int z;
    if (corner1.getBlockZ() > corner2.getBlockZ()) {
        z = corner1.getBlockZ();
    } else {
        z = corner2.getBlockZ();
    }
    this.upCorner = new LocationBuilder(new Location(corner1.getWorld(), x, y, z));
}
 
Example 6
Source File: StructureService.java    From Crazy-Crates with MIT License 5 votes vote down vote up
/**
 * Pastes a single structure into the world
 * @param structure - The structure to be pasted
 * @param startEdge - The starting corner with the lowest x, y, z coordinates
 * @param rotation - You may rotate the structure by 90 degrees steps
 */
public static void insertSingleStructure(DefinedStructure structure, Location startEdge, EnumBlockRotation rotation) {
    WorldServer world = ((CraftWorld) startEdge.getWorld()).getHandle();
    DefinedStructureInfo structInfo = new DefinedStructureInfo().a(EnumBlockMirror.NONE).a(rotation).a(false).a((ChunkCoordIntPair) null).a((Block) null).c(false).a(1.0f).a(new Random());
    BlockPosition blockPosition = new BlockPosition(startEdge.getBlockX(), startEdge.getBlockY(), startEdge.getBlockZ());
    structure.a(world, blockPosition, structInfo);
}
 
Example 7
Source File: Spigot_v1_15_R2.java    From worldedit-adapters with GNU Lesser General Public License v3.0 5 votes vote down vote up
@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();
}
 
Example 8
Source File: CraftWorld.java    From Thermos with GNU General Public License v3.0 5 votes vote down vote up
public FallingBlock spawnFallingBlock(Location location, org.bukkit.Material material, byte data) throws IllegalArgumentException {
    Validate.notNull(location, "Location cannot be null");
    Validate.notNull(material, "Material cannot be null");
    Validate.isTrue(material.isBlock(), "Material must be a block");

    double x = location.getBlockX() + 0.5;
    double y = location.getBlockY() + 0.5;
    double z = location.getBlockZ() + 0.5;

    net.minecraft.entity.item.EntityFallingBlock entity = new net.minecraft.entity.item.EntityFallingBlock(world, x, y, z, net.minecraft.block.Block.getBlockById(material.getId()), data);
    entity.field_145812_b = 1; // ticksLived

    world.addEntity(entity, SpawnReason.CUSTOM);
    return (FallingBlock) entity.getBukkitEntity();
}
 
Example 9
Source File: PlotSquaredIntegrationV5.java    From QuickShop-Reremake with GNU General Public License v3.0 5 votes vote down vote up
@Override
public boolean canCreateShopHere(@NotNull Player player, @NotNull Location location) {
    com.plotsquared.core.location.Location pLocation =
            new com.plotsquared.core.location.Location(
                    location.getWorld().getName(),
                    location.getBlockX(),
                    location.getBlockY(),
                    location.getBlockZ());
    Plot plot = pLocation.getPlot();
    if (plot == null) {
        return !whiteList;
    }
    return plot.getFlag(createFlag);
}
 
Example 10
Source File: ProximityGoal.java    From ProjectAres with GNU Affero General Public License v3.0 5 votes vote down vote up
public int getProximityFrom(ParticipantState player, Location location) {
    if(Double.isInfinite(location.lengthSquared())) return Integer.MAX_VALUE;

    ProximityMetric metric = getProximityMetric(player.getParty());
    if(metric == null) return Integer.MAX_VALUE;

    int minimumDistance = Integer.MAX_VALUE;
    for(Location v : getProximityLocations(player)) {
        // If either point is at infinity, the distance is infinite
        if(Double.isInfinite(v.lengthSquared())) continue;

        int dx = location.getBlockX() - v.getBlockX();
        int dy = location.getBlockY() - v.getBlockY();
        int dz = location.getBlockZ() - v.getBlockZ();

        // Note: distances stay squared as long as possible
        int distance;
        if(metric.horizontal) {
            distance = dx*dx + dz*dz;
        } else {
            distance = dx*dx + dy*dy + dz*dz;
        }

        if(distance < minimumDistance) {
            minimumDistance = distance;
        }
    }

    return minimumDistance;
}
 
Example 11
Source File: FaweAdapter_1_12.java    From FastAsyncWorldedit with GNU General Public License v3.0 5 votes vote down vote up
public boolean setBlock(Location location, BaseBlock block, boolean notifyAndLight)
{
    Preconditions.checkNotNull(location);
    Preconditions.checkNotNull(block);

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

    boolean changed = location.getBlock().setTypeIdAndData(block.getId(), (byte)block.getData(), notifyAndLight);

    CompoundTag nativeTag = block.getNbtData();
    if (nativeTag != null)
    {
        TileEntity tileEntity = craftWorld.getHandle().getTileEntity(new BlockPosition(x, y, z));
        if (tileEntity != null)
        {
            NBTTagCompound tag = (NBTTagCompound)fromNative(nativeTag);
            tag.set("x", new NBTTagInt(x));
            tag.set("y", new NBTTagInt(y));
            tag.set("z", new NBTTagInt(z));
            readTagIntoTileEntity(tag, tileEntity);
        }
    }
    return changed;
}
 
Example 12
Source File: BlockStorage.java    From Slimefun4 with GNU General Public License v3.0 4 votes vote down vote up
private static String serializeLocation(Location l) {
    return l.getWorld().getName() + ';' + l.getBlockX() + ';' + l.getBlockY() + ';' + l.getBlockZ();
}
 
Example 13
Source File: Util.java    From ObsidianDestroyer with GNU General Public License v3.0 4 votes vote down vote up
public static boolean isTargetsPathBlocked(Location tLoc, Location dLoc, boolean useOnlyMaterialListing) {

        // check world
        if (!dLoc.getWorld().getName().equalsIgnoreCase(tLoc.getWorld().getName())) {
            return false;
        }

        // if the distance is too close... the path is not blocked ;)
        if (dLoc.distance(tLoc) <= 0.9) {
            return false;
        }

        // try to iterate through blocks between dLoc and tLoc
        try {
            // Create a vector block trace from the detonator location to damaged block's location
            final BlockIterator blocksInPath = new BlockIterator(tLoc.getWorld(), dLoc.toVector(), tLoc.toVector().subtract(dLoc.toVector()).normalize(), 0.5, (int) dLoc.distance(tLoc));

            // iterate through the blocks in the path
            int over = 0; // prevents rare case of infinite loop and server crash
            while (blocksInPath.hasNext() && over < 128) {
                over++;
                // the next block
                final Block block = blocksInPath.next();
                if (block == null) {
                    continue;
                }
                // check if next block is the target block
                if (tLoc.getWorld().getName().equals(block.getWorld().getName()) &&
                        tLoc.getBlockX() == block.getX() &&
                        tLoc.getBlockY() == block.getY() &&
                        tLoc.getBlockZ() == block.getZ()) {
                    // ignore target block
                    continue;
                }

                // check if the block material is being handled
                if (useOnlyMaterialListing) {
                    // only handle for certain case as to not interfere with all explosions
                    if (MaterialManager.getInstance().contains(block.getType().name(), block.getData())) {
                        return true;
                    } else {
                        continue;
                    }
                }
                // check if the block material is a solid
                if (!isNonSolid(block.getType())) {
                    return true;
                }
            }
        } catch (Exception e) {
            // ignore the error and return no targets in path
        }
        return false;
    }
 
Example 14
Source File: FreezeHandler.java    From StaffPlus with GNU General Public License v3.0 4 votes vote down vote up
private boolean compareLocations(Location previous, Location current)
{
	return previous.getBlockX() == current.getBlockX() && previous.getBlockY() == current.getBlockY() && previous.getBlockZ() == current.getBlockZ();
}
 
Example 15
Source File: Road.java    From civcraft with GNU General Public License v2.0 4 votes vote down vote up
private int buildRoadSegment(Player player, Location locFirst, Location locSecond, int blockCount, 
			HashMap<String, SimpleBlock> simpleBlocks, int segments) throws CivException {		
		
		Vector dir = new Vector(locFirst.getX() - locSecond.getX(),
								locFirst.getY() - locSecond.getY(),
								locFirst.getZ() - locSecond.getZ());
		dir.normalize();
				
		dir.multiply(0.5);
		getHorizontalSegment(player, locSecond, simpleBlocks);
		segments++;
		
		/* Increment towards the first location. */
		double distance = locSecond.distance(locFirst);
		
		BlockCoord lastBlockCoord = new BlockCoord(locSecond);
		BlockCoord currentBlockCoord = new BlockCoord(locSecond);
		int lastY = locSecond.getBlockY();
		
		while (locSecond.distance(locFirst) > 1.0) {
			locSecond.add(dir);
						
			currentBlockCoord.setFromLocation(locSecond);
			if (lastBlockCoord.distance(currentBlockCoord) < Road.WIDTH) {
				continue; /* Didn't move far enough, keep going. */
			} else {
				lastBlockCoord.setFromLocation(locSecond);
			}
			
			/* Make sure the Y doesnt get too steep. */
			if (Math.abs(lastY - locSecond.getBlockY()) > 1.0 ) {
				throw new CivException("Road is too steep to be built here. Try lowering the one of the end points to make the road less steep.");
			}
			
			if (locSecond.getBlockY() < 5) {
				throw new CivException("Cannot build road blocks within 5 blocks of bedrock.");
			}
			
			lastY = locSecond.getBlockY();
			
			blockCount++;
			if (blockCount > Road.RECURSION_LIMIT) {
				throw new CivException("ERROR: Building road blocks exceeded recursion limit! Halted to keep server alive.");
			}
			
			getHorizontalSegment(player, locSecond, simpleBlocks);

//			Road.DEBUG_DATA++;
//			if (Road.DEBUG_DATA > 15) {
//				Road.DEBUG_DATA = 0;
//			}
			segments++;
			
			//Distance should always be going down, as a failsave
			//check that it is. Abort if our distance goes up.
			double tmpDist = locSecond.distance(locFirst);
			if (tmpDist > distance) {
				break;
			}
			
		}
		
		/* 
		 * Build last road segment
		 */
		getHorizontalSegment(player, locFirst, simpleBlocks);		
		return segments;
	}
 
Example 16
Source File: WrappedBlock8.java    From Hawk with GNU General Public License v3.0 4 votes vote down vote up
@Override
public void sendPacketToPlayer(Player p) {
    Location loc = getBukkitBlock().getLocation();
    PacketPlayOutBlockChange pac = new PacketPlayOutBlockChange(((CraftWorld) loc.getWorld()).getHandle(), new BlockPosition(loc.getBlockX(), loc.getBlockY(), loc.getBlockZ()));
    ((CraftPlayer) p).getHandle().playerConnection.sendPacket(pac);
}
 
Example 17
Source File: CombatLogTracker.java    From ProjectAres with GNU Affero General Public License v3.0 4 votes vote down vote up
/**
 * Get the cause of the player's imminent death, or null if they are not about to die
 * NOTE: not idempotent, has the side effect of clearing the recentDamage cache
 */
public @Nullable ImminentDeath getImminentDeath(Player player) {
    // If the player is already dead or in creative mode, we don't care
    if(player.isDead() || player.getGameMode() == GameMode.CREATIVE) return null;

    // If the player was on the ground, or is flying, or is able to fly, they are fine
    if(!(player.isOnGround() || player.isFlying() || player.getAllowFlight())) {
        // If the player is falling, detect an imminent falling death
        double fallDistance = player.getFallDistance();
        Block landingBlock = null;
        int waterDepth = 0;
        Location location = player.getLocation();

        if(location.getY() > 256) {
            // If player is above Y 256, assume they fell at least to there
            fallDistance += location.getY() - 256;
            location.setY(256);
        }

        // Search the blocks directly beneath the player until we find what they would have landed on
        Block block = null;
        for(; location.getY() >= 0; location.add(0, -1, 0)) {
            block = location.getBlock();
            if(block != null) {
                landingBlock = block;

                if(Materials.isWater(landingBlock.getType())) {
                    // If the player falls through water, reset fall distance and inc the water depth
                    fallDistance = -1;
                    waterDepth += 1;

                    // Break if they have fallen through enough water to stop falling
                    if(waterDepth >= BREAK_FALL_WATER_DEPTH) break;
                } else {
                    // If the block is not water, reset the water depth
                    waterDepth = 0;

                    if(Materials.isColliding(landingBlock.getType()) || Materials.isLava(landingBlock.getType())) {
                        // Break if the player hits a solid block or lava
                        break;
                    } else if(landingBlock.getType() == Material.WEB) {
                        // If they hit web, reset their fall distance, but assume they keep falling
                        fallDistance = -1;
                    }
                }
            }

            fallDistance += 1;
        }

        double resistanceFactor = getResistanceFactor(player);
        boolean fireResistance = hasFireResistance(player);

        // Now decide if the landing would have killed them
        if(location.getBlockY() < 0) {
            // The player would have fallen into the void
            return new ImminentDeath(EntityDamageEvent.DamageCause.VOID, location, null, false);
        } else if(landingBlock != null) {
            if(Materials.isColliding(landingBlock.getType()) && player.getHealth() <= resistanceFactor * (fallDistance - SAFE_FALL_DISTANCE)) {
                // The player would have landed on a solid block and taken enough fall damage to kill them
                return new ImminentDeath(EntityDamageEvent.DamageCause.FALL, landingBlock.getLocation().add(0, 0.5, 0), null, false);
            } else if (Materials.isLava(landingBlock.getType()) && resistanceFactor > 0 && !fireResistance) {
                // The player would have landed in lava, and we give the lava the benefit of the doubt
                return new ImminentDeath(EntityDamageEvent.DamageCause.LAVA, landingBlock.getLocation(), landingBlock, false);
            }
        }
    }

    // If we didn't predict a falling death, detect combat log due to recent damage
    Damage damage = this.recentDamage.remove(player);
    if(damage != null && damage.time.plus(RECENT_DAMAGE_THRESHOLD).isAfter(Instant.now())) {
        // Player logged out too soon after taking damage
        return new ImminentDeath(damage.event.getCause(), player.getLocation(), null, true);
    }

    return null;
}
 
Example 18
Source File: RemoveHoloCommand.java    From BedwarsRel with GNU General Public License v3.0 4 votes vote down vote up
@Override
public boolean execute(CommandSender sender, ArrayList<String> args) {
  if (!super.hasPermission(sender)) {
    return false;
  }

  final Player player = (Player) sender;
  player.setMetadata("bw-remove-holo", new FixedMetadataValue(BedwarsRel.getInstance(), true));
  if (BedwarsRel.getInstance().getHolographicInteractor().getType()
      .equalsIgnoreCase("HolographicDisplays")) {
    player.sendMessage(
        ChatWriter
            .pluginMessage(
                ChatColor.GREEN + BedwarsRel._l(player, "commands.removeholo.explain")));

  } else if (BedwarsRel.getInstance().getHolographicInteractor().getType()
      .equalsIgnoreCase("HologramAPI")) {

    for (Location location : BedwarsRel.getInstance().getHolographicInteractor()
        .getHologramLocations()) {
      if (player.getEyeLocation().getBlockX() == location.getBlockX()
          && player.getEyeLocation().getBlockY() == location.getBlockY()
          && player.getEyeLocation().getBlockZ() == location.getBlockZ()) {
        BedwarsRel.getInstance().getHolographicInteractor().onHologramTouch(player, location);
      }
    }
    BedwarsRel.getInstance().getServer().getScheduler().runTaskLater(BedwarsRel.getInstance(),
        new Runnable() {

          @Override
          public void run() {
            if (player.hasMetadata("bw-remove-holo")) {
              player.removeMetadata("bw-remove-holo", BedwarsRel.getInstance());
            }
          }

        }, 10L * 20L);

  }
  return true;
}
 
Example 19
Source File: WorldCord.java    From civcraft with GNU General Public License v2.0 4 votes vote down vote up
public WorldCord(Location location) {
	this.worldname = location.getWorld().getName();
	this.x = location.getBlockX();
	this.y = location.getBlockY();
	this.z = location.getBlockZ();
}
 
Example 20
Source File: CEListener.java    From ce with GNU Lesser General Public License v3.0 3 votes vote down vote up
@EventHandler(priority = EventPriority.MONITOR, ignoreCancelled = true)
public void PlayerMoveEvent(PlayerMoveEvent e) {

    Location from = e.getFrom();
    Location to = e.getTo();

    if (from.getBlockX() != to.getBlockX() || from.getBlockY() != to.getBlockY() || from.getBlockZ() != to.getBlockZ()) {

        CEventHandler.handleEvent(e.getPlayer(), e, move);
        CEventHandler.handleMines(e.getPlayer(), e);

    }

}