コード例 #1
0
def on_load(server: ServerInterface, old):
    global config, data, host, port
    from ConfigAPI import Config
    from JsonDataAPI import Json
    config = Config(PLUGIN_METADATA['name'], DEFAULT_CONFIG)
    data = Json(PLUGIN_METADATA['name'])
    host = server.get_plugin_instance('cool_q_api').get_config()['api_host']
    port = server.get_plugin_instance('cool_q_api').get_config()['api_port']

    def qq(src, ctx):
        if config['command']['qq']:
            player = src.player if src.is_player else 'Console'
            for i in config['group_id']:
                send_group_msg(f'[{player}] {ctx["message"]}', i)

    server.register_help_message('!!qq <msg>', '向QQ群发送消息')
    server.register_command(
        Literal('!!qq').
            then(
            GreedyText('message').runs(qq)
        )
    )
    server.register_event_listener('cool_q_api.on_qq_info', on_qq_info)
    server.register_event_listener('cool_q_api.on_qq_command', on_qq_command)
    server.register_event_listener('cool_q_api.on_qq_notice', on_qq_notice)
コード例 #2
0
def on_load(server: ServerInterface, old):
    # load data
    if not os.path.exists(FILE_PATH):
        os.makedirs(FILE_PATH)
    if not os.path.isfile(FILE_PATH + 'AdvancedBan.json'):
        save_data()
    load_data()
    server.register_help_message('!!ab', 'AdvancedBan帮助信息',
                                 permission=min(PERMISSIONS.values()))
    register_command(server)
コード例 #3
0
ファイル: Info.py プロジェクト: fbano-0619/MCDReforgedPlugins
def on_load(server: ServerInterface, old):
    server.register_help_message('!!info', '获取服务器信息')
    server.register_command(
        Literal('!!info').runs(lambda src: src.reply(
            RTextList(
                '§7============ §6服务器信息 §7============\n',
                f'§7CPU利用率:§6 {average(*psutil.cpu_percent(percpu=True))}%\n',
                f'§7内存使用量:§6 {get_used_memory()} / {get_total_memory()}\n',
                f'§7服务器内存占用:§6 {get_this_used_memory(server)}\n',
                f'§7存档大小:§6 {get_world_size()}'))))
コード例 #4
0
def on_load(server: ServerInterface, old):
    global host, port
    host = server.get_plugin_instance('cool_q_api').get_config()['api_host']
    port = server.get_plugin_instance('cool_q_api').get_config()['api_port']

    def qq(src, ctx):
        player = src.player if src.is_player else 'Console'
        for i in config['group_id']:
            send_group_msg(f'[{player}] {ctx["message"]}', i)

    server.register_help_message('!!qq <msg>', '向QQ群发送消息')
    server.register_command(
        Literal('!!qq').then(GreedyText('message').runs(qq)))
コード例 #5
0
def on_load(server: ServerInterface, old):
    server.register_help_message('!!calc', '查看计算插件使用帮助')
    server.register_command(
        Literal('!!calc').requires(lambda src: src.is_player).runs(
            lambda src: src.reply(HELP_MSG)).then(
                Literal('item').then(
                    Integer('box/count').runs(calc_item).then(
                        Integer('stack').then(
                            Integer('single').runs(calc_item))))).
        then(
            Literal('color').then(
                Text('red/#HEX').runs(calc_color).then(
                    Integer('green').then(
                        Integer('blue').runs(calc_color))))).then(
                            GreedyText('expression').runs(calc_expression)))
コード例 #6
0
def on_load(server: ServerInterface, old):
    global mined_ranking
    from ConfigAPI import Config
    config = Config(PLUGIN_METADATA['name'], DEFAULT_CONFIG)
    mined_ranking = MinedRanking(server, config)
    mined_ranking.start()
    server.register_help_message('!!update mined', '更新挖掘榜')
    server.register_command(
        Literal('!!update').
            then(
            Literal('mined').
                requires(
                lambda src: src.has_permission(config['update_permission'])).
                runs(mined_ranking.update)
        )
    )
