UNPKG

mjsrv

Version:

JavaScript library to initalize Minecraft Java servers

156 lines (95 loc) 4.05 kB
<div align="center"> # mjsrv ## Minecraft JS server [![NPM Version](https://img.shields.io/npm/v/mjsrv?color=blue&label=npm)](https://www.npmjs.com/package/mjsrv) [![License](https://img.shields.io/github/license/myferr/mjsrv?color=yellow)](https://github.com/myferr/mjsrv/blob/main/LICENSE) [![Made with Node.js](https://img.shields.io/badge/Made%20with-Node.js-43853D?logo=node.js&logoColor=white)](https://nodejs.org/) [![Minecraft Java](https://img.shields.io/badge/Minecraft-Java-62B47A?logo=minecraft&logoColor=white)](https://www.minecraft.net/) A JavaScript library for creating and managing Minecraft Java servers. </div> ## Installation ```bash npm install mjsrv ``` ## Quick Start ```javascript import { MinecraftServer } from "mjsrv"; MinecraftServer.create({ version: "1.21.6", motd: "Welcome to my server!", id: "my-server", }); setTimeout(() => { MinecraftServer.serve("my-server"); }, 5000); ``` ## Documentation ### `MinecraftServer` The `MinecraftServer` class provides methods for creating and managing Minecraft servers. #### `MinecraftServer.create(options)` Creates a new Minecraft server. **Options:** - `version` (string): The version of the Minecraft server to create. Defaults to the latest version. - `motd` (string): The message of the day for the server. **Required**. - `id` (string): The ID of the server. Defaults to `minecraft-server-<random_6_figure_uuid>`. - `maxPlayers` (number): The maximum number of players that can join the server. Defaults to `20`. - `hardcore` (boolean): Whether to enable hardcore mode. Defaults to `false`. **Example:** ```javascript import { MinecraftServer } from "mjsrv"; MinecraftServer.create({ version: "1.21.6", motd: "Welcome to my hardcore server!", id: "my-hardcore-server", hardcore: true, }); ``` #### `MinecraftServer.serve(id, port, gui)` Starts a Minecraft server. - `id` (string): The ID of the server to start. - `port` (number): The port to start the server on. Defaults to `25565`. - `gui` (boolean): Whether to enable the MinecraftServer GUI. Defaults to `false`. To specify, first specify `port`. #### `MinecraftServer.start(id, port, gui)` Starts a Minecraft server. - `id` (string): The ID of the server to start. - `port` (number): The port to start the server on. Defaults to `25565`. - `gui` (boolean): Whether to enable the MinecraftServer GUI. Defaults to `false`. To specify, first specify `port`. #### `MinecraftServer.stop(id)` Stops a Minecraft server. - `id` (string): The ID of the server to stop. #### `MinecraftServer.restart(id)` Restarts a Minecraft server. - `id` (string): The ID of the server to restart. #### `MinecraftServer.delete(id)` Deletes a Minecraft server. - `id` (string): The ID of the server to delete. #### `MinecraftServer.toContainer(id, options)` Converts a Minecraft server to a Docker container. - `id` (string): The ID of the server to convert. - `options` (object): - `image` (string): The name of the Docker image to create. Defaults to the server ID. **Example:** ```javascript import { MinecraftServer } from "mjsrv"; MinecraftServer.toContainer("my-server", { image: "my-minecraft-image" }); ``` ### `Containers` The `Containers` class provides methods for managing Docker containers for Minecraft servers. #### `Containers.start(id, image, port)` Starts a Docker container for a Minecraft server. - `id` (string): The ID of the server. - `image` (string): The name of the Docker image to use. - `port` (number): The port to start the server on. Defaults to `25565`. #### `Containers.stop(id)` Stops a Docker container for a Minecraft server. - `id` (string): The ID of the server. #### `Containers.restart(id)` Restarts a Docker container for a Minecraft server. - `id` (string): The ID of the server. #### `Containers.delete(id)` Deletes a Docker container for a Minecraft server. - `id` (string): The ID of the server. ## Contributing Contributions are welcome! Please open an issue or submit a pull request. ## License [MIT](LICENSE)