修复领地禁止点燃:新增PlayerInteractEvent拦截打火石/火球/火焰弹,ProjectileHitEvent拦截烈焰球落地,彻底关闭TNT/篝火点燃

This commit is contained in:
2026-07-02 21:58:19 +08:00
parent 6f004f257f
commit c9a3d24e64
@@ -9559,6 +9559,57 @@ public class AreaProtection implements Listener {
}
}
// ===== 玩家使用打火石/点燃物品时直接拦截 =====
@EventHandler
public void onPlayerInteractFire(PlayerInteractEvent e) {
Player p = e.getPlayer();
Action action = e.getAction();
Material mat = e.getItem() == null ? null : e.getItem().getType();
// 只拦截 RIGHT_CLICK_BLOCK/AIR 使用打火石/火床/TNT
if (action != Action.RIGHT_CLICK_BLOCK && action != Action.RIGHT_CLICK_AIR) return;
if (mat != Material.FLINT_AND_STEEL && mat != Material.FIRE_CHARGE && mat != Material.CAMPFIRE && mat != Material.SOUL_CAMPFIRE) {
// 如果是打火石或火球,检查使用的物品
if (mat != Material.TNT) return;
}
// 检查目标方块或玩家所处领地
Block clickedBlock = e.getClickedBlock();
AreaConfig ac1 = null;
AreaConfig ac2 = null;
// 玩家位置
ac1 = getArea(p.getWorld().getName(),
p.getLocation().getBlockX(), p.getLocation().getBlockY(), p.getLocation().getBlockZ());
// 点击的方块
if (clickedBlock != null) {
ac2 = getArea(clickedBlock.getWorld().getName(),
clickedBlock.getX(), clickedBlock.getY(), clickedBlock.getZ());
}
if ((ac1 != null && ac1.denyFire) || (ac2 != null && ac2.denyFire)) {
e.setCancelled(true);
p.sendMessage("§c§l[区域防护] §f此区域禁止点燃物品");
}
}
// ===== 火焰弹/烈焰球拦截 =====
@EventHandler
public void onProjectileHitFireball(ProjectileHitEvent e) {
if (!(e.getEntity() instanceof org.bukkit.entity.Fireball)) return;
org.bukkit.entity.Fireball fb = (org.bukkit.entity.Fireball) e.getEntity();
AreaConfig ac = getArea(fb.getWorld().getName(),
fb.getLocation().getBlockX(), fb.getLocation().getBlockY(), fb.getLocation().getBlockZ());
if (ac != null && ac.denyFire) {
fb.remove();
// 如果射手是玩家,发消息
if (fb.getShooter() instanceof Player) {
((Player) fb.getShooter()).sendMessage("§c§l[区域防护] §f此区域禁止投掷火焰");
}
}
}
// ===== TNT自爆防漏网:EntityExplodeEvent =====
@EventHandler
public void onEntityExplode(EntityExplodeEvent e) {