物品源系统
EMC 高级物品库通过物品源(ItemSource)接口统一管理来自不同渠道的物品。内置 9 种物品源,均通过反射对接,无需编译时依赖。
物品源一览
| # | 源名称 | 插件 | 物品 ID 格式 | 说明 |
|---|---|---|---|---|
| 1 | config | — | config:物品ID | 配置文件自定义物品(始终可用) |
| 2 | mythicmobs | MythicMobs | mythicmobs:物品ID | MythicMobs 自定义物品 |
| 3 | mmoitems | MMOItems | mmoitems:TYPE.ID | MMOItems 物品(类型.ID) |
| 4 | neigeitems | NeigeItems | neigeitems:物品ID | NeigeItems 物品 |
| 5 | itemsadder | ItemsAdder | itemsadder:namespace:id | ItemsAdder 物品 |
| 6 | oraxen | Oraxen | oraxen:物品ID | Oraxen 物品 |
| 7 | executableitems | ExecutableItems | executableitems:物品ID | ExecutableItems 物品 |
| 8 | ecoitems | EcoItems | ecoitems:物品ID | EcoItems 物品 |
| 9 | sxitem | SX-Item | sxitem:物品ID | SX-Item / SX-Attribute 物品 |
物品源优先级
当使用不带来源前缀的物品 ID(如 example_sword)时,插件按 config.yml 中 source-priority 列表的顺序依次搜索:
source-priority:
- config # 1. 先查配置文件
- mythicmobs # 2. 再查 MythicMobs
- mmoitems # 3. 再查 MMOItems
- neigeitems # 4. ...
- itemsadder
- oraxen
- executableitems
- ecoitems
- sxitem
找到第一个匹配的物品后立即返回。建议将最常用的物品源排在前面以提高效率。
物品源开关
在 config.yml 中可以单独启用/禁用某个物品源:
enabled-sources:
config: true # 始终建议开启
mythicmobs: true
mmoitems: true
neigeitems: false # 设为 false 即使插件已安装也不会对接
itemsadder: true
oraxen: true
executableitems: true
ecoitems: true
sxitem: true
禁用的物品源不会注册到管理器中,不会被搜索也不会出现在 /emcitem sources 中。
查看物品源状态
使用命令查看当前哪些物品源可用:
/emcitem sources
输出示例:
=== 物品源状态 ===
config ✔ 可用
mythicmobs ✔ 可用
mmoitems ✘ 不可用
neigeitems ✘ 不可用
itemsadder ✔ 可用
oraxen ✘ 不可用
executableitems ✘ 不可用
ecoitems ✘ 不可用
sxitem ✘ 不可用
使用示例
给予配置文件物品
/emcitem give Steve config:example_sword 1
给予 MythicMobs 物品
/emcitem give Steve mythicmobs:SkeletonKingSword 1
给予 MMOItems 物品
MMOItems 使用 TYPE.ID 格式:
/emcitem give Steve mmoitems:SWORD.STEEL_SWORD 1
给予 ItemsAdder 物品
/emcitem give Steve itemsadder:custom_items:ruby 1
开发者 API
其他插件可通过 EMCItemAPI 获取物品或注册自定义物品源。
获取物品
import com.emc.itemlib.api.EMCItemAPI;
// 获取物品(指定来源)
ItemStack sword = EMCItemAPI.getItem("config:example_sword");
// 获取物品并指定数量
ItemStack swords = EMCItemAPI.getItem("mythicmobs:SkeletonKingSword", 5);
// 检查物品是否存在
boolean exists = EMCItemAPI.hasItem("config:example_sword");
// 检查插件是否可用
boolean available = EMCItemAPI.isAvailable();
注册自定义物品源
import com.emc.itemlib.api.EMCItemAPI;
import com.emc.itemlib.item.ItemSource;
// 实现 ItemSource 接口
public class MyItemSource implements ItemSource {
@Override public String getName() { return "myplugin"; }
@Override public boolean isAvailable() { return true; }
@Override public ItemStack getItem(String id) { /* ... */ }
@Override public ItemStack getItem(String id, int amount) { /* ... */ }
@Override public Set<String> getItemIds() { /* ... */ }
@Override public void reload() { /* ... */ }
}
// 注册到物品库
EMCItemAPI.registerSource(new MyItemSource());
// 取消注册
EMCItemAPI.unregisterSource("myplugin");
可用的 API 方法
| 方法 | 返回类型 | 说明 |
|---|---|---|
getItem(String fullId) | ItemStack | 获取物品(数量 1) |
getItem(String fullId, int amount) | ItemStack | 获取指定数量的物品 |
hasItem(String fullId) | boolean | 检查物品是否存在 |
isAvailable() | boolean | 检查插件是否已加载 |
getItemManager() | ItemManager | 获取物品管理器实例 |
registerSource(ItemSource) | void | 注册自定义物品源 |
unregisterSource(String) | void | 取消注册物品源 |
getSourceNames() | Set<String> | 获取所有物品源名称 |
getAllItemIds() | Set<String> | 获取所有物品 ID(带来源前缀) |