第125批续8: Dialog 按钮点击回调修复(拒签/签收 action 未执行根因)
根因:125 续1 引入 Dialog API 时,ConfirmationType 的 yes/no 两个 ActionButton 第4参
(DialogAction)传 null → 按钮点击后只关弹窗(afterAction=CLOSE),不执行任何 Java 代码。
executeDenyAction/handleAccept 从未被调用 → 用户配「拒签=删号」但实际点拒签只是关屏幕,
玩家活得好好的(一镜到底视频 13.06.50 坐实)。
修复:两个按钮各挂 DialogAction.customClick 回调
- 签收按钮:回调里 audience instanceof Player → 查 pendingSigs → response.getText("signature")
取签名 → 校验匹配 → handleAccept 落盘回执单
- 拒签按钮:回调里同上取 signature → confirmDeny → executeDenyAction(del/rm→删号+kick)
- 回调 uses=UNLIMITED_USES(无限次)、lifetime=12h(每次上线重建 Dialog 新回调,足够覆盖)
配套:executeDenyAction 加 normalizeAction(trim+别名:del/rm/delete/删号→del,kick/踢出→kick),
default 分支从「静默跳过」改为「保底 kick + 大声 warning」(避免未知动作静默无后果被误判)。
This commit is contained in:
BIN
Binary file not shown.
@@ -1,6 +1,7 @@
|
|||||||
package Sdf1_login;
|
package Sdf1_login;
|
||||||
|
|
||||||
import net.kyori.adventure.text.Component;
|
import net.kyori.adventure.text.Component;
|
||||||
|
import net.kyori.adventure.text.event.ClickCallback;
|
||||||
import org.bukkit.Bukkit;
|
import org.bukkit.Bukkit;
|
||||||
import org.bukkit.Material;
|
import org.bukkit.Material;
|
||||||
import org.bukkit.entity.Player;
|
import org.bukkit.entity.Player;
|
||||||
@@ -467,22 +468,57 @@ public class CustomScreenManager implements Listener {
|
|||||||
.build();
|
.build();
|
||||||
|
|
||||||
// ConfirmationType:签收(yes)+ 拒签(no)
|
// ConfirmationType:签收(yes)+ 拒签(no)
|
||||||
io.papermc.paper.registry.data.dialog.type.ConfirmationType type =
|
// ★ 125 续8:两个按钮都挂 DialogAction.customClick 回调(旧代码第4参传 null → 按钮点击只关弹窗不执行任何 Java 代码,
|
||||||
io.papermc.paper.registry.data.dialog.type.DialogType.confirmation(
|
// 这是「点拒签/签收都只是关屏幕、action 没执行」的根因)。回调里 audience=点按钮的玩家,
|
||||||
|
// 响应数据(DialogResponseView)含 DialogInput 的 key-value(signature 等),可判断 yes/no。
|
||||||
|
io.papermc.paper.registry.data.dialog.ActionButton acceptBtn =
|
||||||
io.papermc.paper.registry.data.dialog.ActionButton.create(
|
io.papermc.paper.registry.data.dialog.ActionButton.create(
|
||||||
Component.text("§a§l✔ 签收"),
|
Component.text("§a§l✔ 签收"),
|
||||||
Component.text("确认签收用户协议"),
|
Component.text("确认签收用户协议"),
|
||||||
200,
|
200,
|
||||||
null
|
io.papermc.paper.registry.data.dialog.action.DialogAction.customClick(
|
||||||
),
|
(response, audience) -> {
|
||||||
|
// audience = 点按钮的玩家(Audience 类型,实际是 Player)
|
||||||
|
if (!(audience instanceof Player player)) return;
|
||||||
|
PendingSign cur = pendingSigs.get(player.getUniqueId());
|
||||||
|
if (cur == null) return;
|
||||||
|
// 签名从 DialogInput key="signature" 取
|
||||||
|
String signature = response.getText("signature");
|
||||||
|
if (signature == null || signature.isEmpty()) {
|
||||||
|
player.sendMessage(Component.text("§c请先填写签名(您的游戏ID)再点签收"));
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
if (!signature.equalsIgnoreCase(player.getName())) {
|
||||||
|
player.sendMessage(Component.text("§c签名与您的游戏ID不匹配,请重新填写"));
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
handleAccept(player, cur, signature.trim());
|
||||||
|
},
|
||||||
|
ClickCallback.Options.builder().build()
|
||||||
|
)
|
||||||
|
);
|
||||||
|
|
||||||
|
io.papermc.paper.registry.data.dialog.ActionButton denyBtn =
|
||||||
io.papermc.paper.registry.data.dialog.ActionButton.create(
|
io.papermc.paper.registry.data.dialog.ActionButton.create(
|
||||||
Component.text("§c§l✘ 拒签"),
|
Component.text("§c§l✘ 拒签"),
|
||||||
Component.text("执行 " + ps.actions.denyAction + " 动作"),
|
Component.text("执行 " + ps.actions.denyAction + " 动作"),
|
||||||
200,
|
200,
|
||||||
null
|
io.papermc.paper.registry.data.dialog.action.DialogAction.customClick(
|
||||||
|
(response, audience) -> {
|
||||||
|
if (!(audience instanceof Player player)) return;
|
||||||
|
PendingSign cur = pendingSigs.get(player.getUniqueId());
|
||||||
|
if (cur == null) return;
|
||||||
|
String signature = response.getText("signature");
|
||||||
|
confirmDeny(player, new File(cur.pendingFile).getName(),
|
||||||
|
signature != null ? signature.trim() : "");
|
||||||
|
},
|
||||||
|
ClickCallback.Options.builder().build()
|
||||||
)
|
)
|
||||||
);
|
);
|
||||||
|
|
||||||
|
io.papermc.paper.registry.data.dialog.type.ConfirmationType type =
|
||||||
|
io.papermc.paper.registry.data.dialog.type.DialogType.confirmation(acceptBtn, denyBtn);
|
||||||
|
|
||||||
io.papermc.paper.dialog.Dialog dialog = io.papermc.paper.dialog.Dialog.create(
|
io.papermc.paper.dialog.Dialog dialog = io.papermc.paper.dialog.Dialog.create(
|
||||||
builder -> builder.empty()
|
builder -> builder.empty()
|
||||||
.base(base)
|
.base(base)
|
||||||
@@ -659,17 +695,46 @@ public class CustomScreenManager implements Listener {
|
|||||||
/**
|
/**
|
||||||
* 执行拒签动作。
|
* 执行拒签动作。
|
||||||
*/
|
*/
|
||||||
|
/**
|
||||||
|
* 拒签动作归一化:trim + 别名映射(支持中文别名与常见英文变体)。
|
||||||
|
* del/rm/delete/remove/delaccount/删号/删号 → del
|
||||||
|
* kick/踢出/踢掉/踢 → kick
|
||||||
|
* ban/banip 保持原样(精确匹配)
|
||||||
|
* 未知值 → 原样返回(由 executeDenyAction 的 default 分支兜底为 kick)
|
||||||
|
*/
|
||||||
|
private static String normalizeAction(String raw) {
|
||||||
|
if (raw == null) return "";
|
||||||
|
String a = raw.trim().toLowerCase();
|
||||||
|
switch (a) {
|
||||||
|
case "rm":
|
||||||
|
case "delete":
|
||||||
|
case "remove":
|
||||||
|
case "delaccount":
|
||||||
|
case "删号":
|
||||||
|
case "删除":
|
||||||
|
return "del";
|
||||||
|
case "踢出":
|
||||||
|
case "踢掉":
|
||||||
|
case "踢":
|
||||||
|
return "kick";
|
||||||
|
default:
|
||||||
|
return a; // del/kick/ban/banip 及其它未知值原样
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
private void executeDenyAction(Player p, ActionConfig actions) {
|
private void executeDenyAction(Player p, ActionConfig actions) {
|
||||||
String action = actions.denyAction;
|
String action = normalizeAction(actions.denyAction);
|
||||||
plugin.getLogger().info("[自定义屏幕] 玩家 " + p.getName() + " 拒签,执行动作: " + action);
|
plugin.getLogger().info("[自定义屏幕] 玩家 " + p.getName() + " 拒签,执行动作: " + action);
|
||||||
Main main = (Main) plugin;
|
Main main = (Main) plugin;
|
||||||
switch (action.toLowerCase()) {
|
switch (action) {
|
||||||
case "del", "rm":
|
case "del":
|
||||||
// 删号:先删 DB 记录再踢出
|
// 删号:先删 DB 记录再踢出
|
||||||
try {
|
try {
|
||||||
if (main.getDb() != null) {
|
if (main.getDb() != null) {
|
||||||
main.getDb().deleteUser(p.getName());
|
main.getDb().deleteUser(p.getName());
|
||||||
plugin.getLogger().info("[自定义屏幕] " + p.getName() + " 账号已删除(del/rm)");
|
plugin.getLogger().info("[自定义屏幕] " + p.getName() + " 账号已删除(del/rm)");
|
||||||
|
} else {
|
||||||
|
plugin.getLogger().warning("[自定义屏幕] " + p.getName() + " 拒签 del 动作但 DB 未初始化,跳过删号仅踢出");
|
||||||
}
|
}
|
||||||
} catch (Exception ex) {
|
} catch (Exception ex) {
|
||||||
plugin.getLogger().warning("[自定义屏幕] 删号失败: " + ex.getMessage());
|
plugin.getLogger().warning("[自定义屏幕] 删号失败: " + ex.getMessage());
|
||||||
@@ -700,7 +765,10 @@ public class CustomScreenManager implements Listener {
|
|||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
default:
|
default:
|
||||||
plugin.getLogger().warning("[自定义屏幕] 未知拒签动作: " + action + ",跳过执行");
|
// ★ 125 续7:未知动作不再静默跳过(旧行为是"跳过执行",玩家看起来像"只关屏幕没后果"),
|
||||||
|
// 保底执行 kick(最小副作用),同时大声 warning 提示管理员检查 action.json 配置。
|
||||||
|
plugin.getLogger().warning("[自定义屏幕] 未知拒签动作「" + action + "」(原始值「" + actions.denyAction + "」),已保底执行 kick。合法值:del/rm/delete/删号、kick/踢出、ban、banip");
|
||||||
|
p.kick(Component.text("您已拒签用户协议,已被踢出服务器(拒签动作未识别,已执行保底踢出)。如有疑问请联系管理员。"));
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -760,10 +828,11 @@ public class CustomScreenManager implements Listener {
|
|||||||
if (obj.has("deny")) {
|
if (obj.has("deny")) {
|
||||||
com.google.gson.JsonElement el = obj.get("deny");
|
com.google.gson.JsonElement el = obj.get("deny");
|
||||||
if (el.isJsonPrimitive()) {
|
if (el.isJsonPrimitive()) {
|
||||||
config.denyAction = el.getAsString();
|
// ★ 125 续7:解析即归一化(trim+别名),保证 GUI 文案与 executeDenyAction 判定一致
|
||||||
|
config.denyAction = normalizeAction(el.getAsString());
|
||||||
} else if (el.isJsonObject()) {
|
} else if (el.isJsonObject()) {
|
||||||
com.google.gson.JsonObject dobj = el.getAsJsonObject();
|
com.google.gson.JsonObject dobj = el.getAsJsonObject();
|
||||||
if (dobj.has("action")) config.denyAction = dobj.get("action").getAsString();
|
if (dobj.has("action")) config.denyAction = normalizeAction(dobj.get("action").getAsString());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
} catch (Exception ignored) {}
|
} catch (Exception ignored) {}
|
||||||
|
|||||||
Reference in New Issue
Block a user