Package redempt.redlib.misc
Class LocationUtils
java.lang.Object
redempt.redlib.misc.LocationUtils
-
Field Summary
FieldsModifier and TypeFieldDescriptionstatic 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 -
Method Summary
Modifier and TypeMethodDescriptionstatic org.bukkit.Locationcenter(org.bukkit.block.Block block) Returns the Location at the center of a Block - shorthandstatic org.bukkit.Locationcenter(org.bukkit.Location loc) Sets the location's coordinates to the center point of its block coordinates, then returns itstatic voiddelayedTeleport(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 voiddelayedTeleport(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 straightstatic 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 straightstatic org.bukkit.LocationfromString(String string) Converts a String back to a Location.static org.bukkit.LocationfromString(String string, String separator) Converts a String back to a Locationstatic voidfromStringLater(String string, String separator, Consumer<org.bukkit.Location> callback) Loads a Location from a String.static voidfromStringLater(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 locationstatic org.bukkit.util.VectorgetDirection(org.bukkit.block.BlockFace face) Gets the Vector direction of a BlockFace.static org.bukkit.LocationgetNearestSafeLocation(org.bukkit.Location loc, int maxDistance) Gets the nearest safe location to the given location within the given distancestatic org.bukkit.LocationgetNearestSafeLocation(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 checkstatic booleanisHazard(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 itstatic booleanisSafe(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 locationstatic 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.LocationtoBlockLocation(org.bukkit.Location loc) Sets the location's coordinates to its block coordinates, then returns itstatic StringtoString(org.bukkit.block.Block block) Converts a Location to a String representing its locationstatic StringConverts a Location to a String representing its locationstatic StringtoString(org.bukkit.Location loc) Converts a Location to a String.static StringConverts a Location to a Stringstatic voidwaitForWorld(String worldname, Consumer<org.bukkit.World> callback) Waits for a world with the given name to load before calling the callback
-
Field Details
-
PRIMARY_BLOCK_FACES
public static final org.bukkit.block.BlockFace[] PRIMARY_BLOCK_FACESAn 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 tomaxDistance- The maximum distance to check from this locationfilter- 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 tomaxDistance- 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 teleportloc- The location to teleport the player to after the delayticks- The delay for the teleport, in ticksresult- 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 teleportloc- The location to teleport the player to after the delayticks- The delay for the teleport, in ticks
-
toString
Converts a Location to a String- Parameters:
loc- The Location to be stringifiedseparator- The separator to use between pieces of information- Returns:
- The stringified Location
-
fromString
Converts a String back to a Location- Parameters:
string- The stringified Locationseparator- The separator that was used in toString- Returns:
- The Location
-
toString
Converts a Location to a String representing its location- Parameters:
block- The Block location to be stringifiedseparator- The separator to use between pieces of information- Returns:
- The stringified location
-
toString
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 Locationseparator- The separator used when converting this Location to a Stringcallback- 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
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 Locationcallback- The callback to use the Location once it has been loaded
-
toString
Converts a Location to a String. The same as calling toString(Location, " ")- Parameters:
loc- The Location to be stringified- Returns:
- The stringified Location
-
fromString
Converts a String back to a Location. The same as calling fromString(String, " ")- Parameters:
string- The stringified Location- Returns:
- The Location
-
waitForWorld
Waits for a world with the given name to load before calling the callback- Parameters:
worldname- The name of the worldcallback- 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 blockend- The ending blockmax- The max number of locations to be checked - use to limit runtimefilter- 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 blockend- The ending blockmax- 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 blockend- The ending blockmax- 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 blockend- The ending blockmax- The max number of locations to be checked - use to limit runtimefilter- 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
-