WhatsUp
Quilt 版本需要:QSL 和 GroovyDuvet
Forge 版本需要:GML
WhatsUp 是一个用于数据包的工具,允许服务器以指定的频率查询提供的 Web 端点,并根据该端点返回的结果执行函数(标准的 .mcfunction 类型)。
WhatsUp 定义了 listeners 和 predicates。listeners 定义在 data/<namespace>/whatsup/listeners/<name>.json 中,其结构如下:
endpoint - 监听器要查询的 URL
frequency - 一个整数,表示两次查询端点之间应经过的秒数
actions - 基于端点返回结果要执行的操作列表。每个操作具有以下形式:
predicate - 用于检查端点结果的谓词的资源位置
function - 如果谓词检查通过,则要执行的函数的资源位置
levels - (可选;默认为 ["overworld"])在其中运行所提供函数的维度列表
then - (可选)在此监听器之后链接的其他监听器的位置列表
storage - (可选)属性名称到资源位置的映射,指定谓词可访问的命令数据存储
谓词存储在 data/<namespace>/whatsup/predicates/<name>.groovy 中,是 Groovy 脚本。谓词运行的 Groovy 环境可以访问 context 变量,该变量具有以下属性:
text - 未处理的响应文本
json - 将响应解析为 JSON 的 Map,如果响应不是 JSON 对象则为 null
storage - 包含在操作中指定的每个命令数据存储的属性;可以查询和修改数据存储。此上下文对象也可作为脚本的委托,因此访问这些属性时前缀 context. 是可选的。
示例数据包可在 GitHub releases 找到。
该模组还提供了 /whatsup 命令,以便轻松测试数据包;可用于立即运行任何监听器。
WhatsUp
Quilt version requires: QSL and GroovyDuvet
Forge version requires: GML
WhatsUp is a tool for datapacks that allows servers to query a provided web endpoint at a given frequency, and execute
functions (the normal .mcfunction type) based on the results returned by that endpoint.
WhatsUp defines both listeners and predicates. listeners are defined at data/<namespace>/whatsup/listeners/<name>.json,
and take the following structure:
endpoint - The URL to be queried by the listener
frequency - An integer representing how many seconds should pass between queries of the endpoint
actions - A list of actions to do based on the returned result of the endpoint. Each takes the following form:
predicate - The resource location of a predicate to check against the endpoint's result
function - The resource location of a function to execute if the predicate passes
levels - (Optional; defaults to ["overworld"]) A list of dimensions to run the provided function in
then - (Optional) a list of locations of other listeners to chain after this listener
storage - (Optional) a map of property names to resource locations specifying command data storage that the predicate has access to
Predicates are stored at data/<namespace>/whatsup/predicates/<name>.groovy, and are groovy scripts. The groovy environment
the predicates run in has access to the context variable, which has the following properties:
text - The unprocessed response text
json - The a Map of the response parsed as JSON, or null if the response is not a JSON object
storage - Contains a property for every command data storage specified in the action; data storages can be queried and mutated.
This context object is also available as the delegate of the script, so a leading context. to access these properties is optional.
An example datapack can be found on the GitHub releases.
The mod also provides the /whatsup command for easily testing datapacks; this can be used to run any listener immediately.
评论 0
登录后参与评分
还没有评论,来抢沙发吧