如何在 Minecraft 中制作右键运行命令的物品(2026)
本文译自英文。阅读原文。
简短回答:原版 Minecraft 在不借助取巧手段的情况下,无法在玩家右键点击物品时运行命令,因此你需要一个插件。使用 ExecutableItems(提供免费版),只需写一个激活器 option: PLAYER_RIGHT_CLICK,把命令列在 playerCommands 下,再用 cooldownFeatures 添加冷却,用 ifHasPermission 添加权限。如果你更喜欢写脚本,Denizen 和 Skript 都是免费的;MMOItems 为 RPG 物品提供了 Commands 属性。
ExecutableItems 是我们开发的,因此本指南用它来做完整示例。下文的替代方案依据各自的官方文档介绍,核查日期为 2026 年 11 月 26 日。
为什么原版无法干净地实现
原版 Java 版没有“使用时运行此命令”这样的物品选项。常见的 datapack 技巧是统计 minecraft.used 这项统计数据:Minecraft Wiki 将在胡萝卜钓竿或诡异菌钓竿上按下使用键记为一次“使用”。在该统计数据上建立一个计分板目标,再配合每刻检查它的函数,就能对点击做出反应。
这样可行,但存在以下问题:
- 只适用于少数在使用时不会放置或消耗任何东西的物品;
- 该函数每刻为每位玩家运行一次;
- 权限、冷却、消息以及“仅在点击方块时”这些功能都需要你自己用命令构建。
对于单张地图或小游戏,datapack 就够用了。对于拥有大量物品的生存或 RPG 服务器,用插件更简单。
选项一览
| 工具 | 编写方式 | 价格 | 冷却 | 权限检查 | 服务器软件 |
|---|---|---|---|---|---|
| ExecutableItems | YAML 或游戏内编辑器(/ei editor) | 免费版;高级版一次性 19.99 EUR | 内置(cooldownFeatures、全局冷却、绕过权限) | 内置(ei.item.<id>、ifHasPermission) | Spigot、Paper、Folia |
| Denizen | 脚本(player right clicks block with:<item>) | 免费,MIT | 需要自己编写脚本 | 需要自己编写脚本 | 根据其 README,Spigot 1.17.1 至 26.3 |
| Skript | 脚本(on rightclick holding ...) | 免费,GPL-3.0 | 需要自己编写脚本 | 需要自己编写脚本 | Modrinth 列出 Paper,最高支持 26.3 |
| MMOItems | 物品配置,commands 属性 | 19.99 EUR(SpigotMC) | 每条命令的 cooldown 和 delay | 此处未涉及 | 需要 MythicLib |
| Datapack | 函数与计分板 | 免费 | 需要自己构建 | 无 | 原版 |
使用 ExecutableItems 分步操作
1. 安装
把 SCore(免费,必需)和 ExecutableItems 放入 plugins/,然后重启服务器。免费版允许创建 500 个物品,每个物品 1 个激活器,PLAYER_RIGHT_CLICK 就是其中包含的激活器之一。
2. 创建物品
手持你想用作基础的物品(或空手),然后运行:
/ei create spawn_scroll
物品文件会创建在 plugins/ExecutableItems/items/ 中。你可以在游戏内编辑器(/ei editor)里完成下面的所有操作,也可以直接编辑 YAML。
3. 添加右键激活器
这个示例是一张把玩家传送到出生点的卷轴,带有 30 秒冷却和权限检查。每个键都来自 ExecutableItems 和 SCore 的文档。
name: '&6Spawn Scroll'
lore:
- '&7Right-click to go back to spawn'
material: PAPER
cancelEventIfNoPermission: true
activators:
activator0:
name: '&eTeleport to spawn'
option: PLAYER_RIGHT_CLICK
typeTarget: NO_TYPE_TARGET
cancelEvent: true
cooldownFeatures:
cooldown: 30
isCooldownInTicks: false
cooldownMsg: '&cWait &e%time_S%s &cbefore using the scroll again.'
displayCooldownMessage: true
playerConditions:
ifHasPermission:
- myserver.scroll.spawn
ifHasPermissionMsg: '&cYou are not allowed to use this scroll.'
playerCommands:
- SEND_MESSAGE text:&aTeleporting to spawn...
- SUDO spawn
- execute at %player% run playsound minecraft:entity.enderman.teleport master %player% ~ ~ ~ 1 1
各部分的作用:
| 键 | 作用 |
|---|---|
option: PLAYER_RIGHT_CLICK | 玩家手持该物品右键点击时触发。 |
typeTarget | NO_TYPE_TARGET 接受在空中和方块上的点击;ONLY_AIR 或 ONLY_BLOCK 会限制范围(使用 ONLY_BLOCK 时还可获得 blockCommands 和方块占位符)。 |
cancelEvent: true | 取消原版点击,因此这张纸不会再做其他事。 |
cooldownFeatures | 每位玩家的冷却,单位为秒(或刻),并附带其消息。%time_H%、%time_M% 和 %time_S% 显示剩余时间。 |
playerConditions / ifHasPermission | 仅对拥有你所设权限的玩家运行激活器,否则显示错误消息。 |
playerCommands | 命令。它们从控制台运行;像 SEND_MESSAGE 这样的 SCore 命令会作用于该玩家,SUDO <command> 则让玩家自己运行一条命令。 |
cancelEventIfNoPermission | 没有 ei.item.spawn_scroll 的玩家完全无法使用该物品。 |
文档中有两个能节省时间的细节:
- 需要位置的原版命令(
playsound、summon、particle、setblock)从控制台运行时位置是 0,0,0。请像示例中那样在前面加上execute at %player% run。 spawn是来自其他插件(例如 EssentialsX)的命令。你可以使用服务器上有的任何命令。
4. 重载并发放
/ei reload
/ei give YourName spawn_scroll 1
拥有 ei.nocd.spawn_scroll(或 ei.nocd.*)的玩家会跳过冷却,因此请在没有 OP 权限的情况下测试。
进一步扩展
- 同一物品上的左键和右键: 把
PLAYER_RIGHT_CLICK和PLAYER_LEFT_CLICK作为两个激活器使用(高级版功能,因为免费版每个物品只有一个激活器),或用PLAYER_ALL_CLICK在一个激活器中同时处理两种点击。 - 有限次数使用:
usageFeatures和usageModification功能可将物品变成消耗品,使用 N 次后消失(usageModification为高级版功能)。 - 对所有人生效的冷却:
globalCooldownFeatures会在一次使用后对所有玩家屏蔽该激活器。 - 自定义材质: 设置
itemModel或customModelData,包括用 ItemsAdder 或 Nexo 制作的模型。
替代方案,坦诚对比
Denizen
Denizen 是一个面向 Spigot 的免费脚本引擎(MIT 许可证)。它的事件 player (right|left) clicks <block> 带有 with:<item> 开关,可以只在手持特定物品时做出反应。它功能非常强大,但所有内容都要以脚本形式编写:冷却、权限检查和消息都是你要自己添加的代码行。其 README 列出支持 Spigot 1.17.1 至 26.3,并指出 SpigotMC 页面更新很慢,因此下载要从它的 CI 服务器获取。
选它的情况: 你或你的团队习惯编写类似代码的脚本,并且希望用一个工具完成远不止物品的许多事情。
Skript
Skript 免费且开源(GPL-3.0)。它的点击事件可以覆盖这种情况,例如 on rightclick holding a fishing rod:,后面接上你想要的效果。Modrinth 列出的加载器是 Paper,最高支持 26.3。取舍与 Denizen 相同:灵活,但每个功能都是一行需要你维护的脚本。
选它的情况: 你的服务器上已经在运行 Skript 脚本。
MMOItems
MMOItems(SpigotMC 上 19.99 EUR,需要 MythicLib)有一个 commands 属性:“物品在被右键点击时执行的命令列表”,每条命令都带有 cooldown 和 delay。对于已经用 MMOItems 管理属性、阶级和套装的 RPG 服务器,这是很自然的选择。参见 ExecutableItems 与 MMOItems 的对比。
Nexo
如果物品主要需要自定义材质和一条命令,Nexo 的 Custom Mechanic 会针对一小部分事件(包括点击)按条件运行动作。Nexo 是付费的(19.99 EUR),且仅支持 Paper 或 Folia 1.21.4+。详情见 ExecutableItems 与 Nexo 的对比。
你应该选哪一个?
- 无需编码,内置冷却和权限,支持 Spigot、Paper 或 Folia: ExecutableItems。
- 你喜欢写脚本,想控制一切: Denizen 或 Skript。
- 已经在使用 MMOItems 的 RPG 服务器: 它的 Commands 属性。
- 以材质为先,只需一个简单的点击动作,Paper 1.21.4+: Nexo,还可以在其之上搭配 ExecutableItems 实现行为。
- 不用插件的一次性地图: 使用
minecraft.used统计数据的 datapack。
相关指南
来源
- ExecutableItems: List of the Activators (PLAYER_RIGHT_CLICK, PLAYER_ALL_CLICK)
- ExecutableItems: Activators features (cooldownFeatures, typeTarget, playerCommands, cancelEvent)
- ExecutableItems: Item Features (material, name, lore, cancelEventIfNoPermission)
- ExecutableItems: Commands & Permissions (ei.item.<id>, ei.nocd.<id>, /ei create, /ei give)
- ExecutableItems: Free vs premium (500 items, 1 activator per item)
- ExecutableItems: How to use vanilla commands (execute at %player% run)
- SCore: Player and target commands (SEND_MESSAGE, SUDO)
- SCore: Player and target conditions (ifHasPermission)
- ExecutableItems product page (SPlugins): 19.99 EUR, checked 2026-11-26
- Minecraft Wiki: Statistics (minecraft.used counts the use key on carrots and warped fungus on a stick), checked 2026-11-26
- Denizen on GitHub: MIT, Spigot 1.17.1 to 26.3, checked 2026-11-26
- Denizen Meta: 'player (right|left) clicks <block>' event with the with:<item> switch, checked 2026-11-26
- Skript on Modrinth: GPL-3.0, Paper loader, up to 26.3, checked 2026-11-26
- Skript docs: Click event syntax, checked 2026-11-26
- MMOItems docs: Item Stats (Commands stat, cooldown and delay), checked 2026-11-26
- MMOItems on SpigotMC: 19.99 EUR (via the Spiget API), checked 2026-11-26
- Nexo docs: Custom Mechanic