You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
A configurable Minecraft server wrapper written in Node.js.
10
-
Using a combination of RCON and the output of the server console it allows you to do some pretty cool things.
11
-
Though, this is the engine of ScriptServer, and is honestly pretty bare.
12
-
The modules are where the magic happens (check 'Published Modules' down below).
13
-
14
-
The ScriptServer engine does 3 things:
15
-
- Starts the Minecraft server as a child process, using the specified jar & arguments
16
-
- Provides an interface to send commands, use their results, and make use of other things that are displayed in the server console.
17
-
- Initializes a simple module loader for ScriptServer modules.
18
-
19
-
## What version of Minecraft does it work with?
20
-
21
-
Because it relies on the RCON interface and the format of the output log, it should work with pretty much any version of Minecraft dating back to 2012. It should continue to work for all future releases and snapshots as long as the logging format doesn't drastically change, and they don't drop RCON support. (Both unlikely)
- Somewhat of a familiarity with NodeJS is recommended.
28
-
29
-
#### Setup
30
-
While inside the root of your Minecraft server directory, run `npm install scriptserver`. Then create a javascript file to run the server, I usually go with `server.js`. Paste in the following:
31
-
32
-
```javascript
33
-
constScriptServer=require('scriptserver');
34
-
35
-
constserver=newScriptServer({
36
-
core: {
37
-
jar:'minecraft_server.jar',
38
-
args: ['-Xmx2G'],
39
-
rcon: {
40
-
port:'25575',
41
-
password:'password'
42
-
}
43
-
}
44
-
});
45
-
46
-
server.start();
47
-
```
48
-
49
-
When initializing your ScriptServer instance all it takes is an optional config object, which is automatically set to `server.config`, and accessible by third party modules. Read each module's README to check for configuration options.
50
-
51
-
The options in the `core` config are used by the ScriptServer engine to determine the startup jar, arguments, and RCON configuration.
52
-
53
-
**RCON IS NOT ENABLED BY DEFAULT**, you will need to add the following to your `server.properties` to enable it:
54
-
```
55
-
enable-rcon=true
56
-
rcon.port=25575
57
-
rcon.password=password
58
-
```
59
-
60
-
You start your server with `server.start()`
61
-
62
-
Finally, you can run the server with node using
63
-
```bash
64
-
node server.js
65
-
```
66
-
67
-
And that's it!
68
-
69
-
Seriously. Like I said the engine is pretty bare, especially to users, but in the section 'Creating Modules' I'll explain how developers can utilize the simplicity of this engine.
70
-
71
-
For people looking to quickly try this out, I recommend giving [scriptserver-essentials](https://github.com/garrettjoecox/scriptserver-essentials) a try, it provides basic commands like `tpa`, `home`, and `spawn`, as well as a starter kit.
72
-
73
-
## Using Modules
74
-
75
-
To put 3rd party modules to use, you must first of course `npm install` them, then in your `server.js` initialize them one at a time with `server.use()`
As for the functionality of the actual module please refer to it's own `README.md` for use.
110
-
111
-
## Creating Modules
112
-
113
-
As a developer you have a few tools to work with. Below I will explain and use them in examples.
114
-
115
-
### 1) server.on(event, callback)
116
-
117
-
The server's console output is our main way of getting data from the server to our javascript wrapper.
118
-
Every time a log is output the engine emits the `console` event. This sounds useless as first but combining that with RegExp you'd be surprised at how much you can do.
119
-
120
-
Because ScriptServer extends the EventsEmitter, 3rd party module creators can utilize the emitter themselves. For instance the `scriptserver-event` module emits the events `chat`, `login`, `logout`, etc. right along side the main `console` event.
The send method allows you to send commands to the Minecraft server.
141
-
See [here](http://minecraft.gamepedia.com/Commands) for a list of available commands. When mixed with ES2015's template strings and Promises, server.send can be a powerful tool.
142
-
143
-
#### Using server.send
144
-
```javascript
145
-
constplayer='ProxySaw';
146
-
// Just like commands you'd type in the server console.
`server.send` also allows you to use the result of the command through it's returned promise. Similar to the console output, when combined with RegExp this can be extremely useful.
153
-
154
-
#### Using server.send promises to get player location
155
-
156
-
Sending the following command to the server console:
sendConsole is a helper method for special use-cases that want/need to bypass the RCON interface, and instead write directly to the server console. The drawback of this, is that there is no direct response to anything sent directly to the console. About 99% of the time you'll likely want to use `server.send` instead.
182
-
183
-
### Module Structure
184
-
So now that you know how to utilize those tools, it's time to build a module. Whenever a user `.use`'s your module, it simply invokes it with the context of their server, therefor encapsulate all server-side logic in a module.exports function.
185
-
186
-
The following was taken from the [scriptserver-command module](https://github.com/garrettjoecox/scriptserver-command). It allows for custom commands to be created using server.command() Read inline comments for breakdown.
187
-
```javascript
188
-
// The function that is called on server.use(require('scriptserver-command'))
189
-
module.exports=function() {
190
-
// Invoked with the context of the user's server
191
-
constserver=this;
192
-
// Local storage for commands
193
-
constcommands= {};
194
-
195
-
// Uses another scriptserver module
196
-
server.use(require('scriptserver-event'));
197
-
198
-
// Interface for users to add commands
199
-
server.command=function(cmd, callback) {
200
-
commands[cmd] = commands[cmd] || [];
201
-
commands[cmd].push(callback);
202
-
}
203
-
204
-
// Hooks into chat event to watch for the ~ char, then emits the command event
And muahlah! In game sending the command `~head` will give yourself your player head or passing in a name `~head Notch` will give you their player head!
247
-
248
-
If you run into any issues or questions, read through other published modules(below) or submit an issue and I'll try to help you out!
Lets you restart the server in game, and auto update to snapshot/release channels.
6
+
## What's this?
7
+
Sciptserver is a minecraft server wrapper, allowing you to write simple plugins using the RCON connection and STDIN/OUT from the java console. This is currently a WIP port to deno, milage may vary.
0 commit comments