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

The following examples show how to use org.bukkit.Location#setX() . 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: CommandParticle.java    From Carbon with GNU Lesser General Public License v3.0 6 votes vote down vote up
private Location getLocation(CommandSender sender, boolean color, Location location, String x, String y, String z) {
	boolean xRelative = x.startsWith("~");
	boolean yRelative = y.startsWith("~");
	boolean zRelative = z.startsWith("~");
	double dX = parseDouble(sender, color, x.replaceAll("~", ""));
	double dY = parseDouble(sender, color, y.replaceAll("~", ""));
	double dZ = parseDouble(sender, color, z.replaceAll("~", ""));
	Location finalloc = location;
	if (xRelative) {
		finalloc = finalloc.add(dX, 0D, 0D);
	} else {
		finalloc.setX(dX);
	}
	if (yRelative) {
		finalloc = finalloc.add(0D, dY, 0D);
	} else {
		finalloc.setY(dY);
	}
	if (zRelative) {
		finalloc = finalloc.add(0D, 0D, dZ);
	} else {
		finalloc.setZ(dZ);
	}
	return finalloc;
}
 
Example 2
Source File: Portal.java    From CardinalPGM with MIT License 6 votes vote down vote up
private void tryTeleport(Player player, Location from, RegionModule destination, int dir) {
    if ((filter == null || filter.evaluate(player).equals(FilterState.ALLOW)) || ObserverModule.testObserver(player)) {
        if (destination != null) {
            from.setPosition(destination.getRandomPoint().getLocation().position());
        } else {
            from.setX(x.getLeft() ? from.getX() + (x.getRight() * dir) : x.getRight());
            from.setY(y.getLeft() ? from.getY() + (y.getRight() * dir) : y.getRight());
            from.setZ(z.getLeft() ? from.getZ() + (z.getRight() * dir) : z.getRight());
        }
        from.setYaw((float) (yaw.getLeft() ? from.getYaw() + (yaw.getRight() * dir) : yaw.getRight()));
        from.setPitch((float) (pitch.getLeft() ? from.getPitch() + (pitch.getRight() * dir) : pitch.getRight()));
        player.setFallDistance(0);
        player.teleport(from);
        if (sound) player.playSound(player.getLocation(), Sound.ENTITY_ENDERMEN_TELEPORT, 0.2F, 1);
    }
}
 
Example 3
Source File: ClaimChecks.java    From WildernessTp with MIT License 6 votes vote down vote up
private boolean checkSurroundingWGClaims(Location loc){
    if(wild.getConfig().getBoolean("WorldGuard")){
            int distance = range / 2;
            Vector top = new Vector(loc.getX() + distance, loc.getY(), loc.getZ() + distance);
            Vector bottom = new Vector(loc.getX() - distance, loc.getY(), loc.getZ() - distance);
            for (int z = bottom.getBlockZ(); z <= top.getBlockZ(); z++) {
                for (int x = bottom.getBlockX(); x <= top.getBlockX(); x++) {
                    loc.setX(x);
                    loc.setY(Bukkit.getWorld(loc.getWorld().getName()).getHighestBlockYAt(x, z));
                    loc.setZ(z);
                    if (!WorldGuardWrapper.getInstance().getRegions(loc).isEmpty())
                        return true;
                }
            }
        }
    return false;
}
 
Example 4
Source File: LocationUtilTest.java    From uSkyBlock with GNU General Public License v3.0 6 votes vote down vote up
@Test
public void testAlignToDistance1024x1024() throws Exception {
    Location loc = new Location(null, 1024,0,1024);
    assertThat(LocationUtil.alignToDistance(loc, 1024), is(new Location(null, 1024, Settings.island_height, 1024)));

    loc.setX(511.9);
    loc.setZ(512.5);
    assertThat(LocationUtil.alignToDistance(loc, 1024), is(new Location(null, 0, Settings.island_height, 1024)));

    loc.setX(1535.9);
    loc.setZ(512.5);
    assertThat(LocationUtil.alignToDistance(loc, 1024), is(new Location(null, 1024, Settings.island_height, 1024)));

    loc.setX(-511.99);
    loc.setZ(-511.99);
    assertThat(LocationUtil.alignToDistance(loc, 1024), is(new Location(null, 0, Settings.island_height, 0)));

    loc.setX(-512.01);
    loc.setZ(-512.01);
    assertThat(LocationUtil.alignToDistance(loc, 1024), is(new Location(null, -1024, Settings.island_height, -1024)));
}
 
