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 0000000..1049a98 Binary files /dev/null and b/Pagination/src/main/resources/assets/pagination/icon.png differ diff --git a/Pagination/src/main/resources/fabric.mod.json b/Pagination/src/main/resources/fabric.mod.json new file mode 100644 index 0000000..52051dc --- /dev/null +++ b/Pagination/src/main/resources/fabric.mod.json @@ -0,0 +1,33 @@ +{ + "schemaVersion": 1, + "id": "pagination", + "version": "${version}", + "name": "Task", + "description": "A mod to use to paginate long result to player in chat", + "authors": [ + "Altarik" + ], + "contributors": [ + "Legot Quentin" + ], + "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 0000000..1049a98 Binary files /dev/null and b/Tasks/src/main/resources/assets/tasks/icon.png differ diff --git a/Tasks/src/main/resources/fabric.mod.json b/Tasks/src/main/resources/fabric.mod.json index d0a2a7d..c7940a1 100644 --- a/Tasks/src/main/resources/fabric.mod.json +++ b/Tasks/src/main/resources/fabric.mod.json @@ -14,7 +14,7 @@ "homepage": "https://altarik.fr" }, "license": "Altarik @ All-Rights-Reserved ", - "icon": "assets/quests/icon.png", + "icon": "assets/tasks/icon.png", "environment": "*", "entrypoints": { "main": [ diff --git a/gradle.properties b/gradle.properties index b918202..706b1f7 100644 --- a/gradle.properties +++ b/gradle.properties @@ -4,8 +4,8 @@ org.gradle.jvmargs=-Xmx5G junit_version=5.9.0 minecraft_version=1.19.3 yarn_mappings=1.19.3+build.5 -loader_version=0.14.12 -fabric_version=0.70.0+1.19.3 +loader_version=0.14.14 +fabric_version=0.75.1+1.19.3 maven_group=fr.altarik.toolbox maven_version=4.0.0-SNAPSHOT diff --git a/settings.gradle b/settings.gradle index ea6151c..3f9b534 100644 --- a/settings.gradle +++ b/settings.gradle @@ -10,4 +10,4 @@ pluginManagement { } rootProject.name = 'Toolbox' -include(':Tasks', ':Database') +include(':Tasks', ':Database', ':Pagination')