org.bukkit.Location.setY()

Here are the examples of the java api org.bukkit.Location.setY() taken from open source projects. By voting up you can indicate which examples are most useful and appropriate.

95 Examples 7

19 Source : SignRegistration.java
with MIT License
from NyaaCat

public void setCoordinateY(Long y) {
    if (location == null) {
        location = new Location(Bukkit.getWorlds().get(0), 0, y, 0);
    } else {
        location.setY(y);
    }
}

19 Source : BossBar_legacy.java
with Apache License 2.0
from NEZNAMY

/**
 * Returns location where wither should be located based on where player is looking
 * @param p - player to get wither location for
 * @return location of wither
 */
public Location getWitherLocation(TabPlayer p) {
    Player pl = (Player) p.getPlayer();
    Location loc = pl.getEyeLocation().add(pl.getEyeLocation().getDirection().normalize().multiply(WITHER_DISTANCE));
    if (loc.getY() < 1)
        loc.setY(1);
    return loc;
}

19 Source : FishAttempt.java
with GNU General Public License v3.0
from dniym

public void fishCaught(Location hookLoc) {
    if (lastLocation == null || lastLocation.getWorld() != hookLoc.getWorld())
        lastLocation = hookLoc;
    Location testLoc = hookLoc.clone();
    testLoc.setY(lastLocation.getY());
    if (lastLocation.getWorld() == testLoc.getWorld() && lastLocation.distance(testLoc) <= range)
        setSameSpotCount(getSameSpotCount() + 1);
    else {
        setSameSpotCount(1);
        lastLocation = hookLoc;
    }
}

19 Source : FishAttempt.java
with GNU General Public License v3.0
from dniym

public boolean isBlackListedSpot(Location location) {
    for (Location l : BLACKLIST) {
        Location testLoc = l.clone();
        testLoc.setY(location.getY());
        if (location.getWorld() != testLoc.getWorld())
            continue;
        if (testLoc.distance(location) <= range)
            return true;
    }
    return false;
}

18 Source : ArmorStandHologram.java
with GNU General Public License v3.0
from Plugily-Projects

/**
 * @param y the y axis of the hologram
 * @return {@link ArmorStand}
 */
private ArmorStand getEnreplacedyArmorStand(Location loc, double y) {
    loc.setY(y);
    if (location != null) {
        location.getWorld().getNearbyEnreplacedies(location, 0.2, 0.2, 0.2).forEach(enreplacedy -> {
            if (enreplacedy instanceof ArmorStand && !armorStands.contains(enreplacedy) && !HologramManager.getArmorStands().contains(enreplacedy)) {
                enreplacedy.remove();
                enreplacedy.setCustomNameVisible(false);
                HologramManager.getArmorStands().remove(enreplacedy);
            }
        });
    }
    ArmorStand stand = (ArmorStand) loc.getWorld().spawnEnreplacedy(loc, EnreplacedyType.ARMOR_STAND);
    stand.setVisible(false);
    stand.setGravity(false);
    stand.setCustomNameVisible(true);
    return stand;
}

18 Source : LocationUtils.java
with GNU General Public License v3.0
from Mezy

/**
 * Returns location of ground.
 * @param loc Location to look for ground.
 * @param allowCaves When set to true, the first location on the y axis is returned. This will include caves.
 * @return Ground location.
 */
private static Location getGroundLocation(Location loc, boolean allowCaves) {
    World w = loc.getWorld();
    loc.setY(0);
    if (allowCaves) {
        while (loc.getBlock().getType() != Material.AIR) {
            loc = loc.add(0, 1, 0);
        }
    } else {
        loc = w.getHighestBlockAt(loc).getLocation();
    }
    loc = loc.add(.5, 0, .5);
    return loc;
}

18 Source : CraftLivingEntity.java
with GNU Lesser General Public License v3.0
from Luohuayu

public Location getEyeLocation() {
    Location loc = getLocation();
    loc.setY(loc.getY() + getEyeHeight());
    return loc;
}

18 Source : CylinderDrawer.java
with GNU General Public License v3.0
from KennyTV

@Override
public void draw(final Player player, final Region region, final DrawedType drawedType) {
    if (!hasValidSize(player, region))
        return;
    final SimpleVector radius = plugin.getRegionHelper().getRadius((CylinderRegion) region, 1.3, 1.3);
    final int width = (int) radius.getX();
    final int length = (int) radius.getZ();
    final int height = (int) radius.getY();
    final int max = Math.max(length, width);
    final int bottom = ((FlatRegion) region).getMinimumY();
    final int top = ((FlatRegion) region).getMaximumY() + 1;
    final SimpleVector center = plugin.getRegionHelper().getCenter(region, 0.5, 0, 0.5);
    final Location location = new Location(player.getWorld(), center.getX(), bottom, center.getZ());
    final double wideGrid = Math.PI / (settings.getParticlesPerBlock() * max * 2);
    final int heightSpace = (int) (settings.getParticleSpace() * height);
    drawCurves(player, width, length, heightSpace == 0 ? height : height / heightSpace, location, wideGrid, heightSpace == 0 ? 1 : heightSpace);
    location.setY(top);
    drawCurves(player, width, length, 1, location, wideGrid, heightSpace == 0 ? 1 : heightSpace);
    if (settings.hasAdvancedGrid(drawedType)) {
        location.setY(bottom);
        final double wideInterval = Math.PI / (settings.getParticlesPerGridBlock(drawedType) * max / 10D);
        drawCurves(player, width, length, height * settings.getParticlesPerGridBlock(drawedType), location, wideInterval, settings.getParticleGridSpace(drawedType));
        drawGrid(player, drawedType, width, length, top, location, true);
        drawGrid(player, drawedType, length, width, top, location, false);
    }
}

