Fix HeaderCondition
Signed-off-by: Quentin Legot <legotquentin@gmail.com>
This commit is contained in:
parent
19e1dd2937
commit
be9c4de097
@ -1,4 +1,9 @@
|
|||||||
package fr.altarik.toolbox.pagination;
|
package fr.altarik.toolbox.pagination;
|
||||||
|
|
||||||
public class PaginatedContent {
|
public class PaginatedContent {
|
||||||
|
|
||||||
|
public PaginatedContent(String header, String content) {
|
||||||
|
// TODO: 19/03/2023
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -2,6 +2,7 @@ package fr.altarik.toolbox.pagination.api;
|
|||||||
|
|
||||||
import net.minecraft.server.network.ServerPlayerEntity;
|
import net.minecraft.server.network.ServerPlayerEntity;
|
||||||
|
|
||||||
|
@SuppressWarnings("unused") // Api usage
|
||||||
public interface PaginationApi {
|
public interface PaginationApi {
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -12,6 +12,9 @@ import java.util.Map;
|
|||||||
import java.util.function.Predicate;
|
import java.util.function.Predicate;
|
||||||
|
|
||||||
public class PaginationApiImpl implements PaginationApi {
|
public class PaginationApiImpl implements PaginationApi {
|
||||||
|
/**
|
||||||
|
* Integer represent relative tts of the paginated content, decreased by 1 every seconds
|
||||||
|
*/
|
||||||
private final 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<ServerPlayerEntity> playerCondition = new NullPlayerCondition().negate();
|
||||||
private final Predicate<String> headerCondition = new HeaderCondition().negate();
|
private final Predicate<String> headerCondition = new HeaderCondition().negate();
|
||||||
@ -21,7 +24,6 @@ public class PaginationApiImpl implements PaginationApi {
|
|||||||
if(playerCondition.test(playerEntity) || headerCondition.test(header) || contentCondition.test(content)) {
|
if(playerCondition.test(playerEntity) || headerCondition.test(header) || contentCondition.test(content)) {
|
||||||
throw new IllegalArgumentException("Preconditions aren't satisfied");
|
throw new IllegalArgumentException("Preconditions aren't satisfied");
|
||||||
}
|
}
|
||||||
|
paginatedContent.put(playerEntity, new Pair<>(900, new PaginatedContent(header, content)));
|
||||||
// TODO: 01/03/2023
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -3,12 +3,11 @@ package fr.altarik.toolbox.pagination.precondition;
|
|||||||
import java.util.function.Predicate;
|
import java.util.function.Predicate;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* This predicate returns true if header is not null, not blank (not empty excluding whitespaces)
|
* This predicate returns true if its length doesn't exceed 50 characters.
|
||||||
* and if its length doesn't exceed 50 characters.
|
|
||||||
*/
|
*/
|
||||||
public class HeaderCondition implements Predicate<String> {
|
public class HeaderCondition implements Predicate<String> {
|
||||||
@Override
|
@Override
|
||||||
public boolean test(String header) {
|
public boolean test(String header) {
|
||||||
return header != null && !header.isBlank() && header.length() <= 50;
|
return header.length() <= 50;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user