SpiGUI icon indicating copy to clipboard operation
SpiGUI copied to clipboard

Bug in Toolbar

Open ArvidHoppe opened this issue 1 year ago • 4 comments

I created a pagable ui with a Toolbar. But it seens like the first slot of the toolbar is still used by the page-content. The Item is not displayed, but its clickable, so one item in the page-content is lost!

ArvidHoppe avatar May 05 '24 00:05 ArvidHoppe

EDIT: the Item is not "removed" from the pages, but is duplicated. But the Click Listener overrides the clicklistener of the toolbar, so the problem remains.

ArvidHoppe avatar May 05 '24 09:05 ArvidHoppe

Interesting... might be a case of a <= instead of a <.

Are you able to share some code for the inventory (quick n' dirty is fine!) to reproduce the issue?

SamJakob avatar May 05 '24 10:05 SamJakob

Yes of cause, I can paste the code when im home again :)

ArvidHoppe avatar May 06 '24 06:05 ArvidHoppe

This is the breakdown of my code. If i left something Project-Specific in there im sorry :'D


private void openJoinInventory(Player player){
    SGMenu menu = getMessageMenu("§aJoin Messages", player, CustomMessageType.JOIN);
    player.playSound(player.getLocation(), Sound.ENTITY_CHICKEN_EGG, 1, 1);
    player.openInventory(menu.getInventory());
}

private SGMenu getMessageMenu(String title, Player player){
    List<String> messages = new ArrayList<>();
    for(int i = 0; i<50; i++){
            messages.add("String " + i);
    }
    SGMenu menu = this.gui.create(title, 6);
    menu.setAutomaticPaginationEnabled(true);
    menu.setRowsPerPage(5);
    for(String msg : messages){
        ItemStack msgStack = new ItemBuilder(Material.PAPER).name(msg).build();
        SGButton messageButton = new SGButton(msgStack).withListener(event -> {
            Player clicker = (Player) event.getWhoClicked();
            clicker.playSound(clicker.getLocation(), Sound.ENTITY_PLAYER_LEVELUP, 1, 1);
        });
        menu.addButton(messageButton);
    }
    setupToolBar(menu, CustomMessageType.JOIN);
    return menu;
}

private void setupToolBar(SGMenu menu){
    menu.setToolbarBuilder((slot, page, buttonType, sgMenu) -> switch (buttonType) {
        case CURRENT_BUTTON -> new SGButton(new ItemBuilder(Material.NAME_TAG)
                .name("&7&lSeite " + (menu.getCurrentPage() + 1) + " von " + menu.getMaxPage())
                .build()
        ).withListener(event -> event.setResult(Event.Result.DENY));

        case NEXT_BUTTON -> {
            if (page == menu.getMaxPage()) yield null;

            if (menu.getCurrentPage() < menu.getMaxPage() - 1) {
                yield new SGButton(new ItemBuilder(NEXT_SKULL)
                        .name("&a&lNächste Seite →")
                        .build()
                ).withListener(event -> {
                    event.setResult(Event.Result.DENY);
                    menu.nextPage(event.getWhoClicked());
                    Player player = (Player) event.getWhoClicked();
                    player.playSound(player.getLocation(), Sound.ITEM_BOOK_PAGE_TURN, 1, 1);
                });
            }
            yield null;
        }

        case PREV_BUTTON -> {
            if (page == 0) yield null;

            if (menu.getCurrentPage() > 0) {
                yield new SGButton(new ItemBuilder(BACK_SKULL)
                        .name("&a&l← Vorherige Seite").build()
                    ).withListener(event -> {
                        event.setResult(Event.Result.DENY);
                        menu.previousPage(event.getWhoClicked());
                        Player player = (Player) event.getWhoClicked();
                        player.playSound(player.getLocation(), Sound.ITEM_BOOK_PAGE_TURN, 1, 1);
                    });
            }
            yield null;

        }

        case UNASSIGNED -> {
            if(slot == 1) {
                yield new SGButton(HOME_SKULL)
                        .withListener(event -> {
                            Player player = (Player) event.getWhoClicked();
				player.closeInventory();
                            player.playSound(player.getLocation(), Sound.ENTITY_EXPERIENCE_ORB_PICKUP, 1, 1);
                        });
            } else if(slot == 7) {
                yield new SGButton(
                        new ItemBuilder(Material.LAVA_BUCKET).name("§cClear Message").build()
                ).withListener(event -> {
                    Player player = (Player) event.getWhoClicked();
		player.closeInventory();
                    player.playSound(player.getLocation(), Sound.ENTITY_GENERIC_BURN, 1, 1);
                });
            }
            yield null;
        }
    });
}

ArvidHoppe avatar May 06 '24 17:05 ArvidHoppe