From f345f60ac0aad7d638379386c33bf2dbf2372992 Mon Sep 17 00:00:00 2001 From: youpaishidifu Date: Fri, 10 Jul 2026 13:17:00 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BF=AE=E5=A4=8DPVP=E6=B5=8B=E8=AF=95?= =?UTF-8?q?=E5=9C=BA=E5=BC=BA=E5=88=B6=E9=80=89=E8=A3=85=EF=BC=9A=E8=BF=9B?= =?UTF-8?q?=E5=85=A5=E6=B5=8B=E8=AF=95=E4=B8=96=E7=95=8C=E5=BF=85=E9=A1=BB?= =?UTF-8?q?=E9=80=89=E8=A3=85=E5=A4=87=EF=BC=8C=E5=85=B3=E9=97=AD2?= =?UTF-8?q?=E6=AC=A1GUI=E9=81=A3=E8=BF=94=E4=B8=BB=E4=B8=96=E7=95=8C?= =?UTF-8?q?=EF=BC=9B/back=E7=A6=81=E6=AD=A2=E4=BC=A0=E9=80=81=E8=87=B3?= =?UTF-8?q?=E6=B5=8B=E8=AF=95=E4=B8=96=E7=95=8C?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/main/java/Sdf1_login/Main.java | 4 +- src/main/java/Sdf1_login/PVPTestManager.java | 117 +++++++++++++++---- src/main/java/Sdf1_login/QuickBack.java | 9 +- 3 files changed, 102 insertions(+), 28 deletions(-) diff --git a/src/main/java/Sdf1_login/Main.java b/src/main/java/Sdf1_login/Main.java index 260bcf8..2570907 100644 --- a/src/main/java/Sdf1_login/Main.java +++ b/src/main/java/Sdf1_login/Main.java @@ -5172,9 +5172,9 @@ public class Main extends JavaPlugin } Player p = (Player) sender; - // PVP练习测试场:/pvp test 打开设置面板 + // PVP练习测试场:/pvp test 打开设置面板(强制选装追踪) if (args.length > 0 && args[0].equalsIgnoreCase("test")) { - pvpTestManager.openGUI(p); + pvpTestManager.openGUIWithTracking(p); return true; } diff --git a/src/main/java/Sdf1_login/PVPTestManager.java b/src/main/java/Sdf1_login/PVPTestManager.java index 3f7765d..61f3cf6 100644 --- a/src/main/java/Sdf1_login/PVPTestManager.java +++ b/src/main/java/Sdf1_login/PVPTestManager.java @@ -14,6 +14,7 @@ import org.bukkit.event.player.PlayerChangedWorldEvent; import org.bukkit.event.player.PlayerJoinEvent; import org.bukkit.event.player.PlayerQuitEvent; import org.bukkit.event.player.PlayerRespawnEvent; +import org.bukkit.event.inventory.InventoryCloseEvent; import org.bukkit.inventory.Inventory; import org.bukkit.inventory.ItemStack; import org.bukkit.inventory.meta.ItemMeta; @@ -82,6 +83,10 @@ public class PVPTestManager implements Listener { /** 每个玩家生成的练习生物 UUID 列表(离开时按玩家清理) */ private final Map> playerMobs = new HashMap<>(); /** 玩家原背包备份(仅内存,练习场为临时场景) */ + /** ★ 强制选装追踪:等待选装确认的玩家集合 */ + private final Set pendingEquipSelect = new HashSet<>(); + /** ★ GUI关闭次数追踪:玩家关闭选装GUI的次数(≥2次遣返出生点) */ + private final Map guiCloseCount = new HashMap<>(); private final Map inventoryBackups = new HashMap<>(); private final Random rand = new Random(); @@ -244,6 +249,15 @@ public class PVPTestManager implements Listener { // ==================== GUI ==================== + /** ★ 强制选装追踪版打开GUI:/pvp test 调用,关闭2次遣返 */ + public void openGUIWithTracking(Player p) { + UUID uid = p.getUniqueId(); + pendingEquipSelect.add(uid); + guiCloseCount.put(uid, 0); + p.sendMessage("§e§l[PVP测试] 请选择装备!关闭GUI 2次将被遣返主世界。"); + openGUI(p); + } + public void openGUI(Player p) { Inventory gui = Bukkit.createInventory(null, 54, TEST_GUI_TITLE); @@ -524,6 +538,9 @@ public class PVPTestManager implements Listener { } // ★ 确认开始(49) if (slot == 49) { + // 清除强制选装追踪 + pendingEquipSelect.remove(id); + guiCloseCount.remove(id); p.closeInventory(); startTest(p, chosenDiff.getOrDefault(p.getUniqueId(), TestDifficulty.EASY), @@ -731,13 +748,17 @@ public class PVPTestManager implements Listener { * 供可点击超链接 /pvp back 调用。 */ public void handleBack(Player p) { - if (inTest.contains(p.getUniqueId())) { + UUID uid = p.getUniqueId(); + // 清除强制选装追踪 + pendingEquipSelect.remove(uid); + guiCloseCount.remove(uid); + if (inTest.contains(uid)) { removePlayerMobs(p); restoreInventory(p); - inTest.remove(p.getUniqueId()); - chosenDiff.remove(p.getUniqueId()); - chosenEquip.remove(p.getUniqueId()); - pendingRespawn.remove(p.getUniqueId()); + inTest.remove(uid); + chosenDiff.remove(uid); + chosenEquip.remove(uid); + pendingRespawn.remove(uid); checkAllLeft(); } Location bed = p.getBedSpawnLocation(); @@ -1018,12 +1039,16 @@ public class PVPTestManager implements Listener { @EventHandler public void onRespawn(PlayerRespawnEvent e) { Player p = e.getPlayer(); - if (!inTest.contains(p.getUniqueId())) return; + UUID uid = p.getUniqueId(); + // 清除强制选装追踪 + pendingEquipSelect.remove(uid); + guiCloseCount.remove(uid); + if (!inTest.contains(uid)) return; removePlayerMobs(p); - inTest.remove(p.getUniqueId()); - chosenDiff.remove(p.getUniqueId()); - chosenEquip.remove(p.getUniqueId()); - pendingRespawn.remove(p.getUniqueId()); + inTest.remove(uid); + chosenDiff.remove(uid); + chosenEquip.remove(uid); + pendingRespawn.remove(uid); World main = Bukkit.getWorlds().get(0); e.setRespawnLocation(main.getSpawnLocation()); // 复活瞬间立即还原原背包,杜绝利用快速重进保留/携带测试场装备 @@ -1035,12 +1060,16 @@ public class PVPTestManager implements Listener { @EventHandler public void onQuit(PlayerQuitEvent e) { Player p = e.getPlayer(); - if (!inTest.contains(p.getUniqueId())) return; + UUID uid = p.getUniqueId(); + // 清除强制选装追踪 + pendingEquipSelect.remove(uid); + guiCloseCount.remove(uid); + if (!inTest.contains(uid)) return; removePlayerMobs(p); restoreInventory(p); - inTest.remove(p.getUniqueId()); - chosenDiff.remove(p.getUniqueId()); - chosenEquip.remove(p.getUniqueId()); + inTest.remove(uid); + chosenDiff.remove(uid); + chosenEquip.remove(uid); pendingRespawn.remove(p.getUniqueId()); checkAllLeft(); } @@ -1049,19 +1078,23 @@ public class PVPTestManager implements Listener { @EventHandler public void onPlayerJoin(PlayerJoinEvent e) { Player p = e.getPlayer(); + UUID uid = p.getUniqueId(); + // 清除强制选装追踪 + pendingEquipSelect.remove(uid); + guiCloseCount.remove(uid); // 情况1:测试场世界里有记录或身上有测试场装备残留 boolean inTestWorld = isTestWorld(p.getWorld()); - boolean hasBackup = inventoryBackups.containsKey(p.getUniqueId()); - if (!inTestWorld && !hasBackup && !inTest.contains(p.getUniqueId())) return; + boolean hasBackup = inventoryBackups.containsKey(uid); + if (!inTestWorld && !hasBackup && !inTest.contains(uid)) return; if (hasBackup) { restoreInventory(p); } removePlayerMobs(p); - inTest.remove(p.getUniqueId()); - chosenDiff.remove(p.getUniqueId()); - chosenEquip.remove(p.getUniqueId()); - pendingRespawn.remove(p.getUniqueId()); + inTest.remove(uid); + chosenDiff.remove(uid); + chosenEquip.remove(uid); + pendingRespawn.remove(uid); if (inTestWorld) { World main = Bukkit.getWorlds().get(0); @@ -1075,14 +1108,48 @@ public class PVPTestManager implements Listener { @EventHandler public void onChangedWorld(PlayerChangedWorldEvent e) { Player p = e.getPlayer(); - if (!inTest.contains(p.getUniqueId())) return; + UUID uid = p.getUniqueId(); + if (!inTest.contains(uid)) { + // ★ 未正式入测试但进入测试世界(如/back传送)→ 强制选装 + if (isTestWorld(p.getWorld()) && !pendingEquipSelect.contains(uid)) { + pendingEquipSelect.add(uid); + guiCloseCount.put(uid, 0); + p.sendMessage("§e§l[PVP测试] 你已进入测试世界,请先选择装备!关闭GUI 2次将被遣返主世界。"); + Bukkit.getScheduler().runTaskLater(plugin, () -> openGUI(p), 5L); + } + return; + } if (isTestWorld(p.getWorld())) return; // 仍在测试场 + // 清除强制选装追踪(离开测试世界) + pendingEquipSelect.remove(uid); + guiCloseCount.remove(uid); removePlayerMobs(p); restoreInventory(p); - inTest.remove(p.getUniqueId()); - chosenDiff.remove(p.getUniqueId()); - chosenEquip.remove(p.getUniqueId()); - pendingRespawn.remove(p.getUniqueId()); + inTest.remove(uid); + chosenDiff.remove(uid); + chosenEquip.remove(uid); + pendingRespawn.remove(uid); checkAllLeft(); } + + /** ★ 选装GUI关闭追踪:关闭2次遣返主世界 */ + @EventHandler + public void onInventoryClose(org.bukkit.event.inventory.InventoryCloseEvent e) { + if (!(e.getPlayer() instanceof Player p)) return; + if (!p.getOpenInventory().getTitle().equals(TEST_GUI_TITLE)) return; + UUID uid = p.getUniqueId(); + if (!pendingEquipSelect.contains(uid)) return; + int count = guiCloseCount.getOrDefault(uid, 0) + 1; + guiCloseCount.put(uid, count); + if (count >= 2) { + // 遣返主世界 + pendingEquipSelect.remove(uid); + guiCloseCount.remove(uid); + World main = Bukkit.getWorlds().get(0); + p.teleport(main.getSpawnLocation()); + p.sendMessage("§c§l[PVP测试] 你多次关闭选装界面,已被遣返主世界。"); + } else { + p.sendMessage("§e§l[PVP测试] 还需选择装备!再关闭 " + (2 - count) + " 次将被遣返。"); + } + } } diff --git a/src/main/java/Sdf1_login/QuickBack.java b/src/main/java/Sdf1_login/QuickBack.java index 37db093..c379cac 100644 --- a/src/main/java/Sdf1_login/QuickBack.java +++ b/src/main/java/Sdf1_login/QuickBack.java @@ -102,7 +102,14 @@ public class QuickBack implements Listener, CommandExecutor, TabCompleter { player.sendMessage("§c位置世界信息无效"); return true; } - + + // ★ 禁止/back传送至PVP测试世界 + String worldName = loc.getWorld().getName(); + if (worldName != null && worldName.startsWith("pvp_test_")) { + player.sendMessage("§c§l[快速返回] §c无法返回PVP测试世界,请使用 /pvp test 进入测试场选装"); + return true; + } + Location dest = loc.clone().add(0.5, 0, 0.5); // 对齐格子中心 player.teleport(dest);