A Python API for running and extending a Minecraft server.
This downloads the Minecraft server jar, and starts up a server with the specified options. GreetBot will also greet people by name when they log in.
# minecraft_server.py
from mcnode import MCNode
from greet_bot import GreetBot
node = MCNode({
'server_jar_url' : 'https://s3.amazonaws.com/MinecraftDownload/launcher/minecraft_server.jar',
'server_directory' : './server/',
'server_jar_path' : 'minecraft_server.jar',
'init_memory' : '512M',
'max_memory' : '1024M'
})
node.add_bot(GreetBot(node))
node.read()
# greet_bot.py
from mcbot import MCBot
class GreetBot(MCBot):
def on_connect(self, data):
self.node.say('Welcome, %s' % (data[3]))
Then, in a command line, run python2 minecraft_server.py
Note: the
python2
command may differ by system. Checkpython
,python2.7
, etc. It just needs to be Python 2 (probably 2.7)
git clone git://github.com/laneaasen/mcnode.git
cd mcnode/include/pexpect/ sudo python2 setup.py install
>> Note: the `python2` command may differ by system. Check `python`, `python2.7`, etc. It just needs to be Python 2 (probably 2.7)
### Run the Example Server
> ```bash
python2 main.py
It will be running on
localhost
. To configure the Minecraft server itself, open up the server directory (server/
by default) and editserver.properties
.
Passes an arbitrary string into the server. Functions like
node.say()
,node.ban()
andnode.tp()
all extendnode.tell()
.
Wrapper for Minecraft's say function.
def say(self, message): return self.tell('say ' + message)
## Killing the Server
#### `node.stop()`
> Politely asks the server to stop.
> ```python
def stop(self):
return self.tell('stop')
Uses
SIGTERM
(or Windows equivalent) to shut down the server. Usually won't cause data loss, butnode.stop()
is still advised.
Uses
SIGKILL
(or Windows equivalent) to kill the server. This is not advised as it may cause data loss.