rename ServerJarCache to ServerJarStorage, allow MCEdit to override the default ServerJarStorage.cacheDir location, check that items in the worldCacheDir are directories before using rmtree on them, set allow-nether to false in the server properties (nether support here is unfinished), MCServerChunkGenerator won't overwrite existing chunks
This commit is contained in:
parent
6f035c4aaa
commit
05cd068104
@ -72,12 +72,9 @@ elif sys.platform == "darwin":
|
|||||||
else:
|
else:
|
||||||
appSupportDir = os.path.expanduser("~/.pymclevel")
|
appSupportDir = os.path.expanduser("~/.pymclevel")
|
||||||
|
|
||||||
class ServerJarCache(object):
|
class ServerJarStorage(object):
|
||||||
|
cacheDir = os.path.join(appSupportDir, "ServerJarStorage")
|
||||||
def __init__(self, cacheDir=None):
|
def __init__(self):
|
||||||
if cacheDir is None:
|
|
||||||
cacheDir = os.path.join(appSupportDir, "ServerJarCache")
|
|
||||||
self.cacheDir = cacheDir
|
|
||||||
if not os.path.exists(self.cacheDir):
|
if not os.path.exists(self.cacheDir):
|
||||||
os.makedirs(self.cacheDir)
|
os.makedirs(self.cacheDir)
|
||||||
readme = os.path.join(self.cacheDir, "README.TXT")
|
readme = os.path.join(self.cacheDir, "README.TXT")
|
||||||
@ -172,7 +169,7 @@ class JavaNotFound(RuntimeError): pass
|
|||||||
class VersionNotFound(RuntimeError): pass
|
class VersionNotFound(RuntimeError): pass
|
||||||
|
|
||||||
class MCServerChunkGenerator(object):
|
class MCServerChunkGenerator(object):
|
||||||
"""Generates chunks using minecraft_server.jar. Uses a ServerJarCache to
|
"""Generates chunks using minecraft_server.jar. Uses a ServerJarStorage to
|
||||||
store different versions of minecraft_server.jar in an application support
|
store different versions of minecraft_server.jar in an application support
|
||||||
folder.
|
folder.
|
||||||
|
|
||||||
@ -201,11 +198,11 @@ class MCServerChunkGenerator(object):
|
|||||||
else:
|
else:
|
||||||
javaExe = which("java")
|
javaExe = which("java")
|
||||||
|
|
||||||
jarcache = ServerJarCache()
|
jarcache = ServerJarStorage()
|
||||||
tempWorldCache = {}
|
tempWorldCache = {}
|
||||||
@classmethod
|
@classmethod
|
||||||
def reloadJarCache(cls):
|
def reloadJarCache(cls):
|
||||||
cls.jarcache = ServerJarCache()
|
cls.jarcache = ServerJarStorage()
|
||||||
|
|
||||||
def __init__(self, version=None, jarfile=None):
|
def __init__(self, version=None, jarfile=None):
|
||||||
if self.javaExe is None:
|
if self.javaExe is None:
|
||||||
@ -222,7 +219,9 @@ class MCServerChunkGenerator(object):
|
|||||||
cls.tempWorldCache = {}
|
cls.tempWorldCache = {}
|
||||||
|
|
||||||
for tempDir in os.listdir(cls.worldCacheDir):
|
for tempDir in os.listdir(cls.worldCacheDir):
|
||||||
shutil.rmtree(os.path.join(cls.worldCacheDir, tempDir))
|
t = os.path.join(cls.worldCacheDir, tempDir)
|
||||||
|
if os.path.isdir(t):
|
||||||
|
shutil.rmtree(t)
|
||||||
|
|
||||||
def waitForServer(self, proc):
|
def waitForServer(self, proc):
|
||||||
""" wait for the server to finish starting up, then stop it. """
|
""" wait for the server to finish starting up, then stop it. """
|
||||||
@ -264,10 +263,20 @@ generation. Feel free to delete it for any reason.
|
|||||||
del tempWorld.version # for compatibility with older servers. newer ones will set it again without issue.
|
del tempWorld.version # for compatibility with older servers. newer ones will set it again without issue.
|
||||||
|
|
||||||
self.tempWorldCache[level.RandomSeed] = (tempWorld, tempDir)
|
self.tempWorldCache[level.RandomSeed] = (tempWorld, tempDir)
|
||||||
|
|
||||||
|
propsFile = os.path.join(tempDir, "server.properties")
|
||||||
|
if level.dimNo == 0:
|
||||||
|
with file(propsFile, "w") as f:
|
||||||
|
f.write("allow-nether=false\n")
|
||||||
|
else:
|
||||||
|
with file(propsFile, "w") as f:
|
||||||
|
f.write("allow-nether=true\n")
|
||||||
|
|
||||||
return (tempWorld, tempDir)
|
return (tempWorld, tempDir)
|
||||||
|
|
||||||
def generateChunkInLevel(self, level, cx, cz):
|
def generateChunkInLevel(self, level, cx, cz):
|
||||||
assert isinstance(level, MCInfdevOldLevel)
|
assert isinstance(level, MCInfdevOldLevel)
|
||||||
|
|
||||||
tempWorld, tempDir = self.tempWorldForLevel(level)
|
tempWorld, tempDir = self.tempWorldForLevel(level)
|
||||||
self.generateAtPosition(tempWorld, tempDir, cx, cz)
|
self.generateAtPosition(tempWorld, tempDir, cx, cz)
|
||||||
self.copyChunkAtPosition(tempWorld, level, cx, cz)
|
self.copyChunkAtPosition(tempWorld, level, cx, cz)
|
||||||
@ -276,12 +285,14 @@ generation. Feel free to delete it for any reason.
|
|||||||
tempWorld.setPlayerSpawnPosition((cx * 16, 64, cz * 16))
|
tempWorld.setPlayerSpawnPosition((cx * 16, 64, cz * 16))
|
||||||
tempWorld.saveInPlace()
|
tempWorld.saveInPlace()
|
||||||
tempWorld.unloadRegions()
|
tempWorld.unloadRegions()
|
||||||
|
|
||||||
proc = self.runServer(tempDir)
|
proc = self.runServer(tempDir)
|
||||||
self.waitForServer(proc)
|
self.waitForServer(proc)
|
||||||
|
|
||||||
tempWorld.loadLevelDat() #reload version number
|
tempWorld.loadLevelDat() #reload version number
|
||||||
|
|
||||||
def copyChunkAtPosition(self, tempWorld, level, cx, cz):
|
def copyChunkAtPosition(self, tempWorld, level, cx, cz):
|
||||||
|
if level.containsChunk(cx, cz): return
|
||||||
try:
|
try:
|
||||||
tempChunk = tempWorld.getChunk(cx, cz)
|
tempChunk = tempWorld.getChunk(cx, cz)
|
||||||
except ChunkNotPresent, e:
|
except ChunkNotPresent, e:
|
||||||
|
Reference in New Issue
Block a user