コード例 #7
0
def on_load(server: ServerInterface, old):
    global single

    @new_thread('SinglePlayerSleep')
    def sleep(src):
        get_time(src.get_server())
        if single.now_time >= 12542:
            fall_asleep = src.get_server().get_plugin_instance(
                'minecraft_data_api').get_player_info(src.player, 'SleepTimer')
            if fall_asleep != 100:
                return src.reply(single.config['not_fall_asleep'])
        else:
            return src.reply(single.config['is_daytime'])
        single.want_skip = True
        need_skip_time = 24000 - single.now_time
        for i in range(single.config['wait_before_skip'], 0, -1):
            if not single.want_skip:
                return
            msg = RText(single.config['waiting_for_skip'].format(
                src.player, i)).c(RAction.run_command, '!!sleep cancel')
            src.get_server().say(msg)
            time.sleep(1)
        for i in range(0, single.config['skip_wait_time']):
            if not single.want_skip:
                return
            jump_times = int(need_skip_time / single.config['skip_wait_time'])
            if src.get_server().is_rcon_running():
                src.get_server().rcon_query(f'time add {jump_times}')
            else:
                src.get_server().execute(f'time add {jump_times}')
            time.sleep(1)
        single.want_skip = False

    def cancel(src):
        if single.want_skip:
            single.want_skip = False
            src.reply(single.config['skip_abort'])
        else:
            src.reply(single.config['no_one_sleeping'])

    single = Single()
    server.register_help_message(
        '!!sleep',
        RText('单人睡觉跳过夜晚').c(RAction.run_command, '!!sleep').h('点我跳过夜晚'))
    server.register_help_message('!!sleep cancel', '取消跳过夜晚')
    server.register_command(
        Literal('!!sleep').runs(sleep).then(Literal('cancel').runs(cancel)))
コード例 #8
0
def on_load(server: ServerInterface, old):
    server.register_help_message('!!ab',
                                 'AdvancedBan帮助信息',
                                 permission=min(PERMISSIONS.values()))
    register_command(server)
コード例 #9
0
def on_load(server: ServerInterface, old):
    global api, data
    api = server.get_plugin_instance('minecraft_data_api')
    data = Json(PLUGIN_METADATA['name'])

    @new_thread('Gamemode switch mode')
    def change_mode(src):
        # Survival now
        if src.player not in data.keys():
            sur_to_spec(server, src.player)
            src.reply('§a已切换至旁观模式')
        # Spectator now
        elif src.player in data.keys():
            use_time = ceil((time.time() - data[src.player]['time']) / 60)
            src.reply(f'§a您使用了§e{use_time}min')
            spec_to_sur(server, src.player)

    @new_thread('Gamemode tp')
    def tp(src, ctx):
        if src.player not in data.keys():
            src.reply('§c您只能在旁观模式下传送')
        elif ctx['dimension'] not in DIMENSIONS.keys():
            src.reply('§c没有此维度')
        else:
            pos = ' '.join((str(ctx.get('x', '0')), str(ctx.get('y', '80')),
                            str(ctx.get('z', '0'))))
            dim = DIMENSIONS[ctx['dimension']]
            data[src.player]['back'] = {
                'dim': DIMENSIONS[api.get_player_info(src.player,
                                                      'Dimension')],
                'pos': api.get_player_info(src.player, 'Pos')
            }
            data.save()
            server.execute(f'execute in {dim} run tp {src.player} {pos}')
            src.reply(f'§a传送至§e{dim}§a, 坐标§e{dim}')

    @new_thread('Gamemode back')
    def back(src):
        if src.player not in data.keys():
            return server.reply('§c您只能在旁观模式下传送')
        else:
            dim = data[src.player]['back']['dim']
            pos = [str(x) for x in data[src.player]['back']['pos']]
            data[src.player]['back'] = {
                'dim': DIMENSIONS[api.get_player_info(src.player,
                                                      'Dimension')],
                'pos': api.get_player_info(src.player, 'Pos')
            }
            data.save()
            server.execute(
                f'execute in {dim} run tp {src.player} {" ".join(pos)}')
            src.reply('§a已将您传送至上个地点')

    server.register_help_message('!!spec help', 'Gamemode插件帮助')
    server.register_command(
        Literal('!!spec').requires(lambda src: src.is_player).runs(
            change_mode).then(
                Literal('help').runs(lambda src: src.reply(HELP_MESSAGE))))
    server.register_command(
        Literal('!!tp').requires(lambda src: src.is_player).then(
            Text('dimension').runs(tp).then(
                Float('x').then(Float('y').then(Float('z').runs(tp))))))
    server.register_command(
        Literal('!!back').requires(lambda src: src.is_player).runs(back))
