@dimzxzzx07/mc-headless 1.8.0 → 1.9.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (37) hide show
  1. package/README.md +317 -703
  2. package/dist/core/JavaChecker.d.ts +16 -3
  3. package/dist/core/JavaChecker.d.ts.map +1 -1
  4. package/dist/core/JavaChecker.js +171 -65
  5. package/dist/core/JavaChecker.js.map +1 -1
  6. package/dist/core/MinecraftServer.d.ts +15 -0
  7. package/dist/core/MinecraftServer.d.ts.map +1 -1
  8. package/dist/core/MinecraftServer.js +200 -110
  9. package/dist/core/MinecraftServer.js.map +1 -1
  10. package/dist/index.d.ts +3 -0
  11. package/dist/index.d.ts.map +1 -1
  12. package/dist/index.js +31 -16
  13. package/dist/index.js.map +1 -1
  14. package/dist/platforms/BedrockServer.d.ts.map +1 -1
  15. package/dist/platforms/BedrockServer.js +2 -0
  16. package/dist/platforms/BedrockServer.js.map +1 -1
  17. package/dist/platforms/JavaServer.d.ts.map +1 -1
  18. package/dist/platforms/JavaServer.js +2 -0
  19. package/dist/platforms/JavaServer.js.map +1 -1
  20. package/dist/platforms/SkinRestorer.d.ts +14 -0
  21. package/dist/platforms/SkinRestorer.d.ts.map +1 -0
  22. package/dist/platforms/SkinRestorer.js +145 -0
  23. package/dist/platforms/SkinRestorer.js.map +1 -0
  24. package/dist/platforms/SkinsRestorer.d.ts +14 -0
  25. package/dist/platforms/SkinsRestorer.d.ts.map +1 -0
  26. package/dist/platforms/SkinsRestorer.js +145 -0
  27. package/dist/platforms/SkinsRestorer.js.map +1 -0
  28. package/dist/types/index.d.ts +2 -0
  29. package/dist/types/index.d.ts.map +1 -1
  30. package/package.json +1 -1
  31. package/src/core/JavaChecker.ts +162 -61
  32. package/src/core/MinecraftServer.ts +233 -120
  33. package/src/index.ts +33 -17
  34. package/src/platforms/BedrockServer.ts +2 -0
  35. package/src/platforms/JavaServer.ts +2 -0
  36. package/src/platforms/SkinRestorer.ts +127 -0
  37. package/src/types/index.ts +2 -0
package/README.md CHANGED
@@ -1,16 +1,16 @@
1
- @dimzxzzx07/mc-headless
1
+ # @dimzxzzx07/mc-headless
2
2
 
3
3
  <div align="center">
4
4
  <img src="https://i.imgur.com/LIQuuPL.jpeg" width="800" alt="Minecraft Headless Server">
5
5
  </div>
6
6
 
7
7
  <div align="center">
8
- <img src="https://img.shields.io/badge/Version-1.7.0-2563eb?style=for-the-badge&logo=typescript" alt="Version">
8
+ <img src="https://img.shields.io/badge/Version-1.9.0-2563eb?style=for-the-badge&logo=typescript" alt="Version">
9
9
  <img src="https://img.shields.io/badge/License-MIT-green?style=for-the-badge&logo=open-source-initiative" alt="License">
10
10
  <img src="https://img.shields.io/badge/Node-18%2B-339933?style=for-the-badge&logo=nodedotjs" alt="Node">
11
- <img src="https://img.shields.io/badge/Java-17%2B-007396?style=for-the-badge&logo=openjdk" alt="Java">
11
+ <img src="https://img.shields.io/badge/Java-Portable-007396?style=for-the-badge&logo=openjdk" alt="Java Portable">
12
12
  <img src="https://img.shields.io/badge/Termux-Friendly-00A98F?style=for-the-badge&logo=termux" alt="Termux">
13
- <img src="https://img.shields.io/badge/Stable-1.7.0-brightgreen?style=for-the-badge" alt="Stable">
13
+ <img src="https://img.shields.io/badge/Stable-1.9.0-brightgreen?style=for-the-badge" alt="Stable">
14
14
  </div>
15
15
 
16
16
  <div align="center">
@@ -30,84 +30,98 @@
30
30
 
31
31
  ---
32
32
 
