pagination #10

Merged
quentinlegot merged 7 commits from pagination into dev 2023-03-23 02:16:31 +01:00
8 changed files with 100 additions and 31 deletions
Showing only changes of commit 19e1dd2937 - Show all commits

View File

@ -16,7 +16,7 @@ public interface PaginationApi {
* <li><b>empty String</b> if you want just the header to be filled only with "="</li></ul>
* @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>content</b> is empty/blank</li>
* <li><b>playerEntity</b> or <b>content</b> are null</li>
* </ol>
*/

View File

@ -1,18 +1,27 @@
package fr.altarik.toolbox.pagination.api;
import fr.altarik.toolbox.pagination.PaginatedContent;
import fr.altarik.toolbox.pagination.precondition.ContentCondition;
import fr.altarik.toolbox.pagination.precondition.HeaderCondition;
import fr.altarik.toolbox.pagination.precondition.NullPlayerCondition;
import net.minecraft.server.network.ServerPlayerEntity;
import net.minecraft.util.Pair;
import java.util.HashMap;
import java.util.Map;
import java.util.function.Predicate;
public class PaginationApiImpl implements PaginationApi {
Map<ServerPlayerEntity, Pair<Integer, PaginatedContent>> paginatedContent = new HashMap<>();
private final Map<ServerPlayerEntity, Pair<Integer, PaginatedContent>> paginatedContent = new HashMap<>();
private final Predicate<ServerPlayerEntity> playerCondition = new NullPlayerCondition().negate();
private final Predicate<String> headerCondition = new HeaderCondition().negate();
private final Predicate<String> contentCondition = new ContentCondition().negate();
@Override
public void createTable(ServerPlayerEntity playerEntity, String content, String header) {
if(playerCondition.test(playerEntity) || headerCondition.test(header) || contentCondition.test(content)) {
throw new IllegalArgumentException("Preconditions aren't satisfied");
}
// TODO: 01/03/2023
}
}

View File

@ -0,0 +1,15 @@
package fr.altarik.toolbox.pagination.precondition;
import java.util.function.Predicate;
/**
* This predicate returns true if the String is not null or
* if its content is not blank (empty or only contains whitespaces)
*/
public class ContentCondition implements Predicate<String> {
@Override
public boolean test(String s) {
return s != null && !s.isBlank();
}
}

View File

@ -0,0 +1,14 @@
package fr.altarik.toolbox.pagination.precondition;
import java.util.function.Predicate;
/**
* This predicate returns true if header is not null, not blank (not empty excluding whitespaces)
* and if its length doesn't exceed 50 characters.
*/
public class HeaderCondition implements Predicate<String> {
@Override
public boolean test(String header) {
return header != null && !header.isBlank() && header.length() <= 50;
}
}

View File

@ -0,0 +1,15 @@
package fr.altarik.toolbox.pagination.precondition;
import net.minecraft.server.network.ServerPlayerEntity;
import java.util.function.Predicate;
/**
* This predicate returns true if the player isn't null, false otherwise
*/
public class NullPlayerCondition implements Predicate<ServerPlayerEntity> {
@Override
public boolean test(ServerPlayerEntity player) {
return player != null;
}
}

View File

@ -1,24 +1,3 @@
plugins {
id 'fabric-loom'
}
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}"
}
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

View File

@ -1,11 +1,12 @@
plugins {
id 'java'
id 'fabric-loom' version '1.1-SNAPSHOT' apply false
id 'fabric-loom' version '1.1-SNAPSHOT'
}
allprojects {
apply plugin: 'java'
apply plugin: 'maven-publish'
apply plugin: 'fabric-loom'
group = project.maven_group
version = project.maven_version
@ -46,13 +47,45 @@ allprojects {
}
}
}
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
}
}
dependencies {
testImplementation "org.junit.jupiter:junit-jupiter-api:${project.junit_version}"
testRuntimeOnly "org.junit.jupiter:junit-jupiter-engine:${project.junit_version}"
minecraft "com.mojang:minecraft:${project.minecraft_version}"
mappings "net.fabricmc:yarn:${project.yarn_mappings}:v2"
modImplementation "net.fabricmc:fabric-loader:${project.loader_version}"
}
}
subprojects {
dependencies {
testImplementation "org.junit.jupiter:junit-jupiter-api:${project.junit_version}"
testRuntimeOnly "org.junit.jupiter:junit-jupiter-engine:${project.junit_version}"
modImplementation "net.fabricmc.fabric-api:fabric-api:${project.fabric_version}"
}
java {
@ -66,11 +99,15 @@ subprojects {
}
jar {
dependencies {
include allprojects.collect { project -> project }
}
/*jar {
dependsOn subprojects.jar
subprojects.each { project ->
from(project.jar) {
into("META-INF/jars/")
}
}
}
}*/

View File

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