clean up classpaths, deprecating options.forge.path to options.forge

This commit is contained in:
Pierce 2019-05-04 21:57:12 -04:00
parent ebefa405a0
commit 5748b386e3
5 changed files with 26 additions and 11 deletions

View file

@ -50,7 +50,7 @@ launcher.authenticator.getAuth("email", "password").then(auth => {
| `options.version.custom` | String | Name of the jar, json, and folder of the custom client you are launching with. (Optifine) | False | | `options.version.custom` | String | Name of the jar, json, and folder of the custom client you are launching with. (Optifine) | False |
| `options.memory.max` | String | Max amount of memory being used by Minectaft | True | | `options.memory.max` | String | Max amount of memory being used by Minectaft | True |
| `options.memory.min` | String | Min amount of memory being used by Minectaft | True | | `options.memory.min` | String | Min amount of memory being used by Minectaft | True |
| `options.forge.path` | String | Path to Universal Forge Jar | False | | `options.forge` | String | Path to Universal Forge Jar | False |
| `options.customArgs` | String | Array of custom JVM options | False | | `options.customArgs` | String | Array of custom JVM options | False |
| `options.server.host` | String | Host url to the server, don't include the port | False | | `options.server.host` | String | Host url to the server, don't include the port | False |
| `options.server.port` | String | Port of the host url, will default to `25565` if not entered. | False | | `options.server.port` | String | Port of the host url, will default to `25565` if not entered. | False |
@ -144,9 +144,7 @@ launcher.authenticator.getAuth("email", "password").then(auth => {
authorization: auth, authorization: auth,
clientPackage: null, clientPackage: null,
root: "C:/Users/user/AppData/Roaming/.mc", root: "C:/Users/user/AppData/Roaming/.mc",
forge: { forge: "C:/Users/user/Desktop/forge.jar",
path: "C:/Users/user/Desktop/forge.jar"
},
os: "windows", os: "windows",
version: { version: {
number: "1.12.2", // needs to be the same as the Forge version number: "1.12.2", // needs to be the same as the Forge version

View file

@ -1,3 +1,7 @@
const event = require('events'); const event = new (require('events')).EventEmitter();
event.on('newListener', event => {
module.exports = new event.EventEmitter(); if(event === 'start') {
process.emitWarning('The \'start\' event is deprecated. Use \'data\' instead.', 'DeprecationWarning');
}
});
module.exports = event;

View file

@ -266,6 +266,17 @@ module.exports.getClasses = function (options, version) {
}); });
}; };
module.exports.cleanUp = async function(array) {
const newArray = [];
for(let argument in array) {
if(newArray.includes(array[argument])) continue;
newArray.push(array[argument]);
}
return newArray;
};
module.exports.getLaunchOptions = function (version, modification, options) { module.exports.getLaunchOptions = function (version, modification, options) {
return new Promise(resolve => { return new Promise(resolve => {
let type = modification || version; let type = modification || version;

View file

@ -32,8 +32,9 @@ module.exports = async function (options) {
let forge = null; let forge = null;
let custom = null; let custom = null;
if(options.forge) { if(options.forge) {
if(options.forge.path) process.emitWarning('\'options.forge.path\' will be deprecated. Use \'options.forge\' instead');
event.emit('debug', '[MCLC]: Detected Forge in options, getting dependencies'); event.emit('debug', '[MCLC]: Detected Forge in options, getting dependencies');
forge = await handler.getForgeDependencies(options.root, versionFile, options.forge.path); forge = await handler.getForgeDependencies(options.root, versionFile, options.forge.path || options.forge);
} }
if(options.version.custom) { if(options.version.custom) {
event.emit('debug', '[MCLC]: Detected custom in options, setting custom version file'); event.emit('debug', '[MCLC]: Detected custom in options, setting custom version file');
@ -56,17 +57,18 @@ module.exports = async function (options) {
if(options.customArgs) jvm = jvm.concat(options.customArgs); if(options.customArgs) jvm = jvm.concat(options.customArgs);
const classes = await handler.getClasses(options, versionFile); const classes = await handler.getClasses(options, versionFile);
const classPaths = ['-cp']; let classPaths = ['-cp'];
const separator = options.os === "windows" ? ";" : ":"; const separator = options.os === "windows" ? ";" : ":";
event.emit('debug', `[MCLC]: Using ${separator} to separate class paths`); event.emit('debug', `[MCLC]: Using ${separator} to separate class paths`);
if(forge) { if(forge) {
event.emit('debug', '[MCLC]: Setting Forge class paths'); event.emit('debug', '[MCLC]: Setting Forge class paths');
classPaths.push(`${options.forge.path}${separator}${forge.paths.join(separator)}${separator}${classes.join(separator)};${mcPath}`); classPaths.push(`${options.forge.path || options.forge}${separator}${forge.paths.join(separator)}${separator}${classes.join(separator)};${mcPath}`);
classPaths.push(forge.forge.mainClass) classPaths.push(forge.forge.mainClass)
} else { } else {
classPaths.push(`${mcPath}${separator}${classes.join(separator)}`); classPaths.push(`${mcPath}${separator}${classes.join(separator)}`);
classPaths.push(versionFile.mainClass || custom.mainClass); classPaths.push(versionFile.mainClass || custom.mainClass);
} }
classPaths = await handler.cleanUp(classPaths);
// Download version's assets // Download version's assets
event.emit('debug', '[MCLC]: Attempting to download assets'); event.emit('debug', '[MCLC]: Attempting to download assets');

View file

@ -1,6 +1,6 @@
{ {
"name": "minecraft-launcher-core", "name": "minecraft-launcher-core",
"version": "2.6.1", "version": "2.6.2",
"description": "Module that downloads Minecraft assets and runs Minecraft. Also Supports Forge", "description": "Module that downloads Minecraft assets and runs Minecraft. Also Supports Forge",
"main": "index.js", "main": "index.js",
"dependencies": { "dependencies": {