Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix Loading Mappings When Mappings File is in a Folder #864

Merged
merged 2 commits into from
Dec 8, 2023
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -99,15 +99,17 @@ public boolean requiresPackageAccessHack() {
private void initializeMetadata() {
if (initializedMetadata) return;

final JarURLConnection connection = openMappingsJar();
final URLConnection connection = openMappings();

try {
if (connection != null) {
final Manifest manifest = connection.getManifest();
if (connection instanceof JarURLConnection) {
final Manifest manifest = ((JarURLConnection)connection).getManifest();

if (manifest != null) {
gameId = ManifestUtil.getManifestValue(manifest, new Name("Game-Id"));
gameVersion = ManifestUtil.getManifestValue(manifest, new Name("Game-Version"));
if (manifest != null) {
gameId = ManifestUtil.getManifestValue(manifest, new Name("Game-Id"));
gameVersion = ManifestUtil.getManifestValue(manifest, new Name("Game-Version"));
}
}

try (BufferedReader reader = new BufferedReader(new InputStreamReader(connection.getInputStream()))) {
Expand Down Expand Up @@ -136,7 +138,7 @@ private void initializeMappings() {
if (initializedMappings) return;

initializeMetadata();
final URLConnection connection = openMappingsJar();
final URLConnection connection = openMappings();

if (connection != null) {
try (BufferedReader reader = new BufferedReader(new InputStreamReader(connection.getInputStream()))) {
Expand Down Expand Up @@ -172,16 +174,12 @@ private void initializeMappings() {
}

@Nullable
private JarURLConnection openMappingsJar() {
private URLConnection openMappings() {
URL url = MappingConfiguration.class.getClassLoader().getResource("mappings/mappings.tiny");

if (url != null) {
try {
URLConnection connection = url.openConnection();

if (connection instanceof JarURLConnection) {
return (JarURLConnection) connection;
}
return url.openConnection();
} catch (IOException | ZipError e) {
throw new RuntimeException("Error reading "+url, e);
}
Expand Down
Loading