pagination #10

Merged
quentinlegot merged 7 commits from pagination into dev 2023-03-23 02:16:31 +01:00
2 changed files with 30 additions and 2 deletions
Showing only changes of commit 5992aaa5a0 - Show all commits

View File

@ -32,18 +32,20 @@ public class PaginatedContent {
List<String> currentPage = new ArrayList<>();
for(String elem : secondSplit) {
line++;
currentPage.add(elem);
if(!elem.isEmpty())
currentPage.add(elem);
if(line == 8 || elem.isEmpty()) {
pages.add(new Page(currentPage));
line = 0;
currentPage = new ArrayList<>();
}
}
pages.add(new Page(currentPage));
}
public void display(ServerPlayerEntity playerEntity, int page) {
if(page >= this.pages.size()) {
throw new IllegalArgumentException("There's " + this.pages.size() + " paginated pages but you wanted page n°" + page);
throw new IllegalArgumentException("There's " + this.pages.size() + " paginated pages but you wanted page n°" + (page + 1));
} else if(page < 0) {
throw new IllegalArgumentException("argument page is lower than 0");
} else {

View File

@ -26,10 +26,36 @@ public class CommandsRegister {
.then(argument("page", IntegerArgumentType.integer())
.executes(this::selectPageCommand)
)
).then(literal("test")
.requires(source -> source.isExecutedByPlayer() && source.hasPermissionLevel(3))
.executes(this::testPageCommand)
)
);
}
/**
* Simply a debug command
*/
private int testPageCommand(CommandContext<ServerCommandSource> context) {
api.createTable(context.getSource().getPlayer(), """
first line
Second line
second page
dqdq
dqdqd
qdqdq
dqdq
dqdq
dqdq
dqdqd
third page
dqdqd
dqdqd
d""", "My header");
return 0;
}
private int selectPageCommand(CommandContext<ServerCommandSource> context) throws CommandSyntaxException {
try {
int page = IntegerArgumentType.getInteger(context, "page");