DevNatan / inventory-framework

Minecraft Inventory API framework
MIT License
124 stars 22 forks source link

Dynamic pagination cannot be accessed on user-defined layout pattern #245

Closed iGabyTM closed 11 months ago

iGabyTM commented 2 years ago

Hey, I need to create a paginated view that would look like this:

 ---------
<OOOOOOO>
<OOOOOOO>
<OOOOOOO>
---------

Where - is the filler, < and > are previous/next page buttons are O is where items would go, but I can't figure out how to that.

This is the code used in the plugin that I try to update

    @Override
    protected void onOpen(@NotNull OpenViewContext context) {
        final var config = ViewModule.getMenuConfigManager().getConfig(WarpPaginatedMenuConfig.class);
        context.setInventorySize(config.getLayout().length); // 6
        context.setInventoryTitle(config.getTitle());
        context.setLayout(config.getLayout()); // XXXXXXXXX, <OOOOOOO>, <OOOOOOO>, <OOOOOOO>, XXXXXXXXX, XXXXXXXXX
    }

    @Override
    protected void onRender(ViewContext context) {
        final var config = ViewModule.getMenuConfigManager().getConfig(WarpPaginatedMenuConfig.class);
        LandUser landUser = context.get("landUser");
        ViewHelper.setFillerAndDecorations(context, config);

        setSource(landUser.getWarps());

        if (landUser.getWarps().isEmpty()) {
            config.noValuesItem().forEachSlot((slot, item) -> context.slot(slot, item.getItemStack()));
        }
    }

    @Override
    protected void onItemRender(PaginatedViewSlotContext<LandWarp> context, ViewItem viewItem, LandWarp value) {
        final var config = ViewModule.getMenuConfigManager().getConfig(WarpPaginatedMenuConfig.class);
        Player player = context.getPlayer();

        viewItem.withItem(config.warpItem().createItem(value.createPlaceholders())).onClick(handler -> {
            if (handler.getClickOrigin().isRightClick()) {
                player.closeInventory();
                player.performCommand("land delwarp " + value.getName());
            } else if (handler.getClickOrigin().isLeftClick()) {
                player.closeInventory();
                player.performCommand("land warp " + value.getName());
            } else if (handler.getClickOrigin().getClick() == ClickType.MIDDLE) {
                value.setPublicWarp(!value.isPublicWarp());
                player.sendMessage("§aYou make this warp §f" + (value.isPublicWarp() ? "public" : "private") + "§a successfully.");

                if (value.isPublicWarp()) {
                    viewFrame.open(ChangeWarpCategoryView.class, player, ImmutableMap.of("landWarp", value));
                } else {
                    value.setCategory(LandWarpCategory.NONE);
                    player.closeInventory();
                }
            }
        });
    }

But the menu looks like this: image

If the user doesn't have any warps, it looks good: image

Also, I have this error when the layout doesn't have 6 rows: https://paste.helpch.at/zucofebeso.sql

DevNatan commented 2 years ago

@iGabyTM what version of InventoryFramework are you using?

there are some remarks:

  1. setSource(landUser.getWarps()) should be context.setSource(landUser.getWarps()), anything called on onRender must use context... you are probably using an outdated version as it was supposed to give an error
  2. you can use User-Defined Patterns to create theses fillers.
  3. it's recommended to use handler.closeUninterruptedly() instead of player.closeInventory()

your code looks right, nothing except ^^ wrong, probably a bug i'll try to reproduce

iGabyTM commented 2 years ago

The version I use is com.github.DevNatan:inventory-framework:v2.4.2 - I know, old - but since I don't have experience with this library and the code is fairly big, I don't have enough time to fix possible bugs. Also, I don't really want to use layout unless I have to, e.g. I can't place the pagination items on other slots without layout or to set the items of each page in specific slots (10 - 16, 19 - 25, 28 - 34)

DevNatan commented 2 years ago

The version I use is com.github.DevNatan:inventory-framework:v2.4.2 - I know, old - but since I don't have experience with this library and the code is fairly big, I don't have enough time to fix possible bugs. Also, I don't really want to use layout unless I have to, e.g. I can't place the pagination items on other slots without layout or to set the items of each page in specific slots (10 - 16, 19 - 25, 28 - 34)