18 Source : CylinderDrawer.java
with GNU General Public License v3.0
from KennyTV

private void drawGrid(final Player player, final DrawedType drawedType, final int width, final int length, final int top, final Location location, final boolean xAxis) {
    final double x = location.getX();
    final double z = location.getZ();
    final double bottom = location.getY();
    final int gap = checkSpace(settings.getParticlesPerBlock() * (((width * length) / AREA_FACTOR) + 1));
    final int ticks = 2 * (width - 1) / gap;
    if (xAxis) {
        location.setX(location.getX() - width);
    } else {
        location.setZ(location.getZ() - width);
    }
    for (int i = 0; i < ticks; i++) {
        if (xAxis) {
            location.setX(location.getX() + gap);
        } else {
            location.setZ(location.getZ() + gap);
        }
        final double delta = Math.abs(xAxis ? location.getX() - x : location.getZ() - z);
        // Thanks to a beautiful buddy of mine that took an our of his life to come up with this formula by himself, even though it's on Wikipedia 👀
        final double radius = ((double) length / width) * Math.sqrt((width * width) - (delta * delta));
        final int gridTicks = (int) (radius * settings.getParticlesPerGridBlock(drawedType) * 2);
        if (xAxis) {
            location.setZ(location.getZ() - radius);
        } else {
            location.setX(location.getX() - radius);
        }
        for (int j = 0; j < gridTicks; j++) {
            if (xAxis) {
                location.setZ(location.getZ() + settings.getParticleGridSpace(drawedType));
            } else {
                location.setX(location.getX() + settings.getParticleGridSpace(drawedType));
            }
            playEffect(location, player);
            location.setY(top);
            playEffect(location, player);
            location.setY(bottom);
        }
        if (xAxis) {
            location.setZ(z);
        } else {
            location.setX(x);
        }
    }
    if (xAxis) {
        location.setX(x);
    } else {
        location.setZ(z);
    }
}

18 Source : CuboidDrawer.java
with GNU General Public License v3.0
from KennyTV

private void drawPillarsAndGrid(final Player player, final Location minimum, final int gridSpaceX, final int gridSpaceZ, final double height, final double width, final double length, final DrawedType drawedType) {
    final boolean advancedGridEnabled = settings.hasAdvancedGrid(drawedType);
    final double x = minimum.getX();
    final double y = minimum.getY();
    final double z = minimum.getZ();
    final double gridSpace = advancedGridEnabled ? settings.getParticleGridSpace(drawedType) : 0;
    final double maxTicks = height * settings.getParticlesPerBlock();
    final double maxGridTicksX = advancedGridEnabled ? width * settings.getParticlesPerGridBlock(drawedType) - 1 : 0;
    final double maxGridTicksZ = advancedGridEnabled ? length * settings.getParticlesPerGridBlock(drawedType) - 1 : 0;
    setGrid(player, minimum, gridSpaceX, maxTicks, maxGridTicksX, gridSpace, 0, drawedType);
    minimum.setX(x + width);
    minimum.setY(y);
    minimum.setZ(z + length);
    setGrid(player, minimum, gridSpaceX, maxTicks, maxGridTicksX, -gridSpace, 0, drawedType);
    minimum.setX(x + width);
    minimum.setY(y);
    minimum.setZ(z);
    setGrid(player, minimum, gridSpaceZ, maxTicks, maxGridTicksZ, 0, gridSpace, drawedType);
    minimum.setX(x);
    minimum.setY(y);
    minimum.setZ(z + length);
    setGrid(player, minimum, gridSpaceZ, maxTicks, maxGridTicksZ, 0, -gridSpace, drawedType);
}

18 Source : CuboidDrawer.java
with GNU General Public License v3.0
from KennyTV

private void drawLines(final Player player, final Location location, final int gridSpace, final int topGridSpace, final double maxTicks, final double maxGridTicks, final double maxTopGridTicks, final double height, final boolean x, final DrawedType drawedType) {
    // Lower row (with vertical grid)
    final double oldX = location.getX();
    final double oldZ = location.getZ();
    int blocks = 0;
    for (int i = 0; i < maxTicks; i++) {
        if (settings.hasAdvancedGrid(drawedType)) {
            if (blocks % gridSpace == 0 && i != 0) {
                final Location clone = location.clone();
                for (double j = 0; j < maxGridTicks; j++) {
                    clone.add(0, settings.getParticleGridSpace(drawedType), 0);
                    playEffect(clone, player, drawedType);
                }
            }
            if (topGridSpace != 0 && blocks % topGridSpace == 0 && i != 0) {
                tickGrid(player, location, maxTopGridTicks, x, drawedType);
            }
            blocks++;
        }
        if (x) {
            location.add(settings.getParticleSpace(), 0, 0);
        } else {
            location.add(0, 0, settings.getParticleSpace());
        }
        playEffect(location, player, drawedType);
    }
    // Upper row
    location.setX(oldX);
    location.setZ(oldZ);
    location.setY(location.getY() + height);
    blocks = 0;
    for (double i = 0; i < maxTicks; i++) {
        if (settings.hasAdvancedGrid(drawedType) && topGridSpace != 0 && blocks++ % topGridSpace == 0 && i != 0) {
            tickGrid(player, location, maxTopGridTicks, x, drawedType);
        }
        if (x) {
            location.add(settings.getParticleSpace(), 0, 0);
        } else {
            location.add(0, 0, settings.getParticleSpace());
        }
        playEffect(location, player, drawedType);
    }
}

