Ejemplo n.º 1
0
def help_and_run(src):
    server, info = __get(src)

    line1 = f"{'='*10} 使用方法 {'='*10}"
    line2 = f"{cmdprefix}                      查看方法和使用"
    line3 = f"{cmdprefix} store <number>       存储number瓶经验(7经验/瓶)"
    line4 = RText(f"{cmdprefix} store-all            存储全部经验", RColor.yellow)
    line5 = RText(f"{cmdprefix} store-30             存储多出30级的经验",
                  RColor.yellow)

    xp_total = __get_xp_total(server, info.player)

    number_all, space_all = __store_space(xp_total)

    number_30, space_30 = __store_space(xp_total - LEVEL30TOTAL)

    line4.set_hover_text(
        RTextList("当前能存:", RText(f"{number_all}", RColor.green), "瓶(",
                  RText(f"{space_all}", RColor.blue), ")格"))
    if number_all > 0:
        line4.set_click_event(RAction.run_command,
                              f"{cmdprefix} store {number_all}")

    line5.set_hover_text(
        RTextList("当前能存:", RText(f"{number_30}", RColor.green), "瓶(",
                  RText(f"{space_30}", RColor.blue), ")格"))
    if number_30 > 0:
        line5.set_click_event(RAction.run_command,
                              f"{cmdprefix} store {number_30}")

    server.reply(info, "\n".join([line1, line2, line3]))
    server.reply(info, RTextList(line4, "\n", line5))
Ejemplo n.º 2
0
def invite(src, ctx):
    server, info = __get(src)

    invite_player = ctx["player"]

    if invite_player == info.player:
        server.reply(info, RText("不能向你自已发送邀请", RColor.red))
        return

    # 邀请的玩家是否在线
    if player_online(server, invite_player):

        if check_level(server, info):

            # 查看邀请信息
            k = info.player + "_" + invite_player
            v = int(time.time())
            INVITE[k] = v

            server.tell(invite_player, click_invite(info.player,
                                                    invite_player))
            server.reply(
                info,
                RTextList("向玩家 ", RText(f"{invite_player}", RColor.yellow),
                          " 发送tp邀请"))
            playsound(server, info.player)

    else:
        server.reply(
            info,
            RTextList("玩家 ", RText(f"{invite_player}", RColor.red), " 不在线"))
Ejemplo n.º 3
0
def remove(src, ctx):
    server, info = __get(src)

    u = USERTP.get(info.player)

    if u is None:
        server.tell(info.player, RText(f"当前没有收藏点.", RColor.red))
    else:
        label_name = ctx.get("label_name")

        label = u.get(label_name)

        if label is None:
            server.reply(
                info,
                RTextList(RText("没有 "), RText(label_name, RColor.yellow),
                          RText(" 收藏点")))
            return

        u.pop(label_name)

        player_save(info.player, u)

        server.reply(
            info,
            RTextList("地点: ",
                      RText(label_name, RColor.yellow, RStyle.strikethrough),
                      " 删除成功"))
        playsound(server, info.player)

    server.logger.debug(f"remove ctx -------------->\n{ctx}")
Ejemplo n.º 4
0
def accept(src, ctx):
    server, info = __get(src)

    accept_player = ctx["player"]

    # 对方是否在线
    if player_online(server, accept_player):

        # 查看邀请信息
        k = accept_player + "_" + info.player

        t = int(time.time()) - INVITE.get(k, 0)

        if t < 180:
            server.rcon_query(
                f"execute at {info.player} run teleport {info.player} {accept_player}"
            )
            server.rcon_query(
                f"execute at {info.player} run playsound minecraft:item.chorus_fruit.teleport player {info.player}"
            )
        else:
            server.reply(info, RText("玩家没有邀请你或邀请已超过3分钟", RColor.yellow))
            #playsound(server, info.player)

        pop_invite(k)

    else:
        server.reply(
            info,
            RTextList("玩家 ", RText(f"{accept_player}", RColor.red), " 不在线"))
