Skip to content

Commit e2eb8ad

Browse files
committed
Added getLaunchCommand for all launchers
1 parent 83aeb86 commit e2eb8ad

File tree

3 files changed

+44
-16
lines changed

3 files changed

+44
-16
lines changed
Lines changed: 22 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,24 +1,39 @@
11
package sk.tomsik68.mclauncher.api.versions;
22

3+
import java.util.List;
4+
35
import sk.tomsik68.mclauncher.api.common.ILaunchSettings;
46
import sk.tomsik68.mclauncher.api.common.mc.IMinecraftInstance;
57
import sk.tomsik68.mclauncher.api.login.ISession;
68
import sk.tomsik68.mclauncher.api.servers.ISavedServer;
9+
710
/**
811
* Launcher can run one type of version
12+
*
913
* @author Tomsik68
10-
*
14+
*
1115
*/
1216
public interface IVersionLauncher {
17+
18+
public List<String> getLaunchCommand(ISession session, IMinecraftInstance mc, ISavedServer server, IVersion version, ILaunchSettings settings)
19+
throws Exception;
20+
1321
/**
1422
* Launches minecraft
15-
* @param session Login session
16-
* @param mc Target minecraft instance
17-
* @param server Server to connect to
18-
* @param version Version to launch
19-
* @param settings Launch settings
23+
*
24+
* @param session
25+
* Login session
26+
* @param mc
27+
* Target minecraft instance
28+
* @param server
29+
* Server to connect to
30+
* @param version
31+
* Version to launch
32+
* @param settings
33+
* Launch settings
2034
* @return Process which was created
21-
* @throws Exception various errors
35+
* @throws Exception
36+
* various errors
2237
*/
2338
public Process launch(ISession session, IMinecraftInstance mc, ISavedServer server, IVersion version, ILaunchSettings settings) throws Exception;
2439
}

src/sk/tomsik68/mclauncher/impl/versions/mcassets/MCAssetsVersionLauncher.java

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,15 @@ public class MCAssetsVersionLauncher implements IVersionLauncher {
1919

2020
@Override
2121
public Process launch(ISession session, IMinecraftInstance mc, ISavedServer server, IVersion version, ILaunchSettings settings) throws Exception {
22+
ProcessBuilder pb = new ProcessBuilder(getLaunchCommand(session, mc, server, version, settings));
23+
pb.redirectErrorStream(settings.isErrorStreamRedirected());
24+
Process result = pb.start();
25+
return result;
26+
}
27+
28+
@Override
29+
public List<String> getLaunchCommand(ISession session, IMinecraftInstance mc, ISavedServer server, IVersion version, ILaunchSettings settings)
30+
throws Exception {
2231
String pathToJar = Relauncher.class.getProtectionDomain().getCodeSource().getLocation().getFile();
2332
List<String> command = new ArrayList<String>();
2433
if (settings.getCommandPrefix() != null && !settings.getCommandPrefix().isEmpty())
@@ -68,10 +77,7 @@ public Process launch(ISession session, IMinecraftInstance mc, ISavedServer serv
6877
command.add(mc.getLibraryProvider().getNativesDirectory(version).getAbsolutePath());
6978
command.add("-jlibpath");
7079
command.add(mc.getLibraryProvider().getNativesDirectory(version).getAbsolutePath());
71-
ProcessBuilder pb = new ProcessBuilder(command);
72-
pb.redirectErrorStream(settings.isErrorStreamRedirected());
73-
Process result = pb.start();
74-
return result;
80+
return command;
7581
}
7682

7783
}

src/sk/tomsik68/mclauncher/impl/versions/mcdownload/MCDownloadVersionLauncher.java

Lines changed: 12 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,16 @@ public String[] getMinecraftArguments(IMinecraftInstance mc, ISession session, I
5555

5656
@Override
5757
public Process launch(ISession session, IMinecraftInstance mc, ISavedServer server, IVersion v, ILaunchSettings settings) throws Exception {
58+
59+
ProcessBuilder pb = new ProcessBuilder(getLaunchCommand(session, mc, server, v, settings));
60+
pb.redirectErrorStream(settings.isErrorStreamRedirected());
61+
pb.directory(mc.getLocation());
62+
return pb.start();
63+
}
64+
65+
@Override
66+
public List<String> getLaunchCommand(ISession session, IMinecraftInstance mc, ISavedServer server, IVersion v, ILaunchSettings settings)
67+
throws Exception {
5868
// get JSON information about the version
5969
File jsonFile = new File(mc.getJarProvider().getVersionFile(v.getUniqueID()).getParent(), "info.json");
6070
System.out.println("Looking for " + jsonFile.getAbsolutePath());
@@ -106,10 +116,7 @@ public Process launch(ISession session, IMinecraftInstance mc, ISavedServer serv
106116
command.add("--port");
107117
command.add("" + server.getPort());
108118
}
109-
ProcessBuilder pb = new ProcessBuilder(command);
110-
pb.redirectErrorStream(settings.isErrorStreamRedirected());
111-
pb.directory(mc.getLocation());
112-
System.out.println(command.toString());
113-
return pb.start();
119+
120+
return command;
114121
}
115122
}

0 commit comments

Comments
 (0)