Bukkit myInventory更改项目名称

时间:2018-01-18 15:53:58

标签: java minecraft bukkit

我制作了一个Minecraft bukkit插件,这是一个游戏模式转换器GUI,但我无法弄清楚如何更改我打开的库存中的块名称。目前他们所说的只是Iron_Block,Gold_block等等

如果有人能帮助我,那会非常有帮助

这是库存代码位

public static Inventory myInventory = Bukkit.createInventory(null, 9, "GamemodeGUI");

static {
    myInventory.setItem(0, new ItemStack(Material.IRON_BLOCK, 1)); //Survival
    myInventory.setItem(1, new ItemStack(Material.DIAMOND_BLOCK, 1)); //Creative
    myInventory.setItem(2, new ItemStack(Material.GOLD_BLOCK, 1)); //Adventure
    myInventory.setItem(3, new ItemStack(Material.LAPIS_BLOCK, 1)); //Spectator

    myInventory.setItem(8, new ItemStack(Material.STAINED_GLASS, 1)); //Cancel
}

1 个答案:

答案 0 :(得分:2)

通过将方法调用分配给变量来创建ItemStack:

ItemStack iron = new ItemStack(Material.IRON_BLOCK, 1); //Can be added to your static block

自定义它以更改您想要的名称

public static void setItemStackName(ItemStack renamed, String customName) {
    ItemMeta renamedMeta = renamed.getItemMeta();
    renamedMeta.setDisplayName(customName);
    renamed.setItemMeta(renamedMeta);
}

ItemMeta您还可以添加传说。这是项目的描述

renamedMeta.setLore(Arrays.asList("Line 1 lore", "Line 2", "..."));

然后将自定义ItemStack添加到库存

setItemStackName(iron, "Survival");
inventory.setItem(0, iron);    //Pass your customized ItemStack to the method now