-
-
Notifications
You must be signed in to change notification settings - Fork 4
槽位与放置
huanmeng_qwq edited this page Dec 27, 2024
·
1 revision
Slot
用来描述一个按钮在哪个位置
// 代表界面中的第1格
Slot slot = Slot.of(0);
// 代表界面中的 第2行的第1格
Slot slot = Slot.ofGame(1,2);
// 代表界面中的 第2行的第1格
Slot slot = Slot.ofBukkit(0,1);
// 表示界面中的第1格 只能放置钻石
Slot slot = Slot.of(0, (slot, button, player) -> { /* ButtonPlaceInterface类型 */
ItemStack showItem = button.getShowItem(player); // 可能为空
return showItem != null && showItem.getType() == Material.DIAMOND;
});
// 处理点击事件
Slot slot = Slot.of(0, new ButtonClickInterface() {
@Override
public @NonNull Result onClick(@NonNull AbstractGui<?> gui, @NonNull Slot slot, @NonNull Button button, @NonNull Player player, @NonNull ClickType click, @NonNull InventoryAction action, InventoryType.@NonNull SlotType slotType, int slotKey, int hotBarKey, @NonNull InventoryClickEvent e) {
// 在触发按钮的点击方法前执行一下你先做的事情
// 当然也可以选择不调用按钮的onClick直接返回 `Result`
// 也可以选择使用 `ButtonSimpleClickInterface` 接口,仅接收Button和Player参数
return button.onClick(gui, slot, player, click, action, slotType, slotKey, hotBarKey, e);
}
});
Slots
表示按钮将按照一定的布局进行摆放
// 表示界面中所有的槽位
Slots slots = Slots.full();
// 使用数组指定
Slots slots = Slots.of(Slot.of(0), Slot.of(1), ...);
Slots slots = Slots.of(0, 1, 2);
// 网格状
Slots slots = Slots.GRID;
// 多页界面时也可以使用该预设
Slots slots = Slots.PATTERN_LINE_PAGE_DEFAULT;
Slots slots = Slots.PATTERN_LINE_DEFAULT;