Skip to content

Commit

Permalink
Some tiny things...
Browse files Browse the repository at this point in the history
  • Loading branch information
PhoenixVX committed Mar 13, 2024
1 parent c19bbf9 commit 32e5fec
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 4 deletions.
9 changes: 8 additions & 1 deletion src/main/java/org/mcphackers/mcp/TranslatorUtil.java
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,14 @@ private void readTranslation(Class<?> cls, Language lang) {
private void readTranslation(Map<String, String> map, Class<?> cls, Language lang) {
String resourceName = "/lang/" + lang.name + ".lang";
//FIXME Hardcoded MCP.class because Class#getResourceAsStream return result is not the same as ClassLoader#getResourceAsStream
InputStream resource = (cls == MCP.class) ? cls.getResourceAsStream(resourceName) : cls.getClassLoader().getResourceAsStream(resourceName);
try (InputStream resource = (cls == MCP.class) ? cls.getResourceAsStream(resourceName) : cls.getClassLoader().getResourceAsStream(resourceName)) {
this.readTranslation(map, resource);
} catch (IOException ex) {
ex.printStackTrace();
}
}

private void readTranslation(Map<String, String> map, InputStream resource) {
if (resource == null) {
return;
}
Expand Down
15 changes: 13 additions & 2 deletions src/main/java/org/mcphackers/mcp/plugin/PluginManager.java
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
package org.mcphackers.mcp.plugin;

import java.io.IOException;
import java.nio.file.FileSystem;
import java.nio.file.FileSystems;
import java.nio.file.Files;
import java.nio.file.Path;
import java.nio.file.Paths;
Expand Down Expand Up @@ -30,8 +32,17 @@ public void discoverPlugins(MCP mcp) {
if (Files.exists(pluginsDir) && Files.isDirectory(pluginsDir)) {
List<Path> pluginCandidates = FileUtil.getPathsOfType(pluginsDir, ".jar", ".zip");
for (Path pluginCandidate : pluginCandidates) {
System.out.println("Adding " + pluginCandidate.getFileName() + " to classpath!");
pluginClassLoader.addURL(pluginCandidate.toUri().toURL());
try (FileSystem fs = FileSystems.newFileSystem(pluginCandidate, pluginClassLoader)) {
Path serviceConfigPath = fs.getPath("META-INF", "services", MCPPlugin.class.getName());
if (!Files.exists(serviceConfigPath)) {
System.out.println("Plugin candidate (" + pluginCandidate.getFileName() + ") does not contain a valid service configuration. Skipping!");
} else {
System.out.println("Adding plugin candidate (" + pluginCandidate.getFileName() + ") to classpath!");
pluginClassLoader.addURL(pluginCandidate.toUri().toURL());
}
} catch (IOException ex) {
ex.printStackTrace();
}
}
}

Expand Down
3 changes: 2 additions & 1 deletion src/main/java/org/mcphackers/mcp/tasks/TaskRun.java
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

import static org.mcphackers.mcp.MCPPaths.*;

import java.io.File;
import java.io.IOException;
import java.nio.file.Files;
import java.nio.file.Path;
Expand Down Expand Up @@ -58,7 +59,7 @@ protected Stage[] setStages() {
Collections.addAll(args, runArgs);
args.add("-Djava.library.path=" + natives);
args.add("-cp");
args.add(String.join(System.getProperty("path.separator"), classPath));
args.add(String.join(File.pathSeparator, classPath));
args.add(main);
if (side == Side.CLIENT) {
args.addAll(getLaunchArgs(mcp, mcpSide));
Expand Down

0 comments on commit 32e5fec

Please sign in to comment.