18 Source : DragDownDown.java
with GNU General Public License v3.0
from herobrine99dan

private int getDistance(Enreplacedy e) {
    Location loc = e.getLocation().clone();
    double y = loc.getBlockY();
    int distance = 0;
    for (double i = y; i >= 0; i--) {
        loc.setY(i);
        if (loc.getBlock().getType().isSolid())
            break;
        distance++;
    }
    return distance;
}

18 Source : VectorUtil.java
with GNU General Public License v2.0
from BananaPuncher714

/**
 * Round a location's values rounded to the sixteenth
 *
 * @param location
 * @return
 */
public static Location sixteenth(Location location) {
    location.setX(location.getX() * 128 / 128);
    location.setY(location.getY() * 128 / 128);
    location.setZ(location.getZ() * 128 / 128);
    return location;
}

18 Source : FlagHighlightTask.java
with MIT License
from Avicus

@Override
public void run() {
    boolean anyCarried = false;
    for (FlagObjective flag : this.flags) {
        Optional<Location> optional = flag.getCurrentLocation();
        if (optional.isPresent() && flag.isHighlightHolder() && (!flag.getHighlightDelay().isPresent() || (flag.getHoldingTime().isPresent() && flag.getHoldingTime().get().isAfter(flag.getHighlightDelay().get().getMillis())))) {
            Location curr = optional.get().clone().add(0, 2.0, 0);
            double x = curr.getX();
            double z = curr.getZ();
            while (curr.getY() < optional.get().getY() + 46) {
                curr.setY(curr.getY() + 1);
                curr.setX(x + 0.4 * Math.cos(curr.getY()));
                curr.setZ(z + 0.4 * Math.sin(curr.getY()));
                Worlds.playColoredParticle(curr, 256, flag.getColor().getColor());
            }
        }
        if (flag.isCarried()) {
            anyCarried = true;
        }
        // Reward
        if (flag.isCarried() && flag.getCarryingPoints() > 0 && flag.getHoldingTime().isPresent()) {
            flag.reward();
        }
    }
    // Updates the flashing carrying symbol
    if (anyCarried) {
        Atlas.get().getSideBar().syncUpdate();
    }
}

17 Source : Post.java
with GNU Affero General Public License v3.0
from PGMDev

private Location roundToBlock(Location loc) {
    Location newLoc = loc.clone();
    newLoc.setX(Math.floor(loc.getX()) + 0.5);
    newLoc.setY(Math.floor(loc.getY()));
    newLoc.setZ(Math.floor(loc.getZ()) + 0.5);
    return newLoc;
}

17 Source : BoardFactory.java
with GNU Affero General Public License v3.0
from northpl93

private static void walkWall(final Location loc1, final Location loc2, final Consumer<Location> locationConsumer) {
    final Location tempLocation = new Location(loc1.getWorld(), 0, 0, 0);
    final int minY = Math.min(loc1.getBlockY(), loc2.getBlockY());
    final int maxY = Math.max(loc1.getBlockY(), loc2.getBlockY());
    if (// x sie roznia, z takie samo
    loc1.getBlockX() > loc2.getBlockX()) {
        tempLocation.setZ(loc1.getBlockZ());
        for (int x = loc1.getBlockX(); x >= loc2.getBlockX(); x--) {
            tempLocation.setX(x);
            for (int y = maxY; y >= minY; y--) {
                tempLocation.setY(y);
                locationConsumer.accept(tempLocation);
            }
        }
    } else if (// x sie roznia, z takie samo
    loc1.getBlockX() < loc2.getBlockX()) {
        tempLocation.setZ(loc1.getBlockZ());
        for (int x = loc1.getBlockX(); x <= loc2.getBlockX(); x++) {
            tempLocation.setX(x);
            for (int y = maxY; y >= minY; y--) {
                tempLocation.setY(y);
                locationConsumer.accept(tempLocation);
            }
        }
    } else // 
    if (// z sie roznia, x takie samo
    loc1.getBlockZ() > loc2.getBlockZ()) {
        tempLocation.setX(loc1.getBlockX());
        for (int z = loc1.getBlockZ(); z >= loc2.getBlockZ(); z--) {
            tempLocation.setZ(z);
            for (int y = maxY; y >= minY; y--) {
                tempLocation.setY(y);
                locationConsumer.accept(tempLocation);
            }
        }
    } else if (// z sie roznia, x takie samo
    loc1.getBlockZ() < loc2.getBlockZ()) {
        tempLocation.setX(loc1.getBlockX());
        for (int z = loc1.getBlockZ(); z <= loc2.getBlockZ(); z++) {
            tempLocation.setZ(z);
            for (int y = maxY; y >= minY; y--) {
                tempLocation.setY(y);
                locationConsumer.accept(tempLocation);
            }
        }
    }
}

17 Source : CraftLivingEntity.java
with GNU General Public License v3.0
from Mohist-Community

@Override
public Location getEyeLocation() {
    Location loc = getLocation();
    loc.setY(loc.getY() + getEyeHeight());
    return loc;
}

17 Source : ParticleShapes.java
with GNU General Public License v3.0
from Lix3nn53

/**
 * Plays several of a particle type randomly within a circle
 *
 * @param loc    center location of the circle
 * @param radius radius of the circle
 * @param amount amount of particles to playSingleParticle
 */
