From 19e1dd2937113bc3cb05b3dbd1c66914aad08f96 Mon Sep 17 00:00:00 2001 From: Quentin Legot Date: Sun, 19 Mar 2023 19:38:08 +0100 Subject: [PATCH 01/37] Add pagination precondition --- .../toolbox/pagination/api/PaginationApi.java | 2 +- .../pagination/api/PaginationApiImpl.java | 15 ++++-- .../precondition/ContentCondition.java | 15 ++++++ .../precondition/HeaderCondition.java | 14 ++++++ .../precondition/NullPlayerCondition.java | 15 ++++++ Tasks/build.gradle | 21 --------- build.gradle | 47 +++++++++++++++++-- settings.gradle | 2 +- 8 files changed, 100 insertions(+), 31 deletions(-) create mode 100644 Pagination/src/main/java/fr/altarik/toolbox/pagination/precondition/ContentCondition.java create mode 100644 Pagination/src/main/java/fr/altarik/toolbox/pagination/precondition/HeaderCondition.java create mode 100644 Pagination/src/main/java/fr/altarik/toolbox/pagination/precondition/NullPlayerCondition.java 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 index 3adb373..3b23724 100644 --- a/Pagination/src/main/java/fr/altarik/toolbox/pagination/api/PaginationApi.java +++ b/Pagination/src/main/java/fr/altarik/toolbox/pagination/api/PaginationApi.java @@ -16,7 +16,7 @@ public interface PaginationApi { *
  • empty String if you want just the header to be filled only with "="
  • * @throws IllegalArgumentException if one of its conditions is met:
      *
    1. header length is more than 50 characters
    2. - *
    3. content is empty
    4. + *
    5. content is empty/blank
    6. *
    7. playerEntity or content are null
    8. *
    */ 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 index 2d0477d..2e27090 100644 --- a/Pagination/src/main/java/fr/altarik/toolbox/pagination/api/PaginationApiImpl.java +++ b/Pagination/src/main/java/fr/altarik/toolbox/pagination/api/PaginationApiImpl.java @@ -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> paginatedContent = new HashMap<>(); - + private final Map> paginatedContent = new HashMap<>(); + private final Predicate playerCondition = new NullPlayerCondition().negate(); + private final Predicate headerCondition = new HeaderCondition().negate(); + private final Predicate 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 } } diff --git a/Pagination/src/main/java/fr/altarik/toolbox/pagination/precondition/ContentCondition.java b/Pagination/src/main/java/fr/altarik/toolbox/pagination/precondition/ContentCondition.java new file mode 100644 index 0000000..a5d2542 --- /dev/null +++ b/Pagination/src/main/java/fr/altarik/toolbox/pagination/precondition/ContentCondition.java @@ -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 { + @Override + public boolean test(String s) { + return s != null && !s.isBlank(); + } + +} diff --git a/Pagination/src/main/java/fr/altarik/toolbox/pagination/precondition/HeaderCondition.java b/Pagination/src/main/java/fr/altarik/toolbox/pagination/precondition/HeaderCondition.java new file mode 100644 index 0000000..d39cde5 --- /dev/null +++ b/Pagination/src/main/java/fr/altarik/toolbox/pagination/precondition/HeaderCondition.java @@ -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 { + @Override + public boolean test(String header) { + return header != null && !header.isBlank() && header.length() <= 50; + } +} diff --git a/Pagination/src/main/java/fr/altarik/toolbox/pagination/precondition/NullPlayerCondition.java b/Pagination/src/main/java/fr/altarik/toolbox/pagination/precondition/NullPlayerCondition.java new file mode 100644 index 0000000..16e8dfb --- /dev/null +++ b/Pagination/src/main/java/fr/altarik/toolbox/pagination/precondition/NullPlayerCondition.java @@ -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 { + @Override + public boolean test(ServerPlayerEntity player) { + return player != null; + } +} diff --git a/Tasks/build.gradle b/Tasks/build.gradle index 77c4a5a..2d673a0 100644 --- a/Tasks/build.gradle +++ b/Tasks/build.gradle @@ -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 diff --git a/build.gradle b/build.gradle index 7ab39e6..a33d141 100644 --- a/build.gradle +++ b/build.gradle @@ -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/") } } -} +}*/ diff --git a/settings.gradle b/settings.gradle index 16f164b..3f9b534 100644 --- a/settings.gradle +++ b/settings.gradle @@ -10,4 +10,4 @@ pluginManagement { } rootProject.name = 'Toolbox' -include(':Tasks', ':Database', /* ':Pagination' */) +include(':Tasks', ':Database', ':Pagination') -- 2.39.5 From be9c4de0978a21ad83d1b0922868f064eec3b6e4 Mon Sep 17 00:00:00 2001 From: Quentin Legot Date: Sun, 19 Mar 2023 19:53:54 +0100 Subject: [PATCH 02/37] Fix HeaderCondition Signed-off-by: Quentin Legot --- .../fr/altarik/toolbox/pagination/PaginatedContent.java | 5 +++++ .../fr/altarik/toolbox/pagination/api/PaginationApi.java | 1 + .../altarik/toolbox/pagination/api/PaginationApiImpl.java | 6 ++++-- .../toolbox/pagination/precondition/HeaderCondition.java | 5 ++--- 4 files changed, 12 insertions(+), 5 deletions(-) diff --git a/Pagination/src/main/java/fr/altarik/toolbox/pagination/PaginatedContent.java b/Pagination/src/main/java/fr/altarik/toolbox/pagination/PaginatedContent.java index ca07c3a..50eb02c 100644 --- a/Pagination/src/main/java/fr/altarik/toolbox/pagination/PaginatedContent.java +++ b/Pagination/src/main/java/fr/altarik/toolbox/pagination/PaginatedContent.java @@ -1,4 +1,9 @@ package fr.altarik.toolbox.pagination; public class PaginatedContent { + + public PaginatedContent(String header, String content) { + // TODO: 19/03/2023 + } + } 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 index 3b23724..36f4f07 100644 --- a/Pagination/src/main/java/fr/altarik/toolbox/pagination/api/PaginationApi.java +++ b/Pagination/src/main/java/fr/altarik/toolbox/pagination/api/PaginationApi.java @@ -2,6 +2,7 @@ package fr.altarik.toolbox.pagination.api; import net.minecraft.server.network.ServerPlayerEntity; +@SuppressWarnings("unused") // Api usage public interface PaginationApi { /** 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 index 2e27090..93e7972 100644 --- a/Pagination/src/main/java/fr/altarik/toolbox/pagination/api/PaginationApiImpl.java +++ b/Pagination/src/main/java/fr/altarik/toolbox/pagination/api/PaginationApiImpl.java @@ -12,6 +12,9 @@ import java.util.Map; import java.util.function.Predicate; public class PaginationApiImpl implements PaginationApi { + /** + * Integer represent relative tts of the paginated content, decreased by 1 every seconds + */ private final Map> paginatedContent = new HashMap<>(); private final Predicate playerCondition = new NullPlayerCondition().negate(); private final Predicate headerCondition = new HeaderCondition().negate(); @@ -21,7 +24,6 @@ public class PaginationApiImpl implements PaginationApi { if(playerCondition.test(playerEntity) || headerCondition.test(header) || contentCondition.test(content)) { throw new IllegalArgumentException("Preconditions aren't satisfied"); } - - // TODO: 01/03/2023 + paginatedContent.put(playerEntity, new Pair<>(900, new PaginatedContent(header, content))); } } diff --git a/Pagination/src/main/java/fr/altarik/toolbox/pagination/precondition/HeaderCondition.java b/Pagination/src/main/java/fr/altarik/toolbox/pagination/precondition/HeaderCondition.java index d39cde5..9b9ee5e 100644 --- a/Pagination/src/main/java/fr/altarik/toolbox/pagination/precondition/HeaderCondition.java +++ b/Pagination/src/main/java/fr/altarik/toolbox/pagination/precondition/HeaderCondition.java @@ -3,12 +3,11 @@ 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. + * This predicate returns true if its length doesn't exceed 50 characters. */ public class HeaderCondition implements Predicate { @Override public boolean test(String header) { - return header != null && !header.isBlank() && header.length() <= 50; + return header.length() <= 50; } } -- 2.39.5 From 5a1e741eac7d63688a3159ea3836175f3f8b6148 Mon Sep 17 00:00:00 2001 From: Quentin Legot Date: Thu, 23 Mar 2023 01:12:46 +0100 Subject: [PATCH 03/37] Add command and page display Signed-off-by: Quentin Legot --- .../toolbox/pagination/PaginatedContent.java | 64 ++++++++++++++++++- .../toolbox/pagination/Pagination.java | 2 +- .../toolbox/pagination/api/PaginationApi.java | 10 +++ .../pagination/api/PaginationApiImpl.java | 39 ++++++++++- .../pagination/command/CommandsRegister.java | 25 +++++++- 5 files changed, 135 insertions(+), 5 deletions(-) diff --git a/Pagination/src/main/java/fr/altarik/toolbox/pagination/PaginatedContent.java b/Pagination/src/main/java/fr/altarik/toolbox/pagination/PaginatedContent.java index 50eb02c..706605f 100644 --- a/Pagination/src/main/java/fr/altarik/toolbox/pagination/PaginatedContent.java +++ b/Pagination/src/main/java/fr/altarik/toolbox/pagination/PaginatedContent.java @@ -1,9 +1,71 @@ package fr.altarik.toolbox.pagination; +import net.minecraft.server.network.ServerPlayerEntity; +import net.minecraft.text.ClickEvent; +import net.minecraft.text.MutableText; +import net.minecraft.text.Text; +import net.minecraft.util.Formatting; + +import java.util.ArrayList; +import java.util.List; +import java.util.stream.Collectors; +import java.util.stream.Stream; + public class PaginatedContent { + private final List pages; + private final String header; + public PaginatedContent(String header, String content) { - // TODO: 19/03/2023 + this.header = header; + pages = new ArrayList<>(); + List secondSplit = new ArrayList<>(); + for(String elem : Stream.of(content.split("\n")).collect(Collectors.toCollection(ArrayList::new))) { + if(elem.length() > 50) { + secondSplit.add(elem.substring(0, 50)); + secondSplit.add(elem.substring(51, elem.length() - 1)); + } else { + secondSplit.add(elem); + } + } + int line = 0; + List currentPage = new ArrayList<>(); + for(String elem : secondSplit) { + line++; + currentPage.add(elem); + if(line == 8 || elem.isEmpty()) { + pages.add(new Page(currentPage)); + line = 0; + currentPage = new ArrayList<>(); + } + } + } + + public void display(ServerPlayerEntity playerEntity, int page) { + if(page >= this.pages.size()) { + throw new IllegalArgumentException("There's " + this.pages.size() + " paginated pages but you wanted page n°" + page); + } else if(page < 0) { + throw new IllegalArgumentException("argument page is lower than 0"); + } else { + playerEntity.sendMessage(Text.literal(header)); + for(String s : pages.get(page).lines) { + playerEntity.sendMessage(Text.literal(s)); + } + MutableText left = Text.literal("<").styled( + style -> style + .withColor(Formatting.YELLOW) + .withClickEvent(new ClickEvent(ClickEvent.Action.RUN_COMMAND, "/table page " + (page - 1))) + ); + MutableText right = Text.literal(">").styled( + style -> style + .withColor(Formatting.YELLOW) + .withClickEvent(new ClickEvent(ClickEvent.Action.RUN_COMMAND, "/table page " + (page + 1))) + ); + playerEntity.sendMessage(left.append(" " + page + " ").append(right)); + } + } + + private record Page(List lines) { } } diff --git a/Pagination/src/main/java/fr/altarik/toolbox/pagination/Pagination.java b/Pagination/src/main/java/fr/altarik/toolbox/pagination/Pagination.java index 009e005..8e4b19e 100644 --- a/Pagination/src/main/java/fr/altarik/toolbox/pagination/Pagination.java +++ b/Pagination/src/main/java/fr/altarik/toolbox/pagination/Pagination.java @@ -19,7 +19,7 @@ public class Pagination implements ModInitializer { @Override public void onInitialize() { - CommandRegistrationCallback.EVENT.register((dispatcher, registryAccess, environment) -> new CommandsRegister().register(dispatcher, environment.dedicated)); + CommandRegistrationCallback.EVENT.register((dispatcher, registryAccess, environment) -> new CommandsRegister(this).register(dispatcher, environment.dedicated)); } public @NotNull PaginationApi getApi() { 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 index 36f4f07..34f8f23 100644 --- a/Pagination/src/main/java/fr/altarik/toolbox/pagination/api/PaginationApi.java +++ b/Pagination/src/main/java/fr/altarik/toolbox/pagination/api/PaginationApi.java @@ -23,4 +23,14 @@ public interface PaginationApi { */ void createTable(ServerPlayerEntity playerEntity, String content, String header); + /** + * Display the given page for the given player + * @param player display the content of this player + * @param page display this page + * @throws IllegalArgumentException if page is invalid + * @throws NullPointerException if player is null or paginated content for the player doesn't exist (or have expired) + * @see fr.altarik.toolbox.pagination.PaginatedContent#display(ServerPlayerEntity, int) + */ + void display(ServerPlayerEntity player, int page); + } 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 index 93e7972..8a2abf9 100644 --- a/Pagination/src/main/java/fr/altarik/toolbox/pagination/api/PaginationApiImpl.java +++ b/Pagination/src/main/java/fr/altarik/toolbox/pagination/api/PaginationApiImpl.java @@ -4,10 +4,14 @@ 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.fabricmc.fabric.api.event.lifecycle.v1.ServerTickEvents; +import net.minecraft.server.MinecraftServer; import net.minecraft.server.network.ServerPlayerEntity; import net.minecraft.util.Pair; +import java.util.ArrayList; import java.util.HashMap; +import java.util.List; import java.util.Map; import java.util.function.Predicate; @@ -15,15 +19,46 @@ public class PaginationApiImpl implements PaginationApi { /** * Integer represent relative tts of the paginated content, decreased by 1 every seconds */ - private final Map> paginatedContent = new HashMap<>(); + public final Map> paginatedContent = new HashMap<>(); private final Predicate playerCondition = new NullPlayerCondition().negate(); private final Predicate headerCondition = new HeaderCondition().negate(); private final Predicate contentCondition = new ContentCondition().negate(); + + public PaginationApiImpl() { + ServerTickEvents.START_SERVER_TICK.register(this::serverTick); + } + @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"); } - paginatedContent.put(playerEntity, new Pair<>(900, new PaginatedContent(header, content))); + PaginatedContent paginatedContent1 = new PaginatedContent(header, content); + paginatedContent.put(playerEntity, new Pair<>(18000, paginatedContent1)); + paginatedContent1.display(playerEntity, 0); + } + + @Override + public void display(ServerPlayerEntity player, int page) { + if(player == null) + throw new NullPointerException("Player is null"); + Pair pair = paginatedContent.get(player); + if(pair == null) + throw new NullPointerException("No paginated page for player " + player.getCustomName()); + pair.getRight().display(player, page); + } + + private void serverTick(MinecraftServer server) { + List toRemove = new ArrayList<>(); + for(Map.Entry> content : paginatedContent.entrySet()) { + if(content.getValue().getLeft() == 0) { + toRemove.add(content.getKey()); + } else { + content.getValue().setLeft(content.getValue().getLeft() - 1); + } + } + for(ServerPlayerEntity player : toRemove) { + paginatedContent.remove(player); + } } } 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 index ae295a4..fa01f2e 100644 --- a/Pagination/src/main/java/fr/altarik/toolbox/pagination/command/CommandsRegister.java +++ b/Pagination/src/main/java/fr/altarik/toolbox/pagination/command/CommandsRegister.java @@ -2,19 +2,42 @@ package fr.altarik.toolbox.pagination.command; import com.mojang.brigadier.CommandDispatcher; import com.mojang.brigadier.arguments.IntegerArgumentType; +import com.mojang.brigadier.context.CommandContext; +import com.mojang.brigadier.exceptions.CommandSyntaxException; +import fr.altarik.toolbox.pagination.Pagination; +import fr.altarik.toolbox.pagination.api.PaginationApi; import net.minecraft.server.command.ServerCommandSource; +import net.minecraft.text.Text; import static net.minecraft.server.command.CommandManager.argument; import static net.minecraft.server.command.CommandManager.literal; public class CommandsRegister { + private final PaginationApi api; + + public CommandsRegister(Pagination instance) { + this.api = instance.getApi(); + } + public void register(CommandDispatcher dispatcher, boolean dedicated) { dispatcher.register(literal("table") .then(literal("page") - .then(argument("page", IntegerArgumentType.integer())) + .then(argument("page", IntegerArgumentType.integer()) + .executes(this::selectPageCommand) + ) ) ); } + private int selectPageCommand(CommandContext context) throws CommandSyntaxException { + try { + int page = IntegerArgumentType.getInteger(context, "page"); + api.display(context.getSource().getPlayerOrThrow(), page); + } catch(NullPointerException | IllegalArgumentException e) { + context.getSource().sendFeedback(Text.literal("Error: " + e.getMessage()), false); + } + return 0; + } + } -- 2.39.5 From f2359c75f4a5c820874d1798926e32005fcffba2 Mon Sep 17 00:00:00 2001 From: Quentin Legot Date: Thu, 23 Mar 2023 01:33:03 +0100 Subject: [PATCH 04/37] Fix build and reduce memory footprint by fixing max memory usage to 2G instead of 4G Signed-off-by: Quentin Legot --- Pagination/build.gradle | 35 ----------------------------------- Tasks/build.gradle | 15 --------------- build.gradle | 15 +++------------ gradle.properties | 2 +- 4 files changed, 4 insertions(+), 63 deletions(-) diff --git a/Pagination/build.gradle b/Pagination/build.gradle index 75f7707..e69de29 100644 --- a/Pagination/build.gradle +++ b/Pagination/build.gradle @@ -1,35 +0,0 @@ -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 - // 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 - } -} \ No newline at end of file diff --git a/Tasks/build.gradle b/Tasks/build.gradle index 2d673a0..e69de29 100644 --- a/Tasks/build.gradle +++ b/Tasks/build.gradle @@ -1,15 +0,0 @@ -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 - } -} diff --git a/build.gradle b/build.gradle index a33d141..d168d1d 100644 --- a/build.gradle +++ b/build.gradle @@ -1,10 +1,8 @@ plugins { - id 'java' - id 'fabric-loom' version '1.1-SNAPSHOT' + id 'fabric-loom' version '1.1-SNAPSHOT' apply false } allprojects { - apply plugin: 'java' apply plugin: 'maven-publish' apply plugin: 'fabric-loom' @@ -35,7 +33,7 @@ allprojects { mavenJava(MavenPublication) { from components.java } - } + } repositories { maven { name 'altarik' @@ -78,13 +76,6 @@ allprojects { 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 { modImplementation "net.fabricmc.fabric-api:fabric-api:${project.fabric_version}" } @@ -100,7 +91,7 @@ subprojects { } dependencies { - include allprojects.collect { project -> project } + include subprojects.collect { project -> project } } /*jar { diff --git a/gradle.properties b/gradle.properties index f76810d..16c0d2a 100644 --- a/gradle.properties +++ b/gradle.properties @@ -1,4 +1,4 @@ -org.gradle.jvmargs=-Xmx4G +org.gradle.jvmargs=-Xmx2G junit_version=5.9.0 -- 2.39.5 From 5992aaa5a02dfbc0fd6d4f2128e59cb5ef6888b6 Mon Sep 17 00:00:00 2001 From: Quentin Legot Date: Thu, 23 Mar 2023 01:52:02 +0100 Subject: [PATCH 05/37] Added a test command and made some fixes Signed-off-by: Quentin Legot --- .../toolbox/pagination/PaginatedContent.java | 6 +++-- .../pagination/command/CommandsRegister.java | 26 +++++++++++++++++++ 2 files changed, 30 insertions(+), 2 deletions(-) diff --git a/Pagination/src/main/java/fr/altarik/toolbox/pagination/PaginatedContent.java b/Pagination/src/main/java/fr/altarik/toolbox/pagination/PaginatedContent.java index 706605f..e7034c5 100644 --- a/Pagination/src/main/java/fr/altarik/toolbox/pagination/PaginatedContent.java +++ b/Pagination/src/main/java/fr/altarik/toolbox/pagination/PaginatedContent.java @@ -32,18 +32,20 @@ public class PaginatedContent { List currentPage = new ArrayList<>(); for(String elem : secondSplit) { line++; - currentPage.add(elem); + if(!elem.isEmpty()) + currentPage.add(elem); if(line == 8 || elem.isEmpty()) { pages.add(new Page(currentPage)); line = 0; currentPage = new ArrayList<>(); } } + pages.add(new Page(currentPage)); } public void display(ServerPlayerEntity playerEntity, int page) { if(page >= this.pages.size()) { - throw new IllegalArgumentException("There's " + this.pages.size() + " paginated pages but you wanted page n°" + page); + throw new IllegalArgumentException("There's " + this.pages.size() + " paginated pages but you wanted page n°" + (page + 1)); } else if(page < 0) { throw new IllegalArgumentException("argument page is lower than 0"); } else { 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 index fa01f2e..8c32487 100644 --- a/Pagination/src/main/java/fr/altarik/toolbox/pagination/command/CommandsRegister.java +++ b/Pagination/src/main/java/fr/altarik/toolbox/pagination/command/CommandsRegister.java @@ -26,10 +26,36 @@ public class CommandsRegister { .then(argument("page", IntegerArgumentType.integer()) .executes(this::selectPageCommand) ) + ).then(literal("test") + .requires(source -> source.isExecutedByPlayer() && source.hasPermissionLevel(3)) + .executes(this::testPageCommand) ) ); } + /** + * Simply a debug command + */ + private int testPageCommand(CommandContext context) { + api.createTable(context.getSource().getPlayer(), """ + first line + Second line + + second page + dqdq + dqdqd + qdqdq + dqdq + dqdq + dqdq + dqdqd + third page + dqdqd + dqdqd + d""", "My header"); + return 0; + } + private int selectPageCommand(CommandContext context) throws CommandSyntaxException { try { int page = IntegerArgumentType.getInteger(context, "page"); -- 2.39.5 From d82c8cecad98759315d61228bcaf5a2bf8cae580 Mon Sep 17 00:00:00 2001 From: Quentin Legot Date: Thu, 23 Mar 2023 02:15:37 +0100 Subject: [PATCH 06/37] Added some "=" to headers and footers Signed-off-by: Quentin Legot --- .../toolbox/pagination/PaginatedContent.java | 44 ++++++++++++++----- 1 file changed, 32 insertions(+), 12 deletions(-) diff --git a/Pagination/src/main/java/fr/altarik/toolbox/pagination/PaginatedContent.java b/Pagination/src/main/java/fr/altarik/toolbox/pagination/PaginatedContent.java index e7034c5..95ac763 100644 --- a/Pagination/src/main/java/fr/altarik/toolbox/pagination/PaginatedContent.java +++ b/Pagination/src/main/java/fr/altarik/toolbox/pagination/PaginatedContent.java @@ -17,7 +17,7 @@ public class PaginatedContent { private final String header; public PaginatedContent(String header, String content) { - this.header = header; + this.header = buildHeader(header); pages = new ArrayList<>(); List secondSplit = new ArrayList<>(); for(String elem : Stream.of(content.split("\n")).collect(Collectors.toCollection(ArrayList::new))) { @@ -43,6 +43,11 @@ public class PaginatedContent { pages.add(new Page(currentPage)); } + private String buildHeader(String header) { + int numberOfEq = (50 - header.length()) / 2; + return "=".repeat(numberOfEq) + header + "=".repeat(numberOfEq); + } + public void display(ServerPlayerEntity playerEntity, int page) { if(page >= this.pages.size()) { throw new IllegalArgumentException("There's " + this.pages.size() + " paginated pages but you wanted page n°" + (page + 1)); @@ -53,20 +58,35 @@ public class PaginatedContent { for(String s : pages.get(page).lines) { playerEntity.sendMessage(Text.literal(s)); } - MutableText left = Text.literal("<").styled( - style -> style - .withColor(Formatting.YELLOW) - .withClickEvent(new ClickEvent(ClickEvent.Action.RUN_COMMAND, "/table page " + (page - 1))) - ); - MutableText right = Text.literal(">").styled( - style -> style - .withColor(Formatting.YELLOW) - .withClickEvent(new ClickEvent(ClickEvent.Action.RUN_COMMAND, "/table page " + (page + 1))) - ); - playerEntity.sendMessage(left.append(" " + page + " ").append(right)); + + playerEntity.sendMessage(buildFooter(page)); } } + private Text buildFooter(int page) { + String strPage = String.valueOf(page + 1); + int numberOfEq = (46 - strPage.length()) / 2; + MutableText left = Text.literal("<").styled( + style -> style + .withColor(Formatting.YELLOW) + .withClickEvent(new ClickEvent(ClickEvent.Action.RUN_COMMAND, "/table page " + (page - 1))) + ); + MutableText middle = Text.literal(" " + strPage + " ").styled(style -> style.withColor(Formatting.RESET)); + MutableText right = Text.literal(">").styled( + style -> style + .withColor(Formatting.YELLOW) + .withClickEvent(new ClickEvent(ClickEvent.Action.RUN_COMMAND, "/table page " + (page + 1))) + ); + return Text.literal("=".repeat(numberOfEq)) + .append(left) + .append(middle) + .append(right) + .append( + Text.literal("=".repeat(numberOfEq)) + .styled(style -> style.withColor(Formatting.RESET)) + ); + } + private record Page(List lines) { } -- 2.39.5 From e16843c3e4209b58a3e56615ce011e0ea4ea7d4b Mon Sep 17 00:00:00 2001 From: Quentin Legot Date: Thu, 23 Mar 2023 21:32:52 +0100 Subject: [PATCH 07/37] Add postgresql to perform databases tests --- .gitea/workflows/test.yml | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/.gitea/workflows/test.yml b/.gitea/workflows/test.yml index 91ff768..e72a7ff 100644 --- a/.gitea/workflows/test.yml +++ b/.gitea/workflows/test.yml @@ -16,8 +16,7 @@ jobs: strategy: matrix: java: [ '17' ] - # and run on both Linux and Windows - os: [ubuntu-latest, windows-2022] + os: [ ubuntu-latest ] runs-on: ${{ matrix.os }} steps: - name: checkout repository @@ -29,6 +28,13 @@ jobs: with: java-version: ${{ matrix.java }} distribution: 'oracle' + - name: setup psql + uses: https://github.com/harmon758/postgresql-action@v1 + with: + postgresql version: '15' + postgresql db: postgres + postgresql user: postgres + postgresql password: 'root' - name: make gradle wrapper executable if: ${{ runner.os != 'Windows' }} run: chmod +x ./gradlew -- 2.39.5 From 7326fb2a7ff8f4362452f607dc9288c9b11d6bed Mon Sep 17 00:00:00 2001 From: Quentin Legot Date: Thu, 23 Mar 2023 21:40:00 +0100 Subject: [PATCH 08/37] Update '.gitea/workflows/test.yml' --- .gitea/workflows/test.yml | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/.gitea/workflows/test.yml b/.gitea/workflows/test.yml index e72a7ff..a5b51f6 100644 --- a/.gitea/workflows/test.yml +++ b/.gitea/workflows/test.yml @@ -29,21 +29,21 @@ jobs: java-version: ${{ matrix.java }} distribution: 'oracle' - name: setup psql - uses: https://github.com/harmon758/postgresql-action@v1 + uses: https://github.com/ikalnytskyi/action-setup-postgres@v4 with: - postgresql version: '15' - postgresql db: postgres - postgresql user: postgres - postgresql password: 'root' + port: 5432 + database: postgres + username: postgres + password: 'root' - name: make gradle wrapper executable if: ${{ runner.os != 'Windows' }} run: chmod +x ./gradlew - name: build run: ./gradlew build --no-daemon - - name: test - run: ./gradlew test --no-daemon + #- name: test + # run: ./gradlew test --no-daemon deploy: - runs-on: ${{ ubuntu-latest }} + runs-on: ubuntu-latest if: gitea.ref == 'refs/heads/master' steps: - name: deploy -- 2.39.5 From 2f75bb6083fa40fa9bcfce42432e7ea7d3079f95 Mon Sep 17 00:00:00 2001 From: Quentin Legot Date: Thu, 23 Mar 2023 21:47:04 +0100 Subject: [PATCH 09/37] Exclude test which require a connection to database --- Database/build.gradle | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/Database/build.gradle b/Database/build.gradle index 87ae4db..1c29a69 100644 --- a/Database/build.gradle +++ b/Database/build.gradle @@ -2,3 +2,7 @@ dependencies { implementation 'org.postgresql:postgresql:42.5.0' testImplementation 'com.google.code.gson:gson:2.10' } + +test { + exclude 'fr/altarik/toolbox/database/**' +} \ No newline at end of file -- 2.39.5 From e6455a86e09f59bf69a545781e534f4a8a9fe3b7 Mon Sep 17 00:00:00 2001 From: Quentin Legot Date: Thu, 23 Mar 2023 21:48:05 +0100 Subject: [PATCH 10/37] Remove psql from tests --- .gitea/workflows/test.yml | 7 ------- 1 file changed, 7 deletions(-) diff --git a/.gitea/workflows/test.yml b/.gitea/workflows/test.yml index a5b51f6..829087c 100644 --- a/.gitea/workflows/test.yml +++ b/.gitea/workflows/test.yml @@ -28,13 +28,6 @@ jobs: with: java-version: ${{ matrix.java }} distribution: 'oracle' - - name: setup psql - uses: https://github.com/ikalnytskyi/action-setup-postgres@v4 - with: - port: 5432 - database: postgres - username: postgres - password: 'root' - name: make gradle wrapper executable if: ${{ runner.os != 'Windows' }} run: chmod +x ./gradlew -- 2.39.5 From 25e65e0a9883d40c4bf6dfac4166ec009453575f Mon Sep 17 00:00:00 2001 From: Quentin Legot Date: Thu, 23 Mar 2023 21:55:09 +0100 Subject: [PATCH 11/37] Update '.gitea/workflows/test.yml' --- .gitea/workflows/test.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.gitea/workflows/test.yml b/.gitea/workflows/test.yml index 829087c..ee983cf 100644 --- a/.gitea/workflows/test.yml +++ b/.gitea/workflows/test.yml @@ -37,7 +37,7 @@ jobs: # run: ./gradlew test --no-daemon deploy: runs-on: ubuntu-latest - if: gitea.ref == 'refs/heads/master' + if: ${{ gitea.ref }} == 'refs/heads/master' steps: - name: deploy uses: actions/upload-artifact@v3 -- 2.39.5 From 088566175fb874070c0d50f8f11ca929ffffd2e9 Mon Sep 17 00:00:00 2001 From: Quentin Legot Date: Thu, 23 Mar 2023 22:02:32 +0100 Subject: [PATCH 12/37] remove deploy job --- .gitea/workflows/test.yml | 10 +--------- 1 file changed, 1 insertion(+), 9 deletions(-) diff --git a/.gitea/workflows/test.yml b/.gitea/workflows/test.yml index ee983cf..80ad767 100644 --- a/.gitea/workflows/test.yml +++ b/.gitea/workflows/test.yml @@ -35,12 +35,4 @@ jobs: run: ./gradlew build --no-daemon #- name: test # run: ./gradlew test --no-daemon - deploy: - runs-on: ubuntu-latest - if: ${{ gitea.ref }} == 'refs/heads/master' - steps: - - name: deploy - uses: actions/upload-artifact@v3 - with: - name: Artifacts - path: build/libs/ + -- 2.39.5 From 5d6cf245826b102330b815fd2b334447a45e84f3 Mon Sep 17 00:00:00 2001 From: Quentin Legot Date: Fri, 24 Mar 2023 18:41:36 +0100 Subject: [PATCH 13/37] Change values in PaginatedContentfrom String to Text for future updates Signed-off-by: Quentin Legot --- .../toolbox/pagination/PaginatedContent.java | 18 +++++++++--------- .../toolbox/pagination/api/PaginationApi.java | 5 +++-- .../pagination/api/PaginationApiImpl.java | 5 +++-- .../pagination/command/CommandsRegister.java | 2 +- 4 files changed, 16 insertions(+), 14 deletions(-) diff --git a/Pagination/src/main/java/fr/altarik/toolbox/pagination/PaginatedContent.java b/Pagination/src/main/java/fr/altarik/toolbox/pagination/PaginatedContent.java index 95ac763..23fb640 100644 --- a/Pagination/src/main/java/fr/altarik/toolbox/pagination/PaginatedContent.java +++ b/Pagination/src/main/java/fr/altarik/toolbox/pagination/PaginatedContent.java @@ -14,7 +14,7 @@ import java.util.stream.Stream; public class PaginatedContent { private final List pages; - private final String header; + private final Text header; public PaginatedContent(String header, String content) { this.header = buildHeader(header); @@ -29,11 +29,11 @@ public class PaginatedContent { } } int line = 0; - List currentPage = new ArrayList<>(); + List currentPage = new ArrayList<>(); for(String elem : secondSplit) { line++; if(!elem.isEmpty()) - currentPage.add(elem); + currentPage.add(Text.literal(elem)); if(line == 8 || elem.isEmpty()) { pages.add(new Page(currentPage)); line = 0; @@ -43,9 +43,9 @@ public class PaginatedContent { pages.add(new Page(currentPage)); } - private String buildHeader(String header) { + private Text buildHeader(String header) { int numberOfEq = (50 - header.length()) / 2; - return "=".repeat(numberOfEq) + header + "=".repeat(numberOfEq); + return Text.literal("=".repeat(numberOfEq) + header + "=".repeat(numberOfEq)); } public void display(ServerPlayerEntity playerEntity, int page) { @@ -54,9 +54,9 @@ public class PaginatedContent { } else if(page < 0) { throw new IllegalArgumentException("argument page is lower than 0"); } else { - playerEntity.sendMessage(Text.literal(header)); - for(String s : pages.get(page).lines) { - playerEntity.sendMessage(Text.literal(s)); + playerEntity.sendMessage(header); + for(Text s : pages.get(page).lines) { + playerEntity.sendMessage(s); } playerEntity.sendMessage(buildFooter(page)); @@ -87,7 +87,7 @@ public class PaginatedContent { ); } - private record Page(List lines) { + private record Page(List lines) { } } 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 index 34f8f23..eb5297b 100644 --- a/Pagination/src/main/java/fr/altarik/toolbox/pagination/api/PaginationApi.java +++ b/Pagination/src/main/java/fr/altarik/toolbox/pagination/api/PaginationApi.java @@ -2,7 +2,6 @@ package fr.altarik.toolbox.pagination.api; import net.minecraft.server.network.ServerPlayerEntity; -@SuppressWarnings("unused") // Api usage public interface PaginationApi { /** @@ -15,13 +14,15 @@ public interface PaginationApi { *

    Special values are: *

    • null if you doesn't want to add a header
    • *
    • empty String if you want just the header to be filled only with "="
    + * @param display true if you want the message to be displayed now, false otherwise if you want to display the + * message yourself * @throws IllegalArgumentException if one of its conditions is met:
      *
    1. header length is more than 50 characters
    2. *
    3. content is empty/blank
    4. *
    5. playerEntity or content are null
    6. *
    */ - void createTable(ServerPlayerEntity playerEntity, String content, String header); + void createTable(ServerPlayerEntity playerEntity, String content, String header, boolean display); /** * Display the given page for the given player 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 index 8a2abf9..5a62fb4 100644 --- a/Pagination/src/main/java/fr/altarik/toolbox/pagination/api/PaginationApiImpl.java +++ b/Pagination/src/main/java/fr/altarik/toolbox/pagination/api/PaginationApiImpl.java @@ -29,13 +29,14 @@ public class PaginationApiImpl implements PaginationApi { } @Override - public void createTable(ServerPlayerEntity playerEntity, String content, String header) { + public void createTable(ServerPlayerEntity playerEntity, String content, String header, boolean display) { if(playerCondition.test(playerEntity) || headerCondition.test(header) || contentCondition.test(content)) { throw new IllegalArgumentException("Preconditions aren't satisfied"); } PaginatedContent paginatedContent1 = new PaginatedContent(header, content); paginatedContent.put(playerEntity, new Pair<>(18000, paginatedContent1)); - paginatedContent1.display(playerEntity, 0); + if(display) + paginatedContent1.display(playerEntity, 0); } @Override 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 index 8c32487..58642c4 100644 --- a/Pagination/src/main/java/fr/altarik/toolbox/pagination/command/CommandsRegister.java +++ b/Pagination/src/main/java/fr/altarik/toolbox/pagination/command/CommandsRegister.java @@ -52,7 +52,7 @@ public class CommandsRegister { third page dqdqd dqdqd - d""", "My header"); + d""", "My header", true); return 0; } -- 2.39.5 From 30853dee70daad53de47914a02eda2b3fbb55127 Mon Sep 17 00:00:00 2001 From: Quentin Legot Date: Fri, 24 Mar 2023 19:38:40 +0100 Subject: [PATCH 14/37] Improve player feedback and improve table style Signed-off-by: Quentin Legot --- .../toolbox/pagination/PaginatedContent.java | 13 ++++++------ .../toolbox/pagination/Pagination.java | 3 ++- .../api/PageIndexOutOfBoundException.java | 20 +++++++++++++++++++ .../toolbox/pagination/api/PaginationApi.java | 2 +- .../pagination/api/PaginationApiImpl.java | 11 +++++++--- .../pagination/command/CommandsRegister.java | 9 +++++---- .../assets/pagination/lang/en_us.json | 4 ++++ 7 files changed, 47 insertions(+), 15 deletions(-) create mode 100644 Pagination/src/main/java/fr/altarik/toolbox/pagination/api/PageIndexOutOfBoundException.java create mode 100644 Pagination/src/main/resources/assets/pagination/lang/en_us.json diff --git a/Pagination/src/main/java/fr/altarik/toolbox/pagination/PaginatedContent.java b/Pagination/src/main/java/fr/altarik/toolbox/pagination/PaginatedContent.java index 23fb640..6cadae2 100644 --- a/Pagination/src/main/java/fr/altarik/toolbox/pagination/PaginatedContent.java +++ b/Pagination/src/main/java/fr/altarik/toolbox/pagination/PaginatedContent.java @@ -1,5 +1,6 @@ package fr.altarik.toolbox.pagination; +import fr.altarik.toolbox.pagination.api.PageIndexOutOfBoundException; import net.minecraft.server.network.ServerPlayerEntity; import net.minecraft.text.ClickEvent; import net.minecraft.text.MutableText; @@ -45,14 +46,14 @@ public class PaginatedContent { private Text buildHeader(String header) { int numberOfEq = (50 - header.length()) / 2; - return Text.literal("=".repeat(numberOfEq) + header + "=".repeat(numberOfEq)); + return Text.literal("=".repeat(numberOfEq) + " " + header + " " + "=".repeat(numberOfEq)); } - public void display(ServerPlayerEntity playerEntity, int page) { + public void display(ServerPlayerEntity playerEntity, int page) throws PageIndexOutOfBoundException { if(page >= this.pages.size()) { - throw new IllegalArgumentException("There's " + this.pages.size() + " paginated pages but you wanted page n°" + (page + 1)); + throw new PageIndexOutOfBoundException("api.pagination.page_higher_than_expected", this.pages.size(), (page + 1)); } else if(page < 0) { - throw new IllegalArgumentException("argument page is lower than 0"); + throw new PageIndexOutOfBoundException("api.pagination.page_lower_than_0"); } else { playerEntity.sendMessage(header); for(Text s : pages.get(page).lines) { @@ -66,13 +67,13 @@ public class PaginatedContent { private Text buildFooter(int page) { String strPage = String.valueOf(page + 1); int numberOfEq = (46 - strPage.length()) / 2; - MutableText left = Text.literal("<").styled( + MutableText left = Text.literal(" <").styled( style -> style .withColor(Formatting.YELLOW) .withClickEvent(new ClickEvent(ClickEvent.Action.RUN_COMMAND, "/table page " + (page - 1))) ); MutableText middle = Text.literal(" " + strPage + " ").styled(style -> style.withColor(Formatting.RESET)); - MutableText right = Text.literal(">").styled( + MutableText right = Text.literal("> ").styled( style -> style .withColor(Formatting.YELLOW) .withClickEvent(new ClickEvent(ClickEvent.Action.RUN_COMMAND, "/table page " + (page + 1))) diff --git a/Pagination/src/main/java/fr/altarik/toolbox/pagination/Pagination.java b/Pagination/src/main/java/fr/altarik/toolbox/pagination/Pagination.java index 8e4b19e..5ef76c5 100644 --- a/Pagination/src/main/java/fr/altarik/toolbox/pagination/Pagination.java +++ b/Pagination/src/main/java/fr/altarik/toolbox/pagination/Pagination.java @@ -19,13 +19,14 @@ public class Pagination implements ModInitializer { @Override public void onInitialize() { - CommandRegistrationCallback.EVENT.register((dispatcher, registryAccess, environment) -> new CommandsRegister(this).register(dispatcher, environment.dedicated)); + CommandRegistrationCallback.EVENT.register((dispatcher, registryAccess, environment) -> new CommandsRegister(this).register(dispatcher)); } public @NotNull PaginationApi getApi() { return api; } + @SuppressWarnings("unused") public static @NotNull Pagination getInstance() { return instance; } diff --git a/Pagination/src/main/java/fr/altarik/toolbox/pagination/api/PageIndexOutOfBoundException.java b/Pagination/src/main/java/fr/altarik/toolbox/pagination/api/PageIndexOutOfBoundException.java new file mode 100644 index 0000000..1d222f8 --- /dev/null +++ b/Pagination/src/main/java/fr/altarik/toolbox/pagination/api/PageIndexOutOfBoundException.java @@ -0,0 +1,20 @@ +package fr.altarik.toolbox.pagination.api; + +import net.minecraft.text.Text; + +public class PageIndexOutOfBoundException extends Exception { + + private final Text text; + + public PageIndexOutOfBoundException(String s) { + this.text = Text.translatable(s); + } + + public PageIndexOutOfBoundException(String s, int size, int currentPage) { + this.text = Text.translatable(s, size, currentPage); + } + + public Text getText() { + return text; + } +} 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 index eb5297b..88f345e 100644 --- a/Pagination/src/main/java/fr/altarik/toolbox/pagination/api/PaginationApi.java +++ b/Pagination/src/main/java/fr/altarik/toolbox/pagination/api/PaginationApi.java @@ -32,6 +32,6 @@ public interface PaginationApi { * @throws NullPointerException if player is null or paginated content for the player doesn't exist (or have expired) * @see fr.altarik.toolbox.pagination.PaginatedContent#display(ServerPlayerEntity, int) */ - void display(ServerPlayerEntity player, int page); + void display(ServerPlayerEntity player, int page) throws PageIndexOutOfBoundException; } 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 index 5a62fb4..43c858f 100644 --- a/Pagination/src/main/java/fr/altarik/toolbox/pagination/api/PaginationApiImpl.java +++ b/Pagination/src/main/java/fr/altarik/toolbox/pagination/api/PaginationApiImpl.java @@ -35,12 +35,17 @@ public class PaginationApiImpl implements PaginationApi { } PaginatedContent paginatedContent1 = new PaginatedContent(header, content); paginatedContent.put(playerEntity, new Pair<>(18000, paginatedContent1)); - if(display) - paginatedContent1.display(playerEntity, 0); + if(display) { + try { + paginatedContent1.display(playerEntity, 0); + } catch (PageIndexOutOfBoundException e) { + throw new IllegalArgumentException(e); + } + } } @Override - public void display(ServerPlayerEntity player, int page) { + public void display(ServerPlayerEntity player, int page) throws PageIndexOutOfBoundException { if(player == null) throw new NullPointerException("Player is null"); Pair pair = paginatedContent.get(player); 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 index 58642c4..57be1f0 100644 --- a/Pagination/src/main/java/fr/altarik/toolbox/pagination/command/CommandsRegister.java +++ b/Pagination/src/main/java/fr/altarik/toolbox/pagination/command/CommandsRegister.java @@ -4,10 +4,11 @@ import com.mojang.brigadier.CommandDispatcher; import com.mojang.brigadier.arguments.IntegerArgumentType; import com.mojang.brigadier.context.CommandContext; import com.mojang.brigadier.exceptions.CommandSyntaxException; +import com.mojang.brigadier.exceptions.SimpleCommandExceptionType; import fr.altarik.toolbox.pagination.Pagination; +import fr.altarik.toolbox.pagination.api.PageIndexOutOfBoundException; import fr.altarik.toolbox.pagination.api.PaginationApi; import net.minecraft.server.command.ServerCommandSource; -import net.minecraft.text.Text; import static net.minecraft.server.command.CommandManager.argument; import static net.minecraft.server.command.CommandManager.literal; @@ -20,7 +21,7 @@ public class CommandsRegister { this.api = instance.getApi(); } - public void register(CommandDispatcher dispatcher, boolean dedicated) { + public void register(CommandDispatcher dispatcher) { dispatcher.register(literal("table") .then(literal("page") .then(argument("page", IntegerArgumentType.integer()) @@ -60,8 +61,8 @@ public class CommandsRegister { try { int page = IntegerArgumentType.getInteger(context, "page"); api.display(context.getSource().getPlayerOrThrow(), page); - } catch(NullPointerException | IllegalArgumentException e) { - context.getSource().sendFeedback(Text.literal("Error: " + e.getMessage()), false); + } catch(PageIndexOutOfBoundException e) { + throw new CommandSyntaxException(new SimpleCommandExceptionType(e.getText()), e.getText()); } return 0; } diff --git a/Pagination/src/main/resources/assets/pagination/lang/en_us.json b/Pagination/src/main/resources/assets/pagination/lang/en_us.json new file mode 100644 index 0000000..94665c3 --- /dev/null +++ b/Pagination/src/main/resources/assets/pagination/lang/en_us.json @@ -0,0 +1,4 @@ +{ + "api.pagination.page_lower_than_0": "argument page is lower than 0", + "api.pagination.page_higher_than_expected": "There's %d paginated pages but you wanted page n°%d" +} \ No newline at end of file -- 2.39.5 From 351b8aaf84258760a568552add7c88ba244e0173 Mon Sep 17 00:00:00 2001 From: Quentin Legot Date: Fri, 24 Mar 2023 19:56:10 +0100 Subject: [PATCH 15/37] Add a new api method (not developed yet) Signed-off-by: Quentin Legot --- .../toolbox/pagination/api/PaginationApi.java | 29 ++++++++++++++++++- .../pagination/api/PaginationApiImpl.java | 6 ++++ 2 files changed, 34 insertions(+), 1 deletion(-) 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 index 88f345e..c7bea9a 100644 --- a/Pagination/src/main/java/fr/altarik/toolbox/pagination/api/PaginationApi.java +++ b/Pagination/src/main/java/fr/altarik/toolbox/pagination/api/PaginationApi.java @@ -1,12 +1,15 @@ package fr.altarik.toolbox.pagination.api; import net.minecraft.server.network.ServerPlayerEntity; +import net.minecraft.text.Text; + +import java.util.List; 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.

    + * You can separate yourself content between two pages by adding *\n\n*.

    *

    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 @@ -24,6 +27,30 @@ public interface PaginationApi { */ void createTable(ServerPlayerEntity playerEntity, String content, String header, boolean display); + /** + *

    Create a pagination table for player the same way than + * {@link PaginationApi#createTable(ServerPlayerEntity, String, String, boolean)}, + * content is separated into multiple pages.
    + * You can separate yourself content between 2 pages by adding a null instance of Text in content list.

    + *

    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:

    + *
    • null if you doesn't want to add a header
    • + *
    • Empty textif you want just the header to be filled only with "="
    + * @param display true if you want the message to be displayed now, false otherwise if you want to display the + * message yourself + * @throws IllegalArgumentException if one of its conditions is met:
      + *
    1. header length is more than 50 characters
    2. + *
    3. content is empty/blank
    4. + *
    5. playerEntity or content are null
    6. + *
    + * @see Text#empty() + */ + void createTable(ServerPlayerEntity playerEntity, List content, Text header, boolean display); + + /** * Display the given page for the given player * @param player display the content of this player 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 index 43c858f..a95946c 100644 --- a/Pagination/src/main/java/fr/altarik/toolbox/pagination/api/PaginationApiImpl.java +++ b/Pagination/src/main/java/fr/altarik/toolbox/pagination/api/PaginationApiImpl.java @@ -7,6 +7,7 @@ import fr.altarik.toolbox.pagination.precondition.NullPlayerCondition; import net.fabricmc.fabric.api.event.lifecycle.v1.ServerTickEvents; import net.minecraft.server.MinecraftServer; import net.minecraft.server.network.ServerPlayerEntity; +import net.minecraft.text.Text; import net.minecraft.util.Pair; import java.util.ArrayList; @@ -44,6 +45,11 @@ public class PaginationApiImpl implements PaginationApi { } } + @Override + public void createTable(ServerPlayerEntity playerEntity, List content, Text header, boolean display) { + throw new UnsupportedOperationException("Not yet implemented"); + } + @Override public void display(ServerPlayerEntity player, int page) throws PageIndexOutOfBoundException { if(player == null) -- 2.39.5 From 48e53e0edb6b716cf341a21905fab0c5b32fc88f Mon Sep 17 00:00:00 2001 From: Quentin Legot Date: Fri, 24 Mar 2023 21:58:05 +0100 Subject: [PATCH 16/37] Added support of Text for Pagination Signed-off-by: Quentin Legot --- .../toolbox/pagination/PaginatedContent.java | 33 ++++++++++++++---- .../toolbox/pagination/api/PaginationApi.java | 3 +- .../pagination/api/PaginationApiImpl.java | 19 ++++++++--- .../pagination/command/CommandsRegister.java | 34 ++++++++++++++++++- 4 files changed, 75 insertions(+), 14 deletions(-) diff --git a/Pagination/src/main/java/fr/altarik/toolbox/pagination/PaginatedContent.java b/Pagination/src/main/java/fr/altarik/toolbox/pagination/PaginatedContent.java index 6cadae2..f6868c4 100644 --- a/Pagination/src/main/java/fr/altarik/toolbox/pagination/PaginatedContent.java +++ b/Pagination/src/main/java/fr/altarik/toolbox/pagination/PaginatedContent.java @@ -6,6 +6,7 @@ import net.minecraft.text.ClickEvent; import net.minecraft.text.MutableText; import net.minecraft.text.Text; import net.minecraft.util.Formatting; +import org.jetbrains.annotations.Nullable; import java.util.ArrayList; import java.util.List; @@ -29,26 +30,44 @@ public class PaginatedContent { secondSplit.add(elem); } } - int line = 0; List currentPage = new ArrayList<>(); for(String elem : secondSplit) { - line++; - if(!elem.isEmpty()) + if(!elem.isEmpty()) { currentPage.add(Text.literal(elem)); - if(line == 8 || elem.isEmpty()) { + } + if(currentPage.size() == 8 || elem.isEmpty()) { pages.add(new Page(currentPage)); - line = 0; currentPage = new ArrayList<>(); } } pages.add(new Page(currentPage)); } - private Text buildHeader(String header) { - int numberOfEq = (50 - header.length()) / 2; + public PaginatedContent(@Nullable Text header, List content) { + this.header = buildHeader(header); + this.pages = new ArrayList<>(); + List currentPage = new ArrayList<>(); + for(Text elem : content) { + if(elem != null) + currentPage.add(elem); + if(currentPage.size() == 8 || elem == null) { + pages.add(new Page(currentPage)); + currentPage = new ArrayList<>(); + } + } + pages.add(new Page(currentPage)); + } + + private Text buildHeader(@Nullable String header) { + int numberOfEq = (50 - (header != null ? header.length() : 0)) / 2; return Text.literal("=".repeat(numberOfEq) + " " + header + " " + "=".repeat(numberOfEq)); } + private Text buildHeader(@Nullable Text header) { + int numberOfEq = (50 - (header != null ? header.getString().length() : 0)) / 2; + return Text.literal("=".repeat(numberOfEq) + " ").append(header).append(" " + "=".repeat(numberOfEq)); + } + public void display(ServerPlayerEntity playerEntity, int page) throws PageIndexOutOfBoundException { if(page >= this.pages.size()) { throw new PageIndexOutOfBoundException("api.pagination.page_higher_than_expected", this.pages.size(), (page + 1)); 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 index c7bea9a..cee4fcf 100644 --- a/Pagination/src/main/java/fr/altarik/toolbox/pagination/api/PaginationApi.java +++ b/Pagination/src/main/java/fr/altarik/toolbox/pagination/api/PaginationApi.java @@ -2,6 +2,7 @@ package fr.altarik.toolbox.pagination.api; import net.minecraft.server.network.ServerPlayerEntity; import net.minecraft.text.Text; +import org.jetbrains.annotations.Nullable; import java.util.List; @@ -48,7 +49,7 @@ public interface PaginationApi { * * @see Text#empty() */ - void createTable(ServerPlayerEntity playerEntity, List content, Text header, boolean display); + void createTable(ServerPlayerEntity playerEntity, List content, @Nullable Text header, boolean display); /** 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 index a95946c..700997c 100644 --- a/Pagination/src/main/java/fr/altarik/toolbox/pagination/api/PaginationApiImpl.java +++ b/Pagination/src/main/java/fr/altarik/toolbox/pagination/api/PaginationApiImpl.java @@ -9,6 +9,7 @@ import net.minecraft.server.MinecraftServer; import net.minecraft.server.network.ServerPlayerEntity; import net.minecraft.text.Text; import net.minecraft.util.Pair; +import org.jetbrains.annotations.Nullable; import java.util.ArrayList; import java.util.HashMap; @@ -35,6 +36,19 @@ public class PaginationApiImpl implements PaginationApi { throw new IllegalArgumentException("Preconditions aren't satisfied"); } PaginatedContent paginatedContent1 = new PaginatedContent(header, content); + storeAndDisplay(playerEntity, paginatedContent1, display); + } + + @Override + public void createTable(ServerPlayerEntity playerEntity, List content, @Nullable Text header, boolean display) { + if(playerCondition.test(playerEntity)) { + throw new IllegalArgumentException("Preconditions aren't satisfied"); + } + PaginatedContent paginatedContent1 = new PaginatedContent(header, content); + storeAndDisplay(playerEntity, paginatedContent1, display); + } + + private void storeAndDisplay(ServerPlayerEntity playerEntity, PaginatedContent paginatedContent1, boolean display) { paginatedContent.put(playerEntity, new Pair<>(18000, paginatedContent1)); if(display) { try { @@ -45,11 +59,6 @@ public class PaginationApiImpl implements PaginationApi { } } - @Override - public void createTable(ServerPlayerEntity playerEntity, List content, Text header, boolean display) { - throw new UnsupportedOperationException("Not yet implemented"); - } - @Override public void display(ServerPlayerEntity player, int page) throws PageIndexOutOfBoundException { if(player == null) 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 index 57be1f0..e46d715 100644 --- a/Pagination/src/main/java/fr/altarik/toolbox/pagination/command/CommandsRegister.java +++ b/Pagination/src/main/java/fr/altarik/toolbox/pagination/command/CommandsRegister.java @@ -9,6 +9,10 @@ import fr.altarik.toolbox.pagination.Pagination; import fr.altarik.toolbox.pagination.api.PageIndexOutOfBoundException; import fr.altarik.toolbox.pagination.api.PaginationApi; import net.minecraft.server.command.ServerCommandSource; +import net.minecraft.text.Text; + +import java.util.ArrayList; +import java.util.List; import static net.minecraft.server.command.CommandManager.argument; import static net.minecraft.server.command.CommandManager.literal; @@ -30,6 +34,9 @@ public class CommandsRegister { ).then(literal("test") .requires(source -> source.isExecutedByPlayer() && source.hasPermissionLevel(3)) .executes(this::testPageCommand) + ).then(literal("testText") + .requires(source -> source.isExecutedByPlayer() && source.hasPermissionLevel(3)) + .executes(this::testPageTextCommand) ) ); } @@ -39,7 +46,7 @@ public class CommandsRegister { */ private int testPageCommand(CommandContext context) { api.createTable(context.getSource().getPlayer(), """ - first line + first line, string version Second line second page @@ -57,6 +64,26 @@ public class CommandsRegister { return 0; } + private int testPageTextCommand(CommandContext context) { + List content = new ArrayList<>(); + content.add(Text.literal("first line, text version")); + content.add(Text.literal("Second line")); + content.add(null); + content.add(Text.literal("second page")); + content.add(Text.literal("dqdq")); + content.add(Text.literal("dqdqd")); + content.add(Text.literal("dqdqd")); + content.add(Text.literal("dqdq")); + content.add(Text.literal("dqdq")); + content.add(Text.literal("dqdq")); + content.add(Text.literal("dqdqd")); + content.add(Text.literal("third page")); + content.add(Text.literal("dqdqd")); + content.add(Text.literal("dqdqd")); + api.createTable(context.getSource().getPlayer(), content, Text.literal("My Text Header"), true); + return 0; + } + private int selectPageCommand(CommandContext context) throws CommandSyntaxException { try { int page = IntegerArgumentType.getInteger(context, "page"); @@ -67,4 +94,9 @@ public class CommandsRegister { return 0; } + private enum TestType { + String, + Text; + } + } -- 2.39.5 From 6f059785532cafb6131755ef65966e79a4554867 Mon Sep 17 00:00:00 2001 From: Quentin Legot Date: Mon, 5 Jun 2023 18:42:20 +0200 Subject: [PATCH 17/37] Add KeyValueConnection, update loom to 1.2, gradle to 8.1 --- .../database/AbstractSqlConnection.java | 18 ++- .../toolbox/database/PostgresConnection.java | 2 +- .../toolbox/database/SqlConnection.java | 18 ++- .../database/keyvalue/KeyValueBuilder.java | 59 +++++++ .../database/keyvalue/KeyValueConnection.java | 146 ++++++++++++++++++ build.gradle | 2 +- gradle/wrapper/gradle-wrapper.properties | 2 +- 7 files changed, 235 insertions(+), 12 deletions(-) create mode 100644 Database/src/main/java/fr/altarik/toolbox/database/keyvalue/KeyValueBuilder.java create mode 100644 Database/src/main/java/fr/altarik/toolbox/database/keyvalue/KeyValueConnection.java diff --git a/Database/src/main/java/fr/altarik/toolbox/database/AbstractSqlConnection.java b/Database/src/main/java/fr/altarik/toolbox/database/AbstractSqlConnection.java index 7fefcce..e2a4c15 100644 --- a/Database/src/main/java/fr/altarik/toolbox/database/AbstractSqlConnection.java +++ b/Database/src/main/java/fr/altarik/toolbox/database/AbstractSqlConnection.java @@ -25,16 +25,18 @@ public abstract class AbstractSqlConnection implements SqlConnection { return connection; } + @Override public void closeConnection() { try { - if(!connection.isClosed()) { - connection.close(); - connection = null; - } - } catch(SQLException ignored) { - // no op - } + close(); + } catch (Exception ignored) {} } - + @Override + public void close() throws Exception { + if(!connection.isClosed()) { + connection.close(); + connection = null; + } + } } diff --git a/Database/src/main/java/fr/altarik/toolbox/database/PostgresConnection.java b/Database/src/main/java/fr/altarik/toolbox/database/PostgresConnection.java index beac2bb..a20d381 100644 --- a/Database/src/main/java/fr/altarik/toolbox/database/PostgresConnection.java +++ b/Database/src/main/java/fr/altarik/toolbox/database/PostgresConnection.java @@ -5,7 +5,7 @@ import java.sql.SQLException; public class PostgresConnection extends AbstractSqlConnection { - PostgresConnection(ConnectionConfig config) throws SQLException { + public PostgresConnection(ConnectionConfig config) throws SQLException { super(config); } diff --git a/Database/src/main/java/fr/altarik/toolbox/database/SqlConnection.java b/Database/src/main/java/fr/altarik/toolbox/database/SqlConnection.java index 0b04fe4..a2839d7 100644 --- a/Database/src/main/java/fr/altarik/toolbox/database/SqlConnection.java +++ b/Database/src/main/java/fr/altarik/toolbox/database/SqlConnection.java @@ -3,14 +3,30 @@ package fr.altarik.toolbox.database; import java.sql.Connection; import java.sql.SQLException; -public interface SqlConnection { +public interface SqlConnection extends AutoCloseable { + /** + * Start the connection to sql database + * @throws SQLException if unable to connect to database + */ void connect() throws SQLException; + /** + * Get the sql connection + * @return the connection session + */ Connection getConnection(); + /** + * Reconnect you to database if it has closed or lost. + * @throws SQLException if unable to reconnect you + */ void checkConnection() throws SQLException; + /** + * @deprecated replaced with {@link AutoCloseable#close()} + */ + @Deprecated(forRemoval = true) void closeConnection(); } diff --git a/Database/src/main/java/fr/altarik/toolbox/database/keyvalue/KeyValueBuilder.java b/Database/src/main/java/fr/altarik/toolbox/database/keyvalue/KeyValueBuilder.java new file mode 100644 index 0000000..a665599 --- /dev/null +++ b/Database/src/main/java/fr/altarik/toolbox/database/keyvalue/KeyValueBuilder.java @@ -0,0 +1,59 @@ +package fr.altarik.toolbox.database.keyvalue; + +import fr.altarik.toolbox.database.SqlConnection; +import net.minecraft.util.Pair; +import org.jetbrains.annotations.NotNull; +import org.jetbrains.annotations.Nullable; + +import java.sql.JDBCType; +import java.sql.SQLException; +import java.util.ArrayList; +import java.util.List; +import java.util.Objects; + +public class KeyValueBuilder { + + private final String tableName; + private final List additionalColumns; + private final SqlConnection connection; + + private KeyValueBuilder(SqlConnection connection, String tableName) { + this.connection = connection; + this.tableName = tableName; + this.additionalColumns = new ArrayList<>(); + } + + public static KeyValueBuilder builder(@NotNull SqlConnection connection, @NotNull String tableName) { + return new KeyValueBuilder(connection, tableName); + } + + public KeyValueBuilder addColumn(AdditionalColumn additionalColumn) { + this.additionalColumns.add(additionalColumn); + return this; + } + + public KeyValueConnection build() throws SQLException { + return new KeyValueConnection(connection, tableName, additionalColumns); + } + + public record AdditionalColumn(@NotNull String columnName, @NotNull JDBCType type, boolean notNull, @Nullable AdditionalColumnReference reference) { + public AdditionalColumn { + Objects.requireNonNull(columnName); + Objects.requireNonNull(type); + } + + public Pair toPair(Object value) { + return new Pair<>(this, value); + } + } + + public record AdditionalColumnReference(@NotNull String referenceTable, @NotNull String... referenceColumns) { + public AdditionalColumnReference { + Objects.requireNonNull(referenceTable); + if(Objects.requireNonNull(referenceColumns).length == 0) + throw new IllegalArgumentException("Reference Columns should not be empty"); + } + + } + +} diff --git a/Database/src/main/java/fr/altarik/toolbox/database/keyvalue/KeyValueConnection.java b/Database/src/main/java/fr/altarik/toolbox/database/keyvalue/KeyValueConnection.java new file mode 100644 index 0000000..9970629 --- /dev/null +++ b/Database/src/main/java/fr/altarik/toolbox/database/keyvalue/KeyValueConnection.java @@ -0,0 +1,146 @@ +package fr.altarik.toolbox.database.keyvalue; + +import fr.altarik.toolbox.database.SqlConnection; +import net.minecraft.util.Pair; +import org.jetbrains.annotations.Nullable; + +import java.sql.PreparedStatement; +import java.sql.ResultSet; +import java.sql.SQLException; +import java.sql.Statement; +import java.util.List; + +public class KeyValueConnection { + + private final SqlConnection connection; + private final String tableName; + private final List additionColumns; + + public KeyValueConnection(SqlConnection connection, String tableName, List additionalColumns) throws SQLException { + this.connection = connection; + this.tableName = tableName; + this.additionColumns = additionalColumns; + + try(Statement statement = connection.getConnection().createStatement()) { + StringBuilder sql = new StringBuilder("CREATE TABLE IF NOT EXISTS ").append(tableName).append("(id SERIAL,"); + for(KeyValueBuilder.AdditionalColumn additionalColumn : additionalColumns) { + sql.append(additionalColumn.columnName()).append(" ").append(additionalColumn.type().getName()); + if(additionalColumn.notNull()) { + sql.append(" NOT NULL "); + } + if(additionalColumn.reference() != null) { + sql.append("REFERENCES ").append(additionalColumn.reference().referenceTable()).append("("); + for(int i = 0; i < additionalColumn.reference().referenceColumns().length; ++i) { + sql.append(additionalColumn.reference().referenceColumns()[i]); + if(i != additionalColumn.reference().referenceColumns().length - 1) { + sql.append(", "); + } + } + sql.append(")"); + } + sql.append(","); + sql.append("key VARCHAR(50) NOT NULL,").append("value TEXT NOT NULL,").append("PRIMARY KEY(id)"); + } + statement.executeUpdate(sql.toString()); + + + } + } + + public @Nullable String getValueById(int id) throws SQLException { + try(PreparedStatement preparedStatement = connection.getConnection().prepareStatement("SELECT value FROM " + tableName + " WHERE id=?")) { + preparedStatement.setInt(1, id); + ResultSet resultSet = preparedStatement.executeQuery(); + if(resultSet.next()) { + return resultSet.getString(1); + } + return null; + } + } + + public @Nullable String getValueByAdditionalColumnAndKey(String key, List> additionalColumns) throws SQLException { + StringBuilder sql = new StringBuilder("SELECT value FROM ").append(tableName).append(" WHERE key=? AND "); + for(int i = 0; i < additionalColumns.size(); ++i) { + sql.append(additionalColumns.get(i).getLeft().columnName()).append("=?"); + if(i != additionalColumns.size() - 1) { + sql.append(" AND "); + } + } + sql.append(";"); + try(PreparedStatement preparedStatement = connection.getConnection().prepareStatement(sql.toString())) { + preparedStatement.setString(1, key); + for(int i = 0; i < additionalColumns.size(); ++i) { + preparedStatement.setObject(i + 1, additionalColumns.get(i).getRight()); + } + ResultSet resultSet = preparedStatement.executeQuery(); + if(resultSet.next()) + return resultSet.getString(1); + return null; + } + } + + public long insertValue(String key, String value, List> additionalColumns) throws SQLException { + StringBuilder sql = new StringBuilder("INSERT INTO " + tableName + "(key, value"); + for(int i = 0; i < additionalColumns.size(); ++i) { + if(i != additionalColumns.size() - 1) { + sql.append(", "); + } + sql.append(additionalColumns.get(i).getLeft().columnName()); + + } + sql.append(") VALUES (?, ?"); + for(int i = 0; i < additionalColumns.size(); ++i) { + if(i != additionalColumns.size() - 1) { + sql.append(", "); + } + sql.append("?"); + } + sql.append(");"); + try(PreparedStatement preparedStatement = connection.getConnection().prepareStatement(sql.toString(), Statement.RETURN_GENERATED_KEYS)){ + preparedStatement.setString(1, key); + preparedStatement.setString(2, value); + for(int i = 0; i < additionalColumns.size(); ++i) { + preparedStatement.setObject(i + 3, additionalColumns.get(i).getRight()); + } + preparedStatement.executeUpdate(); + try(ResultSet resultSet = preparedStatement.getGeneratedKeys()) { + if(resultSet.next()) { + return resultSet.getLong(1); + } + return -1L; + } + } + } + + public void updateValueById(String key, String value) throws SQLException { + try(PreparedStatement preparedStatement = connection.getConnection().prepareStatement("UPDATE " + tableName + " SET value=? WHERE key=?")) { + preparedStatement.setString(1, value); + preparedStatement.setString(2, key); + preparedStatement.executeUpdate(); + } + + } + + public void updateValue(String key, String value, List> additionalColumns) throws SQLException { + StringBuilder sql = new StringBuilder("UPDATE " + tableName + " SET value=? WHERE key=?"); + for(int i = 0; i < additionalColumns.size(); ++i) { + if(i != additionalColumns.size() - 1) { + sql.append(" AND "); + } + sql.append(additionalColumns.get(i).getLeft().columnName()).append("=?"); + } + sql.append(";"); + try(PreparedStatement preparedStatement = connection.getConnection().prepareStatement(sql.toString())) { + preparedStatement.setString(1, value); + preparedStatement.setString(2, key); + for(int i = 0; i < additionalColumns.size(); ++i) { + preparedStatement.setObject(3 + i, additionalColumns.get(i).getRight()); + } + preparedStatement.executeUpdate(); + } + } + + public List getAdditionColumns() { + return additionColumns; + } +} diff --git a/build.gradle b/build.gradle index d168d1d..e6c86e7 100644 --- a/build.gradle +++ b/build.gradle @@ -1,5 +1,5 @@ plugins { - id 'fabric-loom' version '1.1-SNAPSHOT' apply false + id 'fabric-loom' version '1.2-SNAPSHOT' apply false } allprojects { diff --git a/gradle/wrapper/gradle-wrapper.properties b/gradle/wrapper/gradle-wrapper.properties index 070cb70..59bc51a 100644 --- a/gradle/wrapper/gradle-wrapper.properties +++ b/gradle/wrapper/gradle-wrapper.properties @@ -1,5 +1,5 @@ distributionBase=GRADLE_USER_HOME distributionPath=wrapper/dists -distributionUrl=https\://services.gradle.org/distributions/gradle-7.6-bin.zip +distributionUrl=https\://services.gradle.org/distributions/gradle-8.1-bin.zip zipStoreBase=GRADLE_USER_HOME zipStorePath=wrapper/dists -- 2.39.5 From 879dd5554df8d918ab4b0357b773858384bee118 Mon Sep 17 00:00:00 2001 From: Quentin Legot Date: Mon, 5 Jun 2023 22:38:53 +0200 Subject: [PATCH 18/37] Add comments to KeyValueTable, KeyValueConnection implements KeyValueTable --- .../database/keyvalue/KeyValueConnection.java | 23 ++++-- .../database/keyvalue/KeyValueTable.java | 72 +++++++++++++++++++ 2 files changed, 90 insertions(+), 5 deletions(-) create mode 100644 Database/src/main/java/fr/altarik/toolbox/database/keyvalue/KeyValueTable.java diff --git a/Database/src/main/java/fr/altarik/toolbox/database/keyvalue/KeyValueConnection.java b/Database/src/main/java/fr/altarik/toolbox/database/keyvalue/KeyValueConnection.java index 9970629..2fabedb 100644 --- a/Database/src/main/java/fr/altarik/toolbox/database/keyvalue/KeyValueConnection.java +++ b/Database/src/main/java/fr/altarik/toolbox/database/keyvalue/KeyValueConnection.java @@ -2,6 +2,7 @@ package fr.altarik.toolbox.database.keyvalue; import fr.altarik.toolbox.database.SqlConnection; import net.minecraft.util.Pair; +import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.Nullable; import java.sql.PreparedStatement; @@ -10,16 +11,17 @@ import java.sql.SQLException; import java.sql.Statement; import java.util.List; -public class KeyValueConnection { +public class KeyValueConnection implements KeyValueTable { private final SqlConnection connection; private final String tableName; private final List additionColumns; - public KeyValueConnection(SqlConnection connection, String tableName, List additionalColumns) throws SQLException { + public KeyValueConnection(@NotNull SqlConnection connection, @NotNull String tableName, @NotNull List additionalColumns) throws SQLException { this.connection = connection; this.tableName = tableName; this.additionColumns = additionalColumns; + connection.checkConnection(); try(Statement statement = connection.getConnection().createStatement()) { StringBuilder sql = new StringBuilder("CREATE TABLE IF NOT EXISTS ").append(tableName).append("(id SERIAL,"); @@ -47,7 +49,9 @@ public class KeyValueConnection { } } + @Override public @Nullable String getValueById(int id) throws SQLException { + connection.checkConnection(); try(PreparedStatement preparedStatement = connection.getConnection().prepareStatement("SELECT value FROM " + tableName + " WHERE id=?")) { preparedStatement.setInt(1, id); ResultSet resultSet = preparedStatement.executeQuery(); @@ -58,8 +62,10 @@ public class KeyValueConnection { } } - public @Nullable String getValueByAdditionalColumnAndKey(String key, List> additionalColumns) throws SQLException { - StringBuilder sql = new StringBuilder("SELECT value FROM ").append(tableName).append(" WHERE key=? AND "); + @Override + public @Nullable Result getValueByAdditionalColumnAndKey(String key, List> additionalColumns) throws SQLException { + connection.checkConnection(); + StringBuilder sql = new StringBuilder("SELECT id, value FROM ").append(tableName).append(" WHERE key=? AND "); for(int i = 0; i < additionalColumns.size(); ++i) { sql.append(additionalColumns.get(i).getLeft().columnName()).append("=?"); if(i != additionalColumns.size() - 1) { @@ -74,12 +80,14 @@ public class KeyValueConnection { } ResultSet resultSet = preparedStatement.executeQuery(); if(resultSet.next()) - return resultSet.getString(1); + return new Result(resultSet.getString(1), resultSet.getString(2)); return null; } } + @Override public long insertValue(String key, String value, List> additionalColumns) throws SQLException { + connection.checkConnection(); StringBuilder sql = new StringBuilder("INSERT INTO " + tableName + "(key, value"); for(int i = 0; i < additionalColumns.size(); ++i) { if(i != additionalColumns.size() - 1) { @@ -112,7 +120,9 @@ public class KeyValueConnection { } } + @Override public void updateValueById(String key, String value) throws SQLException { + connection.checkConnection(); try(PreparedStatement preparedStatement = connection.getConnection().prepareStatement("UPDATE " + tableName + " SET value=? WHERE key=?")) { preparedStatement.setString(1, value); preparedStatement.setString(2, key); @@ -121,7 +131,9 @@ public class KeyValueConnection { } + @Override public void updateValue(String key, String value, List> additionalColumns) throws SQLException { + connection.checkConnection(); StringBuilder sql = new StringBuilder("UPDATE " + tableName + " SET value=? WHERE key=?"); for(int i = 0; i < additionalColumns.size(); ++i) { if(i != additionalColumns.size() - 1) { @@ -140,6 +152,7 @@ public class KeyValueConnection { } } + @Override public List getAdditionColumns() { return additionColumns; } diff --git a/Database/src/main/java/fr/altarik/toolbox/database/keyvalue/KeyValueTable.java b/Database/src/main/java/fr/altarik/toolbox/database/keyvalue/KeyValueTable.java new file mode 100644 index 0000000..67079f9 --- /dev/null +++ b/Database/src/main/java/fr/altarik/toolbox/database/keyvalue/KeyValueTable.java @@ -0,0 +1,72 @@ +package fr.altarik.toolbox.database.keyvalue; + +import net.minecraft.util.Pair; +import org.jetbrains.annotations.Nullable; + +import java.sql.SQLException; +import java.util.List; + +public interface KeyValueTable { + + /** + * Return the value which correspond to the given id + * @param id primary key, unique id of the key value table + * @return the correspond value + * @throws SQLException when connection is lost + */ + @Nullable String getValueById(int id) throws SQLException; + + /** + *

    Return the first value associated with the key and all the additional columns values given.

    + *

    In a perfect context, key and additional columns combinaison return a pseudo unique result.

    + * + * @param key String key of associated to the value, doesn't require to be unique + * @param additionalColumns Object keys of associated to the value, doesn't require to be unique + * @return first (id, value) pair associated with the key and additonal columns combinaison + * @throws SQLException if connection is lost, or if additional columns name or value format is incorrect + */ + @Nullable Result getValueByAdditionalColumnAndKey(String key, List> additionalColumns) throws SQLException; + + /** + *

    Insert a new value in the table, associate key and additional columns with the value

    + *

    Key and additional columns doesn't need to be unique, the combinaison of them have the goal to be unique or it isn't a hard requirement

    + * @param key String key which will be associated with the value, doesn't require to be unique + * @param value String value which will be stored in the database + * @param additionalColumns Additional columns which will be associated with the value, doesn't require to be unique + * @return the id (unique id) of the newly inserted value + * @throws SQLException if connection is lost, or if additional columns name or value format is incorrect + */ + long insertValue(String key, String value, List> additionalColumns) throws SQLException; + + /** + * Update a row associated with the unique key {@code id} with the new value given in parameter + * @param key unique key associated with the value + * @param value new value + * @throws SQLException if connection is lost + */ + void updateValueById(String key, String value) throws SQLException; + + /** + * Update all rows associated with the key and additional columns combinaisons with the new value given in parameter + * @param key String key which will is associated with the value, doesn't require to be unique + * @param value new value + * @param additionalColumns Additional columns which are associated with the value, doesn't require to be unique + * @throws SQLException if connection is lost, or if additional columns name or value format is incorrect + */ + void updateValue(String key, String value, List> additionalColumns) throws SQLException; + + /** + * Give the declared additional columns given during initialisation of the class + * @return list of declared additional columns + */ + List getAdditionColumns(); + + /** + * Result unique id and value pair stored in the table when using {@link KeyValueTable#getValueByAdditionalColumnAndKey(String, List)} + * @param id unique id the row + * @param value value store in the same row as {@code id} + */ + record Result(String id, String value) { + + } +} -- 2.39.5 From c66067da8c05ab100f8d134837301b3c7a928493 Mon Sep 17 00:00:00 2001 From: Quentin Legot Date: Thu, 8 Jun 2023 18:25:21 +0200 Subject: [PATCH 19/37] Move builder to Core module and developed it a bit --- .../builder/EmptyCollectionException.java | 8 +++ .../toolbox/core/builder/IBuilder.java | 11 ++++ .../toolbox/core/builder/IParamBuilder.java | 24 +++++++++ .../core/builder/OptionalParamBuilder.java | 24 +++++++++ .../RequiredCollectionParameterBuilder.java | 52 +++++++++++++++++++ .../core/builder/RequiredParamBuilder.java | 30 +++++++++++ Core/src/test/java/BuilderImpl.java | 38 ++++++++++++++ Core/src/test/java/BuilderResult.java | 5 ++ Core/src/test/java/BuilderTest.java | 32 ++++++++++++ Database/build.gradle | 1 + .../database/keyvalue/KeyValueBuilder.java | 35 +++++++++---- .../toolbox/database/ConnectionTest.java | 1 + settings.gradle | 2 +- 13 files changed, 251 insertions(+), 12 deletions(-) create mode 100644 Core/src/main/java/fr/altarik/toolbox/core/builder/EmptyCollectionException.java create mode 100644 Core/src/main/java/fr/altarik/toolbox/core/builder/IBuilder.java create mode 100644 Core/src/main/java/fr/altarik/toolbox/core/builder/IParamBuilder.java create mode 100644 Core/src/main/java/fr/altarik/toolbox/core/builder/OptionalParamBuilder.java create mode 100644 Core/src/main/java/fr/altarik/toolbox/core/builder/RequiredCollectionParameterBuilder.java create mode 100644 Core/src/main/java/fr/altarik/toolbox/core/builder/RequiredParamBuilder.java create mode 100644 Core/src/test/java/BuilderImpl.java create mode 100644 Core/src/test/java/BuilderResult.java create mode 100644 Core/src/test/java/BuilderTest.java diff --git a/Core/src/main/java/fr/altarik/toolbox/core/builder/EmptyCollectionException.java b/Core/src/main/java/fr/altarik/toolbox/core/builder/EmptyCollectionException.java new file mode 100644 index 0000000..798e6c3 --- /dev/null +++ b/Core/src/main/java/fr/altarik/toolbox/core/builder/EmptyCollectionException.java @@ -0,0 +1,8 @@ +package fr.altarik.toolbox.core.builder; + +public class EmptyCollectionException extends NullPointerException { + + public EmptyCollectionException(String message) { + super(message); + } +} diff --git a/Core/src/main/java/fr/altarik/toolbox/core/builder/IBuilder.java b/Core/src/main/java/fr/altarik/toolbox/core/builder/IBuilder.java new file mode 100644 index 0000000..64324a9 --- /dev/null +++ b/Core/src/main/java/fr/altarik/toolbox/core/builder/IBuilder.java @@ -0,0 +1,11 @@ +package fr.altarik.toolbox.core.builder; + +public interface IBuilder { + + /** + * Build the builders parameters into T object + * @return The created objects thanks to given parameters + * @throws Exception if any error occur during creation of the built object + */ + T build() throws Exception; +} diff --git a/Core/src/main/java/fr/altarik/toolbox/core/builder/IParamBuilder.java b/Core/src/main/java/fr/altarik/toolbox/core/builder/IParamBuilder.java new file mode 100644 index 0000000..ffa1b5a --- /dev/null +++ b/Core/src/main/java/fr/altarik/toolbox/core/builder/IParamBuilder.java @@ -0,0 +1,24 @@ +package fr.altarik.toolbox.core.builder; + +/** + * Builder parameter, for more flexibility + * @param the parameter type + * @see OptionalParamBuilder + * @see RequiredParamBuilder + * @see RequiredCollectionParameterBuilder + */ +public interface IParamBuilder { + + /** + * Get the given object, may return {@link NullPointerException} depending on the policy of implemented class + * @return the parameter given by {@link IParamBuilder#set(Object)} + * @throws NullPointerException may throw this error depending on the policy of implemented class + */ + T get() throws NullPointerException; + + /** + * Change/insert the value of the parameter + * @param parameter the given parameter + */ + void set(T parameter); +} diff --git a/Core/src/main/java/fr/altarik/toolbox/core/builder/OptionalParamBuilder.java b/Core/src/main/java/fr/altarik/toolbox/core/builder/OptionalParamBuilder.java new file mode 100644 index 0000000..fa60979 --- /dev/null +++ b/Core/src/main/java/fr/altarik/toolbox/core/builder/OptionalParamBuilder.java @@ -0,0 +1,24 @@ +package fr.altarik.toolbox.core.builder; + +/** + * Doesn't throw a {@link NullPointerException} when using {@link IParamBuilder#get()} in any case + * @param the returned type + * @see IParamBuilder + */ +public class OptionalParamBuilder implements IParamBuilder { + + private T parameter; + + public OptionalParamBuilder(T param) { + this.parameter = param; + } + @Override + public T get() throws NullPointerException { + return parameter; + } + + @Override + public void set(T parameter) { + this.parameter = parameter; + } +} diff --git a/Core/src/main/java/fr/altarik/toolbox/core/builder/RequiredCollectionParameterBuilder.java b/Core/src/main/java/fr/altarik/toolbox/core/builder/RequiredCollectionParameterBuilder.java new file mode 100644 index 0000000..8a828bd --- /dev/null +++ b/Core/src/main/java/fr/altarik/toolbox/core/builder/RequiredCollectionParameterBuilder.java @@ -0,0 +1,52 @@ +package fr.altarik.toolbox.core.builder; + +import org.jetbrains.annotations.NotNull; + +import java.util.Collection; +import java.util.Objects; + +/** + * Mostly same as {@link RequiredParamBuilder} but for list + * @param The type contained in the collection + * @param The returned type + */ +public class RequiredCollectionParameterBuilder> implements IParamBuilder { + + private final T collection; + private final boolean canBeEmpty; + + public RequiredCollectionParameterBuilder(@NotNull T collection, boolean canBeEmpty) { + this.collection = Objects.requireNonNull(collection); + this.canBeEmpty = canBeEmpty; + } + + /** + *

    Return the list, if not empty

    + *

    If empty, return the collection if {@code canBeEmpty} if true, otherwise throw a {@link NullPointerException}

    + * @return the collection + * @throws NullPointerException if collection is empty and {@code canBeEmpty} is false + */ + @Override + public T get() throws NullPointerException { + if(canBeEmpty) { + return collection; + } else if(!collection.isEmpty()) { + return collection; + } else { + throw new EmptyCollectionException("Collection cannot be empty"); + } + } + + @Override + public void set(T parameter) { + throw new UnsupportedOperationException("Use `add` in place of `set` for RequiredCollectionParameterBuilder"); + } + + /** + * Add an element to the collection + * @param element element to add to the list + */ + public void add(E element) { + collection.add(element); + } +} diff --git a/Core/src/main/java/fr/altarik/toolbox/core/builder/RequiredParamBuilder.java b/Core/src/main/java/fr/altarik/toolbox/core/builder/RequiredParamBuilder.java new file mode 100644 index 0000000..7d45fdc --- /dev/null +++ b/Core/src/main/java/fr/altarik/toolbox/core/builder/RequiredParamBuilder.java @@ -0,0 +1,30 @@ +package fr.altarik.toolbox.core.builder; + +import java.util.Objects; + +/** + * Throw a {@link NullPointerException} when using {@link IParamBuilder#get()} if the parameter doesn't have been initialized + * @param the returned type + */ +public class RequiredParamBuilder implements IParamBuilder { + + private T parameter; + + public RequiredParamBuilder(T parameter) { + this.parameter = parameter; + } + + public RequiredParamBuilder() { + this(null); + } + + @Override + public T get() { + return Objects.requireNonNull(parameter); + } + + @Override + public void set(T parameter) { + this.parameter = parameter; + } +} diff --git a/Core/src/test/java/BuilderImpl.java b/Core/src/test/java/BuilderImpl.java new file mode 100644 index 0000000..a5a8850 --- /dev/null +++ b/Core/src/test/java/BuilderImpl.java @@ -0,0 +1,38 @@ +import fr.altarik.toolbox.core.builder.IBuilder; +import fr.altarik.toolbox.core.builder.RequiredCollectionParameterBuilder; +import fr.altarik.toolbox.core.builder.RequiredParamBuilder; + +import java.util.ArrayList; +import java.util.List; + +public class BuilderImpl implements IBuilder { + + private final RequiredCollectionParameterBuilder> collection; + private final RequiredParamBuilder numberOfSentences; + + private BuilderImpl(boolean canBeEmpty) { + this.collection = new RequiredCollectionParameterBuilder<>(new ArrayList<>(), canBeEmpty); + this.numberOfSentences = new RequiredParamBuilder<>(); + } + + public BuilderImpl addSentence(String sentence) { + collection.add(sentence); + return this; + } + + public BuilderImpl numberOfSentence(int i) { + this.numberOfSentences.set(i); + return this; + } + + public static BuilderImpl builder(boolean canBeEmpty) { + return new BuilderImpl(canBeEmpty); + } + + + + @Override + public BuilderResult build() throws Exception { + return new BuilderResult(collection.get(), numberOfSentences.get()); + } +} diff --git a/Core/src/test/java/BuilderResult.java b/Core/src/test/java/BuilderResult.java new file mode 100644 index 0000000..3952469 --- /dev/null +++ b/Core/src/test/java/BuilderResult.java @@ -0,0 +1,5 @@ +import java.util.List; + +public record BuilderResult(List sentences, int numberOfSentences) { + +} diff --git a/Core/src/test/java/BuilderTest.java b/Core/src/test/java/BuilderTest.java new file mode 100644 index 0000000..148efe2 --- /dev/null +++ b/Core/src/test/java/BuilderTest.java @@ -0,0 +1,32 @@ +import fr.altarik.toolbox.core.builder.EmptyCollectionException; +import org.junit.jupiter.api.Assertions; +import org.junit.jupiter.api.Test; + +import java.util.Arrays; + +public class BuilderTest { + + + @Test + void builderTest() throws Exception { + BuilderImpl builder = BuilderImpl.builder(true); + builder.addSentence("First sentence"); + builder.addSentence("Second sentence"); + builder.numberOfSentence(2); + BuilderResult res = builder.build(); + Assertions.assertEquals(Arrays.asList("First sentence", "Second sentence"), res.sentences()); + Assertions.assertEquals(res.numberOfSentences(), 2); + + BuilderImpl builder1 = BuilderImpl.builder(false); + builder1.numberOfSentence(3); + Assertions.assertThrowsExactly(EmptyCollectionException.class, builder1::build); + + BuilderImpl builder2 = BuilderImpl.builder(true); + builder2.numberOfSentence(3); + Assertions.assertDoesNotThrow(builder2::build); + + BuilderImpl builder3 = BuilderImpl.builder(true); + Assertions.assertThrowsExactly(NullPointerException.class, builder3::build); + } + +} diff --git a/Database/build.gradle b/Database/build.gradle index 1c29a69..9aa1fc3 100644 --- a/Database/build.gradle +++ b/Database/build.gradle @@ -1,6 +1,7 @@ dependencies { implementation 'org.postgresql:postgresql:42.5.0' testImplementation 'com.google.code.gson:gson:2.10' + implementation project(':Core') } test { diff --git a/Database/src/main/java/fr/altarik/toolbox/database/keyvalue/KeyValueBuilder.java b/Database/src/main/java/fr/altarik/toolbox/database/keyvalue/KeyValueBuilder.java index a665599..c802d67 100644 --- a/Database/src/main/java/fr/altarik/toolbox/database/keyvalue/KeyValueBuilder.java +++ b/Database/src/main/java/fr/altarik/toolbox/database/keyvalue/KeyValueBuilder.java @@ -1,5 +1,8 @@ package fr.altarik.toolbox.database.keyvalue; +import fr.altarik.toolbox.core.builder.IBuilder; +import fr.altarik.toolbox.core.builder.RequiredCollectionParameterBuilder; +import fr.altarik.toolbox.core.builder.RequiredParamBuilder; import fr.altarik.toolbox.database.SqlConnection; import net.minecraft.util.Pair; import org.jetbrains.annotations.NotNull; @@ -11,20 +14,30 @@ import java.util.ArrayList; import java.util.List; import java.util.Objects; -public class KeyValueBuilder { +public class KeyValueBuilder implements IBuilder { - private final String tableName; - private final List additionalColumns; - private final SqlConnection connection; + private final RequiredParamBuilder tableName; + private final RequiredCollectionParameterBuilder> additionalColumns; + private final RequiredParamBuilder connection; - private KeyValueBuilder(SqlConnection connection, String tableName) { - this.connection = connection; - this.tableName = tableName; - this.additionalColumns = new ArrayList<>(); + private KeyValueBuilder() { + this.tableName = new RequiredParamBuilder<>(); + this.connection = new RequiredParamBuilder<>(); + this.additionalColumns = new RequiredCollectionParameterBuilder<>(new ArrayList<>(), true); } - public static KeyValueBuilder builder(@NotNull SqlConnection connection, @NotNull String tableName) { - return new KeyValueBuilder(connection, tableName); + public static KeyValueBuilder builder() { + return new KeyValueBuilder(); + } + + public KeyValueBuilder setConnection(@NotNull SqlConnection connection) { + this.connection.set(connection); + return this; + } + + public KeyValueBuilder setTableName(@NotNull String tableName) { + this.tableName.set(tableName); + return this; } public KeyValueBuilder addColumn(AdditionalColumn additionalColumn) { @@ -33,7 +46,7 @@ public class KeyValueBuilder { } public KeyValueConnection build() throws SQLException { - return new KeyValueConnection(connection, tableName, additionalColumns); + return new KeyValueConnection(connection.get(), tableName.get(), additionalColumns.get()); } public record AdditionalColumn(@NotNull String columnName, @NotNull JDBCType type, boolean notNull, @Nullable AdditionalColumnReference reference) { diff --git a/Database/src/test/java/fr/altarik/toolbox/database/ConnectionTest.java b/Database/src/test/java/fr/altarik/toolbox/database/ConnectionTest.java index 955151d..94759a5 100644 --- a/Database/src/test/java/fr/altarik/toolbox/database/ConnectionTest.java +++ b/Database/src/test/java/fr/altarik/toolbox/database/ConnectionTest.java @@ -30,6 +30,7 @@ class ConnectionTest { try(PreparedStatement statement = connection.getConnection().prepareStatement("CREATE TABLE IF NOT EXISTS toolbox(id SERIAL, PRIMARY KEY (id));")) { statement.executeUpdate(); } + connection.close(); }); } diff --git a/settings.gradle b/settings.gradle index 3f9b534..4a814ce 100644 --- a/settings.gradle +++ b/settings.gradle @@ -10,4 +10,4 @@ pluginManagement { } rootProject.name = 'Toolbox' -include(':Tasks', ':Database', ':Pagination') +include(':Tasks', ':Database', ':Pagination', ':Core') -- 2.39.5 From 17cf359e832dbc91d2dcaec458f4c340338309c9 Mon Sep 17 00:00:00 2001 From: Quentin Legot Date: Thu, 8 Jun 2023 18:41:05 +0200 Subject: [PATCH 20/37] KeyValue has been simplified --- .../database/keyvalue/KeyValueBuilder.java | 37 +----- .../database/keyvalue/KeyValueConnection.java | 119 ++---------------- .../database/keyvalue/KeyValueTable.java | 64 +++------- 3 files changed, 25 insertions(+), 195 deletions(-) diff --git a/Database/src/main/java/fr/altarik/toolbox/database/keyvalue/KeyValueBuilder.java b/Database/src/main/java/fr/altarik/toolbox/database/keyvalue/KeyValueBuilder.java index c802d67..78394da 100644 --- a/Database/src/main/java/fr/altarik/toolbox/database/keyvalue/KeyValueBuilder.java +++ b/Database/src/main/java/fr/altarik/toolbox/database/keyvalue/KeyValueBuilder.java @@ -1,29 +1,21 @@ package fr.altarik.toolbox.database.keyvalue; import fr.altarik.toolbox.core.builder.IBuilder; -import fr.altarik.toolbox.core.builder.RequiredCollectionParameterBuilder; import fr.altarik.toolbox.core.builder.RequiredParamBuilder; import fr.altarik.toolbox.database.SqlConnection; -import net.minecraft.util.Pair; import org.jetbrains.annotations.NotNull; -import org.jetbrains.annotations.Nullable; -import java.sql.JDBCType; import java.sql.SQLException; -import java.util.ArrayList; -import java.util.List; -import java.util.Objects; + public class KeyValueBuilder implements IBuilder { private final RequiredParamBuilder tableName; - private final RequiredCollectionParameterBuilder> additionalColumns; private final RequiredParamBuilder connection; private KeyValueBuilder() { this.tableName = new RequiredParamBuilder<>(); this.connection = new RequiredParamBuilder<>(); - this.additionalColumns = new RequiredCollectionParameterBuilder<>(new ArrayList<>(), true); } public static KeyValueBuilder builder() { @@ -40,33 +32,8 @@ public class KeyValueBuilder implements IBuilder { return this; } - public KeyValueBuilder addColumn(AdditionalColumn additionalColumn) { - this.additionalColumns.add(additionalColumn); - return this; - } - public KeyValueConnection build() throws SQLException { - return new KeyValueConnection(connection.get(), tableName.get(), additionalColumns.get()); - } - - public record AdditionalColumn(@NotNull String columnName, @NotNull JDBCType type, boolean notNull, @Nullable AdditionalColumnReference reference) { - public AdditionalColumn { - Objects.requireNonNull(columnName); - Objects.requireNonNull(type); - } - - public Pair toPair(Object value) { - return new Pair<>(this, value); - } - } - - public record AdditionalColumnReference(@NotNull String referenceTable, @NotNull String... referenceColumns) { - public AdditionalColumnReference { - Objects.requireNonNull(referenceTable); - if(Objects.requireNonNull(referenceColumns).length == 0) - throw new IllegalArgumentException("Reference Columns should not be empty"); - } - + return new KeyValueConnection(connection.get(), tableName.get()); } } diff --git a/Database/src/main/java/fr/altarik/toolbox/database/keyvalue/KeyValueConnection.java b/Database/src/main/java/fr/altarik/toolbox/database/keyvalue/KeyValueConnection.java index 2fabedb..0f16d3d 100644 --- a/Database/src/main/java/fr/altarik/toolbox/database/keyvalue/KeyValueConnection.java +++ b/Database/src/main/java/fr/altarik/toolbox/database/keyvalue/KeyValueConnection.java @@ -1,7 +1,6 @@ package fr.altarik.toolbox.database.keyvalue; import fr.altarik.toolbox.database.SqlConnection; -import net.minecraft.util.Pair; import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.Nullable; @@ -9,151 +8,51 @@ import java.sql.PreparedStatement; import java.sql.ResultSet; import java.sql.SQLException; import java.sql.Statement; -import java.util.List; public class KeyValueConnection implements KeyValueTable { private final SqlConnection connection; private final String tableName; - private final List additionColumns; - public KeyValueConnection(@NotNull SqlConnection connection, @NotNull String tableName, @NotNull List additionalColumns) throws SQLException { + public KeyValueConnection(@NotNull SqlConnection connection, @NotNull String tableName) throws SQLException { this.connection = connection; this.tableName = tableName; - this.additionColumns = additionalColumns; connection.checkConnection(); try(Statement statement = connection.getConnection().createStatement()) { - StringBuilder sql = new StringBuilder("CREATE TABLE IF NOT EXISTS ").append(tableName).append("(id SERIAL,"); - for(KeyValueBuilder.AdditionalColumn additionalColumn : additionalColumns) { - sql.append(additionalColumn.columnName()).append(" ").append(additionalColumn.type().getName()); - if(additionalColumn.notNull()) { - sql.append(" NOT NULL "); - } - if(additionalColumn.reference() != null) { - sql.append("REFERENCES ").append(additionalColumn.reference().referenceTable()).append("("); - for(int i = 0; i < additionalColumn.reference().referenceColumns().length; ++i) { - sql.append(additionalColumn.reference().referenceColumns()[i]); - if(i != additionalColumn.reference().referenceColumns().length - 1) { - sql.append(", "); - } - } - sql.append(")"); - } - sql.append(","); - sql.append("key VARCHAR(50) NOT NULL,").append("value TEXT NOT NULL,").append("PRIMARY KEY(id)"); - } - statement.executeUpdate(sql.toString()); - - + statement.executeUpdate("CREATE TABLE IF NOT EXISTS " + tableName + "(key VARCHAR(50) NOT NULL, value TEXT NOT NULL, PRIMARY KEY(key));"); } } @Override - public @Nullable String getValueById(int id) throws SQLException { + public @Nullable String getValue(String key) throws SQLException { connection.checkConnection(); - try(PreparedStatement preparedStatement = connection.getConnection().prepareStatement("SELECT value FROM " + tableName + " WHERE id=?")) { - preparedStatement.setInt(1, id); - ResultSet resultSet = preparedStatement.executeQuery(); - if(resultSet.next()) { - return resultSet.getString(1); - } - return null; - } - } - - @Override - public @Nullable Result getValueByAdditionalColumnAndKey(String key, List> additionalColumns) throws SQLException { - connection.checkConnection(); - StringBuilder sql = new StringBuilder("SELECT id, value FROM ").append(tableName).append(" WHERE key=? AND "); - for(int i = 0; i < additionalColumns.size(); ++i) { - sql.append(additionalColumns.get(i).getLeft().columnName()).append("=?"); - if(i != additionalColumns.size() - 1) { - sql.append(" AND "); - } - } - sql.append(";"); - try(PreparedStatement preparedStatement = connection.getConnection().prepareStatement(sql.toString())) { + try(PreparedStatement preparedStatement = connection.getConnection().prepareStatement("SELECT value FROM " + tableName + " WHERE key=?;")) { preparedStatement.setString(1, key); - for(int i = 0; i < additionalColumns.size(); ++i) { - preparedStatement.setObject(i + 1, additionalColumns.get(i).getRight()); - } ResultSet resultSet = preparedStatement.executeQuery(); if(resultSet.next()) - return new Result(resultSet.getString(1), resultSet.getString(2)); + return resultSet.getString(1); return null; } } @Override - public long insertValue(String key, String value, List> additionalColumns) throws SQLException { + public void insertValue(String key, String value) throws SQLException { connection.checkConnection(); - StringBuilder sql = new StringBuilder("INSERT INTO " + tableName + "(key, value"); - for(int i = 0; i < additionalColumns.size(); ++i) { - if(i != additionalColumns.size() - 1) { - sql.append(", "); - } - sql.append(additionalColumns.get(i).getLeft().columnName()); - - } - sql.append(") VALUES (?, ?"); - for(int i = 0; i < additionalColumns.size(); ++i) { - if(i != additionalColumns.size() - 1) { - sql.append(", "); - } - sql.append("?"); - } - sql.append(");"); - try(PreparedStatement preparedStatement = connection.getConnection().prepareStatement(sql.toString(), Statement.RETURN_GENERATED_KEYS)){ + try(PreparedStatement preparedStatement = connection.getConnection().prepareStatement("INSERT INTO " + tableName + "(key, value) VALUES (?, ?);")){ preparedStatement.setString(1, key); preparedStatement.setString(2, value); - for(int i = 0; i < additionalColumns.size(); ++i) { - preparedStatement.setObject(i + 3, additionalColumns.get(i).getRight()); - } preparedStatement.executeUpdate(); - try(ResultSet resultSet = preparedStatement.getGeneratedKeys()) { - if(resultSet.next()) { - return resultSet.getLong(1); - } - return -1L; - } } } @Override - public void updateValueById(String key, String value) throws SQLException { + public void updateValue(String key, String value) throws SQLException { connection.checkConnection(); - try(PreparedStatement preparedStatement = connection.getConnection().prepareStatement("UPDATE " + tableName + " SET value=? WHERE key=?")) { + try(PreparedStatement preparedStatement = connection.getConnection().prepareStatement("UPDATE " + tableName + " SET value=? WHERE key=?;")) { preparedStatement.setString(1, value); preparedStatement.setString(2, key); preparedStatement.executeUpdate(); } - - } - - @Override - public void updateValue(String key, String value, List> additionalColumns) throws SQLException { - connection.checkConnection(); - StringBuilder sql = new StringBuilder("UPDATE " + tableName + " SET value=? WHERE key=?"); - for(int i = 0; i < additionalColumns.size(); ++i) { - if(i != additionalColumns.size() - 1) { - sql.append(" AND "); - } - sql.append(additionalColumns.get(i).getLeft().columnName()).append("=?"); - } - sql.append(";"); - try(PreparedStatement preparedStatement = connection.getConnection().prepareStatement(sql.toString())) { - preparedStatement.setString(1, value); - preparedStatement.setString(2, key); - for(int i = 0; i < additionalColumns.size(); ++i) { - preparedStatement.setObject(3 + i, additionalColumns.get(i).getRight()); - } - preparedStatement.executeUpdate(); - } - } - - @Override - public List getAdditionColumns() { - return additionColumns; } } diff --git a/Database/src/main/java/fr/altarik/toolbox/database/keyvalue/KeyValueTable.java b/Database/src/main/java/fr/altarik/toolbox/database/keyvalue/KeyValueTable.java index 67079f9..6aa53c7 100644 --- a/Database/src/main/java/fr/altarik/toolbox/database/keyvalue/KeyValueTable.java +++ b/Database/src/main/java/fr/altarik/toolbox/database/keyvalue/KeyValueTable.java @@ -1,72 +1,36 @@ package fr.altarik.toolbox.database.keyvalue; -import net.minecraft.util.Pair; import org.jetbrains.annotations.Nullable; import java.sql.SQLException; -import java.util.List; public interface KeyValueTable { /** - * Return the value which correspond to the given id - * @param id primary key, unique id of the key value table - * @return the correspond value - * @throws SQLException when connection is lost - */ - @Nullable String getValueById(int id) throws SQLException; - - /** - *

    Return the first value associated with the key and all the additional columns values given.

    - *

    In a perfect context, key and additional columns combinaison return a pseudo unique result.

    + *

    Return the first value associated with the unique key.

    * - * @param key String key of associated to the value, doesn't require to be unique - * @param additionalColumns Object keys of associated to the value, doesn't require to be unique - * @return first (id, value) pair associated with the key and additonal columns combinaison - * @throws SQLException if connection is lost, or if additional columns name or value format is incorrect + * @param key String key of associated to the value + * @return value associated with the key + * @throws SQLException if connection is lost */ - @Nullable Result getValueByAdditionalColumnAndKey(String key, List> additionalColumns) throws SQLException; + @Nullable String getValue(String key) throws SQLException; /** - *

    Insert a new value in the table, associate key and additional columns with the value

    - *

    Key and additional columns doesn't need to be unique, the combinaison of them have the goal to be unique or it isn't a hard requirement

    - * @param key String key which will be associated with the value, doesn't require to be unique + *

    Insert a new value in the table, associated with key

    + * + * @param key String key which will be associated with the value, is unique * @param value String value which will be stored in the database - * @param additionalColumns Additional columns which will be associated with the value, doesn't require to be unique - * @return the id (unique id) of the newly inserted value - * @throws SQLException if connection is lost, or if additional columns name or value format is incorrect + * @throws SQLException if connection is lost or if {@code key} is not unique (already exist in database) */ - long insertValue(String key, String value, List> additionalColumns) throws SQLException; + void insertValue(String key, String value) throws SQLException; /** - * Update a row associated with the unique key {@code id} with the new value given in parameter - * @param key unique key associated with the value + *

    Update value column of the row associated with the key by {@code value}

    + *

    If {@code key} doesn't exist in table, will update no row without warning

    + * @param key String key which will is associated with the value, is unique * @param value new value * @throws SQLException if connection is lost */ - void updateValueById(String key, String value) throws SQLException; + void updateValue(String key, String value) throws SQLException; - /** - * Update all rows associated with the key and additional columns combinaisons with the new value given in parameter - * @param key String key which will is associated with the value, doesn't require to be unique - * @param value new value - * @param additionalColumns Additional columns which are associated with the value, doesn't require to be unique - * @throws SQLException if connection is lost, or if additional columns name or value format is incorrect - */ - void updateValue(String key, String value, List> additionalColumns) throws SQLException; - - /** - * Give the declared additional columns given during initialisation of the class - * @return list of declared additional columns - */ - List getAdditionColumns(); - - /** - * Result unique id and value pair stored in the table when using {@link KeyValueTable#getValueByAdditionalColumnAndKey(String, List)} - * @param id unique id the row - * @param value value store in the same row as {@code id} - */ - record Result(String id, String value) { - - } } -- 2.39.5 From 95d06283e4830705917dfff4dcacec76f3d8826b Mon Sep 17 00:00:00 2001 From: Quentin Legot Date: Thu, 8 Jun 2023 18:44:18 +0200 Subject: [PATCH 21/37] Moved class from keyvalue to keyValue --- .../database/{keyvalue => keyValue}/KeyValueBuilder.java | 2 +- .../database/{keyvalue => keyValue}/KeyValueConnection.java | 2 +- .../toolbox/database/{keyvalue => keyValue}/KeyValueTable.java | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) rename Database/src/main/java/fr/altarik/toolbox/database/{keyvalue => keyValue}/KeyValueBuilder.java (95%) rename Database/src/main/java/fr/altarik/toolbox/database/{keyvalue => keyValue}/KeyValueConnection.java (98%) rename Database/src/main/java/fr/altarik/toolbox/database/{keyvalue => keyValue}/KeyValueTable.java (96%) diff --git a/Database/src/main/java/fr/altarik/toolbox/database/keyvalue/KeyValueBuilder.java b/Database/src/main/java/fr/altarik/toolbox/database/keyValue/KeyValueBuilder.java similarity index 95% rename from Database/src/main/java/fr/altarik/toolbox/database/keyvalue/KeyValueBuilder.java rename to Database/src/main/java/fr/altarik/toolbox/database/keyValue/KeyValueBuilder.java index 78394da..d086a91 100644 --- a/Database/src/main/java/fr/altarik/toolbox/database/keyvalue/KeyValueBuilder.java +++ b/Database/src/main/java/fr/altarik/toolbox/database/keyValue/KeyValueBuilder.java @@ -1,4 +1,4 @@ -package fr.altarik.toolbox.database.keyvalue; +package fr.altarik.toolbox.database.keyValue; import fr.altarik.toolbox.core.builder.IBuilder; import fr.altarik.toolbox.core.builder.RequiredParamBuilder; diff --git a/Database/src/main/java/fr/altarik/toolbox/database/keyvalue/KeyValueConnection.java b/Database/src/main/java/fr/altarik/toolbox/database/keyValue/KeyValueConnection.java similarity index 98% rename from Database/src/main/java/fr/altarik/toolbox/database/keyvalue/KeyValueConnection.java rename to Database/src/main/java/fr/altarik/toolbox/database/keyValue/KeyValueConnection.java index 0f16d3d..85b1994 100644 --- a/Database/src/main/java/fr/altarik/toolbox/database/keyvalue/KeyValueConnection.java +++ b/Database/src/main/java/fr/altarik/toolbox/database/keyValue/KeyValueConnection.java @@ -1,4 +1,4 @@ -package fr.altarik.toolbox.database.keyvalue; +package fr.altarik.toolbox.database.keyValue; import fr.altarik.toolbox.database.SqlConnection; import org.jetbrains.annotations.NotNull; diff --git a/Database/src/main/java/fr/altarik/toolbox/database/keyvalue/KeyValueTable.java b/Database/src/main/java/fr/altarik/toolbox/database/keyValue/KeyValueTable.java similarity index 96% rename from Database/src/main/java/fr/altarik/toolbox/database/keyvalue/KeyValueTable.java rename to Database/src/main/java/fr/altarik/toolbox/database/keyValue/KeyValueTable.java index 6aa53c7..71054ee 100644 --- a/Database/src/main/java/fr/altarik/toolbox/database/keyvalue/KeyValueTable.java +++ b/Database/src/main/java/fr/altarik/toolbox/database/keyValue/KeyValueTable.java @@ -1,4 +1,4 @@ -package fr.altarik.toolbox.database.keyvalue; +package fr.altarik.toolbox.database.keyValue; import org.jetbrains.annotations.Nullable; -- 2.39.5 From ee67f7e075b49717b85b4e59c9e326963f16fdfc Mon Sep 17 00:00:00 2001 From: Quentin Legot Date: Thu, 8 Jun 2023 20:31:47 +0200 Subject: [PATCH 22/37] Added deleteRow and truncateTable for KeyValueTable, add test for KeyValueTable --- .gitignore | 5 +- Database/build.gradle | 4 +- .../altarik/toolbox/database/Connections.java | 16 ++++- .../database/keyValue/KeyValueBuilder.java | 6 +- ...onnection.java => KeyValuePostgresql.java} | 24 ++++++- .../database/keyValue/KeyValueTable.java | 18 +++++ .../database/keyValue/KeyValueTest.java | 68 +++++++++++++++++++ Database/src/test/resources/config.yml | 2 +- 8 files changed, 132 insertions(+), 11 deletions(-) rename Database/src/main/java/fr/altarik/toolbox/database/keyValue/{KeyValueConnection.java => KeyValuePostgresql.java} (71%) create mode 100644 Database/src/test/java/fr/altarik/toolbox/database/keyValue/KeyValueTest.java diff --git a/.gitignore b/.gitignore index d037336..a4bcb99 100644 --- a/.gitignore +++ b/.gitignore @@ -4,8 +4,9 @@ build/ !**/src/main/**/build/ !**/src/test/**/build/ -*/run -*/logs +run/* +**/run +**/logs ### IntelliJ IDEA ### .idea diff --git a/Database/build.gradle b/Database/build.gradle index 9aa1fc3..52c3f78 100644 --- a/Database/build.gradle +++ b/Database/build.gradle @@ -1,9 +1,9 @@ dependencies { - implementation 'org.postgresql:postgresql:42.5.0' + implementation 'org.postgresql:postgresql:42.6.0' testImplementation 'com.google.code.gson:gson:2.10' implementation project(':Core') } test { - exclude 'fr/altarik/toolbox/database/**' + exclude 'fr/altarik/toolbox/database/**' // exclude for runner } \ No newline at end of file diff --git a/Database/src/main/java/fr/altarik/toolbox/database/Connections.java b/Database/src/main/java/fr/altarik/toolbox/database/Connections.java index 7d8f5a7..4f30e9b 100644 --- a/Database/src/main/java/fr/altarik/toolbox/database/Connections.java +++ b/Database/src/main/java/fr/altarik/toolbox/database/Connections.java @@ -1,14 +1,28 @@ package fr.altarik.toolbox.database; +import fr.altarik.toolbox.database.keyValue.KeyValueBuilder; +import fr.altarik.toolbox.database.keyValue.KeyValueTable; + import java.sql.SQLException; public class Connections { /** * Create a new Connection object for a postgresql database server - * @return + * @return postgresql connection */ public static SqlConnection newPostgresConnection(ConnectionConfig config) throws SQLException { return new PostgresConnection(config); } + + /** + * Create a new (key, value) table if not exist and use it through {@link KeyValueTable} interface + * @param connection Postgresql connection + * @param tableName name of the table to use + * @return interface to control the table + * @throws SQLException if connection is lost + */ + public static KeyValueTable newKeyValueTable(SqlConnection connection, String tableName) throws SQLException { + return KeyValueBuilder.builder().setConnection(connection).setTableName(tableName).build(); + } } diff --git a/Database/src/main/java/fr/altarik/toolbox/database/keyValue/KeyValueBuilder.java b/Database/src/main/java/fr/altarik/toolbox/database/keyValue/KeyValueBuilder.java index d086a91..b393cbb 100644 --- a/Database/src/main/java/fr/altarik/toolbox/database/keyValue/KeyValueBuilder.java +++ b/Database/src/main/java/fr/altarik/toolbox/database/keyValue/KeyValueBuilder.java @@ -8,7 +8,7 @@ import org.jetbrains.annotations.NotNull; import java.sql.SQLException; -public class KeyValueBuilder implements IBuilder { +public class KeyValueBuilder implements IBuilder { private final RequiredParamBuilder tableName; private final RequiredParamBuilder connection; @@ -32,8 +32,8 @@ public class KeyValueBuilder implements IBuilder { return this; } - public KeyValueConnection build() throws SQLException { - return new KeyValueConnection(connection.get(), tableName.get()); + public KeyValuePostgresql build() throws SQLException { + return new KeyValuePostgresql(connection.get(), tableName.get()); } } diff --git a/Database/src/main/java/fr/altarik/toolbox/database/keyValue/KeyValueConnection.java b/Database/src/main/java/fr/altarik/toolbox/database/keyValue/KeyValuePostgresql.java similarity index 71% rename from Database/src/main/java/fr/altarik/toolbox/database/keyValue/KeyValueConnection.java rename to Database/src/main/java/fr/altarik/toolbox/database/keyValue/KeyValuePostgresql.java index 85b1994..28a55bf 100644 --- a/Database/src/main/java/fr/altarik/toolbox/database/keyValue/KeyValueConnection.java +++ b/Database/src/main/java/fr/altarik/toolbox/database/keyValue/KeyValuePostgresql.java @@ -9,16 +9,19 @@ import java.sql.ResultSet; import java.sql.SQLException; import java.sql.Statement; -public class KeyValueConnection implements KeyValueTable { +public class KeyValuePostgresql implements KeyValueTable { private final SqlConnection connection; private final String tableName; - public KeyValueConnection(@NotNull SqlConnection connection, @NotNull String tableName) throws SQLException { + public KeyValuePostgresql(@NotNull SqlConnection connection, @NotNull String tableName) throws SQLException { this.connection = connection; this.tableName = tableName; connection.checkConnection(); + createTable(tableName); + } + private void createTable(String tableName) throws SQLException { try(Statement statement = connection.getConnection().createStatement()) { statement.executeUpdate("CREATE TABLE IF NOT EXISTS " + tableName + "(key VARCHAR(50) NOT NULL, value TEXT NOT NULL, PRIMARY KEY(key));"); } @@ -55,4 +58,21 @@ public class KeyValueConnection implements KeyValueTable { preparedStatement.executeUpdate(); } } + + @Override + public void deleteRow(String key) throws SQLException { + connection.checkConnection(); + try(PreparedStatement preparedStatement = connection.getConnection().prepareStatement("DELETE FROM " + tableName + " WHERE key=?")) { + preparedStatement.setString(1, key); + preparedStatement.executeUpdate(); + } + } + + @Override + public void truncateTable() throws SQLException { + connection.checkConnection(); + try(PreparedStatement preparedStatement = connection.getConnection().prepareStatement("TRUNCATE TABLE " + tableName)) { + preparedStatement.executeUpdate(); + } + } } diff --git a/Database/src/main/java/fr/altarik/toolbox/database/keyValue/KeyValueTable.java b/Database/src/main/java/fr/altarik/toolbox/database/keyValue/KeyValueTable.java index 71054ee..567c4be 100644 --- a/Database/src/main/java/fr/altarik/toolbox/database/keyValue/KeyValueTable.java +++ b/Database/src/main/java/fr/altarik/toolbox/database/keyValue/KeyValueTable.java @@ -4,6 +4,10 @@ import org.jetbrains.annotations.Nullable; import java.sql.SQLException; +/** + *

    Implement of a key value table, abstract the actual representation of the table and its manipulation between this interface

    + * @see KeyValuePostgresql + */ public interface KeyValueTable { /** @@ -33,4 +37,18 @@ public interface KeyValueTable { */ void updateValue(String key, String value) throws SQLException; + /** + *

    Delete row with having {@code key} as unique key

    + *

    If key doesn't exist in database, will delete no row without warning

    + * @param key the key of the row to delete + * @throws SQLException if connection is lost + */ + void deleteRow(String key) throws SQLException; + + /** + * Will delete every data inside the table + * @throws SQLException if connection is lost + */ + void truncateTable() throws SQLException; + } diff --git a/Database/src/test/java/fr/altarik/toolbox/database/keyValue/KeyValueTest.java b/Database/src/test/java/fr/altarik/toolbox/database/keyValue/KeyValueTest.java new file mode 100644 index 0000000..78990a6 --- /dev/null +++ b/Database/src/test/java/fr/altarik/toolbox/database/keyValue/KeyValueTest.java @@ -0,0 +1,68 @@ +package fr.altarik.toolbox.database.keyValue; + +import com.google.gson.Gson; +import fr.altarik.toolbox.database.ConnectionConfig; +import fr.altarik.toolbox.database.Connections; +import fr.altarik.toolbox.database.SqlConnection; +import org.junit.jupiter.api.Test; + +import java.io.BufferedReader; +import java.io.IOException; +import java.io.InputStream; +import java.io.InputStreamReader; +import java.net.URL; +import java.net.URLConnection; +import java.util.Objects; +import java.util.stream.Collectors; + +import static org.junit.jupiter.api.Assertions.*; + +public class KeyValueTest { + + @Test + void tableTest() { + System.out.println("Hello"); + assertDoesNotThrow(() -> {InputStream configInput = getResource("config.yml"); + String configStr = new BufferedReader(new InputStreamReader(Objects.requireNonNull(configInput))) + .lines().collect(Collectors.joining("\n")); + Gson gson = new Gson(); + ConnectionConfig config = gson.fromJson(configStr, ConnectionConfig.class); + try(SqlConnection connection = Connections.newPostgresConnection(config)) { + KeyValueTable keyValueTable = Connections.newKeyValueTable(connection, "toolbox_keyvalue"); + keyValueTable.truncateTable(); + keyValueTable.insertValue("location", "here"); + keyValueTable.insertValue("experience", "5"); + assertEquals("here", keyValueTable.getValue("location")); + assertEquals("5", keyValueTable.getValue("experience")); + keyValueTable.updateValue("location", "Elsewhere"); + assertEquals("Elsewhere", keyValueTable.getValue("location")); + assertEquals("5", keyValueTable.getValue("experience")); + keyValueTable.updateValue("experience", "10"); + assertEquals("Elsewhere", keyValueTable.getValue("location")); + assertEquals("10", keyValueTable.getValue("experience")); + keyValueTable.deleteRow("experience"); + assertEquals("Elsewhere", keyValueTable.getValue("location")); + assertNull(keyValueTable.getValue("experience")); + keyValueTable.truncateTable(); + assertNull(keyValueTable.getValue("location")); + assertNull(keyValueTable.getValue("experience")); + } + }); + } + + // TODO: 08/06/2023 Move to Core module in a toolkit class + private InputStream getResource(String resourcePath) { + try { + URL url = this.getClass().getClassLoader().getResource(resourcePath); + if(url == null) + return null; + + URLConnection connection = url.openConnection(); + connection.setUseCaches(false); + return connection.getInputStream(); + } catch (IOException e){ + return null; + } + } + +} diff --git a/Database/src/test/resources/config.yml b/Database/src/test/resources/config.yml index 9e2feb9..4f42d65 100644 --- a/Database/src/test/resources/config.yml +++ b/Database/src/test/resources/config.yml @@ -3,5 +3,5 @@ "port": 5432, "database": "postgres", "username": "postgres", - "password": "root" + "password": "Vaubadon1" } \ No newline at end of file -- 2.39.5 From c976468d2b797c3bad4dcba8ac388ca6261879b7 Mon Sep 17 00:00:00 2001 From: Quentin Legot Date: Tue, 13 Jun 2023 17:36:22 +0200 Subject: [PATCH 23/37] Add DataTracker and TrackedData --- .gitea/workflows/test.yml | 2 +- .../toolbox/core/data/DataTracker.java | 37 +++++++++++++++++++ .../toolbox/core/data/TrackedData.java | 5 +++ Pagination/build.gradle | 0 Tasks/build.gradle | 0 gradle.properties | 2 +- settings.gradle | 5 ++- 7 files changed, 48 insertions(+), 3 deletions(-) create mode 100644 Core/src/main/java/fr/altarik/toolbox/core/data/DataTracker.java create mode 100644 Core/src/main/java/fr/altarik/toolbox/core/data/TrackedData.java delete mode 100644 Pagination/build.gradle delete mode 100644 Tasks/build.gradle diff --git a/.gitea/workflows/test.yml b/.gitea/workflows/test.yml index 80ad767..3444f5f 100644 --- a/.gitea/workflows/test.yml +++ b/.gitea/workflows/test.yml @@ -32,7 +32,7 @@ jobs: if: ${{ runner.os != 'Windows' }} run: chmod +x ./gradlew - name: build - run: ./gradlew build --no-daemon + run: ./gradlew build --no-daemon --max-workers 1 #- name: test # run: ./gradlew test --no-daemon diff --git a/Core/src/main/java/fr/altarik/toolbox/core/data/DataTracker.java b/Core/src/main/java/fr/altarik/toolbox/core/data/DataTracker.java new file mode 100644 index 0000000..aa9bcb9 --- /dev/null +++ b/Core/src/main/java/fr/altarik/toolbox/core/data/DataTracker.java @@ -0,0 +1,37 @@ +package fr.altarik.toolbox.core.data; + +import java.util.HashMap; +import java.util.Map; +import java.util.Objects; + +public class DataTracker { + + private final Map trackedData; + + public DataTracker() { + this.trackedData = new HashMap<>(); + } + + public void startTracking(TrackedData data) { + trackedData.put(data, data.defaultValue()); + } + + public String getOrDefault(TrackedData data) { + return Objects.requireNonNull(trackedData.get(data)); + } + + public void set(TrackedData data, String value) { + String v = trackedData.get(data); + if(v != null) { + trackedData.putIfAbsent(data, value); + } else { + throw new IllegalArgumentException("Data " + data.name() + " is not tracked, please initialize it with DataTracker#startTracking(TrackedData, String) first"); + } + + } + + public void saveToDb() { + + } + +} diff --git a/Core/src/main/java/fr/altarik/toolbox/core/data/TrackedData.java b/Core/src/main/java/fr/altarik/toolbox/core/data/TrackedData.java new file mode 100644 index 0000000..c8bec33 --- /dev/null +++ b/Core/src/main/java/fr/altarik/toolbox/core/data/TrackedData.java @@ -0,0 +1,5 @@ +package fr.altarik.toolbox.core.data; + +public record TrackedData(String name, String defaultValue) { + +} diff --git a/Pagination/build.gradle b/Pagination/build.gradle deleted file mode 100644 index e69de29..0000000 diff --git a/Tasks/build.gradle b/Tasks/build.gradle deleted file mode 100644 index e69de29..0000000 diff --git a/gradle.properties b/gradle.properties index 16c0d2a..59d1cfe 100644 --- a/gradle.properties +++ b/gradle.properties @@ -8,6 +8,6 @@ loader_version=0.14.14 fabric_version=0.75.1+1.19.3 maven_group=fr.altarik.toolbox -maven_version=4.0.0-SNAPSHOT +maven_version=4.1.0-SNAPSHOT repo_username=Altarik repo_password=password diff --git a/settings.gradle b/settings.gradle index 4a814ce..c266500 100644 --- a/settings.gradle +++ b/settings.gradle @@ -10,4 +10,7 @@ pluginManagement { } rootProject.name = 'Toolbox' -include(':Tasks', ':Database', ':Pagination', ':Core') +include(':Tasks') +include(':Database') +include(':Pagination') +include(':Core') -- 2.39.5 From 780c0d650ce18ed40ff26cb72a631ef57bac6cd9 Mon Sep 17 00:00:00 2001 From: Quentin Legot Date: Tue, 13 Jun 2023 17:46:19 +0200 Subject: [PATCH 24/37] Updated and added fabric.mod.json --- Core/src/main/resources/assets/core/icon.png | Bin 0 -> 3805 bytes Core/src/main/resources/fabric.mod.json | 29 ++++++++++++++++++ .../main/resources/assets/database/icon.png | Bin 0 -> 3805 bytes Database/src/main/resources/fabric.mod.json | 29 ++++++++++++++++++ Pagination/src/main/resources/fabric.mod.json | 2 +- Tasks/src/main/resources/fabric.mod.json | 2 +- src/main/resources/assets/toolbox/icon.png | Bin 0 -> 3805 bytes src/main/resources/fabric.mod.json | 2 +- 8 files changed, 61 insertions(+), 3 deletions(-) create mode 100644 Core/src/main/resources/assets/core/icon.png create mode 100644 Core/src/main/resources/fabric.mod.json create mode 100644 Database/src/main/resources/assets/database/icon.png create mode 100644 Database/src/main/resources/fabric.mod.json create mode 100644 src/main/resources/assets/toolbox/icon.png diff --git a/Core/src/main/resources/assets/core/icon.png b/Core/src/main/resources/assets/core/icon.png new file mode 100644 index 0000000000000000000000000000000000000000..1049a98c68691f2040e340fd044c1efe3f4601e6 GIT binary patch literal 3805 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" + ], + "contact": { + "homepage": "https://altarik.fr" + }, + "license": "Altarik @ All-Rights-Reserved ", + "icon": "assets/core/icon.png", + "environment": "*", + "entrypoints": { + "main": [] + }, + "mixins": [], + "depends": { + "fabricloader": "^0.14.12", + "fabric-api": "*", + "minecraft": "1.19.3", + "java": ">=17" + } +} diff --git a/Database/src/main/resources/assets/database/icon.png b/Database/src/main/resources/assets/database/icon.png new file mode 100644 index 0000000000000000000000000000000000000000..1049a98c68691f2040e340fd044c1efe3f4601e6 GIT binary patch literal 3805 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" + ], + "contact": { + "homepage": "https://altarik.fr" + }, + "license": "Altarik @ All-Rights-Reserved ", + "icon": "assets/database/icon.png", + "environment": "*", + "entrypoints": { + "main": [] + }, + "mixins": [], + "depends": { + "fabricloader": "^0.14.12", + "fabric-api": "*", + "minecraft": "1.19.3", + "java": ">=17" + } +} diff --git a/Pagination/src/main/resources/fabric.mod.json b/Pagination/src/main/resources/fabric.mod.json index 52051dc..f59feb8 100644 --- a/Pagination/src/main/resources/fabric.mod.json +++ b/Pagination/src/main/resources/fabric.mod.json @@ -1,6 +1,6 @@ { "schemaVersion": 1, - "id": "pagination", + "id": "toolbox-pagination", "version": "${version}", "name": "Task", "description": "A mod to use to paginate long result to player in chat", diff --git a/Tasks/src/main/resources/fabric.mod.json b/Tasks/src/main/resources/fabric.mod.json index c7940a1..217672b 100644 --- a/Tasks/src/main/resources/fabric.mod.json +++ b/Tasks/src/main/resources/fabric.mod.json @@ -1,6 +1,6 @@ { "schemaVersion": 1, - "id": "task", + "id": "toolbox-task", "version": "${version}", "name": "Task", "description": "A mod to use as a dependency for others to schedule tasks", diff --git a/src/main/resources/assets/toolbox/icon.png b/src/main/resources/assets/toolbox/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_3kYG7!NT|7QEHFP{I!3LY zmYW+bEDNbA!yg+foZa)ADg_h?i zt_v}E@5lRjU@G+H3Q5nZ<(w|I$E+E z>#m)K$JH=o1(+rdCi7G)^=Xg1{5Y7$up+JyY3@M2Jdk+LyM7^xXYyw>;s?kqTxeRv zdRkAPdTyPS*WM;Q;dqJ*o1UshJL1{)gupQ-!Kwkk!nbrkzG^$Z^hg>EB;w~SqW2(0 zoV2o8SeDlq^KKz`=Dof)Pnz$DM4hR;{NAbKsm$AZlaIyQs$><`Olu6xE-G^-5n14Y zXSavno!y^p7B$(NmAmywX{m+C8%P8E!B=}hLyfHkU3^ZfP@mnzKJ#SK)CsBTfy~4+ z)2(ImR5N{tPooZ~;L8Tw z%PlOy4dAxTT(r%V9N<#XEf;uhABgtesmjc`3zyJ0-yO7W$TtFFa zOERiv>vY^B%NAnb3;STgtK#(g#TSM&%wkvq)Pyul-8wf3jIpDZR^LEU!WoV%&;sL@ z{bJRhmWwdJ-3z_BO^8Pt4u_onoDYBQm^cC1H@JM7-&;ib zA1ke7+_6%q-xE_kr#b@na?3b>?)jXup@5FCU^m1{yLOo()g(9i)cUVmj#yGjDa
          7y&8%5Zxz@y;pF9ibic`!LP%H5kkM7XnXTS>xu*mAJM zTc_8$a8GQ*ZxWhBp!>{0A^C5Em)_Gm#Fj1$dL0y+yetY@fF#vZawBOHTwQ zYm^&)CM(;+fs${Eu0kE4UM(qrxtP`gYYWs=wQNhe+vfB`{($N5H4!nnC3|LfPUrYz zyjBe4@O9xkMA>Uq5^ncFi-$*L+v-XzIyKA%ZIJY*bV65x&v`pk|)2^MU zW&!0gGwJg&2$Wd-XX|B=<|1c5xRUq^aVzfHR`K}@to;b52b}C(=eCeV;6$G}3&m#x-qy1)=Lu%bi^r;E#OC@MR$E8xByKo5hB&F?YzR(j4e5QT z&{u(+do8e+t75KN9FPg9isv&g&zaSa%_k`>9O=xgb{kK^=PQ9@9lbQiG$#xY2NTrV zV3%B<7`wwjzaTMQ>L1oddTe{2IwxEYeZbk@k^i;-(HdnWyCEr?HQI?UJ}1c@uPR_K z;M~p@bF9d({p#I*xz>?hyM^-V_Zs>SEq<)7x2EQ6T{Rg_ct=*}ekodX2cRg2JUJNe zVou>(FBavFyMM7~6rMwC#MTuq(cm*o#tDwu(&5j$&w;u1XRLbK2fp#5Lj)DEqPOi_ 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 Date: Tue, 13 Jun 2023 18:03:13 +0200 Subject: [PATCH 25/37] Update fabric.mod.json and fix Pagination name --- Pagination/src/main/resources/fabric.mod.json | 2 +- build.gradle | 1 + src/main/resources/fabric.mod.json | 6 +++++- 3 files changed, 7 insertions(+), 2 deletions(-) diff --git a/Pagination/src/main/resources/fabric.mod.json b/Pagination/src/main/resources/fabric.mod.json index f59feb8..68cc742 100644 --- a/Pagination/src/main/resources/fabric.mod.json +++ b/Pagination/src/main/resources/fabric.mod.json @@ -2,7 +2,7 @@ "schemaVersion": 1, "id": "toolbox-pagination", "version": "${version}", - "name": "Task", + "name": "Pagination", "description": "A mod to use to paginate long result to player in chat", "authors": [ "Altarik" diff --git a/build.gradle b/build.gradle index e6c86e7..f291487 100644 --- a/build.gradle +++ b/build.gradle @@ -92,6 +92,7 @@ allprojects { dependencies { include subprojects.collect { project -> project } + implementation subprojects.collect { project -> project } } /*jar { diff --git a/src/main/resources/fabric.mod.json b/src/main/resources/fabric.mod.json index 2119248..ce07720 100644 --- a/src/main/resources/fabric.mod.json +++ b/src/main/resources/fabric.mod.json @@ -20,7 +20,11 @@ "fabricloader": "^0.14.12", "fabric-api": "*", "minecraft": "1.19.3", - "java": ">=17" + "java": ">=17", + "toolbox-core": "${version}", + "toolbox-database": "${version}", + "toolbox-pagination": "${version}", + "toolbox-task": "${version}" } } -- 2.39.5 From 81d780f081c768b55ce6fdd54c818e9f268827b4 Mon Sep 17 00:00:00 2001 From: Quentin Legot Date: Tue, 13 Jun 2023 18:13:23 +0200 Subject: [PATCH 26/37] Change password to a secret --- gradle.properties | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/gradle.properties b/gradle.properties index 59d1cfe..bdf0a21 100644 --- a/gradle.properties +++ b/gradle.properties @@ -10,4 +10,4 @@ fabric_version=0.75.1+1.19.3 maven_group=fr.altarik.toolbox maven_version=4.1.0-SNAPSHOT repo_username=Altarik -repo_password=password +repo_password=REPO_PASSWORD -- 2.39.5 From cfb953e8dc63a3069ddea436cf61e7e4b03f5822 Mon Sep 17 00:00:00 2001 From: Quentin Legot Date: Tue, 13 Jun 2023 21:02:46 +0200 Subject: [PATCH 27/37] Remove secret from gradle.properties, moved it to ENV variables or local.properties --- .gitignore | 1 + build.gradle | 7 +++++-- gradle.properties | 1 - 3 files changed, 6 insertions(+), 3 deletions(-) diff --git a/.gitignore b/.gitignore index a4bcb99..71baab6 100644 --- a/.gitignore +++ b/.gitignore @@ -3,6 +3,7 @@ build/ !gradle/wrapper/gradle-wrapper.jar !**/src/main/**/build/ !**/src/test/**/build/ +local.properties run/* **/run diff --git a/build.gradle b/build.gradle index f291487..1a47000 100644 --- a/build.gradle +++ b/build.gradle @@ -2,6 +2,9 @@ plugins { id 'fabric-loom' version '1.2-SNAPSHOT' apply false } +Properties local = new Properties() +local.load(project.rootProject.file('local.properties').newDataInputStream()) + allprojects { apply plugin: 'maven-publish' apply plugin: 'fabric-loom' @@ -39,8 +42,8 @@ allprojects { name 'altarik' url 'https://repo.altarik.fr/'.concat(project.version.endsWith('SNAPSHOT') ? 'snapshots/' : 'releases/') credentials { - username = project.repo_username - password = project.repo_password + username = Objects.requireNonNull(System.getProperty("REPO_USERNAME", local.getProperty("repo_username"))) + password = Objects.requireNonNull(System.getProperty("REPO_PASSWORD", local.getProperty("repo_password"))) } } } diff --git a/gradle.properties b/gradle.properties index bdf0a21..edaf432 100644 --- a/gradle.properties +++ b/gradle.properties @@ -10,4 +10,3 @@ fabric_version=0.75.1+1.19.3 maven_group=fr.altarik.toolbox maven_version=4.1.0-SNAPSHOT repo_username=Altarik -repo_password=REPO_PASSWORD -- 2.39.5 From eceba274d83a8d5338c714e4e46cb966ff80a88e Mon Sep 17 00:00:00 2001 From: Quentin Legot Date: Tue, 13 Jun 2023 21:12:34 +0200 Subject: [PATCH 28/37] Fix build config --- .gitea/workflows/test.yml | 4 +++- build.gradle | 2 +- 2 files changed, 4 insertions(+), 2 deletions(-) diff --git a/.gitea/workflows/test.yml b/.gitea/workflows/test.yml index 3444f5f..b9ee9db 100644 --- a/.gitea/workflows/test.yml +++ b/.gitea/workflows/test.yml @@ -30,7 +30,9 @@ jobs: distribution: 'oracle' - name: make gradle wrapper executable if: ${{ runner.os != 'Windows' }} - run: chmod +x ./gradlew + run: | + chmod +x ./gradlew + touch local.properties - name: build run: ./gradlew build --no-daemon --max-workers 1 #- name: test diff --git a/build.gradle b/build.gradle index 1a47000..38248ca 100644 --- a/build.gradle +++ b/build.gradle @@ -3,7 +3,7 @@ plugins { } Properties local = new Properties() -local.load(project.rootProject.file('local.properties').newDataInputStream()) +local.load(new FileInputStream(rootProject.file("local.properties"))) allprojects { apply plugin: 'maven-publish' -- 2.39.5 From 393da963e65dca33c531be5af706984d0b9ea7f1 Mon Sep 17 00:00:00 2001 From: Quentin Legot Date: Tue, 13 Jun 2023 21:15:55 +0200 Subject: [PATCH 29/37] log message to try to file runner --- .gitea/workflows/test.yml | 1 + 1 file changed, 1 insertion(+) diff --git a/.gitea/workflows/test.yml b/.gitea/workflows/test.yml index b9ee9db..9e3a858 100644 --- a/.gitea/workflows/test.yml +++ b/.gitea/workflows/test.yml @@ -33,6 +33,7 @@ jobs: run: | chmod +x ./gradlew touch local.properties + echo $REPO_USERNAME - name: build run: ./gradlew build --no-daemon --max-workers 1 #- name: test -- 2.39.5 From bd8980b8cc17338a62b89be397cfb231ec8a3739 Mon Sep 17 00:00:00 2001 From: Quentin Legot Date: Tue, 13 Jun 2023 21:19:23 +0200 Subject: [PATCH 30/37] log message to try to file runner --- .gitea/workflows/test.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.gitea/workflows/test.yml b/.gitea/workflows/test.yml index 9e3a858..99fb008 100644 --- a/.gitea/workflows/test.yml +++ b/.gitea/workflows/test.yml @@ -33,7 +33,7 @@ jobs: run: | chmod +x ./gradlew touch local.properties - echo $REPO_USERNAME + echo ${{ secrets.REPO_USERNAME }} - name: build run: ./gradlew build --no-daemon --max-workers 1 #- name: test -- 2.39.5 From 20ba0a126ad2aef4bfb336b98feb2336a95fcdb8 Mon Sep 17 00:00:00 2001 From: Quentin Legot Date: Tue, 13 Jun 2023 21:24:24 +0200 Subject: [PATCH 31/37] log message to try to file runner --- .gitea/workflows/test.yml | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/.gitea/workflows/test.yml b/.gitea/workflows/test.yml index 99fb008..a9af4c1 100644 --- a/.gitea/workflows/test.yml +++ b/.gitea/workflows/test.yml @@ -33,7 +33,9 @@ jobs: run: | chmod +x ./gradlew touch local.properties - echo ${{ secrets.REPO_USERNAME }} + echo $REPO_USERNAME + env: + REPO_USERNAME: ${{ secrets.REPO_USERNAME }} - name: build run: ./gradlew build --no-daemon --max-workers 1 #- name: test -- 2.39.5 From 1184558c31948ba6b869b824ae59b7cce7b89acf Mon Sep 17 00:00:00 2001 From: Quentin Legot Date: Tue, 13 Jun 2023 21:27:06 +0200 Subject: [PATCH 32/37] log message to try to file runner --- .gitea/workflows/test.yml | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/.gitea/workflows/test.yml b/.gitea/workflows/test.yml index a9af4c1..58502eb 100644 --- a/.gitea/workflows/test.yml +++ b/.gitea/workflows/test.yml @@ -33,11 +33,11 @@ jobs: run: | chmod +x ./gradlew touch local.properties - echo $REPO_USERNAME - env: - REPO_USERNAME: ${{ secrets.REPO_USERNAME }} - name: build run: ./gradlew build --no-daemon --max-workers 1 + env: + REPO_USERNAME: ${{ secrets.REPO_USERNAME }} + REPO_PASSWORD: ${{ secrets.REPO_PASSWORD }} #- name: test # run: ./gradlew test --no-daemon -- 2.39.5 From 97476da96410336a6c325b70b513ec213de4a3f0 Mon Sep 17 00:00:00 2001 From: Quentin Legot Date: Tue, 13 Jun 2023 21:34:10 +0200 Subject: [PATCH 33/37] log message to try to file runner --- .gitea/workflows/test.yml | 14 +++++++++----- 1 file changed, 9 insertions(+), 5 deletions(-) diff --git a/.gitea/workflows/test.yml b/.gitea/workflows/test.yml index 58502eb..50170d3 100644 --- a/.gitea/workflows/test.yml +++ b/.gitea/workflows/test.yml @@ -30,14 +30,18 @@ jobs: distribution: 'oracle' - name: make gradle wrapper executable if: ${{ runner.os != 'Windows' }} - run: | - chmod +x ./gradlew - touch local.properties - - name: build - run: ./gradlew build --no-daemon --max-workers 1 env: REPO_USERNAME: ${{ secrets.REPO_USERNAME }} REPO_PASSWORD: ${{ secrets.REPO_PASSWORD }} + run: | + chmod +x ./gradlew + touch local.properties + echo $REPO_USERNAME + - name: build + env: + REPO_USERNAME: ${{ secrets.REPO_USERNAME }} + REPO_PASSWORD: ${{ secrets.REPO_PASSWORD }} + run: ./gradlew build --no-daemon --max-workers 1 #- name: test # run: ./gradlew test --no-daemon -- 2.39.5 From 26d546e229f97262166e8fe38404f0d68f2918e8 Mon Sep 17 00:00:00 2001 From: Quentin Legot Date: Tue, 13 Jun 2023 21:40:11 +0200 Subject: [PATCH 34/37] log message to try to file runner --- .gitea/workflows/test.yml | 9 +++------ 1 file changed, 3 insertions(+), 6 deletions(-) diff --git a/.gitea/workflows/test.yml b/.gitea/workflows/test.yml index 50170d3..2b00813 100644 --- a/.gitea/workflows/test.yml +++ b/.gitea/workflows/test.yml @@ -10,6 +10,9 @@ on: pull_request_target: branches: [ master, dev ] +env: + REPO_USERNAME: ${{ secrets.REPO_USERNAME }} + REPO_PASSWORD: ${{ secrets.REPO_PASSWORD }} jobs: build: @@ -30,17 +33,11 @@ jobs: distribution: 'oracle' - name: make gradle wrapper executable if: ${{ runner.os != 'Windows' }} - env: - REPO_USERNAME: ${{ secrets.REPO_USERNAME }} - REPO_PASSWORD: ${{ secrets.REPO_PASSWORD }} run: | chmod +x ./gradlew touch local.properties echo $REPO_USERNAME - name: build - env: - REPO_USERNAME: ${{ secrets.REPO_USERNAME }} - REPO_PASSWORD: ${{ secrets.REPO_PASSWORD }} run: ./gradlew build --no-daemon --max-workers 1 #- name: test # run: ./gradlew test --no-daemon -- 2.39.5 From 6f9bd143721584c11105d3c074408421fccde7e7 Mon Sep 17 00:00:00 2001 From: Quentin Legot Date: Tue, 13 Jun 2023 21:49:55 +0200 Subject: [PATCH 35/37] Update '.gitea/workflows/test.yml' --- .gitea/workflows/test.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.gitea/workflows/test.yml b/.gitea/workflows/test.yml index 2b00813..3823945 100644 --- a/.gitea/workflows/test.yml +++ b/.gitea/workflows/test.yml @@ -11,7 +11,7 @@ on: branches: [ master, dev ] env: - REPO_USERNAME: ${{ secrets.REPO_USERNAME }} + REPO_USERNAME: Altarik REPO_PASSWORD: ${{ secrets.REPO_PASSWORD }} jobs: -- 2.39.5 From ea37bdb98fe0fb4b5455c969e29eaecca136d428 Mon Sep 17 00:00:00 2001 From: Quentin Legot Date: Tue, 13 Jun 2023 21:51:54 +0200 Subject: [PATCH 36/37] Update 'build.gradle' --- build.gradle | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/build.gradle b/build.gradle index 38248ca..333cd5f 100644 --- a/build.gradle +++ b/build.gradle @@ -42,8 +42,8 @@ allprojects { name 'altarik' url 'https://repo.altarik.fr/'.concat(project.version.endsWith('SNAPSHOT') ? 'snapshots/' : 'releases/') credentials { - username = Objects.requireNonNull(System.getProperty("REPO_USERNAME", local.getProperty("repo_username"))) - password = Objects.requireNonNull(System.getProperty("REPO_PASSWORD", local.getProperty("repo_password"))) + username = System.getProperty("REPO_USERNAME", local.getProperty("repo_username")) + password = System.getProperty("REPO_PASSWORD", local.getProperty("repo_password")) } } } -- 2.39.5 From 193236f18648f4d7575a31efb6b20d4a0c713082 Mon Sep 17 00:00:00 2001 From: Quentin Legot Date: Tue, 13 Jun 2023 21:59:12 +0200 Subject: [PATCH 37/37] Update '.gitea/workflows/test.yml' --- .gitea/workflows/test.yml | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/.gitea/workflows/test.yml b/.gitea/workflows/test.yml index 3823945..bcd8f0a 100644 --- a/.gitea/workflows/test.yml +++ b/.gitea/workflows/test.yml @@ -41,4 +41,11 @@ jobs: run: ./gradlew build --no-daemon --max-workers 1 #- name: test # run: ./gradlew test --no-daemon + deploy: + runs-on: ${{ ubuntu-latest }} + if: gitea.ref == 'refs/heads/master' + needs: build + steps: + - name: deploy + run: ./gradlew publish -- 2.39.5