Ejemplo n.º 5
0
def remove(src, ctx):
    server, info = __get(src)

    u = player_load(info.player)

    if u == {}:
        server.tell(info.player, RText(f"当前没有强制加载区块.", RColor.red))
    else:
        label_name = ctx.get("label_name")

        label = u.get(label_name)

        if label is None:
            server.reply(
                info,
                RTextList(RText("没有 "), RText(label_name, RColor.yellow),
                          RText("强制加载区块")))
            return

        position = u.pop(label_name)
        world = position["world"]
        x, z = position["x"], position["z"]

        #
        rcon_result = server.rcon_query(
            f"execute in {world} run forceload remove {x} {z}")
        unload = re.match(
            f"Unmarked chunk \[(-?[0-9]+), (-?[0-9]+)\] in (.*) for force loading",
            rcon_result)

        if unload is None:
            server.reply(info, RText(f"未知错误,请报告服主。", RColor.red))
            server.logger.error(f"{rcon_result=}")

        else:
            player_save(info.player, u)
            server.reply(
                info,
                RTextList(
                    "强制加载区块: ",
                    RText(label_name, RColor.yellow, RStyle.strikethrough),
                    " 删除成功"))

    server.logger.debug(f"remove ctx -------------->\n{ctx}")
Ejemplo n.º 6
0
def add(src, ctx):
    server, info = __get(src)

    # 查看玩家的等级够不够
    if not check_level(server, info):
        server.reply(info, RText(f"当前等级不足,至少需要1级。", RColor.red))
        return

    # 查询坐标
    rcon_result = server.rcon_query(f"data get entity {info.player} Pos")
    position = re.search(
        f"{info.player} has the following entity data: \[(-?[0-9\.]+)d, (-?[0-9.]+)d, (-?[0-9.]+)d\]",
        rcon_result)
    x, y, z = position.group(1), position.group(2), position.group(3)
    x, y, z = round(float(x)), round(float(y)), round(float(z))

    rcon_result = server.rcon_query(f"forceload add {x} {z}")
    load = re.match(
        f"Marked chunk \[(-?[0-9]+), (-?[0-9]+)\] in (.*) to be force loaded",
        rcon_result)

    if load is None:
        check = re.match("No chunks were marked for force loading",
                         rcon_result)
        server.logger.error(f"{rcon_result=}")

        if check is None:
            server.reply(info, RText(f"未知错误,请报告服主。", RColor.red))
            server.logger.error(f"{check=}")
        else:
            server.reply(info, RText(f"当前区块已经强制加载!(可能是其他人加载)", RColor.yellow))

    else:

        #
        world = load.group(3)

        label_name = ctx["label_name"]

        u = player_load(info.player)

        u[label_name] = {"world": world, "x": x, "y": y, "z": z}

        server.tell(
            info.player,
            RTextList("强制加载区块: ", RText(label_name, RColor.yellow), " 添加成功"))

        player_save(info.player, u)

        if len(u) > PLAYER_MAX_BLOCK:
            server.reply(
                info,
                RText(f"强制加载区块已到最大数: {PLAYER_MAX_BLOCK} 请删除后添加", RColor.red))
            return

    server.logger.debug(f"add ctx -------------->\n{ctx}")
Ejemplo n.º 7
0
def help_and_run(src):
    server, info = __get(src)

    line1 = f"{'='*10} 使用方法 {'='*10}"
    line2 = f"{CMD}                      查看方法和使用"
    line3 = f"{CMD} <number>             购买number个不死图腾(7绿宝石/个)"
    line4 = RText(f"{CMD} all                   使用背包全部的绿宝石购买", RColor.yellow)

    total = emerald(server, info.player)

    number_all, _ = divmod(total, UNIT_PRICE)

    line4.set_hover_text(
        RTextList("当前能购买:", RText(f"{number_all}", RColor.green), "/个"))
    if number_all > 0:
        line4.set_click_event(RAction.run_command, f"{CMD} {number_all}")
    else:
        server.reply(info, RText("你当前背包绿宝石不够", RColor.red))

    server.reply(info, "\n".join([line1, line2, line3]))
    server.reply(info, RTextList(line4))
