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 Type
    Method
    Description
    @NotNull Position
    add(double x, double y, double z)
    Returns a new position made by adding the given lengths to each coordinate.
    double
    distance(@NotNull Position position)
    Returns the distance between this position and another position.
    double
    distance(@NotNull org.bukkit.Location location)
    Returns the distance between this position and a Location.
    double
    distance(@NotNull org.bukkit.entity.Entity entity)
    Returns the distance between this position and an entity.
    double
    distanceSquared(@NotNull Position position)
    Returns the squared distance between this position and another position.
    double
    distanceSquared(@NotNull org.bukkit.Location location)
    Returns the squared distance between this position and a Location.
    double
    distanceSquared(@NotNull org.bukkit.entity.Entity entity)
    Returns the squared distance between this position and an entity.
    int
    Returns the X coordinate of the block in this position.
    int
    Returns the Y coordinate of the block in this position.
    int
    Returns the Z coordinate of the block in this position.
    @Nullable org.bukkit.World
    Returns the loaded world of this position or null if it's not loaded.
    @NotNull String
    Returns the name of the world of this position.
    double
    Returns the X coordinate of this position.
    double
    Returns the Y coordinate of this position.
    double
    Returns the Z coordinate of this position.
    boolean
    isInSameWorld(@NotNull Position position)
    Returns if this position is in the same world of another position.
    boolean
    isInSameWorld(@NotNull org.bukkit.Location location)
    Returns if this position is in the same world of a Location.
    boolean
    isInSameWorld(@NotNull org.bukkit.entity.Entity entity)
    Returns if this position is in the same world of an entity.
    boolean
    isInWorld(@Nullable String worldName)
    Returns if this position is in the given world name.
    boolean
    isInWorld(@Nullable org.bukkit.World world)
    Returns if this position is in the given world.
    static @NotNull Position
    of(@NotNull String worldName, double x, double y, double z)
    Returns the position with the given world and coordinates.
    static @NotNull Position
    of(@NotNull org.bukkit.Location location)
    Returns the position from a Location.
    static @NotNull Position
    of(@NotNull org.bukkit.World world, double x, double y, double z)
    Returns the position with the given world and coordinates.
    static @NotNull Position
    of(@NotNull org.bukkit.block.Block block)
    Returns the position of a block.
    static @NotNull Position
    of(@NotNull org.bukkit.entity.Entity entity)
    Returns the position of an entity.
    @NotNull Position
    subtract(double x, double y, double z)
    Returns a new position made by subtracting the given lengths from each coordinate.
    @NotNull org.bukkit.Location
    Returns a new Location derived from this position.
    @NotNull org.bukkit.util.Vector
    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 world
      x - the X coordinate
      y - the Y coordinate
      z - 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 world
      x - the X coordinate
      y - the Y coordinate
      z - the Z coordinate
      Returns:
      the created position
      Since:
      1
    • of

      @NotNull static @NotNull Position of(@NotNull @NotNull org.bukkit.Location location)
      Returns the position from a Location.
      Parameters:
      location - the location from which to obtain the position
      Returns:
      the created position
      Since:
      1
    • of

      @NotNull static @NotNull Position of(@NotNull @NotNull org.bukkit.entity.Entity entity)
      Returns the position of an entity.
      Parameters:
      entity - the entity from which to obtain the position
      Returns:
      the created position
      Since:
      1
    • of

      @NotNull static @NotNull Position of(@NotNull @NotNull org.bukkit.block.Block block)
      Returns the position of a block.
      Parameters:
      block - the block from which to obtain the position
      Returns:
      the created position
      Since:
      1
    • getWorldName

      @NotNull @NotNull String 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

      boolean isInSameWorld(@NotNull @NotNull Position position)
      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

      boolean isInWorld(@Nullable @Nullable String worldName)
      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

      @NotNull @NotNull Position add(double x, double y, double z)
      Returns a new position made by adding the given lengths to each coordinate.
      Parameters:
      x - the length to add to the X coordinate
      y - the length to add to the Y coordinate
      z - the length to add to the Z coordinate
      Returns:
      the new position
      Since:
      1
    • subtract

      @NotNull @NotNull Position subtract(double x, double y, double z)
      Returns a new position made by subtracting the given lengths from each coordinate.
      Parameters:
      x - the length to subtract from the X coordinate
      y - the length to subtract from the Y coordinate
      z - the length to subtract from the Z coordinate
      Returns:
      the new position
      Since:
      1
    • distance

      double distance(@NotNull @NotNull Position position)
      Returns the distance between this position and another position. Avoid repeatedly calling this method as it uses a costly square-root function, or consider using distanceSquared(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 using distanceSquared(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 using distanceSquared(Entity) instead.
      Parameters:
      entity - the entity from which to measure the distance
      Returns:
      the distance from the entity
      Since:
      1
    • distanceSquared

      double distanceSquared(@NotNull @NotNull Position position)
      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 null World, 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