### Get Items via HookerManager Source: https://context7.com/ankhorg/neigeitems-kotlin/llms.txt Shows how to retrieve items using HookerManager, prioritizing NeigeItems' own items and falling back to items from other integrated plugins like MythicMobs, ItemsAdder, or Oraxen. It also demonstrates fetching vanilla items. ```java import org.bukkit.OfflinePlayer; import org.bukkit.configuration.ConfigurationSection; import org.bukkit.inventory.ItemStack; import pers.neige.neigeitems.manager.HookerManager; import pers.neige.neigeitems.hook.mythicmobs.MythicMobsHooker; import java.util.HashMap; import java.util.Map; public class HookerManagerExample { // 获取NI物品或其他插件的物品 public ItemStack getAnyItem(String id, OfflinePlayer player) { // 优先获取NI物品,如果不存在则尝试从其他插件获取 return HookerManager.getNiOrHookedItem(id, player); } // 指定插件获取物品 public ItemStack getSpecificPluginItem(String itemId) { // 使用前缀指定物品来源 // mm:物品ID - MythicMobs // ia:物品ID - ItemsAdder // or:物品ID - Oraxen // mg:物品ID - MagicGem // vn:物品ID - Vanilla原版物品 ItemStack mmItem = HookerManager.getHookedItem("mm:MythicSword"); ItemStack iaItem = HookerManager.getHookedItem("ia:custom_helmet"); ItemStack orItem = HookerManager.getHookedItem("or:amethyst_sword"); ItemStack vnItem = HookerManager.getHookedItem("vn:DIAMOND_SWORD"); return mmItem; } } ``` -------------------------------- ### Interact with MythicMobs via HookerManager Source: https://context7.com/ankhorg/neigeitems-kotlin/llms.txt Provides examples for interacting with MythicMobs, including retrieving mob configurations and casting skills. It checks if the MythicMobs hooker is available before attempting operations. ```java import org.bukkit.OfflinePlayer; import org.bukkit.configuration.ConfigurationSection; import org.bukkit.inventory.ItemStack; import pers.neige.neigeitems.manager.HookerManager; import pers.neige.neigeitems.hook.mythicmobs.MythicMobsHooker; import java.util.HashMap; import java.util.Map; public class HookerManagerExample { // 获取MythicMobs怪物配置 public void getMythicMobsConfigs() { MythicMobsHooker hooker = HookerManager.INSTANCE.getMythicMobsHooker(); if (hooker == null) { System.out.println("MythicMobs未加载"); return; } // 获取所有怪物配置 Map mobInfos = hooker.getMobInfos(); for (Map.Entry entry : mobInfos.entrySet()) { String mobId = entry.getKey(); ConfigurationSection config = entry.getValue(); System.out.println("怪物ID: " + mobId); System.out.println("血量: " + config.getDouble("Health")); } } // 释放MythicMobs技能 public void castMythicSkill(org.bukkit.entity.Player player, String skillId) { MythicMobsHooker hooker = HookerManager.INSTANCE.getMythicMobsHooker(); if (hooker == null) return; hooker.castSkill(player, skillId, player); } } ``` -------------------------------- ### Get ItemStack for Player with PAPI Support Source: https://context7.com/ankhorg/neigeitems-kotlin/llms.txt Obtain an ItemStack for a specific player, allowing for PlaceholderAPI variable parsing within item configurations. ```java public ItemStack getItemForPlayer(String itemId, Player player) { return ItemManager.INSTANCE.getItemStack(itemId, player); } ``` -------------------------------- ### Get Total Item Count Source: https://context7.com/ankhorg/neigeitems-kotlin/llms.txt Returns the total number of items currently registered and managed by the ItemManager. ```java public int getTotalItemCount() { return ItemManager.INSTANCE.getItemAmount(); } ``` -------------------------------- ### Get ItemStack using Item ID Source: https://context7.com/ankhorg/neigeitems-kotlin/llms.txt Retrieve an ItemStack using its unique item ID. This is the most straightforward method for obtaining an item. ```java public ItemStack getSimpleItem(String itemId) { return ItemManager.INSTANCE.getItemStack(itemId); } ``` -------------------------------- ### Get ItemStack with Custom Data Source: https://context7.com/ankhorg/neigeitems-kotlin/llms.txt Retrieve an ItemStack with specific custom data applied. This method allows for dynamic item properties based on provided key-value pairs. ```java public ItemStack getItemWithData(String itemId, Player player) { HashMap data = new HashMap<>(); data.put("level", "50"); data.put("quality", "legendary"); return ItemManager.INSTANCE.getItemStack(itemId, player, data); } ``` -------------------------------- ### Perform Operations on ActionContext Source: https://context7.com/ankhorg/neigeitems-kotlin/llms.txt Illustrates common operations on an ActionContext, such as retrieving player information, accessing and modifying global variables, getting item details, setting custom values, cloning the context, and checking if it's running on the main thread. ```java import org.bukkit.entity.Player; import org.bukkit.inventory.ItemStack; import pers.neige.neigeitems.action.ActionContext; import pers.neige.neigeitems.action.ContextKeys; import pers.neige.neigeitems.libs.bot.inker.bukkit.nbt.NbtCompound; import java.util.HashMap; import java.util.Map; public class ActionContextExample { // 上下文操作示例 public void contextOperations(ActionContext context) { // 获取玩家 Player player = context.getPlayer(); // 获取全局变量 Map global = context.getGlobal(); global.put("newVar", "value"); // 获取物品信息 ItemStack item = context.getItemStack(); NbtCompound nbt = context.getNbt(); Map data = context.getData(); // 设置自定义值 context.set(ContextKeys.ITEM_STACK, item); // 克隆上下文 ActionContext cloned = context.clone(); // 检查是否在主线程 boolean isSync = context.isSync(); } } ``` -------------------------------- ### Get Item Generator Source: https://context7.com/ankhorg/neigeitems-kotlin/llms.txt Retrieve the ItemGenerator instance for a given item ID. This can be used for more advanced item manipulation. ```java public ItemGenerator getGenerator(String itemId) { return ItemManager.INSTANCE.getItem(itemId); } ``` -------------------------------- ### Get ItemStack with JSON Data Source: https://context7.com/ankhorg/neigeitems-kotlin/llms.txt Retrieve an ItemStack using a JSON string for custom data. This is an alternative to using a HashMap for specifying item properties. ```java public ItemStack getItemWithJsonData(String itemId, Player player) { String jsonData = "{\"level\":\"50\",\"quality\":\"legendary\"}"; return ItemManager.INSTANCE.getItemStack(itemId, player, jsonData); } ``` -------------------------------- ### Get NeigeItems Item ID Source: https://context7.com/ankhorg/neigeitems-kotlin/llms.txt Extract the NeigeItems specific item ID from an ItemStack. Returns null if the ItemStack is not a NeigeItems item. ```java public String getItemId(ItemStack itemStack) { String itemId = ItemUtils.getItemId(itemStack); if (itemId == null) { System.out.println("这不是一个NI物品"); return null; } return itemId; } ``` -------------------------------- ### Check if ItemStack is NeigeItems Item and Get Info Source: https://context7.com/ankhorg/neigeitems-kotlin/llms.txt Determine if an ItemStack is a NeigeItems item and retrieve its full ItemInfo, including ID, node data, and NBT tags. Node data is returned as a HashMap. ```java public void checkNiItem(ItemStack itemStack) { ItemInfo itemInfo = ItemUtils.isNiItem(itemStack); if (itemInfo == null) { System.out.println("这不是一个NI物品"); return; } // 获取物品ID String id = itemInfo.getId(); System.out.println("物品ID: " + id); // 获取物品的节点数据 java.util.HashMap data = itemInfo.getData(); System.out.println("节点数据: " + data); // 获取特定节点的值 String levelValue = itemInfo.getDataValue("level"); System.out.println("等级: " + levelValue); // 获取物品NBT var nbt = itemInfo.getItemTag(); System.out.println("NBT: " + nbt); // 获取NeigeItems专用NBT var neigeItemsNbt = itemInfo.getNeigeItems(); System.out.println("NeigeItems NBT: " + neigeItemsNbt); } ``` -------------------------------- ### Create ActionContext Instances Source: https://context7.com/ankhorg/neigeitems-kotlin/llms.txt Demonstrates different ways to create an ActionContext, from basic to complex configurations with global variables and parameters, including using the Builder pattern. ```java import org.bukkit.entity.Player; import org.bukkit.inventory.ItemStack; import pers.neige.neigeitems.action.ActionContext; import pers.neige.neigeitems.action.ContextKeys; import pers.neige.neigeitems.libs.bot.inker.bukkit.nbt.NbtCompound; import java.util.HashMap; import java.util.Map; public class ActionContextExample { // 基本上下文创建 public ActionContext createBasicContext(Player player) { return new ActionContext(player); } // 带全局变量和参数的上下文 public ActionContext createFullContext(Player player) { Map global = new HashMap<>(); global.put("level", "50"); global.put("name", player.getName()); Map params = new HashMap<>(); params.put("damage", 100); params.put("critical", true); return new ActionContext(player, global, params); } // 使用Builder模式创建上下文 public ActionContext createWithBuilder(Player player, ItemStack item, NbtCompound nbt) { Map data = new HashMap<>(); data.put("quality", "legendary"); return ActionContext.builder() .caster(player) .with(ContextKeys.ITEM_STACK, item) .with(ContextKeys.NBT, nbt) .with(ContextKeys.DATA, data) .build(); } } ``` -------------------------------- ### Plugin Main Class with Action Manager Usage Source: https://context7.com/ankhorg/neigeitems-kotlin/llms.txt Demonstrates how to initialize and use the custom action manager within a plugin's main class. Includes methods for executing actions with and without parameters, compiling actions, and creating action contexts. ```java // 在插件主类中使用 public class MyPlugin extends JavaPlugin { private static MyPlugin instance; private static MyActionManager actionManager; public static MyPlugin getInstance() { return instance; } public static MyActionManager getActionManager() { return actionManager; } @Override public void onEnable() { instance = this; actionManager = new MyActionManager(this); } // 使用动作系统 public void executeAction(Player player, Object actionConfig) { // 编译动作 Action action = actionManager.compile(actionConfig); // 创建执行上下文 ActionContext context = new ActionContext(player); // 执行动作 action.eval(context); } // 带参数的动作执行 public void executeWithParams(Player player, Object actionConfig) { Action action = actionManager.compile(actionConfig); // 创建带参数的上下文 Map params = new HashMap<>(); params.put("damage", 100); params.put("target", "enemy"); Map global = new HashMap<>(); global.put("bonus", 1.5); // global参数可在动作中以<变量名>形式访问 // params参数可在condition中直接访问 ActionContext context = new ActionContext(player, global, params); // 异步获取执行结果 CompletableFuture result = action.eval(context); result.thenAccept(r -> { if (r.isStop()) { System.out.println("动作被中止"); } else { System.out.println("动作执行成功"); } }); } } ``` -------------------------------- ### Parse Placeholders with HookerManager Source: https://context7.com/ankhorg/neigeitems-kotlin/llms.txt Demonstrates parsing placeholders using HookerManager, including standard placeholders, placeholders with color code parsing, and item-specific placeholders. ```java import org.bukkit.OfflinePlayer; import org.bukkit.configuration.ConfigurationSection; import org.bukkit.inventory.ItemStack; import pers.neige.neigeitems.manager.HookerManager; import pers.neige.neigeitems.hook.mythicmobs.MythicMobsHooker; import java.util.HashMap; import java.util.Map; public class HookerManagerExample { // 解析PAPI变量 public String parsePlaceholder(OfflinePlayer player, String text) { return HookerManager.papi(player, text); } // 解析PAPI变量同时解析颜色代码 public String parsePlaceholderWithColor(OfflinePlayer player, String text) { return HookerManager.papiColor(player, text); } // 解析物品变量 public String parseItemPlaceholder(ItemStack item, String text) { return HookerManager.parseItemPlaceholder(item, text); } } ``` -------------------------------- ### Configure Item Actions and Events Source: https://context7.com/ankhorg/neigeitems-kotlin/llms.txt Define item behaviors using YAML configuration, including event triggers like left/right clicks and consumption, as well as a variety of built-in action types. ```yaml # 物品动作配置示例 (Items/example.yml) example_sword: material: DIAMOND_SWORD name: "&6传奇之剑" lore: - "&7等级: " - "&7伤害: " sections: level: "random(1,100)" damage: "random(50,200)" event: # 左键点击动作 left: actions: - "tell: &a你使用了左键攻击!" - "sound: entity.player.attack.sweep 1 1" - "give-exp: 10" # 右键点击动作 right: sync: - "cast-skill: FireBall" actions: - "tell: &c释放了火球术!" # 消耗动作 consume: actions: - "give-health: 20" - "set-potion: SPEED 2 30" ``` ```yaml # 动作类型完整示例 actions: # 消息类动作 - "tell: &a向玩家发送消息" - "tell-no-color: 不解析颜色代码的消息" - "chat: 强制玩家发送消息" - "broadcast: &e全服公告" - "title: &6标题 &e副标题 10 70 20" - "actionbar: &aActionBar消息" # 指令类动作 - "command: spawn" - "console: give %player_name% diamond 1" # 经济类动作 - "give-money: 1000" - "take-money: 500" - "give-exp: 100" - "take-exp: 50" - "give-level: 5" # 状态类动作 - "give-health: 10" - "take-health: 5" - "set-health: 20" - "give-food: 6" - "set-saturation: 20" - "set-potion: SPEED 2 60" - "remove-potion: SPEED" # 物品类动作 - "take-ni-item: example_item 1" # 流程控制 - "delay: 20" - "return: label_name" - "sync: " - "async: " # 变量操作 - "set-global: myVar value" - "del-global: myVar" # MythicMobs技能 - "cast-skill: FireBall" # 传送 - "teleport: world 0 64 0 0 0" # 跨服 - "server: lobby" # 条件动作 condition_action: type: condition condition: "player.getHealth() > 10" actions: - "tell: &a血量充足!" deny: - "tell: &c血量不足!" ``` -------------------------------- ### Custom Action Manager Implementation Source: https://context7.com/ankhorg/neigeitems-kotlin/llms.txt Extend BaseActionManager to create a custom action manager. Load built-in JS libraries and register custom actions like consumers and functions. Ensure proper handling of player context and return values for functions. ```java import org.bukkit.entity.Player; import org.bukkit.plugin.Plugin; import org.bukkit.plugin.java.JavaPlugin; import pers.neige.neigeitems.action.Action; import pers.neige.neigeitems.action.ActionContext; import pers.neige.neigeitems.action.ActionResult; import pers.neige.neigeitems.manager.BaseActionManager; import java.util.HashMap; import java.util.Map; import java.util.concurrent.CompletableFuture; // 自定义动作管理器 public class MyActionManager extends BaseActionManager { public MyActionManager(Plugin plugin) { super(plugin); // 加载NI内置的JS库 loadJSLib("NeigeItems", "JavaScriptLib/lib.js"); // 注册自定义动作 registerCustomActions(); } private void registerCustomActions() { // 添加简单动作(无返回值) addConsumer("my-action", (context, content) -> { Player player = context.getPlayer(); if (player == null) return; player.sendMessage("执行自定义动作: " + content); }); // 添加带返回值的动作 addFunction("my-check", (context, content) -> { Player player = context.getPlayer(); if (player == null) { return CompletableFuture.completedFuture( pers.neige.neigeitems.action.result.Results.STOP ); } // 执行检查逻辑 return CompletableFuture.completedFuture( pers.neige.neigeitems.action.result.Results.SUCCESS ); }); // 添加必须同步执行的动作 addConsumer("sync-action", false, (context, content) -> { // 这个动作将在主线程执行 Player player = context.getPlayer(); if (player != null) { player.teleport(player.getWorld().getSpawnLocation()); } }); } } ``` -------------------------------- ### Manage Custom Durability and Charges Source: https://context7.com/ankhorg/neigeitems-kotlin/llms.txt Use the ItemManager class to programmatically set or modify custom durability and usage charges for ItemStack objects. ```java import org.bukkit.inventory.ItemStack; import pers.neige.neigeitems.manager.ItemManager; public class DurabilityExample { // 设置物品使用次数 public void setCharge(ItemStack itemStack, int amount) { ItemManager.setCharge(itemStack, amount); } // 添加物品使用次数(可为负数表示扣除) public void addCharge(ItemStack itemStack, int amount) { ItemManager.addCharge(itemStack, amount); } // 设置物品最大使用次数 public void setMaxCharge(ItemStack itemStack, int amount) { ItemManager.setMaxCharge(itemStack, amount); } // 添加物品最大使用次数 public void addMaxCharge(ItemStack itemStack, int amount) { ItemManager.addMaxCharge(itemStack, amount); } // 设置物品自定义耐久 public void setCustomDurability(ItemStack itemStack, int amount) { ItemManager.setCustomDurability(itemStack, amount); } // 添加物品自定义耐久 public void addCustomDurability(ItemStack itemStack, int amount) { ItemManager.addCustomDurability(itemStack, amount); } // 设置物品最大自定义耐久 public void setMaxCustomDurability(ItemStack itemStack, int amount) { ItemManager.setMaxCustomDurability(itemStack, amount); } // 添加物品最大自定义耐久 public void addMaxCustomDurability(ItemStack itemStack, int amount) { ItemManager.addMaxCustomDurability(itemStack, amount); } } ``` -------------------------------- ### Rebuild Items and Update Properties Source: https://context7.com/ankhorg/neigeitems-kotlin/llms.txt Update item attributes while optionally protecting specific NBT paths or sections from being overwritten during the rebuild process. ```java import org.bukkit.entity.Player; import org.bukkit.inventory.ItemStack; import pers.neige.neigeitems.manager.ItemManager; import java.util.Arrays; import java.util.HashMap; import java.util.List; import java.util.Map; public class RebuildExample { // 重构物品并更新指定节点 public void rebuildWithSections(Player player, ItemStack itemStack) { Map sections = new HashMap<>(); sections.put("level", "100"); // 更新level节点 sections.put("damage", null); // 刷新damage节点(重新随机) boolean success = ItemManager.rebuild(itemStack, player, sections); if (success) { player.sendMessage("物品重构成功!"); } } // 重构物品并保护特定NBT public void rebuildWithProtection(Player player, ItemStack itemStack) { Map sections = new HashMap<>(); sections.put("quality", "mythic"); // 保护这些NBT路径不被刷新 List protectNBT = Arrays.asList( "CustomModelData", "NeigeItems.enchantments" ); ItemManager.rebuild(itemStack, player, sections, protectNBT); } // 仅保留指定节点的重构 public void rebuildKeepingSections(Player player, ItemStack itemStack) { // 只保留这些节点的值,其他节点重新随机 List protectSections = Arrays.asList("level", "owner"); List protectNBT = Arrays.asList("display.Name"); ItemManager.rebuild(itemStack, player, protectSections, protectNBT); } // 自动更新物品(根据配置的update选项) public void autoUpdate(Player player, ItemStack itemStack) { // 根据物品配置中的options.update设置自动更新 // forceUpdate为true时强制更新,忽略hashCode检查 // sendMessage为true时向玩家发送更新提示 ItemManager.INSTANCE.update(player, itemStack, false, true); } } ``` -------------------------------- ### Reload Item Manager Source: https://context7.com/ankhorg/neigeitems-kotlin/llms.txt Force a reload of the ItemManager, which will re-read all item configurations from their sources. ```java public void reloadItems() { ItemManager.INSTANCE.reload(); } ``` -------------------------------- ### Check if Item Exists Source: https://context7.com/ankhorg/neigeitems-kotlin/llms.txt Verify if a NeigeItems item with the specified ID is registered in the ItemManager. ```java public boolean checkItemExists(String itemId) { return ItemManager.INSTANCE.hasItem(itemId); } ``` -------------------------------- ### Check if ItemStack is NeigeItems Item with Parsed Data Source: https://context7.com/ankhorg/neigeitems-kotlin/llms.txt Check if an ItemStack is a NeigeItems item and parse its node data directly into a HashMap. This is useful for iterating through all custom item properties. ```java public void checkNiItemWithParsedData(ItemStack itemStack) { // 第二个参数为true时会将data解析为HashMap ItemInfo itemInfo = ItemUtils.isNiItem(itemStack, true); if (itemInfo != null) { java.util.HashMap data = itemInfo.getData(); for (var entry : data.entrySet()) { System.out.println(entry.getKey() + " = " + entry.getValue()); } } } ``` === COMPLETE CONTENT === This response contains all available snippets from this library. No additional content exists. Do not make further requests.