Class LocationUtils

java.lang.Object
redempt.redlib.misc.LocationUtils

public class LocationUtils extends Object
  • Field Summary

    Fields
    Modifier and Type
    Field
    Description
    static final org.bukkit.block.BlockFace[]
    An array of all the block faces which face in a single direction (positive X, negative X, etc.)
  • Constructor Summary

    Constructors
    Constructor
    Description
     
  • Method Summary

    Modifier and Type
    Method
    Description
    static org.bukkit.Location
    center(org.bukkit.block.Block block)
    Returns the Location at the center of a Block - shorthand
    static org.bukkit.Location
    center(org.bukkit.Location loc)
    Sets the location's coordinates to the center point of its block coordinates, then returns it
    static void
    delayedTeleport(org.bukkit.entity.Player player, org.bukkit.Location loc, int ticks)
    Initiates a delayed teleport for a player which will be cancelled if the player moves.
    static void
    delayedTeleport(org.bukkit.entity.Player player, org.bukkit.Location loc, int ticks, Consumer<Boolean> result)
    Initiates a delayed teleport for a player which will be cancelled if the player moves.
    static List<org.bukkit.Location>
    directPathfind(org.bukkit.block.Block start, org.bukkit.block.Block end, int max)
    Finds the fastest path between a starting and ending location using A*, then removes unneeded steps for straight
    static List<org.bukkit.Location>
    directPathfind(org.bukkit.block.Block start, org.bukkit.block.Block end, int max, Predicate<org.bukkit.block.Block> filter)
    Finds the fastest path between a starting and ending location using A*, then removes unneeded steps for straight
    static org.bukkit.Location
    Converts a String back to a Location.
    static org.bukkit.Location
    fromString(String string, String separator)
    Converts a String back to a Location
    static void
    fromStringLater(String string, String separator, Consumer<org.bukkit.Location> callback)
    Loads a Location from a String.
    static void
    fromStringLater(String string, Consumer<org.bukkit.Location> callback)
    Loads a Location from a String.
    static int[]
    getChunkCoordinates(org.bukkit.Location loc)
    Gets the chunk X and Z of a location
    static org.bukkit.util.Vector
    getDirection(org.bukkit.block.BlockFace face)
    Gets the Vector direction of a BlockFace.
    static org.bukkit.Location
    getNearestSafeLocation(org.bukkit.Location loc, int maxDistance)
    Gets the nearest safe location to the given location within the given distance
    static org.bukkit.Location
    getNearestSafeLocation(org.bukkit.Location loc, int maxDistance, Predicate<org.bukkit.Location> filter)
    Gets the nearest safe location to the given location within the given distance passing the given predicate check
    static boolean
    isHazard(org.bukkit.Material type)
    Checks if a given block type is a hazard - whether it would damage the player if they were on top of it
    static boolean
    isSafe(org.bukkit.Location loc)
    Checks whether the given location is safe to teleport a player to - that a player would not be damaged as a result of being moved to this location
    static Deque<org.bukkit.Location>
    pathfind(org.bukkit.block.Block start, org.bukkit.block.Block end, int max)
    Finds the fastest path between a starting and ending location using A*
    static Deque<org.bukkit.Location>
    pathfind(org.bukkit.block.Block start, org.bukkit.block.Block end, int max, Predicate<org.bukkit.block.Block> filter)
    Finds the fastest path between a starting and ending location using A*
    static org.bukkit.Location
    toBlockLocation(org.bukkit.Location loc)
    Sets the location's coordinates to its block coordinates, then returns it
    static String
    toString(org.bukkit.block.Block block)
    Converts a Location to a String representing its location
    static String
    toString(org.bukkit.block.Block block, String separator)
    Converts a Location to a String representing its location
    static String
    toString(org.bukkit.Location loc)
    Converts a Location to a String.
    static String
    toString(org.bukkit.Location loc, String separator)
    Converts a Location to a String
    static void
    waitForWorld(String worldname, Consumer<org.bukkit.World> callback)
    Waits for a world with the given name to load before calling the callback

    Methods inherited from class java.lang.Object

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

    • PRIMARY_BLOCK_FACES

      public static final org.bukkit.block.BlockFace[] PRIMARY_BLOCK_FACES
      An array of all the block faces which face in a single direction (positive X, negative X, etc.)
  • Constructor Details

    • LocationUtils

      public LocationUtils()
  • Method Details

    • isHazard

      public static boolean isHazard(org.bukkit.Material type)
      Checks if a given block type is a hazard - whether it would damage the player if they were on top of it
      Parameters:
      type - The type to check
      Returns:
      Whether the block type is a hazard
    • isSafe

      public static boolean isSafe(org.bukkit.Location loc)
      Checks whether the given location is safe to teleport a player to - that a player would not be damaged as a result of being moved to this location
      Parameters:
      loc - The location to check
      Returns:
      Whether the given location is safe
    • getNearestSafeLocation

      public static org.bukkit.Location getNearestSafeLocation(org.bukkit.Location loc, int maxDistance, Predicate<org.bukkit.Location> filter)
      Gets the nearest safe location to the given location within the given distance passing the given predicate check
      Parameters:
      loc - The location to find the nearest safe location to
      maxDistance - The maximum distance to check from this location
      filter - Used to filter safe locations that you still don't want to send the player to. Any locations this returns false for will be ignored.
      Returns:
      The nearest safe location, or null if one was not found
    • getNearestSafeLocation

      public static org.bukkit.Location getNearestSafeLocation(org.bukkit.Location loc, int maxDistance)
      Gets the nearest safe location to the given location within the given distance
      Parameters:
      loc - The location to find the nearest safe location to
      maxDistance - The maximum distance to check from this location
      Returns:
      The nearest safe location, or null if one was not found
    • getDirection

      public static org.bukkit.util.Vector getDirection(org.bukkit.block.BlockFace face)
      Gets the Vector direction of a BlockFace. For use in versions below 1.13.
      Parameters:
      face - The block face
      Returns:
      The vector representing the direction
    • delayedTeleport

      public static void delayedTeleport(org.bukkit.entity.Player player, org.bukkit.Location loc, int ticks, Consumer<Boolean> result)
      Initiates a delayed teleport for a player which will be cancelled if the player moves. The messages relevant to this will be sent automatically.
      Parameters:
      player - The player to teleport
      loc - The location to teleport the player to after the delay
      ticks - The delay for the teleport, in ticks
      result - A lambda to handle the result, given true if the teleport succeeded, false otherwise
    • delayedTeleport

      public static void delayedTeleport(org.bukkit.entity.Player player, org.bukkit.Location loc, int ticks)
      Initiates a delayed teleport for a player which will be cancelled if the player moves. The messages relevant to this will be sent automatically.
      Parameters:
      player - The player to teleport
      loc - The location to teleport the player to after the delay
      ticks - The delay for the teleport, in ticks
    • toString

      public static String toString(org.bukkit.Location loc, String separator)
      Converts a Location to a String
      Parameters:
      loc - The Location to be stringified
      separator - The separator to use between pieces of information
      Returns:
      The stringified Location
    • fromString

      public static org.bukkit.Location fromString(String string, String separator)
      Converts a String back to a Location
      Parameters:
      string - The stringified Location
      separator - The separator that was used in toString
      Returns:
      The Location
    • toString

      public static String toString(org.bukkit.block.Block block, String separator)
      Converts a Location to a String representing its location
      Parameters:
      block - The Block location to be stringified
      separator - The separator to use between pieces of information
      Returns:
      The stringified location
    • toString

      public static String toString(org.bukkit.block.Block block)
      Converts a Location to a String representing its location
      Parameters:
      block - The Block location to be stringified
      Returns:
      The stringified location
    • fromStringLater

      public static void fromStringLater(String string, String separator, Consumer<org.bukkit.Location> callback)
      Loads a Location from a String. If the world this Location is in is not yet loaded, waits for it to load, then passes the Location to the callback.
      Parameters:
      string - The String to be parsed into a Location
      separator - The separator used when converting this Location to a String
      callback - The callback to use the Location once it has been loaded
    • center

      public static org.bukkit.Location center(org.bukkit.block.Block block)
      Returns the Location at the center of a Block - shorthand
      Parameters:
      block - The Block to get the center of
      Returns:
      The center of the Block
    • toBlockLocation

      public static org.bukkit.Location toBlockLocation(org.bukkit.Location loc)
      Sets the location's coordinates to its block coordinates, then returns it
      Parameters:
      loc - The location
      Returns:
      The block location
    • center

      public static org.bukkit.Location center(org.bukkit.Location loc)
      Sets the location's coordinates to the center point of its block coordinates, then returns it
      Parameters:
      loc - The location
      Returns:
      The block location
    • fromStringLater

      public static void fromStringLater(String string, Consumer<org.bukkit.Location> callback)
      Loads a Location from a String. If the world this Location is in is not yet loaded, waits for it to load, then passes the Location to the callback.
      Parameters:
      string - The String to be parsed into a Location
      callback - The callback to use the Location once it has been loaded
    • toString

      public static String toString(org.bukkit.Location loc)
      Converts a Location to a String. The same as calling toString(Location, " ")
      Parameters:
      loc - The Location to be stringified
      Returns:
      The stringified Location
    • fromString

      public static org.bukkit.Location fromString(String string)
      Converts a String back to a Location. The same as calling fromString(String, " ")
      Parameters:
      string - The stringified Location
      Returns:
      The Location
    • waitForWorld

      public static void waitForWorld(String worldname, Consumer<org.bukkit.World> callback)
      Waits for a world with the given name to load before calling the callback
      Parameters:
      worldname - The name of the world
      callback - A callback to be passed the world when it loads
    • getChunkCoordinates

      public static int[] getChunkCoordinates(org.bukkit.Location loc)
      Gets the chunk X and Z of a location
      Parameters:
      loc - The location to get the chunk coordinates of
      Returns:
      An array containing the chunk coordinates [x, z]
    • directPathfind

      public static List<org.bukkit.Location> directPathfind(org.bukkit.block.Block start, org.bukkit.block.Block end, int max, Predicate<org.bukkit.block.Block> filter)
      Finds the fastest path between a starting and ending location using A*, then removes unneeded steps for straight
      Parameters:
      start - The starting block
      end - The ending block
      max - The max number of locations to be checked - use to limit runtime
      filter - A filter to determine which blocks are passable
      Returns:
      A List of locations leading from the start to the end, or the closest block if the path could not be completed
    • directPathfind

      public static List<org.bukkit.Location> directPathfind(org.bukkit.block.Block start, org.bukkit.block.Block end, int max)
      Finds the fastest path between a starting and ending location using A*, then removes unneeded steps for straight
      Parameters:
      start - The starting block
      end - The ending block
      max - The max number of locations to be checked - use to limit runtime
      Returns:
      A List of locations leading from the start to the end, or the closest block if the path could not be completed
    • pathfind

      public static Deque<org.bukkit.Location> pathfind(org.bukkit.block.Block start, org.bukkit.block.Block end, int max)
      Finds the fastest path between a starting and ending location using A*
      Parameters:
      start - The starting block
      end - The ending block
      max - The max number of locations to be checked - use to limit runtime
      Returns:
      A Deque of locations leading from the start to the end, or the closest block if the path could not be completed
    • pathfind

      public static Deque<org.bukkit.Location> pathfind(org.bukkit.block.Block start, org.bukkit.block.Block end, int max, Predicate<org.bukkit.block.Block> filter)
      Finds the fastest path between a starting and ending location using A*
      Parameters:
      start - The starting block
      end - The ending block
      max - The max number of locations to be checked - use to limit runtime
      filter - A filter to determine which blocks are passable
      Returns:
      A Deque of locations leading from the start to the end, or the closest block if the path could not be completed