Note that you may want to modify this to prevent non OPs from getting TNT .etc
#This is public domain
import subprocess, string, time
args = 'java -Xmx1024M -Xms1024M -jar minecraft_server.jar nogui'.split()
p = subprocess.Popen(args, stdin=subprocess.PIPE, stdout=subprocess.PIPE, stderr=subprocess.PIPE)
# Edit this line to add OPs
oplist = ['koufu',]
def givenum(proc, oplist, player, item, num):
try:
if (player not in oplist) and (int(num) > 64):
proc.stdin.write('say Non OPs can only make 64 at a time!\n')
num = "64"
for i in range(int(num)):
proc.stdin.write('give %s %s\n' % (player, item))
time.sleep(0.1)
except Exception:
proc.stdin.write('say That is not a valid number!\n')
while(p.poll() == None):
log = p.stderr.readline()
words = log.split()
if('!#' in words):
i = words.index('!#')
if(len(words) < (i+3)):
p.stdin.write('say ERROR: Usage is !# num item\n')
time.sleep(0.1)
p.stderr.readline()
else:
player = words[i-1].strip('<>')
num = words[i+1]
item = words[i+2]
givenum(p, oplist, player, item, num)
print log.strip()
time.sleep(0.1)
EDIT:
To use, just run in the same directory as minecraft-server.jar:
python whatever_you_saved_this_as.py
It will start up your server with the new command enabled.
Eventually, I may make a nice version of this with more features, but meh. It's good enough for local servers at least, and an absolute grief-fest on any public ones :smile.gif:
How exactly would you go using this, I have the code pasted into a .py file, and I have the minecraft_server.jar in the same dir. But when I run it it closes.
Do you have the minecraft-server.jar in the same folder as the script?
As well, do you have python installed? If you open up a command prompt and type python, does python start?
Note that this is incompatible with python 3, it was developed with python 2.6 :tongue.gif:
This is just a quick and ugly python wrapper around minecraft-server.jar that adds a server command :smile.gif:
#! num itemnum
this spawns num of itemnum
For instance, to give yourself 64 TNT:
#! 64 46
(As 46 is TNT, see http://www.minecraftwiki.net/wiki/Data_Values)
Note that you may want to modify this to prevent non OPs from getting TNT .etc
EDIT:
To use, just run in the same directory as minecraft-server.jar:
It will start up your server with the new command enabled.
Eventually, I may make a nice version of this with more features, but meh. It's good enough for local servers at least, and an absolute grief-fest on any public ones :smile.gif:
Make sure that your server .jar is named EXACTLY minecraft_server.jar
It could be an indentation error, as that sometimes happens with copy and paste.
Try the new script first, and report back any error messages.
Good luck,
Koufu
As well, do you have python installed? If you open up a command prompt and type python, does python start?
Note that this is incompatible with python 3, it was developed with python 2.6 :tongue.gif:
EDIT: If you don't have python, I recommend ActiveState ActivePython: http://downloads.activestate.com/Active ... 32-x86.msi
EDIT: I think I found out my problem, I have python 3.1 but most programs are coded with 2.7 because 3.1 is in beta, I'll try using that.
Also, use the newer version of the script instead:
viewtopic.php?f=1012&t=23069