33
- Table of Contents
34
-
35
- · Overview
36
- · What's New in 1.7.0
37
- · Features
38
- · Why MC-Headless?
39
- · Installation
40
- · Quick Start
41
- · Configuration Guide
42
- · API Reference
43
- · Usage Examples
44
- · Server Types
45
- · Platform Options
46
- · Memory Management
47
- · Network Settings
48
- · World Configuration
49
- · Folder Structure
50
- · Backup System
51
- · Event System
52
- · Commands
53
- · Player Management
54
- · Cross-Play (Geyser)
55
- · ViaVersion Support
56
- · Termux Setup
57
- · Performance Tuning
58
- · Troubleshooting
59
- · Contributing
60
- · License
33
+ ## Table of Contents
34
+
35
+ - [Overview](#overview)
36
+ - [What's New in 1.9.0](#whats-new-in-190)
37
+ - [Features](#features)
38
+ - [Why MC-Headless?](#why-mc-headless)
39
+ - [Installation](#installation)
40
+ - [Quick Start](#quick-start)
41
+ - [Configuration Guide](#configuration-guide)
42
+ - [API Reference](#api-reference)
43
+ - [Usage Examples](#usage-examples)
44
+ - [Server Types](#server-types)
45
+ - [Platform Options](#platform-options)
46
+ - [Memory Management](#memory-management)
47
+ - [Network Settings](#network-settings)
48
+ - [World Configuration](#world-configuration)
49
+ - [Folder Structure](#folder-structure)
50
+ - [Backup System](#backup-system)
51
+ - [Event System](#event-system)
52
+ - [Commands](#commands)
53
+ - [Player Management](#player-management)
54
+ - [Cross-Play (Geyser)](#cross-play-geyser)
55
+ - [ViaVersion Support](#viaversion-support)
56
+ - [SkinRestorer Support](#skinrestorer-support)
57
+ - [Portable Java](#portable-java)
58
+ - [Performance Tuning](#performance-tuning)
59
+ - [Troubleshooting](#troubleshooting)
60
+ - [Contributing](#contributing)
61
+ - [License](#license)
61
62
 
62
63
  ---
63
64
 
64
- Overview
65
+ ## Overview
65
66
 
66
- MC-Headless is a powerful Node.js library that simplifies running Minecraft servers (Java, Bedrock, or Cross-play) with a clean, promise-based API. No more dealing with complex Java commands, server.properties files, or manual downloads - just simple JavaScript methods.
67
+ **MC-Headless** is a powerful Node.js library that simplifies running Minecraft servers (Java, Bedrock, or Cross-play) with a clean, promise-based API. No more dealing with complex Java commands, server.properties files, or manual downloads - just simple JavaScript methods.
67
68
 
68
69
  Built specifically for developers, sysadmins, and Minecraft enthusiasts who want to automate server management, run headless servers on VPS/Termux, or integrate Minecraft servers into their applications.
69
70
 
70
71
  ---
71
72
 
72
- What's New in 1.7.0
73
+ ## What's New in 1.9.0
73
74
 
74
- Version 1.7.0 - March 2026
75
+ ### Version 1.9.0 - March 2026
75
76
 
76
- · Stable ViaVersion Integration - Fixed download URLs for ViaVersion 5.7.2, ViaBackwards 5.7.2, and ViaRewind 4.0.15
77
- · Improved Error Handling - Better validation and retry logic for plugin downloads
78
- · File Corruption Prevention - Automatic detection and cleanup of corrupt JAR files
79
- · ZIP Header Verification - Ensures downloaded plugins are valid before loading
80
- · Performance Optimizations - Reduced CPU usage with optimized view distance defaults
81
- · Better Memory Management - Aikar's flags now properly configured for all server types
82
- · Enhanced Logging - More detailed logs for debugging
77
+ - **Portable Java** - Auto-download JRE to `/tmp` (no system installation required)
78
+ - **Smart Java Detection** - Uses `which java` to check existing installation
79
+ - **Auto-cleanup** - Removes old Java files after 24 hours
80
+ - **Cgroups Support** - Reads CPU/Memory stats directly from kernel (like Pterodactyl)
81
+ - **Silent Mode** - Direct pipe for logs, no Node.js processing overhead
82
+ - **30-second Stats** - Resource monitoring every 30 seconds (not real-time)
83
+ - **MALLOC_ARENA_MAX=2** - Environment optimization for memory efficiency
84
+ - **SkinRestorer Plugin** - Auto-download and install SkinRestorer
85
+ - **System RAM Detection** - Auto-recommend memory based on available RAM
86
+ - **Better Error Handling** - Improved error messages and recovery
83
87
 
84
88
  ---
85
89
 
86
- Features
87
-
88
- Category Features
89
- Server Types Paper, Purpur, Vanilla, Spigot, Forge, Fabric
90
- Platforms Java Edition, Bedrock Edition, Cross-play (Geyser)
91
- Auto Setup Automatic Java detection, EULA acceptance, server.properties generation
92
- Downloader Automatic download of server jars from official sources
93
- Memory Management Custom memory allocation, Aikar's flags optimization
94
- Backup System Automatic scheduled backups, manual backup triggers
95
- Monitoring Real-time CPU/memory usage, player tracking, server events
96
- Cross-play Built-in Geyser & Floodgate support for Bedrock clients
97
- ViaVersion Built-in ViaVersion, ViaBackwards, ViaRewind support
98
- Termux Friendly Optimized for Android/Termux environments
99
- Headless Ready No GUI required, perfect for servers and automation
90
+ ## Features
91
+
92
+ | Category | Features |
93
+ |----------|----------|
94
+ | **Server Types** | Paper, Purpur, Vanilla, Spigot, Forge, Fabric |
95
+ | **Platforms** | Java Edition, Bedrock Edition, Cross-play (Geyser) |
96
+ | **Auto Setup** | Automatic Java detection, EULA acceptance, server.properties generation |
97
+ | **Portable Java** | Download JRE to `/tmp`, no system installation required |
98
+ | **Cgroups Stats** | CPU/Memory stats like Pterodactyl (30s interval) |
99
+ | **Downloader** | Automatic download of server jars from official sources |
100
+ | **Memory Management** | Custom memory allocation, Aikar's flags optimization |
101
+ | **Backup System** | Automatic scheduled backups, manual backup triggers |
102
+ | **Monitoring** | Real-time CPU/memory usage, player tracking, server events |
103
+ | **Cross-play** | Built-in Geyser & Floodgate support for Bedrock clients |
104
+ | **ViaVersion** | Built-in ViaVersion, ViaBackwards, ViaRewind support |
105
+ | **SkinRestorer** | Auto-download and install SkinRestorer plugin |
106
+ | **Termux Friendly** | Optimized for Android/Termux environments |
107
+ | **Headless Ready** | No GUI required, perfect for servers and automation |
108
+ | **Silent Mode** | Direct log piping for minimal CPU usage |
100
109
 
101
110
  ---
102
111
 
103
- Why MC-Headless?
104
-
105
- Before (Manual Setup)
112
+ ## Why MC-Headless?
106
113
 
114
+ ### Before (Manual Setup)
107
115
  ```bash
108
116
  # Download server jar
109
117
  wget https://api.papermc.io/v2/projects/paper/versions/1.21.11/builds/69/downloads/paper-1.21.11-69.jar
110
118
 
119
+ # Check if Java installed
120
+ which java || echo "Java not found"
121
+
122
+ # Install Java manually if needed
123
+ sudo apt install openjdk-17-jre-headless
124
+
111
125
  # Accept EULA
112
126
  echo "eula=true" > eula.txt
113
127
 
@@ -116,24 +130,26 @@ echo "server-port=25565" > server.properties
116
130
  echo "max-players=20" >> server.properties
117
131
 
118
132
  # Run server with complex Java flags
119
- java -Xms2G -Xmx4G -XX:+UseG1GC -jar paper-1.21.11-69.jar nogui
133
+ java -Xms4G -Xmx12G -XX:+UseG1GC -jar paper-1.21.11-69.jar nogui
120
134
 
121
135
  # Download plugins manually
122
136
  wget https://github.com/ViaVersion/ViaVersion/releases/download/5.7.2/ViaVersion-5.7.2.jar -P plugins/
137
+ wget https://github.com/SkinsRestorer/SkinsRestorerX/releases/latest/download/SkinsRestorer.jar -P plugins/
123
138
 
124
139
  # Monitor manually
125
140
  tail -f logs/latest.log
126
141
  ```
127
142
 
128
- After (MC-Headless)
143
+ After (MC-Headless v1.9.0)
129
144
 
130
145
  ```javascript
131
146
  const server = new MinecraftServer({
132
147
  version: '1.21.11',
133
148
  type: 'paper',
134
- memory: { init: '2G', max: '4G' },
135
- network: { port: 25565 },
136
- enableViaVersion: true
149
+ usePortableJava: true,
150
+ memory: { init: '4G', max: '12G' },
151
+ enableViaVersion: true,
152
+ enableSkinRestorer: true
137
153
  });
138
154
 
139
155
  server.on('ready', () => console.log('Server ready!'));
@@ -160,92 +176,156 @@ Requirements
160
176
 
161
177
  Requirement Minimum Recommended
162
178
  Node.js 18.0.0 20.0.0 or higher
163
- Java 17 17 or 21
164
179
  RAM 2 GB 4 GB or more
165
180
  Storage 1 GB 5 GB
166
181
  OS Linux, macOS, Windows, Termux Linux (production)
167
182
 
183
+ Note: Java is auto-downloaded as portable JRE (no system installation needed)
184
+
168
185
  ---
169
186
 
170
187
  Quick Start
171
188
 
172
- Basic Java Server
189
+ Basic Java Server with Portable Java
173
190
 
174
191
  ```javascript
175
192
  const { MinecraftServer } = require('@dimzxzzx07/mc-headless');
193
+ const os = require('os');
194
+
195
+ async function startServer() {
196
+ // Auto-detect system RAM
197
+ const totalRam = Math.floor(os.totalmem() / 1024 / 1024 / 1024);
198
+ const recommendedMax = Math.min(12, Math.max(2, Math.floor(totalRam * 0.7)));
199
+
200
+ console.log(`System RAM: ${totalRam}GB, Recommended: ${recommendedMax}GB`);
201
+
202
+ const server = new MinecraftServer({
203
+ platform: 'java',
204
+ version: '1.21.11',
205
+ type: 'paper',
206
+ usePortableJava: true,
207
+ memory: {
208
+ init: '4G',
209
+ max: `${recommendedMax}G`,
210
+ useAikarsFlags: true
211
+ }
212
+ });
213
+
214
+ server.on('ready', (info) => {
215
+ console.log(`Server ready on port ${info.port}`);
216
+ console.log(`Memory: ${info.memory.used}/${info.memory.max} MB`);
217
+ console.log(`CPU: ${info.cpu}%`);
218
+ });
219
+
220
+ await server.start();
221
+ }
176
222
 
177
- const server = new MinecraftServer({
178
- platform: 'java',
179
- version: '1.21.11',
180
- type: 'paper',
181
- memory: {
182
- init: '2G',
183
- max: '4G'
184
- }
185
- });
186
-
187
- server.on('ready', (info) => {
188
- console.log(`Server is ready on port ${info.port}`);
189
- console.log(`Version: ${info.version} ${info.type}`);
190
- });
191
-
192
- server.on('player-join', (player) => {
193
- console.log(`${player.name} joined the game`);
194
- });
195
-
196
- server.on('player-leave', (name) => {
197
- console.log(`${name} left the game`);
198
- });
199
-
200
- server.start().catch(console.error);
223
+ startServer();
201
224
  ```
202
225
 
203
- Basic Bedrock Server
226
+ Complete Server with All Features
204
227
 
205
228
  ```javascript
206
229
  const { MinecraftServer } = require('@dimzxzzx07/mc-headless');
207
-
208
- const server = new MinecraftServer({
209
- platform: 'bedrock',
210
- version: '1.21.11',
211
- network: {
212
- port: 19132,
213
- motd: 'Bedrock Server'
230
+ const axios = require('axios');
231
+ const os = require('os');
232
+
233
+ async function startServer() {
234
+ // Get public IP
235
+ let publicIp = "127.0.0.1";
236
+ try {
237
+ const res = await axios.get('https://api.ipify.org?format=json');
238
+ publicIp = res.data.ip;
239
+ } catch (err) {
240
+ console.log("Using default IP");
214
241
  }
215
- });
216
-
217
- server.start();
218
- ```
219
-
220
- Cross-Play Server with ViaVersion
221
242
 
222
- ```javascript
223
- const { MinecraftServer } = require('@dimzxzzx07/mc-headless');
224
-
225
- const server = new MinecraftServer({
226
- platform: 'all',
227
- version: '1.21.11',
228
- type: 'paper',
229
- memory: {
230
- init: '2G',
231
- max: '4G'
232
- },
233
- network: {
234
- port: 25565,
235
- bedrockPort: 19132,
236
- motd: 'Cross-Play Server'
237
- },
238
- enableViaVersion: true,
239
- enableViaBackwards: true,
240
- enableViaRewind: true
241
- });
242
-
243
- server.on('ready', () => {
244
- console.log('Server ready with ViaVersion support!');
245
- console.log('Players from 1.7.x to 1.21.x can join');
246
- });
243
+ // Auto-detect RAM
244
+ const totalRam = Math.floor(os.totalmem() / 1024 / 1024 / 1024);
245
+ const recommendedMax = Math.min(12, Math.max(2, Math.floor(totalRam * 0.7)));
246
+
247
+ const server = new MinecraftServer({
248
+ platform: "all",
249
+ version: "1.21.11",
250
+ type: "paper",
251
+ autoAcceptEula: true,
252
+
253
+ // Java options
254
+ usePortableJava: true,
255
+ javaVersion: "auto",
256
+
257
+ memory: {
258
+ init: "4G",
259
+ max: "12G",
260
+ useAikarsFlags: true
261
+ },
262
+
263
+ network: {
264
+ ip: "0.0.0.0",
265
+ port: 25565,
266
+ bedrockPort: 19132,
267
+ motd: "Minecraft 1.21.11 Server",
268
+ onlineMode: false
269
+ },
270
+
271
+ world: {
272
+ difficulty: "normal",
273
+ maxPlayers: 20,
274
+ levelName: "world",
275
+ viewDistance: 6,
276
+ simulationDistance: 4
277
+ },
278
+
279
+ // Plugins
280
+ enableViaVersion: true,
281
+ enableViaBackwards: true,
282
+ enableViaRewind: true,
283
+ enableSkinRestorer: true,
284
+
285
+ // Monitoring
286
+ memoryMonitor: {
287
+ enabled: true,
288
+ threshold: 85,
289
+ interval: 30000,
290
+ action: 'warn'
291
+ },
292
+
293
+ // Performance
294
+ silentMode: true,
295
+ statsInterval: 30000
296
+ });
297
+
298
+ server.on("ready", (info) => {
299
+ console.clear();
300
+ console.log(`\n==========================================`);
301
+ console.log(`Minecraft Server - v1.9.0`);
302
+ console.log(` IP: ${publicIp}:${info.port}`);
303
+ console.log(` Version: ${info.version}`);
304
+ console.log(` Memory: ${info.memory.used}/${info.memory.max} MB`);
305
+ console.log(` CPU: ${info.cpu || 0}%`);
306
+ console.log(` Players: ${info.players}/${info.maxPlayers}`);
307
+ console.log(`==========================================\n`);
308
+ });
309
+
310
+ server.on("player-join", (player) => {
311
+ console.log(`${player.name} joined`);
312
+ server.sendCommand(`tellraw ${player.name} {"text":"Welcome!","color":"aqua"}`);
313
+ });
314
+
315
+ server.on("player-leave", (name) => {
316
+ console.log(`${name} left`);
317
+ });
318
+
319
+ server.on("resource", (info) => {
320
+ if (info.memory.used > info.memory.max * 0.8) {
321
+ console.log(`high memory: ${info.memory.used}/${info.memory.max} MB`);
322
+ }
323
+ });
324
+
325
+ await server.start();
326
+ }
247
327
 
248
- server.start();
328
+ startServer();
249
329
  ```
250
330
 
251
331
  ---
@@ -264,10 +344,14 @@ const server = new MinecraftServer({
264
344
  type: 'paper',
265
345
  autoAcceptEula: true,
266
346
 
347
+ // Java Options
348
+ usePortableJava: true,
349
+ javaVersion: 'auto',
350
+
267
351
  // Resource Management
268
352
  memory: {
269
- init: '2G',
270
- max: '4G',
353
+ init: '4G',
354
+ max: '12G',
271
355
  useAikarsFlags: true
272
356
  },
273
357
 
@@ -287,7 +371,7 @@ const server = new MinecraftServer({
287
371
  gamemode: 'survival',
288
372
  seed: 'my-secret-seed',
289
373
  maxPlayers: 20,
290
- viewDistance: 8,
374
+ viewDistance: 6,
291
375
  simulationDistance: 4,
292
376
  levelName: 'world'
293
377
  },
@@ -300,6 +384,12 @@ const server = new MinecraftServer({
300
384
  world: './world'
301
385
  },
302
386
 
387
+ // Plugins
388
+ enableViaVersion: true,
389
+ enableViaBackwards: true,
390
+ enableViaRewind: true,
391
+ enableSkinRestorer: true,
392
+
303
393
  // Server Behavior
304
394
  autoRestart: true,
305
395
  backup: {
@@ -308,10 +398,17 @@ const server = new MinecraftServer({
308
398
  path: './backups'
309
399
  },
310
400
 
311
- // ViaVersion Support
312
- enableViaVersion: true,
313
- enableViaBackwards: true,
314
- enableViaRewind: true
401
+ // Monitoring
402
+ memoryMonitor: {
403
+ enabled: true,
404
+ threshold: 85,
405
+ interval: 30000,
406
+ action: 'warn'
407
+ },
408
+
409
+ // Performance
410
+ silentMode: true,
411
+ statsInterval: 30000
315
412
  });
316
413
 
317
414
  await server.start();
@@ -327,11 +424,17 @@ version string '1.21.11' Minecraft version
327
424
  type string 'paper' paper, purpur, vanilla, spigot, forge, fabric
328
425
  autoAcceptEula boolean true Automatically accept Minecraft EULA
329
426
 
427
+ Java Options
428
+
429
+ Option Type Default Description
430
+ usePortableJava boolean true Download portable JRE to /tmp
431
+ javaVersion string 'auto' '17', '21', or 'auto'
432
+
330
433
  Memory Options
331
434
 
332
435
  Option Type Default Description
333
- memory.init string '1G' Initial heap size
334
- memory.max string '2G' Maximum heap size
436
+ memory.init string '2G' Initial heap size
437
+ memory.max string '4G' Maximum heap size
335
438
  memory.useAikarsFlags boolean true Use Aikar's optimized GC flags
336
439
 
337
440
  Network Options
@@ -351,31 +454,23 @@ world.hardcore boolean false Enable hardcore mode
351
454
  world.gamemode string 'survival' survival, creative, adventure, spectator
352
455
  world.seed string undefined World generation seed
353
456
  world.maxPlayers number 20 Maximum player count
354
- world.viewDistance number 8 Chunk view distance
457
+ world.viewDistance number 6 Chunk view distance
355
458
  world.simulationDistance number 4 Simulation distance
356
459
  world.levelName string 'world' World folder name
357
460
 
358
- Folder Options
359
-
360
- Option Type Default Description
361
- folders.addons string './addons' Bedrock addons folder
362
- folders.mods string './mods' Forge/Fabric mods folder
363
- folders.plugins string './plugins' Paper/Spigot plugins folder
364
- folders.world string './world' World data folder
365
-
366
- Backup Options
367
-
368
- Option Type Default Description
369
- backup.enabled boolean false Enable automatic backups
370
- backup.interval string '24h' Backup interval
371
- backup.path string './backups' Backup storage path
372
-
373
- ViaVersion Options
461
+ Plugin Options
374
462
 
375
463
  Option Type Default Description
376
464
  enableViaVersion boolean false Enable ViaVersion plugin
377
465
  enableViaBackwards boolean false Enable ViaBackwards plugin
378
466
  enableViaRewind boolean false Enable ViaRewind plugin
467
+ enableSkinRestorer boolean false Enable SkinRestorer plugin
468
+
469
+ Performance Options
470
+
471
+ Option Type Default Description
472
+ silentMode boolean true Direct pipe logs (no Node.js processing)
473
+ statsInterval number 30000 Stats update interval in ms
379
474
 
380
475
  ---
381
476
 
@@ -422,589 +517,145 @@ interface ServerInfo {
422
517
  used: number;
423
518
  max: number;
424
519
  };
520
+ cpu: number;
425
521
  status: 'starting' | 'running' | 'stopping' | 'stopped' | 'crashed';
426
522
  }
427
523
  ```
428
524
 
429
- Player Interface
430
-
431
- ```javascript
432
- interface Player {
433
- name: string;
434
- uuid: string;
435
- ip: string;
436
- ping: number;
437
- connectedAt: Date;
438
- }
439
- ```
440
-
441
525
  ---
442
526
 
443
527
  Usage Examples
444
528
 
445
- Advanced Server Configuration
529
+ Server with Auto RAM Detection
446
530
 
447
531
  ```javascript
448
532
  const { MinecraftServer } = require('@dimzxzzx07/mc-headless');
533
+ const os = require('os');
534
+
535
+ const totalRam = Math.floor(os.totalmem() / 1024 / 1024 / 1024);
536
+ const maxRam = Math.min(12, Math.floor(totalRam * 0.7));
449
537
 
450
538
  const server = new MinecraftServer({
451
- platform: 'java',
452
539
  version: '1.21.11',
453
540
  type: 'paper',
454
-
541
+ usePortableJava: true,
455
542
  memory: {
456
- init: '2G',
457
- max: '8G',
458
- useAikarsFlags: true
459
- },
460
-
461
- network: {
462
- port: 25565,
463
- ip: '0.0.0.0',
464
- onlineMode: true,
465
- motd: 'Premium Minecraft Server'
466
- },
467
-
468
- world: {
469
- difficulty: 'hard',
470
- gamemode: 'survival',
471
- maxPlayers: 50,
472
- viewDistance: 8,
473
- simulationDistance: 4,
474
- levelName: 'survival_world'
475
- },
476
-
477
- folders: {
478
- plugins: './plugins',
479
- world: './survival_world'
480
- },
481
-
482
- autoRestart: true,
483
- backup: {
484
- enabled: true,
485
- interval: '12h',
486
- path: './backups'
487
- },
488
-
489
- enableViaVersion: true,
490
- enableViaBackwards: true,
491
- enableViaRewind: true
492
- });
493
-
494
- server.on('ready', async (info) => {
495
- console.log(`Server PID: ${info.pid}`);
496
- console.log(`Memory: ${info.memory.used}/${info.memory.max} MB`);
497
- console.log('ViaVersion active - all versions welcome!');
543
+ init: `${Math.floor(maxRam * 0.3)}G`,
544
+ max: `${maxRam}G`
545
+ }
498
546
  });
499
547
 
500
- server.on('resource', (info) => {
501
- if (info.memory.used > info.memory.max * 0.9) {
502
- console.log('High memory usage detected');
503
- }
548
+ server.on('ready', (info) => {
549
+ console.log(`Server running with ${info.memory.max} MB max`);
504
550
  });
505
551
 
506
552
  server.start();
507
553
  ```
508
554
 
509
- Multiple Servers Manager
555
+ Multiple Servers with Different Versions
510
556
 
511
557
  ```javascript
512
558
  const { ServerManager } = require('@dimzxzzx07/mc-headless');
513
559
 
514
560
  const manager = new ServerManager();
515
561
 
516
- // Create survival server
517
- const survival = manager.createServer('survival', {
562
+ // Create servers
563
+ manager.createServer('lobby', {
518
564
  version: '1.21.11',
519
565
  type: 'paper',
520
566
  network: { port: 25565 }
521
567
  });
522
568
 
523
- // Create creative server
524
- const creative = manager.createServer('creative', {
569
+ manager.createServer('survival', {
525
570
  version: '1.21.11',
526
571
  type: 'paper',
527
572
  network: { port: 25566 },
528
- world: { gamemode: 'creative' }
529
- });
530
-
531
- // Start all servers
532
- await manager.startServer('survival');
533
- await manager.startServer('creative');
534
-
535
- // Broadcast to all servers
536
- await manager.broadcastCommand('say Server is running!');
537
- ```
538
-
539
- Server Control with Commands
540
-
541
- ```javascript
542
- server.on('ready', () => {
543
- // Send various commands
544
- server.sendCommand('say Welcome to the server!');
545
- server.sendCommand('time set day');
546
- server.sendCommand('weather clear');
547
- server.sendCommand('difficulty normal');
548
-
549
- // OP a player
550
- server.sendCommand('op Dimzxzzx07');
551
-
552
- // Save world
553
- server.sendCommand('save-all');
554
- });
555
-
556
- // Get server stats periodically
557
- setInterval(async () => {
558
- const info = await server.getInfo();
559
- console.log(`Players: ${info.players}/${info.maxPlayers}`);
560
- console.log(`Memory: ${info.memory.used}/${info.memory.max} MB`);
561
- }, 60000);
562
- ```
563
-
564
- ---
565
-
566
- Server Types
567
-
568
- Paper (Recommended for Performance)
569
-
570
- ```javascript
571
- const server = new MinecraftServer({
572
- type: 'paper',
573
- version: '1.21.11',
574
- memory: { useAikarsFlags: true }
575
- });
576
- ```
577
-
578
- Vanilla (Official Mojang)
579
-
580
- ```javascript
581
- const server = new MinecraftServer({
582
- type: 'vanilla',
583
- version: '1.21.11'
584
- });
585
- ```
586
-
587
- Forge (Modded)
588
-
589
- ```javascript
590
- const server = new MinecraftServer({
591
- type: 'forge',
592
- version: '1.21.11',
593
- folders: { mods: './mods' }
594
- });
595
- ```
596
-
597
- Fabric (Lightweight Modding)
598
-
599
- ```javascript
600
- const server = new MinecraftServer({
601
- type: 'fabric',
602
- version: '1.21.11',
603
- folders: { mods: './mods' }
604
- });
605
- ```
606
-
607
- ---
608
-
609
- Platform Options
610
-
611
- Java Edition Only
612
-
613
- ```javascript
614
- const server = new MinecraftServer({
615
- platform: 'java',
616
- version: '1.21.11',
617
- type: 'paper',
618
- network: { port: 25565 }
619
- });
620
- ```
621
-
622
- Bedrock Edition Only
623
-
624
- ```javascript
625
- const server = new MinecraftServer({
626
- platform: 'bedrock',
627
- version: '1.21.11',
628
- network: { port: 19132 },
629
- folders: { addons: './addons' }
573
+ world: { levelName: 'survival' }
630
574
  });
631
- ```
632
-
633
- Cross-Play (Java + Bedrock)
634
575
 
635
- ```javascript
636
- const server = new MinecraftServer({
637
- platform: 'all',
576
+ manager.createServer('creative', {
638
577
  version: '1.21.11',
639
578
  type: 'paper',
640
- network: {
641
- port: 25565,
642
- bedrockPort: 19132
643
- }
644
- });
645
- ```
646
-
647
- ---
648
-
649
- Memory Management
650
-
651
- Basic Memory Configuration
652
-
653
- ```javascript
654
- memory: {
655
- init: '2G',
656
- max: '4G',
657
- useAikarsFlags: false
658
- }
659
- ```
660
-
661
- Aikar's Flags (Optimized)
662
-
663
- ```javascript
664
- memory: {
665
- init: '2G',
666
- max: '8G',
667
- useAikarsFlags: true
668
- }
669
- ```
670
-
671
- Memory Recommendations
672
-
673
- Players RAM Init Max
674
- 1-10 2 GB 1G 2G
675
- 10-20 4 GB 2G 4G
676
- 20-50 8 GB 4G 8G
677
- 50-100 16 GB 8G 16G
678
-
679
- ---
680
-
681
- Network Settings
682
-
683
- Basic Network
684
-
685
- ```javascript
686
- network: {
687
- port: 25565,
688
- ip: '0.0.0.0',
689
- onlineMode: false,
690
- motd: 'My Server'
691
- }
692
- ```
693
-
694
- Cross-Play Network
695
-
696
- ```javascript
697
- network: {
698
- port: 25565,
699
- bedrockPort: 19132,
700
- ip: '0.0.0.0',
701
- onlineMode: false,
702
- motd: 'Cross-Play Server'
703
- }
704
- ```
705
-
706
- ---
707
-
708
- World Configuration
709
-
710
- Basic World
711
-
712
- ```javascript
713
- world: {
714
- difficulty: 'normal',
715
- gamemode: 'survival',
716
- maxPlayers: 20,
717
- viewDistance: 8,
718
- simulationDistance: 4,
719
- levelName: 'world'
720
- }
721
- ```
722
-
723
- Hardcore Mode
724
-
725
- ```javascript
726
- world: {
727
- difficulty: 'hard',
728
- hardcore: true,
729
- gamemode: 'survival',
730
- maxPlayers: 10,
731
- viewDistance: 6
732
- }
733
- ```
734
-
735
- Custom Seed
736
-
737
- ```javascript
738
- world: {
739
- seed: 'my-amazing-seed-12345',
740
- levelName: 'custom_world'
741
- }
742
- ```
743
-
744
- ---
745
-
746
- Folder Structure
747
-
748
- ```
749
- server/
750
- ├── plugins/ # Paper/Spigot plugins
751
- ├── mods/ # Forge/Fabric mods
752
- ├── addons/ # Bedrock addons
753
- ├── world/ # World data
754
- ├── logs/ # Server logs
755
- └── backups/ # Backup files
756
- ```
757
-
758
- ---
759
-
760
- Backup System
761
-
762
- Enable Automatic Backups
763
-
764
- ```javascript
765
- backup: {
766
- enabled: true,
767
- interval: '24h',
768
- path: './backups'
769
- }
770
- ```
771
-
772
- Manual Backup
773
-
774
- ```javascript
775
- // Full backup
776
- const fullPath = await server.backup('full');
777
-
778
- // World only backup
779
- const worldPath = await server.backup('world');
780
-
781
- // Plugins only backup
782
- const pluginsPath = await server.backup('plugins');
783
- ```
784
-
785
- ---
786
-
787
- Event System
788
-
789
- Server Events
790
-
791
- ```javascript
792
- server.on('ready', (info) => {
793
- console.log('Server ready at', info.port);
794
- });
795
-
796
- server.on('stop', ({ code }) => {
797
- console.log('Server stopped with code', code);
798
- });
799
-
800
- server.on('resource', (info) => {
801
- console.log(`Memory: ${info.memory.used}/${info.memory.max} MB`);
802
- });
803
- ```
804
-
805
- Player Events
806
-
807
- ```javascript
808
- server.on('player-join', (player) => {
809
- console.log(`${player.name} joined from ${player.ip}`);
810
- server.sendCommand(`say Welcome ${player.name}!`);
811
- });
812
-
813
- server.on('player-leave', (name) => {
814
- console.log(`${name} left the game`);
815
- });
816
- ```
817
-
818
- ---
819
-
820
- Commands
821
-
822
- Built-in Commands
823
-
824
- ```javascript
825
- // Send any Minecraft command
826
- server.sendCommand('say Hello world');
827
- server.sendCommand('time set day');
828
- server.sendCommand('weather clear');
829
- server.sendCommand('difficulty hard');
830
- server.sendCommand('gamemode creative @a');
831
- ```
832
-
833
- Console Commands
834
-
835
- ```javascript
836
- // Stop server
837
- server.sendCommand('stop');
838
-
839
- // Save world
840
- server.sendCommand('save-all');
841
-
842
- // List players
843
- server.sendCommand('list');
844
-
845
- // Ban player
846
- server.sendCommand('ban Notch');
847
- ```
848
-
849
- ---
850
-
851
- Player Management
852
-
853
- Get Player List
854
-
855
- ```javascript
856
- const players = server.getPlayers();
857
- players.forEach(player => {
858
- console.log(`${player.name} - Ping: ${player.ping}ms`);
579
+ network: { port: 25567 },
580
+ world: { gamemode: 'creative' }
859
581
  });
860
- ```
861
582
 
862
- Player Count
583
+ // Start all
584
+ await manager.startAll();
863
585
 
864
- ```javascript
865
- const info = await server.getInfo();
866
- console.log(`Players online: ${info.players}/${info.maxPlayers}`);
586
+ // Broadcast command
587
+ await manager.broadcastCommand('say Server is running!');
867
588
  ```
868
589
 
869
590
  ---
870
591
 
871
- Cross-Play (Geyser)
592
+ Portable Java
872
593
 
873
- Automatic Setup
594
+ How It Works
874
595
 
875
596
  ```javascript
876
597
  const server = new MinecraftServer({
877
- platform: 'all',
878
- version: '1.21.11',
879
- type: 'paper',
880
- network: {
881
- port: 25565,
882
- bedrockPort: 19132
883
- }
598
+ usePortableJava: true, // Download JRE to /tmp
599
+ javaVersion: '17' // or '21', 'auto'
884
600
  });
885
601
  ```
886
602
 
603
+ · Downloads JRE (not full JDK) ~50MB
604
+ · Extracts to /tmp/.mc-headless-java/
605
+ · Auto-cleanup after 24 hours
606
+ · No system installation required
607
+ · Sets JAVA_HOME and PATH automatically
608
+ · Adds MALLOC_ARENA_MAX=2 for memory efficiency
609
+
887
610
  ---
888
611
 
889
- ViaVersion Support
612
+ SkinRestorer Support
890
613
 
891
- Enable All ViaVersion Plugins
614
+ Enable SkinRestorer
892
615
 
893
616
  ```javascript
894
617
  const server = new MinecraftServer({
895
- version: '1.21.11',
896
- type: 'paper',
897
- enableViaVersion: true,
898
- enableViaBackwards: true,
899
- enableViaRewind: true
618
+ enableSkinRestorer: true // Auto-download and install
900
619
  });
901
620
  ```
902
621
 
903
- What Each Plugin Does
904
-
905
- Plugin Function
906
- ViaVersion Allows newer clients to connect to older servers
907
- ViaBackwards Allows older clients to connect to newer servers
908
- ViaRewind Adds support for 1.7.x - 1.8.x clients
909
-
910
- With ViaVersion enabled, your server can accept connections from Minecraft versions 1.7.x through 1.21.x.
911
-
912
- ---
913
-
914
- Termux Setup
915
-
916
- Install in Termux
917
-
918
- ```bash
919
- # Update packages
920
- pkg update && pkg upgrade
921
-
922
- # Install Node.js
923
- pkg install nodejs
924
-
925
- # Install Java
926
- pkg install openjdk-17
927
-
928
- # Install mc-headless
929
- npm install -g @dimzxzzx07/mc-headless
930
-
931
- # Create server
932
- mkdir minecraft-server
933
- cd minecraft-server
934
- npm init -y
935
- npm install @dimzxzzx07/mc-headless
936
-
937
- # Create server script
938
- cat > server.js << 'EOF'
939
- const { MinecraftServer } = require('@dimzxzzx07/mc-headless');
940
-
941
- const server = new MinecraftServer({
942
- platform: 'java',
943
- version: '1.21.11',
944
- type: 'paper',
945
- memory: {
946
- init: '512M',
947
- max: '2G'
948
- }
949
- });
950
-
951
- server.start();
952
- EOF
953
-
954
- # Run server
955
- node server.js
956
- ```
622
+ · Auto-downloads latest SkinRestorer
623
+ · Fixes player skins for offline mode
624
+ · Works with Geyser (Bedrock players)
625
+ · No manual plugin installation needed
957
626
 
958
627
  ---
959
628
 
960
629
  Performance Tuning
961
630
 
962
- Optimized Configuration for Low CPU
631
+ Optimized Configuration
963
632
 
964
633
  ```javascript
965
634
  const server = new MinecraftServer({
966
635
  version: '1.21.11',
967
636
  type: 'paper',
637
+ usePortableJava: true,
968
638
  memory: {
969
- init: '1G',
970
- max: '3G',
639
+ init: '4G',
640
+ max: '12G',
971
641
  useAikarsFlags: true
972
642
  },
973
643
  world: {
974
- maxPlayers: 20,
975
644
  viewDistance: 6,
976
- simulationDistance: 4
977
- }
645
+ simulationDistance: 4,
646
+ maxPlayers: 20
647
+ },
648
+ silentMode: true,
649
+ statsInterval: 30000
978
650
  });
979
651
  ```
980
652
 
981
- Paper Configuration (paper-global.yml)
653
+ Environment Optimizations
982
654
 
983
- ```yaml
984
- chunk-loading:
985
- global-max-chunk-load-rate: 100
986
- global-max-chunk-send-rate: 50
987
-
988
- entities:
989
- spawn-limits:
990
- monster: 15
991
- creature: 10
992
- ambient: 5
993
-
994
- player-auto-save: 6000
995
- ```
996
-
997
- Bukkit Configuration (bukkit.yml)
998
-
999
- ```yaml
1000
- settings:
1001
- spawn-limits:
1002
- monsters: 30
1003
- animals: 10
1004
- ticks-per:
1005
- monster-spawns: 200
1006
- animal-spawns: 400
1007
- ```
655
+ Variable Value Effect
656
+ MALLOC_ARENA_MAX 2 Prevents memory fragmentation
657
+ _JAVA_OPTIONS -Xmx... Global Java memory limit
658
+ JAVA_HOME (auto) Points to portable Java
1008
659
 
1009
660
  ---
1010
661
 
@@ -1013,57 +664,20 @@ Troubleshooting
1013
664
  Common Issues
1014
665
 
1015
666
  Issue Cause Solution
1016
- Java not found Java not installed Run pkg install openjdk-17 in Termux
1017
- Port already in use Another server running Change port or kill other process
1018
- Out of memory Insufficient RAM Reduce max memory or add more RAM
1019
- Connection refused Firewall blocking Check firewall settings
667
+ Java not found No system Java Enable usePortableJava: true
668
+ High memory usage Too many chunks Reduce viewDistance
669
+ High CPU usage Stats interval too low Increase statsInterval to 60000
1020
670
  Plugin corrupt Bad download Delete plugin and restart
1021
- High CPU usage Too many chunks loaded Reduce view distance
1022
-
1023
- Debug Mode
1024
-
1025
- ```javascript
1026
- // Enable debug logging
1027
- const server = new MinecraftServer({
1028
- // ... config
1029
- debug: true
1030
- });
1031
- ```
671
+ Port in use Another server Change port number
1032
672
 
1033
- Logs Location
673
+ Check Logs
1034
674
 
1035
675
  ```bash
1036
- # Server logs
1037
- tail -f logs/latest.log
676
+ # Server logs are piped directly
677
+ # Just look at console output
1038
678
 
1039
- # MC-Headless logs
1040
- tail -f logs/mc-headless.log
1041
- ```
1042
-
1043
- ---
1044
-
1045
- Project Structure
1046
-
1047
- ```
1048
- mc-headless/
1049
- ├── src/
1050
- │ ├── core/
1051
- │ │ ├── MinecraftServer.ts
1052
- │ │ ├── ConfigHandler.ts
1053
- │ │ └── JavaChecker.ts
1054
- │ ├── engines/
1055
- │ │ ├── PaperEngine.ts
1056
- │ │ ├── VanillaEngine.ts
1057
- │ │ └── ...
1058
- │ ├── platforms/
1059
- │ │ ├── GeyserBridge.ts
1060
- │ │ └── ViaVersion.ts
1061
- │ └── utils/
1062
- │ ├── Logger.ts
1063
- │ └── FileUtils.ts
1064
- ├── tests/
1065
- ├── examples/
1066
- └── README.md
679
+ # Or check cgroup stats
680
+ cat /sys/fs/cgroup/memory/memory.usage_in_bytes
1067
681
  ```
1068
682
 
1069
683
  ---