第121批续6:OFF模式持续扫描+副手盾即时清空
Auto Release / build (push) Successful in 2m41s

- 新增 enforceShieldCooldownScan 定时任务(每秒 20 tick,loadConfig 注册):
  OFF 模式下扫 PVP 世界所有在线玩家,给背包+副手+盔甲所有盾牌写 24h 超冷,
  并清空副手盾。持续扫描保证创造 /give、创造物品栏、别地图带盾进来等
  任何来源的盾都带冷却,一旦试图使用即进 24h 冷却不可用。
- 新增 onPVPShieldOffhandClear(PlayerItemHeldEvent):OFF + PVP 世界
  副手持盾即时清空(补充持续扫描,创造拖盾到副手/捡盾进副手瞬间收起)。
- FREE/ON 模式直接跳过扫描与清空,交还原版冷却逻辑,不误伤。

Co-Authored-By: WorkBuddy <noreply@workbuddy.cn>
This commit is contained in:
youpaishidifu
2026-11-12 19:56:15 +08:00
co-authored by WorkBuddy
parent 643a515597
commit 0ce943a99f
+65 -1
View File
@@ -32,6 +32,7 @@ import org.bukkit.event.block.BlockPlaceEvent;
import org.bukkit.event.entity.ProjectileHitEvent; import org.bukkit.event.entity.ProjectileHitEvent;
import org.bukkit.event.entity.ProjectileLaunchEvent; import org.bukkit.event.entity.ProjectileLaunchEvent;
import org.bukkit.event.player.PlayerInteractEvent; import org.bukkit.event.player.PlayerInteractEvent;
import org.bukkit.event.player.PlayerItemHeldEvent;
import java.io.ByteArrayInputStream; import java.io.ByteArrayInputStream;
import java.io.ByteArrayOutputStream; import java.io.ByteArrayOutputStream;
@@ -287,12 +288,20 @@ public class PVPArenaManager implements Listener {
// 加载配置 // 加载配置
loadConfig(); loadConfig();
// ★ 观赛身份强制巡视(每2秒):已登记为观赛者且仍在PVP世界的玩家, // ★ 观赛身份强制巡视(每2秒):已登记为观战者且仍在PVP世界的玩家,
// 若模式被外部改成生存/冒险等 → 立即强制恢复观察者并打印诊断日志。 // 若模式被外部改成生存/冒险等 → 立即强制恢复观察者并打印诊断日志。
// 战斗拦截另有"登记身份"双保险(见 isProtectedSpectator),二者共同保证 // 战斗拦截另有"登记身份"双保险(见 isProtectedSpectator),二者共同保证
// 观赛者以任何形式都无法攻击玩家或被玩家攻击。 // 观赛者以任何形式都无法攻击玩家或被玩家攻击。
Bukkit.getScheduler().runTaskTimer(plugin, this::enforceSpectatorModes, 40L, 40L); Bukkit.getScheduler().runTaskTimer(plugin, this::enforceSpectatorModes, 40L, 40L);
// ★ 第121批续6:OFF 模式全员禁盾持续扫描(每秒 20 tick)。
// 背景:仅靠进世界时写一次超冷不够——创造模式 /give、创造物品栏、
// 玩家从别地图带盾进来,都可能绕过一次性写入。持续扫描保证任何时刻
// 玩家手里的盾都带 24h 超冷(UseCooldown 组件),效果等同被斧头破盾冷却。
// 仅 OFF 模式生效;FREE/ON 交还原版冷却逻辑,插件不接管。
// 范围:仅 PVP 世界(isPVPWorld 判定),不误伤其他世界。
Bukkit.getScheduler().runTaskTimer(plugin, this::enforceShieldCooldownScan, 20L, 20L);
// ★ 插件语义"和平模式":剔除 PVP 世界玩家周边的敌对生物(每 2 秒), // ★ 插件语义"和平模式":剔除 PVP 世界玩家周边的敌对生物(每 2 秒),
// 代替原生 Difficulty.PEACEFUL(原生和平会强制回血+不消耗饱食度,杀敌困难)。 // 代替原生 Difficulty.PEACEFUL(原生和平会强制回血+不消耗饱食度,杀敌困难)。
startPeacefulMobCleanupTask(); startPeacefulMobCleanupTask();
@@ -1924,6 +1933,30 @@ public class PVPArenaManager implements Listener {
} }
} }
/**
* 第121批续6:OFF 模式下副手持盾即时清空(每 tick 轻量检查)。
* 持续扫描 enforceShieldCooldownScan 每秒清一次,本闸作为补充——
* 创造模式把盾拖到副手 / 捡盾进副手的瞬间即被清空,玩家拿不到能用的盾。
* 仅 PVP 世界 + OFF 模式生效;FREE/ON 交还原版,不误伤。
*/
@EventHandler
public void onPVPShieldOffhandClear(PlayerItemHeldEvent event) {
Player p = event.getPlayer();
if (!inPVPArena.contains(p.getName())) return;
if (!isPVPWorld(p.getWorld())) return;
PVPCustomModeManager.CustomConfig ownerCfg =
(customModeOwner != null) ? customCfg.get(customModeOwner) : null;
PVPCustomModeManager.ShieldMode mode =
(ownerCfg != null) ? ownerCfg.shieldMode : PVPCustomModeManager.ShieldMode.OFF;
if (mode != PVPCustomModeManager.ShieldMode.OFF) return;
ItemStack off = p.getInventory().getItemInOffHand();
if (off != null && off.getType() == Material.SHIELD) {
p.getInventory().setItemInOffHand(null);
p.sendMessage("§c§l[PVP] §f本局禁用盾牌,副手盾已自动收起");
p.playSound(p.getLocation(), Sound.ENTITY_VILLAGER_NO, 0.8f, 1.0f);
}
}
@EventHandler(priority = EventPriority.HIGH) @EventHandler(priority = EventPriority.HIGH)
public void onBridgeEggUse(PlayerInteractEvent event) { public void onBridgeEggUse(PlayerInteractEvent event) {
if (event.getAction() != Action.RIGHT_CLICK_AIR && event.getAction() != Action.RIGHT_CLICK_BLOCK) return; if (event.getAction() != Action.RIGHT_CLICK_AIR && event.getAction() != Action.RIGHT_CLICK_BLOCK) return;
@@ -3564,6 +3597,37 @@ public class PVPArenaManager implements Listener {
} }
} }
/**
* 第121批续6:OFF 模式全员禁盾持续扫描(每秒 20 tick,由 loadConfig 定时任务驱动)。
* 仅盾模式=OFF 时生效;FREE/ON 直接返回,交还原版冷却逻辑。
* 范围:仅 PVP 世界在线玩家(isPVPWorld 判定),不误伤其他世界。
* 动作:给该玩家背包+副手+盔甲里所有盾牌写 24h 超冷 + 清空副手(OFF 时副手不该有盾)。
* 持续扫描保证创造 /give、创造物品栏、别地图带盾进来等任何来源的盾都带冷却,
* 玩家一旦试图使用即进 24h 冷却不可用(效果等同被斧头破盾冷却)。
*/
private void enforceShieldCooldownScan() {
// 取本局盾模式(房主键)
PVPCustomModeManager.CustomConfig ownerCfg =
(customModeOwner != null) ? customCfg.get(customModeOwner) : null;
PVPCustomModeManager.ShieldMode mode =
(ownerCfg != null) ? ownerCfg.shieldMode : PVPCustomModeManager.ShieldMode.OFF;
if (mode != PVPCustomModeManager.ShieldMode.OFF) return; // FREE/ON 交还原版
World pvpW = Bukkit.getWorld(pvpWorldName);
if (pvpW == null || pvpW.getPlayers().isEmpty()) return;
for (Player p : pvpW.getPlayers()) {
if (!p.isOnline() || !isPVPWorld(p.getWorld())) continue;
applyShieldCooldownToAll(p, SHIELD_OFF_COOLDOWN_SECONDS);
// OFF 时副手清空(不该有盾在副手)
ItemStack off = p.getInventory().getItemInOffHand();
if (off != null && off.getType() == Material.SHIELD) {
p.getInventory().setItemInOffHand(null);
p.sendMessage("§c§l[PVP] §f本局禁用盾牌,已自动收起副手盾牌");
p.playSound(p.getLocation(), Sound.ENTITY_VILLAGER_NO, 0.8f, 1.0f);
}
}
}
// ==================== 命令入口 ==================== // ==================== 命令入口 ====================
/** /**