public static void fillCircle(Location loc, Particle particle, double radius, int amount, Particle.DustOptions dustOptions, Direction direction) {
    Location temp = loc.clone();
    double rSquared = radius * radius;
    double twoRadius = radius * 2;
    int index = 0;
    // Play the particles
    while (index < amount) {
        if (direction == Direction.XY || direction == Direction.XZ) {
            temp.setX(loc.getX() + random.nextDouble() * twoRadius - radius);
        }
        if (direction == Direction.XY || direction == Direction.YZ) {
            temp.setY(loc.getY() + random.nextDouble() * twoRadius - radius);
        }
        if (direction == Direction.XZ || direction == Direction.YZ) {
            temp.setZ(loc.getZ() + random.nextDouble() * twoRadius - radius);
        }
        if (temp.distanceSquared(loc) > rSquared) {
            continue;
        }
        playSingleParticle(temp, particle, dustOptions);
        index++;
    }
}

17 Source : ParticleShapes.java
with GNU General Public License v3.0
from Lix3nn53

/**
 * Randomly plays particle effects within the hemisphere
 *
 * @param loc      location to center the effect around
 * @param particle the string value for the particle
 * @param radius   radius of the sphere
 * @param amount   amount of particles to use
 */
public static void fillHemisphere(Location loc, Particle particle, double radius, int amount, Particle.DustOptions dustOptions) {
    Location temp = loc.clone();
    double twoRadius = radius * 2;
    // Play the particles
    for (int i = 0; i < amount; i++) {
        temp.setX(loc.getX() + random.nextDouble() * twoRadius - radius);
        temp.setY(loc.getY() + random.nextDouble() * radius);
        temp.setZ(loc.getZ() + random.nextDouble() * twoRadius - radius);
        playSingleParticle(temp, particle, dustOptions);
    }
}

17 Source : PolygonalDrawer.java
with GNU General Public License v3.0
from KennyTV

private void connect(final Simple2DVector vector, final int bottom, final int top, final int upwardsTicks, final Location location, final Player player) {
    final double length = vector.length();
    final double factor = length * settings.getParticlesPerBlock();
    final double x = vector.getX() / factor;
    final double z = vector.getZ() / factor;
    final int ticks = (int) factor;
    for (int i = 0; i < ticks; i++) {
        playEffect(location.add(x, 0, z), player);
        location.setY(top);
        playEffect(location, player);
        location.setY(bottom);
    }
    for (int j = 1; j < upwardsTicks; j++) {
        location.setY(location.getY() + settings.getParticleSpace());
        playEffect(location, player);
    }
    location.setY(bottom);
}

17 Source : EventFaction.java
with MIT License
from IPVP-MC

/**
 * Sets the {@link Cuboid} area of this {@link KothFaction}.
 *
 * @param cuboid the {@link Cuboid} to set
 * @param sender the {@link CommandSender} setting the claim
 */
public void setClaim(Cuboid cuboid, CommandSender sender) {
    removeClaims(getClaims(), sender);
    // Now add the new claim.
    Location min = cuboid.getMinimumPoint();
    min.setY(ClaimHandler.MIN_CLAIM_HEIGHT);
    Location max = cuboid.getMaximumPoint();
    max.setY(ClaimHandler.MAX_CLAIM_HEIGHT);
    addClaim(new Claim(this, min, max), sender);
}

16 Source : EntitySelector.java
with GNU General Public License v3.0
from yuttyann

@NotNull
private static Location setCenter(@NotNull Location location) {
    location.setX(location.getBlockX() + 0.5D);
    location.setY(location.getBlockY());
    location.setZ(location.getBlockZ() + 0.5D);
    return location;
}

16 Source : WorldMock.java
with MIT License
from seeseemelk

@Override
public boolean setSpawnLocation(int x, int y, int z) {
    if (spawnLocation == null) {
        spawnLocation = new Location(this, x, y, z);
    } else {
        spawnLocation.setX(x);
        spawnLocation.setY(y);
        spawnLocation.setZ(z);
    }
    return true;
}

16 Source : WorldLocationQueryModifier.java
with GNU Affero General Public License v3.0
from PGMDev

@Override
protected BlockQueryCustomLocation modifyQuery(LocationQuery query) {
    Location origin = query.getLocation();
    Location newLoc = origin.clone();
    newLoc.setX(relative[0] ? origin.getX() + coords.getX() : coords.getX());
    newLoc.setY(relative[1] ? origin.getY() + coords.getY() : coords.getY());
    newLoc.setZ(relative[2] ? origin.getZ() + coords.getZ() : coords.getZ());
    return new BlockQueryCustomLocation(query.getEvent(), newLoc);
}

16 Source : TreasureChest.java
with GNU General Public License v2.0
from PatoTheBest

private Location getChestLocation(int i, Location loc) {
    Location chestLocation = this.center.clone();
    chestLocation.setX(loc.getBlockX() + 0.5D);
    chestLocation.setY(loc.getBlockY() + 1.0D);
    chestLocation.setZ(loc.getBlockZ() + 0.5D);
    switch(i) {
        case 1:
            chestLocation.add(2.0D, 0.0D, 0.0D);
            break;
        case 2:
            chestLocation.add(-2.0D, 0.0D, 0.0D);
            break;
        case 3:
            chestLocation.add(0.0D, 0.0D, 2.0D);
            break;
        case 4:
            chestLocation.add(0.0D, 0.0D, -2.0D);
    }
    return chestLocation;
}

16 Source : BlockUtils.java
with GNU Affero General Public License v3.0
from OvercastNetwork

public static Location center(Location location) {
    Location center = location.clone();
    center.setX(center.getBlockX() + 0.5);
    center.setY(center.getBlockY() + 0.5);
    center.setZ(center.getBlockZ() + 0.5);
    return center;
}

16 Source : FireworkUtil.java
with GNU Affero General Public License v3.0
from OvercastNetwork

@Nonnull
public static Location getOpenSpaceAbove(@Nonnull 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;
}

