Example #1
0
 async def fillAny(self, blockname, blockdata=0):
     sequence = generateCoorSequence(self.pos1, self.pos2)
     await self.ws.send(message_utils.autocmd('closechat'))
     for i in sequence['sequence']:
         await self.ws.send(
             message_utils.autocmd("fill {0} {1} {2} {3}".format(
                 i[0], i[1], blockname, blockdata)))
         time.sleep(0.01)
     return {
         "success": True,
         "data": ref_strings.worldedit.fill_message.format(sequence['size'])
     }
Example #2
0
 async def playsound(self, selector, sound, pan, volume, pitch):
     await self.ws.send(
         message_utils.autocmd(
             "execute {0} ~ ~ ~ playsound {1} @s ^{2} ^ ^ {3} {4}".format(
                 selector, sound, message_utils.formatNumber(pan),
                 message_utils.formatNumber(volume),
                 message_utils.formatNumber(pitch))))
Example #3
0
 async def getHost(self):
     await self.ws.send(message_utils.autocmd('getlocalplayername'))
     msg = await self.ws.recv()
     self.host = json.loads(msg)['body']['localplayername']
     self.chatmsg = {
         'time': time.time(),
         'host_name': self.host,
         'messages': []
     }
     return self.host
Example #4
0
 async def update(self):
     await self.ws.send(message_utils.autocmd('testfor @e'))
     data = json.loads(await self.ws.recv())
     if not 'victim' in data['body']:
         self.time.append(time.time() - self.start_time)
         self.count.append(0)
         plt.plot(self.time, self.count, 'r')
         plt.pause(1)
         return
     self.time.append(time.time() - self.start_time)
     self.count.append(len(data['body']['victim']))
     plt.plot(self.time, self.count, 'r')
     if len(self.time) > 60:
         self.time.pop(0)
         self.count.pop(0)
     plt.pause(1)
Example #5
0
    async def parseCmd(self, args):
        if args[0] == ".set":
            if (len(args) == 1 or args[1] == ''):
                await self.ws.send(
                    message_utils.error(ref_strings.command_error))
                return
            if args[1] == "1":
                self.pos1 = await self.getPlayerBlockPos()
                if self.pos2 == None:
                    self.pos2 = self.pos1
                await self.ws.send(
                    message_utils.info(
                        ref_strings.worldedit.coor_1_msg.format(
                            str(self.pos1), self.pos1 * self.pos2)))
            if args[1] == "2":
                self.pos2 = await self.getPlayerBlockPos()
                if self.pos1 == None:
                    self.pos1 = self.pos2
                await self.ws.send(
                    message_utils.info(
                        ref_strings.worldedit.coor_2_msg.format(
                            str(self.pos2), self.pos1 * self.pos2)))
            await self.ws.send(message_utils.autocmd('closechat'))

        if args[0] == ".fill":
            if (len(args) == 1 or args[1] == ''):
                await self.ws.send(
                    message_utils.error(ref_strings.command_error))
                return
            if self.pos1 == None or self.pos2 == None:
                await self.ws.send(
                    message_utils.error(ref_strings.worldedit.no_coordinate))
                return
            if len(args) == 2:
                result = await self.fillAny(args[1])
            else:
                result = await self.fillAny(args[1], args[2])
            if result["success"]:
                await self.ws.send(message_utils.info(result["data"]))
            else:
                await self.ws.send(message_utils.error(result["data"]))
Example #6
0
 async def updatekey(self):
     await self.ws.send(
         message_utils.autocmd('title {0} actionbar {1}'.format(
             self.selector, self.keyboard)))
Example #7
0
 async def copyBlock(self, source, destination):
     cmd = 'clone {0} {0} {1}'.format(source, destination)
     await self.ws.send(message_utils.autocmd(cmd))
Example #8
0
 async def fill(self, pos1, pos2, blockname, blockdata=0):
     cmd = 'fill {0} {1} {2} {3}'.format(pos1, pos2, blockname, blockdata)
     await self.ws.send(message_utils.autocmd(cmd))
Example #9
0
 async def setblock(self, pos, blockname, blockdata=0):
     cmd = 'setblock {0} {1} {2}'.format(pos, blockname, blockdata)
     await self.ws.send(message_utils.autocmd(cmd))
