Skip to main content

Helper Lib for LLSE Python Runtime

Project description

LLSE-Python Helper Lib

wakatime

Developing……

Install

Use pdm to install, then you can import it in your plugin

pdm add llpy-helper-lib

or you can use lip

lip i github.com/lgc-LLSEDev/llpy-helper-lib

Usage

from typing import cast

# you can input any ll's built-ins from `llpy`
from llpy import (
    LLSE_CommandOrigin,
    LLSE_CommandOutput,
    ParamType,
    PermType,
    Version,
    colorLog,
    ll,
    logger,
    mc,
)

# you can input some types from `llpy.types`
from llpy.types import T_CommandCallbackResult

# you can input some utils from `llpy.utils`
from llpy.utils import command_callback, listener

# register a listener
mc.listen("onServerStarted", lambda: colorLog("green", "The Server Started!"))


# or you can use the decorator from `llpy.utils`
@listener("onConsoleCmd")
def _(cmd: str):
    logger.info(f'You typed "{cmd}"')


# register a command
cmd = mc.newCommand("testcmd", "A Test Command", PermType.Any)
cmd.optional("input", ParamType.RawText)
cmd.overload(["input"])


# set callback using `command_callback` decorator from `llpy.utils`
@command_callback(cmd)
def _(
    _,
    ori: LLSE_CommandOrigin,
    out: LLSE_CommandOutput,
    res: dict[str, T_CommandCallbackResult],
):
    arg = cast(str | None, res.get("input"))
    tip = f'§aYou inputed §r"§6§l{arg}§r"' if arg else "§cNothing inputted!"

    player = ori.player
    if player:
        # if player exec the cmd, send a form
        form = mc.newSimpleForm().setTitle("Test Form").setContent(tip)
        player.sendForm(form, lambda _, __: None)

    else:
        # if not, send output to console
        out.success(tip) if arg else out.error(tip)

    return True


cmd.setup()  # set up it


# and more...

# set plugin metadata
ll.registerPlugin(
    "test",
    "test",
    [0, 0, 1, Version.Dev],
    {"Author": "student_2333"},
)

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

llpy-helper-lib-0.0.1.dev8.tar.gz (60.9 kB view hashes)

Uploaded Source

Built Distribution

llpy_helper_lib-0.0.1.dev8-py3-none-any.whl (93.3 kB view hashes)

Uploaded Python 3

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page