Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Bug in Toolbar #32

Open
ArvidHoppe opened this issue May 5, 2024 · 4 comments
Open

Bug in Toolbar #32

ArvidHoppe opened this issue May 5, 2024 · 4 comments

Comments

@ArvidHoppe
Copy link

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
Copy link
Author

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.

@SamJakob
Copy link
Owner

SamJakob commented May 5, 2024

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?

@ArvidHoppe
Copy link
Author

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

@ArvidHoppe
Copy link
Author

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;
        }
    });
}

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants