【发布时间】:2021-09-06 05:43:15
【问题描述】:
首先,我想为我糟糕的英语 xD 道歉。所以,我正在开发一个经济插件来学习,在这个插件中,我正在创建一个标志商店。一切都很顺利,但是当我尝试我的商店时,我被附魔物品卡住了,例如,因为我无法获得 ID:
ItemStack item = player.getItemInHand();
item.getTypeId();
这只会返回真实物品的 id,没有附魔。 有人可以告诉我是否有一种方法可以设置一些 自定义 id,例如,在项目的知识中,我可以在以后使用它来制作标志商店?
编辑:
现在可以正常保存项目数据,但仍然报错。 我现在使用的是:
public static void saveItem(Player player){
ItemStack item = player.getItemInHand();
//config.createSection("eco.sell.aFirstItem");
ConfigurationSection configToEdit = config.createSection("eco.sell.aFirstItem");
configToEdit.set("type", item.getType().name());
configToEdit.set("amount", item.getAmount());
if(item.hasItemMeta()){
ItemMeta meta = item.getItemMeta();
configToEdit.set("meta.name", meta.getDisplayName());
List<String> enchants = new ArrayList<>();
meta.getEnchants().forEach((en, lvl) -> enchants.add(en.getName() + ":" + lvl));
configToEdit.set("meta.enchant", enchants);
save();
}
}
所以,要恢复我正在使用的数据:
public static void restoreData(Player player){
//config.getConfigurationSection("eco.sell.aFirstItem");
ConfigurationSection configToEdit = config.createSection("eco.sell.aFirstItem");
ItemStack item = new ItemStack(Material.valueOf(configToEdit.getString("type")), configToEdit.getInt("amount"));
if(configToEdit.contains("meta")) {
player.sendMessage("Contains( Meta )");
ItemMeta meta = item.getItemMeta();
meta.setDisplayName(configToEdit.getString("meta.name"));
List<String> enchants = configToEdit.getStringList("meta.enchants");
enchants.forEach(line -> {
String[] split = line.split(":");
item.addEnchantment(Enchantment.getByName(split[0]), Integer.parseInt(split[1]));
});
}
player.getInventory().addItem(item);
player.updateInventory();
}
【问题讨论】:
-
这个问题对我来说是模棱两可的,你到底想做什么?添加一种方法来识别特定物品或从特定物品中获得附魔?
-
是的,类似的。更具体地说,我想做一些类似 ChestShop 插件的 /iinfo 命令,你知道吗?但我想用一些附魔来识别物品,例如,从标志中取出它来制作商店标志。