pagination #10
@ -32,6 +32,7 @@ public class PaginatedContent {
|
|||||||
List<String> currentPage = new ArrayList<>();
|
List<String> currentPage = new ArrayList<>();
|
||||||
for(String elem : secondSplit) {
|
for(String elem : secondSplit) {
|
||||||
line++;
|
line++;
|
||||||
|
if(!elem.isEmpty())
|
||||||
currentPage.add(elem);
|
currentPage.add(elem);
|
||||||
if(line == 8 || elem.isEmpty()) {
|
if(line == 8 || elem.isEmpty()) {
|
||||||
pages.add(new Page(currentPage));
|
pages.add(new Page(currentPage));
|
||||||
@ -39,11 +40,12 @@ public class PaginatedContent {
|
|||||||
currentPage = new ArrayList<>();
|
currentPage = new ArrayList<>();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
pages.add(new Page(currentPage));
|
||||||
}
|
}
|
||||||
|
|
||||||
public void display(ServerPlayerEntity playerEntity, int page) {
|
public void display(ServerPlayerEntity playerEntity, int page) {
|
||||||
if(page >= this.pages.size()) {
|
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) {
|
} else if(page < 0) {
|
||||||
throw new IllegalArgumentException("argument page is lower than 0");
|
throw new IllegalArgumentException("argument page is lower than 0");
|
||||||
} else {
|
} else {
|
||||||
|
@ -26,10 +26,36 @@ public class CommandsRegister {
|
|||||||
.then(argument("page", IntegerArgumentType.integer())
|
.then(argument("page", IntegerArgumentType.integer())
|
||||||
.executes(this::selectPageCommand)
|
.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 {
|
private int selectPageCommand(CommandContext<ServerCommandSource> context) throws CommandSyntaxException {
|
||||||
try {
|
try {
|
||||||
int page = IntegerArgumentType.getInteger(context, "page");
|
int page = IntegerArgumentType.getInteger(context, "page");
|
||||||
|
Loading…
Reference in New Issue
Block a user