Ejemplo n.º 8
0
    def autobackup(self, msg=""):

        self.server.say(
            RTextList(RText("开始备份存档: "),
                      RText(f"{self.cur_timestamp} ", RColor.yellow),
                      RText("...")))

        t1 = time.time()
        # save-off
        self.server.rcon_query("save-off")
        # server.rcon_query("save-all flush")

        result = self.server.rcon_query("save-all")

        if re.findall("Saved the game", result):
            # self.server.say("拿到 `Saved the game` 结果")
            pass
        else:
            # self.server.say(RText("服务器可能 过于卡顿 备份失败。。。", RColor.red))
            # self.server.say(RText(f"没拿到 `Saved the game` 拿到的是{result}", RColor.red))
            return

        try:
            backup2current(str(WORLD_DIR), str(BACKUP_DIR / "bak-0"))
        except Exception as e:
            self.server.say(RText("插件内部错误。。。", RColor.red))
            raise e

        self.server.rcon_query("save-on")

        t2 = time.time()

        self.server.say(
            RTextList(RText("备份存档: "),
                      RText(f"{self.cur_timestamp}", RColor.yellow),
                      RText(" 完成 "),
                      RText(f"耗时:{round(t2-t1, 2)}s", RColor.yellow)))

        # 更新存档信息
        self.__update(msg)
Ejemplo n.º 9
0
def welcome(server, player):
    msg = [
        RText("=" * 10 + "嗨~!" + "=" * 10 + "\n\n"),
        RText(f"欢迎! {player} !\n\n", RColor.yellow),
    ]

    r = RText(">>> 点击这里,查看可用命令 <<<", RColor.green)
    r.set_hover_text("!!help")
    r.set_click_event(RAction.run_command, f"!!help")

    msg.append(r)

    server.tell(player, RTextList(*msg))
Ejemplo n.º 10
0
def add(src, ctx):
    server, info = __get(src)

    # 查询世界
    rcon_result = server.rcon_query(f"data get entity {info.player} Dimension")

    if rcon_result is None:
        prompt = RText("rcon 没有开启, 请分别server.properties, MCDR/config.yml 开启。",
                       RColor.red)
        server.logger.warning(prompt)
        server.tell(info.player, RText(f"{CMD} 插件没有配置成功,请联系服主。", RColor.red))

    world = re.match(
        '{} has the following entity data: "(.*)"'.format(info.player),
        rcon_result).group(1)

    # 查询坐标
    rcon_result = server.rcon_query(f"data get entity {info.player} Pos")
    position = re.search(
        f"{info.player} has the following entity data: \[(-?[0-9\.]+)d, (-?[0-9.]+)d, (-?[0-9.]+)d\]",
        rcon_result)
    x, y, z = position.group(1), position.group(2), position.group(3)
    x, y, z = round(float(x), 1), round(float(y), 1), round(float(z), 1)

    u = USERTP.get(info.player)
    if u is None:
        u = {}
        USERTP[info.player] = u
    elif len(u) > PLAYER_MAX_POINT:
        server.reply(info,
                     RText(f"收藏点已到最大数: {PLAYER_MAX_POINT} 请删除后添加", RColor.red))
        return

    # 查看玩家的等级够不够
    if check_level(server, info):
        label_name = ctx["label_name"]

        u[label_name] = {"world": world, "x": x, "y": y, "z": z}

        server.tell(
            info.player,
            RTextList("地点: ", RText(label_name, RColor.yellow), " 收藏成功"))
        playsound(server, info.player)

        player_save(info.player, u)

    server.logger.debug(f"add ctx -------------->\n{ctx}")