Your need is real, it makes sense for me to allow paginated items to be applied in slots defined by themselves, i'll make a note of that. Anyway, there's no way i can give you a solution for an old version because there's a high chance that it has already been fixed in new versions. Try to use the newest version v2.5.4-rc.1, it and v2.5.4-beta fix many bugs previously reported it might be your case.

If it doesn't solve your problem, i'm here to help you.

iGabyTM commented 2 years ago

image

layout:
  - "---------"
  - "[OOOOOOO]"
  - "[OOOOOOO]"
  - "[OOOOOOO]"
  - "---------"

Looks good @DevNatan but just to make sure I do things right. I couldn't set the layout and its items on onOpen due to class cast conflict between BukkitOpenViewContext and PaginatedViewContext so I moved it to onRender.


final var paginatedContext = context.paginated();
paginatedContext.setLayout(config.getLayout());
paginatedContext.setLayout('-', item -> item.setItem(config.getFiller().getItemStack()));
paginatedContext.setLayout('[', item -> item.withItem(config.previousPageItem().getItemStack()).onClick(__ -> {
    Player player = context.getPlayer();

    if (paginatedContext.isFirstPage()) {
        viewFrame.open(MainView.class, player, paginatedContext.getData());
    } else {
        paginatedContext.switchToPreviousPage();
    }
}));
paginatedContext.setLayout(']', item -> item.withItem(config.nextPageItem().getItemStack()).onClick(__ -> paginatedContext.switchToNextPage()));```
iGabyTM commented 2 years ago

So I've made this util class to load the layout because I will use a similar system on multiple menus that are paginated

public void setPaginationItems(
        @NotNull final PaginatedViewContext<Object> context, @NotNull final PaginatedMenuConfig config,
        @NotNull final Consumer<ViewSlotClickContext> previousPageClickHandler, @NotNull final Consumer<ViewSlotClickContext> nextPageClickHandler
) {
    context.setLayout(config.getLayout());
    context.setLayout('-', item -> item.setItem(config.getFiller().getItemStack()));
    context.setLayout('[', item -> item.withItem(config.previousPageItem(context.hasPreviousPage()).getItemStack()).onClick(previousPageClickHandler));
    context.setLayout(']', item -> item.withItem(config.nextPageItem(context.hasNextPage()).getItemStack()).onClick(nextPageClickHandler));
}

And on onRender I can the method like this:

ViewHelper.setPaginationItems(
        context.paginated(),
        config,
        handler -> {
            final var player = handler.getPlayer();

            if (handler.paginated().isFirstPage()) {
                viewFrame.open(MainView.class, player, handler.getData());
            } else {
                handler.paginated().switchToPreviousPage();
            }
        },
        handler -> handler.paginated().switchToNextPage()
);

But this https://paste.helpch.at/lakaqeqawu.rb error is thrown by context.hasNextPage() (I use this and context.hasPreviousPage to check what item I should use, nextPage/previousPage or noNextPage/noPreviousPage) Though, I set the source on the constructor, so idk why it would be null setSource(context -> ((LandUser) context.get("landUser")).getWarps()); Version used: com.github.DevNatan:inventory-framework:2.5.4-rc.1

DevNatan commented 2 years ago

Hmm, ok @iGabyTM I understand why this happens, the pagination interceptor comes after the layout resolution interceptor so pagination I'll not be available on user-defined layout pattern, this is the first time this has been reported, so it's a bug, I'll change the order of the interceptors to make it possible

Looks good @DevNatan but just to make sure I do things right. I couldn't set the layout and its items on onOpen due to class cast conflict between BukkitOpenViewContext and PaginatedViewContext so I moved it to onRender.

y onOpen is a pre-creation treatment of the inventory container that will be shown to the player there you prepare everything and can cancel it even before the menu is shown to the player, things related to rendering are in the class constructor and onRender.

iGabyTM commented 2 years ago

Any idea when a fix will be released? I kind need this soon 😅

DevNatan commented 2 years ago

Any idea when a fix will be released? I kind need this soon 😅

Today or tomorrow, don't worry, it's literally just swapping one line for another. And you will still be able to use the fix before I release the version, using a specific build version that I will upload here

iGabyTM commented 2 years ago

Thank you sir 🎩

iGabyTM commented 2 years ago

@DevNatan is possible to set the source on onOpen? I need to filter some lists and combine the result, then I need to know if the final list has any object and set it as a context variable which I access later on onRender. Calling context.paginated() throws a class cast exception because BukkitOpenViewContext can not be casted as a PaginatedViewContext.

DevNatan commented 2 years ago

@DevNatan is possible to set the source on onOpen? I need to filter some lists and combine the result, then I need to know if the final list has any object and set it as a context variable which I access later on onRender. Calling context.paginated() throws a class cast exception because BukkitOpenViewContext can not be casted as a PaginatedViewContext.

You can do this in onRender, it's only called once.

It is not possible to set the pagination data in onOpen because nothing was dealt with at that point, it is only used to prepopulate inventory information like title and size or cancel its opening, but yes, you can define context data in onOpen and they will be accessible in onRender.

It is common to do this type of code to save computation

override fun onOpen(ctx: ViewContext) {
    val profile = getProfileSomehow<Profile>("iGabyTM")
    if (profile == null) {
        ctx.setCancelled(true)
        ctx.player.sendMessage("Cannot find profile of iGabyTM :(")
        return
    }

    ctx.setInventoryTitle("Profile of %s".format(profile.owner))
    ctx.set("profile", profile)
}

override fun onRender(ctx: ViewContext) {
    val profile = ctx.get<Profile>("profile")

    ctx.paginated().setSource(() -> profile.getStatistics() /* imagine this is a list */)
}
DevNatan commented 2 years ago

@iGabyTM Please try to use 4ba907ff90 version and check if your bug was fixed also if you need a executable plugin, get it here https://github.com/DevNatan/inventory-framework/actions/runs/3153688855 (#248) (scroll down to Artifacts)

iGabyTM commented 2 years ago

Will test this version a bit later, thank you!

iGabyTM commented 2 years ago

Hmm, so with this layout and 2 items to show, it displays the "no next page" item @DevNatan.

layout:
  - "---------"
  - "[---O---]"
  - "---------"

image

[20:18:04 INFO]: [ClaimCommons] [STDOUT] called pattern get factory ViewItem(item=ItemStack{GRAY_STAINED_GLASS_PANE x 1, UNSPECIFIC_META:{meta-type=UNSPECIFIC, display-name={"extra":[{"text":" "}],"text":""}, custom-model-data=0}}, slot=-1, state=UNDEFINED, paginationItem=false, navigationItem=false, referenceKey=null, closeOnClick=false, cancelOnClick=false, cancelOnShiftClick=false, renderHandler=null, updateHandler=null, clickHandler=null, moveInHandler=null, moveOutHandler=null, itemHoldHandler=null, itemReleaseHandler=null, data=null, updateIntervalInTicks=-3, overlay=null, removed=false)
[20:18:04 INFO]: [ClaimCommons] [STDOUT] called pattern get factory ViewItem(item=ItemStack{RED_STAINED_GLASS_PANE x 1, UNSPECIFIC_META:{meta-type=UNSPECIFIC, display-name={"extra":[{"bold":false,"italic":false,"underlined":false,"strikethrough":false,"obfuscated":false,"color":"red","text":"Previous Menu"}],"text":""}, custom-model-data=0}}, slot=-1, state=UNDEFINED, paginationItem=false, navigationItem=false, referenceKey=null, closeOnClick=false, cancelOnClick=false, cancelOnShiftClick=false, renderHandler=null, updateHandler=null, clickHandler=me.gabytm.minecraftc.claimcommons.menu.util.ViewUtil$$Lambda$7295/0x0000000801fcf088@120cc078, moveInHandler=null, moveOutHandler=null, itemHoldHandler=null, itemReleaseHandler=null, data=null, updateIntervalInTicks=-3, overlay=null, removed=false)
[20:18:04 INFO]: [ClaimCommons] [STDOUT] called pattern get factory ViewItem(item=ItemStack{BLACK_STAINED_GLASS_PANE x 1, UNSPECIFIC_META:{meta-type=UNSPECIFIC, display-name={"extra":[{"bold":false,"italic":false,"underlined":false,"strikethrough":false,"obfuscated":false,"color":"gray","text":"No Next Page"}],"text":""}, custom-model-data=0}}, slot=-1, state=UNDEFINED, paginationItem=false, navigationItem=false, referenceKey=null, closeOnClick=false, cancelOnClick=false, cancelOnShiftClick=false, renderHandler=null, updateHandler=null, clickHandler=me.gabytm.minecraftc.claimcommons.menu.util.ViewUtil$$Lambda$7296/0x0000000801fcf2b8@e9023e9, moveInHandler=null, moveOutHandler=null, itemHoldHandler=null, itemReleaseHandler=null, data=null, updateIntervalInTicks=-3, overlay=null, removed=false)
DevNatan commented 2 years ago

Hmm, so with this layout and 2 items to show, it displays the "no next page" item @DevNatan.

...

@iGabyTM are you using setLayout with "onRender" or without?

setLayout is just a factory, it is only called once on Layout Resolution pipeline phase and applied to context, later Render pipeline phase reuse this manufactured value, so it will always be the same item.

when an update occurs (like change page), only dynamic items (that have onRender or onUpdate) will be re-computed, for performance reasons, so it is necessary to use them.

So if you use, this way nothing will happen since this function is just a factory and not a computed value


context.setLayout('[', item ->
    // just an item with fallback become a static item 
    item.withItem(
        context.paginated().hasNextPage() ? A : B
    )
)

to make your item become dynamic and react to updates such as page switches you need to use the render function

// on constructor
setLayout('[', item -> 
    // render function found, is defined as dynamically rendered item
    item.onRender(render -> render.setItem(
      context.paginated().hasNextPage() ? A : B
    ))
)

you can also use the rendered shortcut if you already have access to the context

// on "onRender"
context.setLayout('[', item -> item.rendered(() ->
  context.paginated().hasNextPage() ? A : B
))

so it will work this way:

context.setLayout('[', item -> item.rendered(() -> 
    context.paginated().hasNextPage() ? WHITE_GLASS_PANE : RED_GLASS_PANE
))

https://user-images.githubusercontent.com/24600258/193425628-0d1a1a2f-49b0-459e-82a6-ea6efdad9253.mp4

iGabyTM commented 2 years ago
public static void setPaginationItems(
        @NotNull final PaginatedViewContext<Object> context, @NotNull final PaginatedMenuConfig config,
        @NotNull final Consumer<ViewSlotClickContext> previousPageClickHandler, @NotNull final Consumer<ViewSlotClickContext> nextPageClickHandler
) {
    context.setLayout(config.getLayout());
    context.setLayout('-', item -> item.setItem(config.getFiller().getItemStack()));
    context.setLayout('[', item ->
            item.rendered(() -> config.previousPageItem(context.hasPreviousPage()).getItemStack())
                    .onClick(previousPageClickHandler)
    );
    context.setLayout(']', item ->
            item.rendered(() -> config.nextPageItem(context.hasNextPage()).getItemStack())
                    .onClick(nextPageClickHandler)
    );
}

So I call this method on onRender and I still see the no next page item 😕

iGabyTM commented 2 years ago

Also, is this some debugging left in code?

[20:18:04 INFO]: [ClaimCommons] [STDOUT] called pattern get factory ViewItem(item=ItemStack{GRAY_STAINED_GLASS_PANE x 1, UNSPECIFIC_META:{meta-type=UNSPECIFIC, display-name={"extra":[{"text":" "}],"text":""}, custom-model-data=0}}, slot=-1, state=UNDEFINED, paginationItem=false, navigationItem=false, referenceKey=null, closeOnClick=false, cancelOnClick=false, cancelOnShiftClick=false, renderHandler=null, updateHandler=null, clickHandler=null, moveInHandler=null, moveOutHandler=null, itemHoldHandler=null, itemReleaseHandler=null, data=null, updateIntervalInTicks=-3, overlay=null, removed=false)
[20:18:04 INFO]: [ClaimCommons] [STDOUT] called pattern get factory ViewItem(item=ItemStack{RED_STAINED_GLASS_PANE x 1, UNSPECIFIC_META:{meta-type=UNSPECIFIC, display-name={"extra":[{"bold":false,"italic":false,"underlined":false,"strikethrough":false,"obfuscated":false,"color":"red","text":"Previous Menu"}],"text":""}, custom-model-data=0}}, slot=-1, state=UNDEFINED, paginationItem=false, navigationItem=false, referenceKey=null, closeOnClick=false, cancelOnClick=false, cancelOnShiftClick=false, renderHandler=null, updateHandler=null, clickHandler=me.gabytm.minecraftc.claimcommons.menu.util.ViewUtil$$Lambda$7295/0x0000000801fcf088@120cc078, moveInHandler=null, moveOutHandler=null, itemHoldHandler=null, itemReleaseHandler=null, data=null, updateIntervalInTicks=-3, overlay=null, removed=false)
[20:18:04 INFO]: [ClaimCommons] [STDOUT] called pattern get factory ViewItem(item=ItemStack{BLACK_STAINED_GLASS_PANE x 1, UNSPECIFIC_META:{meta-type=UNSPECIFIC, display-name={"extra":[{"bold":false,"italic":false,"underlined":false,"strikethrough":false,"obfuscated":false,"color":"gray","text":"No Next Page"}],"text":""}, custom-model-data=0}}, slot=-1, state=UNDEFINED, paginationItem=false, navigationItem=false, referenceKey=null, closeOnClick=false, cancelOnClick=false, cancelOnShiftClick=false, renderHandler=null, updateHandler=null, clickHandler=me.gabytm.minecraftc.claimcommons.menu.util.ViewUtil$$Lambda$7296/0x0000000801fcf2b8@e9023e9, moveInHandler=null, moveOutHandler=null, itemHoldHandler=null, itemReleaseHandler=null, data=null, updateIntervalInTicks=-3, overlay=null, removed=false)
iGabyTM commented 2 years ago

Hey @DevNatan any idea?

DevNatan commented 2 years ago

Hey @DevNatan any idea?

sorry for the late reply, i'm traveling, try updating to the latest version to see if your issue is resolved

iGabyTM commented 2 years ago

@DevNatan with https://github.com/DevNatan/inventory-framework/tree/d7705792e992a05f79199e10b76179ad76d893a4 now I get this error for any paginated view :(

java.lang.IllegalStateException: Paginator source cannot be null (page size = 44, factory = net.stonegomes.towny.menu.subview.member.MemberPaginatedView$$Lambda$5904/0x0000000801d3dfe8@51102b1d, is provided = true)
    at me.saiintbrisson.minecraft.Paginator.checkSource(Paginator.java:131) ~[ClaimCommons-1.0.1.jar:?]
    at me.saiintbrisson.minecraft.Paginator.hasPage(Paginator.java:64) ~[ClaimCommons-1.0.1.jar:?]
    at me.saiintbrisson.minecraft.BasePaginatedViewContext.hasNextPage(BasePaginatedViewContext.java:79) ~[ClaimCommons-1.0.1.jar:?]
    at me.gabytm.minecraftc.claimcommons.menu.util.ViewUtil.lambda$setPaginationItems$5(ViewUtil.java:63) ~[ClaimCommons-1.0.1.jar:?]
    at me.saiintbrisson.minecraft.ViewItem.lambda$rendered$0(ViewItem.java:395) ~[ClaimCommons-1.0.1.jar:?]
    at me.saiintbrisson.minecraft.AbstractView.lambda$triggerSlotRender$4(AbstractView.java:720) ~[ClaimCommons-1.0.1.jar:?]
    at me.saiintbrisson.minecraft.AbstractVirtualView.runCatching(AbstractVirtualView.java:342) ~[ClaimCommons-1.0.1.jar:?]
    at me.saiintbrisson.minecraft.AbstractView.triggerSlotRender(AbstractView.java:720) ~[ClaimCommons-1.0.1.jar:?]
    at me.saiintbrisson.minecraft.AbstractView.render(AbstractView.java:752) ~[ClaimCommons-1.0.1.jar:?]
    at me.saiintbrisson.minecraft.pipeline.interceptors.LayoutPatternRenderInterceptor.intercept(LayoutPatternRenderInterceptor.java:32) ~[ClaimCommons-1.0.1.jar:?]
    at me.saiintbrisson.minecraft.pipeline.interceptors.LayoutPatternRenderInterceptor.intercept(LayoutPatternRenderInterceptor.java:13) ~[ClaimCommons-1.0.1.jar:?]
    at me.saiintbrisson.minecraft.pipeline.PipelineContext.loop(PipelineContext.java:39) ~[ClaimCommons-1.0.1.jar:?]
    at me.saiintbrisson.minecraft.pipeline.PipelineContext.proceed(PipelineContext.java:49) ~[ClaimCommons-1.0.1.jar:?]
    at me.saiintbrisson.minecraft.pipeline.PipelineContext.execute(PipelineContext.java:55) ~[ClaimCommons-1.0.1.jar:?]
    at me.saiintbrisson.minecraft.pipeline.Pipeline.execute(Pipeline.java:116) ~[ClaimCommons-1.0.1.jar:?]
    at me.saiintbrisson.minecraft.AbstractView.lambda$render$0(AbstractView.java:317) ~[ClaimCommons-1.0.1.jar:?]
    at me.saiintbrisson.minecraft.AbstractVirtualView.runCatching(AbstractVirtualView.java:342) ~[ClaimCommons-1.0.1.jar:?]
    at me.saiintbrisson.minecraft.AbstractView.render(AbstractView.java:315) ~[ClaimCommons-1.0.1.jar:?]
    at me.saiintbrisson.minecraft.pipeline.interceptors.OpenInterceptor.finishOpen(OpenInterceptor.java:74) ~[ClaimCommons-1.0.1.jar:?]
    at me.saiintbrisson.minecraft.pipeline.interceptors.OpenInterceptor.intercept(OpenInterceptor.java:30) ~[ClaimCommons-1.0.1.jar:?]
    at me.saiintbrisson.minecraft.pipeline.interceptors.OpenInterceptor.intercept(OpenInterceptor.java:19) ~[ClaimCommons-1.0.1.jar:?]
    at me.saiintbrisson.minecraft.pipeline.PipelineContext.loop(PipelineContext.java:39) ~[ClaimCommons-1.0.1.jar:?]
    at me.saiintbrisson.minecraft.pipeline.PipelineContext.proceed(PipelineContext.java:49) ~[ClaimCommons-1.0.1.jar:?]
    at me.saiintbrisson.minecraft.pipeline.PipelineContext.execute(PipelineContext.java:55) ~[ClaimCommons-1.0.1.jar:?]
    at me.saiintbrisson.minecraft.pipeline.Pipeline.execute(Pipeline.java:116) ~[ClaimCommons-1.0.1.jar:?]
    at me.saiintbrisson.minecraft.AbstractView.open(AbstractView.java:308) ~[ClaimCommons-1.0.1.jar:?]
    at me.saiintbrisson.minecraft.ViewFrame.lambda$open$0(ViewFrame.java:255) ~[ClaimCommons-1.0.1.jar:?]
    at org.bukkit.craftbukkit.v1_19_R1.scheduler.CraftTask.run(CraftTask.java:101) ~[paper-1.19.2.jar:git-Paper-134]
    at org.bukkit.craftbukkit.v1_19_R1.scheduler.CraftScheduler.mainThreadHeartbeat(CraftScheduler.java:483) ~[paper-1.19.2.jar:git-Paper-134]
    at net.minecraft.server.MinecraftServer.tickChildren(MinecraftServer.java:1493) ~[paper-1.19.2.jar:git-Paper-134]
    at net.minecraft.server.dedicated.DedicatedServer.tickChildren(DedicatedServer.java:446) ~[paper-1.19.2.jar:git-Paper-134]
    at net.minecraft.server.MinecraftServer.tickServer(MinecraftServer.java:1417) ~[paper-1.19.2.jar:git-Paper-134]
    at net.minecraft.server.MinecraftServer.runServer(MinecraftServer.java:1193) ~[paper-1.19.2.jar:git-Paper-134]
    at net.minecraft.server.MinecraftServer.lambda$spin$0(MinecraftServer.java:305) ~[paper-1.19.2.jar:git-Paper-134]
    at java.lang.Thread.run(Thread.java:833) ~[?:?]
iGabyTM commented 1 year ago

Hey @DevNatan, I've updated to ae6b07b0b98ce1233f5c9fb0cdb10a64c8d68864 and I'm still not able to get this code working, any ideas?

Click for code > Menu ```java // Constructor setSource(context -> (Towny) context.get("towny")).getClaims()); @Override protected void onOpen(@NotNull OpenViewContext context) { final var config = ViewModule.getConfigManager().getConfig(ClaimPaginatedMenuConfig.class); context.setContainerSize(config.getLayout().length); context.setContainerTitle(config.getTitle()); } @Override protected void onRender(ViewContext context) { final var config = ViewModule.getConfigManager().getConfig(ClaimPaginatedMenuConfig.class); ViewUtil.setPaginationItems(context.paginated(), config, viewFrame, MainView.class); if (((Towny) context.get("towny")).getClaims().isEmpty()) { config.noValuesItem().forEachSlot((slot, item) -> context.slot(slot, item.getItemStack())); } ViewUtil.setDecorations(context, config); } ``` > ViewUtil ```java public static void setPaginationItems( @NotNull final PaginatedViewContext context, @NotNull final PaginatedMenuConfig config, @NotNull final Consumer previousPageClickHandler, @NotNull final Consumer nextPageClickHandler ) { context.setLayout(config.getLayout()); context.setLayout('-', item -> item.rendered(() -> config.getFiller().getItemStack())); context.setLayout('[', item -> item.rendered(() -> config.previousPageItem(context.hasPreviousPage()).getItemStack()) .onClick(previousPageClickHandler) ); context.setLayout(']', item -> item.rendered(() -> config.nextPageItem(context.hasNextPage()).getItemStack()) .onClick(nextPageClickHandler) ); } public static void setPaginationItems( @NotNull final PaginatedViewContext context, @NotNull final PaginatedMenuConfig config, @NotNull final ViewFrame viewFrame, @NotNull final Class mainView ) { setPaginationItems( context, config, // I've tried to use this context, maybe that's the problem 🤷‍♂️ ctx -> { var paginated = ctx.paginated(); if (paginated.isFirstPage()) { viewFrame.open(mainView, paginated.getPlayer(), paginated.getData()); } else { paginated.switchToPreviousPage(); } }, ctx -> ctx.paginated().switchToNextPage() ); } ```
DevNatan commented 1 year ago