16 Source : MovementValuesHelper.java
with GNU General Public License v3.0
from herobrine99dan

public boolean hasBlock(Player p, String m) {
    m = m.toUpperCase();
    boolean done = false;
    Location loc = p.getLocation().clone();
    int min = (int) loc.getY() - 15;
    int max = (int) (loc.getY() + 15);
    if (min < 0) {
        min = 0;
    }
    if (max > 255) {
        max = 255;
    }
    for (int i = min; i < max; i++) {
        loc.setY(i);
        if (loc.getBlock().getType().name().contains(m)) {
            return true;
        }
    }
    return done;
}

16 Source : WorldUtils.java
with MIT License
from EpiCanard

/**
 * Transform a String into a location
 *
 * @param locatString String location
 * @param location    if not null set location inside this variable
 * @return Location
 */
public Location getLocationFromString(String locatString, Location location) {
    if (locatString == null)
        return null;
    String[] args = locatString.split(",");
    if (args.length != 4)
        return null;
    if (location == null) {
        location = new Location(GlobalMarketChest.plugin.getServer().getWorld(args[0]), Double.parseDouble(args[1]), Double.parseDouble(args[2]), Double.parseDouble(args[3]));
    } else {
        World world = GlobalMarketChest.plugin.getServer().getWorld(args[0]);
        if (world == null) {
            LoggerUtils.warn(LangUtils.get("ErrorMessages.UnkownWorld") + " " + locatString);
            return null;
        }
        location.setWorld(world);
        location.setX(Double.parseDouble(args[1]));
        location.setY(Double.parseDouble(args[2]));
        location.setZ(Double.parseDouble(args[3]));
    }
    return location;
}

16 Source : Pet.java
with GNU General Public License v3.0
from Arnuh

@Override
public void setAsHat(boolean flag) {
    if (isHat == flag)
        return;
    if (ownerRiding) {
        ownerRidePet(false);
    }
    if (!isSpawned())
        return;
    this.teleportToOwner();
    if (!flag) {
        getOwner().eject();
    } else {
        getOwner().addPreplacedenger(getCraftPet());
    }
    this.getEnreplacedyPet().resizeBoundingBox(flag);
    this.isHat = flag;
    getLocation().getWorld().spawnParticle(Particle.PORTAL, getLocation(), 1);
    // Particle.PORTAL.builder().at(getLocation()).show();
    Location l = this.getLocation().clone();
    l.setY(l.getY() - 1D);
    getLocation().getWorld().spawnParticle(Particle.PORTAL, getLocation(), 1);
// Particle.PORTAL.builder().at(getLocation()).show();
}

15 Source : Trackers.java
with GNU Affero General Public License v3.0
from PGMDev

public static double distanceFromRanged(RangedInfo rangedInfo, @Nullable Location deathLocation) {
    if (rangedInfo.getOrigin() == null || deathLocation == null)
        return Double.NaN;
    // When players fall in the void, use y=0 as their death location
    if (deathLocation.getY() < 0) {
        deathLocation = deathLocation.clone();
        deathLocation.setY(0);
    }
    return deathLocation.distance(rangedInfo.getOrigin());
}

15 Source : FireworkMatchModule.java
with GNU Affero General Public License v3.0
from PGMDev

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;
}

15 Source : BlockUtils.java
with GNU Affero General Public License v3.0
from OvercastNetwork

/**
 * Return the "base" {@link Location} of the block at the given location,
 * which is the bottom center point on the block (i.e. the location of any
 * block-shaped enreplacedy that is aligned with the block).
 */
public static Location base(Location location) {
    Location center = location.clone();
    center.setX(center.getBlockX() + 0.5);
    center.setY(center.getBlockY());
    center.setZ(center.getBlockZ() + 0.5);
    return center;
}

15 Source : WoolShuffle.java
with MIT License
from Nicbo

/**
 * Check if a player is standing on the current wool
 *
 * @param player the player
 * @return true if the player is standing on the correct wool
 */
private boolean isPlayerOnWool(Player player) {
    Location loc = player.getLocation();
    loc.setY(loc.getY() - 1);
    Block block = loc.getWorld().getBlockAt(loc);
    loc.setY(loc.getY() - 1);
    Block blockUnder = loc.getWorld().getBlockAt(loc);
    return isEqual(block, wools[index]) || isEqual(blockUnder, wools[index]);
}

15 Source : DungeonPackagerConfigFields.java
with GNU General Public License v3.0
from MagmaGuy

private void setAnchorPoint(Location location) {
    Location roundedLocation = location.clone();
    roundedLocation.setX(roundedLocation.getBlockX() + 0.5);
    roundedLocation.setY(roundedLocation.getBlockY() + 0.5);
    roundedLocation.setZ(roundedLocation.getBlockZ() + 0.5);
    float roundedYaw = roundedLocation.getYaw();
    while (roundedYaw < -225F) {
        roundedYaw += 360F;
    }
    while (roundedYaw > 225F) {
        roundedYaw -= 360F;
    }
    if (roundedYaw <= 45F && roundedYaw >= -45F)
        roundedYaw = 0F;
    else if (roundedYaw >= 45F && roundedYaw <= 135F)
        roundedYaw = 90F;
    else if (roundedYaw <= -45F && roundedYaw >= -135F)
        roundedYaw = -90F;
    else if (roundedYaw >= 135F || roundedYaw <= -135F)
        roundedYaw = 180F;
    roundedLocation.setYaw(roundedYaw);
    this.anchorPoint = roundedLocation;
    setRotation(roundedYaw);
    ConfigurationEngine.writeValue(ConfigurationLocation.serialize(roundedLocation), file, fileConfiguration, "anchorPoint");
    new DebugBlockLocation(roundedLocation);
}

