Class AssetPackPathUtil

java.lang.Object
com.hypixel.hytale.server.core.asset.util.AssetPackPathUtil

public class AssetPackPathUtil extends Object
Utils for resolving actual asset file paths across AssetPack FileSystems.
  • Constructor Details

    • AssetPackPathUtil

      public AssetPackPathUtil()
  • Method Details

    • relativizeAssetPath

      @Nullable public static Path relativizeAssetPath(@Nonnull Path path)
      Relativizes the given asset path against its containing asset pack's root path.
      Parameters:
      path - the path to relativize; must not be null. 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 return null.
      Returns:
      the relativized path within the asset pack it belongs to. May return null if the path cannot be relativized within an asset pack.
    • resolveAssetPath

      @Nullable public static Path resolveAssetPath(@Nonnull Path path) 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.
      Parameters:
      path - the path to resolve; must not be null.
      Returns:
      the resolved asset path if found; null if 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 be null.
      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; null if 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, IOException
      Traverses 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 be null.
      extension - the file extension to filter files; must not be null.
      maxDepth - the maximum directory depth for the traversal.
      ctx - an optional context object to be passed to the consumer; may be null.
      consumer - a bi-consumer that processes each matching file path along with the context; must not be null.
      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.