Fix Platform#getFilePath not returning the *root* file path on Forge (#269)

* Platform#getFilePath now actually returns the *root* path on forge

Signed-off-by: Max <maxh2709@gmail.com>

* Add Mod#findResource (please stop yelling at me now kthx)

Signed-off-by: Max <maxh2709@gmail.com>
This commit is contained in:
Max
2022-05-28 11:54:44 +02:00
committed by GitHub
parent 517205efdc
commit 3b8b9049e0
3 changed files with 24 additions and 4 deletions

View File

@@ -61,6 +61,15 @@ public interface Mod {
@Deprecated(forRemoval = true)
Path getFilePath();
/**
* Gets an NIO Path to the given resource contained within the mod file / folder.
* The path is verified to exist, and an empty optional is returned if it doesn't.
*
* @param path The resource to search for
* @return The path of the resource if it exists, or {@link Optional#empty()} if it doesn't
*/
Optional<Path> findResource(String... path);
Collection<String> getAuthors();
@Nullable

View File

@@ -132,7 +132,12 @@ public class PlatformImpl {
public Path getFilePath() {
return container.getRootPath();
}
@Override
public Optional<Path> findResource(String... path) {
return container.findPath(String.join("/", path));
}
@Override
public Collection<String> getAuthors() {
return metadata.getAuthors().stream()

View File

@@ -35,6 +35,7 @@ import org.jetbrains.annotations.Nullable;
import javax.annotation.Nonnull;
import java.net.URL;
import java.nio.file.Files;
import java.nio.file.Path;
import java.util.*;
import java.util.concurrent.ConcurrentHashMap;
@@ -126,15 +127,20 @@ public class PlatformImpl {
public Optional<String> getLogoFile(int i) {
return this.info.getLogoFile();
}
@Override
public List<Path> getFilePaths() {
return List.of(getFilePath());
}
@Override
public Path getFilePath() {
return this.info.getOwningFile().getFile().getFilePath();
return this.info.getOwningFile().getFile().getSecureJar().getRootPath();
}
@Override
public Optional<Path> findResource(String... path) {
return Optional.of(this.info.getOwningFile().getFile().findResource(path)).filter(Files::exists);
}
@Override