Contents
Class AssetPackPathUtil
java.lang.Object
com.hypixel.hytale.server.core.asset.util.AssetPackPathUtil
Utils for resolving actual asset file paths across AssetPack FileSystems.
-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionstatic PathrelativizeAssetPath(Path path) Relativizes the given asset path against its containing asset pack's root path.static PathresolveAssetPath(Path path) Resolves the given path to its corresponding asset path.static PathresolveAssetPath(Path path, String[] extensions) Resolves the given path to its corresponding asset path.static <T> voidvisitAssetPaths(Path path, String extension, int maxDepth, T ctx, BiConsumer<T, Path> consumer) Traverses the asset paths within a given directory and invokes the provided consumer for each file that matches the specified file extension.
-
Constructor Details
-
AssetPackPathUtil
public AssetPackPathUtil()
-
-
Method Details
-
relativizeAssetPath
Relativizes the given asset path against its containing asset pack's root path.- Parameters:
path- the path to relativize; must not benull. If the path is not absolute, returns the input path. If the path is absolute but doesn't belong to any recognized asset pack, it will returnnull.- Returns:
- the relativized path within the asset pack it belongs to. May return
nullif the path cannot be relativized within an asset pack.
-
resolveAssetPath
Resolves the given path to its corresponding asset path. This considers the current prioritization of asset packs to find the highest-priority occurrence of the asset.- Parameters:
path- the path to resolve; must not benull.- Returns:
- the resolved asset path if found;
nullif the path cannot be resolved to a file. - Throws:
InvalidPathException- if the path is absolute but cannot be relativized within an asset pack.
-
resolveAssetPath
@Nullable public static Path resolveAssetPath(@Nonnull Path path, @Nonnull String[] extensions) throws InvalidPathException Resolves the given path to its corresponding asset path. This considers the current prioritization of asset packs to find the highest-priority occurrence of the asset file.An array of viable file extensions can also be provided in order to find assets that can exist in different formats (eg json and/or binary formats, like prefab assets). If an exact path cannot be found for the given path, each file extension will be appended to the path and tested. The first path-with-extension matching an existing file is returned as the result.
- Parameters:
path- the path to resolve; must not benull.extensions- an ordered array of file extensions that will be appended to the path to find matching alternative file formats.- Returns:
- the resolved asset path if found;
nullif the path cannot be resolved to an existing file. - Throws:
InvalidPathException- if the path is absolute but cannot be relativized within an asset pack.
-
visitAssetPaths
public static <T> void visitAssetPaths(@Nonnull Path path, @Nonnull String extension, int maxDepth, @Nullable T ctx, @Nonnull BiConsumer<T, Path> consumer) throws InvalidPathException, IOExceptionTraverses the asset paths within a given directory and invokes the provided consumer for each file that matches the specified file extension. This method considers the prioritization of asset packs and traverses them in priority order. Paths may be passed to the consumer in a non-lexicographical order depending on the ordering and contents of the registered asset packs.- Parameters:
path- the base path to start traversal from; must not benull.extension- the file extension to filter files; must not benull.maxDepth- the maximum directory depth for the traversal.ctx- an optional context object to be passed to the consumer; may benull.consumer- a bi-consumer that processes each matching file path along with the context; must not benull.- Throws:
InvalidPathException- if the path cannot be relativized to a recognized asset pack root.IOException- if an I/O error is encountered during file traversal.
-