-
Notifications
You must be signed in to change notification settings - Fork 1
箱子界面
Yun Shan edited this page Oct 20, 2019
·
5 revisions
示例,可直接copy执行查看效果
public void testInventory(Player player) {
// 第一个界面
Icon icon = Icon.builder()
.material("diamond")
.name("§b测试§a边界")
.lore(Arrays.asList("§6第一行", "§5第二行"))
.ench(true)
.unbreakable(true)
.build();
Gui gui = new GuiFactory()
.withTitle("§6测试§e标题")
.withRow(6)
.addComponent(
new Border(4, 2, 5, 8, icon)
).build();
// 构建并显示界面
Inventory inv = gui.getInvSingleton();
player.openInventory(inv);
// 5秒后显示第二个界面
// 第二个界面支持放入物品,并可以点击按钮获取放入的物品
Bukkit.getScheduler().runTaskLater(plugin/* 插件实例 */, () -> {
AtomicReference<Inventory> inv2 = new AtomicReference<>();
icon.setCount(1);
icon.setEnch(false);
Icon icon2 = Icon.builder()
.material("skull_item")
.subId(3)
.skullOwner("YunShan")
.name("§b测试§a线")
.lore(Arrays.asList("§6第一行", "§5第二行"))
.build();
Container c = new Container(2, 2, 2, 4);
c.setCanInput(true);
Container c2 = new Container(4, 2, 4, 4);
c2.setCanInput(true);
Icon icon3 = Icon.builder()
.material("chest")
.name("§d测试按钮")
.lore(Arrays.asList("§6第一行", "§5第二行"))
.build();
Button button = new Button(5, 9, icon3);
button.setHandle((click, pObj) -> {
Player p = (Player)pObj;
System.out.println("玩家" + p.getName() + "点击了按钮(" + click.getType() + ")");
Inventory clickInv = inv2.get();
System.out.println("上方容器放入的物品有:");
for (int slot : c.getSlots()) {
ItemStack item = clickInv.getItem(slot);
if (item != null && !item.getType().equals(Material.AIR)) {
System.out.println(item);
}
}
System.out.println("下方容器放入的物品有:");
for (int slot : c2.getSlots()) {
ItemStack item = clickInv.getItem(slot);
if (item != null && !item.getType().equals(Material.AIR)) {
System.out.println(item);
}
}
});
Gui gui2 = new GuiFactory()
.withTitle("§6测试§e标题二号")
.withRow(5)
.addComponent(new Border(1, 1, 5, 5, icon))
.addComponent(new HorizontalLine(3,2, 4, icon2))
.addComponent(c)
.addComponent(c2)
.build();
// 构建并显示界面
inv2.set(gui2.getInvSingleton());
player.openInventory(inv2.get());
}, 20L * 5);
}