Example 5
Source File: VersionUtils_1_14.java    From UhcCore with GNU General Public License v3.0 6 votes vote down vote up
@Override
public void handleNetherPortalEvent(PlayerPortalEvent event){
    Location loc = event.getFrom();
    MainConfiguration cfg = GameManager.getGameManager().getConfiguration();

    if (event.getFrom().getWorld().getEnvironment() == World.Environment.NETHER){
        loc.setWorld(Bukkit.getWorld(cfg.getOverworldUuid()));
        loc.setX(loc.getX() * 2d);
        loc.setZ(loc.getZ() * 2d);
        event.setTo(loc);
    }else{
        loc.setWorld(Bukkit.getWorld(cfg.getNetherUuid()));
        loc.setX(loc.getX() / 2d);
        loc.setZ(loc.getZ() / 2d);
        event.setTo(loc);
    }
}
 
Example 6
Source File: FireworkShow.java    From CS-CoreLib with GNU General Public License v3.0 5 votes vote down vote up
public static void launchRandom(Player p, int amount) {
	for (int i = 0; i < amount; i++) {
		Location l = p.getLocation().clone();
		l.setX(l.getX() + CSCoreLib.randomizer().nextInt(amount));
		l.setX(l.getX() - CSCoreLib.randomizer().nextInt(amount));
		l.setZ(l.getZ() + CSCoreLib.randomizer().nextInt(amount));
		l.setZ(l.getZ() - CSCoreLib.randomizer().nextInt(amount));
		
           launchFirework(l, getColors()[CSCoreLib.randomizer().nextInt(getColors().length)]);
	}
}
 
Example 7
Source File: WorldBorders.java    From PGM with GNU Affero General Public License v3.0 5 votes vote down vote up
static boolean clampToBorder(Location location) {
  WorldBorder border = location.getWorld().getWorldBorder();
  Location center = border.getCenter();
  double radius = border.getSize() / 2d;
  double xMin = center.getX() - radius;
  double xMax = center.getX() + radius;
  double zMin = center.getZ() - radius;
  double zMax = center.getZ() + radius;

  boolean moved = false;

  if (location.getX() < xMin) {
    location.setX(xMin);
    moved = true;
  }

  if (location.getX() > xMax) {
    location.setX(xMax);
    moved = true;
  }

  if (location.getZ() < zMin) {
    location.setZ(zMin);
    moved = true;
  }

  if (location.getZ() > zMax) {
    location.setZ(zMax);
    moved = true;
  }

  return moved;
}
 
Example 8
Source File: IslandLocatorLogic.java    From uSkyBlock with GNU General Public License v3.0 5 votes vote down vote up
/**
 * <pre>
 *                            z
 *   x = -z                   ^                    x = z
 *        \        -x < z     |     x < z         /
 *           \                |                /
 *              \             |             /
 *                 \          |          /
 *                    \       |       /          x > z
 *        -x > z         \    |    /
 *                          \ | /
 *     -----------------------+-----------------------------> x
 *                          / | \
 *        -x > -z        /    |    \
 *        (x < z)     /       |       \          x > -z
 *                 /          |          \
 *              /             |             \
 *           /     -x < -z    |   x < -z       \
 *       x = z                |                x = -z
 *                            |
 *                            v
 * </pre>
 */
static Location nextIslandLocation(final Location lastIsland) {
    int d = Settings.island_distance;
    LocationUtil.alignToDistance(lastIsland, d);
    int x = lastIsland.getBlockX();
    int z = lastIsland.getBlockZ();
    if (x < z) {
        if (-1 * x < z) {
            x += d;
        } else {
            z += d;
        }
    } else if (x > z) {
        if (-1 * x >= z) {
            x -= d;
        } else {
            z -= d;
        }
    } else { // x == z
        if (x <= 0) {
            z += d;
        } else {
            z -= d;
        }
    }
    lastIsland.setX(x);
    lastIsland.setZ(z);
    return lastIsland;
}
 
