Package Exports
- minecraft-java-server
- minecraft-java-server/dist/index.js
This package does not declare an exports field, so the exports above have been automatically detected and optimized by JSPM instead. If any package subpath is missing, it is recommended to post an issue to the original package (minecraft-java-server) to support the "exports" field. If that is not possible, create a JSPM override to customize the exports field for this package.
Readme
Minecraft Java Server
This library helps you run and manage your Minecraft Java Edition server through a node.js environment. It supports type declarations with Typescript, meaning you don't need to install any @types library.
It is heavily inspired by @scriptserver/core. I created it after discovering a missing feature in the library, and decided to make my own, both to learn, and to be able to continue what I was working on.
The library utilizes Minecraft's rcon feature. It allows you to securely send commands through networking, and receive the output text through the response.
Usage
Installation
Run the following command in your project's root directory:
npm install minecraft-java-server --saveBasic Usage
import { MinecraftServer } from 'minecraft-java-server';
const server = new MinecraftServer({
jar: 'server.jar',
path: 'C:/path/to/your/minecraft/server/directory',
args: ['-Xms4G', '-Xmx4G'],
// Minecraft's eula must be agreed to using this value
eula: true,
// every property is the equivalent of server.properties, except for vital ones
properties: {
motd: "Minecraft server hosted with minecraft-java-server",
"max-players": 10
}
});
// Start event
server.on('start', () => {
console.log('Server started');
});
// Stop event
server.on('stop', () => {
console.log('Server stopped');
});
// Start the server
server.start();
server.send('ban herobrine').then(response => {
console.log('Command result: ', response);
}).catch(err => console.log('Failed to run command', err));Since server.send returns a promise, this also works in an asynchronous context using await. The promise is rejected if the server disconnects after queueing the command.