public
Created

Convert Essentials homes to SpawnControl

  • Download Gist
ess2sc.py
Python
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55
#!/usr/bin/env python
 
import sys
import sqlite3
import yaml
import os
import time
from os import path
 
# Make sure paths exist
if len(sys.argv) != 2:
print "Usage: %s pluginpath" % (sys.argv[0])
sys.exit()
 
pluginDir = sys.argv[1]
 
if not path.exists(pluginDir):
print "Path %s doesn't exist" % (pluginDir)
sys.exit()
 
essentialsDir = path.join(pluginDir,'Essentials')
scDir = path.join(pluginDir,'SpawnControl')
 
if not path.exists(essentialsDir):
print "Essentials path %s doesn't exist" % essentialsDir
sys.exit()
 
if not path.exists(scDir):
print "SpawnControl path % doesn't exist" % scDir
sys.exit()
 
userdir = path.join(essentialsDir,'userdata')
 
if not path.exists(userdir):
print "Can't find essentials userdata directory"
sys.exit()
 
# Connect to DB and start the loop
scdb = sqlite3.connect(path.join(scDir,'spawncontrol.db'))
c = scdb.cursor()
 
userfiles = os.listdir(userdir)
for userfile in userfiles:
user = open(path.join(userdir,userfile))
useryaml = yaml.load(user)
if not useryaml or 'home' not in useryaml:
continue
print "Adding %s's home" % userfile[0:-4]
for world in useryaml["home"]["worlds"]:
h = useryaml["home"]["worlds"][world]
c.execute('insert into players (name, world, x, y, z, r, p, updated, updated_by) values (?, ?, ?, ?, ?, ?, ?, ?, ?)',(userfile[0:-4], world, h["x"],h["y"],h["z"],h["yaw"],h["pitch"],int(time.time()),"Essentials Import"))
user.close()
 
scdb.commit()
c.close()

Please sign in to comment on this gist.

Something went wrong with that request. Please try again.