1 Star 0 Fork 0

SuperKripts/SkriptExample

加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
文件
该仓库未声明开源许可证文件(LICENSE),使用请关注具体项目描述及其代码上游依赖。
克隆/下载
nextInput.sk 14.31 KB
一键复制 编辑 原始数据 按行查看 历史
msg_dw 提交于 2023-09-11 07:23 +08:00 . update nextInput.sk.
# _ _ _ _____ _
# | \ | | | | |_ _| | |
# | \| | _____ _| |_ | | _ __ _ __ _ _| |_
# | . ` |/ _ \ \/ / __| | | | '_ \| '_ \| | | | __|
# | |\ | __/> <| |_ _| |_| | | | |_) | |_| | |_
# |_| \_|\___/_/\_\\__| |_____|_| |_| .__/ \__,_|\__|
# | |
# v1.0.0 |_|
#
# 监听玩家的下一次输入
#
# 前置
# Request:
# - skript-packet(处理数据包)
# - - ProtocolLib
# - skript-reflect(自定义语法/调用Java方法)
#
# 测试环境
# Test Environment:
# JDK Version: jdk-19.0.1
# Server Version: paper-1.20.1-171
# Skript Version: skript-2.6.4
# Skript Depend:
# - skript-reflect-2.3
# - skript-packet-2.1.2
# ---------------------------------------------------------------- #
# ██████╗ ██████╗ ████████╗██╗ ██████╗ ███╗ ██╗███████╗
# ██╔═══██╗██╔══██╗╚══██╔══╝██║██╔═══██╗████╗ ██║██╔════╝
# ██║ ██║██████╔╝ ██║ ██║██║ ██║██╔██╗ ██║███████╗
# ██║ ██║██╔═══╝ ██║ ██║██║ ██║██║╚██╗██║╚════██║
# ╚██████╔╝██║ ██║ ██║╚██████╔╝██║ ╚████║███████║
# ╚═════╝ ╚═╝ ╚═╝ ╚═╝ ╚═════╝ ╚═╝ ╚═══╝╚══════╝
# 预设
options:
anvil icon: paper named "&r"
# ---------------------------------------------------------------- #
# ██╗███╗ ███╗██████╗ ██████╗ ██████╗ ████████╗
# ██║████╗ ████║██╔══██╗██╔═══██╗██╔══██╗╚══██╔══╝
# ██║██╔████╔██║██████╔╝██║ ██║██████╔╝ ██║
# ██║██║╚██╔╝██║██╔═══╝ ██║ ██║██╔══██╗ ██║
# ██║██║ ╚═╝ ██║██║ ╚██████╔╝██║ ██║ ██║
# ╚═╝╚═╝ ╚═╝╚═╝ ╚═════╝ ╚═╝ ╚═╝ ╚═╝
# 引入
import:
com.comphenix.protocol.wrappers.WrappedChatComponent
# ---------------------------------------------------------------- #
# ███████╗██╗ ██╗███╗ ██╗████████╗ █████╗ ██╗ ██╗
# ██╔════╝╚██╗ ██╔╝████╗ ██║╚══██╔══╝██╔══██╗╚██╗██╔╝
# ███████╗ ╚████╔╝ ██╔██╗ ██║ ██║ ███████║ ╚███╔╝
# ╚════██║ ╚██╔╝ ██║╚██╗██║ ██║ ██╔══██║ ██╔██╗
# ███████║ ██║ ██║ ╚████║ ██║ ██║ ██║██╔╝ ██╗
# ╚══════╝ ╚═╝ ╚═╝ ╚═══╝ ╚═╝ ╚═╝ ╚═╝╚═╝ ╚═╝
# 语法
# 自定义效果 监听来自玩家的下一次输入
effect listen next input (of|from) %player% [using (0¦chat|1¦anvil|2¦sign)] [with %-string%]:
trigger:
if mark is 0:
set metadata value "next-input-type" of expr-1 to "chat"
else if mark is 1:
set {_containerId} to expr-1.getHandle().nextContainerCounter()
send packet buildOpenAnvilPacket({_containerId}) to expr-1
wait 1 tick
send packet buildSetSlotPacket({_containerId}, 0, {@anvil icon}) to expr-1
set metadata value "next-input-type" of expr-1 to "anvil"
set metadata value "next-input-data" of expr-1 to {_containerId}
else if mark is 2:
send packet buildSignEditerPacket(location of expr-1) to expr-1
set metadata value "next-input-type" of expr-1 to "sign"
set metadata value "next-input-identifier" of expr-1 to expr-2
# 自定义事件 下一次输入事件
event "next-input-event":
pattern: next input [of %-string%]
event-values: player, string
check:
if expr-1 is not set:
continue
if expr-1 is data "identifier":
continue
# 自定义事件 取消输入事件
event "cancel-input-event":
pattern: (cancel|stop) [next] input [of %-string%]
event-values: player
check:
if expr-1 is not set:
continue
if expr-1 is data "identifier":
continue
# ---------------------------------------------------------------- #
# ███████╗██╗ ██╗███████╗███╗ ██╗████████╗
# ██╔════╝██║ ██║██╔════╝████╗ ██║╚══██╔══╝
# █████╗ ██║ ██║█████╗ ██╔██╗ ██║ ██║
# ██╔══╝ ╚██╗ ██╔╝██╔══╝ ██║╚██╗██║ ██║
# ███████╗ ╚████╔╝ ███████╗██║ ╚████║ ██║
# ╚══════╝ ╚═══╝ ╚══════╝╚═╝ ╚═══╝ ╚═╝
# 事件
# 处理聊天
on chat:
metadata value "next-input-type" of player is "chat"
delete metadata value "next-input-type" of player
cancel event
if message is "取消" or "cancel":
set {_eventValue::player} to player
set {_dataValue::identifier} to metadata value "next-input-identifier" of player
call custom event "cancel-input-event" with {_eventValue::*} using data {_dataValue::*}
else:
set {_eventValue::player} to player
set {_eventValue::string} to message
set {_dataValue::identifier} to metadata value "next-input-identifier" of player
call custom event "next-input-event" with {_eventValue::*} using data {_dataValue::*}
# ---------------------------------------------------------------- #
# 打开其它库存时 取消本次输入
on packet event play_server_open_window:
metadata value "next-input-type" of player is "anvil"
metadata value "next-input-data" of player is not field 0 of event-packet
delete metadata value "next-input-type" of player
set {_eventValue::player} to player
set {_dataValue::identifier} to metadata value "next-input-identifier" of player
call custom event "cancel-input-event" with {_eventValue::*} using data {_dataValue::*}
# 关闭库存窗口时 取消本次输入
on packet event play_client_close_window:
metadata value "next-input-type" of player is "anvil"
delete metadata value "next-input-type" of player
set {_eventValue::player} to player
set {_dataValue::identifier} to metadata value "next-input-identifier" of player
call custom event "cancel-input-event" with {_eventValue::*} using data {_dataValue::*}
# 点击库存时 进行处理
on packet event play_client_window_click:
metadata value "next-input-type" of player is "anvil"
metadata value "next-input-data" of player is field 0 of event-packet
player.updateInventory()
send packet buildSetSlotPacket(-1, -1, air) to player
send packet buildSetSlotPacket(field 0 of event-packet, 0, {@anvil icon}) to player
send packet buildWindowDataPacket(field 0 of event-packet) to player
field 2 of event-packet is 2 # 这个地方 1.17以下 可能是 field 1 不清楚 懒得测试
delete metadata value "next-input-type" of player
set {_eventValue::player} to player
set {_eventValue::string} to metadata value "next-input-result" of player
set {_dataValue::identifier} to metadata value "next-input-identifier" of player
call custom event "next-input-event" with {_eventValue::*} using data {_dataValue::*}
close inventory of player
# 输入名字时 重新发送改名需要的等级
on packet event play_client_item_name:
metadata value "next-input-type" of player is "anvil"
send packet buildWindowDataPacket(metadata value "next-input-data" of player) to player
set metadata value "next-input-result" of player to field 0 of event-packet
# ---------------------------------------------------------------- #
# 木牌编辑确认
on packet event play_client_update_sign:
metadata value "next-input-type" of player is "sign"
delete metadata value "next-input-type" of player
set {_eventValue::player} to player
set {_eventValue::string} to field 1 of event-packet # 这个默认只有第一行 懒得管多行文本了
set {_dataValue::identifier} to metadata value "next-input-identifier" of player
call custom event "next-input-event" with {_eventValue::*} using data {_dataValue::*}
# ---------------------------------------------------------------- #
# ███████╗██╗ ██╗███╗ ██╗████████╗██╗ ██████╗ ███╗ ██╗
# ██╔════╝██║ ██║████╗ ██║╚══██╔══╝██║██╔═══██╗████╗ ██║
# █████╗ ██║ ██║██╔██╗ ██║ ██║ ██║██║ ██║██╔██╗ ██║
# ██╔══╝ ██║ ██║██║╚██╗██║ ██║ ██║██║ ██║██║╚██╗██║
# ██║ ╚██████╔╝██║ ╚████║ ██║ ██║╚██████╔╝██║ ╚████║
# ╚═╝ ╚═════╝ ╚═╝ ╚═══╝ ╚═╝ ╚═╝ ╚═════╝ ╚═╝ ╚═══╝
# 函数
# 构建 打开铁砧 数据包
# @param windowId 库存ID
# @param title 标题
# @return 打开铁砧数据包
function buildOpenAnvilPacket(windowId: integer, title: string = "") :: packet:
set {_packet} to new play_server_open_window packet
set field 0 of {_packet} to {_windowId}
if 2nd element of fields classes of {_packet} is "net.minecraft.world.inventory.Containers":
set field 1 of {_packet} to (class "net.minecraft.world.inventory.Containers").h
else:
set field 1 of {_packet} to 7
if {_title} is not "":
{_packet}.getChatComponents().write(0, WrappedChatComponent.fromText({_title})) # 自定义容器名
return {_packet}
# 构建 库存数据 数据包
# @param windowId 库存ID
# @param key 键
# @param value 值
# @return 库存数据 数据包
function buildWindowDataPacket(windowId: integer, key: integer = 0, value: integer = 0) :: packet:
set {_packet} to new play_server_window_data packet
set field 0 of {_packet} to {_windowId}
set field 1 of {_packet} to {_key}
set field 2 of {_packet} to {_value}
return {_packet}
# 构建 set slot 数据包
# @param windowId 库存ID
# @param slotId 插槽ID
# @param item 物品
# @return set slot数据包
function buildSetSlotPacket(windowId: integer, slotId: integer, item: item) :: packet:
set {_packet} to new play_server_set_slot packet
set {_fieldCount} to size of all fields of {_packet}
if {_fieldCount} is 3:
set field 0 of {_packet} to {_windowId}
set field 1 of {_packet} to {_slotId}
set field 2 of {_packet} to NMS of {_item}
else if {_fieldCount} is 4:
set field 0 of {_packet} to {_windowId}
set field 2 of {_packet} to {_slotId}
set field 3 of {_packet} to NMS of {_item}
else:
send "error" to console
return {_packet}
# ---------------------------------------------------------------- #
# 构建 木牌编辑 数据包
# @param location 位置(距离过远会自动关闭)
# @return 木牌编辑数据包
function buildSignEditerPacket(location: location) :: packet:
set {_packet} to new play_server_open_sign_editor packet
set field 0 of {_packet} to NMS of {_location}
return {_packet}
# ---------------------------------------------------------------- #
# ███████╗██╗ ██╗ █████╗ ███╗ ███╗██████╗ ██╗ ███████╗
# ██╔════╝╚██╗██╔╝██╔══██╗████╗ ████║██╔══██╗██║ ██╔════╝
# █████╗ ╚███╔╝ ███████║██╔████╔██║██████╔╝██║ █████╗
# ██╔══╝ ██╔██╗ ██╔══██║██║╚██╔╝██║██╔═══╝ ██║ ██╔══╝
# ███████╗██╔╝ ██╗██║ ██║██║ ╚═╝ ██║██║ ███████╗███████╗
# ╚══════╝╚═╝ ╚═╝╚═╝ ╚═╝╚═╝ ╚═╝╚═╝ ╚══════╝╚══════╝
# 例子
# 命令 聊天输入
command /chatinput <player>:
permission: skript.admin
trigger:
send "请输入: " to arg-1
listen next input of arg-1 using chat with "test"
# 命令 铁砧输入
command /anvilinput <player>:
permission: skript.admin
trigger:
listen next input of arg-1 using anvil with "test"
# 命令 木牌输入
command /signinput <player>:
permission: skript.admin
trigger:
listen next input of arg-1 using sign with "test"
# 下一次输入事件
on next input of "test":
send "玩家 %player% 输入了: %string%" to console
# 取消输入事件
on cancel input of "test":
send "玩家 %player% 取消了本次输入!" to console
Loading...
马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化
1
https://gitee.com/Super-KRIPT/skript-example.git
git@gitee.com:Super-KRIPT/skript-example.git
Super-KRIPT
skript-example
SkriptExample
master

搜索帮助