From 24564362ec120aaf87d699386b0c2d7b0a66516d Mon Sep 17 00:00:00 2001 From: Quentin Legot Date: Wed, 1 Mar 2023 23:21:59 +0100 Subject: [PATCH] Add pagination components Signed-off-by: Quentin Legot --- .gitignore | 2 +- Pagination/build.gradle | 44 ++++++++++++++++++ .../toolbox/pagination/PaginatedContent.java | 4 ++ .../toolbox/pagination/Pagination.java | 32 +++++++++++++ .../toolbox/pagination/api/PaginationApi.java | 26 +++++++++++ .../pagination/api/PaginationApiImpl.java | 18 +++++++ .../pagination/command/CommandsRegister.java | 20 ++++++++ .../src/main/resources/Pagination.mixins.json | 14 ++++++ .../main/resources/assets/pagination/icon.png | Bin 0 -> 3805 bytes Pagination/src/main/resources/fabric.mod.json | 33 +++++++++++++ .../src/main/resources/assets/tasks/icon.png | Bin 0 -> 3805 bytes Tasks/src/main/resources/fabric.mod.json | 2 +- gradle.properties | 4 +- settings.gradle | 2 +- 14 files changed, 196 insertions(+), 5 deletions(-) create mode 100644 Pagination/build.gradle create mode 100644 Pagination/src/main/java/fr/altarik/toolbox/pagination/PaginatedContent.java create mode 100644 Pagination/src/main/java/fr/altarik/toolbox/pagination/Pagination.java create mode 100644 Pagination/src/main/java/fr/altarik/toolbox/pagination/api/PaginationApi.java create mode 100644 Pagination/src/main/java/fr/altarik/toolbox/pagination/api/PaginationApiImpl.java create mode 100644 Pagination/src/main/java/fr/altarik/toolbox/pagination/command/CommandsRegister.java create mode 100644 Pagination/src/main/resources/Pagination.mixins.json create mode 100644 Pagination/src/main/resources/assets/pagination/icon.png create mode 100644 Pagination/src/main/resources/fabric.mod.json create mode 100644 Tasks/src/main/resources/assets/tasks/icon.png diff --git a/.gitignore b/.gitignore index 5f60383..521e14b 100644 --- a/.gitignore +++ b/.gitignore @@ -4,7 +4,7 @@ build/ !**/src/main/**/build/ !**/src/test/**/build/ -Tasks/run +*/run ### IntelliJ IDEA ### .idea diff --git a/Pagination/build.gradle b/Pagination/build.gradle new file mode 100644 index 0000000..590944e --- /dev/null +++ b/Pagination/build.gradle @@ -0,0 +1,44 @@ +plugins { + id 'fabric-loom' version '1.1-SNAPSHOT' + +} + +dependencies { + minecraft "com.mojang:minecraft:${project.minecraft_version}" + mappings "net.fabricmc:yarn:${project.yarn_mappings}:v2" + modImplementation "net.fabricmc:fabric-loader:${project.loader_version}" + + modImplementation "net.fabricmc.fabric-api:fabric-api:${project.fabric_version}" + + testImplementation "org.junit.jupiter:junit-jupiter-api:${project.junit_version}" + testRuntimeOnly "org.junit.jupiter:junit-jupiter-engine:${project.junit_version}" +} + +processResources { + inputs.property "version", project.version + + filesMatching("fabric.mod.json") { + expand "version": project.version + } +} + +tasks.withType(JavaCompile).configureEach { + // ensure that the encoding is set to UTF-8, no matter what the system default is + // this fixes some edge cases with special characters not displaying correctly + // see http://yodaconditions.net/blog/fix-for-java-file-encoding-problems-with-gradle.html + // If Javadoc is generated, this must be specified in that task too. + it.options.encoding = "UTF-8" + + // The Minecraft launcher currently installs Java 8 for users, so your mod probably wants to target Java 8 too + // JDK 9 introduced a new way of specifying this that will make sure no newer classes or methods are used. + // We'll use that if it's available, but otherwise we'll use the older option. + def targetVersion = 17 + if (JavaVersion.current().isJava9Compatible()) { + it.options.release = targetVersion + } +} + + +test { + useJUnitPlatform() +} diff --git a/Pagination/src/main/java/fr/altarik/toolbox/pagination/PaginatedContent.java b/Pagination/src/main/java/fr/altarik/toolbox/pagination/PaginatedContent.java new file mode 100644 index 0000000..ca07c3a --- /dev/null +++ b/Pagination/src/main/java/fr/altarik/toolbox/pagination/PaginatedContent.java @@ -0,0 +1,4 @@ +package fr.altarik.toolbox.pagination; + +public class PaginatedContent { +} diff --git a/Pagination/src/main/java/fr/altarik/toolbox/pagination/Pagination.java b/Pagination/src/main/java/fr/altarik/toolbox/pagination/Pagination.java new file mode 100644 index 0000000..009e005 --- /dev/null +++ b/Pagination/src/main/java/fr/altarik/toolbox/pagination/Pagination.java @@ -0,0 +1,32 @@ +package fr.altarik.toolbox.pagination; + +import fr.altarik.toolbox.pagination.api.PaginationApi; +import fr.altarik.toolbox.pagination.api.PaginationApiImpl; +import fr.altarik.toolbox.pagination.command.CommandsRegister; +import net.fabricmc.api.ModInitializer; +import net.fabricmc.fabric.api.command.v2.CommandRegistrationCallback; +import org.jetbrains.annotations.NotNull; + +public class Pagination implements ModInitializer { + + private static Pagination instance; + private final PaginationApi api; + + public Pagination() { + instance = this; + this.api = new PaginationApiImpl(); + } + + @Override + public void onInitialize() { + CommandRegistrationCallback.EVENT.register((dispatcher, registryAccess, environment) -> new CommandsRegister().register(dispatcher, environment.dedicated)); + } + + public @NotNull PaginationApi getApi() { + return api; + } + + public static @NotNull Pagination getInstance() { + return instance; + } +} 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 new file mode 100644 index 0000000..b6197e0 --- /dev/null +++ b/Pagination/src/main/java/fr/altarik/toolbox/pagination/api/PaginationApi.java @@ -0,0 +1,26 @@ +package fr.altarik.toolbox.pagination.api; + +import net.minecraft.server.network.ServerPlayerEntity; + +public interface PaginationApi { + + /** + *

