UseCooldown 组件实测无效(OFF 拦右键 → 原版永不触发冷却,盾牌 0 冷却)。 改为直接没收:enforceShieldConfiscationScan 每秒扫 PVP 世界所有玩家背包+主手+ 副手+盔甲,发现盾牌立刻 setItem(null) 没收,玩家拿到的盾下一秒就被清。 删除 applyShieldUseCooldown/applyShieldCooldownToAll/onPVPShieldOffhandClear/ SHIELD_OFF_COOLDOWN_SECONDS。FREE/ON 交还原版,不误伤。 Co-Authored-By: WorkBuddy <noreply@workbuddy.cn>
This commit is contained in:
co-authored by
WorkBuddy
parent
0ce943a99f
commit
770ca9e816
@@ -32,7 +32,6 @@ import org.bukkit.event.block.BlockPlaceEvent;
|
||||
import org.bukkit.event.entity.ProjectileHitEvent;
|
||||
import org.bukkit.event.entity.ProjectileLaunchEvent;
|
||||
import org.bukkit.event.player.PlayerInteractEvent;
|
||||
import org.bukkit.event.player.PlayerItemHeldEvent;
|
||||
|
||||
import java.io.ByteArrayInputStream;
|
||||
import java.io.ByteArrayOutputStream;
|
||||
@@ -227,11 +226,8 @@ public class PVPArenaManager implements Listener {
|
||||
private static final int FOOD_MAX = 64;
|
||||
private static final int FOOD_DEFAULT = 16;
|
||||
|
||||
// ★ 第121批:盾牌模式=OFF 时给 PVP 盾牌设置的超长冷却(秒)。
|
||||
// 效果等同被斧头破盾后的冷却:玩家一旦拿出/使用即进入该冷却,不可再格挡。
|
||||
// 第121批续:300s(5分钟)太短——追逐战模式 5 分钟就过去,玩家又能用盾。
|
||||
// 改为 24 小时(86400s),一局内等同永久禁盾,最保险。
|
||||
private static final float SHIELD_OFF_COOLDOWN_SECONDS = 86400.0f;
|
||||
// ★ 第121批续7:OFF 模式全员禁盾——持续没收(enforceShieldConfiscationScan 每秒扫一次)。
|
||||
// UseCooldown 组件实测无效(OFF 拦右键 → 原版永不触发冷却),改为直接没收盾牌。
|
||||
|
||||
private static final Material[] SWORD_TIERS = {
|
||||
Material.IRON_SWORD, Material.GOLDEN_SWORD, Material.DIAMOND_SWORD, Material.NETHERITE_SWORD };
|
||||
@@ -294,13 +290,11 @@ public class PVPArenaManager implements Listener {
|
||||
// 观赛者以任何形式都无法攻击玩家或被玩家攻击。
|
||||
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);
|
||||
// ★ 第121批续7:OFF 模式全员禁盾持续没收(每秒 20 tick)。
|
||||
// UseCooldown 组件实测无效(OFF 拦右键 → 原版永不触发冷却),改为直接没收:
|
||||
// 扫背包+主手+副手+盔甲,发现盾牌立刻清空,玩家拿到的盾下一秒就被收走。
|
||||
// 仅 OFF 模式生效;FREE/ON 交还原版,不误伤。范围仅 PVP 世界。
|
||||
Bukkit.getScheduler().runTaskTimer(plugin, this::enforceShieldConfiscationScan, 20L, 20L);
|
||||
|
||||
// ★ 插件语义"和平模式":剔除 PVP 世界玩家周边的敌对生物(每 2 秒),
|
||||
// 代替原生 Difficulty.PEACEFUL(原生和平会强制回血+不消耗饱食度,杀敌困难)。
|
||||
@@ -1592,16 +1586,6 @@ public class PVPArenaManager implements Listener {
|
||||
player.playSound(player.getLocation(), Sound.ENTITY_PLAYER_LEVELUP, 1.0f, 1.0f);
|
||||
|
||||
plugin.getLogger().info("[PVP] 玩家 " + playerName + " 进入PVP竞技场(已备份清空原背包,等待选装备)");
|
||||
|
||||
// ★ 第121批续5:自定义模式强制关(盾模式=OFF)时,清空背包后仍兜底扫一次——
|
||||
// 覆盖玩家从创造物品栏/别地图带盾进来的场景(清背包前的盾已不在,
|
||||
// 但若 clearInventory 未覆盖盔甲栏/副手残余,这里兜底写超冷)。
|
||||
PVPCustomModeManager.CustomConfig eCfg = customCfg.get(playerName);
|
||||
PVPCustomModeManager.ShieldMode eMode =
|
||||
(eCfg != null) ? eCfg.shieldMode : PVPCustomModeManager.ShieldMode.OFF;
|
||||
if (eMode == PVPCustomModeManager.ShieldMode.OFF) {
|
||||
applyShieldCooldownToAll(player, SHIELD_OFF_COOLDOWN_SECONDS);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -1794,17 +1778,8 @@ public class PVPArenaManager implements Listener {
|
||||
boolean toIsPVP = isPVPWorld(player.getWorld());
|
||||
boolean fromIsPVP = isPVPWorld(Bukkit.getWorld(from));
|
||||
if (toIsPVP && !fromIsPVP) {
|
||||
// ★ 第121批续5:自定义模式强制关(盾模式=OFF)时,进世界即给该玩家所有盾牌
|
||||
// 写 24h 超长冷却——覆盖创造模式直接拿盾(/give、创造物品栏、别地图带进来)。
|
||||
// 仅对 PVP 世界生效(isPVPWorld 判定),非 OFF 模式直接跳过,不误伤其他世界。
|
||||
PVPCustomModeManager.CustomConfig wCfg = customCfg.get(player.getName());
|
||||
PVPCustomModeManager.ShieldMode wMode =
|
||||
(wCfg != null) ? wCfg.shieldMode : PVPCustomModeManager.ShieldMode.OFF;
|
||||
if (wMode == PVPCustomModeManager.ShieldMode.OFF) {
|
||||
applyShieldCooldownToAll(player, SHIELD_OFF_COOLDOWN_SECONDS);
|
||||
plugin.getLogger().info("[PVP] 玩家 " + player.getName()
|
||||
+ " 进入PVP世界:盾牌模式=OFF,已给全部盾牌写 24h 超冷(含创造模式拿盾)");
|
||||
}
|
||||
// ★ 第121批续7:OFF 模式下持续没收由 enforceShieldConfiscationScan 每秒扫一次,
|
||||
// 进世界时无需额外处理(清背包逻辑在 onPlayerEnterPVPWorld 里)。
|
||||
// 进入PVP世界 → 打开装备选择GUI(此时玩家仍持有原背包)
|
||||
onPlayerEnterPVPWorld(player);
|
||||
} else if (fromIsPVP && !toIsPVP) {
|
||||
@@ -1933,30 +1908,6 @@ 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)
|
||||
public void onBridgeEggUse(PlayerInteractEvent event) {
|
||||
if (event.getAction() != Action.RIGHT_CLICK_AIR && event.getAction() != Action.RIGHT_CLICK_BLOCK) return;
|
||||
@@ -3558,55 +3509,13 @@ public class PVPArenaManager implements Listener {
|
||||
}
|
||||
|
||||
/**
|
||||
* 第121批:给 PVP 盾牌写入超长使用冷却(UseCooldown 组件)。
|
||||
* 盾牌模式=OFF 全员禁盾时使用——玩家(含管理员从面板帮忙拿出的)一旦试图使用,
|
||||
* 即进入超长冷却,效果等同被斧头破盾后的不可用状态。
|
||||
* 第121批续7:OFF 模式全员禁盾——持续扫描没收盾牌(每秒 20 tick,由 loadConfig 定时任务驱动)。
|
||||
* UseCooldown 组件实测无效(OFF 时拦了右键,原版永不触发冷却),改为直接没收:
|
||||
* 扫背包+主手+副手+盔甲,发现盾牌立刻 setItem(null) 没收,玩家拿到的盾下一秒就被清。
|
||||
* 仅盾模式=OFF 时生效;FREE/ON 直接返回,交还原版冷却逻辑,不误伤。
|
||||
* 范围:仅 PVP 世界在线玩家(isPVPWorld 判定),离开 PVP 世界后背包还原自动失效。
|
||||
*/
|
||||
private void applyShieldUseCooldown(ItemStack shield, float seconds) {
|
||||
if (shield == null || shield.getType() != Material.SHIELD) return;
|
||||
io.papermc.paper.datacomponent.item.UseCooldown cooldown =
|
||||
io.papermc.paper.datacomponent.item.UseCooldown.useCooldown(seconds).build();
|
||||
shield.setData(io.papermc.paper.datacomponent.DataComponentTypes.USE_COOLDOWN, cooldown);
|
||||
}
|
||||
|
||||
/**
|
||||
* 第121批续5:自定义模式强制关(盾模式=OFF)时,给该玩家【背包+副手+盔甲】里
|
||||
* 的任何一个盾牌写 24h 超长冷却。覆盖创造模式直接拿盾(/give、创造物品栏、从别的地图带进来等),
|
||||
* 仅对当前 PVP 世界生效(调用点已用 isPVPWorld 判定),离开 PVP 世界后背包还原自动失效,
|
||||
* 不误伤其他世界。
|
||||
*/
|
||||
private void applyShieldCooldownToAll(Player player, float seconds) {
|
||||
if (player == null) return;
|
||||
for (int i = 0; i < player.getInventory().getSize(); i++) {
|
||||
ItemStack it = player.getInventory().getItem(i);
|
||||
if (it != null && it.getType() == Material.SHIELD) {
|
||||
applyShieldUseCooldown(it, seconds);
|
||||
}
|
||||
}
|
||||
ItemStack off = player.getInventory().getItemInOffHand();
|
||||
if (off != null && off.getType() == Material.SHIELD) {
|
||||
applyShieldUseCooldown(off, seconds);
|
||||
}
|
||||
ItemStack[] arm = player.getInventory().getArmorContents();
|
||||
if (arm != null) {
|
||||
for (ItemStack a : arm) {
|
||||
if (a != null && a.getType() == Material.SHIELD) {
|
||||
applyShieldUseCooldown(a, seconds);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 第121批续6:OFF 模式全员禁盾持续扫描(每秒 20 tick,由 loadConfig 定时任务驱动)。
|
||||
* 仅盾模式=OFF 时生效;FREE/ON 直接返回,交还原版冷却逻辑。
|
||||
* 范围:仅 PVP 世界在线玩家(isPVPWorld 判定),不误伤其他世界。
|
||||
* 动作:给该玩家背包+副手+盔甲里所有盾牌写 24h 超冷 + 清空副手(OFF 时副手不该有盾)。
|
||||
* 持续扫描保证创造 /give、创造物品栏、别地图带盾进来等任何来源的盾都带冷却,
|
||||
* 玩家一旦试图使用即进 24h 冷却不可用(效果等同被斧头破盾冷却)。
|
||||
*/
|
||||
private void enforceShieldCooldownScan() {
|
||||
// 取本局盾模式(房主键)
|
||||
private void enforceShieldConfiscationScan() {
|
||||
PVPCustomModeManager.CustomConfig ownerCfg =
|
||||
(customModeOwner != null) ? customCfg.get(customModeOwner) : null;
|
||||
PVPCustomModeManager.ShieldMode mode =
|
||||
@@ -3617,12 +3526,34 @@ public class PVPArenaManager implements Listener {
|
||||
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 时副手清空(不该有盾在副手)
|
||||
int cleared = 0;
|
||||
// 背包(0-35)
|
||||
for (int i = 0; i < p.getInventory().getSize(); i++) {
|
||||
ItemStack it = p.getInventory().getItem(i);
|
||||
if (it != null && it.getType() == Material.SHIELD) {
|
||||
p.getInventory().setItem(i, null);
|
||||
cleared++;
|
||||
}
|
||||
}
|
||||
// 副手
|
||||
ItemStack off = p.getInventory().getItemInOffHand();
|
||||
if (off != null && off.getType() == Material.SHIELD) {
|
||||
p.getInventory().setItemInOffHand(null);
|
||||
p.sendMessage("§c§l[PVP] §f本局禁用盾牌,已自动收起副手盾牌");
|
||||
cleared++;
|
||||
}
|
||||
// 盔甲栏(盾牌不会出现在盔甲,但防御性扫)
|
||||
ItemStack[] arm = p.getInventory().getArmorContents();
|
||||
if (arm != null) {
|
||||
for (int i = 0; i < arm.length; i++) {
|
||||
if (arm[i] != null && arm[i].getType() == Material.SHIELD) {
|
||||
arm[i] = null;
|
||||
p.getInventory().setArmorContents(arm);
|
||||
cleared++;
|
||||
}
|
||||
}
|
||||
}
|
||||
if (cleared > 0) {
|
||||
p.sendMessage("§c§l[PVP] §f本局禁用盾牌,已没收 " + cleared + " 个盾牌");
|
||||
p.playSound(p.getLocation(), Sound.ENTITY_VILLAGER_NO, 0.8f, 1.0f);
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user