Class LocationManager

java.lang.Object
com.ranull.graves.manager.LocationManager

public class LocationManager extends Object
Manages location-related operations for graves.
  • Constructor Summary

    Constructors
    Constructor
    Description
    Initializes a new instance of the LocationManager class.
  • Method Summary

    Modifier and Type
    Method
    Description
    boolean
    canBuild(org.bukkit.entity.LivingEntity livingEntity, org.bukkit.Location location, List<String> permissionList)
    Determines if a living entity can build at a specified location.
    org.bukkit.Location
    getGround(org.bukkit.Location location, org.bukkit.entity.Entity entity, Grave grave)
    Gets the ground location for placement.
    org.bukkit.Location
    getLastSolidLocation(org.bukkit.entity.Entity entity)
    Gets the last solid location of an entity.
    org.bukkit.Location
    getLavaTop(org.bukkit.Location location, org.bukkit.entity.Entity entity, Grave grave)
    Gets the top location above lava for placement.
    int
    getMinHeight(org.bukkit.Location location)
    Gets the minimum height for a location.
    org.bukkit.Location
    getNewLocationIfCachedGraveExists(org.bukkit.entity.LivingEntity livingEntity, org.bukkit.Location location, Grave grave)
    Returns a new location if a cached grave already exists at the provided location.
    org.bukkit.Location
    getRoof(org.bukkit.Location location, org.bukkit.entity.Entity entity, Grave grave)
    Gets the roof location for placement.
    org.bukkit.Location
    getSafeGraveLocation(org.bukkit.entity.LivingEntity livingEntity, org.bukkit.Location location, Grave grave)
    Gets a safe grave location.
    org.bukkit.Location
    getSafeTeleportLocation(org.bukkit.entity.Entity entity, org.bukkit.Location location, Grave grave, Graves plugin)
    Gets a safe teleport location.
    org.bukkit.Location
    getTop(org.bukkit.Location location, org.bukkit.entity.Entity entity, Grave grave)
    Finds the top location for placement, searching downward from the given location's Y-coordinate.
    org.bukkit.Location
    getWaterTop(org.bukkit.Location location, org.bukkit.entity.Entity entity, Grave grave)
    Gets the top location above water for placement.
    boolean
    hasCachedGraveAt(org.bukkit.Location location)
    Determines if a location has a grave using the cache manager grave map.
    boolean
    hasGrave(org.bukkit.Location location)
    Determines if a location has a grave.
    boolean
    isInsideBorder(org.bukkit.Location location)
    Determines if a location is inside the world border.
    boolean
    isLocationSafeGrave(org.bukkit.Location location)
    Determines if a location is safe for a grave.
    boolean
    isLocationSafePlayer(org.bukkit.Location location)
    Determines if a location is safe for a player to spawn or teleport to.
    boolean
    isNetherRoofPlacement(org.bukkit.Location location, Grave grave)
    Checks whether placing a grave at the given location would put it on the Nether roof.
    boolean
    isVoid(org.bukkit.Location location)
    Determines if the specified location is in the void.
    void
    removeLastSolidLocation(org.bukkit.entity.Entity entity)
    Removes the last solid location of an entity.
    void
    setLastSolidLocation(org.bukkit.entity.Entity entity, org.bukkit.Location location)
    Sets the last solid location of an entity.

    Methods inherited from class java.lang.Object

    clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
  • Constructor Details

    • LocationManager

      public LocationManager(Graves plugin)
      Initializes a new instance of the LocationManager class.
      Parameters:
      plugin - The plugin instance.
  • Method Details

    • setLastSolidLocation

      public void setLastSolidLocation(org.bukkit.entity.Entity entity, org.bukkit.Location location)
      Sets the last solid location of an entity.
      Parameters:
      entity - The entity.
      location - The location.
    • getLastSolidLocation

      public org.bukkit.Location getLastSolidLocation(org.bukkit.entity.Entity entity)
      Gets the last solid location of an entity.

      Returns null if:

      • No last location is stored,
      • The stored location is in a different world than the entity's current world,
      • The block below the stored location is not considered a safe solid block.
      Parameters:
      entity - The entity.
      Returns:
      The last solid location, or null if none is valid.
    • removeLastSolidLocation

      public void removeLastSolidLocation(org.bukkit.entity.Entity entity)
      Removes the last solid location of an entity.
      Parameters:
      entity - The entity.
    • getSafeTeleportLocation

      public org.bukkit.Location getSafeTeleportLocation(org.bukkit.entity.Entity entity, org.bukkit.Location location, Grave grave, Graves plugin)
      Gets a safe teleport location.

      This method attempts to return a location that is safe for a player/entity to teleport to:

      • If teleport.unsafe is enabled, the provided location is returned as-is (as long as it has a world).
      • Otherwise, the location must pass isLocationSafePlayer(Location).
      • If unsafe and teleport.top is enabled, a top-safe candidate is searched and returned if valid.
      Parameters:
      entity - The entity.
      location - The location.
      grave - The grave.
      plugin - The plugin instance.
      Returns:
      The safe teleport location, or null if none is found/allowed.
    • getSafeGraveLocation

      public org.bukkit.Location getSafeGraveLocation(org.bukkit.entity.LivingEntity livingEntity, org.bukkit.Location location, Grave grave)
      Gets a safe grave location.

      All returned locations are rounded using LocationUtil.roundLocation(Location).

      Parameters:
      livingEntity - The living entity.
      location - The location.
      grave - The grave.
      Returns:
      The safe grave location, or null if no suitable location is found.
    • hasCachedGraveAt

      public boolean hasCachedGraveAt(org.bukkit.Location location)
      Determines if a location has a grave using the cache manager grave map.
      Parameters:
      location - The location.
      Returns:
      True if the location has a cached grave, otherwise false.
    • getNewLocationIfCachedGraveExists

      public org.bukkit.Location getNewLocationIfCachedGraveExists(org.bukkit.entity.LivingEntity livingEntity, org.bukkit.Location location, Grave grave)
      Returns a new location if a cached grave already exists at the provided location.

      This does NOT update the cache or the grave. It only computes a new location that can be used by the caller to move/place the grave elsewhere.

      Parameters:
      livingEntity - The living entity (used for safe-location logic).
      location - The desired location.
      grave - The grave being placed/moved.
      Returns:
      A new safe location if the desired location is occupied; otherwise the original (rounded) location. Returns null if the location is occupied and no suitable alternative could be found.
    • isNetherRoofPlacement

      public boolean isNetherRoofPlacement(org.bukkit.Location location, Grave grave)
      Checks whether placing a grave at the given location would put it on the Nether roof.
      Parameters:
      location - the candidate grave location (entity/grave position, not block center-only)
      Returns:
      true if this would be considered a Nether roof placement, otherwise false
    • getTop

      public org.bukkit.Location getTop(org.bukkit.Location location, org.bukkit.entity.Entity entity, Grave grave)
      Finds the top location for placement, searching downward from the given location's Y-coordinate.

      This method starts scanning from the world's max build height downwards (or from the provided location's Y if the world is unavailable) and returns the first safe position it finds.

      Parameters:
      location - The base location.
      entity - The entity.
      grave - The grave.
      Returns:
      The found top location, or null if no suitable location is found.
    • getRoof

      public org.bukkit.Location getRoof(org.bukkit.Location location, org.bukkit.entity.Entity entity, Grave grave)
      Gets the roof location for placement.

      This searches upward starting just above the current Y level to find a safe position suitable for a grave.

      Parameters:
      location - The location.
      entity - The entity.
      grave - The grave.
      Returns:
      The roof location, or null if none is found.
    • getGround

      public org.bukkit.Location getGround(org.bukkit.Location location, org.bukkit.entity.Entity entity, Grave grave)
      Gets the ground location for placement.

      This searches downward from the current Y level to find a safe position suitable for a grave.

      Parameters:
      location - The location.
      entity - The entity.
      grave - The grave.
      Returns:
      The ground location, or null if none is found.
    • getLavaTop

      public org.bukkit.Location getLavaTop(org.bukkit.Location location, org.bukkit.entity.Entity entity, Grave grave)
      Gets the top location above lava for placement.

      Behavior:

      • If placement.lava-smart is enabled, attempts to use the entity's last solid location first.
      • If placement.lava-top is enabled, scans upward from the provided location until out of lava, then searches for the first air block without title/protected data to place into.
      Parameters:
      location - The location to check.
      entity - The entity.
      grave - The grave.
      Returns:
      The lava top location, or null if no valid location is found.
    • getWaterTop

      public org.bukkit.Location getWaterTop(org.bukkit.Location location, org.bukkit.entity.Entity entity, Grave grave)
      Gets the top location above water for placement.

      Behavior mirrors getLavaTop(Location, Entity, Grave):

      • If placement.water-smart is enabled, attempts to use the entity's last solid location first.
      • If placement.water-top is enabled, scans upward out of water and then finds the first air block without title/protected data.
      Parameters:
      location - The location to check.
      entity - The entity.
      grave - The grave.
      Returns:
      The water top location, or null if no valid location is found.
    • canBuild

      public boolean canBuild(org.bukkit.entity.LivingEntity livingEntity, org.bukkit.Location location, List<String> permissionList)
      Determines if a living entity can build at a specified location.
      Parameters:
      livingEntity - The living entity.
      location - The location.
      permissionList - The list of permissions.
      Returns:
      True if the entity can build, otherwise false.
    • isLocationSafePlayer

      public boolean isLocationSafePlayer(org.bukkit.Location location)
      Determines if a location is safe for a player to spawn or teleport to.
      Parameters:
      location - The location to check.
      Returns:
      True if the location is safe; otherwise, false.
    • isLocationSafeGrave

      public boolean isLocationSafeGrave(org.bukkit.Location location)
      Determines if a location is safe for a grave.
      Parameters:
      location - The location.
      Returns:
      True if the location is safe, otherwise false.
    • hasGrave

      public boolean hasGrave(org.bukkit.Location location)
      Determines if a location has a grave.
      Parameters:
      location - The location.
      Returns:
      True if the location has a grave, otherwise false.
    • isInsideBorder

      public boolean isInsideBorder(org.bukkit.Location location)
      Determines if a location is inside the world border. For versions prior to 1.12, the world border is ignored and this always returns true.
      Parameters:
      location - The location to check.
      Returns:
      True if the location is inside the world border; otherwise, false.
    • isVoid

      public boolean isVoid(org.bukkit.Location location)
      Determines if the specified location is in the void.
      Parameters:
      location - The location to check.
      Returns:
      True if the location is in the void; otherwise, false.
    • getMinHeight

      public int getMinHeight(org.bukkit.Location location)
      Gets the minimum height for a location.
      Parameters:
      location - The location.
      Returns:
      The minimum height.