Add pagination components

Signed-off-by: Quentin Legot <legotquentin@gmail.com>
This commit is contained in:
Quentin Legot 2023-03-01 23:21:59 +01:00
parent e3c5d0dd67
commit 24564362ec
14 changed files with 196 additions and 5 deletions

2
.gitignore vendored
View File

@ -4,7 +4,7 @@ build/
!**/src/main/**/build/
!**/src/test/**/build/
Tasks/run
*/run
### IntelliJ IDEA ###
.idea

44
Pagination/build.gradle Normal file
View File

@ -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()
}

View File

@ -0,0 +1,4 @@
package fr.altarik.toolbox.pagination;
public class PaginatedContent {
}

View File

@ -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;
}
}

View File

@ -0,0 +1,26 @@
package fr.altarik.toolbox.pagination.api;
import net.minecraft.server.network.ServerPlayerEntity;
public interface PaginationApi {
/**
* <p>Create a pagination table for player, content is separated into multiple pages.<br>
* You can separate yourself content by adding *\n\n* between two pages.</p>
* <p>Content have a time-to-live of 15 minutes (18,000 ticks)</p>
* @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 "=".
* <p>Special values are:
* <ul><li><b>null</b> if you doesn't want to add a header</li>
* <li><b>empty String</b> if you want just the header to be filled only with "="</li></ul>
* </p>
* @throws IllegalArgumentException if one of its conditions is met: <ol>
* <li><b>header</b> length is more than 50 characters</li>
* <li><b>content</b> is empty</li>
* <li><b>playerEntity</b> or <b>content</b> are null</li>
* </ol>
*/
void createTable(ServerPlayerEntity playerEntity, String content, String header);
}

View File

@ -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<ServerPlayerEntity, Pair<Integer, PaginatedContent>> paginatedContent = new HashMap<>();
@Override
public void createTable(ServerPlayerEntity playerEntity, String content, String header) {
// TODO: 01/03/2023
}
}

View File

@ -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<ServerCommandSource> dispatcher, boolean dedicated) {
dispatcher.register(literal("table")
.then(literal("page")
.then(argument("page", IntegerArgumentType.integer()))
)
);
}
}

View File

@ -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
}
}

Binary file not shown.

After

Width:  |  Height:  |  Size: 3.7 KiB

View File

@ -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<legotquentin@gmail.com>"
],
"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"
}
}

Binary file not shown.

After

Width:  |  Height:  |  Size: 3.7 KiB

View File

@ -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": [

View File

@ -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

View File

@ -10,4 +10,4 @@ pluginManagement {
}
rootProject.name = 'Toolbox'
include(':Tasks', ':Database')
include(':Tasks', ':Database', ':Pagination')