Example 9
Source File: WaterStructure.java    From civcraft with GNU General Public License v2.0 5 votes vote down vote up
@Override
protected Location repositionCenter(Location center, String dir, double x_size, double z_size) {
	Location loc = new Location(center.getWorld(), 
			center.getX(), center.getY(), center.getZ(), 
			center.getYaw(), center.getPitch());
	
	// Reposition tile improvements
	if (this.isTileImprovement()) {
		// just put the center at 0,0 of this chunk?
		loc = center.getChunk().getBlock(0, center.getBlockY(), 0).getLocation();
		//loc = center.getChunk().getBlock(arg0, arg1, arg2)
	} else {
		if (dir.equalsIgnoreCase("east")) {
			loc.setZ(loc.getZ() - (z_size / 2));
			loc.setX(loc.getX() + SHIFT_OUT);
		}
		else if (dir.equalsIgnoreCase("west")) {
			loc.setZ(loc.getZ() - (z_size / 2));
			loc.setX(loc.getX() - (SHIFT_OUT+x_size));

		}
		else if (dir.equalsIgnoreCase("north")) {
			loc.setX(loc.getX() - (x_size / 2));
			loc.setZ(loc.getZ() - (SHIFT_OUT+z_size));
		}
		else if (dir.equalsIgnoreCase("south")) {
			loc.setX(loc.getX() - (x_size / 2));
			loc.setZ(loc.getZ() + SHIFT_OUT);

		}
	}
	
	if (this.getTemplateYShift() != 0) {
		// Y-Shift based on the config, this allows templates to be built underground.
		loc.setY(WATER_LEVEL + this.getTemplateYShift());
	}

	return loc;
}
 
Example 10
Source File: AsyncBlock.java    From FastAsyncWorldedit with GNU General Public License v3.0 5 votes vote down vote up
@Override
public Location getLocation(Location loc) {
    if(loc != null) {
        loc.setWorld(this.getWorld());
        loc.setX((double)this.x);
        loc.setY((double)this.y);
        loc.setZ((double)this.z);
    }
    return loc;
}
 
Example 11
Source File: CraftWorld.java    From Thermos with GNU General Public License v3.0 5 votes vote down vote up
public org.bukkit.entity.Item dropItemNaturally(Location loc, ItemStack item) {
    double xs = world.rand.nextFloat() * 0.7F + (1.0F - 0.7F) * 0.5D;
    double ys = world.rand.nextFloat() * 0.7F + (1.0F - 0.7F) * 0.5D;
    double zs = world.rand.nextFloat() * 0.7F + (1.0F - 0.7F) * 0.5D;
    loc = loc.clone();
    loc.setX(loc.getX() + xs);
    loc.setY(loc.getY() + ys);
    loc.setZ(loc.getZ() + zs);
    return dropItem(loc, item);
}
 
Example 12
Source File: PlayerMovementListener.java    From UhcCore with GNU General Public License v3.0 5 votes vote down vote up
private void handleFrozenPlayers(PlayerMoveEvent e){
    UhcPlayer uhcPlayer = playersManager.getUhcPlayer(e.getPlayer());
    if (uhcPlayer.isFrozen()){
        Location freezeLoc = uhcPlayer.getFreezeLocation();
        Location toLoc = e.getTo();

        if (toLoc.getBlockX() != freezeLoc.getBlockX() || toLoc.getBlockZ() != freezeLoc.getBlockZ()){
            Location newLoc = toLoc.clone();
            newLoc.setX(freezeLoc.getBlockX() + .5);
            newLoc.setZ(freezeLoc.getBlockZ() + .5);

            e.getPlayer().teleport(newLoc);
        }
    }
}
 