コード例 #10
0
def on_load(server: ServerInterface, old):
    from ConfigAPI import Config
    from JsonDataAPI import Json
    global api, data
    api = server.get_plugin_instance('minecraft_data_api')
    config = Config(PLUGIN_METADATA['name'], DEFAULT_CONFIG)
    data = Json(PLUGIN_METADATA['name'])
    permissions = config['permissions']
    server.register_help_message('!!spec help', 'Gamemode插件帮助')

    @new_thread('Gamemode switch mode')
    def change_mode(src, ctx):
        if src.is_console:
            return src.reply('§c仅允许玩家使用')
        player = src.player if ctx == {} else ctx['player']
        if player not in data.keys():
            server.tell(player, '§a已切换至旁观模式')
            sur_to_spec(server, player)
        elif player in data.keys():
            use_time = ceil((time.time() - data[player]['time']) / 60)
            server.tell(player, f'§a您使用了§e{use_time}min')
            spec_to_sur(server, player)

    @new_thread('Gamemode tp')
    def tp(src, ctx):
        if src.is_console:
            return src.reply('§c仅允许玩家使用')
        if src.player not in data.keys():
            src.reply('§c您只能在旁观模式下传送')
        elif ctx['dimension'] not in DIMENSIONS.keys():
            src.reply('§c没有此维度')
        else:
            pos = ' '.join((
                str(ctx.get('x', '0')),
                str(ctx.get('y', '80')),
                str(ctx.get('z', '0'))
            ))
            dim = DIMENSIONS[ctx['dimension']]
            data[src.player]['back'] = {
                'dim': DIMENSIONS[api.get_player_info(src.player, 'Dimension')],
                'pos': api.get_player_info(src.player, 'Pos')
            }
            data.save()
            server.execute(f'execute in {dim} run tp {src.player} {pos}')
            src.reply(f'§a传送至§e{dim}§a, 坐标§e{dim}')

    @new_thread('Gamemode back')
    def back(src):
        if src.is_console:
            return src.reply('§c仅允许玩家使用')
        if src.player not in data.keys():
            return src.reply('§c您只能在旁观模式下传送')
        else:
            dim = data[src.player]['back']['dim']
            pos = [str(x) for x in data[src.player]['back']['pos']]
            data[src.player]['back'] = {
                'dim': DIMENSIONS[api.get_player_info(src.player, 'Dimension')],
                'pos': api.get_player_info(src.player, 'Pos')
            }
            data.save()
            server.execute(
                f'execute in {dim} run tp {src.player} {" ".join(pos)}')
            src.reply('§a已将您传送至上个地点')

    server.register_command(
        Literal('!!spec').
            requires(lambda src: src.has_permission(permissions['spec'])).
            runs(change_mode).
            then(
            Literal('help').
                runs(lambda src: src.reply(HELP_MESSAGE))
        ).
            then(
            Text('player').
                requires(
                lambda src: src.has_permission(permissions['spec_other'])
            ).
                runs(change_mode)
        )
    )
    server.register_command(
        Literal('!!tp').
            requires(lambda src: src.has_permission(permissions['tp'])).
            then(
            Text('dimension').
                runs(tp).
                then(
                Float('x').
                    then(
                    Float('y').
                        then(
                        Float('z').runs(tp)
                    )
                )
            )
        )
    )
    server.register_command(
        Literal('!!back').
            requires(lambda src: src.has_permission(permissions['back'])).
            runs(back)
    )
コード例 #11
0
def on_load(server: ServerInterface, prev):
    get_notice_data(server)
    get_config(server)
    server.register_help_message('!!notice', RText('简易公告插件,!!notice help查看帮助'))
    command_register(server)