@iGabyTM i already found the problem, the pagination source check is not compatible with dynamic or asynchronous pagination yet, i already prepared a fix for this should be in main branch soon.

DevNatan commented 1 year ago

@iGabyTM I tried to reproduce your code and it worked. Try using the version of #254 and see if it gives any problems

class Test extends PaginatedView<Integer> {

    public Test() {
        super(3);
        setSource($ -> IntStream.rangeClosed(1, 100).boxed().collect(Collectors.toList()));
    }

    @Override
    protected void onRender(@NotNull ViewContext context) {
        context.setLayout("XXXXXXXXX", "[OOOOOOO]", "XXXXXXXXX");
        context.setLayout(']', item -> {
            item.rendered(() -> {
                // breakpoint maybe
                context.paginated().hasPreviousPage();
                return new ItemStack(Material.ARROW);
            });
        });
        context.setLayout('[', item -> {
            item.rendered(() -> {
                // breakpoint maybe
                context.paginated().hasNextPage();
                return new ItemStack(Material.ARROW);
            });
        });
    }

    @Override
    protected void onItemRender(
            @NotNull PaginatedViewSlotContext<Integer> context, @NotNull ViewItem viewItem, @NotNull Integer value) {
        viewItem.withItem(new ItemStack(Material.DIAMOND));
    }
}
iGabyTM commented 1 year ago