Example 13
Source File: BlockUtils.java    From ProjectAres with GNU Affero General Public License v3.0 5 votes vote down vote up
/**
 * 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 entity 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;
}
 
Example 14
Source File: Camp.java    From civcraft with GNU General Public License v2.0 5 votes vote down vote up
protected Location repositionCenter(Location center, String dir, double x_size, double z_size) throws CivException {
	Location loc = new Location(center.getWorld(), 
			center.getX(), center.getY(), center.getZ(), 
			center.getYaw(), center.getPitch());
	
	// Reposition tile improvements
	if (dir.equalsIgnoreCase("east")) {
		loc.setZ(loc.getZ() - (z_size / 2));
		loc.setX(loc.getX() + SHIFT_OUT);
	}
	else if (dir.equalsIgnoreCase("west")) {
		loc.setZ(loc.getZ() - (z_size / 2));
		loc.setX(loc.getX() - (SHIFT_OUT+x_size));

	}
	else if (dir.equalsIgnoreCase("north")) {
		loc.setX(loc.getX() - (x_size / 2));
		loc.setZ(loc.getZ() - (SHIFT_OUT+z_size));
	}
	else if (dir.equalsIgnoreCase("south")) {
		loc.setX(loc.getX() - (x_size / 2));
		loc.setZ(loc.getZ() + SHIFT_OUT);

	}
	
	return loc;
}
 
Example 15
Source File: Post.java    From ProjectAres with GNU Affero General Public License v3.0 5 votes vote down vote up
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;
}
 
Example 16
Source File: CraftBlock.java    From Kettle with GNU General Public License v3.0 5 votes vote down vote up
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;
}
 
Example 17
Source File: Post.java    From PGM with GNU Affero General Public License v3.0 5 votes vote down vote up
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;
}
 
Example 18
Source File: Buildable.java    From civcraft with GNU General Public License v2.0 4 votes vote down vote up
public static Location repositionCenterStatic(Location center, ConfigBuildableInfo info, String dir, double x_size, double z_size) throws CivException {
	Location loc = new Location(center.getWorld(), 
			center.getX(), center.getY(), center.getZ(), 
			center.getYaw(), center.getPitch());
	
	
	// Reposition tile improvements
	if (info.tile_improvement) {
		// just put the center at 0,0 of this chunk?
		loc = center.getChunk().getBlock(0, center.getBlockY(), 0).getLocation();
	} else { 
		if (dir.equalsIgnoreCase("east")) {				
			loc.setZ(loc.getZ() - (z_size / 2));
			loc = center.getChunk().getBlock(0, center.getBlockY(), 0).getLocation();
			loc.setX(loc.getX() + SHIFT_OUT);				
		}
		else if (dir.equalsIgnoreCase("west")) {
			loc.setZ(loc.getZ() - (z_size / 2));
			loc = center.getChunk().getBlock(0, center.getBlockY(), 0).getLocation();
			loc.setX(loc.getX() - (SHIFT_OUT+x_size));
		}
		else if (dir.equalsIgnoreCase("north")) {
			loc.setX(loc.getX() - (x_size / 2));
			loc = center.getChunk().getBlock(0, center.getBlockY(), 0).getLocation();
			loc.setZ(loc.getZ() - (SHIFT_OUT+z_size));
		}
		else if (dir.equalsIgnoreCase("south")) {
			loc.setX(loc.getX() - (x_size / 2));
			loc = center.getChunk().getBlock(0, center.getBlockY(), 0).getLocation();
			loc.setZ(loc.getZ() + SHIFT_OUT);
		}
	}   
	if (info.templateYShift != 0) {
		// Y-Shift based on the config, this allows templates to be built underground.
		loc.setY(loc.getY() + info.templateYShift);
		
		if (loc.getY() < 1) {
			throw new CivException("Cannot build here, too close to bedrock.");
		}
	}
			
	return loc;
}
 
Example 19
Source File: FlyOld.java    From Hawk with GNU General Public License v3.0 4 votes vote down vote up
@Override
protected void check(MoveEvent event) {
    Player p = event.getPlayer();
    HawkPlayer pp = event.getHawkPlayer();
    double deltaY = event.getTo().getY() - event.getFrom().getY();
    if (pp.hasFlyPending() && p.getAllowFlight())
        return;
    if (!event.isOnGroundReally() && !pp.isFlying() && !p.isInsideVehicle() && !pp.isSwimming() && !p.isSleeping() &&
            !isInClimbable(event.getTo()) && !isOnBoat(p, event.getTo())) {

        if (!inAir.contains(p.getUniqueId()) && deltaY > 0)
            lastDeltaY.put(p.getUniqueId(), 0.42 + getJumpBoostLvl(p) * 0.1);

        //handle any pending knockbacks
        if(event.hasAcceptedKnockback())
            lastDeltaY.put(p.getUniqueId(), deltaY);

        if(event.isSlimeBlockBounce())
            lastDeltaY.put(p.getUniqueId(), deltaY);

        double expectedDeltaY = lastDeltaY.getOrDefault(p.getUniqueId(), 0D);
        double epsilon = 0.03;

        //lastDeltaY.put(p.getUniqueId(), (lastDeltaY.getOrDefault(p.getUniqueId(), 0D) - 0.025) * 0.8); //water function
        if (WrappedEntity.getWrappedEntity(p).getCollisionBox(event.getFrom().toVector()).getMaterials(p.getWorld()).contains(Material.WEB)) {
            lastDeltaY.put(p.getUniqueId(), -0.007);
            epsilon = 0.000001;
            if (AdjacentBlocks.onGroundReally(event.getTo().clone().add(0, -0.03, 0), -1, false, 0.02, pp))
                return;
        } else if(!pp.isInWater() && event.isInWater()) {
            //entering liquid
            lastDeltaY.put(p.getUniqueId(), (lastDeltaY.getOrDefault(p.getUniqueId(), 0D) * 0.98) - 0.038399);
        } else {
            //in air
            lastDeltaY.put(p.getUniqueId(), (lastDeltaY.getOrDefault(p.getUniqueId(), 0D) - 0.08) * 0.98);
        }


        //handle teleport
        if (event.hasTeleported()) {
            lastDeltaY.put(p.getUniqueId(), 0D);
            expectedDeltaY = 0;
            legitLoc.put(p.getUniqueId(), event.getTo());
        }

        if (deltaY - expectedDeltaY > epsilon && event.hasDeltaPos()) { //oopsie daisy. client made a goof up

            //wait one little second: minecraft is being a pain in the ass and it wants to play tricks when you parkour on the very edge of blocks
            //we need to check this first...
            if (deltaY < 0) {
                Location checkLoc = event.getFrom().clone();
                checkLoc.setY(event.getTo().getY());
                if (AdjacentBlocks.onGroundReally(checkLoc, deltaY, false, 0.02, pp)) {
                    onGroundStuff(p);
                    return;
                }
                //extrapolate move BEFORE getFrom, then check
                checkLoc.setY(event.getFrom().getY());
                checkLoc.setX(checkLoc.getX() - (event.getTo().getX() - event.getFrom().getX()));
                checkLoc.setZ(checkLoc.getZ() - (event.getTo().getZ() - event.getFrom().getZ()));
                if (AdjacentBlocks.onGroundReally(checkLoc, deltaY, false, 0.02, pp)) {
                    onGroundStuff(p);
                    return;
                }
            }

            if(event.isOnClientBlock() != null) {
                onGroundStuff(p);
                return;
            }

            //scold the child
            punish(pp, false, event);
            tryRubberband(event);
            lastDeltaY.put(p.getUniqueId(), canCancel() ? 0 : deltaY);
            failedSoDontUpdateRubberband.add(p.getUniqueId());
            return;
        }

        reward(pp);

        //the player is in air now, since they have a positive Y velocity and they're not on the ground
        if (inAir.contains(p.getUniqueId()))
            //upwards now
            stupidMoves.put(p.getUniqueId(), 0);

        //handle stupid moves, because the client tends to want to jump a little late if you jump off the edge of a block
        if (stupidMoves.getOrDefault(p.getUniqueId(), 0) >= STUPID_MOVES || (deltaY > 0 && AdjacentBlocks.onGroundReally(event.getFrom(), -1, true, 0.02, pp)))
            //falling now
            inAir.add(p.getUniqueId());
        stupidMoves.put(p.getUniqueId(), stupidMoves.getOrDefault(p.getUniqueId(), 0) + 1);
    } else {
        onGroundStuff(p);
    }

    if (!failedSoDontUpdateRubberband.contains(p.getUniqueId()) || event.isOnGroundReally()) {
        legitLoc.put(p.getUniqueId(), p.getLocation());
        failedSoDontUpdateRubberband.remove(p.getUniqueId());
    }

}
 
Example 20
Source File: Explosive.java    From ce with GNU Lesser General Public License v3.0 4 votes vote down vote up
@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);
                        }
    }

}