Interface Position
public interface Position
Represents an immutable 3-dimensional position in a world. Differently from a
Location it holds a reference
to a world's name instead of a World object directly, making it suitable for unloaded worlds. Another
difference is the lack of yaw and pitch.- Since:
- 1
-
Method Summary
Modifier and TypeMethodDescription@NotNull Positionadd(double x, double y, double z) Returns a new position made by adding the given lengths to each coordinate.doubleReturns the distance between this position and another position.doubledistance(@NotNull org.bukkit.Location location) Returns the distance between this position and a Location.doubledistance(@NotNull org.bukkit.entity.Entity entity) Returns the distance between this position and an entity.doubledistanceSquared(@NotNull Position position) Returns the squared distance between this position and another position.doubledistanceSquared(@NotNull org.bukkit.Location location) Returns the squared distance between this position and a Location.doubledistanceSquared(@NotNull org.bukkit.entity.Entity entity) Returns the squared distance between this position and an entity.intReturns the X coordinate of the block in this position.intReturns the Y coordinate of the block in this position.intReturns the Z coordinate of the block in this position.@Nullable org.bukkit.WorldReturns the loaded world of this position or null if it's not loaded.@NotNull StringReturns the name of the world of this position.doublegetX()Returns the X coordinate of this position.doublegetY()Returns the Y coordinate of this position.doublegetZ()Returns the Z coordinate of this position.booleanisInSameWorld(@NotNull Position position) Returns if this position is in the same world of another position.booleanisInSameWorld(@NotNull org.bukkit.Location location) Returns if this position is in the same world of a Location.booleanisInSameWorld(@NotNull org.bukkit.entity.Entity entity) Returns if this position is in the same world of an entity.booleanReturns if this position is in the given world name.booleanisInWorld(@Nullable org.bukkit.World world) Returns if this position is in the given world.static @NotNull PositionReturns the position with the given world and coordinates.static @NotNull Positionof(@NotNull org.bukkit.Location location) Returns the position from a Location.static @NotNull Positionof(@NotNull org.bukkit.World world, double x, double y, double z) Returns the position with the given world and coordinates.static @NotNull Positionof(@NotNull org.bukkit.block.Block block) Returns the position of a block.static @NotNull Positionof(@NotNull org.bukkit.entity.Entity entity) Returns the position of an entity.@NotNull Positionsubtract(double x, double y, double z) Returns a new position made by subtracting the given lengths from each coordinate.@NotNull org.bukkit.LocationReturns a new Location derived from this position.@NotNull org.bukkit.util.VectortoVector()Returns a new Vector derived from this position.
-
Method Details
-
of
@NotNull static @NotNull Position of(@NotNull @NotNull org.bukkit.World world, double x, double y, double z) Returns the position with the given world and coordinates.- Parameters:
world- the worldx- the X coordinatey- the Y coordinatez- the Z coordinate- Returns:
- the created position
- Since:
- 1
-
of
@NotNull static @NotNull Position of(@NotNull @NotNull String worldName, double x, double y, double z) Returns the position with the given world and coordinates.- Parameters:
worldName- the name of the worldx- the X coordinatey- the Y coordinatez- the Z coordinate- Returns:
- the created position
- Since:
- 1
-
of
Returns the position from a Location.- Parameters:
location- the location from which to obtain the position- Returns:
- the created position
- Since:
- 1
-
of
Returns the position of an entity.- Parameters:
entity- the entity from which to obtain the position- Returns:
- the created position
- Since:
- 1
-
of
Returns the position of a block.- Parameters:
block- the block from which to obtain the position- Returns:
- the created position
- Since:
- 1
-
getWorldName
Returns the name of the world of this position.- Returns:
- the world name
- Since:
- 1
-
getX
double getX()Returns the X coordinate of this position.- Returns:
- the X coordinate
- Since:
- 1
-
getY
double getY()Returns the Y coordinate of this position.- Returns:
- the Y coordinate
- Since:
- 1
-
getZ
double getZ()Returns the Z coordinate of this position.- Returns:
- the Z coordinate
- Since:
- 1
-
getWorldIfLoaded
@Nullable @Nullable org.bukkit.World getWorldIfLoaded()Returns the loaded world of this position or null if it's not loaded.- Returns:
- the loaded world or null if not loaded
- Since:
- 1
-
isInSameWorld
Returns if this position is in the same world of another position.- Parameters:
position- the position to compare- Returns:
- true if the world is the same, false otherwise
- Since:
- 1
-
isInSameWorld
boolean isInSameWorld(@NotNull @NotNull org.bukkit.Location location) Returns if this position is in the same world of a Location.- Parameters:
location- the location to compare- Returns:
- true if the world is the same, false otherwise
- Since:
- 1
-
isInSameWorld
boolean isInSameWorld(@NotNull @NotNull org.bukkit.entity.Entity entity) Returns if this position is in the same world of an entity.- Parameters:
entity- the entity to compare- Returns:
- true if the world is the same, false otherwise
- Since:
- 1
-
isInWorld
boolean isInWorld(@Nullable @Nullable org.bukkit.World world) Returns if this position is in the given world.- Parameters:
world- the world to compare- Returns:
- true if the world matches, false otherwise
- Since:
- 1
-
isInWorld
Returns if this position is in the given world name.- Parameters:
worldName- the world name to compare- Returns:
- true if the world name matches, false otherwise
- Since:
- 1
-
getBlockX
int getBlockX()Returns the X coordinate of the block in this position.- Returns:
- the block's X coordinate
- Since:
- 1
-
getBlockY
int getBlockY()Returns the Y coordinate of the block in this position.- Returns:
- the block's Y coordinate
- Since:
- 1
-
getBlockZ
int getBlockZ()Returns the Z coordinate of the block in this position.- Returns:
- the block's Z coordinate
- Since:
- 1
-
add
Returns a new position made by adding the given lengths to each coordinate.- Parameters:
x- the length to add to the X coordinatey- the length to add to the Y coordinatez- the length to add to the Z coordinate- Returns:
- the new position
- Since:
- 1
-
subtract
Returns a new position made by subtracting the given lengths from each coordinate.- Parameters:
x- the length to subtract from the X coordinatey- the length to subtract from the Y coordinatez- the length to subtract from the Z coordinate- Returns:
- the new position
- Since:
- 1
-
distance
Returns the distance between this position and another position. Avoid repeatedly calling this method as it uses a costly square-root function, or consider usingdistanceSquared(Position)instead.- Parameters:
position- the position from which to measure the distance- Returns:
- the distance from the other position
- Since:
- 1
-
distance
double distance(@NotNull @NotNull org.bukkit.Location location) Returns the distance between this position and a Location. Avoid repeatedly calling this method as it uses a costly square-root function, or consider usingdistanceSquared(Location)instead.- Parameters:
location- the location from which to measure the distance- Returns:
- the distance from the Location
- Since:
- 1
-
distance
double distance(@NotNull @NotNull org.bukkit.entity.Entity entity) Returns the distance between this position and an entity. Avoid repeatedly calling this method as it uses a costly square-root function, or consider usingdistanceSquared(Entity)instead.- Parameters:
entity- the entity from which to measure the distance- Returns:
- the distance from the entity
- Since:
- 1
-
distanceSquared
Returns the squared distance between this position and another position.- Parameters:
position- the position from which to measure the distance- Returns:
- the squared distance from the other position
- Since:
- 1
-
distanceSquared
double distanceSquared(@NotNull @NotNull org.bukkit.Location location) Returns the squared distance between this position and a Location.- Parameters:
location- the location from which to measure the distance- Returns:
- the squared distance from the Location
- Since:
- 1
-
distanceSquared
double distanceSquared(@NotNull @NotNull org.bukkit.entity.Entity entity) Returns the squared distance between this position and an entity.- Parameters:
entity- the entity from which to measure the distance- Returns:
- the squared distance from the entity
- Since:
- 1
-
toLocation
@NotNull @NotNull org.bukkit.Location toLocation()Returns a new Location derived from this position. Warning: if the world is not loaded, the Location will contain a nullWorld, which can lead to unexpected errors.- Returns:
- A new Location based on this position
- Since:
- 1
-
toVector
@NotNull @NotNull org.bukkit.util.Vector toVector()Returns a new Vector derived from this position.- Returns:
- a new Vector based on this position
- Since:
- 1
-