第122批:PVP 私人陪练 password 模式 + 命令简拼/前缀兼容(pvp.md 第一二板块)
Auto Release / build (push) Successful in 2m49s

- 简拼归一化:c/d/ps/j/le/m/rm/v/t/s/f/pub/pre/* 全称与简写都有效(修 custom简写c无效)
- 命令行兼容模式:--version/-v/version 双杠/单杠/无杠前缀都支持
- /pvp join password [pwd] (model):开房生成3位数字房码,model 可选 default/custom
- /pvp join [code] [pwd]:凭房码+密码加入私人陪练房间
- 落地输密码:非命令入口进入 password 房先输密码(ChatInputManager.PVP_PASSWORD 聊天框监听),
  错5次弹回出生点,输密码期间无敌(onEntityDamage 豁免),输对放行进标准选装流程
- /pvp join custom [public|private]:命令行穿房间类型(第一板块 model/type 自穿)
- 供应商.json:新增 coarena 供应商
This commit is contained in:
youpaishidifu
2026-11-15 11:38:41 +08:00
parent 4f37357c9f
commit 21f9158dbc
4 changed files with 283 additions and 3 deletions
@@ -40,6 +40,8 @@ public class ChatInputManager {
TICKET_ADMIN_PROVIDER,
BACK_CHECK_ECONOMY_CONFIRM,
USER_MGMT_SEARCH,
// ★ 第122批:PVP 私人陪练 password 房间落地输密码(由 PVPArenaManager.handlePasswordInput 消费)
PVP_PASSWORD,
}
public static class PlayerState {
@@ -938,6 +940,15 @@ public class ChatInputManager {
return;
}
case PVP_PASSWORD: {
// ★ 第122批:PVP 私人陪练 password 房间落地输密码(聊天框监听)。
// 校验/计次/弹回出生点全在 PVPArenaManager.handlePasswordInput;
// 无论对错本流程都结束(输对→放行进标准选装流程,输错满5次→弹回出生点),这里 reset。
mainPlugin.getPVPArenaManager().handlePasswordInput(p, msg);
reset(p);
return;
}
default:
reset(p);
return;
@@ -1558,6 +1558,30 @@ public class PVPArenaManager implements Listener {
return; // 已经在流程中,防止重复触发
}
// ★ 第122批:私人陪练 password 房间——非 `/pvp join [code] [password]` 入口落地的玩家,
// 先输密码(聊天框监听)再走后续选装流程;输密码期间无敌(见 onEntityDamage),
// 错5次弹回出生点。命令入口(passwordVerified)已校验过密码,不再拦。
// 提前 return:不登记 inPVPArena、不清背包、不开选装 GUI、不启动 60 秒踢人计时,
// 输对后由 handlePasswordInput 放行重走本流程。
String worldName = player.getWorld().getName();
if (isPrivateRoomWorld(worldName)
&& passwordRoomPwd.containsKey(worldName)
&& !passwordRoomPwd.get(worldName).isEmpty()
&& !passwordVerified.contains(playerName)) {
passwordPending.put(playerName, worldName);
passwordInvulnerable.add(playerName);
passwordWrongCount.put(playerName, 0);
// ★ 同步登记 ChatInputManager 状态:Main.onChat 只拦 isInFlow 的玩家,
// 不登记则密码消息会被当普通聊天发出去(本流程靠聊天框监听输密码)。
plugin.getChatInput().getState(player).type =
ChatInputManager.InputType.PVP_PASSWORD;
player.sendMessage("§6§l[PVP] 这是私人陪练房间,请在聊天框输入密码后开始练习");
player.sendMessage("§7(输密码期间无敌;输错5次将弹回出生点;输入 取消 可离开)");
return;
}
// 已通过命令校验的玩家落地放行,标记用后即清(下次进房若再非命令入口仍会被拦)
passwordVerified.remove(playerName);
// 标记进入PVP世界
inPVPArena.add(playerName);
registerPlayerStats(player);
@@ -1736,6 +1760,9 @@ public class PVPArenaManager implements Listener {
// 清理所有状态(含取消超时定时器)
inPVPArena.remove(playerName);
passwordPending.remove(playerName);
passwordInvulnerable.remove(playerName);
passwordWrongCount.remove(playerName);
equipmentConfirmed.remove(playerName);
inventoryBackups.remove(playerName);
guiReopening.remove(playerName);
@@ -2040,6 +2067,12 @@ public class PVPArenaManager implements Listener {
event.setCancelled(true);
}
// ★ 第122批:输密码期间无敌(落地后先输密码的玩家,输对之前不受任何伤害)
if (passwordInvulnerable.contains(name)) {
event.setCancelled(true);
return;
}
// ★ 第114批:原"最后伤害者留痕"已删除——归因改为读取原版 kill credit(见 onPlayerDeath),
// 无需插件自造时间窗口。
}
@@ -4493,16 +4526,153 @@ public class PVPArenaManager implements Listener {
/** 私人房间超时时间(毫秒):5 分钟 */
private static final long PRIVATE_ROOM_TIMEOUT_MS = 5 * 60 * 1000L;
// ===== 第122批:私人陪练 password 模式(pvp.md 第二板块)=====
/** 房码(3位数字) → 世界名 */
private final Map<String, String> passwordRoomCodes = new ConcurrentHashMap<>();
/** 世界名 → 房主设定的密码(空串=无密码) */
private final Map<String, String> passwordRoomPwd = new ConcurrentHashMap<>();
/** 世界名 → 房主命令里指定的模型(default/custom,未指定=default) */
private final Map<String, String> passwordRoomModel = new ConcurrentHashMap<>();
/** 玩家名 → 落地后待输密码的世界名(非命令入口进入时先输密码) */
private final Map<String, String> passwordPending = new ConcurrentHashMap<>();
/** 玩家名 → 密码错误次数(错5次弹回出生点) */
private final Map<String, Integer> passwordWrongCount = new ConcurrentHashMap<>();
/** 输密码期间无敌的玩家名集合(输密码期间不受伤害) */
private final Set<String> passwordInvulnerable = ConcurrentHashMap.newKeySet();
/** 已通过 `/pvp join [code] [password]` 命令校验的玩家(落地不再二次拦输密码) */
private final Set<String> passwordVerified = ConcurrentHashMap.newKeySet();
/** 密码错误次数上限:错5次弹回出生点 */
private static final int PASSWORD_MAX_WRONG = 5;
/** 是否私人房间世界名 */
public boolean isPrivateRoomWorld(String worldName) {
return worldName != null && worldName.startsWith(PRIVATE_WORLD_PREFIX);
}
/**
* 第122批:房主 `/pvp join password [password] (model)` —— 创建 password 私人陪练房间。
* 复用私人房体系(独立世界 + 5分钟清场 + /tpahere 邀请),额外生成3位数字房码。
* model 不填默认 default;填 custom 走自定义 CLI 菜单(第一板块)。
*/
public void joinPasswordArena(Player owner, String pwd, String model) {
String name = owner.getName();
if (privateRooms.containsKey(name)) {
owner.sendMessage("§c你已创建私人房间,请勿重复创建");
return;
}
String worldName = PRIVATE_WORLD_PREFIX + name;
// 模型参数归一:不填/model=default → default;custom → 走自定义菜单
String m = (model == null || model.trim().isEmpty()
|| model.equalsIgnoreCase("default")
|| model.equalsIgnoreCase("d")) ? "default" : "custom";
// 生成3位数字房码(避免与既有房码冲突)
String code;
do {
code = String.valueOf(100 + new java.util.Random().nextInt(900));
} while (passwordRoomCodes.containsKey(code));
passwordRoomCodes.put(code, worldName);
passwordRoomPwd.put(worldName, pwd == null ? "" : pwd);
passwordRoomModel.put(worldName, m);
passwordVerified.add(name); // ★ 房主开房者落地不被自己密码拦
owner.sendMessage("§a§l[PVP] 私人陪练房间已创建: 房码 §e" + code
+ " §7模型=" + m + " §7(队员用 /pvp join " + code + " <密码> 加入)");
// 复用既有私人房创建链路(独立世界+5分钟清场+tpahere邀请)
joinPrivateArena(owner);
}
/**
* 第122批:队员 `/pvp join [code] [password]` —— 凭3位房码+密码加入私人陪练房间。
*/
public void joinPasswordArenaByCode(Player player, String code, String pwd) {
String worldName = passwordRoomCodes.get(code);
if (worldName == null) {
player.sendMessage("§c房码不存在: " + code);
return;
}
String realPwd = passwordRoomPwd.get(worldName);
if (realPwd == null) realPwd = "";
if (!realPwd.equals(pwd == null ? "" : pwd)) {
player.sendMessage("§c密码错误,无法加入房间 " + code);
return;
}
World w = Bukkit.getWorld(worldName);
if (w == null) {
player.sendMessage("§c房间已解散(世界不存在)");
return;
}
// 直接送入私人房世界(走标准进入流程:选装/清背包由 onPlayerEnterPVPWorld 处理)
passwordVerified.add(player.getName()); // ★ 命令入口已校验密码,落地不二次拦
player.teleport(w.getSpawnLocation());
player.sendMessage("§a§l[PVP] 已加入私人陪练房间 " + code);
plugin.getLogger().info("[PVP私人陪练] " + player.getName()
+ " 凭房码 " + code + " 加入 " + worldName);
}
/** 是否该玩家是某私人房间的房主 */
public boolean isPrivateRoomOwner(String playerName) {
return privateRooms.containsKey(playerName);
}
// ===== 第122批:password 房间落地输密码消费(由 ChatInputManager 聊天框调用)=====
/** 该玩家是否正等待输入私人陪练房间密码 */
public boolean isPasswordPending(Player p) {
return p != null && passwordPending.containsKey(p.getName());
}
/**
* 消费玩家在聊天框输入的内容(第122批:输密码流程)。
* 对 → 清状态并放行进标准选装流程;错 → 计次,错满5次弹回出生点并清状态。
* @return true=已消费(聊天框不外发);false=该玩家不在输密码流程中
*/
public boolean handlePasswordInput(Player p, String msg) {
if (p == null) return false;
String name = p.getName();
String wName = passwordPending.get(name);
if (wName == null) return false;
// 取消:弹回出生点
if (msg.trim().equalsIgnoreCase("取消")
|| msg.trim().equals("0")) {
passwordPending.remove(name);
passwordInvulnerable.remove(name);
passwordWrongCount.remove(name);
p.sendMessage("§c已取消进入私人陪练房间");
p.teleport(getBedOrSpawnLocation(p));
return true;
}
String realPwd = passwordRoomPwd.get(wName);
if (realPwd != null && realPwd.equals(msg.trim())) {
// ★ 输对:清状态,先给短暂无敌缓冲(选装 GUI 由后续 onPlayerEnterPVPWorld 重开),
// 再重走标准进入流程(登记 inPVPArena/清背包/选装 GUI/超时计时)
passwordPending.remove(name);
passwordInvulnerable.remove(name);
passwordWrongCount.remove(name);
p.sendMessage("§a§l[PVP] 密码正确,欢迎加入私人陪练练习");
onPlayerEnterPVPWorld(p);
return true;
}
// 输错:计次,满5次弹回出生点
int wrong = passwordWrongCount.getOrDefault(name, 0) + 1;
passwordWrongCount.put(name, wrong);
if (wrong >= PASSWORD_MAX_WRONG) {
passwordPending.remove(name);
passwordInvulnerable.remove(name);
passwordWrongCount.remove(name);
p.sendMessage("§c§l[PVP] 密码错误已达 " + PASSWORD_MAX_WRONG
+ " 次,已弹回出生点");
p.teleport(getBedOrSpawnLocation(p));
plugin.getLogger().info("[PVP私人陪练] " + name
+ " 输密码错满5次,已弹回出生点(房间 " + wName + ")");
} else {
p.sendMessage("§c密码错误(" + wrong + "/" + PASSWORD_MAX_WRONG
+ "),请重试;输入 取消 可离开");
}
return true;
}
/**
* 创建私人房间并进入(private 分支入口)
*/
@@ -4579,6 +4749,18 @@ public class PVPArenaManager implements Listener {
if (wName == null) return;
privateRoomOwners.remove(wName);
privateRoomCreatedAt.remove(wName);
// ★ 第122批:解散时清掉房码/密码/模型登记 + 所有待输密码状态
passwordRoomPwd.remove(wName);
passwordRoomModel.remove(wName);
String codeToRemove = null;
for (java.util.Map.Entry<String, String> en : passwordRoomCodes.entrySet()) {
if (en.getValue().equals(wName)) { codeToRemove = en.getKey(); break; }
}
if (codeToRemove != null) passwordRoomCodes.remove(codeToRemove);
for (java.util.Iterator<java.util.Map.Entry<String, String>> it =
passwordPending.entrySet().iterator(); it.hasNext(); ) {
if (wName.equals(it.next().getValue())) it.remove();
}
BukkitTask task = privateRoomTasks.remove(wName);
if (task != null && !task.isCancelled()) task.cancel();
World w = Bukkit.getWorld(wName);
+75
View File
@@ -1114,6 +1114,48 @@ public class PVPManager implements Listener {
// ===== 指令 =====
// ===== 第122批:命令简拼/前缀兼容归一化(pvp.md 第二板块 + 命令行兼容模式)=====
/**
* 简拼表(pvp.md「参数简写/中文语义」):全称与简写都有效。
* room/give 无简写;all 简写 *;join→j、leave→le、model→m、remove→rm、
* password→ps、custom→c、default→d、version→v、test→t、start→s、forge→f、
* public→pub、private→pre。
*/
private static final java.util.Map<String, String> PVP_ALIAS =
new java.util.HashMap<String, String>() {{
put("c", "custom");
put("d", "default");
put("ps", "password");
put("j", "join");
put("le", "leave");
put("m", "model");
put("rm", "remove");
put("v", "version");
put("t", "test");
put("*", "all");
put("s", "start");
put("f", "forge");
put("pub", "public");
put("pre", "private");
}};
/**
* 归一化一个命令 token:去掉 --/- 前缀(命令行兼容模式),再做简拼→全称映射。
* 数字(房码)原样返回不归一。
*/
private String normalizeToken(String tok) {
if (tok == null) return null;
String t = tok.toLowerCase();
// ★ 命令行兼容模式:--version / -v / version 都支持(pvp.md 第五板块)
while (t.startsWith("--")) t = t.substring(2);
while (t.startsWith("-")) t = t.substring(1);
if (t.isEmpty()) return t;
if (t.matches("\\d+")) return t; // 房码/数字参数不归一
String full = PVP_ALIAS.get(t);
return full != null ? full : t;
}
public boolean onCommand(Player p,
String[] args) {
if (args.length == 0) {
@@ -1122,6 +1164,10 @@ public class PVPManager implements Listener {
showArenaTotalStats(p, p.getName());
return true;
}
// ★ 第122批:入口归一化——简拼与 --/- 前缀一律转全称后再分发
String[] na = new String[args.length];
for (int i = 0; i < args.length; i++) na[i] = normalizeToken(args[i]);
args = na;
// ★ 数字参数 → 查询指定会话编号的竞技场战绩
if (args.length == 1 && args[0].matches("\\d+")) {
showArenaSessionStats(p, p.getName(), Integer.parseInt(args[0]));
@@ -1169,6 +1215,35 @@ public class PVPManager implements Listener {
plugin.getPVPArenaManager().handleSeeCommand(p, "enter");
return true;
}
// ★ 第122批 /pvp join password [password] (model) → 私人陪练模式
// 生成3位数字房间码,后续玩家 /pvp join [code] [password] 加入(pvp.md 第二板块)
if (args.length >= 2 && args[1].equalsIgnoreCase("password")) {
String pwd = args.length >= 3 ? args[2] : "";
String model = args.length >= 4 ? args[3] : "default";
plugin.getPVPArenaManager()
.joinPasswordArena(p, pwd, model);
return true;
}
// ★ 第122批 /pvp join [code] [password] → 凭3位房码+密码加入私人陪练房间
if (args.length >= 3 && args[1].matches("\\d{3}")
&& !args[2].matches("\\d+")) {
plugin.getPVPArenaManager()
.joinPasswordArenaByCode(p, args[1], args[2]);
return true;
}
// ★ 第122批 /pvp join custom [public|private](简拼 c)→ 自定义模式 CLI 菜单,
// model 与房间类型(公开/私人)可从命令行穿(pvp.md 第一板块:
// 「同时支持public和private参数,/pvp join [model] [type]」)。
// 不穿 type 时默认公开;进菜单后仍可点 [私人] 按钮切换。
if (args.length >= 2 && args[1].equalsIgnoreCase("custom")) {
plugin.getCustomModeManager().openCustomMenu(p);
// 把命令行穿的房间类型写进刚创建的配置(openCustomMenu 会覆盖默认值,故放后面)
if (args.length >= 3 && (args[2].equalsIgnoreCase("private")
|| args[2].equalsIgnoreCase("pre"))) {
plugin.getCustomModeManager().setOption(p, "room", "私人");
}
return true;
}
// ★ /pvp join default|d → 公共竞技场(pvp.md 第一关:默认无参进第一个public房间)
if (args.length >= 2 && (args[1].equalsIgnoreCase("default")
|| args[1].equalsIgnoreCase("d"))) {
+14 -2
View File
@@ -13,7 +13,8 @@
"API.airforce",
"Kilo Gateway",
"魔搭社区",
"Numes"
"Numes",
"coarena"
],
"混合类型": [
"opencode",
@@ -179,7 +180,18 @@
"OpenRouter": "https://openrouter.ai/api/v1",
"numes": {
"url": "https://api.numes.ai/api/v1",
"说明": "需要纯净的科学上网环境,VPN不行"
"说明": [
"1. 需要纯净的科学上网环境,VPN不行",
"2. 注册不需要VPN"
]
},
"coarena": {
"url": "https://coarena.ai/api/v1",
"备注": [
"1. 注册需要Google账户",
"2. 和numes不同,国内可以直连",
"3. 目前免费,5$额度,北京时间早上8:00自动恢复"
]
}
},
"芯片厂商": {