开发者 API🔗
你可以在 github.com/Zrips/CMI-API 找到 CMI-API 的源代码,并下载 .jar 文件。
添加到 pom.xml:
<dependency>
<groupId>com.github.Zrips</groupId>
<artifactId>CMI-API</artifactId>
<version>9.8.6.4</version>
<scope>provided</scope>
</dependency>
玩家/用户对象 (Player/User Object)🔗
与玩家相关的大多数事情都可以通过用户对象访问:
这在一些罕见的情况下可能返回 NULL,因此请执行 NPE 检查。
你可以通过以下方式从中获取离线玩家对象:
这可以用来访问玩家的一些数据信息,即使他离线。请注意,这实际上会加载玩家的信息,高度不建议用此方法加载数百甚至数千名玩家,因为这无疑会给服务器带来一些压力。你仍然可以更新一些玩家数据,但你需要保存它(仅当玩家离线时)使用:
或者使用:
这是更安全的方法,因为会检查玩家对象是否进行了适当的保存。
管理器 (Managers)🔗
很多内容可以通过相应的管理器访问。它们都可以通过基本方法访问:
例如,要访问传送门管理器,请使用:
物品价值 (Worth)🔗
获取物品价值:
// Item stack used to get worth
ItemStack item;
WorthItem worth = CMI.getInstance().getWorthManager().getWorth(item);
if (worth == null){
// Worthless item so we can return null or 0D, whatever is needed in your case
return null;
}
// Buy price used in exploit detection
Double buyPrice = worth.getBuyPrice();
// Sell price defines actual worth of the file
Double sellPrice = worth.getSellPrice();
设置物品价值:
// Item of which worth value we are getting
ItemStack item;
// Worth object
WorthItem worth = CMI.getInstance().getWorthManager().getWorth(item);
if (worth == null){
// If its null then lets create new one
worth = new WorthItem(item);
// Adding worth to cache
CMI.getInstance().getWorthManager().addWorth(worth);
}
// Changing prices
worth.setBuyPrice(2D);
worth.setSellPrice(1D);
// Lets update values in save file
CMI.getInstance().getWorthManager().updatePriceInFile(worth);
自定义事件 (Custom Events)🔗
- CMIAfkEnterEvent – 当玩家进入 AFK 模式时触发。
- CMIAfkKickEvent – 当玩家在 AFK 后应从服务器被踢出时触发。
- CMIAfkLeaveEvent – 当玩家离开 AFK 模式时触发。
- CMIAnvilItemRenameEvent – 在铁砧中重命名物品时触发。
- CMIAnvilItemRepairEvent – 在铁砧上执行物品修复操作时触发。
- CMIArmorChangeEvent – 当玩家更换盔甲槽中的物品时触发。
- CMIAsyncPlayerTeleportEvent – 当玩家在异步模式下被传送时触发。可以被取消。
- CMIBackpackOpenEvent – 打开背包时触发。
- CMIChequeCreationEvent – 在支票创建前触发。
- CMIChequeUsageEvent – 使用支票时触发。
- CMIChunkChangeEvent – 当玩家更换区块时触发。
- CMIConfigReloadEvent – 配置重新加载时触发。
- CMIEventCommandEvent – 触发事件命令时触发。
- CMIIpBanEvent – 当 IP 被禁时触发。
- CMIIpUnBanEvent – 当 IP 被解禁时触发。
- CMIHologramClickEvent – 与可交互的全息图交互时触发。
- CMIPlayerBanEvent – 当玩家被封禁时触发。
- CMIPlayerFakeEntityInteractEvent – 当玩家与虚假实体交互时触发,大多数情况下这将是全息图按钮交互。
- CMIPlayerItemsSellEvent – 直接使用命令出售物品或关闭出售 GUI 时触发。
- CMIPlayerItemsSellEvent – 使用价值(worth)命令出售玩家物品时触发。
- CMIPlayerJailEvent – 玩家入狱时触发。
- CMIPlayerKickEvent – 玩家被踢出时触发。
- CMIPlayerNickNameChangeEvent – 玩家昵称改变时触发。
- CMIPlayerOpenArmorStandEditorEvent – 玩家打开盔甲架编辑器时触发。
- CMIPlayerSitEvent – 玩家坐下时触发。
- CMIPlayerTeleportRequestEvent – 玩家传送后触发。
- CMIPlayerUnBanEvent – 当玩家被解禁时触发。
- CMIPlayerUnjailEvent – 玩家出狱时触发。
- CMIPlayerUnVanishEvent – 玩家退出隐身状态时触发。
- CMIPlayerVanishEvent – 玩家进入隐身状态时触发。
- CMIPlayerWarnEvent – 玩家收到警告时触发。
- CMIPlayerWarpEvent – 在将玩家传送到目标位置前触发。
- CMIPortalCreateEvent – 在下界传送门创建事件时触发。
- CMIPortalUseEvent – 使用 CMI 传送门时触发。
- CMIPvEStartEventAsync – 玩家对战环境(PVE)开始时触发。
- CMIPvEEndEventAsync – 玩家对战环境(PVE)结束时触发。
- CMIPvPStartEventAsync – 玩家对战(PVP)开始时触发。
- CMIPvPEndEventAsync – 玩家对战(PVP)结束时触发。
- CMISelectionEvent – 进行选择时触发。
- CMISelectionVisualizationEvent – 选择可视化开始显示前触发。可以被取消。
- CMIStaffMessageEvent – 发送员工消息时触发。
- CMIUserBalanceChangeEvent – 当用户余额改变时触发,如果使用 CMI 经济系统的话。改变类型包括:setBalance、Withdraw、Deposit。 (内容由AI生成,仅供参考)