Huh, how do I use that version? Could not resolve: com.github.DevNatan:inventory-framework:fix~provided-source-check-SNAPSHOT

DevNatan commented 1 year ago

Huh, how do I use that version? Could not resolve: com.github.DevNatan:inventory-framework:fix~provided-source-check-SNAPSHOT

Last commit short id eb184e5f8c as version

iGabyTM commented 1 year ago

I got it, thanks. I've tried the same code as yours and I still can't see the next page button..

DevNatan commented 1 year ago

I got it, thanks. I've tried the same code as yours and I still can't see the next page button..

are you getting an error or is the code just not working?

iGabyTM commented 1 year ago

No, I'm not getting errors. Is there a method I can use to check how many items fit in a page? I see that you are testing with 100 items and I got only a small amount of items

DevNatan commented 1 year ago

No, I'm not getting errors. Is there a method I can use to check how many items fit in a page? I see that you are testing with 100 items and I got only a small amount of items

few, but some are only accurate if you have context available, u can use getSource().size(), getPageSize() or getPageMaxItemsCount() they have slightly different behaviors, in the documentation it is written what each one returns maybe it can be useful.

iGabyTM commented 1 year ago

context.paginated().getPageSize() = 44, the default size is set to 5 trough the super() constructor but on onOpen I have context.setContainerSize(config.getLayout().length); And I can't access getPageMaxItemsCount() because of this error https://paste.helpch.at/topafevago.rb

