def on_load(server: ServerInterface, old):
    def abort():
        global abort_flag
        abort_flag = True

    @new_thread(PLUGIN_METADATA["name"])
    def stop(src):
        if wait(server, 'stop'):
            server.stop()

    @new_thread(PLUGIN_METADATA["name"])
    def stop_exit(src):
        if wait(server, 'stop'):
            server.stop_exit()

    @new_thread(PLUGIN_METADATA["name"])
    def restart(src):
        if wait(server, 'restart'):
            server.restart()

    server.register_command(
        Literal('!!abort').
            requires(lambda s: s.has_permission(PERMISSIONS['abort'])).
            runs(abort)
    )

    server.register_command(
        Literal('!!start').
            requires(lambda s: s.has_permission(PERMISSIONS['start'])).
            runs(lambda src: server.start())
    )
    server.register_command(
        Literal('!!stop').
            requires(lambda s: s.has_permission(PERMISSIONS['stop'])).
            runs(stop)
    )
    server.register_command(
        Literal('!!stop_exit').
            requires(lambda s: s.has_permission(PERMISSIONS['stop_exit'])).
            runs(stop_exit)
    )
    server.register_command(
        Literal('!!restart').
            requires(lambda s: s.has_permission(PERMISSIONS['restart'])).
            runs(restart)
    )
    server.register_command(
        Literal('!!exit').
            requires(lambda s: s.has_permission(PERMISSIONS['exit'])).
            runs(lambda src: server.exit())
    )
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())
        )
    )