Skip to content

this.gui.setContent(); alternative and problem with addItems #58

@Challangerson

Description

@Challangerson

image

if(!controlItems.isEmpty()) {
this.gui.setContent(controlItems);
}

public BansGui(LogsManager logsManager) {
    this.logsManager = logsManager;
    this.gui = PagedGui.items()
            .setStructure(
                    "# # # # # # # # #",
                    "# x x x x x x x #",
                    "# x x x x x x x #",
                    "# x x x x x x x #",
                    "# # # < # > # # #"
            ).addIngredient(
                    '#', new SimpleItem(new ItemBuilder(Material.BLACK_STAINED_GLASS_PANE).setDisplayName(" "))
            ).addIngredient(
                    '<', new BackItem()
            ).addIngredient(
                    'x', Markers.CONTENT_LIST_SLOT_HORIZONTAL
            ).addIngredient(
                    '>', new ForwardItem()
            ).build();
}

private void prepareGui() {
    for(Logs logs : this.logsManager.getLogs().values()) {



        this.gui.addItems(
            new ControlItem<>() {

                @Override
                public void handleClick(@NotNull ClickType clickType, @NotNull Player player, @NotNull InventoryClickEvent event) {
                    if(clickType.isLeftClick()) {
                        ChatUtil.sendMessage(player, "&8>> &cPowod: &7" + logs.getReason());
                    }
                }

                @Override
                public ItemProvider getItemProvider(Gui gui) {

                    return new ItemBuilder(logs.getLogsType().getMaterial())
                    .setDisplayName(ChatUtil.fixColor("&f>> &e" + logs.getPunishment() + " &f<<"))
                    .setLegacyLore(
                        ChatUtil.fixColors(
                            Arrays.asList(
                                    "&8>> &7Rodzaj kary: &c" + logs.getLogsType().getName(),
                                    "&8>> &7Administrator: &c" + logs.getPunisher(),
                                    "&8>> &7Powod: &c" + logs.getReason(),
                                    "&8>> &7Czas rozpoczecia: &c" + TimeUtil.getDateFromLong(logs.getTimeStarted().toEpochMilli()),
                                    "&8>> &7Czas: &c" + (logs.getTime() >= 0
                                            ? "PERMANENTNIE" : (logs.getTime() > System.currentTimeMillis()
                                            ? TimeUtil.secondsToString(logs.getTime() - System.currentTimeMillis()) : "zakonczony")
                            )
                        )
                    ));
                }

            }
        );
        

    }
}

public void openGui(Player player) {
    Window window = Window.single()
            .setTitle(ChatUtil.fixColor("&f>> &4Historia banow &f<<"))
            .setViewer(player)
            .setGui(gui)
            .build();

    this.prepareGui();
    window.open();
}

how can i replace a setItems for no dupling

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions