Giter Site home page Giter Site logo

mcnode's Introduction

MCNode

A Python API for running and extending a Minecraft server.

Examples

Make and Extend a 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. Check python, python2.7, etc. It just needs to be Python 2 (probably 2.7)

Installation

Fetch from Github

git clone git://github.com/laneaasen/mcnode.git

Install pexpect (bundled with MCNode)

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

Log into the Server on Minecraft

It will be running on localhost. To configure the Minecraft server itself, open up the server directory (server/ by default) and edit server.properties.

The Full API

Communicating with the Server

node.tell(message)

Passes an arbitrary string into the server. Functions like node.say(), node.ban() and node.tp() all extend node.tell().

node.say(message)

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')

node.terminate()

Uses SIGTERM (or Windows equivalent) to shut down the server. Usually won't cause data loss, but node.stop() is still advised.

node.kill()

Uses SIGKILL (or Windows equivalent) to kill the server. This is not advised as it may cause data loss.

mcnode's People

Contributors

aaasen avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.