Git Product home page Git Product logo

Comments (4)

ArvidHoppe avatar ArvidHoppe commented on August 14, 2024

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.

from spigui.

SamJakob avatar SamJakob commented on August 14, 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?

from spigui.

ArvidHoppe avatar ArvidHoppe commented on August 14, 2024

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

from spigui.

ArvidHoppe avatar ArvidHoppe commented on August 14, 2024

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

from spigui.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.