mirror of
https://github.com/artegoser/pimi-launcher-core.git
synced 2024-11-06 05:33:58 +03:00
small but major changes again. Pretty much done now
Removed: close restart. setting options in constructor. Added: getPid and new gif Reformatted: options now go back into the launch function. `authorization` still accepts either an json object or a promise. Better docs v2
This commit is contained in:
parent
845fac3767
commit
62d02dccba
4 changed files with 33 additions and 44 deletions
34
README.md
34
README.md
|
@ -19,6 +19,7 @@ const { Client, Authenticator } = require('minecraft-launcher-core');
|
|||
|
||||
let opts = {
|
||||
clientPackage: null,
|
||||
authorization: Authenticator.getAuth("username", "password"),
|
||||
root: "./minecraft",
|
||||
os: "windows",
|
||||
version: {
|
||||
|
@ -31,16 +32,23 @@ let opts = {
|
|||
}
|
||||
}
|
||||
|
||||
const launcher = new Client(opts);
|
||||
launcher.launch(Authenticator.getAuth(username, password));
|
||||
const launcher = new Client();
|
||||
launcher.launch(opts);
|
||||
|
||||
launcher.on('debug', (e) => console.log(e));
|
||||
launcher.on('data', (e) => console.log(e));
|
||||
launcher.on('error', (e) => console.log(e));
|
||||
```
|
||||
### Usage
|
||||
### Documentation
|
||||
|
||||
##### Client Options
|
||||
#### Client Functions
|
||||
|
||||
| Function | Type | Description |
|
||||
|----------|---------|-----------------------------------------------------------------------------------------|
|
||||
| `launch` | Promise | Launches the client with the specified `options` as a parameter |
|
||||
| `getPid` | Integer | Returns the Minecraft client's PID |
|
||||
|
||||
##### launch
|
||||
|
||||
| Parameter | Type | Description | Required |
|
||||
|--------------------------|----------|-------------------------------------------------------------------------------------------|----------|
|
||||
|
@ -52,6 +60,7 @@ launcher.on('error', (e) => console.log(e));
|
|||
| `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` | String | Path to Universal Forge Jar. | False |
|
||||
| `options.javaPath` | String | Path to the JRE executable file, will default to `java` if not entered. | 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 |
|
||||
|
@ -66,19 +75,6 @@ launcher.on('error', (e) => console.log(e));
|
|||
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` |
|
||||
|
||||
##### launch
|
||||
| Parameter | Type | Description | Required |
|
||||
|-----------|--------|--------------------------------------------------------------|----------|
|
||||
| `authentication` | Object | Result from `getAuth` or the getAuth function itself. | True |
|
||||
|
||||
#### Authenticator Functions
|
||||
|
||||
##### getAuth
|
||||
|
@ -131,5 +127,5 @@ if you don't provide downloads url downloads like Forge and Fabric. Still need t
|
|||
|
||||
|
||||
#### What should it look like running from console?
|
||||
|
||||
![gif](https://pierce.is-serious.business/7d91a7.gif)
|
||||
Showing the emitted information from debug and data, also using `getPid` after the process has been created.
|
||||
![gif](https://pierce.is-serious.business/3N3PMC4.gif)
|
||||
|
|
|
@ -301,7 +301,7 @@ class Handler {
|
|||
}
|
||||
|
||||
getLaunchOptions(modification) {
|
||||
return new Promise(resolve => {
|
||||
return new Promise(async resolve => {
|
||||
let type = modification || this.version;
|
||||
|
||||
let args = type.minecraftArguments ? type.minecraftArguments.split(' ') : type.arguments.game;
|
||||
|
@ -309,6 +309,10 @@ class Handler {
|
|||
|
||||
if(args.length < 5) args = args.concat(this.version.minecraftArguments ? this.version.minecraftArguments.split(' ') : this.version.arguments.game);
|
||||
|
||||
if({}.toString.call(this.options.authorization) === "[object Promise]") {
|
||||
this.options.authorization = await this.options.authorization;
|
||||
}
|
||||
|
||||
const fields = {
|
||||
'${auth_access_token}': this.options.authorization.access_token,
|
||||
'${auth_session}': this.options.authorization.access_token,
|
||||
|
@ -364,4 +368,4 @@ class Handler {
|
|||
}
|
||||
}
|
||||
|
||||
module.exports = Handler;
|
||||
module.exports = Handler;
|
||||
|
|
|
@ -6,24 +6,17 @@ const fs = require('fs');
|
|||
const EventEmitter = require('events').EventEmitter;
|
||||
|
||||
class MCLCore extends EventEmitter {
|
||||
constructor(options) {
|
||||
constructor() {
|
||||
super();
|
||||
|
||||
this.options = options;
|
||||
this.handler = new handler(this);
|
||||
this.pid = null;
|
||||
}
|
||||
|
||||
async launch(authorization) {
|
||||
if(!authorization) throw Error('No authorization to launch the client with!');
|
||||
|
||||
if({}.toString.call(authorization) === "[object Promise]") {
|
||||
this.options.authorization = await authorization;
|
||||
} else {
|
||||
this.options.authorization = authorization
|
||||
}
|
||||
|
||||
async launch(options) {
|
||||
this.options = options;
|
||||
this.options.root = path.resolve(this.options.root);
|
||||
this.handler = new handler(this);
|
||||
|
||||
if(!fs.existsSync(this.options.root)) {
|
||||
this.emit('debug', '[MCLC]: Attempting to create root folder');
|
||||
fs.mkdirSync(this.options.root);
|
||||
|
@ -109,14 +102,9 @@ class MCLCore extends EventEmitter {
|
|||
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()
|
||||
getPid() {
|
||||
return this.pid;
|
||||
}
|
||||
}
|
||||
|
||||
module.exports = MCLCore;
|
||||
module.exports = MCLCore;
|
||||
|
|
|
@ -1,7 +1,7 @@
|
|||
{
|
||||
"name": "minecraft-launcher-core",
|
||||
"version": "3.3.1",
|
||||
"description": "Module that downloads Minecraft assets and runs Minecraft. Also Supports Forge",
|
||||
"version": "3.4.0",
|
||||
"description": "Lightweight module that downloads and runs Minecraft using javascript / NodeJS",
|
||||
"main": "index.js",
|
||||
"dependencies": {
|
||||
"adm-zip": "^0.4.13",
|
||||
|
@ -20,7 +20,8 @@
|
|||
},
|
||||
"keywords": [
|
||||
"minecraft",
|
||||
"minecraft-launcher-node"
|
||||
"minecraft-launcher-node",
|
||||
"minecraft-launcher"
|
||||
],
|
||||
"author": "Pierce Harriz",
|
||||
"license": "MIT",
|
||||
|
|
Loading…
Reference in a new issue