Example #10
0
    async def host_only(self, args):
        await self.we.parseCmd(args)

        if args[0] == ".getscore":
            await self.ws.send(
                message_utils.autocmd("scoreboard players list @s"))
            msg2 = json.loads(await self.ws.recv())
            match = re.findall(scoreRegex,
                               msg2.get("body").get("statusMessage"))
            out = {}
            for i in match:
                out[i[2]] = i[4]
            print(out)

        if args[0] == ".pixelart" and import_pixel:
            try:
                await self.pixelgen.parse_command(args[1:])
            except FileNotFoundError:
                await self.ws.send(
                    message_utils.error(ref_strings.file_not_exists))

        if args[0] == ".test":
            pass

        if args[0] == ".debug":
            if len(args) == 1:
                return
            if args[1] == '0':
                message_utils.log_command = False
            elif args[1] == '1':
                message_utils.log_command = True

        if args[0] == '.exit':
            await self.ws.send(message_utils.info('bye!'))
            raise KeyboardInterrupt

        if args[0] == '.copy':
            origin = worldedit.Position(2, 71, 10)
            destination = worldedit.Position(-60, 4, -75)
            for i in range(100):
                isEnd = await self.we.isBlock(
                    worldedit.Position(origin.x + i * 2, origin.y - 1,
                                       origin.z), 'command_block')
                if isEnd:
                    break
                for j in range(4):
                    for k in range(31):
                        detectPosition = worldedit.Position(
                            origin.x + i * 2, origin.y + k, origin.z + j * 2)
                        isBlock = await self.we.isBlock(
                            detectPosition, 'command_block')
                        isBlock2 = await self.we.isBlock(
                            detectPosition, 'chain_command_block')
                        if isBlock or isBlock2:
                            await self.we.copyBlock(
                                detectPosition,
                                worldedit.Position(destination.x - (j + i * 4),
                                                   destination.y + k,
                                                   destination.z))
                        else:
                            break

        if args[0] == '.save':
            self.save()
Example #11
0
    async def parse_command(self, msg):
        if msg["header"]["messagePurpose"] == "event":

            if msg["body"]["eventName"] == "PlayerMessage" and msg["body"][
                    "properties"]['MessageType'] == 'chat':

                self.log.log(msg)

                raw = message_utils.getChat(msg)

                args = raw.split(" ")

                executor = msg["body"]["properties"]["Sender"]

                if executor == self.log.host:
                    await self.host_only(args)

                if args[0] == ".info":
                    await self.ws.send(
                        message_utils.info(ref_strings.mcws.info))
                    await self.ws.send(
                        message_utils.info(ref_strings.pyversion))

                if args[0] == ".help":
                    for i in ref_strings.mcws.help:
                        await self.ws.send(
                            message_utils.info(i + " - " +
                                               ref_strings.mcws.help[i]))

                if args[0] == ".function":
                    arg1 = raw[10:]
                    if arg1 == "-ls":
                        for filename in glob.glob(
                                "files/functions/*.mcfunction"):
                            await self.ws.send(message_utils.info(filename))
                    else:
                        if os.path.exists("functions/" + arg1 + ".mcfunction"):
                            with open("functions/" + arg1 + ".mcfunction",
                                      "r") as file:
                                for i in file.readlines():
                                    await self.ws.send(message_utils.autocmd(i)
                                                       )
                        else:
                            await self.ws.send(
                                message_utils.error(
                                    ref_strings.file_not_exists))

                if args[0] == ".midi" and import_midiplayer:
                    await self.player.parse_command(args[1:])

                if args[0] == ".sier":
                    pass
                    '''
                    px = 50200
                    py = 100
                    pz = 50000
                    for x in range(-50, 50):
                        for z in range(-50, 50):
                            y = x ^ z
                            await ws.send(setBlock(px + x, py + y, pz + z, "redstone_block"))
                            time.sleep(0.001)'''

        elif msg["header"]["messagePurpose"] == "commandResponse":
            pass
Example #12
0
    async def generate(self, filename, position):
        img = Image.open(filename)
        size = img.size

        await self.ws.send(message_utils.autocmd('closechat'))
        await self.ws.send(
            message_utils.info(
                ref_strings.pixel.image_info.format(
                    filename, size[0], size[1],
                    message_utils.fileSize(filename))))
        max_width = 16 << 4

        if (not self.config['big']) and size[0] > max_width:
            ratio = size[0] / size[1]
            resize = max_width, int(max_width / ratio)
            img = img.resize(resize)
            size = resize
            await self.ws.send(
                message_utils.info(
                    ref_strings.pixel.resize_info.format(size[0], size[1])))

        if self.config['dither']:
            try:
                palimage = Image.new('P', (16, 16))
                palimage.putpalette(pal * 7)
                img = img.convert('RGB').quantize(palette=palimage)
                img.save('files/cache/test.png', 'png')
            except Exception as e:
                print(e)
                return

        if self.config['big']:
            block_size = 128
            work = 0
            required = math.ceil(size[0] / block_size) * math.ceil(
                size[1] / block_size)
            await self.ws.send(
                message_utils.info('block size = {0}'.format(block_size)))
            for x in range(0, size[0], block_size):
                for y in range(0, size[1], block_size):
                    if size[0] - x < block_size:
                        x2 = size[0]
                    else:
                        x2 = x + block_size - 1
                    if size[1] - y < block_size:
                        y2 = size[1]
                    else:
                        y2 = y + block_size - 1
                    print(x, y, x2, y2)
                    tempimage = img.crop((x, y, x2 + 1, y2 + 1))
                    temppos = worldedit.Position(position.x + x, position.y,
                                                 position.z + y)
                    print(temppos)
                    await self.ws.send(
                        message_utils.info('{0}/{1}'.format(work, required)))
                    sleep(1)
                    await self.ws.send(
                        message_utils.autocmd('tp @p ' + str(temppos)))
                    await self.draw(tempimage, temppos)
                    work += 1
                    sleep(1)
            return

        await self.draw(img, position)