Create a pagination table for player, content is separated into multiple pages.
+ * You can separate yourself content by adding *\n\n* between two pages.

+ *

Content have a time-to-live of 15 minutes (18,000 ticks)

+ * @param playerEntity The player who will be able to interact and see the paginated message + * @param content Content you want to paginate + * @param header Header/title you want to add to every page, empty space is filled with "=". + *

Special values are: + *

+ *

+ * @throws IllegalArgumentException if one of its conditions is met:
    + *
  1. header length is more than 50 characters
  2. + *
  3. content is empty
  4. + *
  5. playerEntity or content are null
  6. + *
+ */ + void createTable(ServerPlayerEntity playerEntity, String content, String header); + +} 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 new file mode 100644 index 0000000..2d0477d --- /dev/null +++ b/Pagination/src/main/java/fr/altarik/toolbox/pagination/api/PaginationApiImpl.java @@ -0,0 +1,18 @@ +package fr.altarik.toolbox.pagination.api; + +import fr.altarik.toolbox.pagination.PaginatedContent; +import net.minecraft.server.network.ServerPlayerEntity; +import net.minecraft.util.Pair; + +import java.util.HashMap; +import java.util.Map; + +public class PaginationApiImpl implements PaginationApi { + + Map> paginatedContent = new HashMap<>(); + + @Override + public void createTable(ServerPlayerEntity playerEntity, String content, String header) { + // TODO: 01/03/2023 + } +} 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 new file mode 100644 index 0000000..ae295a4 --- /dev/null +++ b/Pagination/src/main/java/fr/altarik/toolbox/pagination/command/CommandsRegister.java @@ -0,0 +1,20 @@ +package fr.altarik.toolbox.pagination.command; + +import com.mojang.brigadier.CommandDispatcher; +import com.mojang.brigadier.arguments.IntegerArgumentType; +import net.minecraft.server.command.ServerCommandSource; + +import static net.minecraft.server.command.CommandManager.argument; +import static net.minecraft.server.command.CommandManager.literal; + +public class CommandsRegister { + + public void register(CommandDispatcher dispatcher, boolean dedicated) { + dispatcher.register(literal("table") + .then(literal("page") + .then(argument("page", IntegerArgumentType.integer())) + ) + ); + } + +} diff --git a/Pagination/src/main/resources/Pagination.mixins.json b/Pagination/src/main/resources/Pagination.mixins.json new file mode 100644 index 0000000..79392b0 --- /dev/null +++ b/Pagination/src/main/resources/Pagination.mixins.json @@ -0,0 +1,14 @@ +{ + "required": true, + "minVersion": "0.8", + "package": "fr.altarik.toolbox.task.mixin", + "compatibilityLevel": "JAVA_17", + "mixins": [ + ], + "client": [ + ], + "verbose": false, + "injectors": { + "defaultRequire": 1 + } +} diff --git a/Pagination/src/main/resources/assets/pagination/icon.png b/Pagination/src/main/resources/assets/pagination/icon.png new file mode 100644 index 0000000000000000000000000000000000000000..1049a98c68691f2040e340fd044c1efe3f4601e6 GIT binary patch literal 3805 zcmaJ^c{r5q+a9|xmhAf&%D(Sg!Wip#hsM%k8H^=nVTKuFi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EqPOi_ z&kri@cbt~)t3q5Ddg4+EE6RrH4uJdQPlPBKsCZZ?bQD*7W&gn%(dA&1_@wrQH?MJB z%7(`$@06mRrs|$o729aXlD^>Cjc@TzB~3roX(c!5-t*&Q{UJtCHzr z&3;$%5pJ*S#mXs*tY!jt{4^iLBo<;TJ}j)}?was#Iq9Yddy?9bBpA|ZOrj|c{OJQ-zo)fugDfy-q4HnXycTqo$sKp*$xESSBLdly$Mtxu(N1~TL23SUv}n>JRYp8j~D{r1&~p+L9! zKMJ5)GT@e)IQiIp6{Cv5?CLkgICMr<9iycST)ldFRodjLq^0JAhc|6*t=)DarWVtLjTfEN!p8Uw}5i~lW9B~=`+c+?`ef)`gRSLKBeE_4MG=n@Xg@* zi-JUn(LXj-K9}&zJGG@>CEAnICYNglLHrb21|N{*?KG|U1lUkr=p=uAMQMnWF-vDuvlqz*aCRvsH00nl*UGNcXM;STgiV zk)%QBzDevxm+c@q8~pBh_ek|rwplD|CyBXQ0$NpVSvtgL_;nn7(S>CzmgX8glh(>! zyFYh(;@lKV{CI_u?pl9ZJLO~_}se9%fG7d^-@(@?pMK@p~&m^ zJ{z<+@6N)WEuKA9SDGI^HNandYcUB~kagi;se<8E*qFRm4mUGuV0n#Q@;rZAUh8qQ zFMJ}yA-Oh#JdIgmmC(JX3tH8#N=xB1JXI(-w5cYicXBj0)!SYv#KGfbU{O!7@I1%; zV8NK3>-_fZ3#q$BC6pMX?CoV5uk|Sl?<=bHd)_9r(Sd9(v~2SH8`wiBo?f5BgX!7D z=FG;-v-jH})C-Q3)+pM8z@fawkUG=|?fZv%kH" + ], + "contact": { + "homepage": "https://altarik.fr" + }, + "license": "Altarik @ All-Rights-Reserved ", + "icon": "assets/pagination/icon.png", + "environment": "*", + "entrypoints": { + "main": [ + "fr.altarik.toolbox.pagination.Pagination" + ] + }, + "mixins": [ + "Pagination.mixins.json" + ], + "depends": { + "fabricloader": "^0.14.12", + "fabric-api": "*", + "minecraft": "1.19.3", + "java": ">=17" + } +} diff --git a/Tasks/src/main/resources/assets/tasks/icon.png b/Tasks/src/main/resources/assets/tasks/icon.png new file mode 100644 index 0000000000000000000000000000000000000000..1049a98c68691f2040e340fd044c1efe3f4601e6 GIT binary patch literal 3805 zcmaJ^c{r5q+a9|xmhAf&%D(Sg!Wip#hsM%k8H^=nVTKuFiPTs|LJG+%WGx~~B-ZYI>@^nmPs`eM2=(Jsk~gJr$6ahNhvqhJm`KwyK7vk%pd;u0H6W2TYF^ z=I3wZ41xX=i@q`i2NDQ4BXxBmk*G%0R>Ot`sB0P;(lxZywX{^}2vvL}hJYlgV(_xR z6d)+PZ&(nH5QN2mjueqT*l>a=nC|pHDWGxx%3|>Ul!;z2brKS%uBoPRl+rIC4EFy+ z(dd8Cc!D$PzkdHuVLT!dhf;S&;j!UizVw6hmpuxFGqMarAqm(p1Qr|etBUYIECGuT z#Nt3&bW0!ww;+rkmWWsUn*f6u*<$bnB*qtI3o!-LCDej~{EW1%th9AC&2=pd^q`uW zRuBVA11%^-M^8^rTTfFTYW0f?!TN@yQ5eE6uHS#TdcWl!^#U44j|@SD1x29zpkY`v z=7<#*h(fj(- z=hP|yfD>*DF-MR-cDV(INVtibu1(~}w140Dn8yE5(zsS!e>v;Pw*-pNAUs~|u1y>u zKCoiQj-8p2d4{d>O8T~?xdn)$1k_M3FbDzG!?QB)Vff{rCohtICJ{$Gm+=w)0RaK? zodIl>DME-THX@;Fb?Nm4zJ1wvJ~~@bkm^l)fn_m2EgjA9dL1yi9rx*uil3|8Y1WU}HRnIxW-oEdJ-5!B*36jmm3X01iF92{iHK}= zHft}{Kl!zG)0hFSmfeXR3xVKeImDmcL*&$N=Oy;6j&)XfNE-}IZd6P!^`Os3F-|O1 z9UD^8&4Kd6#xD=!oJKynE0t$^^$A@1NycofhF4|m5CH~hOg99g-zx5lzY80GY*PPN zKC-`6zqGwAKqD4(eB&-rgRxh+Q+y?XbGO4Ch|r>zD~H$LMrSE;k8Ae`U)!a=+j-&G zr)pN2hn`ymNEk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