根因:forceLeaveArena(player, true) 断线分支里,回收PVP装备与还原背包 都被 isDisconnect 跳过 → PVP装备留在身上被带出主城(触发残骸裹身成就), 且原背包从未还原(空白背包,必须靠定时备份找回)。私人房更糟:备份 skipDb 只存内存,状态清理时内存备份被删,DB 里也没有。 修复: 1. forceLeaveArena 断线时也当场回收装备+还原背包(PlayerQuitEvent 里 player 仍在线,setContents 立即生效并随玩家数据持久化); isDisconnect 仅影响日志口径与观赛模式还原。 2. 回收PVPEquipment 新增 returnToInventory 重载:回收的 PVP 装备先尝试 放回背包空槽,放不下的才销毁并打日志列清单(防静默吞物)。 3. restoreInventory 未找到备份时 loud 告警(空白背包根源定位信号)。 调用点复核:forceLeaveArena 全部 4 处调用(正常退出/死亡复活/断线/私人房解散) 统一走同一出口;/pvp leave 与 /pvp leave see 均经 teleport 触发 PlayerChangedWorldEvent → forceLeaveArena,无旁路。
This commit is contained in:
@@ -1793,7 +1793,9 @@ public class PVPArenaManager implements Listener {
|
|||||||
* 强制离开竞技场 — 所有退场的唯一入口
|
* 强制离开竞技场 — 所有退场的唯一入口
|
||||||
*
|
*
|
||||||
* @param player 玩家对象(可能在线也可能离线——离线时只清理状态+存DB标记)
|
* @param player 玩家对象(可能在线也可能离线——离线时只清理状态+存DB标记)
|
||||||
* @param isDisconnect 是否为掉线场景(不掉线时直接还原;掉线时仅存DB等待下次登录还原)
|
* @param isDisconnect 是否为掉线场景。★续17起:断线也当场回收装备+还原背包
|
||||||
|
* (PlayerQuitEvent 里 player 仍在线,setContents 立即生效并
|
||||||
|
* 随玩家数据持久化);isDisconnect 仅影响日志口径与观赛模式还原。
|
||||||
*/
|
*/
|
||||||
public void forceLeaveArena(Player player, boolean isDisconnect) {
|
public void forceLeaveArena(Player player, boolean isDisconnect) {
|
||||||
String playerName = player.getName();
|
String playerName = player.getName();
|
||||||
@@ -1839,19 +1841,20 @@ public class PVPArenaManager implements Listener {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// 回收PVP装备
|
// ★ 第123批续17(2026-11-17 用户要求):回收PVP装备 + 还原背包,不再跳过断线。
|
||||||
if (!isDisconnect && player.isOnline()) {
|
// 旧逻辑断线时两处都被 isDisconnect 跳过 → PVP装备留在身上被带出主城(触发
|
||||||
回收PVPEquipment(player);
|
// 残骸裹身成就),且原背包从未还原(空白背包,必须靠定时备份找回)。
|
||||||
}
|
// 实测断线瞬间 PlayerQuitEvent 里 player 仍在线,setContents 立即生效并随
|
||||||
|
// 玩家数据一起持久化;onPlayerJoin 的 DB 还原路径保留作兜底(防极端时序)。
|
||||||
// 还原背包(在线且非断开连接时立即还原)
|
if (player.isOnline()) {
|
||||||
if (!isDisconnect && player.isOnline()) {
|
// 先回收PVP专属装备(回收物返还背包空槽,防吞物),再还原原背包
|
||||||
|
回收PVPEquipment(player, true);
|
||||||
restoreInventory(player);
|
restoreInventory(player);
|
||||||
player.sendMessage("§e§l你已离开PVP竞技场,背包已恢复");
|
player.sendMessage("§e§l你已离开PVP竞技场,背包已恢复");
|
||||||
player.playSound(player.getLocation(), Sound.ENTITY_EXPERIENCE_ORB_PICKUP, 1.0f, 1.0f);
|
player.playSound(player.getLocation(), Sound.ENTITY_EXPERIENCE_ORB_PICKUP, 1.0f, 1.0f);
|
||||||
} else if (isDisconnect) {
|
} else {
|
||||||
// 断线时确保备份已在DB中(下次onPlayerJoin时还原)
|
// 真离线(对象已不可用):确保备份已在DB中(下次onPlayerJoin时还原)
|
||||||
plugin.getLogger().info("[PVP] 玩家 " + playerName + " 在PVP中断线,备份已存DB待还原");
|
plugin.getLogger().warning("[PVP] 玩家 " + playerName + " 断线时对象已离线,依赖DB备份下次登录还原");
|
||||||
}
|
}
|
||||||
|
|
||||||
// ★ 还原观赛前的游戏模式(避免把观察者模式一路带到主世界)
|
// ★ 还原观赛前的游戏模式(避免把观察者模式一路带到主世界)
|
||||||
@@ -1870,6 +1873,7 @@ public class PVPArenaManager implements Listener {
|
|||||||
passwordInvulnerable.remove(playerName);
|
passwordInvulnerable.remove(playerName);
|
||||||
passwordWrongCount.remove(playerName);
|
passwordWrongCount.remove(playerName);
|
||||||
equipmentConfirmed.remove(playerName);
|
equipmentConfirmed.remove(playerName);
|
||||||
|
// ★ 续17:inventoryBackups 在上方 restoreInventory 里已 remove;此处仅防泄漏兜底
|
||||||
inventoryBackups.remove(playerName);
|
inventoryBackups.remove(playerName);
|
||||||
guiReopening.remove(playerName);
|
guiReopening.remove(playerName);
|
||||||
guiOpenedMillis.remove(playerName);
|
guiOpenedMillis.remove(playerName);
|
||||||
@@ -2696,9 +2700,15 @@ public class PVPArenaManager implements Listener {
|
|||||||
// ★ 无论备份来自缓存还是数据库,还原后必须清理数据库备份,
|
// ★ 无论备份来自缓存还是数据库,还原后必须清理数据库备份,
|
||||||
// 否则断线重连时 onPlayerJoin 会再次覆盖玩家当前背包(序列化生效后的隐藏坑)
|
// 否则断线重连时 onPlayerJoin 会再次覆盖玩家当前背包(序列化生效后的隐藏坑)
|
||||||
db.deletePvpInventoryBackup(playerName);
|
db.deletePvpInventoryBackup(playerName);
|
||||||
plugin.getLogger().info("[PVP] 已还原玩家 " + playerName + " 的背包");
|
plugin.getLogger().info("[PVP] 已还原玩家 " + playerName + " 的背包"
|
||||||
|
+ "(主手=" + (backup.contents != null && backup.contents.length > 0
|
||||||
|
? backup.contents[0] : null)
|
||||||
|
+ " 盔甲=" + (backup.armor != null ? backup.armor.length : 0) + "格)");
|
||||||
} else {
|
} else {
|
||||||
plugin.getLogger().warning("[PVP] 未找到玩家 " + playerName + " 的背包备份");
|
// ★ 续17:未找到备份是重大事故信号(空白背包根源),必须 loud 告警 + 线程栈,
|
||||||
|
// 便于从日志直接定位是哪条链路把备份弄丢的。
|
||||||
|
plugin.getLogger().warning("[PVP] 未找到玩家 " + playerName + " 的背包备份"
|
||||||
|
+ "(续17:还原失败,玩家背包将保持现状)");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -2717,9 +2727,22 @@ public class PVPArenaManager implements Listener {
|
|||||||
* 回收PVP装备
|
* 回收PVP装备
|
||||||
*/
|
*/
|
||||||
private void 回收PVPEquipment(Player player) {
|
private void 回收PVPEquipment(Player player) {
|
||||||
|
回收PVPEquipment(player, false);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* ★ 第123批续17:回收PVP装备时把回收物返还玩家背包(放进行列)。
|
||||||
|
* 旧实现直接置 null 销毁 —— 断线当场回收 + 还原背包后,回收的 PVP 装备
|
||||||
|
* 凭空消失,等于玩家进竞技场前背包里的物品被吞(用户反馈"给了个空白背包"
|
||||||
|
* 的另一半原因)。现在:回收的 PVP 装备先尝试放回背包空槽,放不下的才销毁,
|
||||||
|
* 并打日志列出销毁清单(防静默吞物)。
|
||||||
|
*/
|
||||||
|
private void 回收PVPEquipment(Player player, boolean returnToInventory) {
|
||||||
|
java.util.List<ItemStack> reclaimed = new ArrayList<>();
|
||||||
ItemStack[] contents = player.getInventory().getContents();
|
ItemStack[] contents = player.getInventory().getContents();
|
||||||
for (int i = 0; i < contents.length; i++) {
|
for (int i = 0; i < contents.length; i++) {
|
||||||
if (contents[i] != null && isPVPEquipment(contents[i])) {
|
if (contents[i] != null && isPVPEquipment(contents[i])) {
|
||||||
|
reclaimed.add(contents[i].clone());
|
||||||
contents[i] = null;
|
contents[i] = null;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -2728,6 +2751,7 @@ public class PVPArenaManager implements Listener {
|
|||||||
ItemStack[] armor = player.getInventory().getArmorContents();
|
ItemStack[] armor = player.getInventory().getArmorContents();
|
||||||
for (int i = 0; i < armor.length; i++) {
|
for (int i = 0; i < armor.length; i++) {
|
||||||
if (armor[i] != null && isPVPEquipment(armor[i])) {
|
if (armor[i] != null && isPVPEquipment(armor[i])) {
|
||||||
|
reclaimed.add(armor[i].clone());
|
||||||
armor[i] = null;
|
armor[i] = null;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -2735,8 +2759,29 @@ public class PVPArenaManager implements Listener {
|
|||||||
|
|
||||||
ItemStack offHand = player.getInventory().getItemInOffHand();
|
ItemStack offHand = player.getInventory().getItemInOffHand();
|
||||||
if (offHand != null && isPVPEquipment(offHand)) {
|
if (offHand != null && isPVPEquipment(offHand)) {
|
||||||
|
reclaimed.add(offHand.clone());
|
||||||
player.getInventory().setItemInOffHand(null);
|
player.getInventory().setItemInOffHand(null);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (returnToInventory && !reclaimed.isEmpty()) {
|
||||||
|
java.util.List<ItemStack> overflow = new ArrayList<>();
|
||||||
|
for (ItemStack it : reclaimed) {
|
||||||
|
java.util.HashMap<Integer, ItemStack> left =
|
||||||
|
player.getInventory().addItem(it);
|
||||||
|
if (left != null && !left.isEmpty()) {
|
||||||
|
overflow.addAll(left.values());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if (!overflow.isEmpty()) {
|
||||||
|
plugin.getLogger().warning("[PVP] 回收PVP装备时背包已满,以下装备无法返还将销毁: "
|
||||||
|
+ overflow.stream().map(i -> i.getType().name() + "x" + i.getAmount())
|
||||||
|
.collect(java.util.stream.Collectors.joining(", "))
|
||||||
|
+ " 玩家=" + player.getName());
|
||||||
|
} else {
|
||||||
|
plugin.getLogger().info("[PVP] 回收的 " + reclaimed.size()
|
||||||
|
+ " 件PVP装备已返还玩家背包 玩家=" + player.getName());
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|||||||
Reference in New Issue
Block a user