Added a test command and made some fixes

Signed-off-by: Quentin Legot <legotquentin@gmail.com>
This commit is contained in:
Quentin Legot 2023-03-23 01:52:02 +01:00
parent f2359c75f4
commit 5992aaa5a0
2 changed files with 30 additions and 2 deletions

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");