15 Source : TargetHelper.java
with GNU General Public License v3.0
from Lix3nn53

public static Location getOpenLocation(Location loc1, Location loc2, boolean throughWall) {
    if (loc1.getX() == loc2.getX() && loc1.getY() == loc2.getY() && loc1.getZ() == loc2.getZ()) {
        return loc1;
    }
    Vector slope = loc2.clone().subtract(loc1).toVector();
    int steps = (int) (slope.length() * 4.0D) + 1;
    slope.multiply(1.0D / steps);
    if (throughWall) {
        Location temp = loc2.clone();
        while (temp.getBlock().getType().isSolid() && steps > 0) {
            temp.subtract(slope);
            steps--;
        }
        temp.setX(temp.getBlockX() + 0.5D);
        temp.setZ(temp.getBlockZ() + 0.5D);
        temp.setY((temp.getBlockY() + 1));
        return temp;
    }
    Location temp = loc1.clone();
    while (!temp.getBlock().getType().isSolid() && steps > 0) {
        temp.add(slope);
        steps--;
    }
    temp.subtract(slope);
    temp.setX(temp.getBlockX() + 0.5D);
    temp.setZ(temp.getBlockZ() + 0.5D);
    temp.setY((temp.getBlockY() + 1));
    return temp;
}

15 Source : MyPlayerDeathEvent.java
with GNU General Public License v3.0
from Lix3nn53

@EventHandler(priority = EventPriority.MONITOR, ignoreCancelled = true)
public void onEvent(PlayerDeathEvent event) {
    Player player = event.getEnreplacedy();
    final Location deathLocation = player.getLocation();
    if (deathLocation.getY() < 1) {
        deathLocation.setY(1);
    }
    new BukkitRunnable() {

        @Override
        public void run() {
            player.spigot().respawn();
            if (deathLocation.getWorld().getName().equals("world")) {
                if (CharacterSelectionScreenManager.isPlayerInCharSelection(player)) {
                    player.teleport(CharacterSelectionScreenManager.getCharacterSelectionCenter());
                } else {
                    TombManager.onDeath(player, deathLocation);
                }
            } else if (deathLocation.getWorld().getName().equals("tutorial")) {
                player.teleport(CharacterSelectionScreenManager.getTutorialStart());
            } else if (MiniGameManager.isInMinigame(player)) {
                MiniGameManager.onPlayerDeath(player);
            } else {
                Town town = TownManager.getTown(1);
                player.teleport(town.getLocation());
            }
            InventoryUtils.removeAllFromInventoryByMaterial(player.getInventory(), Material.COMPreplaced);
        }
    }.runTaskLater(GuardiansOfAdelia.getInstance(), 5L);
}

15 Source : ExistingPortalChecker.java
with zlib License
from Lauriethefish

@Override
public PortalSpawnPosition findClosestInChunk(@NotNull ChunkPosition chunk, @NotNull PortalSpawningContext context) {
    if (!generationChecker.isChunkGenerated(chunk)) {
        return null;
    }
    int frameSize = context.getSize().getBlockY() + 2;
    Collection<Location> obsidianBlocks = searchForObsidianBlocks(chunk, frameSize, context.getWorldLink());
    PortalSpawnPosition closestPosition = null;
    double closestDistance = Double.POSITIVE_INFINITY;
    for (Location block : obsidianBlocks) {
        // Because the above may only check every frameSize(th) block, we have to check the surrounding areas for portals here
        // This ends up being faster, since most chunks have very little obsidian in them
        for (int yOffset = -frameSize; yOffset <= frameSize; yOffset++) {
            // We also must check surrounding blocks on the X/Z for portals, since otherwise it wouldn't work if the portal corners don't exist.
            for (Vector offset : XZ_CHECK_OFFSETS) {
                Location offsetBlock = block.clone().add(offset);
                offsetBlock.setY(offsetBlock.getY() + yOffset);
                // Check the distance here to speed it up a bit if a location gets found
                double distance = offsetBlock.distance(context.getPreferredLocation());
                if (distance >= closestDistance) {
                    continue;
                }
                for (PortalDirection direction : CHECKED_DIRECTIONS) {
                    if (validPortalExists(offsetBlock, direction, context.getSize())) {
                        closestPosition = new PortalSpawnPosition(offsetBlock, context.getSize(), direction);
                        closestDistance = distance;
                    }
                }
            }
        }
    }
    return closestPosition;
}

15 Source : Pet.java
with GNU General Public License v3.0
from Arnuh

@Override
public void ownerRidePet(boolean flag) {
    if (this.ownerRiding == flag)
        return;
    this.ownerIsMounting = true;
    if (this.isHat) {
        this.setAsHat(false);
    }
    if (!isSpawned()) {
        this.ownerIsMounting = false;
        return;
    }
    if (!flag) {
        if (getCraftPet() != null) {
            getCraftPet().eject();
            if (this.getEnreplacedyPet() instanceof IEnreplacedyNoClipPet) {
                ((IEnreplacedyNoClipPet) this.getEnreplacedyPet()).noClip(true);
            }
        }
        ownerIsMounting = false;
    } else {
        if (getCraftPet() != null) {
            if (getRider() != null && getRider().isSpawned())
                getRider().removePet(false, true);
            new BukkitRunnable() {

                @Override
                public void run() {
                    getCraftPet().addPreplacedenger(getOwner());
                    ownerIsMounting = false;
                    if (getEnreplacedyPet() instanceof IEnreplacedyNoClipPet) {
                        ((IEnreplacedyNoClipPet) getEnreplacedyPet()).noClip(false);
                    }
                }
            }.runTaskLater(EchoPet.getPlugin(), 5L);
        } else
            ownerIsMounting = false;
    }
    this.teleportToOwner();
    this.getEnreplacedyPet().resizeBoundingBox(flag);
    this.ownerRiding = flag;
    getLocation().getWorld().spawnParticle(Particle.PORTAL, getLocation(), 1);
    Location l = this.getLocation().clone();
    l.setY(l.getY() - 1D);
// getLocation().getWorld().spawnParticle(Particle.BLOCK_DUST, getLocation(), 1);
// Particle.BLOCK_DUST.builder().ofBlockType(l.getBlock().getType()).at(getLocation()).show();
}

