Interface TeleportHelper


  • public interface TeleportHelper
    Finds safe ServerLocations for Entitys (typically ones that won't hurt them).

    Typically, the teleport helper will first determine whether the requested location is a safe one. If not, it will investigate locations close by, favouring spots closer, and favouring a location above or below over the x-z plane if two locations are equidistant.

    • Field Detail

      • DEFAULT_HEIGHT

        static final int DEFAULT_HEIGHT
        The default height radius to scan for safe locations.
        See Also:
        Constant Field Values
      • DEFAULT_WIDTH

        static final int DEFAULT_WIDTH
        The default width radius to scan for safe locations.
        See Also:
        Constant Field Values
      • DEFAULT_FLOOR_CHECK_DISTANCE

        static final int DEFAULT_FLOOR_CHECK_DISTANCE
        The default distance to check for a suitable floor below any candidate location.
        See Also:
        Constant Field Values
    • Method Detail

      • findSafeLocation

        default java.util.Optional<ServerLocation> findSafeLocation​(ServerLocation location)
        Gets the next safe ServerLocation around the given location.

        Safe entails that the returned location will not be somewhere that would harm an Entity. This method will use the default height and width for a search area, and will check for a suitable floor up to two blocks below any selected block.

        It's possible the same location will be returned that was passed in. This means it was safe.

        Parameters:
        location - The location to search nearby.
        Returns:
        A safe location near the original location or the original location if it is deemed safe. If no safe location can be found, Optional.empty() will be returned.
      • findSafeLocation

        default java.util.Optional<ServerLocation> findSafeLocation​(ServerLocation location,
                                                                    int height,
                                                                    int width)
        Gets the next safe ServerLocation around the given location with a given tolerance and search radius.

        Safe entails that the returned location will not be somewhere that would harm an Entity.

        It's possible the same location will be returned that was passed in. This means it was safe.

        This method will check for a suitable floor up to two blocks below any selected block.

        This method will use the default TeleportHelperFilter

        Parameters:
        location - The location to search nearby.
        height - The radius of blocks on the y-axis to search.
        width - The radius of blocks on the x and z-axis to search.
        Returns:
        A safe location near the original location or the original location if it is deemed safe. If no safe location can be found, Optional.empty() will be returned
      • findSafeLocation

        default java.util.Optional<ServerLocation> findSafeLocation​(ServerLocation location,
                                                                    int height,
                                                                    int width,
                                                                    int floorDistance)
        Gets the next safe ServerLocation around the given location with a given tolerance and search radius.

        Safe entails that the returned location will not be somewhere that would harm an Entity.

        It's possible the same location will be returned that was passed in. This means it was safe.

        This method will use the default TeleportHelperFilter and will respect the blacklist.

        Parameters:
        location - The location to search nearby.
        height - The radius of blocks on the y-axis to search.
        width - The radius of blocks on the x and z-axis to search.
        floorDistance - The number of blocks below a selected block to search for a suitable floor, that is, the maximum distance to a floor that the selected point can be. If this is zero or negative, a floor check will not be performed.
        Returns:
        A safe location near the original location or the original location if it is deemed safe. If no safe location can be found, Optional.empty() will be returned
      • findSafeLocation

        java.util.Optional<ServerLocation> findSafeLocation​(ServerLocation location,
                                                            int height,
                                                            int width,
                                                            int floorDistance,
                                                            TeleportHelperFilter filter,
                                                            TeleportHelperFilter... additionalFilters)
        Gets the next safe ServerLocation around the given location with a given tolerance and search radius.

        Safe entails that the returned location will not be somewhere that would harm an Entity.

        It's possible the same location will be returned that was passed in. This means it was safe.

        Parameters:
        location - The location to search nearby.
        height - The radius of blocks on the y-axis to search.
        width - The radius of blocks on the x and z-axis to search.
        floorDistance - The number of blocks below a selected block to search for a suitable floor, that is, the maximum distance to a floor that the selected point can be. If this is zero or negative, a floor check will not be performed.
        filter - The TeleportHelperFilter to use to determine if a location is safe.
        additionalFilters - Additional TeleportHelperFilters to check. All filters must match for a location to be marked as safe.
        Returns:
        A safe location near the original location or the original location if it is deemed safe. If no safe location can be found, Optional.empty() will be returned
      • findSafeLocationWithBlacklist

        default java.util.Optional<ServerLocation> findSafeLocationWithBlacklist​(ServerLocation location,
                                                                                 int height,
                                                                                 int width,
                                                                                 int floorDistance,
                                                                                 TeleportHelperFilter... filters)
        Gets the next safe ServerLocation around the given location with a given tolerance and search radius.

        Safe entails that the returned location will not be somewhere that would harm an Entity.

        It's possible the same location will be returned that was passed in. This means it was safe.

        This method will use the defined blacklist, effectively an equivalent to adding TeleportHelperFilters.CONFIG to the filter set.

        Parameters:
        location - The location to search nearby.
        height - The radius of blocks on the y-axis to search.
        width - The radius of blocks on the x and z-axis to search.
        floorDistance - The number of blocks below a selected block to search for a suitable floor, that is, the maximum distance to a floor that the selected point can be. If this is zero or negative, a floor check will not be performed.
        filters - The TeleportHelperFilters to check, in addition to TeleportHelperFilters.CONFIG. All filters must match for a location to be marked as safe.
        Returns:
        A safe location near the original location or the original location if it is deemed safe. If no safe location can be found, Optional.empty() will be returned