From 5d6cf245826b102330b815fd2b334447a45e84f3 Mon Sep 17 00:00:00 2001 From: Quentin Legot Date: Fri, 24 Mar 2023 18:41:36 +0100 Subject: [PATCH] Change values in PaginatedContentfrom String to Text for future updates Signed-off-by: Quentin Legot --- .../toolbox/pagination/PaginatedContent.java | 18 +++++++++--------- .../toolbox/pagination/api/PaginationApi.java | 5 +++-- .../pagination/api/PaginationApiImpl.java | 5 +++-- .../pagination/command/CommandsRegister.java | 2 +- 4 files changed, 16 insertions(+), 14 deletions(-) diff --git a/Pagination/src/main/java/fr/altarik/toolbox/pagination/PaginatedContent.java b/Pagination/src/main/java/fr/altarik/toolbox/pagination/PaginatedContent.java index 95ac763..23fb640 100644 --- a/Pagination/src/main/java/fr/altarik/toolbox/pagination/PaginatedContent.java +++ b/Pagination/src/main/java/fr/altarik/toolbox/pagination/PaginatedContent.java @@ -14,7 +14,7 @@ import java.util.stream.Stream; public class PaginatedContent { private final List pages; - private final String header; + private final Text header; public PaginatedContent(String header, String content) { this.header = buildHeader(header); @@ -29,11 +29,11 @@ public class PaginatedContent { } } int line = 0; - List currentPage = new ArrayList<>(); + List currentPage = new ArrayList<>(); for(String elem : secondSplit) { line++; if(!elem.isEmpty()) - currentPage.add(elem); + currentPage.add(Text.literal(elem)); if(line == 8 || elem.isEmpty()) { pages.add(new Page(currentPage)); line = 0; @@ -43,9 +43,9 @@ public class PaginatedContent { pages.add(new Page(currentPage)); } - private String buildHeader(String header) { + private Text buildHeader(String header) { int numberOfEq = (50 - header.length()) / 2; - return "=".repeat(numberOfEq) + header + "=".repeat(numberOfEq); + return Text.literal("=".repeat(numberOfEq) + header + "=".repeat(numberOfEq)); } public void display(ServerPlayerEntity playerEntity, int page) { @@ -54,9 +54,9 @@ public class PaginatedContent { } else if(page < 0) { throw new IllegalArgumentException("argument page is lower than 0"); } else { - playerEntity.sendMessage(Text.literal(header)); - for(String s : pages.get(page).lines) { - playerEntity.sendMessage(Text.literal(s)); + playerEntity.sendMessage(header); + for(Text s : pages.get(page).lines) { + playerEntity.sendMessage(s); } playerEntity.sendMessage(buildFooter(page)); @@ -87,7 +87,7 @@ public class PaginatedContent { ); } - private record Page(List lines) { + private record Page(List lines) { } } diff --git a/Pagination/src/main/java/fr/altarik/toolbox/pagination/api/PaginationApi.java b/Pagination/src/main/java/fr/altarik/toolbox/pagination/api/PaginationApi.java index 34f8f23..eb5297b 100644 --- a/Pagination/src/main/java/fr/altarik/toolbox/pagination/api/PaginationApi.java +++ b/Pagination/src/main/java/fr/altarik/toolbox/pagination/api/PaginationApi.java @@ -2,7 +2,6 @@ package fr.altarik.toolbox.pagination.api; import net.minecraft.server.network.ServerPlayerEntity; -@SuppressWarnings("unused") // Api usage public interface PaginationApi { /** @@ -15,13 +14,15 @@ public interface PaginationApi { *

Special values are: *

  • null if you doesn't want to add a header
  • *
  • empty String if you want just the header to be filled only with "="
+ * @param display true if you want the message to be displayed now, false otherwise if you want to display the + * message yourself * @throws IllegalArgumentException if one of its conditions is met:
    *
  1. header length is more than 50 characters
  2. *
  3. content is empty/blank
  4. *
  5. playerEntity or content are null
  6. *
*/ - void createTable(ServerPlayerEntity playerEntity, String content, String header); + void createTable(ServerPlayerEntity playerEntity, String content, String header, boolean display); /** * Display the given page for the given player diff --git a/Pagination/src/main/java/fr/altarik/toolbox/pagination/api/PaginationApiImpl.java b/Pagination/src/main/java/fr/altarik/toolbox/pagination/api/PaginationApiImpl.java index 8a2abf9..5a62fb4 100644 --- a/Pagination/src/main/java/fr/altarik/toolbox/pagination/api/PaginationApiImpl.java +++ b/Pagination/src/main/java/fr/altarik/toolbox/pagination/api/PaginationApiImpl.java @@ -29,13 +29,14 @@ public class PaginationApiImpl implements PaginationApi { } @Override - public void createTable(ServerPlayerEntity playerEntity, String content, String header) { + public void createTable(ServerPlayerEntity playerEntity, String content, String header, boolean display) { if(playerCondition.test(playerEntity) || headerCondition.test(header) || contentCondition.test(content)) { throw new IllegalArgumentException("Preconditions aren't satisfied"); } PaginatedContent paginatedContent1 = new PaginatedContent(header, content); paginatedContent.put(playerEntity, new Pair<>(18000, paginatedContent1)); - paginatedContent1.display(playerEntity, 0); + if(display) + paginatedContent1.display(playerEntity, 0); } @Override diff --git a/Pagination/src/main/java/fr/altarik/toolbox/pagination/command/CommandsRegister.java b/Pagination/src/main/java/fr/altarik/toolbox/pagination/command/CommandsRegister.java index 8c32487..58642c4 100644 --- a/Pagination/src/main/java/fr/altarik/toolbox/pagination/command/CommandsRegister.java +++ b/Pagination/src/main/java/fr/altarik/toolbox/pagination/command/CommandsRegister.java @@ -52,7 +52,7 @@ public class CommandsRegister { third page dqdqd dqdqd - d""", "My header"); + d""", "My header", true); return 0; }