DevNatan commented 1 year ago

context.paginated().getPageSize() = 44, the default size is set to 5 trough the super() constructor but on onOpen I have context.setContainerSize(config.getLayout().length); And I can't access getPageMaxItemsCount() because of this error https://paste.helpch.at/topafevago.rb

weird, layout resolution should happen before rendering and this error shouldn't happen. Apparently the values are wrong due to the definition of the container in onOpen, i'll analyze

iGabyTM commented 1 year ago

Hey @DevNatan any updates?

WizWazWizard commented 1 year ago

Any Updates on the matter? Need this fixed asap :/

iGabyTM commented 1 year ago

@DevNatan 😬

iGabyTM commented 1 year ago

@DevNatan do you think you can update us on this? :(

iGabyTM commented 1 year ago

@DevNatan ?

DevNatan commented 1 year ago

@iGabyTM we have a major version under development, this issue is already planned to be fixed in v3.0.0, I don't have time to code inventory-framework lately so please be patient, i'm doing the best i can. more info will come soon.

and I will also give you a mirror code from your version to the new version since some things have changed

WizWazWizard commented 1 year ago

@iGabyTM we have a major version under development, this issue is already planned to be fixed in v3.0.0, I don't have time to code inventory-framework lately so please be patient, i'm doing the best i can. more info will come soon.

and I will also give you a mirror code from your version to the new version since some things have changed

Any luck on this???

DevNatan commented 1 year ago

@iGabyTM we have a major version under development, this issue is already planned to be fixed in v3.0.0, I don't have time to code inventory-framework lately so please be patient, i'm doing the best i can. more info will come soon. and I will also give you a mirror code from your version to the new version since some things have changed

Any luck on this???

Expected to be released in the first week of April, code itself appears to be finished there are still some tests left. I'm just finishing up fully updating the Wiki before releasing it. Some PRs #328, #262, #322 remaining as well.

iGabyTM commented 1 year ago

@DevNatan I don't want to be rude but it is 1st of May, any news on the update?

DevNatan commented 1 year ago

@DevNatan I don't want to be rude but it is 1st of May, any news on the update?

Yes, there was a 3.0.0 version, but several problems were found mainly in relation to the integration in projects of different JDKs since the entire Inventory Framework project was updated, which is already being resolved.

Some features that existed in the previous version and would not exist more in this new version will be brought back, some people complained about it.

There is a todo roadmap for a preview release or beta #370

WizWazWizard commented 1 year ago

Any luck? Been waiting 3 months for this one fix :/

DevNatan commented 1 year ago

Any luck? Been waiting 3 months for this one fix :/

Yeah, v3.0.0-EAP is available but not production ready. But I will keep this issue open until the definitive v3.0.0 is released.

WizWazWizard commented 1 year ago

Awesome! Could you add me on discord so I can give you direct contact with a developer? Mainly to look over the changes in the library :)

Discord: silenttail

iGabyTM commented 1 year ago

@DevNatan I've noticed that the version that contains the fix for this issue is a major release with a lot of API changes. I was wondering if you could help us fix the issue without updating to v3 because that involves a lot of work to update all the menus we have. I'm not experienced enough with this library, I just continue the work of another developer that I sadly can not contact. Is there any way to create some sort of fake pagination with normal GUIs, where each page is a different GUI?

WizWazWizard commented 1 year ago

DevNatan?

WizWazWizard commented 1 year ago

Hiya, an luck? Been an extra month and I haven't heard or seen any updates around this issue? I understand you may be busy, but this issue was reported on Sep 27, 2022. Its now August 26th 2023, almost a whole year?

WizWazWizard commented 11 months ago

Any luck? Been waiting 3 months for this one fix :/

Yeah, v3.0.0-EAP is available but not production ready. But I will keep this issue open until the definitive v3.0.0 is released.

This is kinda ridiculous.. Its almost been 2 years..

DevNatan commented 11 months ago

Please update to version 3. It is extremely similar and simpler. I no longer support version 2