PvP 切换插件
一款轻量级、高性能的 Minecraft 服务器 PvP 管理插件,支持 Paper、Purpur 或 Spigot(1.20.4+)服务器,采用可选加入机制。
📖 概述
在原版 Minecraft 中,如果服务器全局启用了 PvP,任何玩家都可以攻击其他玩家。本插件引入了一个可选加入(opt-in)的 PvP 系统:玩家可以自行选择是参与战斗还是保持和平。
所有反馈消息均通过操作栏(Action Bar)(玩家快捷栏上方)发送,而非聊天窗口,从而在激烈的游戏过程中保持聊天窗口的整洁,避免刷屏。
✨ 主要功能
- 双向同意 PvP:攻击者和防御者都必须显式开启 PvP 才能互相战斗。
- 投射物伤害保护:自动拦截远程投射物(如箭矢、三叉戟等)的伤害,防止绕过 PvP 规则。
- 非侵入式操作栏通知:即时反馈,无需 cluttering 玩家聊天。
- 管理员/ moderator 权限绕过:拥有特定权限 (
pvp.pvpall) 的工作人员可以无视切换状态直接攻击玩家。
- 多世界支持:可配置为全服生效的保护,或限制仅在特定世界中生效(例如:生存世界受保护,小游戏/无政府世界不受限)。
- 可配置的默认状态:可选择新加入或重新连接的玩家默认处于 PvP 开启还是关闭状态。
- 轻量且高性能:内存占用极小;使用内存中的
UUID 集合以及高效的 Paper 事件钩子(HIGH 优先级,ignoreCancelled = true)。
⚔️ 工作原理(详细机制)
1. 双向同意规则
要在两名玩家之间造成伤害,双方都必须将他们的 PvP 模式设置为开启:
- 攻击者 (ON) vs 防御者 (ON):允许造成伤害。战斗正常进行。
- 攻击者 (ON) vs 防御者 (OFF):伤害被阻止。攻击者会看到操作栏警告 (
messages.denied)。
- 攻击者 (OFF) vs 防御者 (ON):伤害被阻止。当攻击者自己的 PvP 关闭时,无法造成伤害 (
messages.denied)。
- 攻击者 (OFF) vs 防御者 (OFF):伤害被阻止 (
messages.denied)。
2. 投射物保护
当启用 protect-projectiles (true) 时,插件会拦截来自远程武器(如弓/弩箭矢、三叉戟、雪球等)的伤害。它会验证发射者实体:
- 如果发射者是玩家,则应用相同的双向 PvP 同意检查。
- 如果任何一方禁用了 PvP,则命中被取消,不造成任何伤害或击退效果。
3. 工作人员权限绕过 (pvp.pvpall)
任何持有 pvp.pvpall 权限的玩家(默认授予服务器操作员)都将绕过所有限制:
- 他们可以随时随地攻击任何玩家,即使他们或目标禁用了 PvP。
- 这非常适合用于 moderator、管理员或自定义赏金猎人角色。
4. 世界过滤
您可以通过 config.yml 中的 protected-worlds 仅对指定世界强制执行 PvP 保护:
- 如果
protected-worlds: [](空列表):保护在所有世界中生效。
- 如果
protected-worlds: ["world", "world_nether"]:保护仅在 world 和 world_nether 中严格强制执行。在任何未列出的世界(例如 pvp_arena)中,适用标准的原版 PvP 规则,不受限制。
5. 会话状态
- 玩家的 PvP 状态按
UUID 保存在内存中。
- 玩家加入服务器时,其初始状态根据
config.yml 中的 default-pvp 进行初始化。
- 玩家退出时,其条目会被清理,以防止内存泄漏。
🎮 命令
| 命令 |
权限 |
描述 |
/pvp |
pvp.toggle |
切换您个人的 PvP 状态(已启用 ↔ 已禁用)。 |
注意:此命令仅限玩家使用。尝试从服务器控制台运行 /pvp 不会执行任何操作。
🔐 权限
| 权限 |
默认值 |
描述 |
pvp.toggle |
true (所有玩家) |
授予使用 /pvp 命令切换战斗模式的权限。 |
pvp.pvpall |
op (管理员) |
允许无视对方的 PvP 切换模式攻击任何玩家。 |
⚙️ 配置 (config.yml)
配置文件会在首次运行时自动生成于 plugins/Pvp/config.yml:
# 是否在某个世界中启用 PvP 保护。
# 空列表 ([]) 表示保护适用于服务器上的所有世界。
# 示例:protected-worlds: ["world", "world_nether"]
protected-worlds: []
# 玩家加入服务器时的初始 PvP 模式。
# 设置为 false,以便玩家默认以 PvP 禁用状态加入。
default-pvp: false
# 是否保护由投射物(箭矢、三叉戟、雪球等)发起的攻击。
protect-projectiles: true
# 发送给玩家的消息(显示在操作栏中,支持 '&' 颜色代码)。
messages:
enabled: '&aPvP 已启用。你现在可以与其他玩家战斗了。'
disabled: '&ePvP 已禁用。'
denied: '&c对方玩家已禁用 PvP。'
no-permission: '&c你没有权限使用此命令。'
选项说明:
protected-worlds:YAML 字符串列表。指定应启用保护的世界名称。留空 [] 以保护所有地方。
default-pvp:设置为 false(推荐用于和平/SMP 服务器),以便玩家安全加入。如果您希望玩家默认选择退出战斗,请设置为 true。
protect-projectiles:设置为 true 以阻止非同意玩家之间的箭矢和三叉戟攻击。如果您只想规范直接近战打击,请设置为 false。
messages:支持标准 Minecraft & 颜色格式的可定制文本字符串(例如,&a = 绿色,&e = 黄色,&c = 红色)。
PvP Toggle Plugin
A lightweight, high-performance opt-in PvP management plugin for Minecraft servers running Paper, Purpur, or Spigot (1.20.4+).
📖 Overview
By default in vanilla Minecraft, any player can attack another player if server-wide PvP is enabled. This plugin introduces an opt-in PvP system: players choose for themselves whether they want to engage in combat or remain peaceful.
All feedback messages are delivered via the Action Bar (above the player's hotbar) rather than the chat window, keeping chat clean and unspammed during intense gameplay.
✨ Key Features
- Mutual Consent PvP: Both the attacker and the defender must explicitly enable PvP to fight each other.
- Projectile Damage Protection: Automatically resolves shooters of ranged projectiles (arrows, tridents, etc.) to prevent circumvention of the PvP rule.
- Non-Intrusive Action Bar Notifications: Instant feedback without cluttering player chat.
- Admin / Moderator Bypass: Specific permission (
pvp.pvpall) allows authorized staff to strike players regardless of toggle status.
- Multi-World Support: Configure protection server-wide or limit it to specific worlds (e.g., survival world protected, minigame/anarchy worlds unrestricted).
- Configurable Default State: Choose whether new or joining players start with PvP turned ON or OFF.
- Lightweight & High Performance: Minimal memory footprint; uses in-memory
UUID sets and efficient Paper event hooks (HIGH priority, ignoreCancelled = true).
⚔️ How It Works (Detailed Mechanics)
1. The Two-Way Consent Rule
For damage between two players to be registered, both players must have their PvP mode toggled on:
- Attacker (ON) vs Defender (ON): Damage is allowed. Combat proceeds normally.
- Attacker (ON) vs Defender (OFF): Damage is blocked. The attacker sees an Action Bar warning (
messages.denied).
- Attacker (OFF) vs Defender (ON): Damage is blocked. The attacker cannot deal damage while having their own PvP turned off (
messages.denied).
- Attacker (OFF) vs Defender (OFF): Damage is blocked (
messages.denied).
2. Projectile Protection
When protect-projectiles is enabled (true), the plugin intercepts damage from ranged weapons (such as bow/crossbow arrows, tridents, snowballs, etc.). It verifies the shooter entity:
- If the shooter is a player, the same two-way PvP consent check is applied.
- If either party has PvP disabled, the hit is cancelled and no damage or knockback is applied.
3. Staff Bypass (pvp.pvpall)
Any player holding the permission pvp.pvpall (granted to server operators by default) bypasses all restrictions:
- They can damage any player at any time, even if they or the target have PvP disabled.
- This is ideal for moderators, admins, or custom bounty hunter roles.
4. World Filtering
You can selectively enforce PvP protection only in designated worlds via protected-worlds in config.yml:
- If
protected-worlds: [] (empty list): Protection is active across all worlds.
- If
protected-worlds: ["world", "world_nether"]: Protection is strictly enforced in world and world_nether. In any unlisted world (e.g., pvp_arena), standard vanilla PvP rules apply unrestricted.
5. Session State
- Player PvP states are kept in memory by
UUID.
- On joining the server, the player's initial state is initialized according to
default-pvp in config.yml.
- On quitting, their entry is cleaned up to prevent memory leaks.
🎮 Commands
| Command |
Permission |
Description |
/pvp |
pvp.toggle |
Toggles your personal PvP status (Enabled ↔ Disabled). |
Note: The command is player-only. Attempting to run /pvp from the server console safely does nothing.
🔐 Permissions
| Permission |
Default |
Description |
pvp.toggle |
true (all players) |
Grants permission to use the /pvp command to switch combat modes. |
pvp.pvpall |
op (administrators) |
Allows attacking any player regardless of their PvP toggle mode. |
⚙️ Configuration (config.yml)
The configuration file is automatically generated at plugins/Pvp/config.yml on first run:
# Whether PvP protection is enabled in a world.
# An empty list ([]) means protection applies to all worlds on the server.
# Example: protected-worlds: ["world", "world_nether"]
protected-worlds: []
# Initial PvP mode for players when they join the server.
# Set to false so players join with PvP disabled by default.
default-pvp: false
# Whether to protect against attacks made with projectiles (arrows, tridents, snowballs, etc.).
protect-projectiles: true
# Messages sent to players (displayed in the Action Bar, supports '&' color codes).
messages:
enabled: '&aPvP enabled. You can now fight other players.'
disabled: '&ePvP disabled.'
denied: '&cThe other player has PvP disabled.'
no-permission: '&cYou do not have permission to use this command.'
Options Explanation:
protected-worlds: A YAML string list. Specify the names of the worlds where protection should run. Leave empty [] to protect everywhere.
default-pvp: Set to false (recommended for peaceful/SMP servers) so players join safe. Set to true if you prefer players opting out of combat.
protect-projectiles: Set to true to stop arrow and trident attacks between non-consenting players. Set to false if you only want to regulate direct melee strikes.
messages: Customizable text strings supporting standard Minecraft & color formatting (e.g., &a = green, &e = yellow, &c = red).
评论 0
登录后参与评分
还没有评论,来抢沙发吧