Fixed dev bugs and old docs. Added restart and close functions

This commit is contained in:
Pierce 2019-05-23 19:40:34 -04:00
parent 1a5d290cc8
commit 69ec61f56e
3 changed files with 28 additions and 8 deletions

View file

@ -52,26 +52,35 @@ launcher.on('error', (e) => console.log(e));
| `options.version.number` | String | Minecraft version that is going to be launched. | True |
| `options.version.type` | String | Any string. The actual Minecraft launcher uses `release` and `snapshot`. | True |
| `options.memory.max` | String | Max amount of memory being used by Minectaft. | True |
| `options.forge.path` | String | Path to Universal Forge Jar. | False |
| `options.memory.min` | String | Min amount of memory being used by Minectaft. | True |
| `options.forge` | String | Path to Universal Forge Jar. | 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.proxy.host` | String | Host url to the proxy, don't include the port. | False |
| `options.proxy.port` | String | Port of the host proxy, will default to `8080` if not entered. | False |
| `options.proxy.username` | String | Username for the proxy. | False |
| `options.proxy.password` | String | Password for the proxy. | False |
| `options.timeout` | Interger | Timeout on download requests. | False |
| `options.timeout` | Integer | Timeout on download requests. | False |
##### Note
If you are loading up a client outside of vanilla Minecraft or Forge (Optifine and for an example), you'll need to download the needed files yourself
if you don't provide downloads url downloads like Forge and Fabric. Still need to provide the version jar.
#### Client Functions
| Function | Type | Description |
|----------|---------|-----------------------------------------------------------------------------------------|
| `launch` | Promise | Launches the client with the specified `options` |
| `close` | Promise | Closes current client |
| `restart`| Promise | Restarts by closing the current client then relaunching it with the specified `options` |
#### Authenticator Functions
##### getAuth
| Parameter | Type | Description | Required |
|-----------|--------|--------------------------------------------------------------|----------|
| `email` | String | Email or username | True |
| `password` | String | Password for the Mojang account being used if online mode. | False |
| `username`| String | Email or username | True |
| `password`| String | Password for the Mojang account being used if online mode. | False |
##### validate

View file

@ -1,5 +1,4 @@
const child = require('child_process');
const event = require('./events');
const path = require('path');
const handler = require('./handler');
const packager = require('./package');
@ -12,6 +11,7 @@ class MCLCore extends EventEmitter {
this.options = options;
this.handler = new handler(this);
this.pid = null;
}
async launch() {
@ -90,13 +90,24 @@ class MCLCore extends EventEmitter {
const launchOptions = await this.handler.getLaunchOptions(modification);
const launchArguments = args.concat(jvm, classPaths, launchOptions);
event.emit('arguments', launchArguments);
event.emit('debug', launchArguments.join(' '));
this.emit('arguments', launchArguments);
this.emit('debug', launchArguments.join(' '));
const minecraft = child.spawn(this.options.javaPath ? this.options.javaPath : 'java', launchArguments);
minecraft.stdout.on('data', (data) => this.emit('data', data));
minecraft.stderr.on('data', (data) => this.emit('error', data));
minecraft.on('close', (code) => this.emit('close', code));
this.pid = minecraft.pid;
}
async close() {
child.exec(`taskkill /PID ${this.pid}`, (err, out, error) => {return {err, out, error}})
}
async restart() {
await this.close();
await this.launch()
}
}

View file

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