Exemple #1
0
    def load_player(self, username):
        fp = self.folder.child("players").child("%s.dat" % username)
        if not fp.exists():
            raise SerializerReadException("%r doesn't exist!" % username)

        tag = self._read_tag(fp)
        if not tag:
            raise SerializerReadException("%r (in %s) is corrupt!" %
                                          (username, fp.path))

        try:
            player = Player(username=username)
            x, y, z = [i.value for i in tag["Pos"].tags]
            player.location.pos = Position(x, y, z)

            yaw = tag["Rotation"].tags[0].value
            pitch = tag["Rotation"].tags[1].value
            player.location.ori = Orientation.from_degs(yaw, pitch)

            if "Inventory" in tag:
                self._load_inventory_from_tag(player.inventory,
                                              tag["Inventory"])
        except KeyError, e:
            raise SerializerReadException("%r couldn't be loaded: %s" %
                                          (player, e))
Exemple #2
0
    def load_chunk(self, x, z):
        name = name_for_anvil(x, z)
        fp = self.folder.child("region").child(name)
        region = Region(fp)
        chunk = Chunk(x, z)

        try:
            data = region.get_chunk(x, z)
            tag = NBTFile(buffer=StringIO(data))
            self._load_chunk_from_tag(chunk, tag)
        except MissingChunk:
            raise SerializerReadException("No chunk %r in region" % chunk)
        except Exception, e:
            raise SerializerReadException("%r couldn't be loaded: %s" %
                                          (chunk, e))
Exemple #3
0
    def load_level(self):
        fp = self.folder.child("level.dat")
        if not fp.exists():
            raise SerializerReadException("Level doesn't exist!")

        tag = self._read_tag(self.folder.child("level.dat"))
        if not tag:
            raise SerializerReadException("Level (in %s) is corrupt!" %
                                          fp.path)

        try:
            spawn = (tag["Data"]["SpawnX"].value, tag["Data"]["SpawnY"].value,
                     tag["Data"]["SpawnZ"].value)
            seed = tag["Data"]["RandomSeed"].value
            time = tag["Data"]["Time"].value
            level = Level(seed, spawn, time)
            return level
        except KeyError, e:
            # Just raise. It's probably gonna be caught and ignored anyway.
            raise SerializerReadException("Level couldn't be loaded: %s" % e)
Exemple #4
0
    def load_chunk(self, chunk):
        first, second, filename = names_for_chunk(chunk.x, chunk.z)
        fp = self.folder.child(first).child(second)
        if not fp.exists():
            fp.makedirs()

        fp = fp.child(filename)
        if not fp.exists():
            raise SerializerReadException("%r doesn't exist!" % chunk)

        tag = self._read_tag(fp)
        if not tag:
            raise SerializerReadException("%r (in %s) is corrupt!" %
                    (chunk, fp.path))

        try:
            self._load_chunk_from_tag(chunk, tag)
        except Exception, e:
            raise SerializerReadException("%r couldn't be loaded: %s" %
                    (chunk, e))
Exemple #5
0
    def load_level(self, level):
        tag = self._read_tag(self.folder.child("level.dat"))
        if not tag:
            return

        try:
            level.spawn = (tag["Data"]["SpawnX"].value,
                           tag["Data"]["SpawnY"].value,
                           tag["Data"]["SpawnZ"].value)

            level.seed = tag["Data"]["RandomSeed"].value
            level.time = tag["Data"]["Time"].value
        except KeyError:
            # Just raise. It's probably gonna be caught and ignored anyway.
            raise SerializerReadException("Incomplete level data")
Exemple #6
0
    def load_chunk(self, chunk):
        first, second, filename = names_for_chunk(chunk.x, chunk.z)
        fp = self.folder.child(first).child(second)
        if not fp.exists():
            fp.makedirs()
        fp = fp.child(filename)

        tag = self._read_tag(fp)
        if not tag:
            return

        try:
            self._load_chunk_from_tag(chunk, tag)
        except Exception, e:
            raise SerializerReadException(e)
Exemple #7
0
 def load_player(self, username):
     if username in self.players:
         return deepcopy(self.players[username])
     raise SerializerReadException("%r couldn't be loaded" % username)
Exemple #8
0
 def load_level(self):
     if self.level:
         return deepcopy(self.level)
     raise SerializerReadException("Level couldn't be loaded")
Exemple #9
0
 def load_chunk(self, x, z):
     key = x, z
     if key in self.chunks:
         return deepcopy(self.chunks[key])
     raise SerializerReadException("%d, %d couldn't be loaded" % key)