14 Source : LocationUtils.java
with MIT License
from Redempt

/**
 * Sets the location's coordinates to its block coordinates, then returns it
 * @param loc The location
 * @return The block location
 */
public static Location toBlockLocation(Location loc) {
    loc.setX(loc.getBlockX());
    loc.setY(loc.getBlockY());
    loc.setZ(loc.getBlockZ());
    return loc;
}

14 Source : TreasureChest.java
with GNU General Public License v2.0
from PatoTheBest

private void spawnHologram(Location location, String s) {
    location.setY(location.getY() + 1);
    ArmorStand armorStand = (ArmorStand) location.getWorld().spawnEnreplacedy(location, EnreplacedyType.ARMOR_STAND);
    armorStand.setSmall(true);
    armorStand.setVisible(false);
    armorStand.setGravity(false);
    armorStand.setBasePlate(false);
    armorStand.setCustomName(s);
    armorStand.setCustomNameVisible(true);
    this.holograms.add(armorStand);
}

14 Source : CagePhase.java
with GNU General Public License v2.0
from PatoTheBest

public void updateCage(Player player) {
    if (!usedLocations.containsKey(player)) {
        throw new IllegalArgumentException(player.getName() + " is not in arena " + arena.getName() + "!");
    }
    IPlayer iPlayer = playerManager.getPlayer(player);
    Location clone = usedLocations.get(player).clone();
    clone.setX(usedLocations.get(player).getBlockX() + 0.5);
    clone.setZ(usedLocations.get(player).getBlockZ() + 0.5);
    clone.setY(usedLocations.get(player).getBlockY() + 2);
    player.teleport(clone);
    cage.createCage(nms, iPlayer.getSelectedItemOrDefault(Cage.clreplaced, cageManager.getDefaulreplacedem()), usedLocations.get(player).clone().subtract(cage.getOffset(), -1, cage.getOffset()));
}

14 Source : CraftBlockState.java
with GNU Lesser General Public License v3.0
from Luohuayu

public Location getLocation(Location loc) {
    if (loc != null) {
        loc.setWorld(world);
        loc.setX(x);
        loc.setY(y);
        loc.setZ(z);
        loc.setYaw(0);
        loc.setPitch(0);
    }
    return loc;
}

14 Source : CraftBlock.java
with GNU General Public License v3.0
from kmecpp

public Location getLocation(Location loc) {
    if (loc != null) {
        loc.setWorld(getWorld());
        loc.setX(position.getX());
        loc.setY(position.getY());
        loc.setZ(position.getZ());
        loc.setYaw(0);
        loc.setPitch(0);
    }
    return loc;
}

14 Source : PacketConverter7.java
with GNU General Public License v3.0
from HawkAnticheat

private static Event packetToPosEvent(PacketPlayInFlying packet, Player p, HawkPlayer pp) {
    // default position
    Vector position = pp.getPosition();
    Location loc = new Location(pp.getWorld(), position.getX(), position.getY(), position.getZ(), pp.getYaw(), pp.getPitch());
    // There's an NPE here if someone teleports to another world using a dumb multi-world plugin (which sets the PlayerTeleportEvent#getTo() location to null)
    // I don't believe it is my responsibility to "fix" this. If there are enough complaints, I MIGHT consider looking into it.
    loc = new Location(pp.getWorld(), loc.getX(), loc.getY(), loc.getZ(), loc.getYaw(), loc.getPitch());
    WrappedPacket.PacketType pType = WrappedPacket.PacketType.FLYING;
    // update if has look
    boolean updateRot = false;
    if (packet.k()) {
        updateRot = true;
        pType = WrappedPacket.PacketType.LOOK;
        loc.setYaw(packet.g());
        loc.setPitch(packet.h());
    }
    // update if has position
    boolean updatePos = false;
    if (packet.j()) {
        updatePos = true;
        if (packet.k())
            pType = WrappedPacket.PacketType.POSITION_LOOK;
        else
            pType = WrappedPacket.PacketType.POSITION;
        loc.setX(packet.c());
        loc.setY(packet.d());
        loc.setZ(packet.e());
    }
    if (Math.abs(loc.getX()) >= Integer.MAX_VALUE || Math.abs(loc.getY()) >= Integer.MAX_VALUE || Math.abs(loc.getZ()) >= Integer.MAX_VALUE || Double.isNaN(loc.getX()) || Double.isNaN(loc.getY()) || Double.isNaN(loc.getZ())) {
        return new BadEvent(p, pp, new WrappedPacket7(packet, pType));
    }
    return new MoveEvent(p, loc, packet.i(), pp, new WrappedPacket7(packet, pType), updatePos, updateRot);
}

13 Source : TargetHelper.java
with MIT License
from zeshan321

/**
 * Retrieves an open location along the line for teleporting or linear targeting
 *
 * @param loc1        start location of the path
 * @param loc2        end location of the path
 * @param throughWall whether or not going through walls is allowed
 * @return the farthest open location along the path
 */
