From 5748b386e338c97fc1bb4e860606ea46e14a8357 Mon Sep 17 00:00:00 2001 From: Pierce Date: Sat, 4 May 2019 21:57:12 -0400 Subject: [PATCH] clean up classpaths, deprecating options.forge.path to options.forge --- README.md | 6 ++---- components/events.js | 10 +++++++--- components/handler.js | 11 +++++++++++ components/launcher.js | 8 +++++--- package.json | 2 +- 5 files changed, 26 insertions(+), 11 deletions(-) diff --git a/README.md b/README.md index f2680b1..5c84ec9 100644 --- a/README.md +++ b/README.md @@ -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.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.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.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 | @@ -144,9 +144,7 @@ launcher.authenticator.getAuth("email", "password").then(auth => { authorization: auth, clientPackage: null, root: "C:/Users/user/AppData/Roaming/.mc", - forge: { - path: "C:/Users/user/Desktop/forge.jar" - }, + forge: "C:/Users/user/Desktop/forge.jar", os: "windows", version: { number: "1.12.2", // needs to be the same as the Forge version diff --git a/components/events.js b/components/events.js index 3dd35bf..f0bcb4a 100644 --- a/components/events.js +++ b/components/events.js @@ -1,3 +1,7 @@ -const event = require('events'); - -module.exports = new event.EventEmitter(); \ No newline at end of file +const event = new (require('events')).EventEmitter(); +event.on('newListener', event => { + if(event === 'start') { + process.emitWarning('The \'start\' event is deprecated. Use \'data\' instead.', 'DeprecationWarning'); + } +}); +module.exports = event; \ No newline at end of file diff --git a/components/handler.js b/components/handler.js index a608fe4..944721c 100644 --- a/components/handler.js +++ b/components/handler.js @@ -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) { return new Promise(resolve => { let type = modification || version; diff --git a/components/launcher.js b/components/launcher.js index f1a90e5..aa65bd4 100644 --- a/components/launcher.js +++ b/components/launcher.js @@ -32,8 +32,9 @@ module.exports = async function (options) { let forge = null; let custom = null; 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'); - 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) { 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); const classes = await handler.getClasses(options, versionFile); - const classPaths = ['-cp']; + let classPaths = ['-cp']; const separator = options.os === "windows" ? ";" : ":"; event.emit('debug', `[MCLC]: Using ${separator} to separate class paths`); if(forge) { 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) } else { classPaths.push(`${mcPath}${separator}${classes.join(separator)}`); classPaths.push(versionFile.mainClass || custom.mainClass); } + classPaths = await handler.cleanUp(classPaths); // Download version's assets event.emit('debug', '[MCLC]: Attempting to download assets'); diff --git a/package.json b/package.json index 4e49808..3611712 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "minecraft-launcher-core", - "version": "2.6.1", + "version": "2.6.2", "description": "Module that downloads Minecraft assets and runs Minecraft. Also Supports Forge", "main": "index.js", "dependencies": {