- 根因:reapplyWorldRules 设 Difficulty.PEACEFUL = 原生和平, 强制回血+不消耗饱食度,PVP 杀敌极困难 - 修复:世界难度改回 NORMAL(随服务端),新增 startPeacefulMobCleanupTask 每 2 秒剔除 PVP 世界玩家周边 32 格内敌对生物(复用 AreaProtection HOSTILE_TYPES 同口径),达到插件语义的和平效果 - 用户纠正:和平模式不是 MC 的和平模式,是插件剔除玩家周边敌对生物
This commit is contained in:
@@ -24,6 +24,7 @@ import org.bukkit.util.io.BukkitObjectInputStream;
|
|||||||
import org.bukkit.util.io.BukkitObjectOutputStream;
|
import org.bukkit.util.io.BukkitObjectOutputStream;
|
||||||
|
|
||||||
import org.bukkit.entity.Egg;
|
import org.bukkit.entity.Egg;
|
||||||
|
import org.bukkit.entity.Entity;
|
||||||
import org.bukkit.entity.SmallFireball;
|
import org.bukkit.entity.SmallFireball;
|
||||||
import org.bukkit.event.block.Action;
|
import org.bukkit.event.block.Action;
|
||||||
import org.bukkit.event.entity.ProjectileHitEvent;
|
import org.bukkit.event.entity.ProjectileHitEvent;
|
||||||
@@ -248,6 +249,10 @@ public class PVPArenaManager implements Listener {
|
|||||||
// 战斗拦截另有"登记身份"双保险(见 isProtectedSpectator),二者共同保证
|
// 战斗拦截另有"登记身份"双保险(见 isProtectedSpectator),二者共同保证
|
||||||
// 观赛者以任何形式都无法攻击玩家或被玩家攻击。
|
// 观赛者以任何形式都无法攻击玩家或被玩家攻击。
|
||||||
Bukkit.getScheduler().runTaskTimer(plugin, this::enforceSpectatorModes, 40L, 40L);
|
Bukkit.getScheduler().runTaskTimer(plugin, this::enforceSpectatorModes, 40L, 40L);
|
||||||
|
|
||||||
|
// ★ 插件语义"和平模式":剔除 PVP 世界玩家周边的敌对生物(每 2 秒),
|
||||||
|
// 代替原生 Difficulty.PEACEFUL(原生和平会强制回血+不消耗饱食度,杀敌困难)。
|
||||||
|
startPeacefulMobCleanupTask();
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -560,8 +565,11 @@ public class PVPArenaManager implements Listener {
|
|||||||
|
|
||||||
private void reapplyWorldRules(World w) {
|
private void reapplyWorldRules(World w) {
|
||||||
w.setPVP(true);
|
w.setPVP(true);
|
||||||
// ★ 和平模式:排除敌对生物干扰PVP
|
// ★ 和平模式(2026-11-09 用户纠正):不是 MC 的 Difficulty.PEACEFUL!
|
||||||
w.setDifficulty(Difficulty.PEACEFUL);
|
// 原生和平会强制回血+不消耗饱食度,杀敌极困难。
|
||||||
|
// 插件语义 = 世界保持 NORMAL(难度随服务端),由下方定时任务
|
||||||
|
// clearHostileMobsAroundPlayers 剔除玩家周边的敌对生物,达到和平效果。
|
||||||
|
w.setDifficulty(Difficulty.NORMAL);
|
||||||
w.setGameRule(GameRules.ADVANCE_TIME, false);
|
w.setGameRule(GameRules.ADVANCE_TIME, false);
|
||||||
w.setGameRule(GameRules.ADVANCE_WEATHER, false);
|
w.setGameRule(GameRules.ADVANCE_WEATHER, false);
|
||||||
w.setTime(6000);
|
w.setTime(6000);
|
||||||
@@ -569,6 +577,44 @@ public class PVPArenaManager implements Listener {
|
|||||||
// (vanilla 移除 spawn chunks 概念,调用为纯 no-op),保留注释仅供追溯。
|
// (vanilla 移除 spawn chunks 概念,调用为纯 no-op),保留注释仅供追溯。
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// ★ 插件语义"和平模式":PVP 世界保持 NORMAL 难度(原生和平会强制回血+不消耗饱食度,
|
||||||
|
// 杀敌极困难),由本任务每 2 秒剔除玩家周边 32 格内的敌对生物,达到和平效果。
|
||||||
|
// 复用 AreaProtection 的 HOSTILE_TYPES 判定口径(isHostile 私有,此处独立维护同一份词表)。
|
||||||
|
private static final Set<String> PVP_HOSTILE_TYPES = new HashSet<>(Arrays.asList(
|
||||||
|
"ZOMBIE", "ZOMBIE_VILLAGER", "HUSK", "DROWNED",
|
||||||
|
"SKELETON", "STRAY", "BOGGED", "WITHER_SKELETON",
|
||||||
|
"CREEPER", "SPIDER", "CAVE_SPIDER", "ENDERMITE",
|
||||||
|
"SILVERFISH", "BLAZE", "GHAST", "BIG_GHAST",
|
||||||
|
"MAGMA_CUBE", "SLIME", "WITCH",
|
||||||
|
"GUARDIAN", "ELDER_GUARDIAN",
|
||||||
|
"PILLAGER", "VINDICATOR", "EVOKER", "RAVAGER",
|
||||||
|
"ILLUSIONER", "VEX",
|
||||||
|
"PHANTOM", "SHULKER", "WARDEN", "BREEZE",
|
||||||
|
"PIGLIN", "PIGLIN_BRUTE", "ZOGLIN",
|
||||||
|
"ZOMBIFIED_PIGLIN", "ENDER_DRAGON",
|
||||||
|
"ENDERMAN", "WITHER"
|
||||||
|
));
|
||||||
|
|
||||||
|
private void startPeacefulMobCleanupTask() {
|
||||||
|
Bukkit.getScheduler().runTaskTimer(plugin, () -> {
|
||||||
|
World w = Bukkit.getWorld(pvpWorldName);
|
||||||
|
if (w == null || w.getPlayers().isEmpty()) return;
|
||||||
|
final double RADIUS = 32.0;
|
||||||
|
int removed = 0;
|
||||||
|
for (Player p : w.getPlayers()) {
|
||||||
|
for (Entity ent : w.getNearbyEntities(p.getLocation(), RADIUS, RADIUS, RADIUS)) {
|
||||||
|
if (PVP_HOSTILE_TYPES.contains(ent.getType().name())) {
|
||||||
|
ent.remove();
|
||||||
|
removed++;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if (removed > 0) {
|
||||||
|
plugin.getLogger().info("[PVP和平] 本轮剔除玩家周边敌对生物 " + removed + " 个");
|
||||||
|
}
|
||||||
|
}, 40L, 40L);
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 在FLAT空世界上手动生成随机PVP竞技场地形
|
* 在FLAT空世界上手动生成随机PVP竞技场地形
|
||||||
*
|
*
|
||||||
|
|||||||
Reference in New Issue
Block a user