- showCustomScreen 用 Dialog.create + ClickEvent.showDialog 弹出对话框
- DialogBase:标题+协议正文(截断500字)+签名输入框
- ConfirmationType:签收(yes)+拒签(no)双按钮
- canCloseWithEscape=false 强制表态
- onCustomClick 捕获 PlayerCustomClickEvent:
- IP 匹配在线玩家(PlayerCommonConnection 无 UUID 方法)
- 读 DialogResponseView.getText("signature")
- 有签名→校验签收;无签名→拒签
- 编译通过 EXIT=0
This commit is contained in:
@@ -427,33 +427,82 @@ public class CustomScreenManager implements Listener {
|
|||||||
* 改用 Inventory GUI + 书与笔(完整协议塞入书页),死循环弹窗强制表态。
|
* 改用 Inventory GUI + 书与笔(完整协议塞入书页),死循环弹窗强制表态。
|
||||||
*/
|
*/
|
||||||
/**
|
/**
|
||||||
* Java 版玩家:聊天确认(输入签名 → 回复 sign 签收 / deny 拒签)。
|
* Java 版玩家:MC 1.21.6+ 自定义屏幕(Dialog API)。
|
||||||
* Paper 26.x Dialog API 需 Registry + builder,无法动态创建实例,改用聊天流。
|
* 用 Dialog.create + ClickEvent.showDialog 弹出对话框,
|
||||||
* 死循环:未表态前每次上线都重新提示。
|
* 签收按钮 → 确认;拒签按钮 → 执行拒签动作。
|
||||||
|
* 死循环:未表态前每次上线都重新弹。
|
||||||
*/
|
*/
|
||||||
private void showCustomScreen(Player p, String pendingFile, String ackFileName, String content, ActionConfig actions) {
|
private void showCustomScreen(Player p, String pendingFile, String ackFileName, String content, ActionConfig actions) {
|
||||||
PendingSign ps = new PendingSign(pendingFile, ackFileName, content, actions);
|
PendingSign ps = new PendingSign(pendingFile, ackFileName, content, actions);
|
||||||
pendingSigs.put(p.getUniqueId(), ps);
|
pendingSigs.put(p.getUniqueId(), ps);
|
||||||
|
|
||||||
// 分块发送协议内容(每段 5 行)
|
try {
|
||||||
String[] lines = content.split("\\n");
|
String title = "【待签收】" + new File(pendingFile).getName();
|
||||||
int chunk = 5;
|
String body = content.length() > 500 ? content.substring(0, 500) + "...(全文请右键书查看)" : content;
|
||||||
for (int i = 0; i < lines.length; i += chunk) {
|
|
||||||
int end = Math.min(i + chunk, lines.length);
|
|
||||||
StringBuilder sb = new StringBuilder();
|
|
||||||
for (int j = i; j < end; j++) {
|
|
||||||
sb.append(lines[j]);
|
|
||||||
if (j < end - 1) sb.append("\n");
|
|
||||||
}
|
|
||||||
p.sendMessage(Component.text(sb.toString()).color(net.kyori.adventure.text.format.NamedTextColor.GRAY));
|
|
||||||
}
|
|
||||||
|
|
||||||
p.sendMessage(Component.text(""));
|
// 构建 DialogBase:标题 + 正文 + 签名输入框
|
||||||
p.sendMessage(Component.text("§6§l【待签收】" + new File(pendingFile).getName()));
|
io.papermc.paper.registry.data.dialog.DialogBase base =
|
||||||
p.sendMessage(Component.text("§7请输入您的游戏ID作为签名,然后回复:"));
|
io.papermc.paper.registry.data.dialog.DialogBase.builder(
|
||||||
p.sendMessage(Component.text(" §a/sign§r = 签收 | §c/deny§r = 拒签(执行 " + ps.actions.denyAction + ")"));
|
Component.text(title)
|
||||||
p.sendMessage(Component.text("§e未表态前每次上线都会重新提示,必须表态"));
|
)
|
||||||
plugin.getLogger().info("[自定义屏幕] " + p.getName() + " Java版聊天确认已启动: " + new File(pendingFile).getName());
|
.canCloseWithEscape(false)
|
||||||
|
.afterAction(io.papermc.paper.registry.data.dialog.DialogBase.DialogAfterAction.NONE)
|
||||||
|
.body(java.util.List.of(
|
||||||
|
io.papermc.paper.registry.data.dialog.body.DialogBody.plainMessage(
|
||||||
|
Component.text(body).color(net.kyori.adventure.text.format.NamedTextColor.GRAY),
|
||||||
|
400
|
||||||
|
)
|
||||||
|
))
|
||||||
|
.inputs(java.util.List.of(
|
||||||
|
io.papermc.paper.registry.data.dialog.input.DialogInput.text(
|
||||||
|
"signature",
|
||||||
|
300,
|
||||||
|
Component.text("签名(输入您的游戏ID)"),
|
||||||
|
true,
|
||||||
|
"",
|
||||||
|
64,
|
||||||
|
null
|
||||||
|
)
|
||||||
|
))
|
||||||
|
.build();
|
||||||
|
|
||||||
|
// ConfirmationType:签收(yes)+ 拒签(no)
|
||||||
|
io.papermc.paper.registry.data.dialog.type.ConfirmationType type =
|
||||||
|
io.papermc.paper.registry.data.dialog.type.DialogType.confirmation(
|
||||||
|
io.papermc.paper.registry.data.dialog.ActionButton.create(
|
||||||
|
Component.text("§a§l✔ 签收"),
|
||||||
|
Component.text("确认签收用户协议"),
|
||||||
|
200,
|
||||||
|
null
|
||||||
|
),
|
||||||
|
io.papermc.paper.registry.data.dialog.ActionButton.create(
|
||||||
|
Component.text("§c§l✘ 拒签"),
|
||||||
|
Component.text("执行 " + ps.actions.denyAction + " 动作"),
|
||||||
|
200,
|
||||||
|
null
|
||||||
|
)
|
||||||
|
);
|
||||||
|
|
||||||
|
io.papermc.paper.dialog.Dialog dialog = io.papermc.paper.dialog.Dialog.create(
|
||||||
|
builder -> builder.empty()
|
||||||
|
.base(base)
|
||||||
|
.type(type)
|
||||||
|
);
|
||||||
|
|
||||||
|
// 发送对话框(通过 ClickEvent.showDialog 触发)
|
||||||
|
p.sendMessage(Component.empty().clickEvent(
|
||||||
|
net.kyori.adventure.text.event.ClickEvent.showDialog(dialog)
|
||||||
|
));
|
||||||
|
|
||||||
|
plugin.getLogger().info("[自定义屏幕] " + p.getName() + " Java版自定义屏幕已弹出: " + new File(pendingFile).getName());
|
||||||
|
|
||||||
|
} catch (Exception ex) {
|
||||||
|
plugin.getLogger().warning("[自定义屏幕] " + p.getName() + " 自定义屏幕失败,fallback 聊天: " + ex.getMessage());
|
||||||
|
p.sendMessage(Component.text("§6【待签收】" + new File(pendingFile).getName()));
|
||||||
|
p.sendMessage(Component.text("§7请输入您的游戏ID作为签名,然后回复:"));
|
||||||
|
p.sendMessage(Component.text(" §a/sign§r = 签收 | §c/deny§r = 拒签(执行 " + ps.actions.denyAction + ")"));
|
||||||
|
p.sendMessage(Component.text("§e未表态前每次上线都会重新提示,必须表态"));
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private org.bukkit.inventory.meta.ItemMeta buildMeta(Material mat, String displayName, String lore) {
|
private org.bukkit.inventory.meta.ItemMeta buildMeta(Material mat, String displayName, String lore) {
|
||||||
@@ -777,6 +826,52 @@ public class CustomScreenManager implements Listener {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// ==================== 自定义屏幕 Dialog 点击处理 ====================
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 处理 Java 版自定义屏幕(Dialog API)的按钮点击。
|
||||||
|
* 签收按钮 → 读取签名输入框 → 校验 → 落盘回执;
|
||||||
|
* 拒签按钮 → 执行拒签动作。
|
||||||
|
*/
|
||||||
|
@EventHandler(priority = EventPriority.MONITOR, ignoreCancelled = false)
|
||||||
|
public void onCustomClick(io.papermc.paper.event.player.PlayerCustomClickEvent e) {
|
||||||
|
if (e.getDialogResponseView() == null) return;
|
||||||
|
|
||||||
|
// 通过 IP 匹配在线玩家
|
||||||
|
var connection = e.getCommonConnection();
|
||||||
|
if (connection == null) return;
|
||||||
|
|
||||||
|
java.net.SocketAddress addr = connection.getAddress();
|
||||||
|
if (!(addr instanceof java.net.InetSocketAddress)) return;
|
||||||
|
String ip = ((java.net.InetSocketAddress) addr).getAddress().getHostAddress();
|
||||||
|
|
||||||
|
Player p = null;
|
||||||
|
for (Player online : Bukkit.getOnlinePlayers()) {
|
||||||
|
if (online.getAddress() != null && online.getAddress().getAddress().getHostAddress().equals(ip)) {
|
||||||
|
p = online;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if (p == null) return;
|
||||||
|
|
||||||
|
PendingSign ps = pendingSigs.get(p.getUniqueId());
|
||||||
|
if (ps == null) return;
|
||||||
|
|
||||||
|
io.papermc.paper.dialog.DialogResponseView view = e.getDialogResponseView();
|
||||||
|
String signature = view.getText("signature");
|
||||||
|
plugin.getLogger().info("[自定义屏幕] " + p.getName() + " 自定义屏幕点击, 签名=" + signature);
|
||||||
|
|
||||||
|
if (signature != null && !signature.isEmpty()) {
|
||||||
|
if (signature.equalsIgnoreCase(p.getName())) {
|
||||||
|
handleAccept(p, ps, signature);
|
||||||
|
} else {
|
||||||
|
p.sendMessage(Component.text("§c签名「" + signature + "」与您的游戏ID不匹配,请重新上线"));
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
confirmDeny(p, new File(ps.pendingFile).getName(), "");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 处理 /sdf1_login sign [signature] 命令(备用,无需指定标题——自动匹配当前待签收)。
|
* 处理 /sdf1_login sign [signature] 命令(备用,无需指定标题——自动匹配当前待签收)。
|
||||||
* @return true 已处理,false 未处理(非签收命令)
|
* @return true 已处理,false 未处理(非签收命令)
|
||||||
|
|||||||
Reference in New Issue
Block a user