Ejemplo n.º 11
0
def ls(src, ctx):
    server, info = __get(src)

    u = player_load(info.player)

    msg = [
        f"{'='*10} 当前没有强制加载区块, 快使用下面命令添加一个吧。 {'='*10}",
        f"{CMD} add <名字>",
    ]

    if u == {}:
        server.reply(info, "\n".join(msg))
    else:
        msg1 = [RText(f"{'='*10} 强制加载区块 {'='*10}\n", RColor.white)]
        msg2 = []
        for label_name, data in u.items():
            msg2.append(
                click_text(info.player, label_name, data["world"], data["x"],
                           data["y"], data["z"]))

        msg = msg1 + fmt(msg2)
        server.reply(info, RTextList(*msg))

    server.logger.debug(f"list ctx -------------->\n{ctx}")
Ejemplo n.º 12
0
def ls(src, ctx):
    server, info = __get(src)

    u = USERTP.get(info.player)

    msg = [
        f"{'='*10} 当前没有收藏点, 快使用下面命令收藏一个吧。 {'='*10}",
        f"{CMD} add <收藏点名>",
    ]

    if u is None:
        server.reply(info, "\n".join(msg))
    else:
        msg1 = [RText(f"{'='*10} 收藏点 {'='*10}\n", RColor.white)]
        msg2 = []
        for label_name, data in u.items():
            msg2.append(
                click_text(info.player, label_name, data["world"], data["x"],
                           data["y"], data["z"]))

        msg = msg1 + fmt(msg2)
        server.reply(info, RTextList(*msg))

    server.logger.debug(f"list ctx -------------->\n{ctx}")
Ejemplo n.º 13
0
    def game_start(self, gameid):
        # 点我unready
        unready = RText("秒钟后游戏开始, 请不要中途退出。", RColor.yellow)
        unready.set_hover_text(RText("点我unready", RColor.green))
        unready.set_click_event(RAction.run_command, f"unready")

        # 10秒后游戏开始
        self.countdowning = True
        for i in range(10, 0, -1):

            # 如果有玩家 unready 取消开局
            if not self.countdowning:
                self.server.say(RText("取消开局,有玩家unready。", RColor.yellow))
                return

            self.server.say(RTextList(RText(f"{i} ", RColor.green), unready))
            time.sleep(1)

        # 开局前准备
        self.game_start_init()

        self.game_started = True

        # 每局开始时,第一次提示.
        first_show = True
        # sleep = 30 # testing
        sleep = 5 * 60

        # 如果 逃亡者存活过30分钟,逃亡者胜利。
        for i in range(6):

            if self.gameid != gameid:
                self.server.logger.info(f"之前的游戏线程退出 gameid: {self.gameid}.")
                return

            now = time.strftime("%Y-%m-%d %H:%M:%S", time.localtime())

            # 广播逃亡者位置,并高亮1分钟。
            self.running_x, self.running_y, self.running_z = get_pos_point(
                self.server, self.player_running)
            self.server.say(
                RTextList(
                    "逃亡者:", RText(self.player_running, RColor.yellow),
                    "现在的位置是:",
                    RText(
                        f"x:{self.running_x} y:{self.running_y} z:{self.running_z} ",
                        RColor.green), RText(f"{now}", RColor.green)))
            self.server.rcon_query(
                f"effect give {self.player_running} minecraft:glowing 60")

            # 向他杀者显示, 逃亡者坐标。
            if first_show:
                first_show = False

                for killer in self.killer:
                    flow_thread(self.server, 60, killer, self.player_running)

                time.sleep(5)
                # self.show_running_location()
                time.sleep(sleep - 5)
            else:
                for killer in self.killer:
                    flow_thread(self.server, 60, killer, self.player_running)

                # self.show_running_location()
                time.sleep(sleep)

        # 时间到,逃亡者胜利。
        self.game_end("running")