コード例 #12
0
def on_load(server: ServerInterface, old):
    from ConfigAPI import Config
    from JsonDataAPI import Json
    config = Config(PLUGIN_METADATA['name'], DEFAULT_CONFIG)
    data = Json(PLUGIN_METADATA['name'])
    permissions = config['permissions']
    server.register_help_message('!!bot help', '显示Bot插件帮助')
    server.register_help_message(
        '!!bot',
        RText('显示机器人列表').c(RAction.run_command, '!!bot').h('点击显示机器人列表'))

    def show_list(src):
        c = []
        for a, b in data.items():
            bot_info = RTextList(
                '\n'
                f'§7----------- §6{a}§7 -----------\n',
                f'§7Dimension:§6 {b["dim"]}\n', f'§7Position:§6 {b["pos"]}\n',
                f'§7Facing:§6 {b["facing"]}\n',
                RText('§d点击放置\n').c(RAction.run_command,
                                    f'!!bot spawn {a}').h(f'放置§6{a}'),
                RText('§d点击移除\n').c(RAction.run_command,
                                    f'!!bot kill {a}').h(f'移除§6{a}'))
            c.append(bot_info)
        src.reply(RTextList(*c))

    def spawn(src, ctx):
        name = ctx['name']
        if name in data.keys():
            dim = data[name]['dim']
            pos = ' '.join([str(i) for i in data[name]['pos']])
            facing = data[name]['facing']
            command = f'player {name} spawn at {pos} facing {facing} in {dim}'
            src.get_server().execute(command)
            src.get_server().execute(f'gamemode {config["gamemode"]} {name}')
        else:
            src.reply('§c机器人名称不正确')

    def kill(src, ctx):
        name = ctx['name']
        if name in data.keys():
            server.execute(f'player {name} kill')
        else:
            src.reply('§c机器人名称不正确')

    def add(src, ctx):
        if ctx['dim'] in DIMENSIONS.keys():
            dim = DIMENSIONS[ctx['dim']]
            pos = [ctx['x'], ctx['y'], ctx['z']]
            facing = f'{ctx["facing_level"]} {ctx["facing_pitch"]}'
            data[ctx['name']] = {'dim': dim, 'pos': pos, 'facing': facing}
            data.save()
            src.reply(f'§a已添加机器人{ctx["name"]}')
        else:
            src.reply('§c无法识别的维度')

    def remove(src, ctx):
        name = ctx['name']
        if name in data.keys():
            del data[name]
            data.save()
            src.reply(f'§a已删除机器人{name}')
        else:
            src.reply('§c机器人名称不正确')

    server.register_command(
        Literal('!!bot').requires(lambda src: src.has_permission(permissions[
            'list'])).runs(show_list).
        then(Literal('help').runs(lambda src: src.reply(HELP_MESSAGE))).then(
            Literal('spawn').requires(lambda src: src.has_permission(
                permissions['spawn'])).then(Text('name').runs(spawn))).then(
                    Literal('kill').requires(lambda src: src.has_permission(
                        permissions['kill'])).then(Text('name').runs(kill))).
        then(
            Literal('add')
            .requires(lambda src: src.has_permission(permissions['add'])).then(
                Text('name').then(
                    Text('dim').then(
                        Integer('x').then(
                            Integer('y').then(
                                Integer('z').then(
                                    Float('facing_level').then(
                                        Float('facing_pitch').runs(add))))))))
        ).then(
            Literal('remove').requires(
                lambda src: src.has_permission(permissions['remove'])).then(
                    Text('name').runs(remove))))
コード例 #13
0
def on_load(server: ServerInterface, old):
    def abort():
        global abort_flag
        abort_flag = True

    @new_thread(PLUGIN_METADATA['name'])
    def stop(src, ctx):
        if wait(server, 'stop', ctx.get('time', DEFAULT_WAIT_TIME)):
            server.stop()

    @new_thread(PLUGIN_METADATA['name'])
    def stop_exit(src, ctx):
        if wait(server, 'stop', ctx.get('time', DEFAULT_WAIT_TIME)):
            server.stop_exit()

    @new_thread(PLUGIN_METADATA['name'])
    def restart(src, ctx):
        if wait(server, 'restart', ctx.get('time', DEFAULT_WAIT_TIME)):
            server.restart()

    server.register_help_message('!!server', '服务器控制指令')
    server.register_command(
        Literal('!!server').
            requires(lambda src: src.has_permission(PERMISSIONS['help'])).
            runs(lambda src: src.reply(HELP_MESSAGE)).
            then(
            Literal('abort').
                requires(lambda src: src.has_permission(PERMISSIONS['abort'])).
                runs(abort)
        ).
            then(
            Literal('start').
                requires(lambda src: src.has_permission(PERMISSIONS['start'])).
                runs(lambda src: server.start())
        ).
            then(
            Literal('stop').
                requires(lambda src: src.has_permission(PERMISSIONS['stop'])).
                runs(stop).
                then(
                Integer('time').
                    runs(stop)
            )
        ).
            then(
            Literal('stop_exit').
                requires(
                lambda src: src.has_permission(PERMISSIONS['stop_exit'])).
                runs(stop_exit).
                then(
                Integer('time').
                    runs(stop_exit)
            )
        ).
            then(
            Literal('restart').
                requires(
                lambda src: src.has_permission(PERMISSIONS['restart'])).
                runs(restart).
                then(
                Integer('time').
                    runs(restart)
            )
        ).
            then(
            Literal('exit').
                requires(lambda src: src.has_permission(PERMISSIONS['exit'])).
                runs(lambda src: server.exit())
        )
    )