PackDetector.java

net.minecraft.server.packs.repository.PackDetector

信息

  • 全限定名:net.minecraft.server.packs.repository.PackDetector
  • 类型:public abstract class
  • 包:net.minecraft.server.packs.repository
  • 源码路径:src/main/java/net/minecraft/server/packs/repository/PackDetector.java
  • 起始行号:L14
  • 职责:

    TODO

字段/常量

  • validator
    • 类型: DirectoryValidator
    • 修饰符: private final
    • 源码定位: L15
    • 说明:

      TODO

内部类/嵌套类型

构造器

protected PackDetector(DirectoryValidator validator) @ L17

  • 构造器名:PackDetector
  • 源码定位:L17
  • 修饰符:protected

参数:

  • validator: DirectoryValidator

说明:

TODO

方法

下面的方法块按源码顺序生成。

public T detectPackResources(Path content, List<ForbiddenSymlinkInfo> issues) @ L21

  • 方法名:detectPackResources
  • 源码定位:L21
  • 返回类型:T
  • 修饰符:public

参数:

  • content: Path
  • issues: List

说明:

TODO

protected abstract T createZipPack(Path content) @ L53

  • 方法名:createZipPack
  • 源码定位:L53
  • 返回类型:T
  • 修饰符:protected abstract

参数:

  • content: Path

说明:

TODO

protected abstract T createDirectoryPack(Path content) @ L55

  • 方法名:createDirectoryPack
  • 源码定位:L55
  • 返回类型:T
  • 修饰符:protected abstract

参数:

  • content: Path

说明:

TODO

代码

public abstract class PackDetector<T> {
    private final DirectoryValidator validator;
 
    protected PackDetector(DirectoryValidator validator) {
        this.validator = validator;
    }
 
    public @Nullable T detectPackResources(Path content, List<ForbiddenSymlinkInfo> issues) throws IOException {
        Path targetContext = content;
 
        BasicFileAttributes attributes;
        try {
            attributes = Files.readAttributes(content, BasicFileAttributes.class, LinkOption.NOFOLLOW_LINKS);
        } catch (NoSuchFileException var6) {
            return null;
        }
 
        if (attributes.isSymbolicLink()) {
            this.validator.validateSymlink(content, issues);
            if (!issues.isEmpty()) {
                return null;
            }
 
            targetContext = Files.readSymbolicLink(content);
            attributes = Files.readAttributes(targetContext, BasicFileAttributes.class, LinkOption.NOFOLLOW_LINKS);
        }
 
        if (attributes.isDirectory()) {
            this.validator.validateKnownDirectory(targetContext, issues);
            if (!issues.isEmpty()) {
                return null;
            } else {
                return !Files.isRegularFile(targetContext.resolve("pack.mcmeta")) ? null : this.createDirectoryPack(targetContext);
            }
        } else {
            return attributes.isRegularFile() && targetContext.getFileName().toString().endsWith(".zip") ? this.createZipPack(targetContext) : null;
        }
    }
 
    protected abstract @Nullable T createZipPack(final Path content) throws IOException;
 
    protected abstract @Nullable T createDirectoryPack(final Path content) throws IOException;
}

引用的其他类