public Location getOpenLocation(Location loc1, Location loc2, boolean throughWall) {
    // Special case
    if (loc1.getX() == loc2.getX() && loc1.getY() == loc2.getY() && loc1.getZ() == loc2.getZ()) {
        return loc1;
    }
    // Common data
    Vector slope = loc2.clone().subtract(loc1).toVector();
    int steps = (int) (slope.length() * 4) + 1;
    slope.multiply(1.0 / steps);
    // Going through walls starts at the end and traverses backwards
    if (throughWall) {
        Location temp = loc2.clone();
        while (temp.getBlock().getType().isSolid() && steps > 0) {
            temp.subtract(slope);
            steps--;
        }
        temp.setX(temp.getBlockX() + 0.5);
        temp.setZ(temp.getBlockZ() + 0.5);
        temp.setY(temp.getBlockY() + 1);
        return temp;
    } else // Not going through walls starts at the beginning and traverses forward
    {
        Location temp = loc1.clone();
        while (!temp.getBlock().getType().isSolid() && steps > 0) {
            temp.add(slope);
            steps--;
        }
        temp.subtract(slope);
        temp.setX(temp.getBlockX() + 0.5);
        temp.setZ(temp.getBlockZ() + 0.5);
        temp.setY(temp.getBlockY() + 1);
        return temp;
    }
}

13 Source : EntitySelector.java
with GNU General Public License v3.0
from yuttyann

public static void setLocation(@NotNull Location location, @NotNull String axes, @NotNull String value) {
    if (value.startsWith("^")) {
        double number = value.length() == 1 ? 0.0D : Double.parseDouble(value.substring(1));
        switch(axes.toLowerCase(Locale.ROOT)) {
            case "x":
                {
                    var empty = new Location(location.getWorld(), 0.0D, 0.0D, 0.0D);
                    empty.setYaw(normalizeYaw(location.getYaw() - 90.0F));
                    empty.setPitch(location.getPitch());
                    location.add(empty.getDirection().normalize().multiply(number));
                    break;
                }
            case "y":
                {
                    var empty = new Location(location.getWorld(), 0.0D, 0.0D, 0.0D);
                    empty.setYaw(location.getYaw());
                    empty.setPitch(location.getPitch() - 90.0F);
                    location.add(empty.getDirection().normalize().multiply(number));
                    break;
                }
            case "z":
                location.add(location.getDirection().normalize().multiply(number));
                break;
        }
    } else if (value.startsWith("~")) {
        double number = value.length() == 1 ? 0.0D : Double.parseDouble(value.substring(1));
        switch(axes.toLowerCase(Locale.ROOT)) {
            case "x":
                location.add(number, 0.0D, 0.0D);
                break;
            case "y":
                location.add(0.0D, number, 0.0D);
                break;
            case "z":
                location.add(0.0D, 0.0D, number);
                break;
        }
    } else {
        double number = Double.parseDouble(value);
        switch(axes.toLowerCase(Locale.ROOT)) {
            case "x":
                location.setX(number);
                break;
            case "y":
                location.setY(number);
                break;
            case "z":
                location.setZ(number);
                break;
        }
    }
}

13 Source : TeleportEffect.java
with GNU General Public License v3.0
from Multitallented

public void apply() {
    Object target = getTarget();
    Enreplacedy origin = getOrigin();
    Location t;
    if (!setPos) {
        if (target.equals(origin)) {
            return;
        }
        float pitch = origin.getLocation().getPitch();
        float yaw = origin.getLocation().getYaw();
        if (target instanceof Location) {
            t = (Location) target;
        } else if (target instanceof Enreplacedy) {
            t = ((Enreplacedy) target).getLocation();
        } else if (target instanceof Block) {
            t = ((Block) target).getLocation();
        } else {
            return;
        }
        t.setPitch(pitch);
        t.setYaw(yaw);
    } else {
        t = new Location(origin.getWorld(), x, y, z, origin.getLocation().getYaw(), origin.getLocation().getPitch());
        t.setX(x);
        t.setY(y);
        t.setZ(z);
    }
    LivingEnreplacedy livingEnreplacedy;
    if (!other) {
        livingEnreplacedy = (LivingEnreplacedy) origin;
    } else if (target instanceof LivingEnreplacedy) {
        livingEnreplacedy = (LivingEnreplacedy) target;
    } else {
        return;
    }
    Player player = null;
    if (other && target instanceof Player) {
        player = (Player) livingEnreplacedy;
    // NCPExemptionManager.exemptPermanently(player, CheckType.MOVING);
    } else if (!other && origin instanceof Player) {
        player = (Player) origin;
    // NCPExemptionManager.exemptPermanently(player, CheckType.MOVING);
    }
    livingEnreplacedy.teleport(t);
    if (player != null) {
    // NCPExemptionManager.unexempt(player, CheckType.MOVING);
    }
}

13 Source : CraftBlockState.java
with GNU General Public License v3.0
from Mohist-Community

@Override
public Location getLocation(Location loc) {
    if (loc != null) {
        loc.setWorld(world);
        loc.setX(getX());
        loc.setY(getY());
        loc.setZ(getZ());
        loc.setYaw(0);
        loc.setPitch(0);
    }
    return loc;
}

13 Source : CraftBlock.java
with GNU Lesser General Public License v3.0
from Luohuayu

public Location getLocation(Location loc) {
    if (loc != null) {
        loc.setWorld(getWorld());
        loc.setX(x);
        loc.setY(y);
        loc.setZ(z);
        loc.setYaw(0);
        loc.setPitch(0);
    }
    return loc;
}

See More Examples