-
-
Notifications
You must be signed in to change notification settings - Fork 4
示例 背包按钮
huanmeng_qwq edited this page Dec 28, 2024
·
1 revision
// 需要自行备份玩家的背包,Gui框架不会保存玩家的背包内容
ItemStack[] contents = player.getInventory().getContents();
ItemStack[] storageContents = player.getInventory().getStorageContents();
GuiCustom gui = new GuiCustom();
// 允许放置在背包中
gui.enablePlayerInventory(true);
// 当关闭时执行
gui.whenClose(g -> player.getInventory().setContents(contents));
gui.whenClose(g -> player.getInventory().setStorageContents(storageContents));
// 允许点击背包和放置物品到背包
gui.setCancelClickBottom(false);
gui.setCancelMoveItemToBottom(false);
gui.draw().set(Slot.of(0).asPlayer(), Button.of(new ItemStack(Material.DIAMOND), p -> p.sendMessage("hi")))
.set(Slot.player(10), Button.of(new ItemStack(Material.GOLD_INGOT), p-> p.sendMessage(p.getName())));
gui.openGui();