pagination #10
@ -32,6 +32,7 @@ public class PaginatedContent {
|
||||
List<String> currentPage = new ArrayList<>();
|
||||
for(String elem : secondSplit) {
|
||||
line++;
|
||||
if(!elem.isEmpty())
|
||||
currentPage.add(elem);
|
||||
if(line == 8 || elem.isEmpty()) {
|
||||
pages.add(new Page(currentPage));
|
||||
@ -39,11 +40,12 @@ public class PaginatedContent {
|
||||
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 {
|
||||
|
@ -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");
|
||||
|
Loading…
Reference in New Issue
Block a user