SlotPaginator

페이지 GUI를 위한 유틸리티 입니다. 특정 영역을 기반으로 한 페이지 및 슬롯 기능을 제공합니다.

Usage

// Fo Gui는 redraw 가 어려운 편이므로 HelperPageGui를 추천함
public class GuiLootData extends HelperPageGui {

    private final SlotPaginator coordinate = new SlotPaginator(7, 4, 1, 1);
    // 뒤 쪽의 두 숫자는 표시 영역이 시작하는 좌측 상단의 슬롯 좌표을 의미함
    // 이 경우 9 * 6 GUI의 테두리를 제외한 중앙 부분의 슬롯을 뜻함

    private final List<Data> dataList;

    public GuiLootData(@NotNull Player player, @NotNull List<Data> dataList) {
        super(McLocalizationController.getDefaultBundle(SimplePlugin.getInstance()), "TEST", player, 6);

        this.dataList = dataList;
    }

    @Override
    public void redraw() {
        clearItems();

        coordinate.processSlots(getPage(), (ordinal, slot) -> {
            if (ordinal >= dataList.size()) return;
            // 위 메서드는 페이지의 모든 ordinal에 대해 루프를 돌리므로 
            // 원 데이터에서 찾을 수 없는 경우 return 이 필요함

            Data data = dataList.get(ordinal);
            ItemStack icon = data.getIcon();

            registerButton(slot, new ButtonBuilder(icon).toItemStack());
        });

        if (isNextExist()) registerNextButton();
        if (isPrevExist()) registerPrevButton();
    }

    @Override
    protected int getMaxPage() {
        return coordinate.getMaxPage(dataList.size());
    }
}

Last updated