inventory-framework
inventory-framework copied to clipboard
check if there is an item in the layout and if not, set a barrier
I wanted to know if it is possible to check if there is an item in the layout and if not, define a barrier
`
private final State<Pagination> paginationState = lazyPaginationState(
(context) -> getBosses(),
(context, item, index, bossType) -> item.withItem(
new ItemBuilder(bossType.getIcon().clone())
.amount(1)
.lore(
"§7Está área de bosses tem",
"§7o nível para este boss.",
"",
" §fVida: §c❤" + NumberFormatter.format(bossType.getLife()),
" §7#" + bossType.getRewards().size() + " recompensas.",
"",
"§eClique para ver as recompensas."
).build()
).onClick(click -> click.openForPlayer(RewardsView.class,
ImmutableMap.of("boss_type", bossType))));
@Override
public void onInit(@NotNull ViewConfigBuilder config) {
config.cancelOnPickup()
.size(6)
.title("Área de boss")
.cancelOnDrag()
.cancelOnClick()
.cancelOnDrop()
.layout(
" ",
" OOO ",
" OOO ",
" ",
" ",
" "
);
}
@Override
public void onFirstRender(@NotNull RenderContext render) {
final Pagination pagination = paginationState.get(render);
// verify not has item in pagination
-> BARRIER ITEM
}
public List<BossType> getBosses() {
return plugin.getBossTypeCache().getCachedElements();
}
}
`
You can check getBosses()
in onFirstRender
and set it.
If it is necessary in the same slots defined in the paginationState
, the ideal is to have a Boolean
to use .displayIf
within the pagination, this way, you can define several ItemStack
in the pagination.