From 83b0b477473d4c8b202c48b4cbbb210602494112 Mon Sep 17 00:00:00 2001 From: WizardlyBump17 Date: Thu, 19 Jun 2025 17:22:45 -0300 Subject: [PATCH 001/363] the skull field is only for URLs and owner is only for UUIDs --- .../wlib/item/handler/SkullMetaHandler.java | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/core/src/main/java/com/wizardlybump17/wlib/item/handler/SkullMetaHandler.java b/core/src/main/java/com/wizardlybump17/wlib/item/handler/SkullMetaHandler.java index fcb05fef..900b7563 100644 --- a/core/src/main/java/com/wizardlybump17/wlib/item/handler/SkullMetaHandler.java +++ b/core/src/main/java/com/wizardlybump17/wlib/item/handler/SkullMetaHandler.java @@ -34,14 +34,14 @@ public void serialize(Map map) { @Override public void deserialize(Map map) { String skull = (String) map.get("skull"); - if (skull == null) - return; - - try { - skull(Bukkit.getOfflinePlayer(UUID.fromString(skull))); - } catch (IllegalArgumentException ignored) { + if (skull != null) { skull(skull); + return; } + + String owner = (String) map.get("owner"); + if (owner != null) + skull(Bukkit.getOfflinePlayer(UUID.fromString(owner))); } public String skullUrl() { From a775a3d97ada6eb08011a4f18bee0c837182acce Mon Sep 17 00:00:00 2001 From: WizardlyBump17 Date: Mon, 28 Jul 2025 16:24:11 -0300 Subject: [PATCH 002/363] added support to 1.21.8 --- core/src/main/java/com/wizardlybump17/wlib/WLib.java | 7 +------ 1 file changed, 1 insertion(+), 6 deletions(-) diff --git a/core/src/main/java/com/wizardlybump17/wlib/WLib.java b/core/src/main/java/com/wizardlybump17/wlib/WLib.java index a8a09a00..3e1d35fd 100644 --- a/core/src/main/java/com/wizardlybump17/wlib/WLib.java +++ b/core/src/main/java/com/wizardlybump17/wlib/WLib.java @@ -26,7 +26,6 @@ import com.wizardlybump17.wlib.util.bukkit.config.wrapper.potion.PotionEffectWrapper; import com.wizardlybump17.wlib.util.bukkit.particle.*; import lombok.Getter; -import lombok.NonNull; import org.bukkit.Bukkit; import org.bukkit.configuration.serialization.ConfigurationSerialization; import org.bukkit.event.HandlerList; @@ -131,7 +130,7 @@ private void setupAdapters() { PlayerAdapter.setInstance(new com.wizardlybump17.wlib.adapter.v1_21_R3.player.PlayerAdapter()); AttributeAdapter.setInstance(new com.wizardlybump17.wlib.adapter.v1_21_R3.AttributeAdapter()); } - case "1.21.6", "1.21.7" -> { + case "1.21.6", "1.21.7", "1.21.8" -> { ItemAdapter.setInstance(new com.wizardlybump17.wlib.adapter.v1_21_R5.ItemAdapter()); PlayerAdapter.setInstance(new com.wizardlybump17.wlib.adapter.v1_21_R5.player.PlayerAdapter()); AttributeAdapter.setInstance(new com.wizardlybump17.wlib.adapter.v1_21_R5.AttributeAdapter()); @@ -143,8 +142,4 @@ private void setupAdapters() { public static WLib getInstance() { return getPlugin(WLib.class); } - - public static @NonNull String getServerVersion() { - return Bukkit.getServer().getClass().getName().split("\\.")[3]; - } } From 58cc528434e969c044ce6beee0521210edb0dc2f Mon Sep 17 00:00:00 2001 From: WizardlyBump17 Date: Tue, 14 Oct 2025 18:42:35 -0300 Subject: [PATCH 003/363] upgraded some versions --- build.gradle | 19 ++++++------------- bungee/build.gradle | 2 +- gradle/wrapper/gradle-wrapper.properties | 2 +- versions/v1_21_R5/build.gradle.kts | 2 +- 4 files changed, 9 insertions(+), 16 deletions(-) diff --git a/build.gradle b/build.gradle index 014ee24d..fa2419ba 100644 --- a/build.gradle +++ b/build.gradle @@ -1,5 +1,5 @@ plugins { - id("com.gradleup.shadow") version "8.3.2" + id("com.gradleup.shadow") version "9.2.2" id 'maven-publish' } @@ -20,9 +20,6 @@ subprojects { } } - sourceCompatibility = '21' - targetCompatibility = '21' - tasks { compileJava { options.encoding = 'UTF-8' @@ -38,13 +35,16 @@ subprojects { java { withSourcesJar() + sourceCompatibility = 21 + targetCompatibility = 21 } } subprojects { dependencies { - testImplementation(platform("org.junit:junit-bom:5.10.3")) - testImplementation("org.junit.jupiter:junit-jupiter:5.10.3") + testImplementation(platform("org.junit:junit-bom:6.0.0")) + testImplementation("org.junit.jupiter:junit-jupiter") + testImplementation("org.junit.platform:junit-platform-launcher") } test { @@ -82,13 +82,6 @@ subprojects { } } - dependencies { - testImplementation( - platform('org.junit:junit-bom:5.10.2'), - 'org.junit.jupiter:junit-jupiter:5.10.2' - ) - } - test { useJUnitPlatform() testLogging { diff --git a/bungee/build.gradle b/bungee/build.gradle index 9b89a640..713c008e 100644 --- a/bungee/build.gradle +++ b/bungee/build.gradle @@ -8,7 +8,7 @@ dependencies { compileOnly( 'org.projectlombok:lombok:1.18.32', 'org.jetbrains:annotations:23.0.0', - 'net.md-5:bungeecord-api:1.18-R0.1-SNAPSHOT', + 'net.md-5:bungeecord-api:1.21-R0.3', ) annotationProcessor('org.projectlombok:lombok:1.18.32') implementation( diff --git a/gradle/wrapper/gradle-wrapper.properties b/gradle/wrapper/gradle-wrapper.properties index 5c82cb03..d706aba6 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-8.14-bin.zip +distributionUrl=https\://services.gradle.org/distributions/gradle-9.1.0-bin.zip zipStoreBase=GRADLE_USER_HOME zipStorePath=wrapper/dists diff --git a/versions/v1_21_R5/build.gradle.kts b/versions/v1_21_R5/build.gradle.kts index 96a822fc..a9f0149e 100644 --- a/versions/v1_21_R5/build.gradle.kts +++ b/versions/v1_21_R5/build.gradle.kts @@ -4,7 +4,7 @@ plugins { apply(plugin = "io.papermc.paperweight.userdev") -val paper = "1.21.7-R0.1-SNAPSHOT" +val paper = "1.21.8-R0.1-SNAPSHOT" val jetbrainsAnnotations = "26.0.2" dependencies { From 27a965eacb0cdb22e14c193417f7c2748248f831 Mon Sep 17 00:00:00 2001 From: WizardlyBump17 Date: Wed, 15 Oct 2025 17:38:19 -0300 Subject: [PATCH 004/363] starting some rework --- .../wlib/command/rework/Command.java | 21 +++++++++++ .../wlib/command/rework/node/CommandNode.java | 36 +++++++++++++++++++ .../rework/node/IntegerCommandNode.java | 31 ++++++++++++++++ .../rework/node/LiteralCommandNode.java | 28 +++++++++++++++ .../rework/node/input/AllowedInputs.java | 8 +++++ .../node/input/AllowedNumberInputs.java | 28 +++++++++++++++ .../node/input/LiteralAllowedInput.java | 16 +++++++++ 7 files changed, 168 insertions(+) create mode 100644 commands/src/main/java/com/wizardlybump17/wlib/command/rework/Command.java create mode 100644 commands/src/main/java/com/wizardlybump17/wlib/command/rework/node/CommandNode.java create mode 100644 commands/src/main/java/com/wizardlybump17/wlib/command/rework/node/IntegerCommandNode.java create mode 100644 commands/src/main/java/com/wizardlybump17/wlib/command/rework/node/LiteralCommandNode.java create mode 100644 commands/src/main/java/com/wizardlybump17/wlib/command/rework/node/input/AllowedInputs.java create mode 100644 commands/src/main/java/com/wizardlybump17/wlib/command/rework/node/input/AllowedNumberInputs.java create mode 100644 commands/src/main/java/com/wizardlybump17/wlib/command/rework/node/input/LiteralAllowedInput.java diff --git a/commands/src/main/java/com/wizardlybump17/wlib/command/rework/Command.java b/commands/src/main/java/com/wizardlybump17/wlib/command/rework/Command.java new file mode 100644 index 00000000..1e560c3d --- /dev/null +++ b/commands/src/main/java/com/wizardlybump17/wlib/command/rework/Command.java @@ -0,0 +1,21 @@ +package com.wizardlybump17.wlib.command.rework; + +import com.wizardlybump17.wlib.command.rework.node.input.LiteralAllowedInput; +import com.wizardlybump17.wlib.command.sender.CommandSender; +import org.jetbrains.annotations.NotNull; + +public class Command { + + private final @NotNull LiteralAllowedInput root; + + public Command(@NotNull LiteralAllowedInput root) { + this.root = root; + } + + public @NotNull LiteralAllowedInput getRoot() { + return root; + } + + public void execute(@NotNull CommandSender sender, @NotNull String execution) { + } +} diff --git a/commands/src/main/java/com/wizardlybump17/wlib/command/rework/node/CommandNode.java b/commands/src/main/java/com/wizardlybump17/wlib/command/rework/node/CommandNode.java new file mode 100644 index 00000000..5df51453 --- /dev/null +++ b/commands/src/main/java/com/wizardlybump17/wlib/command/rework/node/CommandNode.java @@ -0,0 +1,36 @@ +package com.wizardlybump17.wlib.command.rework.node; + +import com.wizardlybump17.wlib.command.rework.node.input.AllowedInputs; +import org.jetbrains.annotations.NotNull; +import org.jetbrains.annotations.Unmodifiable; + +import java.util.Collections; +import java.util.List; +import java.util.Optional; + +public abstract class CommandNode { + + private final @NotNull String name; + private final @NotNull @Unmodifiable List> children; + private final @NotNull AllowedInputs allowedInputs; + + public CommandNode(@NotNull String name, @NotNull List> children, @NotNull AllowedInputs allowedInputs) { + this.name = name; + this.children = Collections.unmodifiableList(children); + this.allowedInputs = allowedInputs; + } + + public @NotNull String getName() { + return name; + } + + public @NotNull @Unmodifiable List> getChildren() { + return children; + } + + public @NotNull AllowedInputs getAllowedInputs() { + return allowedInputs; + } + + public abstract @NotNull Optional parse(@NotNull String input); +} diff --git a/commands/src/main/java/com/wizardlybump17/wlib/command/rework/node/IntegerCommandNode.java b/commands/src/main/java/com/wizardlybump17/wlib/command/rework/node/IntegerCommandNode.java new file mode 100644 index 00000000..ba6b8aa8 --- /dev/null +++ b/commands/src/main/java/com/wizardlybump17/wlib/command/rework/node/IntegerCommandNode.java @@ -0,0 +1,31 @@ +package com.wizardlybump17.wlib.command.rework.node; + +import com.wizardlybump17.wlib.command.rework.node.input.AllowedNumberInputs; +import org.jetbrains.annotations.NotNull; + +import java.util.List; +import java.util.Optional; + +public class IntegerCommandNode extends CommandNode { + + public IntegerCommandNode(@NotNull String name, @NotNull List> children, @NotNull AllowedNumberInputs.AllowedIntegerInputs allowedInputs) { + super(name, children, allowedInputs); + } + + @Override + public @NotNull AllowedNumberInputs.AllowedIntegerInputs getAllowedInputs() { + return (AllowedNumberInputs.AllowedIntegerInputs) super.getAllowedInputs(); + } + + @Override + public @NotNull Optional parse(@NotNull String input) { + try { + int integer = Integer.parseInt(input); + if (getAllowedInputs().isAllowed(integer)) + return Optional.of(integer); + return Optional.empty(); + } catch (NumberFormatException e) { + return Optional.empty(); + } + } +} diff --git a/commands/src/main/java/com/wizardlybump17/wlib/command/rework/node/LiteralCommandNode.java b/commands/src/main/java/com/wizardlybump17/wlib/command/rework/node/LiteralCommandNode.java new file mode 100644 index 00000000..16d22ed7 --- /dev/null +++ b/commands/src/main/java/com/wizardlybump17/wlib/command/rework/node/LiteralCommandNode.java @@ -0,0 +1,28 @@ +package com.wizardlybump17.wlib.command.rework.node; + +import com.wizardlybump17.wlib.command.rework.node.input.LiteralAllowedInput; +import org.jetbrains.annotations.NotNull; + +import java.util.List; +import java.util.Optional; + +public class LiteralCommandNode extends CommandNode { + + public static final @NotNull String EMPTY_STRING = ""; + + public LiteralCommandNode(@NotNull String name, @NotNull List> children) { + super(name, children, new LiteralAllowedInput(name, false)); + } + + @Override + public @NotNull LiteralAllowedInput getAllowedInputs() { + return (LiteralAllowedInput) super.getAllowedInputs(); + } + + @Override + public @NotNull Optional parse(@NotNull String input) { + if (!getName().equalsIgnoreCase(input)) + return Optional.empty(); + return Optional.of(EMPTY_STRING); + } +} diff --git a/commands/src/main/java/com/wizardlybump17/wlib/command/rework/node/input/AllowedInputs.java b/commands/src/main/java/com/wizardlybump17/wlib/command/rework/node/input/AllowedInputs.java new file mode 100644 index 00000000..47207fb5 --- /dev/null +++ b/commands/src/main/java/com/wizardlybump17/wlib/command/rework/node/input/AllowedInputs.java @@ -0,0 +1,8 @@ +package com.wizardlybump17.wlib.command.rework.node.input; + +import org.jetbrains.annotations.Nullable; + +public interface AllowedInputs { + + boolean isAllowed(@Nullable T input); +} diff --git a/commands/src/main/java/com/wizardlybump17/wlib/command/rework/node/input/AllowedNumberInputs.java b/commands/src/main/java/com/wizardlybump17/wlib/command/rework/node/input/AllowedNumberInputs.java new file mode 100644 index 00000000..e97344af --- /dev/null +++ b/commands/src/main/java/com/wizardlybump17/wlib/command/rework/node/input/AllowedNumberInputs.java @@ -0,0 +1,28 @@ +package com.wizardlybump17.wlib.command.rework.node.input; + +import org.jetbrains.annotations.NotNull; +import org.jetbrains.annotations.Nullable; + +public interface AllowedNumberInputs extends AllowedInputs { + + @NotNull N from(); + + @NotNull N to(); + + boolean isInRange(@NotNull N number); + + record AllowedIntegerInputs(@NotNull Integer from, @NotNull Integer to) implements AllowedNumberInputs { + + @Override + public boolean isInRange(@NotNull Integer number) { + return number.compareTo(from) >= 0 && number.compareTo(to) <= 0; + } + + @Override + public boolean isAllowed(@Nullable Integer input) { + if (input == null) + return false; + return isInRange(input); + } + } +} diff --git a/commands/src/main/java/com/wizardlybump17/wlib/command/rework/node/input/LiteralAllowedInput.java b/commands/src/main/java/com/wizardlybump17/wlib/command/rework/node/input/LiteralAllowedInput.java new file mode 100644 index 00000000..7e7c5098 --- /dev/null +++ b/commands/src/main/java/com/wizardlybump17/wlib/command/rework/node/input/LiteralAllowedInput.java @@ -0,0 +1,16 @@ +package com.wizardlybump17.wlib.command.rework.node.input; + +import org.jetbrains.annotations.NotNull; +import org.jetbrains.annotations.Nullable; + +public record LiteralAllowedInput(@NotNull String value, boolean caseSensitive) implements AllowedInputs { + + @Override + public boolean isAllowed(@Nullable String input) { + if (input == null) + return false; + if (caseSensitive) + return input.equals(value); + return input.equalsIgnoreCase(value); + } +} From dd9a2c102847654fbfb09fa52590efb473ef61cf Mon Sep 17 00:00:00 2001 From: WizardlyBump17 Date: Wed, 15 Oct 2025 21:29:51 -0300 Subject: [PATCH 005/363] giving some suggestions --- .../wlib/command/rework/node/CommandNode.java | 5 +++++ .../command/rework/node/IntegerCommandNode.java | 17 +++++++++++++++++ .../command/rework/node/LiteralCommandNode.java | 6 ++++++ 3 files changed, 28 insertions(+) diff --git a/commands/src/main/java/com/wizardlybump17/wlib/command/rework/node/CommandNode.java b/commands/src/main/java/com/wizardlybump17/wlib/command/rework/node/CommandNode.java index 5df51453..a31c60df 100644 --- a/commands/src/main/java/com/wizardlybump17/wlib/command/rework/node/CommandNode.java +++ b/commands/src/main/java/com/wizardlybump17/wlib/command/rework/node/CommandNode.java @@ -1,6 +1,7 @@ package com.wizardlybump17.wlib.command.rework.node; import com.wizardlybump17.wlib.command.rework.node.input.AllowedInputs; +import com.wizardlybump17.wlib.command.sender.CommandSender; import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.Unmodifiable; @@ -33,4 +34,8 @@ public CommandNode(@NotNull String name, @NotNull List> children, } public abstract @NotNull Optional parse(@NotNull String input); + + public @NotNull List getSuggestions(@NotNull CommandSender sender, @NotNull List args, @NotNull String currentInput) { + return List.of(); + } } diff --git a/commands/src/main/java/com/wizardlybump17/wlib/command/rework/node/IntegerCommandNode.java b/commands/src/main/java/com/wizardlybump17/wlib/command/rework/node/IntegerCommandNode.java index ba6b8aa8..3b91c4ee 100644 --- a/commands/src/main/java/com/wizardlybump17/wlib/command/rework/node/IntegerCommandNode.java +++ b/commands/src/main/java/com/wizardlybump17/wlib/command/rework/node/IntegerCommandNode.java @@ -1,10 +1,12 @@ package com.wizardlybump17.wlib.command.rework.node; import com.wizardlybump17.wlib.command.rework.node.input.AllowedNumberInputs; +import com.wizardlybump17.wlib.command.sender.CommandSender; import org.jetbrains.annotations.NotNull; import java.util.List; import java.util.Optional; +import java.util.stream.IntStream; public class IntegerCommandNode extends CommandNode { @@ -28,4 +30,19 @@ public IntegerCommandNode(@NotNull String name, @NotNull List> ch return Optional.empty(); } } + + @Override + public @NotNull List getSuggestions(@NotNull CommandSender sender, @NotNull List args, @NotNull String currentInput) { + if (!currentInput.isEmpty()) + return List.of(); + + AllowedNumberInputs.AllowedIntegerInputs allowedInputs = getAllowedInputs(); + int from = allowedInputs.from(); + int to = allowedInputs.to(); + + if (to - from < 3) + return IntStream.rangeClosed(from, to).boxed().toList(); + + return List.of(from, (from + to) / 2, to); + } } diff --git a/commands/src/main/java/com/wizardlybump17/wlib/command/rework/node/LiteralCommandNode.java b/commands/src/main/java/com/wizardlybump17/wlib/command/rework/node/LiteralCommandNode.java index 16d22ed7..f0c5da12 100644 --- a/commands/src/main/java/com/wizardlybump17/wlib/command/rework/node/LiteralCommandNode.java +++ b/commands/src/main/java/com/wizardlybump17/wlib/command/rework/node/LiteralCommandNode.java @@ -1,6 +1,7 @@ package com.wizardlybump17.wlib.command.rework.node; import com.wizardlybump17.wlib.command.rework.node.input.LiteralAllowedInput; +import com.wizardlybump17.wlib.command.sender.CommandSender; import org.jetbrains.annotations.NotNull; import java.util.List; @@ -25,4 +26,9 @@ public LiteralCommandNode(@NotNull String name, @NotNull List> ch return Optional.empty(); return Optional.of(EMPTY_STRING); } + + @Override + public @NotNull List getSuggestions(@NotNull CommandSender sender, @NotNull List args, @NotNull String currentInput) { + return List.of(getName()); + } } From 5b755e4a6da34c9d286dcd68c2456f106e508e90 Mon Sep 17 00:00:00 2001 From: WizardlyBump17 Date: Fri, 17 Oct 2025 17:56:41 -0300 Subject: [PATCH 006/363] improved the AllowedInputs system --- .../rework/node/IntegerCommandNode.java | 17 ++++++++---- .../node/input/AllowedNumberInputs.java | 27 +++++++++---------- .../node/input/RangedAllowedInputs.java | 12 +++++++++ 3 files changed, 36 insertions(+), 20 deletions(-) create mode 100644 commands/src/main/java/com/wizardlybump17/wlib/command/rework/node/input/RangedAllowedInputs.java diff --git a/commands/src/main/java/com/wizardlybump17/wlib/command/rework/node/IntegerCommandNode.java b/commands/src/main/java/com/wizardlybump17/wlib/command/rework/node/IntegerCommandNode.java index 3b91c4ee..8867c907 100644 --- a/commands/src/main/java/com/wizardlybump17/wlib/command/rework/node/IntegerCommandNode.java +++ b/commands/src/main/java/com/wizardlybump17/wlib/command/rework/node/IntegerCommandNode.java @@ -1,6 +1,7 @@ package com.wizardlybump17.wlib.command.rework.node; import com.wizardlybump17.wlib.command.rework.node.input.AllowedNumberInputs; +import com.wizardlybump17.wlib.command.rework.node.input.RangedAllowedInputs; import com.wizardlybump17.wlib.command.sender.CommandSender; import org.jetbrains.annotations.NotNull; @@ -37,12 +38,18 @@ public IntegerCommandNode(@NotNull String name, @NotNull List> ch return List.of(); AllowedNumberInputs.AllowedIntegerInputs allowedInputs = getAllowedInputs(); - int from = allowedInputs.from(); - int to = allowedInputs.to(); - if (to - from < 3) - return IntStream.rangeClosed(from, to).boxed().toList(); + if (allowedInputs instanceof RangedAllowedInputs ranged) { + int from = (int) ranged.from(); + int to = (int) ranged.to(); - return List.of(from, (from + to) / 2, to); + if (to - from < 5) + return IntStream.rangeClosed(from, to).boxed().toList(); + + int fourth = (to - from) / 4; + return List.of(from, from + fourth, from + fourth * 2, from + fourth * 3, to); + } + + return List.of(-100, -10, 0, 10, 100); } } diff --git a/commands/src/main/java/com/wizardlybump17/wlib/command/rework/node/input/AllowedNumberInputs.java b/commands/src/main/java/com/wizardlybump17/wlib/command/rework/node/input/AllowedNumberInputs.java index e97344af..cc2e40b4 100644 --- a/commands/src/main/java/com/wizardlybump17/wlib/command/rework/node/input/AllowedNumberInputs.java +++ b/commands/src/main/java/com/wizardlybump17/wlib/command/rework/node/input/AllowedNumberInputs.java @@ -5,24 +5,21 @@ public interface AllowedNumberInputs extends AllowedInputs { - @NotNull N from(); + interface AllowedIntegerInputs extends AllowedInputs { - @NotNull N to(); + record Range(@NotNull Integer from, @NotNull Integer to) implements AllowedIntegerInputs, RangedAllowedInputs { - boolean isInRange(@NotNull N number); + @Override + public boolean isInRange(@NotNull Integer number) { + return number.compareTo(from) >= 0 && number.compareTo(to) <= 0; + } - record AllowedIntegerInputs(@NotNull Integer from, @NotNull Integer to) implements AllowedNumberInputs { - - @Override - public boolean isInRange(@NotNull Integer number) { - return number.compareTo(from) >= 0 && number.compareTo(to) <= 0; - } - - @Override - public boolean isAllowed(@Nullable Integer input) { - if (input == null) - return false; - return isInRange(input); + @Override + public boolean isAllowed(@Nullable Integer input) { + if (input == null) + return false; + return isInRange(input); + } } } } diff --git a/commands/src/main/java/com/wizardlybump17/wlib/command/rework/node/input/RangedAllowedInputs.java b/commands/src/main/java/com/wizardlybump17/wlib/command/rework/node/input/RangedAllowedInputs.java new file mode 100644 index 00000000..b44ac63a --- /dev/null +++ b/commands/src/main/java/com/wizardlybump17/wlib/command/rework/node/input/RangedAllowedInputs.java @@ -0,0 +1,12 @@ +package com.wizardlybump17.wlib.command.rework.node.input; + +import org.jetbrains.annotations.NotNull; + +public interface RangedAllowedInputs extends AllowedInputs { + + @NotNull T from(); + + @NotNull T to(); + + boolean isInRange(@NotNull T input); +} From f84042bdd7735bb46faa170a51f8fa68f15b5ed7 Mon Sep 17 00:00:00 2001 From: WizardlyBump17 Date: Fri, 17 Oct 2025 18:20:39 -0300 Subject: [PATCH 007/363] improved the parse system --- .../wlib/command/rework/node/CommandNode.java | 25 +++++++++++++++++-- .../rework/node/IntegerCommandNode.java | 10 +++----- .../rework/node/LiteralCommandNode.java | 7 ++---- 3 files changed, 28 insertions(+), 14 deletions(-) diff --git a/commands/src/main/java/com/wizardlybump17/wlib/command/rework/node/CommandNode.java b/commands/src/main/java/com/wizardlybump17/wlib/command/rework/node/CommandNode.java index a31c60df..453f3767 100644 --- a/commands/src/main/java/com/wizardlybump17/wlib/command/rework/node/CommandNode.java +++ b/commands/src/main/java/com/wizardlybump17/wlib/command/rework/node/CommandNode.java @@ -3,14 +3,16 @@ import com.wizardlybump17.wlib.command.rework.node.input.AllowedInputs; import com.wizardlybump17.wlib.command.sender.CommandSender; import org.jetbrains.annotations.NotNull; +import org.jetbrains.annotations.Nullable; import org.jetbrains.annotations.Unmodifiable; import java.util.Collections; import java.util.List; -import java.util.Optional; public abstract class CommandNode { + public static final @NotNull Object EMPTY_OBJECT = new Object(); + private final @NotNull String name; private final @NotNull @Unmodifiable List> children; private final @NotNull AllowedInputs allowedInputs; @@ -33,9 +35,28 @@ public CommandNode(@NotNull String name, @NotNull List> children, return allowedInputs; } - public abstract @NotNull Optional parse(@NotNull String input); + public abstract @NotNull ParseResult parse(@NotNull String input); + + public final boolean isValidInput(@Nullable T input) { + return allowedInputs.isAllowed(input); + } public @NotNull List getSuggestions(@NotNull CommandSender sender, @NotNull List args, @NotNull String currentInput) { return List.of(); } + + public record ParseResult(boolean success, @Nullable T value) { + + public static @NotNull ParseResult success(@Nullable T value) { + return new ParseResult<>(true, value); + } + + public static @NotNull ParseResult emptySuccess() { + return new ParseResult<>(true, null); + } + + public static @NotNull ParseResult failure() { + return new ParseResult<>(false, null); + } + } } diff --git a/commands/src/main/java/com/wizardlybump17/wlib/command/rework/node/IntegerCommandNode.java b/commands/src/main/java/com/wizardlybump17/wlib/command/rework/node/IntegerCommandNode.java index 8867c907..baeddca0 100644 --- a/commands/src/main/java/com/wizardlybump17/wlib/command/rework/node/IntegerCommandNode.java +++ b/commands/src/main/java/com/wizardlybump17/wlib/command/rework/node/IntegerCommandNode.java @@ -6,7 +6,6 @@ import org.jetbrains.annotations.NotNull; import java.util.List; -import java.util.Optional; import java.util.stream.IntStream; public class IntegerCommandNode extends CommandNode { @@ -21,14 +20,11 @@ public IntegerCommandNode(@NotNull String name, @NotNull List> ch } @Override - public @NotNull Optional parse(@NotNull String input) { + public @NotNull ParseResult parse(@NotNull String input) { try { - int integer = Integer.parseInt(input); - if (getAllowedInputs().isAllowed(integer)) - return Optional.of(integer); - return Optional.empty(); + return ParseResult.success(Integer.parseInt(input)); } catch (NumberFormatException e) { - return Optional.empty(); + return ParseResult.failure(); } } diff --git a/commands/src/main/java/com/wizardlybump17/wlib/command/rework/node/LiteralCommandNode.java b/commands/src/main/java/com/wizardlybump17/wlib/command/rework/node/LiteralCommandNode.java index f0c5da12..1ddfa500 100644 --- a/commands/src/main/java/com/wizardlybump17/wlib/command/rework/node/LiteralCommandNode.java +++ b/commands/src/main/java/com/wizardlybump17/wlib/command/rework/node/LiteralCommandNode.java @@ -5,7 +5,6 @@ import org.jetbrains.annotations.NotNull; import java.util.List; -import java.util.Optional; public class LiteralCommandNode extends CommandNode { @@ -21,10 +20,8 @@ public LiteralCommandNode(@NotNull String name, @NotNull List> ch } @Override - public @NotNull Optional parse(@NotNull String input) { - if (!getName().equalsIgnoreCase(input)) - return Optional.empty(); - return Optional.of(EMPTY_STRING); + public @NotNull ParseResult parse(@NotNull String input) { + return ParseResult.emptySuccess(); } @Override From ea500e8989110bca1c5d14346b3c84d88f2198b6 Mon Sep 17 00:00:00 2001 From: WizardlyBump17 Date: Fri, 17 Oct 2025 18:23:54 -0300 Subject: [PATCH 008/363] starting the CommandResult system --- .../wlib/command/rework/Command.java | 9 ++++++- .../command/rework/result/CommandResult.java | 24 +++++++++++++++++++ .../rework/result/ExceptionResult.java | 11 +++++++++ .../rework/result/GenericErrorResult.java | 14 +++++++++++ .../command/rework/result/SuccessResult.java | 16 +++++++++++++ .../wlib/command/test/rework/ReworkTests.java | 4 ++++ 6 files changed, 77 insertions(+), 1 deletion(-) create mode 100644 commands/src/main/java/com/wizardlybump17/wlib/command/rework/result/CommandResult.java create mode 100644 commands/src/main/java/com/wizardlybump17/wlib/command/rework/result/ExceptionResult.java create mode 100644 commands/src/main/java/com/wizardlybump17/wlib/command/rework/result/GenericErrorResult.java create mode 100644 commands/src/main/java/com/wizardlybump17/wlib/command/rework/result/SuccessResult.java create mode 100644 commands/src/test/java/com/wizardlybump17/wlib/command/test/rework/ReworkTests.java diff --git a/commands/src/main/java/com/wizardlybump17/wlib/command/rework/Command.java b/commands/src/main/java/com/wizardlybump17/wlib/command/rework/Command.java index 1e560c3d..5822d805 100644 --- a/commands/src/main/java/com/wizardlybump17/wlib/command/rework/Command.java +++ b/commands/src/main/java/com/wizardlybump17/wlib/command/rework/Command.java @@ -1,9 +1,14 @@ package com.wizardlybump17.wlib.command.rework; import com.wizardlybump17.wlib.command.rework.node.input.LiteralAllowedInput; +import com.wizardlybump17.wlib.command.rework.result.CommandResult; +import com.wizardlybump17.wlib.command.rework.result.SuccessResult; import com.wizardlybump17.wlib.command.sender.CommandSender; +import com.wizardlybump17.wlib.util.StringUtil; import org.jetbrains.annotations.NotNull; +import java.util.List; + public class Command { private final @NotNull LiteralAllowedInput root; @@ -16,6 +21,8 @@ public Command(@NotNull LiteralAllowedInput root) { return root; } - public void execute(@NotNull CommandSender sender, @NotNull String execution) { + public @NotNull CommandResult execute(@NotNull CommandSender sender, @NotNull String execution) { + List strings = StringUtil.parseQuotedStrings(execution); + return SuccessResult.INSTANCE; } } diff --git a/commands/src/main/java/com/wizardlybump17/wlib/command/rework/result/CommandResult.java b/commands/src/main/java/com/wizardlybump17/wlib/command/rework/result/CommandResult.java new file mode 100644 index 00000000..c0961d39 --- /dev/null +++ b/commands/src/main/java/com/wizardlybump17/wlib/command/rework/result/CommandResult.java @@ -0,0 +1,24 @@ +package com.wizardlybump17.wlib.command.rework.result; + +import org.jetbrains.annotations.NotNull; + +public interface CommandResult { + + boolean success(); + + static @NotNull SuccessResult successful() { + return SuccessResult.INSTANCE; + } + + static @NotNull ExceptionResult exceptionally(@NotNull Throwable throwable) { + return new ExceptionResult(throwable); + } + + static @NotNull GenericErrorResult error(@NotNull String message) { + return new GenericErrorResult(message); + } + + static @NotNull GenericErrorResult error() { + return GenericErrorResult.DEFAULT_ERROR; + } +} diff --git a/commands/src/main/java/com/wizardlybump17/wlib/command/rework/result/ExceptionResult.java b/commands/src/main/java/com/wizardlybump17/wlib/command/rework/result/ExceptionResult.java new file mode 100644 index 00000000..69e6902a --- /dev/null +++ b/commands/src/main/java/com/wizardlybump17/wlib/command/rework/result/ExceptionResult.java @@ -0,0 +1,11 @@ +package com.wizardlybump17.wlib.command.rework.result; + +import org.jetbrains.annotations.NotNull; + +public record ExceptionResult(@NotNull Throwable exception) implements CommandResult { + + @Override + public boolean success() { + return false; + } +} diff --git a/commands/src/main/java/com/wizardlybump17/wlib/command/rework/result/GenericErrorResult.java b/commands/src/main/java/com/wizardlybump17/wlib/command/rework/result/GenericErrorResult.java new file mode 100644 index 00000000..cab0fe23 --- /dev/null +++ b/commands/src/main/java/com/wizardlybump17/wlib/command/rework/result/GenericErrorResult.java @@ -0,0 +1,14 @@ +package com.wizardlybump17.wlib.command.rework.result; + +import org.jetbrains.annotations.NotNull; + +public record GenericErrorResult(@NotNull String message) implements CommandResult { + + public static final @NotNull String DEFAULT_MESSAGE = "An error occurred while executing the command"; + public static final @NotNull GenericErrorResult DEFAULT_ERROR = new GenericErrorResult(DEFAULT_MESSAGE); + + @Override + public boolean success() { + return false; + } +} diff --git a/commands/src/main/java/com/wizardlybump17/wlib/command/rework/result/SuccessResult.java b/commands/src/main/java/com/wizardlybump17/wlib/command/rework/result/SuccessResult.java new file mode 100644 index 00000000..9e32cdc7 --- /dev/null +++ b/commands/src/main/java/com/wizardlybump17/wlib/command/rework/result/SuccessResult.java @@ -0,0 +1,16 @@ +package com.wizardlybump17.wlib.command.rework.result; + +import org.jetbrains.annotations.NotNull; + +public final class SuccessResult implements CommandResult { + + public static final @NotNull SuccessResult INSTANCE = new SuccessResult(); + + private SuccessResult() { + } + + @Override + public boolean success() { + return false; + } +} diff --git a/commands/src/test/java/com/wizardlybump17/wlib/command/test/rework/ReworkTests.java b/commands/src/test/java/com/wizardlybump17/wlib/command/test/rework/ReworkTests.java new file mode 100644 index 00000000..785cf5ba --- /dev/null +++ b/commands/src/test/java/com/wizardlybump17/wlib/command/test/rework/ReworkTests.java @@ -0,0 +1,4 @@ +package com.wizardlybump17.wlib.command.test.rework; + +class ReworkTests { +} From b38bc6e26f22e246bff93b1aebb2928d7c41b687 Mon Sep 17 00:00:00 2001 From: WizardlyBump17 Date: Fri, 17 Oct 2025 18:27:20 -0300 Subject: [PATCH 009/363] lol --- .../com/wizardlybump17/wlib/command/rework/Command.java | 7 ++++--- .../wlib/command/rework/node/LiteralCommandNode.java | 2 -- 2 files changed, 4 insertions(+), 5 deletions(-) diff --git a/commands/src/main/java/com/wizardlybump17/wlib/command/rework/Command.java b/commands/src/main/java/com/wizardlybump17/wlib/command/rework/Command.java index 5822d805..bc4fa610 100644 --- a/commands/src/main/java/com/wizardlybump17/wlib/command/rework/Command.java +++ b/commands/src/main/java/com/wizardlybump17/wlib/command/rework/Command.java @@ -1,6 +1,7 @@ package com.wizardlybump17.wlib.command.rework; import com.wizardlybump17.wlib.command.rework.node.input.LiteralAllowedInput; +import com.wizardlybump17.wlib.command.rework.node.LiteralCommandNode; import com.wizardlybump17.wlib.command.rework.result.CommandResult; import com.wizardlybump17.wlib.command.rework.result.SuccessResult; import com.wizardlybump17.wlib.command.sender.CommandSender; @@ -11,13 +12,13 @@ public class Command { - private final @NotNull LiteralAllowedInput root; + private final @NotNull LiteralCommandNode root; - public Command(@NotNull LiteralAllowedInput root) { + public Command(@NotNull LiteralCommandNode root) { this.root = root; } - public @NotNull LiteralAllowedInput getRoot() { + public @NotNull LiteralCommandNode getRoot() { return root; } diff --git a/commands/src/main/java/com/wizardlybump17/wlib/command/rework/node/LiteralCommandNode.java b/commands/src/main/java/com/wizardlybump17/wlib/command/rework/node/LiteralCommandNode.java index 1ddfa500..7e3f5a65 100644 --- a/commands/src/main/java/com/wizardlybump17/wlib/command/rework/node/LiteralCommandNode.java +++ b/commands/src/main/java/com/wizardlybump17/wlib/command/rework/node/LiteralCommandNode.java @@ -8,8 +8,6 @@ public class LiteralCommandNode extends CommandNode { - public static final @NotNull String EMPTY_STRING = ""; - public LiteralCommandNode(@NotNull String name, @NotNull List> children) { super(name, children, new LiteralAllowedInput(name, false)); } From 84f3676767cd3ee7c714d8fd355e3fa6cf4a0fbc Mon Sep 17 00:00:00 2001 From: WizardlyBump17 Date: Fri, 17 Oct 2025 18:31:27 -0300 Subject: [PATCH 010/363] added a parent system to CommandNode --- .../wlib/command/rework/node/CommandNode.java | 18 ++++++++++++++++-- 1 file changed, 16 insertions(+), 2 deletions(-) diff --git a/commands/src/main/java/com/wizardlybump17/wlib/command/rework/node/CommandNode.java b/commands/src/main/java/com/wizardlybump17/wlib/command/rework/node/CommandNode.java index 453f3767..3133472d 100644 --- a/commands/src/main/java/com/wizardlybump17/wlib/command/rework/node/CommandNode.java +++ b/commands/src/main/java/com/wizardlybump17/wlib/command/rework/node/CommandNode.java @@ -11,15 +11,17 @@ public abstract class CommandNode { - public static final @NotNull Object EMPTY_OBJECT = new Object(); - private final @NotNull String name; private final @NotNull @Unmodifiable List> children; private final @NotNull AllowedInputs allowedInputs; + private @NotNull CommandNode parent = this; public CommandNode(@NotNull String name, @NotNull List> children, @NotNull AllowedInputs allowedInputs) { this.name = name; + + children.forEach(child -> child.setParent(this)); this.children = Collections.unmodifiableList(children); + this.allowedInputs = allowedInputs; } @@ -45,6 +47,18 @@ public final boolean isValidInput(@Nullable T input) { return List.of(); } + public @NotNull CommandNode getParent() { + return parent; + } + + public void setParent(@NotNull CommandNode parent) { + this.parent = parent; + } + + public boolean hasParent() { + return parent != this; + } + public record ParseResult(boolean success, @Nullable T value) { public static @NotNull ParseResult success(@Nullable T value) { From 1606318b8ce46735c808b5efbbea10dcd51a72f0 Mon Sep 17 00:00:00 2001 From: WizardlyBump17 Date: Fri, 17 Oct 2025 19:12:48 -0300 Subject: [PATCH 011/363] returning something --- .../wlib/command/rework/Command.java | 58 ++++++++++++++++++- .../rework/node/LiteralCommandNode.java | 2 +- .../wlib/command/test/rework/ReworkTests.java | 22 +++++++ 3 files changed, 80 insertions(+), 2 deletions(-) diff --git a/commands/src/main/java/com/wizardlybump17/wlib/command/rework/Command.java b/commands/src/main/java/com/wizardlybump17/wlib/command/rework/Command.java index bc4fa610..8c128256 100644 --- a/commands/src/main/java/com/wizardlybump17/wlib/command/rework/Command.java +++ b/commands/src/main/java/com/wizardlybump17/wlib/command/rework/Command.java @@ -1,14 +1,17 @@ package com.wizardlybump17.wlib.command.rework; -import com.wizardlybump17.wlib.command.rework.node.input.LiteralAllowedInput; +import com.wizardlybump17.wlib.command.rework.node.CommandNode; import com.wizardlybump17.wlib.command.rework.node.LiteralCommandNode; import com.wizardlybump17.wlib.command.rework.result.CommandResult; import com.wizardlybump17.wlib.command.rework.result.SuccessResult; import com.wizardlybump17.wlib.command.sender.CommandSender; import com.wizardlybump17.wlib.util.StringUtil; import org.jetbrains.annotations.NotNull; +import org.jetbrains.annotations.Nullable; +import java.util.LinkedHashMap; import java.util.List; +import java.util.Map; public class Command { @@ -26,4 +29,57 @@ public Command(@NotNull LiteralCommandNode root) { List strings = StringUtil.parseQuotedStrings(execution); return SuccessResult.INSTANCE; } + + @SuppressWarnings("unchecked") + public @NotNull Map> getNodes(@NotNull List input) { + Map> nodes = new LinkedHashMap<>(); + + CommandNode root = (CommandNode) (Object) this.root; + String firstInput = input.getFirst(); + + NodeResult firstNodeResult = getNodeResult(root, firstInput); + if (firstNodeResult == null) + return Map.of(); + + nodes.put(firstInput, firstNodeResult); + + if (root.getChildren().isEmpty()) + return input.size() > 1 ? Map.of() : nodes; + + for (String inputString : input.subList(1, input.size())) { + boolean found = false; + + for (CommandNode child : root.getChildren()) { + NodeResult nodeResult = getNodeResult(child, inputString); + if (nodeResult == null) + continue; + + found = true; + root = (CommandNode) child; + nodes.put(inputString, nodeResult); + break; + } + + if (!found) + return Map.of(); + } + + return nodes.size() < input.size() ? Map.of() : nodes; + } + + @SuppressWarnings("unchecked") + public static @Nullable NodeResult getNodeResult(@NotNull CommandNode node, @NotNull String input) { + CommandNode.ParseResult parseResult = node.parse(input); + if (!parseResult.success()) + return null; + + Object value = parseResult.value(); + if (!((CommandNode) node).isValidInput(value)) + return null; + + return new NodeResult<>((CommandNode) node, value); + } + + public record NodeResult(@NotNull CommandNode node, @Nullable T value) { + } } diff --git a/commands/src/main/java/com/wizardlybump17/wlib/command/rework/node/LiteralCommandNode.java b/commands/src/main/java/com/wizardlybump17/wlib/command/rework/node/LiteralCommandNode.java index 7e3f5a65..1c634198 100644 --- a/commands/src/main/java/com/wizardlybump17/wlib/command/rework/node/LiteralCommandNode.java +++ b/commands/src/main/java/com/wizardlybump17/wlib/command/rework/node/LiteralCommandNode.java @@ -19,7 +19,7 @@ public LiteralCommandNode(@NotNull String name, @NotNull List> ch @Override public @NotNull ParseResult parse(@NotNull String input) { - return ParseResult.emptySuccess(); + return ParseResult.success(input); } @Override diff --git a/commands/src/test/java/com/wizardlybump17/wlib/command/test/rework/ReworkTests.java b/commands/src/test/java/com/wizardlybump17/wlib/command/test/rework/ReworkTests.java index 785cf5ba..2ea0915a 100644 --- a/commands/src/test/java/com/wizardlybump17/wlib/command/test/rework/ReworkTests.java +++ b/commands/src/test/java/com/wizardlybump17/wlib/command/test/rework/ReworkTests.java @@ -1,4 +1,26 @@ package com.wizardlybump17.wlib.command.test.rework; +import com.wizardlybump17.wlib.command.rework.Command; +import com.wizardlybump17.wlib.command.rework.node.LiteralCommandNode; +import org.junit.jupiter.api.Assertions; +import org.junit.jupiter.api.Test; + +import java.util.List; +import java.util.Map; + class ReworkTests { + + @Test + void test() { + LiteralCommandNode world = new LiteralCommandNode("world", List.of()); + LiteralCommandNode hello = new LiteralCommandNode("hello", List.of(world)); + Command command = new Command(hello); + + Map> nodes = command.getNodes(List.of("hello")); + Assertions.assertEquals(Map.of( + "hello", new Command.NodeResult<>(hello, "hello"), + "world", new Command.NodeResult<>(world, "world") + ), nodes); + System.out.println(nodes); + } } From 92dd4854ba4b033e4fc9e5491a67c5785654fa99 Mon Sep 17 00:00:00 2001 From: WizardlyBump17 Date: Sat, 18 Oct 2025 16:39:22 -0300 Subject: [PATCH 012/363] hmm. seems to be working --- .../wlib/command/rework/Command.java | 29 +++- .../wlib/command/test/rework/ReworkTests.java | 131 +++++++++++++++++- 2 files changed, 150 insertions(+), 10 deletions(-) diff --git a/commands/src/main/java/com/wizardlybump17/wlib/command/rework/Command.java b/commands/src/main/java/com/wizardlybump17/wlib/command/rework/Command.java index 8c128256..247352dd 100644 --- a/commands/src/main/java/com/wizardlybump17/wlib/command/rework/Command.java +++ b/commands/src/main/java/com/wizardlybump17/wlib/command/rework/Command.java @@ -9,6 +9,7 @@ import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.Nullable; +import java.util.Iterator; import java.util.LinkedHashMap; import java.util.List; import java.util.Map; @@ -32,6 +33,9 @@ public Command(@NotNull LiteralCommandNode root) { @SuppressWarnings("unchecked") public @NotNull Map> getNodes(@NotNull List input) { + if (input.isEmpty()) + return Map.of(); + Map> nodes = new LinkedHashMap<>(); CommandNode root = (CommandNode) (Object) this.root; @@ -46,25 +50,36 @@ public Command(@NotNull LiteralCommandNode root) { if (root.getChildren().isEmpty()) return input.size() > 1 ? Map.of() : nodes; - for (String inputString : input.subList(1, input.size())) { - boolean found = false; + Iterator inputIterator = input.subList(1, input.size()).iterator(); + Iterator> childrenIterator = (Iterator>) (Object) root.getChildren().iterator(); + if (!inputIterator.hasNext() && childrenIterator.hasNext()) + return Map.of(); + + CommandNode last = null; + inputLoop: for (String inputString : input.subList(1, input.size())) { for (CommandNode child : root.getChildren()) { NodeResult nodeResult = getNodeResult(child, inputString); if (nodeResult == null) continue; - found = true; + last = child; root = (CommandNode) child; + nodes.put(inputString, nodeResult); - break; + continue inputLoop; } - if (!found) - return Map.of(); + return Map.of(); } - return nodes.size() < input.size() ? Map.of() : nodes; + if (last == null) + return Map.of(); + + if (!last.getChildren().isEmpty()) + return Map.of(); + + return nodes; } @SuppressWarnings("unchecked") diff --git a/commands/src/test/java/com/wizardlybump17/wlib/command/test/rework/ReworkTests.java b/commands/src/test/java/com/wizardlybump17/wlib/command/test/rework/ReworkTests.java index 2ea0915a..f5ba6409 100644 --- a/commands/src/test/java/com/wizardlybump17/wlib/command/test/rework/ReworkTests.java +++ b/commands/src/test/java/com/wizardlybump17/wlib/command/test/rework/ReworkTests.java @@ -11,16 +11,141 @@ class ReworkTests { @Test - void test() { + void testSuccess() { LiteralCommandNode world = new LiteralCommandNode("world", List.of()); LiteralCommandNode hello = new LiteralCommandNode("hello", List.of(world)); Command command = new Command(hello); - Map> nodes = command.getNodes(List.of("hello")); + Map> nodes = command.getNodes(List.of("hello", "world")); Assertions.assertEquals(Map.of( "hello", new Command.NodeResult<>(hello, "hello"), "world", new Command.NodeResult<>(world, "world") ), nodes); - System.out.println(nodes); + } + + @Test + void testUnsuccessExtra1() { + Command command = new Command( + new LiteralCommandNode("hello", List.of( + new LiteralCommandNode("world", List.of()) + )) + ); + + Map> nodes = command.getNodes(List.of("hello", "world", "a")); + Assertions.assertEquals(Map.of(), nodes); + } + + @Test + void testUnsuccessExtra2() { + Command command = new Command( + new LiteralCommandNode("hello", List.of( + new LiteralCommandNode("world", List.of()) + )) + ); + + Map> nodes = command.getNodes(List.of("hello", "world", "a", "b")); + Assertions.assertEquals(Map.of(), nodes); + } + + @Test + void testUnsuccessExtra3() { + Command command = new Command( + new LiteralCommandNode("hello", List.of( + new LiteralCommandNode("world", List.of()) + )) + ); + + Map> nodes = command.getNodes(List.of("hello", "world", "a", "b", "c")); + Assertions.assertEquals(Map.of(), nodes); + } + + @Test + void testUnsuccessLess1() { + Command command = new Command( + new LiteralCommandNode("hello", List.of( + new LiteralCommandNode("world", List.of( + new LiteralCommandNode("a", List.of( + new LiteralCommandNode("b", List.of( + new LiteralCommandNode("c", List.of()) + )) + )) + )) + )) + ); + + Map> nodes = command.getNodes(List.of("hello", "world", "a", "b")); + Assertions.assertEquals(Map.of(), nodes); + } + + @Test + void testUnsuccessLess2() { + Command command = new Command( + new LiteralCommandNode("hello", List.of( + new LiteralCommandNode("world", List.of( + new LiteralCommandNode("a", List.of( + new LiteralCommandNode("b", List.of( + new LiteralCommandNode("c", List.of()) + )) + )) + )) + )) + ); + + Map> nodes = command.getNodes(List.of("hello", "world", "a")); + Assertions.assertEquals(Map.of(), nodes); + } + + @Test + void testUnsuccessLess3() { + Command command = new Command( + new LiteralCommandNode("hello", List.of( + new LiteralCommandNode("world", List.of( + new LiteralCommandNode("a", List.of( + new LiteralCommandNode("b", List.of( + new LiteralCommandNode("c", List.of()) + )) + )) + )) + )) + ); + + Map> nodes = command.getNodes(List.of("hello", "world")); + Assertions.assertEquals(Map.of(), nodes); + } + + @Test + void testUnsuccessLess4() { + Command command = new Command( + new LiteralCommandNode("hello", List.of( + new LiteralCommandNode("world", List.of( + new LiteralCommandNode("a", List.of( + new LiteralCommandNode("b", List.of( + new LiteralCommandNode("c", List.of()) + )) + )) + )) + )) + ); + + Map> nodes = command.getNodes(List.of("hello")); + Assertions.assertEquals(Map.of(), nodes); + } + + @Test + void testUnsuccessLess5() { + Command command = new Command( + new LiteralCommandNode("hello", List.of( + new LiteralCommandNode("world", List.of( + new LiteralCommandNode("a", List.of( + new LiteralCommandNode("b", List.of( + new LiteralCommandNode("c", List.of()) + )) + )) + )) + )) + ); + + Map> nodes = command.getNodes(List.of()); + Assertions.assertEquals(Map.of(), nodes); } } From f100a10ebdba916351aa48525f6b4db88410c5fc Mon Sep 17 00:00:00 2001 From: WizardlyBump17 Date: Sat, 18 Oct 2025 17:07:49 -0300 Subject: [PATCH 013/363] simplified the code a little bit --- .../wlib/command/rework/Command.java | 31 +++---------------- 1 file changed, 5 insertions(+), 26 deletions(-) diff --git a/commands/src/main/java/com/wizardlybump17/wlib/command/rework/Command.java b/commands/src/main/java/com/wizardlybump17/wlib/command/rework/Command.java index 247352dd..86c36ad3 100644 --- a/commands/src/main/java/com/wizardlybump17/wlib/command/rework/Command.java +++ b/commands/src/main/java/com/wizardlybump17/wlib/command/rework/Command.java @@ -9,7 +9,6 @@ import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.Nullable; -import java.util.Iterator; import java.util.LinkedHashMap; import java.util.List; import java.util.Map; @@ -31,40 +30,23 @@ public Command(@NotNull LiteralCommandNode root) { return SuccessResult.INSTANCE; } - @SuppressWarnings("unchecked") public @NotNull Map> getNodes(@NotNull List input) { if (input.isEmpty()) return Map.of(); Map> nodes = new LinkedHashMap<>(); - CommandNode root = (CommandNode) (Object) this.root; - String firstInput = input.getFirst(); - - NodeResult firstNodeResult = getNodeResult(root, firstInput); - if (firstNodeResult == null) - return Map.of(); - - nodes.put(firstInput, firstNodeResult); - - if (root.getChildren().isEmpty()) - return input.size() > 1 ? Map.of() : nodes; - - Iterator inputIterator = input.subList(1, input.size()).iterator(); - Iterator> childrenIterator = (Iterator>) (Object) root.getChildren().iterator(); - - if (!inputIterator.hasNext() && childrenIterator.hasNext()) - return Map.of(); + List> children = List.of(root); CommandNode last = null; - inputLoop: for (String inputString : input.subList(1, input.size())) { - for (CommandNode child : root.getChildren()) { - NodeResult nodeResult = getNodeResult(child, inputString); + inputLoop: for (String inputString : input) { + for (CommandNode child : children) { + NodeResult nodeResult = getNodeResult(child, inputString); if (nodeResult == null) continue; last = child; - root = (CommandNode) child; + children = child.getChildren(); nodes.put(inputString, nodeResult); continue inputLoop; @@ -73,9 +55,6 @@ public Command(@NotNull LiteralCommandNode root) { return Map.of(); } - if (last == null) - return Map.of(); - if (!last.getChildren().isEmpty()) return Map.of(); From 2ea3dd5d2f67877f259075474f7fc902f27b69a5 Mon Sep 17 00:00:00 2001 From: WizardlyBump17 Date: Sat, 18 Oct 2025 17:12:13 -0300 Subject: [PATCH 014/363] renamed the class --- .../test/rework/{ReworkTests.java => NodeResultTests.java} | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) rename commands/src/test/java/com/wizardlybump17/wlib/command/test/rework/{ReworkTests.java => NodeResultTests.java} (99%) diff --git a/commands/src/test/java/com/wizardlybump17/wlib/command/test/rework/ReworkTests.java b/commands/src/test/java/com/wizardlybump17/wlib/command/test/rework/NodeResultTests.java similarity index 99% rename from commands/src/test/java/com/wizardlybump17/wlib/command/test/rework/ReworkTests.java rename to commands/src/test/java/com/wizardlybump17/wlib/command/test/rework/NodeResultTests.java index f5ba6409..19b8268c 100644 --- a/commands/src/test/java/com/wizardlybump17/wlib/command/test/rework/ReworkTests.java +++ b/commands/src/test/java/com/wizardlybump17/wlib/command/test/rework/NodeResultTests.java @@ -8,7 +8,7 @@ import java.util.List; import java.util.Map; -class ReworkTests { +class NodeResultTests { @Test void testSuccess() { From b037e2a178a5fd0997e25da383c86547b084a3e6 Mon Sep 17 00:00:00 2001 From: WizardlyBump17 Date: Sat, 18 Oct 2025 17:14:05 -0300 Subject: [PATCH 015/363] starting the execution --- .../wizardlybump17/wlib/command/rework/Command.java | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git a/commands/src/main/java/com/wizardlybump17/wlib/command/rework/Command.java b/commands/src/main/java/com/wizardlybump17/wlib/command/rework/Command.java index 86c36ad3..e8bc638f 100644 --- a/commands/src/main/java/com/wizardlybump17/wlib/command/rework/Command.java +++ b/commands/src/main/java/com/wizardlybump17/wlib/command/rework/Command.java @@ -26,10 +26,19 @@ public Command(@NotNull LiteralCommandNode root) { } public @NotNull CommandResult execute(@NotNull CommandSender sender, @NotNull String execution) { - List strings = StringUtil.parseQuotedStrings(execution); + List strings = getInputList(execution); + Map> results = getNodes(strings); + + if (results.isEmpty()) + return CommandResult.error(); + return SuccessResult.INSTANCE; } + public @NotNull List getInputList(@NotNull String original) { + return StringUtil.parseQuotedStrings(original); + } + public @NotNull Map> getNodes(@NotNull List input) { if (input.isEmpty()) return Map.of(); From 49c647c83cf6c84291147a3b7c162e6b65be0097 Mon Sep 17 00:00:00 2001 From: WizardlyBump17 Date: Sat, 18 Oct 2025 18:39:12 -0300 Subject: [PATCH 016/363] creating a simple ass command --- .../wlib/command/rework/Command.java | 47 +++++++++++++++++-- .../wlib/command/rework/node/CommandNode.java | 24 ++++++++++ .../command/test/rework/CommandTests.java | 43 +++++++++++++++++ 3 files changed, 111 insertions(+), 3 deletions(-) create mode 100644 commands/src/test/java/com/wizardlybump17/wlib/command/test/rework/CommandTests.java diff --git a/commands/src/main/java/com/wizardlybump17/wlib/command/rework/Command.java b/commands/src/main/java/com/wizardlybump17/wlib/command/rework/Command.java index e8bc638f..bc394f63 100644 --- a/commands/src/main/java/com/wizardlybump17/wlib/command/rework/Command.java +++ b/commands/src/main/java/com/wizardlybump17/wlib/command/rework/Command.java @@ -9,9 +9,7 @@ import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.Nullable; -import java.util.LinkedHashMap; -import java.util.List; -import java.util.Map; +import java.util.*; public class Command { @@ -85,4 +83,47 @@ public Command(@NotNull LiteralCommandNode root) { public record NodeResult(@NotNull CommandNode node, @Nullable T value) { } + + public static @Nullable Command createCommand(@NotNull String execution) { + LiteralCommandNode firstNode = null; + LiteralCommandNode lastNode = null; + List> children = new ArrayList<>(); + for (String string : execution.split(" ")) { + if (firstNode == null) { + firstNode = new LiteralCommandNode(string, children); + lastNode = firstNode; + continue; + } + + List> newChildren = new ArrayList<>(); + LiteralCommandNode newNode = new LiteralCommandNode(string, newChildren); + children.add(newNode); + newNode.setParent(lastNode); + + children = newChildren; + lastNode = newNode; + } + + return firstNode == null ? null : new Command(firstNode); + } + + @Override + public String toString() { + return "Command{" + + "root=" + root + + '}'; + } + + @Override + public boolean equals(Object o) { + if (o == null || getClass() != o.getClass()) + return false; + Command command = (Command) o; + return Objects.equals(root, command.root); + } + + @Override + public int hashCode() { + return Objects.hashCode(root); + } } diff --git a/commands/src/main/java/com/wizardlybump17/wlib/command/rework/node/CommandNode.java b/commands/src/main/java/com/wizardlybump17/wlib/command/rework/node/CommandNode.java index 3133472d..2b4381d2 100644 --- a/commands/src/main/java/com/wizardlybump17/wlib/command/rework/node/CommandNode.java +++ b/commands/src/main/java/com/wizardlybump17/wlib/command/rework/node/CommandNode.java @@ -8,6 +8,7 @@ import java.util.Collections; import java.util.List; +import java.util.Objects; public abstract class CommandNode { @@ -73,4 +74,27 @@ public record ParseResult(boolean success, @Nullable T value) { return new ParseResult<>(false, null); } } + + @Override + public String toString() { + return "CommandNode{" + + "name='" + name + '\'' + + ", children=" + children + + ", allowedInputs=" + allowedInputs + + ", parent=" + parent.name + + '}'; + } + + @Override + public boolean equals(Object o) { + if (o == null || getClass() != o.getClass()) + return false; + CommandNode that = (CommandNode) o; + return Objects.equals(name, that.name) && Objects.equals(children, that.children) && Objects.equals(allowedInputs, that.allowedInputs) && Objects.equals(parent.name, that.parent.name); + } + + @Override + public int hashCode() { + return Objects.hash(name, children, allowedInputs, parent.name); + } } diff --git a/commands/src/test/java/com/wizardlybump17/wlib/command/test/rework/CommandTests.java b/commands/src/test/java/com/wizardlybump17/wlib/command/test/rework/CommandTests.java new file mode 100644 index 00000000..ab17233b --- /dev/null +++ b/commands/src/test/java/com/wizardlybump17/wlib/command/test/rework/CommandTests.java @@ -0,0 +1,43 @@ +package com.wizardlybump17.wlib.command.test.rework; + +import com.wizardlybump17.wlib.command.rework.Command; +import com.wizardlybump17.wlib.command.rework.node.LiteralCommandNode; +import org.junit.jupiter.api.Assertions; +import org.junit.jupiter.api.Test; + +import java.util.List; + +class CommandTests { + + @Test + void testCreate() { + Command expected = new Command( + new LiteralCommandNode("hello", List.of( + new LiteralCommandNode("world", List.of()) + )) + ); + Command created = Command.createCommand("hello world"); + + Assertions.assertEquals(expected, created); + } + + @Test + void testCreate1() { + Command expected = new Command( + new LiteralCommandNode("hello", List.of( + new LiteralCommandNode("world", List.of( + new LiteralCommandNode("hello1", List.of( + new LiteralCommandNode("world1", List.of( + new LiteralCommandNode("hello2", List.of( + new LiteralCommandNode("world2", List.of()) + )) + )) + )) + )) + )) + ); + Command created = Command.createCommand("hello world hello1 world1 hello2 world2"); + + Assertions.assertEquals(expected, created); + } +} From a697fcebd613f86b6c4a30beb04c4dc4a5a10017 Mon Sep 17 00:00:00 2001 From: WizardlyBump17 Date: Sat, 18 Oct 2025 19:00:26 -0300 Subject: [PATCH 017/363] moved to a better place --- .../wlib/command/rework/{node => }/input/AllowedInputs.java | 2 +- .../command/rework/{node => }/input/AllowedNumberInputs.java | 2 +- .../command/rework/{node => }/input/LiteralAllowedInput.java | 2 +- .../command/rework/{node => }/input/RangedAllowedInputs.java | 2 +- .../wizardlybump17/wlib/command/rework/node/CommandNode.java | 2 +- .../wlib/command/rework/node/IntegerCommandNode.java | 4 ++-- .../wlib/command/rework/node/LiteralCommandNode.java | 2 +- 7 files changed, 8 insertions(+), 8 deletions(-) rename commands/src/main/java/com/wizardlybump17/wlib/command/rework/{node => }/input/AllowedInputs.java (68%) rename commands/src/main/java/com/wizardlybump17/wlib/command/rework/{node => }/input/AllowedNumberInputs.java (92%) rename commands/src/main/java/com/wizardlybump17/wlib/command/rework/{node => }/input/LiteralAllowedInput.java (88%) rename commands/src/main/java/com/wizardlybump17/wlib/command/rework/{node => }/input/RangedAllowedInputs.java (77%) diff --git a/commands/src/main/java/com/wizardlybump17/wlib/command/rework/node/input/AllowedInputs.java b/commands/src/main/java/com/wizardlybump17/wlib/command/rework/input/AllowedInputs.java similarity index 68% rename from commands/src/main/java/com/wizardlybump17/wlib/command/rework/node/input/AllowedInputs.java rename to commands/src/main/java/com/wizardlybump17/wlib/command/rework/input/AllowedInputs.java index 47207fb5..5f4f3ec2 100644 --- a/commands/src/main/java/com/wizardlybump17/wlib/command/rework/node/input/AllowedInputs.java +++ b/commands/src/main/java/com/wizardlybump17/wlib/command/rework/input/AllowedInputs.java @@ -1,4 +1,4 @@ -package com.wizardlybump17.wlib.command.rework.node.input; +package com.wizardlybump17.wlib.command.rework.input; import org.jetbrains.annotations.Nullable; diff --git a/commands/src/main/java/com/wizardlybump17/wlib/command/rework/node/input/AllowedNumberInputs.java b/commands/src/main/java/com/wizardlybump17/wlib/command/rework/input/AllowedNumberInputs.java similarity index 92% rename from commands/src/main/java/com/wizardlybump17/wlib/command/rework/node/input/AllowedNumberInputs.java rename to commands/src/main/java/com/wizardlybump17/wlib/command/rework/input/AllowedNumberInputs.java index cc2e40b4..b73e23a1 100644 --- a/commands/src/main/java/com/wizardlybump17/wlib/command/rework/node/input/AllowedNumberInputs.java +++ b/commands/src/main/java/com/wizardlybump17/wlib/command/rework/input/AllowedNumberInputs.java @@ -1,4 +1,4 @@ -package com.wizardlybump17.wlib.command.rework.node.input; +package com.wizardlybump17.wlib.command.rework.input; import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.Nullable; diff --git a/commands/src/main/java/com/wizardlybump17/wlib/command/rework/node/input/LiteralAllowedInput.java b/commands/src/main/java/com/wizardlybump17/wlib/command/rework/input/LiteralAllowedInput.java similarity index 88% rename from commands/src/main/java/com/wizardlybump17/wlib/command/rework/node/input/LiteralAllowedInput.java rename to commands/src/main/java/com/wizardlybump17/wlib/command/rework/input/LiteralAllowedInput.java index 7e7c5098..725599c1 100644 --- a/commands/src/main/java/com/wizardlybump17/wlib/command/rework/node/input/LiteralAllowedInput.java +++ b/commands/src/main/java/com/wizardlybump17/wlib/command/rework/input/LiteralAllowedInput.java @@ -1,4 +1,4 @@ -package com.wizardlybump17.wlib.command.rework.node.input; +package com.wizardlybump17.wlib.command.rework.input; import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.Nullable; diff --git a/commands/src/main/java/com/wizardlybump17/wlib/command/rework/node/input/RangedAllowedInputs.java b/commands/src/main/java/com/wizardlybump17/wlib/command/rework/input/RangedAllowedInputs.java similarity index 77% rename from commands/src/main/java/com/wizardlybump17/wlib/command/rework/node/input/RangedAllowedInputs.java rename to commands/src/main/java/com/wizardlybump17/wlib/command/rework/input/RangedAllowedInputs.java index b44ac63a..35ef7af1 100644 --- a/commands/src/main/java/com/wizardlybump17/wlib/command/rework/node/input/RangedAllowedInputs.java +++ b/commands/src/main/java/com/wizardlybump17/wlib/command/rework/input/RangedAllowedInputs.java @@ -1,4 +1,4 @@ -package com.wizardlybump17.wlib.command.rework.node.input; +package com.wizardlybump17.wlib.command.rework.input; import org.jetbrains.annotations.NotNull; diff --git a/commands/src/main/java/com/wizardlybump17/wlib/command/rework/node/CommandNode.java b/commands/src/main/java/com/wizardlybump17/wlib/command/rework/node/CommandNode.java index 2b4381d2..655ade19 100644 --- a/commands/src/main/java/com/wizardlybump17/wlib/command/rework/node/CommandNode.java +++ b/commands/src/main/java/com/wizardlybump17/wlib/command/rework/node/CommandNode.java @@ -1,6 +1,6 @@ package com.wizardlybump17.wlib.command.rework.node; -import com.wizardlybump17.wlib.command.rework.node.input.AllowedInputs; +import com.wizardlybump17.wlib.command.rework.input.AllowedInputs; import com.wizardlybump17.wlib.command.sender.CommandSender; import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.Nullable; diff --git a/commands/src/main/java/com/wizardlybump17/wlib/command/rework/node/IntegerCommandNode.java b/commands/src/main/java/com/wizardlybump17/wlib/command/rework/node/IntegerCommandNode.java index baeddca0..f718a80f 100644 --- a/commands/src/main/java/com/wizardlybump17/wlib/command/rework/node/IntegerCommandNode.java +++ b/commands/src/main/java/com/wizardlybump17/wlib/command/rework/node/IntegerCommandNode.java @@ -1,7 +1,7 @@ package com.wizardlybump17.wlib.command.rework.node; -import com.wizardlybump17.wlib.command.rework.node.input.AllowedNumberInputs; -import com.wizardlybump17.wlib.command.rework.node.input.RangedAllowedInputs; +import com.wizardlybump17.wlib.command.rework.input.AllowedNumberInputs; +import com.wizardlybump17.wlib.command.rework.input.RangedAllowedInputs; import com.wizardlybump17.wlib.command.sender.CommandSender; import org.jetbrains.annotations.NotNull; diff --git a/commands/src/main/java/com/wizardlybump17/wlib/command/rework/node/LiteralCommandNode.java b/commands/src/main/java/com/wizardlybump17/wlib/command/rework/node/LiteralCommandNode.java index 1c634198..5fb33928 100644 --- a/commands/src/main/java/com/wizardlybump17/wlib/command/rework/node/LiteralCommandNode.java +++ b/commands/src/main/java/com/wizardlybump17/wlib/command/rework/node/LiteralCommandNode.java @@ -1,6 +1,6 @@ package com.wizardlybump17.wlib.command.rework.node; -import com.wizardlybump17.wlib.command.rework.node.input.LiteralAllowedInput; +import com.wizardlybump17.wlib.command.rework.input.LiteralAllowedInput; import com.wizardlybump17.wlib.command.sender.CommandSender; import org.jetbrains.annotations.NotNull; From 9f6693ec261d5519aab7d86009c61b0564b80701 Mon Sep 17 00:00:00 2001 From: WizardlyBump17 Date: Sat, 18 Oct 2025 19:24:20 -0300 Subject: [PATCH 018/363] starting the CommandExecutor system and removed the parent system --- .../wlib/command/rework/Command.java | 23 +++++++---- .../rework/context/CommandContext.java | 8 ++++ .../rework/executor/CommandExecutor.java | 15 ++++++++ .../wlib/command/rework/node/CommandNode.java | 38 +++++++++---------- .../rework/node/IntegerCommandNode.java | 6 ++- .../rework/node/LiteralCommandNode.java | 6 +++ .../command/test/rework/CommandTests.java | 5 ++- 7 files changed, 69 insertions(+), 32 deletions(-) create mode 100644 commands/src/main/java/com/wizardlybump17/wlib/command/rework/context/CommandContext.java create mode 100644 commands/src/main/java/com/wizardlybump17/wlib/command/rework/executor/CommandExecutor.java diff --git a/commands/src/main/java/com/wizardlybump17/wlib/command/rework/Command.java b/commands/src/main/java/com/wizardlybump17/wlib/command/rework/Command.java index bc394f63..74765768 100644 --- a/commands/src/main/java/com/wizardlybump17/wlib/command/rework/Command.java +++ b/commands/src/main/java/com/wizardlybump17/wlib/command/rework/Command.java @@ -1,5 +1,6 @@ package com.wizardlybump17.wlib.command.rework; +import com.wizardlybump17.wlib.command.rework.executor.CommandExecutor; import com.wizardlybump17.wlib.command.rework.node.CommandNode; import com.wizardlybump17.wlib.command.rework.node.LiteralCommandNode; import com.wizardlybump17.wlib.command.rework.result.CommandResult; @@ -86,22 +87,28 @@ public record NodeResult(@NotNull CommandNode node, @Nullable T value) { public static @Nullable Command createCommand(@NotNull String execution) { LiteralCommandNode firstNode = null; - LiteralCommandNode lastNode = null; + List> children = new ArrayList<>(); - for (String string : execution.split(" ")) { - if (firstNode == null) { - firstNode = new LiteralCommandNode(string, children); - lastNode = firstNode; + String[] strings = execution.split(" "); + + for (int i = 0; i < strings.length; i++) { + String string = strings[i]; + if (i == 0) { + firstNode = new LiteralCommandNode(string, children, null); continue; } + CommandExecutor executor; + if (i + 1 >= strings.length) + executor = CommandExecutor.TEST_EXECUTOR; + else + executor = null; + List> newChildren = new ArrayList<>(); - LiteralCommandNode newNode = new LiteralCommandNode(string, newChildren); + LiteralCommandNode newNode = new LiteralCommandNode(string, newChildren, executor); children.add(newNode); - newNode.setParent(lastNode); children = newChildren; - lastNode = newNode; } return firstNode == null ? null : new Command(firstNode); diff --git a/commands/src/main/java/com/wizardlybump17/wlib/command/rework/context/CommandContext.java b/commands/src/main/java/com/wizardlybump17/wlib/command/rework/context/CommandContext.java new file mode 100644 index 00000000..43beb1ef --- /dev/null +++ b/commands/src/main/java/com/wizardlybump17/wlib/command/rework/context/CommandContext.java @@ -0,0 +1,8 @@ +package com.wizardlybump17.wlib.command.rework.context; + +import com.wizardlybump17.wlib.command.rework.Command; +import com.wizardlybump17.wlib.command.sender.CommandSender; +import org.jetbrains.annotations.NotNull; + +public record CommandContext(@NotNull Command command, @NotNull CommandSender sender) { +} diff --git a/commands/src/main/java/com/wizardlybump17/wlib/command/rework/executor/CommandExecutor.java b/commands/src/main/java/com/wizardlybump17/wlib/command/rework/executor/CommandExecutor.java new file mode 100644 index 00000000..8ba39431 --- /dev/null +++ b/commands/src/main/java/com/wizardlybump17/wlib/command/rework/executor/CommandExecutor.java @@ -0,0 +1,15 @@ +package com.wizardlybump17.wlib.command.rework.executor; + +import com.wizardlybump17.wlib.command.rework.context.CommandContext; +import com.wizardlybump17.wlib.command.rework.result.CommandResult; +import org.jetbrains.annotations.NotNull; + +public interface CommandExecutor { + + @NotNull CommandExecutor TEST_EXECUTOR = context -> { + System.out.println(context); + return CommandResult.successful(); + }; + + @NotNull CommandResult execute(@NotNull CommandContext context); +} diff --git a/commands/src/main/java/com/wizardlybump17/wlib/command/rework/node/CommandNode.java b/commands/src/main/java/com/wizardlybump17/wlib/command/rework/node/CommandNode.java index 655ade19..54212a69 100644 --- a/commands/src/main/java/com/wizardlybump17/wlib/command/rework/node/CommandNode.java +++ b/commands/src/main/java/com/wizardlybump17/wlib/command/rework/node/CommandNode.java @@ -1,5 +1,6 @@ package com.wizardlybump17.wlib.command.rework.node; +import com.wizardlybump17.wlib.command.rework.executor.CommandExecutor; import com.wizardlybump17.wlib.command.rework.input.AllowedInputs; import com.wizardlybump17.wlib.command.sender.CommandSender; import org.jetbrains.annotations.NotNull; @@ -15,15 +16,17 @@ public abstract class CommandNode { private final @NotNull String name; private final @NotNull @Unmodifiable List> children; private final @NotNull AllowedInputs allowedInputs; - private @NotNull CommandNode parent = this; + private final @Nullable CommandExecutor executor; - public CommandNode(@NotNull String name, @NotNull List> children, @NotNull AllowedInputs allowedInputs) { + public CommandNode(@NotNull String name, @NotNull List> children, @NotNull AllowedInputs allowedInputs, @Nullable CommandExecutor executor) { this.name = name; - - children.forEach(child -> child.setParent(this)); this.children = Collections.unmodifiableList(children); - this.allowedInputs = allowedInputs; + this.executor = executor; + } + + public CommandNode(@NotNull String name, @NotNull List> children, @NotNull AllowedInputs allowedInputs) { + this(name, children, allowedInputs, null); } public @NotNull String getName() { @@ -48,18 +51,6 @@ public final boolean isValidInput(@Nullable T input) { return List.of(); } - public @NotNull CommandNode getParent() { - return parent; - } - - public void setParent(@NotNull CommandNode parent) { - this.parent = parent; - } - - public boolean hasParent() { - return parent != this; - } - public record ParseResult(boolean success, @Nullable T value) { public static @NotNull ParseResult success(@Nullable T value) { @@ -75,13 +66,17 @@ public record ParseResult(boolean success, @Nullable T value) { } } + public @Nullable CommandExecutor getExecutor() { + return executor; + } + @Override public String toString() { return "CommandNode{" + "name='" + name + '\'' + ", children=" + children + ", allowedInputs=" + allowedInputs + - ", parent=" + parent.name + + ", executor=" + executor + '}'; } @@ -90,11 +85,14 @@ public boolean equals(Object o) { if (o == null || getClass() != o.getClass()) return false; CommandNode that = (CommandNode) o; - return Objects.equals(name, that.name) && Objects.equals(children, that.children) && Objects.equals(allowedInputs, that.allowedInputs) && Objects.equals(parent.name, that.parent.name); + return Objects.equals(name, that.name) + && Objects.equals(children, that.children) + && Objects.equals(allowedInputs, that.allowedInputs) + && Objects.equals(executor, that.executor); } @Override public int hashCode() { - return Objects.hash(name, children, allowedInputs, parent.name); + return Objects.hash(name, children, allowedInputs, executor); } } diff --git a/commands/src/main/java/com/wizardlybump17/wlib/command/rework/node/IntegerCommandNode.java b/commands/src/main/java/com/wizardlybump17/wlib/command/rework/node/IntegerCommandNode.java index f718a80f..514ecfa0 100644 --- a/commands/src/main/java/com/wizardlybump17/wlib/command/rework/node/IntegerCommandNode.java +++ b/commands/src/main/java/com/wizardlybump17/wlib/command/rework/node/IntegerCommandNode.java @@ -1,17 +1,19 @@ package com.wizardlybump17.wlib.command.rework.node; +import com.wizardlybump17.wlib.command.rework.executor.CommandExecutor; import com.wizardlybump17.wlib.command.rework.input.AllowedNumberInputs; import com.wizardlybump17.wlib.command.rework.input.RangedAllowedInputs; import com.wizardlybump17.wlib.command.sender.CommandSender; import org.jetbrains.annotations.NotNull; +import org.jetbrains.annotations.Nullable; import java.util.List; import java.util.stream.IntStream; public class IntegerCommandNode extends CommandNode { - public IntegerCommandNode(@NotNull String name, @NotNull List> children, @NotNull AllowedNumberInputs.AllowedIntegerInputs allowedInputs) { - super(name, children, allowedInputs); + public IntegerCommandNode(@NotNull String name, @NotNull List> children, @NotNull AllowedNumberInputs.AllowedIntegerInputs allowedInputs, @Nullable CommandExecutor executor) { + super(name, children, allowedInputs, executor); } @Override diff --git a/commands/src/main/java/com/wizardlybump17/wlib/command/rework/node/LiteralCommandNode.java b/commands/src/main/java/com/wizardlybump17/wlib/command/rework/node/LiteralCommandNode.java index 5fb33928..9304b091 100644 --- a/commands/src/main/java/com/wizardlybump17/wlib/command/rework/node/LiteralCommandNode.java +++ b/commands/src/main/java/com/wizardlybump17/wlib/command/rework/node/LiteralCommandNode.java @@ -1,13 +1,19 @@ package com.wizardlybump17.wlib.command.rework.node; +import com.wizardlybump17.wlib.command.rework.executor.CommandExecutor; import com.wizardlybump17.wlib.command.rework.input.LiteralAllowedInput; import com.wizardlybump17.wlib.command.sender.CommandSender; import org.jetbrains.annotations.NotNull; +import org.jetbrains.annotations.Nullable; import java.util.List; public class LiteralCommandNode extends CommandNode { + public LiteralCommandNode(@NotNull String name, @NotNull List> children, @Nullable CommandExecutor executor) { + super(name, children, new LiteralAllowedInput(name, false), executor); + } + public LiteralCommandNode(@NotNull String name, @NotNull List> children) { super(name, children, new LiteralAllowedInput(name, false)); } diff --git a/commands/src/test/java/com/wizardlybump17/wlib/command/test/rework/CommandTests.java b/commands/src/test/java/com/wizardlybump17/wlib/command/test/rework/CommandTests.java index ab17233b..b7ee6b4b 100644 --- a/commands/src/test/java/com/wizardlybump17/wlib/command/test/rework/CommandTests.java +++ b/commands/src/test/java/com/wizardlybump17/wlib/command/test/rework/CommandTests.java @@ -1,6 +1,7 @@ package com.wizardlybump17.wlib.command.test.rework; import com.wizardlybump17.wlib.command.rework.Command; +import com.wizardlybump17.wlib.command.rework.executor.CommandExecutor; import com.wizardlybump17.wlib.command.rework.node.LiteralCommandNode; import org.junit.jupiter.api.Assertions; import org.junit.jupiter.api.Test; @@ -13,7 +14,7 @@ class CommandTests { void testCreate() { Command expected = new Command( new LiteralCommandNode("hello", List.of( - new LiteralCommandNode("world", List.of()) + new LiteralCommandNode("world", List.of(), CommandExecutor.TEST_EXECUTOR) )) ); Command created = Command.createCommand("hello world"); @@ -29,7 +30,7 @@ void testCreate1() { new LiteralCommandNode("hello1", List.of( new LiteralCommandNode("world1", List.of( new LiteralCommandNode("hello2", List.of( - new LiteralCommandNode("world2", List.of()) + new LiteralCommandNode("world2", List.of(), CommandExecutor.TEST_EXECUTOR) )) )) )) From 4072eae3613ed0d83c11893224d0871db29bc679 Mon Sep 17 00:00:00 2001 From: WizardlyBump17 Date: Sat, 18 Oct 2025 22:19:57 -0300 Subject: [PATCH 019/363] CommandContext improvements --- .../wlib/command/rework/Command.java | 30 ++++++------- .../rework/context/CommandContext.java | 33 +++++++++++++- .../command/test/rework/NodeResultTests.java | 44 ++++++++++--------- 3 files changed, 69 insertions(+), 38 deletions(-) diff --git a/commands/src/main/java/com/wizardlybump17/wlib/command/rework/Command.java b/commands/src/main/java/com/wizardlybump17/wlib/command/rework/Command.java index 74765768..8bbca3a1 100644 --- a/commands/src/main/java/com/wizardlybump17/wlib/command/rework/Command.java +++ b/commands/src/main/java/com/wizardlybump17/wlib/command/rework/Command.java @@ -1,5 +1,6 @@ package com.wizardlybump17.wlib.command.rework; +import com.wizardlybump17.wlib.command.rework.context.CommandContext; import com.wizardlybump17.wlib.command.rework.executor.CommandExecutor; import com.wizardlybump17.wlib.command.rework.node.CommandNode; import com.wizardlybump17.wlib.command.rework.node.LiteralCommandNode; @@ -26,9 +27,9 @@ public Command(@NotNull LiteralCommandNode root) { public @NotNull CommandResult execute(@NotNull CommandSender sender, @NotNull String execution) { List strings = getInputList(execution); - Map> results = getNodes(strings); + CommandContext.CommandNodeArguments arguments = getArguments(strings); - if (results.isEmpty()) + if (arguments == null) return CommandResult.error(); return SuccessResult.INSTANCE; @@ -38,39 +39,39 @@ public Command(@NotNull LiteralCommandNode root) { return StringUtil.parseQuotedStrings(original); } - public @NotNull Map> getNodes(@NotNull List input) { + public @Nullable CommandContext.CommandNodeArguments getArguments(@NotNull List input) { if (input.isEmpty()) - return Map.of(); + return null; - Map> nodes = new LinkedHashMap<>(); + Map> arguments = new LinkedHashMap<>(); List> children = List.of(root); CommandNode last = null; inputLoop: for (String inputString : input) { for (CommandNode child : children) { - NodeResult nodeResult = getNodeResult(child, inputString); - if (nodeResult == null) + CommandContext.CommandNodeArgument argument = getNodeResult(child, inputString); + if (argument == null) continue; last = child; children = child.getChildren(); - nodes.put(inputString, nodeResult); + arguments.put(inputString, argument); continue inputLoop; } - return Map.of(); + return null; } if (!last.getChildren().isEmpty()) - return Map.of(); + return null; - return nodes; + return new CommandContext.CommandNodeArguments(arguments); } @SuppressWarnings("unchecked") - public static @Nullable NodeResult getNodeResult(@NotNull CommandNode node, @NotNull String input) { + public static @Nullable CommandContext.CommandNodeArgument getNodeResult(@NotNull CommandNode node, @NotNull String input) { CommandNode.ParseResult parseResult = node.parse(input); if (!parseResult.success()) return null; @@ -79,10 +80,7 @@ public Command(@NotNull LiteralCommandNode root) { if (!((CommandNode) node).isValidInput(value)) return null; - return new NodeResult<>((CommandNode) node, value); - } - - public record NodeResult(@NotNull CommandNode node, @Nullable T value) { + return new CommandContext.CommandNodeArgument<>((CommandNode) node, input, value); } public static @Nullable Command createCommand(@NotNull String execution) { diff --git a/commands/src/main/java/com/wizardlybump17/wlib/command/rework/context/CommandContext.java b/commands/src/main/java/com/wizardlybump17/wlib/command/rework/context/CommandContext.java index 43beb1ef..ed5887db 100644 --- a/commands/src/main/java/com/wizardlybump17/wlib/command/rework/context/CommandContext.java +++ b/commands/src/main/java/com/wizardlybump17/wlib/command/rework/context/CommandContext.java @@ -1,8 +1,39 @@ package com.wizardlybump17.wlib.command.rework.context; import com.wizardlybump17.wlib.command.rework.Command; +import com.wizardlybump17.wlib.command.rework.node.CommandNode; import com.wizardlybump17.wlib.command.sender.CommandSender; import org.jetbrains.annotations.NotNull; +import org.jetbrains.annotations.Nullable; -public record CommandContext(@NotNull Command command, @NotNull CommandSender sender) { +import java.util.*; + +public record CommandContext(@NotNull Command command, @NotNull CommandSender sender, @NotNull CommandNodeArguments arguments) { + + public record CommandNodeArgument(@NotNull CommandNode node, @NotNull String input, @Nullable T value) { + } + + public record CommandNodeArguments(@NotNull Map> arguments) { + + public CommandNodeArguments { + arguments = Collections.unmodifiableMap(arguments); + } + + @SuppressWarnings("unchecked") + public CommandNodeArguments(@NotNull List> arguments) { + this(Map.ofEntries(arguments.stream() + .map(argument -> new AbstractMap.SimpleEntry<>(argument.node().getName(), argument)) + .toArray(Map.Entry[]::new) + )); + } + + public boolean hasArgument(@NotNull String key) { + return arguments.containsKey(key); + } + + @SuppressWarnings("unchecked") + public @NotNull Optional> getArgument(@NotNull String key) { + return Optional.ofNullable((CommandNodeArgument) arguments.get(key)); + } + } } diff --git a/commands/src/test/java/com/wizardlybump17/wlib/command/test/rework/NodeResultTests.java b/commands/src/test/java/com/wizardlybump17/wlib/command/test/rework/NodeResultTests.java index 19b8268c..9de1b760 100644 --- a/commands/src/test/java/com/wizardlybump17/wlib/command/test/rework/NodeResultTests.java +++ b/commands/src/test/java/com/wizardlybump17/wlib/command/test/rework/NodeResultTests.java @@ -1,6 +1,7 @@ package com.wizardlybump17.wlib.command.test.rework; import com.wizardlybump17.wlib.command.rework.Command; +import com.wizardlybump17.wlib.command.rework.context.CommandContext; import com.wizardlybump17.wlib.command.rework.node.LiteralCommandNode; import org.junit.jupiter.api.Assertions; import org.junit.jupiter.api.Test; @@ -16,11 +17,12 @@ void testSuccess() { LiteralCommandNode hello = new LiteralCommandNode("hello", List.of(world)); Command command = new Command(hello); - Map> nodes = command.getNodes(List.of("hello", "world")); - Assertions.assertEquals(Map.of( - "hello", new Command.NodeResult<>(hello, "hello"), - "world", new Command.NodeResult<>(world, "world") - ), nodes); + CommandContext.CommandNodeArguments expected = new CommandContext.CommandNodeArguments(Map.of( + "hello", new CommandContext.CommandNodeArgument<>(hello, "hello", "hello"), + "world", new CommandContext.CommandNodeArgument<>(world, "world", "world") + )); + CommandContext.CommandNodeArguments actual = command.getArguments(List.of("hello", "world")); + Assertions.assertEquals(expected, actual); } @Test @@ -31,8 +33,8 @@ void testUnsuccessExtra1() { )) ); - Map> nodes = command.getNodes(List.of("hello", "world", "a")); - Assertions.assertEquals(Map.of(), nodes); + CommandContext.CommandNodeArguments arguments = command.getArguments(List.of("hello", "world", "a")); + Assertions.assertNull(arguments); } @Test @@ -43,8 +45,8 @@ void testUnsuccessExtra2() { )) ); - Map> nodes = command.getNodes(List.of("hello", "world", "a", "b")); - Assertions.assertEquals(Map.of(), nodes); + CommandContext.CommandNodeArguments arguments = command.getArguments(List.of("hello", "world", "a", "b")); + Assertions.assertNull(arguments); } @Test @@ -55,8 +57,8 @@ void testUnsuccessExtra3() { )) ); - Map> nodes = command.getNodes(List.of("hello", "world", "a", "b", "c")); - Assertions.assertEquals(Map.of(), nodes); + CommandContext.CommandNodeArguments arguments = command.getArguments(List.of("hello", "world", "a", "b", "c")); + Assertions.assertNull(arguments); } @Test @@ -73,8 +75,8 @@ void testUnsuccessLess1() { )) ); - Map> nodes = command.getNodes(List.of("hello", "world", "a", "b")); - Assertions.assertEquals(Map.of(), nodes); + CommandContext.CommandNodeArguments arguments = command.getArguments(List.of("hello", "world", "a", "b")); + Assertions.assertNull(arguments); } @Test @@ -91,8 +93,8 @@ void testUnsuccessLess2() { )) ); - Map> nodes = command.getNodes(List.of("hello", "world", "a")); - Assertions.assertEquals(Map.of(), nodes); + CommandContext.CommandNodeArguments arguments = command.getArguments(List.of("hello", "world", "a")); + Assertions.assertNull(arguments); } @Test @@ -109,8 +111,8 @@ void testUnsuccessLess3() { )) ); - Map> nodes = command.getNodes(List.of("hello", "world")); - Assertions.assertEquals(Map.of(), nodes); + CommandContext.CommandNodeArguments arguments = command.getArguments(List.of("hello", "world")); + Assertions.assertNull(arguments); } @Test @@ -127,8 +129,8 @@ void testUnsuccessLess4() { )) ); - Map> nodes = command.getNodes(List.of("hello")); - Assertions.assertEquals(Map.of(), nodes); + CommandContext.CommandNodeArguments arguments = command.getArguments(List.of("hello")); + Assertions.assertNull(arguments); } @Test @@ -145,7 +147,7 @@ void testUnsuccessLess5() { )) ); - Map> nodes = command.getNodes(List.of()); - Assertions.assertEquals(Map.of(), nodes); + CommandContext.CommandNodeArguments arguments = command.getArguments(List.of()); + Assertions.assertNull(arguments); } } From 6a38d70fa161f60e0ba63a633d9fc357f0e5cb12 Mon Sep 17 00:00:00 2001 From: WizardlyBump17 Date: Sun, 19 Oct 2025 16:41:44 -0300 Subject: [PATCH 020/363] improved the CommandResult system --- .../wlib/command/rework/Command.java | 9 ++++---- .../rework/executor/CommandExecutor.java | 8 +++---- .../wlib/command/rework/node/CommandNode.java | 6 +++--- .../rework/node/IntegerCommandNode.java | 2 +- .../rework/node/LiteralCommandNode.java | 2 +- .../command/rework/result/CommandResult.java | 21 +++++++++++-------- .../rework/result/ExceptionResult.java | 8 ++++++- .../rework/result/GenericErrorResult.java | 13 ++++++++++-- .../command/rework/result/SuccessResult.java | 9 ++------ 9 files changed, 45 insertions(+), 33 deletions(-) diff --git a/commands/src/main/java/com/wizardlybump17/wlib/command/rework/Command.java b/commands/src/main/java/com/wizardlybump17/wlib/command/rework/Command.java index 8bbca3a1..f1e82b55 100644 --- a/commands/src/main/java/com/wizardlybump17/wlib/command/rework/Command.java +++ b/commands/src/main/java/com/wizardlybump17/wlib/command/rework/Command.java @@ -5,7 +5,6 @@ import com.wizardlybump17.wlib.command.rework.node.CommandNode; import com.wizardlybump17.wlib.command.rework.node.LiteralCommandNode; import com.wizardlybump17.wlib.command.rework.result.CommandResult; -import com.wizardlybump17.wlib.command.rework.result.SuccessResult; import com.wizardlybump17.wlib.command.sender.CommandSender; import com.wizardlybump17.wlib.util.StringUtil; import org.jetbrains.annotations.NotNull; @@ -25,14 +24,14 @@ public Command(@NotNull LiteralCommandNode root) { return root; } - public @NotNull CommandResult execute(@NotNull CommandSender sender, @NotNull String execution) { + public @NotNull CommandResult execute(@NotNull CommandSender sender, @NotNull String execution) { List strings = getInputList(execution); CommandContext.CommandNodeArguments arguments = getArguments(strings); if (arguments == null) return CommandResult.error(); - return SuccessResult.INSTANCE; + return CommandResult.successful(new Object()); } public @NotNull List getInputList(@NotNull String original) { @@ -61,7 +60,7 @@ public Command(@NotNull LiteralCommandNode root) { continue inputLoop; } - return null; + return null; //return something that holds the CommandNodeArguments and an error, if any } if (!last.getChildren().isEmpty()) @@ -96,7 +95,7 @@ public Command(@NotNull LiteralCommandNode root) { continue; } - CommandExecutor executor; + CommandExecutor executor; if (i + 1 >= strings.length) executor = CommandExecutor.TEST_EXECUTOR; else diff --git a/commands/src/main/java/com/wizardlybump17/wlib/command/rework/executor/CommandExecutor.java b/commands/src/main/java/com/wizardlybump17/wlib/command/rework/executor/CommandExecutor.java index 8ba39431..c70f5faa 100644 --- a/commands/src/main/java/com/wizardlybump17/wlib/command/rework/executor/CommandExecutor.java +++ b/commands/src/main/java/com/wizardlybump17/wlib/command/rework/executor/CommandExecutor.java @@ -4,12 +4,12 @@ import com.wizardlybump17.wlib.command.rework.result.CommandResult; import org.jetbrains.annotations.NotNull; -public interface CommandExecutor { +public interface CommandExecutor { - @NotNull CommandExecutor TEST_EXECUTOR = context -> { + @NotNull CommandExecutor TEST_EXECUTOR = context -> { System.out.println(context); - return CommandResult.successful(); + return CommandResult.successful(""); }; - @NotNull CommandResult execute(@NotNull CommandContext context); + @NotNull CommandResult execute(@NotNull CommandContext context); } diff --git a/commands/src/main/java/com/wizardlybump17/wlib/command/rework/node/CommandNode.java b/commands/src/main/java/com/wizardlybump17/wlib/command/rework/node/CommandNode.java index 54212a69..6a981290 100644 --- a/commands/src/main/java/com/wizardlybump17/wlib/command/rework/node/CommandNode.java +++ b/commands/src/main/java/com/wizardlybump17/wlib/command/rework/node/CommandNode.java @@ -16,9 +16,9 @@ public abstract class CommandNode { private final @NotNull String name; private final @NotNull @Unmodifiable List> children; private final @NotNull AllowedInputs allowedInputs; - private final @Nullable CommandExecutor executor; + private final @Nullable CommandExecutor executor; - public CommandNode(@NotNull String name, @NotNull List> children, @NotNull AllowedInputs allowedInputs, @Nullable CommandExecutor executor) { + public CommandNode(@NotNull String name, @NotNull List> children, @NotNull AllowedInputs allowedInputs, @Nullable CommandExecutor executor) { this.name = name; this.children = Collections.unmodifiableList(children); this.allowedInputs = allowedInputs; @@ -66,7 +66,7 @@ public record ParseResult(boolean success, @Nullable T value) { } } - public @Nullable CommandExecutor getExecutor() { + public @Nullable CommandExecutor getExecutor() { return executor; } diff --git a/commands/src/main/java/com/wizardlybump17/wlib/command/rework/node/IntegerCommandNode.java b/commands/src/main/java/com/wizardlybump17/wlib/command/rework/node/IntegerCommandNode.java index 514ecfa0..1271279b 100644 --- a/commands/src/main/java/com/wizardlybump17/wlib/command/rework/node/IntegerCommandNode.java +++ b/commands/src/main/java/com/wizardlybump17/wlib/command/rework/node/IntegerCommandNode.java @@ -12,7 +12,7 @@ public class IntegerCommandNode extends CommandNode { - public IntegerCommandNode(@NotNull String name, @NotNull List> children, @NotNull AllowedNumberInputs.AllowedIntegerInputs allowedInputs, @Nullable CommandExecutor executor) { + public IntegerCommandNode(@NotNull String name, @NotNull List> children, @NotNull AllowedNumberInputs.AllowedIntegerInputs allowedInputs, @Nullable CommandExecutor executor) { super(name, children, allowedInputs, executor); } diff --git a/commands/src/main/java/com/wizardlybump17/wlib/command/rework/node/LiteralCommandNode.java b/commands/src/main/java/com/wizardlybump17/wlib/command/rework/node/LiteralCommandNode.java index 9304b091..6776849f 100644 --- a/commands/src/main/java/com/wizardlybump17/wlib/command/rework/node/LiteralCommandNode.java +++ b/commands/src/main/java/com/wizardlybump17/wlib/command/rework/node/LiteralCommandNode.java @@ -10,7 +10,7 @@ public class LiteralCommandNode extends CommandNode { - public LiteralCommandNode(@NotNull String name, @NotNull List> children, @Nullable CommandExecutor executor) { + public LiteralCommandNode(@NotNull String name, @NotNull List> children, @Nullable CommandExecutor executor) { super(name, children, new LiteralAllowedInput(name, false), executor); } diff --git a/commands/src/main/java/com/wizardlybump17/wlib/command/rework/result/CommandResult.java b/commands/src/main/java/com/wizardlybump17/wlib/command/rework/result/CommandResult.java index c0961d39..49f806e7 100644 --- a/commands/src/main/java/com/wizardlybump17/wlib/command/rework/result/CommandResult.java +++ b/commands/src/main/java/com/wizardlybump17/wlib/command/rework/result/CommandResult.java @@ -1,24 +1,27 @@ package com.wizardlybump17.wlib.command.rework.result; import org.jetbrains.annotations.NotNull; +import org.jetbrains.annotations.Nullable; -public interface CommandResult { +public interface CommandResult { boolean success(); - static @NotNull SuccessResult successful() { - return SuccessResult.INSTANCE; + @Nullable T data(); + + static @NotNull SuccessResult successful(@Nullable T data) { + return new SuccessResult<>(data); } - static @NotNull ExceptionResult exceptionally(@NotNull Throwable throwable) { - return new ExceptionResult(throwable); + static @NotNull ExceptionResult exceptionally(@NotNull Throwable throwable) { + return new ExceptionResult<>(throwable); } - static @NotNull GenericErrorResult error(@NotNull String message) { - return new GenericErrorResult(message); + static @NotNull GenericErrorResult error(@NotNull String message) { + return new GenericErrorResult<>(message); } - static @NotNull GenericErrorResult error() { - return GenericErrorResult.DEFAULT_ERROR; + static @NotNull GenericErrorResult error() { + return new GenericErrorResult<>(); } } diff --git a/commands/src/main/java/com/wizardlybump17/wlib/command/rework/result/ExceptionResult.java b/commands/src/main/java/com/wizardlybump17/wlib/command/rework/result/ExceptionResult.java index 69e6902a..fa4069f9 100644 --- a/commands/src/main/java/com/wizardlybump17/wlib/command/rework/result/ExceptionResult.java +++ b/commands/src/main/java/com/wizardlybump17/wlib/command/rework/result/ExceptionResult.java @@ -1,11 +1,17 @@ package com.wizardlybump17.wlib.command.rework.result; import org.jetbrains.annotations.NotNull; +import org.jetbrains.annotations.Nullable; -public record ExceptionResult(@NotNull Throwable exception) implements CommandResult { +public record ExceptionResult(@NotNull Throwable exception) implements CommandResult { @Override public boolean success() { return false; } + + @Override + public @Nullable T data() { + return null; + } } diff --git a/commands/src/main/java/com/wizardlybump17/wlib/command/rework/result/GenericErrorResult.java b/commands/src/main/java/com/wizardlybump17/wlib/command/rework/result/GenericErrorResult.java index cab0fe23..7adb8a11 100644 --- a/commands/src/main/java/com/wizardlybump17/wlib/command/rework/result/GenericErrorResult.java +++ b/commands/src/main/java/com/wizardlybump17/wlib/command/rework/result/GenericErrorResult.java @@ -1,14 +1,23 @@ package com.wizardlybump17.wlib.command.rework.result; import org.jetbrains.annotations.NotNull; +import org.jetbrains.annotations.Nullable; -public record GenericErrorResult(@NotNull String message) implements CommandResult { +public record GenericErrorResult(@NotNull String message) implements CommandResult { public static final @NotNull String DEFAULT_MESSAGE = "An error occurred while executing the command"; - public static final @NotNull GenericErrorResult DEFAULT_ERROR = new GenericErrorResult(DEFAULT_MESSAGE); + + public GenericErrorResult() { + this(DEFAULT_MESSAGE); + } @Override public boolean success() { return false; } + + @Override + public @Nullable T data() { + return null; + } } diff --git a/commands/src/main/java/com/wizardlybump17/wlib/command/rework/result/SuccessResult.java b/commands/src/main/java/com/wizardlybump17/wlib/command/rework/result/SuccessResult.java index 9e32cdc7..f40d06de 100644 --- a/commands/src/main/java/com/wizardlybump17/wlib/command/rework/result/SuccessResult.java +++ b/commands/src/main/java/com/wizardlybump17/wlib/command/rework/result/SuccessResult.java @@ -1,13 +1,8 @@ package com.wizardlybump17.wlib.command.rework.result; -import org.jetbrains.annotations.NotNull; +import org.jetbrains.annotations.Nullable; -public final class SuccessResult implements CommandResult { - - public static final @NotNull SuccessResult INSTANCE = new SuccessResult(); - - private SuccessResult() { - } +public record SuccessResult(@Nullable T data) implements CommandResult { @Override public boolean success() { From 77d7aff3af5fca83a113d3cb8bf7b8b5f6b1a55e Mon Sep 17 00:00:00 2001 From: WizardlyBump17 Date: Sun, 19 Oct 2025 16:46:11 -0300 Subject: [PATCH 021/363] true --- .../wlib/command/rework/result/SuccessResult.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/commands/src/main/java/com/wizardlybump17/wlib/command/rework/result/SuccessResult.java b/commands/src/main/java/com/wizardlybump17/wlib/command/rework/result/SuccessResult.java index f40d06de..1f4db577 100644 --- a/commands/src/main/java/com/wizardlybump17/wlib/command/rework/result/SuccessResult.java +++ b/commands/src/main/java/com/wizardlybump17/wlib/command/rework/result/SuccessResult.java @@ -6,6 +6,6 @@ public record SuccessResult(@Nullable T data) implements CommandResult { @Override public boolean success() { - return false; + return true; } } From f94015e12570c28a47254dae1fad21d2f384f86a Mon Sep 17 00:00:00 2001 From: WizardlyBump17 Date: Sun, 19 Oct 2025 16:46:25 -0300 Subject: [PATCH 022/363] using the CommandResult instead --- .../wlib/command/rework/Command.java | 4 ++-- .../wlib/command/rework/node/CommandNode.java | 18 ++---------------- .../rework/node/IntegerCommandNode.java | 7 ++++--- .../rework/node/LiteralCommandNode.java | 5 +++-- 4 files changed, 11 insertions(+), 23 deletions(-) diff --git a/commands/src/main/java/com/wizardlybump17/wlib/command/rework/Command.java b/commands/src/main/java/com/wizardlybump17/wlib/command/rework/Command.java index f1e82b55..ec90011d 100644 --- a/commands/src/main/java/com/wizardlybump17/wlib/command/rework/Command.java +++ b/commands/src/main/java/com/wizardlybump17/wlib/command/rework/Command.java @@ -71,11 +71,11 @@ public Command(@NotNull LiteralCommandNode root) { @SuppressWarnings("unchecked") public static @Nullable CommandContext.CommandNodeArgument getNodeResult(@NotNull CommandNode node, @NotNull String input) { - CommandNode.ParseResult parseResult = node.parse(input); + CommandResult parseResult = node.parse(input); if (!parseResult.success()) return null; - Object value = parseResult.value(); + Object value = parseResult.data(); if (!((CommandNode) node).isValidInput(value)) return null; diff --git a/commands/src/main/java/com/wizardlybump17/wlib/command/rework/node/CommandNode.java b/commands/src/main/java/com/wizardlybump17/wlib/command/rework/node/CommandNode.java index 6a981290..e77e5cf3 100644 --- a/commands/src/main/java/com/wizardlybump17/wlib/command/rework/node/CommandNode.java +++ b/commands/src/main/java/com/wizardlybump17/wlib/command/rework/node/CommandNode.java @@ -2,6 +2,7 @@ import com.wizardlybump17.wlib.command.rework.executor.CommandExecutor; import com.wizardlybump17.wlib.command.rework.input.AllowedInputs; +import com.wizardlybump17.wlib.command.rework.result.CommandResult; import com.wizardlybump17.wlib.command.sender.CommandSender; import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.Nullable; @@ -41,7 +42,7 @@ public CommandNode(@NotNull String name, @NotNull List> children, return allowedInputs; } - public abstract @NotNull ParseResult parse(@NotNull String input); + public abstract @NotNull CommandResult parse(@NotNull String input); public final boolean isValidInput(@Nullable T input) { return allowedInputs.isAllowed(input); @@ -51,21 +52,6 @@ public final boolean isValidInput(@Nullable T input) { return List.of(); } - public record ParseResult(boolean success, @Nullable T value) { - - public static @NotNull ParseResult success(@Nullable T value) { - return new ParseResult<>(true, value); - } - - public static @NotNull ParseResult emptySuccess() { - return new ParseResult<>(true, null); - } - - public static @NotNull ParseResult failure() { - return new ParseResult<>(false, null); - } - } - public @Nullable CommandExecutor getExecutor() { return executor; } diff --git a/commands/src/main/java/com/wizardlybump17/wlib/command/rework/node/IntegerCommandNode.java b/commands/src/main/java/com/wizardlybump17/wlib/command/rework/node/IntegerCommandNode.java index 1271279b..40cfd2af 100644 --- a/commands/src/main/java/com/wizardlybump17/wlib/command/rework/node/IntegerCommandNode.java +++ b/commands/src/main/java/com/wizardlybump17/wlib/command/rework/node/IntegerCommandNode.java @@ -3,6 +3,7 @@ import com.wizardlybump17.wlib.command.rework.executor.CommandExecutor; import com.wizardlybump17.wlib.command.rework.input.AllowedNumberInputs; import com.wizardlybump17.wlib.command.rework.input.RangedAllowedInputs; +import com.wizardlybump17.wlib.command.rework.result.CommandResult; import com.wizardlybump17.wlib.command.sender.CommandSender; import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.Nullable; @@ -22,11 +23,11 @@ public IntegerCommandNode(@NotNull String name, @NotNull List> ch } @Override - public @NotNull ParseResult parse(@NotNull String input) { + public @NotNull CommandResult parse(@NotNull String input) { try { - return ParseResult.success(Integer.parseInt(input)); + return CommandResult.successful(Integer.parseInt(input)); } catch (NumberFormatException e) { - return ParseResult.failure(); + return CommandResult.exceptionally(e); } } diff --git a/commands/src/main/java/com/wizardlybump17/wlib/command/rework/node/LiteralCommandNode.java b/commands/src/main/java/com/wizardlybump17/wlib/command/rework/node/LiteralCommandNode.java index 6776849f..269d5191 100644 --- a/commands/src/main/java/com/wizardlybump17/wlib/command/rework/node/LiteralCommandNode.java +++ b/commands/src/main/java/com/wizardlybump17/wlib/command/rework/node/LiteralCommandNode.java @@ -2,6 +2,7 @@ import com.wizardlybump17.wlib.command.rework.executor.CommandExecutor; import com.wizardlybump17.wlib.command.rework.input.LiteralAllowedInput; +import com.wizardlybump17.wlib.command.rework.result.CommandResult; import com.wizardlybump17.wlib.command.sender.CommandSender; import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.Nullable; @@ -24,8 +25,8 @@ public LiteralCommandNode(@NotNull String name, @NotNull List> ch } @Override - public @NotNull ParseResult parse(@NotNull String input) { - return ParseResult.success(input); + public @NotNull CommandResult parse(@NotNull String input) { + return CommandResult.successful(input); } @Override From fd122054a95e55e4c70e5fe34248edf46a4061b0 Mon Sep 17 00:00:00 2001 From: WizardlyBump17 Date: Mon, 20 Oct 2025 19:37:11 -0300 Subject: [PATCH 023/363] improved the CommandNodeArguments system --- .../wlib/command/rework/Command.java | 50 +++++++++++-------- .../rework/context/CommandContext.java | 24 ++++++--- .../wlib/command/rework/node/CommandNode.java | 9 ++++ .../command/rework/result/CommandResult.java | 13 +++++ .../rework/result/InvalidArgumentResult.java | 48 ++++++++++++++++++ .../command/test/rework/NodeResultTests.java | 16 ++++-- 6 files changed, 129 insertions(+), 31 deletions(-) create mode 100644 commands/src/main/java/com/wizardlybump17/wlib/command/rework/result/InvalidArgumentResult.java diff --git a/commands/src/main/java/com/wizardlybump17/wlib/command/rework/Command.java b/commands/src/main/java/com/wizardlybump17/wlib/command/rework/Command.java index ec90011d..a79b7851 100644 --- a/commands/src/main/java/com/wizardlybump17/wlib/command/rework/Command.java +++ b/commands/src/main/java/com/wizardlybump17/wlib/command/rework/Command.java @@ -38,6 +38,7 @@ public Command(@NotNull LiteralCommandNode root) { return StringUtil.parseQuotedStrings(original); } + @SuppressWarnings("unchecked") public @Nullable CommandContext.CommandNodeArguments getArguments(@NotNull List input) { if (input.isEmpty()) return null; @@ -46,40 +47,49 @@ public Command(@NotNull LiteralCommandNode root) { List> children = List.of(root); - CommandNode last = null; + CommandNode lastSuccessfulNode = null; + CommandResult lastResult = null; + String lastInputString = null; inputLoop: for (String inputString : input) { for (CommandNode child : children) { - CommandContext.CommandNodeArgument argument = getNodeResult(child, inputString); - if (argument == null) + CommandResult result = child.parseOrInvalid(inputString); + + lastResult = result; + lastInputString = inputString; + + if (!result.success()) continue; - last = child; + lastSuccessfulNode = child; children = child.getChildren(); - arguments.put(inputString, argument); + arguments.put(inputString, new CommandContext.CommandNodeArgument<>((CommandNode) child, inputString, (CommandResult) result)); continue inputLoop; } - return null; //return something that holds the CommandNodeArguments and an error, if any + return new CommandContext.CommandNodeArguments(arguments, lastResult, lastSuccessfulNode, lastInputString); } - if (!last.getChildren().isEmpty()) - return null; + if (!lastSuccessfulNode.getChildren().isEmpty()) + return new CommandContext.CommandNodeArguments(arguments, lastResult, lastSuccessfulNode, lastInputString); - return new CommandContext.CommandNodeArguments(arguments); + return new CommandContext.CommandNodeArguments(arguments, lastResult, lastSuccessfulNode, lastInputString); } - @SuppressWarnings("unchecked") - public static @Nullable CommandContext.CommandNodeArgument getNodeResult(@NotNull CommandNode node, @NotNull String input) { - CommandResult parseResult = node.parse(input); - if (!parseResult.success()) - return null; - - Object value = parseResult.data(); - if (!((CommandNode) node).isValidInput(value)) - return null; - - return new CommandContext.CommandNodeArgument<>((CommandNode) node, input, value); + public static @NotNull CommandResult getNodeResult(@NotNull CommandNode node, @NotNull String input) { + return node.parseOrInvalid(input); +// +// CommandResult parseResult = (CommandResult) node.parse(input); +// Object value = parseResult.data(); +// +// CommandContext.CommandNodeArgument argument = new CommandContext.CommandNodeArgument<>((CommandNode) node, input, parseResult); +// if (!parseResult.success()) +// return argument; +// +// if (!((CommandNode) node).isValidInput(value)) +// return argument; +// +// return argument; } public static @Nullable Command createCommand(@NotNull String execution) { diff --git a/commands/src/main/java/com/wizardlybump17/wlib/command/rework/context/CommandContext.java b/commands/src/main/java/com/wizardlybump17/wlib/command/rework/context/CommandContext.java index ed5887db..3fc9e67d 100644 --- a/commands/src/main/java/com/wizardlybump17/wlib/command/rework/context/CommandContext.java +++ b/commands/src/main/java/com/wizardlybump17/wlib/command/rework/context/CommandContext.java @@ -2,6 +2,7 @@ import com.wizardlybump17.wlib.command.rework.Command; import com.wizardlybump17.wlib.command.rework.node.CommandNode; +import com.wizardlybump17.wlib.command.rework.result.CommandResult; import com.wizardlybump17.wlib.command.sender.CommandSender; import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.Nullable; @@ -10,21 +11,30 @@ public record CommandContext(@NotNull Command command, @NotNull CommandSender sender, @NotNull CommandNodeArguments arguments) { - public record CommandNodeArgument(@NotNull CommandNode node, @NotNull String input, @Nullable T value) { + public record CommandNodeArgument(@NotNull CommandNode node, @NotNull String input, @NotNull CommandResult result) { + + public @Nullable T data() { + return result.data(); + } } - public record CommandNodeArguments(@NotNull Map> arguments) { + public record CommandNodeArguments(@NotNull Map> arguments, @Nullable CommandResult lastResult, @Nullable CommandNode lastNode, @Nullable String lastInput) { public CommandNodeArguments { arguments = Collections.unmodifiableMap(arguments); } @SuppressWarnings("unchecked") - public CommandNodeArguments(@NotNull List> arguments) { - this(Map.ofEntries(arguments.stream() - .map(argument -> new AbstractMap.SimpleEntry<>(argument.node().getName(), argument)) - .toArray(Map.Entry[]::new) - )); + public CommandNodeArguments(@NotNull List> arguments, @Nullable CommandResult lastResult, @Nullable CommandNode lastNode, @Nullable String lastInput) { + this( + Map.ofEntries(arguments.stream() + .map(argument -> new AbstractMap.SimpleEntry<>(argument.node().getName(), argument)) + .toArray(Map.Entry[]::new) + ), + lastResult, + lastNode, + lastInput + ); } public boolean hasArgument(@NotNull String key) { diff --git a/commands/src/main/java/com/wizardlybump17/wlib/command/rework/node/CommandNode.java b/commands/src/main/java/com/wizardlybump17/wlib/command/rework/node/CommandNode.java index e77e5cf3..e6adc5e0 100644 --- a/commands/src/main/java/com/wizardlybump17/wlib/command/rework/node/CommandNode.java +++ b/commands/src/main/java/com/wizardlybump17/wlib/command/rework/node/CommandNode.java @@ -3,6 +3,7 @@ import com.wizardlybump17.wlib.command.rework.executor.CommandExecutor; import com.wizardlybump17.wlib.command.rework.input.AllowedInputs; import com.wizardlybump17.wlib.command.rework.result.CommandResult; +import com.wizardlybump17.wlib.command.rework.result.InvalidArgumentResult; import com.wizardlybump17.wlib.command.sender.CommandSender; import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.Nullable; @@ -48,6 +49,14 @@ public final boolean isValidInput(@Nullable T input) { return allowedInputs.isAllowed(input); } + public final @NotNull CommandResult parseOrInvalid(@NotNull String input) { + CommandResult parse = parse(input); + if (parse.success() && isValidInput(parse.data())) + return parse; + + return new InvalidArgumentResult<>(this, parse); + } + public @NotNull List getSuggestions(@NotNull CommandSender sender, @NotNull List args, @NotNull String currentInput) { return List.of(); } diff --git a/commands/src/main/java/com/wizardlybump17/wlib/command/rework/result/CommandResult.java b/commands/src/main/java/com/wizardlybump17/wlib/command/rework/result/CommandResult.java index 49f806e7..4a5acd12 100644 --- a/commands/src/main/java/com/wizardlybump17/wlib/command/rework/result/CommandResult.java +++ b/commands/src/main/java/com/wizardlybump17/wlib/command/rework/result/CommandResult.java @@ -1,5 +1,6 @@ package com.wizardlybump17.wlib.command.rework.result; +import com.wizardlybump17.wlib.command.rework.node.CommandNode; import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.Nullable; @@ -24,4 +25,16 @@ public interface CommandResult { static @NotNull GenericErrorResult error() { return new GenericErrorResult<>(); } + + static @NotNull InvalidArgumentResult invalidArgument(@NotNull CommandNode node, @NotNull CommandResult previousResult) { + return new InvalidArgumentResult<>(node, previousResult); + } + + static @NotNull InvalidArgumentResult invalidArgument(@NotNull CommandNode node, @NotNull T data) { + return new InvalidArgumentResult<>(node, data); + } + + static @NotNull InvalidArgumentResult invalidArgument(@NotNull CommandNode node) { + return new InvalidArgumentResult<>(node); + } } diff --git a/commands/src/main/java/com/wizardlybump17/wlib/command/rework/result/InvalidArgumentResult.java b/commands/src/main/java/com/wizardlybump17/wlib/command/rework/result/InvalidArgumentResult.java new file mode 100644 index 00000000..fe7a916c --- /dev/null +++ b/commands/src/main/java/com/wizardlybump17/wlib/command/rework/result/InvalidArgumentResult.java @@ -0,0 +1,48 @@ +package com.wizardlybump17.wlib.command.rework.result; + +import com.wizardlybump17.wlib.command.rework.node.CommandNode; +import org.jetbrains.annotations.NotNull; +import org.jetbrains.annotations.Nullable; + +public final class InvalidArgumentResult implements CommandResult { + + private final @NotNull CommandNode node; + private final @Nullable T data; + private final @Nullable CommandResult previousResult; + + private InvalidArgumentResult(@NotNull CommandNode node, @Nullable T data, @Nullable CommandResult previousResult) { + this.node = node; + this.data = data; + this.previousResult = previousResult; + } + + public InvalidArgumentResult(@NotNull CommandNode node, @NotNull CommandResult previousResult) { + this(node, previousResult.data(), previousResult); + } + + public InvalidArgumentResult(@NotNull CommandNode node, @Nullable T data) { + this(node, data, null); + } + + public InvalidArgumentResult(@NotNull CommandNode node) { + this(node, null, null); + } + + @Override + public boolean success() { + return false; + } + + @Override + public @Nullable T data() { + return data; + } + + public @NotNull CommandNode node() { + return node; + } + + public @Nullable CommandResult previousResult() { + return previousResult; + } +} diff --git a/commands/src/test/java/com/wizardlybump17/wlib/command/test/rework/NodeResultTests.java b/commands/src/test/java/com/wizardlybump17/wlib/command/test/rework/NodeResultTests.java index 9de1b760..7a08d3c8 100644 --- a/commands/src/test/java/com/wizardlybump17/wlib/command/test/rework/NodeResultTests.java +++ b/commands/src/test/java/com/wizardlybump17/wlib/command/test/rework/NodeResultTests.java @@ -3,6 +3,8 @@ import com.wizardlybump17.wlib.command.rework.Command; import com.wizardlybump17.wlib.command.rework.context.CommandContext; import com.wizardlybump17.wlib.command.rework.node.LiteralCommandNode; +import com.wizardlybump17.wlib.command.rework.result.CommandResult; +import com.wizardlybump17.wlib.command.rework.result.SuccessResult; import org.junit.jupiter.api.Assertions; import org.junit.jupiter.api.Test; @@ -17,10 +19,16 @@ void testSuccess() { LiteralCommandNode hello = new LiteralCommandNode("hello", List.of(world)); Command command = new Command(hello); - CommandContext.CommandNodeArguments expected = new CommandContext.CommandNodeArguments(Map.of( - "hello", new CommandContext.CommandNodeArgument<>(hello, "hello", "hello"), - "world", new CommandContext.CommandNodeArgument<>(world, "world", "world") - )); + SuccessResult worldResult = CommandResult.successful("world"); + CommandContext.CommandNodeArguments expected = new CommandContext.CommandNodeArguments( + Map.of( + "hello", new CommandContext.CommandNodeArgument<>(hello, "hello", CommandResult.successful("hello")), + "world", new CommandContext.CommandNodeArgument<>(world, "world", worldResult) + ), + worldResult, + world, + "world" + ); CommandContext.CommandNodeArguments actual = command.getArguments(List.of("hello", "world")); Assertions.assertEquals(expected, actual); } From 3eca79f43d235c9bdb5e087edcad73868fdddb8b Mon Sep 17 00:00:00 2001 From: WizardlyBump17 Date: Wed, 22 Oct 2025 00:18:59 -0300 Subject: [PATCH 024/363] return an InvalidArgumentResult --- .../wlib/command/rework/Command.java | 14 ++++++++------ 1 file changed, 8 insertions(+), 6 deletions(-) diff --git a/commands/src/main/java/com/wizardlybump17/wlib/command/rework/Command.java b/commands/src/main/java/com/wizardlybump17/wlib/command/rework/Command.java index a79b7851..de547c0c 100644 --- a/commands/src/main/java/com/wizardlybump17/wlib/command/rework/Command.java +++ b/commands/src/main/java/com/wizardlybump17/wlib/command/rework/Command.java @@ -5,6 +5,7 @@ import com.wizardlybump17.wlib.command.rework.node.CommandNode; import com.wizardlybump17.wlib.command.rework.node.LiteralCommandNode; import com.wizardlybump17.wlib.command.rework.result.CommandResult; +import com.wizardlybump17.wlib.command.rework.result.InvalidArgumentResult; import com.wizardlybump17.wlib.command.sender.CommandSender; import com.wizardlybump17.wlib.util.StringUtil; import org.jetbrains.annotations.NotNull; @@ -47,11 +48,13 @@ public Command(@NotNull LiteralCommandNode root) { List> children = List.of(root); - CommandNode lastSuccessfulNode = null; + CommandNode lastNode = null; CommandResult lastResult = null; String lastInputString = null; inputLoop: for (String inputString : input) { for (CommandNode child : children) { + lastNode = child; + CommandResult result = child.parseOrInvalid(inputString); lastResult = result; @@ -60,20 +63,19 @@ public Command(@NotNull LiteralCommandNode root) { if (!result.success()) continue; - lastSuccessfulNode = child; children = child.getChildren(); arguments.put(inputString, new CommandContext.CommandNodeArgument<>((CommandNode) child, inputString, (CommandResult) result)); continue inputLoop; } - return new CommandContext.CommandNodeArguments(arguments, lastResult, lastSuccessfulNode, lastInputString); + return new CommandContext.CommandNodeArguments(arguments, new InvalidArgumentResult<>((CommandNode) lastNode, lastResult), lastNode, lastInputString); } - if (!lastSuccessfulNode.getChildren().isEmpty()) - return new CommandContext.CommandNodeArguments(arguments, lastResult, lastSuccessfulNode, lastInputString); + if (!lastNode.getChildren().isEmpty()) + return new CommandContext.CommandNodeArguments(arguments, new InvalidArgumentResult<>((CommandNode) lastNode), lastNode, lastInputString); - return new CommandContext.CommandNodeArguments(arguments, lastResult, lastSuccessfulNode, lastInputString); + return new CommandContext.CommandNodeArguments(arguments, lastResult, lastNode, lastInputString); } public static @NotNull CommandResult getNodeResult(@NotNull CommandNode node, @NotNull String input) { From 77f4a20ae20cb1b1eaced5d70c11cbbe239b6a00 Mon Sep 17 00:00:00 2001 From: WizardlyBump17 Date: Wed, 22 Oct 2025 00:34:41 -0300 Subject: [PATCH 025/363] ExtraArgumentsResult. I am too sleepy --- .../wlib/command/rework/Command.java | 8 ++++++- .../rework/result/ExtraArgumentsResult.java | 17 ++++++++++++++ .../command/test/rework/NodeResultTests.java | 22 +++++++++++++------ 3 files changed, 39 insertions(+), 8 deletions(-) create mode 100644 commands/src/main/java/com/wizardlybump17/wlib/command/rework/result/ExtraArgumentsResult.java diff --git a/commands/src/main/java/com/wizardlybump17/wlib/command/rework/Command.java b/commands/src/main/java/com/wizardlybump17/wlib/command/rework/Command.java index de547c0c..8f2d1c21 100644 --- a/commands/src/main/java/com/wizardlybump17/wlib/command/rework/Command.java +++ b/commands/src/main/java/com/wizardlybump17/wlib/command/rework/Command.java @@ -5,6 +5,7 @@ import com.wizardlybump17.wlib.command.rework.node.CommandNode; import com.wizardlybump17.wlib.command.rework.node.LiteralCommandNode; import com.wizardlybump17.wlib.command.rework.result.CommandResult; +import com.wizardlybump17.wlib.command.rework.result.ExtraArgumentsResult; import com.wizardlybump17.wlib.command.rework.result.InvalidArgumentResult; import com.wizardlybump17.wlib.command.sender.CommandSender; import com.wizardlybump17.wlib.util.StringUtil; @@ -69,7 +70,12 @@ public Command(@NotNull LiteralCommandNode root) { continue inputLoop; } - return new CommandContext.CommandNodeArguments(arguments, new InvalidArgumentResult<>((CommandNode) lastNode, lastResult), lastNode, lastInputString); + CommandResult error; + if (lastNode.getChildren().isEmpty()) + error = new ExtraArgumentsResult<>(inputString); + else + error = new InvalidArgumentResult<>((CommandNode) lastNode, lastResult); + return new CommandContext.CommandNodeArguments(arguments, error, lastNode, lastInputString); } if (!lastNode.getChildren().isEmpty()) diff --git a/commands/src/main/java/com/wizardlybump17/wlib/command/rework/result/ExtraArgumentsResult.java b/commands/src/main/java/com/wizardlybump17/wlib/command/rework/result/ExtraArgumentsResult.java new file mode 100644 index 00000000..fc8eb4fe --- /dev/null +++ b/commands/src/main/java/com/wizardlybump17/wlib/command/rework/result/ExtraArgumentsResult.java @@ -0,0 +1,17 @@ +package com.wizardlybump17.wlib.command.rework.result; + +import org.jetbrains.annotations.NotNull; +import org.jetbrains.annotations.Nullable; + +public record ExtraArgumentsResult(@NotNull String extra) implements CommandResult { + + @Override + public boolean success() { + return false; + } + + @Override + public @Nullable T data() { + return null; + } +} diff --git a/commands/src/test/java/com/wizardlybump17/wlib/command/test/rework/NodeResultTests.java b/commands/src/test/java/com/wizardlybump17/wlib/command/test/rework/NodeResultTests.java index 7a08d3c8..24811bde 100644 --- a/commands/src/test/java/com/wizardlybump17/wlib/command/test/rework/NodeResultTests.java +++ b/commands/src/test/java/com/wizardlybump17/wlib/command/test/rework/NodeResultTests.java @@ -4,6 +4,7 @@ import com.wizardlybump17.wlib.command.rework.context.CommandContext; import com.wizardlybump17.wlib.command.rework.node.LiteralCommandNode; import com.wizardlybump17.wlib.command.rework.result.CommandResult; +import com.wizardlybump17.wlib.command.rework.result.ExtraArgumentsResult; import com.wizardlybump17.wlib.command.rework.result.SuccessResult; import org.junit.jupiter.api.Assertions; import org.junit.jupiter.api.Test; @@ -35,14 +36,21 @@ void testSuccess() { @Test void testUnsuccessExtra1() { - Command command = new Command( - new LiteralCommandNode("hello", List.of( - new LiteralCommandNode("world", List.of()) - )) - ); + LiteralCommandNode worldNode = new LiteralCommandNode("world", List.of()); + LiteralCommandNode helloNode = new LiteralCommandNode("hello", List.of(worldNode)); + Command command = new Command(helloNode); - CommandContext.CommandNodeArguments arguments = command.getArguments(List.of("hello", "world", "a")); - Assertions.assertNull(arguments); + CommandContext.CommandNodeArguments expected = new CommandContext.CommandNodeArguments( + List.of( + new CommandContext.CommandNodeArgument<>(helloNode, "hello", CommandResult.successful("hello")), + new CommandContext.CommandNodeArgument<>(worldNode, "world", CommandResult.successful("world")) + ), + new ExtraArgumentsResult<>("a"), + worldNode, + "world" + ); + CommandContext.CommandNodeArguments actual = command.getArguments(List.of("hello", "world", "a")); + Assertions.assertEquals(expected, actual); } @Test From 684abb58687ad027d27267ca7ea4e24506126f4d Mon Sep 17 00:00:00 2001 From: WizardlyBump17 Date: Wed, 22 Oct 2025 23:19:11 -0300 Subject: [PATCH 026/363] InsufficientArgumentsResult and fixed the tests --- .../wlib/command/rework/Command.java | 9 +- .../rework/context/CommandContext.java | 2 + .../result/InsufficientArgumentsResult.java | 18 ++ .../command/test/rework/NodeResultTests.java | 170 +++++++++++------- 4 files changed, 127 insertions(+), 72 deletions(-) create mode 100644 commands/src/main/java/com/wizardlybump17/wlib/command/rework/result/InsufficientArgumentsResult.java diff --git a/commands/src/main/java/com/wizardlybump17/wlib/command/rework/Command.java b/commands/src/main/java/com/wizardlybump17/wlib/command/rework/Command.java index 8f2d1c21..3719068d 100644 --- a/commands/src/main/java/com/wizardlybump17/wlib/command/rework/Command.java +++ b/commands/src/main/java/com/wizardlybump17/wlib/command/rework/Command.java @@ -6,6 +6,7 @@ import com.wizardlybump17.wlib.command.rework.node.LiteralCommandNode; import com.wizardlybump17.wlib.command.rework.result.CommandResult; import com.wizardlybump17.wlib.command.rework.result.ExtraArgumentsResult; +import com.wizardlybump17.wlib.command.rework.result.InsufficientArgumentsResult; import com.wizardlybump17.wlib.command.rework.result.InvalidArgumentResult; import com.wizardlybump17.wlib.command.sender.CommandSender; import com.wizardlybump17.wlib.util.StringUtil; @@ -41,9 +42,9 @@ public Command(@NotNull LiteralCommandNode root) { } @SuppressWarnings("unchecked") - public @Nullable CommandContext.CommandNodeArguments getArguments(@NotNull List input) { + public @NotNull CommandContext.CommandNodeArguments getArguments(@NotNull List input) { if (input.isEmpty()) - return null; + return CommandContext.CommandNodeArguments.EMPTY; Map> arguments = new LinkedHashMap<>(); @@ -71,7 +72,7 @@ public Command(@NotNull LiteralCommandNode root) { } CommandResult error; - if (lastNode.getChildren().isEmpty()) + if (lastNode.getChildren().isEmpty()) //TODO: just because the last node has no children that it means the input is an extra argument error = new ExtraArgumentsResult<>(inputString); else error = new InvalidArgumentResult<>((CommandNode) lastNode, lastResult); @@ -79,7 +80,7 @@ public Command(@NotNull LiteralCommandNode root) { } if (!lastNode.getChildren().isEmpty()) - return new CommandContext.CommandNodeArguments(arguments, new InvalidArgumentResult<>((CommandNode) lastNode), lastNode, lastInputString); + return new CommandContext.CommandNodeArguments(arguments, new InsufficientArgumentsResult<>(lastInputString, lastNode), lastNode, lastInputString); return new CommandContext.CommandNodeArguments(arguments, lastResult, lastNode, lastInputString); } diff --git a/commands/src/main/java/com/wizardlybump17/wlib/command/rework/context/CommandContext.java b/commands/src/main/java/com/wizardlybump17/wlib/command/rework/context/CommandContext.java index 3fc9e67d..a5bac388 100644 --- a/commands/src/main/java/com/wizardlybump17/wlib/command/rework/context/CommandContext.java +++ b/commands/src/main/java/com/wizardlybump17/wlib/command/rework/context/CommandContext.java @@ -20,6 +20,8 @@ public record CommandNodeArgument(@NotNull CommandNode node, @NotNull Stri public record CommandNodeArguments(@NotNull Map> arguments, @Nullable CommandResult lastResult, @Nullable CommandNode lastNode, @Nullable String lastInput) { + public static @NotNull CommandNodeArguments EMPTY = new CommandNodeArguments(Map.of(), null, null, null); + public CommandNodeArguments { arguments = Collections.unmodifiableMap(arguments); } diff --git a/commands/src/main/java/com/wizardlybump17/wlib/command/rework/result/InsufficientArgumentsResult.java b/commands/src/main/java/com/wizardlybump17/wlib/command/rework/result/InsufficientArgumentsResult.java new file mode 100644 index 00000000..ff082002 --- /dev/null +++ b/commands/src/main/java/com/wizardlybump17/wlib/command/rework/result/InsufficientArgumentsResult.java @@ -0,0 +1,18 @@ +package com.wizardlybump17.wlib.command.rework.result; + +import com.wizardlybump17.wlib.command.rework.node.CommandNode; +import org.jetbrains.annotations.NotNull; +import org.jetbrains.annotations.Nullable; + +public record InsufficientArgumentsResult(@NotNull String lastInput, @NotNull CommandNode node) implements CommandResult { + + @Override + public boolean success() { + return false; + } + + @Override + public @Nullable T data() { + return null; + } +} diff --git a/commands/src/test/java/com/wizardlybump17/wlib/command/test/rework/NodeResultTests.java b/commands/src/test/java/com/wizardlybump17/wlib/command/test/rework/NodeResultTests.java index 24811bde..b6732227 100644 --- a/commands/src/test/java/com/wizardlybump17/wlib/command/test/rework/NodeResultTests.java +++ b/commands/src/test/java/com/wizardlybump17/wlib/command/test/rework/NodeResultTests.java @@ -5,6 +5,7 @@ import com.wizardlybump17.wlib.command.rework.node.LiteralCommandNode; import com.wizardlybump17.wlib.command.rework.result.CommandResult; import com.wizardlybump17.wlib.command.rework.result.ExtraArgumentsResult; +import com.wizardlybump17.wlib.command.rework.result.InsufficientArgumentsResult; import com.wizardlybump17.wlib.command.rework.result.SuccessResult; import org.junit.jupiter.api.Assertions; import org.junit.jupiter.api.Test; @@ -55,98 +56,130 @@ void testUnsuccessExtra1() { @Test void testUnsuccessExtra2() { - Command command = new Command( - new LiteralCommandNode("hello", List.of( - new LiteralCommandNode("world", List.of()) - )) - ); + LiteralCommandNode worldNode = new LiteralCommandNode("world", List.of()); + LiteralCommandNode helloNode = new LiteralCommandNode("hello", List.of(worldNode)); + Command command = new Command(helloNode); - CommandContext.CommandNodeArguments arguments = command.getArguments(List.of("hello", "world", "a", "b")); - Assertions.assertNull(arguments); + CommandContext.CommandNodeArguments expected = new CommandContext.CommandNodeArguments( + List.of( + new CommandContext.CommandNodeArgument<>(helloNode, "hello", CommandResult.successful("hello")), + new CommandContext.CommandNodeArgument<>(worldNode, "world", CommandResult.successful("world")) + ), + new ExtraArgumentsResult<>("a"), + worldNode, + "world" + ); + CommandContext.CommandNodeArguments actual = command.getArguments(List.of("hello", "world", "a", "b")); + Assertions.assertEquals(expected, actual); } @Test void testUnsuccessExtra3() { - Command command = new Command( - new LiteralCommandNode("hello", List.of( - new LiteralCommandNode("world", List.of()) - )) - ); + LiteralCommandNode worldNode = new LiteralCommandNode("world", List.of()); + LiteralCommandNode helloNode = new LiteralCommandNode("hello", List.of(worldNode)); + Command command = new Command(helloNode); - CommandContext.CommandNodeArguments arguments = command.getArguments(List.of("hello", "world", "a", "b", "c")); - Assertions.assertNull(arguments); + CommandContext.CommandNodeArguments expected = new CommandContext.CommandNodeArguments( + List.of( + new CommandContext.CommandNodeArgument<>(helloNode, "hello", CommandResult.successful("hello")), + new CommandContext.CommandNodeArgument<>(worldNode, "world", CommandResult.successful("world")) + ), + new ExtraArgumentsResult<>("a"), + worldNode, + "world" + ); + CommandContext.CommandNodeArguments actual = command.getArguments(List.of("hello", "world", "a", "b", "c")); + Assertions.assertEquals(expected, actual); } @Test void testUnsuccessLess1() { - Command command = new Command( - new LiteralCommandNode("hello", List.of( - new LiteralCommandNode("world", List.of( - new LiteralCommandNode("a", List.of( - new LiteralCommandNode("b", List.of( - new LiteralCommandNode("c", List.of()) - )) - )) - )) - )) - ); + LiteralCommandNode cNode = new LiteralCommandNode("c", List.of()); + LiteralCommandNode bNode = new LiteralCommandNode("b", List.of(cNode)); + LiteralCommandNode aNode = new LiteralCommandNode("a", List.of(bNode)); + LiteralCommandNode worldNode = new LiteralCommandNode("world", List.of(aNode)); + LiteralCommandNode helloNode = new LiteralCommandNode("hello", List.of(worldNode)); + Command command = new Command(helloNode); - CommandContext.CommandNodeArguments arguments = command.getArguments(List.of("hello", "world", "a", "b")); - Assertions.assertNull(arguments); + CommandContext.CommandNodeArguments expected = new CommandContext.CommandNodeArguments( + List.of( + new CommandContext.CommandNodeArgument<>(helloNode, "hello", CommandResult.successful("hello")), + new CommandContext.CommandNodeArgument<>(worldNode, "world", CommandResult.successful("world")), + new CommandContext.CommandNodeArgument<>(aNode, "a", CommandResult.successful("a")), + new CommandContext.CommandNodeArgument<>(bNode, "b", CommandResult.successful("b")) + ), + new InsufficientArgumentsResult<>("b", bNode), + bNode, + "b" + ); + CommandContext.CommandNodeArguments actual = command.getArguments(List.of("hello", "world", "a", "b")); + Assertions.assertEquals(expected, actual); } @Test void testUnsuccessLess2() { - Command command = new Command( - new LiteralCommandNode("hello", List.of( - new LiteralCommandNode("world", List.of( - new LiteralCommandNode("a", List.of( - new LiteralCommandNode("b", List.of( - new LiteralCommandNode("c", List.of()) - )) - )) - )) - )) - ); + LiteralCommandNode cNode = new LiteralCommandNode("c", List.of()); + LiteralCommandNode bNode = new LiteralCommandNode("b", List.of(cNode)); + LiteralCommandNode aNode = new LiteralCommandNode("a", List.of(bNode)); + LiteralCommandNode worldNode = new LiteralCommandNode("world", List.of(aNode)); + LiteralCommandNode helloNode = new LiteralCommandNode("hello", List.of(worldNode)); + Command command = new Command(helloNode); - CommandContext.CommandNodeArguments arguments = command.getArguments(List.of("hello", "world", "a")); - Assertions.assertNull(arguments); + CommandContext.CommandNodeArguments expected = new CommandContext.CommandNodeArguments( + List.of( + new CommandContext.CommandNodeArgument<>(helloNode, "hello", CommandResult.successful("hello")), + new CommandContext.CommandNodeArgument<>(worldNode, "world", CommandResult.successful("world")), + new CommandContext.CommandNodeArgument<>(aNode, "a", CommandResult.successful("a")) + ), + new InsufficientArgumentsResult<>("a", aNode), + aNode, + "a" + ); + CommandContext.CommandNodeArguments actual = command.getArguments(List.of("hello", "world", "a")); + Assertions.assertEquals(expected, actual); } @Test void testUnsuccessLess3() { - Command command = new Command( - new LiteralCommandNode("hello", List.of( - new LiteralCommandNode("world", List.of( - new LiteralCommandNode("a", List.of( - new LiteralCommandNode("b", List.of( - new LiteralCommandNode("c", List.of()) - )) - )) - )) - )) - ); + LiteralCommandNode cNode = new LiteralCommandNode("c", List.of()); + LiteralCommandNode bNode = new LiteralCommandNode("b", List.of(cNode)); + LiteralCommandNode aNode = new LiteralCommandNode("a", List.of(bNode)); + LiteralCommandNode worldNode = new LiteralCommandNode("world", List.of(aNode)); + LiteralCommandNode helloNode = new LiteralCommandNode("hello", List.of(worldNode)); + Command command = new Command(helloNode); - CommandContext.CommandNodeArguments arguments = command.getArguments(List.of("hello", "world")); - Assertions.assertNull(arguments); + CommandContext.CommandNodeArguments expected = new CommandContext.CommandNodeArguments( + List.of( + new CommandContext.CommandNodeArgument<>(helloNode, "hello", CommandResult.successful("hello")), + new CommandContext.CommandNodeArgument<>(worldNode, "world", CommandResult.successful("world")) + ), + new InsufficientArgumentsResult<>("world", worldNode), + worldNode, + "world" + ); + CommandContext.CommandNodeArguments actual = command.getArguments(List.of("hello", "world")); + Assertions.assertEquals(expected, actual); } @Test void testUnsuccessLess4() { - Command command = new Command( - new LiteralCommandNode("hello", List.of( - new LiteralCommandNode("world", List.of( - new LiteralCommandNode("a", List.of( - new LiteralCommandNode("b", List.of( - new LiteralCommandNode("c", List.of()) - )) - )) - )) - )) - ); + LiteralCommandNode cNode = new LiteralCommandNode("c", List.of()); + LiteralCommandNode bNode = new LiteralCommandNode("b", List.of(cNode)); + LiteralCommandNode aNode = new LiteralCommandNode("a", List.of(bNode)); + LiteralCommandNode worldNode = new LiteralCommandNode("world", List.of(aNode)); + LiteralCommandNode helloNode = new LiteralCommandNode("hello", List.of(worldNode)); + Command command = new Command(helloNode); - CommandContext.CommandNodeArguments arguments = command.getArguments(List.of("hello")); - Assertions.assertNull(arguments); + CommandContext.CommandNodeArguments expected = new CommandContext.CommandNodeArguments( + List.of( + new CommandContext.CommandNodeArgument<>(helloNode, "hello", CommandResult.successful("hello")) + ), + new InsufficientArgumentsResult<>("hello", helloNode), + helloNode, + "hello" + ); + CommandContext.CommandNodeArguments actual = command.getArguments(List.of("hello")); + Assertions.assertEquals(expected, actual); } @Test @@ -163,7 +196,8 @@ void testUnsuccessLess5() { )) ); - CommandContext.CommandNodeArguments arguments = command.getArguments(List.of()); - Assertions.assertNull(arguments); + CommandContext.CommandNodeArguments expected = CommandContext.CommandNodeArguments.EMPTY; + CommandContext.CommandNodeArguments actual = command.getArguments(List.of()); + Assertions.assertEquals(expected, actual); } } From 674fd3ed99440dcd38aa4123e1030a6ef742ed57 Mon Sep 17 00:00:00 2001 From: WizardlyBump17 Date: Fri, 24 Oct 2025 19:23:49 -0300 Subject: [PATCH 027/363] NotNull --- .../wlib/command/rework/Command.java | 25 +++---------------- .../rework/context/CommandContext.java | 6 ++--- .../command/test/rework/NodeResultTests.java | 22 +++++++++------- 3 files changed, 18 insertions(+), 35 deletions(-) diff --git a/commands/src/main/java/com/wizardlybump17/wlib/command/rework/Command.java b/commands/src/main/java/com/wizardlybump17/wlib/command/rework/Command.java index 3719068d..3da8c926 100644 --- a/commands/src/main/java/com/wizardlybump17/wlib/command/rework/Command.java +++ b/commands/src/main/java/com/wizardlybump17/wlib/command/rework/Command.java @@ -31,9 +31,6 @@ public Command(@NotNull LiteralCommandNode root) { List strings = getInputList(execution); CommandContext.CommandNodeArguments arguments = getArguments(strings); - if (arguments == null) - return CommandResult.error(); - return CommandResult.successful(new Object()); } @@ -42,9 +39,9 @@ public Command(@NotNull LiteralCommandNode root) { } @SuppressWarnings("unchecked") - public @NotNull CommandContext.CommandNodeArguments getArguments(@NotNull List input) { + public @Nullable CommandContext.CommandNodeArguments getArguments(@NotNull List input) { if (input.isEmpty()) - return CommandContext.CommandNodeArguments.EMPTY; + return new CommandContext.CommandNodeArguments(Map.of(), new InsufficientArgumentsResult<>("", root), root, ""); Map> arguments = new LinkedHashMap<>(); @@ -72,7 +69,7 @@ public Command(@NotNull LiteralCommandNode root) { } CommandResult error; - if (lastNode.getChildren().isEmpty()) //TODO: just because the last node has no children that it means the input is an extra argument + if (lastNode.getChildren().isEmpty()) error = new ExtraArgumentsResult<>(inputString); else error = new InvalidArgumentResult<>((CommandNode) lastNode, lastResult); @@ -85,22 +82,6 @@ public Command(@NotNull LiteralCommandNode root) { return new CommandContext.CommandNodeArguments(arguments, lastResult, lastNode, lastInputString); } - public static @NotNull CommandResult getNodeResult(@NotNull CommandNode node, @NotNull String input) { - return node.parseOrInvalid(input); -// -// CommandResult parseResult = (CommandResult) node.parse(input); -// Object value = parseResult.data(); -// -// CommandContext.CommandNodeArgument argument = new CommandContext.CommandNodeArgument<>((CommandNode) node, input, parseResult); -// if (!parseResult.success()) -// return argument; -// -// if (!((CommandNode) node).isValidInput(value)) -// return argument; -// -// return argument; - } - public static @Nullable Command createCommand(@NotNull String execution) { LiteralCommandNode firstNode = null; diff --git a/commands/src/main/java/com/wizardlybump17/wlib/command/rework/context/CommandContext.java b/commands/src/main/java/com/wizardlybump17/wlib/command/rework/context/CommandContext.java index a5bac388..d25a760b 100644 --- a/commands/src/main/java/com/wizardlybump17/wlib/command/rework/context/CommandContext.java +++ b/commands/src/main/java/com/wizardlybump17/wlib/command/rework/context/CommandContext.java @@ -18,16 +18,14 @@ public record CommandNodeArgument(@NotNull CommandNode node, @NotNull Stri } } - public record CommandNodeArguments(@NotNull Map> arguments, @Nullable CommandResult lastResult, @Nullable CommandNode lastNode, @Nullable String lastInput) { - - public static @NotNull CommandNodeArguments EMPTY = new CommandNodeArguments(Map.of(), null, null, null); + public record CommandNodeArguments(@NotNull Map> arguments, @NotNull CommandResult lastResult, @NotNull CommandNode lastNode, @NotNull String lastInput) { public CommandNodeArguments { arguments = Collections.unmodifiableMap(arguments); } @SuppressWarnings("unchecked") - public CommandNodeArguments(@NotNull List> arguments, @Nullable CommandResult lastResult, @Nullable CommandNode lastNode, @Nullable String lastInput) { + public CommandNodeArguments(@NotNull List> arguments, @NotNull CommandResult lastResult, @NotNull CommandNode lastNode, @NotNull String lastInput) { this( Map.ofEntries(arguments.stream() .map(argument -> new AbstractMap.SimpleEntry<>(argument.node().getName(), argument)) diff --git a/commands/src/test/java/com/wizardlybump17/wlib/command/test/rework/NodeResultTests.java b/commands/src/test/java/com/wizardlybump17/wlib/command/test/rework/NodeResultTests.java index b6732227..125ecaac 100644 --- a/commands/src/test/java/com/wizardlybump17/wlib/command/test/rework/NodeResultTests.java +++ b/commands/src/test/java/com/wizardlybump17/wlib/command/test/rework/NodeResultTests.java @@ -184,19 +184,23 @@ void testUnsuccessLess4() { @Test void testUnsuccessLess5() { - Command command = new Command( - new LiteralCommandNode("hello", List.of( - new LiteralCommandNode("world", List.of( - new LiteralCommandNode("a", List.of( - new LiteralCommandNode("b", List.of( - new LiteralCommandNode("c", List.of()) - )) + LiteralCommandNode helloNode = new LiteralCommandNode("hello", List.of( + new LiteralCommandNode("world", List.of( + new LiteralCommandNode("a", List.of( + new LiteralCommandNode("b", List.of( + new LiteralCommandNode("c", List.of()) )) )) )) - ); + )); + Command command = new Command(helloNode); - CommandContext.CommandNodeArguments expected = CommandContext.CommandNodeArguments.EMPTY; + CommandContext.CommandNodeArguments expected = new CommandContext.CommandNodeArguments( + Map.of(), + new InsufficientArgumentsResult<>("", helloNode), + helloNode, + "" + ); CommandContext.CommandNodeArguments actual = command.getArguments(List.of()); Assertions.assertEquals(expected, actual); } From 9b842a5f88a25d5b0fcb5fc2084d5ac56fb92a76 Mon Sep 17 00:00:00 2001 From: WizardlyBump17 Date: Mon, 27 Oct 2025 16:52:58 -0300 Subject: [PATCH 028/363] checkpoint --- .../wlib/command/rework/Command.java | 66 +-- .../rework/context/CommandContext.java | 54 ++- .../exception/InputParsingException.java | 14 + .../exception/InvalidInputException.java | 14 + .../wlib/command/rework/node/CommandNode.java | 17 +- .../rework/node/IntegerCommandNode.java | 7 +- .../rework/node/LiteralCommandNode.java | 5 +- .../rework/result/ExtraArgumentsResult.java | 5 +- .../result/InsufficientArgumentsResult.java | 2 +- .../command/test/rework/NodeResultTests.java | 404 ++++++++++-------- 10 files changed, 325 insertions(+), 263 deletions(-) create mode 100644 commands/src/main/java/com/wizardlybump17/wlib/command/rework/exception/InputParsingException.java create mode 100644 commands/src/main/java/com/wizardlybump17/wlib/command/rework/exception/InvalidInputException.java diff --git a/commands/src/main/java/com/wizardlybump17/wlib/command/rework/Command.java b/commands/src/main/java/com/wizardlybump17/wlib/command/rework/Command.java index 3da8c926..718f83d7 100644 --- a/commands/src/main/java/com/wizardlybump17/wlib/command/rework/Command.java +++ b/commands/src/main/java/com/wizardlybump17/wlib/command/rework/Command.java @@ -1,6 +1,8 @@ package com.wizardlybump17.wlib.command.rework; import com.wizardlybump17.wlib.command.rework.context.CommandContext; +import com.wizardlybump17.wlib.command.rework.exception.InputParsingException; +import com.wizardlybump17.wlib.command.rework.exception.InvalidInputException; import com.wizardlybump17.wlib.command.rework.executor.CommandExecutor; import com.wizardlybump17.wlib.command.rework.node.CommandNode; import com.wizardlybump17.wlib.command.rework.node.LiteralCommandNode; @@ -13,7 +15,9 @@ import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.Nullable; -import java.util.*; +import java.util.ArrayList; +import java.util.List; +import java.util.Objects; public class Command { @@ -27,59 +31,55 @@ public Command(@NotNull LiteralCommandNode root) { return root; } - public @NotNull CommandResult execute(@NotNull CommandSender sender, @NotNull String execution) { - List strings = getInputList(execution); - CommandContext.CommandNodeArguments arguments = getArguments(strings); - - return CommandResult.successful(new Object()); - } - - public @NotNull List getInputList(@NotNull String original) { - return StringUtil.parseQuotedStrings(original); + public @NotNull CommandResult execute(@NotNull CommandSender sender, @NotNull String input) { + List inputList = getInputList(input); + return execute(sender, inputList); } @SuppressWarnings("unchecked") - public @Nullable CommandContext.CommandNodeArguments getArguments(@NotNull List input) { + public @NotNull CommandResult execute(@NotNull CommandSender sender, @NotNull List input) { if (input.isEmpty()) - return new CommandContext.CommandNodeArguments(Map.of(), new InsufficientArgumentsResult<>("", root), root, ""); - - Map> arguments = new LinkedHashMap<>(); + throw new IllegalArgumentException(); + List> arguments = new ArrayList<>(); List> children = List.of(root); CommandNode lastNode = null; - CommandResult lastResult = null; - String lastInputString = null; - inputLoop: for (String inputString : input) { - for (CommandNode child : children) { - lastNode = child; + int lastInputIndex = 0; - CommandResult result = child.parseOrInvalid(inputString); + inputLoop: for (int i = 0; i < input.size(); i++) { + String inputString = input.get(i); + lastInputIndex = i; - lastResult = result; - lastInputString = inputString; + for (CommandNode child : children) { + lastNode = child; - if (!result.success()) - continue; + try { + Object result = child.parseOrInvalid(inputString); - children = child.getChildren(); + arguments.add(new CommandContext.CommandNodeArgument<>((CommandNode) child, inputString, result)); - arguments.put(inputString, new CommandContext.CommandNodeArgument<>((CommandNode) child, inputString, (CommandResult) result)); - continue inputLoop; + children = child.getChildren(); + continue inputLoop; + } catch (InputParsingException | InvalidInputException ignored) { + ignored.toString(); + } } - CommandResult error; if (lastNode.getChildren().isEmpty()) - error = new ExtraArgumentsResult<>(inputString); + return new ExtraArgumentsResult<>(i); else - error = new InvalidArgumentResult<>((CommandNode) lastNode, lastResult); - return new CommandContext.CommandNodeArguments(arguments, error, lastNode, lastInputString); + return new InvalidArgumentResult<>((CommandNode) lastNode); } if (!lastNode.getChildren().isEmpty()) - return new CommandContext.CommandNodeArguments(arguments, new InsufficientArgumentsResult<>(lastInputString, lastNode), lastNode, lastInputString); + return new InsufficientArgumentsResult<>(lastInputIndex, lastNode); + + return CommandResult.successful(new Object()); + } - return new CommandContext.CommandNodeArguments(arguments, lastResult, lastNode, lastInputString); + public @NotNull List getInputList(@NotNull String original) { + return StringUtil.parseQuotedStrings(original); } public static @Nullable Command createCommand(@NotNull String execution) { diff --git a/commands/src/main/java/com/wizardlybump17/wlib/command/rework/context/CommandContext.java b/commands/src/main/java/com/wizardlybump17/wlib/command/rework/context/CommandContext.java index d25a760b..1c00f1a8 100644 --- a/commands/src/main/java/com/wizardlybump17/wlib/command/rework/context/CommandContext.java +++ b/commands/src/main/java/com/wizardlybump17/wlib/command/rework/context/CommandContext.java @@ -2,39 +2,31 @@ import com.wizardlybump17.wlib.command.rework.Command; import com.wizardlybump17.wlib.command.rework.node.CommandNode; -import com.wizardlybump17.wlib.command.rework.result.CommandResult; import com.wizardlybump17.wlib.command.sender.CommandSender; +import com.wizardlybump17.wlib.util.MapUtils; import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.Nullable; -import java.util.*; +import java.util.LinkedHashMap; +import java.util.List; +import java.util.Objects; +import java.util.Optional; public record CommandContext(@NotNull Command command, @NotNull CommandSender sender, @NotNull CommandNodeArguments arguments) { - public record CommandNodeArgument(@NotNull CommandNode node, @NotNull String input, @NotNull CommandResult result) { - - public @Nullable T data() { - return result.data(); - } + public record CommandNodeArgument(@NotNull CommandNode node, @NotNull String input, @Nullable T data) { } - public record CommandNodeArguments(@NotNull Map> arguments, @NotNull CommandResult lastResult, @NotNull CommandNode lastNode, @NotNull String lastInput) { + public static final class CommandNodeArguments { + + private final @NotNull LinkedHashMap> arguments; - public CommandNodeArguments { - arguments = Collections.unmodifiableMap(arguments); + private CommandNodeArguments(@NotNull LinkedHashMap> arguments) { + this.arguments = arguments; //CommandResult and ParseResult } - @SuppressWarnings("unchecked") - public CommandNodeArguments(@NotNull List> arguments, @NotNull CommandResult lastResult, @NotNull CommandNode lastNode, @NotNull String lastInput) { - this( - Map.ofEntries(arguments.stream() - .map(argument -> new AbstractMap.SimpleEntry<>(argument.node().getName(), argument)) - .toArray(Map.Entry[]::new) - ), - lastResult, - lastNode, - lastInput - ); + public CommandNodeArguments(@NotNull List> arguments) { + this((LinkedHashMap>) MapUtils.collectionToMap(LinkedHashMap::new, arguments, argument -> argument.node().getName())); } public boolean hasArgument(@NotNull String key) { @@ -45,5 +37,25 @@ public boolean hasArgument(@NotNull String key) { public @NotNull Optional> getArgument(@NotNull String key) { return Optional.ofNullable((CommandNodeArgument) arguments.get(key)); } + + @Override + public String toString() { + return "CommandNodeArguments{" + + "arguments=" + arguments + + '}'; + } + + @Override + public boolean equals(Object o) { + if (o == null || getClass() != o.getClass()) + return false; + CommandNodeArguments arguments1 = (CommandNodeArguments) o; + return Objects.equals(arguments, arguments1.arguments); + } + + @Override + public int hashCode() { + return Objects.hash(arguments); + } } } diff --git a/commands/src/main/java/com/wizardlybump17/wlib/command/rework/exception/InputParsingException.java b/commands/src/main/java/com/wizardlybump17/wlib/command/rework/exception/InputParsingException.java new file mode 100644 index 00000000..7b29a2aa --- /dev/null +++ b/commands/src/main/java/com/wizardlybump17/wlib/command/rework/exception/InputParsingException.java @@ -0,0 +1,14 @@ +package com.wizardlybump17.wlib.command.rework.exception; + +import org.jetbrains.annotations.NotNull; + +public class InputParsingException extends Exception { + + public InputParsingException(@NotNull String message) { + super(message); + } + + public InputParsingException(String message, Throwable cause) { + super(message, cause); + } +} diff --git a/commands/src/main/java/com/wizardlybump17/wlib/command/rework/exception/InvalidInputException.java b/commands/src/main/java/com/wizardlybump17/wlib/command/rework/exception/InvalidInputException.java new file mode 100644 index 00000000..97ffb499 --- /dev/null +++ b/commands/src/main/java/com/wizardlybump17/wlib/command/rework/exception/InvalidInputException.java @@ -0,0 +1,14 @@ +package com.wizardlybump17.wlib.command.rework.exception; + +import org.jetbrains.annotations.NotNull; + +public class InvalidInputException extends Exception { + + public InvalidInputException(@NotNull String message) { + super(message); + } + + public InvalidInputException(@NotNull String message, @NotNull Throwable cause) { + super(message, cause); + } +} diff --git a/commands/src/main/java/com/wizardlybump17/wlib/command/rework/node/CommandNode.java b/commands/src/main/java/com/wizardlybump17/wlib/command/rework/node/CommandNode.java index e6adc5e0..d3b27134 100644 --- a/commands/src/main/java/com/wizardlybump17/wlib/command/rework/node/CommandNode.java +++ b/commands/src/main/java/com/wizardlybump17/wlib/command/rework/node/CommandNode.java @@ -1,9 +1,9 @@ package com.wizardlybump17.wlib.command.rework.node; +import com.wizardlybump17.wlib.command.rework.exception.InputParsingException; +import com.wizardlybump17.wlib.command.rework.exception.InvalidInputException; import com.wizardlybump17.wlib.command.rework.executor.CommandExecutor; import com.wizardlybump17.wlib.command.rework.input.AllowedInputs; -import com.wizardlybump17.wlib.command.rework.result.CommandResult; -import com.wizardlybump17.wlib.command.rework.result.InvalidArgumentResult; import com.wizardlybump17.wlib.command.sender.CommandSender; import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.Nullable; @@ -43,18 +43,17 @@ public CommandNode(@NotNull String name, @NotNull List> children, return allowedInputs; } - public abstract @NotNull CommandResult parse(@NotNull String input); + public abstract @Nullable T parse(@NotNull String input) throws InputParsingException; public final boolean isValidInput(@Nullable T input) { return allowedInputs.isAllowed(input); } - public final @NotNull CommandResult parseOrInvalid(@NotNull String input) { - CommandResult parse = parse(input); - if (parse.success() && isValidInput(parse.data())) - return parse; - - return new InvalidArgumentResult<>(this, parse); + public final @Nullable T parseOrInvalid(@NotNull String input) throws InputParsingException, InvalidInputException { + T parse = parse(input); + if (!isValidInput(parse)) + throw new InvalidInputException("Invalid input " + input); + return parse; } public @NotNull List getSuggestions(@NotNull CommandSender sender, @NotNull List args, @NotNull String currentInput) { diff --git a/commands/src/main/java/com/wizardlybump17/wlib/command/rework/node/IntegerCommandNode.java b/commands/src/main/java/com/wizardlybump17/wlib/command/rework/node/IntegerCommandNode.java index 40cfd2af..c0d9d20f 100644 --- a/commands/src/main/java/com/wizardlybump17/wlib/command/rework/node/IntegerCommandNode.java +++ b/commands/src/main/java/com/wizardlybump17/wlib/command/rework/node/IntegerCommandNode.java @@ -3,7 +3,6 @@ import com.wizardlybump17.wlib.command.rework.executor.CommandExecutor; import com.wizardlybump17.wlib.command.rework.input.AllowedNumberInputs; import com.wizardlybump17.wlib.command.rework.input.RangedAllowedInputs; -import com.wizardlybump17.wlib.command.rework.result.CommandResult; import com.wizardlybump17.wlib.command.sender.CommandSender; import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.Nullable; @@ -23,11 +22,11 @@ public IntegerCommandNode(@NotNull String name, @NotNull List> ch } @Override - public @NotNull CommandResult parse(@NotNull String input) { + public @NotNull Integer parse(@NotNull String input) { try { - return CommandResult.successful(Integer.parseInt(input)); + return Integer.parseInt(input); } catch (NumberFormatException e) { - return CommandResult.exceptionally(e); + throw new IllegalArgumentException("Could not parse as int: " + input, e); } } diff --git a/commands/src/main/java/com/wizardlybump17/wlib/command/rework/node/LiteralCommandNode.java b/commands/src/main/java/com/wizardlybump17/wlib/command/rework/node/LiteralCommandNode.java index 269d5191..8fc3aa45 100644 --- a/commands/src/main/java/com/wizardlybump17/wlib/command/rework/node/LiteralCommandNode.java +++ b/commands/src/main/java/com/wizardlybump17/wlib/command/rework/node/LiteralCommandNode.java @@ -2,7 +2,6 @@ import com.wizardlybump17.wlib.command.rework.executor.CommandExecutor; import com.wizardlybump17.wlib.command.rework.input.LiteralAllowedInput; -import com.wizardlybump17.wlib.command.rework.result.CommandResult; import com.wizardlybump17.wlib.command.sender.CommandSender; import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.Nullable; @@ -25,8 +24,8 @@ public LiteralCommandNode(@NotNull String name, @NotNull List> ch } @Override - public @NotNull CommandResult parse(@NotNull String input) { - return CommandResult.successful(input); + public @NotNull String parse(@NotNull String input) { + return input; } @Override diff --git a/commands/src/main/java/com/wizardlybump17/wlib/command/rework/result/ExtraArgumentsResult.java b/commands/src/main/java/com/wizardlybump17/wlib/command/rework/result/ExtraArgumentsResult.java index fc8eb4fe..4c959504 100644 --- a/commands/src/main/java/com/wizardlybump17/wlib/command/rework/result/ExtraArgumentsResult.java +++ b/commands/src/main/java/com/wizardlybump17/wlib/command/rework/result/ExtraArgumentsResult.java @@ -1,15 +1,16 @@ package com.wizardlybump17.wlib.command.rework.result; -import org.jetbrains.annotations.NotNull; +import org.jetbrains.annotations.Contract; import org.jetbrains.annotations.Nullable; -public record ExtraArgumentsResult(@NotNull String extra) implements CommandResult { +public record ExtraArgumentsResult(int index) implements CommandResult { @Override public boolean success() { return false; } + @Contract("-> null") @Override public @Nullable T data() { return null; diff --git a/commands/src/main/java/com/wizardlybump17/wlib/command/rework/result/InsufficientArgumentsResult.java b/commands/src/main/java/com/wizardlybump17/wlib/command/rework/result/InsufficientArgumentsResult.java index ff082002..71d66c64 100644 --- a/commands/src/main/java/com/wizardlybump17/wlib/command/rework/result/InsufficientArgumentsResult.java +++ b/commands/src/main/java/com/wizardlybump17/wlib/command/rework/result/InsufficientArgumentsResult.java @@ -4,7 +4,7 @@ import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.Nullable; -public record InsufficientArgumentsResult(@NotNull String lastInput, @NotNull CommandNode node) implements CommandResult { +public record InsufficientArgumentsResult(int index, @NotNull CommandNode node) implements CommandResult { @Override public boolean success() { diff --git a/commands/src/test/java/com/wizardlybump17/wlib/command/test/rework/NodeResultTests.java b/commands/src/test/java/com/wizardlybump17/wlib/command/test/rework/NodeResultTests.java index 125ecaac..c2ad53c9 100644 --- a/commands/src/test/java/com/wizardlybump17/wlib/command/test/rework/NodeResultTests.java +++ b/commands/src/test/java/com/wizardlybump17/wlib/command/test/rework/NodeResultTests.java @@ -1,207 +1,231 @@ package com.wizardlybump17.wlib.command.test.rework; import com.wizardlybump17.wlib.command.rework.Command; -import com.wizardlybump17.wlib.command.rework.context.CommandContext; import com.wizardlybump17.wlib.command.rework.node.LiteralCommandNode; import com.wizardlybump17.wlib.command.rework.result.CommandResult; -import com.wizardlybump17.wlib.command.rework.result.ExtraArgumentsResult; -import com.wizardlybump17.wlib.command.rework.result.InsufficientArgumentsResult; -import com.wizardlybump17.wlib.command.rework.result.SuccessResult; -import org.junit.jupiter.api.Assertions; import org.junit.jupiter.api.Test; import java.util.List; -import java.util.Map; class NodeResultTests { @Test - void testSuccess() { - LiteralCommandNode world = new LiteralCommandNode("world", List.of()); - LiteralCommandNode hello = new LiteralCommandNode("hello", List.of(world)); - Command command = new Command(hello); - - SuccessResult worldResult = CommandResult.successful("world"); - CommandContext.CommandNodeArguments expected = new CommandContext.CommandNodeArguments( - Map.of( - "hello", new CommandContext.CommandNodeArgument<>(hello, "hello", CommandResult.successful("hello")), - "world", new CommandContext.CommandNodeArgument<>(world, "world", worldResult) - ), - worldResult, - world, - "world" - ); - CommandContext.CommandNodeArguments actual = command.getArguments(List.of("hello", "world")); - Assertions.assertEquals(expected, actual); - } - - @Test - void testUnsuccessExtra1() { - LiteralCommandNode worldNode = new LiteralCommandNode("world", List.of()); - LiteralCommandNode helloNode = new LiteralCommandNode("hello", List.of(worldNode)); - Command command = new Command(helloNode); - - CommandContext.CommandNodeArguments expected = new CommandContext.CommandNodeArguments( - List.of( - new CommandContext.CommandNodeArgument<>(helloNode, "hello", CommandResult.successful("hello")), - new CommandContext.CommandNodeArgument<>(worldNode, "world", CommandResult.successful("world")) - ), - new ExtraArgumentsResult<>("a"), - worldNode, - "world" - ); - CommandContext.CommandNodeArguments actual = command.getArguments(List.of("hello", "world", "a")); - Assertions.assertEquals(expected, actual); - } - - @Test - void testUnsuccessExtra2() { - LiteralCommandNode worldNode = new LiteralCommandNode("world", List.of()); - LiteralCommandNode helloNode = new LiteralCommandNode("hello", List.of(worldNode)); - Command command = new Command(helloNode); - - CommandContext.CommandNodeArguments expected = new CommandContext.CommandNodeArguments( - List.of( - new CommandContext.CommandNodeArgument<>(helloNode, "hello", CommandResult.successful("hello")), - new CommandContext.CommandNodeArgument<>(worldNode, "world", CommandResult.successful("world")) - ), - new ExtraArgumentsResult<>("a"), - worldNode, - "world" - ); - CommandContext.CommandNodeArguments actual = command.getArguments(List.of("hello", "world", "a", "b")); - Assertions.assertEquals(expected, actual); - } - - @Test - void testUnsuccessExtra3() { - LiteralCommandNode worldNode = new LiteralCommandNode("world", List.of()); - LiteralCommandNode helloNode = new LiteralCommandNode("hello", List.of(worldNode)); - Command command = new Command(helloNode); - - CommandContext.CommandNodeArguments expected = new CommandContext.CommandNodeArguments( - List.of( - new CommandContext.CommandNodeArgument<>(helloNode, "hello", CommandResult.successful("hello")), - new CommandContext.CommandNodeArgument<>(worldNode, "world", CommandResult.successful("world")) - ), - new ExtraArgumentsResult<>("a"), - worldNode, - "world" - ); - CommandContext.CommandNodeArguments actual = command.getArguments(List.of("hello", "world", "a", "b", "c")); - Assertions.assertEquals(expected, actual); - } - - @Test - void testUnsuccessLess1() { - LiteralCommandNode cNode = new LiteralCommandNode("c", List.of()); - LiteralCommandNode bNode = new LiteralCommandNode("b", List.of(cNode)); - LiteralCommandNode aNode = new LiteralCommandNode("a", List.of(bNode)); - LiteralCommandNode worldNode = new LiteralCommandNode("world", List.of(aNode)); - LiteralCommandNode helloNode = new LiteralCommandNode("hello", List.of(worldNode)); - Command command = new Command(helloNode); - - CommandContext.CommandNodeArguments expected = new CommandContext.CommandNodeArguments( - List.of( - new CommandContext.CommandNodeArgument<>(helloNode, "hello", CommandResult.successful("hello")), - new CommandContext.CommandNodeArgument<>(worldNode, "world", CommandResult.successful("world")), - new CommandContext.CommandNodeArgument<>(aNode, "a", CommandResult.successful("a")), - new CommandContext.CommandNodeArgument<>(bNode, "b", CommandResult.successful("b")) - ), - new InsufficientArgumentsResult<>("b", bNode), - bNode, - "b" - ); - CommandContext.CommandNodeArguments actual = command.getArguments(List.of("hello", "world", "a", "b")); - Assertions.assertEquals(expected, actual); - } - - @Test - void testUnsuccessLess2() { - LiteralCommandNode cNode = new LiteralCommandNode("c", List.of()); - LiteralCommandNode bNode = new LiteralCommandNode("b", List.of(cNode)); - LiteralCommandNode aNode = new LiteralCommandNode("a", List.of(bNode)); - LiteralCommandNode worldNode = new LiteralCommandNode("world", List.of(aNode)); - LiteralCommandNode helloNode = new LiteralCommandNode("hello", List.of(worldNode)); - Command command = new Command(helloNode); - - CommandContext.CommandNodeArguments expected = new CommandContext.CommandNodeArguments( - List.of( - new CommandContext.CommandNodeArgument<>(helloNode, "hello", CommandResult.successful("hello")), - new CommandContext.CommandNodeArgument<>(worldNode, "world", CommandResult.successful("world")), - new CommandContext.CommandNodeArgument<>(aNode, "a", CommandResult.successful("a")) - ), - new InsufficientArgumentsResult<>("a", aNode), - aNode, - "a" - ); - CommandContext.CommandNodeArguments actual = command.getArguments(List.of("hello", "world", "a")); - Assertions.assertEquals(expected, actual); - } - - @Test - void testUnsuccessLess3() { - LiteralCommandNode cNode = new LiteralCommandNode("c", List.of()); - LiteralCommandNode bNode = new LiteralCommandNode("b", List.of(cNode)); - LiteralCommandNode aNode = new LiteralCommandNode("a", List.of(bNode)); - LiteralCommandNode worldNode = new LiteralCommandNode("world", List.of(aNode)); - LiteralCommandNode helloNode = new LiteralCommandNode("hello", List.of(worldNode)); - Command command = new Command(helloNode); - - CommandContext.CommandNodeArguments expected = new CommandContext.CommandNodeArguments( - List.of( - new CommandContext.CommandNodeArgument<>(helloNode, "hello", CommandResult.successful("hello")), - new CommandContext.CommandNodeArgument<>(worldNode, "world", CommandResult.successful("world")) - ), - new InsufficientArgumentsResult<>("world", worldNode), - worldNode, - "world" - ); - CommandContext.CommandNodeArguments actual = command.getArguments(List.of("hello", "world")); - Assertions.assertEquals(expected, actual); - } - - @Test - void testUnsuccessLess4() { - LiteralCommandNode cNode = new LiteralCommandNode("c", List.of()); - LiteralCommandNode bNode = new LiteralCommandNode("b", List.of(cNode)); - LiteralCommandNode aNode = new LiteralCommandNode("a", List.of(bNode)); - LiteralCommandNode worldNode = new LiteralCommandNode("world", List.of(aNode)); - LiteralCommandNode helloNode = new LiteralCommandNode("hello", List.of(worldNode)); - Command command = new Command(helloNode); - - CommandContext.CommandNodeArguments expected = new CommandContext.CommandNodeArguments( - List.of( - new CommandContext.CommandNodeArgument<>(helloNode, "hello", CommandResult.successful("hello")) - ), - new InsufficientArgumentsResult<>("hello", helloNode), - helloNode, - "hello" - ); - CommandContext.CommandNodeArguments actual = command.getArguments(List.of("hello")); - Assertions.assertEquals(expected, actual); - } - - @Test - void testUnsuccessLess5() { - LiteralCommandNode helloNode = new LiteralCommandNode("hello", List.of( - new LiteralCommandNode("world", List.of( - new LiteralCommandNode("a", List.of( - new LiteralCommandNode("b", List.of( - new LiteralCommandNode("c", List.of()) - )) + void test() { + Command command = new Command( + new LiteralCommandNode("hello", List.of( + new LiteralCommandNode("world", List.of( + new LiteralCommandNode("a1", List.of()) )) )) - )); - Command command = new Command(helloNode); - - CommandContext.CommandNodeArguments expected = new CommandContext.CommandNodeArguments( - Map.of(), - new InsufficientArgumentsResult<>("", helloNode), - helloNode, - "" ); - CommandContext.CommandNodeArguments actual = command.getArguments(List.of()); - Assertions.assertEquals(expected, actual); + + CommandResult result = command.execute(null, List.of("hello", "world", "a", "b")); + System.out.println(result); } + +// @Test +// void testSuccess() { +// LiteralCommandNode world = new LiteralCommandNode("world", List.of()); +// LiteralCommandNode hello = new LiteralCommandNode("hello", List.of(world)); +// Command command = new Command(hello); +// +// SuccessResult worldResult = CommandResult.successful("world"); +// CommandContext.CommandNodeArguments expected = new CommandContext.CommandNodeArguments( +// List.of( +// new CommandContext.CommandNodeArgument<>(hello, "hello", null), +// new CommandContext.CommandNodeArgument<>(world, "world", null) +// ) +// ); +// CommandContext.CommandNodeArguments actual = command.execute(null, List.of("hello", "world")); +// Assertions.assertEquals(expected, actual); +// } +// +// @Test +// void testUnsuccessExtra1() { +// LiteralCommandNode worldNode = new LiteralCommandNode("world", List.of()); +// LiteralCommandNode helloNode = new LiteralCommandNode("hello", List.of(worldNode)); +// Command command = new Command(helloNode); +// +// CommandContext.CommandNodeArguments expected = new CommandContext.CommandNodeArguments( +// List.of( +// new CommandContext.CommandNodeArgument<>(helloNode, "hello", CommandResult.successful("hello")), +// new CommandContext.CommandNodeArgument<>(worldNode, "world", CommandResult.successful("world")) +// ), +// new ExtraArgumentsResult<>("a"), +// worldNode, +// "world" +// ); +// CommandContext.CommandNodeArguments actual = command.getArguments(List.of("hello", "world", "a")); +// Assertions.assertEquals(expected, actual); +// } +// +// @Test +// void testUnsuccessExtra2() { +// LiteralCommandNode worldNode = new LiteralCommandNode("world", List.of()); +// LiteralCommandNode helloNode = new LiteralCommandNode("hello", List.of(worldNode)); +// Command command = new Command(helloNode); +// +// CommandContext.CommandNodeArguments expected = new CommandContext.CommandNodeArguments( +// List.of( +// new CommandContext.CommandNodeArgument<>(helloNode, "hello", CommandResult.successful("hello")), +// new CommandContext.CommandNodeArgument<>(worldNode, "world", CommandResult.successful("world")) +// ), +// new ExtraArgumentsResult<>("a"), +// worldNode, +// "world" +// ); +// CommandContext.CommandNodeArguments actual = command.getArguments(List.of("hello", "world", "a", "b")); +// Assertions.assertEquals(expected, actual); +// } +// +// @Test +// void testUnsuccessExtra3() { +// LiteralCommandNode worldNode = new LiteralCommandNode("world", List.of()); +// LiteralCommandNode helloNode = new LiteralCommandNode("hello", List.of(worldNode)); +// Command command = new Command(helloNode); +// +// CommandContext.CommandNodeArguments expected = new CommandContext.CommandNodeArguments( +// List.of( +// new CommandContext.CommandNodeArgument<>(helloNode, "hello", CommandResult.successful("hello")), +// new CommandContext.CommandNodeArgument<>(worldNode, "world", CommandResult.successful("world")) +// ), +// new ExtraArgumentsResult<>("a"), +// worldNode, +// "world" +// ); +// CommandContext.CommandNodeArguments actual = command.getArguments(List.of("hello", "world", "a", "b", "c")); +// Assertions.assertEquals(expected, actual); +// } +// +// @Test +// void testUnsuccessLess1() { +// LiteralCommandNode cNode = new LiteralCommandNode("c", List.of()); +// LiteralCommandNode bNode = new LiteralCommandNode("b", List.of(cNode)); +// LiteralCommandNode aNode = new LiteralCommandNode("a", List.of(bNode)); +// LiteralCommandNode worldNode = new LiteralCommandNode("world", List.of(aNode)); +// LiteralCommandNode helloNode = new LiteralCommandNode("hello", List.of(worldNode)); +// Command command = new Command(helloNode); +// +// CommandContext.CommandNodeArguments expected = new CommandContext.CommandNodeArguments( +// List.of( +// new CommandContext.CommandNodeArgument<>(helloNode, "hello", CommandResult.successful("hello")), +// new CommandContext.CommandNodeArgument<>(worldNode, "world", CommandResult.successful("world")), +// new CommandContext.CommandNodeArgument<>(aNode, "a", CommandResult.successful("a")), +// new CommandContext.CommandNodeArgument<>(bNode, "b", CommandResult.successful("b")) +// ), +// new InsufficientArgumentsResult<>("b", bNode), +// bNode, +// "b" +// ); +// CommandContext.CommandNodeArguments actual = command.getArguments(List.of("hello", "world", "a", "b")); +// Assertions.assertEquals(expected, actual); +// } +// +// @Test +// void testUnsuccessLess2() { +// LiteralCommandNode cNode = new LiteralCommandNode("c", List.of()); +// LiteralCommandNode bNode = new LiteralCommandNode("b", List.of(cNode)); +// LiteralCommandNode aNode = new LiteralCommandNode("a", List.of(bNode)); +// LiteralCommandNode worldNode = new LiteralCommandNode("world", List.of(aNode)); +// LiteralCommandNode helloNode = new LiteralCommandNode("hello", List.of(worldNode)); +// Command command = new Command(helloNode); +// +// CommandContext.CommandNodeArguments expected = new CommandContext.CommandNodeArguments( +// List.of( +// new CommandContext.CommandNodeArgument<>(helloNode, "hello", CommandResult.successful("hello")), +// new CommandContext.CommandNodeArgument<>(worldNode, "world", CommandResult.successful("world")), +// new CommandContext.CommandNodeArgument<>(aNode, "a", CommandResult.successful("a")) +// ), +// new InsufficientArgumentsResult<>("a", aNode), +// aNode, +// "a" +// ); +// CommandContext.CommandNodeArguments actual = command.getArguments(List.of("hello", "world", "a")); +// Assertions.assertEquals(expected, actual); +// } +// +// @Test +// void testUnsuccessLess3() { +// LiteralCommandNode cNode = new LiteralCommandNode("c", List.of()); +// LiteralCommandNode bNode = new LiteralCommandNode("b", List.of(cNode)); +// LiteralCommandNode aNode = new LiteralCommandNode("a", List.of(bNode)); +// LiteralCommandNode worldNode = new LiteralCommandNode("world", List.of(aNode)); +// LiteralCommandNode helloNode = new LiteralCommandNode("hello", List.of(worldNode)); +// Command command = new Command(helloNode); +// +// CommandContext.CommandNodeArguments expected = new CommandContext.CommandNodeArguments( +// List.of( +// new CommandContext.CommandNodeArgument<>(helloNode, "hello", CommandResult.successful("hello")), +// new CommandContext.CommandNodeArgument<>(worldNode, "world", CommandResult.successful("world")) +// ), +// new InsufficientArgumentsResult<>("world", worldNode), +// worldNode, +// "world" +// ); +// CommandContext.CommandNodeArguments actual = command.getArguments(List.of("hello", "world")); +// Assertions.assertEquals(expected, actual); +// } +// +// @Test +// void testUnsuccessLess4() { +// LiteralCommandNode cNode = new LiteralCommandNode("c", List.of()); +// LiteralCommandNode bNode = new LiteralCommandNode("b", List.of(cNode)); +// LiteralCommandNode aNode = new LiteralCommandNode("a", List.of(bNode)); +// LiteralCommandNode worldNode = new LiteralCommandNode("world", List.of(aNode)); +// LiteralCommandNode helloNode = new LiteralCommandNode("hello", List.of(worldNode)); +// Command command = new Command(helloNode); +// +// CommandContext.CommandNodeArguments expected = new CommandContext.CommandNodeArguments( +// List.of( +// new CommandContext.CommandNodeArgument<>(helloNode, "hello", CommandResult.successful("hello")) +// ), +// new InsufficientArgumentsResult<>("hello", helloNode), +// helloNode, +// "hello" +// ); +// CommandContext.CommandNodeArguments actual = command.getArguments(List.of("hello")); +// Assertions.assertEquals(expected, actual); +// } +// +// @Test +// void testUnsuccessLess5() { +// LiteralCommandNode helloNode = new LiteralCommandNode("hello", List.of( +// new LiteralCommandNode("world", List.of( +// new LiteralCommandNode("a", List.of( +// new LiteralCommandNode("b", List.of( +// new LiteralCommandNode("c", List.of()) +// )) +// )) +// )) +// )); +// Command command = new Command(helloNode); +// +// CommandContext.CommandNodeArguments expected = new CommandContext.CommandNodeArguments( +// Map.of(), +// new InsufficientArgumentsResult<>("", helloNode), +// helloNode, +// "" +// ); +// CommandContext.CommandNodeArguments actual = command.getArguments(List.of()); +// Assertions.assertEquals(expected, actual); +// } +// +// @Test +// void testSuccessMultipleChildren0() { +// Command command = new Command( +// new LiteralCommandNode("hello", List.of( +// new LiteralCommandNode("world2", List.of( +// new LiteralCommandNode("world3", List.of()), +// new LiteralCommandNode("world4", List.of()) +// )), +// new LiteralCommandNode("world1", List.of( +// new LiteralCommandNode("world3", List.of()) +// )), +// new LiteralCommandNode("world", List.of()) +// )) +// ); +// +// CommandContext.CommandNodeArguments actual = command.getArguments(List.of("hello", "world2", "world3", "a")); +// Assertions.assertInstanceOf(ExtraArgumentsResult.class, actual.lastResult()); +// } } From 81670e1a0daa26d956a657abe35c82903bf5f386 Mon Sep 17 00:00:00 2001 From: WizardlyBump17 Date: Mon, 27 Oct 2025 20:33:29 -0300 Subject: [PATCH 029/363] checkpoint 2 --- .../wlib/command/rework/Command.java | 18 +++++++++----- .../rework/node/IntegerCommandNode.java | 5 ++-- .../rework/result/UnsuccessResult.java | 24 +++++++++++++++++++ .../command/test/rework/NodeResultTests.java | 6 +++-- 4 files changed, 43 insertions(+), 10 deletions(-) create mode 100644 commands/src/main/java/com/wizardlybump17/wlib/command/rework/result/UnsuccessResult.java diff --git a/commands/src/main/java/com/wizardlybump17/wlib/command/rework/Command.java b/commands/src/main/java/com/wizardlybump17/wlib/command/rework/Command.java index 718f83d7..ec15dfa2 100644 --- a/commands/src/main/java/com/wizardlybump17/wlib/command/rework/Command.java +++ b/commands/src/main/java/com/wizardlybump17/wlib/command/rework/Command.java @@ -6,10 +6,7 @@ import com.wizardlybump17.wlib.command.rework.executor.CommandExecutor; import com.wizardlybump17.wlib.command.rework.node.CommandNode; import com.wizardlybump17.wlib.command.rework.node.LiteralCommandNode; -import com.wizardlybump17.wlib.command.rework.result.CommandResult; -import com.wizardlybump17.wlib.command.rework.result.ExtraArgumentsResult; -import com.wizardlybump17.wlib.command.rework.result.InsufficientArgumentsResult; -import com.wizardlybump17.wlib.command.rework.result.InvalidArgumentResult; +import com.wizardlybump17.wlib.command.rework.result.*; import com.wizardlybump17.wlib.command.sender.CommandSender; import com.wizardlybump17.wlib.util.StringUtil; import org.jetbrains.annotations.NotNull; @@ -46,6 +43,8 @@ public Command(@NotNull LiteralCommandNode root) { CommandNode lastNode = null; int lastInputIndex = 0; + InputParsingException lastParsingError = null; + InvalidInputException lastInputError = null; inputLoop: for (int i = 0; i < input.size(); i++) { String inputString = input.get(i); @@ -61,11 +60,18 @@ public Command(@NotNull LiteralCommandNode root) { children = child.getChildren(); continue inputLoop; - } catch (InputParsingException | InvalidInputException ignored) { - ignored.toString(); + } catch (InputParsingException e) { + lastParsingError = e; + } catch (InvalidInputException e) { + lastInputError = e; } } + if (lastParsingError != null) + return new ExceptionResult<>(lastParsingError); + if (lastInputError != null) + return new InvalidArgumentResult<>((CommandNode) lastNode); + if (lastNode.getChildren().isEmpty()) return new ExtraArgumentsResult<>(i); else diff --git a/commands/src/main/java/com/wizardlybump17/wlib/command/rework/node/IntegerCommandNode.java b/commands/src/main/java/com/wizardlybump17/wlib/command/rework/node/IntegerCommandNode.java index c0d9d20f..db01d132 100644 --- a/commands/src/main/java/com/wizardlybump17/wlib/command/rework/node/IntegerCommandNode.java +++ b/commands/src/main/java/com/wizardlybump17/wlib/command/rework/node/IntegerCommandNode.java @@ -1,5 +1,6 @@ package com.wizardlybump17.wlib.command.rework.node; +import com.wizardlybump17.wlib.command.rework.exception.InputParsingException; import com.wizardlybump17.wlib.command.rework.executor.CommandExecutor; import com.wizardlybump17.wlib.command.rework.input.AllowedNumberInputs; import com.wizardlybump17.wlib.command.rework.input.RangedAllowedInputs; @@ -22,11 +23,11 @@ public IntegerCommandNode(@NotNull String name, @NotNull List> ch } @Override - public @NotNull Integer parse(@NotNull String input) { + public @NotNull Integer parse(@NotNull String input) throws InputParsingException { try { return Integer.parseInt(input); } catch (NumberFormatException e) { - throw new IllegalArgumentException("Could not parse as int: " + input, e); + throw new InputParsingException("Could not parse as int: " + input, e); } } diff --git a/commands/src/main/java/com/wizardlybump17/wlib/command/rework/result/UnsuccessResult.java b/commands/src/main/java/com/wizardlybump17/wlib/command/rework/result/UnsuccessResult.java new file mode 100644 index 00000000..8dcdcea8 --- /dev/null +++ b/commands/src/main/java/com/wizardlybump17/wlib/command/rework/result/UnsuccessResult.java @@ -0,0 +1,24 @@ +package com.wizardlybump17.wlib.command.rework.result; + +import com.wizardlybump17.wlib.command.rework.node.CommandNode; +import org.jetbrains.annotations.Contract; +import org.jetbrains.annotations.NotNull; +import org.jetbrains.annotations.Nullable; + +public interface UnsuccessResult extends CommandResult { + + @Override + default boolean success() { + return false; + } + + @Contract("-> null") + @Override + default @Nullable T data() { + return null; + } + + int lastInputIndex(); + + @NotNull CommandNode lastNode(); +} diff --git a/commands/src/test/java/com/wizardlybump17/wlib/command/test/rework/NodeResultTests.java b/commands/src/test/java/com/wizardlybump17/wlib/command/test/rework/NodeResultTests.java index c2ad53c9..897d3f82 100644 --- a/commands/src/test/java/com/wizardlybump17/wlib/command/test/rework/NodeResultTests.java +++ b/commands/src/test/java/com/wizardlybump17/wlib/command/test/rework/NodeResultTests.java @@ -1,6 +1,8 @@ package com.wizardlybump17.wlib.command.test.rework; import com.wizardlybump17.wlib.command.rework.Command; +import com.wizardlybump17.wlib.command.rework.input.AllowedNumberInputs; +import com.wizardlybump17.wlib.command.rework.node.IntegerCommandNode; import com.wizardlybump17.wlib.command.rework.node.LiteralCommandNode; import com.wizardlybump17.wlib.command.rework.result.CommandResult; import org.junit.jupiter.api.Test; @@ -14,12 +16,12 @@ void test() { Command command = new Command( new LiteralCommandNode("hello", List.of( new LiteralCommandNode("world", List.of( - new LiteralCommandNode("a1", List.of()) + new IntegerCommandNode("a1", List.of(), new AllowedNumberInputs.AllowedIntegerInputs.Range(10, 100), null) )) )) ); - CommandResult result = command.execute(null, List.of("hello", "world", "a", "b")); + CommandResult result = command.execute(null, List.of("hello", "world", "10", "b")); System.out.println(result); } From 8a3ccfaf70462fb24525f340800adce0f97305e3 Mon Sep 17 00:00:00 2001 From: WizardlyBump17 Date: Mon, 27 Oct 2025 20:42:21 -0300 Subject: [PATCH 030/363] improved the CommandResult system --- .../wlib/command/rework/Command.java | 6 ++- .../command/rework/result/CommandResult.java | 32 ++++++------- .../rework/result/ExceptionResult.java | 17 ------- .../rework/result/ExtraArgumentsResult.java | 18 ------- .../rework/result/GenericErrorResult.java | 23 --------- .../result/InsufficientArgumentsResult.java | 18 ------- .../rework/result/InvalidArgumentResult.java | 48 ------------------- .../command/rework/result/SuccessResult.java | 4 +- .../result/error/AbstractUnsuccessResult.java | 36 ++++++++++++++ .../rework/result/error/ExceptionResult.java | 18 +++++++ .../result/error/ExtraArgumentsResult.java | 11 +++++ .../error/InsufficientArgumentsResult.java | 11 +++++ .../result/error/InvalidArgumentResult.java | 11 +++++ .../result/{ => error}/UnsuccessResult.java | 9 +--- 14 files changed, 113 insertions(+), 149 deletions(-) delete mode 100644 commands/src/main/java/com/wizardlybump17/wlib/command/rework/result/ExceptionResult.java delete mode 100644 commands/src/main/java/com/wizardlybump17/wlib/command/rework/result/ExtraArgumentsResult.java delete mode 100644 commands/src/main/java/com/wizardlybump17/wlib/command/rework/result/GenericErrorResult.java delete mode 100644 commands/src/main/java/com/wizardlybump17/wlib/command/rework/result/InsufficientArgumentsResult.java delete mode 100644 commands/src/main/java/com/wizardlybump17/wlib/command/rework/result/InvalidArgumentResult.java create mode 100644 commands/src/main/java/com/wizardlybump17/wlib/command/rework/result/error/AbstractUnsuccessResult.java create mode 100644 commands/src/main/java/com/wizardlybump17/wlib/command/rework/result/error/ExceptionResult.java create mode 100644 commands/src/main/java/com/wizardlybump17/wlib/command/rework/result/error/ExtraArgumentsResult.java create mode 100644 commands/src/main/java/com/wizardlybump17/wlib/command/rework/result/error/InsufficientArgumentsResult.java create mode 100644 commands/src/main/java/com/wizardlybump17/wlib/command/rework/result/error/InvalidArgumentResult.java rename commands/src/main/java/com/wizardlybump17/wlib/command/rework/result/{ => error}/UnsuccessResult.java (58%) diff --git a/commands/src/main/java/com/wizardlybump17/wlib/command/rework/Command.java b/commands/src/main/java/com/wizardlybump17/wlib/command/rework/Command.java index ec15dfa2..1d660789 100644 --- a/commands/src/main/java/com/wizardlybump17/wlib/command/rework/Command.java +++ b/commands/src/main/java/com/wizardlybump17/wlib/command/rework/Command.java @@ -6,7 +6,11 @@ import com.wizardlybump17.wlib.command.rework.executor.CommandExecutor; import com.wizardlybump17.wlib.command.rework.node.CommandNode; import com.wizardlybump17.wlib.command.rework.node.LiteralCommandNode; -import com.wizardlybump17.wlib.command.rework.result.*; +import com.wizardlybump17.wlib.command.rework.result.CommandResult; +import com.wizardlybump17.wlib.command.rework.result.error.ExceptionResult; +import com.wizardlybump17.wlib.command.rework.result.error.ExtraArgumentsResult; +import com.wizardlybump17.wlib.command.rework.result.error.InsufficientArgumentsResult; +import com.wizardlybump17.wlib.command.rework.result.error.InvalidArgumentResult; import com.wizardlybump17.wlib.command.sender.CommandSender; import com.wizardlybump17.wlib.util.StringUtil; import org.jetbrains.annotations.NotNull; diff --git a/commands/src/main/java/com/wizardlybump17/wlib/command/rework/result/CommandResult.java b/commands/src/main/java/com/wizardlybump17/wlib/command/rework/result/CommandResult.java index 4a5acd12..2b032553 100644 --- a/commands/src/main/java/com/wizardlybump17/wlib/command/rework/result/CommandResult.java +++ b/commands/src/main/java/com/wizardlybump17/wlib/command/rework/result/CommandResult.java @@ -1,6 +1,10 @@ package com.wizardlybump17.wlib.command.rework.result; import com.wizardlybump17.wlib.command.rework.node.CommandNode; +import com.wizardlybump17.wlib.command.rework.result.error.ExceptionResult; +import com.wizardlybump17.wlib.command.rework.result.error.ExtraArgumentsResult; +import com.wizardlybump17.wlib.command.rework.result.error.InsufficientArgumentsResult; +import com.wizardlybump17.wlib.command.rework.result.error.InvalidArgumentResult; import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.Nullable; @@ -10,31 +14,27 @@ public interface CommandResult { @Nullable T data(); - static @NotNull SuccessResult successful(@Nullable T data) { - return new SuccessResult<>(data); - } + int lastInputIndex(); - static @NotNull ExceptionResult exceptionally(@NotNull Throwable throwable) { - return new ExceptionResult<>(throwable); - } + @NotNull CommandNode lastNode(); - static @NotNull GenericErrorResult error(@NotNull String message) { - return new GenericErrorResult<>(message); + static @NotNull SuccessResult successful(@Nullable T data, int lastInputIndex, @NotNull CommandNode lastNode) { + return new SuccessResult<>(lastInputIndex, lastNode, data); } - static @NotNull GenericErrorResult error() { - return new GenericErrorResult<>(); + static @NotNull ExceptionResult exceptionally(@NotNull Throwable throwable, int lastInputIndex, @NotNull CommandNode lastNode) { + return new ExceptionResult<>(lastInputIndex, lastNode, throwable); } - static @NotNull InvalidArgumentResult invalidArgument(@NotNull CommandNode node, @NotNull CommandResult previousResult) { - return new InvalidArgumentResult<>(node, previousResult); + static @NotNull InvalidArgumentResult invalidArgument(int lastInputIndex, @NotNull CommandNode lastNode) { + return new InvalidArgumentResult<>(lastInputIndex, lastNode); } - static @NotNull InvalidArgumentResult invalidArgument(@NotNull CommandNode node, @NotNull T data) { - return new InvalidArgumentResult<>(node, data); + static @NotNull ExtraArgumentsResult extraArguments(int lastInputIndex, @NotNull CommandNode lastNode) { + return new ExtraArgumentsResult<>(lastInputIndex, lastNode); } - static @NotNull InvalidArgumentResult invalidArgument(@NotNull CommandNode node) { - return new InvalidArgumentResult<>(node); + static @NotNull InsufficientArgumentsResult insufficientArguments(int lastInputIndex, @NotNull CommandNode lastNode) { + return new InsufficientArgumentsResult<>(lastInputIndex, lastNode); } } diff --git a/commands/src/main/java/com/wizardlybump17/wlib/command/rework/result/ExceptionResult.java b/commands/src/main/java/com/wizardlybump17/wlib/command/rework/result/ExceptionResult.java deleted file mode 100644 index fa4069f9..00000000 --- a/commands/src/main/java/com/wizardlybump17/wlib/command/rework/result/ExceptionResult.java +++ /dev/null @@ -1,17 +0,0 @@ -package com.wizardlybump17.wlib.command.rework.result; - -import org.jetbrains.annotations.NotNull; -import org.jetbrains.annotations.Nullable; - -public record ExceptionResult(@NotNull Throwable exception) implements CommandResult { - - @Override - public boolean success() { - return false; - } - - @Override - public @Nullable T data() { - return null; - } -} diff --git a/commands/src/main/java/com/wizardlybump17/wlib/command/rework/result/ExtraArgumentsResult.java b/commands/src/main/java/com/wizardlybump17/wlib/command/rework/result/ExtraArgumentsResult.java deleted file mode 100644 index 4c959504..00000000 --- a/commands/src/main/java/com/wizardlybump17/wlib/command/rework/result/ExtraArgumentsResult.java +++ /dev/null @@ -1,18 +0,0 @@ -package com.wizardlybump17.wlib.command.rework.result; - -import org.jetbrains.annotations.Contract; -import org.jetbrains.annotations.Nullable; - -public record ExtraArgumentsResult(int index) implements CommandResult { - - @Override - public boolean success() { - return false; - } - - @Contract("-> null") - @Override - public @Nullable T data() { - return null; - } -} diff --git a/commands/src/main/java/com/wizardlybump17/wlib/command/rework/result/GenericErrorResult.java b/commands/src/main/java/com/wizardlybump17/wlib/command/rework/result/GenericErrorResult.java deleted file mode 100644 index 7adb8a11..00000000 --- a/commands/src/main/java/com/wizardlybump17/wlib/command/rework/result/GenericErrorResult.java +++ /dev/null @@ -1,23 +0,0 @@ -package com.wizardlybump17.wlib.command.rework.result; - -import org.jetbrains.annotations.NotNull; -import org.jetbrains.annotations.Nullable; - -public record GenericErrorResult(@NotNull String message) implements CommandResult { - - public static final @NotNull String DEFAULT_MESSAGE = "An error occurred while executing the command"; - - public GenericErrorResult() { - this(DEFAULT_MESSAGE); - } - - @Override - public boolean success() { - return false; - } - - @Override - public @Nullable T data() { - return null; - } -} diff --git a/commands/src/main/java/com/wizardlybump17/wlib/command/rework/result/InsufficientArgumentsResult.java b/commands/src/main/java/com/wizardlybump17/wlib/command/rework/result/InsufficientArgumentsResult.java deleted file mode 100644 index 71d66c64..00000000 --- a/commands/src/main/java/com/wizardlybump17/wlib/command/rework/result/InsufficientArgumentsResult.java +++ /dev/null @@ -1,18 +0,0 @@ -package com.wizardlybump17.wlib.command.rework.result; - -import com.wizardlybump17.wlib.command.rework.node.CommandNode; -import org.jetbrains.annotations.NotNull; -import org.jetbrains.annotations.Nullable; - -public record InsufficientArgumentsResult(int index, @NotNull CommandNode node) implements CommandResult { - - @Override - public boolean success() { - return false; - } - - @Override - public @Nullable T data() { - return null; - } -} diff --git a/commands/src/main/java/com/wizardlybump17/wlib/command/rework/result/InvalidArgumentResult.java b/commands/src/main/java/com/wizardlybump17/wlib/command/rework/result/InvalidArgumentResult.java deleted file mode 100644 index fe7a916c..00000000 --- a/commands/src/main/java/com/wizardlybump17/wlib/command/rework/result/InvalidArgumentResult.java +++ /dev/null @@ -1,48 +0,0 @@ -package com.wizardlybump17.wlib.command.rework.result; - -import com.wizardlybump17.wlib.command.rework.node.CommandNode; -import org.jetbrains.annotations.NotNull; -import org.jetbrains.annotations.Nullable; - -public final class InvalidArgumentResult implements CommandResult { - - private final @NotNull CommandNode node; - private final @Nullable T data; - private final @Nullable CommandResult previousResult; - - private InvalidArgumentResult(@NotNull CommandNode node, @Nullable T data, @Nullable CommandResult previousResult) { - this.node = node; - this.data = data; - this.previousResult = previousResult; - } - - public InvalidArgumentResult(@NotNull CommandNode node, @NotNull CommandResult previousResult) { - this(node, previousResult.data(), previousResult); - } - - public InvalidArgumentResult(@NotNull CommandNode node, @Nullable T data) { - this(node, data, null); - } - - public InvalidArgumentResult(@NotNull CommandNode node) { - this(node, null, null); - } - - @Override - public boolean success() { - return false; - } - - @Override - public @Nullable T data() { - return data; - } - - public @NotNull CommandNode node() { - return node; - } - - public @Nullable CommandResult previousResult() { - return previousResult; - } -} diff --git a/commands/src/main/java/com/wizardlybump17/wlib/command/rework/result/SuccessResult.java b/commands/src/main/java/com/wizardlybump17/wlib/command/rework/result/SuccessResult.java index 1f4db577..ffa70de6 100644 --- a/commands/src/main/java/com/wizardlybump17/wlib/command/rework/result/SuccessResult.java +++ b/commands/src/main/java/com/wizardlybump17/wlib/command/rework/result/SuccessResult.java @@ -1,8 +1,10 @@ package com.wizardlybump17.wlib.command.rework.result; +import com.wizardlybump17.wlib.command.rework.node.CommandNode; +import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.Nullable; -public record SuccessResult(@Nullable T data) implements CommandResult { +public record SuccessResult(int lastInputIndex, @NotNull CommandNode lastNode, @Nullable T data) implements CommandResult { @Override public boolean success() { diff --git a/commands/src/main/java/com/wizardlybump17/wlib/command/rework/result/error/AbstractUnsuccessResult.java b/commands/src/main/java/com/wizardlybump17/wlib/command/rework/result/error/AbstractUnsuccessResult.java new file mode 100644 index 00000000..cdb5d79c --- /dev/null +++ b/commands/src/main/java/com/wizardlybump17/wlib/command/rework/result/error/AbstractUnsuccessResult.java @@ -0,0 +1,36 @@ +package com.wizardlybump17.wlib.command.rework.result.error; + +import com.wizardlybump17.wlib.command.rework.node.CommandNode; +import org.jetbrains.annotations.NotNull; +import org.jetbrains.annotations.Nullable; + +public abstract class AbstractUnsuccessResult implements UnsuccessResult { + + private final int lastInputIndex; + private final @NotNull CommandNode lastNode; + + public AbstractUnsuccessResult(int lastInputIndex, @NotNull CommandNode lastNode) { + this.lastInputIndex = lastInputIndex; + this.lastNode = lastNode; + } + + @Override + public final boolean success() { + return false; + } + + @Override + public final @Nullable T data() { + return null; + } + + @Override + public int lastInputIndex() { + return lastInputIndex; + } + + @Override + public @NotNull CommandNode lastNode() { + return lastNode; + } +} diff --git a/commands/src/main/java/com/wizardlybump17/wlib/command/rework/result/error/ExceptionResult.java b/commands/src/main/java/com/wizardlybump17/wlib/command/rework/result/error/ExceptionResult.java new file mode 100644 index 00000000..337d8416 --- /dev/null +++ b/commands/src/main/java/com/wizardlybump17/wlib/command/rework/result/error/ExceptionResult.java @@ -0,0 +1,18 @@ +package com.wizardlybump17.wlib.command.rework.result.error; + +import com.wizardlybump17.wlib.command.rework.node.CommandNode; +import org.jetbrains.annotations.NotNull; + +public final class ExceptionResult extends AbstractUnsuccessResult { + + private final @NotNull Throwable exception; + + public ExceptionResult(int lastInputIndex, @NotNull CommandNode lastNode, @NotNull Throwable exception) { + super(lastInputIndex, lastNode); + this.exception = exception; + } + + public @NotNull Throwable exception() { + return exception; + } +} diff --git a/commands/src/main/java/com/wizardlybump17/wlib/command/rework/result/error/ExtraArgumentsResult.java b/commands/src/main/java/com/wizardlybump17/wlib/command/rework/result/error/ExtraArgumentsResult.java new file mode 100644 index 00000000..044026e2 --- /dev/null +++ b/commands/src/main/java/com/wizardlybump17/wlib/command/rework/result/error/ExtraArgumentsResult.java @@ -0,0 +1,11 @@ +package com.wizardlybump17.wlib.command.rework.result.error; + +import com.wizardlybump17.wlib.command.rework.node.CommandNode; +import org.jetbrains.annotations.NotNull; + +public final class ExtraArgumentsResult extends AbstractUnsuccessResult { + + public ExtraArgumentsResult(int lastInputIndex, @NotNull CommandNode lastNode) { + super(lastInputIndex, lastNode); + } +} diff --git a/commands/src/main/java/com/wizardlybump17/wlib/command/rework/result/error/InsufficientArgumentsResult.java b/commands/src/main/java/com/wizardlybump17/wlib/command/rework/result/error/InsufficientArgumentsResult.java new file mode 100644 index 00000000..cddffb46 --- /dev/null +++ b/commands/src/main/java/com/wizardlybump17/wlib/command/rework/result/error/InsufficientArgumentsResult.java @@ -0,0 +1,11 @@ +package com.wizardlybump17.wlib.command.rework.result.error; + +import com.wizardlybump17.wlib.command.rework.node.CommandNode; +import org.jetbrains.annotations.NotNull; + +public final class InsufficientArgumentsResult extends AbstractUnsuccessResult { + + public InsufficientArgumentsResult(int lastInputIndex, @NotNull CommandNode lastNode) { + super(lastInputIndex, lastNode); + } +} diff --git a/commands/src/main/java/com/wizardlybump17/wlib/command/rework/result/error/InvalidArgumentResult.java b/commands/src/main/java/com/wizardlybump17/wlib/command/rework/result/error/InvalidArgumentResult.java new file mode 100644 index 00000000..27abe1f9 --- /dev/null +++ b/commands/src/main/java/com/wizardlybump17/wlib/command/rework/result/error/InvalidArgumentResult.java @@ -0,0 +1,11 @@ +package com.wizardlybump17.wlib.command.rework.result.error; + +import com.wizardlybump17.wlib.command.rework.node.CommandNode; +import org.jetbrains.annotations.NotNull; + +public final class InvalidArgumentResult extends AbstractUnsuccessResult { + + public InvalidArgumentResult(int lastInputIndex, @NotNull CommandNode lastNode) { + super(lastInputIndex, lastNode); + } +} diff --git a/commands/src/main/java/com/wizardlybump17/wlib/command/rework/result/UnsuccessResult.java b/commands/src/main/java/com/wizardlybump17/wlib/command/rework/result/error/UnsuccessResult.java similarity index 58% rename from commands/src/main/java/com/wizardlybump17/wlib/command/rework/result/UnsuccessResult.java rename to commands/src/main/java/com/wizardlybump17/wlib/command/rework/result/error/UnsuccessResult.java index 8dcdcea8..5ba3646a 100644 --- a/commands/src/main/java/com/wizardlybump17/wlib/command/rework/result/UnsuccessResult.java +++ b/commands/src/main/java/com/wizardlybump17/wlib/command/rework/result/error/UnsuccessResult.java @@ -1,8 +1,7 @@ -package com.wizardlybump17.wlib.command.rework.result; +package com.wizardlybump17.wlib.command.rework.result.error; -import com.wizardlybump17.wlib.command.rework.node.CommandNode; +import com.wizardlybump17.wlib.command.rework.result.CommandResult; import org.jetbrains.annotations.Contract; -import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.Nullable; public interface UnsuccessResult extends CommandResult { @@ -17,8 +16,4 @@ default boolean success() { default @Nullable T data() { return null; } - - int lastInputIndex(); - - @NotNull CommandNode lastNode(); } From 669108b57c43c813de0183e22aa41e9f8c6ebc2d Mon Sep 17 00:00:00 2001 From: WizardlyBump17 Date: Mon, 27 Oct 2025 20:43:32 -0300 Subject: [PATCH 031/363] removed the CommandExecutor from the CommandNode --- .../wlib/command/rework/node/CommandNode.java | 19 +++---------------- 1 file changed, 3 insertions(+), 16 deletions(-) diff --git a/commands/src/main/java/com/wizardlybump17/wlib/command/rework/node/CommandNode.java b/commands/src/main/java/com/wizardlybump17/wlib/command/rework/node/CommandNode.java index d3b27134..29365ba1 100644 --- a/commands/src/main/java/com/wizardlybump17/wlib/command/rework/node/CommandNode.java +++ b/commands/src/main/java/com/wizardlybump17/wlib/command/rework/node/CommandNode.java @@ -2,7 +2,6 @@ import com.wizardlybump17.wlib.command.rework.exception.InputParsingException; import com.wizardlybump17.wlib.command.rework.exception.InvalidInputException; -import com.wizardlybump17.wlib.command.rework.executor.CommandExecutor; import com.wizardlybump17.wlib.command.rework.input.AllowedInputs; import com.wizardlybump17.wlib.command.sender.CommandSender; import org.jetbrains.annotations.NotNull; @@ -18,17 +17,11 @@ public abstract class CommandNode { private final @NotNull String name; private final @NotNull @Unmodifiable List> children; private final @NotNull AllowedInputs allowedInputs; - private final @Nullable CommandExecutor executor; - public CommandNode(@NotNull String name, @NotNull List> children, @NotNull AllowedInputs allowedInputs, @Nullable CommandExecutor executor) { + public CommandNode(@NotNull String name, @NotNull List> children, @NotNull AllowedInputs allowedInputs) { this.name = name; this.children = Collections.unmodifiableList(children); this.allowedInputs = allowedInputs; - this.executor = executor; - } - - public CommandNode(@NotNull String name, @NotNull List> children, @NotNull AllowedInputs allowedInputs) { - this(name, children, allowedInputs, null); } public @NotNull String getName() { @@ -60,17 +53,12 @@ public final boolean isValidInput(@Nullable T input) { return List.of(); } - public @Nullable CommandExecutor getExecutor() { - return executor; - } - @Override public String toString() { return "CommandNode{" + "name='" + name + '\'' + ", children=" + children + ", allowedInputs=" + allowedInputs + - ", executor=" + executor + '}'; } @@ -81,12 +69,11 @@ public boolean equals(Object o) { CommandNode that = (CommandNode) o; return Objects.equals(name, that.name) && Objects.equals(children, that.children) - && Objects.equals(allowedInputs, that.allowedInputs) - && Objects.equals(executor, that.executor); + && Objects.equals(allowedInputs, that.allowedInputs); } @Override public int hashCode() { - return Objects.hash(name, children, allowedInputs, executor); + return Objects.hash(name, children, allowedInputs); } } From aa4a299bee185b5b5759f3209a2416a8d3b02cb7 Mon Sep 17 00:00:00 2001 From: WizardlyBump17 Date: Mon, 27 Oct 2025 22:33:40 -0300 Subject: [PATCH 032/363] well, I think this part is done now --- .../wlib/command/rework/Command.java | 32 +++++++------------ .../rework/executor/CommandExecutor.java | 8 ++--- .../rework/node/IntegerCommandNode.java | 6 ++-- .../rework/node/LiteralCommandNode.java | 6 ---- .../command/rework/result/CommandResult.java | 14 ++++---- .../rework/result/error/ExceptionResult.java | 2 +- ...Result.java => OutOfRangeInputResult.java} | 4 +-- .../error/ParseInputExceptionResult.java | 17 ++++++++++ .../command/test/rework/CommandTests.java | 5 ++- .../command/test/rework/NodeResultTests.java | 4 +-- 10 files changed, 49 insertions(+), 49 deletions(-) rename commands/src/main/java/com/wizardlybump17/wlib/command/rework/result/error/{InvalidArgumentResult.java => OutOfRangeInputResult.java} (67%) create mode 100644 commands/src/main/java/com/wizardlybump17/wlib/command/rework/result/error/ParseInputExceptionResult.java diff --git a/commands/src/main/java/com/wizardlybump17/wlib/command/rework/Command.java b/commands/src/main/java/com/wizardlybump17/wlib/command/rework/Command.java index 1d660789..31c01550 100644 --- a/commands/src/main/java/com/wizardlybump17/wlib/command/rework/Command.java +++ b/commands/src/main/java/com/wizardlybump17/wlib/command/rework/Command.java @@ -3,14 +3,9 @@ import com.wizardlybump17.wlib.command.rework.context.CommandContext; import com.wizardlybump17.wlib.command.rework.exception.InputParsingException; import com.wizardlybump17.wlib.command.rework.exception.InvalidInputException; -import com.wizardlybump17.wlib.command.rework.executor.CommandExecutor; import com.wizardlybump17.wlib.command.rework.node.CommandNode; import com.wizardlybump17.wlib.command.rework.node.LiteralCommandNode; import com.wizardlybump17.wlib.command.rework.result.CommandResult; -import com.wizardlybump17.wlib.command.rework.result.error.ExceptionResult; -import com.wizardlybump17.wlib.command.rework.result.error.ExtraArgumentsResult; -import com.wizardlybump17.wlib.command.rework.result.error.InsufficientArgumentsResult; -import com.wizardlybump17.wlib.command.rework.result.error.InvalidArgumentResult; import com.wizardlybump17.wlib.command.sender.CommandSender; import com.wizardlybump17.wlib.util.StringUtil; import org.jetbrains.annotations.NotNull; @@ -63,6 +58,10 @@ public Command(@NotNull LiteralCommandNode root) { arguments.add(new CommandContext.CommandNodeArgument<>((CommandNode) child, inputString, result)); children = child.getChildren(); + + lastParsingError = null; + lastInputError = null; + continue inputLoop; } catch (InputParsingException e) { lastParsingError = e; @@ -72,20 +71,17 @@ public Command(@NotNull LiteralCommandNode root) { } if (lastParsingError != null) - return new ExceptionResult<>(lastParsingError); + return CommandResult.parseInputException(lastInputIndex, lastNode, lastParsingError); if (lastInputError != null) - return new InvalidArgumentResult<>((CommandNode) lastNode); + return CommandResult.outOfRangeInput(lastInputIndex, lastNode); //TODO: return a NotInRangeResult - if (lastNode.getChildren().isEmpty()) - return new ExtraArgumentsResult<>(i); - else - return new InvalidArgumentResult<>((CommandNode) lastNode); + return CommandResult.extraArguments(lastInputIndex, lastNode); } if (!lastNode.getChildren().isEmpty()) - return new InsufficientArgumentsResult<>(lastInputIndex, lastNode); + return CommandResult.insufficientArguments(lastInputIndex, lastNode); - return CommandResult.successful(new Object()); + return CommandResult.successful(new Object(), lastInputIndex, lastNode); } public @NotNull List getInputList(@NotNull String original) { @@ -101,18 +97,12 @@ public Command(@NotNull LiteralCommandNode root) { for (int i = 0; i < strings.length; i++) { String string = strings[i]; if (i == 0) { - firstNode = new LiteralCommandNode(string, children, null); + firstNode = new LiteralCommandNode(string, children); continue; } - CommandExecutor executor; - if (i + 1 >= strings.length) - executor = CommandExecutor.TEST_EXECUTOR; - else - executor = null; - List> newChildren = new ArrayList<>(); - LiteralCommandNode newNode = new LiteralCommandNode(string, newChildren, executor); + LiteralCommandNode newNode = new LiteralCommandNode(string, newChildren); children.add(newNode); children = newChildren; diff --git a/commands/src/main/java/com/wizardlybump17/wlib/command/rework/executor/CommandExecutor.java b/commands/src/main/java/com/wizardlybump17/wlib/command/rework/executor/CommandExecutor.java index c70f5faa..ba046d66 100644 --- a/commands/src/main/java/com/wizardlybump17/wlib/command/rework/executor/CommandExecutor.java +++ b/commands/src/main/java/com/wizardlybump17/wlib/command/rework/executor/CommandExecutor.java @@ -6,10 +6,10 @@ public interface CommandExecutor { - @NotNull CommandExecutor TEST_EXECUTOR = context -> { - System.out.println(context); - return CommandResult.successful(""); - }; +// @NotNull CommandExecutor TEST_EXECUTOR = context -> { +// System.out.println(context); +// return CommandResult.successful(""); +// }; @NotNull CommandResult execute(@NotNull CommandContext context); } diff --git a/commands/src/main/java/com/wizardlybump17/wlib/command/rework/node/IntegerCommandNode.java b/commands/src/main/java/com/wizardlybump17/wlib/command/rework/node/IntegerCommandNode.java index db01d132..79b5df9e 100644 --- a/commands/src/main/java/com/wizardlybump17/wlib/command/rework/node/IntegerCommandNode.java +++ b/commands/src/main/java/com/wizardlybump17/wlib/command/rework/node/IntegerCommandNode.java @@ -1,20 +1,18 @@ package com.wizardlybump17.wlib.command.rework.node; import com.wizardlybump17.wlib.command.rework.exception.InputParsingException; -import com.wizardlybump17.wlib.command.rework.executor.CommandExecutor; import com.wizardlybump17.wlib.command.rework.input.AllowedNumberInputs; import com.wizardlybump17.wlib.command.rework.input.RangedAllowedInputs; import com.wizardlybump17.wlib.command.sender.CommandSender; import org.jetbrains.annotations.NotNull; -import org.jetbrains.annotations.Nullable; import java.util.List; import java.util.stream.IntStream; public class IntegerCommandNode extends CommandNode { - public IntegerCommandNode(@NotNull String name, @NotNull List> children, @NotNull AllowedNumberInputs.AllowedIntegerInputs allowedInputs, @Nullable CommandExecutor executor) { - super(name, children, allowedInputs, executor); + public IntegerCommandNode(@NotNull String name, @NotNull List> children, @NotNull AllowedNumberInputs.AllowedIntegerInputs allowedInputs) { + super(name, children, allowedInputs); } @Override diff --git a/commands/src/main/java/com/wizardlybump17/wlib/command/rework/node/LiteralCommandNode.java b/commands/src/main/java/com/wizardlybump17/wlib/command/rework/node/LiteralCommandNode.java index 8fc3aa45..4440b167 100644 --- a/commands/src/main/java/com/wizardlybump17/wlib/command/rework/node/LiteralCommandNode.java +++ b/commands/src/main/java/com/wizardlybump17/wlib/command/rework/node/LiteralCommandNode.java @@ -1,19 +1,13 @@ package com.wizardlybump17.wlib.command.rework.node; -import com.wizardlybump17.wlib.command.rework.executor.CommandExecutor; import com.wizardlybump17.wlib.command.rework.input.LiteralAllowedInput; import com.wizardlybump17.wlib.command.sender.CommandSender; import org.jetbrains.annotations.NotNull; -import org.jetbrains.annotations.Nullable; import java.util.List; public class LiteralCommandNode extends CommandNode { - public LiteralCommandNode(@NotNull String name, @NotNull List> children, @Nullable CommandExecutor executor) { - super(name, children, new LiteralAllowedInput(name, false), executor); - } - public LiteralCommandNode(@NotNull String name, @NotNull List> children) { super(name, children, new LiteralAllowedInput(name, false)); } diff --git a/commands/src/main/java/com/wizardlybump17/wlib/command/rework/result/CommandResult.java b/commands/src/main/java/com/wizardlybump17/wlib/command/rework/result/CommandResult.java index 2b032553..c6e43e59 100644 --- a/commands/src/main/java/com/wizardlybump17/wlib/command/rework/result/CommandResult.java +++ b/commands/src/main/java/com/wizardlybump17/wlib/command/rework/result/CommandResult.java @@ -1,10 +1,8 @@ package com.wizardlybump17.wlib.command.rework.result; +import com.wizardlybump17.wlib.command.rework.exception.InputParsingException; import com.wizardlybump17.wlib.command.rework.node.CommandNode; -import com.wizardlybump17.wlib.command.rework.result.error.ExceptionResult; -import com.wizardlybump17.wlib.command.rework.result.error.ExtraArgumentsResult; -import com.wizardlybump17.wlib.command.rework.result.error.InsufficientArgumentsResult; -import com.wizardlybump17.wlib.command.rework.result.error.InvalidArgumentResult; +import com.wizardlybump17.wlib.command.rework.result.error.*; import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.Nullable; @@ -26,8 +24,8 @@ public interface CommandResult { return new ExceptionResult<>(lastInputIndex, lastNode, throwable); } - static @NotNull InvalidArgumentResult invalidArgument(int lastInputIndex, @NotNull CommandNode lastNode) { - return new InvalidArgumentResult<>(lastInputIndex, lastNode); + static @NotNull OutOfRangeInputResult outOfRangeInput(int lastInputIndex, @NotNull CommandNode lastNode) { + return new OutOfRangeInputResult<>(lastInputIndex, lastNode); } static @NotNull ExtraArgumentsResult extraArguments(int lastInputIndex, @NotNull CommandNode lastNode) { @@ -37,4 +35,8 @@ public interface CommandResult { static @NotNull InsufficientArgumentsResult insufficientArguments(int lastInputIndex, @NotNull CommandNode lastNode) { return new InsufficientArgumentsResult<>(lastInputIndex, lastNode); } + + static @NotNull ParseInputExceptionResult parseInputException(int lastInputIndex, @NotNull CommandNode lastNode, @NotNull InputParsingException exception) { + return new ParseInputExceptionResult<>(lastInputIndex, lastNode, exception); + } } diff --git a/commands/src/main/java/com/wizardlybump17/wlib/command/rework/result/error/ExceptionResult.java b/commands/src/main/java/com/wizardlybump17/wlib/command/rework/result/error/ExceptionResult.java index 337d8416..03f6461d 100644 --- a/commands/src/main/java/com/wizardlybump17/wlib/command/rework/result/error/ExceptionResult.java +++ b/commands/src/main/java/com/wizardlybump17/wlib/command/rework/result/error/ExceptionResult.java @@ -3,7 +3,7 @@ import com.wizardlybump17.wlib.command.rework.node.CommandNode; import org.jetbrains.annotations.NotNull; -public final class ExceptionResult extends AbstractUnsuccessResult { +public sealed class ExceptionResult extends AbstractUnsuccessResult permits ParseInputExceptionResult { private final @NotNull Throwable exception; diff --git a/commands/src/main/java/com/wizardlybump17/wlib/command/rework/result/error/InvalidArgumentResult.java b/commands/src/main/java/com/wizardlybump17/wlib/command/rework/result/error/OutOfRangeInputResult.java similarity index 67% rename from commands/src/main/java/com/wizardlybump17/wlib/command/rework/result/error/InvalidArgumentResult.java rename to commands/src/main/java/com/wizardlybump17/wlib/command/rework/result/error/OutOfRangeInputResult.java index 27abe1f9..b1287150 100644 --- a/commands/src/main/java/com/wizardlybump17/wlib/command/rework/result/error/InvalidArgumentResult.java +++ b/commands/src/main/java/com/wizardlybump17/wlib/command/rework/result/error/OutOfRangeInputResult.java @@ -3,9 +3,9 @@ import com.wizardlybump17.wlib.command.rework.node.CommandNode; import org.jetbrains.annotations.NotNull; -public final class InvalidArgumentResult extends AbstractUnsuccessResult { +public final class OutOfRangeInputResult extends AbstractUnsuccessResult { - public InvalidArgumentResult(int lastInputIndex, @NotNull CommandNode lastNode) { + public OutOfRangeInputResult(int lastInputIndex, @NotNull CommandNode lastNode) { super(lastInputIndex, lastNode); } } diff --git a/commands/src/main/java/com/wizardlybump17/wlib/command/rework/result/error/ParseInputExceptionResult.java b/commands/src/main/java/com/wizardlybump17/wlib/command/rework/result/error/ParseInputExceptionResult.java new file mode 100644 index 00000000..694a4a8e --- /dev/null +++ b/commands/src/main/java/com/wizardlybump17/wlib/command/rework/result/error/ParseInputExceptionResult.java @@ -0,0 +1,17 @@ +package com.wizardlybump17.wlib.command.rework.result.error; + +import com.wizardlybump17.wlib.command.rework.exception.InputParsingException; +import com.wizardlybump17.wlib.command.rework.node.CommandNode; +import org.jetbrains.annotations.NotNull; + +public final class ParseInputExceptionResult extends ExceptionResult { + + public ParseInputExceptionResult(int lastInputIndex, @NotNull CommandNode lastNode, @NotNull InputParsingException exception) { + super(lastInputIndex, lastNode, exception); + } + + @Override + public @NotNull InputParsingException exception() { + return (InputParsingException) super.exception(); + } +} diff --git a/commands/src/test/java/com/wizardlybump17/wlib/command/test/rework/CommandTests.java b/commands/src/test/java/com/wizardlybump17/wlib/command/test/rework/CommandTests.java index b7ee6b4b..ab17233b 100644 --- a/commands/src/test/java/com/wizardlybump17/wlib/command/test/rework/CommandTests.java +++ b/commands/src/test/java/com/wizardlybump17/wlib/command/test/rework/CommandTests.java @@ -1,7 +1,6 @@ package com.wizardlybump17.wlib.command.test.rework; import com.wizardlybump17.wlib.command.rework.Command; -import com.wizardlybump17.wlib.command.rework.executor.CommandExecutor; import com.wizardlybump17.wlib.command.rework.node.LiteralCommandNode; import org.junit.jupiter.api.Assertions; import org.junit.jupiter.api.Test; @@ -14,7 +13,7 @@ class CommandTests { void testCreate() { Command expected = new Command( new LiteralCommandNode("hello", List.of( - new LiteralCommandNode("world", List.of(), CommandExecutor.TEST_EXECUTOR) + new LiteralCommandNode("world", List.of()) )) ); Command created = Command.createCommand("hello world"); @@ -30,7 +29,7 @@ void testCreate1() { new LiteralCommandNode("hello1", List.of( new LiteralCommandNode("world1", List.of( new LiteralCommandNode("hello2", List.of( - new LiteralCommandNode("world2", List.of(), CommandExecutor.TEST_EXECUTOR) + new LiteralCommandNode("world2", List.of()) )) )) )) diff --git a/commands/src/test/java/com/wizardlybump17/wlib/command/test/rework/NodeResultTests.java b/commands/src/test/java/com/wizardlybump17/wlib/command/test/rework/NodeResultTests.java index 897d3f82..c3fbb53c 100644 --- a/commands/src/test/java/com/wizardlybump17/wlib/command/test/rework/NodeResultTests.java +++ b/commands/src/test/java/com/wizardlybump17/wlib/command/test/rework/NodeResultTests.java @@ -16,12 +16,12 @@ void test() { Command command = new Command( new LiteralCommandNode("hello", List.of( new LiteralCommandNode("world", List.of( - new IntegerCommandNode("a1", List.of(), new AllowedNumberInputs.AllowedIntegerInputs.Range(10, 100), null) + new IntegerCommandNode("a1", List.of(), new AllowedNumberInputs.AllowedIntegerInputs.Range(10, 100)) )) )) ); - CommandResult result = command.execute(null, List.of("hello", "world", "10", "b")); + CommandResult result = command.execute(null, List.of("hello", "world", "10a", "a")); System.out.println(result); } From 97af0c3afbd8818d42de965fb38d8257b17b0a4a Mon Sep 17 00:00:00 2001 From: WizardlyBump17 Date: Mon, 27 Oct 2025 22:44:21 -0300 Subject: [PATCH 033/363] added the CommandNodeExecutor back --- ...Executor.java => CommandNodeExecutor.java} | 2 +- .../wlib/command/rework/node/CommandNode.java | 27 ++++++++++++++++--- .../rework/node/IntegerCommandNode.java | 16 ++++++++++- .../rework/node/LiteralCommandNode.java | 16 ++++++++++- 4 files changed, 55 insertions(+), 6 deletions(-) rename commands/src/main/java/com/wizardlybump17/wlib/command/rework/executor/{CommandExecutor.java => CommandNodeExecutor.java} (91%) diff --git a/commands/src/main/java/com/wizardlybump17/wlib/command/rework/executor/CommandExecutor.java b/commands/src/main/java/com/wizardlybump17/wlib/command/rework/executor/CommandNodeExecutor.java similarity index 91% rename from commands/src/main/java/com/wizardlybump17/wlib/command/rework/executor/CommandExecutor.java rename to commands/src/main/java/com/wizardlybump17/wlib/command/rework/executor/CommandNodeExecutor.java index ba046d66..895e5623 100644 --- a/commands/src/main/java/com/wizardlybump17/wlib/command/rework/executor/CommandExecutor.java +++ b/commands/src/main/java/com/wizardlybump17/wlib/command/rework/executor/CommandNodeExecutor.java @@ -4,7 +4,7 @@ import com.wizardlybump17.wlib.command.rework.result.CommandResult; import org.jetbrains.annotations.NotNull; -public interface CommandExecutor { +public interface CommandNodeExecutor { // @NotNull CommandExecutor TEST_EXECUTOR = context -> { // System.out.println(context); diff --git a/commands/src/main/java/com/wizardlybump17/wlib/command/rework/node/CommandNode.java b/commands/src/main/java/com/wizardlybump17/wlib/command/rework/node/CommandNode.java index 29365ba1..0c59be1a 100644 --- a/commands/src/main/java/com/wizardlybump17/wlib/command/rework/node/CommandNode.java +++ b/commands/src/main/java/com/wizardlybump17/wlib/command/rework/node/CommandNode.java @@ -2,6 +2,7 @@ import com.wizardlybump17.wlib.command.rework.exception.InputParsingException; import com.wizardlybump17.wlib.command.rework.exception.InvalidInputException; +import com.wizardlybump17.wlib.command.rework.executor.CommandNodeExecutor; import com.wizardlybump17.wlib.command.rework.input.AllowedInputs; import com.wizardlybump17.wlib.command.sender.CommandSender; import org.jetbrains.annotations.NotNull; @@ -17,11 +18,25 @@ public abstract class CommandNode { private final @NotNull String name; private final @NotNull @Unmodifiable List> children; private final @NotNull AllowedInputs allowedInputs; + private final @Nullable CommandNodeExecutor executor; - public CommandNode(@NotNull String name, @NotNull List> children, @NotNull AllowedInputs allowedInputs) { + public CommandNode(@NotNull String name, @NotNull List> children, @NotNull AllowedInputs allowedInputs, @Nullable CommandNodeExecutor executor) { this.name = name; this.children = Collections.unmodifiableList(children); this.allowedInputs = allowedInputs; + this.executor = executor; + } + + public CommandNode(@NotNull String name, @NotNull AllowedInputs allowedInputs, @Nullable CommandNodeExecutor executor) { + this(name, List.of(), allowedInputs, executor); + } + + public CommandNode(@NotNull String name, @NotNull List> children, @NotNull AllowedInputs allowedInputs) { + this(name, children, allowedInputs, null); + } + + public CommandNode(@NotNull String name, @NotNull AllowedInputs allowedInputs) { + this(name, List.of(), allowedInputs, null); } public @NotNull String getName() { @@ -53,12 +68,17 @@ public final boolean isValidInput(@Nullable T input) { return List.of(); } + public @Nullable CommandNodeExecutor getExecutor() { + return executor; + } + @Override public String toString() { return "CommandNode{" + "name='" + name + '\'' + ", children=" + children + ", allowedInputs=" + allowedInputs + + ", executor=" + executor + '}'; } @@ -69,11 +89,12 @@ public boolean equals(Object o) { CommandNode that = (CommandNode) o; return Objects.equals(name, that.name) && Objects.equals(children, that.children) - && Objects.equals(allowedInputs, that.allowedInputs); + && Objects.equals(allowedInputs, that.allowedInputs) + && Objects.equals(executor, that.executor); } @Override public int hashCode() { - return Objects.hash(name, children, allowedInputs); + return Objects.hash(name, children, allowedInputs, executor); } } diff --git a/commands/src/main/java/com/wizardlybump17/wlib/command/rework/node/IntegerCommandNode.java b/commands/src/main/java/com/wizardlybump17/wlib/command/rework/node/IntegerCommandNode.java index 79b5df9e..d5cef1f7 100644 --- a/commands/src/main/java/com/wizardlybump17/wlib/command/rework/node/IntegerCommandNode.java +++ b/commands/src/main/java/com/wizardlybump17/wlib/command/rework/node/IntegerCommandNode.java @@ -1,18 +1,32 @@ package com.wizardlybump17.wlib.command.rework.node; import com.wizardlybump17.wlib.command.rework.exception.InputParsingException; +import com.wizardlybump17.wlib.command.rework.executor.CommandNodeExecutor; import com.wizardlybump17.wlib.command.rework.input.AllowedNumberInputs; import com.wizardlybump17.wlib.command.rework.input.RangedAllowedInputs; import com.wizardlybump17.wlib.command.sender.CommandSender; import org.jetbrains.annotations.NotNull; +import org.jetbrains.annotations.Nullable; import java.util.List; import java.util.stream.IntStream; public class IntegerCommandNode extends CommandNode { + public IntegerCommandNode(@NotNull String name, @NotNull List> children, @NotNull AllowedNumberInputs.AllowedIntegerInputs allowedInputs, @Nullable CommandNodeExecutor executor) { + super(name, children, allowedInputs, executor); + } + + public IntegerCommandNode(@NotNull String name, @NotNull AllowedNumberInputs.AllowedIntegerInputs allowedInputs, @Nullable CommandNodeExecutor executor) { + this(name, List.of(), allowedInputs, executor); + } + public IntegerCommandNode(@NotNull String name, @NotNull List> children, @NotNull AllowedNumberInputs.AllowedIntegerInputs allowedInputs) { - super(name, children, allowedInputs); + this(name, children, allowedInputs, null); + } + + public IntegerCommandNode(@NotNull String name, @NotNull AllowedNumberInputs.AllowedIntegerInputs allowedInputs) { + this(name, List.of(), allowedInputs, null); } @Override diff --git a/commands/src/main/java/com/wizardlybump17/wlib/command/rework/node/LiteralCommandNode.java b/commands/src/main/java/com/wizardlybump17/wlib/command/rework/node/LiteralCommandNode.java index 4440b167..80331514 100644 --- a/commands/src/main/java/com/wizardlybump17/wlib/command/rework/node/LiteralCommandNode.java +++ b/commands/src/main/java/com/wizardlybump17/wlib/command/rework/node/LiteralCommandNode.java @@ -1,15 +1,29 @@ package com.wizardlybump17.wlib.command.rework.node; +import com.wizardlybump17.wlib.command.rework.executor.CommandNodeExecutor; import com.wizardlybump17.wlib.command.rework.input.LiteralAllowedInput; import com.wizardlybump17.wlib.command.sender.CommandSender; import org.jetbrains.annotations.NotNull; +import org.jetbrains.annotations.Nullable; import java.util.List; public class LiteralCommandNode extends CommandNode { + public LiteralCommandNode(@NotNull String name, @NotNull List> children, @Nullable CommandNodeExecutor executor) { + super(name, children, new LiteralAllowedInput(name, false), executor); + } + + public LiteralCommandNode(@NotNull String name, @Nullable CommandNodeExecutor executor) { + this(name, List.of(), executor); + } + public LiteralCommandNode(@NotNull String name, @NotNull List> children) { - super(name, children, new LiteralAllowedInput(name, false)); + this(name, children, null); + } + + public LiteralCommandNode(@NotNull String name) { + this(name, List.of(), null); } @Override From cdf5a06672ef0fcddcd8112ec58aff042191512b Mon Sep 17 00:00:00 2001 From: WizardlyBump17 Date: Mon, 27 Oct 2025 22:48:31 -0300 Subject: [PATCH 034/363] actually executing the command --- .../wlib/command/rework/Command.java | 15 +++++++++++---- .../wlib/command/rework/result/CommandResult.java | 4 ++++ .../error/CommandNodeExecutorNotFoundResult.java | 7 +++++++ 3 files changed, 22 insertions(+), 4 deletions(-) create mode 100644 commands/src/main/java/com/wizardlybump17/wlib/command/rework/result/error/CommandNodeExecutorNotFoundResult.java diff --git a/commands/src/main/java/com/wizardlybump17/wlib/command/rework/Command.java b/commands/src/main/java/com/wizardlybump17/wlib/command/rework/Command.java index 31c01550..21d0ee14 100644 --- a/commands/src/main/java/com/wizardlybump17/wlib/command/rework/Command.java +++ b/commands/src/main/java/com/wizardlybump17/wlib/command/rework/Command.java @@ -3,6 +3,7 @@ import com.wizardlybump17.wlib.command.rework.context.CommandContext; import com.wizardlybump17.wlib.command.rework.exception.InputParsingException; import com.wizardlybump17.wlib.command.rework.exception.InvalidInputException; +import com.wizardlybump17.wlib.command.rework.executor.CommandNodeExecutor; import com.wizardlybump17.wlib.command.rework.node.CommandNode; import com.wizardlybump17.wlib.command.rework.node.LiteralCommandNode; import com.wizardlybump17.wlib.command.rework.result.CommandResult; @@ -73,15 +74,21 @@ public Command(@NotNull LiteralCommandNode root) { if (lastParsingError != null) return CommandResult.parseInputException(lastInputIndex, lastNode, lastParsingError); if (lastInputError != null) - return CommandResult.outOfRangeInput(lastInputIndex, lastNode); //TODO: return a NotInRangeResult + return CommandResult.outOfRangeInput(lastInputIndex, lastNode); return CommandResult.extraArguments(lastInputIndex, lastNode); } - if (!lastNode.getChildren().isEmpty()) - return CommandResult.insufficientArguments(lastInputIndex, lastNode); + CommandNodeExecutor executor = lastNode.getExecutor(); + if (executor == null) + return CommandResult.noCommandNodeExecutor(lastInputIndex, lastNode); - return CommandResult.successful(new Object(), lastInputIndex, lastNode); + CommandContext context = new CommandContext( + this, + sender, + new CommandContext.CommandNodeArguments(arguments) + ); + return executor.execute(context); } public @NotNull List getInputList(@NotNull String original) { diff --git a/commands/src/main/java/com/wizardlybump17/wlib/command/rework/result/CommandResult.java b/commands/src/main/java/com/wizardlybump17/wlib/command/rework/result/CommandResult.java index c6e43e59..b3d31126 100644 --- a/commands/src/main/java/com/wizardlybump17/wlib/command/rework/result/CommandResult.java +++ b/commands/src/main/java/com/wizardlybump17/wlib/command/rework/result/CommandResult.java @@ -39,4 +39,8 @@ public interface CommandResult { static @NotNull ParseInputExceptionResult parseInputException(int lastInputIndex, @NotNull CommandNode lastNode, @NotNull InputParsingException exception) { return new ParseInputExceptionResult<>(lastInputIndex, lastNode, exception); } + + static @NotNull CommandNodeExecutorNotFoundResult noCommandNodeExecutor(int lastInputIndex, @NotNull CommandNode lastNode) { + return new CommandNodeExecutorNotFoundResult<>(lastInputIndex, lastNode); + } } diff --git a/commands/src/main/java/com/wizardlybump17/wlib/command/rework/result/error/CommandNodeExecutorNotFoundResult.java b/commands/src/main/java/com/wizardlybump17/wlib/command/rework/result/error/CommandNodeExecutorNotFoundResult.java new file mode 100644 index 00000000..ff946f04 --- /dev/null +++ b/commands/src/main/java/com/wizardlybump17/wlib/command/rework/result/error/CommandNodeExecutorNotFoundResult.java @@ -0,0 +1,7 @@ +package com.wizardlybump17.wlib.command.rework.result.error; + +import com.wizardlybump17.wlib.command.rework.node.CommandNode; +import org.jetbrains.annotations.NotNull; + +public record CommandNodeExecutorNotFoundResult(int lastInputIndex, @NotNull CommandNode lastNode) implements UnsuccessResult { +} From 876aa7c67a2d7900a79a46d086ee4feb506768e0 Mon Sep 17 00:00:00 2001 From: WizardlyBump17 Date: Mon, 27 Oct 2025 22:51:27 -0300 Subject: [PATCH 035/363] returning a CommandResult --- .../java/com/wizardlybump17/wlib/command/rework/Command.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/commands/src/main/java/com/wizardlybump17/wlib/command/rework/Command.java b/commands/src/main/java/com/wizardlybump17/wlib/command/rework/Command.java index 21d0ee14..27405c99 100644 --- a/commands/src/main/java/com/wizardlybump17/wlib/command/rework/Command.java +++ b/commands/src/main/java/com/wizardlybump17/wlib/command/rework/Command.java @@ -36,7 +36,7 @@ public Command(@NotNull LiteralCommandNode root) { @SuppressWarnings("unchecked") public @NotNull CommandResult execute(@NotNull CommandSender sender, @NotNull List input) { if (input.isEmpty()) - throw new IllegalArgumentException(); + return CommandResult.insufficientArguments(-1, root); List> arguments = new ArrayList<>(); List> children = List.of(root); From ce9a0734ddbac5ee7bec12ee376a5c39257df803 Mon Sep 17 00:00:00 2001 From: WizardlyBump17 Date: Mon, 27 Oct 2025 22:51:43 -0300 Subject: [PATCH 036/363] keeping track of the last input stuff --- .../java/com/wizardlybump17/wlib/command/rework/Command.java | 4 +++- .../wlib/command/rework/context/CommandContext.java | 2 +- .../wlib/command/test/rework/NodeResultTests.java | 4 ++-- 3 files changed, 6 insertions(+), 4 deletions(-) diff --git a/commands/src/main/java/com/wizardlybump17/wlib/command/rework/Command.java b/commands/src/main/java/com/wizardlybump17/wlib/command/rework/Command.java index 27405c99..0c5c4722 100644 --- a/commands/src/main/java/com/wizardlybump17/wlib/command/rework/Command.java +++ b/commands/src/main/java/com/wizardlybump17/wlib/command/rework/Command.java @@ -86,7 +86,9 @@ public Command(@NotNull LiteralCommandNode root) { CommandContext context = new CommandContext( this, sender, - new CommandContext.CommandNodeArguments(arguments) + new CommandContext.CommandNodeArguments(arguments), + lastInputIndex, + lastNode ); return executor.execute(context); } diff --git a/commands/src/main/java/com/wizardlybump17/wlib/command/rework/context/CommandContext.java b/commands/src/main/java/com/wizardlybump17/wlib/command/rework/context/CommandContext.java index 1c00f1a8..f44ee876 100644 --- a/commands/src/main/java/com/wizardlybump17/wlib/command/rework/context/CommandContext.java +++ b/commands/src/main/java/com/wizardlybump17/wlib/command/rework/context/CommandContext.java @@ -12,7 +12,7 @@ import java.util.Objects; import java.util.Optional; -public record CommandContext(@NotNull Command command, @NotNull CommandSender sender, @NotNull CommandNodeArguments arguments) { +public record CommandContext(@NotNull Command command, @NotNull CommandSender sender, @NotNull CommandNodeArguments arguments, int lastInputIndex, @NotNull CommandNode lastNode) { public record CommandNodeArgument(@NotNull CommandNode node, @NotNull String input, @Nullable T data) { } diff --git a/commands/src/test/java/com/wizardlybump17/wlib/command/test/rework/NodeResultTests.java b/commands/src/test/java/com/wizardlybump17/wlib/command/test/rework/NodeResultTests.java index c3fbb53c..609a2176 100644 --- a/commands/src/test/java/com/wizardlybump17/wlib/command/test/rework/NodeResultTests.java +++ b/commands/src/test/java/com/wizardlybump17/wlib/command/test/rework/NodeResultTests.java @@ -16,12 +16,12 @@ void test() { Command command = new Command( new LiteralCommandNode("hello", List.of( new LiteralCommandNode("world", List.of( - new IntegerCommandNode("a1", List.of(), new AllowedNumberInputs.AllowedIntegerInputs.Range(10, 100)) + new IntegerCommandNode("a1", new AllowedNumberInputs.AllowedIntegerInputs.Range(10, 100), context -> CommandResult.successful("a1", context.lastInputIndex(), context.lastNode())) )) )) ); - CommandResult result = command.execute(null, List.of("hello", "world", "10a", "a")); + CommandResult result = command.execute(null, List.of("hello", "world", "10")); System.out.println(result); } From 4849ffdd6dc35402d5b7493708e9dceca2c7935c Mon Sep 17 00:00:00 2001 From: WizardlyBump17 Date: Mon, 27 Oct 2025 23:05:26 -0300 Subject: [PATCH 037/363] improved the CommandResult --- .../command/rework/result/CommandResult.java | 29 +++++++++++++++ .../result/error/AbstractUnsuccessResult.java | 36 ------------------- .../rework/result/error/ExceptionResult.java | 13 +------ .../result/error/ExtraArgumentsResult.java | 6 +--- .../result/error/GenericErrorResult.java | 13 +++++++ .../error/InsufficientArgumentsResult.java | 6 +--- .../result/error/OutOfRangeInputResult.java | 6 +--- .../error/ParseInputExceptionResult.java | 11 +----- .../command/test/rework/NodeResultTests.java | 2 +- 9 files changed, 48 insertions(+), 74 deletions(-) delete mode 100644 commands/src/main/java/com/wizardlybump17/wlib/command/rework/result/error/AbstractUnsuccessResult.java create mode 100644 commands/src/main/java/com/wizardlybump17/wlib/command/rework/result/error/GenericErrorResult.java diff --git a/commands/src/main/java/com/wizardlybump17/wlib/command/rework/result/CommandResult.java b/commands/src/main/java/com/wizardlybump17/wlib/command/rework/result/CommandResult.java index b3d31126..b5d16bc7 100644 --- a/commands/src/main/java/com/wizardlybump17/wlib/command/rework/result/CommandResult.java +++ b/commands/src/main/java/com/wizardlybump17/wlib/command/rework/result/CommandResult.java @@ -1,5 +1,6 @@ package com.wizardlybump17.wlib.command.rework.result; +import com.wizardlybump17.wlib.command.rework.context.CommandContext; import com.wizardlybump17.wlib.command.rework.exception.InputParsingException; import com.wizardlybump17.wlib.command.rework.node.CommandNode; import com.wizardlybump17.wlib.command.rework.result.error.*; @@ -16,6 +17,8 @@ public interface CommandResult { @NotNull CommandNode lastNode(); + //without context + static @NotNull SuccessResult successful(@Nullable T data, int lastInputIndex, @NotNull CommandNode lastNode) { return new SuccessResult<>(lastInputIndex, lastNode, data); } @@ -43,4 +46,30 @@ public interface CommandResult { static @NotNull CommandNodeExecutorNotFoundResult noCommandNodeExecutor(int lastInputIndex, @NotNull CommandNode lastNode) { return new CommandNodeExecutorNotFoundResult<>(lastInputIndex, lastNode); } + + static @NotNull GenericErrorResult genericError(int lastInputIndex, @NotNull CommandNode lastNode, @NotNull String message) { + return new GenericErrorResult<>(lastInputIndex, lastNode, message); + } + + static @NotNull GenericErrorResult genericError(int lastInputIndex, @NotNull CommandNode lastNode) { + return new GenericErrorResult<>(lastInputIndex, lastNode); + } + + //with context + + static @NotNull SuccessResult successful(@NotNull CommandContext context, @Nullable T data) { + return successful(data, context.lastInputIndex(), context.lastNode()); + } + + static @NotNull ExceptionResult exceptionally(@NotNull CommandContext context, @NotNull Throwable exception) { + return exceptionally(exception, context.lastInputIndex(), context.lastNode()); + } + + static @NotNull GenericErrorResult genericError(@NotNull CommandContext context, @NotNull String message) { + return genericError(context.lastInputIndex(), context.lastNode(), message); + } + + static @NotNull GenericErrorResult genericError(@NotNull CommandContext context) { + return genericError(context.lastInputIndex(), context.lastNode()); + } } diff --git a/commands/src/main/java/com/wizardlybump17/wlib/command/rework/result/error/AbstractUnsuccessResult.java b/commands/src/main/java/com/wizardlybump17/wlib/command/rework/result/error/AbstractUnsuccessResult.java deleted file mode 100644 index cdb5d79c..00000000 --- a/commands/src/main/java/com/wizardlybump17/wlib/command/rework/result/error/AbstractUnsuccessResult.java +++ /dev/null @@ -1,36 +0,0 @@ -package com.wizardlybump17.wlib.command.rework.result.error; - -import com.wizardlybump17.wlib.command.rework.node.CommandNode; -import org.jetbrains.annotations.NotNull; -import org.jetbrains.annotations.Nullable; - -public abstract class AbstractUnsuccessResult implements UnsuccessResult { - - private final int lastInputIndex; - private final @NotNull CommandNode lastNode; - - public AbstractUnsuccessResult(int lastInputIndex, @NotNull CommandNode lastNode) { - this.lastInputIndex = lastInputIndex; - this.lastNode = lastNode; - } - - @Override - public final boolean success() { - return false; - } - - @Override - public final @Nullable T data() { - return null; - } - - @Override - public int lastInputIndex() { - return lastInputIndex; - } - - @Override - public @NotNull CommandNode lastNode() { - return lastNode; - } -} diff --git a/commands/src/main/java/com/wizardlybump17/wlib/command/rework/result/error/ExceptionResult.java b/commands/src/main/java/com/wizardlybump17/wlib/command/rework/result/error/ExceptionResult.java index 03f6461d..1e3376ab 100644 --- a/commands/src/main/java/com/wizardlybump17/wlib/command/rework/result/error/ExceptionResult.java +++ b/commands/src/main/java/com/wizardlybump17/wlib/command/rework/result/error/ExceptionResult.java @@ -3,16 +3,5 @@ import com.wizardlybump17.wlib.command.rework.node.CommandNode; import org.jetbrains.annotations.NotNull; -public sealed class ExceptionResult extends AbstractUnsuccessResult permits ParseInputExceptionResult { - - private final @NotNull Throwable exception; - - public ExceptionResult(int lastInputIndex, @NotNull CommandNode lastNode, @NotNull Throwable exception) { - super(lastInputIndex, lastNode); - this.exception = exception; - } - - public @NotNull Throwable exception() { - return exception; - } +public record ExceptionResult(int lastInputIndex, @NotNull CommandNode lastNode, @NotNull Throwable exception) implements UnsuccessResult { } diff --git a/commands/src/main/java/com/wizardlybump17/wlib/command/rework/result/error/ExtraArgumentsResult.java b/commands/src/main/java/com/wizardlybump17/wlib/command/rework/result/error/ExtraArgumentsResult.java index 044026e2..daf0b25d 100644 --- a/commands/src/main/java/com/wizardlybump17/wlib/command/rework/result/error/ExtraArgumentsResult.java +++ b/commands/src/main/java/com/wizardlybump17/wlib/command/rework/result/error/ExtraArgumentsResult.java @@ -3,9 +3,5 @@ import com.wizardlybump17.wlib.command.rework.node.CommandNode; import org.jetbrains.annotations.NotNull; -public final class ExtraArgumentsResult extends AbstractUnsuccessResult { - - public ExtraArgumentsResult(int lastInputIndex, @NotNull CommandNode lastNode) { - super(lastInputIndex, lastNode); - } +public record ExtraArgumentsResult(int lastInputIndex, @NotNull CommandNode lastNode) implements UnsuccessResult { } diff --git a/commands/src/main/java/com/wizardlybump17/wlib/command/rework/result/error/GenericErrorResult.java b/commands/src/main/java/com/wizardlybump17/wlib/command/rework/result/error/GenericErrorResult.java new file mode 100644 index 00000000..20683167 --- /dev/null +++ b/commands/src/main/java/com/wizardlybump17/wlib/command/rework/result/error/GenericErrorResult.java @@ -0,0 +1,13 @@ +package com.wizardlybump17.wlib.command.rework.result.error; + +import com.wizardlybump17.wlib.command.rework.node.CommandNode; +import org.jetbrains.annotations.NotNull; + +public record GenericErrorResult(int lastInputIndex, @NotNull CommandNode lastNode, @NotNull String message) implements UnsuccessResult { + + public static final @NotNull String DEFAULT_MESSAGE = "An error occurred while executing the command."; + + public GenericErrorResult(int lastInputIndex, @NotNull CommandNode lastNode) { + this(lastInputIndex, lastNode, DEFAULT_MESSAGE); + } +} diff --git a/commands/src/main/java/com/wizardlybump17/wlib/command/rework/result/error/InsufficientArgumentsResult.java b/commands/src/main/java/com/wizardlybump17/wlib/command/rework/result/error/InsufficientArgumentsResult.java index cddffb46..efba1774 100644 --- a/commands/src/main/java/com/wizardlybump17/wlib/command/rework/result/error/InsufficientArgumentsResult.java +++ b/commands/src/main/java/com/wizardlybump17/wlib/command/rework/result/error/InsufficientArgumentsResult.java @@ -3,9 +3,5 @@ import com.wizardlybump17.wlib.command.rework.node.CommandNode; import org.jetbrains.annotations.NotNull; -public final class InsufficientArgumentsResult extends AbstractUnsuccessResult { - - public InsufficientArgumentsResult(int lastInputIndex, @NotNull CommandNode lastNode) { - super(lastInputIndex, lastNode); - } +public record InsufficientArgumentsResult(int lastInputIndex, @NotNull CommandNode lastNode) implements UnsuccessResult { } diff --git a/commands/src/main/java/com/wizardlybump17/wlib/command/rework/result/error/OutOfRangeInputResult.java b/commands/src/main/java/com/wizardlybump17/wlib/command/rework/result/error/OutOfRangeInputResult.java index b1287150..14dfc24a 100644 --- a/commands/src/main/java/com/wizardlybump17/wlib/command/rework/result/error/OutOfRangeInputResult.java +++ b/commands/src/main/java/com/wizardlybump17/wlib/command/rework/result/error/OutOfRangeInputResult.java @@ -3,9 +3,5 @@ import com.wizardlybump17.wlib.command.rework.node.CommandNode; import org.jetbrains.annotations.NotNull; -public final class OutOfRangeInputResult extends AbstractUnsuccessResult { - - public OutOfRangeInputResult(int lastInputIndex, @NotNull CommandNode lastNode) { - super(lastInputIndex, lastNode); - } +public record OutOfRangeInputResult(int lastInputIndex, @NotNull CommandNode lastNode) implements UnsuccessResult { } diff --git a/commands/src/main/java/com/wizardlybump17/wlib/command/rework/result/error/ParseInputExceptionResult.java b/commands/src/main/java/com/wizardlybump17/wlib/command/rework/result/error/ParseInputExceptionResult.java index 694a4a8e..d4842c9b 100644 --- a/commands/src/main/java/com/wizardlybump17/wlib/command/rework/result/error/ParseInputExceptionResult.java +++ b/commands/src/main/java/com/wizardlybump17/wlib/command/rework/result/error/ParseInputExceptionResult.java @@ -4,14 +4,5 @@ import com.wizardlybump17.wlib.command.rework.node.CommandNode; import org.jetbrains.annotations.NotNull; -public final class ParseInputExceptionResult extends ExceptionResult { - - public ParseInputExceptionResult(int lastInputIndex, @NotNull CommandNode lastNode, @NotNull InputParsingException exception) { - super(lastInputIndex, lastNode, exception); - } - - @Override - public @NotNull InputParsingException exception() { - return (InputParsingException) super.exception(); - } +public record ParseInputExceptionResult(int lastInputIndex, @NotNull CommandNode lastNode, @NotNull InputParsingException exception) implements UnsuccessResult { } diff --git a/commands/src/test/java/com/wizardlybump17/wlib/command/test/rework/NodeResultTests.java b/commands/src/test/java/com/wizardlybump17/wlib/command/test/rework/NodeResultTests.java index 609a2176..09fb242b 100644 --- a/commands/src/test/java/com/wizardlybump17/wlib/command/test/rework/NodeResultTests.java +++ b/commands/src/test/java/com/wizardlybump17/wlib/command/test/rework/NodeResultTests.java @@ -16,7 +16,7 @@ void test() { Command command = new Command( new LiteralCommandNode("hello", List.of( new LiteralCommandNode("world", List.of( - new IntegerCommandNode("a1", new AllowedNumberInputs.AllowedIntegerInputs.Range(10, 100), context -> CommandResult.successful("a1", context.lastInputIndex(), context.lastNode())) + new IntegerCommandNode("a1", new AllowedNumberInputs.AllowedIntegerInputs.Range(10, 100), context -> CommandResult.successful(context, "a1")) )) )) ); From d56772873a98ce8f53464069d3573e1f9c6a4ea3 Mon Sep 17 00:00:00 2001 From: WizardlyBump17 Date: Mon, 27 Oct 2025 23:51:53 -0300 Subject: [PATCH 038/363] executing from methods --- .../wlib/command/rework/Command.java | 94 +++++++++++++++++++ .../command/rework/annotation/Command.java | 15 +++ .../rework/context/CommandContext.java | 10 +- .../rework/input/AllowedNumberInputs.java | 8 ++ .../command/test/rework/CommandTests.java | 27 +++++- 5 files changed, 149 insertions(+), 5 deletions(-) create mode 100644 commands/src/main/java/com/wizardlybump17/wlib/command/rework/annotation/Command.java diff --git a/commands/src/main/java/com/wizardlybump17/wlib/command/rework/Command.java b/commands/src/main/java/com/wizardlybump17/wlib/command/rework/Command.java index 0c5c4722..a7985857 100644 --- a/commands/src/main/java/com/wizardlybump17/wlib/command/rework/Command.java +++ b/commands/src/main/java/com/wizardlybump17/wlib/command/rework/Command.java @@ -4,7 +4,9 @@ import com.wizardlybump17.wlib.command.rework.exception.InputParsingException; import com.wizardlybump17.wlib.command.rework.exception.InvalidInputException; import com.wizardlybump17.wlib.command.rework.executor.CommandNodeExecutor; +import com.wizardlybump17.wlib.command.rework.input.AllowedNumberInputs; import com.wizardlybump17.wlib.command.rework.node.CommandNode; +import com.wizardlybump17.wlib.command.rework.node.IntegerCommandNode; import com.wizardlybump17.wlib.command.rework.node.LiteralCommandNode; import com.wizardlybump17.wlib.command.rework.result.CommandResult; import com.wizardlybump17.wlib.command.sender.CommandSender; @@ -12,6 +14,10 @@ import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.Nullable; +import java.lang.invoke.MethodHandle; +import java.lang.invoke.MethodHandles; +import java.lang.invoke.MethodType; +import java.lang.reflect.Method; import java.util.ArrayList; import java.util.List; import java.util.Objects; @@ -139,4 +145,92 @@ public boolean equals(Object o) { public int hashCode() { return Objects.hashCode(root); } + + public static @NotNull Command fromMethod(@NotNull Method method, @NotNull Object object) { + com.wizardlybump17.wlib.command.rework.annotation.Command annotation = method.getDeclaredAnnotation(com.wizardlybump17.wlib.command.rework.annotation.Command.class); + if (annotation == null) + throw new IllegalArgumentException("Method " + method.getName() + " does not have a Command annotation"); + + Class[] parameterTypes = method.getParameterTypes(); + if (parameterTypes.length == 0) + throw new IllegalArgumentException("Method " + method.getName() + " does not have any parameter"); + + if (!parameterTypes[0].equals(CommandContext.class)) + throw new IllegalArgumentException("Method " + method.getName() + "'s first parameter is not a CommandContext"); + + LiteralCommandNode firstNode = null; + + List> children = new ArrayList<>(); + String[] parts = annotation.value().split(" "); + + int parameterIndex = 1; + for (int i = 0; i < parts.length; i++) { + String part = parts[i]; + + CommandNodeExecutor executor; + if (i + 1 >= parts.length) { + executor = new CommandNodeExecutor<>() { + @NotNull MethodHandle methodHandle; { + try { + methodHandle = MethodHandles.publicLookup().findVirtual(object.getClass(), method.getName(), MethodType.methodType(method.getReturnType(), method.getParameterTypes())); + } catch (NoSuchMethodException | IllegalAccessException e) { + throw new RuntimeException(e); + } + } + + @SuppressWarnings("unchecked") + @Override + public @NotNull CommandResult execute(@NotNull CommandContext context) { + List arguments = new ArrayList<>(); + + arguments.add(object); + arguments.add(context); + + arguments.addAll(context.arguments().getArguments().values() + .stream() + .filter(argument -> !(argument.node() instanceof LiteralCommandNode)) + .map(CommandContext.CommandNodeArgument::data) + .toList() + ); + + try { + Object invoke = methodHandle.invokeWithArguments(arguments); + return invoke instanceof CommandResult result ? (CommandResult) result : CommandResult.successful(context, invoke); + } catch (Throwable e) { + throw new RuntimeException(e); + } + } + }; + } else { + executor = null; + } + + if (i == 0) { + firstNode = new LiteralCommandNode(part, children, executor); + continue; + } + + List> newChildren = new ArrayList<>(); + CommandNode newNode; + + if (part.charAt(0) == '<' && part.charAt(part.length() - 1) == '>') { + String nodeName = part.substring(1, part.length() - 1); + + Class parameterType = parameterTypes[parameterIndex++]; + if (parameterType == int.class || parameterType == Integer.class) + newNode = new IntegerCommandNode(nodeName, newChildren, new AllowedNumberInputs.AllowedIntegerInputs.Unlimited(), executor); + else + throw new IllegalArgumentException("Just trying stuff for now. Come back later"); + + } else { + newNode = new LiteralCommandNode(part, newChildren, executor); + } + + children.add(newNode); + + children = newChildren; + } + + return firstNode == null ? null : new Command(firstNode); + } } diff --git a/commands/src/main/java/com/wizardlybump17/wlib/command/rework/annotation/Command.java b/commands/src/main/java/com/wizardlybump17/wlib/command/rework/annotation/Command.java new file mode 100644 index 00000000..6a65ac55 --- /dev/null +++ b/commands/src/main/java/com/wizardlybump17/wlib/command/rework/annotation/Command.java @@ -0,0 +1,15 @@ +package com.wizardlybump17.wlib.command.rework.annotation; + +import org.jetbrains.annotations.NotNull; + +import java.lang.annotation.ElementType; +import java.lang.annotation.Retention; +import java.lang.annotation.RetentionPolicy; +import java.lang.annotation.Target; + +@Target(ElementType.METHOD) +@Retention(RetentionPolicy.RUNTIME) +public @interface Command { + + @NotNull String value(); +} diff --git a/commands/src/main/java/com/wizardlybump17/wlib/command/rework/context/CommandContext.java b/commands/src/main/java/com/wizardlybump17/wlib/command/rework/context/CommandContext.java index f44ee876..0f1ac2a4 100644 --- a/commands/src/main/java/com/wizardlybump17/wlib/command/rework/context/CommandContext.java +++ b/commands/src/main/java/com/wizardlybump17/wlib/command/rework/context/CommandContext.java @@ -6,11 +6,9 @@ import com.wizardlybump17.wlib.util.MapUtils; import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.Nullable; +import org.jetbrains.annotations.Unmodifiable; -import java.util.LinkedHashMap; -import java.util.List; -import java.util.Objects; -import java.util.Optional; +import java.util.*; public record CommandContext(@NotNull Command command, @NotNull CommandSender sender, @NotNull CommandNodeArguments arguments, int lastInputIndex, @NotNull CommandNode lastNode) { @@ -38,6 +36,10 @@ public boolean hasArgument(@NotNull String key) { return Optional.ofNullable((CommandNodeArgument) arguments.get(key)); } + public @NotNull @Unmodifiable Map> getArguments() { + return Collections.unmodifiableMap(arguments); + } + @Override public String toString() { return "CommandNodeArguments{" + diff --git a/commands/src/main/java/com/wizardlybump17/wlib/command/rework/input/AllowedNumberInputs.java b/commands/src/main/java/com/wizardlybump17/wlib/command/rework/input/AllowedNumberInputs.java index b73e23a1..b72e5a81 100644 --- a/commands/src/main/java/com/wizardlybump17/wlib/command/rework/input/AllowedNumberInputs.java +++ b/commands/src/main/java/com/wizardlybump17/wlib/command/rework/input/AllowedNumberInputs.java @@ -21,5 +21,13 @@ public boolean isAllowed(@Nullable Integer input) { return isInRange(input); } } + + record Unlimited() implements AllowedIntegerInputs { + + @Override + public boolean isAllowed(@Nullable Integer input) { + return true; + } + } } } diff --git a/commands/src/test/java/com/wizardlybump17/wlib/command/test/rework/CommandTests.java b/commands/src/test/java/com/wizardlybump17/wlib/command/test/rework/CommandTests.java index ab17233b..3b64434b 100644 --- a/commands/src/test/java/com/wizardlybump17/wlib/command/test/rework/CommandTests.java +++ b/commands/src/test/java/com/wizardlybump17/wlib/command/test/rework/CommandTests.java @@ -1,13 +1,17 @@ package com.wizardlybump17.wlib.command.test.rework; import com.wizardlybump17.wlib.command.rework.Command; +import com.wizardlybump17.wlib.command.rework.context.CommandContext; import com.wizardlybump17.wlib.command.rework.node.LiteralCommandNode; +import com.wizardlybump17.wlib.command.rework.result.CommandResult; +import org.jetbrains.annotations.NotNull; import org.junit.jupiter.api.Assertions; import org.junit.jupiter.api.Test; +import java.lang.reflect.Method; import java.util.List; -class CommandTests { +public class CommandTests { @Test void testCreate() { @@ -40,4 +44,25 @@ void testCreate1() { Assertions.assertEquals(expected, created); } + + @Test + public void testCreate2() { + CommandTests object = new CommandTests(); + + for (Method method : object.getClass().getMethods()) { + if (method.isAnnotationPresent(com.wizardlybump17.wlib.command.rework.annotation.Command.class)) { + Command command = Command.fromMethod(method, object); + CommandResult result = command.execute(null, List.of("test", "test2")); + System.out.println(result); + } + } + } + + @com.wizardlybump17.wlib.command.rework.annotation.Command("test") + public void testCommand(@NotNull CommandContext context) { + } + + @com.wizardlybump17.wlib.command.rework.annotation.Command("test test2") + public void testCommand2(@NotNull CommandContext context) { + } } From 3731fec1ee90e3a80f3a719c2ca15d7ed20119ca Mon Sep 17 00:00:00 2001 From: WizardlyBump17 Date: Tue, 28 Oct 2025 21:52:57 -0300 Subject: [PATCH 039/363] added the ComponentCollector --- .../bukkit/collector/ComponentCollector.java | 65 +++++++++++++++++++ 1 file changed, 65 insertions(+) create mode 100644 bukkit-utils/src/main/java/com/wizardlybump17/wlib/util/bukkit/collector/ComponentCollector.java diff --git a/bukkit-utils/src/main/java/com/wizardlybump17/wlib/util/bukkit/collector/ComponentCollector.java b/bukkit-utils/src/main/java/com/wizardlybump17/wlib/util/bukkit/collector/ComponentCollector.java new file mode 100644 index 00000000..efd535a2 --- /dev/null +++ b/bukkit-utils/src/main/java/com/wizardlybump17/wlib/util/bukkit/collector/ComponentCollector.java @@ -0,0 +1,65 @@ +package com.wizardlybump17.wlib.util.bukkit.collector; + +import net.kyori.adventure.text.Component; +import org.jetbrains.annotations.NotNull; + +import java.util.Objects; +import java.util.Set; +import java.util.function.BiConsumer; +import java.util.function.BinaryOperator; +import java.util.function.Function; +import java.util.function.Supplier; +import java.util.stream.Collector; + +public class ComponentCollector implements Collector { + + public static final @NotNull ComponentCollector COMMA = new ComponentCollector(Component.text(", ")); + public static final @NotNull ComponentCollector NEW_LINE = new ComponentCollector(Component.text("\n")); + public static final @NotNull ComponentCollector EMPTY = new ComponentCollector(Component.empty()); + + private final @NotNull Component separator; + + public ComponentCollector(@NotNull Component separator) { + this.separator = separator; + } + + @Override + public @NotNull Supplier supplier() { + return () -> new Component[1]; + } + + @Override + public @NotNull BiConsumer accumulator() { + return (array, component) -> { + if (array[0] == null) + array[0] = component; + else + array[0] = array[0].append(separator).append(component); + }; + } + + @Override + public @NotNull BinaryOperator combiner() { + return (left, right) -> { + if (left[0] == null) + left[0] = right[0]; + else + left[0] = left[0].append(separator).append(right[0]); + return left; + }; + } + + @Override + public @NotNull Function finisher() { + return array -> Objects.requireNonNullElseGet(array[0], Component::empty); + } + + @Override + public @NotNull Set characteristics() { + return Set.of(); + } + + public @NotNull Component getSeparator() { + return separator; + } +} From 2c4909417179a6ac83d8193cad3ea0e1e4cc2973 Mon Sep 17 00:00:00 2001 From: WizardlyBump17 Date: Tue, 28 Oct 2025 22:07:27 -0300 Subject: [PATCH 040/363] sending object messages --- .../command/sender/BungeeCommandSender.java | 34 +++++++++ .../util/collector/ComponentCollector.java | 72 +++++++++++++++++++ .../command/sender/BasicCommandSender.java | 15 ++++ .../wlib/command/sender/CommandSender.java | 5 ++ .../command/sender/BukkitCommandSender.java | 36 ++++++++++ 5 files changed, 162 insertions(+) create mode 100644 bungee/src/main/java/com/wizardlybump17/wlib/bungee/util/collector/ComponentCollector.java diff --git a/bungee/src/main/java/com/wizardlybump17/wlib/bungee/command/sender/BungeeCommandSender.java b/bungee/src/main/java/com/wizardlybump17/wlib/bungee/command/sender/BungeeCommandSender.java index 702f31eb..f211ce88 100644 --- a/bungee/src/main/java/com/wizardlybump17/wlib/bungee/command/sender/BungeeCommandSender.java +++ b/bungee/src/main/java/com/wizardlybump17/wlib/bungee/command/sender/BungeeCommandSender.java @@ -1,11 +1,16 @@ package com.wizardlybump17.wlib.bungee.command.sender; +import com.wizardlybump17.wlib.bungee.util.collector.ComponentCollector; import lombok.RequiredArgsConstructor; +import net.md_5.bungee.api.chat.BaseComponent; import net.md_5.bungee.api.chat.TextComponent; import net.md_5.bungee.api.connection.ConnectedPlayer; import net.md_5.bungee.api.connection.ProxiedPlayer; import org.jetbrains.annotations.NotNull; +import org.jetbrains.annotations.Nullable; +import java.util.ArrayList; +import java.util.List; import java.util.UUID; @RequiredArgsConstructor @@ -28,6 +33,35 @@ public void sendMessage(String... messages) { handle.sendMessage(TextComponent.fromLegacyText(String.join("\n", messages))); } + @Override + public void sendMessage(@Nullable Object message) { + switch (message) { + case null -> handle.sendMessage(new TextComponent("null")); + case BaseComponent component -> handle.sendMessage(component); + default -> handle.sendMessage(new TextComponent(String.valueOf(message))); + } + } + + @Override + public void sendMessage(@Nullable Object @Nullable ... messages) { + if (messages == null) { + sendMessage((Object) null); + return; + } + + List components = new ArrayList<>(messages.length); + for (Object message : messages) { + switch (message) { + case null -> components.add(new TextComponent("null")); + case BaseComponent component -> components.add(component); + case String string -> components.add(new TextComponent(string)); + default -> components.add(new TextComponent(String.valueOf(message))); + } + } + + handle.sendMessage(components.stream().collect(ComponentCollector.NEW_LINE)); + } + @Override public String getName() { return handle.getName(); diff --git a/bungee/src/main/java/com/wizardlybump17/wlib/bungee/util/collector/ComponentCollector.java b/bungee/src/main/java/com/wizardlybump17/wlib/bungee/util/collector/ComponentCollector.java new file mode 100644 index 00000000..55c83b05 --- /dev/null +++ b/bungee/src/main/java/com/wizardlybump17/wlib/bungee/util/collector/ComponentCollector.java @@ -0,0 +1,72 @@ +package com.wizardlybump17.wlib.bungee.util.collector; + +import net.md_5.bungee.api.chat.BaseComponent; +import net.md_5.bungee.api.chat.TextComponent; +import org.jetbrains.annotations.NotNull; + +import java.util.Objects; +import java.util.Set; +import java.util.function.BiConsumer; +import java.util.function.BinaryOperator; +import java.util.function.Function; +import java.util.function.Supplier; +import java.util.stream.Collector; + +public class ComponentCollector implements Collector { + + public static final @NotNull ComponentCollector COMMA = new ComponentCollector(new TextComponent(", ")); + public static final @NotNull ComponentCollector NEW_LINE = new ComponentCollector(new TextComponent("\n")); + public static final @NotNull ComponentCollector EMPTY = new ComponentCollector(new TextComponent()); + + private final @NotNull BaseComponent separator; + + public ComponentCollector(@NotNull BaseComponent separator) { + this.separator = separator; + } + + @Override + public @NotNull Supplier supplier() { + return () -> new BaseComponent[1]; + } + + @Override + public @NotNull BiConsumer accumulator() { + return (array, component) -> { + if (array[0] == null) + array[0] = component.duplicate(); + else { + array[0] = array[0].duplicate(); + array[0].addExtra(separator); + array[0].addExtra(component); + } + }; + } + + @Override + public @NotNull BinaryOperator combiner() { + return (left, right) -> { + if (left[0] == null) + left[0] = right[0].duplicate(); + else { + left[0] = left[0].duplicate(); + left[0].addExtra(separator); + left[0].addExtra(right[0].duplicate()); + } + return left; + }; + } + + @Override + public @NotNull Function finisher() { + return array -> Objects.requireNonNullElseGet(array[0], TextComponent::new); + } + + @Override + public @NotNull Set characteristics() { + return Set.of(); + } + + public @NotNull BaseComponent getSeparator() { + return separator.duplicate(); + } +} diff --git a/commands/src/main/java/com/wizardlybump17/wlib/command/sender/BasicCommandSender.java b/commands/src/main/java/com/wizardlybump17/wlib/command/sender/BasicCommandSender.java index 8f2d8f86..11becfc8 100644 --- a/commands/src/main/java/com/wizardlybump17/wlib/command/sender/BasicCommandSender.java +++ b/commands/src/main/java/com/wizardlybump17/wlib/command/sender/BasicCommandSender.java @@ -3,10 +3,12 @@ import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.Nullable; +import java.util.Arrays; import java.util.Objects; import java.util.UUID; import java.util.function.Consumer; import java.util.function.Predicate; +import java.util.stream.Collectors; public class BasicCommandSender implements CommandSender { @@ -39,6 +41,19 @@ public void sendMessage(String... messages) { sendMessage(String.join("\n", messages)); } + @Override + public void sendMessage(@Nullable Object message) { + sendMessage(String.valueOf(message)); + } + + @Override + public void sendMessage(@Nullable Object @Nullable ... messages) { + if (messages == null) + sendMessage((Object) null); + else + sendMessage(Arrays.stream(messages).map(String::valueOf).collect(Collectors.joining("\n"))); + } + @Override public @NotNull String getName() { return name; diff --git a/commands/src/main/java/com/wizardlybump17/wlib/command/sender/CommandSender.java b/commands/src/main/java/com/wizardlybump17/wlib/command/sender/CommandSender.java index 0786ac74..80941403 100644 --- a/commands/src/main/java/com/wizardlybump17/wlib/command/sender/CommandSender.java +++ b/commands/src/main/java/com/wizardlybump17/wlib/command/sender/CommandSender.java @@ -1,6 +1,7 @@ package com.wizardlybump17.wlib.command.sender; import org.jetbrains.annotations.NotNull; +import org.jetbrains.annotations.Nullable; import java.util.UUID; @@ -20,6 +21,10 @@ public interface CommandSender { void sendMessage(String... messages); + void sendMessage(@Nullable Object message); + + void sendMessage(@Nullable Object @Nullable ... messages); + String getName(); boolean hasPermission(String permission); diff --git a/core/src/main/java/com/wizardlybump17/wlib/command/sender/BukkitCommandSender.java b/core/src/main/java/com/wizardlybump17/wlib/command/sender/BukkitCommandSender.java index e1f3fc9a..b5aac8ca 100644 --- a/core/src/main/java/com/wizardlybump17/wlib/command/sender/BukkitCommandSender.java +++ b/core/src/main/java/com/wizardlybump17/wlib/command/sender/BukkitCommandSender.java @@ -1,11 +1,17 @@ package com.wizardlybump17.wlib.command.sender; +import com.wizardlybump17.wlib.util.bukkit.collector.ComponentCollector; +import net.kyori.adventure.text.Component; +import net.kyori.adventure.text.ComponentLike; import org.bukkit.command.BlockCommandSender; import org.bukkit.command.ConsoleCommandSender; import org.bukkit.entity.Entity; import org.bukkit.entity.Player; import org.jetbrains.annotations.NotNull; +import org.jetbrains.annotations.Nullable; +import java.util.ArrayList; +import java.util.List; import java.util.UUID; public class BukkitCommandSender implements CommandSender { @@ -31,6 +37,36 @@ public void sendMessage(String... message) { handle.sendMessage(String.join("\n", message)); } + @Override + public void sendMessage(@Nullable Object message) { + switch (message) { + case null -> handle.sendMessage("null"); + case ComponentLike component -> handle.sendMessage(component); + case String string -> handle.sendMessage(string); + default -> handle.sendMessage(String.valueOf(message)); + } + } + + @Override + public void sendMessage(@Nullable Object @Nullable ... messages) { + if (messages == null) { + sendMessage((Object) null); + return; + } + + List components = new ArrayList<>(messages.length); + for (Object message : messages) { + switch (message) { + case null -> components.add(Component.text("null")); + case ComponentLike componentLike -> components.add(componentLike.asComponent()); + case String string -> components.add(Component.text(string)); + default -> components.add(Component.text(String.valueOf(message))); + } + } + + handle.sendMessage(components.stream().collect(ComponentCollector.NEW_LINE)); + } + @Override public String getName() { return handle.getName(); From 6ef7b05509d0410d83fc03c35fea10c2099623c5 Mon Sep 17 00:00:00 2001 From: WizardlyBump17 Date: Tue, 28 Oct 2025 22:12:41 -0300 Subject: [PATCH 041/363] added permissions --- .../wlib/command/rework/node/CommandNode.java | 32 +++++++++++++++---- .../rework/node/IntegerCommandNode.java | 24 +++++++++++--- .../rework/node/LiteralCommandNode.java | 24 +++++++++++--- 3 files changed, 66 insertions(+), 14 deletions(-) diff --git a/commands/src/main/java/com/wizardlybump17/wlib/command/rework/node/CommandNode.java b/commands/src/main/java/com/wizardlybump17/wlib/command/rework/node/CommandNode.java index 0c59be1a..30111426 100644 --- a/commands/src/main/java/com/wizardlybump17/wlib/command/rework/node/CommandNode.java +++ b/commands/src/main/java/com/wizardlybump17/wlib/command/rework/node/CommandNode.java @@ -19,24 +19,38 @@ public abstract class CommandNode { private final @NotNull @Unmodifiable List> children; private final @NotNull AllowedInputs allowedInputs; private final @Nullable CommandNodeExecutor executor; + private final @Nullable String permission; - public CommandNode(@NotNull String name, @NotNull List> children, @NotNull AllowedInputs allowedInputs, @Nullable CommandNodeExecutor executor) { + public CommandNode(@NotNull String name, @NotNull List> children, @NotNull AllowedInputs allowedInputs, @Nullable CommandNodeExecutor executor, @Nullable String permission) { this.name = name; this.children = Collections.unmodifiableList(children); this.allowedInputs = allowedInputs; this.executor = executor; + this.permission = permission; + } + + public CommandNode(@NotNull String name, @NotNull AllowedInputs allowedInputs, @Nullable CommandNodeExecutor executor, @Nullable String permission) { + this(name, List.of(), allowedInputs, executor, permission); + } + + public CommandNode(@NotNull String name, @NotNull List> children, @NotNull AllowedInputs allowedInputs, @Nullable String permission) { + this(name, children, allowedInputs, null, permission); + } + + public CommandNode(@NotNull String name, @NotNull AllowedInputs allowedInputs, @Nullable String permission) { + this(name, List.of(), allowedInputs, null, permission); } public CommandNode(@NotNull String name, @NotNull AllowedInputs allowedInputs, @Nullable CommandNodeExecutor executor) { - this(name, List.of(), allowedInputs, executor); + this(name, List.of(), allowedInputs, executor, null); } public CommandNode(@NotNull String name, @NotNull List> children, @NotNull AllowedInputs allowedInputs) { - this(name, children, allowedInputs, null); + this(name, children, allowedInputs, null, null); } public CommandNode(@NotNull String name, @NotNull AllowedInputs allowedInputs) { - this(name, List.of(), allowedInputs, null); + this(name, List.of(), allowedInputs, null, null); } public @NotNull String getName() { @@ -72,6 +86,10 @@ public final boolean isValidInput(@Nullable T input) { return executor; } + public @Nullable String getPermission() { + return permission; + } + @Override public String toString() { return "CommandNode{" + @@ -79,6 +97,7 @@ public String toString() { ", children=" + children + ", allowedInputs=" + allowedInputs + ", executor=" + executor + + ", permission='" + permission + '\'' + '}'; } @@ -90,11 +109,12 @@ public boolean equals(Object o) { return Objects.equals(name, that.name) && Objects.equals(children, that.children) && Objects.equals(allowedInputs, that.allowedInputs) - && Objects.equals(executor, that.executor); + && Objects.equals(executor, that.executor) + && Objects.equals(permission, that.permission); } @Override public int hashCode() { - return Objects.hash(name, children, allowedInputs, executor); + return Objects.hash(name, children, allowedInputs, executor, permission); } } diff --git a/commands/src/main/java/com/wizardlybump17/wlib/command/rework/node/IntegerCommandNode.java b/commands/src/main/java/com/wizardlybump17/wlib/command/rework/node/IntegerCommandNode.java index d5cef1f7..4c4acd18 100644 --- a/commands/src/main/java/com/wizardlybump17/wlib/command/rework/node/IntegerCommandNode.java +++ b/commands/src/main/java/com/wizardlybump17/wlib/command/rework/node/IntegerCommandNode.java @@ -13,20 +13,36 @@ public class IntegerCommandNode extends CommandNode { + public IntegerCommandNode(@NotNull String name, @NotNull List> children, @NotNull AllowedNumberInputs.AllowedIntegerInputs allowedInputs, @Nullable CommandNodeExecutor executor, @Nullable String permission) { + super(name, children, allowedInputs, executor, permission); + } + + public IntegerCommandNode(@NotNull String name, @NotNull AllowedNumberInputs.AllowedIntegerInputs allowedInputs, @Nullable CommandNodeExecutor executor, @Nullable String permission) { + this(name, List.of(), allowedInputs, executor, permission); + } + + public IntegerCommandNode(@NotNull String name, @NotNull List> children, @NotNull AllowedNumberInputs.AllowedIntegerInputs allowedInputs, @Nullable String permission) { + this(name, children, allowedInputs, null, permission); + } + + public IntegerCommandNode(@NotNull String name, @NotNull AllowedNumberInputs.AllowedIntegerInputs allowedInputs, @Nullable String permission) { + this(name, List.of(), allowedInputs, null, permission); + } + public IntegerCommandNode(@NotNull String name, @NotNull List> children, @NotNull AllowedNumberInputs.AllowedIntegerInputs allowedInputs, @Nullable CommandNodeExecutor executor) { - super(name, children, allowedInputs, executor); + super(name, children, allowedInputs, executor, null); } public IntegerCommandNode(@NotNull String name, @NotNull AllowedNumberInputs.AllowedIntegerInputs allowedInputs, @Nullable CommandNodeExecutor executor) { - this(name, List.of(), allowedInputs, executor); + this(name, List.of(), allowedInputs, executor, null); } public IntegerCommandNode(@NotNull String name, @NotNull List> children, @NotNull AllowedNumberInputs.AllowedIntegerInputs allowedInputs) { - this(name, children, allowedInputs, null); + this(name, children, allowedInputs, null, null); } public IntegerCommandNode(@NotNull String name, @NotNull AllowedNumberInputs.AllowedIntegerInputs allowedInputs) { - this(name, List.of(), allowedInputs, null); + this(name, List.of(), allowedInputs, null, null); } @Override diff --git a/commands/src/main/java/com/wizardlybump17/wlib/command/rework/node/LiteralCommandNode.java b/commands/src/main/java/com/wizardlybump17/wlib/command/rework/node/LiteralCommandNode.java index 80331514..26f42b37 100644 --- a/commands/src/main/java/com/wizardlybump17/wlib/command/rework/node/LiteralCommandNode.java +++ b/commands/src/main/java/com/wizardlybump17/wlib/command/rework/node/LiteralCommandNode.java @@ -10,20 +10,36 @@ public class LiteralCommandNode extends CommandNode { + public LiteralCommandNode(@NotNull String name, @NotNull List> children, @Nullable CommandNodeExecutor executor, @Nullable String permission) { + super(name, children, new LiteralAllowedInput(name, false), executor, permission); + } + + public LiteralCommandNode(@NotNull String name, @Nullable CommandNodeExecutor executor, @Nullable String permission) { + this(name, List.of(), executor, permission); + } + + public LiteralCommandNode(@NotNull String name, @NotNull List> children, @Nullable String permission) { + this(name, children, null, permission); + } + + public LiteralCommandNode(@NotNull String name, @Nullable String permission) { + this(name, List.of(), null, permission); + } + public LiteralCommandNode(@NotNull String name, @NotNull List> children, @Nullable CommandNodeExecutor executor) { - super(name, children, new LiteralAllowedInput(name, false), executor); + super(name, children, new LiteralAllowedInput(name, false), executor, null); } public LiteralCommandNode(@NotNull String name, @Nullable CommandNodeExecutor executor) { - this(name, List.of(), executor); + this(name, List.of(), executor, null); } public LiteralCommandNode(@NotNull String name, @NotNull List> children) { - this(name, children, null); + this(name, children, null, null); } public LiteralCommandNode(@NotNull String name) { - this(name, List.of(), null); + this(name, List.of(), null, null); } @Override From 7859ae4f4bb87208f7506a8566b7357ead84bf58 Mon Sep 17 00:00:00 2001 From: WizardlyBump17 Date: Tue, 28 Oct 2025 22:22:36 -0300 Subject: [PATCH 042/363] added some more AllowedNumberInputs --- .../rework/input/AllowedNumberInputs.java | 25 +++++++++++ .../rework/node/IntegerCommandNode.java | 45 ++++++++++++------- 2 files changed, 53 insertions(+), 17 deletions(-) diff --git a/commands/src/main/java/com/wizardlybump17/wlib/command/rework/input/AllowedNumberInputs.java b/commands/src/main/java/com/wizardlybump17/wlib/command/rework/input/AllowedNumberInputs.java index b72e5a81..28263b64 100644 --- a/commands/src/main/java/com/wizardlybump17/wlib/command/rework/input/AllowedNumberInputs.java +++ b/commands/src/main/java/com/wizardlybump17/wlib/command/rework/input/AllowedNumberInputs.java @@ -3,6 +3,8 @@ import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.Nullable; +import java.util.List; + public interface AllowedNumberInputs extends AllowedInputs { interface AllowedIntegerInputs extends AllowedInputs { @@ -29,5 +31,28 @@ public boolean isAllowed(@Nullable Integer input) { return true; } } + + record SingleValue(int value) implements AllowedIntegerInputs { + + @Override + public boolean isAllowed(@Nullable Integer input) { + return input != null && input.compareTo(value) == 0; + } + } + + record ValuesList(@NotNull List values) implements AllowedIntegerInputs { + + @Override + public boolean isAllowed(@Nullable Integer input) { + if (input == null) + return false; + + for (Integer value : values) + if (input.compareTo(value) == 0) + return true; + + return false; + } + } } } diff --git a/commands/src/main/java/com/wizardlybump17/wlib/command/rework/node/IntegerCommandNode.java b/commands/src/main/java/com/wizardlybump17/wlib/command/rework/node/IntegerCommandNode.java index 4c4acd18..b646ccd3 100644 --- a/commands/src/main/java/com/wizardlybump17/wlib/command/rework/node/IntegerCommandNode.java +++ b/commands/src/main/java/com/wizardlybump17/wlib/command/rework/node/IntegerCommandNode.java @@ -61,22 +61,33 @@ public IntegerCommandNode(@NotNull String name, @NotNull AllowedNumberInputs.All @Override public @NotNull List getSuggestions(@NotNull CommandSender sender, @NotNull List args, @NotNull String currentInput) { - if (!currentInput.isEmpty()) - return List.of(); - - AllowedNumberInputs.AllowedIntegerInputs allowedInputs = getAllowedInputs(); - - if (allowedInputs instanceof RangedAllowedInputs ranged) { - int from = (int) ranged.from(); - int to = (int) ranged.to(); - - if (to - from < 5) - return IntStream.rangeClosed(from, to).boxed().toList(); - - int fourth = (to - from) / 4; - return List.of(from, from + fourth, from + fourth * 2, from + fourth * 3, to); - } - - return List.of(-100, -10, 0, 10, 100); + return switch (getAllowedInputs()) { + case RangedAllowedInputs ranged -> { + int from = (int) ranged.from(); + int to = (int) ranged.to(); + + if (to - from < 5) + yield IntStream.rangeClosed(from, to).boxed().toList(); + + int fourth = (to - from) / 4; + yield List.of(from, from + fourth, from + fourth * 2, from + fourth * 3, to); + } + case AllowedNumberInputs.AllowedIntegerInputs.SingleValue singleValue -> List.of(singleValue.value()); + case AllowedNumberInputs.AllowedIntegerInputs.ValuesList valuesList -> { + List list = valuesList.values(); + if (list.size() < 5) + yield list; + + int fourth = list.size() / 4; + yield List.of( + list.get(0), + list.get(fourth), + list.get(fourth * 2), + list.get(fourth * 3), + list.get(list.size() - 1) + ); + } + default -> List.of(-100, -10, 0, 10, 100); + }; } } From 401f40c4fb4d36f54738079c6ec0e7bcfa81849a Mon Sep 17 00:00:00 2001 From: WizardlyBump17 Date: Tue, 28 Oct 2025 22:27:17 -0300 Subject: [PATCH 043/363] checking for permissions --- .../wizardlybump17/wlib/command/rework/Command.java | 4 ++++ .../wlib/command/rework/result/CommandResult.java | 8 ++++++++ .../rework/result/error/NoPermissionResult.java | 11 +++++++++++ 3 files changed, 23 insertions(+) create mode 100644 commands/src/main/java/com/wizardlybump17/wlib/command/rework/result/error/NoPermissionResult.java diff --git a/commands/src/main/java/com/wizardlybump17/wlib/command/rework/Command.java b/commands/src/main/java/com/wizardlybump17/wlib/command/rework/Command.java index a7985857..7ef439a6 100644 --- a/commands/src/main/java/com/wizardlybump17/wlib/command/rework/Command.java +++ b/commands/src/main/java/com/wizardlybump17/wlib/command/rework/Command.java @@ -89,6 +89,10 @@ public Command(@NotNull LiteralCommandNode root) { if (executor == null) return CommandResult.noCommandNodeExecutor(lastInputIndex, lastNode); + String nodePermission = lastNode.getPermission(); + if (nodePermission != null && !sender.hasPermission(nodePermission)) + return CommandResult.noPermission(lastInputIndex, lastNode); + CommandContext context = new CommandContext( this, sender, diff --git a/commands/src/main/java/com/wizardlybump17/wlib/command/rework/result/CommandResult.java b/commands/src/main/java/com/wizardlybump17/wlib/command/rework/result/CommandResult.java index b5d16bc7..2a806b05 100644 --- a/commands/src/main/java/com/wizardlybump17/wlib/command/rework/result/CommandResult.java +++ b/commands/src/main/java/com/wizardlybump17/wlib/command/rework/result/CommandResult.java @@ -55,6 +55,10 @@ public interface CommandResult { return new GenericErrorResult<>(lastInputIndex, lastNode); } + static @NotNull NoPermissionResult noPermission(int lastInputIndex, @NotNull CommandNode lastNode) { + return new NoPermissionResult<>(lastInputIndex, lastNode); + } + //with context static @NotNull SuccessResult successful(@NotNull CommandContext context, @Nullable T data) { @@ -72,4 +76,8 @@ public interface CommandResult { static @NotNull GenericErrorResult genericError(@NotNull CommandContext context) { return genericError(context.lastInputIndex(), context.lastNode()); } + + static @NotNull NoPermissionResult noPermission(@NotNull CommandContext context) { + return noPermission(context.lastInputIndex(), context.lastNode()); + } } diff --git a/commands/src/main/java/com/wizardlybump17/wlib/command/rework/result/error/NoPermissionResult.java b/commands/src/main/java/com/wizardlybump17/wlib/command/rework/result/error/NoPermissionResult.java new file mode 100644 index 00000000..804ce428 --- /dev/null +++ b/commands/src/main/java/com/wizardlybump17/wlib/command/rework/result/error/NoPermissionResult.java @@ -0,0 +1,11 @@ +package com.wizardlybump17.wlib.command.rework.result.error; + +import com.wizardlybump17.wlib.command.rework.node.CommandNode; +import org.jetbrains.annotations.NotNull; + +public record NoPermissionResult(int lastInputIndex, @NotNull CommandNode lastNode) implements UnsuccessResult { + + public @NotNull String permission() { + return lastNode.getPermission(); + } +} From 963fafcbe6bc18c7c4f516c081a2566a2a75c05f Mon Sep 17 00:00:00 2001 From: WizardlyBump17 Date: Tue, 28 Oct 2025 22:33:30 -0300 Subject: [PATCH 044/363] starting the suggestion system --- .../wlib/command/rework/Command.java | 49 +++++++++++++++++++ .../wlib/command/rework/node/CommandNode.java | 2 +- .../rework/node/IntegerCommandNode.java | 2 +- .../rework/node/LiteralCommandNode.java | 2 +- 4 files changed, 52 insertions(+), 3 deletions(-) diff --git a/commands/src/main/java/com/wizardlybump17/wlib/command/rework/Command.java b/commands/src/main/java/com/wizardlybump17/wlib/command/rework/Command.java index 7ef439a6..205c3010 100644 --- a/commands/src/main/java/com/wizardlybump17/wlib/command/rework/Command.java +++ b/commands/src/main/java/com/wizardlybump17/wlib/command/rework/Command.java @@ -107,6 +107,55 @@ public Command(@NotNull LiteralCommandNode root) { return StringUtil.parseQuotedStrings(original); } + public @NotNull List getSuggestions(@NotNull CommandSender sender, @NotNull List input) { + if (input.isEmpty()) + return List.of(); + + String currentInput = input.getLast(); + + List suggestions = new ArrayList<>(); + List> children = List.of(root); + + CommandNode lastNode = null; + InputParsingException lastParsingError = null; + + inputLoop: for (int i = 0; i < input.size(); i++) { + String inputString = input.get(i); + + for (CommandNode child : children) { + lastNode = child; + + try { + child.parse(inputString); + + suggestions.addAll(child.getSuggestions(sender, input, currentInput).stream().map(String::valueOf).toList()); + + children = child.getChildren(); + + lastParsingError = null; + + continue inputLoop; + } catch (InputParsingException e) { + lastParsingError = e; + } + } + + if (lastParsingError != null) + return List.of(); + + return List.of(); + } + + if (lastNode == null) + return List.of(); + + String nodePermission = lastNode.getPermission(); + if (nodePermission != null && !sender.hasPermission(nodePermission)) + return List.of(); + + return suggestions; + } + public static @Nullable Command createCommand(@NotNull String execution) { LiteralCommandNode firstNode = null; diff --git a/commands/src/main/java/com/wizardlybump17/wlib/command/rework/node/CommandNode.java b/commands/src/main/java/com/wizardlybump17/wlib/command/rework/node/CommandNode.java index 30111426..7c520b05 100644 --- a/commands/src/main/java/com/wizardlybump17/wlib/command/rework/node/CommandNode.java +++ b/commands/src/main/java/com/wizardlybump17/wlib/command/rework/node/CommandNode.java @@ -78,7 +78,7 @@ public final boolean isValidInput(@Nullable T input) { return parse; } - public @NotNull List getSuggestions(@NotNull CommandSender sender, @NotNull List args, @NotNull String currentInput) { + public @NotNull List getSuggestions(@NotNull CommandSender sender, @NotNull List args, @NotNull String currentInput) { return List.of(); } diff --git a/commands/src/main/java/com/wizardlybump17/wlib/command/rework/node/IntegerCommandNode.java b/commands/src/main/java/com/wizardlybump17/wlib/command/rework/node/IntegerCommandNode.java index b646ccd3..7df12981 100644 --- a/commands/src/main/java/com/wizardlybump17/wlib/command/rework/node/IntegerCommandNode.java +++ b/commands/src/main/java/com/wizardlybump17/wlib/command/rework/node/IntegerCommandNode.java @@ -60,7 +60,7 @@ public IntegerCommandNode(@NotNull String name, @NotNull AllowedNumberInputs.All } @Override - public @NotNull List getSuggestions(@NotNull CommandSender sender, @NotNull List args, @NotNull String currentInput) { + public @NotNull List getSuggestions(@NotNull CommandSender sender, @NotNull List args, @NotNull String currentInput) { return switch (getAllowedInputs()) { case RangedAllowedInputs ranged -> { int from = (int) ranged.from(); diff --git a/commands/src/main/java/com/wizardlybump17/wlib/command/rework/node/LiteralCommandNode.java b/commands/src/main/java/com/wizardlybump17/wlib/command/rework/node/LiteralCommandNode.java index 26f42b37..1884a9d8 100644 --- a/commands/src/main/java/com/wizardlybump17/wlib/command/rework/node/LiteralCommandNode.java +++ b/commands/src/main/java/com/wizardlybump17/wlib/command/rework/node/LiteralCommandNode.java @@ -53,7 +53,7 @@ public LiteralCommandNode(@NotNull String name) { } @Override - public @NotNull List getSuggestions(@NotNull CommandSender sender, @NotNull List args, @NotNull String currentInput) { + public @NotNull List getSuggestions(@NotNull CommandSender sender, @NotNull List args, @NotNull String currentInput) { return List.of(getName()); } } From bec948d4c6fca751bfcb3dda2f78c324963506de Mon Sep 17 00:00:00 2001 From: WizardlyBump17 Date: Tue, 28 Oct 2025 22:52:19 -0300 Subject: [PATCH 045/363] suggesting stuff --- .../wlib/command/rework/Command.java | 38 ++++++++++++++----- .../command/test/rework/SuggestionTests.java | 36 ++++++++++++++++++ 2 files changed, 64 insertions(+), 10 deletions(-) create mode 100644 commands/src/test/java/com/wizardlybump17/wlib/command/test/rework/SuggestionTests.java diff --git a/commands/src/main/java/com/wizardlybump17/wlib/command/rework/Command.java b/commands/src/main/java/com/wizardlybump17/wlib/command/rework/Command.java index 205c3010..f81301ea 100644 --- a/commands/src/main/java/com/wizardlybump17/wlib/command/rework/Command.java +++ b/commands/src/main/java/com/wizardlybump17/wlib/command/rework/Command.java @@ -109,7 +109,7 @@ public Command(@NotNull LiteralCommandNode root) { public @NotNull List getSuggestions(@NotNull CommandSender sender, @NotNull List input) { if (input.isEmpty()) - return List.of(); + return List.of(root.getName()); String currentInput = input.getLast(); @@ -121,20 +121,41 @@ public Command(@NotNull LiteralCommandNode root) { inputLoop: for (int i = 0; i < input.size(); i++) { String inputString = input.get(i); + boolean isLastInput = i == input.size() - 1; + + if (inputString.isEmpty()) { + suggestions.addAll(children.stream() + .filter(child -> { + String permission = child.getPermission(); + return permission == null || sender.hasPermission(permission); + }) + .map(CommandNode::getName) + .toList() + ); + break; + } + boolean foundNode = false; for (CommandNode child : children) { lastNode = child; try { + foundNode = true; + child.parse(inputString); - suggestions.addAll(child.getSuggestions(sender, input, currentInput).stream().map(String::valueOf).toList()); - - children = child.getChildren(); + String permission = child.getPermission(); + if (isLastInput && (permission == null || sender.hasPermission(permission))) + suggestions.addAll(child.getSuggestions(sender, input, currentInput).stream().map(String::valueOf).toList()); lastParsingError = null; - continue inputLoop; + if (isLastInput) { + continue; + } else { + children = child.getChildren(); + continue inputLoop; + } } catch (InputParsingException e) { lastParsingError = e; } @@ -143,16 +164,13 @@ public Command(@NotNull LiteralCommandNode root) { if (lastParsingError != null) return List.of(); - return List.of(); + if (!foundNode) + return List.of(); } if (lastNode == null) return List.of(); - String nodePermission = lastNode.getPermission(); - if (nodePermission != null && !sender.hasPermission(nodePermission)) - return List.of(); - return suggestions; } diff --git a/commands/src/test/java/com/wizardlybump17/wlib/command/test/rework/SuggestionTests.java b/commands/src/test/java/com/wizardlybump17/wlib/command/test/rework/SuggestionTests.java new file mode 100644 index 00000000..22290ed9 --- /dev/null +++ b/commands/src/test/java/com/wizardlybump17/wlib/command/test/rework/SuggestionTests.java @@ -0,0 +1,36 @@ +package com.wizardlybump17.wlib.command.test.rework; + +import com.wizardlybump17.wlib.command.rework.Command; +import com.wizardlybump17.wlib.command.rework.input.AllowedNumberInputs; +import com.wizardlybump17.wlib.command.rework.node.IntegerCommandNode; +import com.wizardlybump17.wlib.command.rework.node.LiteralCommandNode; +import com.wizardlybump17.wlib.command.rework.result.CommandResult; +import org.junit.jupiter.api.Test; + +import java.util.List; + +class SuggestionTests { + + @Test + void test() { + Command command = new Command( + new LiteralCommandNode("hello", List.of( + new LiteralCommandNode("world", List.of( + new IntegerCommandNode("a1", new AllowedNumberInputs.AllowedIntegerInputs.Range(10, 100), context -> CommandResult.successful(context, "a1")) + )), + new LiteralCommandNode("world1", List.of( + new IntegerCommandNode("a1", new AllowedNumberInputs.AllowedIntegerInputs.Range(10, 100), context -> CommandResult.successful(context, "a1")) + )), + new LiteralCommandNode("world2", List.of( + new IntegerCommandNode("a1", new AllowedNumberInputs.AllowedIntegerInputs.Range(10, 100), context -> CommandResult.successful(context, "a1")) + )), + new LiteralCommandNode("world3", List.of( + new IntegerCommandNode("a1", new AllowedNumberInputs.AllowedIntegerInputs.Range(10, 100), context -> CommandResult.successful(context, "a1")) + )) + )) + ); + + List suggestions = command.getSuggestions(null, List.of("hello", "world")); + System.out.println(suggestions); + } +} From 01239d1b66866534ea4318011e5f8008d643b88d Mon Sep 17 00:00:00 2001 From: WizardlyBump17 Date: Tue, 28 Oct 2025 23:10:25 -0300 Subject: [PATCH 046/363] starting the CommandManager system --- .../rework/manager/CommandManager.java | 50 +++++++++++++++++++ .../command/rework/result/CommandResult.java | 4 ++ .../result/error/CommandNotFoundResult.java | 32 ++++++++++++ 3 files changed, 86 insertions(+) create mode 100644 commands/src/main/java/com/wizardlybump17/wlib/command/rework/manager/CommandManager.java create mode 100644 commands/src/main/java/com/wizardlybump17/wlib/command/rework/result/error/CommandNotFoundResult.java diff --git a/commands/src/main/java/com/wizardlybump17/wlib/command/rework/manager/CommandManager.java b/commands/src/main/java/com/wizardlybump17/wlib/command/rework/manager/CommandManager.java new file mode 100644 index 00000000..b314052c --- /dev/null +++ b/commands/src/main/java/com/wizardlybump17/wlib/command/rework/manager/CommandManager.java @@ -0,0 +1,50 @@ +package com.wizardlybump17.wlib.command.rework.manager; + +import com.wizardlybump17.wlib.command.rework.Command; +import com.wizardlybump17.wlib.command.rework.result.CommandResult; +import com.wizardlybump17.wlib.command.sender.CommandSender; +import org.jetbrains.annotations.NotNull; + +import java.util.HashMap; +import java.util.List; +import java.util.Map; + +public class CommandManager { + + private static final char SEPARATOR = ':'; + + private final @NotNull Map commands = new HashMap<>(); + + public @NotNull Command registerCommand(@NotNull String identifier, @NotNull Command command) { + String commandName = command.getRoot().getName().toLowerCase(); + String fullCommandName = identifier + SEPARATOR + commandName; + Command existingCommand = commands.get(fullCommandName); + + if (existingCommand != null) { + Command newCommand = mergeCommand(command, existingCommand); + commands.put(fullCommandName, newCommand); + commands.put(commandName, newCommand); + return newCommand; + } + + commands.put(fullCommandName, command); + commands.put(commandName, command); + return command; + } + + protected @NotNull Command mergeCommand(@NotNull Command left, @NotNull Command right) { + return right; + } + + public @NotNull CommandResult execute(@NotNull CommandSender sender, @NotNull List input) { + if (input.isEmpty()) + return CommandResult.commandNotFound(""); + + String commandName = input.getFirst(); + + Command command = commands.get(commandName); + if (command == null) + return CommandResult.commandNotFound(commandName); + return command.execute(sender, input); + } +} diff --git a/commands/src/main/java/com/wizardlybump17/wlib/command/rework/result/CommandResult.java b/commands/src/main/java/com/wizardlybump17/wlib/command/rework/result/CommandResult.java index 2a806b05..7e0ab147 100644 --- a/commands/src/main/java/com/wizardlybump17/wlib/command/rework/result/CommandResult.java +++ b/commands/src/main/java/com/wizardlybump17/wlib/command/rework/result/CommandResult.java @@ -59,6 +59,10 @@ public interface CommandResult { return new NoPermissionResult<>(lastInputIndex, lastNode); } + static @NotNull CommandNotFoundResult commandNotFound(@NotNull String input) { + return new CommandNotFoundResult<>(input); + } + //with context static @NotNull SuccessResult successful(@NotNull CommandContext context, @Nullable T data) { diff --git a/commands/src/main/java/com/wizardlybump17/wlib/command/rework/result/error/CommandNotFoundResult.java b/commands/src/main/java/com/wizardlybump17/wlib/command/rework/result/error/CommandNotFoundResult.java new file mode 100644 index 00000000..d63833ac --- /dev/null +++ b/commands/src/main/java/com/wizardlybump17/wlib/command/rework/result/error/CommandNotFoundResult.java @@ -0,0 +1,32 @@ +package com.wizardlybump17.wlib.command.rework.result.error; + +import com.wizardlybump17.wlib.command.rework.node.CommandNode; +import org.jetbrains.annotations.NotNull; +import org.jetbrains.annotations.Nullable; + +public record CommandNotFoundResult(@NotNull String input) implements UnsuccessResult { + + @Override + public int lastInputIndex() { + return -1; + } + + @Override + public @NotNull CommandNode lastNode() { + return DummyNode.INSTANCE; + } + + private static final class DummyNode extends CommandNode { + + public static final @NotNull DummyNode INSTANCE = new DummyNode(); + + private DummyNode() { + super("DummyNode", $ -> true); + } + + @Override + public @Nullable Object parse(@NotNull String input) { + return null; + } + } +} From 6cf3c4c501f76f92fb95a419693309f6251c8a39 Mon Sep 17 00:00:00 2001 From: WizardlyBump17 Date: Tue, 28 Oct 2025 23:18:41 -0300 Subject: [PATCH 047/363] merging? --- .../wlib/command/rework/Command.java | 9 ++++-- .../rework/manager/CommandManager.java | 2 +- .../wlib/command/rework/node/CommandNode.java | 30 ++++++++++++++----- 3 files changed, 31 insertions(+), 10 deletions(-) diff --git a/commands/src/main/java/com/wizardlybump17/wlib/command/rework/Command.java b/commands/src/main/java/com/wizardlybump17/wlib/command/rework/Command.java index f81301ea..5b1ca167 100644 --- a/commands/src/main/java/com/wizardlybump17/wlib/command/rework/Command.java +++ b/commands/src/main/java/com/wizardlybump17/wlib/command/rework/Command.java @@ -19,6 +19,7 @@ import java.lang.invoke.MethodType; import java.lang.reflect.Method; import java.util.ArrayList; +import java.util.Collection; import java.util.List; import java.util.Objects; @@ -45,7 +46,7 @@ public Command(@NotNull LiteralCommandNode root) { return CommandResult.insufficientArguments(-1, root); List> arguments = new ArrayList<>(); - List> children = List.of(root); + Collection> children = List.of(root); CommandNode lastNode = null; int lastInputIndex = 0; @@ -114,7 +115,7 @@ public Command(@NotNull LiteralCommandNode root) { String currentInput = input.getLast(); List suggestions = new ArrayList<>(); - List> children = List.of(root); + Collection> children = List.of(root); CommandNode lastNode = null; InputParsingException lastParsingError = null; @@ -174,6 +175,10 @@ public Command(@NotNull LiteralCommandNode root) { return suggestions; } + public @NotNull Command merge(@NotNull Command other) { + return new Command((LiteralCommandNode) root.merge(other.getRoot())); + } + public static @Nullable Command createCommand(@NotNull String execution) { LiteralCommandNode firstNode = null; diff --git a/commands/src/main/java/com/wizardlybump17/wlib/command/rework/manager/CommandManager.java b/commands/src/main/java/com/wizardlybump17/wlib/command/rework/manager/CommandManager.java index b314052c..74e250f4 100644 --- a/commands/src/main/java/com/wizardlybump17/wlib/command/rework/manager/CommandManager.java +++ b/commands/src/main/java/com/wizardlybump17/wlib/command/rework/manager/CommandManager.java @@ -33,7 +33,7 @@ public class CommandManager { } protected @NotNull Command mergeCommand(@NotNull Command left, @NotNull Command right) { - return right; + return left.merge(right); } public @NotNull CommandResult execute(@NotNull CommandSender sender, @NotNull List input) { diff --git a/commands/src/main/java/com/wizardlybump17/wlib/command/rework/node/CommandNode.java b/commands/src/main/java/com/wizardlybump17/wlib/command/rework/node/CommandNode.java index 7c520b05..7f9e62be 100644 --- a/commands/src/main/java/com/wizardlybump17/wlib/command/rework/node/CommandNode.java +++ b/commands/src/main/java/com/wizardlybump17/wlib/command/rework/node/CommandNode.java @@ -5,25 +5,24 @@ import com.wizardlybump17.wlib.command.rework.executor.CommandNodeExecutor; import com.wizardlybump17.wlib.command.rework.input.AllowedInputs; import com.wizardlybump17.wlib.command.sender.CommandSender; +import com.wizardlybump17.wlib.util.MapUtils; import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.Nullable; import org.jetbrains.annotations.Unmodifiable; -import java.util.Collections; -import java.util.List; -import java.util.Objects; +import java.util.*; public abstract class CommandNode { private final @NotNull String name; - private final @NotNull @Unmodifiable List> children; + private final @NotNull LinkedHashMap> children; private final @NotNull AllowedInputs allowedInputs; private final @Nullable CommandNodeExecutor executor; private final @Nullable String permission; public CommandNode(@NotNull String name, @NotNull List> children, @NotNull AllowedInputs allowedInputs, @Nullable CommandNodeExecutor executor, @Nullable String permission) { this.name = name; - this.children = Collections.unmodifiableList(children); + this.children = (LinkedHashMap>) MapUtils.collectionToMap(LinkedHashMap::new, children, CommandNode::getName); this.allowedInputs = allowedInputs; this.executor = executor; this.permission = permission; @@ -57,8 +56,8 @@ public CommandNode(@NotNull String name, @NotNull AllowedInputs allowedInputs return name; } - public @NotNull @Unmodifiable List> getChildren() { - return children; + public @NotNull @Unmodifiable SequencedCollection> getChildren() { + return Collections.unmodifiableSequencedCollection(children.sequencedValues()); } public @NotNull AllowedInputs getAllowedInputs() { @@ -117,4 +116,21 @@ public boolean equals(Object o) { public int hashCode() { return Objects.hash(name, children, allowedInputs, executor, permission); } + + public abstract @NotNull CommandNode withChildren(@NotNull List> children); + + public @NotNull CommandNode merge(@NotNull CommandNode other) { + LinkedHashMap> newChildren = new LinkedHashMap<>(); + + children.forEach((leftKey, leftChild) -> { + if (!other.children.containsKey(leftKey)) { + newChildren.put(leftKey, leftChild); + return; + } + + newChildren.put(leftKey, leftChild.merge(other.children.get(leftKey))); + }); + + return withChildren(new ArrayList<>(newChildren.values())); + } } From 35ab2b59eeb601e50de876ad4fd1af39c47ac4a7 Mon Sep 17 00:00:00 2001 From: WizardlyBump17 Date: Tue, 28 Oct 2025 23:34:50 -0300 Subject: [PATCH 048/363] merging. --- .../rework/manager/CommandManager.java | 7 +- .../wlib/command/rework/node/CommandNode.java | 8 +- .../rework/node/IntegerCommandNode.java | 5 ++ .../rework/node/LiteralCommandNode.java | 5 ++ .../result/error/CommandNotFoundResult.java | 7 ++ .../test/rework/CommandManagerTests.java | 78 +++++++++++++++++++ 6 files changed, 105 insertions(+), 5 deletions(-) create mode 100644 commands/src/test/java/com/wizardlybump17/wlib/command/test/rework/CommandManagerTests.java diff --git a/commands/src/main/java/com/wizardlybump17/wlib/command/rework/manager/CommandManager.java b/commands/src/main/java/com/wizardlybump17/wlib/command/rework/manager/CommandManager.java index 74e250f4..9804cfc8 100644 --- a/commands/src/main/java/com/wizardlybump17/wlib/command/rework/manager/CommandManager.java +++ b/commands/src/main/java/com/wizardlybump17/wlib/command/rework/manager/CommandManager.java @@ -8,6 +8,7 @@ import java.util.HashMap; import java.util.List; import java.util.Map; +import java.util.Optional; public class CommandManager { @@ -21,7 +22,7 @@ public class CommandManager { Command existingCommand = commands.get(fullCommandName); if (existingCommand != null) { - Command newCommand = mergeCommand(command, existingCommand); + Command newCommand = mergeCommand(existingCommand, command); commands.put(fullCommandName, newCommand); commands.put(commandName, newCommand); return newCommand; @@ -47,4 +48,8 @@ public class CommandManager { return CommandResult.commandNotFound(commandName); return command.execute(sender, input); } + + public @NotNull Optional getCommand(@NotNull String name) { + return Optional.ofNullable(commands.get(name)); + } } diff --git a/commands/src/main/java/com/wizardlybump17/wlib/command/rework/node/CommandNode.java b/commands/src/main/java/com/wizardlybump17/wlib/command/rework/node/CommandNode.java index 7f9e62be..10550a59 100644 --- a/commands/src/main/java/com/wizardlybump17/wlib/command/rework/node/CommandNode.java +++ b/commands/src/main/java/com/wizardlybump17/wlib/command/rework/node/CommandNode.java @@ -120,15 +120,15 @@ public int hashCode() { public abstract @NotNull CommandNode withChildren(@NotNull List> children); public @NotNull CommandNode merge(@NotNull CommandNode other) { - LinkedHashMap> newChildren = new LinkedHashMap<>(); + LinkedHashMap> newChildren = new LinkedHashMap<>(children); - children.forEach((leftKey, leftChild) -> { - if (!other.children.containsKey(leftKey)) { + other.children.forEach((leftKey, leftChild) -> { + if (!children.containsKey(leftKey)) { newChildren.put(leftKey, leftChild); return; } - newChildren.put(leftKey, leftChild.merge(other.children.get(leftKey))); + newChildren.put(leftKey, leftChild.merge(children.get(leftKey))); }); return withChildren(new ArrayList<>(newChildren.values())); diff --git a/commands/src/main/java/com/wizardlybump17/wlib/command/rework/node/IntegerCommandNode.java b/commands/src/main/java/com/wizardlybump17/wlib/command/rework/node/IntegerCommandNode.java index 7df12981..4a750b4d 100644 --- a/commands/src/main/java/com/wizardlybump17/wlib/command/rework/node/IntegerCommandNode.java +++ b/commands/src/main/java/com/wizardlybump17/wlib/command/rework/node/IntegerCommandNode.java @@ -90,4 +90,9 @@ public IntegerCommandNode(@NotNull String name, @NotNull AllowedNumberInputs.All default -> List.of(-100, -10, 0, 10, 100); }; } + + @Override + public @NotNull IntegerCommandNode withChildren(@NotNull List> children) { + return new IntegerCommandNode(getName(), children, getAllowedInputs(), getExecutor(), getPermission()); + } } diff --git a/commands/src/main/java/com/wizardlybump17/wlib/command/rework/node/LiteralCommandNode.java b/commands/src/main/java/com/wizardlybump17/wlib/command/rework/node/LiteralCommandNode.java index 1884a9d8..a9f40f8a 100644 --- a/commands/src/main/java/com/wizardlybump17/wlib/command/rework/node/LiteralCommandNode.java +++ b/commands/src/main/java/com/wizardlybump17/wlib/command/rework/node/LiteralCommandNode.java @@ -56,4 +56,9 @@ public LiteralCommandNode(@NotNull String name) { public @NotNull List getSuggestions(@NotNull CommandSender sender, @NotNull List args, @NotNull String currentInput) { return List.of(getName()); } + + @Override + public @NotNull LiteralCommandNode withChildren(@NotNull List> children) { + return new LiteralCommandNode(getName(), children, getExecutor(), getPermission()); + } } diff --git a/commands/src/main/java/com/wizardlybump17/wlib/command/rework/result/error/CommandNotFoundResult.java b/commands/src/main/java/com/wizardlybump17/wlib/command/rework/result/error/CommandNotFoundResult.java index d63833ac..0565f2c3 100644 --- a/commands/src/main/java/com/wizardlybump17/wlib/command/rework/result/error/CommandNotFoundResult.java +++ b/commands/src/main/java/com/wizardlybump17/wlib/command/rework/result/error/CommandNotFoundResult.java @@ -4,6 +4,8 @@ import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.Nullable; +import java.util.List; + public record CommandNotFoundResult(@NotNull String input) implements UnsuccessResult { @Override @@ -28,5 +30,10 @@ private DummyNode() { public @Nullable Object parse(@NotNull String input) { return null; } + + @Override + public @NotNull DummyNode withChildren(@NotNull List> children) { + return this; + } } } diff --git a/commands/src/test/java/com/wizardlybump17/wlib/command/test/rework/CommandManagerTests.java b/commands/src/test/java/com/wizardlybump17/wlib/command/test/rework/CommandManagerTests.java new file mode 100644 index 00000000..59de8b1a --- /dev/null +++ b/commands/src/test/java/com/wizardlybump17/wlib/command/test/rework/CommandManagerTests.java @@ -0,0 +1,78 @@ +package com.wizardlybump17.wlib.command.test.rework; + +import com.wizardlybump17.wlib.command.rework.Command; +import com.wizardlybump17.wlib.command.rework.executor.CommandNodeExecutor; +import com.wizardlybump17.wlib.command.rework.input.AllowedNumberInputs; +import com.wizardlybump17.wlib.command.rework.manager.CommandManager; +import com.wizardlybump17.wlib.command.rework.node.IntegerCommandNode; +import com.wizardlybump17.wlib.command.rework.node.LiteralCommandNode; +import com.wizardlybump17.wlib.command.rework.result.CommandResult; +import org.junit.jupiter.api.Assertions; +import org.junit.jupiter.api.Test; + +import java.util.List; + +class CommandManagerTests { + + @Test + void test() { + CommandNodeExecutor executor = context -> CommandResult.successful(context, "a1"); + + Command command0 = new Command( + new LiteralCommandNode("hello", List.of( + new LiteralCommandNode("world", List.of( + new IntegerCommandNode("a1", new AllowedNumberInputs.AllowedIntegerInputs.Range(10, 100), executor) + )) + )) + ); + Command command1 = new Command( + new LiteralCommandNode("hello", List.of( + new LiteralCommandNode("world1", List.of( + new IntegerCommandNode("a1", new AllowedNumberInputs.AllowedIntegerInputs.Range(10, 100), executor) + )) + )) + ); + Command command2 = new Command( + new LiteralCommandNode("hello", List.of( + new LiteralCommandNode("world", List.of( + new IntegerCommandNode("a2", new AllowedNumberInputs.AllowedIntegerInputs.Range(10, 100), executor) + )) + )) + ); + Command command3 = new Command( + new LiteralCommandNode("hello", List.of( + new LiteralCommandNode("world", List.of( + new IntegerCommandNode("a1", new AllowedNumberInputs.AllowedIntegerInputs.Range(10, 100), executor), + new IntegerCommandNode("a2", List.of( + new LiteralCommandNode("hi") + ), new AllowedNumberInputs.AllowedIntegerInputs.Range(10, 100), executor) + )), + new LiteralCommandNode("world1", List.of( + new IntegerCommandNode("a1", new AllowedNumberInputs.AllowedIntegerInputs.Range(10, 100), executor) + )) + )) + ); + + CommandManager manager = new CommandManager(); + manager.registerCommand("test", command0); + manager.registerCommand("test", command1); + manager.registerCommand("test", command2); + manager.registerCommand("test", command3); + + Command expected = new Command( + new LiteralCommandNode("hello", List.of( + new LiteralCommandNode("world", List.of( + new IntegerCommandNode("a1", new AllowedNumberInputs.AllowedIntegerInputs.Range(10, 100), executor), + new IntegerCommandNode("a2", List.of( + new LiteralCommandNode("hi") + ), new AllowedNumberInputs.AllowedIntegerInputs.Range(10, 100), executor) + )), + new LiteralCommandNode("world1", List.of( + new IntegerCommandNode("a1", new AllowedNumberInputs.AllowedIntegerInputs.Range(10, 100), executor) + )) + )) + ); + + Assertions.assertEquals(expected, manager.getCommand("hello").get()); + } +} From 75f8c4dd8d1dd2961b988770d594cdd1a7475e3d Mon Sep 17 00:00:00 2001 From: WizardlyBump17 Date: Wed, 29 Oct 2025 00:19:25 -0300 Subject: [PATCH 049/363] fixed the create methods --- .../wlib/command/rework/Command.java | 44 ++++++------------- 1 file changed, 14 insertions(+), 30 deletions(-) diff --git a/commands/src/main/java/com/wizardlybump17/wlib/command/rework/Command.java b/commands/src/main/java/com/wizardlybump17/wlib/command/rework/Command.java index 5b1ca167..1d4eb434 100644 --- a/commands/src/main/java/com/wizardlybump17/wlib/command/rework/Command.java +++ b/commands/src/main/java/com/wizardlybump17/wlib/command/rework/Command.java @@ -180,26 +180,20 @@ public Command(@NotNull LiteralCommandNode root) { } public static @Nullable Command createCommand(@NotNull String execution) { - LiteralCommandNode firstNode = null; + String[] parts = execution.split(" "); - List> children = new ArrayList<>(); - String[] strings = execution.split(" "); - - for (int i = 0; i < strings.length; i++) { - String string = strings[i]; - if (i == 0) { - firstNode = new LiteralCommandNode(string, children); + LiteralCommandNode lastNode = null; + for (int i = parts.length - 1; i >= 0; i--) { + String part = parts[i]; + if (lastNode == null) { + lastNode = new LiteralCommandNode(part); continue; } - List> newChildren = new ArrayList<>(); - LiteralCommandNode newNode = new LiteralCommandNode(string, newChildren); - children.add(newNode); - - children = newChildren; + lastNode = new LiteralCommandNode(part, List.of(lastNode)); } - return firstNode == null ? null : new Command(firstNode); + return new Command(lastNode); } @Override @@ -234,13 +228,11 @@ public int hashCode() { if (!parameterTypes[0].equals(CommandContext.class)) throw new IllegalArgumentException("Method " + method.getName() + "'s first parameter is not a CommandContext"); - LiteralCommandNode firstNode = null; - - List> children = new ArrayList<>(); String[] parts = annotation.value().split(" "); int parameterIndex = 1; - for (int i = 0; i < parts.length; i++) { + CommandNode lastNode = null; + for (int i = parts.length - 1; i >= 0; i--) { String part = parts[i]; CommandNodeExecutor executor; @@ -281,12 +273,6 @@ public int hashCode() { executor = null; } - if (i == 0) { - firstNode = new LiteralCommandNode(part, children, executor); - continue; - } - - List> newChildren = new ArrayList<>(); CommandNode newNode; if (part.charAt(0) == '<' && part.charAt(part.length() - 1) == '>') { @@ -294,19 +280,17 @@ public int hashCode() { Class parameterType = parameterTypes[parameterIndex++]; if (parameterType == int.class || parameterType == Integer.class) - newNode = new IntegerCommandNode(nodeName, newChildren, new AllowedNumberInputs.AllowedIntegerInputs.Unlimited(), executor); + newNode = new IntegerCommandNode(nodeName, lastNode == null ? List.of() : List.of(lastNode), new AllowedNumberInputs.AllowedIntegerInputs.Unlimited(), executor); else throw new IllegalArgumentException("Just trying stuff for now. Come back later"); } else { - newNode = new LiteralCommandNode(part, newChildren, executor); + newNode = new LiteralCommandNode(part, lastNode == null ? List.of() : List.of(lastNode), executor); } - children.add(newNode); - - children = newChildren; + lastNode = newNode; } - return firstNode == null ? null : new Command(firstNode); + return new Command((LiteralCommandNode) lastNode); } } From 09d6bc636d7758f9e57bbd56ea746cb6d60bff6d Mon Sep 17 00:00:00 2001 From: WizardlyBump17 Date: Wed, 29 Oct 2025 00:27:14 -0300 Subject: [PATCH 050/363] added more execute methods --- .../wlib/command/rework/manager/CommandManager.java | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/commands/src/main/java/com/wizardlybump17/wlib/command/rework/manager/CommandManager.java b/commands/src/main/java/com/wizardlybump17/wlib/command/rework/manager/CommandManager.java index 9804cfc8..8e56f449 100644 --- a/commands/src/main/java/com/wizardlybump17/wlib/command/rework/manager/CommandManager.java +++ b/commands/src/main/java/com/wizardlybump17/wlib/command/rework/manager/CommandManager.java @@ -3,6 +3,7 @@ import com.wizardlybump17.wlib.command.rework.Command; import com.wizardlybump17.wlib.command.rework.result.CommandResult; import com.wizardlybump17.wlib.command.sender.CommandSender; +import com.wizardlybump17.wlib.util.StringUtil; import org.jetbrains.annotations.NotNull; import java.util.HashMap; @@ -49,6 +50,14 @@ public class CommandManager { return command.execute(sender, input); } + public @NotNull CommandResult execute(@NotNull CommandSender sender, @NotNull String input) { + return execute(sender, StringUtil.parseQuotedStrings(input)); + } + + public @NotNull CommandResult execute(@NotNull CommandSender sender, @NotNull String @NotNull [] input) { + return execute(sender, String.join(" ", input)); + } + public @NotNull Optional getCommand(@NotNull String name) { return Optional.ofNullable(commands.get(name)); } From 322086c4c3319a3dd5d71e6ab81c6f5496c5d462 Mon Sep 17 00:00:00 2001 From: WizardlyBump17 Date: Wed, 29 Oct 2025 00:38:04 -0300 Subject: [PATCH 051/363] beginning the global suggestion system --- .../rework/manager/CommandManager.java | 28 +++++++++ .../wizardlybump17/wlib/util/StringUtil.java | 59 +++++++++++++++++++ 2 files changed, 87 insertions(+) diff --git a/commands/src/main/java/com/wizardlybump17/wlib/command/rework/manager/CommandManager.java b/commands/src/main/java/com/wizardlybump17/wlib/command/rework/manager/CommandManager.java index 8e56f449..1c710a80 100644 --- a/commands/src/main/java/com/wizardlybump17/wlib/command/rework/manager/CommandManager.java +++ b/commands/src/main/java/com/wizardlybump17/wlib/command/rework/manager/CommandManager.java @@ -4,6 +4,7 @@ import com.wizardlybump17.wlib.command.rework.result.CommandResult; import com.wizardlybump17.wlib.command.sender.CommandSender; import com.wizardlybump17.wlib.util.StringUtil; +import com.wizardlybump17.wlib.util.exception.QuotedStringException; import org.jetbrains.annotations.NotNull; import java.util.HashMap; @@ -58,6 +59,33 @@ public class CommandManager { return execute(sender, String.join(" ", input)); } + public @NotNull List getSuggestions(@NotNull CommandSender sender, @NotNull List input) { + if (input.isEmpty()) + return List.of(); + + String commandName = input.getFirst(); + + Command command = commands.get(commandName); + if (command == null) + return List.of(); + + return command.getSuggestions(sender, input); + } + + public @NotNull List getSuggestions(@NotNull CommandSender sender, @NotNull String input) { + try { + if (!input.isEmpty() && !StringUtil.isProperlyQuoted(input)) + input = input + "\""; + return getSuggestions(sender, StringUtil.parseQuotedStrings(input)); + } catch (QuotedStringException e) { + return List.of(); + } + } + + public @NotNull List getSuggestions(@NotNull CommandSender sender, @NotNull String @NotNull [] input) { + return getSuggestions(sender, String.join(" ", input)); + } + public @NotNull Optional getCommand(@NotNull String name) { return Optional.ofNullable(commands.get(name)); } diff --git a/utils/src/main/java/com/wizardlybump17/wlib/util/StringUtil.java b/utils/src/main/java/com/wizardlybump17/wlib/util/StringUtil.java index cf848b11..6790f9c4 100644 --- a/utils/src/main/java/com/wizardlybump17/wlib/util/StringUtil.java +++ b/utils/src/main/java/com/wizardlybump17/wlib/util/StringUtil.java @@ -3,6 +3,7 @@ import com.wizardlybump17.wlib.util.exception.PlaceholderException; import com.wizardlybump17.wlib.util.exception.QuotedStringException; import lombok.NonNull; +import org.jetbrains.annotations.NotNull; import java.util.ArrayList; import java.util.List; @@ -387,6 +388,64 @@ public static String fixName(String name) { return strings; } + public static boolean isProperlyQuoted(@NotNull String input, char quote, char escape, char delimiter) throws QuotedStringException { + char[] chars = input.toCharArray(); + + boolean escaped = false; + boolean delimited = true; + boolean hadQuote = false; + boolean insideQuotes = false; + + for (char current : chars) { + if (current == escape && !escaped) { // start of an escaped char + escaped = true; + continue; + } + + if (escaped) { // end of the escaped char + escaped = false; + continue; + } + + if (current == quote) { + if (!delimited) // the previous char was not the delimiter. Example case: string"quoted" + throw new QuotedStringException(QuotedStringException.QUOTED_WITHOUT_DELIMITER); + + if (!insideQuotes) { // begin of quoted string + insideQuotes = true; + continue; + } + + // end of quoted string + delimited = false; + hadQuote = true; + insideQuotes = false; + continue; + } + + if (current == delimiter && !insideQuotes) { // delimiter (space) + delimited = true; + hadQuote = false; + continue; + } + + if (hadQuote) // the previous char was a quote. Example case: "quoted"string + throw new QuotedStringException(QuotedStringException.NON_QUOTED_AFTER_QUOTED); + + if (insideQuotes) + delimited = false; + } + + if (escaped) + throw new QuotedStringException(QuotedStringException.INVALID_ESCAPE); + + return !insideQuotes; + } + + public static boolean isProperlyQuoted(@NotNull String input) throws QuotedStringException { + return isProperlyQuoted(input, QUOTE, QUOTE_ESCAPE, QUOTE_DELIMITER); + } + /** *

* Removes any extra space from the {@link String}. From 8d5f44f822472e3414ecf3f14ae571acd4a7e1d3 Mon Sep 17 00:00:00 2001 From: WizardlyBump17 Date: Thu, 30 Oct 2025 19:39:21 -0300 Subject: [PATCH 052/363] made the parameter order follow the pattern --- .../wlib/command/rework/result/CommandResult.java | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/commands/src/main/java/com/wizardlybump17/wlib/command/rework/result/CommandResult.java b/commands/src/main/java/com/wizardlybump17/wlib/command/rework/result/CommandResult.java index 7e0ab147..787ae730 100644 --- a/commands/src/main/java/com/wizardlybump17/wlib/command/rework/result/CommandResult.java +++ b/commands/src/main/java/com/wizardlybump17/wlib/command/rework/result/CommandResult.java @@ -19,11 +19,11 @@ public interface CommandResult { //without context - static @NotNull SuccessResult successful(@Nullable T data, int lastInputIndex, @NotNull CommandNode lastNode) { + static @NotNull SuccessResult successful(int lastInputIndex, @NotNull CommandNode lastNode, @Nullable T data) { return new SuccessResult<>(lastInputIndex, lastNode, data); } - static @NotNull ExceptionResult exceptionally(@NotNull Throwable throwable, int lastInputIndex, @NotNull CommandNode lastNode) { + static @NotNull ExceptionResult exceptionally( int lastInputIndex, @NotNull CommandNode lastNode, @NotNull Throwable throwable) { return new ExceptionResult<>(lastInputIndex, lastNode, throwable); } @@ -66,11 +66,11 @@ public interface CommandResult { //with context static @NotNull SuccessResult successful(@NotNull CommandContext context, @Nullable T data) { - return successful(data, context.lastInputIndex(), context.lastNode()); + return successful(context.lastInputIndex(), context.lastNode(), data); } static @NotNull ExceptionResult exceptionally(@NotNull CommandContext context, @NotNull Throwable exception) { - return exceptionally(exception, context.lastInputIndex(), context.lastNode()); + return exceptionally(context.lastInputIndex(), context.lastNode(), exception); } static @NotNull GenericErrorResult genericError(@NotNull CommandContext context, @NotNull String message) { From 50fdfa3705c252b0f93658b639ef0fefdb1aa7c6 Mon Sep 17 00:00:00 2001 From: WizardlyBump17 Date: Thu, 30 Oct 2025 19:39:34 -0300 Subject: [PATCH 053/363] removed the NodeResultTests --- .../command/test/rework/NodeResultTests.java | 233 ------------------ 1 file changed, 233 deletions(-) delete mode 100644 commands/src/test/java/com/wizardlybump17/wlib/command/test/rework/NodeResultTests.java diff --git a/commands/src/test/java/com/wizardlybump17/wlib/command/test/rework/NodeResultTests.java b/commands/src/test/java/com/wizardlybump17/wlib/command/test/rework/NodeResultTests.java deleted file mode 100644 index 09fb242b..00000000 --- a/commands/src/test/java/com/wizardlybump17/wlib/command/test/rework/NodeResultTests.java +++ /dev/null @@ -1,233 +0,0 @@ -package com.wizardlybump17.wlib.command.test.rework; - -import com.wizardlybump17.wlib.command.rework.Command; -import com.wizardlybump17.wlib.command.rework.input.AllowedNumberInputs; -import com.wizardlybump17.wlib.command.rework.node.IntegerCommandNode; -import com.wizardlybump17.wlib.command.rework.node.LiteralCommandNode; -import com.wizardlybump17.wlib.command.rework.result.CommandResult; -import org.junit.jupiter.api.Test; - -import java.util.List; - -class NodeResultTests { - - @Test - void test() { - Command command = new Command( - new LiteralCommandNode("hello", List.of( - new LiteralCommandNode("world", List.of( - new IntegerCommandNode("a1", new AllowedNumberInputs.AllowedIntegerInputs.Range(10, 100), context -> CommandResult.successful(context, "a1")) - )) - )) - ); - - CommandResult result = command.execute(null, List.of("hello", "world", "10")); - System.out.println(result); - } - -// @Test -// void testSuccess() { -// LiteralCommandNode world = new LiteralCommandNode("world", List.of()); -// LiteralCommandNode hello = new LiteralCommandNode("hello", List.of(world)); -// Command command = new Command(hello); -// -// SuccessResult worldResult = CommandResult.successful("world"); -// CommandContext.CommandNodeArguments expected = new CommandContext.CommandNodeArguments( -// List.of( -// new CommandContext.CommandNodeArgument<>(hello, "hello", null), -// new CommandContext.CommandNodeArgument<>(world, "world", null) -// ) -// ); -// CommandContext.CommandNodeArguments actual = command.execute(null, List.of("hello", "world")); -// Assertions.assertEquals(expected, actual); -// } -// -// @Test -// void testUnsuccessExtra1() { -// LiteralCommandNode worldNode = new LiteralCommandNode("world", List.of()); -// LiteralCommandNode helloNode = new LiteralCommandNode("hello", List.of(worldNode)); -// Command command = new Command(helloNode); -// -// CommandContext.CommandNodeArguments expected = new CommandContext.CommandNodeArguments( -// List.of( -// new CommandContext.CommandNodeArgument<>(helloNode, "hello", CommandResult.successful("hello")), -// new CommandContext.CommandNodeArgument<>(worldNode, "world", CommandResult.successful("world")) -// ), -// new ExtraArgumentsResult<>("a"), -// worldNode, -// "world" -// ); -// CommandContext.CommandNodeArguments actual = command.getArguments(List.of("hello", "world", "a")); -// Assertions.assertEquals(expected, actual); -// } -// -// @Test -// void testUnsuccessExtra2() { -// LiteralCommandNode worldNode = new LiteralCommandNode("world", List.of()); -// LiteralCommandNode helloNode = new LiteralCommandNode("hello", List.of(worldNode)); -// Command command = new Command(helloNode); -// -// CommandContext.CommandNodeArguments expected = new CommandContext.CommandNodeArguments( -// List.of( -// new CommandContext.CommandNodeArgument<>(helloNode, "hello", CommandResult.successful("hello")), -// new CommandContext.CommandNodeArgument<>(worldNode, "world", CommandResult.successful("world")) -// ), -// new ExtraArgumentsResult<>("a"), -// worldNode, -// "world" -// ); -// CommandContext.CommandNodeArguments actual = command.getArguments(List.of("hello", "world", "a", "b")); -// Assertions.assertEquals(expected, actual); -// } -// -// @Test -// void testUnsuccessExtra3() { -// LiteralCommandNode worldNode = new LiteralCommandNode("world", List.of()); -// LiteralCommandNode helloNode = new LiteralCommandNode("hello", List.of(worldNode)); -// Command command = new Command(helloNode); -// -// CommandContext.CommandNodeArguments expected = new CommandContext.CommandNodeArguments( -// List.of( -// new CommandContext.CommandNodeArgument<>(helloNode, "hello", CommandResult.successful("hello")), -// new CommandContext.CommandNodeArgument<>(worldNode, "world", CommandResult.successful("world")) -// ), -// new ExtraArgumentsResult<>("a"), -// worldNode, -// "world" -// ); -// CommandContext.CommandNodeArguments actual = command.getArguments(List.of("hello", "world", "a", "b", "c")); -// Assertions.assertEquals(expected, actual); -// } -// -// @Test -// void testUnsuccessLess1() { -// LiteralCommandNode cNode = new LiteralCommandNode("c", List.of()); -// LiteralCommandNode bNode = new LiteralCommandNode("b", List.of(cNode)); -// LiteralCommandNode aNode = new LiteralCommandNode("a", List.of(bNode)); -// LiteralCommandNode worldNode = new LiteralCommandNode("world", List.of(aNode)); -// LiteralCommandNode helloNode = new LiteralCommandNode("hello", List.of(worldNode)); -// Command command = new Command(helloNode); -// -// CommandContext.CommandNodeArguments expected = new CommandContext.CommandNodeArguments( -// List.of( -// new CommandContext.CommandNodeArgument<>(helloNode, "hello", CommandResult.successful("hello")), -// new CommandContext.CommandNodeArgument<>(worldNode, "world", CommandResult.successful("world")), -// new CommandContext.CommandNodeArgument<>(aNode, "a", CommandResult.successful("a")), -// new CommandContext.CommandNodeArgument<>(bNode, "b", CommandResult.successful("b")) -// ), -// new InsufficientArgumentsResult<>("b", bNode), -// bNode, -// "b" -// ); -// CommandContext.CommandNodeArguments actual = command.getArguments(List.of("hello", "world", "a", "b")); -// Assertions.assertEquals(expected, actual); -// } -// -// @Test -// void testUnsuccessLess2() { -// LiteralCommandNode cNode = new LiteralCommandNode("c", List.of()); -// LiteralCommandNode bNode = new LiteralCommandNode("b", List.of(cNode)); -// LiteralCommandNode aNode = new LiteralCommandNode("a", List.of(bNode)); -// LiteralCommandNode worldNode = new LiteralCommandNode("world", List.of(aNode)); -// LiteralCommandNode helloNode = new LiteralCommandNode("hello", List.of(worldNode)); -// Command command = new Command(helloNode); -// -// CommandContext.CommandNodeArguments expected = new CommandContext.CommandNodeArguments( -// List.of( -// new CommandContext.CommandNodeArgument<>(helloNode, "hello", CommandResult.successful("hello")), -// new CommandContext.CommandNodeArgument<>(worldNode, "world", CommandResult.successful("world")), -// new CommandContext.CommandNodeArgument<>(aNode, "a", CommandResult.successful("a")) -// ), -// new InsufficientArgumentsResult<>("a", aNode), -// aNode, -// "a" -// ); -// CommandContext.CommandNodeArguments actual = command.getArguments(List.of("hello", "world", "a")); -// Assertions.assertEquals(expected, actual); -// } -// -// @Test -// void testUnsuccessLess3() { -// LiteralCommandNode cNode = new LiteralCommandNode("c", List.of()); -// LiteralCommandNode bNode = new LiteralCommandNode("b", List.of(cNode)); -// LiteralCommandNode aNode = new LiteralCommandNode("a", List.of(bNode)); -// LiteralCommandNode worldNode = new LiteralCommandNode("world", List.of(aNode)); -// LiteralCommandNode helloNode = new LiteralCommandNode("hello", List.of(worldNode)); -// Command command = new Command(helloNode); -// -// CommandContext.CommandNodeArguments expected = new CommandContext.CommandNodeArguments( -// List.of( -// new CommandContext.CommandNodeArgument<>(helloNode, "hello", CommandResult.successful("hello")), -// new CommandContext.CommandNodeArgument<>(worldNode, "world", CommandResult.successful("world")) -// ), -// new InsufficientArgumentsResult<>("world", worldNode), -// worldNode, -// "world" -// ); -// CommandContext.CommandNodeArguments actual = command.getArguments(List.of("hello", "world")); -// Assertions.assertEquals(expected, actual); -// } -// -// @Test -// void testUnsuccessLess4() { -// LiteralCommandNode cNode = new LiteralCommandNode("c", List.of()); -// LiteralCommandNode bNode = new LiteralCommandNode("b", List.of(cNode)); -// LiteralCommandNode aNode = new LiteralCommandNode("a", List.of(bNode)); -// LiteralCommandNode worldNode = new LiteralCommandNode("world", List.of(aNode)); -// LiteralCommandNode helloNode = new LiteralCommandNode("hello", List.of(worldNode)); -// Command command = new Command(helloNode); -// -// CommandContext.CommandNodeArguments expected = new CommandContext.CommandNodeArguments( -// List.of( -// new CommandContext.CommandNodeArgument<>(helloNode, "hello", CommandResult.successful("hello")) -// ), -// new InsufficientArgumentsResult<>("hello", helloNode), -// helloNode, -// "hello" -// ); -// CommandContext.CommandNodeArguments actual = command.getArguments(List.of("hello")); -// Assertions.assertEquals(expected, actual); -// } -// -// @Test -// void testUnsuccessLess5() { -// LiteralCommandNode helloNode = new LiteralCommandNode("hello", List.of( -// new LiteralCommandNode("world", List.of( -// new LiteralCommandNode("a", List.of( -// new LiteralCommandNode("b", List.of( -// new LiteralCommandNode("c", List.of()) -// )) -// )) -// )) -// )); -// Command command = new Command(helloNode); -// -// CommandContext.CommandNodeArguments expected = new CommandContext.CommandNodeArguments( -// Map.of(), -// new InsufficientArgumentsResult<>("", helloNode), -// helloNode, -// "" -// ); -// CommandContext.CommandNodeArguments actual = command.getArguments(List.of()); -// Assertions.assertEquals(expected, actual); -// } -// -// @Test -// void testSuccessMultipleChildren0() { -// Command command = new Command( -// new LiteralCommandNode("hello", List.of( -// new LiteralCommandNode("world2", List.of( -// new LiteralCommandNode("world3", List.of()), -// new LiteralCommandNode("world4", List.of()) -// )), -// new LiteralCommandNode("world1", List.of( -// new LiteralCommandNode("world3", List.of()) -// )), -// new LiteralCommandNode("world", List.of()) -// )) -// ); -// -// CommandContext.CommandNodeArguments actual = command.getArguments(List.of("hello", "world2", "world3", "a")); -// Assertions.assertInstanceOf(ExtraArgumentsResult.class, actual.lastResult()); -// } -} From 82cac5ade38a302d8e40fa29e2b7fa3ab77b282a Mon Sep 17 00:00:00 2001 From: WizardlyBump17 Date: Thu, 30 Oct 2025 19:39:44 -0300 Subject: [PATCH 054/363] starting actual tests --- .../command/test/rework/CommandTests.java | 69 ++++++++----------- 1 file changed, 27 insertions(+), 42 deletions(-) diff --git a/commands/src/test/java/com/wizardlybump17/wlib/command/test/rework/CommandTests.java b/commands/src/test/java/com/wizardlybump17/wlib/command/test/rework/CommandTests.java index 3b64434b..ce7c6903 100644 --- a/commands/src/test/java/com/wizardlybump17/wlib/command/test/rework/CommandTests.java +++ b/commands/src/test/java/com/wizardlybump17/wlib/command/test/rework/CommandTests.java @@ -1,68 +1,53 @@ package com.wizardlybump17.wlib.command.test.rework; import com.wizardlybump17.wlib.command.rework.Command; -import com.wizardlybump17.wlib.command.rework.context.CommandContext; import com.wizardlybump17.wlib.command.rework.node.LiteralCommandNode; import com.wizardlybump17.wlib.command.rework.result.CommandResult; +import com.wizardlybump17.wlib.command.sender.BasicCommandSender; +import com.wizardlybump17.wlib.command.sender.CommandSender; import org.jetbrains.annotations.NotNull; import org.junit.jupiter.api.Assertions; import org.junit.jupiter.api.Test; -import java.lang.reflect.Method; import java.util.List; +import java.util.UUID; +import java.util.function.Consumer; public class CommandTests { + static final @NotNull Consumer SENDER_MESSAGE_CONSUMER = System.out::println; + static final @NotNull CommandSender ALL_KNOWING_SENDER = new BasicCommandSender<>(new Object(), "Test", UUID.nameUUIDFromBytes("Test".getBytes()), SENDER_MESSAGE_CONSUMER, $ -> true); + @Test - void testCreate() { - Command expected = new Command( - new LiteralCommandNode("hello", List.of( - new LiteralCommandNode("world", List.of()) - )) - ); - Command created = Command.createCommand("hello world"); + void testSuccessHello() { + LiteralCommandNode helloNode = new LiteralCommandNode("hello", context -> CommandResult.successful(context, "hello")); + Command command = new Command(helloNode); + + CommandResult expected = CommandResult.successful(0, helloNode, "hello"); + CommandResult actual = command.execute(ALL_KNOWING_SENDER, List.of("hello")); - Assertions.assertEquals(expected, created); + Assertions.assertEquals(expected, actual); } @Test - void testCreate1() { - Command expected = new Command( - new LiteralCommandNode("hello", List.of( - new LiteralCommandNode("world", List.of( - new LiteralCommandNode("hello1", List.of( - new LiteralCommandNode("world1", List.of( - new LiteralCommandNode("hello2", List.of( - new LiteralCommandNode("world2", List.of()) - )) - )) - )) - )) - )) - ); - Command created = Command.createCommand("hello world hello1 world1 hello2 world2"); + void testSuccessHelloWorld() { + LiteralCommandNode worldNode = new LiteralCommandNode("world", context -> CommandResult.successful(context, "hello world")); + Command command = new Command(new LiteralCommandNode("hello", List.of(worldNode))); + + CommandResult expected = CommandResult.successful(1, worldNode, "hello world"); + CommandResult actual = command.execute(ALL_KNOWING_SENDER, List.of("hello", "world")); - Assertions.assertEquals(expected, created); + Assertions.assertEquals(expected, actual); } @Test - public void testCreate2() { - CommandTests object = new CommandTests(); + void testSuccessHelloWorldHi() { + LiteralCommandNode hiNode = new LiteralCommandNode("hi", context -> CommandResult.successful(context, "hello world hi")); + Command command = new Command(new LiteralCommandNode("hello", List.of(new LiteralCommandNode("world", List.of(hiNode))))); - for (Method method : object.getClass().getMethods()) { - if (method.isAnnotationPresent(com.wizardlybump17.wlib.command.rework.annotation.Command.class)) { - Command command = Command.fromMethod(method, object); - CommandResult result = command.execute(null, List.of("test", "test2")); - System.out.println(result); - } - } - } - - @com.wizardlybump17.wlib.command.rework.annotation.Command("test") - public void testCommand(@NotNull CommandContext context) { - } + CommandResult expected = CommandResult.successful(2, hiNode, "hello world hi"); + CommandResult actual = command.execute(ALL_KNOWING_SENDER, List.of("hello", "world", "hi")); - @com.wizardlybump17.wlib.command.rework.annotation.Command("test test2") - public void testCommand2(@NotNull CommandContext context) { + Assertions.assertEquals(expected, actual); } } From c55f38f852f627d3176d3fe1df126b807388da1c Mon Sep 17 00:00:00 2001 From: WizardlyBump17 Date: Thu, 30 Oct 2025 19:48:32 -0300 Subject: [PATCH 055/363] some more success tests --- .../command/test/rework/CommandTests.java | 37 +++++++++++++++++++ 1 file changed, 37 insertions(+) diff --git a/commands/src/test/java/com/wizardlybump17/wlib/command/test/rework/CommandTests.java b/commands/src/test/java/com/wizardlybump17/wlib/command/test/rework/CommandTests.java index ce7c6903..f45343bd 100644 --- a/commands/src/test/java/com/wizardlybump17/wlib/command/test/rework/CommandTests.java +++ b/commands/src/test/java/com/wizardlybump17/wlib/command/test/rework/CommandTests.java @@ -7,6 +7,7 @@ import com.wizardlybump17.wlib.command.sender.CommandSender; import org.jetbrains.annotations.NotNull; import org.junit.jupiter.api.Assertions; +import org.junit.jupiter.api.DisplayName; import org.junit.jupiter.api.Test; import java.util.List; @@ -50,4 +51,40 @@ void testSuccessHelloWorldHi() { Assertions.assertEquals(expected, actual); } + + @Test + @DisplayName("Multiple children 0 (hello, hi): success") + void test0() { + LiteralCommandNode hiNode = new LiteralCommandNode("hi", context -> CommandResult.successful(context, "hello hi")); + Command command = new Command(new LiteralCommandNode( + "hello", + List.of( + new LiteralCommandNode("world", context -> CommandResult.successful(context, "hello world")), + hiNode + ) + )); + + CommandResult expected = CommandResult.successful(1, hiNode, "hello hi"); + CommandResult actual = command.execute(ALL_KNOWING_SENDER, List.of("hello", "hi")); + + Assertions.assertEquals(expected, actual); + } + + @Test + @DisplayName("Multiple children 1 (hello, hi, world): success") + void test1() { + LiteralCommandNode hiWorldNode = new LiteralCommandNode("world", context -> CommandResult.successful(context, "hello hi world")); + Command command = new Command(new LiteralCommandNode( + "hello", + List.of( + new LiteralCommandNode("world", context -> CommandResult.successful(context, "hello world")), + new LiteralCommandNode("hi", List.of(hiWorldNode)) + ) + )); + + CommandResult expected = CommandResult.successful(2, hiWorldNode, "hello hi world"); + CommandResult actual = command.execute(ALL_KNOWING_SENDER, List.of("hello", "hi", "world")); + + Assertions.assertEquals(expected, actual); + } } From f1d6d6244ba654faa44f119a2c783b0f17904803 Mon Sep 17 00:00:00 2001 From: WizardlyBump17 Date: Thu, 30 Oct 2025 19:57:37 -0300 Subject: [PATCH 056/363] testing extra arguments --- .../command/test/rework/CommandTests.java | 45 +++++++++++++++++++ 1 file changed, 45 insertions(+) diff --git a/commands/src/test/java/com/wizardlybump17/wlib/command/test/rework/CommandTests.java b/commands/src/test/java/com/wizardlybump17/wlib/command/test/rework/CommandTests.java index f45343bd..bd5c3cbc 100644 --- a/commands/src/test/java/com/wizardlybump17/wlib/command/test/rework/CommandTests.java +++ b/commands/src/test/java/com/wizardlybump17/wlib/command/test/rework/CommandTests.java @@ -3,6 +3,7 @@ import com.wizardlybump17.wlib.command.rework.Command; import com.wizardlybump17.wlib.command.rework.node.LiteralCommandNode; import com.wizardlybump17.wlib.command.rework.result.CommandResult; +import com.wizardlybump17.wlib.command.rework.result.error.ExtraArgumentsResult; import com.wizardlybump17.wlib.command.sender.BasicCommandSender; import com.wizardlybump17.wlib.command.sender.CommandSender; import org.jetbrains.annotations.NotNull; @@ -87,4 +88,48 @@ void test1() { Assertions.assertEquals(expected, actual); } + + @Test + void testExtraArguments0() { + LiteralCommandNode helloNode = new LiteralCommandNode("hello", context -> CommandResult.successful(context, "hello")); + Command command = new Command(helloNode); + + ExtraArgumentsResult expected = CommandResult.extraArguments(1, helloNode); + CommandResult actual = command.execute(ALL_KNOWING_SENDER, List.of("hello", "world")); + + Assertions.assertEquals(expected, actual); + } + + @Test + void testExtraArguments1() { + LiteralCommandNode worldNode = new LiteralCommandNode("world", context -> CommandResult.successful(context, "hello world")); + Command command = new Command( + new LiteralCommandNode( + "hello", + List.of(worldNode) + ) + ); + + ExtraArgumentsResult expected = CommandResult.extraArguments(2, worldNode); + CommandResult actual = command.execute(ALL_KNOWING_SENDER, List.of("hello", "world", "hi")); + + Assertions.assertEquals(expected, actual); + } + + @Test + void testExtraArguments2() { + LiteralCommandNode hiWorldNode = new LiteralCommandNode("world", context -> CommandResult.successful(context, "hello hi world")); + Command command = new Command(new LiteralCommandNode( + "hello", + List.of( + new LiteralCommandNode("world", context -> CommandResult.successful(context, "hello world")), + new LiteralCommandNode("hi", List.of(hiWorldNode)) + ) + )); + + ExtraArgumentsResult expected = CommandResult.extraArguments(3, hiWorldNode); + CommandResult actual = command.execute(ALL_KNOWING_SENDER, List.of("hello", "hi", "world", "extra")); + + Assertions.assertEquals(expected, actual); + } } From 0a46b68048083dd9e5b1075ccc5ad5cdf8c1f4d2 Mon Sep 17 00:00:00 2001 From: WizardlyBump17 Date: Thu, 30 Oct 2025 19:59:50 -0300 Subject: [PATCH 057/363] catching any errors --- .../com/wizardlybump17/wlib/command/rework/Command.java | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/commands/src/main/java/com/wizardlybump17/wlib/command/rework/Command.java b/commands/src/main/java/com/wizardlybump17/wlib/command/rework/Command.java index 1d4eb434..4f424e11 100644 --- a/commands/src/main/java/com/wizardlybump17/wlib/command/rework/Command.java +++ b/commands/src/main/java/com/wizardlybump17/wlib/command/rework/Command.java @@ -101,7 +101,12 @@ public Command(@NotNull LiteralCommandNode root) { lastInputIndex, lastNode ); - return executor.execute(context); + + try { + return executor.execute(context); + } catch (Throwable throwable) { + return CommandResult.exceptionally(lastInputIndex, lastNode, throwable); + } } public @NotNull List getInputList(@NotNull String original) { From e92957b3fc802a1be3a419966b6da4b9baf30cc2 Mon Sep 17 00:00:00 2001 From: WizardlyBump17 Date: Thu, 30 Oct 2025 20:04:51 -0300 Subject: [PATCH 058/363] testing for exceptions --- .../wlib/command/test/rework/CommandTests.java | 15 +++++++++++++++ 1 file changed, 15 insertions(+) diff --git a/commands/src/test/java/com/wizardlybump17/wlib/command/test/rework/CommandTests.java b/commands/src/test/java/com/wizardlybump17/wlib/command/test/rework/CommandTests.java index bd5c3cbc..e0c61618 100644 --- a/commands/src/test/java/com/wizardlybump17/wlib/command/test/rework/CommandTests.java +++ b/commands/src/test/java/com/wizardlybump17/wlib/command/test/rework/CommandTests.java @@ -3,6 +3,7 @@ import com.wizardlybump17.wlib.command.rework.Command; import com.wizardlybump17.wlib.command.rework.node.LiteralCommandNode; import com.wizardlybump17.wlib.command.rework.result.CommandResult; +import com.wizardlybump17.wlib.command.rework.result.error.ExceptionResult; import com.wizardlybump17.wlib.command.rework.result.error.ExtraArgumentsResult; import com.wizardlybump17.wlib.command.sender.BasicCommandSender; import com.wizardlybump17.wlib.command.sender.CommandSender; @@ -132,4 +133,18 @@ void testExtraArguments2() { Assertions.assertEquals(expected, actual); } + + @Test + void testException() { + RuntimeException helloException = new RuntimeException("hello"); + LiteralCommandNode helloNode = new LiteralCommandNode("hello", context -> { + throw helloException; + }); + Command command = new Command(helloNode); + + ExceptionResult expected = CommandResult.exceptionally(0, helloNode, helloException); + CommandResult actual = command.execute(ALL_KNOWING_SENDER, List.of("hello")); + + Assertions.assertEquals(expected, actual); + } } From 215b0972c4ddb61aa88e359739489c8c34e223cc Mon Sep 17 00:00:00 2001 From: WizardlyBump17 Date: Thu, 30 Oct 2025 20:09:39 -0300 Subject: [PATCH 059/363] there is only one way that this result gets returned --- .../wizardlybump17/wlib/command/rework/Command.java | 2 +- .../wlib/command/rework/result/CommandResult.java | 5 +++-- .../result/error/InsufficientArgumentsResult.java | 13 ++++++++++++- 3 files changed, 16 insertions(+), 4 deletions(-) diff --git a/commands/src/main/java/com/wizardlybump17/wlib/command/rework/Command.java b/commands/src/main/java/com/wizardlybump17/wlib/command/rework/Command.java index 4f424e11..a8b2b069 100644 --- a/commands/src/main/java/com/wizardlybump17/wlib/command/rework/Command.java +++ b/commands/src/main/java/com/wizardlybump17/wlib/command/rework/Command.java @@ -43,7 +43,7 @@ public Command(@NotNull LiteralCommandNode root) { @SuppressWarnings("unchecked") public @NotNull CommandResult execute(@NotNull CommandSender sender, @NotNull List input) { if (input.isEmpty()) - return CommandResult.insufficientArguments(-1, root); + return CommandResult.insufficientArguments(this); List> arguments = new ArrayList<>(); Collection> children = List.of(root); diff --git a/commands/src/main/java/com/wizardlybump17/wlib/command/rework/result/CommandResult.java b/commands/src/main/java/com/wizardlybump17/wlib/command/rework/result/CommandResult.java index 787ae730..64f96cb2 100644 --- a/commands/src/main/java/com/wizardlybump17/wlib/command/rework/result/CommandResult.java +++ b/commands/src/main/java/com/wizardlybump17/wlib/command/rework/result/CommandResult.java @@ -1,5 +1,6 @@ package com.wizardlybump17.wlib.command.rework.result; +import com.wizardlybump17.wlib.command.rework.Command; import com.wizardlybump17.wlib.command.rework.context.CommandContext; import com.wizardlybump17.wlib.command.rework.exception.InputParsingException; import com.wizardlybump17.wlib.command.rework.node.CommandNode; @@ -35,8 +36,8 @@ public interface CommandResult { return new ExtraArgumentsResult<>(lastInputIndex, lastNode); } - static @NotNull InsufficientArgumentsResult insufficientArguments(int lastInputIndex, @NotNull CommandNode lastNode) { - return new InsufficientArgumentsResult<>(lastInputIndex, lastNode); + static @NotNull InsufficientArgumentsResult insufficientArguments(@NotNull Command command) { + return new InsufficientArgumentsResult<>(command); } static @NotNull ParseInputExceptionResult parseInputException(int lastInputIndex, @NotNull CommandNode lastNode, @NotNull InputParsingException exception) { diff --git a/commands/src/main/java/com/wizardlybump17/wlib/command/rework/result/error/InsufficientArgumentsResult.java b/commands/src/main/java/com/wizardlybump17/wlib/command/rework/result/error/InsufficientArgumentsResult.java index efba1774..032114bf 100644 --- a/commands/src/main/java/com/wizardlybump17/wlib/command/rework/result/error/InsufficientArgumentsResult.java +++ b/commands/src/main/java/com/wizardlybump17/wlib/command/rework/result/error/InsufficientArgumentsResult.java @@ -1,7 +1,18 @@ package com.wizardlybump17.wlib.command.rework.result.error; +import com.wizardlybump17.wlib.command.rework.Command; import com.wizardlybump17.wlib.command.rework.node.CommandNode; import org.jetbrains.annotations.NotNull; -public record InsufficientArgumentsResult(int lastInputIndex, @NotNull CommandNode lastNode) implements UnsuccessResult { +public record InsufficientArgumentsResult(@NotNull Command command) implements UnsuccessResult { + + @Override + public int lastInputIndex() { + return -1; + } + + @Override + public @NotNull CommandNode lastNode() { + return command.getRoot(); + } } From 0c2ac12c4de461b93d1dff6ae26adbf00586165b Mon Sep 17 00:00:00 2001 From: WizardlyBump17 Date: Thu, 30 Oct 2025 20:15:14 -0300 Subject: [PATCH 060/363] testing for insufficient arguments --- .../wlib/command/test/rework/CommandTests.java | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/commands/src/test/java/com/wizardlybump17/wlib/command/test/rework/CommandTests.java b/commands/src/test/java/com/wizardlybump17/wlib/command/test/rework/CommandTests.java index e0c61618..4d4728bf 100644 --- a/commands/src/test/java/com/wizardlybump17/wlib/command/test/rework/CommandTests.java +++ b/commands/src/test/java/com/wizardlybump17/wlib/command/test/rework/CommandTests.java @@ -5,6 +5,7 @@ import com.wizardlybump17.wlib.command.rework.result.CommandResult; import com.wizardlybump17.wlib.command.rework.result.error.ExceptionResult; import com.wizardlybump17.wlib.command.rework.result.error.ExtraArgumentsResult; +import com.wizardlybump17.wlib.command.rework.result.error.InsufficientArgumentsResult; import com.wizardlybump17.wlib.command.sender.BasicCommandSender; import com.wizardlybump17.wlib.command.sender.CommandSender; import org.jetbrains.annotations.NotNull; @@ -147,4 +148,14 @@ void testException() { Assertions.assertEquals(expected, actual); } + + @Test + void testInsufficientArguments() { + Command command = new Command(new LiteralCommandNode("hello", context -> CommandResult.successful(context, "hello"))); + + InsufficientArgumentsResult expected = CommandResult.insufficientArguments(command); + CommandResult actual = command.execute(ALL_KNOWING_SENDER, List.of()); + + Assertions.assertEquals(expected, actual); + } } From e97bb432dc733db8270028b7aa8c108dfc97bd7a Mon Sep 17 00:00:00 2001 From: WizardlyBump17 Date: Thu, 30 Oct 2025 20:16:34 -0300 Subject: [PATCH 061/363] renamed and added another sender --- .../command/test/rework/CommandTests.java | 23 ++++++++++--------- 1 file changed, 12 insertions(+), 11 deletions(-) diff --git a/commands/src/test/java/com/wizardlybump17/wlib/command/test/rework/CommandTests.java b/commands/src/test/java/com/wizardlybump17/wlib/command/test/rework/CommandTests.java index 4d4728bf..40378ac2 100644 --- a/commands/src/test/java/com/wizardlybump17/wlib/command/test/rework/CommandTests.java +++ b/commands/src/test/java/com/wizardlybump17/wlib/command/test/rework/CommandTests.java @@ -20,7 +20,8 @@ public class CommandTests { static final @NotNull Consumer SENDER_MESSAGE_CONSUMER = System.out::println; - static final @NotNull CommandSender ALL_KNOWING_SENDER = new BasicCommandSender<>(new Object(), "Test", UUID.nameUUIDFromBytes("Test".getBytes()), SENDER_MESSAGE_CONSUMER, $ -> true); + static final @NotNull CommandSender CHAD_SENDER = new BasicCommandSender<>(new Object(), "Chad", UUID.nameUUIDFromBytes("Chad".getBytes()), SENDER_MESSAGE_CONSUMER, $ -> true); + static final @NotNull CommandSender BETA_SENDER = new BasicCommandSender<>(new Object(), "Beta", UUID.nameUUIDFromBytes("Beta".getBytes()), SENDER_MESSAGE_CONSUMER, $ -> false); @Test void testSuccessHello() { @@ -28,7 +29,7 @@ void testSuccessHello() { Command command = new Command(helloNode); CommandResult expected = CommandResult.successful(0, helloNode, "hello"); - CommandResult actual = command.execute(ALL_KNOWING_SENDER, List.of("hello")); + CommandResult actual = command.execute(CHAD_SENDER, List.of("hello")); Assertions.assertEquals(expected, actual); } @@ -39,7 +40,7 @@ void testSuccessHelloWorld() { Command command = new Command(new LiteralCommandNode("hello", List.of(worldNode))); CommandResult expected = CommandResult.successful(1, worldNode, "hello world"); - CommandResult actual = command.execute(ALL_KNOWING_SENDER, List.of("hello", "world")); + CommandResult actual = command.execute(CHAD_SENDER, List.of("hello", "world")); Assertions.assertEquals(expected, actual); } @@ -50,7 +51,7 @@ void testSuccessHelloWorldHi() { Command command = new Command(new LiteralCommandNode("hello", List.of(new LiteralCommandNode("world", List.of(hiNode))))); CommandResult expected = CommandResult.successful(2, hiNode, "hello world hi"); - CommandResult actual = command.execute(ALL_KNOWING_SENDER, List.of("hello", "world", "hi")); + CommandResult actual = command.execute(CHAD_SENDER, List.of("hello", "world", "hi")); Assertions.assertEquals(expected, actual); } @@ -68,7 +69,7 @@ void test0() { )); CommandResult expected = CommandResult.successful(1, hiNode, "hello hi"); - CommandResult actual = command.execute(ALL_KNOWING_SENDER, List.of("hello", "hi")); + CommandResult actual = command.execute(CHAD_SENDER, List.of("hello", "hi")); Assertions.assertEquals(expected, actual); } @@ -86,7 +87,7 @@ void test1() { )); CommandResult expected = CommandResult.successful(2, hiWorldNode, "hello hi world"); - CommandResult actual = command.execute(ALL_KNOWING_SENDER, List.of("hello", "hi", "world")); + CommandResult actual = command.execute(CHAD_SENDER, List.of("hello", "hi", "world")); Assertions.assertEquals(expected, actual); } @@ -97,7 +98,7 @@ void testExtraArguments0() { Command command = new Command(helloNode); ExtraArgumentsResult expected = CommandResult.extraArguments(1, helloNode); - CommandResult actual = command.execute(ALL_KNOWING_SENDER, List.of("hello", "world")); + CommandResult actual = command.execute(CHAD_SENDER, List.of("hello", "world")); Assertions.assertEquals(expected, actual); } @@ -113,7 +114,7 @@ void testExtraArguments1() { ); ExtraArgumentsResult expected = CommandResult.extraArguments(2, worldNode); - CommandResult actual = command.execute(ALL_KNOWING_SENDER, List.of("hello", "world", "hi")); + CommandResult actual = command.execute(CHAD_SENDER, List.of("hello", "world", "hi")); Assertions.assertEquals(expected, actual); } @@ -130,7 +131,7 @@ void testExtraArguments2() { )); ExtraArgumentsResult expected = CommandResult.extraArguments(3, hiWorldNode); - CommandResult actual = command.execute(ALL_KNOWING_SENDER, List.of("hello", "hi", "world", "extra")); + CommandResult actual = command.execute(CHAD_SENDER, List.of("hello", "hi", "world", "extra")); Assertions.assertEquals(expected, actual); } @@ -144,7 +145,7 @@ void testException() { Command command = new Command(helloNode); ExceptionResult expected = CommandResult.exceptionally(0, helloNode, helloException); - CommandResult actual = command.execute(ALL_KNOWING_SENDER, List.of("hello")); + CommandResult actual = command.execute(CHAD_SENDER, List.of("hello")); Assertions.assertEquals(expected, actual); } @@ -154,7 +155,7 @@ void testInsufficientArguments() { Command command = new Command(new LiteralCommandNode("hello", context -> CommandResult.successful(context, "hello"))); InsufficientArgumentsResult expected = CommandResult.insufficientArguments(command); - CommandResult actual = command.execute(ALL_KNOWING_SENDER, List.of()); + CommandResult actual = command.execute(CHAD_SENDER, List.of()); Assertions.assertEquals(expected, actual); } From 23758a3bac4c0c30b1701913407df7e11e0e4113 Mon Sep 17 00:00:00 2001 From: WizardlyBump17 Date: Thu, 30 Oct 2025 20:18:27 -0300 Subject: [PATCH 062/363] testing for no permission --- .../wlib/command/test/rework/CommandTests.java | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/commands/src/test/java/com/wizardlybump17/wlib/command/test/rework/CommandTests.java b/commands/src/test/java/com/wizardlybump17/wlib/command/test/rework/CommandTests.java index 40378ac2..7c175a03 100644 --- a/commands/src/test/java/com/wizardlybump17/wlib/command/test/rework/CommandTests.java +++ b/commands/src/test/java/com/wizardlybump17/wlib/command/test/rework/CommandTests.java @@ -6,6 +6,7 @@ import com.wizardlybump17.wlib.command.rework.result.error.ExceptionResult; import com.wizardlybump17.wlib.command.rework.result.error.ExtraArgumentsResult; import com.wizardlybump17.wlib.command.rework.result.error.InsufficientArgumentsResult; +import com.wizardlybump17.wlib.command.rework.result.error.NoPermissionResult; import com.wizardlybump17.wlib.command.sender.BasicCommandSender; import com.wizardlybump17.wlib.command.sender.CommandSender; import org.jetbrains.annotations.NotNull; @@ -159,4 +160,15 @@ void testInsufficientArguments() { Assertions.assertEquals(expected, actual); } + + @Test + void testNoPermission() { + LiteralCommandNode helloNode = new LiteralCommandNode("hello", context -> CommandResult.successful(context, "hello"), "permission"); + Command command = new Command(helloNode); + + NoPermissionResult expected = CommandResult.noPermission(0, helloNode); + CommandResult actual = command.execute(BETA_SENDER, List.of("hello")); + + Assertions.assertEquals(expected, actual); + } } From 6efb7330f4a56cfbe442ef18d1074216c80f8d32 Mon Sep 17 00:00:00 2001 From: WizardlyBump17 Date: Thu, 30 Oct 2025 20:19:56 -0300 Subject: [PATCH 063/363] testing for out of range --- .../wlib/command/test/rework/CommandTests.java | 16 ++++++++++++---- 1 file changed, 12 insertions(+), 4 deletions(-) diff --git a/commands/src/test/java/com/wizardlybump17/wlib/command/test/rework/CommandTests.java b/commands/src/test/java/com/wizardlybump17/wlib/command/test/rework/CommandTests.java index 7c175a03..5dc97715 100644 --- a/commands/src/test/java/com/wizardlybump17/wlib/command/test/rework/CommandTests.java +++ b/commands/src/test/java/com/wizardlybump17/wlib/command/test/rework/CommandTests.java @@ -3,10 +3,7 @@ import com.wizardlybump17.wlib.command.rework.Command; import com.wizardlybump17.wlib.command.rework.node.LiteralCommandNode; import com.wizardlybump17.wlib.command.rework.result.CommandResult; -import com.wizardlybump17.wlib.command.rework.result.error.ExceptionResult; -import com.wizardlybump17.wlib.command.rework.result.error.ExtraArgumentsResult; -import com.wizardlybump17.wlib.command.rework.result.error.InsufficientArgumentsResult; -import com.wizardlybump17.wlib.command.rework.result.error.NoPermissionResult; +import com.wizardlybump17.wlib.command.rework.result.error.*; import com.wizardlybump17.wlib.command.sender.BasicCommandSender; import com.wizardlybump17.wlib.command.sender.CommandSender; import org.jetbrains.annotations.NotNull; @@ -171,4 +168,15 @@ void testNoPermission() { Assertions.assertEquals(expected, actual); } + + @Test + void testOutOfRange() { + LiteralCommandNode helloNode = new LiteralCommandNode("hello", context -> CommandResult.successful(context, "hello")); + Command command = new Command(helloNode); + + OutOfRangeInputResult expected = CommandResult.outOfRangeInput(0, helloNode); + CommandResult actual = command.execute(CHAD_SENDER, List.of("hello0")); + + Assertions.assertEquals(expected, actual); + } } From 1a6ccf2401f1a86af9de96dd13630e83bb3281c1 Mon Sep 17 00:00:00 2001 From: WizardlyBump17 Date: Thu, 30 Oct 2025 20:26:50 -0300 Subject: [PATCH 064/363] testing for parse input exception --- .../command/test/rework/CommandTests.java | 20 +++++++++++++++++++ 1 file changed, 20 insertions(+) diff --git a/commands/src/test/java/com/wizardlybump17/wlib/command/test/rework/CommandTests.java b/commands/src/test/java/com/wizardlybump17/wlib/command/test/rework/CommandTests.java index 5dc97715..ba76c133 100644 --- a/commands/src/test/java/com/wizardlybump17/wlib/command/test/rework/CommandTests.java +++ b/commands/src/test/java/com/wizardlybump17/wlib/command/test/rework/CommandTests.java @@ -1,6 +1,9 @@ package com.wizardlybump17.wlib.command.test.rework; import com.wizardlybump17.wlib.command.rework.Command; +import com.wizardlybump17.wlib.command.rework.exception.InputParsingException; +import com.wizardlybump17.wlib.command.rework.input.AllowedNumberInputs; +import com.wizardlybump17.wlib.command.rework.node.IntegerCommandNode; import com.wizardlybump17.wlib.command.rework.node.LiteralCommandNode; import com.wizardlybump17.wlib.command.rework.result.CommandResult; import com.wizardlybump17.wlib.command.rework.result.error.*; @@ -179,4 +182,21 @@ void testOutOfRange() { Assertions.assertEquals(expected, actual); } + + @Test + void testParseInputException() { + IntegerCommandNode worldNode = new IntegerCommandNode("world", new AllowedNumberInputs.AllowedIntegerInputs.SingleValue(10), context -> CommandResult.successful(context, 10)); + Command command = new Command(new LiteralCommandNode("hello", List.of(worldNode))); + + ParseInputExceptionResult expected = CommandResult.parseInputException(1, worldNode, new InputParsingException("Could not parse as int: world", new NumberFormatException("For input string: \"world\""))); + CommandResult actual = command.execute(CHAD_SENDER, List.of("hello", "world")); + + Assertions.assertInstanceOf(ParseInputExceptionResult.class, actual); + + ParseInputExceptionResult actualException = (ParseInputExceptionResult) actual; + Assertions.assertEquals(expected.lastInputIndex(), actual.lastInputIndex()); + Assertions.assertEquals(expected.lastNode(), actual.lastNode()); + Assertions.assertEquals(expected.exception().getMessage(), actualException.exception().getMessage()); + Assertions.assertEquals(expected.exception().getCause().getMessage(), actualException.exception().getCause().getMessage()); + } } From 7403361306854214ef267f6189bdb31cd890f398 Mon Sep 17 00:00:00 2001 From: WizardlyBump17 Date: Thu, 30 Oct 2025 20:46:11 -0300 Subject: [PATCH 065/363] starting actual CommandManager tests --- .../test/rework/CommandManagerTests.java | 79 ++----------------- 1 file changed, 8 insertions(+), 71 deletions(-) diff --git a/commands/src/test/java/com/wizardlybump17/wlib/command/test/rework/CommandManagerTests.java b/commands/src/test/java/com/wizardlybump17/wlib/command/test/rework/CommandManagerTests.java index 59de8b1a..1e26bab6 100644 --- a/commands/src/test/java/com/wizardlybump17/wlib/command/test/rework/CommandManagerTests.java +++ b/commands/src/test/java/com/wizardlybump17/wlib/command/test/rework/CommandManagerTests.java @@ -1,78 +1,15 @@ package com.wizardlybump17.wlib.command.test.rework; -import com.wizardlybump17.wlib.command.rework.Command; -import com.wizardlybump17.wlib.command.rework.executor.CommandNodeExecutor; -import com.wizardlybump17.wlib.command.rework.input.AllowedNumberInputs; -import com.wizardlybump17.wlib.command.rework.manager.CommandManager; -import com.wizardlybump17.wlib.command.rework.node.IntegerCommandNode; -import com.wizardlybump17.wlib.command.rework.node.LiteralCommandNode; -import com.wizardlybump17.wlib.command.rework.result.CommandResult; -import org.junit.jupiter.api.Assertions; -import org.junit.jupiter.api.Test; +import com.wizardlybump17.wlib.command.sender.BasicCommandSender; +import com.wizardlybump17.wlib.command.sender.CommandSender; +import org.jetbrains.annotations.NotNull; -import java.util.List; +import java.util.UUID; +import java.util.function.Consumer; class CommandManagerTests { - @Test - void test() { - CommandNodeExecutor executor = context -> CommandResult.successful(context, "a1"); - - Command command0 = new Command( - new LiteralCommandNode("hello", List.of( - new LiteralCommandNode("world", List.of( - new IntegerCommandNode("a1", new AllowedNumberInputs.AllowedIntegerInputs.Range(10, 100), executor) - )) - )) - ); - Command command1 = new Command( - new LiteralCommandNode("hello", List.of( - new LiteralCommandNode("world1", List.of( - new IntegerCommandNode("a1", new AllowedNumberInputs.AllowedIntegerInputs.Range(10, 100), executor) - )) - )) - ); - Command command2 = new Command( - new LiteralCommandNode("hello", List.of( - new LiteralCommandNode("world", List.of( - new IntegerCommandNode("a2", new AllowedNumberInputs.AllowedIntegerInputs.Range(10, 100), executor) - )) - )) - ); - Command command3 = new Command( - new LiteralCommandNode("hello", List.of( - new LiteralCommandNode("world", List.of( - new IntegerCommandNode("a1", new AllowedNumberInputs.AllowedIntegerInputs.Range(10, 100), executor), - new IntegerCommandNode("a2", List.of( - new LiteralCommandNode("hi") - ), new AllowedNumberInputs.AllowedIntegerInputs.Range(10, 100), executor) - )), - new LiteralCommandNode("world1", List.of( - new IntegerCommandNode("a1", new AllowedNumberInputs.AllowedIntegerInputs.Range(10, 100), executor) - )) - )) - ); - - CommandManager manager = new CommandManager(); - manager.registerCommand("test", command0); - manager.registerCommand("test", command1); - manager.registerCommand("test", command2); - manager.registerCommand("test", command3); - - Command expected = new Command( - new LiteralCommandNode("hello", List.of( - new LiteralCommandNode("world", List.of( - new IntegerCommandNode("a1", new AllowedNumberInputs.AllowedIntegerInputs.Range(10, 100), executor), - new IntegerCommandNode("a2", List.of( - new LiteralCommandNode("hi") - ), new AllowedNumberInputs.AllowedIntegerInputs.Range(10, 100), executor) - )), - new LiteralCommandNode("world1", List.of( - new IntegerCommandNode("a1", new AllowedNumberInputs.AllowedIntegerInputs.Range(10, 100), executor) - )) - )) - ); - - Assertions.assertEquals(expected, manager.getCommand("hello").get()); - } + static final @NotNull Consumer SENDER_MESSAGE_CONSUMER = System.out::println; + static final @NotNull CommandSender CHAD_SENDER = new BasicCommandSender<>(new Object(), "Chad", UUID.nameUUIDFromBytes("Chad".getBytes()), SENDER_MESSAGE_CONSUMER, $ -> true); + static final @NotNull CommandSender BETA_SENDER = new BasicCommandSender<>(new Object(), "Beta", UUID.nameUUIDFromBytes("Beta".getBytes()), SENDER_MESSAGE_CONSUMER, $ -> false); } From d2bc167acfd59c9d9c864617623a6eee3340f214 Mon Sep 17 00:00:00 2001 From: WizardlyBump17 Date: Thu, 30 Oct 2025 20:49:48 -0300 Subject: [PATCH 066/363] testing for registering different commands --- .../test/rework/CommandManagerTests.java | 26 +++++++++++++++++++ 1 file changed, 26 insertions(+) diff --git a/commands/src/test/java/com/wizardlybump17/wlib/command/test/rework/CommandManagerTests.java b/commands/src/test/java/com/wizardlybump17/wlib/command/test/rework/CommandManagerTests.java index 1e26bab6..5b3b39ca 100644 --- a/commands/src/test/java/com/wizardlybump17/wlib/command/test/rework/CommandManagerTests.java +++ b/commands/src/test/java/com/wizardlybump17/wlib/command/test/rework/CommandManagerTests.java @@ -1,8 +1,14 @@ package com.wizardlybump17.wlib.command.test.rework; +import com.wizardlybump17.wlib.command.rework.Command; +import com.wizardlybump17.wlib.command.rework.manager.CommandManager; +import com.wizardlybump17.wlib.command.rework.node.LiteralCommandNode; +import com.wizardlybump17.wlib.command.rework.result.CommandResult; import com.wizardlybump17.wlib.command.sender.BasicCommandSender; import com.wizardlybump17.wlib.command.sender.CommandSender; import org.jetbrains.annotations.NotNull; +import org.junit.jupiter.api.Assertions; +import org.junit.jupiter.api.Test; import java.util.UUID; import java.util.function.Consumer; @@ -12,4 +18,24 @@ class CommandManagerTests { static final @NotNull Consumer SENDER_MESSAGE_CONSUMER = System.out::println; static final @NotNull CommandSender CHAD_SENDER = new BasicCommandSender<>(new Object(), "Chad", UUID.nameUUIDFromBytes("Chad".getBytes()), SENDER_MESSAGE_CONSUMER, $ -> true); static final @NotNull CommandSender BETA_SENDER = new BasicCommandSender<>(new Object(), "Beta", UUID.nameUUIDFromBytes("Beta".getBytes()), SENDER_MESSAGE_CONSUMER, $ -> false); + + @Test + void testRegisterDifferent() { + Command command0 = new Command(new LiteralCommandNode("hello0", context -> CommandResult.successful(context, "hello0"))); + Command command1 = new Command(new LiteralCommandNode("hello1", context -> CommandResult.successful(context, "hello1"))); + Command command2 = new Command(new LiteralCommandNode("hello2", context -> CommandResult.successful(context, "hello2"))); + Command command3 = new Command(new LiteralCommandNode("hello3", context -> CommandResult.successful(context, "hello3"))); + + CommandManager manager = new CommandManager(); + + Command registeredCommand0 = manager.registerCommand("test", command0); + Command registeredCommand1 = manager.registerCommand("test", command1); + Command registeredCommand2 = manager.registerCommand("test", command2); + Command registeredCommand3 = manager.registerCommand("test", command3); + + Assertions.assertEquals(command0, registeredCommand0); + Assertions.assertEquals(command1, registeredCommand1); + Assertions.assertEquals(command2, registeredCommand2); + Assertions.assertEquals(command3, registeredCommand3); + } } From 3bd10106b85a366175d55ede2800203060fcdeec Mon Sep 17 00:00:00 2001 From: WizardlyBump17 Date: Thu, 30 Oct 2025 22:06:40 -0300 Subject: [PATCH 067/363] added the CommandNode#withExecutor(CommandNodeExecutor) method --- .../wlib/command/rework/node/CommandNode.java | 1 + .../wlib/command/rework/node/IntegerCommandNode.java | 6 ++++++ .../wlib/command/rework/node/LiteralCommandNode.java | 6 ++++++ .../command/rework/result/error/CommandNotFoundResult.java | 6 ++++++ 4 files changed, 19 insertions(+) diff --git a/commands/src/main/java/com/wizardlybump17/wlib/command/rework/node/CommandNode.java b/commands/src/main/java/com/wizardlybump17/wlib/command/rework/node/CommandNode.java index 10550a59..379f49fa 100644 --- a/commands/src/main/java/com/wizardlybump17/wlib/command/rework/node/CommandNode.java +++ b/commands/src/main/java/com/wizardlybump17/wlib/command/rework/node/CommandNode.java @@ -121,6 +121,7 @@ public int hashCode() { public @NotNull CommandNode merge(@NotNull CommandNode other) { LinkedHashMap> newChildren = new LinkedHashMap<>(children); + public abstract @NotNull CommandNode withExecutor(@NotNull CommandNodeExecutor executor); other.children.forEach((leftKey, leftChild) -> { if (!children.containsKey(leftKey)) { diff --git a/commands/src/main/java/com/wizardlybump17/wlib/command/rework/node/IntegerCommandNode.java b/commands/src/main/java/com/wizardlybump17/wlib/command/rework/node/IntegerCommandNode.java index 4a750b4d..3a05713d 100644 --- a/commands/src/main/java/com/wizardlybump17/wlib/command/rework/node/IntegerCommandNode.java +++ b/commands/src/main/java/com/wizardlybump17/wlib/command/rework/node/IntegerCommandNode.java @@ -8,6 +8,7 @@ import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.Nullable; +import java.util.ArrayList; import java.util.List; import java.util.stream.IntStream; @@ -95,4 +96,9 @@ public IntegerCommandNode(@NotNull String name, @NotNull AllowedNumberInputs.All public @NotNull IntegerCommandNode withChildren(@NotNull List> children) { return new IntegerCommandNode(getName(), children, getAllowedInputs(), getExecutor(), getPermission()); } + + @Override + public @NotNull IntegerCommandNode withExecutor(@NotNull CommandNodeExecutor executor) { + return new IntegerCommandNode(getName(), new ArrayList<>(getChildren()), getAllowedInputs(), executor, getPermission()); + } } diff --git a/commands/src/main/java/com/wizardlybump17/wlib/command/rework/node/LiteralCommandNode.java b/commands/src/main/java/com/wizardlybump17/wlib/command/rework/node/LiteralCommandNode.java index a9f40f8a..21742197 100644 --- a/commands/src/main/java/com/wizardlybump17/wlib/command/rework/node/LiteralCommandNode.java +++ b/commands/src/main/java/com/wizardlybump17/wlib/command/rework/node/LiteralCommandNode.java @@ -6,6 +6,7 @@ import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.Nullable; +import java.util.ArrayList; import java.util.List; public class LiteralCommandNode extends CommandNode { @@ -61,4 +62,9 @@ public LiteralCommandNode(@NotNull String name) { public @NotNull LiteralCommandNode withChildren(@NotNull List> children) { return new LiteralCommandNode(getName(), children, getExecutor(), getPermission()); } + + @Override + public @NotNull CommandNode withExecutor(@NotNull CommandNodeExecutor executor) { + return new LiteralCommandNode(getName(), new ArrayList<>(getChildren()), executor, getPermission()); + } } diff --git a/commands/src/main/java/com/wizardlybump17/wlib/command/rework/result/error/CommandNotFoundResult.java b/commands/src/main/java/com/wizardlybump17/wlib/command/rework/result/error/CommandNotFoundResult.java index 0565f2c3..66b25ccd 100644 --- a/commands/src/main/java/com/wizardlybump17/wlib/command/rework/result/error/CommandNotFoundResult.java +++ b/commands/src/main/java/com/wizardlybump17/wlib/command/rework/result/error/CommandNotFoundResult.java @@ -1,5 +1,6 @@ package com.wizardlybump17.wlib.command.rework.result.error; +import com.wizardlybump17.wlib.command.rework.executor.CommandNodeExecutor; import com.wizardlybump17.wlib.command.rework.node.CommandNode; import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.Nullable; @@ -35,5 +36,10 @@ private DummyNode() { public @NotNull DummyNode withChildren(@NotNull List> children) { return this; } + + @Override + public @NotNull DummyNode withExecutor(@NotNull CommandNodeExecutor executor) { + return this; + } } } From 5069050106a2f3936f13930f31f942c4b5846f7b Mon Sep 17 00:00:00 2001 From: WizardlyBump17 Date: Thu, 30 Oct 2025 22:08:17 -0300 Subject: [PATCH 068/363] working on the command merging --- .../wlib/command/rework/node/CommandNode.java | 45 ++++++---- .../test/rework/CommandManagerTests.java | 85 +++++++++++++++++++ 2 files changed, 114 insertions(+), 16 deletions(-) diff --git a/commands/src/main/java/com/wizardlybump17/wlib/command/rework/node/CommandNode.java b/commands/src/main/java/com/wizardlybump17/wlib/command/rework/node/CommandNode.java index 379f49fa..cb66f5ac 100644 --- a/commands/src/main/java/com/wizardlybump17/wlib/command/rework/node/CommandNode.java +++ b/commands/src/main/java/com/wizardlybump17/wlib/command/rework/node/CommandNode.java @@ -5,24 +5,26 @@ import com.wizardlybump17.wlib.command.rework.executor.CommandNodeExecutor; import com.wizardlybump17.wlib.command.rework.input.AllowedInputs; import com.wizardlybump17.wlib.command.sender.CommandSender; -import com.wizardlybump17.wlib.util.MapUtils; import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.Nullable; import org.jetbrains.annotations.Unmodifiable; -import java.util.*; +import java.util.ArrayList; +import java.util.List; +import java.util.Objects; +import java.util.Optional; public abstract class CommandNode { private final @NotNull String name; - private final @NotNull LinkedHashMap> children; + private final @NotNull @Unmodifiable List> children; private final @NotNull AllowedInputs allowedInputs; private final @Nullable CommandNodeExecutor executor; private final @Nullable String permission; public CommandNode(@NotNull String name, @NotNull List> children, @NotNull AllowedInputs allowedInputs, @Nullable CommandNodeExecutor executor, @Nullable String permission) { - this.name = name; - this.children = (LinkedHashMap>) MapUtils.collectionToMap(LinkedHashMap::new, children, CommandNode::getName); + this.name = name.toLowerCase(); + this.children = List.copyOf(children); this.allowedInputs = allowedInputs; this.executor = executor; this.permission = permission; @@ -56,8 +58,8 @@ public CommandNode(@NotNull String name, @NotNull AllowedInputs allowedInputs return name; } - public @NotNull @Unmodifiable SequencedCollection> getChildren() { - return Collections.unmodifiableSequencedCollection(children.sequencedValues()); + public @NotNull @Unmodifiable List> getChildren() { + return children; } public @NotNull AllowedInputs getAllowedInputs() { @@ -119,19 +121,30 @@ public int hashCode() { public abstract @NotNull CommandNode withChildren(@NotNull List> children); - public @NotNull CommandNode merge(@NotNull CommandNode other) { - LinkedHashMap> newChildren = new LinkedHashMap<>(children); public abstract @NotNull CommandNode withExecutor(@NotNull CommandNodeExecutor executor); - other.children.forEach((leftKey, leftChild) -> { - if (!children.containsKey(leftKey)) { - newChildren.put(leftKey, leftChild); - return; + public @NotNull Optional> getChild(@NotNull String name) { + for (CommandNode child : children) + if (child.getName().equals(name)) + return Optional.of(child); + return Optional.empty(); + } + + public @NotNull CommandNode merge(@NotNull CommandNode right) { + List> newChildren = new ArrayList<>(); + + for (CommandNode rightChild : right.children) { + Optional> leftChildOptional = getChild(rightChild.name); + + if (leftChildOptional.isEmpty()) { + newChildren.add(rightChild); + continue; } - newChildren.put(leftKey, leftChild.merge(children.get(leftKey))); - }); + CommandNode leftChild = leftChildOptional.get(); + newChildren.add(leftChild.merge(rightChild)); + } - return withChildren(new ArrayList<>(newChildren.values())); + return withChildren(newChildren); } } diff --git a/commands/src/test/java/com/wizardlybump17/wlib/command/test/rework/CommandManagerTests.java b/commands/src/test/java/com/wizardlybump17/wlib/command/test/rework/CommandManagerTests.java index 5b3b39ca..92cc9eef 100644 --- a/commands/src/test/java/com/wizardlybump17/wlib/command/test/rework/CommandManagerTests.java +++ b/commands/src/test/java/com/wizardlybump17/wlib/command/test/rework/CommandManagerTests.java @@ -1,6 +1,7 @@ package com.wizardlybump17.wlib.command.test.rework; import com.wizardlybump17.wlib.command.rework.Command; +import com.wizardlybump17.wlib.command.rework.executor.CommandNodeExecutor; import com.wizardlybump17.wlib.command.rework.manager.CommandManager; import com.wizardlybump17.wlib.command.rework.node.LiteralCommandNode; import com.wizardlybump17.wlib.command.rework.result.CommandResult; @@ -10,6 +11,7 @@ import org.junit.jupiter.api.Assertions; import org.junit.jupiter.api.Test; +import java.util.List; import java.util.UUID; import java.util.function.Consumer; @@ -38,4 +40,87 @@ void testRegisterDifferent() { Assertions.assertEquals(command2, registeredCommand2); Assertions.assertEquals(command3, registeredCommand3); } + + @Test + void testRegisterMerging0() { + CommandNodeExecutor helloExecutor = context -> CommandResult.successful(context, "hello"); + CommandNodeExecutor helloWorldExecutor = context -> CommandResult.successful(context, "hello world"); + CommandNodeExecutor helloWorldHiExecutor = context -> CommandResult.successful(context, "hello world hi"); + + Command command0 = new Command( + new LiteralCommandNode( + "hello", + helloExecutor + ) + ); + Command command1 = new Command( + new LiteralCommandNode( + "hello", + List.of( + new LiteralCommandNode( + "world", + helloWorldExecutor + ) + ) + ) + ); + Command command2 = new Command( + new LiteralCommandNode( + "hello", + List.of( + new LiteralCommandNode( + "world", + List.of( + new LiteralCommandNode( + "hi", + helloWorldHiExecutor + ) + ) + ) + ) + ) + ); + + CommandManager manager = new CommandManager(); + + Command registeredCommand0 = manager.registerCommand("test", command0); + Command registeredCommand1 = manager.registerCommand("test", command1); + Command registeredCommand2 = manager.registerCommand("test", command2); + + Command expectedCommand0 = command0; + Command expectedCommand1 = new Command( + new LiteralCommandNode( + "hello", + List.of( + new LiteralCommandNode( + "world", + helloWorldExecutor + ) + ), + helloExecutor + ) + ); + Command expectedCommand2 = new Command( + new LiteralCommandNode( + "hello", + List.of( + new LiteralCommandNode( + "world", + List.of( + new LiteralCommandNode( + "hi", + helloWorldHiExecutor + ) + ), + helloWorldExecutor + ) + ), + helloExecutor + ) + ); + + Assertions.assertEquals(registeredCommand0, expectedCommand0); + Assertions.assertEquals(registeredCommand1, expectedCommand1); + Assertions.assertEquals(registeredCommand2, expectedCommand2); + } } From 71d2101e7d6fc8bc9b35768fbf3152b5573c3520 Mon Sep 17 00:00:00 2001 From: WizardlyBump17 Date: Thu, 30 Oct 2025 22:18:57 -0300 Subject: [PATCH 069/363] its the other way around --- .../wlib/command/test/rework/CommandManagerTests.java | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/commands/src/test/java/com/wizardlybump17/wlib/command/test/rework/CommandManagerTests.java b/commands/src/test/java/com/wizardlybump17/wlib/command/test/rework/CommandManagerTests.java index 92cc9eef..5c4cd054 100644 --- a/commands/src/test/java/com/wizardlybump17/wlib/command/test/rework/CommandManagerTests.java +++ b/commands/src/test/java/com/wizardlybump17/wlib/command/test/rework/CommandManagerTests.java @@ -119,8 +119,8 @@ void testRegisterMerging0() { ) ); - Assertions.assertEquals(registeredCommand0, expectedCommand0); - Assertions.assertEquals(registeredCommand1, expectedCommand1); - Assertions.assertEquals(registeredCommand2, expectedCommand2); + Assertions.assertEquals(expectedCommand0, registeredCommand0); + Assertions.assertEquals(expectedCommand1, registeredCommand1); + Assertions.assertEquals(expectedCommand2, registeredCommand2); } } From 4360a411acce8e5fed5ab0ff40b98624651ba58c Mon Sep 17 00:00:00 2001 From: WizardlyBump17 Date: Thu, 30 Oct 2025 22:36:33 -0300 Subject: [PATCH 070/363] checking for the content instead --- .../wlib/command/rework/node/CommandNode.java | 3 ++- .../java/com/wizardlybump17/wlib/util/CollectionUtil.java | 7 +++++++ 2 files changed, 9 insertions(+), 1 deletion(-) diff --git a/commands/src/main/java/com/wizardlybump17/wlib/command/rework/node/CommandNode.java b/commands/src/main/java/com/wizardlybump17/wlib/command/rework/node/CommandNode.java index cb66f5ac..87f2fa00 100644 --- a/commands/src/main/java/com/wizardlybump17/wlib/command/rework/node/CommandNode.java +++ b/commands/src/main/java/com/wizardlybump17/wlib/command/rework/node/CommandNode.java @@ -5,6 +5,7 @@ import com.wizardlybump17.wlib.command.rework.executor.CommandNodeExecutor; import com.wizardlybump17.wlib.command.rework.input.AllowedInputs; import com.wizardlybump17.wlib.command.sender.CommandSender; +import com.wizardlybump17.wlib.util.CollectionUtil; import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.Nullable; import org.jetbrains.annotations.Unmodifiable; @@ -108,7 +109,7 @@ public boolean equals(Object o) { return false; CommandNode that = (CommandNode) o; return Objects.equals(name, that.name) - && Objects.equals(children, that.children) + && CollectionUtil.contentEquals(children, that.children) && Objects.equals(allowedInputs, that.allowedInputs) && Objects.equals(executor, that.executor) && Objects.equals(permission, that.permission); diff --git a/utils/src/main/java/com/wizardlybump17/wlib/util/CollectionUtil.java b/utils/src/main/java/com/wizardlybump17/wlib/util/CollectionUtil.java index 8c355141..09b4ac26 100644 --- a/utils/src/main/java/com/wizardlybump17/wlib/util/CollectionUtil.java +++ b/utils/src/main/java/com/wizardlybump17/wlib/util/CollectionUtil.java @@ -2,6 +2,7 @@ import lombok.NonNull; import lombok.RequiredArgsConstructor; +import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.Nullable; import java.util.*; @@ -235,4 +236,10 @@ public static > T deepClone(Supplier supplier, T o public static @NonNull List sort(@NonNull Collection collection) { return sort(collection, null); } + + public static boolean contentEquals(@NotNull Collection left, @NotNull Collection right) { + if (left.size() != right.size()) + return false; + return left.containsAll(right) && right.containsAll(left); + } } From 4f2168dfbec0603ce4e90c89df21a90ba3d89a00 Mon Sep 17 00:00:00 2001 From: WizardlyBump17 Date: Thu, 30 Oct 2025 22:37:55 -0300 Subject: [PATCH 071/363] it can be nullable --- .../wizardlybump17/wlib/command/rework/node/CommandNode.java | 2 +- .../wlib/command/rework/node/IntegerCommandNode.java | 5 ++--- .../wlib/command/rework/node/LiteralCommandNode.java | 5 ++--- .../command/rework/result/error/CommandNotFoundResult.java | 2 +- 4 files changed, 6 insertions(+), 8 deletions(-) diff --git a/commands/src/main/java/com/wizardlybump17/wlib/command/rework/node/CommandNode.java b/commands/src/main/java/com/wizardlybump17/wlib/command/rework/node/CommandNode.java index 87f2fa00..00cdfe47 100644 --- a/commands/src/main/java/com/wizardlybump17/wlib/command/rework/node/CommandNode.java +++ b/commands/src/main/java/com/wizardlybump17/wlib/command/rework/node/CommandNode.java @@ -122,7 +122,7 @@ public int hashCode() { public abstract @NotNull CommandNode withChildren(@NotNull List> children); - public abstract @NotNull CommandNode withExecutor(@NotNull CommandNodeExecutor executor); + public abstract @NotNull CommandNode withExecutor(@Nullable CommandNodeExecutor executor); public @NotNull Optional> getChild(@NotNull String name) { for (CommandNode child : children) diff --git a/commands/src/main/java/com/wizardlybump17/wlib/command/rework/node/IntegerCommandNode.java b/commands/src/main/java/com/wizardlybump17/wlib/command/rework/node/IntegerCommandNode.java index 3a05713d..3b7d084c 100644 --- a/commands/src/main/java/com/wizardlybump17/wlib/command/rework/node/IntegerCommandNode.java +++ b/commands/src/main/java/com/wizardlybump17/wlib/command/rework/node/IntegerCommandNode.java @@ -8,7 +8,6 @@ import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.Nullable; -import java.util.ArrayList; import java.util.List; import java.util.stream.IntStream; @@ -98,7 +97,7 @@ public IntegerCommandNode(@NotNull String name, @NotNull AllowedNumberInputs.All } @Override - public @NotNull IntegerCommandNode withExecutor(@NotNull CommandNodeExecutor executor) { - return new IntegerCommandNode(getName(), new ArrayList<>(getChildren()), getAllowedInputs(), executor, getPermission()); + public @NotNull IntegerCommandNode withExecutor(@Nullable CommandNodeExecutor executor) { + return new IntegerCommandNode(getName(), getChildren(), getAllowedInputs(), executor, getPermission()); } } diff --git a/commands/src/main/java/com/wizardlybump17/wlib/command/rework/node/LiteralCommandNode.java b/commands/src/main/java/com/wizardlybump17/wlib/command/rework/node/LiteralCommandNode.java index 21742197..5feb641f 100644 --- a/commands/src/main/java/com/wizardlybump17/wlib/command/rework/node/LiteralCommandNode.java +++ b/commands/src/main/java/com/wizardlybump17/wlib/command/rework/node/LiteralCommandNode.java @@ -6,7 +6,6 @@ import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.Nullable; -import java.util.ArrayList; import java.util.List; public class LiteralCommandNode extends CommandNode { @@ -64,7 +63,7 @@ public LiteralCommandNode(@NotNull String name) { } @Override - public @NotNull CommandNode withExecutor(@NotNull CommandNodeExecutor executor) { - return new LiteralCommandNode(getName(), new ArrayList<>(getChildren()), executor, getPermission()); + public @NotNull CommandNode withExecutor(@Nullable CommandNodeExecutor executor) { + return new LiteralCommandNode(getName(), getChildren(), executor, getPermission()); } } diff --git a/commands/src/main/java/com/wizardlybump17/wlib/command/rework/result/error/CommandNotFoundResult.java b/commands/src/main/java/com/wizardlybump17/wlib/command/rework/result/error/CommandNotFoundResult.java index 66b25ccd..cd083c50 100644 --- a/commands/src/main/java/com/wizardlybump17/wlib/command/rework/result/error/CommandNotFoundResult.java +++ b/commands/src/main/java/com/wizardlybump17/wlib/command/rework/result/error/CommandNotFoundResult.java @@ -38,7 +38,7 @@ private DummyNode() { } @Override - public @NotNull DummyNode withExecutor(@NotNull CommandNodeExecutor executor) { + public @NotNull DummyNode withExecutor(@Nullable CommandNodeExecutor executor) { return this; } } From b15baf3176e36bd34f7ced546d4fad72f1620a58 Mon Sep 17 00:00:00 2001 From: WizardlyBump17 Date: Thu, 30 Oct 2025 22:39:02 -0300 Subject: [PATCH 072/363] I think the merging is working now --- .../wlib/command/rework/node/CommandNode.java | 50 +++++++- .../test/rework/CommandManagerTests.java | 108 +++++++++++++++++- 2 files changed, 155 insertions(+), 3 deletions(-) diff --git a/commands/src/main/java/com/wizardlybump17/wlib/command/rework/node/CommandNode.java b/commands/src/main/java/com/wizardlybump17/wlib/command/rework/node/CommandNode.java index 00cdfe47..77d86557 100644 --- a/commands/src/main/java/com/wizardlybump17/wlib/command/rework/node/CommandNode.java +++ b/commands/src/main/java/com/wizardlybump17/wlib/command/rework/node/CommandNode.java @@ -132,10 +132,52 @@ public int hashCode() { } public @NotNull CommandNode merge(@NotNull CommandNode right) { + List> newChildrenLeft = getNewChildren(right, this); + List> newChildrenRight = getNewChildren(this, right); + + newChildrenLeft.removeIf(newChildLeft -> { + for (CommandNode newChildRight : newChildrenRight) + if (newChildRight.getName().equals(newChildLeft.getName())) + return true; + return false; + }); + newChildrenRight.removeIf(newChildRight -> { + for (CommandNode newChildLeft : newChildrenLeft) + if (newChildLeft.getName().equals(newChildRight.getName())) + return true; + return false; + }); + + newChildrenLeft.addAll(newChildrenRight); + + return withChildren(newChildrenLeft); + } + + private static @Nullable CommandNodeExecutor getNewExecutor(@NotNull CommandNode left, @NotNull CommandNode right) { + CommandNodeExecutor leftExecutor = left.getExecutor(); + CommandNodeExecutor rightExecutor = right.getExecutor(); + CommandNodeExecutor newLeftExecutor; + + if (leftExecutor == null && rightExecutor == null) { + newLeftExecutor = null; + } else if (leftExecutor == null && rightExecutor != null) { + newLeftExecutor = rightExecutor; + } else if (leftExecutor != null && rightExecutor == null) { + newLeftExecutor = leftExecutor; + } else if (Objects.equals(leftExecutor, rightExecutor)) { + newLeftExecutor = leftExecutor; + } else { + throw new IllegalStateException("Could not resolve an executor for the merged node."); + } + + return newLeftExecutor; + } + + private static @NotNull List> getNewChildren(@NotNull CommandNode left, @NotNull CommandNode right) { List> newChildren = new ArrayList<>(); for (CommandNode rightChild : right.children) { - Optional> leftChildOptional = getChild(rightChild.name); + Optional> leftChildOptional = left.getChild(rightChild.name); if (leftChildOptional.isEmpty()) { newChildren.add(rightChild); @@ -143,9 +185,13 @@ public int hashCode() { } CommandNode leftChild = leftChildOptional.get(); + + CommandNodeExecutor newLeftExecutor = getNewExecutor(leftChild, rightChild); + leftChild = leftChild.withExecutor(newLeftExecutor); + newChildren.add(leftChild.merge(rightChild)); } - return withChildren(newChildren); + return newChildren; } } diff --git a/commands/src/test/java/com/wizardlybump17/wlib/command/test/rework/CommandManagerTests.java b/commands/src/test/java/com/wizardlybump17/wlib/command/test/rework/CommandManagerTests.java index 5c4cd054..4ea8edf5 100644 --- a/commands/src/test/java/com/wizardlybump17/wlib/command/test/rework/CommandManagerTests.java +++ b/commands/src/test/java/com/wizardlybump17/wlib/command/test/rework/CommandManagerTests.java @@ -87,7 +87,105 @@ void testRegisterMerging0() { Command registeredCommand1 = manager.registerCommand("test", command1); Command registeredCommand2 = manager.registerCommand("test", command2); - Command expectedCommand0 = command0; + Command expectedCommand0 = new Command( + new LiteralCommandNode( + "hello", + helloExecutor + ) + ); + Command expectedCommand1 = new Command( + new LiteralCommandNode( + "hello", + List.of( + new LiteralCommandNode( + "world", + helloWorldExecutor + ) + ), + helloExecutor + ) + ); + Command expectedCommand2 = new Command( + new LiteralCommandNode( + "hello", + List.of( + new LiteralCommandNode( + "world", + List.of( + new LiteralCommandNode( + "hi", + helloWorldHiExecutor + ) + ), + helloWorldExecutor + ) + ), + helloExecutor + ) + ); + + Assertions.assertEquals(expectedCommand0, registeredCommand0); + Assertions.assertEquals(expectedCommand1, registeredCommand1); + Assertions.assertEquals(expectedCommand2, registeredCommand2); + } + + @Test + void testRegisterMerging1() { + CommandNodeExecutor helloExecutor = context -> CommandResult.successful(context, "hello"); + CommandNodeExecutor helloWorldExecutor = context -> CommandResult.successful(context, "hello world"); + CommandNodeExecutor helloWorldHiExecutor = context -> CommandResult.successful(context, "hello world hi"); + CommandNodeExecutor helloThereExecutor = context -> CommandResult.successful(context, "hello there"); + + Command command0 = new Command( + new LiteralCommandNode( + "hello", + helloExecutor + ) + ); + Command command1 = new Command( + new LiteralCommandNode( + "hello", + List.of( + new LiteralCommandNode( + "world", + helloWorldExecutor + ), + new LiteralCommandNode( + "there", + helloThereExecutor + ) + ) + ) + ); + Command command2 = new Command( + new LiteralCommandNode( + "hello", + List.of( + new LiteralCommandNode( + "world", + List.of( + new LiteralCommandNode( + "hi", + helloWorldHiExecutor + ) + ) + ) + ) + ) + ); + + CommandManager manager = new CommandManager(); + + Command registeredCommand0 = manager.registerCommand("test", command0); + Command registeredCommand1 = manager.registerCommand("test", command1); + Command registeredCommand2 = manager.registerCommand("test", command2); + + Command expectedCommand0 = new Command( + new LiteralCommandNode( + "hello", + helloExecutor + ) + ); Command expectedCommand1 = new Command( new LiteralCommandNode( "hello", @@ -95,6 +193,10 @@ void testRegisterMerging0() { new LiteralCommandNode( "world", helloWorldExecutor + ), + new LiteralCommandNode( + "there", + helloThereExecutor ) ), helloExecutor @@ -113,6 +215,10 @@ void testRegisterMerging0() { ) ), helloWorldExecutor + ), + new LiteralCommandNode( + "there", + helloThereExecutor ) ), helloExecutor From 138cebef3833a4e56c33f5f62bc6f450775102ab Mon Sep 17 00:00:00 2001 From: WizardlyBump17 Date: Thu, 30 Oct 2025 22:42:48 -0300 Subject: [PATCH 073/363] testing for command node executor not found --- .../wlib/command/test/rework/CommandTests.java | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/commands/src/test/java/com/wizardlybump17/wlib/command/test/rework/CommandTests.java b/commands/src/test/java/com/wizardlybump17/wlib/command/test/rework/CommandTests.java index ba76c133..83e8d7d7 100644 --- a/commands/src/test/java/com/wizardlybump17/wlib/command/test/rework/CommandTests.java +++ b/commands/src/test/java/com/wizardlybump17/wlib/command/test/rework/CommandTests.java @@ -199,4 +199,15 @@ void testParseInputException() { Assertions.assertEquals(expected.exception().getMessage(), actualException.exception().getMessage()); Assertions.assertEquals(expected.exception().getCause().getMessage(), actualException.exception().getCause().getMessage()); } + + @Test + void testCommandNodeExecutorNotFound() { + LiteralCommandNode helloNode = new LiteralCommandNode("hello"); + Command command = new Command(helloNode); + + CommandNodeExecutorNotFoundResult expected = CommandResult.noCommandNodeExecutor(0, helloNode); + CommandResult actual = command.execute(CHAD_SENDER, List.of("hello")); + + Assertions.assertEquals(expected, actual); + } } From 326ebec463dbae9442346a7f756c84ac43583596 Mon Sep 17 00:00:00 2001 From: WizardlyBump17 Date: Thu, 30 Oct 2025 22:46:28 -0300 Subject: [PATCH 074/363] testing for command not found --- .../test/rework/CommandManagerTests.java | 37 +++++++++++++++++++ 1 file changed, 37 insertions(+) diff --git a/commands/src/test/java/com/wizardlybump17/wlib/command/test/rework/CommandManagerTests.java b/commands/src/test/java/com/wizardlybump17/wlib/command/test/rework/CommandManagerTests.java index 4ea8edf5..a63593cf 100644 --- a/commands/src/test/java/com/wizardlybump17/wlib/command/test/rework/CommandManagerTests.java +++ b/commands/src/test/java/com/wizardlybump17/wlib/command/test/rework/CommandManagerTests.java @@ -5,6 +5,7 @@ import com.wizardlybump17.wlib.command.rework.manager.CommandManager; import com.wizardlybump17.wlib.command.rework.node.LiteralCommandNode; import com.wizardlybump17.wlib.command.rework.result.CommandResult; +import com.wizardlybump17.wlib.command.rework.result.error.CommandNotFoundResult; import com.wizardlybump17.wlib.command.sender.BasicCommandSender; import com.wizardlybump17.wlib.command.sender.CommandSender; import org.jetbrains.annotations.NotNull; @@ -229,4 +230,40 @@ void testRegisterMerging1() { Assertions.assertEquals(expectedCommand1, registeredCommand1); Assertions.assertEquals(expectedCommand2, registeredCommand2); } + + @Test + void testCommandNotFound0() { + Command command = new Command( + new LiteralCommandNode( + "hello", + context -> CommandResult.successful(context, "hello") + ) + ); + + CommandManager manager = new CommandManager(); + manager.registerCommand("test", command); + + CommandNotFoundResult expected = CommandResult.commandNotFound("hello0"); + CommandResult actual = manager.execute(CHAD_SENDER, List.of("hello0")); + + Assertions.assertEquals(expected, actual); + } + + @Test + void testCommandNotFound1() { + Command command = new Command( + new LiteralCommandNode( + "hello", + context -> CommandResult.successful(context, "hello") + ) + ); + + CommandManager manager = new CommandManager(); + manager.registerCommand("test", command); + + CommandNotFoundResult expected = CommandResult.commandNotFound(""); + CommandResult actual = manager.execute(CHAD_SENDER, List.of()); + + Assertions.assertEquals(expected, actual); + } } From 1fbcf30f46205f798fe0f6d15ea7cf459a546c0d Mon Sep 17 00:00:00 2001 From: WizardlyBump17 Date: Thu, 30 Oct 2025 22:51:27 -0300 Subject: [PATCH 075/363] testing for successful commands --- .../test/rework/CommandManagerTests.java | 71 +++++++++++++++++++ 1 file changed, 71 insertions(+) diff --git a/commands/src/test/java/com/wizardlybump17/wlib/command/test/rework/CommandManagerTests.java b/commands/src/test/java/com/wizardlybump17/wlib/command/test/rework/CommandManagerTests.java index a63593cf..c63fd10f 100644 --- a/commands/src/test/java/com/wizardlybump17/wlib/command/test/rework/CommandManagerTests.java +++ b/commands/src/test/java/com/wizardlybump17/wlib/command/test/rework/CommandManagerTests.java @@ -5,6 +5,7 @@ import com.wizardlybump17.wlib.command.rework.manager.CommandManager; import com.wizardlybump17.wlib.command.rework.node.LiteralCommandNode; import com.wizardlybump17.wlib.command.rework.result.CommandResult; +import com.wizardlybump17.wlib.command.rework.result.SuccessResult; import com.wizardlybump17.wlib.command.rework.result.error.CommandNotFoundResult; import com.wizardlybump17.wlib.command.sender.BasicCommandSender; import com.wizardlybump17.wlib.command.sender.CommandSender; @@ -266,4 +267,74 @@ void testCommandNotFound1() { Assertions.assertEquals(expected, actual); } + + @Test + void testSuccess0() { + LiteralCommandNode helloNode = new LiteralCommandNode( + "hello", + context -> CommandResult.successful(context, "hello") + ); + Command command0 = new Command(helloNode); + + Command command1 = new Command( + new LiteralCommandNode( + "hi", + context -> CommandResult.successful(context, "hi") + ) + ); + Command command2 = new Command( + new LiteralCommandNode( + "welcome", + context -> CommandResult.successful(context, "welcome") + ) + ); + + CommandManager manager = new CommandManager(); + manager.registerCommand("test", command0); + manager.registerCommand("test", command1); + manager.registerCommand("test", command2); + + SuccessResult expected = CommandResult.successful(0, helloNode, "hello"); + CommandResult actual = manager.execute(CHAD_SENDER, List.of("hello")); + + Assertions.assertEquals(expected, actual); + } + + @Test + void testSuccess1() { + Command command0 = new Command(new LiteralCommandNode( + "hello", + context -> CommandResult.successful(context, "hello") + )); + + LiteralCommandNode thereNode = new LiteralCommandNode( + "there", + context -> CommandResult.successful(context, "hi there") + ); + Command command1 = new Command( + new LiteralCommandNode( + "hi", + List.of( + thereNode + ) + ) + ); + + Command command2 = new Command( + new LiteralCommandNode( + "welcome", + context -> CommandResult.successful(context, "welcome") + ) + ); + + CommandManager manager = new CommandManager(); + manager.registerCommand("test", command0); + manager.registerCommand("test", command1); + manager.registerCommand("test", command2); + + SuccessResult expected = CommandResult.successful(1, thereNode, "hi there"); + CommandResult actual = manager.execute(CHAD_SENDER, List.of("hi", "there")); + + Assertions.assertEquals(expected, actual); + } } From 1639b3a14bdcafbe1533e0bb56561c80dc4e1fbb Mon Sep 17 00:00:00 2001 From: WizardlyBump17 Date: Thu, 30 Oct 2025 23:47:17 -0300 Subject: [PATCH 076/363] adding the suggestions instead of the name --- .../wizardlybump17/wlib/command/rework/Command.java | 13 +++++-------- 1 file changed, 5 insertions(+), 8 deletions(-) diff --git a/commands/src/main/java/com/wizardlybump17/wlib/command/rework/Command.java b/commands/src/main/java/com/wizardlybump17/wlib/command/rework/Command.java index a8b2b069..e00e11ec 100644 --- a/commands/src/main/java/com/wizardlybump17/wlib/command/rework/Command.java +++ b/commands/src/main/java/com/wizardlybump17/wlib/command/rework/Command.java @@ -130,14 +130,11 @@ public Command(@NotNull LiteralCommandNode root) { boolean isLastInput = i == input.size() - 1; if (inputString.isEmpty()) { - suggestions.addAll(children.stream() - .filter(child -> { - String permission = child.getPermission(); - return permission == null || sender.hasPermission(permission); - }) - .map(CommandNode::getName) - .toList() - ); + for (CommandNode child : children) { + String permission = child.getPermission(); + if (permission == null || sender.hasPermission(permission)) + suggestions.addAll(child.getSuggestions(sender, input, "").stream().map(String::valueOf).toList()); + } break; } From 0cd4bd582ef4d6e5c12cbc30dbbe7c0cbde1dea8 Mon Sep 17 00:00:00 2001 From: WizardlyBump17 Date: Thu, 30 Oct 2025 23:47:42 -0300 Subject: [PATCH 077/363] added actual tests for the suggestion system --- .../command/test/rework/SuggestionTests.java | 157 ++++++++++++++++-- 1 file changed, 140 insertions(+), 17 deletions(-) diff --git a/commands/src/test/java/com/wizardlybump17/wlib/command/test/rework/SuggestionTests.java b/commands/src/test/java/com/wizardlybump17/wlib/command/test/rework/SuggestionTests.java index 22290ed9..60cb1142 100644 --- a/commands/src/test/java/com/wizardlybump17/wlib/command/test/rework/SuggestionTests.java +++ b/commands/src/test/java/com/wizardlybump17/wlib/command/test/rework/SuggestionTests.java @@ -5,32 +5,155 @@ import com.wizardlybump17.wlib.command.rework.node.IntegerCommandNode; import com.wizardlybump17.wlib.command.rework.node.LiteralCommandNode; import com.wizardlybump17.wlib.command.rework.result.CommandResult; +import com.wizardlybump17.wlib.command.sender.BasicCommandSender; +import com.wizardlybump17.wlib.command.sender.CommandSender; +import org.jetbrains.annotations.NotNull; +import org.junit.jupiter.api.Assertions; +import org.junit.jupiter.api.DisplayName; import org.junit.jupiter.api.Test; import java.util.List; +import java.util.UUID; +import java.util.function.Consumer; class SuggestionTests { + static final @NotNull Consumer SENDER_MESSAGE_CONSUMER = System.out::println; + static final @NotNull CommandSender CHAD_SENDER = new BasicCommandSender<>(new Object(), "Chad", UUID.nameUUIDFromBytes("Chad".getBytes()), SENDER_MESSAGE_CONSUMER, $ -> true); + static final @NotNull CommandSender BETA_SENDER = new BasicCommandSender<>(new Object(), "Beta", UUID.nameUUIDFromBytes("Beta".getBytes()), SENDER_MESSAGE_CONSUMER, $ -> false); + + @Test + @DisplayName("Test Success: root 0") + void testSuccess0() { + Command command = new Command( + new LiteralCommandNode( + "hello", + List.of( + new LiteralCommandNode( + "world", + context -> CommandResult.successful(context, "hello world") + ) + ) + ) + ); + + List expected = List.of("hello"); + List actual = command.getSuggestions(CHAD_SENDER, List.of()); + + Assertions.assertEquals(expected, actual); + } + + @Test + @DisplayName("Test Success: root 1") + void testSuccess1() { + Command command = new Command( + new LiteralCommandNode( + "hello", + List.of( + new LiteralCommandNode( + "world", + context -> CommandResult.successful(context, "hello world") + ) + ) + ) + ); + + List expected = List.of("hello"); + List actual = command.getSuggestions(CHAD_SENDER, List.of("he")); + + Assertions.assertEquals(expected, actual); + } + @Test - void test() { + @DisplayName("Test Success: children 0") + void testSuccess2() { Command command = new Command( - new LiteralCommandNode("hello", List.of( - new LiteralCommandNode("world", List.of( - new IntegerCommandNode("a1", new AllowedNumberInputs.AllowedIntegerInputs.Range(10, 100), context -> CommandResult.successful(context, "a1")) - )), - new LiteralCommandNode("world1", List.of( - new IntegerCommandNode("a1", new AllowedNumberInputs.AllowedIntegerInputs.Range(10, 100), context -> CommandResult.successful(context, "a1")) - )), - new LiteralCommandNode("world2", List.of( - new IntegerCommandNode("a1", new AllowedNumberInputs.AllowedIntegerInputs.Range(10, 100), context -> CommandResult.successful(context, "a1")) - )), - new LiteralCommandNode("world3", List.of( - new IntegerCommandNode("a1", new AllowedNumberInputs.AllowedIntegerInputs.Range(10, 100), context -> CommandResult.successful(context, "a1")) - )) - )) + new LiteralCommandNode( + "hello", + List.of( + new LiteralCommandNode( + "world", + context -> CommandResult.successful(context, "hello world") + ), + new LiteralCommandNode( + "hi", + context -> CommandResult.successful(context, "hello hi") + ), + new LiteralCommandNode( + "there", + context -> CommandResult.successful(context, "hello there") + ) + ) + ) ); - List suggestions = command.getSuggestions(null, List.of("hello", "world")); - System.out.println(suggestions); + List expected = List.of("world", "hi", "there"); + List actual = command.getSuggestions(CHAD_SENDER, List.of("hello", "")); + + Assertions.assertEquals(expected, actual); + } + + @Test + @DisplayName("Test Success: children 1") + void testSuccess3() { + Command command = new Command( + new LiteralCommandNode( + "hello", + List.of( + new LiteralCommandNode( + "world", + context -> CommandResult.successful(context, "hello world") + ), + new LiteralCommandNode( + "hi", + context -> CommandResult.successful(context, "hello hi") + ), + new IntegerCommandNode( + "there", + new AllowedNumberInputs.AllowedIntegerInputs.Range(1, 10), + context -> CommandResult.successful(context, "hello there") + ) + ) + ) + ); + + List expected = List.of("world", "hi", "1", "3", "5", "7", "10"); + List actual = command.getSuggestions(CHAD_SENDER, List.of("hello", "")); + + Assertions.assertEquals(expected, actual); + } + + @Test + @DisplayName("Test Success: children 2") + void testSuccess4() { + Command command = new Command( + new LiteralCommandNode( + "hello", + List.of( + new LiteralCommandNode( + "world", + context -> CommandResult.successful(context, "hello world") + ), + new LiteralCommandNode( + "hi", + context -> CommandResult.successful(context, "hello hi") + ), + new IntegerCommandNode( + "there", + new AllowedNumberInputs.AllowedIntegerInputs.Range(1, 10), + context -> CommandResult.successful(context, "hello there") + ), + new LiteralCommandNode( + "happy", + context -> CommandResult.successful(context, "hello happy") + ) + ) + ) + ); + + List expected = List.of("world", "hi", "happy"); + List actual = command.getSuggestions(CHAD_SENDER, List.of("hello", "h")); + + Assertions.assertEquals(expected, actual); } } From bd3e3b53107a25aa31696d7b176dc894897782ce Mon Sep 17 00:00:00 2001 From: WizardlyBump17 Date: Fri, 31 Oct 2025 21:40:12 -0300 Subject: [PATCH 078/363] returning a list of objects instead --- .../wlib/command/rework/Command.java | 8 ++++---- .../rework/manager/CommandManager.java | 6 +++--- .../command/test/rework/SuggestionTests.java | 20 +++++++++---------- 3 files changed, 17 insertions(+), 17 deletions(-) diff --git a/commands/src/main/java/com/wizardlybump17/wlib/command/rework/Command.java b/commands/src/main/java/com/wizardlybump17/wlib/command/rework/Command.java index e00e11ec..f33c9efa 100644 --- a/commands/src/main/java/com/wizardlybump17/wlib/command/rework/Command.java +++ b/commands/src/main/java/com/wizardlybump17/wlib/command/rework/Command.java @@ -113,13 +113,13 @@ public Command(@NotNull LiteralCommandNode root) { return StringUtil.parseQuotedStrings(original); } - public @NotNull List getSuggestions(@NotNull CommandSender sender, @NotNull List input) { + public @NotNull List getSuggestions(@NotNull CommandSender sender, @NotNull List input) { if (input.isEmpty()) return List.of(root.getName()); String currentInput = input.getLast(); - List suggestions = new ArrayList<>(); + List suggestions = new ArrayList<>(); Collection> children = List.of(root); CommandNode lastNode = null; @@ -133,7 +133,7 @@ public Command(@NotNull LiteralCommandNode root) { for (CommandNode child : children) { String permission = child.getPermission(); if (permission == null || sender.hasPermission(permission)) - suggestions.addAll(child.getSuggestions(sender, input, "").stream().map(String::valueOf).toList()); + suggestions.addAll(child.getSuggestions(sender, input, "")); } break; } @@ -149,7 +149,7 @@ public Command(@NotNull LiteralCommandNode root) { String permission = child.getPermission(); if (isLastInput && (permission == null || sender.hasPermission(permission))) - suggestions.addAll(child.getSuggestions(sender, input, currentInput).stream().map(String::valueOf).toList()); + suggestions.addAll(child.getSuggestions(sender, input, currentInput)); lastParsingError = null; diff --git a/commands/src/main/java/com/wizardlybump17/wlib/command/rework/manager/CommandManager.java b/commands/src/main/java/com/wizardlybump17/wlib/command/rework/manager/CommandManager.java index 1c710a80..5e4f9af5 100644 --- a/commands/src/main/java/com/wizardlybump17/wlib/command/rework/manager/CommandManager.java +++ b/commands/src/main/java/com/wizardlybump17/wlib/command/rework/manager/CommandManager.java @@ -59,7 +59,7 @@ public class CommandManager { return execute(sender, String.join(" ", input)); } - public @NotNull List getSuggestions(@NotNull CommandSender sender, @NotNull List input) { + public @NotNull List getSuggestions(@NotNull CommandSender sender, @NotNull List input) { if (input.isEmpty()) return List.of(); @@ -72,7 +72,7 @@ public class CommandManager { return command.getSuggestions(sender, input); } - public @NotNull List getSuggestions(@NotNull CommandSender sender, @NotNull String input) { + public @NotNull List getSuggestions(@NotNull CommandSender sender, @NotNull String input) { try { if (!input.isEmpty() && !StringUtil.isProperlyQuoted(input)) input = input + "\""; @@ -82,7 +82,7 @@ public class CommandManager { } } - public @NotNull List getSuggestions(@NotNull CommandSender sender, @NotNull String @NotNull [] input) { + public @NotNull List getSuggestions(@NotNull CommandSender sender, @NotNull String @NotNull [] input) { return getSuggestions(sender, String.join(" ", input)); } diff --git a/commands/src/test/java/com/wizardlybump17/wlib/command/test/rework/SuggestionTests.java b/commands/src/test/java/com/wizardlybump17/wlib/command/test/rework/SuggestionTests.java index 60cb1142..eec3cbac 100644 --- a/commands/src/test/java/com/wizardlybump17/wlib/command/test/rework/SuggestionTests.java +++ b/commands/src/test/java/com/wizardlybump17/wlib/command/test/rework/SuggestionTests.java @@ -37,8 +37,8 @@ void testSuccess0() { ) ); - List expected = List.of("hello"); - List actual = command.getSuggestions(CHAD_SENDER, List.of()); + List expected = List.of("hello"); + List actual = command.getSuggestions(CHAD_SENDER, List.of()); Assertions.assertEquals(expected, actual); } @@ -58,8 +58,8 @@ void testSuccess1() { ) ); - List expected = List.of("hello"); - List actual = command.getSuggestions(CHAD_SENDER, List.of("he")); + List expected = List.of("hello"); + List actual = command.getSuggestions(CHAD_SENDER, List.of("he")); Assertions.assertEquals(expected, actual); } @@ -87,8 +87,8 @@ void testSuccess2() { ) ); - List expected = List.of("world", "hi", "there"); - List actual = command.getSuggestions(CHAD_SENDER, List.of("hello", "")); + List expected = List.of("world", "hi", "there"); + List actual = command.getSuggestions(CHAD_SENDER, List.of("hello", "")); Assertions.assertEquals(expected, actual); } @@ -117,8 +117,8 @@ void testSuccess3() { ) ); - List expected = List.of("world", "hi", "1", "3", "5", "7", "10"); - List actual = command.getSuggestions(CHAD_SENDER, List.of("hello", "")); + List expected = List.of("world", "hi", 1, 3, 5, 7, 10); + List actual = command.getSuggestions(CHAD_SENDER, List.of("hello", "")); Assertions.assertEquals(expected, actual); } @@ -151,8 +151,8 @@ void testSuccess4() { ) ); - List expected = List.of("world", "hi", "happy"); - List actual = command.getSuggestions(CHAD_SENDER, List.of("hello", "h")); + List expected = List.of("world", "hi", "happy"); + List actual = command.getSuggestions(CHAD_SENDER, List.of("hello", "h")); Assertions.assertEquals(expected, actual); } From 6e49c3fd8d6fc160b08c43530534411c198c16f9 Mon Sep 17 00:00:00 2001 From: WizardlyBump17 Date: Fri, 31 Oct 2025 21:50:22 -0300 Subject: [PATCH 079/363] using to maps: one with the full name and other with the simple name --- .../rework/manager/CommandManager.java | 30 +++++++++++++------ 1 file changed, 21 insertions(+), 9 deletions(-) diff --git a/commands/src/main/java/com/wizardlybump17/wlib/command/rework/manager/CommandManager.java b/commands/src/main/java/com/wizardlybump17/wlib/command/rework/manager/CommandManager.java index 5e4f9af5..52e77927 100644 --- a/commands/src/main/java/com/wizardlybump17/wlib/command/rework/manager/CommandManager.java +++ b/commands/src/main/java/com/wizardlybump17/wlib/command/rework/manager/CommandManager.java @@ -1,6 +1,7 @@ package com.wizardlybump17.wlib.command.rework.manager; import com.wizardlybump17.wlib.command.rework.Command; +import com.wizardlybump17.wlib.command.rework.node.CommandNode; import com.wizardlybump17.wlib.command.rework.result.CommandResult; import com.wizardlybump17.wlib.command.sender.CommandSender; import com.wizardlybump17.wlib.util.StringUtil; @@ -16,22 +17,27 @@ public class CommandManager { private static final char SEPARATOR = ':'; - private final @NotNull Map commands = new HashMap<>(); + private final @NotNull Map commandsByFullName = new HashMap<>(); + private final @NotNull Map commandsByName = new HashMap<>(); public @NotNull Command registerCommand(@NotNull String identifier, @NotNull Command command) { String commandName = command.getRoot().getName().toLowerCase(); String fullCommandName = identifier + SEPARATOR + commandName; - Command existingCommand = commands.get(fullCommandName); + + Command existingCommand = commandsByFullName.get(fullCommandName); if (existingCommand != null) { Command newCommand = mergeCommand(existingCommand, command); - commands.put(fullCommandName, newCommand); - commands.put(commandName, newCommand); + + commandsByFullName.put(fullCommandName, newCommand); + commandsByName.put(commandName, newCommand); + return newCommand; } - commands.put(fullCommandName, command); - commands.put(commandName, command); + commandsByFullName.put(fullCommandName, command); + commandsByName.put(commandName, command); + return command; } @@ -45,9 +51,13 @@ public class CommandManager { String commandName = input.getFirst(); - Command command = commands.get(commandName); + Command command = commandsByFullName.get(commandName); + + if (command == null) + command = commandsByName.get(commandName); if (command == null) return CommandResult.commandNotFound(commandName); + return command.execute(sender, input); } @@ -65,7 +75,7 @@ public class CommandManager { String commandName = input.getFirst(); - Command command = commands.get(commandName); + Command command = commandsByFullName.get(commandName); if (command == null) return List.of(); @@ -87,6 +97,8 @@ public class CommandManager { } public @NotNull Optional getCommand(@NotNull String name) { - return Optional.ofNullable(commands.get(name)); + return Optional + .ofNullable(commandsByFullName.get(name)) + .or(() -> Optional.ofNullable(commandsByName.get(name))); } } From bc04034db2dbe219f1aaa21ca3b952c0ada842a7 Mon Sep 17 00:00:00 2001 From: WizardlyBump17 Date: Fri, 31 Oct 2025 21:51:54 -0300 Subject: [PATCH 080/363] added the CommandNode#canExecute(CommandSender) method --- .../wizardlybump17/wlib/command/rework/node/CommandNode.java | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/commands/src/main/java/com/wizardlybump17/wlib/command/rework/node/CommandNode.java b/commands/src/main/java/com/wizardlybump17/wlib/command/rework/node/CommandNode.java index 77d86557..6eba44e9 100644 --- a/commands/src/main/java/com/wizardlybump17/wlib/command/rework/node/CommandNode.java +++ b/commands/src/main/java/com/wizardlybump17/wlib/command/rework/node/CommandNode.java @@ -194,4 +194,8 @@ public int hashCode() { return newChildren; } + + public boolean canExecute(@NotNull CommandSender sender) { + return permission == null || sender.hasPermission(permission); + } } From 31848d036276f6a5de47742281b02f21339a34fc Mon Sep 17 00:00:00 2001 From: WizardlyBump17 Date: Fri, 31 Oct 2025 21:52:27 -0300 Subject: [PATCH 081/363] returning all possible commands --- .../wlib/command/rework/manager/CommandManager.java | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/commands/src/main/java/com/wizardlybump17/wlib/command/rework/manager/CommandManager.java b/commands/src/main/java/com/wizardlybump17/wlib/command/rework/manager/CommandManager.java index 52e77927..54569b40 100644 --- a/commands/src/main/java/com/wizardlybump17/wlib/command/rework/manager/CommandManager.java +++ b/commands/src/main/java/com/wizardlybump17/wlib/command/rework/manager/CommandManager.java @@ -70,8 +70,14 @@ public class CommandManager { } public @NotNull List getSuggestions(@NotNull CommandSender sender, @NotNull List input) { - if (input.isEmpty()) - return List.of(); + if (input.isEmpty()) { + return commandsByName.values().stream() + .map(Command::getRoot) + .filter(node -> node.canExecute(sender)) + .map(CommandNode::getName) + .map(string -> (Object) string) + .toList(); + } String commandName = input.getFirst(); From 1d60cc8e7d557a0fba8a0baa91d98010d0d96943 Mon Sep 17 00:00:00 2001 From: WizardlyBump17 Date: Fri, 31 Oct 2025 21:54:09 -0300 Subject: [PATCH 082/363] we dont still dont know which command is that --- .../wlib/command/rework/manager/CommandManager.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/commands/src/main/java/com/wizardlybump17/wlib/command/rework/manager/CommandManager.java b/commands/src/main/java/com/wizardlybump17/wlib/command/rework/manager/CommandManager.java index 54569b40..a1fc3528 100644 --- a/commands/src/main/java/com/wizardlybump17/wlib/command/rework/manager/CommandManager.java +++ b/commands/src/main/java/com/wizardlybump17/wlib/command/rework/manager/CommandManager.java @@ -70,7 +70,7 @@ public class CommandManager { } public @NotNull List getSuggestions(@NotNull CommandSender sender, @NotNull List input) { - if (input.isEmpty()) { + if (input.isEmpty() || input.size() == 1) { return commandsByName.values().stream() .map(Command::getRoot) .filter(node -> node.canExecute(sender)) From 04cf5e11067d8632ca167dc218a4600a76f006ed Mon Sep 17 00:00:00 2001 From: WizardlyBump17 Date: Fri, 31 Oct 2025 21:54:33 -0300 Subject: [PATCH 083/363] trying by the simple name --- .../wlib/command/rework/manager/CommandManager.java | 3 +++ 1 file changed, 3 insertions(+) diff --git a/commands/src/main/java/com/wizardlybump17/wlib/command/rework/manager/CommandManager.java b/commands/src/main/java/com/wizardlybump17/wlib/command/rework/manager/CommandManager.java index a1fc3528..df210b3f 100644 --- a/commands/src/main/java/com/wizardlybump17/wlib/command/rework/manager/CommandManager.java +++ b/commands/src/main/java/com/wizardlybump17/wlib/command/rework/manager/CommandManager.java @@ -82,6 +82,9 @@ public class CommandManager { String commandName = input.getFirst(); Command command = commandsByFullName.get(commandName); + + if (command == null) + command = commandsByName.get(commandName); if (command == null) return List.of(); From a0bb374d2c28ab2db4c63ff4ce3a83cb7e147450 Mon Sep 17 00:00:00 2001 From: WizardlyBump17 Date: Fri, 31 Oct 2025 22:02:55 -0300 Subject: [PATCH 084/363] added more allowed inputs --- .../rework/input/AllowedNumberInputs.java | 50 +++++++++++++++++++ 1 file changed, 50 insertions(+) diff --git a/commands/src/main/java/com/wizardlybump17/wlib/command/rework/input/AllowedNumberInputs.java b/commands/src/main/java/com/wizardlybump17/wlib/command/rework/input/AllowedNumberInputs.java index 28263b64..7b8d9e05 100644 --- a/commands/src/main/java/com/wizardlybump17/wlib/command/rework/input/AllowedNumberInputs.java +++ b/commands/src/main/java/com/wizardlybump17/wlib/command/rework/input/AllowedNumberInputs.java @@ -54,5 +54,55 @@ public boolean isAllowed(@Nullable Integer input) { return false; } } + + record Positive() implements AllowedIntegerInputs, RangedAllowedInputs { + + @Override + public @NotNull Integer from() { + return 0; + } + + @Override + public @NotNull Integer to() { + return Integer.MAX_VALUE; + } + + @Override + public boolean isInRange(@NotNull Integer input) { + return input > 0; + } + + @Override + public boolean isAllowed(@Nullable Integer input) { + if (input == null) + return false; + return isInRange(input); + } + } + + record Negative() implements AllowedIntegerInputs, RangedAllowedInputs { + + @Override + public @NotNull Integer from() { + return Integer.MIN_VALUE; + } + + @Override + public @NotNull Integer to() { + return -1; + } + + @Override + public boolean isInRange(@NotNull Integer input) { + return input < 0; + } + + @Override + public boolean isAllowed(@Nullable Integer input) { + if (input == null) + return false; + return isInRange(input); + } + } } } From 2cf02539fccd841c5403fe97f41064a1ddf11c96 Mon Sep 17 00:00:00 2001 From: WizardlyBump17 Date: Fri, 31 Oct 2025 22:03:09 -0300 Subject: [PATCH 085/363] testing for successful suggestions --- .../test/rework/CommandManagerTests.java | 227 ++++++++++++++++++ 1 file changed, 227 insertions(+) diff --git a/commands/src/test/java/com/wizardlybump17/wlib/command/test/rework/CommandManagerTests.java b/commands/src/test/java/com/wizardlybump17/wlib/command/test/rework/CommandManagerTests.java index c63fd10f..c4de7d48 100644 --- a/commands/src/test/java/com/wizardlybump17/wlib/command/test/rework/CommandManagerTests.java +++ b/commands/src/test/java/com/wizardlybump17/wlib/command/test/rework/CommandManagerTests.java @@ -2,13 +2,16 @@ import com.wizardlybump17.wlib.command.rework.Command; import com.wizardlybump17.wlib.command.rework.executor.CommandNodeExecutor; +import com.wizardlybump17.wlib.command.rework.input.AllowedNumberInputs; import com.wizardlybump17.wlib.command.rework.manager.CommandManager; +import com.wizardlybump17.wlib.command.rework.node.IntegerCommandNode; import com.wizardlybump17.wlib.command.rework.node.LiteralCommandNode; import com.wizardlybump17.wlib.command.rework.result.CommandResult; import com.wizardlybump17.wlib.command.rework.result.SuccessResult; import com.wizardlybump17.wlib.command.rework.result.error.CommandNotFoundResult; import com.wizardlybump17.wlib.command.sender.BasicCommandSender; import com.wizardlybump17.wlib.command.sender.CommandSender; +import com.wizardlybump17.wlib.util.CollectionUtil; import org.jetbrains.annotations.NotNull; import org.junit.jupiter.api.Assertions; import org.junit.jupiter.api.Test; @@ -337,4 +340,228 @@ void testSuccess1() { Assertions.assertEquals(expected, actual); } + + @Test + void testSuggestionsListChad0() { + Command command0 = new Command(new LiteralCommandNode( + "hello", + context -> CommandResult.successful(context, "hello") + )); + Command command1 = new Command( + new LiteralCommandNode( + "hi", + List.of( + new LiteralCommandNode( + "there", + context -> CommandResult.successful(context, "hi there") + ) + ) + ) + ); + Command command2 = new Command( + new LiteralCommandNode( + "welcome", + context -> CommandResult.successful(context, "welcome") + ) + ); + + CommandManager manager = new CommandManager(); + manager.registerCommand("test", command0); + manager.registerCommand("test", command1); + manager.registerCommand("test", command2); + + List expected = List.of("hello", "hi", "welcome"); + List actual = manager.getSuggestions(CHAD_SENDER, List.of()); + + Assertions.assertTrue(CollectionUtil.contentEquals(expected, actual)); + } + + @Test + void testSuggestionsListChad1() { + Command command0 = new Command(new LiteralCommandNode( + "hello", + context -> CommandResult.successful(context, "hello") + )); + Command command1 = new Command( + new LiteralCommandNode( + "hi", + List.of( + new LiteralCommandNode( + "there", + context -> CommandResult.successful(context, "hi there") + ) + ) + ) + ); + Command command2 = new Command( + new LiteralCommandNode( + "welcome", + context -> CommandResult.successful(context, "welcome") + ) + ); + + CommandManager manager = new CommandManager(); + manager.registerCommand("test", command0); + manager.registerCommand("test", command1); + manager.registerCommand("test", command2); + + List expected = List.of("hello", "hi", "welcome"); + List actual = manager.getSuggestions(CHAD_SENDER, List.of("he")); + + Assertions.assertTrue(CollectionUtil.contentEquals(expected, actual)); + } + + @Test + void testSuggestionsListChad2() { + Command command0 = new Command(new LiteralCommandNode( + "hello", + context -> CommandResult.successful(context, "hello") + )); + Command command1 = new Command( + new LiteralCommandNode( + "hi", + List.of( + new LiteralCommandNode( + "there", + context -> CommandResult.successful(context, "hi there") + ) + ) + ) + ); + Command command2 = new Command( + new LiteralCommandNode( + "welcome", + context -> CommandResult.successful(context, "welcome") + ) + ); + + CommandManager manager = new CommandManager(); + manager.registerCommand("test", command0); + manager.registerCommand("test", command1); + manager.registerCommand("test", command2); + + List expected = List.of("there"); + List actual = manager.getSuggestions(CHAD_SENDER, List.of("hi", "")); + + Assertions.assertTrue(CollectionUtil.contentEquals(expected, actual)); + } + + @Test + void testSuggestionsListChad3() { + Command command0 = new Command(new LiteralCommandNode( + "hello", + context -> CommandResult.successful(context, "hello") + )); + Command command1 = new Command( + new LiteralCommandNode( + "hi", + List.of( + new LiteralCommandNode( + "there", + context -> CommandResult.successful(context, "hi there") + ) + ) + ) + ); + Command command2 = new Command( + new LiteralCommandNode( + "welcome", + context -> CommandResult.successful(context, "welcome") + ) + ); + + CommandManager manager = new CommandManager(); + manager.registerCommand("test", command0); + manager.registerCommand("test", command1); + manager.registerCommand("test", command2); + + List expected = List.of("there"); + List actual = manager.getSuggestions(CHAD_SENDER, List.of("hi", "ther")); + + Assertions.assertTrue(CollectionUtil.contentEquals(expected, actual)); + } + + @Test + void testSuggestionsListChad4() { + Command command0 = new Command(new LiteralCommandNode( + "hello", + context -> CommandResult.successful(context, "hello") + )); + Command command1 = new Command( + new LiteralCommandNode( + "hi", + List.of( + new LiteralCommandNode( + "there", + context -> CommandResult.successful(context, "hi there") + ) + ) + ) + ); + Command command2 = new Command( + new LiteralCommandNode( + "welcome", + List.of( + new IntegerCommandNode( + "repeat", + new AllowedNumberInputs.AllowedIntegerInputs.Positive(), + context -> CommandResult.successful(context, "welcome".repeat(context.arguments().getArgument("repeat").orElseThrow().data())) + ) + ), + context -> CommandResult.successful(context, "welcome") + ) + ); + + CommandManager manager = new CommandManager(); + manager.registerCommand("test", command0); + manager.registerCommand("test", command1); + manager.registerCommand("test", command2); + + List expected = List.of(0, 536870911, 1073741822, 1610612733, 2147483647); + List actual = manager.getSuggestions(CHAD_SENDER, List.of("welcome", "")); + + Assertions.assertTrue(CollectionUtil.contentEquals(expected, actual)); + } + + @Test + void testSuggestionsListChad6() { + Command command0 = new Command(new LiteralCommandNode( + "hello", + context -> CommandResult.successful(context, "hello") + )); + Command command1 = new Command( + new LiteralCommandNode( + "hi", + List.of( + new LiteralCommandNode( + "there", + context -> CommandResult.successful(context, "hi there") + ) + ) + ) + ); + Command command2 = new Command( + new LiteralCommandNode( + "welcome", + List.of( + new IntegerCommandNode( + "repeat", + new AllowedNumberInputs.AllowedIntegerInputs.Positive(), + context -> CommandResult.successful(context, "welcome".repeat(context.arguments().getArgument("repeat").orElseThrow().data())) + ) + ), + context -> CommandResult.successful(context, "welcome") + ) + ); + + CommandManager manager = new CommandManager(); + manager.registerCommand("test", command0); + manager.registerCommand("test", command1); + manager.registerCommand("test", command2); + + List expected = List.of(0, 536870911, 1073741822, 1610612733, 2147483647); + List actual = manager.getSuggestions(CHAD_SENDER, List.of("welcome", "10")); + + Assertions.assertTrue(CollectionUtil.contentEquals(expected, actual)); + } } From ba395d6307708d90233a9eb59f8524776b3ddeef Mon Sep 17 00:00:00 2001 From: WizardlyBump17 Date: Fri, 31 Oct 2025 22:10:11 -0300 Subject: [PATCH 086/363] the AllowedInputs is now responsible for returning the suggestions --- .../command/rework/input/AllowedInputs.java | 8 +++ .../rework/input/AllowedNumberInputs.java | 72 +++++++++++++++++++ .../wlib/command/rework/node/CommandNode.java | 2 +- .../rework/node/IntegerCommandNode.java | 35 --------- .../test/rework/CommandManagerTests.java | 4 +- 5 files changed, 83 insertions(+), 38 deletions(-) diff --git a/commands/src/main/java/com/wizardlybump17/wlib/command/rework/input/AllowedInputs.java b/commands/src/main/java/com/wizardlybump17/wlib/command/rework/input/AllowedInputs.java index 5f4f3ec2..b9ed89f3 100644 --- a/commands/src/main/java/com/wizardlybump17/wlib/command/rework/input/AllowedInputs.java +++ b/commands/src/main/java/com/wizardlybump17/wlib/command/rework/input/AllowedInputs.java @@ -1,8 +1,16 @@ package com.wizardlybump17.wlib.command.rework.input; +import com.wizardlybump17.wlib.command.sender.CommandSender; +import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.Nullable; +import java.util.List; + public interface AllowedInputs { boolean isAllowed(@Nullable T input); + + default @NotNull List getSuggestions(@NotNull CommandSender sender, @NotNull List input, @NotNull String current) { + return List.of(); + } } diff --git a/commands/src/main/java/com/wizardlybump17/wlib/command/rework/input/AllowedNumberInputs.java b/commands/src/main/java/com/wizardlybump17/wlib/command/rework/input/AllowedNumberInputs.java index 7b8d9e05..fae75c39 100644 --- a/commands/src/main/java/com/wizardlybump17/wlib/command/rework/input/AllowedNumberInputs.java +++ b/commands/src/main/java/com/wizardlybump17/wlib/command/rework/input/AllowedNumberInputs.java @@ -1,9 +1,11 @@ package com.wizardlybump17.wlib.command.rework.input; +import com.wizardlybump17.wlib.command.sender.CommandSender; import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.Nullable; import java.util.List; +import java.util.stream.IntStream; public interface AllowedNumberInputs extends AllowedInputs { @@ -22,6 +24,15 @@ public boolean isAllowed(@Nullable Integer input) { return false; return isInRange(input); } + + @Override + public @NotNull List getSuggestions(@NotNull CommandSender sender, @NotNull List input, @NotNull String current) { + if (to - from < 5) + return IntStream.rangeClosed(from, to).boxed().toList(); + + int fourth = (to - from) / 4; + return List.of(from, from + fourth, from + fourth * 2, from + fourth * 3, to); + } } record Unlimited() implements AllowedIntegerInputs { @@ -30,6 +41,23 @@ record Unlimited() implements AllowedIntegerInputs { public boolean isAllowed(@Nullable Integer input) { return true; } + + @Override + public @NotNull List getSuggestions(@NotNull CommandSender sender, @NotNull List input, @NotNull String current) { + return List.of( + -100000, + -50000, + -3000, + -200, + -50, + 0, + 50, + 200, + 3000, + 50000, + 100000 + ); + } } record SingleValue(int value) implements AllowedIntegerInputs { @@ -38,6 +66,11 @@ record SingleValue(int value) implements AllowedIntegerInputs { public boolean isAllowed(@Nullable Integer input) { return input != null && input.compareTo(value) == 0; } + + @Override + public @NotNull List getSuggestions(@NotNull CommandSender sender, @NotNull List input, @NotNull String current) { + return List.of(value); + } } record ValuesList(@NotNull List values) implements AllowedIntegerInputs { @@ -53,6 +86,21 @@ public boolean isAllowed(@Nullable Integer input) { return false; } + + @Override + public @NotNull List getSuggestions(@NotNull CommandSender sender, @NotNull List input, @NotNull String current) { + if (values.size() < 5) + return values; + + int fourth = values.size() / 4; + return List.of( + values.get(0), + values.get(fourth), + values.get(fourth * 2), + values.get(fourth * 3), + values.get(values.size() - 1) + ); + } } record Positive() implements AllowedIntegerInputs, RangedAllowedInputs { @@ -78,6 +126,18 @@ public boolean isAllowed(@Nullable Integer input) { return false; return isInRange(input); } + + @Override + public @NotNull List getSuggestions(@NotNull CommandSender sender, @NotNull List input, @NotNull String current) { + return List.of( + 0, + 50, + 200, + 3000, + 50000, + 100000 + ); + } } record Negative() implements AllowedIntegerInputs, RangedAllowedInputs { @@ -103,6 +163,18 @@ public boolean isAllowed(@Nullable Integer input) { return false; return isInRange(input); } + + @Override + public @NotNull List getSuggestions(@NotNull CommandSender sender, @NotNull List input, @NotNull String current) { + return List.of( + -100000, + -50000, + -3000, + -200, + -50, + -1 + ); + } } } } diff --git a/commands/src/main/java/com/wizardlybump17/wlib/command/rework/node/CommandNode.java b/commands/src/main/java/com/wizardlybump17/wlib/command/rework/node/CommandNode.java index 6eba44e9..74a5d984 100644 --- a/commands/src/main/java/com/wizardlybump17/wlib/command/rework/node/CommandNode.java +++ b/commands/src/main/java/com/wizardlybump17/wlib/command/rework/node/CommandNode.java @@ -81,7 +81,7 @@ public final boolean isValidInput(@Nullable T input) { } public @NotNull List getSuggestions(@NotNull CommandSender sender, @NotNull List args, @NotNull String currentInput) { - return List.of(); + return allowedInputs.getSuggestions(sender, args, currentInput); } public @Nullable CommandNodeExecutor getExecutor() { diff --git a/commands/src/main/java/com/wizardlybump17/wlib/command/rework/node/IntegerCommandNode.java b/commands/src/main/java/com/wizardlybump17/wlib/command/rework/node/IntegerCommandNode.java index 3b7d084c..77940deb 100644 --- a/commands/src/main/java/com/wizardlybump17/wlib/command/rework/node/IntegerCommandNode.java +++ b/commands/src/main/java/com/wizardlybump17/wlib/command/rework/node/IntegerCommandNode.java @@ -3,13 +3,10 @@ import com.wizardlybump17.wlib.command.rework.exception.InputParsingException; import com.wizardlybump17.wlib.command.rework.executor.CommandNodeExecutor; import com.wizardlybump17.wlib.command.rework.input.AllowedNumberInputs; -import com.wizardlybump17.wlib.command.rework.input.RangedAllowedInputs; -import com.wizardlybump17.wlib.command.sender.CommandSender; import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.Nullable; import java.util.List; -import java.util.stream.IntStream; public class IntegerCommandNode extends CommandNode { @@ -59,38 +56,6 @@ public IntegerCommandNode(@NotNull String name, @NotNull AllowedNumberInputs.All } } - @Override - public @NotNull List getSuggestions(@NotNull CommandSender sender, @NotNull List args, @NotNull String currentInput) { - return switch (getAllowedInputs()) { - case RangedAllowedInputs ranged -> { - int from = (int) ranged.from(); - int to = (int) ranged.to(); - - if (to - from < 5) - yield IntStream.rangeClosed(from, to).boxed().toList(); - - int fourth = (to - from) / 4; - yield List.of(from, from + fourth, from + fourth * 2, from + fourth * 3, to); - } - case AllowedNumberInputs.AllowedIntegerInputs.SingleValue singleValue -> List.of(singleValue.value()); - case AllowedNumberInputs.AllowedIntegerInputs.ValuesList valuesList -> { - List list = valuesList.values(); - if (list.size() < 5) - yield list; - - int fourth = list.size() / 4; - yield List.of( - list.get(0), - list.get(fourth), - list.get(fourth * 2), - list.get(fourth * 3), - list.get(list.size() - 1) - ); - } - default -> List.of(-100, -10, 0, 10, 100); - }; - } - @Override public @NotNull IntegerCommandNode withChildren(@NotNull List> children) { return new IntegerCommandNode(getName(), children, getAllowedInputs(), getExecutor(), getPermission()); diff --git a/commands/src/test/java/com/wizardlybump17/wlib/command/test/rework/CommandManagerTests.java b/commands/src/test/java/com/wizardlybump17/wlib/command/test/rework/CommandManagerTests.java index c4de7d48..229fef78 100644 --- a/commands/src/test/java/com/wizardlybump17/wlib/command/test/rework/CommandManagerTests.java +++ b/commands/src/test/java/com/wizardlybump17/wlib/command/test/rework/CommandManagerTests.java @@ -517,7 +517,7 @@ void testSuggestionsListChad4() { manager.registerCommand("test", command1); manager.registerCommand("test", command2); - List expected = List.of(0, 536870911, 1073741822, 1610612733, 2147483647); + List expected = List.of(0, 50, 200, 3000, 50000, 100000); List actual = manager.getSuggestions(CHAD_SENDER, List.of("welcome", "")); Assertions.assertTrue(CollectionUtil.contentEquals(expected, actual)); @@ -559,7 +559,7 @@ void testSuggestionsListChad6() { manager.registerCommand("test", command1); manager.registerCommand("test", command2); - List expected = List.of(0, 536870911, 1073741822, 1610612733, 2147483647); + List expected = List.of(0, 50, 200, 3000, 50000, 100000); List actual = manager.getSuggestions(CHAD_SENDER, List.of("welcome", "10")); Assertions.assertTrue(CollectionUtil.contentEquals(expected, actual)); From 430729238fc9170cdd36b72c706b163771f2da00 Mon Sep 17 00:00:00 2001 From: WizardlyBump17 Date: Fri, 31 Oct 2025 22:12:49 -0300 Subject: [PATCH 087/363] renamed --- .../command/test/rework/CommandManagerTests.java | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/commands/src/test/java/com/wizardlybump17/wlib/command/test/rework/CommandManagerTests.java b/commands/src/test/java/com/wizardlybump17/wlib/command/test/rework/CommandManagerTests.java index 229fef78..00a589b8 100644 --- a/commands/src/test/java/com/wizardlybump17/wlib/command/test/rework/CommandManagerTests.java +++ b/commands/src/test/java/com/wizardlybump17/wlib/command/test/rework/CommandManagerTests.java @@ -342,7 +342,7 @@ void testSuccess1() { } @Test - void testSuggestionsListChad0() { + void testSuggestionsSuccessListChad0() { Command command0 = new Command(new LiteralCommandNode( "hello", context -> CommandResult.successful(context, "hello") @@ -377,7 +377,7 @@ void testSuggestionsListChad0() { } @Test - void testSuggestionsListChad1() { + void testSuggestionsSuccessListChad1() { Command command0 = new Command(new LiteralCommandNode( "hello", context -> CommandResult.successful(context, "hello") @@ -412,7 +412,7 @@ void testSuggestionsListChad1() { } @Test - void testSuggestionsListChad2() { + void testSuggestionsSuccessListChad2() { Command command0 = new Command(new LiteralCommandNode( "hello", context -> CommandResult.successful(context, "hello") @@ -447,7 +447,7 @@ void testSuggestionsListChad2() { } @Test - void testSuggestionsListChad3() { + void testSuggestionsSuccessListChad3() { Command command0 = new Command(new LiteralCommandNode( "hello", context -> CommandResult.successful(context, "hello") @@ -482,7 +482,7 @@ void testSuggestionsListChad3() { } @Test - void testSuggestionsListChad4() { + void testSuggestionsSuccessListChad4() { Command command0 = new Command(new LiteralCommandNode( "hello", context -> CommandResult.successful(context, "hello") @@ -524,7 +524,7 @@ void testSuggestionsListChad4() { } @Test - void testSuggestionsListChad6() { + void testSuggestionsSuccessListChad6() { Command command0 = new Command(new LiteralCommandNode( "hello", context -> CommandResult.successful(context, "hello") From 3a90ee52de2d3a2e3307dc70b40e523883b8823c Mon Sep 17 00:00:00 2001 From: WizardlyBump17 Date: Fri, 31 Oct 2025 22:19:10 -0300 Subject: [PATCH 088/363] added permissions --- .../test/rework/CommandManagerTests.java | 194 ++++++++++++------ 1 file changed, 128 insertions(+), 66 deletions(-) diff --git a/commands/src/test/java/com/wizardlybump17/wlib/command/test/rework/CommandManagerTests.java b/commands/src/test/java/com/wizardlybump17/wlib/command/test/rework/CommandManagerTests.java index 00a589b8..731ab05c 100644 --- a/commands/src/test/java/com/wizardlybump17/wlib/command/test/rework/CommandManagerTests.java +++ b/commands/src/test/java/com/wizardlybump17/wlib/command/test/rework/CommandManagerTests.java @@ -28,10 +28,10 @@ class CommandManagerTests { @Test void testRegisterDifferent() { - Command command0 = new Command(new LiteralCommandNode("hello0", context -> CommandResult.successful(context, "hello0"))); - Command command1 = new Command(new LiteralCommandNode("hello1", context -> CommandResult.successful(context, "hello1"))); - Command command2 = new Command(new LiteralCommandNode("hello2", context -> CommandResult.successful(context, "hello2"))); - Command command3 = new Command(new LiteralCommandNode("hello3", context -> CommandResult.successful(context, "hello3"))); + Command command0 = new Command(new LiteralCommandNode("hello0", context -> CommandResult.successful(context, "hello0"), "permission")); + Command command1 = new Command(new LiteralCommandNode("hello1", context -> CommandResult.successful(context, "hello1"), "permission")); + Command command2 = new Command(new LiteralCommandNode("hello2", context -> CommandResult.successful(context, "hello2"), "permission")); + Command command3 = new Command(new LiteralCommandNode("hello3", context -> CommandResult.successful(context, "hello3"), "permission")); CommandManager manager = new CommandManager(); @@ -55,7 +55,8 @@ void testRegisterMerging0() { Command command0 = new Command( new LiteralCommandNode( "hello", - helloExecutor + helloExecutor, + "permission" ) ); Command command1 = new Command( @@ -64,9 +65,11 @@ void testRegisterMerging0() { List.of( new LiteralCommandNode( "world", - helloWorldExecutor + helloWorldExecutor, + "permission" ) - ) + ), + "permission" ) ); Command command2 = new Command( @@ -78,11 +81,14 @@ void testRegisterMerging0() { List.of( new LiteralCommandNode( "hi", - helloWorldHiExecutor + helloWorldHiExecutor, + "permission" ) - ) + ), + "permission" ) - ) + ), + "permission" ) ); @@ -95,7 +101,8 @@ void testRegisterMerging0() { Command expectedCommand0 = new Command( new LiteralCommandNode( "hello", - helloExecutor + helloExecutor, + "permission" ) ); Command expectedCommand1 = new Command( @@ -104,10 +111,12 @@ void testRegisterMerging0() { List.of( new LiteralCommandNode( "world", - helloWorldExecutor + helloWorldExecutor, + "permission" ) ), - helloExecutor + helloExecutor, + "permission" ) ); Command expectedCommand2 = new Command( @@ -119,13 +128,16 @@ void testRegisterMerging0() { List.of( new LiteralCommandNode( "hi", - helloWorldHiExecutor + helloWorldHiExecutor, + "permission" ) ), - helloWorldExecutor + helloWorldExecutor, + "permission" ) ), - helloExecutor + helloExecutor, + "permission" ) ); @@ -144,7 +156,8 @@ void testRegisterMerging1() { Command command0 = new Command( new LiteralCommandNode( "hello", - helloExecutor + helloExecutor, + "permission" ) ); Command command1 = new Command( @@ -153,13 +166,16 @@ void testRegisterMerging1() { List.of( new LiteralCommandNode( "world", - helloWorldExecutor + helloWorldExecutor, + "permission" ), new LiteralCommandNode( "there", - helloThereExecutor + helloThereExecutor, + "permission" ) - ) + ), + "permission" ) ); Command command2 = new Command( @@ -171,11 +187,14 @@ void testRegisterMerging1() { List.of( new LiteralCommandNode( "hi", - helloWorldHiExecutor + helloWorldHiExecutor, + "permission" ) - ) + ), + "permission" ) - ) + ), + "permission" ) ); @@ -188,7 +207,8 @@ void testRegisterMerging1() { Command expectedCommand0 = new Command( new LiteralCommandNode( "hello", - helloExecutor + helloExecutor, + "permission" ) ); Command expectedCommand1 = new Command( @@ -197,14 +217,17 @@ void testRegisterMerging1() { List.of( new LiteralCommandNode( "world", - helloWorldExecutor + helloWorldExecutor, + "permission" ), new LiteralCommandNode( "there", - helloThereExecutor + helloThereExecutor, + "permission" ) ), - helloExecutor + helloExecutor, + "permission" ) ); Command expectedCommand2 = new Command( @@ -216,17 +239,21 @@ void testRegisterMerging1() { List.of( new LiteralCommandNode( "hi", - helloWorldHiExecutor + helloWorldHiExecutor, + "permission" ) ), - helloWorldExecutor + helloWorldExecutor, + "permission" ), new LiteralCommandNode( "there", - helloThereExecutor + helloThereExecutor, + "permission" ) ), - helloExecutor + helloExecutor, + "permission" ) ); @@ -240,7 +267,8 @@ void testCommandNotFound0() { Command command = new Command( new LiteralCommandNode( "hello", - context -> CommandResult.successful(context, "hello") + context -> CommandResult.successful(context, "hello"), + "permission" ) ); @@ -258,7 +286,8 @@ void testCommandNotFound1() { Command command = new Command( new LiteralCommandNode( "hello", - context -> CommandResult.successful(context, "hello") + context -> CommandResult.successful(context, "hello"), + "permission" ) ); @@ -275,20 +304,23 @@ void testCommandNotFound1() { void testSuccess0() { LiteralCommandNode helloNode = new LiteralCommandNode( "hello", - context -> CommandResult.successful(context, "hello") + context -> CommandResult.successful(context, "hello"), + "permission" ); Command command0 = new Command(helloNode); Command command1 = new Command( new LiteralCommandNode( "hi", - context -> CommandResult.successful(context, "hi") + context -> CommandResult.successful(context, "hi"), + "permission" ) ); Command command2 = new Command( new LiteralCommandNode( "welcome", - context -> CommandResult.successful(context, "welcome") + context -> CommandResult.successful(context, "welcome"), + "permission" ) ); @@ -307,26 +339,30 @@ void testSuccess0() { void testSuccess1() { Command command0 = new Command(new LiteralCommandNode( "hello", - context -> CommandResult.successful(context, "hello") + context -> CommandResult.successful(context, "hello"), + "permission" )); LiteralCommandNode thereNode = new LiteralCommandNode( "there", - context -> CommandResult.successful(context, "hi there") + context -> CommandResult.successful(context, "hi there"), + "permission" ); Command command1 = new Command( new LiteralCommandNode( "hi", List.of( thereNode - ) + ), + "permission" ) ); Command command2 = new Command( new LiteralCommandNode( "welcome", - context -> CommandResult.successful(context, "welcome") + context -> CommandResult.successful(context, "welcome"), + "permission" ) ); @@ -345,7 +381,8 @@ void testSuccess1() { void testSuggestionsSuccessListChad0() { Command command0 = new Command(new LiteralCommandNode( "hello", - context -> CommandResult.successful(context, "hello") + context -> CommandResult.successful(context, "hello"), + "permission" )); Command command1 = new Command( new LiteralCommandNode( @@ -353,15 +390,18 @@ void testSuggestionsSuccessListChad0() { List.of( new LiteralCommandNode( "there", - context -> CommandResult.successful(context, "hi there") + context -> CommandResult.successful(context, "hi there"), + "permission" ) - ) + ), + "permission" ) ); Command command2 = new Command( new LiteralCommandNode( "welcome", - context -> CommandResult.successful(context, "welcome") + context -> CommandResult.successful(context, "welcome"), + "permission" ) ); @@ -380,7 +420,8 @@ void testSuggestionsSuccessListChad0() { void testSuggestionsSuccessListChad1() { Command command0 = new Command(new LiteralCommandNode( "hello", - context -> CommandResult.successful(context, "hello") + context -> CommandResult.successful(context, "hello"), + "permission" )); Command command1 = new Command( new LiteralCommandNode( @@ -388,15 +429,18 @@ void testSuggestionsSuccessListChad1() { List.of( new LiteralCommandNode( "there", - context -> CommandResult.successful(context, "hi there") + context -> CommandResult.successful(context, "hi there"), + "permission" ) - ) + ), + "permission" ) ); Command command2 = new Command( new LiteralCommandNode( "welcome", - context -> CommandResult.successful(context, "welcome") + context -> CommandResult.successful(context, "welcome"), + "permission" ) ); @@ -415,7 +459,8 @@ void testSuggestionsSuccessListChad1() { void testSuggestionsSuccessListChad2() { Command command0 = new Command(new LiteralCommandNode( "hello", - context -> CommandResult.successful(context, "hello") + context -> CommandResult.successful(context, "hello"), + "permission" )); Command command1 = new Command( new LiteralCommandNode( @@ -423,15 +468,18 @@ void testSuggestionsSuccessListChad2() { List.of( new LiteralCommandNode( "there", - context -> CommandResult.successful(context, "hi there") + context -> CommandResult.successful(context, "hi there"), + "permission" ) - ) + ), + "permission" ) ); Command command2 = new Command( new LiteralCommandNode( "welcome", - context -> CommandResult.successful(context, "welcome") + context -> CommandResult.successful(context, "welcome"), + "permission" ) ); @@ -450,7 +498,8 @@ void testSuggestionsSuccessListChad2() { void testSuggestionsSuccessListChad3() { Command command0 = new Command(new LiteralCommandNode( "hello", - context -> CommandResult.successful(context, "hello") + context -> CommandResult.successful(context, "hello"), + "permission" )); Command command1 = new Command( new LiteralCommandNode( @@ -458,15 +507,18 @@ void testSuggestionsSuccessListChad3() { List.of( new LiteralCommandNode( "there", - context -> CommandResult.successful(context, "hi there") + context -> CommandResult.successful(context, "hi there"), + "permission" ) - ) + ), + "permission" ) ); Command command2 = new Command( new LiteralCommandNode( "welcome", - context -> CommandResult.successful(context, "welcome") + context -> CommandResult.successful(context, "welcome"), + "permission" ) ); @@ -485,7 +537,8 @@ void testSuggestionsSuccessListChad3() { void testSuggestionsSuccessListChad4() { Command command0 = new Command(new LiteralCommandNode( "hello", - context -> CommandResult.successful(context, "hello") + context -> CommandResult.successful(context, "hello"), + "permission" )); Command command1 = new Command( new LiteralCommandNode( @@ -493,9 +546,11 @@ void testSuggestionsSuccessListChad4() { List.of( new LiteralCommandNode( "there", - context -> CommandResult.successful(context, "hi there") + context -> CommandResult.successful(context, "hi there"), + "permission" ) - ) + ), + "permission" ) ); Command command2 = new Command( @@ -505,10 +560,12 @@ void testSuggestionsSuccessListChad4() { new IntegerCommandNode( "repeat", new AllowedNumberInputs.AllowedIntegerInputs.Positive(), - context -> CommandResult.successful(context, "welcome".repeat(context.arguments().getArgument("repeat").orElseThrow().data())) + context -> CommandResult.successful(context, "welcome".repeat(context.arguments().getArgument("repeat").orElseThrow().data())), + "permission" ) ), - context -> CommandResult.successful(context, "welcome") + context -> CommandResult.successful(context, "welcome"), + "permission" ) ); @@ -527,7 +584,8 @@ void testSuggestionsSuccessListChad4() { void testSuggestionsSuccessListChad6() { Command command0 = new Command(new LiteralCommandNode( "hello", - context -> CommandResult.successful(context, "hello") + context -> CommandResult.successful(context, "hello"), + "permission" )); Command command1 = new Command( new LiteralCommandNode( @@ -535,9 +593,11 @@ void testSuggestionsSuccessListChad6() { List.of( new LiteralCommandNode( "there", - context -> CommandResult.successful(context, "hi there") + context -> CommandResult.successful(context, "hi there"), + "permission" ) - ) + ), + "permission" ) ); Command command2 = new Command( @@ -547,10 +607,12 @@ void testSuggestionsSuccessListChad6() { new IntegerCommandNode( "repeat", new AllowedNumberInputs.AllowedIntegerInputs.Positive(), - context -> CommandResult.successful(context, "welcome".repeat(context.arguments().getArgument("repeat").orElseThrow().data())) + context -> CommandResult.successful(context, "welcome".repeat(context.arguments().getArgument("repeat").orElseThrow().data())), + "permission" ) ), - context -> CommandResult.successful(context, "welcome") + context -> CommandResult.successful(context, "welcome"), + "permission" ) ); From f633c7dff78cdbc25468d2e3bb99e6f898161d96 Mon Sep 17 00:00:00 2001 From: WizardlyBump17 Date: Sun, 2 Nov 2025 22:57:09 -0300 Subject: [PATCH 089/363] testing the beta sender --- .../test/rework/CommandManagerTests.java | 39 +++++++++++++++++++ 1 file changed, 39 insertions(+) diff --git a/commands/src/test/java/com/wizardlybump17/wlib/command/test/rework/CommandManagerTests.java b/commands/src/test/java/com/wizardlybump17/wlib/command/test/rework/CommandManagerTests.java index 731ab05c..d1dba42d 100644 --- a/commands/src/test/java/com/wizardlybump17/wlib/command/test/rework/CommandManagerTests.java +++ b/commands/src/test/java/com/wizardlybump17/wlib/command/test/rework/CommandManagerTests.java @@ -626,4 +626,43 @@ void testSuggestionsSuccessListChad6() { Assertions.assertTrue(CollectionUtil.contentEquals(expected, actual)); } + + @Test + void testSuggestionsFailListBeta0() { + Command command0 = new Command(new LiteralCommandNode( + "hello", + context -> CommandResult.successful(context, "hello"), + "permission" + )); + Command command1 = new Command( + new LiteralCommandNode( + "hi", + List.of( + new LiteralCommandNode( + "there", + context -> CommandResult.successful(context, "hi there"), + "permission" + ) + ), + "permission" + ) + ); + Command command2 = new Command( + new LiteralCommandNode( + "welcome", + context -> CommandResult.successful(context, "welcome"), + "permission" + ) + ); + + CommandManager manager = new CommandManager(); + manager.registerCommand("test", command0); + manager.registerCommand("test", command1); + manager.registerCommand("test", command2); + + List expected = List.of(); + List actual = manager.getSuggestions(BETA_SENDER, List.of()); + + Assertions.assertTrue(CollectionUtil.contentEquals(expected, actual)); + } } From a8767bebaecb01a0cac2bf59be473b2b3bfd4c72 Mon Sep 17 00:00:00 2001 From: WizardlyBump17 Date: Mon, 3 Nov 2025 00:06:54 -0300 Subject: [PATCH 090/363] testing the CommandManager#getSuggestions(CommandSender, String) method for successful outputs --- .../test/rework/CommandManagerTests.java | 202 ++++++++++++++++++ 1 file changed, 202 insertions(+) diff --git a/commands/src/test/java/com/wizardlybump17/wlib/command/test/rework/CommandManagerTests.java b/commands/src/test/java/com/wizardlybump17/wlib/command/test/rework/CommandManagerTests.java index d1dba42d..ffda68a3 100644 --- a/commands/src/test/java/com/wizardlybump17/wlib/command/test/rework/CommandManagerTests.java +++ b/commands/src/test/java/com/wizardlybump17/wlib/command/test/rework/CommandManagerTests.java @@ -665,4 +665,206 @@ void testSuggestionsFailListBeta0() { Assertions.assertTrue(CollectionUtil.contentEquals(expected, actual)); } + + @Test + void testSuggestionsSuccessStringChad0() { + Command command0 = new Command(new LiteralCommandNode( + "hello", + context -> CommandResult.successful(context, "hello"), + "permission" + )); + Command command1 = new Command( + new LiteralCommandNode( + "hi", + List.of( + new LiteralCommandNode( + "there", + context -> CommandResult.successful(context, "hi there"), + "permission" + ) + ), + "permission" + ) + ); + Command command2 = new Command( + new LiteralCommandNode( + "welcome", + List.of( + new IntegerCommandNode( + "repeat", + new AllowedNumberInputs.AllowedIntegerInputs.Positive(), + context -> CommandResult.successful(context, "welcome".repeat(context.arguments().getArgument("repeat").orElseThrow().data())), + "permission" + ) + ), + context -> CommandResult.successful(context, "welcome"), + "permission" + ) + ); + + CommandManager manager = new CommandManager(); + manager.registerCommand("test", command0); + manager.registerCommand("test", command1); + manager.registerCommand("test", command2); + + List expected = List.of("hi", "hello", "welcome"); + List actual = manager.getSuggestions(CHAD_SENDER, ""); + + Assertions.assertEquals(expected, actual); + } + + @Test + void testSuggestionsSuccessStringChad1() { + Command command0 = new Command(new LiteralCommandNode( + "hello", + context -> CommandResult.successful(context, "hello"), + "permission" + )); + Command command1 = new Command( + new LiteralCommandNode( + "hi", + List.of( + new LiteralCommandNode( + "there", + context -> CommandResult.successful(context, "hi there"), + "permission" + ) + ), + "permission" + ) + ); + Command command2 = new Command( + new LiteralCommandNode( + "welcome", + List.of( + new IntegerCommandNode( + "repeat", + new AllowedNumberInputs.AllowedIntegerInputs.Positive(), + context -> CommandResult.successful(context, "welcome".repeat(context.arguments().getArgument("repeat").orElseThrow().data())), + "permission" + ) + ), + context -> CommandResult.successful(context, "welcome"), + "permission" + ) + ); + + CommandManager manager = new CommandManager(); + manager.registerCommand("test", command0); + manager.registerCommand("test", command1); + manager.registerCommand("test", command2); + + List expected = List.of("there"); + List actual = manager.getSuggestions(CHAD_SENDER, "hi t"); + + Assertions.assertEquals(expected, actual); + } + + @Test + void testSuggestionsSuccessStringChad2() { + Command command0 = new Command(new LiteralCommandNode( + "hello", + context -> CommandResult.successful(context, "hello"), + "permission" + )); + Command command1 = new Command( + new LiteralCommandNode( + "hi", + List.of( + new LiteralCommandNode( + "there", + context -> CommandResult.successful(context, "hi there"), + "permission" + ) + ), + "permission" + ) + ); + Command command2 = new Command( + new LiteralCommandNode( + "welcome", + List.of( + new IntegerCommandNode( + "repeat", + new AllowedNumberInputs.AllowedIntegerInputs.Positive(), + context -> CommandResult.successful(context, "welcome".repeat(context.arguments().getArgument("repeat").orElseThrow().data())), + "permission" + ) + ), + context -> CommandResult.successful(context, "welcome"), + "permission" + ) + ); + + CommandManager manager = new CommandManager(); + manager.registerCommand("test", command0); + manager.registerCommand("test", command1); + manager.registerCommand("test", command2); + + List expected = List.of(0, 50, 200, 3000, 50000, 100000); + List actual = manager.getSuggestions(CHAD_SENDER, "welcome 1"); + + Assertions.assertEquals(expected, actual); + } + + @Test + void testSuggestionsSuccessStringChad3() { + Command command0 = new Command(new LiteralCommandNode( + "hello", + context -> CommandResult.successful(context, "hello"), + "permission" + )); + Command command1 = new Command( + new LiteralCommandNode( + "hi", + List.of( + new LiteralCommandNode( + "there", + context -> CommandResult.successful(context, "hi there"), + "permission" + ) + ), + "permission" + ) + ); + Command command2 = new Command( + new LiteralCommandNode( + "welcome", + List.of( + new IntegerCommandNode( + "repeat", + new AllowedNumberInputs.AllowedIntegerInputs.Positive(), + context -> CommandResult.successful(context, "welcome".repeat(context.arguments().getArgument("repeat").orElseThrow().data())), + "permission" + ) + ), + context -> CommandResult.successful(context, "welcome"), + "permission" + ) + ); + Command command3 = new Command( + new LiteralCommandNode( + "test", + List.of( + new LiteralCommandNode( + "spaced string", + context -> CommandResult.successful(context, "spaced string"), + "permission" + ) + ), + "permission" + ) + ); + + CommandManager manager = new CommandManager(); + manager.registerCommand("test", command0); + manager.registerCommand("test", command1); + manager.registerCommand("test", command2); + manager.registerCommand("test", command3); + + List expected = List.of("spaced string"); + List actual = manager.getSuggestions(CHAD_SENDER, "test \"spaced "); + + Assertions.assertEquals(expected, actual); + } } From 8824d72f51e2833fbaa806100107ee00161d4b14 Mon Sep 17 00:00:00 2001 From: WizardlyBump17 Date: Mon, 3 Nov 2025 00:08:31 -0300 Subject: [PATCH 091/363] added the CommandNodeArguments#getArgumentData(String) method --- .../wlib/command/rework/context/CommandContext.java | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/commands/src/main/java/com/wizardlybump17/wlib/command/rework/context/CommandContext.java b/commands/src/main/java/com/wizardlybump17/wlib/command/rework/context/CommandContext.java index 0f1ac2a4..6ce27053 100644 --- a/commands/src/main/java/com/wizardlybump17/wlib/command/rework/context/CommandContext.java +++ b/commands/src/main/java/com/wizardlybump17/wlib/command/rework/context/CommandContext.java @@ -36,6 +36,11 @@ public boolean hasArgument(@NotNull String key) { return Optional.ofNullable((CommandNodeArgument) arguments.get(key)); } + @SuppressWarnings("unchecked") + public @NotNull Optional getArgumentData(@NotNull String key) { + return (Optional) getArgument(key).map(CommandNodeArgument::data); + } + public @NotNull @Unmodifiable Map> getArguments() { return Collections.unmodifiableMap(arguments); } From 779d8cc827b664bc367192c50ca8d32b976f0c31 Mon Sep 17 00:00:00 2001 From: WizardlyBump17 Date: Mon, 3 Nov 2025 00:08:43 -0300 Subject: [PATCH 092/363] removed the reminder comment --- .../wlib/command/rework/context/CommandContext.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/commands/src/main/java/com/wizardlybump17/wlib/command/rework/context/CommandContext.java b/commands/src/main/java/com/wizardlybump17/wlib/command/rework/context/CommandContext.java index 6ce27053..cfb11432 100644 --- a/commands/src/main/java/com/wizardlybump17/wlib/command/rework/context/CommandContext.java +++ b/commands/src/main/java/com/wizardlybump17/wlib/command/rework/context/CommandContext.java @@ -20,7 +20,7 @@ public static final class CommandNodeArguments { private final @NotNull LinkedHashMap> arguments; private CommandNodeArguments(@NotNull LinkedHashMap> arguments) { - this.arguments = arguments; //CommandResult and ParseResult + this.arguments = arguments; } public CommandNodeArguments(@NotNull List> arguments) { From 571592f5da1c5898dba3c6ea3bf1410b96b447ae Mon Sep 17 00:00:00 2001 From: WizardlyBump17 Date: Fri, 7 Nov 2025 16:01:45 -0300 Subject: [PATCH 093/363] moved to a better package --- .../CommandManagerSuggestionTests.java} | 358 +---------------- .../rework/manager/CommandManagerTests.java | 376 ++++++++++++++++++ 2 files changed, 378 insertions(+), 356 deletions(-) rename commands/src/test/java/com/wizardlybump17/wlib/command/test/rework/{CommandManagerTests.java => manager/CommandManagerSuggestionTests.java} (59%) create mode 100644 commands/src/test/java/com/wizardlybump17/wlib/command/test/rework/manager/CommandManagerTests.java diff --git a/commands/src/test/java/com/wizardlybump17/wlib/command/test/rework/CommandManagerTests.java b/commands/src/test/java/com/wizardlybump17/wlib/command/test/rework/manager/CommandManagerSuggestionTests.java similarity index 59% rename from commands/src/test/java/com/wizardlybump17/wlib/command/test/rework/CommandManagerTests.java rename to commands/src/test/java/com/wizardlybump17/wlib/command/test/rework/manager/CommandManagerSuggestionTests.java index ffda68a3..2f1d69f7 100644 --- a/commands/src/test/java/com/wizardlybump17/wlib/command/test/rework/CommandManagerTests.java +++ b/commands/src/test/java/com/wizardlybump17/wlib/command/test/rework/manager/CommandManagerSuggestionTests.java @@ -1,14 +1,11 @@ -package com.wizardlybump17.wlib.command.test.rework; +package com.wizardlybump17.wlib.command.test.rework.manager; import com.wizardlybump17.wlib.command.rework.Command; -import com.wizardlybump17.wlib.command.rework.executor.CommandNodeExecutor; import com.wizardlybump17.wlib.command.rework.input.AllowedNumberInputs; import com.wizardlybump17.wlib.command.rework.manager.CommandManager; import com.wizardlybump17.wlib.command.rework.node.IntegerCommandNode; import com.wizardlybump17.wlib.command.rework.node.LiteralCommandNode; import com.wizardlybump17.wlib.command.rework.result.CommandResult; -import com.wizardlybump17.wlib.command.rework.result.SuccessResult; -import com.wizardlybump17.wlib.command.rework.result.error.CommandNotFoundResult; import com.wizardlybump17.wlib.command.sender.BasicCommandSender; import com.wizardlybump17.wlib.command.sender.CommandSender; import com.wizardlybump17.wlib.util.CollectionUtil; @@ -20,363 +17,12 @@ import java.util.UUID; import java.util.function.Consumer; -class CommandManagerTests { +class CommandManagerSuggestionTests { static final @NotNull Consumer SENDER_MESSAGE_CONSUMER = System.out::println; static final @NotNull CommandSender CHAD_SENDER = new BasicCommandSender<>(new Object(), "Chad", UUID.nameUUIDFromBytes("Chad".getBytes()), SENDER_MESSAGE_CONSUMER, $ -> true); static final @NotNull CommandSender BETA_SENDER = new BasicCommandSender<>(new Object(), "Beta", UUID.nameUUIDFromBytes("Beta".getBytes()), SENDER_MESSAGE_CONSUMER, $ -> false); - @Test - void testRegisterDifferent() { - Command command0 = new Command(new LiteralCommandNode("hello0", context -> CommandResult.successful(context, "hello0"), "permission")); - Command command1 = new Command(new LiteralCommandNode("hello1", context -> CommandResult.successful(context, "hello1"), "permission")); - Command command2 = new Command(new LiteralCommandNode("hello2", context -> CommandResult.successful(context, "hello2"), "permission")); - Command command3 = new Command(new LiteralCommandNode("hello3", context -> CommandResult.successful(context, "hello3"), "permission")); - - CommandManager manager = new CommandManager(); - - Command registeredCommand0 = manager.registerCommand("test", command0); - Command registeredCommand1 = manager.registerCommand("test", command1); - Command registeredCommand2 = manager.registerCommand("test", command2); - Command registeredCommand3 = manager.registerCommand("test", command3); - - Assertions.assertEquals(command0, registeredCommand0); - Assertions.assertEquals(command1, registeredCommand1); - Assertions.assertEquals(command2, registeredCommand2); - Assertions.assertEquals(command3, registeredCommand3); - } - - @Test - void testRegisterMerging0() { - CommandNodeExecutor helloExecutor = context -> CommandResult.successful(context, "hello"); - CommandNodeExecutor helloWorldExecutor = context -> CommandResult.successful(context, "hello world"); - CommandNodeExecutor helloWorldHiExecutor = context -> CommandResult.successful(context, "hello world hi"); - - Command command0 = new Command( - new LiteralCommandNode( - "hello", - helloExecutor, - "permission" - ) - ); - Command command1 = new Command( - new LiteralCommandNode( - "hello", - List.of( - new LiteralCommandNode( - "world", - helloWorldExecutor, - "permission" - ) - ), - "permission" - ) - ); - Command command2 = new Command( - new LiteralCommandNode( - "hello", - List.of( - new LiteralCommandNode( - "world", - List.of( - new LiteralCommandNode( - "hi", - helloWorldHiExecutor, - "permission" - ) - ), - "permission" - ) - ), - "permission" - ) - ); - - CommandManager manager = new CommandManager(); - - Command registeredCommand0 = manager.registerCommand("test", command0); - Command registeredCommand1 = manager.registerCommand("test", command1); - Command registeredCommand2 = manager.registerCommand("test", command2); - - Command expectedCommand0 = new Command( - new LiteralCommandNode( - "hello", - helloExecutor, - "permission" - ) - ); - Command expectedCommand1 = new Command( - new LiteralCommandNode( - "hello", - List.of( - new LiteralCommandNode( - "world", - helloWorldExecutor, - "permission" - ) - ), - helloExecutor, - "permission" - ) - ); - Command expectedCommand2 = new Command( - new LiteralCommandNode( - "hello", - List.of( - new LiteralCommandNode( - "world", - List.of( - new LiteralCommandNode( - "hi", - helloWorldHiExecutor, - "permission" - ) - ), - helloWorldExecutor, - "permission" - ) - ), - helloExecutor, - "permission" - ) - ); - - Assertions.assertEquals(expectedCommand0, registeredCommand0); - Assertions.assertEquals(expectedCommand1, registeredCommand1); - Assertions.assertEquals(expectedCommand2, registeredCommand2); - } - - @Test - void testRegisterMerging1() { - CommandNodeExecutor helloExecutor = context -> CommandResult.successful(context, "hello"); - CommandNodeExecutor helloWorldExecutor = context -> CommandResult.successful(context, "hello world"); - CommandNodeExecutor helloWorldHiExecutor = context -> CommandResult.successful(context, "hello world hi"); - CommandNodeExecutor helloThereExecutor = context -> CommandResult.successful(context, "hello there"); - - Command command0 = new Command( - new LiteralCommandNode( - "hello", - helloExecutor, - "permission" - ) - ); - Command command1 = new Command( - new LiteralCommandNode( - "hello", - List.of( - new LiteralCommandNode( - "world", - helloWorldExecutor, - "permission" - ), - new LiteralCommandNode( - "there", - helloThereExecutor, - "permission" - ) - ), - "permission" - ) - ); - Command command2 = new Command( - new LiteralCommandNode( - "hello", - List.of( - new LiteralCommandNode( - "world", - List.of( - new LiteralCommandNode( - "hi", - helloWorldHiExecutor, - "permission" - ) - ), - "permission" - ) - ), - "permission" - ) - ); - - CommandManager manager = new CommandManager(); - - Command registeredCommand0 = manager.registerCommand("test", command0); - Command registeredCommand1 = manager.registerCommand("test", command1); - Command registeredCommand2 = manager.registerCommand("test", command2); - - Command expectedCommand0 = new Command( - new LiteralCommandNode( - "hello", - helloExecutor, - "permission" - ) - ); - Command expectedCommand1 = new Command( - new LiteralCommandNode( - "hello", - List.of( - new LiteralCommandNode( - "world", - helloWorldExecutor, - "permission" - ), - new LiteralCommandNode( - "there", - helloThereExecutor, - "permission" - ) - ), - helloExecutor, - "permission" - ) - ); - Command expectedCommand2 = new Command( - new LiteralCommandNode( - "hello", - List.of( - new LiteralCommandNode( - "world", - List.of( - new LiteralCommandNode( - "hi", - helloWorldHiExecutor, - "permission" - ) - ), - helloWorldExecutor, - "permission" - ), - new LiteralCommandNode( - "there", - helloThereExecutor, - "permission" - ) - ), - helloExecutor, - "permission" - ) - ); - - Assertions.assertEquals(expectedCommand0, registeredCommand0); - Assertions.assertEquals(expectedCommand1, registeredCommand1); - Assertions.assertEquals(expectedCommand2, registeredCommand2); - } - - @Test - void testCommandNotFound0() { - Command command = new Command( - new LiteralCommandNode( - "hello", - context -> CommandResult.successful(context, "hello"), - "permission" - ) - ); - - CommandManager manager = new CommandManager(); - manager.registerCommand("test", command); - - CommandNotFoundResult expected = CommandResult.commandNotFound("hello0"); - CommandResult actual = manager.execute(CHAD_SENDER, List.of("hello0")); - - Assertions.assertEquals(expected, actual); - } - - @Test - void testCommandNotFound1() { - Command command = new Command( - new LiteralCommandNode( - "hello", - context -> CommandResult.successful(context, "hello"), - "permission" - ) - ); - - CommandManager manager = new CommandManager(); - manager.registerCommand("test", command); - - CommandNotFoundResult expected = CommandResult.commandNotFound(""); - CommandResult actual = manager.execute(CHAD_SENDER, List.of()); - - Assertions.assertEquals(expected, actual); - } - - @Test - void testSuccess0() { - LiteralCommandNode helloNode = new LiteralCommandNode( - "hello", - context -> CommandResult.successful(context, "hello"), - "permission" - ); - Command command0 = new Command(helloNode); - - Command command1 = new Command( - new LiteralCommandNode( - "hi", - context -> CommandResult.successful(context, "hi"), - "permission" - ) - ); - Command command2 = new Command( - new LiteralCommandNode( - "welcome", - context -> CommandResult.successful(context, "welcome"), - "permission" - ) - ); - - CommandManager manager = new CommandManager(); - manager.registerCommand("test", command0); - manager.registerCommand("test", command1); - manager.registerCommand("test", command2); - - SuccessResult expected = CommandResult.successful(0, helloNode, "hello"); - CommandResult actual = manager.execute(CHAD_SENDER, List.of("hello")); - - Assertions.assertEquals(expected, actual); - } - - @Test - void testSuccess1() { - Command command0 = new Command(new LiteralCommandNode( - "hello", - context -> CommandResult.successful(context, "hello"), - "permission" - )); - - LiteralCommandNode thereNode = new LiteralCommandNode( - "there", - context -> CommandResult.successful(context, "hi there"), - "permission" - ); - Command command1 = new Command( - new LiteralCommandNode( - "hi", - List.of( - thereNode - ), - "permission" - ) - ); - - Command command2 = new Command( - new LiteralCommandNode( - "welcome", - context -> CommandResult.successful(context, "welcome"), - "permission" - ) - ); - - CommandManager manager = new CommandManager(); - manager.registerCommand("test", command0); - manager.registerCommand("test", command1); - manager.registerCommand("test", command2); - - SuccessResult expected = CommandResult.successful(1, thereNode, "hi there"); - CommandResult actual = manager.execute(CHAD_SENDER, List.of("hi", "there")); - - Assertions.assertEquals(expected, actual); - } - @Test void testSuggestionsSuccessListChad0() { Command command0 = new Command(new LiteralCommandNode( diff --git a/commands/src/test/java/com/wizardlybump17/wlib/command/test/rework/manager/CommandManagerTests.java b/commands/src/test/java/com/wizardlybump17/wlib/command/test/rework/manager/CommandManagerTests.java new file mode 100644 index 00000000..0a12c41b --- /dev/null +++ b/commands/src/test/java/com/wizardlybump17/wlib/command/test/rework/manager/CommandManagerTests.java @@ -0,0 +1,376 @@ +package com.wizardlybump17.wlib.command.test.rework.manager; + +import com.wizardlybump17.wlib.command.rework.Command; +import com.wizardlybump17.wlib.command.rework.executor.CommandNodeExecutor; +import com.wizardlybump17.wlib.command.rework.manager.CommandManager; +import com.wizardlybump17.wlib.command.rework.node.LiteralCommandNode; +import com.wizardlybump17.wlib.command.rework.result.CommandResult; +import com.wizardlybump17.wlib.command.rework.result.SuccessResult; +import com.wizardlybump17.wlib.command.rework.result.error.CommandNotFoundResult; +import com.wizardlybump17.wlib.command.sender.BasicCommandSender; +import com.wizardlybump17.wlib.command.sender.CommandSender; +import org.jetbrains.annotations.NotNull; +import org.junit.jupiter.api.Assertions; +import org.junit.jupiter.api.Test; + +import java.util.List; +import java.util.UUID; +import java.util.function.Consumer; + +class CommandManagerTests { + + static final @NotNull Consumer SENDER_MESSAGE_CONSUMER = System.out::println; + static final @NotNull CommandSender CHAD_SENDER = new BasicCommandSender<>(new Object(), "Chad", UUID.nameUUIDFromBytes("Chad".getBytes()), SENDER_MESSAGE_CONSUMER, $ -> true); + static final @NotNull CommandSender BETA_SENDER = new BasicCommandSender<>(new Object(), "Beta", UUID.nameUUIDFromBytes("Beta".getBytes()), SENDER_MESSAGE_CONSUMER, $ -> false); + + @Test + void testRegisterDifferent() { + Command command0 = new Command(new LiteralCommandNode("hello0", context -> CommandResult.successful(context, "hello0"), "permission")); + Command command1 = new Command(new LiteralCommandNode("hello1", context -> CommandResult.successful(context, "hello1"), "permission")); + Command command2 = new Command(new LiteralCommandNode("hello2", context -> CommandResult.successful(context, "hello2"), "permission")); + Command command3 = new Command(new LiteralCommandNode("hello3", context -> CommandResult.successful(context, "hello3"), "permission")); + + CommandManager manager = new CommandManager(); + + Command registeredCommand0 = manager.registerCommand("test", command0); + Command registeredCommand1 = manager.registerCommand("test", command1); + Command registeredCommand2 = manager.registerCommand("test", command2); + Command registeredCommand3 = manager.registerCommand("test", command3); + + Assertions.assertEquals(command0, registeredCommand0); + Assertions.assertEquals(command1, registeredCommand1); + Assertions.assertEquals(command2, registeredCommand2); + Assertions.assertEquals(command3, registeredCommand3); + } + + @Test + void testRegisterMerging0() { + CommandNodeExecutor helloExecutor = context -> CommandResult.successful(context, "hello"); + CommandNodeExecutor helloWorldExecutor = context -> CommandResult.successful(context, "hello world"); + CommandNodeExecutor helloWorldHiExecutor = context -> CommandResult.successful(context, "hello world hi"); + + Command command0 = new Command( + new LiteralCommandNode( + "hello", + helloExecutor, + "permission" + ) + ); + Command command1 = new Command( + new LiteralCommandNode( + "hello", + List.of( + new LiteralCommandNode( + "world", + helloWorldExecutor, + "permission" + ) + ), + "permission" + ) + ); + Command command2 = new Command( + new LiteralCommandNode( + "hello", + List.of( + new LiteralCommandNode( + "world", + List.of( + new LiteralCommandNode( + "hi", + helloWorldHiExecutor, + "permission" + ) + ), + "permission" + ) + ), + "permission" + ) + ); + + CommandManager manager = new CommandManager(); + + Command registeredCommand0 = manager.registerCommand("test", command0); + Command registeredCommand1 = manager.registerCommand("test", command1); + Command registeredCommand2 = manager.registerCommand("test", command2); + + Command expectedCommand0 = new Command( + new LiteralCommandNode( + "hello", + helloExecutor, + "permission" + ) + ); + Command expectedCommand1 = new Command( + new LiteralCommandNode( + "hello", + List.of( + new LiteralCommandNode( + "world", + helloWorldExecutor, + "permission" + ) + ), + helloExecutor, + "permission" + ) + ); + Command expectedCommand2 = new Command( + new LiteralCommandNode( + "hello", + List.of( + new LiteralCommandNode( + "world", + List.of( + new LiteralCommandNode( + "hi", + helloWorldHiExecutor, + "permission" + ) + ), + helloWorldExecutor, + "permission" + ) + ), + helloExecutor, + "permission" + ) + ); + + Assertions.assertEquals(expectedCommand0, registeredCommand0); + Assertions.assertEquals(expectedCommand1, registeredCommand1); + Assertions.assertEquals(expectedCommand2, registeredCommand2); + } + + @Test + void testRegisterMerging1() { + CommandNodeExecutor helloExecutor = context -> CommandResult.successful(context, "hello"); + CommandNodeExecutor helloWorldExecutor = context -> CommandResult.successful(context, "hello world"); + CommandNodeExecutor helloWorldHiExecutor = context -> CommandResult.successful(context, "hello world hi"); + CommandNodeExecutor helloThereExecutor = context -> CommandResult.successful(context, "hello there"); + + Command command0 = new Command( + new LiteralCommandNode( + "hello", + helloExecutor, + "permission" + ) + ); + Command command1 = new Command( + new LiteralCommandNode( + "hello", + List.of( + new LiteralCommandNode( + "world", + helloWorldExecutor, + "permission" + ), + new LiteralCommandNode( + "there", + helloThereExecutor, + "permission" + ) + ), + "permission" + ) + ); + Command command2 = new Command( + new LiteralCommandNode( + "hello", + List.of( + new LiteralCommandNode( + "world", + List.of( + new LiteralCommandNode( + "hi", + helloWorldHiExecutor, + "permission" + ) + ), + "permission" + ) + ), + "permission" + ) + ); + + CommandManager manager = new CommandManager(); + + Command registeredCommand0 = manager.registerCommand("test", command0); + Command registeredCommand1 = manager.registerCommand("test", command1); + Command registeredCommand2 = manager.registerCommand("test", command2); + + Command expectedCommand0 = new Command( + new LiteralCommandNode( + "hello", + helloExecutor, + "permission" + ) + ); + Command expectedCommand1 = new Command( + new LiteralCommandNode( + "hello", + List.of( + new LiteralCommandNode( + "world", + helloWorldExecutor, + "permission" + ), + new LiteralCommandNode( + "there", + helloThereExecutor, + "permission" + ) + ), + helloExecutor, + "permission" + ) + ); + Command expectedCommand2 = new Command( + new LiteralCommandNode( + "hello", + List.of( + new LiteralCommandNode( + "world", + List.of( + new LiteralCommandNode( + "hi", + helloWorldHiExecutor, + "permission" + ) + ), + helloWorldExecutor, + "permission" + ), + new LiteralCommandNode( + "there", + helloThereExecutor, + "permission" + ) + ), + helloExecutor, + "permission" + ) + ); + + Assertions.assertEquals(expectedCommand0, registeredCommand0); + Assertions.assertEquals(expectedCommand1, registeredCommand1); + Assertions.assertEquals(expectedCommand2, registeredCommand2); + } + + @Test + void testCommandNotFound0() { + Command command = new Command( + new LiteralCommandNode( + "hello", + context -> CommandResult.successful(context, "hello"), + "permission" + ) + ); + + CommandManager manager = new CommandManager(); + manager.registerCommand("test", command); + + CommandNotFoundResult expected = CommandResult.commandNotFound("hello0"); + CommandResult actual = manager.execute(CHAD_SENDER, List.of("hello0")); + + Assertions.assertEquals(expected, actual); + } + + @Test + void testCommandNotFound1() { + Command command = new Command( + new LiteralCommandNode( + "hello", + context -> CommandResult.successful(context, "hello"), + "permission" + ) + ); + + CommandManager manager = new CommandManager(); + manager.registerCommand("test", command); + + CommandNotFoundResult expected = CommandResult.commandNotFound(""); + CommandResult actual = manager.execute(CHAD_SENDER, List.of()); + + Assertions.assertEquals(expected, actual); + } + + @Test + void testSuccess0() { + LiteralCommandNode helloNode = new LiteralCommandNode( + "hello", + context -> CommandResult.successful(context, "hello"), + "permission" + ); + Command command0 = new Command(helloNode); + + Command command1 = new Command( + new LiteralCommandNode( + "hi", + context -> CommandResult.successful(context, "hi"), + "permission" + ) + ); + Command command2 = new Command( + new LiteralCommandNode( + "welcome", + context -> CommandResult.successful(context, "welcome"), + "permission" + ) + ); + + CommandManager manager = new CommandManager(); + manager.registerCommand("test", command0); + manager.registerCommand("test", command1); + manager.registerCommand("test", command2); + + SuccessResult expected = CommandResult.successful(0, helloNode, "hello"); + CommandResult actual = manager.execute(CHAD_SENDER, List.of("hello")); + + Assertions.assertEquals(expected, actual); + } + + @Test + void testSuccess1() { + Command command0 = new Command(new LiteralCommandNode( + "hello", + context -> CommandResult.successful(context, "hello"), + "permission" + )); + + LiteralCommandNode thereNode = new LiteralCommandNode( + "there", + context -> CommandResult.successful(context, "hi there"), + "permission" + ); + Command command1 = new Command( + new LiteralCommandNode( + "hi", + List.of( + thereNode + ), + "permission" + ) + ); + + Command command2 = new Command( + new LiteralCommandNode( + "welcome", + context -> CommandResult.successful(context, "welcome"), + "permission" + ) + ); + + CommandManager manager = new CommandManager(); + manager.registerCommand("test", command0); + manager.registerCommand("test", command1); + manager.registerCommand("test", command2); + + SuccessResult expected = CommandResult.successful(1, thereNode, "hi there"); + CommandResult actual = manager.execute(CHAD_SENDER, List.of("hi", "there")); + + Assertions.assertEquals(expected, actual); + } +} From 6c09c4860f44e34afaca1ff8567886b4ca2733fd Mon Sep 17 00:00:00 2001 From: WizardlyBump17 Date: Fri, 7 Nov 2025 17:27:16 -0300 Subject: [PATCH 094/363] returning an empty list if the input is empty --- .../java/com/wizardlybump17/wlib/util/StringUtil.java | 3 +++ .../wlib/util/test/QuotedStringsTests.java | 9 +++++++++ 2 files changed, 12 insertions(+) diff --git a/utils/src/main/java/com/wizardlybump17/wlib/util/StringUtil.java b/utils/src/main/java/com/wizardlybump17/wlib/util/StringUtil.java index 6790f9c4..a5e3fd72 100644 --- a/utils/src/main/java/com/wizardlybump17/wlib/util/StringUtil.java +++ b/utils/src/main/java/com/wizardlybump17/wlib/util/StringUtil.java @@ -324,6 +324,9 @@ public static String fixName(String name) { public static @NonNull List parseQuotedStrings(@NonNull String input, char quote, char escape, char delimiter) throws QuotedStringException { List strings = new ArrayList<>(); + if (input.isEmpty()) + return strings; + char[] chars = input.toCharArray(); StringBuilder builder = new StringBuilder(); StringBuilder quoted = new StringBuilder(); diff --git a/utils/src/test/java/com/wizardlybump17/wlib/util/test/QuotedStringsTests.java b/utils/src/test/java/com/wizardlybump17/wlib/util/test/QuotedStringsTests.java index 4108d47c..9540d293 100644 --- a/utils/src/test/java/com/wizardlybump17/wlib/util/test/QuotedStringsTests.java +++ b/utils/src/test/java/com/wizardlybump17/wlib/util/test/QuotedStringsTests.java @@ -2,6 +2,7 @@ import com.wizardlybump17.wlib.util.StringUtil; import com.wizardlybump17.wlib.util.exception.QuotedStringException; +import org.junit.jupiter.api.Assertions; import org.junit.jupiter.api.Test; import java.util.List; @@ -120,4 +121,12 @@ void testNonQuotedStringAfterQuotedStringException() { QuotedStringException.NON_QUOTED_AFTER_QUOTED ); } + + @Test + void testEmpty() { + Assertions.assertEquals( + List.of(), + StringUtil.parseQuotedStrings("", QUOTE, ESCAPE, DELIMITER) + ); + } } From 1eca426be24581c6d11f33cc59f590a39c325d0f Mon Sep 17 00:00:00 2001 From: WizardlyBump17 Date: Fri, 7 Nov 2025 17:28:07 -0300 Subject: [PATCH 095/363] appending an empty string if the input ends with the delimiter --- .../com/wizardlybump17/wlib/util/StringUtil.java | 14 +++++++++++++- .../wlib/util/test/QuotedStringsTests.java | 16 ++++++++++++++++ 2 files changed, 29 insertions(+), 1 deletion(-) diff --git a/utils/src/main/java/com/wizardlybump17/wlib/util/StringUtil.java b/utils/src/main/java/com/wizardlybump17/wlib/util/StringUtil.java index a5e3fd72..30551861 100644 --- a/utils/src/main/java/com/wizardlybump17/wlib/util/StringUtil.java +++ b/utils/src/main/java/com/wizardlybump17/wlib/util/StringUtil.java @@ -302,7 +302,15 @@ public static String fixName(String name) { * * {@code Hello "Beautiful World"} * {@code [Hello, Beautiful World]} - * + * + * + * {@code Hello World } (there is an extra space at the end) + * {@code [Hello, World, ]} + * + * + * Empty String + * {@code []} + * * *

* @@ -388,6 +396,10 @@ public static String fixName(String name) { if (!builder.isEmpty()) strings.add(builder.toString()); + + if (input.charAt(input.length() - 1) == delimiter) + strings.add(""); + return strings; } diff --git a/utils/src/test/java/com/wizardlybump17/wlib/util/test/QuotedStringsTests.java b/utils/src/test/java/com/wizardlybump17/wlib/util/test/QuotedStringsTests.java index 9540d293..1585d10a 100644 --- a/utils/src/test/java/com/wizardlybump17/wlib/util/test/QuotedStringsTests.java +++ b/utils/src/test/java/com/wizardlybump17/wlib/util/test/QuotedStringsTests.java @@ -129,4 +129,20 @@ void testEmpty() { StringUtil.parseQuotedStrings("", QUOTE, ESCAPE, DELIMITER) ); } + + @Test + void testEndingWithSpace0() { + Assertions.assertEquals( + List.of(""), + StringUtil.parseQuotedStrings(" ", QUOTE, ESCAPE, DELIMITER) + ); + } + + @Test + void testEndingWithSpace1() { + Assertions.assertEquals( + List.of("Hello", "World", ""), + StringUtil.parseQuotedStrings("Hello World ", QUOTE, ESCAPE, DELIMITER) + ); + } } From a7e5a9799cf8c22d3c26f175b6b8bafd5382a0bb Mon Sep 17 00:00:00 2001 From: WizardlyBump17 Date: Fri, 7 Nov 2025 17:33:03 -0300 Subject: [PATCH 096/363] testing more stuff --- .../CommandManagerSuggestionTests.java | 366 ++++++++++++++++++ 1 file changed, 366 insertions(+) diff --git a/commands/src/test/java/com/wizardlybump17/wlib/command/test/rework/manager/CommandManagerSuggestionTests.java b/commands/src/test/java/com/wizardlybump17/wlib/command/test/rework/manager/CommandManagerSuggestionTests.java index 2f1d69f7..f53886c9 100644 --- a/commands/src/test/java/com/wizardlybump17/wlib/command/test/rework/manager/CommandManagerSuggestionTests.java +++ b/commands/src/test/java/com/wizardlybump17/wlib/command/test/rework/manager/CommandManagerSuggestionTests.java @@ -513,4 +513,370 @@ void testSuggestionsSuccessStringChad3() { Assertions.assertEquals(expected, actual); } + + @Test + void testSuggestionsSuccessStringArrayChad0() { + Command command0 = new Command(new LiteralCommandNode( + "hello", + context -> CommandResult.successful(context, "hello"), + "permission" + )); + Command command1 = new Command( + new LiteralCommandNode( + "hi", + List.of( + new LiteralCommandNode( + "there", + context -> CommandResult.successful(context, "hi there"), + "permission" + ) + ), + "permission" + ) + ); + Command command2 = new Command( + new LiteralCommandNode( + "welcome", + List.of( + new IntegerCommandNode( + "repeat", + new AllowedNumberInputs.AllowedIntegerInputs.Positive(), + context -> CommandResult.successful(context, "welcome".repeat(context.arguments().getArgument("repeat").orElseThrow().data())), + "permission" + ) + ), + context -> CommandResult.successful(context, "welcome"), + "permission" + ) + ); + Command command3 = new Command( + new LiteralCommandNode( + "test", + List.of( + new LiteralCommandNode( + "spaced string", + context -> CommandResult.successful(context, "spaced string"), + "permission" + ) + ), + "permission" + ) + ); + + CommandManager manager = new CommandManager(); + manager.registerCommand("test", command0); + manager.registerCommand("test", command1); + manager.registerCommand("test", command2); + manager.registerCommand("test", command3); + + List expected = List.of("hi", "test", "hello", "welcome"); + List actual = manager.getSuggestions(CHAD_SENDER, new String[]{}); + + Assertions.assertEquals(expected, actual); + } + + @Test + void testSuggestionsSuccessStringArrayChad1() { + Command command0 = new Command(new LiteralCommandNode( + "hello", + context -> CommandResult.successful(context, "hello"), + "permission" + )); + Command command1 = new Command( + new LiteralCommandNode( + "hi", + List.of( + new LiteralCommandNode( + "there", + context -> CommandResult.successful(context, "hi there"), + "permission" + ) + ), + "permission" + ) + ); + Command command2 = new Command( + new LiteralCommandNode( + "welcome", + List.of( + new IntegerCommandNode( + "repeat", + new AllowedNumberInputs.AllowedIntegerInputs.Positive(), + context -> CommandResult.successful(context, "welcome".repeat(context.arguments().getArgument("repeat").orElseThrow().data())), + "permission" + ) + ), + context -> CommandResult.successful(context, "welcome"), + "permission" + ) + ); + Command command3 = new Command( + new LiteralCommandNode( + "test", + List.of( + new LiteralCommandNode( + "spaced string", + context -> CommandResult.successful(context, "spaced string"), + "permission" + ) + ), + "permission" + ) + ); + + CommandManager manager = new CommandManager(); + manager.registerCommand("test", command0); + manager.registerCommand("test", command1); + manager.registerCommand("test", command2); + manager.registerCommand("test", command3); + + List expected = List.of("hi", "test", "hello", "welcome"); + List actual = manager.getSuggestions(CHAD_SENDER, new String[]{"he"}); + + Assertions.assertEquals(expected, actual); + } + + @Test + void testSuggestionsSuccessStringArrayChad2() { + Command command0 = new Command(new LiteralCommandNode( + "hello", + context -> CommandResult.successful(context, "hello"), + "permission" + )); + Command command1 = new Command( + new LiteralCommandNode( + "hi", + List.of( + new LiteralCommandNode( + "there", + context -> CommandResult.successful(context, "hi there"), + "permission" + ) + ), + "permission" + ) + ); + Command command2 = new Command( + new LiteralCommandNode( + "welcome", + List.of( + new IntegerCommandNode( + "repeat", + new AllowedNumberInputs.AllowedIntegerInputs.Positive(), + context -> CommandResult.successful(context, "welcome".repeat(context.arguments().getArgument("repeat").orElseThrow().data())), + "permission" + ) + ), + context -> CommandResult.successful(context, "welcome"), + "permission" + ) + ); + Command command3 = new Command( + new LiteralCommandNode( + "test", + List.of( + new LiteralCommandNode( + "spaced string", + context -> CommandResult.successful(context, "spaced string"), + "permission" + ) + ), + "permission" + ) + ); + + CommandManager manager = new CommandManager(); + manager.registerCommand("test", command0); + manager.registerCommand("test", command1); + manager.registerCommand("test", command2); + manager.registerCommand("test", command3); + + List expected = List.of(0, 50, 200, 3000, 50000, 100000); + List actual = manager.getSuggestions(CHAD_SENDER, new String[]{"welcome", ""}); + + Assertions.assertEquals(expected, actual); + } + + @Test + void testSuggestionsSuccessStringArrayChad3() { + Command command0 = new Command(new LiteralCommandNode( + "hello", + context -> CommandResult.successful(context, "hello"), + "permission" + )); + Command command1 = new Command( + new LiteralCommandNode( + "hi", + List.of( + new LiteralCommandNode( + "there", + context -> CommandResult.successful(context, "hi there"), + "permission" + ) + ), + "permission" + ) + ); + Command command2 = new Command( + new LiteralCommandNode( + "welcome", + List.of( + new IntegerCommandNode( + "repeat", + new AllowedNumberInputs.AllowedIntegerInputs.Positive(), + context -> CommandResult.successful(context, "welcome".repeat(context.arguments().getArgument("repeat").orElseThrow().data())), + "permission" + ) + ), + context -> CommandResult.successful(context, "welcome"), + "permission" + ) + ); + Command command3 = new Command( + new LiteralCommandNode( + "test", + List.of( + new LiteralCommandNode( + "spaced string", + context -> CommandResult.successful(context, "spaced string"), + "permission" + ) + ), + "permission" + ) + ); + + CommandManager manager = new CommandManager(); + manager.registerCommand("test", command0); + manager.registerCommand("test", command1); + manager.registerCommand("test", command2); + manager.registerCommand("test", command3); + + List expected = List.of("spaced string"); + List actual = manager.getSuggestions(CHAD_SENDER, new String[]{"test", ""}); + + Assertions.assertEquals(expected, actual); + } + + @Test + void testSuggestionsSuccessStringArrayChad4() { + Command command0 = new Command(new LiteralCommandNode( + "hello", + context -> CommandResult.successful(context, "hello"), + "permission" + )); + Command command1 = new Command( + new LiteralCommandNode( + "hi", + List.of( + new LiteralCommandNode( + "there", + context -> CommandResult.successful(context, "hi there"), + "permission" + ) + ), + "permission" + ) + ); + Command command2 = new Command( + new LiteralCommandNode( + "welcome", + List.of( + new IntegerCommandNode( + "repeat", + new AllowedNumberInputs.AllowedIntegerInputs.Positive(), + context -> CommandResult.successful(context, "welcome".repeat(context.arguments().getArgument("repeat").orElseThrow().data())), + "permission" + ) + ), + context -> CommandResult.successful(context, "welcome"), + "permission" + ) + ); + Command command3 = new Command( + new LiteralCommandNode( + "test", + List.of( + new LiteralCommandNode( + "spaced string", + context -> CommandResult.successful(context, "spaced string"), + "permission" + ) + ), + "permission" + ) + ); + + CommandManager manager = new CommandManager(); + manager.registerCommand("test", command0); + manager.registerCommand("test", command1); + manager.registerCommand("test", command2); + manager.registerCommand("test", command3); + + List expected = List.of("spaced string"); + List actual = manager.getSuggestions(CHAD_SENDER, new String[]{"test", "spaced"}); + + Assertions.assertEquals(expected, actual); + } + + @Test + void testSuggestionsSuccessStringArrayChad5() { + Command command0 = new Command(new LiteralCommandNode( + "hello", + context -> CommandResult.successful(context, "hello"), + "permission" + )); + Command command1 = new Command( + new LiteralCommandNode( + "hi", + List.of( + new LiteralCommandNode( + "there", + context -> CommandResult.successful(context, "hi there"), + "permission" + ) + ), + "permission" + ) + ); + Command command2 = new Command( + new LiteralCommandNode( + "welcome", + List.of( + new IntegerCommandNode( + "repeat", + new AllowedNumberInputs.AllowedIntegerInputs.Positive(), + context -> CommandResult.successful(context, "welcome".repeat(context.arguments().getArgument("repeat").orElseThrow().data())), + "permission" + ) + ), + context -> CommandResult.successful(context, "welcome"), + "permission" + ) + ); + Command command3 = new Command( + new LiteralCommandNode( + "test", + List.of( + new LiteralCommandNode( + "spaced string", + context -> CommandResult.successful(context, "spaced string"), + "permission" + ) + ), + "permission" + ) + ); + + CommandManager manager = new CommandManager(); + manager.registerCommand("test", command0); + manager.registerCommand("test", command1); + manager.registerCommand("test", command2); + manager.registerCommand("test", command3); + + List expected = List.of("spaced string"); + List actual = manager.getSuggestions(CHAD_SENDER, new String[]{"test", "\"space"}); + + Assertions.assertEquals(expected, actual); + } } From d5c3172de5a860ebc045cf95c5ce997d3c74ae94 Mon Sep 17 00:00:00 2001 From: WizardlyBump17 Date: Fri, 7 Nov 2025 17:34:32 -0300 Subject: [PATCH 097/363] add more tests later --- .../test/rework/manager/CommandManagerSuggestionTests.java | 2 ++ 1 file changed, 2 insertions(+) diff --git a/commands/src/test/java/com/wizardlybump17/wlib/command/test/rework/manager/CommandManagerSuggestionTests.java b/commands/src/test/java/com/wizardlybump17/wlib/command/test/rework/manager/CommandManagerSuggestionTests.java index f53886c9..96ad4b3a 100644 --- a/commands/src/test/java/com/wizardlybump17/wlib/command/test/rework/manager/CommandManagerSuggestionTests.java +++ b/commands/src/test/java/com/wizardlybump17/wlib/command/test/rework/manager/CommandManagerSuggestionTests.java @@ -879,4 +879,6 @@ void testSuggestionsSuccessStringArrayChad5() { Assertions.assertEquals(expected, actual); } + + //TODO: add more tests } From c4c63a51706c2a7208d832ce8253e0ab07b2848f Mon Sep 17 00:00:00 2001 From: WizardlyBump17 Date: Fri, 7 Nov 2025 17:43:22 -0300 Subject: [PATCH 098/363] not rework anymore --- .../wlib/bungee/command/BungeeCommand.java | 25 -- .../bungee/command/BungeeCommandExecutor.java | 33 --- .../bungee/command/BungeeCommandHolder.java | 37 --- .../bungee/command/BungeeCommandManager.java | 25 -- .../wizardlybump17/wlib/command/Argument.java | 23 -- .../wlib/command/{rework => }/Command.java | 24 +- .../wlib/command/CommandManager.java | 130 ----------- .../wlib/command/CommandResult.java | 11 - .../wlib/command/Description.java | 13 -- .../wlib/command/annotation/Command.java | 79 +------ .../wlib/command/args/ArgsNode.java | 57 ----- .../wlib/command/args/ArgsReaderRegistry.java | 52 ----- .../wlib/command/args/ArgsReaderType.java | 21 -- .../wlib/command/args/reader/ArgsReader.java | 49 ---- .../args/reader/ArgsReaderException.java | 16 -- .../args/reader/BigDecimalArgsReader.java | 20 -- .../args/reader/BigIntegerArgsReader.java | 20 -- .../command/args/reader/BooleanReader.java | 37 --- .../command/args/reader/ByteArrayReader.java | 23 -- .../wlib/command/args/reader/ByteReader.java | 36 --- .../wlib/command/args/reader/DateReader.java | 60 ----- .../args/reader/DoubleArrayReader.java | 23 -- .../command/args/reader/DoubleReader.java | 36 --- .../command/args/reader/FloatArrayReader.java | 23 -- .../wlib/command/args/reader/FloatReader.java | 36 --- .../args/reader/IntegerArrayReader.java | 23 -- .../command/args/reader/IntegerReader.java | 36 --- .../command/args/reader/ShortArrayReader.java | 23 -- .../wlib/command/args/reader/ShortReader.java | 36 --- .../command/args/reader/StringReader.java | 26 --- .../wlib/command/args/reader/UUIDReader.java | 31 --- .../command/completer/ArgumentCompleter.java | 12 - .../completer/ArgumentCompleterRegistry.java | 11 - .../{rework => }/context/CommandContext.java | 6 +- .../command/data/AnnotationCommandData.java | 100 -------- .../wlib/command/data/CommandData.java | 81 ------- .../wlib/command/data/SimpleCommandData.java | 216 ------------------ .../command/exception/CommandException.java | 21 -- .../exception/InputParsingException.java | 2 +- .../exception/InvalidInputException.java | 2 +- .../command/executor/CommandExecutor.java | 12 - .../executor/CommandNodeExecutor.java | 6 +- .../command/extractor/CommandExtractor.java | 13 -- .../extractor/DirectCommandExtractor.java | 16 -- .../extractor/MethodCommandExtractor.java | 44 ---- .../wlib/command/holder/Command.java | 19 -- .../wlib/command/holder/CommandExecutor.java | 13 -- .../wlib/command/holder/CommandHolder.java | 20 -- .../{rework => }/input/AllowedInputs.java | 2 +- .../input/AllowedNumberInputs.java | 2 +- .../input/LiteralAllowedInput.java | 2 +- .../input/RangedAllowedInputs.java | 2 +- .../{rework => }/manager/CommandManager.java | 8 +- .../{rework => }/node/CommandNode.java | 10 +- .../{rework => }/node/IntegerCommandNode.java | 8 +- .../{rework => }/node/LiteralCommandNode.java | 6 +- .../command/registered/RegisteredCommand.java | 138 ----------- .../registered/RegisteredMethodCommand.java | 123 ---------- .../{rework => }/result/CommandResult.java | 12 +- .../{rework => }/result/SuccessResult.java | 4 +- .../CommandNodeExecutorNotFoundResult.java | 4 +- .../result/error/CommandNotFoundResult.java | 6 +- .../result/error/ExceptionResult.java | 4 +- .../result/error/ExtraArgumentsResult.java | 4 +- .../result/error/GenericErrorResult.java | 4 +- .../error/InsufficientArgumentsResult.java | 6 +- .../result/error/NoPermissionResult.java | 4 +- .../result/error/OutOfRangeInputResult.java | 4 +- .../error/ParseInputExceptionResult.java | 6 +- .../result/error/UnsuccessResult.java | 4 +- .../command/rework/annotation/Command.java | 15 -- .../rework => test/command}/CommandTests.java | 18 +- .../command}/SuggestionTests.java | 12 +- .../CommandManagerSuggestionTests.java | 16 +- .../command}/manager/CommandManagerTests.java | 18 +- .../sender/BasicCommandSenderTests.java | 2 +- .../java/com/wizardlybump17/wlib/WLib.java | 11 - .../wlib/command/BukkitCommandExecutor.java | 41 ---- .../EntityTypeArgumentCompleter.java | 20 -- .../completer/MaterialArgumentCompleter.java | 20 -- .../completer/PlayerArgumentCompleter.java | 18 -- .../wlib/command/holder/BukkitCommand.java | 27 --- .../command/holder/BukkitCommandHolder.java | 29 --- .../command/reader/BlockDataArgsReader.java | 39 ---- .../command/reader/EnchantmentReader.java | 21 -- .../command/reader/EntityTypeArgsReader.java | 36 --- .../command/reader/MapJsonArgsReader.java | 38 --- .../wlib/command/reader/MaterialReader.java | 29 --- .../command/reader/NamespacedKeyReader.java | 29 --- .../command/reader/OfflinePlayerReader.java | 47 ---- .../wlib/command/reader/PlayerReader.java | 33 --- .../reader/PotionEffectTypeReader.java | 21 -- .../registered/RegisteredBukkitCommand.java | 59 ----- 93 files changed, 105 insertions(+), 2535 deletions(-) delete mode 100644 bungee/src/main/java/com/wizardlybump17/wlib/bungee/command/BungeeCommand.java delete mode 100644 bungee/src/main/java/com/wizardlybump17/wlib/bungee/command/BungeeCommandExecutor.java delete mode 100644 bungee/src/main/java/com/wizardlybump17/wlib/bungee/command/BungeeCommandHolder.java delete mode 100644 bungee/src/main/java/com/wizardlybump17/wlib/bungee/command/BungeeCommandManager.java delete mode 100644 commands/src/main/java/com/wizardlybump17/wlib/command/Argument.java rename commands/src/main/java/com/wizardlybump17/wlib/command/{rework => }/Command.java (92%) delete mode 100644 commands/src/main/java/com/wizardlybump17/wlib/command/CommandManager.java delete mode 100644 commands/src/main/java/com/wizardlybump17/wlib/command/CommandResult.java delete mode 100644 commands/src/main/java/com/wizardlybump17/wlib/command/Description.java delete mode 100644 commands/src/main/java/com/wizardlybump17/wlib/command/args/ArgsNode.java delete mode 100644 commands/src/main/java/com/wizardlybump17/wlib/command/args/ArgsReaderRegistry.java delete mode 100644 commands/src/main/java/com/wizardlybump17/wlib/command/args/ArgsReaderType.java delete mode 100644 commands/src/main/java/com/wizardlybump17/wlib/command/args/reader/ArgsReader.java delete mode 100644 commands/src/main/java/com/wizardlybump17/wlib/command/args/reader/ArgsReaderException.java delete mode 100644 commands/src/main/java/com/wizardlybump17/wlib/command/args/reader/BigDecimalArgsReader.java delete mode 100644 commands/src/main/java/com/wizardlybump17/wlib/command/args/reader/BigIntegerArgsReader.java delete mode 100644 commands/src/main/java/com/wizardlybump17/wlib/command/args/reader/BooleanReader.java delete mode 100644 commands/src/main/java/com/wizardlybump17/wlib/command/args/reader/ByteArrayReader.java delete mode 100644 commands/src/main/java/com/wizardlybump17/wlib/command/args/reader/ByteReader.java delete mode 100644 commands/src/main/java/com/wizardlybump17/wlib/command/args/reader/DateReader.java delete mode 100644 commands/src/main/java/com/wizardlybump17/wlib/command/args/reader/DoubleArrayReader.java delete mode 100644 commands/src/main/java/com/wizardlybump17/wlib/command/args/reader/DoubleReader.java delete mode 100644 commands/src/main/java/com/wizardlybump17/wlib/command/args/reader/FloatArrayReader.java delete mode 100644 commands/src/main/java/com/wizardlybump17/wlib/command/args/reader/FloatReader.java delete mode 100644 commands/src/main/java/com/wizardlybump17/wlib/command/args/reader/IntegerArrayReader.java delete mode 100644 commands/src/main/java/com/wizardlybump17/wlib/command/args/reader/IntegerReader.java delete mode 100644 commands/src/main/java/com/wizardlybump17/wlib/command/args/reader/ShortArrayReader.java delete mode 100644 commands/src/main/java/com/wizardlybump17/wlib/command/args/reader/ShortReader.java delete mode 100644 commands/src/main/java/com/wizardlybump17/wlib/command/args/reader/StringReader.java delete mode 100644 commands/src/main/java/com/wizardlybump17/wlib/command/args/reader/UUIDReader.java delete mode 100644 commands/src/main/java/com/wizardlybump17/wlib/command/completer/ArgumentCompleter.java delete mode 100644 commands/src/main/java/com/wizardlybump17/wlib/command/completer/ArgumentCompleterRegistry.java rename commands/src/main/java/com/wizardlybump17/wlib/command/{rework => }/context/CommandContext.java (93%) delete mode 100644 commands/src/main/java/com/wizardlybump17/wlib/command/data/AnnotationCommandData.java delete mode 100644 commands/src/main/java/com/wizardlybump17/wlib/command/data/CommandData.java delete mode 100644 commands/src/main/java/com/wizardlybump17/wlib/command/data/SimpleCommandData.java delete mode 100644 commands/src/main/java/com/wizardlybump17/wlib/command/exception/CommandException.java rename commands/src/main/java/com/wizardlybump17/wlib/command/{rework => }/exception/InputParsingException.java (83%) rename commands/src/main/java/com/wizardlybump17/wlib/command/{rework => }/exception/InvalidInputException.java (84%) delete mode 100644 commands/src/main/java/com/wizardlybump17/wlib/command/executor/CommandExecutor.java rename commands/src/main/java/com/wizardlybump17/wlib/command/{rework => }/executor/CommandNodeExecutor.java (62%) delete mode 100644 commands/src/main/java/com/wizardlybump17/wlib/command/extractor/CommandExtractor.java delete mode 100644 commands/src/main/java/com/wizardlybump17/wlib/command/extractor/DirectCommandExtractor.java delete mode 100644 commands/src/main/java/com/wizardlybump17/wlib/command/extractor/MethodCommandExtractor.java delete mode 100644 commands/src/main/java/com/wizardlybump17/wlib/command/holder/Command.java delete mode 100644 commands/src/main/java/com/wizardlybump17/wlib/command/holder/CommandExecutor.java delete mode 100644 commands/src/main/java/com/wizardlybump17/wlib/command/holder/CommandHolder.java rename commands/src/main/java/com/wizardlybump17/wlib/command/{rework => }/input/AllowedInputs.java (88%) rename commands/src/main/java/com/wizardlybump17/wlib/command/{rework => }/input/AllowedNumberInputs.java (99%) rename commands/src/main/java/com/wizardlybump17/wlib/command/{rework => }/input/LiteralAllowedInput.java (89%) rename commands/src/main/java/com/wizardlybump17/wlib/command/{rework => }/input/RangedAllowedInputs.java (78%) rename commands/src/main/java/com/wizardlybump17/wlib/command/{rework => }/manager/CommandManager.java (94%) rename commands/src/main/java/com/wizardlybump17/wlib/command/{rework => }/node/CommandNode.java (95%) rename commands/src/main/java/com/wizardlybump17/wlib/command/{rework => }/node/IntegerCommandNode.java (91%) rename commands/src/main/java/com/wizardlybump17/wlib/command/{rework => }/node/LiteralCommandNode.java (92%) delete mode 100644 commands/src/main/java/com/wizardlybump17/wlib/command/registered/RegisteredCommand.java delete mode 100644 commands/src/main/java/com/wizardlybump17/wlib/command/registered/RegisteredMethodCommand.java rename commands/src/main/java/com/wizardlybump17/wlib/command/{rework => }/result/CommandResult.java (90%) rename commands/src/main/java/com/wizardlybump17/wlib/command/{rework => }/result/SuccessResult.java (71%) rename commands/src/main/java/com/wizardlybump17/wlib/command/{rework => }/result/error/CommandNodeExecutorNotFoundResult.java (59%) rename commands/src/main/java/com/wizardlybump17/wlib/command/{rework => }/result/error/CommandNotFoundResult.java (83%) rename commands/src/main/java/com/wizardlybump17/wlib/command/{rework => }/result/error/ExceptionResult.java (60%) rename commands/src/main/java/com/wizardlybump17/wlib/command/{rework => }/result/error/ExtraArgumentsResult.java (57%) rename commands/src/main/java/com/wizardlybump17/wlib/command/{rework => }/result/error/GenericErrorResult.java (78%) rename commands/src/main/java/com/wizardlybump17/wlib/command/{rework => }/result/error/InsufficientArgumentsResult.java (64%) rename commands/src/main/java/com/wizardlybump17/wlib/command/{rework => }/result/error/NoPermissionResult.java (67%) rename commands/src/main/java/com/wizardlybump17/wlib/command/{rework => }/result/error/OutOfRangeInputResult.java (57%) rename commands/src/main/java/com/wizardlybump17/wlib/command/{rework => }/result/error/ParseInputExceptionResult.java (51%) rename commands/src/main/java/com/wizardlybump17/wlib/command/{rework => }/result/error/UnsuccessResult.java (71%) delete mode 100644 commands/src/main/java/com/wizardlybump17/wlib/command/rework/annotation/Command.java rename commands/src/test/java/com/wizardlybump17/wlib/{command/test/rework => test/command}/CommandTests.java (94%) rename commands/src/test/java/com/wizardlybump17/wlib/{command/test/rework => test/command}/SuggestionTests.java (94%) rename commands/src/test/java/com/wizardlybump17/wlib/{command/test/rework => test/command}/manager/CommandManagerSuggestionTests.java (98%) rename commands/src/test/java/com/wizardlybump17/wlib/{command/test/rework => test/command}/manager/CommandManagerTests.java (96%) rename commands/src/test/java/com/wizardlybump17/wlib/{command/test => test/command}/sender/BasicCommandSenderTests.java (98%) delete mode 100644 core/src/main/java/com/wizardlybump17/wlib/command/BukkitCommandExecutor.java delete mode 100644 core/src/main/java/com/wizardlybump17/wlib/command/completer/EntityTypeArgumentCompleter.java delete mode 100644 core/src/main/java/com/wizardlybump17/wlib/command/completer/MaterialArgumentCompleter.java delete mode 100644 core/src/main/java/com/wizardlybump17/wlib/command/completer/PlayerArgumentCompleter.java delete mode 100644 core/src/main/java/com/wizardlybump17/wlib/command/holder/BukkitCommand.java delete mode 100644 core/src/main/java/com/wizardlybump17/wlib/command/holder/BukkitCommandHolder.java delete mode 100644 core/src/main/java/com/wizardlybump17/wlib/command/reader/BlockDataArgsReader.java delete mode 100644 core/src/main/java/com/wizardlybump17/wlib/command/reader/EnchantmentReader.java delete mode 100644 core/src/main/java/com/wizardlybump17/wlib/command/reader/EntityTypeArgsReader.java delete mode 100644 core/src/main/java/com/wizardlybump17/wlib/command/reader/MapJsonArgsReader.java delete mode 100644 core/src/main/java/com/wizardlybump17/wlib/command/reader/MaterialReader.java delete mode 100644 core/src/main/java/com/wizardlybump17/wlib/command/reader/NamespacedKeyReader.java delete mode 100644 core/src/main/java/com/wizardlybump17/wlib/command/reader/OfflinePlayerReader.java delete mode 100644 core/src/main/java/com/wizardlybump17/wlib/command/reader/PlayerReader.java delete mode 100644 core/src/main/java/com/wizardlybump17/wlib/command/reader/PotionEffectTypeReader.java delete mode 100644 core/src/main/java/com/wizardlybump17/wlib/command/registered/RegisteredBukkitCommand.java diff --git a/bungee/src/main/java/com/wizardlybump17/wlib/bungee/command/BungeeCommand.java b/bungee/src/main/java/com/wizardlybump17/wlib/bungee/command/BungeeCommand.java deleted file mode 100644 index 494572cd..00000000 --- a/bungee/src/main/java/com/wizardlybump17/wlib/bungee/command/BungeeCommand.java +++ /dev/null @@ -1,25 +0,0 @@ -package com.wizardlybump17.wlib.bungee.command; - -import com.wizardlybump17.wlib.command.CommandManager; -import com.wizardlybump17.wlib.command.holder.Command; -import com.wizardlybump17.wlib.command.holder.CommandExecutor; - -public class BungeeCommand implements Command { - - private CommandExecutor executor; - - @Override - public void setExecutor(CommandExecutor executor) { - this.executor = executor; - } - - @Override - public CommandExecutor getExecutor() { - return executor; - } - - @Override - public CommandExecutor getDefaultExecutor(CommandManager manager, String name) { - return new BungeeCommandExecutor(manager, name); - } -} diff --git a/bungee/src/main/java/com/wizardlybump17/wlib/bungee/command/BungeeCommandExecutor.java b/bungee/src/main/java/com/wizardlybump17/wlib/bungee/command/BungeeCommandExecutor.java deleted file mode 100644 index cca749bd..00000000 --- a/bungee/src/main/java/com/wizardlybump17/wlib/bungee/command/BungeeCommandExecutor.java +++ /dev/null @@ -1,33 +0,0 @@ -package com.wizardlybump17.wlib.bungee.command; - -import com.wizardlybump17.wlib.bungee.command.sender.BungeeCommandSender; -import com.wizardlybump17.wlib.command.CommandManager; -import com.wizardlybump17.wlib.command.exception.CommandException; -import com.wizardlybump17.wlib.command.holder.CommandExecutor; -import net.md_5.bungee.api.plugin.Command; - -import java.util.logging.Level; - -public class BungeeCommandExecutor extends Command implements CommandExecutor { - - private final CommandManager manager; - - public BungeeCommandExecutor(CommandManager manager, String name) { - super(name); - this.manager = manager; - } - - @Override - public void execute(com.wizardlybump17.wlib.command.sender.CommandSender sender, String commandName, String[] args) throws CommandException { - manager.execute(sender, commandName + " " + String.join(" ", args)); - } - - @Override - public void execute(net.md_5.bungee.api.CommandSender sender, String[] args) { - try { - execute(new BungeeCommandSender(sender), getName(), args); - } catch (CommandException e) { - manager.getHolder().getLogger().log(Level.SEVERE, "Error while executing a command", e); - } - } -} diff --git a/bungee/src/main/java/com/wizardlybump17/wlib/bungee/command/BungeeCommandHolder.java b/bungee/src/main/java/com/wizardlybump17/wlib/bungee/command/BungeeCommandHolder.java deleted file mode 100644 index 878d093c..00000000 --- a/bungee/src/main/java/com/wizardlybump17/wlib/bungee/command/BungeeCommandHolder.java +++ /dev/null @@ -1,37 +0,0 @@ -package com.wizardlybump17.wlib.bungee.command; - -import com.wizardlybump17.wlib.command.holder.Command; -import com.wizardlybump17.wlib.command.holder.CommandHolder; -import lombok.NonNull; -import lombok.RequiredArgsConstructor; -import net.md_5.bungee.api.plugin.Plugin; - -import java.util.HashMap; -import java.util.Map; -import java.util.logging.Logger; - -@RequiredArgsConstructor -public class BungeeCommandHolder implements CommandHolder { - - private final Plugin plugin; - private final Map commands = new HashMap<>(); - - @Override - public Command getCommand(String name) { - if (commands.containsKey(name)) - return commands.get(name); - BungeeCommand command = new BungeeCommand(); - commands.put(name, command); - return command; - } - - @Override - public Plugin getHandle() { - return plugin; - } - - @Override - public @NonNull Logger getLogger() { - return plugin.getLogger(); - } -} diff --git a/bungee/src/main/java/com/wizardlybump17/wlib/bungee/command/BungeeCommandManager.java b/bungee/src/main/java/com/wizardlybump17/wlib/bungee/command/BungeeCommandManager.java deleted file mode 100644 index bfd1bafa..00000000 --- a/bungee/src/main/java/com/wizardlybump17/wlib/bungee/command/BungeeCommandManager.java +++ /dev/null @@ -1,25 +0,0 @@ -package com.wizardlybump17.wlib.bungee.command; - -import com.wizardlybump17.wlib.command.CommandManager; -import com.wizardlybump17.wlib.command.registered.RegisteredCommand; -import net.md_5.bungee.api.plugin.Command; -import net.md_5.bungee.api.plugin.Plugin; -import org.jetbrains.annotations.NotNull; - -public class BungeeCommandManager extends CommandManager { - - public BungeeCommandManager(BungeeCommandHolder holder) { - super(holder); - } - - @Override - public void registerCommands(@NotNull Object @NotNull ... objects) { - super.registerCommands(objects); - for (Object object : objects) { - for (RegisteredCommand command : getCommands(object)) { - Plugin plugin = (Plugin) holder.getHandle(); - plugin.getProxy().getPluginManager().registerCommand(plugin, (Command) holder.getCommand(command.getName()).getExecutor()); - } - } - } -} diff --git a/commands/src/main/java/com/wizardlybump17/wlib/command/Argument.java b/commands/src/main/java/com/wizardlybump17/wlib/command/Argument.java deleted file mode 100644 index 71416e57..00000000 --- a/commands/src/main/java/com/wizardlybump17/wlib/command/Argument.java +++ /dev/null @@ -1,23 +0,0 @@ -package com.wizardlybump17.wlib.command; - -import lombok.AccessLevel; -import lombok.Data; -import lombok.Getter; - -/** - * Class used in the arguments to represent a command argument. - *

It stores useful information like the argument name and the user input

- * @param the argument type - */ -@Data -public class Argument { - - private final String name; - @Getter(AccessLevel.NONE) - private final T value; - private final String input; - - public T value() { - return value; - } -} diff --git a/commands/src/main/java/com/wizardlybump17/wlib/command/rework/Command.java b/commands/src/main/java/com/wizardlybump17/wlib/command/Command.java similarity index 92% rename from commands/src/main/java/com/wizardlybump17/wlib/command/rework/Command.java rename to commands/src/main/java/com/wizardlybump17/wlib/command/Command.java index f33c9efa..94ec2593 100644 --- a/commands/src/main/java/com/wizardlybump17/wlib/command/rework/Command.java +++ b/commands/src/main/java/com/wizardlybump17/wlib/command/Command.java @@ -1,14 +1,14 @@ -package com.wizardlybump17.wlib.command.rework; - -import com.wizardlybump17.wlib.command.rework.context.CommandContext; -import com.wizardlybump17.wlib.command.rework.exception.InputParsingException; -import com.wizardlybump17.wlib.command.rework.exception.InvalidInputException; -import com.wizardlybump17.wlib.command.rework.executor.CommandNodeExecutor; -import com.wizardlybump17.wlib.command.rework.input.AllowedNumberInputs; -import com.wizardlybump17.wlib.command.rework.node.CommandNode; -import com.wizardlybump17.wlib.command.rework.node.IntegerCommandNode; -import com.wizardlybump17.wlib.command.rework.node.LiteralCommandNode; -import com.wizardlybump17.wlib.command.rework.result.CommandResult; +package com.wizardlybump17.wlib.command; + +import com.wizardlybump17.wlib.command.context.CommandContext; +import com.wizardlybump17.wlib.command.exception.InputParsingException; +import com.wizardlybump17.wlib.command.exception.InvalidInputException; +import com.wizardlybump17.wlib.command.executor.CommandNodeExecutor; +import com.wizardlybump17.wlib.command.input.AllowedNumberInputs; +import com.wizardlybump17.wlib.command.node.CommandNode; +import com.wizardlybump17.wlib.command.node.IntegerCommandNode; +import com.wizardlybump17.wlib.command.node.LiteralCommandNode; +import com.wizardlybump17.wlib.command.result.CommandResult; import com.wizardlybump17.wlib.command.sender.CommandSender; import com.wizardlybump17.wlib.util.StringUtil; import org.jetbrains.annotations.NotNull; @@ -219,7 +219,7 @@ public int hashCode() { } public static @NotNull Command fromMethod(@NotNull Method method, @NotNull Object object) { - com.wizardlybump17.wlib.command.rework.annotation.Command annotation = method.getDeclaredAnnotation(com.wizardlybump17.wlib.command.rework.annotation.Command.class); + com.wizardlybump17.wlib.command.annotation.Command annotation = method.getDeclaredAnnotation(com.wizardlybump17.wlib.command.annotation.Command.class); if (annotation == null) throw new IllegalArgumentException("Method " + method.getName() + " does not have a Command annotation"); diff --git a/commands/src/main/java/com/wizardlybump17/wlib/command/CommandManager.java b/commands/src/main/java/com/wizardlybump17/wlib/command/CommandManager.java deleted file mode 100644 index 08bff110..00000000 --- a/commands/src/main/java/com/wizardlybump17/wlib/command/CommandManager.java +++ /dev/null @@ -1,130 +0,0 @@ -package com.wizardlybump17.wlib.command; - -import com.wizardlybump17.wlib.command.data.CommandData; -import com.wizardlybump17.wlib.command.exception.CommandException; -import com.wizardlybump17.wlib.command.extractor.CommandExtractor; -import com.wizardlybump17.wlib.command.extractor.DirectCommandExtractor; -import com.wizardlybump17.wlib.command.extractor.MethodCommandExtractor; -import com.wizardlybump17.wlib.command.holder.CommandHolder; -import com.wizardlybump17.wlib.command.registered.RegisteredCommand; -import com.wizardlybump17.wlib.command.sender.CommandSender; -import org.jetbrains.annotations.NotNull; - -import java.util.*; - -public class CommandManager { - - private final @NotNull Map> commands = new HashMap<>(); - protected final @NotNull CommandHolder holder; - private final @NotNull Set commandExtractors = new HashSet<>(); - - public CommandManager(@NotNull CommandHolder holder) { - this.holder = holder; - commandExtractors.add(new MethodCommandExtractor()); - commandExtractors.add(new DirectCommandExtractor()); - } - - public void registerCommands(@NotNull Object @NotNull ... objects) { - for (Object object : objects) - for (CommandExtractor extractor : commandExtractors) - registerCommands(extractor.extract(this, holder, object)); - } - - public void registerCommands(@NotNull Collection commands) { - commands.forEach(this::registerCommand); - } - - public void registerCommand(@NotNull RegisteredCommand command) { - command.onRegister(this); - List commands = this.commands.computeIfAbsent(command.getName().toLowerCase(), $ -> new ArrayList<>()); - commands.add(command); - commands.sort(null); - } - - public void unregisterCommands() { - commands.forEach((name, commands) -> { - commands.forEach(command -> command.onUnregister(this)); - commands.clear(); - }); - commands.clear(); - } - - public void execute(@NotNull CommandSender sender, @NotNull String string) throws CommandException { - if (commands.isEmpty()) - return; - - int spaceIndex = string.indexOf(' '); - String name; - if (spaceIndex == -1) - name = string; - else - name = string.substring(0, spaceIndex); - - for (RegisteredCommand registeredCommand : commands.getOrDefault(name, List.of())) { - CommandData command = registeredCommand.getCommand(); - CommandResult result = registeredCommand.execute(sender, string); - - switch (result) { - case PERMISSION_FAIL -> { - String message = command.getPermissionMessage(); - if (message != null) - sender.sendMessage(message); - return; - } - - case INVALID_SENDER -> { - String message = command.getInvalidSenderMessage(); - if (message != null) - sender.sendMessage(message); - return; - } - - case SUCCESS, EXCEPTION -> { - return; - } - } - } - } - - public @NotNull List<@NotNull String> autoComplete(@NotNull CommandSender sender, @NotNull String string) { - return List.of(); - } - - public @NotNull List getCommands(@NotNull String name) { - List commands = this.commands.get(name); - return commands == null ? List.of() : List.copyOf(commands); - } - - public @NotNull List getCommands(@NotNull Object object) { - List result = new ArrayList<>(commands.size()); - for (List commands : this.commands.values()) - for (RegisteredCommand command : commands) - if (command.isOwnedBy(object)) - result.add(command); - return result; - } - - public @NotNull CommandHolder getHolder() { - return holder; - } - - public @NotNull Map> getCommands() { - return Map.copyOf(commands); - } - - public @NotNull Set getCommandExtractors() { - return Set.copyOf(commandExtractors); - } - - public void addCommandExtractor(@NotNull CommandExtractor extractor) { - commandExtractors.add(extractor); - } - - public void removeCommandExtractor(@NotNull CommandExtractor extractor) { - commandExtractors.remove(extractor); - } - - public boolean hasCommandExtractor(@NotNull CommandExtractor extractor) { - return commandExtractors.contains(extractor); - } -} \ No newline at end of file diff --git a/commands/src/main/java/com/wizardlybump17/wlib/command/CommandResult.java b/commands/src/main/java/com/wizardlybump17/wlib/command/CommandResult.java deleted file mode 100644 index 875696af..00000000 --- a/commands/src/main/java/com/wizardlybump17/wlib/command/CommandResult.java +++ /dev/null @@ -1,11 +0,0 @@ -package com.wizardlybump17.wlib.command; - -public enum CommandResult { - - SUCCESS, - ARGS_FAIL, - EXCEPTION, - PERMISSION_FAIL, - METHOD_FAIL, - INVALID_SENDER -} diff --git a/commands/src/main/java/com/wizardlybump17/wlib/command/Description.java b/commands/src/main/java/com/wizardlybump17/wlib/command/Description.java deleted file mode 100644 index f66546fc..00000000 --- a/commands/src/main/java/com/wizardlybump17/wlib/command/Description.java +++ /dev/null @@ -1,13 +0,0 @@ -package com.wizardlybump17.wlib.command; - -import java.lang.annotation.ElementType; -import java.lang.annotation.Retention; -import java.lang.annotation.RetentionPolicy; -import java.lang.annotation.Target; - -@Retention(RetentionPolicy.RUNTIME) -@Target(ElementType.PARAMETER) -public @interface Description { - - String value(); -} diff --git a/commands/src/main/java/com/wizardlybump17/wlib/command/annotation/Command.java b/commands/src/main/java/com/wizardlybump17/wlib/command/annotation/Command.java index b941b23b..c2061c85 100644 --- a/commands/src/main/java/com/wizardlybump17/wlib/command/annotation/Command.java +++ b/commands/src/main/java/com/wizardlybump17/wlib/command/annotation/Command.java @@ -1,6 +1,5 @@ package com.wizardlybump17.wlib.command.annotation; -import com.wizardlybump17.wlib.command.sender.CommandSender; import org.jetbrains.annotations.NotNull; import java.lang.annotation.ElementType; @@ -8,85 +7,9 @@ import java.lang.annotation.RetentionPolicy; import java.lang.annotation.Target; -/** - *

An annotation that describes a command.

- *

For a command to be valid the first parameter of the method must implements {@link CommandSender}

- */ @Target(ElementType.METHOD) @Retention(RetentionPolicy.RUNTIME) public @interface Command { - /** - *

How the sender must type the command in order for it to be triggered. - * Example:

command hello world
- * In the example above, the sender must type /command hello world, so it can be triggered. - * To add parameters that depends on the sender input, just put the parameter between <>. - *
- * Example:
command <hello> world

- *

The type of each parameter is defined in the method that have this annotation. - * An example for the command above: - *

-     *  @Command(execution = "command <hello> world")
-     *  public void commandHelloWorld(GenericSender sender, String hello) {
-     *      System.out.println(sender.getName() + " executed the hello world command with the argument " + hello);
-     *  }
-     * 

- * - * @return how the command must be sent to be triggered - * @see com.wizardlybump17.wlib.command.args.reader.ArgsReader - */ - String execution(); - - /** - * @return which permission the sender must have to trigger this command - */ - String permission() default ""; - - /** - *

Used when the {@link CommandSender} does not have the required {@link #permission()}.

- * @return the message to be sent when the {@link CommandSender} does not have the required {@link #permission()} - */ - String permissionMessage() default ""; - - /** - * @return if the {@link #permissionMessage()} is a field in the class that have this annotation - */ - boolean permissionMessageIsField() default false; - - /** - * Sets the priority of this command. If the priority is -1, then the priority check is the same as - *
{@code this.execution().split(" ").length}
- * - * @return the priority of this command - */ - int priority() default -1; - - /** - * Sets the options of this command. - * The Bukkit implementation does nothing with this - * - * @return the options of this command - */ - String[] options() default {}; - - /** - * @return the description of this command - */ - String description() default ""; - - /** - *

Used when the {@link CommandSender} is not valid for this command.

- * @return the message to be sent when the {@link CommandSender} is not valid for this command - */ - String invalidSenderMessage() default ""; - - /** - * @return if the {@link #invalidSenderMessage()} is a field in the class that have this annotation - */ - boolean invalidSenderMessageIsField() default false; - - /** - * @return the type of the {@link CommandSender#getHandle()} that can execute this command - */ - @NotNull Class senderType() default Object.class; + @NotNull String value(); } diff --git a/commands/src/main/java/com/wizardlybump17/wlib/command/args/ArgsNode.java b/commands/src/main/java/com/wizardlybump17/wlib/command/args/ArgsNode.java deleted file mode 100644 index 23d07d47..00000000 --- a/commands/src/main/java/com/wizardlybump17/wlib/command/args/ArgsNode.java +++ /dev/null @@ -1,57 +0,0 @@ -package com.wizardlybump17.wlib.command.args; - -import com.wizardlybump17.wlib.command.Argument; -import com.wizardlybump17.wlib.command.args.reader.ArgsReader; -import com.wizardlybump17.wlib.command.args.reader.ArgsReaderException; -import lombok.AllArgsConstructor; -import lombok.Data; -import org.jetbrains.annotations.NotNull; -import org.jetbrains.annotations.Nullable; - -/** - * Represents a node of a command argument - */ -@Data -@AllArgsConstructor -public class ArgsNode { - - public static final Object EMPTY = new Object(); - - @NotNull - private final String name; - private final boolean userInput; - @Nullable - private final ArgsReader reader; - @Nullable - private final String description; - private final boolean isArgument; - - /** - * Parses the given input - * @param input the input - * @return the parsed object - * @throws ArgsReaderException if the input is invalid - */ - public Object parse(String input) throws ArgsReaderException { - if (reader == null) - return EMPTY; - - Object object = reader.read(input); - if (isArgument) - return new Argument<>(name, object, input); - - return object; - } - - public static @NotNull ArgsNode literal(@NotNull String string) { - return new ArgsNode(string, false, null, null, false); - } - - public static @NotNull ArgsNode userInput(@NotNull String name, @NotNull ArgsReader reader) { - return new ArgsNode(name, true, reader, null, false); - } - - public static @NotNull ArgsNode userInput(@NotNull String name, @NotNull Class type) { - return userInput(name, ArgsReaderRegistry.INSTANCE.getReader(type)); - } -} diff --git a/commands/src/main/java/com/wizardlybump17/wlib/command/args/ArgsReaderRegistry.java b/commands/src/main/java/com/wizardlybump17/wlib/command/args/ArgsReaderRegistry.java deleted file mode 100644 index 09c8f99d..00000000 --- a/commands/src/main/java/com/wizardlybump17/wlib/command/args/ArgsReaderRegistry.java +++ /dev/null @@ -1,52 +0,0 @@ -package com.wizardlybump17.wlib.command.args; - -import com.wizardlybump17.wlib.command.args.reader.*; -import com.wizardlybump17.wlib.object.Registry; - -/** - * A registry for the {@link ArgsReader}. - *

The key is the {@link ArgsReader#getClass()} and the value is the {@link ArgsReader}

- */ -public class ArgsReaderRegistry extends Registry>, ArgsReader> { - - public static final ArgsReaderRegistry INSTANCE = new ArgsReaderRegistry(); - - static { - INSTANCE.add(new StringReader()); - INSTANCE.add(new ByteReader()); - INSTANCE.add(new ByteArrayReader()); - INSTANCE.add(new ShortReader()); - INSTANCE.add(new ShortArrayReader()); - INSTANCE.add(new IntegerReader()); - INSTANCE.add(new IntegerArrayReader()); - INSTANCE.add(new FloatReader()); - INSTANCE.add(new FloatArrayReader()); - INSTANCE.add(new DoubleReader()); - INSTANCE.add(new DoubleArrayReader()); - INSTANCE.add(new BigIntegerArgsReader()); - INSTANCE.add(new BigDecimalArgsReader()); - INSTANCE.add(new UUIDReader()); - INSTANCE.add(new BooleanReader()); - INSTANCE.add(new DateReader()); - } - - private ArgsReaderRegistry() { - } - - @SuppressWarnings("unchecked") - public void add(ArgsReader reader) { - put((Class>) reader.getClass(), reader); - } - - /** - * Gets the first reader that can read the specified type - * @param type the type - * @return the reader - */ - public ArgsReader getReader(Class type) { - for (ArgsReader reader : getMap().values()) - if (reader.getTypes().contains(type)) - return reader; - return null; - } -} diff --git a/commands/src/main/java/com/wizardlybump17/wlib/command/args/ArgsReaderType.java b/commands/src/main/java/com/wizardlybump17/wlib/command/args/ArgsReaderType.java deleted file mode 100644 index 2e8fc4ca..00000000 --- a/commands/src/main/java/com/wizardlybump17/wlib/command/args/ArgsReaderType.java +++ /dev/null @@ -1,21 +0,0 @@ -package com.wizardlybump17.wlib.command.args; - -import com.wizardlybump17.wlib.command.args.reader.ArgsReader; - -import java.lang.annotation.ElementType; -import java.lang.annotation.Retention; -import java.lang.annotation.RetentionPolicy; -import java.lang.annotation.Target; - -/** - * Specified the {@link ArgsReader} of the parameter - */ -@Target(ElementType.PARAMETER) -@Retention(RetentionPolicy.RUNTIME) -public @interface ArgsReaderType { - - /** - * @return the class of the {@link ArgsReader} to use - */ - Class> value(); -} diff --git a/commands/src/main/java/com/wizardlybump17/wlib/command/args/reader/ArgsReader.java b/commands/src/main/java/com/wizardlybump17/wlib/command/args/reader/ArgsReader.java deleted file mode 100644 index d8a6fa5a..00000000 --- a/commands/src/main/java/com/wizardlybump17/wlib/command/args/reader/ArgsReader.java +++ /dev/null @@ -1,49 +0,0 @@ -package com.wizardlybump17.wlib.command.args.reader; - -import com.wizardlybump17.wlib.command.sender.CommandSender; -import lombok.NonNull; -import org.jetbrains.annotations.Nullable; - -import java.util.Collections; -import java.util.List; - -/** - * Used to read and convert the args from string to the specified type - * @param which type the string will be converted to - */ -public abstract class ArgsReader { - - private List> typesCache; - - /** - *

The type that the string will be converted to.

- *

If it is {@code null} then you should use the {@link com.wizardlybump17.wlib.command.args.ArgsReaderType} annotation on your parameter

- * @return the type that the string will be converted to - * @deprecated Use the {@link #getTypes()} instead - */ - @Nullable - @Deprecated - public abstract Class getType(); - - /** - * @return the types that {@code this} {@link ArgsReader} can accept in the method parameter - */ - public @NonNull List> getTypes() { - if (typesCache == null) - typesCache = Collections.singletonList(getType()); - return typesCache; - } - - public abstract T read(String string) throws ArgsReaderException; - - /** - *

Gives the suggestions for the specified sender and current argument (optional).

- * @param sender who is executing the command - * @param current the current argument - * @return a {@link List} of suggestions - */ - @NonNull - public List<@NonNull String> autoComplete(@NonNull CommandSender sender, @NonNull String current) { - return Collections.emptyList(); - } -} diff --git a/commands/src/main/java/com/wizardlybump17/wlib/command/args/reader/ArgsReaderException.java b/commands/src/main/java/com/wizardlybump17/wlib/command/args/reader/ArgsReaderException.java deleted file mode 100644 index e24704dd..00000000 --- a/commands/src/main/java/com/wizardlybump17/wlib/command/args/reader/ArgsReaderException.java +++ /dev/null @@ -1,16 +0,0 @@ -package com.wizardlybump17.wlib.command.args.reader; - -public class ArgsReaderException extends Exception { - - public ArgsReaderException(String message) { - super(message); - } - - public ArgsReaderException(Throwable cause) { - super(cause); - } - - public ArgsReaderException(String message, Throwable cause) { - super(message, cause); - } -} diff --git a/commands/src/main/java/com/wizardlybump17/wlib/command/args/reader/BigDecimalArgsReader.java b/commands/src/main/java/com/wizardlybump17/wlib/command/args/reader/BigDecimalArgsReader.java deleted file mode 100644 index 638016ba..00000000 --- a/commands/src/main/java/com/wizardlybump17/wlib/command/args/reader/BigDecimalArgsReader.java +++ /dev/null @@ -1,20 +0,0 @@ -package com.wizardlybump17.wlib.command.args.reader; - -import java.math.BigDecimal; - -public class BigDecimalArgsReader extends ArgsReader { - - @Override - public Class getType() { - return BigDecimal.class; - } - - @Override - public BigDecimal read(String string) { - try { - return new BigDecimal(string); - } catch (NumberFormatException e) { - return null; - } - } -} diff --git a/commands/src/main/java/com/wizardlybump17/wlib/command/args/reader/BigIntegerArgsReader.java b/commands/src/main/java/com/wizardlybump17/wlib/command/args/reader/BigIntegerArgsReader.java deleted file mode 100644 index bf39e180..00000000 --- a/commands/src/main/java/com/wizardlybump17/wlib/command/args/reader/BigIntegerArgsReader.java +++ /dev/null @@ -1,20 +0,0 @@ -package com.wizardlybump17.wlib.command.args.reader; - -import java.math.BigInteger; - -public class BigIntegerArgsReader extends ArgsReader { - - @Override - public Class getType() { - return BigInteger.class; - } - - @Override - public BigInteger read(String string) { - try { - return new BigInteger(string); - } catch (NumberFormatException e) { - return null; - } - } -} diff --git a/commands/src/main/java/com/wizardlybump17/wlib/command/args/reader/BooleanReader.java b/commands/src/main/java/com/wizardlybump17/wlib/command/args/reader/BooleanReader.java deleted file mode 100644 index 539558be..00000000 --- a/commands/src/main/java/com/wizardlybump17/wlib/command/args/reader/BooleanReader.java +++ /dev/null @@ -1,37 +0,0 @@ -package com.wizardlybump17.wlib.command.args.reader; - -import com.wizardlybump17.wlib.command.sender.CommandSender; -import lombok.NonNull; - -import java.util.List; - -public class BooleanReader extends ArgsReader { - - public static final @NonNull List> TYPES = List.of(boolean.class, Boolean.class); - public static final List SUGGESTIONS = List.of("true", "false"); - - @Override - public Class getType() { - return boolean.class; - } - - @Override - public @NonNull List> getTypes() { - return TYPES; - } - - @Override - public Boolean read(String string) throws ArgsReaderException { - if (string.equalsIgnoreCase("true")) - return true; - if (string.equalsIgnoreCase("false")) - return false; - - return null; - } - - @Override - public @NonNull List<@NonNull String> autoComplete(@NonNull CommandSender sender, @NonNull String current) { - return SUGGESTIONS; - } -} diff --git a/commands/src/main/java/com/wizardlybump17/wlib/command/args/reader/ByteArrayReader.java b/commands/src/main/java/com/wizardlybump17/wlib/command/args/reader/ByteArrayReader.java deleted file mode 100644 index ed29be28..00000000 --- a/commands/src/main/java/com/wizardlybump17/wlib/command/args/reader/ByteArrayReader.java +++ /dev/null @@ -1,23 +0,0 @@ -package com.wizardlybump17.wlib.command.args.reader; - -public class ByteArrayReader extends ArgsReader { - - @Override - public Class getType() { - return byte[].class; - } - - @Override - public byte[] read(String string) throws ArgsReaderException { - try { - final String[] strings = string.split(" "); - - byte[] result = new byte[strings.length]; - for (int i = 0; i < result.length; i++) - result[i] = Byte.parseByte(strings[i]); - return result; - } catch (NumberFormatException e) { - throw new ArgsReaderException("expected a byte array in string form but got " + string); - } - } -} diff --git a/commands/src/main/java/com/wizardlybump17/wlib/command/args/reader/ByteReader.java b/commands/src/main/java/com/wizardlybump17/wlib/command/args/reader/ByteReader.java deleted file mode 100644 index 00c9056c..00000000 --- a/commands/src/main/java/com/wizardlybump17/wlib/command/args/reader/ByteReader.java +++ /dev/null @@ -1,36 +0,0 @@ -package com.wizardlybump17.wlib.command.args.reader; - -import com.wizardlybump17.wlib.command.sender.CommandSender; -import lombok.NonNull; - -import java.util.List; - -public class ByteReader extends ArgsReader { - - public static final List SUGGESTIONS = List.of("-128", "0", "127"); - public static final @NonNull List> TYPES = List.of(byte.class, Byte.class); - - @Override - public Class getType() { - return byte.class; - } - - @Override - public @NonNull List> getTypes() { - return TYPES; - } - - @Override - public Byte read(String string) throws ArgsReaderException { - try { - return Byte.parseByte(string); - } catch (NumberFormatException e) { - return null; - } - } - - @Override - public @NonNull List<@NonNull String> autoComplete(@NonNull CommandSender sender, @NonNull String current) { - return SUGGESTIONS; - } -} diff --git a/commands/src/main/java/com/wizardlybump17/wlib/command/args/reader/DateReader.java b/commands/src/main/java/com/wizardlybump17/wlib/command/args/reader/DateReader.java deleted file mode 100644 index 70f576eb..00000000 --- a/commands/src/main/java/com/wizardlybump17/wlib/command/args/reader/DateReader.java +++ /dev/null @@ -1,60 +0,0 @@ -package com.wizardlybump17.wlib.command.args.reader; - -import com.github.sisyphsu.dateparser.DateParserUtils; -import lombok.NonNull; -import org.jetbrains.annotations.Nullable; - -import java.time.format.DateTimeParseException; -import java.util.Calendar; -import java.util.Date; -import java.util.HashMap; -import java.util.Map; -import java.util.function.Supplier; - -public class DateReader extends ArgsReader { - - //i could do a dedicated system for this, but this one is simpler and works so idc - public static final @NonNull Map> PROVIDERS = new HashMap<>(); - - static { - PROVIDERS.put("now", Date::new); - PROVIDERS.put("today", () -> getToday().getTime()); - PROVIDERS.put("yesterday", () -> { - Calendar today = getToday(); - today.add(Calendar.DAY_OF_YEAR, -1); - return today.getTime(); - }); - PROVIDERS.put("tomorrow", () -> { - Calendar today = getToday(); - today.add(Calendar.DAY_OF_YEAR, 1); - return today.getTime(); - }); - } - - @Override - public @NonNull Class getType() { - return Date.class; - } - - @Override - public @Nullable Date read(@NonNull String string) { - Supplier provider = PROVIDERS.get(string.toLowerCase()); - if (provider != null) - return provider.get(); - - try { - return DateParserUtils.parseDate(string); - } catch (DateTimeParseException e) { - return null; //i need to rework the command system :C - } - } - - public static @NonNull Calendar getToday() { - Calendar calendar = Calendar.getInstance(); - calendar.set(Calendar.HOUR_OF_DAY, 0); - calendar.set(Calendar.MINUTE, 0); - calendar.set(Calendar.SECOND, 0); - calendar.set(Calendar.MILLISECOND, 0); - return calendar; - } -} diff --git a/commands/src/main/java/com/wizardlybump17/wlib/command/args/reader/DoubleArrayReader.java b/commands/src/main/java/com/wizardlybump17/wlib/command/args/reader/DoubleArrayReader.java deleted file mode 100644 index 7ebd303f..00000000 --- a/commands/src/main/java/com/wizardlybump17/wlib/command/args/reader/DoubleArrayReader.java +++ /dev/null @@ -1,23 +0,0 @@ -package com.wizardlybump17.wlib.command.args.reader; - -public class DoubleArrayReader extends ArgsReader { - - @Override - public Class getType() { - return double[].class; - } - - @Override - public double[] read(String string) throws ArgsReaderException { - try { - final String[] strings = string.split(" "); - - double[] result = new double[strings.length]; - for (int i = 0; i < result.length; i++) - result[i] = Double.parseDouble(strings[i]); - return result; - } catch (NumberFormatException e) { - throw new ArgsReaderException("expected a double array in string form but got " + string); - } - } -} diff --git a/commands/src/main/java/com/wizardlybump17/wlib/command/args/reader/DoubleReader.java b/commands/src/main/java/com/wizardlybump17/wlib/command/args/reader/DoubleReader.java deleted file mode 100644 index b7c4f356..00000000 --- a/commands/src/main/java/com/wizardlybump17/wlib/command/args/reader/DoubleReader.java +++ /dev/null @@ -1,36 +0,0 @@ -package com.wizardlybump17.wlib.command.args.reader; - -import com.wizardlybump17.wlib.command.sender.CommandSender; -import lombok.NonNull; - -import java.util.List; - -public class DoubleReader extends ArgsReader { - - public static final List SUGGESTIONS = List.of("1", "1.5", "10", "10.5"); - public static final @NonNull List> TYPES = List.of(double.class, Double.class); - - @Override - public Class getType() { - return double.class; - } - - @Override - public @NonNull List> getTypes() { - return TYPES; - } - - @Override - public Double read(String string) throws ArgsReaderException { - try { - return Double.parseDouble(string); - } catch (NumberFormatException e) { - return null; - } - } - - @Override - public @NonNull List<@NonNull String> autoComplete(@NonNull CommandSender sender, @NonNull String current) { - return SUGGESTIONS; - } -} diff --git a/commands/src/main/java/com/wizardlybump17/wlib/command/args/reader/FloatArrayReader.java b/commands/src/main/java/com/wizardlybump17/wlib/command/args/reader/FloatArrayReader.java deleted file mode 100644 index bdb28e86..00000000 --- a/commands/src/main/java/com/wizardlybump17/wlib/command/args/reader/FloatArrayReader.java +++ /dev/null @@ -1,23 +0,0 @@ -package com.wizardlybump17.wlib.command.args.reader; - -public class FloatArrayReader extends ArgsReader { - - @Override - public Class getType() { - return float[].class; - } - - @Override - public float[] read(String string) throws ArgsReaderException { - try { - final String[] strings = string.split(" "); - - float[] result = new float[strings.length]; - for (int i = 0; i < result.length; i++) - result[i] = Float.parseFloat(strings[i]); - return result; - } catch (NumberFormatException e) { - throw new ArgsReaderException("expected a float array in string form but got " + string); - } - } -} diff --git a/commands/src/main/java/com/wizardlybump17/wlib/command/args/reader/FloatReader.java b/commands/src/main/java/com/wizardlybump17/wlib/command/args/reader/FloatReader.java deleted file mode 100644 index f90a346a..00000000 --- a/commands/src/main/java/com/wizardlybump17/wlib/command/args/reader/FloatReader.java +++ /dev/null @@ -1,36 +0,0 @@ -package com.wizardlybump17.wlib.command.args.reader; - -import com.wizardlybump17.wlib.command.sender.CommandSender; -import lombok.NonNull; - -import java.util.List; - -public class FloatReader extends ArgsReader { - - public static final List SUGGESTIONS = List.of("1", "1.5", "10", "10.5"); - public static final @NonNull List> TYPES = List.of(float.class, Float.class); - - @Override - public Class getType() { - return float.class; - } - - @Override - public @NonNull List> getTypes() { - return TYPES; - } - - @Override - public Float read(String string) throws ArgsReaderException { - try { - return Float.parseFloat(string); - } catch (NumberFormatException e) { - return null; - } - } - - @Override - public @NonNull List<@NonNull String> autoComplete(@NonNull CommandSender sender, @NonNull String current) { - return SUGGESTIONS; - } -} diff --git a/commands/src/main/java/com/wizardlybump17/wlib/command/args/reader/IntegerArrayReader.java b/commands/src/main/java/com/wizardlybump17/wlib/command/args/reader/IntegerArrayReader.java deleted file mode 100644 index 43f4e59e..00000000 --- a/commands/src/main/java/com/wizardlybump17/wlib/command/args/reader/IntegerArrayReader.java +++ /dev/null @@ -1,23 +0,0 @@ -package com.wizardlybump17.wlib.command.args.reader; - -public class IntegerArrayReader extends ArgsReader { - - @Override - public Class getType() { - return int[].class; - } - - @Override - public int[] read(String string) throws ArgsReaderException { - try { - final String[] strings = string.split(" "); - - int[] result = new int[strings.length]; - for (int i = 0; i < result.length; i++) - result[i] = Integer.parseInt(strings[i]); - return result; - } catch (NumberFormatException e) { - throw new ArgsReaderException("expected a int array in string form but got " + string); - } - } -} diff --git a/commands/src/main/java/com/wizardlybump17/wlib/command/args/reader/IntegerReader.java b/commands/src/main/java/com/wizardlybump17/wlib/command/args/reader/IntegerReader.java deleted file mode 100644 index 5123f358..00000000 --- a/commands/src/main/java/com/wizardlybump17/wlib/command/args/reader/IntegerReader.java +++ /dev/null @@ -1,36 +0,0 @@ -package com.wizardlybump17.wlib.command.args.reader; - -import com.wizardlybump17.wlib.command.sender.CommandSender; -import lombok.NonNull; - -import java.util.List; - -public class IntegerReader extends ArgsReader { - - public static final List SUGGESTIONS = List.of("1", "10", "100"); - public static final @NonNull List> TYPES = List.of(int.class, Integer.class); - - @Override - public Class getType() { - return int.class; - } - - @Override - public @NonNull List> getTypes() { - return TYPES; - } - - @Override - public Integer read(String string) throws ArgsReaderException { - try { - return Integer.parseInt(string); - } catch (NumberFormatException e) { - return null; - } - } - - @Override - public @NonNull List<@NonNull String> autoComplete(@NonNull CommandSender sender, @NonNull String current) { - return SUGGESTIONS; - } -} diff --git a/commands/src/main/java/com/wizardlybump17/wlib/command/args/reader/ShortArrayReader.java b/commands/src/main/java/com/wizardlybump17/wlib/command/args/reader/ShortArrayReader.java deleted file mode 100644 index 62315102..00000000 --- a/commands/src/main/java/com/wizardlybump17/wlib/command/args/reader/ShortArrayReader.java +++ /dev/null @@ -1,23 +0,0 @@ -package com.wizardlybump17.wlib.command.args.reader; - -public class ShortArrayReader extends ArgsReader { - - @Override - public Class getType() { - return short[].class; - } - - @Override - public short[] read(String string) throws ArgsReaderException { - try { - final String[] strings = string.split(" "); - - short[] result = new short[strings.length]; - for (int i = 0; i < result.length; i++) - result[i] = Short.parseShort(strings[i]); - return result; - } catch (NumberFormatException e) { - throw new ArgsReaderException("expected a short array in string form but got " + string); - } - } -} diff --git a/commands/src/main/java/com/wizardlybump17/wlib/command/args/reader/ShortReader.java b/commands/src/main/java/com/wizardlybump17/wlib/command/args/reader/ShortReader.java deleted file mode 100644 index 14e84005..00000000 --- a/commands/src/main/java/com/wizardlybump17/wlib/command/args/reader/ShortReader.java +++ /dev/null @@ -1,36 +0,0 @@ -package com.wizardlybump17.wlib.command.args.reader; - -import com.wizardlybump17.wlib.command.sender.CommandSender; -import lombok.NonNull; - -import java.util.List; - -public class ShortReader extends ArgsReader { - - public static final List SUGGESTIONS = List.of("-32768", "0", "32767"); - public static final @NonNull List> TYPES = List.of(short.class, Short.class); - - @Override - public Class getType() { - return short.class; - } - - @Override - public @NonNull List> getTypes() { - return TYPES; - } - - @Override - public Short read(String string) throws ArgsReaderException { - try { - return Short.parseShort(string); - } catch (NumberFormatException e) { - return null; - } - } - - @Override - public @NonNull List<@NonNull String> autoComplete(@NonNull CommandSender sender, @NonNull String current) { - return SUGGESTIONS; - } -} diff --git a/commands/src/main/java/com/wizardlybump17/wlib/command/args/reader/StringReader.java b/commands/src/main/java/com/wizardlybump17/wlib/command/args/reader/StringReader.java deleted file mode 100644 index 93f2c9c4..00000000 --- a/commands/src/main/java/com/wizardlybump17/wlib/command/args/reader/StringReader.java +++ /dev/null @@ -1,26 +0,0 @@ -package com.wizardlybump17.wlib.command.args.reader; - -import com.wizardlybump17.wlib.command.sender.CommandSender; -import lombok.NonNull; - -import java.util.List; - -public class StringReader extends ArgsReader { - - public static final List SUGGESTIONS = List.of("dummy", "text"); - - @Override - public Class getType() { - return String.class; - } - - @Override - public String read(String string) { - return string; - } - - @Override - public @NonNull List<@NonNull String> autoComplete(@NonNull CommandSender sender, @NonNull String current) { - return SUGGESTIONS; - } -} diff --git a/commands/src/main/java/com/wizardlybump17/wlib/command/args/reader/UUIDReader.java b/commands/src/main/java/com/wizardlybump17/wlib/command/args/reader/UUIDReader.java deleted file mode 100644 index d9f4c7db..00000000 --- a/commands/src/main/java/com/wizardlybump17/wlib/command/args/reader/UUIDReader.java +++ /dev/null @@ -1,31 +0,0 @@ -package com.wizardlybump17.wlib.command.args.reader; - -import com.wizardlybump17.wlib.command.sender.CommandSender; -import lombok.NonNull; - -import java.util.List; -import java.util.UUID; - -public class UUIDReader extends ArgsReader { - - public static final List SUGGESTIONS = List.of("00000000-0000-0000-0000-000000000000"); - - @Override - public Class getType() { - return UUID.class; - } - - @Override - public UUID read(String string) throws ArgsReaderException { - try { - return UUID.fromString(string); - } catch (IllegalArgumentException e) { - return null; - } - } - - @Override - public @NonNull List<@NonNull String> autoComplete(@NonNull CommandSender sender, @NonNull String current) { - return SUGGESTIONS; - } -} diff --git a/commands/src/main/java/com/wizardlybump17/wlib/command/completer/ArgumentCompleter.java b/commands/src/main/java/com/wizardlybump17/wlib/command/completer/ArgumentCompleter.java deleted file mode 100644 index f0145c0d..00000000 --- a/commands/src/main/java/com/wizardlybump17/wlib/command/completer/ArgumentCompleter.java +++ /dev/null @@ -1,12 +0,0 @@ -package com.wizardlybump17.wlib.command.completer; - -import com.wizardlybump17.wlib.command.sender.CommandSender; -import lombok.NonNull; - -import java.util.List; - -public interface ArgumentCompleter { - - @NonNull - List complete(@NonNull CommandSender sender, @NonNull String @NonNull [] args); -} diff --git a/commands/src/main/java/com/wizardlybump17/wlib/command/completer/ArgumentCompleterRegistry.java b/commands/src/main/java/com/wizardlybump17/wlib/command/completer/ArgumentCompleterRegistry.java deleted file mode 100644 index 3758074a..00000000 --- a/commands/src/main/java/com/wizardlybump17/wlib/command/completer/ArgumentCompleterRegistry.java +++ /dev/null @@ -1,11 +0,0 @@ -package com.wizardlybump17.wlib.command.completer; - -import com.wizardlybump17.wlib.object.Registry; - -public class ArgumentCompleterRegistry extends Registry, ArgumentCompleter> { - - public static final ArgumentCompleterRegistry INSTANCE = new ArgumentCompleterRegistry(); - - private ArgumentCompleterRegistry() { - } -} diff --git a/commands/src/main/java/com/wizardlybump17/wlib/command/rework/context/CommandContext.java b/commands/src/main/java/com/wizardlybump17/wlib/command/context/CommandContext.java similarity index 93% rename from commands/src/main/java/com/wizardlybump17/wlib/command/rework/context/CommandContext.java rename to commands/src/main/java/com/wizardlybump17/wlib/command/context/CommandContext.java index cfb11432..5840c35d 100644 --- a/commands/src/main/java/com/wizardlybump17/wlib/command/rework/context/CommandContext.java +++ b/commands/src/main/java/com/wizardlybump17/wlib/command/context/CommandContext.java @@ -1,7 +1,7 @@ -package com.wizardlybump17.wlib.command.rework.context; +package com.wizardlybump17.wlib.command.context; -import com.wizardlybump17.wlib.command.rework.Command; -import com.wizardlybump17.wlib.command.rework.node.CommandNode; +import com.wizardlybump17.wlib.command.Command; +import com.wizardlybump17.wlib.command.node.CommandNode; import com.wizardlybump17.wlib.command.sender.CommandSender; import com.wizardlybump17.wlib.util.MapUtils; import org.jetbrains.annotations.NotNull; diff --git a/commands/src/main/java/com/wizardlybump17/wlib/command/data/AnnotationCommandData.java b/commands/src/main/java/com/wizardlybump17/wlib/command/data/AnnotationCommandData.java deleted file mode 100644 index e45d26f0..00000000 --- a/commands/src/main/java/com/wizardlybump17/wlib/command/data/AnnotationCommandData.java +++ /dev/null @@ -1,100 +0,0 @@ -package com.wizardlybump17.wlib.command.data; - -import com.wizardlybump17.wlib.command.annotation.Command; -import com.wizardlybump17.wlib.util.ReflectionUtil; -import org.jetbrains.annotations.NotNull; -import org.jetbrains.annotations.Nullable; - -import java.lang.reflect.Field; -import java.util.HashMap; -import java.util.Map; -import java.util.Objects; - -public class AnnotationCommandData extends CommandData { - - private final @NotNull Command annotation; - private final @NotNull Object object; - private final @NotNull Map fieldCache = new HashMap<>(); - - public AnnotationCommandData(@NotNull Command annotation, @NotNull Object object) { - this.annotation = annotation; - this.object = object; - } - - @Override - public @NotNull String getExecution() { - return annotation.execution(); - } - - @Override - public @Nullable String getPermission() { - String permission = annotation.permission(); - return permission.isBlank() ? super.getPermission() : permission; - } - - @Override - public @Nullable String getPermissionMessage() { - return getMessage(annotation.permissionMessage(), annotation.permissionMessageIsField(), super.getPermissionMessage()); - } - - @Override - public int getPriority() { - int priority = annotation.priority(); - return priority == -1 ? super.getPriority() : priority; - } - - @Override - public @Nullable String getDescription() { - String description = annotation.description(); - return description.isBlank() ? super.getDescription() : description; - } - - @Override - public @Nullable String getInvalidSenderMessage() { - return getMessage(annotation.invalidSenderMessage(), annotation.invalidSenderMessageIsField(), super.getInvalidSenderMessage()); - } - - protected @Nullable String getMessage(@NotNull String message, boolean isField, @Nullable String defaultMessage) { - if (isField) { - return ReflectionUtil.getFieldValue( - fieldCache.computeIfAbsent( - message, - $ -> ReflectionUtil.getField(message, object.getClass()) - ), - object - ); - } - return message.isBlank() ? defaultMessage : message; - } - - public @NotNull Command getAnnotation() { - return annotation; - } - - @Override - public @NotNull Class getSenderType() { - return annotation.senderType(); - } - - @Override - public boolean equals(Object object1) { - if (object1 == null || getClass() != object1.getClass()) - return false; - AnnotationCommandData that = (AnnotationCommandData) object1; - return Objects.equals(annotation, that.annotation) && Objects.equals(object, that.object) && Objects.equals(fieldCache, that.fieldCache); - } - - @Override - public int hashCode() { - return Objects.hash(annotation, object, fieldCache); - } - - @Override - public String toString() { - return "AnnotationCommandData{" + - "annotation=" + annotation + - ", object=" + object + - ", fieldCache=" + fieldCache + - '}'; - } -} diff --git a/commands/src/main/java/com/wizardlybump17/wlib/command/data/CommandData.java b/commands/src/main/java/com/wizardlybump17/wlib/command/data/CommandData.java deleted file mode 100644 index 9dd74ef5..00000000 --- a/commands/src/main/java/com/wizardlybump17/wlib/command/data/CommandData.java +++ /dev/null @@ -1,81 +0,0 @@ -package com.wizardlybump17.wlib.command.data; - -import com.wizardlybump17.wlib.command.sender.CommandSender; -import org.jetbrains.annotations.NotNull; -import org.jetbrains.annotations.Nullable; - -public abstract class CommandData { - - /** - *

How the sender must type the command in order for it to be triggered. - * Example:

command hello world
- * In the example above, the sender must type /command hello world, so it can be triggered. - * To add parameters that depends on the sender input, just put the parameter between <>. - *
- * Example:
command <hello> world

- *

The type of each parameter is defined in the method that have this annotation. - * An example for the command above: - *

-     *  @Command(execution = "command <hello> world")
-     *  public void commandHelloWorld(GenericSender sender, String hello) {
-     *      System.out.println(sender.getName() + " executed the hello world command with the argument " + hello);
-     *  }
-     * 

- * - * @return how the command must be sent to be triggered - * @see com.wizardlybump17.wlib.command.args.reader.ArgsReader - */ - public abstract @NotNull String getExecution(); - - /** - * @return which permission the sender must have to trigger this command - */ - public @Nullable String getPermission() { - return null; - } - - /** - *

Used when the {@link CommandSender} does not have the required {@link #getPermission()}.

- * @return the message to be sent when the {@link CommandSender} does not have the required {@link #getPermission()} - */ - public @Nullable String getPermissionMessage() { - return null; - } - - /** - * @return the priority of this command - */ - public int getPriority() { - return getExecution().split(" ").length; - } - - /** - * @return the description of this command - */ - public @Nullable String getDescription() { - return null; - } - - /** - *

Used when the {@link CommandSender} is not valid for this command.

- * @return the message to be sent when the {@link CommandSender} is not valid for this command - */ - public @Nullable String getInvalidSenderMessage() { - return null; - } - - public final @NotNull String getName() { - return getExecution().split(" ")[0]; - } - - /** - * @return the {@link CommandSender#getHandle()} that can execute this command - */ - public @NotNull Class getSenderType() { - return Object.class; - } - - public static @NotNull SimpleCommandData.Builder builder() { - return new SimpleCommandData.Builder(); - } -} diff --git a/commands/src/main/java/com/wizardlybump17/wlib/command/data/SimpleCommandData.java b/commands/src/main/java/com/wizardlybump17/wlib/command/data/SimpleCommandData.java deleted file mode 100644 index 66905c05..00000000 --- a/commands/src/main/java/com/wizardlybump17/wlib/command/data/SimpleCommandData.java +++ /dev/null @@ -1,216 +0,0 @@ -package com.wizardlybump17.wlib.command.data; - -import org.jetbrains.annotations.NotNull; -import org.jetbrains.annotations.Nullable; - -import java.util.function.Supplier; - -public class SimpleCommandData extends CommandData { - - private final @NotNull Supplier execution; - private final @NotNull Supplier permission; - private final @NotNull Supplier permissionMessage; - private final @NotNull Supplier priority; - private final @NotNull Supplier description; - private final @NotNull Supplier invalidSenderMessage; - private final @NotNull Supplier> senderType; - - public SimpleCommandData(@NotNull Supplier execution, @NotNull Supplier permission, @NotNull Supplier permissionMessage, @NotNull Supplier priority, @NotNull Supplier description, @NotNull Supplier invalidSenderMessage, @NotNull Supplier> senderType) { - this.execution = execution; - this.permission = permission; - this.permissionMessage = permissionMessage; - this.priority = priority; - this.description = description; - this.invalidSenderMessage = invalidSenderMessage; - this.senderType = senderType; - } - - public SimpleCommandData(@NotNull String execution, @Nullable String permission, @Nullable String permissionMessage, int priority, @Nullable String description, @Nullable String invalidSenderMessage, @NotNull Class senderType) { - this( - () -> execution, - () -> permission, - () -> permissionMessage, - () -> priority, - () -> description, - () -> invalidSenderMessage, - () -> senderType - ); - } - - @Override - public @NotNull String getExecution() { - return execution.get(); - } - - @Override - public @Nullable String getPermission() { - return permission.get(); - } - - @Override - public @Nullable String getPermissionMessage() { - return permissionMessage.get(); - } - - @Override - public int getPriority() { - return priority.get(); - } - - @Override - public @Nullable String getDescription() { - return description.get(); - } - - @Override - public @Nullable String getInvalidSenderMessage() { - return invalidSenderMessage.get(); - } - - @Override - public @NotNull Class getSenderType() { - return senderType.get(); - } - - public static class Builder { - - Builder() { - } - - private @Nullable Supplier execution; - private @Nullable Supplier permission; - private @Nullable Supplier permissionMessage; - private @Nullable Supplier priority; - private @Nullable Supplier description; - private @Nullable Supplier invalidSenderMessage; - private @Nullable Supplier> senderType; - - public @Nullable String execution() { - return execution == null ? null : execution.get(); - } - - public @NotNull Builder execution(@Nullable String execution) { - this.execution = () -> execution; - return this; - } - - public @NotNull Builder execution(@Nullable Supplier execution) { - this.execution = execution; - return this; - } - - public @Nullable String permission() { - return permission == null ? null : permission.get(); - } - - public @NotNull Builder permission(@Nullable String permission) { - this.permission = () -> permission; - return this; - } - - public @NotNull Builder permission(@Nullable Supplier permission) { - this.permission = permission; - return this; - } - - public @Nullable String permissionMessage() { - return permissionMessage == null ? null : permissionMessage.get(); - } - - public @NotNull Builder permissionMessage(@Nullable String permissionMessage) { - this.permissionMessage = () -> permissionMessage; - return this; - } - - public @NotNull Builder permissionMessage(@Nullable Supplier permissionMessage) { - this.permissionMessage = permissionMessage; - return this; - } - - public @Nullable Integer priority() { - return priority == null ? null : priority.get(); - } - - public @NotNull Builder priority(@Nullable Integer priority) { - this.priority = () -> priority; - return this; - } - - public @NotNull Builder priority(@Nullable Supplier priority) { - this.priority = priority; - return this; - } - - public @Nullable String description() { - return description == null ? null : description.get(); - } - - public @NotNull Builder description(@Nullable String description) { - this.description = () -> description; - return this; - } - - public @NotNull Builder description(@Nullable Supplier description) { - this.description = description; - return this; - } - - public @Nullable String invalidSenderMessage() { - return invalidSenderMessage == null ? null : invalidSenderMessage.get(); - } - - public @NotNull Builder invalidSenderMessage(@Nullable String invalidSenderMessage) { - this.invalidSenderMessage = () -> invalidSenderMessage; - return this; - } - - public @NotNull Builder invalidSenderMessage(@Nullable Supplier invalidSenderMessage) { - this.invalidSenderMessage = invalidSenderMessage; - return this; - } - - public @Nullable Class senderType() { - return senderType == null ? null : senderType.get(); - } - - public @NotNull Builder senderType(@Nullable Class senderType) { - this.senderType = () -> senderType; - return this; - } - - public @NotNull Builder senderType(@Nullable Supplier> senderType) { - this.senderType = senderType; - return this; - } - - public @NotNull CommandData build() { - String execution = execution(); - if (execution == null) - throw new NullPointerException("The execution can not be null"); - - String permission = permission(); - String permissionMessage = permissionMessage(); - - Integer priority = priority(); - if (priority == null) - priority = execution.split(" ").length; - - String description = description(); - String invalidSenderMessage = invalidSenderMessage(); - - Class senderType = senderType(); - if (senderType == null) - senderType = Object.class; - - return new SimpleCommandData( - execution, - permission, - permissionMessage, - priority, - description, - invalidSenderMessage, - senderType - ); - } - } -} diff --git a/commands/src/main/java/com/wizardlybump17/wlib/command/exception/CommandException.java b/commands/src/main/java/com/wizardlybump17/wlib/command/exception/CommandException.java deleted file mode 100644 index 7c99b73f..00000000 --- a/commands/src/main/java/com/wizardlybump17/wlib/command/exception/CommandException.java +++ /dev/null @@ -1,21 +0,0 @@ -package com.wizardlybump17.wlib.command.exception; - -import org.jetbrains.annotations.NotNull; - -public class CommandException extends Exception { - - public CommandException() { - } - - public CommandException(@NotNull String message) { - super(message); - } - - public CommandException(@NotNull String message, @NotNull Throwable cause) { - super(message, cause); - } - - public CommandException(@NotNull Throwable cause) { - super(cause); - } -} diff --git a/commands/src/main/java/com/wizardlybump17/wlib/command/rework/exception/InputParsingException.java b/commands/src/main/java/com/wizardlybump17/wlib/command/exception/InputParsingException.java similarity index 83% rename from commands/src/main/java/com/wizardlybump17/wlib/command/rework/exception/InputParsingException.java rename to commands/src/main/java/com/wizardlybump17/wlib/command/exception/InputParsingException.java index 7b29a2aa..9f4c4315 100644 --- a/commands/src/main/java/com/wizardlybump17/wlib/command/rework/exception/InputParsingException.java +++ b/commands/src/main/java/com/wizardlybump17/wlib/command/exception/InputParsingException.java @@ -1,4 +1,4 @@ -package com.wizardlybump17.wlib.command.rework.exception; +package com.wizardlybump17.wlib.command.exception; import org.jetbrains.annotations.NotNull; diff --git a/commands/src/main/java/com/wizardlybump17/wlib/command/rework/exception/InvalidInputException.java b/commands/src/main/java/com/wizardlybump17/wlib/command/exception/InvalidInputException.java similarity index 84% rename from commands/src/main/java/com/wizardlybump17/wlib/command/rework/exception/InvalidInputException.java rename to commands/src/main/java/com/wizardlybump17/wlib/command/exception/InvalidInputException.java index 97ffb499..410fa29e 100644 --- a/commands/src/main/java/com/wizardlybump17/wlib/command/rework/exception/InvalidInputException.java +++ b/commands/src/main/java/com/wizardlybump17/wlib/command/exception/InvalidInputException.java @@ -1,4 +1,4 @@ -package com.wizardlybump17.wlib.command.rework.exception; +package com.wizardlybump17.wlib.command.exception; import org.jetbrains.annotations.NotNull; diff --git a/commands/src/main/java/com/wizardlybump17/wlib/command/executor/CommandExecutor.java b/commands/src/main/java/com/wizardlybump17/wlib/command/executor/CommandExecutor.java deleted file mode 100644 index a0c3720a..00000000 --- a/commands/src/main/java/com/wizardlybump17/wlib/command/executor/CommandExecutor.java +++ /dev/null @@ -1,12 +0,0 @@ -package com.wizardlybump17.wlib.command.executor; - -import com.wizardlybump17.wlib.command.exception.CommandException; -import com.wizardlybump17.wlib.command.sender.CommandSender; -import org.jetbrains.annotations.NotNull; - -import java.util.Map; - -public interface CommandExecutor { - - void execute(@NotNull CommandSender sender, @NotNull Map args) throws CommandException; -} diff --git a/commands/src/main/java/com/wizardlybump17/wlib/command/rework/executor/CommandNodeExecutor.java b/commands/src/main/java/com/wizardlybump17/wlib/command/executor/CommandNodeExecutor.java similarity index 62% rename from commands/src/main/java/com/wizardlybump17/wlib/command/rework/executor/CommandNodeExecutor.java rename to commands/src/main/java/com/wizardlybump17/wlib/command/executor/CommandNodeExecutor.java index 895e5623..7985b2cb 100644 --- a/commands/src/main/java/com/wizardlybump17/wlib/command/rework/executor/CommandNodeExecutor.java +++ b/commands/src/main/java/com/wizardlybump17/wlib/command/executor/CommandNodeExecutor.java @@ -1,7 +1,7 @@ -package com.wizardlybump17.wlib.command.rework.executor; +package com.wizardlybump17.wlib.command.executor; -import com.wizardlybump17.wlib.command.rework.context.CommandContext; -import com.wizardlybump17.wlib.command.rework.result.CommandResult; +import com.wizardlybump17.wlib.command.context.CommandContext; +import com.wizardlybump17.wlib.command.result.CommandResult; import org.jetbrains.annotations.NotNull; public interface CommandNodeExecutor { diff --git a/commands/src/main/java/com/wizardlybump17/wlib/command/extractor/CommandExtractor.java b/commands/src/main/java/com/wizardlybump17/wlib/command/extractor/CommandExtractor.java deleted file mode 100644 index 8f1d4373..00000000 --- a/commands/src/main/java/com/wizardlybump17/wlib/command/extractor/CommandExtractor.java +++ /dev/null @@ -1,13 +0,0 @@ -package com.wizardlybump17.wlib.command.extractor; - -import com.wizardlybump17.wlib.command.CommandManager; -import com.wizardlybump17.wlib.command.holder.CommandHolder; -import com.wizardlybump17.wlib.command.registered.RegisteredCommand; -import org.jetbrains.annotations.NotNull; - -import java.util.List; - -public interface CommandExtractor { - - @NotNull List extract(@NotNull CommandManager manager, @NotNull CommandHolder holder, @NotNull Object object); -} diff --git a/commands/src/main/java/com/wizardlybump17/wlib/command/extractor/DirectCommandExtractor.java b/commands/src/main/java/com/wizardlybump17/wlib/command/extractor/DirectCommandExtractor.java deleted file mode 100644 index bb21f6c5..00000000 --- a/commands/src/main/java/com/wizardlybump17/wlib/command/extractor/DirectCommandExtractor.java +++ /dev/null @@ -1,16 +0,0 @@ -package com.wizardlybump17.wlib.command.extractor; - -import com.wizardlybump17.wlib.command.CommandManager; -import com.wizardlybump17.wlib.command.holder.CommandHolder; -import com.wizardlybump17.wlib.command.registered.RegisteredCommand; -import org.jetbrains.annotations.NotNull; - -import java.util.List; - -public class DirectCommandExtractor implements CommandExtractor { - - @Override - public @NotNull List extract(@NotNull CommandManager manager, @NotNull CommandHolder holder, @NotNull Object object) { - return object instanceof RegisteredCommand command ? List.of(command) : List.of(); - } -} diff --git a/commands/src/main/java/com/wizardlybump17/wlib/command/extractor/MethodCommandExtractor.java b/commands/src/main/java/com/wizardlybump17/wlib/command/extractor/MethodCommandExtractor.java deleted file mode 100644 index 354da31d..00000000 --- a/commands/src/main/java/com/wizardlybump17/wlib/command/extractor/MethodCommandExtractor.java +++ /dev/null @@ -1,44 +0,0 @@ -package com.wizardlybump17.wlib.command.extractor; - -import com.wizardlybump17.wlib.command.CommandManager; -import com.wizardlybump17.wlib.command.annotation.Command; -import com.wizardlybump17.wlib.command.holder.CommandHolder; -import com.wizardlybump17.wlib.command.registered.RegisteredCommand; -import com.wizardlybump17.wlib.command.registered.RegisteredMethodCommand; -import com.wizardlybump17.wlib.command.sender.CommandSender; -import org.jetbrains.annotations.NotNull; - -import java.lang.reflect.Method; -import java.util.ArrayList; -import java.util.List; -import java.util.logging.Level; - -public class MethodCommandExtractor implements CommandExtractor { - - @Override - public @NotNull List extract(@NotNull CommandManager manager, @NotNull CommandHolder holder, @NotNull Object object) { - List commands = new ArrayList<>(); - for (Method method : object.getClass().getDeclaredMethods()) { - if (!method.isAnnotationPresent(Command.class) || method.getParameterCount() == 0 || !CommandSender.class.isAssignableFrom(method.getParameterTypes()[0])) - continue; - - RegisteredMethodCommand command; - try { - command = new RegisteredMethodCommand( - method.getAnnotation(Command.class), - object, - method - ); - } catch (Exception e) { - holder.getLogger().log(Level.SEVERE, "Error while creating a command", e); - continue; - } - - commands.add(command); - com.wizardlybump17.wlib.command.holder.Command holderCommand = holder.getCommand(command.getName()); - if (holderCommand != null) - holderCommand.setExecutor(holderCommand.getDefaultExecutor(manager, command.getName())); - } - return commands; - } -} diff --git a/commands/src/main/java/com/wizardlybump17/wlib/command/holder/Command.java b/commands/src/main/java/com/wizardlybump17/wlib/command/holder/Command.java deleted file mode 100644 index e766809d..00000000 --- a/commands/src/main/java/com/wizardlybump17/wlib/command/holder/Command.java +++ /dev/null @@ -1,19 +0,0 @@ -package com.wizardlybump17.wlib.command.holder; - -import com.wizardlybump17.wlib.command.CommandManager; - -public interface Command { - - void setExecutor(CommandExecutor executor); - - CommandExecutor getExecutor(); - - /** - *

Used by the {@link com.wizardlybump17.wlib.command.CommandManager} when creating a new command.

- *

This is used to set the default command executor.

- * @param manager the command manager - * @param name the command name - * @return the default command executor - */ - CommandExecutor getDefaultExecutor(CommandManager manager, String name); -} diff --git a/commands/src/main/java/com/wizardlybump17/wlib/command/holder/CommandExecutor.java b/commands/src/main/java/com/wizardlybump17/wlib/command/holder/CommandExecutor.java deleted file mode 100644 index 05321945..00000000 --- a/commands/src/main/java/com/wizardlybump17/wlib/command/holder/CommandExecutor.java +++ /dev/null @@ -1,13 +0,0 @@ -package com.wizardlybump17.wlib.command.holder; - -import com.wizardlybump17.wlib.command.args.reader.ArgsReaderException; -import com.wizardlybump17.wlib.command.exception.CommandException; -import com.wizardlybump17.wlib.command.sender.CommandSender; - -/** - * Interface for intercepting commands when they are called - */ -public interface CommandExecutor { - - void execute(CommandSender sender, String commandName, String[] args) throws ArgsReaderException, CommandException; -} diff --git a/commands/src/main/java/com/wizardlybump17/wlib/command/holder/CommandHolder.java b/commands/src/main/java/com/wizardlybump17/wlib/command/holder/CommandHolder.java deleted file mode 100644 index c5c8e0ef..00000000 --- a/commands/src/main/java/com/wizardlybump17/wlib/command/holder/CommandHolder.java +++ /dev/null @@ -1,20 +0,0 @@ -package com.wizardlybump17.wlib.command.holder; - -import lombok.NonNull; -import org.jetbrains.annotations.Nullable; - -import java.util.logging.Logger; - -/** - * Represents something that can hold commands - * @param The holder type - */ -public interface CommandHolder { - - @Nullable Command getCommand(String name); - - @NonNull H getHandle(); - - @NonNull - Logger getLogger(); -} diff --git a/commands/src/main/java/com/wizardlybump17/wlib/command/rework/input/AllowedInputs.java b/commands/src/main/java/com/wizardlybump17/wlib/command/input/AllowedInputs.java similarity index 88% rename from commands/src/main/java/com/wizardlybump17/wlib/command/rework/input/AllowedInputs.java rename to commands/src/main/java/com/wizardlybump17/wlib/command/input/AllowedInputs.java index b9ed89f3..65ce2053 100644 --- a/commands/src/main/java/com/wizardlybump17/wlib/command/rework/input/AllowedInputs.java +++ b/commands/src/main/java/com/wizardlybump17/wlib/command/input/AllowedInputs.java @@ -1,4 +1,4 @@ -package com.wizardlybump17.wlib.command.rework.input; +package com.wizardlybump17.wlib.command.input; import com.wizardlybump17.wlib.command.sender.CommandSender; import org.jetbrains.annotations.NotNull; diff --git a/commands/src/main/java/com/wizardlybump17/wlib/command/rework/input/AllowedNumberInputs.java b/commands/src/main/java/com/wizardlybump17/wlib/command/input/AllowedNumberInputs.java similarity index 99% rename from commands/src/main/java/com/wizardlybump17/wlib/command/rework/input/AllowedNumberInputs.java rename to commands/src/main/java/com/wizardlybump17/wlib/command/input/AllowedNumberInputs.java index fae75c39..fc557477 100644 --- a/commands/src/main/java/com/wizardlybump17/wlib/command/rework/input/AllowedNumberInputs.java +++ b/commands/src/main/java/com/wizardlybump17/wlib/command/input/AllowedNumberInputs.java @@ -1,4 +1,4 @@ -package com.wizardlybump17.wlib.command.rework.input; +package com.wizardlybump17.wlib.command.input; import com.wizardlybump17.wlib.command.sender.CommandSender; import org.jetbrains.annotations.NotNull; diff --git a/commands/src/main/java/com/wizardlybump17/wlib/command/rework/input/LiteralAllowedInput.java b/commands/src/main/java/com/wizardlybump17/wlib/command/input/LiteralAllowedInput.java similarity index 89% rename from commands/src/main/java/com/wizardlybump17/wlib/command/rework/input/LiteralAllowedInput.java rename to commands/src/main/java/com/wizardlybump17/wlib/command/input/LiteralAllowedInput.java index 725599c1..3a7bd726 100644 --- a/commands/src/main/java/com/wizardlybump17/wlib/command/rework/input/LiteralAllowedInput.java +++ b/commands/src/main/java/com/wizardlybump17/wlib/command/input/LiteralAllowedInput.java @@ -1,4 +1,4 @@ -package com.wizardlybump17.wlib.command.rework.input; +package com.wizardlybump17.wlib.command.input; import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.Nullable; diff --git a/commands/src/main/java/com/wizardlybump17/wlib/command/rework/input/RangedAllowedInputs.java b/commands/src/main/java/com/wizardlybump17/wlib/command/input/RangedAllowedInputs.java similarity index 78% rename from commands/src/main/java/com/wizardlybump17/wlib/command/rework/input/RangedAllowedInputs.java rename to commands/src/main/java/com/wizardlybump17/wlib/command/input/RangedAllowedInputs.java index 35ef7af1..2cf43936 100644 --- a/commands/src/main/java/com/wizardlybump17/wlib/command/rework/input/RangedAllowedInputs.java +++ b/commands/src/main/java/com/wizardlybump17/wlib/command/input/RangedAllowedInputs.java @@ -1,4 +1,4 @@ -package com.wizardlybump17.wlib.command.rework.input; +package com.wizardlybump17.wlib.command.input; import org.jetbrains.annotations.NotNull; diff --git a/commands/src/main/java/com/wizardlybump17/wlib/command/rework/manager/CommandManager.java b/commands/src/main/java/com/wizardlybump17/wlib/command/manager/CommandManager.java similarity index 94% rename from commands/src/main/java/com/wizardlybump17/wlib/command/rework/manager/CommandManager.java rename to commands/src/main/java/com/wizardlybump17/wlib/command/manager/CommandManager.java index df210b3f..539ec254 100644 --- a/commands/src/main/java/com/wizardlybump17/wlib/command/rework/manager/CommandManager.java +++ b/commands/src/main/java/com/wizardlybump17/wlib/command/manager/CommandManager.java @@ -1,8 +1,8 @@ -package com.wizardlybump17.wlib.command.rework.manager; +package com.wizardlybump17.wlib.command.manager; -import com.wizardlybump17.wlib.command.rework.Command; -import com.wizardlybump17.wlib.command.rework.node.CommandNode; -import com.wizardlybump17.wlib.command.rework.result.CommandResult; +import com.wizardlybump17.wlib.command.Command; +import com.wizardlybump17.wlib.command.node.CommandNode; +import com.wizardlybump17.wlib.command.result.CommandResult; import com.wizardlybump17.wlib.command.sender.CommandSender; import com.wizardlybump17.wlib.util.StringUtil; import com.wizardlybump17.wlib.util.exception.QuotedStringException; diff --git a/commands/src/main/java/com/wizardlybump17/wlib/command/rework/node/CommandNode.java b/commands/src/main/java/com/wizardlybump17/wlib/command/node/CommandNode.java similarity index 95% rename from commands/src/main/java/com/wizardlybump17/wlib/command/rework/node/CommandNode.java rename to commands/src/main/java/com/wizardlybump17/wlib/command/node/CommandNode.java index 74a5d984..620d54a9 100644 --- a/commands/src/main/java/com/wizardlybump17/wlib/command/rework/node/CommandNode.java +++ b/commands/src/main/java/com/wizardlybump17/wlib/command/node/CommandNode.java @@ -1,9 +1,9 @@ -package com.wizardlybump17.wlib.command.rework.node; +package com.wizardlybump17.wlib.command.node; -import com.wizardlybump17.wlib.command.rework.exception.InputParsingException; -import com.wizardlybump17.wlib.command.rework.exception.InvalidInputException; -import com.wizardlybump17.wlib.command.rework.executor.CommandNodeExecutor; -import com.wizardlybump17.wlib.command.rework.input.AllowedInputs; +import com.wizardlybump17.wlib.command.exception.InputParsingException; +import com.wizardlybump17.wlib.command.exception.InvalidInputException; +import com.wizardlybump17.wlib.command.executor.CommandNodeExecutor; +import com.wizardlybump17.wlib.command.input.AllowedInputs; import com.wizardlybump17.wlib.command.sender.CommandSender; import com.wizardlybump17.wlib.util.CollectionUtil; import org.jetbrains.annotations.NotNull; diff --git a/commands/src/main/java/com/wizardlybump17/wlib/command/rework/node/IntegerCommandNode.java b/commands/src/main/java/com/wizardlybump17/wlib/command/node/IntegerCommandNode.java similarity index 91% rename from commands/src/main/java/com/wizardlybump17/wlib/command/rework/node/IntegerCommandNode.java rename to commands/src/main/java/com/wizardlybump17/wlib/command/node/IntegerCommandNode.java index 77940deb..1025194e 100644 --- a/commands/src/main/java/com/wizardlybump17/wlib/command/rework/node/IntegerCommandNode.java +++ b/commands/src/main/java/com/wizardlybump17/wlib/command/node/IntegerCommandNode.java @@ -1,8 +1,8 @@ -package com.wizardlybump17.wlib.command.rework.node; +package com.wizardlybump17.wlib.command.node; -import com.wizardlybump17.wlib.command.rework.exception.InputParsingException; -import com.wizardlybump17.wlib.command.rework.executor.CommandNodeExecutor; -import com.wizardlybump17.wlib.command.rework.input.AllowedNumberInputs; +import com.wizardlybump17.wlib.command.exception.InputParsingException; +import com.wizardlybump17.wlib.command.executor.CommandNodeExecutor; +import com.wizardlybump17.wlib.command.input.AllowedNumberInputs; import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.Nullable; diff --git a/commands/src/main/java/com/wizardlybump17/wlib/command/rework/node/LiteralCommandNode.java b/commands/src/main/java/com/wizardlybump17/wlib/command/node/LiteralCommandNode.java similarity index 92% rename from commands/src/main/java/com/wizardlybump17/wlib/command/rework/node/LiteralCommandNode.java rename to commands/src/main/java/com/wizardlybump17/wlib/command/node/LiteralCommandNode.java index 5feb641f..bfda9c30 100644 --- a/commands/src/main/java/com/wizardlybump17/wlib/command/rework/node/LiteralCommandNode.java +++ b/commands/src/main/java/com/wizardlybump17/wlib/command/node/LiteralCommandNode.java @@ -1,7 +1,7 @@ -package com.wizardlybump17.wlib.command.rework.node; +package com.wizardlybump17.wlib.command.node; -import com.wizardlybump17.wlib.command.rework.executor.CommandNodeExecutor; -import com.wizardlybump17.wlib.command.rework.input.LiteralAllowedInput; +import com.wizardlybump17.wlib.command.executor.CommandNodeExecutor; +import com.wizardlybump17.wlib.command.input.LiteralAllowedInput; import com.wizardlybump17.wlib.command.sender.CommandSender; import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.Nullable; diff --git a/commands/src/main/java/com/wizardlybump17/wlib/command/registered/RegisteredCommand.java b/commands/src/main/java/com/wizardlybump17/wlib/command/registered/RegisteredCommand.java deleted file mode 100644 index aa31aea1..00000000 --- a/commands/src/main/java/com/wizardlybump17/wlib/command/registered/RegisteredCommand.java +++ /dev/null @@ -1,138 +0,0 @@ -package com.wizardlybump17.wlib.command.registered; - -import com.wizardlybump17.wlib.command.CommandManager; -import com.wizardlybump17.wlib.command.CommandResult; -import com.wizardlybump17.wlib.command.args.ArgsNode; -import com.wizardlybump17.wlib.command.args.reader.ArgsReaderException; -import com.wizardlybump17.wlib.command.data.CommandData; -import com.wizardlybump17.wlib.command.exception.CommandException; -import com.wizardlybump17.wlib.command.executor.CommandExecutor; -import com.wizardlybump17.wlib.command.sender.CommandSender; -import com.wizardlybump17.wlib.util.StringUtil; -import org.jetbrains.annotations.NotNull; - -import java.util.LinkedHashMap; -import java.util.List; -import java.util.Optional; - -public class RegisteredCommand implements Comparable { - - private final @NotNull CommandData command; - private final @NotNull List nodes; - private final @NotNull CommandExecutor executor; - - public RegisteredCommand(@NotNull CommandData command, @NotNull List nodes, @NotNull CommandExecutor executor) { - this.command = command; - this.nodes = nodes; - this.executor = executor; - } - - protected RegisteredCommand(@NotNull CommandData command, @NotNull List nodes) { - this.command = command; - this.nodes = nodes; - executor = createExecutor(); - } - - protected CommandExecutor createExecutor() { - throw new UnsupportedOperationException(); - } - - public String getName() { - return command.getExecution().split(" ")[0]; - } - - @Override - public int compareTo(@NotNull RegisteredCommand o) { - return Integer.compare(o.command.getPriority(), command.getPriority()); - } - - public Optional> parse(String input) throws ArgsReaderException { - List toParse = StringUtil.parseQuotedStrings(input); - - LinkedHashMap result = new LinkedHashMap<>(); - - if (checkNodes(result, toParse)) - return Optional.of(result); - - return Optional.empty(); - } - - protected boolean checkNodes(LinkedHashMap target, List strings) throws ArgsReaderException { - if (nodes.size() > strings.size()) - return false; - - for (int i = 0; i < nodes.size() && i < strings.size(); i++) { - ArgsNode node = nodes.get(i); - if (!node.isUserInput()) { - if (node.getName().equalsIgnoreCase(strings.get(i))) - continue; - return false; - } - - Object parse = node.parse(strings.get(i)); - if (parse != ArgsNode.EMPTY) - target.put(node.getName(), parse); - } - - return true; - } - - public @NotNull CommandResult execute(@NotNull CommandSender sender, @NotNull String string) throws CommandException { - if (!canExecute(sender)) - return CommandResult.INVALID_SENDER; - - String permission = command.getPermission(); - if (permission != null && !sender.hasPermission(permission)) - return CommandResult.PERMISSION_FAIL; - - try { - Optional> parse = parse(string); - if (parse.isEmpty()) - return CommandResult.ARGS_FAIL; - - LinkedHashMap args = parse.get(); - if (!isValidArgs(args)) - return CommandResult.ARGS_FAIL; - - executor.execute(sender, args); - return CommandResult.SUCCESS; - } catch (ArgsReaderException e) { - return CommandResult.EXCEPTION; - } - } - - protected boolean isValidArgs(@NotNull LinkedHashMap args) { - return true; - } - - public boolean canExecute(@NotNull CommandSender sender) { - return command.getSenderType().isInstance(sender.getHandle()); - } - - @Override - public String toString() { - return "RegisteredCommand{" + command.getExecution() + "}"; - } - - public @NotNull CommandData getCommand() { - return command; - } - - public @NotNull CommandExecutor getExecutor() { - return executor; - } - - public @NotNull List getNodes() { - return nodes; - } - - public boolean isOwnedBy(@NotNull Object object) { - return false; - } - - public void onRegister(@NotNull CommandManager manager) { - } - - public void onUnregister(@NotNull CommandManager manager) { - } -} \ No newline at end of file diff --git a/commands/src/main/java/com/wizardlybump17/wlib/command/registered/RegisteredMethodCommand.java b/commands/src/main/java/com/wizardlybump17/wlib/command/registered/RegisteredMethodCommand.java deleted file mode 100644 index 721860f0..00000000 --- a/commands/src/main/java/com/wizardlybump17/wlib/command/registered/RegisteredMethodCommand.java +++ /dev/null @@ -1,123 +0,0 @@ -package com.wizardlybump17.wlib.command.registered; - -import com.wizardlybump17.wlib.command.Argument; -import com.wizardlybump17.wlib.command.Description; -import com.wizardlybump17.wlib.command.annotation.Command; -import com.wizardlybump17.wlib.command.args.ArgsNode; -import com.wizardlybump17.wlib.command.args.ArgsReaderRegistry; -import com.wizardlybump17.wlib.command.args.ArgsReaderType; -import com.wizardlybump17.wlib.command.args.reader.ArgsReader; -import com.wizardlybump17.wlib.command.data.AnnotationCommandData; -import com.wizardlybump17.wlib.command.exception.CommandException; -import com.wizardlybump17.wlib.command.executor.CommandExecutor; -import lombok.Getter; -import org.jetbrains.annotations.NotNull; - -import java.lang.invoke.MethodHandle; -import java.lang.invoke.MethodHandles; -import java.lang.invoke.MethodType; -import java.lang.reflect.Method; -import java.lang.reflect.Parameter; -import java.util.ArrayList; -import java.util.LinkedHashMap; -import java.util.List; - -@Getter -public class RegisteredMethodCommand extends RegisteredCommand { - - private final @NotNull Command annotation; - private final @NotNull Object object; - private final @NotNull Method method; - private final @NotNull MethodHandle methodHandle; - - public RegisteredMethodCommand(@NotNull Command annotation, @NotNull Object object, @NotNull Method method) throws NoSuchMethodException, IllegalAccessException { - super( - new AnnotationCommandData( - annotation, - object - ), - new ArrayList<>() - ); - this.annotation = annotation; - this.object = object; - this.method = method; - methodHandle = MethodHandles.publicLookup().findVirtual(object.getClass(), method.getName(), MethodType.methodType(method.getReturnType(), method.getParameterTypes())); - prepareNodes(); - } - - @Override - protected CommandExecutor createExecutor() { - return (sender, args) -> { - List objects = new ArrayList<>(args.values()); - objects.add(0, object); - objects.add(1, sender); - try { - methodHandle.invokeWithArguments(objects); - } catch (Throwable e) { - throw new CommandException("Error while executing the command " + getCommand().getExecution() + " with the arguments " + args, e); - } - }; - } - - protected void prepareNodes() { - String[] commandArgs = getCommand().getExecution().split(" "); - - Class[] types = method.getParameterTypes(); - Parameter[] parameters = method.getParameters(); - int index = 1; //skipping the first type because of the CommandSender - for (String commandArg : commandArgs) { - if (!isRequiredArgs(commandArg)) { - getNodes().add(new ArgsNode( - commandArg, - false, - null, - null, - false - )); - continue; - } - - Description description = parameters[index].getAnnotation(Description.class); - - ArgsReaderType argsReaderType = parameters[index].getAnnotation(ArgsReaderType.class); - if (argsReaderType == null && Argument.class.isAssignableFrom(types[index])) - throw new IllegalArgumentException("the \"" + commandArg + "\" argument requires the " + ArgsReaderType.class.getName() + " annotation"); - - ArgsReader reader; - if (argsReaderType == null) - reader = ArgsReaderRegistry.INSTANCE.getReader(types[index]); - else - reader = ArgsReaderRegistry.INSTANCE.get(argsReaderType.value()); - if (reader == null) - throw new IllegalArgumentException("no reader found for " + types[index].getName()); - - getNodes().add(new ArgsNode( - trim(commandArg), - true, - reader, - description == null ? null : description.value(), - Argument.class.isAssignableFrom(types[index]) - )); - - index++; - } - } - - @Override - protected boolean isValidArgs(@NotNull LinkedHashMap args) { - return args.size() + 1 == method.getParameterCount(); - } - - @Override - public boolean isOwnedBy(@NotNull Object object) { - return this.object == object; - } - - private static String trim(String string) { - return string.substring(1, string.length() - 1); - } - - private static boolean isRequiredArgs(String string) { - return string.startsWith("<") && string.endsWith(">"); - } -} \ No newline at end of file diff --git a/commands/src/main/java/com/wizardlybump17/wlib/command/rework/result/CommandResult.java b/commands/src/main/java/com/wizardlybump17/wlib/command/result/CommandResult.java similarity index 90% rename from commands/src/main/java/com/wizardlybump17/wlib/command/rework/result/CommandResult.java rename to commands/src/main/java/com/wizardlybump17/wlib/command/result/CommandResult.java index 64f96cb2..ad06b73d 100644 --- a/commands/src/main/java/com/wizardlybump17/wlib/command/rework/result/CommandResult.java +++ b/commands/src/main/java/com/wizardlybump17/wlib/command/result/CommandResult.java @@ -1,10 +1,10 @@ -package com.wizardlybump17.wlib.command.rework.result; +package com.wizardlybump17.wlib.command.result; -import com.wizardlybump17.wlib.command.rework.Command; -import com.wizardlybump17.wlib.command.rework.context.CommandContext; -import com.wizardlybump17.wlib.command.rework.exception.InputParsingException; -import com.wizardlybump17.wlib.command.rework.node.CommandNode; -import com.wizardlybump17.wlib.command.rework.result.error.*; +import com.wizardlybump17.wlib.command.Command; +import com.wizardlybump17.wlib.command.context.CommandContext; +import com.wizardlybump17.wlib.command.exception.InputParsingException; +import com.wizardlybump17.wlib.command.node.CommandNode; +import com.wizardlybump17.wlib.command.result.error.*; import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.Nullable; diff --git a/commands/src/main/java/com/wizardlybump17/wlib/command/rework/result/SuccessResult.java b/commands/src/main/java/com/wizardlybump17/wlib/command/result/SuccessResult.java similarity index 71% rename from commands/src/main/java/com/wizardlybump17/wlib/command/rework/result/SuccessResult.java rename to commands/src/main/java/com/wizardlybump17/wlib/command/result/SuccessResult.java index ffa70de6..49fe0585 100644 --- a/commands/src/main/java/com/wizardlybump17/wlib/command/rework/result/SuccessResult.java +++ b/commands/src/main/java/com/wizardlybump17/wlib/command/result/SuccessResult.java @@ -1,6 +1,6 @@ -package com.wizardlybump17.wlib.command.rework.result; +package com.wizardlybump17.wlib.command.result; -import com.wizardlybump17.wlib.command.rework.node.CommandNode; +import com.wizardlybump17.wlib.command.node.CommandNode; import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.Nullable; diff --git a/commands/src/main/java/com/wizardlybump17/wlib/command/rework/result/error/CommandNodeExecutorNotFoundResult.java b/commands/src/main/java/com/wizardlybump17/wlib/command/result/error/CommandNodeExecutorNotFoundResult.java similarity index 59% rename from commands/src/main/java/com/wizardlybump17/wlib/command/rework/result/error/CommandNodeExecutorNotFoundResult.java rename to commands/src/main/java/com/wizardlybump17/wlib/command/result/error/CommandNodeExecutorNotFoundResult.java index ff946f04..d2cbde76 100644 --- a/commands/src/main/java/com/wizardlybump17/wlib/command/rework/result/error/CommandNodeExecutorNotFoundResult.java +++ b/commands/src/main/java/com/wizardlybump17/wlib/command/result/error/CommandNodeExecutorNotFoundResult.java @@ -1,6 +1,6 @@ -package com.wizardlybump17.wlib.command.rework.result.error; +package com.wizardlybump17.wlib.command.result.error; -import com.wizardlybump17.wlib.command.rework.node.CommandNode; +import com.wizardlybump17.wlib.command.node.CommandNode; import org.jetbrains.annotations.NotNull; public record CommandNodeExecutorNotFoundResult(int lastInputIndex, @NotNull CommandNode lastNode) implements UnsuccessResult { diff --git a/commands/src/main/java/com/wizardlybump17/wlib/command/rework/result/error/CommandNotFoundResult.java b/commands/src/main/java/com/wizardlybump17/wlib/command/result/error/CommandNotFoundResult.java similarity index 83% rename from commands/src/main/java/com/wizardlybump17/wlib/command/rework/result/error/CommandNotFoundResult.java rename to commands/src/main/java/com/wizardlybump17/wlib/command/result/error/CommandNotFoundResult.java index cd083c50..b6392e47 100644 --- a/commands/src/main/java/com/wizardlybump17/wlib/command/rework/result/error/CommandNotFoundResult.java +++ b/commands/src/main/java/com/wizardlybump17/wlib/command/result/error/CommandNotFoundResult.java @@ -1,7 +1,7 @@ -package com.wizardlybump17.wlib.command.rework.result.error; +package com.wizardlybump17.wlib.command.result.error; -import com.wizardlybump17.wlib.command.rework.executor.CommandNodeExecutor; -import com.wizardlybump17.wlib.command.rework.node.CommandNode; +import com.wizardlybump17.wlib.command.executor.CommandNodeExecutor; +import com.wizardlybump17.wlib.command.node.CommandNode; import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.Nullable; diff --git a/commands/src/main/java/com/wizardlybump17/wlib/command/rework/result/error/ExceptionResult.java b/commands/src/main/java/com/wizardlybump17/wlib/command/result/error/ExceptionResult.java similarity index 60% rename from commands/src/main/java/com/wizardlybump17/wlib/command/rework/result/error/ExceptionResult.java rename to commands/src/main/java/com/wizardlybump17/wlib/command/result/error/ExceptionResult.java index 1e3376ab..4137420b 100644 --- a/commands/src/main/java/com/wizardlybump17/wlib/command/rework/result/error/ExceptionResult.java +++ b/commands/src/main/java/com/wizardlybump17/wlib/command/result/error/ExceptionResult.java @@ -1,6 +1,6 @@ -package com.wizardlybump17.wlib.command.rework.result.error; +package com.wizardlybump17.wlib.command.result.error; -import com.wizardlybump17.wlib.command.rework.node.CommandNode; +import com.wizardlybump17.wlib.command.node.CommandNode; import org.jetbrains.annotations.NotNull; public record ExceptionResult(int lastInputIndex, @NotNull CommandNode lastNode, @NotNull Throwable exception) implements UnsuccessResult { diff --git a/commands/src/main/java/com/wizardlybump17/wlib/command/rework/result/error/ExtraArgumentsResult.java b/commands/src/main/java/com/wizardlybump17/wlib/command/result/error/ExtraArgumentsResult.java similarity index 57% rename from commands/src/main/java/com/wizardlybump17/wlib/command/rework/result/error/ExtraArgumentsResult.java rename to commands/src/main/java/com/wizardlybump17/wlib/command/result/error/ExtraArgumentsResult.java index daf0b25d..76f1dcca 100644 --- a/commands/src/main/java/com/wizardlybump17/wlib/command/rework/result/error/ExtraArgumentsResult.java +++ b/commands/src/main/java/com/wizardlybump17/wlib/command/result/error/ExtraArgumentsResult.java @@ -1,6 +1,6 @@ -package com.wizardlybump17.wlib.command.rework.result.error; +package com.wizardlybump17.wlib.command.result.error; -import com.wizardlybump17.wlib.command.rework.node.CommandNode; +import com.wizardlybump17.wlib.command.node.CommandNode; import org.jetbrains.annotations.NotNull; public record ExtraArgumentsResult(int lastInputIndex, @NotNull CommandNode lastNode) implements UnsuccessResult { diff --git a/commands/src/main/java/com/wizardlybump17/wlib/command/rework/result/error/GenericErrorResult.java b/commands/src/main/java/com/wizardlybump17/wlib/command/result/error/GenericErrorResult.java similarity index 78% rename from commands/src/main/java/com/wizardlybump17/wlib/command/rework/result/error/GenericErrorResult.java rename to commands/src/main/java/com/wizardlybump17/wlib/command/result/error/GenericErrorResult.java index 20683167..6605d032 100644 --- a/commands/src/main/java/com/wizardlybump17/wlib/command/rework/result/error/GenericErrorResult.java +++ b/commands/src/main/java/com/wizardlybump17/wlib/command/result/error/GenericErrorResult.java @@ -1,6 +1,6 @@ -package com.wizardlybump17.wlib.command.rework.result.error; +package com.wizardlybump17.wlib.command.result.error; -import com.wizardlybump17.wlib.command.rework.node.CommandNode; +import com.wizardlybump17.wlib.command.node.CommandNode; import org.jetbrains.annotations.NotNull; public record GenericErrorResult(int lastInputIndex, @NotNull CommandNode lastNode, @NotNull String message) implements UnsuccessResult { diff --git a/commands/src/main/java/com/wizardlybump17/wlib/command/rework/result/error/InsufficientArgumentsResult.java b/commands/src/main/java/com/wizardlybump17/wlib/command/result/error/InsufficientArgumentsResult.java similarity index 64% rename from commands/src/main/java/com/wizardlybump17/wlib/command/rework/result/error/InsufficientArgumentsResult.java rename to commands/src/main/java/com/wizardlybump17/wlib/command/result/error/InsufficientArgumentsResult.java index 032114bf..313b6e6c 100644 --- a/commands/src/main/java/com/wizardlybump17/wlib/command/rework/result/error/InsufficientArgumentsResult.java +++ b/commands/src/main/java/com/wizardlybump17/wlib/command/result/error/InsufficientArgumentsResult.java @@ -1,7 +1,7 @@ -package com.wizardlybump17.wlib.command.rework.result.error; +package com.wizardlybump17.wlib.command.result.error; -import com.wizardlybump17.wlib.command.rework.Command; -import com.wizardlybump17.wlib.command.rework.node.CommandNode; +import com.wizardlybump17.wlib.command.Command; +import com.wizardlybump17.wlib.command.node.CommandNode; import org.jetbrains.annotations.NotNull; public record InsufficientArgumentsResult(@NotNull Command command) implements UnsuccessResult { diff --git a/commands/src/main/java/com/wizardlybump17/wlib/command/rework/result/error/NoPermissionResult.java b/commands/src/main/java/com/wizardlybump17/wlib/command/result/error/NoPermissionResult.java similarity index 67% rename from commands/src/main/java/com/wizardlybump17/wlib/command/rework/result/error/NoPermissionResult.java rename to commands/src/main/java/com/wizardlybump17/wlib/command/result/error/NoPermissionResult.java index 804ce428..a82751f1 100644 --- a/commands/src/main/java/com/wizardlybump17/wlib/command/rework/result/error/NoPermissionResult.java +++ b/commands/src/main/java/com/wizardlybump17/wlib/command/result/error/NoPermissionResult.java @@ -1,6 +1,6 @@ -package com.wizardlybump17.wlib.command.rework.result.error; +package com.wizardlybump17.wlib.command.result.error; -import com.wizardlybump17.wlib.command.rework.node.CommandNode; +import com.wizardlybump17.wlib.command.node.CommandNode; import org.jetbrains.annotations.NotNull; public record NoPermissionResult(int lastInputIndex, @NotNull CommandNode lastNode) implements UnsuccessResult { diff --git a/commands/src/main/java/com/wizardlybump17/wlib/command/rework/result/error/OutOfRangeInputResult.java b/commands/src/main/java/com/wizardlybump17/wlib/command/result/error/OutOfRangeInputResult.java similarity index 57% rename from commands/src/main/java/com/wizardlybump17/wlib/command/rework/result/error/OutOfRangeInputResult.java rename to commands/src/main/java/com/wizardlybump17/wlib/command/result/error/OutOfRangeInputResult.java index 14dfc24a..bd6c4a1a 100644 --- a/commands/src/main/java/com/wizardlybump17/wlib/command/rework/result/error/OutOfRangeInputResult.java +++ b/commands/src/main/java/com/wizardlybump17/wlib/command/result/error/OutOfRangeInputResult.java @@ -1,6 +1,6 @@ -package com.wizardlybump17.wlib.command.rework.result.error; +package com.wizardlybump17.wlib.command.result.error; -import com.wizardlybump17.wlib.command.rework.node.CommandNode; +import com.wizardlybump17.wlib.command.node.CommandNode; import org.jetbrains.annotations.NotNull; public record OutOfRangeInputResult(int lastInputIndex, @NotNull CommandNode lastNode) implements UnsuccessResult { diff --git a/commands/src/main/java/com/wizardlybump17/wlib/command/rework/result/error/ParseInputExceptionResult.java b/commands/src/main/java/com/wizardlybump17/wlib/command/result/error/ParseInputExceptionResult.java similarity index 51% rename from commands/src/main/java/com/wizardlybump17/wlib/command/rework/result/error/ParseInputExceptionResult.java rename to commands/src/main/java/com/wizardlybump17/wlib/command/result/error/ParseInputExceptionResult.java index d4842c9b..ece9e883 100644 --- a/commands/src/main/java/com/wizardlybump17/wlib/command/rework/result/error/ParseInputExceptionResult.java +++ b/commands/src/main/java/com/wizardlybump17/wlib/command/result/error/ParseInputExceptionResult.java @@ -1,7 +1,7 @@ -package com.wizardlybump17.wlib.command.rework.result.error; +package com.wizardlybump17.wlib.command.result.error; -import com.wizardlybump17.wlib.command.rework.exception.InputParsingException; -import com.wizardlybump17.wlib.command.rework.node.CommandNode; +import com.wizardlybump17.wlib.command.exception.InputParsingException; +import com.wizardlybump17.wlib.command.node.CommandNode; import org.jetbrains.annotations.NotNull; public record ParseInputExceptionResult(int lastInputIndex, @NotNull CommandNode lastNode, @NotNull InputParsingException exception) implements UnsuccessResult { diff --git a/commands/src/main/java/com/wizardlybump17/wlib/command/rework/result/error/UnsuccessResult.java b/commands/src/main/java/com/wizardlybump17/wlib/command/result/error/UnsuccessResult.java similarity index 71% rename from commands/src/main/java/com/wizardlybump17/wlib/command/rework/result/error/UnsuccessResult.java rename to commands/src/main/java/com/wizardlybump17/wlib/command/result/error/UnsuccessResult.java index 5ba3646a..dd95036b 100644 --- a/commands/src/main/java/com/wizardlybump17/wlib/command/rework/result/error/UnsuccessResult.java +++ b/commands/src/main/java/com/wizardlybump17/wlib/command/result/error/UnsuccessResult.java @@ -1,6 +1,6 @@ -package com.wizardlybump17.wlib.command.rework.result.error; +package com.wizardlybump17.wlib.command.result.error; -import com.wizardlybump17.wlib.command.rework.result.CommandResult; +import com.wizardlybump17.wlib.command.result.CommandResult; import org.jetbrains.annotations.Contract; import org.jetbrains.annotations.Nullable; diff --git a/commands/src/main/java/com/wizardlybump17/wlib/command/rework/annotation/Command.java b/commands/src/main/java/com/wizardlybump17/wlib/command/rework/annotation/Command.java deleted file mode 100644 index 6a65ac55..00000000 --- a/commands/src/main/java/com/wizardlybump17/wlib/command/rework/annotation/Command.java +++ /dev/null @@ -1,15 +0,0 @@ -package com.wizardlybump17.wlib.command.rework.annotation; - -import org.jetbrains.annotations.NotNull; - -import java.lang.annotation.ElementType; -import java.lang.annotation.Retention; -import java.lang.annotation.RetentionPolicy; -import java.lang.annotation.Target; - -@Target(ElementType.METHOD) -@Retention(RetentionPolicy.RUNTIME) -public @interface Command { - - @NotNull String value(); -} diff --git a/commands/src/test/java/com/wizardlybump17/wlib/command/test/rework/CommandTests.java b/commands/src/test/java/com/wizardlybump17/wlib/test/command/CommandTests.java similarity index 94% rename from commands/src/test/java/com/wizardlybump17/wlib/command/test/rework/CommandTests.java rename to commands/src/test/java/com/wizardlybump17/wlib/test/command/CommandTests.java index 83e8d7d7..5ab0bbd1 100644 --- a/commands/src/test/java/com/wizardlybump17/wlib/command/test/rework/CommandTests.java +++ b/commands/src/test/java/com/wizardlybump17/wlib/test/command/CommandTests.java @@ -1,12 +1,12 @@ -package com.wizardlybump17.wlib.command.test.rework; - -import com.wizardlybump17.wlib.command.rework.Command; -import com.wizardlybump17.wlib.command.rework.exception.InputParsingException; -import com.wizardlybump17.wlib.command.rework.input.AllowedNumberInputs; -import com.wizardlybump17.wlib.command.rework.node.IntegerCommandNode; -import com.wizardlybump17.wlib.command.rework.node.LiteralCommandNode; -import com.wizardlybump17.wlib.command.rework.result.CommandResult; -import com.wizardlybump17.wlib.command.rework.result.error.*; +package com.wizardlybump17.wlib.test.command; + +import com.wizardlybump17.wlib.command.Command; +import com.wizardlybump17.wlib.command.exception.InputParsingException; +import com.wizardlybump17.wlib.command.input.AllowedNumberInputs; +import com.wizardlybump17.wlib.command.node.IntegerCommandNode; +import com.wizardlybump17.wlib.command.node.LiteralCommandNode; +import com.wizardlybump17.wlib.command.result.CommandResult; +import com.wizardlybump17.wlib.command.result.error.*; import com.wizardlybump17.wlib.command.sender.BasicCommandSender; import com.wizardlybump17.wlib.command.sender.CommandSender; import org.jetbrains.annotations.NotNull; diff --git a/commands/src/test/java/com/wizardlybump17/wlib/command/test/rework/SuggestionTests.java b/commands/src/test/java/com/wizardlybump17/wlib/test/command/SuggestionTests.java similarity index 94% rename from commands/src/test/java/com/wizardlybump17/wlib/command/test/rework/SuggestionTests.java rename to commands/src/test/java/com/wizardlybump17/wlib/test/command/SuggestionTests.java index eec3cbac..85613164 100644 --- a/commands/src/test/java/com/wizardlybump17/wlib/command/test/rework/SuggestionTests.java +++ b/commands/src/test/java/com/wizardlybump17/wlib/test/command/SuggestionTests.java @@ -1,10 +1,10 @@ -package com.wizardlybump17.wlib.command.test.rework; +package com.wizardlybump17.wlib.test.command; -import com.wizardlybump17.wlib.command.rework.Command; -import com.wizardlybump17.wlib.command.rework.input.AllowedNumberInputs; -import com.wizardlybump17.wlib.command.rework.node.IntegerCommandNode; -import com.wizardlybump17.wlib.command.rework.node.LiteralCommandNode; -import com.wizardlybump17.wlib.command.rework.result.CommandResult; +import com.wizardlybump17.wlib.command.Command; +import com.wizardlybump17.wlib.command.input.AllowedNumberInputs; +import com.wizardlybump17.wlib.command.node.IntegerCommandNode; +import com.wizardlybump17.wlib.command.node.LiteralCommandNode; +import com.wizardlybump17.wlib.command.result.CommandResult; import com.wizardlybump17.wlib.command.sender.BasicCommandSender; import com.wizardlybump17.wlib.command.sender.CommandSender; import org.jetbrains.annotations.NotNull; diff --git a/commands/src/test/java/com/wizardlybump17/wlib/command/test/rework/manager/CommandManagerSuggestionTests.java b/commands/src/test/java/com/wizardlybump17/wlib/test/command/manager/CommandManagerSuggestionTests.java similarity index 98% rename from commands/src/test/java/com/wizardlybump17/wlib/command/test/rework/manager/CommandManagerSuggestionTests.java rename to commands/src/test/java/com/wizardlybump17/wlib/test/command/manager/CommandManagerSuggestionTests.java index 96ad4b3a..16ca8ce0 100644 --- a/commands/src/test/java/com/wizardlybump17/wlib/command/test/rework/manager/CommandManagerSuggestionTests.java +++ b/commands/src/test/java/com/wizardlybump17/wlib/test/command/manager/CommandManagerSuggestionTests.java @@ -1,11 +1,11 @@ -package com.wizardlybump17.wlib.command.test.rework.manager; - -import com.wizardlybump17.wlib.command.rework.Command; -import com.wizardlybump17.wlib.command.rework.input.AllowedNumberInputs; -import com.wizardlybump17.wlib.command.rework.manager.CommandManager; -import com.wizardlybump17.wlib.command.rework.node.IntegerCommandNode; -import com.wizardlybump17.wlib.command.rework.node.LiteralCommandNode; -import com.wizardlybump17.wlib.command.rework.result.CommandResult; +package com.wizardlybump17.wlib.test.command.manager; + +import com.wizardlybump17.wlib.command.Command; +import com.wizardlybump17.wlib.command.input.AllowedNumberInputs; +import com.wizardlybump17.wlib.command.manager.CommandManager; +import com.wizardlybump17.wlib.command.node.IntegerCommandNode; +import com.wizardlybump17.wlib.command.node.LiteralCommandNode; +import com.wizardlybump17.wlib.command.result.CommandResult; import com.wizardlybump17.wlib.command.sender.BasicCommandSender; import com.wizardlybump17.wlib.command.sender.CommandSender; import com.wizardlybump17.wlib.util.CollectionUtil; diff --git a/commands/src/test/java/com/wizardlybump17/wlib/command/test/rework/manager/CommandManagerTests.java b/commands/src/test/java/com/wizardlybump17/wlib/test/command/manager/CommandManagerTests.java similarity index 96% rename from commands/src/test/java/com/wizardlybump17/wlib/command/test/rework/manager/CommandManagerTests.java rename to commands/src/test/java/com/wizardlybump17/wlib/test/command/manager/CommandManagerTests.java index 0a12c41b..c047c6e1 100644 --- a/commands/src/test/java/com/wizardlybump17/wlib/command/test/rework/manager/CommandManagerTests.java +++ b/commands/src/test/java/com/wizardlybump17/wlib/test/command/manager/CommandManagerTests.java @@ -1,12 +1,12 @@ -package com.wizardlybump17.wlib.command.test.rework.manager; - -import com.wizardlybump17.wlib.command.rework.Command; -import com.wizardlybump17.wlib.command.rework.executor.CommandNodeExecutor; -import com.wizardlybump17.wlib.command.rework.manager.CommandManager; -import com.wizardlybump17.wlib.command.rework.node.LiteralCommandNode; -import com.wizardlybump17.wlib.command.rework.result.CommandResult; -import com.wizardlybump17.wlib.command.rework.result.SuccessResult; -import com.wizardlybump17.wlib.command.rework.result.error.CommandNotFoundResult; +package com.wizardlybump17.wlib.test.command.manager; + +import com.wizardlybump17.wlib.command.Command; +import com.wizardlybump17.wlib.command.executor.CommandNodeExecutor; +import com.wizardlybump17.wlib.command.manager.CommandManager; +import com.wizardlybump17.wlib.command.node.LiteralCommandNode; +import com.wizardlybump17.wlib.command.result.CommandResult; +import com.wizardlybump17.wlib.command.result.SuccessResult; +import com.wizardlybump17.wlib.command.result.error.CommandNotFoundResult; import com.wizardlybump17.wlib.command.sender.BasicCommandSender; import com.wizardlybump17.wlib.command.sender.CommandSender; import org.jetbrains.annotations.NotNull; diff --git a/commands/src/test/java/com/wizardlybump17/wlib/command/test/sender/BasicCommandSenderTests.java b/commands/src/test/java/com/wizardlybump17/wlib/test/command/sender/BasicCommandSenderTests.java similarity index 98% rename from commands/src/test/java/com/wizardlybump17/wlib/command/test/sender/BasicCommandSenderTests.java rename to commands/src/test/java/com/wizardlybump17/wlib/test/command/sender/BasicCommandSenderTests.java index 6c66a360..c19eef75 100644 --- a/commands/src/test/java/com/wizardlybump17/wlib/command/test/sender/BasicCommandSenderTests.java +++ b/commands/src/test/java/com/wizardlybump17/wlib/test/command/sender/BasicCommandSenderTests.java @@ -1,4 +1,4 @@ -package com.wizardlybump17.wlib.command.test.sender; +package com.wizardlybump17.wlib.test.command.sender; import com.wizardlybump17.wlib.command.sender.BasicCommandSender; import org.junit.jupiter.api.Assertions; diff --git a/core/src/main/java/com/wizardlybump17/wlib/WLib.java b/core/src/main/java/com/wizardlybump17/wlib/WLib.java index 56079ba8..c02b83ca 100644 --- a/core/src/main/java/com/wizardlybump17/wlib/WLib.java +++ b/core/src/main/java/com/wizardlybump17/wlib/WLib.java @@ -4,8 +4,6 @@ import com.wizardlybump17.wlib.adapter.ItemAdapter; import com.wizardlybump17.wlib.adapter.command.CommandMapAdapter; import com.wizardlybump17.wlib.adapter.player.PlayerAdapter; -import com.wizardlybump17.wlib.command.args.ArgsReaderRegistry; -import com.wizardlybump17.wlib.command.reader.*; import com.wizardlybump17.wlib.config.holder.BukkitConfigHolderFactory; import com.wizardlybump17.wlib.config.registry.ConfigHandlerRegistry; import com.wizardlybump17.wlib.config.registry.ConfigHolderFactoryRegistry; @@ -78,15 +76,6 @@ public void onDisable() { } private void initCommandSystem() { - ArgsReaderRegistry.INSTANCE.add(new PlayerReader()); - ArgsReaderRegistry.INSTANCE.add(new OfflinePlayerReader()); - ArgsReaderRegistry.INSTANCE.add(new EntityTypeArgsReader()); - ArgsReaderRegistry.INSTANCE.add(new MaterialReader()); - ArgsReaderRegistry.INSTANCE.add(new BlockDataArgsReader()); - ArgsReaderRegistry.INSTANCE.add(new MapJsonArgsReader()); - ArgsReaderRegistry.INSTANCE.add(new PotionEffectTypeReader()); - ArgsReaderRegistry.INSTANCE.add(new EnchantmentReader()); - ArgsReaderRegistry.INSTANCE.add(new NamespacedKeyReader()); } private void initSerializables() { diff --git a/core/src/main/java/com/wizardlybump17/wlib/command/BukkitCommandExecutor.java b/core/src/main/java/com/wizardlybump17/wlib/command/BukkitCommandExecutor.java deleted file mode 100644 index c878081f..00000000 --- a/core/src/main/java/com/wizardlybump17/wlib/command/BukkitCommandExecutor.java +++ /dev/null @@ -1,41 +0,0 @@ -package com.wizardlybump17.wlib.command; - -import com.wizardlybump17.wlib.command.exception.CommandException; -import com.wizardlybump17.wlib.command.sender.BukkitCommandSender; -import com.wizardlybump17.wlib.command.sender.CommandSender; -import lombok.RequiredArgsConstructor; -import org.bukkit.command.Command; -import org.bukkit.command.TabExecutor; -import org.jetbrains.annotations.NotNull; -import org.jetbrains.annotations.Nullable; - -import java.util.List; -import java.util.logging.Level; - -@RequiredArgsConstructor -public class BukkitCommandExecutor implements TabExecutor, com.wizardlybump17.wlib.command.holder.CommandExecutor { - - private final CommandManager manager; - - @Override - public boolean onCommand(@NotNull org.bukkit.command.CommandSender sender, @NotNull Command command, @NotNull String label, String[] args) { - try { - execute(new BukkitCommandSender(sender), command.getName(), args); - } catch (CommandException e) { - manager.getHolder().getLogger().log(Level.SEVERE, "Error while executing a command", e); - } - return false; - } - - @Override - public void execute(CommandSender sender, String commandName, String[] args) throws CommandException { - String commandExecution = commandName + " " + String.join(" ", args); - manager.execute(sender, commandExecution); - } - - @Nullable - @Override - public List onTabComplete(@NotNull org.bukkit.command.CommandSender sender, @NotNull Command command, @NotNull String label, @NotNull String[] args) { - return null; - } -} diff --git a/core/src/main/java/com/wizardlybump17/wlib/command/completer/EntityTypeArgumentCompleter.java b/core/src/main/java/com/wizardlybump17/wlib/command/completer/EntityTypeArgumentCompleter.java deleted file mode 100644 index 2068365d..00000000 --- a/core/src/main/java/com/wizardlybump17/wlib/command/completer/EntityTypeArgumentCompleter.java +++ /dev/null @@ -1,20 +0,0 @@ -package com.wizardlybump17.wlib.command.completer; - -import com.wizardlybump17.wlib.command.sender.CommandSender; -import lombok.NonNull; -import org.bukkit.entity.EntityType; - -import java.util.Arrays; -import java.util.List; - -public class EntityTypeArgumentCompleter implements ArgumentCompleter { - - public static final @NonNull List ENTITIES = Arrays.stream(EntityType.values()) - .map(Enum::name) - .toList(); - - @Override - public @NonNull List complete(@NonNull CommandSender sender, @NonNull String @NonNull [] args) { - return ENTITIES; - } -} diff --git a/core/src/main/java/com/wizardlybump17/wlib/command/completer/MaterialArgumentCompleter.java b/core/src/main/java/com/wizardlybump17/wlib/command/completer/MaterialArgumentCompleter.java deleted file mode 100644 index 8c72508f..00000000 --- a/core/src/main/java/com/wizardlybump17/wlib/command/completer/MaterialArgumentCompleter.java +++ /dev/null @@ -1,20 +0,0 @@ -package com.wizardlybump17.wlib.command.completer; - -import com.wizardlybump17.wlib.command.sender.CommandSender; -import lombok.NonNull; -import org.bukkit.Material; - -import java.util.Arrays; -import java.util.List; - -public class MaterialArgumentCompleter implements ArgumentCompleter { - - public static final List MATERIALS = Arrays.stream(Material.values()) - .map(Enum::name) - .toList(); - - @Override - public @NonNull List complete(@NonNull CommandSender sender, @NonNull String @NonNull [] args) { - return MATERIALS; - } -} diff --git a/core/src/main/java/com/wizardlybump17/wlib/command/completer/PlayerArgumentCompleter.java b/core/src/main/java/com/wizardlybump17/wlib/command/completer/PlayerArgumentCompleter.java deleted file mode 100644 index 29145e42..00000000 --- a/core/src/main/java/com/wizardlybump17/wlib/command/completer/PlayerArgumentCompleter.java +++ /dev/null @@ -1,18 +0,0 @@ -package com.wizardlybump17.wlib.command.completer; - -import com.wizardlybump17.wlib.command.sender.CommandSender; -import lombok.NonNull; -import org.bukkit.Bukkit; -import org.bukkit.entity.Player; - -import java.util.List; - -public class PlayerArgumentCompleter implements ArgumentCompleter { - - @Override - public @NonNull List complete(@NonNull CommandSender sender, @NonNull String @NonNull [] args) { - return Bukkit.getOnlinePlayers().stream() - .map(Player::getName) - .toList(); - } -} diff --git a/core/src/main/java/com/wizardlybump17/wlib/command/holder/BukkitCommand.java b/core/src/main/java/com/wizardlybump17/wlib/command/holder/BukkitCommand.java deleted file mode 100644 index 5b115f0b..00000000 --- a/core/src/main/java/com/wizardlybump17/wlib/command/holder/BukkitCommand.java +++ /dev/null @@ -1,27 +0,0 @@ -package com.wizardlybump17.wlib.command.holder; - -import com.wizardlybump17.wlib.command.BukkitCommandExecutor; -import com.wizardlybump17.wlib.command.CommandManager; -import lombok.Getter; -import lombok.RequiredArgsConstructor; -import org.bukkit.command.PluginCommand; - -@RequiredArgsConstructor -public class BukkitCommand implements Command { - - private final PluginCommand command; - @Getter - private CommandExecutor executor; - - @Override - public void setExecutor(CommandExecutor executor) { - if (executor instanceof org.bukkit.command.CommandExecutor bukkitExecutor) - command.setExecutor(bukkitExecutor); - this.executor = executor; - } - - @Override - public CommandExecutor getDefaultExecutor(CommandManager manager, String name) { - return new BukkitCommandExecutor(manager); - } -} diff --git a/core/src/main/java/com/wizardlybump17/wlib/command/holder/BukkitCommandHolder.java b/core/src/main/java/com/wizardlybump17/wlib/command/holder/BukkitCommandHolder.java deleted file mode 100644 index 0c716fb4..00000000 --- a/core/src/main/java/com/wizardlybump17/wlib/command/holder/BukkitCommandHolder.java +++ /dev/null @@ -1,29 +0,0 @@ -package com.wizardlybump17.wlib.command.holder; - -import lombok.Getter; -import lombok.NonNull; -import lombok.RequiredArgsConstructor; -import org.bukkit.plugin.java.JavaPlugin; - -import java.util.logging.Logger; - -@RequiredArgsConstructor -@Getter -public class BukkitCommandHolder implements CommandHolder { - - private final JavaPlugin handle; - - public static BukkitCommandHolder of(JavaPlugin plugin) { - return new BukkitCommandHolder(plugin); - } - - @Override - public Command getCommand(String name) { - return new BukkitCommand(handle.getCommand(name)); - } - - @Override - public @NonNull Logger getLogger() { - return handle.getLogger(); - } -} diff --git a/core/src/main/java/com/wizardlybump17/wlib/command/reader/BlockDataArgsReader.java b/core/src/main/java/com/wizardlybump17/wlib/command/reader/BlockDataArgsReader.java deleted file mode 100644 index 8b9ca548..00000000 --- a/core/src/main/java/com/wizardlybump17/wlib/command/reader/BlockDataArgsReader.java +++ /dev/null @@ -1,39 +0,0 @@ -package com.wizardlybump17.wlib.command.reader; - -import com.wizardlybump17.wlib.command.args.reader.ArgsReader; -import com.wizardlybump17.wlib.command.args.reader.ArgsReaderException; -import com.wizardlybump17.wlib.command.sender.CommandSender; -import lombok.NonNull; -import org.bukkit.Bukkit; -import org.bukkit.Material; -import org.bukkit.block.data.BlockData; - -import java.util.Arrays; -import java.util.List; - -public class BlockDataArgsReader extends ArgsReader { - - public static final List SUGGESTIONS = Arrays.stream(Material.values()) - .filter(Material::isBlock) - .map(material -> material.createBlockData().getAsString(true)) - .toList(); - - @Override - public Class getType() { - return BlockData.class; - } - - @Override - public BlockData read(String string) throws ArgsReaderException { - try { - return Bukkit.createBlockData(string); - } catch (IllegalArgumentException e) { - throw new ArgsReaderException(e); - } - } - - @Override - public @NonNull List<@NonNull String> autoComplete(@NonNull CommandSender sender, @NonNull String current) { - return SUGGESTIONS; - } -} diff --git a/core/src/main/java/com/wizardlybump17/wlib/command/reader/EnchantmentReader.java b/core/src/main/java/com/wizardlybump17/wlib/command/reader/EnchantmentReader.java deleted file mode 100644 index dcd0d1ad..00000000 --- a/core/src/main/java/com/wizardlybump17/wlib/command/reader/EnchantmentReader.java +++ /dev/null @@ -1,21 +0,0 @@ -package com.wizardlybump17.wlib.command.reader; - -import com.wizardlybump17.wlib.command.args.reader.ArgsReader; -import org.bukkit.NamespacedKey; -import org.bukkit.Registry; -import org.bukkit.enchantments.Enchantment; -import org.jetbrains.annotations.Nullable; - -public class EnchantmentReader extends ArgsReader { - - @Override - public @Nullable Class getType() { - return Enchantment.class; - } - - @Override - public Enchantment read(String string) { - NamespacedKey key = NamespacedKey.fromString(string); - return key == null ? null : Registry.ENCHANTMENT.get(key); - } -} diff --git a/core/src/main/java/com/wizardlybump17/wlib/command/reader/EntityTypeArgsReader.java b/core/src/main/java/com/wizardlybump17/wlib/command/reader/EntityTypeArgsReader.java deleted file mode 100644 index c6986ffb..00000000 --- a/core/src/main/java/com/wizardlybump17/wlib/command/reader/EntityTypeArgsReader.java +++ /dev/null @@ -1,36 +0,0 @@ -package com.wizardlybump17.wlib.command.reader; - -import com.wizardlybump17.wlib.command.args.reader.ArgsReader; -import com.wizardlybump17.wlib.command.sender.CommandSender; -import lombok.NonNull; -import org.bukkit.entity.EntityType; - -import java.util.Arrays; -import java.util.List; - -public class EntityTypeArgsReader extends ArgsReader { - - public static final List SUGGESTIONS = Arrays.stream(EntityType.values()) - .filter(EntityType::isAlive) - .map(EntityType::name) - .toList(); - - @Override - public Class getType() { - return EntityType.class; - } - - @Override - public EntityType read(String string) { - try { - return EntityType.valueOf(string.toUpperCase()); - } catch (IllegalArgumentException e) { - return null; - } - } - - @Override - public @NonNull List<@NonNull String> autoComplete(@NonNull CommandSender sender, @NonNull String current) { - return SUGGESTIONS; - } -} diff --git a/core/src/main/java/com/wizardlybump17/wlib/command/reader/MapJsonArgsReader.java b/core/src/main/java/com/wizardlybump17/wlib/command/reader/MapJsonArgsReader.java deleted file mode 100644 index d7c82251..00000000 --- a/core/src/main/java/com/wizardlybump17/wlib/command/reader/MapJsonArgsReader.java +++ /dev/null @@ -1,38 +0,0 @@ -package com.wizardlybump17.wlib.command.reader; - -import com.google.gson.Gson; -import com.google.gson.JsonSyntaxException; -import com.wizardlybump17.wlib.command.args.reader.ArgsReader; -import com.wizardlybump17.wlib.command.args.reader.ArgsReaderException; -import com.wizardlybump17.wlib.command.sender.CommandSender; -import lombok.NonNull; - -import java.util.List; -import java.util.Map; - -public class MapJsonArgsReader extends ArgsReader> { - - public static final List SUGGESTIONS = List.of("{key=value,key2=value2}"); - - private final Gson gson = new Gson(); - - @Override - public Class> getType() { - return null; - } - - @SuppressWarnings("unchecked") - @Override - public Map read(String string) throws ArgsReaderException { - try { - return gson.fromJson(string, Map.class); - } catch (JsonSyntaxException exception) { - throw new ArgsReaderException("expected a valid JSON", exception); - } - } - - @Override - public @NonNull List<@NonNull String> autoComplete(@NonNull CommandSender sender, @NonNull String current) { - return SUGGESTIONS; - } -} diff --git a/core/src/main/java/com/wizardlybump17/wlib/command/reader/MaterialReader.java b/core/src/main/java/com/wizardlybump17/wlib/command/reader/MaterialReader.java deleted file mode 100644 index 2daf7f90..00000000 --- a/core/src/main/java/com/wizardlybump17/wlib/command/reader/MaterialReader.java +++ /dev/null @@ -1,29 +0,0 @@ -package com.wizardlybump17.wlib.command.reader; - -import com.wizardlybump17.wlib.command.args.reader.ArgsReader; -import com.wizardlybump17.wlib.command.sender.CommandSender; -import lombok.NonNull; -import org.bukkit.Material; - -import java.util.Arrays; -import java.util.List; - -public class MaterialReader extends ArgsReader { - - public static final List SUGGESTION = Arrays.stream(Material.values()).map(Material::name).toList(); - - @Override - public Class getType() { - return Material.class; - } - - @Override - public Material read(String string) { - return Material.matchMaterial(string); - } - - @Override - public @NonNull List<@NonNull String> autoComplete(@NonNull CommandSender sender, @NonNull String current) { - return SUGGESTION; - } -} diff --git a/core/src/main/java/com/wizardlybump17/wlib/command/reader/NamespacedKeyReader.java b/core/src/main/java/com/wizardlybump17/wlib/command/reader/NamespacedKeyReader.java deleted file mode 100644 index 82154cc5..00000000 --- a/core/src/main/java/com/wizardlybump17/wlib/command/reader/NamespacedKeyReader.java +++ /dev/null @@ -1,29 +0,0 @@ -package com.wizardlybump17.wlib.command.reader; - -import com.wizardlybump17.wlib.command.args.reader.ArgsReader; -import com.wizardlybump17.wlib.command.sender.CommandSender; -import lombok.NonNull; -import org.bukkit.NamespacedKey; -import org.jetbrains.annotations.NotNull; - -import java.util.List; - -public class NamespacedKeyReader extends ArgsReader { - - private static final @NotNull List SUGGESTIONS = List.of("key", "namespace:key"); - - @Override - public @NotNull Class getType() { - return NamespacedKey.class; - } - - @Override - public NamespacedKey read(String string) { - return NamespacedKey.fromString(string.toLowerCase()); - } - - @Override - public @NonNull List<@NonNull String> autoComplete(@NonNull CommandSender sender, @NonNull String current) { - return SUGGESTIONS; - } -} diff --git a/core/src/main/java/com/wizardlybump17/wlib/command/reader/OfflinePlayerReader.java b/core/src/main/java/com/wizardlybump17/wlib/command/reader/OfflinePlayerReader.java deleted file mode 100644 index 46c29ea4..00000000 --- a/core/src/main/java/com/wizardlybump17/wlib/command/reader/OfflinePlayerReader.java +++ /dev/null @@ -1,47 +0,0 @@ -package com.wizardlybump17.wlib.command.reader; - -import com.wizardlybump17.wlib.command.args.reader.ArgsReader; -import com.wizardlybump17.wlib.command.sender.CommandSender; -import lombok.NonNull; -import org.bukkit.Bukkit; -import org.bukkit.OfflinePlayer; -import org.bukkit.entity.Player; - -import java.util.ArrayList; -import java.util.List; -import java.util.UUID; - -public class OfflinePlayerReader extends ArgsReader { - - @Override - public Class getType() { - return OfflinePlayer.class; - } - - @Override - public OfflinePlayer read(String string) { - Player player = Bukkit.getPlayerExact(string); - if (player != null) - return player; - - try { - UUID uuid = UUID.fromString(string); - return Bukkit.getOfflinePlayer(uuid); - } catch (IllegalArgumentException ignored) { - for (OfflinePlayer offlinePlayer : Bukkit.getOfflinePlayers()) - if (string.equalsIgnoreCase(offlinePlayer.getName())) - return offlinePlayer; - } - - return null; - } - - @Override - public @NonNull List<@NonNull String> autoComplete(@NonNull CommandSender sender, @NonNull String current) { - OfflinePlayer[] players = Bukkit.getOfflinePlayers(); - List suggestions = new ArrayList<>(players.length); - for (OfflinePlayer player : players) - suggestions.add(player.getName()); - return suggestions; - } -} diff --git a/core/src/main/java/com/wizardlybump17/wlib/command/reader/PlayerReader.java b/core/src/main/java/com/wizardlybump17/wlib/command/reader/PlayerReader.java deleted file mode 100644 index 1521ff37..00000000 --- a/core/src/main/java/com/wizardlybump17/wlib/command/reader/PlayerReader.java +++ /dev/null @@ -1,33 +0,0 @@ -package com.wizardlybump17.wlib.command.reader; - -import com.wizardlybump17.wlib.command.args.reader.ArgsReader; -import com.wizardlybump17.wlib.command.sender.CommandSender; -import lombok.NonNull; -import org.bukkit.Bukkit; -import org.bukkit.entity.Player; - -import java.util.ArrayList; -import java.util.Collection; -import java.util.List; - -public class PlayerReader extends ArgsReader { - - @Override - public Class getType() { - return Player.class; - } - - @Override - public Player read(String string) { - return Bukkit.getPlayerExact(string); - } - - @Override - public @NonNull List<@NonNull String> autoComplete(@NonNull CommandSender sender, @NonNull String current) { - Collection players = Bukkit.getOnlinePlayers(); - List suggestions = new ArrayList<>(players.size()); - for (Player player : players) - suggestions.add(player.getName()); - return suggestions; - } -} diff --git a/core/src/main/java/com/wizardlybump17/wlib/command/reader/PotionEffectTypeReader.java b/core/src/main/java/com/wizardlybump17/wlib/command/reader/PotionEffectTypeReader.java deleted file mode 100644 index f6454523..00000000 --- a/core/src/main/java/com/wizardlybump17/wlib/command/reader/PotionEffectTypeReader.java +++ /dev/null @@ -1,21 +0,0 @@ -package com.wizardlybump17.wlib.command.reader; - -import com.wizardlybump17.wlib.command.args.reader.ArgsReader; -import org.bukkit.NamespacedKey; -import org.bukkit.Registry; -import org.bukkit.potion.PotionEffectType; -import org.jetbrains.annotations.Nullable; - -public class PotionEffectTypeReader extends ArgsReader { - - @Override - public @Nullable Class getType() { - return PotionEffectType.class; - } - - @Override - public PotionEffectType read(String string) { - NamespacedKey key = NamespacedKey.fromString(string); - return key == null ? null : Registry.POTION_EFFECT_TYPE.get(key); - } -} diff --git a/core/src/main/java/com/wizardlybump17/wlib/command/registered/RegisteredBukkitCommand.java b/core/src/main/java/com/wizardlybump17/wlib/command/registered/RegisteredBukkitCommand.java deleted file mode 100644 index 46ea8992..00000000 --- a/core/src/main/java/com/wizardlybump17/wlib/command/registered/RegisteredBukkitCommand.java +++ /dev/null @@ -1,59 +0,0 @@ -package com.wizardlybump17.wlib.command.registered; - -import com.wizardlybump17.wlib.adapter.command.CommandMapAdapter; -import com.wizardlybump17.wlib.command.CommandManager; -import com.wizardlybump17.wlib.command.args.ArgsNode; -import com.wizardlybump17.wlib.command.data.CommandData; -import com.wizardlybump17.wlib.command.exception.CommandException; -import com.wizardlybump17.wlib.command.executor.CommandExecutor; -import com.wizardlybump17.wlib.command.sender.BukkitCommandSender; -import org.bukkit.command.Command; -import org.bukkit.command.CommandMap; -import org.bukkit.command.CommandSender; -import org.jetbrains.annotations.NotNull; - -import java.util.List; -import java.util.logging.Level; -import java.util.logging.Logger; - -public class RegisteredBukkitCommand extends RegisteredCommand { - - private final @NotNull String fallback; - - public RegisteredBukkitCommand(@NotNull CommandData command, @NotNull List nodes, @NotNull CommandExecutor executor, @NotNull String fallback) { - super(command, nodes, executor); - this.fallback = fallback; - } - - public @NotNull String getFallback() { - return fallback; - } - - @Override - public void onRegister(@NotNull CommandManager manager) { - CommandMap commandMap = CommandMapAdapter.getInstance().getCommandMap(); - String name = getCommand().getName(); - Logger logger = manager.getHolder().getLogger(); - - commandMap.register(name, fallback, new Command(name) { - @Override - public boolean execute(@NotNull CommandSender sender, @NotNull String label, @NotNull String[] args) { - try { - manager.execute(new BukkitCommandSender(sender), name + " " + String.join(" ", args)); - } catch (CommandException e) { - logger.log(Level.SEVERE, "Error while executing a command.", e); - } - return false; - } - }); - } - - @Override - public void onUnregister(@NotNull CommandManager manager) { - CommandMapAdapter adapter = CommandMapAdapter.getInstance(); - - String name = getCommand().getName(); - adapter.unregisterCommand(name); - adapter.unregisterCommand(fallback + ":" + name); - } -} From dee9ef6a27d10f6d51df00a6e29f23a86187c43c Mon Sep 17 00:00:00 2001 From: WizardlyBump17 Date: Fri, 7 Nov 2025 17:45:29 -0300 Subject: [PATCH 099/363] removed the unused methods --- .../wizardlybump17/wlib/command/Command.java | 102 ------------------ 1 file changed, 102 deletions(-) diff --git a/commands/src/main/java/com/wizardlybump17/wlib/command/Command.java b/commands/src/main/java/com/wizardlybump17/wlib/command/Command.java index 94ec2593..ac5c9f5d 100644 --- a/commands/src/main/java/com/wizardlybump17/wlib/command/Command.java +++ b/commands/src/main/java/com/wizardlybump17/wlib/command/Command.java @@ -4,20 +4,13 @@ import com.wizardlybump17.wlib.command.exception.InputParsingException; import com.wizardlybump17.wlib.command.exception.InvalidInputException; import com.wizardlybump17.wlib.command.executor.CommandNodeExecutor; -import com.wizardlybump17.wlib.command.input.AllowedNumberInputs; import com.wizardlybump17.wlib.command.node.CommandNode; -import com.wizardlybump17.wlib.command.node.IntegerCommandNode; import com.wizardlybump17.wlib.command.node.LiteralCommandNode; import com.wizardlybump17.wlib.command.result.CommandResult; import com.wizardlybump17.wlib.command.sender.CommandSender; import com.wizardlybump17.wlib.util.StringUtil; import org.jetbrains.annotations.NotNull; -import org.jetbrains.annotations.Nullable; -import java.lang.invoke.MethodHandle; -import java.lang.invoke.MethodHandles; -import java.lang.invoke.MethodType; -import java.lang.reflect.Method; import java.util.ArrayList; import java.util.Collection; import java.util.List; @@ -181,23 +174,6 @@ public Command(@NotNull LiteralCommandNode root) { return new Command((LiteralCommandNode) root.merge(other.getRoot())); } - public static @Nullable Command createCommand(@NotNull String execution) { - String[] parts = execution.split(" "); - - LiteralCommandNode lastNode = null; - for (int i = parts.length - 1; i >= 0; i--) { - String part = parts[i]; - if (lastNode == null) { - lastNode = new LiteralCommandNode(part); - continue; - } - - lastNode = new LiteralCommandNode(part, List.of(lastNode)); - } - - return new Command(lastNode); - } - @Override public String toString() { return "Command{" + @@ -217,82 +193,4 @@ public boolean equals(Object o) { public int hashCode() { return Objects.hashCode(root); } - - public static @NotNull Command fromMethod(@NotNull Method method, @NotNull Object object) { - com.wizardlybump17.wlib.command.annotation.Command annotation = method.getDeclaredAnnotation(com.wizardlybump17.wlib.command.annotation.Command.class); - if (annotation == null) - throw new IllegalArgumentException("Method " + method.getName() + " does not have a Command annotation"); - - Class[] parameterTypes = method.getParameterTypes(); - if (parameterTypes.length == 0) - throw new IllegalArgumentException("Method " + method.getName() + " does not have any parameter"); - - if (!parameterTypes[0].equals(CommandContext.class)) - throw new IllegalArgumentException("Method " + method.getName() + "'s first parameter is not a CommandContext"); - - String[] parts = annotation.value().split(" "); - - int parameterIndex = 1; - CommandNode lastNode = null; - for (int i = parts.length - 1; i >= 0; i--) { - String part = parts[i]; - - CommandNodeExecutor executor; - if (i + 1 >= parts.length) { - executor = new CommandNodeExecutor<>() { - @NotNull MethodHandle methodHandle; { - try { - methodHandle = MethodHandles.publicLookup().findVirtual(object.getClass(), method.getName(), MethodType.methodType(method.getReturnType(), method.getParameterTypes())); - } catch (NoSuchMethodException | IllegalAccessException e) { - throw new RuntimeException(e); - } - } - - @SuppressWarnings("unchecked") - @Override - public @NotNull CommandResult execute(@NotNull CommandContext context) { - List arguments = new ArrayList<>(); - - arguments.add(object); - arguments.add(context); - - arguments.addAll(context.arguments().getArguments().values() - .stream() - .filter(argument -> !(argument.node() instanceof LiteralCommandNode)) - .map(CommandContext.CommandNodeArgument::data) - .toList() - ); - - try { - Object invoke = methodHandle.invokeWithArguments(arguments); - return invoke instanceof CommandResult result ? (CommandResult) result : CommandResult.successful(context, invoke); - } catch (Throwable e) { - throw new RuntimeException(e); - } - } - }; - } else { - executor = null; - } - - CommandNode newNode; - - if (part.charAt(0) == '<' && part.charAt(part.length() - 1) == '>') { - String nodeName = part.substring(1, part.length() - 1); - - Class parameterType = parameterTypes[parameterIndex++]; - if (parameterType == int.class || parameterType == Integer.class) - newNode = new IntegerCommandNode(nodeName, lastNode == null ? List.of() : List.of(lastNode), new AllowedNumberInputs.AllowedIntegerInputs.Unlimited(), executor); - else - throw new IllegalArgumentException("Just trying stuff for now. Come back later"); - - } else { - newNode = new LiteralCommandNode(part, lastNode == null ? List.of() : List.of(lastNode), executor); - } - - lastNode = newNode; - } - - return new Command((LiteralCommandNode) lastNode); - } } From 4cc66d15249784d0cdcced9bb3298a8c026c09d0 Mon Sep 17 00:00:00 2001 From: WizardlyBump17 Date: Fri, 7 Nov 2025 17:52:29 -0300 Subject: [PATCH 100/363] registering multiple commands at once --- .../wlib/command/manager/CommandManager.java | 12 +- .../command/manager/CommandManagerTests.java | 111 ++++++++++++++++++ 2 files changed, 119 insertions(+), 4 deletions(-) diff --git a/commands/src/main/java/com/wizardlybump17/wlib/command/manager/CommandManager.java b/commands/src/main/java/com/wizardlybump17/wlib/command/manager/CommandManager.java index 539ec254..448f67e7 100644 --- a/commands/src/main/java/com/wizardlybump17/wlib/command/manager/CommandManager.java +++ b/commands/src/main/java/com/wizardlybump17/wlib/command/manager/CommandManager.java @@ -8,10 +8,7 @@ import com.wizardlybump17.wlib.util.exception.QuotedStringException; import org.jetbrains.annotations.NotNull; -import java.util.HashMap; -import java.util.List; -import java.util.Map; -import java.util.Optional; +import java.util.*; public class CommandManager { @@ -41,6 +38,13 @@ public class CommandManager { return command; } + public @NotNull List registerCommands(@NotNull String identifier, @NotNull List commands) { + List newCommands = new ArrayList<>(commands.size()); + for (Command command : commands) + newCommands.add(registerCommand(identifier, command)); + return newCommands; + } + protected @NotNull Command mergeCommand(@NotNull Command left, @NotNull Command right) { return left.merge(right); } diff --git a/commands/src/test/java/com/wizardlybump17/wlib/test/command/manager/CommandManagerTests.java b/commands/src/test/java/com/wizardlybump17/wlib/test/command/manager/CommandManagerTests.java index c047c6e1..5acc0776 100644 --- a/commands/src/test/java/com/wizardlybump17/wlib/test/command/manager/CommandManagerTests.java +++ b/commands/src/test/java/com/wizardlybump17/wlib/test/command/manager/CommandManagerTests.java @@ -373,4 +373,115 @@ void testSuccess1() { Assertions.assertEquals(expected, actual); } + + @Test + void testRegisterMultipleDifferent0() { + Command command0 = new Command(new LiteralCommandNode("hello0", context -> CommandResult.successful(context, "hello0"), "permission")); + Command command1 = new Command(new LiteralCommandNode("hello1", context -> CommandResult.successful(context, "hello1"), "permission")); + Command command2 = new Command(new LiteralCommandNode("hello2", context -> CommandResult.successful(context, "hello2"), "permission")); + Command command3 = new Command(new LiteralCommandNode("hello3", context -> CommandResult.successful(context, "hello3"), "permission")); + + CommandManager manager = new CommandManager(); + + List expected = List.of(command0, command1, command2, command3); + List actual = manager.registerCommands("test", List.of(command0, command1, command2, command3)); + + Assertions.assertEquals(expected, actual); + } + + @Test + void testRegisterMultipleMerging0() { + CommandNodeExecutor helloExecutor = context -> CommandResult.successful(context, "hello"); + CommandNodeExecutor helloWorldExecutor = context -> CommandResult.successful(context, "hello world"); + CommandNodeExecutor helloWorldHiExecutor = context -> CommandResult.successful(context, "hello world hi"); + + Command command0 = new Command( + new LiteralCommandNode( + "hello", + helloExecutor, + "permission" + ) + ); + Command command1 = new Command( + new LiteralCommandNode( + "hello", + List.of( + new LiteralCommandNode( + "world", + helloWorldExecutor, + "permission" + ) + ), + "permission" + ) + ); + Command command2 = new Command( + new LiteralCommandNode( + "hello", + List.of( + new LiteralCommandNode( + "world", + List.of( + new LiteralCommandNode( + "hi", + helloWorldHiExecutor, + "permission" + ) + ), + "permission" + ) + ), + "permission" + ) + ); + + CommandManager manager = new CommandManager(); + + Command expectedCommand0 = new Command( + new LiteralCommandNode( + "hello", + helloExecutor, + "permission" + ) + ); + Command expectedCommand1 = new Command( + new LiteralCommandNode( + "hello", + List.of( + new LiteralCommandNode( + "world", + helloWorldExecutor, + "permission" + ) + ), + helloExecutor, + "permission" + ) + ); + Command expectedCommand2 = new Command( + new LiteralCommandNode( + "hello", + List.of( + new LiteralCommandNode( + "world", + List.of( + new LiteralCommandNode( + "hi", + helloWorldHiExecutor, + "permission" + ) + ), + helloWorldExecutor, + "permission" + ) + ), + helloExecutor, + "permission" + ) + ); + + List expected = List.of(expectedCommand0, expectedCommand1, expectedCommand2); + List actual = manager.registerCommands("test", List.of(command0, command1, command2)); + Assertions.assertEquals(expected, actual); + } } From 0af367b87e8e3ecdc692642b493c23e0f598230a Mon Sep 17 00:00:00 2001 From: WizardlyBump17 Date: Fri, 7 Nov 2025 17:55:22 -0300 Subject: [PATCH 101/363] added the Command#permission() --- .../com/wizardlybump17/wlib/command/annotation/Command.java | 2 ++ 1 file changed, 2 insertions(+) diff --git a/commands/src/main/java/com/wizardlybump17/wlib/command/annotation/Command.java b/commands/src/main/java/com/wizardlybump17/wlib/command/annotation/Command.java index c2061c85..bdd69c96 100644 --- a/commands/src/main/java/com/wizardlybump17/wlib/command/annotation/Command.java +++ b/commands/src/main/java/com/wizardlybump17/wlib/command/annotation/Command.java @@ -12,4 +12,6 @@ public @interface Command { @NotNull String value(); + + @NotNull String permission() default ""; } From 997843f6c802c6343132bbaad0c2a5f65e55f977 Mon Sep 17 00:00:00 2001 From: WizardlyBump17 Date: Sat, 8 Nov 2025 18:41:05 -0300 Subject: [PATCH 102/363] added the CommandNode#withPermission(String) method --- .../com/wizardlybump17/wlib/command/node/CommandNode.java | 2 ++ .../wizardlybump17/wlib/command/node/IntegerCommandNode.java | 5 +++++ .../wizardlybump17/wlib/command/node/LiteralCommandNode.java | 5 +++++ .../wlib/command/result/error/CommandNotFoundResult.java | 5 +++++ 4 files changed, 17 insertions(+) diff --git a/commands/src/main/java/com/wizardlybump17/wlib/command/node/CommandNode.java b/commands/src/main/java/com/wizardlybump17/wlib/command/node/CommandNode.java index 620d54a9..bbc12adc 100644 --- a/commands/src/main/java/com/wizardlybump17/wlib/command/node/CommandNode.java +++ b/commands/src/main/java/com/wizardlybump17/wlib/command/node/CommandNode.java @@ -124,6 +124,8 @@ public int hashCode() { public abstract @NotNull CommandNode withExecutor(@Nullable CommandNodeExecutor executor); + public abstract @NotNull CommandNode withPermission(@Nullable String permission); + public @NotNull Optional> getChild(@NotNull String name) { for (CommandNode child : children) if (child.getName().equals(name)) diff --git a/commands/src/main/java/com/wizardlybump17/wlib/command/node/IntegerCommandNode.java b/commands/src/main/java/com/wizardlybump17/wlib/command/node/IntegerCommandNode.java index 1025194e..7fc45bba 100644 --- a/commands/src/main/java/com/wizardlybump17/wlib/command/node/IntegerCommandNode.java +++ b/commands/src/main/java/com/wizardlybump17/wlib/command/node/IntegerCommandNode.java @@ -65,4 +65,9 @@ public IntegerCommandNode(@NotNull String name, @NotNull AllowedNumberInputs.All public @NotNull IntegerCommandNode withExecutor(@Nullable CommandNodeExecutor executor) { return new IntegerCommandNode(getName(), getChildren(), getAllowedInputs(), executor, getPermission()); } + + @Override + public @NotNull CommandNode withPermission(@Nullable String permission) { + return new IntegerCommandNode(getName(), getChildren(), getAllowedInputs(), getExecutor(), permission); + } } diff --git a/commands/src/main/java/com/wizardlybump17/wlib/command/node/LiteralCommandNode.java b/commands/src/main/java/com/wizardlybump17/wlib/command/node/LiteralCommandNode.java index bfda9c30..0d53e5dc 100644 --- a/commands/src/main/java/com/wizardlybump17/wlib/command/node/LiteralCommandNode.java +++ b/commands/src/main/java/com/wizardlybump17/wlib/command/node/LiteralCommandNode.java @@ -66,4 +66,9 @@ public LiteralCommandNode(@NotNull String name) { public @NotNull CommandNode withExecutor(@Nullable CommandNodeExecutor executor) { return new LiteralCommandNode(getName(), getChildren(), executor, getPermission()); } + + @Override + public @NotNull CommandNode withPermission(@Nullable String permission) { + return new LiteralCommandNode(getName(), getChildren(), getExecutor(), permission); + } } diff --git a/commands/src/main/java/com/wizardlybump17/wlib/command/result/error/CommandNotFoundResult.java b/commands/src/main/java/com/wizardlybump17/wlib/command/result/error/CommandNotFoundResult.java index b6392e47..0f8207f0 100644 --- a/commands/src/main/java/com/wizardlybump17/wlib/command/result/error/CommandNotFoundResult.java +++ b/commands/src/main/java/com/wizardlybump17/wlib/command/result/error/CommandNotFoundResult.java @@ -41,5 +41,10 @@ private DummyNode() { public @NotNull DummyNode withExecutor(@Nullable CommandNodeExecutor executor) { return this; } + + @Override + public @NotNull CommandNode withPermission(@Nullable String permission) { + return this; + } } } From f2a39ae58be1e55c3cc9a4f6d191b3535c0c0ce1 Mon Sep 17 00:00:00 2001 From: WizardlyBump17 Date: Sun, 9 Nov 2025 16:30:19 -0300 Subject: [PATCH 103/363] added the CommandNode#getFullCommand() method --- .../wlib/command/node/CommandNode.java | 15 +++++++++++++++ 1 file changed, 15 insertions(+) diff --git a/commands/src/main/java/com/wizardlybump17/wlib/command/node/CommandNode.java b/commands/src/main/java/com/wizardlybump17/wlib/command/node/CommandNode.java index bbc12adc..acf7c1fb 100644 --- a/commands/src/main/java/com/wizardlybump17/wlib/command/node/CommandNode.java +++ b/commands/src/main/java/com/wizardlybump17/wlib/command/node/CommandNode.java @@ -120,6 +120,21 @@ public int hashCode() { return Objects.hash(name, children, allowedInputs, executor, permission); } + public @NotNull String getFullCommand() { + StringBuilder builder = new StringBuilder(); + if (this instanceof LiteralCommandNode) + builder.append(name); + else + builder.append('<').append(name).append('>'); + + for (CommandNode child : children) { + builder.append(' '); + builder.append(child.getFullCommand()); + } + + return builder.toString(); + } + public abstract @NotNull CommandNode withChildren(@NotNull List> children); public abstract @NotNull CommandNode withExecutor(@Nullable CommandNodeExecutor executor); From 548e966d2e238ad149354afd4cf138f268fbaa64 Mon Sep 17 00:00:00 2001 From: WizardlyBump17 Date: Sun, 9 Nov 2025 16:30:33 -0300 Subject: [PATCH 104/363] added the Command#getFullCommand() method --- .../main/java/com/wizardlybump17/wlib/command/Command.java | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/commands/src/main/java/com/wizardlybump17/wlib/command/Command.java b/commands/src/main/java/com/wizardlybump17/wlib/command/Command.java index ac5c9f5d..276d8f66 100644 --- a/commands/src/main/java/com/wizardlybump17/wlib/command/Command.java +++ b/commands/src/main/java/com/wizardlybump17/wlib/command/Command.java @@ -193,4 +193,8 @@ public boolean equals(Object o) { public int hashCode() { return Objects.hashCode(root); } + + public @NotNull String getFullCommand() { + return root.getFullCommand(); + } } From 8c342b32c6529ba91546faac1f2c6a11f5a2592c Mon Sep 17 00:00:00 2001 From: WizardlyBump17 Date: Sun, 9 Nov 2025 16:30:45 -0300 Subject: [PATCH 105/363] made the Command be Comparable --- .../java/com/wizardlybump17/wlib/command/Command.java | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/commands/src/main/java/com/wizardlybump17/wlib/command/Command.java b/commands/src/main/java/com/wizardlybump17/wlib/command/Command.java index 276d8f66..beef2cdf 100644 --- a/commands/src/main/java/com/wizardlybump17/wlib/command/Command.java +++ b/commands/src/main/java/com/wizardlybump17/wlib/command/Command.java @@ -16,7 +16,7 @@ import java.util.List; import java.util.Objects; -public class Command { +public class Command implements Comparable { private final @NotNull LiteralCommandNode root; @@ -194,6 +194,13 @@ public int hashCode() { return Objects.hashCode(root); } + @Override + public int compareTo(@NotNull Command other) { + String fullCommand = getFullCommand(); + String otherFullCommand = other.getFullCommand(); + return fullCommand.compareTo(otherFullCommand); + } + public @NotNull String getFullCommand() { return root.getFullCommand(); } From 726fdc088942f5c200df13fbe1b79da75bfce59e Mon Sep 17 00:00:00 2001 From: WizardlyBump17 Date: Sun, 9 Nov 2025 16:31:00 -0300 Subject: [PATCH 106/363] added the invalid sender result --- .../wlib/command/result/CommandResult.java | 9 +++++++++ .../wlib/command/result/error/InvalidSenderResult.java | 8 ++++++++ 2 files changed, 17 insertions(+) create mode 100644 commands/src/main/java/com/wizardlybump17/wlib/command/result/error/InvalidSenderResult.java diff --git a/commands/src/main/java/com/wizardlybump17/wlib/command/result/CommandResult.java b/commands/src/main/java/com/wizardlybump17/wlib/command/result/CommandResult.java index ad06b73d..d8ce73d4 100644 --- a/commands/src/main/java/com/wizardlybump17/wlib/command/result/CommandResult.java +++ b/commands/src/main/java/com/wizardlybump17/wlib/command/result/CommandResult.java @@ -5,6 +5,7 @@ import com.wizardlybump17.wlib.command.exception.InputParsingException; import com.wizardlybump17.wlib.command.node.CommandNode; import com.wizardlybump17.wlib.command.result.error.*; +import com.wizardlybump17.wlib.command.sender.CommandSender; import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.Nullable; @@ -64,6 +65,10 @@ public interface CommandResult { return new CommandNotFoundResult<>(input); } + static @NotNull InvalidSenderResult invalidSender(int lastInputIndex, @NotNull CommandNode lastNode, @NotNull CommandSender sender, @NotNull Class> expectedSender) { + return new InvalidSenderResult<>(lastInputIndex, lastNode, sender, expectedSender); + } + //with context static @NotNull SuccessResult successful(@NotNull CommandContext context, @Nullable T data) { @@ -85,4 +90,8 @@ public interface CommandResult { static @NotNull NoPermissionResult noPermission(@NotNull CommandContext context) { return noPermission(context.lastInputIndex(), context.lastNode()); } + + static @NotNull InvalidSenderResult invalidSender(@NotNull CommandContext context, @NotNull Class> expectedSender) { + return invalidSender(context.lastInputIndex(), context.lastNode(), context.sender(), expectedSender); + } } diff --git a/commands/src/main/java/com/wizardlybump17/wlib/command/result/error/InvalidSenderResult.java b/commands/src/main/java/com/wizardlybump17/wlib/command/result/error/InvalidSenderResult.java new file mode 100644 index 00000000..04ebcf53 --- /dev/null +++ b/commands/src/main/java/com/wizardlybump17/wlib/command/result/error/InvalidSenderResult.java @@ -0,0 +1,8 @@ +package com.wizardlybump17.wlib.command.result.error; + +import com.wizardlybump17.wlib.command.node.CommandNode; +import com.wizardlybump17.wlib.command.sender.CommandSender; +import org.jetbrains.annotations.NotNull; + +public record InvalidSenderResult(int lastInputIndex, @NotNull CommandNode lastNode, @NotNull CommandSender sender, @NotNull Class> expectedSender) implements UnsuccessResult { +} From cd8d0ef045bdf0a1265e4564cfebfd8f14bd376a Mon Sep 17 00:00:00 2001 From: WizardlyBump17 Date: Sun, 9 Nov 2025 16:31:45 -0300 Subject: [PATCH 107/363] creating commands from annotated methods --- .../AbstractMethodCommandNodeExecutor.java | 272 ++++++++++++++++++ .../method/MethodCommandExtractor.java | 139 +++++++++ .../method/MethodCommandNodeExecutor.java | 16 ++ .../method/MethodCommandExtractorTests.java | 77 +++++ 4 files changed, 504 insertions(+) create mode 100644 commands/src/main/java/com/wizardlybump17/wlib/command/extractor/method/AbstractMethodCommandNodeExecutor.java create mode 100644 commands/src/main/java/com/wizardlybump17/wlib/command/extractor/method/MethodCommandExtractor.java create mode 100644 commands/src/main/java/com/wizardlybump17/wlib/command/extractor/method/MethodCommandNodeExecutor.java create mode 100644 commands/src/test/java/com/wizardlybump17/wlib/test/command/extractor/method/MethodCommandExtractorTests.java diff --git a/commands/src/main/java/com/wizardlybump17/wlib/command/extractor/method/AbstractMethodCommandNodeExecutor.java b/commands/src/main/java/com/wizardlybump17/wlib/command/extractor/method/AbstractMethodCommandNodeExecutor.java new file mode 100644 index 00000000..97286797 --- /dev/null +++ b/commands/src/main/java/com/wizardlybump17/wlib/command/extractor/method/AbstractMethodCommandNodeExecutor.java @@ -0,0 +1,272 @@ +package com.wizardlybump17.wlib.command.extractor.method; + +import com.wizardlybump17.wlib.command.context.CommandContext; +import com.wizardlybump17.wlib.command.result.CommandResult; +import org.jetbrains.annotations.NotNull; + +import java.lang.invoke.MethodHandle; +import java.lang.invoke.MethodHandles; +import java.lang.invoke.MethodType; +import java.lang.reflect.Method; +import java.util.ArrayList; +import java.util.List; +import java.util.Objects; + +abstract sealed class AbstractMethodCommandNodeExecutor implements MethodCommandNodeExecutor { + + private final @NotNull Object object; + private final @NotNull MethodHandle methodHandle; + private final @NotNull Method method; + + public AbstractMethodCommandNodeExecutor(@NotNull Object object, @NotNull Method method) { + this.object = object; + try { + this.methodHandle = MethodHandles.publicLookup().findVirtual(object.getClass(), method.getName(), MethodType.methodType(method.getReturnType(), method.getParameterTypes())); + } catch (NoSuchMethodException | IllegalAccessException e) { + throw new IllegalArgumentException(e); + } + this.method = method; + } + + @Override + public @NotNull Object object() { + return object; + } + + @Override + public @NotNull MethodHandle methodHandle() { + return methodHandle; + } + + @Override + public @NotNull Method method() { + return method; + } + + @Override + public boolean equals(Object object1) { + if (object1 == null || getClass() != object1.getClass()) + return false; + AbstractMethodCommandNodeExecutor that = (AbstractMethodCommandNodeExecutor) object1; + return Objects.equals(object, that.object) + && Objects.equals(method, that.method); + } + + @Override + public int hashCode() { + return Objects.hash(object, method); + } + + @Override + public String toString() { + return getClass().getSimpleName() + "{" + + "object=" + object + + ", methodHandle=" + methodHandle + + ", method=" + method + + '}'; + } + + static final class CommandSenderCommandContextExecutor extends AbstractMethodCommandNodeExecutor { + + public CommandSenderCommandContextExecutor(@NotNull Object object, @NotNull Method method) { + super(object, method); + } + + @SuppressWarnings("unchecked") + @Override + public @NotNull CommandResult execute(@NotNull CommandContext context) { + try { + List parameters = new ArrayList<>(); + parameters.add(object()); + parameters.add(context.sender()); + return (CommandResult) methodHandle().invokeWithArguments(parameters); + } catch (Throwable throwable) { + return CommandResult.exceptionally(context, throwable); + } + } + } + + static final class CommandSenderExecutor extends AbstractMethodCommandNodeExecutor { + + public CommandSenderExecutor(@NotNull Object object, @NotNull Method method) { + super(object, method); + } + + @SuppressWarnings("unchecked") + @Override + public @NotNull CommandResult execute(@NotNull CommandContext context) { + try { + List parameters = new ArrayList<>(); + parameters.add(object()); + parameters.add(context.sender()); + return (CommandResult) CommandResult.successful(context, methodHandle().invokeWithArguments(parameters)); + } catch (Throwable throwable) { + return CommandResult.exceptionally(context, throwable); + } + } + } + + static final class CommandContextCommandContextExecutor extends AbstractMethodCommandNodeExecutor { + + public CommandContextCommandContextExecutor(@NotNull Object object, @NotNull Method method) { + super(object, method); + } + + @SuppressWarnings("unchecked") + @Override + public @NotNull CommandResult execute(@NotNull CommandContext context) { + try { + List parameters = new ArrayList<>(); + parameters.add(object()); + parameters.add(context); + return (CommandResult) methodHandle().invokeWithArguments(parameters); + } catch (Throwable throwable) { + return CommandResult.exceptionally(context, throwable); + } + } + } + + static final class CommandContextExecutor extends AbstractMethodCommandNodeExecutor { + + public CommandContextExecutor(@NotNull Object object, @NotNull Method method) { + super(object, method); + } + + @SuppressWarnings("unchecked") + @Override + public @NotNull CommandResult execute(@NotNull CommandContext context) { + try { + List parameters = new ArrayList<>(); + parameters.add(object()); + parameters.add(context); + return (CommandResult) CommandResult.successful(context, methodHandle().invokeWithArguments(parameters)); + } catch (Throwable throwable) { + return CommandResult.exceptionally(context, throwable); + } + } + } + + static final class CommandSenderAndArgumentsCommandContextExecutor extends AbstractMethodCommandNodeExecutor { + + public CommandSenderAndArgumentsCommandContextExecutor(@NotNull Object object, @NotNull Method method) { + super(object, method); + } + + @SuppressWarnings("unchecked") + @Override + public @NotNull CommandResult execute(@NotNull CommandContext context) { + try { + List parameters = new ArrayList<>(); + parameters.add(object()); + parameters.add(context.sender()); + context.arguments().getArguments().forEach((nodeName, argument) -> parameters.add(argument.data())); + return (CommandResult) methodHandle().invokeWithArguments(parameters); + } catch (Throwable throwable) { + return CommandResult.exceptionally(context, throwable); + } + } + } + + static final class CommandSenderAndArgumentsExecutor extends AbstractMethodCommandNodeExecutor { + + public CommandSenderAndArgumentsExecutor(@NotNull Object object, @NotNull Method method) { + super(object, method); + } + + @SuppressWarnings("unchecked") + @Override + public @NotNull CommandResult execute(@NotNull CommandContext context) { + try { + List parameters = new ArrayList<>(); + parameters.add(object()); + parameters.add(context.sender()); + context.arguments().getArguments().forEach((nodeName, argument) -> parameters.add(argument.data())); + return (CommandResult) CommandResult.successful(context, methodHandle().invokeWithArguments(parameters)); + } catch (Throwable throwable) { + return CommandResult.exceptionally(context, throwable); + } + } + } + + static final class CommandContextAndArgumentsCommandContextExecutor extends AbstractMethodCommandNodeExecutor { + + public CommandContextAndArgumentsCommandContextExecutor(@NotNull Object object, @NotNull Method method) { + super(object, method); + } + + @SuppressWarnings("unchecked") + @Override + public @NotNull CommandResult execute(@NotNull CommandContext context) { + try { + List parameters = new ArrayList<>(); + parameters.add(object()); + parameters.add(context); + context.arguments().getArguments().forEach((nodeName, argument) -> parameters.add(argument.data())); + return (CommandResult) methodHandle().invokeWithArguments(parameters); + } catch (Throwable throwable) { + return CommandResult.exceptionally(context, throwable); + } + } + } + + static final class CommandContextAndArgumentsExecutor extends AbstractMethodCommandNodeExecutor { + + public CommandContextAndArgumentsExecutor(@NotNull Object object, @NotNull Method method) { + super(object, method); + } + + @SuppressWarnings("unchecked") + @Override + public @NotNull CommandResult execute(@NotNull CommandContext context) { + try { + List parameters = new ArrayList<>(); + parameters.add(object()); + parameters.add(context); + context.arguments().getArguments().forEach((nodeName, argument) -> parameters.add(argument.data())); + return (CommandResult) CommandResult.successful(context, methodHandle().invokeWithArguments(parameters)); + } catch (Throwable throwable) { + return CommandResult.exceptionally(context, throwable); + } + } + } + + static final class ArgumentsCommandContextExecutor extends AbstractMethodCommandNodeExecutor { + + public ArgumentsCommandContextExecutor(@NotNull Object object, @NotNull Method method) { + super(object, method); + } + + @SuppressWarnings("unchecked") + @Override + public @NotNull CommandResult execute(@NotNull CommandContext context) { + try { + List parameters = new ArrayList<>(); + parameters.add(object()); + context.arguments().getArguments().forEach((nodeName, argument) -> parameters.add(argument.data())); + return (CommandResult) methodHandle().invokeWithArguments(parameters); + } catch (Throwable throwable) { + return CommandResult.exceptionally(context, throwable); + } + } + } + + static final class ArgumentsExecutor extends AbstractMethodCommandNodeExecutor { + + public ArgumentsExecutor(@NotNull Object object, @NotNull Method method) { + super(object, method); + } + + @SuppressWarnings("unchecked") + @Override + public @NotNull CommandResult execute(@NotNull CommandContext context) { + try { + List parameters = new ArrayList<>(); + parameters.add(object()); + context.arguments().getArguments().forEach((nodeName, argument) -> parameters.add(argument.data())); + return (CommandResult) CommandResult.successful(context, methodHandle().invokeWithArguments(parameters)); + } catch (Throwable throwable) { + return CommandResult.exceptionally(context, throwable); + } + } + } +} diff --git a/commands/src/main/java/com/wizardlybump17/wlib/command/extractor/method/MethodCommandExtractor.java b/commands/src/main/java/com/wizardlybump17/wlib/command/extractor/method/MethodCommandExtractor.java new file mode 100644 index 00000000..efd8c3dd --- /dev/null +++ b/commands/src/main/java/com/wizardlybump17/wlib/command/extractor/method/MethodCommandExtractor.java @@ -0,0 +1,139 @@ +package com.wizardlybump17.wlib.command.extractor.method; + +import com.wizardlybump17.wlib.command.Command; +import com.wizardlybump17.wlib.command.context.CommandContext; +import com.wizardlybump17.wlib.command.executor.CommandNodeExecutor; +import com.wizardlybump17.wlib.command.input.AllowedNumberInputs; +import com.wizardlybump17.wlib.command.node.CommandNode; +import com.wizardlybump17.wlib.command.node.IntegerCommandNode; +import com.wizardlybump17.wlib.command.node.LiteralCommandNode; +import com.wizardlybump17.wlib.command.sender.CommandSender; +import org.jetbrains.annotations.NotNull; +import org.jetbrains.annotations.Nullable; + +import java.lang.reflect.Method; +import java.util.ArrayList; +import java.util.List; + +public class MethodCommandExtractor { + + public static @NotNull List extract(@NotNull Object object) { + List commands = new ArrayList<>(); + + Class clazz = object.getClass(); + + for (Method method : clazz.getMethods()) { + com.wizardlybump17.wlib.command.annotation.Command annotation = method.getAnnotation(com.wizardlybump17.wlib.command.annotation.Command.class); + if (annotation == null) + continue; + + Class[] parameterTypes = method.getParameterTypes(); + Class returnType = method.getReturnType(); + + String[] commandParts = annotation.value().split(" "); + + CommandNode root = null; + + if (parameterTypes.length == 0) + throw new IllegalArgumentException(); + + int parameterIndex = parameterTypes.length - 1; + for (int i = commandParts.length - 1; i >= 0; i--) { + String part = commandParts[i]; + + CommandNode oldRoot = root; + root = createNode(part, parameterTypes[parameterIndex], root, annotation); + if (!(root instanceof LiteralCommandNode)) + parameterIndex--; + + if (oldRoot == null) + root = root.withExecutor(createExecutor(object, parameterTypes, returnType, method)); + } + + if (root == null) + throw new IllegalArgumentException(); + + commands.add(new Command((LiteralCommandNode) root)); + } + + return commands; + } + + private static @NotNull CommandNode createNode(@NotNull String part, @NotNull Class type, @Nullable CommandNode root, @NotNull com.wizardlybump17.wlib.command.annotation.Command annotation) { + CommandNode newNode; + + if (part.charAt(0) == '<' && part.charAt(part.length() - 1) == '>') { + if (type == int.class || type == Integer.class) { + newNode = new IntegerCommandNode(part, root == null ? List.of() : List.of(root), new AllowedNumberInputs.AllowedIntegerInputs.Unlimited()); + } else { + throw new UnsupportedOperationException(); + } + } else { + newNode = new LiteralCommandNode(part, root == null ? List.of() : List.of(root)); + } + + if (!annotation.permission().isEmpty()) + newNode = newNode.withPermission(annotation.permission()); + + return newNode; + } + + public static @NotNull CommandNodeExecutor createExecutor(@NotNull Object object, @NotNull String methodName, @NotNull Class @NotNull ... parameterTypes) { + try { + Method method = object.getClass().getMethod(methodName, parameterTypes); + return createExecutor(object, parameterTypes, method.getReturnType(), method); + } catch (NoSuchMethodException e) { + throw new IllegalArgumentException(e); + } + } + + private static @NotNull CommandNodeExecutor createExecutor(@NotNull Object object, @NotNull Class @NotNull [] parameterTypes, @NotNull Class returnType, @NotNull Method method) { + /* + If empty -> error + If CommandSender only -> pass only the command sender and check the return type + If CommandContext only -> pass only the command context and check the return type + If CommandSender + more parameters -> pass the command sender and the parameters and check the return type + If CommandContext + more parameters -> pass the command context and the parameters and check the return type + If only parameters -> pass the parameters and check the return type + */ + + if (parameterTypes.length == 0) //empty -> error + throw new IllegalArgumentException(); + + if (parameterTypes.length == 1) { + if (parameterTypes[0].isAssignableFrom(CommandSender.class)) { //CommandSender only + if (returnType.isAssignableFrom(CommandContext.class)) { //CommandContext return type + return new AbstractMethodCommandNodeExecutor.CommandSenderCommandContextExecutor<>(object, method); + } else { //anything else return type + return new AbstractMethodCommandNodeExecutor.CommandSenderExecutor<>(object, method); + } + } else if (parameterTypes[0].isAssignableFrom(CommandContext.class)) { //CommandContext only + if (returnType.isAssignableFrom(CommandContext.class)) { //CommandContext return type + return new AbstractMethodCommandNodeExecutor.CommandContextCommandContextExecutor<>(object, method); + } else { //anything else return type + return new AbstractMethodCommandNodeExecutor.CommandContextExecutor<>(object, method); + } + } + } + + if (parameterTypes[0].isAssignableFrom(CommandSender.class)) { //CommandSender + more arguments + if (returnType.isAssignableFrom(CommandContext.class)) { //CommandContext return type + return new AbstractMethodCommandNodeExecutor.CommandSenderAndArgumentsCommandContextExecutor<>(object, method); + } else { //anything else return type + return new AbstractMethodCommandNodeExecutor.CommandSenderAndArgumentsExecutor<>(object, method); + } + } else if (parameterTypes[0].isAssignableFrom(CommandContext.class)) { //CommandContext + more arguments + if (returnType.isAssignableFrom(CommandContext.class)) { //CommandContext return type + return new AbstractMethodCommandNodeExecutor.CommandContextAndArgumentsCommandContextExecutor<>(object, method); + } else { //anything else return type + return new AbstractMethodCommandNodeExecutor.CommandContextAndArgumentsExecutor<>(object, method); + } + } else { + if (returnType.isAssignableFrom(CommandContext.class)) { //CommandContext return type + return new AbstractMethodCommandNodeExecutor.ArgumentsCommandContextExecutor<>(object, method); + } else { //anything else return type + return new AbstractMethodCommandNodeExecutor.ArgumentsExecutor<>(object, method); + } + } + } +} diff --git a/commands/src/main/java/com/wizardlybump17/wlib/command/extractor/method/MethodCommandNodeExecutor.java b/commands/src/main/java/com/wizardlybump17/wlib/command/extractor/method/MethodCommandNodeExecutor.java new file mode 100644 index 00000000..fc6a23f8 --- /dev/null +++ b/commands/src/main/java/com/wizardlybump17/wlib/command/extractor/method/MethodCommandNodeExecutor.java @@ -0,0 +1,16 @@ +package com.wizardlybump17.wlib.command.extractor.method; + +import com.wizardlybump17.wlib.command.executor.CommandNodeExecutor; +import org.jetbrains.annotations.NotNull; + +import java.lang.invoke.MethodHandle; +import java.lang.reflect.Method; + +public sealed interface MethodCommandNodeExecutor extends CommandNodeExecutor permits AbstractMethodCommandNodeExecutor { + + @NotNull Object object(); + + @NotNull MethodHandle methodHandle(); + + @NotNull Method method(); +} diff --git a/commands/src/test/java/com/wizardlybump17/wlib/test/command/extractor/method/MethodCommandExtractorTests.java b/commands/src/test/java/com/wizardlybump17/wlib/test/command/extractor/method/MethodCommandExtractorTests.java new file mode 100644 index 00000000..405861ed --- /dev/null +++ b/commands/src/test/java/com/wizardlybump17/wlib/test/command/extractor/method/MethodCommandExtractorTests.java @@ -0,0 +1,77 @@ +package com.wizardlybump17.wlib.test.command.extractor.method; + +import com.wizardlybump17.wlib.command.Command; +import com.wizardlybump17.wlib.command.extractor.method.MethodCommandExtractor; +import com.wizardlybump17.wlib.command.node.LiteralCommandNode; +import com.wizardlybump17.wlib.command.sender.CommandSender; +import org.jetbrains.annotations.NotNull; +import org.junit.jupiter.api.Assertions; +import org.junit.jupiter.api.Test; + +import java.util.ArrayList; +import java.util.List; + +class MethodCommandExtractorTests { + + @Test + void test0() { + Test0 object = new Test0(); + + List expected = new ArrayList<>(List.of( + new Command( + new LiteralCommandNode( + "hello", + MethodCommandExtractor.createExecutor(object, "hello", CommandSender.class) + ) + ), + new Command( + new LiteralCommandNode( + "hello", + List.of( + new LiteralCommandNode( + "world", + MethodCommandExtractor.createExecutor(object, "helloWorld", CommandSender.class) + ) + ) + ) + ), + new Command( + new LiteralCommandNode( + "hello", + List.of( + new LiteralCommandNode( + "there", + List.of( + new LiteralCommandNode( + "hi", + MethodCommandExtractor.createExecutor(object, "helloThereHi", CommandSender.class) + ) + ) + ) + ) + ) + ) + )); + List actual = MethodCommandExtractor.extract(object); + + expected.sort(null); + actual.sort(null); + + Assertions.assertEquals(expected, actual); + } + + public static class Test0 { + + @com.wizardlybump17.wlib.command.annotation.Command("hello") + public void hello(@NotNull CommandSender sender) { + } + + @com.wizardlybump17.wlib.command.annotation.Command("hello world") + public void helloWorld(@NotNull CommandSender sender) { + } + + @com.wizardlybump17.wlib.command.annotation.Command("hello there hi") + public void helloThereHi(@NotNull CommandSender sender) { + } + } +} From d480ffc8e7a00c8a4879260edcffab112ab58351 Mon Sep 17 00:00:00 2001 From: WizardlyBump17 Date: Sun, 9 Nov 2025 16:36:04 -0300 Subject: [PATCH 108/363] added the CommandExtractor interface --- .../wlib/command/extractor/CommandExtractor.java | 16 ++++++++++++++++ .../extractor/method/MethodCommandExtractor.java | 13 +++++++++++-- .../method/MethodCommandExtractorTests.java | 3 ++- 3 files changed, 29 insertions(+), 3 deletions(-) create mode 100644 commands/src/main/java/com/wizardlybump17/wlib/command/extractor/CommandExtractor.java diff --git a/commands/src/main/java/com/wizardlybump17/wlib/command/extractor/CommandExtractor.java b/commands/src/main/java/com/wizardlybump17/wlib/command/extractor/CommandExtractor.java new file mode 100644 index 00000000..d18ba4ce --- /dev/null +++ b/commands/src/main/java/com/wizardlybump17/wlib/command/extractor/CommandExtractor.java @@ -0,0 +1,16 @@ +package com.wizardlybump17.wlib.command.extractor; + +import com.wizardlybump17.wlib.command.Command; +import com.wizardlybump17.wlib.command.extractor.method.MethodCommandExtractor; +import org.jetbrains.annotations.NotNull; + +import java.util.List; + +public interface CommandExtractor { + + @NotNull MethodCommandExtractor METHOD = MethodCommandExtractor.INSTANCE; + + boolean isAccepted(@NotNull Object object); + + @NotNull List extract(@NotNull Object object); +} diff --git a/commands/src/main/java/com/wizardlybump17/wlib/command/extractor/method/MethodCommandExtractor.java b/commands/src/main/java/com/wizardlybump17/wlib/command/extractor/method/MethodCommandExtractor.java index efd8c3dd..b83917b4 100644 --- a/commands/src/main/java/com/wizardlybump17/wlib/command/extractor/method/MethodCommandExtractor.java +++ b/commands/src/main/java/com/wizardlybump17/wlib/command/extractor/method/MethodCommandExtractor.java @@ -3,6 +3,7 @@ import com.wizardlybump17.wlib.command.Command; import com.wizardlybump17.wlib.command.context.CommandContext; import com.wizardlybump17.wlib.command.executor.CommandNodeExecutor; +import com.wizardlybump17.wlib.command.extractor.CommandExtractor; import com.wizardlybump17.wlib.command.input.AllowedNumberInputs; import com.wizardlybump17.wlib.command.node.CommandNode; import com.wizardlybump17.wlib.command.node.IntegerCommandNode; @@ -15,9 +16,17 @@ import java.util.ArrayList; import java.util.List; -public class MethodCommandExtractor { +public class MethodCommandExtractor implements CommandExtractor { - public static @NotNull List extract(@NotNull Object object) { + public static final @NotNull MethodCommandExtractor INSTANCE = new MethodCommandExtractor(); + + @Override + public boolean isAccepted(@NotNull Object object) { + return true; + } + + @Override + public @NotNull List extract(@NotNull Object object) { List commands = new ArrayList<>(); Class clazz = object.getClass(); diff --git a/commands/src/test/java/com/wizardlybump17/wlib/test/command/extractor/method/MethodCommandExtractorTests.java b/commands/src/test/java/com/wizardlybump17/wlib/test/command/extractor/method/MethodCommandExtractorTests.java index 405861ed..1237cc41 100644 --- a/commands/src/test/java/com/wizardlybump17/wlib/test/command/extractor/method/MethodCommandExtractorTests.java +++ b/commands/src/test/java/com/wizardlybump17/wlib/test/command/extractor/method/MethodCommandExtractorTests.java @@ -1,6 +1,7 @@ package com.wizardlybump17.wlib.test.command.extractor.method; import com.wizardlybump17.wlib.command.Command; +import com.wizardlybump17.wlib.command.extractor.CommandExtractor; import com.wizardlybump17.wlib.command.extractor.method.MethodCommandExtractor; import com.wizardlybump17.wlib.command.node.LiteralCommandNode; import com.wizardlybump17.wlib.command.sender.CommandSender; @@ -52,7 +53,7 @@ void test0() { ) ) )); - List actual = MethodCommandExtractor.extract(object); + List actual = CommandExtractor.METHOD.extract(object); expected.sort(null); actual.sort(null); From 038d7952d47be03fa96b6047b7724df8a4a29e08 Mon Sep 17 00:00:00 2001 From: WizardlyBump17 Date: Mon, 10 Nov 2025 12:58:02 -0300 Subject: [PATCH 109/363] fixed the names --- .../AbstractMethodCommandNodeExecutor.java | 20 +++++++++--------- .../method/MethodCommandExtractor.java | 21 ++++++++++--------- 2 files changed, 21 insertions(+), 20 deletions(-) diff --git a/commands/src/main/java/com/wizardlybump17/wlib/command/extractor/method/AbstractMethodCommandNodeExecutor.java b/commands/src/main/java/com/wizardlybump17/wlib/command/extractor/method/AbstractMethodCommandNodeExecutor.java index 97286797..d64b67e8 100644 --- a/commands/src/main/java/com/wizardlybump17/wlib/command/extractor/method/AbstractMethodCommandNodeExecutor.java +++ b/commands/src/main/java/com/wizardlybump17/wlib/command/extractor/method/AbstractMethodCommandNodeExecutor.java @@ -66,9 +66,9 @@ public String toString() { '}'; } - static final class CommandSenderCommandContextExecutor extends AbstractMethodCommandNodeExecutor { + static final class CommandSenderCommandResultExecutor extends AbstractMethodCommandNodeExecutor { - public CommandSenderCommandContextExecutor(@NotNull Object object, @NotNull Method method) { + public CommandSenderCommandResultExecutor(@NotNull Object object, @NotNull Method method) { super(object, method); } @@ -106,9 +106,9 @@ public CommandSenderExecutor(@NotNull Object object, @NotNull Method method) { } } - static final class CommandContextCommandContextExecutor extends AbstractMethodCommandNodeExecutor { + static final class CommandContextCommandResultExecutor extends AbstractMethodCommandNodeExecutor { - public CommandContextCommandContextExecutor(@NotNull Object object, @NotNull Method method) { + public CommandContextCommandResultExecutor(@NotNull Object object, @NotNull Method method) { super(object, method); } @@ -146,9 +146,9 @@ public CommandContextExecutor(@NotNull Object object, @NotNull Method method) { } } - static final class CommandSenderAndArgumentsCommandContextExecutor extends AbstractMethodCommandNodeExecutor { + static final class CommandSenderAndArgumentsCommandResultExecutor extends AbstractMethodCommandNodeExecutor { - public CommandSenderAndArgumentsCommandContextExecutor(@NotNull Object object, @NotNull Method method) { + public CommandSenderAndArgumentsCommandResultExecutor(@NotNull Object object, @NotNull Method method) { super(object, method); } @@ -188,9 +188,9 @@ public CommandSenderAndArgumentsExecutor(@NotNull Object object, @NotNull Method } } - static final class CommandContextAndArgumentsCommandContextExecutor extends AbstractMethodCommandNodeExecutor { + static final class CommandContextAndArgumentsCommandResultExecutor extends AbstractMethodCommandNodeExecutor { - public CommandContextAndArgumentsCommandContextExecutor(@NotNull Object object, @NotNull Method method) { + public CommandContextAndArgumentsCommandResultExecutor(@NotNull Object object, @NotNull Method method) { super(object, method); } @@ -230,9 +230,9 @@ public CommandContextAndArgumentsExecutor(@NotNull Object object, @NotNull Metho } } - static final class ArgumentsCommandContextExecutor extends AbstractMethodCommandNodeExecutor { + static final class ArgumentsCommandResultExecutor extends AbstractMethodCommandNodeExecutor { - public ArgumentsCommandContextExecutor(@NotNull Object object, @NotNull Method method) { + public ArgumentsCommandResultExecutor(@NotNull Object object, @NotNull Method method) { super(object, method); } diff --git a/commands/src/main/java/com/wizardlybump17/wlib/command/extractor/method/MethodCommandExtractor.java b/commands/src/main/java/com/wizardlybump17/wlib/command/extractor/method/MethodCommandExtractor.java index b83917b4..dcb6db7b 100644 --- a/commands/src/main/java/com/wizardlybump17/wlib/command/extractor/method/MethodCommandExtractor.java +++ b/commands/src/main/java/com/wizardlybump17/wlib/command/extractor/method/MethodCommandExtractor.java @@ -8,6 +8,7 @@ import com.wizardlybump17.wlib.command.node.CommandNode; import com.wizardlybump17.wlib.command.node.IntegerCommandNode; import com.wizardlybump17.wlib.command.node.LiteralCommandNode; +import com.wizardlybump17.wlib.command.result.CommandResult; import com.wizardlybump17.wlib.command.sender.CommandSender; import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.Nullable; @@ -111,14 +112,14 @@ public boolean isAccepted(@NotNull Object object) { if (parameterTypes.length == 1) { if (parameterTypes[0].isAssignableFrom(CommandSender.class)) { //CommandSender only - if (returnType.isAssignableFrom(CommandContext.class)) { //CommandContext return type - return new AbstractMethodCommandNodeExecutor.CommandSenderCommandContextExecutor<>(object, method); + if (returnType.isAssignableFrom(CommandResult.class)) { //CommandResult return type + return new AbstractMethodCommandNodeExecutor.CommandSenderCommandResultExecutor<>(object, method); } else { //anything else return type return new AbstractMethodCommandNodeExecutor.CommandSenderExecutor<>(object, method); } } else if (parameterTypes[0].isAssignableFrom(CommandContext.class)) { //CommandContext only - if (returnType.isAssignableFrom(CommandContext.class)) { //CommandContext return type - return new AbstractMethodCommandNodeExecutor.CommandContextCommandContextExecutor<>(object, method); + if (returnType.isAssignableFrom(CommandResult.class)) { //CommandResult return type + return new AbstractMethodCommandNodeExecutor.CommandContextCommandResultExecutor<>(object, method); } else { //anything else return type return new AbstractMethodCommandNodeExecutor.CommandContextExecutor<>(object, method); } @@ -126,20 +127,20 @@ public boolean isAccepted(@NotNull Object object) { } if (parameterTypes[0].isAssignableFrom(CommandSender.class)) { //CommandSender + more arguments - if (returnType.isAssignableFrom(CommandContext.class)) { //CommandContext return type - return new AbstractMethodCommandNodeExecutor.CommandSenderAndArgumentsCommandContextExecutor<>(object, method); + if (returnType.isAssignableFrom(CommandResult.class)) { //CommandResult return type + return new AbstractMethodCommandNodeExecutor.CommandSenderAndArgumentsCommandResultExecutor<>(object, method); } else { //anything else return type return new AbstractMethodCommandNodeExecutor.CommandSenderAndArgumentsExecutor<>(object, method); } } else if (parameterTypes[0].isAssignableFrom(CommandContext.class)) { //CommandContext + more arguments - if (returnType.isAssignableFrom(CommandContext.class)) { //CommandContext return type - return new AbstractMethodCommandNodeExecutor.CommandContextAndArgumentsCommandContextExecutor<>(object, method); + if (returnType.isAssignableFrom(CommandResult.class)) { //CommandResult return type + return new AbstractMethodCommandNodeExecutor.CommandContextAndArgumentsCommandResultExecutor<>(object, method); } else { //anything else return type return new AbstractMethodCommandNodeExecutor.CommandContextAndArgumentsExecutor<>(object, method); } } else { - if (returnType.isAssignableFrom(CommandContext.class)) { //CommandContext return type - return new AbstractMethodCommandNodeExecutor.ArgumentsCommandContextExecutor<>(object, method); + if (returnType.isAssignableFrom(CommandResult.class)) { //CommandResult return type + return new AbstractMethodCommandNodeExecutor.ArgumentsCommandResultExecutor<>(object, method); } else { //anything else return type return new AbstractMethodCommandNodeExecutor.ArgumentsExecutor<>(object, method); } From 36498f98f526df9c4241f06b44c4c902ee900a9a Mon Sep 17 00:00:00 2001 From: WizardlyBump17 Date: Mon, 10 Nov 2025 13:05:36 -0300 Subject: [PATCH 110/363] blocking some combinations --- .../AbstractMethodCommandNodeExecutor.java | 41 ------------------- .../method/MethodCommandExtractor.java | 12 ++++-- 2 files changed, 8 insertions(+), 45 deletions(-) diff --git a/commands/src/main/java/com/wizardlybump17/wlib/command/extractor/method/AbstractMethodCommandNodeExecutor.java b/commands/src/main/java/com/wizardlybump17/wlib/command/extractor/method/AbstractMethodCommandNodeExecutor.java index d64b67e8..b5fc7f84 100644 --- a/commands/src/main/java/com/wizardlybump17/wlib/command/extractor/method/AbstractMethodCommandNodeExecutor.java +++ b/commands/src/main/java/com/wizardlybump17/wlib/command/extractor/method/AbstractMethodCommandNodeExecutor.java @@ -66,26 +66,6 @@ public String toString() { '}'; } - static final class CommandSenderCommandResultExecutor extends AbstractMethodCommandNodeExecutor { - - public CommandSenderCommandResultExecutor(@NotNull Object object, @NotNull Method method) { - super(object, method); - } - - @SuppressWarnings("unchecked") - @Override - public @NotNull CommandResult execute(@NotNull CommandContext context) { - try { - List parameters = new ArrayList<>(); - parameters.add(object()); - parameters.add(context.sender()); - return (CommandResult) methodHandle().invokeWithArguments(parameters); - } catch (Throwable throwable) { - return CommandResult.exceptionally(context, throwable); - } - } - } - static final class CommandSenderExecutor extends AbstractMethodCommandNodeExecutor { public CommandSenderExecutor(@NotNull Object object, @NotNull Method method) { @@ -146,27 +126,6 @@ public CommandContextExecutor(@NotNull Object object, @NotNull Method method) { } } - static final class CommandSenderAndArgumentsCommandResultExecutor extends AbstractMethodCommandNodeExecutor { - - public CommandSenderAndArgumentsCommandResultExecutor(@NotNull Object object, @NotNull Method method) { - super(object, method); - } - - @SuppressWarnings("unchecked") - @Override - public @NotNull CommandResult execute(@NotNull CommandContext context) { - try { - List parameters = new ArrayList<>(); - parameters.add(object()); - parameters.add(context.sender()); - context.arguments().getArguments().forEach((nodeName, argument) -> parameters.add(argument.data())); - return (CommandResult) methodHandle().invokeWithArguments(parameters); - } catch (Throwable throwable) { - return CommandResult.exceptionally(context, throwable); - } - } - } - static final class CommandSenderAndArgumentsExecutor extends AbstractMethodCommandNodeExecutor { public CommandSenderAndArgumentsExecutor(@NotNull Object object, @NotNull Method method) { diff --git a/commands/src/main/java/com/wizardlybump17/wlib/command/extractor/method/MethodCommandExtractor.java b/commands/src/main/java/com/wizardlybump17/wlib/command/extractor/method/MethodCommandExtractor.java index dcb6db7b..abfb9871 100644 --- a/commands/src/main/java/com/wizardlybump17/wlib/command/extractor/method/MethodCommandExtractor.java +++ b/commands/src/main/java/com/wizardlybump17/wlib/command/extractor/method/MethodCommandExtractor.java @@ -100,9 +100,13 @@ public boolean isAccepted(@NotNull Object object) { private static @NotNull CommandNodeExecutor createExecutor(@NotNull Object object, @NotNull Class @NotNull [] parameterTypes, @NotNull Class returnType, @NotNull Method method) { /* If empty -> error - If CommandSender only -> pass only the command sender and check the return type + If CommandSender only -| + |-> if CommandResult return type, error + |-> anything else, success If CommandContext only -> pass only the command context and check the return type - If CommandSender + more parameters -> pass the command sender and the parameters and check the return type + If CommandSender + more parameters -| + |-> if CommandResult return type, error + |-> pass the command sender and the parameters, success If CommandContext + more parameters -> pass the command context and the parameters and check the return type If only parameters -> pass the parameters and check the return type */ @@ -113,7 +117,7 @@ public boolean isAccepted(@NotNull Object object) { if (parameterTypes.length == 1) { if (parameterTypes[0].isAssignableFrom(CommandSender.class)) { //CommandSender only if (returnType.isAssignableFrom(CommandResult.class)) { //CommandResult return type - return new AbstractMethodCommandNodeExecutor.CommandSenderCommandResultExecutor<>(object, method); + throw new IllegalArgumentException(); } else { //anything else return type return new AbstractMethodCommandNodeExecutor.CommandSenderExecutor<>(object, method); } @@ -128,7 +132,7 @@ public boolean isAccepted(@NotNull Object object) { if (parameterTypes[0].isAssignableFrom(CommandSender.class)) { //CommandSender + more arguments if (returnType.isAssignableFrom(CommandResult.class)) { //CommandResult return type - return new AbstractMethodCommandNodeExecutor.CommandSenderAndArgumentsCommandResultExecutor<>(object, method); + throw new IllegalArgumentException(); } else { //anything else return type return new AbstractMethodCommandNodeExecutor.CommandSenderAndArgumentsExecutor<>(object, method); } From 062db40046d48062102d563b1a746fda101ae961 Mon Sep 17 00:00:00 2001 From: WizardlyBump17 Date: Mon, 10 Nov 2025 13:08:23 -0300 Subject: [PATCH 111/363] added some more tests --- .../method/MethodCommandExtractorTests.java | 129 ++++++++++++++++++ 1 file changed, 129 insertions(+) diff --git a/commands/src/test/java/com/wizardlybump17/wlib/test/command/extractor/method/MethodCommandExtractorTests.java b/commands/src/test/java/com/wizardlybump17/wlib/test/command/extractor/method/MethodCommandExtractorTests.java index 1237cc41..4cfa2e9a 100644 --- a/commands/src/test/java/com/wizardlybump17/wlib/test/command/extractor/method/MethodCommandExtractorTests.java +++ b/commands/src/test/java/com/wizardlybump17/wlib/test/command/extractor/method/MethodCommandExtractorTests.java @@ -1,9 +1,11 @@ package com.wizardlybump17.wlib.test.command.extractor.method; import com.wizardlybump17.wlib.command.Command; +import com.wizardlybump17.wlib.command.context.CommandContext; import com.wizardlybump17.wlib.command.extractor.CommandExtractor; import com.wizardlybump17.wlib.command.extractor.method.MethodCommandExtractor; import com.wizardlybump17.wlib.command.node.LiteralCommandNode; +import com.wizardlybump17.wlib.command.result.CommandResult; import com.wizardlybump17.wlib.command.sender.CommandSender; import org.jetbrains.annotations.NotNull; import org.junit.jupiter.api.Assertions; @@ -75,4 +77,131 @@ public void helloWorld(@NotNull CommandSender sender) { public void helloThereHi(@NotNull CommandSender sender) { } } + + @Test + void test1() { + Test1 object = new Test1(); + + List expected = new ArrayList<>(List.of( + new Command( + new LiteralCommandNode( + "hello", + MethodCommandExtractor.createExecutor(object, "hello", CommandContext.class) + ) + ), + new Command( + new LiteralCommandNode( + "hello", + List.of( + new LiteralCommandNode( + "world", + MethodCommandExtractor.createExecutor(object, "helloWorld", CommandContext.class) + ) + ) + ) + ), + new Command( + new LiteralCommandNode( + "hello", + List.of( + new LiteralCommandNode( + "there", + List.of( + new LiteralCommandNode( + "hi", + MethodCommandExtractor.createExecutor(object, "helloThereHi", CommandContext.class) + ) + ) + ) + ) + ) + ) + )); + List actual = CommandExtractor.METHOD.extract(object); + + expected.sort(null); + actual.sort(null); + + Assertions.assertEquals(expected, actual); + } + + public static class Test1 { + + @com.wizardlybump17.wlib.command.annotation.Command("hello") + public void hello(@NotNull CommandContext context) { + } + + @com.wizardlybump17.wlib.command.annotation.Command("hello world") + public void helloWorld(@NotNull CommandContext context) { + } + + @com.wizardlybump17.wlib.command.annotation.Command("hello there hi") + public void helloThereHi(@NotNull CommandContext context) { + } + } + + @Test + void test2() { + Test2 object = new Test2(); + + List expected = new ArrayList<>(List.of( + new Command( + new LiteralCommandNode( + "hello", + MethodCommandExtractor.createExecutor(object, "hello", CommandContext.class) + ) + ), + new Command( + new LiteralCommandNode( + "hello", + List.of( + new LiteralCommandNode( + "world", + MethodCommandExtractor.createExecutor(object, "helloWorld", CommandContext.class) + ) + ) + ) + ), + new Command( + new LiteralCommandNode( + "hello", + List.of( + new LiteralCommandNode( + "there", + List.of( + new LiteralCommandNode( + "hi", + MethodCommandExtractor.createExecutor(object, "helloThereHi", CommandContext.class) + ) + ) + ) + ) + ) + ) + )); + List actual = CommandExtractor.METHOD.extract(object); + + expected.sort(null); + actual.sort(null); + + Assertions.assertEquals(expected, actual); + } + + public static class Test2 { + + @com.wizardlybump17.wlib.command.annotation.Command("hello") + public @NotNull CommandResult hello(@NotNull CommandContext context) { + return CommandResult.successful(context, null); + } + + @com.wizardlybump17.wlib.command.annotation.Command("hello world") + public @NotNull CommandResult helloWorld(@NotNull CommandContext context) { + return CommandResult.successful(context, null); + } + + @com.wizardlybump17.wlib.command.annotation.Command("hello there hi") + public @NotNull CommandResult helloThereHi(@NotNull CommandContext context) { + return CommandResult.successful(context, null); + } + } } From 6c204d9f4c18076e1d6bcd49ae85bfd48daf9c7d Mon Sep 17 00:00:00 2001 From: WizardlyBump17 Date: Mon, 10 Nov 2025 13:28:52 -0300 Subject: [PATCH 112/363] throwing an exception when needed --- .../extractor/CommandExtractorException.java | 22 +++++++++++++++++ .../method/InvalidCombinationException.java | 11 +++++++++ .../command/extractor/CommandExtractor.java | 3 ++- .../method/MethodCommandExtractor.java | 9 +++---- .../method/MethodCommandExtractorTests.java | 24 +++++++++---------- 5 files changed, 52 insertions(+), 17 deletions(-) create mode 100644 commands/src/main/java/com/wizardlybump17/wlib/command/exception/extractor/CommandExtractorException.java create mode 100644 commands/src/main/java/com/wizardlybump17/wlib/command/exception/extractor/method/InvalidCombinationException.java diff --git a/commands/src/main/java/com/wizardlybump17/wlib/command/exception/extractor/CommandExtractorException.java b/commands/src/main/java/com/wizardlybump17/wlib/command/exception/extractor/CommandExtractorException.java new file mode 100644 index 00000000..fb6767aa --- /dev/null +++ b/commands/src/main/java/com/wizardlybump17/wlib/command/exception/extractor/CommandExtractorException.java @@ -0,0 +1,22 @@ +package com.wizardlybump17.wlib.command.exception.extractor; + +import org.jetbrains.annotations.NotNull; + +public abstract class CommandExtractorException extends Exception { + + public CommandExtractorException() { + super(); + } + + public CommandExtractorException(@NotNull String message) { + super(message); + } + + public CommandExtractorException(@NotNull String message, @NotNull Throwable cause) { + super(message, cause); + } + + public CommandExtractorException(@NotNull Throwable cause) { + super(cause); + } +} diff --git a/commands/src/main/java/com/wizardlybump17/wlib/command/exception/extractor/method/InvalidCombinationException.java b/commands/src/main/java/com/wizardlybump17/wlib/command/exception/extractor/method/InvalidCombinationException.java new file mode 100644 index 00000000..6df6ba7e --- /dev/null +++ b/commands/src/main/java/com/wizardlybump17/wlib/command/exception/extractor/method/InvalidCombinationException.java @@ -0,0 +1,11 @@ +package com.wizardlybump17.wlib.command.exception.extractor.method; + +import com.wizardlybump17.wlib.command.exception.extractor.CommandExtractorException; +import org.jetbrains.annotations.NotNull; + +public class InvalidCombinationException extends CommandExtractorException { + + public InvalidCombinationException(@NotNull String message) { + super(message); + } +} diff --git a/commands/src/main/java/com/wizardlybump17/wlib/command/extractor/CommandExtractor.java b/commands/src/main/java/com/wizardlybump17/wlib/command/extractor/CommandExtractor.java index d18ba4ce..b70eb4f8 100644 --- a/commands/src/main/java/com/wizardlybump17/wlib/command/extractor/CommandExtractor.java +++ b/commands/src/main/java/com/wizardlybump17/wlib/command/extractor/CommandExtractor.java @@ -1,6 +1,7 @@ package com.wizardlybump17.wlib.command.extractor; import com.wizardlybump17.wlib.command.Command; +import com.wizardlybump17.wlib.command.exception.extractor.CommandExtractorException; import com.wizardlybump17.wlib.command.extractor.method.MethodCommandExtractor; import org.jetbrains.annotations.NotNull; @@ -12,5 +13,5 @@ public interface CommandExtractor { boolean isAccepted(@NotNull Object object); - @NotNull List extract(@NotNull Object object); + @NotNull List extract(@NotNull Object object) throws CommandExtractorException; } diff --git a/commands/src/main/java/com/wizardlybump17/wlib/command/extractor/method/MethodCommandExtractor.java b/commands/src/main/java/com/wizardlybump17/wlib/command/extractor/method/MethodCommandExtractor.java index abfb9871..a0b52b54 100644 --- a/commands/src/main/java/com/wizardlybump17/wlib/command/extractor/method/MethodCommandExtractor.java +++ b/commands/src/main/java/com/wizardlybump17/wlib/command/extractor/method/MethodCommandExtractor.java @@ -2,6 +2,7 @@ import com.wizardlybump17.wlib.command.Command; import com.wizardlybump17.wlib.command.context.CommandContext; +import com.wizardlybump17.wlib.command.exception.extractor.method.InvalidCombinationException; import com.wizardlybump17.wlib.command.executor.CommandNodeExecutor; import com.wizardlybump17.wlib.command.extractor.CommandExtractor; import com.wizardlybump17.wlib.command.input.AllowedNumberInputs; @@ -27,7 +28,7 @@ public boolean isAccepted(@NotNull Object object) { } @Override - public @NotNull List extract(@NotNull Object object) { + public @NotNull List extract(@NotNull Object object) throws InvalidCombinationException { List commands = new ArrayList<>(); Class clazz = object.getClass(); @@ -88,7 +89,7 @@ public boolean isAccepted(@NotNull Object object) { return newNode; } - public static @NotNull CommandNodeExecutor createExecutor(@NotNull Object object, @NotNull String methodName, @NotNull Class @NotNull ... parameterTypes) { + public static @NotNull CommandNodeExecutor createExecutor(@NotNull Object object, @NotNull String methodName, @NotNull Class @NotNull ... parameterTypes) throws InvalidCombinationException { try { Method method = object.getClass().getMethod(methodName, parameterTypes); return createExecutor(object, parameterTypes, method.getReturnType(), method); @@ -97,7 +98,7 @@ public boolean isAccepted(@NotNull Object object) { } } - private static @NotNull CommandNodeExecutor createExecutor(@NotNull Object object, @NotNull Class @NotNull [] parameterTypes, @NotNull Class returnType, @NotNull Method method) { + private static @NotNull CommandNodeExecutor createExecutor(@NotNull Object object, @NotNull Class @NotNull [] parameterTypes, @NotNull Class returnType, @NotNull Method method) throws InvalidCombinationException { /* If empty -> error If CommandSender only -| @@ -117,7 +118,7 @@ public boolean isAccepted(@NotNull Object object) { if (parameterTypes.length == 1) { if (parameterTypes[0].isAssignableFrom(CommandSender.class)) { //CommandSender only if (returnType.isAssignableFrom(CommandResult.class)) { //CommandResult return type - throw new IllegalArgumentException(); + throw new InvalidCombinationException("You can not return a CommandResult when having the first method parameter is a CommandSender: " + method); } else { //anything else return type return new AbstractMethodCommandNodeExecutor.CommandSenderExecutor<>(object, method); } diff --git a/commands/src/test/java/com/wizardlybump17/wlib/test/command/extractor/method/MethodCommandExtractorTests.java b/commands/src/test/java/com/wizardlybump17/wlib/test/command/extractor/method/MethodCommandExtractorTests.java index 4cfa2e9a..8cce39f6 100644 --- a/commands/src/test/java/com/wizardlybump17/wlib/test/command/extractor/method/MethodCommandExtractorTests.java +++ b/commands/src/test/java/com/wizardlybump17/wlib/test/command/extractor/method/MethodCommandExtractorTests.java @@ -24,7 +24,7 @@ void test0() { new Command( new LiteralCommandNode( "hello", - MethodCommandExtractor.createExecutor(object, "hello", CommandSender.class) + Assertions.assertDoesNotThrow(() -> MethodCommandExtractor.createExecutor(object, "hello", CommandSender.class)) ) ), new Command( @@ -33,7 +33,7 @@ void test0() { List.of( new LiteralCommandNode( "world", - MethodCommandExtractor.createExecutor(object, "helloWorld", CommandSender.class) + Assertions.assertDoesNotThrow(() -> MethodCommandExtractor.createExecutor(object, "helloWorld", CommandSender.class)) ) ) ) @@ -47,7 +47,7 @@ void test0() { List.of( new LiteralCommandNode( "hi", - MethodCommandExtractor.createExecutor(object, "helloThereHi", CommandSender.class) + Assertions.assertDoesNotThrow(() -> MethodCommandExtractor.createExecutor(object, "helloThereHi", CommandSender.class)) ) ) ) @@ -55,7 +55,7 @@ void test0() { ) ) )); - List actual = CommandExtractor.METHOD.extract(object); + List actual = Assertions.assertDoesNotThrow(() -> CommandExtractor.METHOD.extract(object)); expected.sort(null); actual.sort(null); @@ -86,7 +86,7 @@ void test1() { new Command( new LiteralCommandNode( "hello", - MethodCommandExtractor.createExecutor(object, "hello", CommandContext.class) + Assertions.assertDoesNotThrow(() -> MethodCommandExtractor.createExecutor(object, "hello", CommandContext.class)) ) ), new Command( @@ -95,7 +95,7 @@ void test1() { List.of( new LiteralCommandNode( "world", - MethodCommandExtractor.createExecutor(object, "helloWorld", CommandContext.class) + Assertions.assertDoesNotThrow(() -> MethodCommandExtractor.createExecutor(object, "helloWorld", CommandContext.class)) ) ) ) @@ -109,7 +109,7 @@ void test1() { List.of( new LiteralCommandNode( "hi", - MethodCommandExtractor.createExecutor(object, "helloThereHi", CommandContext.class) + Assertions.assertDoesNotThrow(() -> MethodCommandExtractor.createExecutor(object, "helloThereHi", CommandContext.class)) ) ) ) @@ -117,7 +117,7 @@ void test1() { ) ) )); - List actual = CommandExtractor.METHOD.extract(object); + List actual = Assertions.assertDoesNotThrow(() -> CommandExtractor.METHOD.extract(object)); expected.sort(null); actual.sort(null); @@ -148,7 +148,7 @@ void test2() { new Command( new LiteralCommandNode( "hello", - MethodCommandExtractor.createExecutor(object, "hello", CommandContext.class) + Assertions.assertDoesNotThrow(() -> MethodCommandExtractor.createExecutor(object, "hello", CommandContext.class)) ) ), new Command( @@ -157,7 +157,7 @@ void test2() { List.of( new LiteralCommandNode( "world", - MethodCommandExtractor.createExecutor(object, "helloWorld", CommandContext.class) + Assertions.assertDoesNotThrow(() -> MethodCommandExtractor.createExecutor(object, "helloWorld", CommandContext.class)) ) ) ) @@ -171,7 +171,7 @@ void test2() { List.of( new LiteralCommandNode( "hi", - MethodCommandExtractor.createExecutor(object, "helloThereHi", CommandContext.class) + Assertions.assertDoesNotThrow(() -> MethodCommandExtractor.createExecutor(object, "helloThereHi", CommandContext.class)) ) ) ) @@ -179,7 +179,7 @@ void test2() { ) ) )); - List actual = CommandExtractor.METHOD.extract(object); + List actual = Assertions.assertDoesNotThrow(() -> CommandExtractor.METHOD.extract(object)); expected.sort(null); actual.sort(null); From 06a99f17a374728bb19e5a8493fc338be644e69f Mon Sep 17 00:00:00 2001 From: WizardlyBump17 Date: Mon, 10 Nov 2025 13:45:16 -0300 Subject: [PATCH 113/363] Revert "blocking some combinations" This reverts commit 36498f98 --- .../AbstractMethodCommandNodeExecutor.java | 41 +++++++++++++++++++ .../method/MethodCommandExtractor.java | 19 ++++----- 2 files changed, 48 insertions(+), 12 deletions(-) diff --git a/commands/src/main/java/com/wizardlybump17/wlib/command/extractor/method/AbstractMethodCommandNodeExecutor.java b/commands/src/main/java/com/wizardlybump17/wlib/command/extractor/method/AbstractMethodCommandNodeExecutor.java index b5fc7f84..d64b67e8 100644 --- a/commands/src/main/java/com/wizardlybump17/wlib/command/extractor/method/AbstractMethodCommandNodeExecutor.java +++ b/commands/src/main/java/com/wizardlybump17/wlib/command/extractor/method/AbstractMethodCommandNodeExecutor.java @@ -66,6 +66,26 @@ public String toString() { '}'; } + static final class CommandSenderCommandResultExecutor extends AbstractMethodCommandNodeExecutor { + + public CommandSenderCommandResultExecutor(@NotNull Object object, @NotNull Method method) { + super(object, method); + } + + @SuppressWarnings("unchecked") + @Override + public @NotNull CommandResult execute(@NotNull CommandContext context) { + try { + List parameters = new ArrayList<>(); + parameters.add(object()); + parameters.add(context.sender()); + return (CommandResult) methodHandle().invokeWithArguments(parameters); + } catch (Throwable throwable) { + return CommandResult.exceptionally(context, throwable); + } + } + } + static final class CommandSenderExecutor extends AbstractMethodCommandNodeExecutor { public CommandSenderExecutor(@NotNull Object object, @NotNull Method method) { @@ -126,6 +146,27 @@ public CommandContextExecutor(@NotNull Object object, @NotNull Method method) { } } + static final class CommandSenderAndArgumentsCommandResultExecutor extends AbstractMethodCommandNodeExecutor { + + public CommandSenderAndArgumentsCommandResultExecutor(@NotNull Object object, @NotNull Method method) { + super(object, method); + } + + @SuppressWarnings("unchecked") + @Override + public @NotNull CommandResult execute(@NotNull CommandContext context) { + try { + List parameters = new ArrayList<>(); + parameters.add(object()); + parameters.add(context.sender()); + context.arguments().getArguments().forEach((nodeName, argument) -> parameters.add(argument.data())); + return (CommandResult) methodHandle().invokeWithArguments(parameters); + } catch (Throwable throwable) { + return CommandResult.exceptionally(context, throwable); + } + } + } + static final class CommandSenderAndArgumentsExecutor extends AbstractMethodCommandNodeExecutor { public CommandSenderAndArgumentsExecutor(@NotNull Object object, @NotNull Method method) { diff --git a/commands/src/main/java/com/wizardlybump17/wlib/command/extractor/method/MethodCommandExtractor.java b/commands/src/main/java/com/wizardlybump17/wlib/command/extractor/method/MethodCommandExtractor.java index a0b52b54..dcb6db7b 100644 --- a/commands/src/main/java/com/wizardlybump17/wlib/command/extractor/method/MethodCommandExtractor.java +++ b/commands/src/main/java/com/wizardlybump17/wlib/command/extractor/method/MethodCommandExtractor.java @@ -2,7 +2,6 @@ import com.wizardlybump17.wlib.command.Command; import com.wizardlybump17.wlib.command.context.CommandContext; -import com.wizardlybump17.wlib.command.exception.extractor.method.InvalidCombinationException; import com.wizardlybump17.wlib.command.executor.CommandNodeExecutor; import com.wizardlybump17.wlib.command.extractor.CommandExtractor; import com.wizardlybump17.wlib.command.input.AllowedNumberInputs; @@ -28,7 +27,7 @@ public boolean isAccepted(@NotNull Object object) { } @Override - public @NotNull List extract(@NotNull Object object) throws InvalidCombinationException { + public @NotNull List extract(@NotNull Object object) { List commands = new ArrayList<>(); Class clazz = object.getClass(); @@ -89,7 +88,7 @@ public boolean isAccepted(@NotNull Object object) { return newNode; } - public static @NotNull CommandNodeExecutor createExecutor(@NotNull Object object, @NotNull String methodName, @NotNull Class @NotNull ... parameterTypes) throws InvalidCombinationException { + public static @NotNull CommandNodeExecutor createExecutor(@NotNull Object object, @NotNull String methodName, @NotNull Class @NotNull ... parameterTypes) { try { Method method = object.getClass().getMethod(methodName, parameterTypes); return createExecutor(object, parameterTypes, method.getReturnType(), method); @@ -98,16 +97,12 @@ public boolean isAccepted(@NotNull Object object) { } } - private static @NotNull CommandNodeExecutor createExecutor(@NotNull Object object, @NotNull Class @NotNull [] parameterTypes, @NotNull Class returnType, @NotNull Method method) throws InvalidCombinationException { + private static @NotNull CommandNodeExecutor createExecutor(@NotNull Object object, @NotNull Class @NotNull [] parameterTypes, @NotNull Class returnType, @NotNull Method method) { /* If empty -> error - If CommandSender only -| - |-> if CommandResult return type, error - |-> anything else, success + If CommandSender only -> pass only the command sender and check the return type If CommandContext only -> pass only the command context and check the return type - If CommandSender + more parameters -| - |-> if CommandResult return type, error - |-> pass the command sender and the parameters, success + If CommandSender + more parameters -> pass the command sender and the parameters and check the return type If CommandContext + more parameters -> pass the command context and the parameters and check the return type If only parameters -> pass the parameters and check the return type */ @@ -118,7 +113,7 @@ public boolean isAccepted(@NotNull Object object) { if (parameterTypes.length == 1) { if (parameterTypes[0].isAssignableFrom(CommandSender.class)) { //CommandSender only if (returnType.isAssignableFrom(CommandResult.class)) { //CommandResult return type - throw new InvalidCombinationException("You can not return a CommandResult when having the first method parameter is a CommandSender: " + method); + return new AbstractMethodCommandNodeExecutor.CommandSenderCommandResultExecutor<>(object, method); } else { //anything else return type return new AbstractMethodCommandNodeExecutor.CommandSenderExecutor<>(object, method); } @@ -133,7 +128,7 @@ public boolean isAccepted(@NotNull Object object) { if (parameterTypes[0].isAssignableFrom(CommandSender.class)) { //CommandSender + more arguments if (returnType.isAssignableFrom(CommandResult.class)) { //CommandResult return type - throw new IllegalArgumentException(); + return new AbstractMethodCommandNodeExecutor.CommandSenderAndArgumentsCommandResultExecutor<>(object, method); } else { //anything else return type return new AbstractMethodCommandNodeExecutor.CommandSenderAndArgumentsExecutor<>(object, method); } From 74ea0987ab5e9ae9fb3572af6def7367f3ceb38c Mon Sep 17 00:00:00 2001 From: WizardlyBump17 Date: Mon, 10 Nov 2025 16:48:10 -0300 Subject: [PATCH 114/363] do whatever you want. You are free --- .../AbstractMethodCommandNodeExecutor.java | 38 +++++++++++++++++++ .../method/MethodCommandExtractor.java | 11 ++++-- 2 files changed, 46 insertions(+), 3 deletions(-) diff --git a/commands/src/main/java/com/wizardlybump17/wlib/command/extractor/method/AbstractMethodCommandNodeExecutor.java b/commands/src/main/java/com/wizardlybump17/wlib/command/extractor/method/AbstractMethodCommandNodeExecutor.java index d64b67e8..b1322b37 100644 --- a/commands/src/main/java/com/wizardlybump17/wlib/command/extractor/method/AbstractMethodCommandNodeExecutor.java +++ b/commands/src/main/java/com/wizardlybump17/wlib/command/extractor/method/AbstractMethodCommandNodeExecutor.java @@ -269,4 +269,42 @@ public ArgumentsExecutor(@NotNull Object object, @NotNull Method method) { } } } + + static final class NoArgumentsExecutor extends AbstractMethodCommandNodeExecutor { + + public NoArgumentsExecutor(@NotNull Object object, @NotNull Method method) { + super(object, method); + } + + @SuppressWarnings("unchecked") + @Override + public @NotNull CommandResult execute(@NotNull CommandContext context) { + try { + List parameters = new ArrayList<>(); + parameters.add(object()); + return (CommandResult) CommandResult.successful(context, methodHandle().invokeWithArguments(parameters)); + } catch (Throwable throwable) { + return CommandResult.exceptionally(context, throwable); + } + } + } + + static final class NoArgumentsCommandResultExecutor extends AbstractMethodCommandNodeExecutor { + + public NoArgumentsCommandResultExecutor(@NotNull Object object, @NotNull Method method) { + super(object, method); + } + + @SuppressWarnings("unchecked") + @Override + public @NotNull CommandResult execute(@NotNull CommandContext context) { + try { + List parameters = new ArrayList<>(); + parameters.add(object()); + return (CommandResult) methodHandle().invokeWithArguments(parameters); + } catch (Throwable throwable) { + return CommandResult.exceptionally(context, throwable); + } + } + } } diff --git a/commands/src/main/java/com/wizardlybump17/wlib/command/extractor/method/MethodCommandExtractor.java b/commands/src/main/java/com/wizardlybump17/wlib/command/extractor/method/MethodCommandExtractor.java index dcb6db7b..185a4bc7 100644 --- a/commands/src/main/java/com/wizardlybump17/wlib/command/extractor/method/MethodCommandExtractor.java +++ b/commands/src/main/java/com/wizardlybump17/wlib/command/extractor/method/MethodCommandExtractor.java @@ -99,7 +99,7 @@ public boolean isAccepted(@NotNull Object object) { private static @NotNull CommandNodeExecutor createExecutor(@NotNull Object object, @NotNull Class @NotNull [] parameterTypes, @NotNull Class returnType, @NotNull Method method) { /* - If empty -> error + If empty -> check the return type If CommandSender only -> pass only the command sender and check the return type If CommandContext only -> pass only the command context and check the return type If CommandSender + more parameters -> pass the command sender and the parameters and check the return type @@ -107,8 +107,13 @@ public boolean isAccepted(@NotNull Object object) { If only parameters -> pass the parameters and check the return type */ - if (parameterTypes.length == 0) //empty -> error - throw new IllegalArgumentException(); + if (parameterTypes.length == 0) { //no parameters + if (returnType.isAssignableFrom(CommandResult.class)) { //CommandResult return type + return new AbstractMethodCommandNodeExecutor.NoArgumentsCommandResultExecutor<>(object, method); + } else { + return new AbstractMethodCommandNodeExecutor.NoArgumentsExecutor<>(object, method); + } + } if (parameterTypes.length == 1) { if (parameterTypes[0].isAssignableFrom(CommandSender.class)) { //CommandSender only From 1deaa5d5cbedb6f7f5f0adf0d0bcbae783a3c044 Mon Sep 17 00:00:00 2001 From: WizardlyBump17 Date: Mon, 10 Nov 2025 16:50:42 -0300 Subject: [PATCH 115/363] more tests --- .../method/MethodCommandExtractorTests.java | 65 +++++++++++++++++++ 1 file changed, 65 insertions(+) diff --git a/commands/src/test/java/com/wizardlybump17/wlib/test/command/extractor/method/MethodCommandExtractorTests.java b/commands/src/test/java/com/wizardlybump17/wlib/test/command/extractor/method/MethodCommandExtractorTests.java index 8cce39f6..4f9974d5 100644 --- a/commands/src/test/java/com/wizardlybump17/wlib/test/command/extractor/method/MethodCommandExtractorTests.java +++ b/commands/src/test/java/com/wizardlybump17/wlib/test/command/extractor/method/MethodCommandExtractorTests.java @@ -204,4 +204,69 @@ public static class Test2 { return CommandResult.successful(context, null); } } + + @Test + void test3() { + Test3 object = new Test3(); + + List expected = new ArrayList<>(List.of( + new Command( + new LiteralCommandNode( + "hello", + Assertions.assertDoesNotThrow(() -> MethodCommandExtractor.createExecutor(object, "hello", CommandSender.class)) + ) + ), + new Command( + new LiteralCommandNode( + "hello", + List.of( + new LiteralCommandNode( + "world", + Assertions.assertDoesNotThrow(() -> MethodCommandExtractor.createExecutor(object, "helloWorld", CommandSender.class)) + ) + ) + ) + ), + new Command( + new LiteralCommandNode( + "hello", + List.of( + new LiteralCommandNode( + "there", + List.of( + new LiteralCommandNode( + "hi", + Assertions.assertDoesNotThrow(() -> MethodCommandExtractor.createExecutor(object, "helloThereHi", CommandSender.class)) + ) + ) + ) + ) + ) + ) + )); + List actual = Assertions.assertDoesNotThrow(() -> CommandExtractor.METHOD.extract(object)); + + expected.sort(null); + actual.sort(null); + + Assertions.assertEquals(expected, actual); + } + + public static class Test3 { + + @com.wizardlybump17.wlib.command.annotation.Command("hello") + public @NotNull CommandResult hello(@NotNull CommandSender sender) { + return null; + } + + @com.wizardlybump17.wlib.command.annotation.Command("hello world") + public @NotNull CommandResult helloWorld(@NotNull CommandSender sender) { + return null; + } + + @com.wizardlybump17.wlib.command.annotation.Command("hello there hi") + public @NotNull CommandResult helloThereHi(@NotNull CommandSender sender) { + return null; + } + } } From a1e1fd3f7128d83e0e2f7f41dbc34a9efccf25a3 Mon Sep 17 00:00:00 2001 From: WizardlyBump17 Date: Mon, 10 Nov 2025 18:55:00 -0300 Subject: [PATCH 116/363] more tests --- .../AbstractMethodCommandNodeExecutor.java | 40 ++- ...hodCommandExtractorRightExecutorTests.java | 266 ++++++++++++++++++ 2 files changed, 293 insertions(+), 13 deletions(-) create mode 100644 commands/src/test/java/com/wizardlybump17/wlib/test/command/extractor/method/MethodCommandExtractorRightExecutorTests.java diff --git a/commands/src/main/java/com/wizardlybump17/wlib/command/extractor/method/AbstractMethodCommandNodeExecutor.java b/commands/src/main/java/com/wizardlybump17/wlib/command/extractor/method/AbstractMethodCommandNodeExecutor.java index b1322b37..dd4633d4 100644 --- a/commands/src/main/java/com/wizardlybump17/wlib/command/extractor/method/AbstractMethodCommandNodeExecutor.java +++ b/commands/src/main/java/com/wizardlybump17/wlib/command/extractor/method/AbstractMethodCommandNodeExecutor.java @@ -2,6 +2,7 @@ import com.wizardlybump17.wlib.command.context.CommandContext; import com.wizardlybump17.wlib.command.result.CommandResult; +import org.jetbrains.annotations.ApiStatus; import org.jetbrains.annotations.NotNull; import java.lang.invoke.MethodHandle; @@ -12,7 +13,8 @@ import java.util.List; import java.util.Objects; -abstract sealed class AbstractMethodCommandNodeExecutor implements MethodCommandNodeExecutor { +@ApiStatus.Internal +public abstract sealed class AbstractMethodCommandNodeExecutor implements MethodCommandNodeExecutor { private final @NotNull Object object; private final @NotNull MethodHandle methodHandle; @@ -66,7 +68,8 @@ public String toString() { '}'; } - static final class CommandSenderCommandResultExecutor extends AbstractMethodCommandNodeExecutor { + @ApiStatus.Internal + public static final class CommandSenderCommandResultExecutor extends AbstractMethodCommandNodeExecutor { public CommandSenderCommandResultExecutor(@NotNull Object object, @NotNull Method method) { super(object, method); @@ -86,7 +89,8 @@ public CommandSenderCommandResultExecutor(@NotNull Object object, @NotNull Metho } } - static final class CommandSenderExecutor extends AbstractMethodCommandNodeExecutor { + @ApiStatus.Internal + public static final class CommandSenderExecutor extends AbstractMethodCommandNodeExecutor { public CommandSenderExecutor(@NotNull Object object, @NotNull Method method) { super(object, method); @@ -106,7 +110,8 @@ public CommandSenderExecutor(@NotNull Object object, @NotNull Method method) { } } - static final class CommandContextCommandResultExecutor extends AbstractMethodCommandNodeExecutor { + @ApiStatus.Internal + public static final class CommandContextCommandResultExecutor extends AbstractMethodCommandNodeExecutor { public CommandContextCommandResultExecutor(@NotNull Object object, @NotNull Method method) { super(object, method); @@ -126,7 +131,8 @@ public CommandContextCommandResultExecutor(@NotNull Object object, @NotNull Meth } } - static final class CommandContextExecutor extends AbstractMethodCommandNodeExecutor { + @ApiStatus.Internal + public static final class CommandContextExecutor extends AbstractMethodCommandNodeExecutor { public CommandContextExecutor(@NotNull Object object, @NotNull Method method) { super(object, method); @@ -146,7 +152,8 @@ public CommandContextExecutor(@NotNull Object object, @NotNull Method method) { } } - static final class CommandSenderAndArgumentsCommandResultExecutor extends AbstractMethodCommandNodeExecutor { + @ApiStatus.Internal + public static final class CommandSenderAndArgumentsCommandResultExecutor extends AbstractMethodCommandNodeExecutor { public CommandSenderAndArgumentsCommandResultExecutor(@NotNull Object object, @NotNull Method method) { super(object, method); @@ -167,7 +174,8 @@ public CommandSenderAndArgumentsCommandResultExecutor(@NotNull Object object, @N } } - static final class CommandSenderAndArgumentsExecutor extends AbstractMethodCommandNodeExecutor { + @ApiStatus.Internal + public static final class CommandSenderAndArgumentsExecutor extends AbstractMethodCommandNodeExecutor { public CommandSenderAndArgumentsExecutor(@NotNull Object object, @NotNull Method method) { super(object, method); @@ -188,7 +196,8 @@ public CommandSenderAndArgumentsExecutor(@NotNull Object object, @NotNull Method } } - static final class CommandContextAndArgumentsCommandResultExecutor extends AbstractMethodCommandNodeExecutor { + @ApiStatus.Internal + public static final class CommandContextAndArgumentsCommandResultExecutor extends AbstractMethodCommandNodeExecutor { public CommandContextAndArgumentsCommandResultExecutor(@NotNull Object object, @NotNull Method method) { super(object, method); @@ -209,7 +218,8 @@ public CommandContextAndArgumentsCommandResultExecutor(@NotNull Object object, @ } } - static final class CommandContextAndArgumentsExecutor extends AbstractMethodCommandNodeExecutor { + @ApiStatus.Internal + public static final class CommandContextAndArgumentsExecutor extends AbstractMethodCommandNodeExecutor { public CommandContextAndArgumentsExecutor(@NotNull Object object, @NotNull Method method) { super(object, method); @@ -230,7 +240,8 @@ public CommandContextAndArgumentsExecutor(@NotNull Object object, @NotNull Metho } } - static final class ArgumentsCommandResultExecutor extends AbstractMethodCommandNodeExecutor { + @ApiStatus.Internal + public static final class ArgumentsCommandResultExecutor extends AbstractMethodCommandNodeExecutor { public ArgumentsCommandResultExecutor(@NotNull Object object, @NotNull Method method) { super(object, method); @@ -250,7 +261,8 @@ public ArgumentsCommandResultExecutor(@NotNull Object object, @NotNull Method me } } - static final class ArgumentsExecutor extends AbstractMethodCommandNodeExecutor { + @ApiStatus.Internal + public static final class ArgumentsExecutor extends AbstractMethodCommandNodeExecutor { public ArgumentsExecutor(@NotNull Object object, @NotNull Method method) { super(object, method); @@ -270,7 +282,8 @@ public ArgumentsExecutor(@NotNull Object object, @NotNull Method method) { } } - static final class NoArgumentsExecutor extends AbstractMethodCommandNodeExecutor { + @ApiStatus.Internal + public static final class NoArgumentsExecutor extends AbstractMethodCommandNodeExecutor { public NoArgumentsExecutor(@NotNull Object object, @NotNull Method method) { super(object, method); @@ -289,7 +302,8 @@ public NoArgumentsExecutor(@NotNull Object object, @NotNull Method method) { } } - static final class NoArgumentsCommandResultExecutor extends AbstractMethodCommandNodeExecutor { + @ApiStatus.Internal + public static final class NoArgumentsCommandResultExecutor extends AbstractMethodCommandNodeExecutor { public NoArgumentsCommandResultExecutor(@NotNull Object object, @NotNull Method method) { super(object, method); diff --git a/commands/src/test/java/com/wizardlybump17/wlib/test/command/extractor/method/MethodCommandExtractorRightExecutorTests.java b/commands/src/test/java/com/wizardlybump17/wlib/test/command/extractor/method/MethodCommandExtractorRightExecutorTests.java new file mode 100644 index 00000000..63301085 --- /dev/null +++ b/commands/src/test/java/com/wizardlybump17/wlib/test/command/extractor/method/MethodCommandExtractorRightExecutorTests.java @@ -0,0 +1,266 @@ +package com.wizardlybump17.wlib.test.command.extractor.method; + +import com.wizardlybump17.wlib.command.context.CommandContext; +import com.wizardlybump17.wlib.command.executor.CommandNodeExecutor; +import com.wizardlybump17.wlib.command.extractor.method.AbstractMethodCommandNodeExecutor; +import com.wizardlybump17.wlib.command.extractor.method.MethodCommandExtractor; +import com.wizardlybump17.wlib.command.result.CommandResult; +import com.wizardlybump17.wlib.command.sender.CommandSender; +import org.jetbrains.annotations.NotNull; +import org.junit.jupiter.api.Assertions; +import org.junit.jupiter.api.Test; + +import java.lang.reflect.Method; + +class MethodCommandExtractorRightExecutorTests { + + /* + No parameters + */ + + @Test + void testNoArgumentsCommandResult() { + TestNoArgumentsCommandResultExecutor object = new TestNoArgumentsCommandResultExecutor(); + + Method method = Assertions.assertDoesNotThrow(() -> object.getClass().getMethod("hello")); + + CommandNodeExecutor expected = new AbstractMethodCommandNodeExecutor.NoArgumentsCommandResultExecutor<>(object, method); + CommandNodeExecutor actual = MethodCommandExtractor.createExecutor(object, "hello"); + + Assertions.assertEquals(expected, actual); + } + + public static final class TestNoArgumentsCommandResultExecutor { + + @com.wizardlybump17.wlib.command.annotation.Command("hello world") + public CommandResult hello() { + return null; + } + } + + @Test + void testNoArguments() { + TestNoArgumentsExecutor object = new TestNoArgumentsExecutor(); + + Method method = Assertions.assertDoesNotThrow(() -> object.getClass().getMethod("hello")); + + CommandNodeExecutor expected = new AbstractMethodCommandNodeExecutor.NoArgumentsExecutor<>(object, method); + CommandNodeExecutor actual = MethodCommandExtractor.createExecutor(object, "hello"); + + Assertions.assertEquals(expected, actual); + } + + public static final class TestNoArgumentsExecutor { + + @com.wizardlybump17.wlib.command.annotation.Command("hello world") + public void hello() { + } + } + + /* + CommandSender/CommandContext only + */ + + @Test + void testCommandSenderCommandResult() { + TestCommandSenderCommandResultExecutor object = new TestCommandSenderCommandResultExecutor(); + + Method method = Assertions.assertDoesNotThrow(() -> object.getClass().getMethod("hello", CommandSender.class)); + + CommandNodeExecutor expected = new AbstractMethodCommandNodeExecutor.CommandSenderCommandResultExecutor<>(object, method); + CommandNodeExecutor actual = MethodCommandExtractor.createExecutor(object, "hello", CommandSender.class); + + Assertions.assertEquals(expected, actual); + } + + public static final class TestCommandSenderCommandResultExecutor { + + @com.wizardlybump17.wlib.command.annotation.Command("hello world") + public CommandResult hello(@NotNull CommandSender sender) { + return null; + } + } + + @Test + void testCommandSender() { + TestCommandSenderExecutor object = new TestCommandSenderExecutor(); + + Method method = Assertions.assertDoesNotThrow(() -> object.getClass().getMethod("hello", CommandSender.class)); + + CommandNodeExecutor expected = new AbstractMethodCommandNodeExecutor.CommandSenderExecutor<>(object, method); + CommandNodeExecutor actual = MethodCommandExtractor.createExecutor(object, "hello", CommandSender.class); + + Assertions.assertEquals(expected, actual); + } + + public static final class TestCommandSenderExecutor { + + @com.wizardlybump17.wlib.command.annotation.Command("hello world") + public void hello(@NotNull CommandSender sender) { + } + } + + @Test + void testCommandContextCommandResult() { + TestCommandContextCommandResultExecutor object = new TestCommandContextCommandResultExecutor(); + + Method method = Assertions.assertDoesNotThrow(() -> object.getClass().getMethod("hello", CommandContext.class)); + + CommandNodeExecutor expected = new AbstractMethodCommandNodeExecutor.CommandContextCommandResultExecutor<>(object, method); + CommandNodeExecutor actual = MethodCommandExtractor.createExecutor(object, "hello", CommandContext.class); + + Assertions.assertEquals(expected, actual); + } + + public static final class TestCommandContextCommandResultExecutor { + + @com.wizardlybump17.wlib.command.annotation.Command("hello world") + public CommandResult hello(@NotNull CommandContext context) { + return null; + } + } + + @Test + void testCommandContext() { + TestCommandContextExecutor object = new TestCommandContextExecutor(); + + Method method = Assertions.assertDoesNotThrow(() -> object.getClass().getMethod("hello", CommandContext.class)); + + CommandNodeExecutor expected = new AbstractMethodCommandNodeExecutor.CommandContextExecutor<>(object, method); + CommandNodeExecutor actual = MethodCommandExtractor.createExecutor(object, "hello", CommandContext.class); + + Assertions.assertEquals(expected, actual); + } + + public static final class TestCommandContextExecutor { + + @com.wizardlybump17.wlib.command.annotation.Command("hello world") + public void hello(@NotNull CommandContext context) { + } + } + + /* + CommandSender/CommandContext and parameters + */ + + @Test + void testCommandSenderAndArgumentsCommandResult() { + TestCommandSenderAndArgumentsCommandResultExecutor object = new TestCommandSenderAndArgumentsCommandResultExecutor(); + + Method method = Assertions.assertDoesNotThrow(() -> object.getClass().getMethod("hello", CommandSender.class, int.class)); + + CommandNodeExecutor expected = new AbstractMethodCommandNodeExecutor.CommandSenderAndArgumentsCommandResultExecutor<>(object, method); + CommandNodeExecutor actual = MethodCommandExtractor.createExecutor(object, "hello", CommandSender.class, int.class); + + Assertions.assertEquals(expected, actual); + } + + public static final class TestCommandSenderAndArgumentsCommandResultExecutor { + + @com.wizardlybump17.wlib.command.annotation.Command("hello world ") + public CommandResult hello(@NotNull CommandSender sender, int arg0) { + return null; + } + } + + @Test + void testCommandSenderAndArguments() { + TestCommandSenderAndArgumentsExecutor object = new TestCommandSenderAndArgumentsExecutor(); + + Method method = Assertions.assertDoesNotThrow(() -> object.getClass().getMethod("hello", CommandSender.class, int.class)); + + CommandNodeExecutor expected = new AbstractMethodCommandNodeExecutor.CommandSenderAndArgumentsExecutor<>(object, method); + CommandNodeExecutor actual = MethodCommandExtractor.createExecutor(object, "hello", CommandSender.class, int.class); + + Assertions.assertEquals(expected, actual); + } + + public static final class TestCommandSenderAndArgumentsExecutor { + + @com.wizardlybump17.wlib.command.annotation.Command("hello world ") + public void hello(@NotNull CommandSender sender, int arg0) { + } + } + + @Test + void testCommandContextAndArgumentsCommandResult() { + TestCommandContextAndArgumentsCommandResultExecutor object = new TestCommandContextAndArgumentsCommandResultExecutor(); + + Method method = Assertions.assertDoesNotThrow(() -> object.getClass().getMethod("hello", CommandContext.class, int.class)); + + CommandNodeExecutor expected = new AbstractMethodCommandNodeExecutor.CommandContextAndArgumentsCommandResultExecutor<>(object, method); + CommandNodeExecutor actual = MethodCommandExtractor.createExecutor(object, "hello", CommandContext.class, int.class); + + Assertions.assertEquals(expected, actual); + } + + public static final class TestCommandContextAndArgumentsCommandResultExecutor { + + @com.wizardlybump17.wlib.command.annotation.Command("hello world ") + public CommandResult hello(@NotNull CommandContext context, int arg0) { + return null; + } + } + + @Test + void testCommandContextAndArguments() { + TestCommandContextAndArgumentsExecutor object = new TestCommandContextAndArgumentsExecutor(); + + Method method = Assertions.assertDoesNotThrow(() -> object.getClass().getMethod("hello", CommandContext.class, int.class)); + + CommandNodeExecutor expected = new AbstractMethodCommandNodeExecutor.CommandContextAndArgumentsExecutor<>(object, method); + CommandNodeExecutor actual = MethodCommandExtractor.createExecutor(object, "hello", CommandContext.class, int.class); + + Assertions.assertEquals(expected, actual); + } + + public static final class TestCommandContextAndArgumentsExecutor { + + @com.wizardlybump17.wlib.command.annotation.Command("hello world ") + public void hello(@NotNull CommandContext context, int arg0) { + } + } + + /* + Parameters only + */ + + @Test + void testArgumentsCommandResult() { + TestArgumentsCommandResult object = new TestArgumentsCommandResult(); + + Method method = Assertions.assertDoesNotThrow(() -> object.getClass().getMethod("hello", int.class)); + + CommandNodeExecutor expected = new AbstractMethodCommandNodeExecutor.ArgumentsCommandResultExecutor<>(object, method); + CommandNodeExecutor actual = MethodCommandExtractor.createExecutor(object, "hello", int.class); + + Assertions.assertEquals(expected, actual); + } + + public static final class TestArgumentsCommandResult { + + @com.wizardlybump17.wlib.command.annotation.Command("hello world ") + public CommandResult hello(int arg0) { + return null; + } + } + + @Test + void testArguments() { + TestArguments object = new TestArguments(); + + Method method = Assertions.assertDoesNotThrow(() -> object.getClass().getMethod("hello", int.class)); + + CommandNodeExecutor expected = new AbstractMethodCommandNodeExecutor.ArgumentsExecutor<>(object, method); + CommandNodeExecutor actual = MethodCommandExtractor.createExecutor(object, "hello", int.class); + + Assertions.assertEquals(expected, actual); + } + + public static final class TestArguments { + + @com.wizardlybump17.wlib.command.annotation.Command("hello world ") + public void hello(int arg0) { + } + } +} From 9d3c8fc962dfe7ff159b38563347264a722f2125 Mon Sep 17 00:00:00 2001 From: WizardlyBump17 Date: Tue, 11 Nov 2025 17:26:33 -0300 Subject: [PATCH 117/363] renamed the tests --- .../method/MethodCommandExtractorTests.java | 30 +++++++++---------- 1 file changed, 15 insertions(+), 15 deletions(-) diff --git a/commands/src/test/java/com/wizardlybump17/wlib/test/command/extractor/method/MethodCommandExtractorTests.java b/commands/src/test/java/com/wizardlybump17/wlib/test/command/extractor/method/MethodCommandExtractorTests.java index 4f9974d5..0dcc6df9 100644 --- a/commands/src/test/java/com/wizardlybump17/wlib/test/command/extractor/method/MethodCommandExtractorTests.java +++ b/commands/src/test/java/com/wizardlybump17/wlib/test/command/extractor/method/MethodCommandExtractorTests.java @@ -17,8 +17,8 @@ class MethodCommandExtractorTests { @Test - void test0() { - Test0 object = new Test0(); + void testCommandSender() { + TestCommandSender object = new TestCommandSender(); List expected = new ArrayList<>(List.of( new Command( @@ -63,7 +63,7 @@ void test0() { Assertions.assertEquals(expected, actual); } - public static class Test0 { + public static class TestCommandSender { @com.wizardlybump17.wlib.command.annotation.Command("hello") public void hello(@NotNull CommandSender sender) { @@ -79,8 +79,8 @@ public void helloThereHi(@NotNull CommandSender sender) { } @Test - void test1() { - Test1 object = new Test1(); + void testCommandContext() { + TestCommandContext object = new TestCommandContext(); List expected = new ArrayList<>(List.of( new Command( @@ -125,7 +125,7 @@ void test1() { Assertions.assertEquals(expected, actual); } - public static class Test1 { + public static class TestCommandContext { @com.wizardlybump17.wlib.command.annotation.Command("hello") public void hello(@NotNull CommandContext context) { @@ -141,8 +141,8 @@ public void helloThereHi(@NotNull CommandContext context) { } @Test - void test2() { - Test2 object = new Test2(); + void testCommandContextCommandResult() { + TestCommandContextCommandResult object = new TestCommandContextCommandResult(); List expected = new ArrayList<>(List.of( new Command( @@ -187,7 +187,7 @@ void test2() { Assertions.assertEquals(expected, actual); } - public static class Test2 { + public static class TestCommandContextCommandResult { @com.wizardlybump17.wlib.command.annotation.Command("hello") public @NotNull CommandResult hello(@NotNull CommandContext context) { @@ -206,8 +206,8 @@ public static class Test2 { } @Test - void test3() { - Test3 object = new Test3(); + void testCommandSenderCommandResult() { + TestCommandSenderCommandResult object = new TestCommandSenderCommandResult(); List expected = new ArrayList<>(List.of( new Command( @@ -252,20 +252,20 @@ void test3() { Assertions.assertEquals(expected, actual); } - public static class Test3 { + public static class TestCommandSenderCommandResult { @com.wizardlybump17.wlib.command.annotation.Command("hello") - public @NotNull CommandResult hello(@NotNull CommandSender sender) { + public CommandResult hello(@NotNull CommandSender sender) { return null; } @com.wizardlybump17.wlib.command.annotation.Command("hello world") - public @NotNull CommandResult helloWorld(@NotNull CommandSender sender) { + public CommandResult helloWorld(@NotNull CommandSender sender) { return null; } @com.wizardlybump17.wlib.command.annotation.Command("hello there hi") - public @NotNull CommandResult helloThereHi(@NotNull CommandSender sender) { + public CommandResult helloThereHi(@NotNull CommandSender sender) { return null; } } From f9792b2b9ed12ee04388a5e2fca3bba45952f7a7 Mon Sep 17 00:00:00 2001 From: WizardlyBump17 Date: Tue, 11 Nov 2025 17:35:09 -0300 Subject: [PATCH 118/363] removing the < and > --- .../wlib/command/extractor/method/MethodCommandExtractor.java | 1 + 1 file changed, 1 insertion(+) diff --git a/commands/src/main/java/com/wizardlybump17/wlib/command/extractor/method/MethodCommandExtractor.java b/commands/src/main/java/com/wizardlybump17/wlib/command/extractor/method/MethodCommandExtractor.java index 185a4bc7..78efed2f 100644 --- a/commands/src/main/java/com/wizardlybump17/wlib/command/extractor/method/MethodCommandExtractor.java +++ b/commands/src/main/java/com/wizardlybump17/wlib/command/extractor/method/MethodCommandExtractor.java @@ -73,6 +73,7 @@ public boolean isAccepted(@NotNull Object object) { CommandNode newNode; if (part.charAt(0) == '<' && part.charAt(part.length() - 1) == '>') { + part = part.substring(1, part.length() - 1); if (type == int.class || type == Integer.class) { newNode = new IntegerCommandNode(part, root == null ? List.of() : List.of(root), new AllowedNumberInputs.AllowedIntegerInputs.Unlimited()); } else { From fa2af57dcc31439d33d28722a37d96ca9080cee0 Mon Sep 17 00:00:00 2001 From: WizardlyBump17 Date: Tue, 11 Nov 2025 17:36:44 -0300 Subject: [PATCH 119/363] added more tests --- .../method/MethodCommandExtractorTests.java | 174 ++++++++++++++++++ 1 file changed, 174 insertions(+) diff --git a/commands/src/test/java/com/wizardlybump17/wlib/test/command/extractor/method/MethodCommandExtractorTests.java b/commands/src/test/java/com/wizardlybump17/wlib/test/command/extractor/method/MethodCommandExtractorTests.java index 0dcc6df9..8edfa2a7 100644 --- a/commands/src/test/java/com/wizardlybump17/wlib/test/command/extractor/method/MethodCommandExtractorTests.java +++ b/commands/src/test/java/com/wizardlybump17/wlib/test/command/extractor/method/MethodCommandExtractorTests.java @@ -4,6 +4,8 @@ import com.wizardlybump17.wlib.command.context.CommandContext; import com.wizardlybump17.wlib.command.extractor.CommandExtractor; import com.wizardlybump17.wlib.command.extractor.method.MethodCommandExtractor; +import com.wizardlybump17.wlib.command.input.AllowedNumberInputs; +import com.wizardlybump17.wlib.command.node.IntegerCommandNode; import com.wizardlybump17.wlib.command.node.LiteralCommandNode; import com.wizardlybump17.wlib.command.result.CommandResult; import com.wizardlybump17.wlib.command.sender.CommandSender; @@ -16,6 +18,10 @@ class MethodCommandExtractorTests { + /* + CommandSender/CommandContext only + */ + @Test void testCommandSender() { TestCommandSender object = new TestCommandSender(); @@ -140,6 +146,10 @@ public void helloThereHi(@NotNull CommandContext context) { } } + /* + CommandSender/CommandSender returning CommandResult + */ + @Test void testCommandContextCommandResult() { TestCommandContextCommandResult object = new TestCommandContextCommandResult(); @@ -269,4 +279,168 @@ public CommandResult helloThereHi(@NotNull CommandSender sender) { return null; } } + + /* + CommandSender/CommandContext + parameters + */ + + @Test + void testCommandSenderParameters() { + TestCommandSenderParameters object = new TestCommandSenderParameters(); + + List expected = new ArrayList<>(List.of( + new Command( + new LiteralCommandNode( + "hello", + List.of( + new IntegerCommandNode( + "int", + new AllowedNumberInputs.AllowedIntegerInputs.Unlimited(), + Assertions.assertDoesNotThrow(() -> MethodCommandExtractor.createExecutor(object, "hello", CommandSender.class, int.class)) + ) + ) + ) + ), + new Command( + new LiteralCommandNode( + "hello", + List.of( + new LiteralCommandNode( + "world", + List.of( + new IntegerCommandNode( + "int", + new AllowedNumberInputs.AllowedIntegerInputs.Unlimited(), + Assertions.assertDoesNotThrow(() -> MethodCommandExtractor.createExecutor(object, "helloWorld", CommandSender.class, int.class)) + ) + ) + ) + ) + ) + ), + new Command( + new LiteralCommandNode( + "hello", + List.of( + new LiteralCommandNode( + "there", + List.of( + new LiteralCommandNode( + "hi", + List.of( + new IntegerCommandNode( + "int", + new AllowedNumberInputs.AllowedIntegerInputs.Unlimited(), + Assertions.assertDoesNotThrow(() -> MethodCommandExtractor.createExecutor(object, "helloThereHi", CommandSender.class, int.class)) + ) + ) + ) + ) + ) + ) + ) + ) + )); + List actual = Assertions.assertDoesNotThrow(() -> CommandExtractor.METHOD.extract(object)); + + expected.sort(null); + actual.sort(null); + + Assertions.assertEquals(expected, actual); + } + + public static class TestCommandSenderParameters { + + @com.wizardlybump17.wlib.command.annotation.Command("hello ") + public void hello(@NotNull CommandSender sender, int arg0) { + } + + @com.wizardlybump17.wlib.command.annotation.Command("hello world ") + public void helloWorld(@NotNull CommandSender sender, int arg0) { + } + + @com.wizardlybump17.wlib.command.annotation.Command("hello there hi ") + public void helloThereHi(@NotNull CommandSender sender, int arg0) { + } + } + + @Test + void testCommandContextParameters() { + TestCommandContextParameters object = new TestCommandContextParameters(); + + List expected = new ArrayList<>(List.of( + new Command( + new LiteralCommandNode( + "hello", + List.of( + new IntegerCommandNode( + "int", + new AllowedNumberInputs.AllowedIntegerInputs.Unlimited(), + Assertions.assertDoesNotThrow(() -> MethodCommandExtractor.createExecutor(object, "hello", CommandContext.class, int.class)) + ) + ) + ) + ), + new Command( + new LiteralCommandNode( + "hello", + List.of( + new LiteralCommandNode( + "world", + List.of( + new IntegerCommandNode( + "int", + new AllowedNumberInputs.AllowedIntegerInputs.Unlimited(), + Assertions.assertDoesNotThrow(() -> MethodCommandExtractor.createExecutor(object, "helloWorld", CommandContext.class, int.class)) + ) + ) + ) + ) + ) + ), + new Command( + new LiteralCommandNode( + "hello", + List.of( + new LiteralCommandNode( + "there", + List.of( + new LiteralCommandNode( + "hi", + List.of( + new IntegerCommandNode( + "int", + new AllowedNumberInputs.AllowedIntegerInputs.Unlimited(), + Assertions.assertDoesNotThrow(() -> MethodCommandExtractor.createExecutor(object, "helloThereHi", CommandContext.class, int.class)) + ) + ) + ) + ) + ) + ) + ) + ) + )); + List actual = Assertions.assertDoesNotThrow(() -> CommandExtractor.METHOD.extract(object)); + + expected.sort(null); + actual.sort(null); + + Assertions.assertEquals(expected, actual); + } + + public static class TestCommandContextParameters { + + @com.wizardlybump17.wlib.command.annotation.Command("hello ") + public void hello(@NotNull CommandContext context, int arg0) { + } + + @com.wizardlybump17.wlib.command.annotation.Command("hello world ") + public void helloWorld(@NotNull CommandContext context, int arg0) { + } + + @com.wizardlybump17.wlib.command.annotation.Command("hello there hi ") + public void helloThereHi(@NotNull CommandContext context, int arg0) { + } + } } From ce52c798edd907b5cb98fd3281c7f8effd6a10d3 Mon Sep 17 00:00:00 2001 From: WizardlyBump17 Date: Tue, 11 Nov 2025 17:52:44 -0300 Subject: [PATCH 120/363] added more tests --- .../method/MethodCommandExtractorTests.java | 170 ++++++++++++++++++ 1 file changed, 170 insertions(+) diff --git a/commands/src/test/java/com/wizardlybump17/wlib/test/command/extractor/method/MethodCommandExtractorTests.java b/commands/src/test/java/com/wizardlybump17/wlib/test/command/extractor/method/MethodCommandExtractorTests.java index 8edfa2a7..bd9c1376 100644 --- a/commands/src/test/java/com/wizardlybump17/wlib/test/command/extractor/method/MethodCommandExtractorTests.java +++ b/commands/src/test/java/com/wizardlybump17/wlib/test/command/extractor/method/MethodCommandExtractorTests.java @@ -443,4 +443,174 @@ public void helloWorld(@NotNull CommandContext context, int arg0) { public void helloThereHi(@NotNull CommandContext context, int arg0) { } } + + /* + CommandSender/CommandContext + parameters returning CommandResult + */ + + @Test + void testCommandSenderParametersCommandResult() { + TestCommandSenderParametersCommandResult object = new TestCommandSenderParametersCommandResult(); + + List expected = new ArrayList<>(List.of( + new Command( + new LiteralCommandNode( + "hello", + List.of( + new IntegerCommandNode( + "int", + new AllowedNumberInputs.AllowedIntegerInputs.Unlimited(), + Assertions.assertDoesNotThrow(() -> MethodCommandExtractor.createExecutor(object, "hello", CommandSender.class, int.class)) + ) + ) + ) + ), + new Command( + new LiteralCommandNode( + "hello", + List.of( + new LiteralCommandNode( + "world", + List.of( + new IntegerCommandNode( + "int", + new AllowedNumberInputs.AllowedIntegerInputs.Unlimited(), + Assertions.assertDoesNotThrow(() -> MethodCommandExtractor.createExecutor(object, "helloWorld", CommandSender.class, int.class)) + ) + ) + ) + ) + ) + ), + new Command( + new LiteralCommandNode( + "hello", + List.of( + new LiteralCommandNode( + "there", + List.of( + new LiteralCommandNode( + "hi", + List.of( + new IntegerCommandNode( + "int", + new AllowedNumberInputs.AllowedIntegerInputs.Unlimited(), + Assertions.assertDoesNotThrow(() -> MethodCommandExtractor.createExecutor(object, "helloThereHi", CommandSender.class, int.class)) + ) + ) + ) + ) + ) + ) + ) + ) + )); + List actual = Assertions.assertDoesNotThrow(() -> CommandExtractor.METHOD.extract(object)); + + expected.sort(null); + actual.sort(null); + + Assertions.assertEquals(expected, actual); + } + + public static class TestCommandSenderParametersCommandResult { + + @com.wizardlybump17.wlib.command.annotation.Command("hello ") + public CommandResult hello(@NotNull CommandSender sender, int arg0) { + return null; + } + + @com.wizardlybump17.wlib.command.annotation.Command("hello world ") + public CommandResult helloWorld(@NotNull CommandSender sender, int arg0) { + return null; + } + + @com.wizardlybump17.wlib.command.annotation.Command("hello there hi ") + public CommandResult helloThereHi(@NotNull CommandSender sender, int arg0) { + return null; + } + } + + @Test + void testCommandContextParametersCommandResult() { + TestCommandContextParametersCommandResult object = new TestCommandContextParametersCommandResult(); + + List expected = new ArrayList<>(List.of( + new Command( + new LiteralCommandNode( + "hello", + List.of( + new IntegerCommandNode( + "int", + new AllowedNumberInputs.AllowedIntegerInputs.Unlimited(), + Assertions.assertDoesNotThrow(() -> MethodCommandExtractor.createExecutor(object, "hello", CommandContext.class, int.class)) + ) + ) + ) + ), + new Command( + new LiteralCommandNode( + "hello", + List.of( + new LiteralCommandNode( + "world", + List.of( + new IntegerCommandNode( + "int", + new AllowedNumberInputs.AllowedIntegerInputs.Unlimited(), + Assertions.assertDoesNotThrow(() -> MethodCommandExtractor.createExecutor(object, "helloWorld", CommandContext.class, int.class)) + ) + ) + ) + ) + ) + ), + new Command( + new LiteralCommandNode( + "hello", + List.of( + new LiteralCommandNode( + "there", + List.of( + new LiteralCommandNode( + "hi", + List.of( + new IntegerCommandNode( + "int", + new AllowedNumberInputs.AllowedIntegerInputs.Unlimited(), + Assertions.assertDoesNotThrow(() -> MethodCommandExtractor.createExecutor(object, "helloThereHi", CommandContext.class, int.class)) + ) + ) + ) + ) + ) + ) + ) + ) + )); + List actual = Assertions.assertDoesNotThrow(() -> CommandExtractor.METHOD.extract(object)); + + expected.sort(null); + actual.sort(null); + + Assertions.assertEquals(expected, actual); + } + + public static class TestCommandContextParametersCommandResult { + + @com.wizardlybump17.wlib.command.annotation.Command("hello ") + public CommandResult hello(@NotNull CommandContext context, int arg0) { + return null; + } + + @com.wizardlybump17.wlib.command.annotation.Command("hello world ") + public CommandResult helloWorld(@NotNull CommandContext context, int arg0) { + return null; + } + + @com.wizardlybump17.wlib.command.annotation.Command("hello there hi ") + public CommandResult helloThereHi(@NotNull CommandContext context, int arg0) { + return null; + } + } } From 0eef0aec73346c04c1201140144b8a48c5ca936c Mon Sep 17 00:00:00 2001 From: WizardlyBump17 Date: Tue, 11 Nov 2025 18:01:34 -0300 Subject: [PATCH 121/363] properly handling the no parameters case --- .../method/MethodCommandExtractor.java | 28 +++++++++++-------- 1 file changed, 17 insertions(+), 11 deletions(-) diff --git a/commands/src/main/java/com/wizardlybump17/wlib/command/extractor/method/MethodCommandExtractor.java b/commands/src/main/java/com/wizardlybump17/wlib/command/extractor/method/MethodCommandExtractor.java index 78efed2f..6aa3b157 100644 --- a/commands/src/main/java/com/wizardlybump17/wlib/command/extractor/method/MethodCommandExtractor.java +++ b/commands/src/main/java/com/wizardlybump17/wlib/command/extractor/method/MethodCommandExtractor.java @@ -44,15 +44,12 @@ public boolean isAccepted(@NotNull Object object) { CommandNode root = null; - if (parameterTypes.length == 0) - throw new IllegalArgumentException(); - int parameterIndex = parameterTypes.length - 1; for (int i = commandParts.length - 1; i >= 0; i--) { String part = commandParts[i]; CommandNode oldRoot = root; - root = createNode(part, parameterTypes[parameterIndex], root, annotation); + root = createNode(part, parameterTypes, parameterIndex, root, annotation); if (!(root instanceof LiteralCommandNode)) parameterIndex--; @@ -69,18 +66,27 @@ public boolean isAccepted(@NotNull Object object) { return commands; } - private static @NotNull CommandNode createNode(@NotNull String part, @NotNull Class type, @Nullable CommandNode root, @NotNull com.wizardlybump17.wlib.command.annotation.Command annotation) { + private static @NotNull CommandNode createNode(@NotNull String part, @NotNull Class @NotNull [] parameterTypes, int parameterIndex, @Nullable CommandNode root, @NotNull com.wizardlybump17.wlib.command.annotation.Command annotation) { CommandNode newNode; - if (part.charAt(0) == '<' && part.charAt(part.length() - 1) == '>') { + boolean argument = part.charAt(0) == '<' && part.charAt(part.length() - 1) == '>'; + if (argument) part = part.substring(1, part.length() - 1); - if (type == int.class || type == Integer.class) { - newNode = new IntegerCommandNode(part, root == null ? List.of() : List.of(root), new AllowedNumberInputs.AllowedIntegerInputs.Unlimited()); + + if (parameterIndex < 1) { + newNode = new LiteralCommandNode(part, root == null ? List.of() : List.of(root)); + } else { + Class parameterType = parameterTypes[parameterIndex]; + + if (argument) { + if (parameterType == int.class || parameterType == Integer.class) { + newNode = new IntegerCommandNode(part, root == null ? List.of() : List.of(root), new AllowedNumberInputs.AllowedIntegerInputs.Unlimited()); + } else { + throw new UnsupportedOperationException(); + } } else { - throw new UnsupportedOperationException(); + newNode = new LiteralCommandNode(part, root == null ? List.of() : List.of(root)); } - } else { - newNode = new LiteralCommandNode(part, root == null ? List.of() : List.of(root)); } if (!annotation.permission().isEmpty()) From ba63b250d62427da025e460a8b5e8021406c1f62 Mon Sep 17 00:00:00 2001 From: WizardlyBump17 Date: Tue, 11 Nov 2025 18:02:49 -0300 Subject: [PATCH 122/363] added more tests --- .../method/MethodCommandExtractorTests.java | 133 ++++++++++++++++++ 1 file changed, 133 insertions(+) diff --git a/commands/src/test/java/com/wizardlybump17/wlib/test/command/extractor/method/MethodCommandExtractorTests.java b/commands/src/test/java/com/wizardlybump17/wlib/test/command/extractor/method/MethodCommandExtractorTests.java index bd9c1376..3ca20401 100644 --- a/commands/src/test/java/com/wizardlybump17/wlib/test/command/extractor/method/MethodCommandExtractorTests.java +++ b/commands/src/test/java/com/wizardlybump17/wlib/test/command/extractor/method/MethodCommandExtractorTests.java @@ -18,6 +18,139 @@ class MethodCommandExtractorTests { + /* + No parameters + */ + @Test + void testNoParameters() { + TestNoParameters object = new TestNoParameters(); + + List expected = new ArrayList<>(List.of( + new Command( + new LiteralCommandNode( + "hello", + Assertions.assertDoesNotThrow(() -> MethodCommandExtractor.createExecutor(object, "hello")) + ) + ), + new Command( + new LiteralCommandNode( + "hello", + List.of( + new LiteralCommandNode( + "world", + Assertions.assertDoesNotThrow(() -> MethodCommandExtractor.createExecutor(object, "helloWorld")) + ) + ) + ) + ), + new Command( + new LiteralCommandNode( + "hello", + List.of( + new LiteralCommandNode( + "there", + List.of( + new LiteralCommandNode( + "hi", + Assertions.assertDoesNotThrow(() -> MethodCommandExtractor.createExecutor(object, "helloThereHi")) + ) + ) + ) + ) + ) + ) + )); + List actual = CommandExtractor.METHOD.extract(object); + + expected.sort(null); + actual.sort(null); + + Assertions.assertEquals(expected, actual); + } + + public static class TestNoParameters { + + @com.wizardlybump17.wlib.command.annotation.Command("hello") + public void hello() { + } + + @com.wizardlybump17.wlib.command.annotation.Command("hello world") + public void helloWorld() { + } + + @com.wizardlybump17.wlib.command.annotation.Command("hello there hi") + public void helloThereHi() { + } + } + + /* + No parameters returning CommandResult + */ + @Test + void testNoParametersCommandResult() { + TestNoParametersCommandResult object = new TestNoParametersCommandResult(); + + List expected = new ArrayList<>(List.of( + new Command( + new LiteralCommandNode( + "hello", + Assertions.assertDoesNotThrow(() -> MethodCommandExtractor.createExecutor(object, "hello")) + ) + ), + new Command( + new LiteralCommandNode( + "hello", + List.of( + new LiteralCommandNode( + "world", + Assertions.assertDoesNotThrow(() -> MethodCommandExtractor.createExecutor(object, "helloWorld")) + ) + ) + ) + ), + new Command( + new LiteralCommandNode( + "hello", + List.of( + new LiteralCommandNode( + "there", + List.of( + new LiteralCommandNode( + "hi", + Assertions.assertDoesNotThrow(() -> MethodCommandExtractor.createExecutor(object, "helloThereHi")) + ) + ) + ) + ) + ) + ) + )); + List actual = CommandExtractor.METHOD.extract(object); + + expected.sort(null); + actual.sort(null); + + Assertions.assertEquals(expected, actual); + } + + public static class TestNoParametersCommandResult { + + @com.wizardlybump17.wlib.command.annotation.Command("hello") + public CommandResult hello() { + return null; + } + + @com.wizardlybump17.wlib.command.annotation.Command("hello world") + public CommandResult helloWorld() { + return null; + } + + @com.wizardlybump17.wlib.command.annotation.Command("hello there hi") + public CommandResult helloThereHi() { + return null; + } + } + /* CommandSender/CommandContext only */ From 530d1e6906ce2b5394f74793722b3d2746257e66 Mon Sep 17 00:00:00 2001 From: WizardlyBump17 Date: Tue, 11 Nov 2025 18:08:27 -0300 Subject: [PATCH 123/363] if less than zero --- .../wlib/command/extractor/method/MethodCommandExtractor.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/commands/src/main/java/com/wizardlybump17/wlib/command/extractor/method/MethodCommandExtractor.java b/commands/src/main/java/com/wizardlybump17/wlib/command/extractor/method/MethodCommandExtractor.java index 6aa3b157..02012e78 100644 --- a/commands/src/main/java/com/wizardlybump17/wlib/command/extractor/method/MethodCommandExtractor.java +++ b/commands/src/main/java/com/wizardlybump17/wlib/command/extractor/method/MethodCommandExtractor.java @@ -73,7 +73,7 @@ public boolean isAccepted(@NotNull Object object) { if (argument) part = part.substring(1, part.length() - 1); - if (parameterIndex < 1) { + if (parameterIndex < 0) { newNode = new LiteralCommandNode(part, root == null ? List.of() : List.of(root)); } else { Class parameterType = parameterTypes[parameterIndex]; From 4b9876631de0c3ee63d62a0c82ebd3b9542db77d Mon Sep 17 00:00:00 2001 From: WizardlyBump17 Date: Tue, 11 Nov 2025 18:10:06 -0300 Subject: [PATCH 124/363] added more tests --- .../method/MethodCommandExtractorTests.java | 171 ++++++++++++++++++ 1 file changed, 171 insertions(+) diff --git a/commands/src/test/java/com/wizardlybump17/wlib/test/command/extractor/method/MethodCommandExtractorTests.java b/commands/src/test/java/com/wizardlybump17/wlib/test/command/extractor/method/MethodCommandExtractorTests.java index 3ca20401..134e182d 100644 --- a/commands/src/test/java/com/wizardlybump17/wlib/test/command/extractor/method/MethodCommandExtractorTests.java +++ b/commands/src/test/java/com/wizardlybump17/wlib/test/command/extractor/method/MethodCommandExtractorTests.java @@ -746,4 +746,175 @@ public CommandResult helloThereHi(@NotNull CommandContext context, int arg0) return null; } } + + /* + Parameters not starting with CommandSender/CommandContext + */ + + @Test + void testParametersPure() { + TestParametersPure object = new TestParametersPure(); + + List expected = new ArrayList<>(List.of( + new Command( + new LiteralCommandNode( + "hello", + List.of( + new IntegerCommandNode( + "int", + new AllowedNumberInputs.AllowedIntegerInputs.Unlimited(), + Assertions.assertDoesNotThrow(() -> MethodCommandExtractor.createExecutor(object, "hello", int.class)) + ) + ) + ) + ), + new Command( + new LiteralCommandNode( + "hello", + List.of( + new LiteralCommandNode( + "world", + List.of( + new IntegerCommandNode( + "int", + new AllowedNumberInputs.AllowedIntegerInputs.Unlimited(), + Assertions.assertDoesNotThrow(() -> MethodCommandExtractor.createExecutor(object, "helloWorld", int.class)) + ) + ) + ) + ) + ) + ), + new Command( + new LiteralCommandNode( + "hello", + List.of( + new LiteralCommandNode( + "there", + List.of( + new LiteralCommandNode( + "hi", + List.of( + new IntegerCommandNode( + "int", + new AllowedNumberInputs.AllowedIntegerInputs.Unlimited(), + Assertions.assertDoesNotThrow(() -> MethodCommandExtractor.createExecutor(object, "helloThereHi", int.class)) + ) + ) + ) + ) + ) + ) + ) + ) + )); + List actual = Assertions.assertDoesNotThrow(() -> CommandExtractor.METHOD.extract(object)); + + expected.sort(null); + actual.sort(null); + + Assertions.assertEquals(expected, actual); + } + + public static class TestParametersPure { + + @com.wizardlybump17.wlib.command.annotation.Command("hello ") + public void hello(int arg0) { + } + + @com.wizardlybump17.wlib.command.annotation.Command("hello world ") + public void helloWorld(int arg0) { + } + + @com.wizardlybump17.wlib.command.annotation.Command("hello there hi ") + public void helloThereHi(int arg0) { + } + } + + /* + Parameters not starting with CommandSender/CommandContext returning CommandResult + */ + + @Test + void testParametersPureCommandResult() { + TestParametersPureCommandResult object = new TestParametersPureCommandResult(); + + List expected = new ArrayList<>(List.of( + new Command( + new LiteralCommandNode( + "hello", + List.of( + new IntegerCommandNode( + "int", + new AllowedNumberInputs.AllowedIntegerInputs.Unlimited(), + Assertions.assertDoesNotThrow(() -> MethodCommandExtractor.createExecutor(object, "hello", int.class)) + ) + ) + ) + ), + new Command( + new LiteralCommandNode( + "hello", + List.of( + new LiteralCommandNode( + "world", + List.of( + new IntegerCommandNode( + "int", + new AllowedNumberInputs.AllowedIntegerInputs.Unlimited(), + Assertions.assertDoesNotThrow(() -> MethodCommandExtractor.createExecutor(object, "helloWorld", int.class)) + ) + ) + ) + ) + ) + ), + new Command( + new LiteralCommandNode( + "hello", + List.of( + new LiteralCommandNode( + "there", + List.of( + new LiteralCommandNode( + "hi", + List.of( + new IntegerCommandNode( + "int", + new AllowedNumberInputs.AllowedIntegerInputs.Unlimited(), + Assertions.assertDoesNotThrow(() -> MethodCommandExtractor.createExecutor(object, "helloThereHi", int.class)) + ) + ) + ) + ) + ) + ) + ) + ) + )); + List actual = Assertions.assertDoesNotThrow(() -> CommandExtractor.METHOD.extract(object)); + + expected.sort(null); + actual.sort(null); + + Assertions.assertEquals(expected, actual); + } + + public static class TestParametersPureCommandResult { + + @com.wizardlybump17.wlib.command.annotation.Command("hello ") + public CommandResult hello(int arg0) { + return null; + } + + @com.wizardlybump17.wlib.command.annotation.Command("hello world ") + public CommandResult helloWorld(int arg0) { + return null; + } + + @com.wizardlybump17.wlib.command.annotation.Command("hello there hi ") + public CommandResult helloThereHi(int arg0) { + return null; + } + } } From f028176b35d383b1ebdeded3f4a14390c5e8b8ab Mon Sep 17 00:00:00 2001 From: WizardlyBump17 Date: Tue, 11 Nov 2025 18:49:05 -0300 Subject: [PATCH 125/363] added the String node --- .../method/MethodCommandExtractor.java | 3 + .../wlib/command/node/StringCommandNode.java | 60 +++++++++++++++++++ 2 files changed, 63 insertions(+) create mode 100644 commands/src/main/java/com/wizardlybump17/wlib/command/node/StringCommandNode.java diff --git a/commands/src/main/java/com/wizardlybump17/wlib/command/extractor/method/MethodCommandExtractor.java b/commands/src/main/java/com/wizardlybump17/wlib/command/extractor/method/MethodCommandExtractor.java index 02012e78..6d4e39e9 100644 --- a/commands/src/main/java/com/wizardlybump17/wlib/command/extractor/method/MethodCommandExtractor.java +++ b/commands/src/main/java/com/wizardlybump17/wlib/command/extractor/method/MethodCommandExtractor.java @@ -8,6 +8,7 @@ import com.wizardlybump17.wlib.command.node.CommandNode; import com.wizardlybump17.wlib.command.node.IntegerCommandNode; import com.wizardlybump17.wlib.command.node.LiteralCommandNode; +import com.wizardlybump17.wlib.command.node.StringCommandNode; import com.wizardlybump17.wlib.command.result.CommandResult; import com.wizardlybump17.wlib.command.sender.CommandSender; import org.jetbrains.annotations.NotNull; @@ -81,6 +82,8 @@ public boolean isAccepted(@NotNull Object object) { if (argument) { if (parameterType == int.class || parameterType == Integer.class) { newNode = new IntegerCommandNode(part, root == null ? List.of() : List.of(root), new AllowedNumberInputs.AllowedIntegerInputs.Unlimited()); + } else if (parameterType == String.class) { + newNode = new StringCommandNode(part, root == null ? List.of() : List.of(root), $ -> true); } else { throw new UnsupportedOperationException(); } diff --git a/commands/src/main/java/com/wizardlybump17/wlib/command/node/StringCommandNode.java b/commands/src/main/java/com/wizardlybump17/wlib/command/node/StringCommandNode.java new file mode 100644 index 00000000..578a9aea --- /dev/null +++ b/commands/src/main/java/com/wizardlybump17/wlib/command/node/StringCommandNode.java @@ -0,0 +1,60 @@ +package com.wizardlybump17.wlib.command.node; + +import com.wizardlybump17.wlib.command.exception.InputParsingException; +import com.wizardlybump17.wlib.command.executor.CommandNodeExecutor; +import com.wizardlybump17.wlib.command.input.AllowedInputs; +import org.jetbrains.annotations.NotNull; +import org.jetbrains.annotations.Nullable; + +import java.util.List; + +public class StringCommandNode extends CommandNode { + + public StringCommandNode(@NotNull String name, @NotNull List> children, @NotNull AllowedInputs allowedInputs, @Nullable CommandNodeExecutor executor, @Nullable String permission) { + super(name, children, allowedInputs, executor, permission); + } + + public StringCommandNode(@NotNull String name, @NotNull AllowedInputs allowedInputs, @Nullable CommandNodeExecutor executor, @Nullable String permission) { + super(name, allowedInputs, executor, permission); + } + + public StringCommandNode(@NotNull String name, @NotNull List> children, @NotNull AllowedInputs allowedInputs, @Nullable String permission) { + super(name, children, allowedInputs, permission); + } + + public StringCommandNode(@NotNull String name, @NotNull AllowedInputs allowedInputs, @Nullable String permission) { + super(name, allowedInputs, permission); + } + + public StringCommandNode(@NotNull String name, @NotNull AllowedInputs allowedInputs, @Nullable CommandNodeExecutor executor) { + super(name, allowedInputs, executor); + } + + public StringCommandNode(@NotNull String name, @NotNull List> children, @NotNull AllowedInputs allowedInputs) { + super(name, children, allowedInputs); + } + + public StringCommandNode(@NotNull String name, @NotNull AllowedInputs allowedInputs) { + super(name, allowedInputs); + } + + @Override + public @Nullable String parse(@NotNull String input) throws InputParsingException { + return input; + } + + @Override + public @NotNull StringCommandNode withChildren(@NotNull List> children) { + return new StringCommandNode(getName(), children, getAllowedInputs(), getExecutor(), getPermission()); + } + + @Override + public @NotNull StringCommandNode withExecutor(@Nullable CommandNodeExecutor executor) { + return new StringCommandNode(getName(), getChildren(), getAllowedInputs(), executor, getPermission()); + } + + @Override + public @NotNull StringCommandNode withPermission(@Nullable String permission) { + return new StringCommandNode(getName(), getChildren(), getAllowedInputs(), getExecutor(), permission); + } +} From 8ebe6a39365bda9e60069f7f892366bda23bbd78 Mon Sep 17 00:00:00 2001 From: WizardlyBump17 Date: Tue, 11 Nov 2025 19:27:16 -0300 Subject: [PATCH 126/363] added some allowed inputs for strings --- .../method/MethodCommandExtractor.java | 3 +- .../input/string/AllowedStringInputs.java | 95 +++++++++++++++++++ 2 files changed, 97 insertions(+), 1 deletion(-) create mode 100644 commands/src/main/java/com/wizardlybump17/wlib/command/input/string/AllowedStringInputs.java diff --git a/commands/src/main/java/com/wizardlybump17/wlib/command/extractor/method/MethodCommandExtractor.java b/commands/src/main/java/com/wizardlybump17/wlib/command/extractor/method/MethodCommandExtractor.java index 6d4e39e9..1ec51712 100644 --- a/commands/src/main/java/com/wizardlybump17/wlib/command/extractor/method/MethodCommandExtractor.java +++ b/commands/src/main/java/com/wizardlybump17/wlib/command/extractor/method/MethodCommandExtractor.java @@ -5,6 +5,7 @@ import com.wizardlybump17.wlib.command.executor.CommandNodeExecutor; import com.wizardlybump17.wlib.command.extractor.CommandExtractor; import com.wizardlybump17.wlib.command.input.AllowedNumberInputs; +import com.wizardlybump17.wlib.command.input.string.AllowedStringInputs; import com.wizardlybump17.wlib.command.node.CommandNode; import com.wizardlybump17.wlib.command.node.IntegerCommandNode; import com.wizardlybump17.wlib.command.node.LiteralCommandNode; @@ -83,7 +84,7 @@ public boolean isAccepted(@NotNull Object object) { if (parameterType == int.class || parameterType == Integer.class) { newNode = new IntegerCommandNode(part, root == null ? List.of() : List.of(root), new AllowedNumberInputs.AllowedIntegerInputs.Unlimited()); } else if (parameterType == String.class) { - newNode = new StringCommandNode(part, root == null ? List.of() : List.of(root), $ -> true); + newNode = new StringCommandNode(part, root == null ? List.of() : List.of(root), new AllowedStringInputs.Any()); } else { throw new UnsupportedOperationException(); } diff --git a/commands/src/main/java/com/wizardlybump17/wlib/command/input/string/AllowedStringInputs.java b/commands/src/main/java/com/wizardlybump17/wlib/command/input/string/AllowedStringInputs.java new file mode 100644 index 00000000..8f6e3a34 --- /dev/null +++ b/commands/src/main/java/com/wizardlybump17/wlib/command/input/string/AllowedStringInputs.java @@ -0,0 +1,95 @@ +package com.wizardlybump17.wlib.command.input.string; + +import com.wizardlybump17.wlib.command.input.AllowedInputs; +import com.wizardlybump17.wlib.command.sender.CommandSender; +import org.jetbrains.annotations.NotNull; +import org.jetbrains.annotations.Nullable; +import org.jetbrains.annotations.Unmodifiable; + +import java.util.List; +import java.util.Objects; + +public interface AllowedStringInputs extends AllowedInputs { + + final class Listed implements AllowedStringInputs { + + private final @NotNull List list; + private final @NotNull List listToCheck; + private final boolean ignoreCase; + + public Listed(@NotNull List list, boolean ignoreCase) { + this.list = List.copyOf(list); + if (ignoreCase) { + listToCheck = list.stream() + .map(String::toLowerCase) + .toList(); + } else { + listToCheck = list; + } + this.ignoreCase = ignoreCase; + } + + @Override + public boolean isAllowed(@Nullable String input) { + return listToCheck.contains(input); + } + + public @NotNull @Unmodifiable List list() { + return list; + } + + public boolean ignoreCase() { + return ignoreCase; + } + + @Override + public boolean equals(Object object) { + if (object == null || getClass() != object.getClass()) + return false; + Listed listed = (Listed) object; + return ignoreCase == listed.ignoreCase && Objects.equals(list, listed.list) && Objects.equals(listToCheck, listed.listToCheck); + } + + @Override + public int hashCode() { + return Objects.hash(list, listToCheck, ignoreCase); + } + + @Override + public String toString() { + return "Listed{" + + "list=" + list + + ", listToCheck=" + listToCheck + + ", ignoreCase=" + ignoreCase + + '}'; + } + } + + final class Any implements AllowedStringInputs { + + @Override + public boolean isAllowed(@Nullable String input) { + return true; + } + + @Override + public @NotNull List getSuggestions(@NotNull CommandSender sender, @NotNull List input, @NotNull String current) { + return List.of(current); + } + + @Override + public boolean equals(Object object) { + return object != null && getClass() == object.getClass(); + } + + @Override + public int hashCode() { + return Objects.hash(); + } + + @Override + public String toString() { + return "Any{}"; + } + } +} From 6f048f9dcb02bb7953ea2918b45f0260a0167304 Mon Sep 17 00:00:00 2001 From: WizardlyBump17 Date: Tue, 11 Nov 2025 19:27:40 -0300 Subject: [PATCH 127/363] starting the final tests --- .../method/MethodCommandExtractorTests.java | 194 ++++++++++++++++++ 1 file changed, 194 insertions(+) diff --git a/commands/src/test/java/com/wizardlybump17/wlib/test/command/extractor/method/MethodCommandExtractorTests.java b/commands/src/test/java/com/wizardlybump17/wlib/test/command/extractor/method/MethodCommandExtractorTests.java index 134e182d..276e6531 100644 --- a/commands/src/test/java/com/wizardlybump17/wlib/test/command/extractor/method/MethodCommandExtractorTests.java +++ b/commands/src/test/java/com/wizardlybump17/wlib/test/command/extractor/method/MethodCommandExtractorTests.java @@ -5,9 +5,13 @@ import com.wizardlybump17.wlib.command.extractor.CommandExtractor; import com.wizardlybump17.wlib.command.extractor.method.MethodCommandExtractor; import com.wizardlybump17.wlib.command.input.AllowedNumberInputs; +import com.wizardlybump17.wlib.command.input.string.AllowedStringInputs; +import com.wizardlybump17.wlib.command.manager.CommandManager; import com.wizardlybump17.wlib.command.node.IntegerCommandNode; import com.wizardlybump17.wlib.command.node.LiteralCommandNode; +import com.wizardlybump17.wlib.command.node.StringCommandNode; import com.wizardlybump17.wlib.command.result.CommandResult; +import com.wizardlybump17.wlib.command.sender.BasicCommandSender; import com.wizardlybump17.wlib.command.sender.CommandSender; import org.jetbrains.annotations.NotNull; import org.junit.jupiter.api.Assertions; @@ -15,6 +19,8 @@ import java.util.ArrayList; import java.util.List; +import java.util.UUID; +import java.util.function.Consumer; class MethodCommandExtractorTests { @@ -917,4 +923,192 @@ public CommandResult helloThereHi(int arg0) { return null; } } + + /* + Lets execute some commands + */ + + static final @NotNull Consumer SENDER_MESSAGE_CONSUMER = System.out::println; + static final @NotNull CommandSender CHAD_SENDER = new BasicCommandSender<>(new Object(), "Chad", UUID.nameUUIDFromBytes("Chad".getBytes()), SENDER_MESSAGE_CONSUMER, $ -> true); + static final @NotNull CommandSender BETA_SENDER = new BasicCommandSender<>(new Object(), "Beta", UUID.nameUUIDFromBytes("Beta".getBytes()), SENDER_MESSAGE_CONSUMER, $ -> false); + + @Test + void testExecute() { + TestExecute object = new TestExecute(); + + Command hello = new Command( + new LiteralCommandNode( + "hello", + List.of( + new LiteralCommandNode( + "world", + Assertions.assertDoesNotThrow(() -> MethodCommandExtractor.createExecutor(object, "helloWorld")) + ) + ), + Assertions.assertDoesNotThrow(() -> MethodCommandExtractor.createExecutor(object, "hello")) + ) + ); + Command hi = new Command( + new LiteralCommandNode( + "hi", + List.of( + new LiteralCommandNode( + "world", + Assertions.assertDoesNotThrow(() -> MethodCommandExtractor.createExecutor(object, "hiWorld", CommandSender.class)) + ) + ), + Assertions.assertDoesNotThrow(() -> MethodCommandExtractor.createExecutor(object, "hi", CommandSender.class)) + ) + ); + Command greetings = new Command( + new LiteralCommandNode( + "greetings", + List.of( + new LiteralCommandNode( + "world", + Assertions.assertDoesNotThrow(() -> MethodCommandExtractor.createExecutor(object, "greetingsWorld", CommandContext.class)) + ) + ), + Assertions.assertDoesNotThrow(() -> MethodCommandExtractor.createExecutor(object, "greetings", CommandContext.class)) + ) + ); + Command welcome = new Command( + new LiteralCommandNode( + "welcome", + List.of( + new StringCommandNode( + "name", + List.of( + new LiteralCommandNode( + "world", + Assertions.assertDoesNotThrow(() -> MethodCommandExtractor.createExecutor(object, "welcomeWorld", CommandSender.class, String.class)) + ) + ), + new AllowedStringInputs.Any(), + Assertions.assertDoesNotThrow(() -> MethodCommandExtractor.createExecutor(object, "welcome", CommandSender.class, String.class)), + null + ) + ) + ) + ); + Command wassup = new Command( + new LiteralCommandNode( + "wassup", + List.of( + new StringCommandNode( + "name", + List.of( + new LiteralCommandNode( + "nice", + Assertions.assertDoesNotThrow(() -> MethodCommandExtractor.createExecutor(object, "wassupNice", CommandContext.class, String.class)) + ) + ), + new AllowedStringInputs.Any(), + Assertions.assertDoesNotThrow(() -> MethodCommandExtractor.createExecutor(object, "wassup", CommandContext.class, String.class)), + null + ) + ) + ) + ); + Command aye = new Command( + new LiteralCommandNode( + "aye", + List.of( + new StringCommandNode( + "name", + List.of( + new LiteralCommandNode( + "nice", + Assertions.assertDoesNotThrow(() -> MethodCommandExtractor.createExecutor(object, "ayeNice", String.class)) + ) + ), + new AllowedStringInputs.Any(), + Assertions.assertDoesNotThrow(() -> MethodCommandExtractor.createExecutor(object, "aye", String.class)), + null + ) + ) + ) + ); + + List extractedCommands = Assertions.assertDoesNotThrow(() -> CommandExtractor.METHOD.extract(object)); + + CommandManager manager = new CommandManager(); + + List expectedCommands = new ArrayList<>(List.of(hello, hi, greetings, welcome, wassup, aye)); + List actualCommands = manager.registerCommands("test", extractedCommands); + + expectedCommands.sort(null); + actualCommands.sort(null); + + actualCommands.remove(0); + actualCommands.remove(1); + actualCommands.remove(2); + actualCommands.remove(3); + actualCommands.remove(4); + actualCommands.remove(5); + + Assertions.assertEquals(expectedCommands, actualCommands); + + Assertions.assertEquals( + CommandResult.successful(0, null, null), + manager.execute(CHAD_SENDER, "hello") + ); + } + + public static class TestExecute { + + @com.wizardlybump17.wlib.command.annotation.Command("hello") + public void hello() { + } + + @com.wizardlybump17.wlib.command.annotation.Command("hello world") + public CommandResult helloWorld() { + return null; + } + + @com.wizardlybump17.wlib.command.annotation.Command("hi") + public void hi(@NotNull CommandSender sender) { + } + + @com.wizardlybump17.wlib.command.annotation.Command("hi world") + public CommandResult hiWorld(@NotNull CommandSender sender) { + return null; + } + + @com.wizardlybump17.wlib.command.annotation.Command("greetings") + public void greetings(@NotNull CommandContext context) { + } + + @com.wizardlybump17.wlib.command.annotation.Command("greetings world") + public @NotNull CommandResult greetingsWorld(@NotNull CommandContext context) { + return CommandResult.successful(context, "Hello, world!"); + } + + @com.wizardlybump17.wlib.command.annotation.Command("welcome ") + public void welcome(@NotNull CommandSender sender, @NotNull String name) { + } + + @com.wizardlybump17.wlib.command.annotation.Command("welcome world") + public CommandResult welcomeWorld(@NotNull CommandSender sender, @NotNull String name) { + return null; + } + + @com.wizardlybump17.wlib.command.annotation.Command("wassup ") + public void wassup(@NotNull CommandContext context, @NotNull String name) { + } + + @com.wizardlybump17.wlib.command.annotation.Command("wassup nice") + public @NotNull CommandResult wassupNice(@NotNull CommandContext context, @NotNull String name) { + return CommandResult.successful(context, "Nice to meet you, " + name + "!"); + } + + @com.wizardlybump17.wlib.command.annotation.Command("aye ") + public void aye(@NotNull String name) { + } + + @com.wizardlybump17.wlib.command.annotation.Command("aye nice") + public CommandResult ayeNice(@NotNull String name) { + return null; + } + } } From bdb0e6156b734991aee37010c82e4d8aa96dfe56 Mon Sep 17 00:00:00 2001 From: WizardlyBump17 Date: Tue, 11 Nov 2025 23:23:06 -0300 Subject: [PATCH 128/363] empty results --- .../wlib/command/result/CommandResult.java | 15 +++++++ .../result/empty/EmptyCommandNode.java | 42 +++++++++++++++++++ .../wlib/command/result/empty/EmptyError.java | 25 +++++++++++ .../command/result/empty/EmptyResult.java | 22 ++++++++++ .../command/result/empty/EmptySuccess.java | 25 +++++++++++ 5 files changed, 129 insertions(+) create mode 100644 commands/src/main/java/com/wizardlybump17/wlib/command/result/empty/EmptyCommandNode.java create mode 100644 commands/src/main/java/com/wizardlybump17/wlib/command/result/empty/EmptyError.java create mode 100644 commands/src/main/java/com/wizardlybump17/wlib/command/result/empty/EmptyResult.java create mode 100644 commands/src/main/java/com/wizardlybump17/wlib/command/result/empty/EmptySuccess.java diff --git a/commands/src/main/java/com/wizardlybump17/wlib/command/result/CommandResult.java b/commands/src/main/java/com/wizardlybump17/wlib/command/result/CommandResult.java index d8ce73d4..d9b2d7e0 100644 --- a/commands/src/main/java/com/wizardlybump17/wlib/command/result/CommandResult.java +++ b/commands/src/main/java/com/wizardlybump17/wlib/command/result/CommandResult.java @@ -4,6 +4,7 @@ import com.wizardlybump17.wlib.command.context.CommandContext; import com.wizardlybump17.wlib.command.exception.InputParsingException; import com.wizardlybump17.wlib.command.node.CommandNode; +import com.wizardlybump17.wlib.command.result.empty.EmptyResult; import com.wizardlybump17.wlib.command.result.error.*; import com.wizardlybump17.wlib.command.sender.CommandSender; import org.jetbrains.annotations.NotNull; @@ -19,6 +20,10 @@ public interface CommandResult { @NotNull CommandNode lastNode(); + default boolean empty() { + return this instanceof EmptyResult; + } + //without context static @NotNull SuccessResult successful(int lastInputIndex, @NotNull CommandNode lastNode, @Nullable T data) { @@ -94,4 +99,14 @@ public interface CommandResult { static @NotNull InvalidSenderResult invalidSender(@NotNull CommandContext context, @NotNull Class> expectedSender) { return invalidSender(context.lastInputIndex(), context.lastNode(), context.sender(), expectedSender); } + + //empty + + static @NotNull EmptyResult emptySuccess() { + return EmptyResult.emptySuccess(); + } + + static @NotNull EmptyResult emptyError() { + return EmptyResult.emptyError(); + } } diff --git a/commands/src/main/java/com/wizardlybump17/wlib/command/result/empty/EmptyCommandNode.java b/commands/src/main/java/com/wizardlybump17/wlib/command/result/empty/EmptyCommandNode.java new file mode 100644 index 00000000..12948786 --- /dev/null +++ b/commands/src/main/java/com/wizardlybump17/wlib/command/result/empty/EmptyCommandNode.java @@ -0,0 +1,42 @@ +package com.wizardlybump17.wlib.command.result.empty; + +import com.wizardlybump17.wlib.command.executor.CommandNodeExecutor; +import com.wizardlybump17.wlib.command.node.CommandNode; +import org.jetbrains.annotations.NotNull; +import org.jetbrains.annotations.Nullable; + +import java.util.List; + +final class EmptyCommandNode extends CommandNode { + + public static final @NotNull EmptyCommandNode INSTANCE = new EmptyCommandNode(); + + private EmptyCommandNode() { + super("EmptyNode", $ -> true); + } + + @Override + public @Nullable Object parse(@NotNull String input) { + return null; + } + + @Override + public @NotNull EmptyCommandNode withChildren(@NotNull List> children) { + return this; + } + + @Override + public @NotNull EmptyCommandNode withExecutor(@Nullable CommandNodeExecutor executor) { + return this; + } + + @Override + public @NotNull EmptyCommandNode withPermission(@Nullable String permission) { + return this; + } + + @Override + public String toString() { + return "EmptyCommandNode{}"; + } +} diff --git a/commands/src/main/java/com/wizardlybump17/wlib/command/result/empty/EmptyError.java b/commands/src/main/java/com/wizardlybump17/wlib/command/result/empty/EmptyError.java new file mode 100644 index 00000000..5d8b8433 --- /dev/null +++ b/commands/src/main/java/com/wizardlybump17/wlib/command/result/empty/EmptyError.java @@ -0,0 +1,25 @@ +package com.wizardlybump17.wlib.command.result.empty; + +import com.wizardlybump17.wlib.command.node.CommandNode; +import org.jetbrains.annotations.NotNull; +import org.jetbrains.annotations.Nullable; + +final class EmptyError implements EmptyResult { + + static final @NotNull EmptyError INSTANCE = new EmptyError<>(); + + @Override + public boolean success() { + return false; + } + + @Override + public @Nullable T data() { + return null; + } + + @Override + public @NotNull CommandNode lastNode() { + return EmptyCommandNode.INSTANCE; + } +} diff --git a/commands/src/main/java/com/wizardlybump17/wlib/command/result/empty/EmptyResult.java b/commands/src/main/java/com/wizardlybump17/wlib/command/result/empty/EmptyResult.java new file mode 100644 index 00000000..6d63571b --- /dev/null +++ b/commands/src/main/java/com/wizardlybump17/wlib/command/result/empty/EmptyResult.java @@ -0,0 +1,22 @@ +package com.wizardlybump17.wlib.command.result.empty; + +import com.wizardlybump17.wlib.command.result.CommandResult; +import org.jetbrains.annotations.NotNull; + +public sealed interface EmptyResult extends CommandResult permits EmptySuccess, EmptyError { + + @Override + default int lastInputIndex() { + return -1; + } + + @SuppressWarnings("unchecked") + static @NotNull EmptyResult emptySuccess() { + return (EmptyResult) EmptySuccess.INSTANCE; + } + + @SuppressWarnings("unchecked") + static @NotNull EmptyResult emptyError() { + return (EmptyResult) EmptyError.INSTANCE; + } +} diff --git a/commands/src/main/java/com/wizardlybump17/wlib/command/result/empty/EmptySuccess.java b/commands/src/main/java/com/wizardlybump17/wlib/command/result/empty/EmptySuccess.java new file mode 100644 index 00000000..d4afdd90 --- /dev/null +++ b/commands/src/main/java/com/wizardlybump17/wlib/command/result/empty/EmptySuccess.java @@ -0,0 +1,25 @@ +package com.wizardlybump17.wlib.command.result.empty; + +import com.wizardlybump17.wlib.command.node.CommandNode; +import org.jetbrains.annotations.NotNull; +import org.jetbrains.annotations.Nullable; + +final class EmptySuccess implements EmptyResult { + + static final @NotNull EmptySuccess INSTANCE = new EmptySuccess<>(); + + @Override + public boolean success() { + return true; + } + + @Override + public @Nullable T data() { + return null; + } + + @Override + public @NotNull CommandNode lastNode() { + return EmptyCommandNode.INSTANCE; + } +} From 9ebfcef89535bc1a5d498a7dbfaf033516a5218f Mon Sep 17 00:00:00 2001 From: WizardlyBump17 Date: Tue, 11 Nov 2025 23:24:46 -0300 Subject: [PATCH 129/363] it can not be null --- .../src/main/java/com/wizardlybump17/wlib/command/Command.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/commands/src/main/java/com/wizardlybump17/wlib/command/Command.java b/commands/src/main/java/com/wizardlybump17/wlib/command/Command.java index beef2cdf..afb6c294 100644 --- a/commands/src/main/java/com/wizardlybump17/wlib/command/Command.java +++ b/commands/src/main/java/com/wizardlybump17/wlib/command/Command.java @@ -96,7 +96,7 @@ public Command(@NotNull LiteralCommandNode root) { ); try { - return executor.execute(context); + return Objects.requireNonNull(executor.execute(context), "The CommandExecutor can not return null. (" + lastNode.getName() + ")"); } catch (Throwable throwable) { return CommandResult.exceptionally(lastInputIndex, lastNode, throwable); } From 204fa871241d2386b13815724d9a664172a204f6 Mon Sep 17 00:00:00 2001 From: WizardlyBump17 Date: Tue, 11 Nov 2025 23:27:16 -0300 Subject: [PATCH 130/363] looking for a child --- .../com/wizardlybump17/wlib/command/Command.java | 5 +++++ .../wlib/command/node/CommandNode.java | 14 ++++++++++++++ 2 files changed, 19 insertions(+) diff --git a/commands/src/main/java/com/wizardlybump17/wlib/command/Command.java b/commands/src/main/java/com/wizardlybump17/wlib/command/Command.java index afb6c294..4ff181f5 100644 --- a/commands/src/main/java/com/wizardlybump17/wlib/command/Command.java +++ b/commands/src/main/java/com/wizardlybump17/wlib/command/Command.java @@ -10,6 +10,7 @@ import com.wizardlybump17.wlib.command.sender.CommandSender; import com.wizardlybump17.wlib.util.StringUtil; import org.jetbrains.annotations.NotNull; +import org.jetbrains.annotations.Nullable; import java.util.ArrayList; import java.util.Collection; @@ -204,4 +205,8 @@ public int compareTo(@NotNull Command other) { public @NotNull String getFullCommand() { return root.getFullCommand(); } + + public @Nullable CommandNode findNode(@NotNull String name) { + return root.findChild(name); + } } diff --git a/commands/src/main/java/com/wizardlybump17/wlib/command/node/CommandNode.java b/commands/src/main/java/com/wizardlybump17/wlib/command/node/CommandNode.java index acf7c1fb..ce9de1c9 100644 --- a/commands/src/main/java/com/wizardlybump17/wlib/command/node/CommandNode.java +++ b/commands/src/main/java/com/wizardlybump17/wlib/command/node/CommandNode.java @@ -215,4 +215,18 @@ public int hashCode() { public boolean canExecute(@NotNull CommandSender sender) { return permission == null || sender.hasPermission(permission); } + + public @Nullable CommandNode findChild(@NotNull String name) { + for (CommandNode child : children) + if (child.getName().equals(name)) + return child; + + for (CommandNode child : children) { + CommandNode found = child.findChild(name); + if (found != null) + return found; + } + + return null; + } } From 2698ccf755ba09761f7d40545e45bb65b8816a52 Mon Sep 17 00:00:00 2001 From: WizardlyBump17 Date: Tue, 11 Nov 2025 23:28:35 -0300 Subject: [PATCH 131/363] overriding the Object#toString() method --- .../wizardlybump17/wlib/command/result/empty/EmptyError.java | 5 +++++ .../wlib/command/result/empty/EmptySuccess.java | 5 +++++ 2 files changed, 10 insertions(+) diff --git a/commands/src/main/java/com/wizardlybump17/wlib/command/result/empty/EmptyError.java b/commands/src/main/java/com/wizardlybump17/wlib/command/result/empty/EmptyError.java index 5d8b8433..5b908e6e 100644 --- a/commands/src/main/java/com/wizardlybump17/wlib/command/result/empty/EmptyError.java +++ b/commands/src/main/java/com/wizardlybump17/wlib/command/result/empty/EmptyError.java @@ -22,4 +22,9 @@ public boolean success() { public @NotNull CommandNode lastNode() { return EmptyCommandNode.INSTANCE; } + + @Override + public String toString() { + return "EmptyError{}"; + } } diff --git a/commands/src/main/java/com/wizardlybump17/wlib/command/result/empty/EmptySuccess.java b/commands/src/main/java/com/wizardlybump17/wlib/command/result/empty/EmptySuccess.java index d4afdd90..bee0326c 100644 --- a/commands/src/main/java/com/wizardlybump17/wlib/command/result/empty/EmptySuccess.java +++ b/commands/src/main/java/com/wizardlybump17/wlib/command/result/empty/EmptySuccess.java @@ -22,4 +22,9 @@ public boolean success() { public @NotNull CommandNode lastNode() { return EmptyCommandNode.INSTANCE; } + + @Override + public String toString() { + return "EmptySuccess{}"; + } } From c9693b51b351c9ab3a73ec5c7fb87afee1100094 Mon Sep 17 00:00:00 2001 From: WizardlyBump17 Date: Tue, 11 Nov 2025 23:36:48 -0300 Subject: [PATCH 132/363] added more tests --- .../method/MethodCommandExtractorTests.java | 62 +++++++++++++++++-- 1 file changed, 56 insertions(+), 6 deletions(-) diff --git a/commands/src/test/java/com/wizardlybump17/wlib/test/command/extractor/method/MethodCommandExtractorTests.java b/commands/src/test/java/com/wizardlybump17/wlib/test/command/extractor/method/MethodCommandExtractorTests.java index 276e6531..fd31dbe2 100644 --- a/commands/src/test/java/com/wizardlybump17/wlib/test/command/extractor/method/MethodCommandExtractorTests.java +++ b/commands/src/test/java/com/wizardlybump17/wlib/test/command/extractor/method/MethodCommandExtractorTests.java @@ -1040,6 +1040,7 @@ void testExecute() { expectedCommands.sort(null); actualCommands.sort(null); + //We already know that the register method works actualCommands.remove(0); actualCommands.remove(1); actualCommands.remove(2); @@ -1050,9 +1051,58 @@ void testExecute() { Assertions.assertEquals(expectedCommands, actualCommands); Assertions.assertEquals( - CommandResult.successful(0, null, null), + CommandResult.successful(0, hello.getRoot(), null), manager.execute(CHAD_SENDER, "hello") ); + Assertions.assertEquals( + CommandResult.emptySuccess(), + manager.execute(CHAD_SENDER, "hello world") + ); + + Assertions.assertEquals( + CommandResult.successful(0, hi.getRoot(), null), + manager.execute(CHAD_SENDER, "hi") + ); + Assertions.assertEquals( + CommandResult.emptySuccess(), + manager.execute(CHAD_SENDER, "hi world") + ); + + Assertions.assertEquals( + CommandResult.successful(0, greetings.getRoot(), null), + manager.execute(CHAD_SENDER, "greetings") + ); + Assertions.assertEquals( + CommandResult.successful(1, greetings.findNode("world"), "Hello, world!"), + manager.execute(CHAD_SENDER, "greetings world") + ); + + Assertions.assertEquals( + CommandResult.successful(1, welcome.findNode("name"), null), + manager.execute(CHAD_SENDER, "welcome test") + ); + Assertions.assertEquals( + CommandResult.emptySuccess(), + manager.execute(CHAD_SENDER, "welcome test world") + ); + + Assertions.assertEquals( + CommandResult.successful(1, wassup.getRoot(), "Nice to meet you, test!"), + manager.execute(CHAD_SENDER, "wassup test") + ); + Assertions.assertEquals( + CommandResult.successful(2, greetings.findNode("name"), "Nice to meet you, test!"), + manager.execute(CHAD_SENDER, "wassup test nice") + ); + + Assertions.assertEquals( + CommandResult.successful(1, wassup.getRoot(), null), + manager.execute(CHAD_SENDER, "aye test") + ); + Assertions.assertEquals( + CommandResult.emptySuccess(), + manager.execute(CHAD_SENDER, "aye test nice") + ); } public static class TestExecute { @@ -1062,8 +1112,8 @@ public void hello() { } @com.wizardlybump17.wlib.command.annotation.Command("hello world") - public CommandResult helloWorld() { - return null; + public @NotNull CommandResult helloWorld() { + return CommandResult.emptySuccess(); } @com.wizardlybump17.wlib.command.annotation.Command("hi") @@ -1072,7 +1122,7 @@ public void hi(@NotNull CommandSender sender) { @com.wizardlybump17.wlib.command.annotation.Command("hi world") public CommandResult hiWorld(@NotNull CommandSender sender) { - return null; + return CommandResult.emptySuccess(); } @com.wizardlybump17.wlib.command.annotation.Command("greetings") @@ -1090,7 +1140,7 @@ public void welcome(@NotNull CommandSender sender, @NotNull String name) { @com.wizardlybump17.wlib.command.annotation.Command("welcome world") public CommandResult welcomeWorld(@NotNull CommandSender sender, @NotNull String name) { - return null; + return CommandResult.emptySuccess(); } @com.wizardlybump17.wlib.command.annotation.Command("wassup ") @@ -1108,7 +1158,7 @@ public void aye(@NotNull String name) { @com.wizardlybump17.wlib.command.annotation.Command("aye nice") public CommandResult ayeNice(@NotNull String name) { - return null; + return CommandResult.emptySuccess(); } } } From 265c3ba2b6b6f56e0a49c9ae40115f318ad1ddf5 Mon Sep 17 00:00:00 2001 From: WizardlyBump17 Date: Tue, 11 Nov 2025 23:44:15 -0300 Subject: [PATCH 133/363] ignoring literal inputs --- .../AbstractMethodCommandNodeExecutor.java | 32 +++++++++++++++---- 1 file changed, 25 insertions(+), 7 deletions(-) diff --git a/commands/src/main/java/com/wizardlybump17/wlib/command/extractor/method/AbstractMethodCommandNodeExecutor.java b/commands/src/main/java/com/wizardlybump17/wlib/command/extractor/method/AbstractMethodCommandNodeExecutor.java index dd4633d4..b0f084bd 100644 --- a/commands/src/main/java/com/wizardlybump17/wlib/command/extractor/method/AbstractMethodCommandNodeExecutor.java +++ b/commands/src/main/java/com/wizardlybump17/wlib/command/extractor/method/AbstractMethodCommandNodeExecutor.java @@ -1,6 +1,7 @@ package com.wizardlybump17.wlib.command.extractor.method; import com.wizardlybump17.wlib.command.context.CommandContext; +import com.wizardlybump17.wlib.command.node.LiteralCommandNode; import com.wizardlybump17.wlib.command.result.CommandResult; import org.jetbrains.annotations.ApiStatus; import org.jetbrains.annotations.NotNull; @@ -166,7 +167,10 @@ public CommandSenderAndArgumentsCommandResultExecutor(@NotNull Object object, @N List parameters = new ArrayList<>(); parameters.add(object()); parameters.add(context.sender()); - context.arguments().getArguments().forEach((nodeName, argument) -> parameters.add(argument.data())); + context.arguments().getArguments().forEach((nodeName, argument) -> { + if (!(argument.node() instanceof LiteralCommandNode)) + parameters.add(argument.data()); + }); return (CommandResult) methodHandle().invokeWithArguments(parameters); } catch (Throwable throwable) { return CommandResult.exceptionally(context, throwable); @@ -188,7 +192,10 @@ public CommandSenderAndArgumentsExecutor(@NotNull Object object, @NotNull Method List parameters = new ArrayList<>(); parameters.add(object()); parameters.add(context.sender()); - context.arguments().getArguments().forEach((nodeName, argument) -> parameters.add(argument.data())); + context.arguments().getArguments().forEach((nodeName, argument) -> { + if (!(argument.node() instanceof LiteralCommandNode)) + parameters.add(argument.data()); + }); return (CommandResult) CommandResult.successful(context, methodHandle().invokeWithArguments(parameters)); } catch (Throwable throwable) { return CommandResult.exceptionally(context, throwable); @@ -210,8 +217,10 @@ public CommandContextAndArgumentsCommandResultExecutor(@NotNull Object object, @ List parameters = new ArrayList<>(); parameters.add(object()); parameters.add(context); - context.arguments().getArguments().forEach((nodeName, argument) -> parameters.add(argument.data())); - return (CommandResult) methodHandle().invokeWithArguments(parameters); + context.arguments().getArguments().forEach((nodeName, argument) -> { + if (!(argument.node() instanceof LiteralCommandNode)) + parameters.add(argument.data()); + });return (CommandResult) methodHandle().invokeWithArguments(parameters); } catch (Throwable throwable) { return CommandResult.exceptionally(context, throwable); } @@ -232,7 +241,10 @@ public CommandContextAndArgumentsExecutor(@NotNull Object object, @NotNull Metho List parameters = new ArrayList<>(); parameters.add(object()); parameters.add(context); - context.arguments().getArguments().forEach((nodeName, argument) -> parameters.add(argument.data())); + context.arguments().getArguments().forEach((nodeName, argument) -> { + if (!(argument.node() instanceof LiteralCommandNode)) + parameters.add(argument.data()); + }); return (CommandResult) CommandResult.successful(context, methodHandle().invokeWithArguments(parameters)); } catch (Throwable throwable) { return CommandResult.exceptionally(context, throwable); @@ -253,7 +265,10 @@ public ArgumentsCommandResultExecutor(@NotNull Object object, @NotNull Method me try { List parameters = new ArrayList<>(); parameters.add(object()); - context.arguments().getArguments().forEach((nodeName, argument) -> parameters.add(argument.data())); + context.arguments().getArguments().forEach((nodeName, argument) -> { + if (!(argument.node() instanceof LiteralCommandNode)) + parameters.add(argument.data()); + }); return (CommandResult) methodHandle().invokeWithArguments(parameters); } catch (Throwable throwable) { return CommandResult.exceptionally(context, throwable); @@ -274,7 +289,10 @@ public ArgumentsExecutor(@NotNull Object object, @NotNull Method method) { try { List parameters = new ArrayList<>(); parameters.add(object()); - context.arguments().getArguments().forEach((nodeName, argument) -> parameters.add(argument.data())); + context.arguments().getArguments().forEach((nodeName, argument) -> { + if (!(argument.node() instanceof LiteralCommandNode)) + parameters.add(argument.data()); + }); return (CommandResult) CommandResult.successful(context, methodHandle().invokeWithArguments(parameters)); } catch (Throwable throwable) { return CommandResult.exceptionally(context, throwable); From ea2d15d52ee72696e047261ab4ce5e8884585de8 Mon Sep 17 00:00:00 2001 From: WizardlyBump17 Date: Tue, 11 Nov 2025 23:44:23 -0300 Subject: [PATCH 134/363] fixed the tests --- .../extractor/method/MethodCommandExtractorTests.java | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/commands/src/test/java/com/wizardlybump17/wlib/test/command/extractor/method/MethodCommandExtractorTests.java b/commands/src/test/java/com/wizardlybump17/wlib/test/command/extractor/method/MethodCommandExtractorTests.java index fd31dbe2..37c4288e 100644 --- a/commands/src/test/java/com/wizardlybump17/wlib/test/command/extractor/method/MethodCommandExtractorTests.java +++ b/commands/src/test/java/com/wizardlybump17/wlib/test/command/extractor/method/MethodCommandExtractorTests.java @@ -1087,16 +1087,16 @@ void testExecute() { ); Assertions.assertEquals( - CommandResult.successful(1, wassup.getRoot(), "Nice to meet you, test!"), + CommandResult.successful(1, wassup.findNode("name"), null), manager.execute(CHAD_SENDER, "wassup test") ); Assertions.assertEquals( - CommandResult.successful(2, greetings.findNode("name"), "Nice to meet you, test!"), + CommandResult.successful(2, wassup.findNode("nice"), "Nice to meet you, test!"), manager.execute(CHAD_SENDER, "wassup test nice") ); Assertions.assertEquals( - CommandResult.successful(1, wassup.getRoot(), null), + CommandResult.successful(1, aye.findNode("name"), null), manager.execute(CHAD_SENDER, "aye test") ); Assertions.assertEquals( From 29ace8c09b67de49e2b6868837ec0a5f582fa4ca Mon Sep 17 00:00:00 2001 From: WizardlyBump17 Date: Tue, 11 Nov 2025 23:49:19 -0300 Subject: [PATCH 135/363] it can not be empty --- commands/build.gradle | 2 +- .../wizardlybump17/wlib/command/Command.java | 5 ++- .../command/executor/CommandNodeExecutor.java | 3 +- .../wlib/command/result/CommandResult.java | 15 ------- .../result/empty/EmptyCommandNode.java | 42 ------------------- .../wlib/command/result/empty/EmptyError.java | 30 ------------- .../command/result/empty/EmptyResult.java | 22 ---------- .../command/result/empty/EmptySuccess.java | 30 ------------- .../method/MethodCommandExtractorTests.java | 18 ++++---- 9 files changed, 16 insertions(+), 151 deletions(-) delete mode 100644 commands/src/main/java/com/wizardlybump17/wlib/command/result/empty/EmptyCommandNode.java delete mode 100644 commands/src/main/java/com/wizardlybump17/wlib/command/result/empty/EmptyError.java delete mode 100644 commands/src/main/java/com/wizardlybump17/wlib/command/result/empty/EmptyResult.java delete mode 100644 commands/src/main/java/com/wizardlybump17/wlib/command/result/empty/EmptySuccess.java diff --git a/commands/build.gradle b/commands/build.gradle index 59d9b615..5cf5fae7 100644 --- a/commands/build.gradle +++ b/commands/build.gradle @@ -1,7 +1,7 @@ dependencies { compileOnly( 'org.projectlombok:lombok:1.18.32', - 'org.jetbrains:annotations:23.0.0', + 'org.jetbrains:annotations:26.0.1', ) annotationProcessor('org.projectlombok:lombok:1.18.32') implementation( diff --git a/commands/src/main/java/com/wizardlybump17/wlib/command/Command.java b/commands/src/main/java/com/wizardlybump17/wlib/command/Command.java index 4ff181f5..3ed30903 100644 --- a/commands/src/main/java/com/wizardlybump17/wlib/command/Command.java +++ b/commands/src/main/java/com/wizardlybump17/wlib/command/Command.java @@ -97,7 +97,10 @@ public Command(@NotNull LiteralCommandNode root) { ); try { - return Objects.requireNonNull(executor.execute(context), "The CommandExecutor can not return null. (" + lastNode.getName() + ")"); + CommandResult result = executor.execute(context); + if (result == null) + return CommandResult.successful(context, null); + return result; } catch (Throwable throwable) { return CommandResult.exceptionally(lastInputIndex, lastNode, throwable); } diff --git a/commands/src/main/java/com/wizardlybump17/wlib/command/executor/CommandNodeExecutor.java b/commands/src/main/java/com/wizardlybump17/wlib/command/executor/CommandNodeExecutor.java index 7985b2cb..acf4a4f0 100644 --- a/commands/src/main/java/com/wizardlybump17/wlib/command/executor/CommandNodeExecutor.java +++ b/commands/src/main/java/com/wizardlybump17/wlib/command/executor/CommandNodeExecutor.java @@ -3,6 +3,7 @@ import com.wizardlybump17.wlib.command.context.CommandContext; import com.wizardlybump17.wlib.command.result.CommandResult; import org.jetbrains.annotations.NotNull; +import org.jetbrains.annotations.Nullable; public interface CommandNodeExecutor { @@ -11,5 +12,5 @@ public interface CommandNodeExecutor { // return CommandResult.successful(""); // }; - @NotNull CommandResult execute(@NotNull CommandContext context); + @Nullable CommandResult execute(@NotNull CommandContext context); } diff --git a/commands/src/main/java/com/wizardlybump17/wlib/command/result/CommandResult.java b/commands/src/main/java/com/wizardlybump17/wlib/command/result/CommandResult.java index d9b2d7e0..d8ce73d4 100644 --- a/commands/src/main/java/com/wizardlybump17/wlib/command/result/CommandResult.java +++ b/commands/src/main/java/com/wizardlybump17/wlib/command/result/CommandResult.java @@ -4,7 +4,6 @@ import com.wizardlybump17.wlib.command.context.CommandContext; import com.wizardlybump17.wlib.command.exception.InputParsingException; import com.wizardlybump17.wlib.command.node.CommandNode; -import com.wizardlybump17.wlib.command.result.empty.EmptyResult; import com.wizardlybump17.wlib.command.result.error.*; import com.wizardlybump17.wlib.command.sender.CommandSender; import org.jetbrains.annotations.NotNull; @@ -20,10 +19,6 @@ public interface CommandResult { @NotNull CommandNode lastNode(); - default boolean empty() { - return this instanceof EmptyResult; - } - //without context static @NotNull SuccessResult successful(int lastInputIndex, @NotNull CommandNode lastNode, @Nullable T data) { @@ -99,14 +94,4 @@ default boolean empty() { static @NotNull InvalidSenderResult invalidSender(@NotNull CommandContext context, @NotNull Class> expectedSender) { return invalidSender(context.lastInputIndex(), context.lastNode(), context.sender(), expectedSender); } - - //empty - - static @NotNull EmptyResult emptySuccess() { - return EmptyResult.emptySuccess(); - } - - static @NotNull EmptyResult emptyError() { - return EmptyResult.emptyError(); - } } diff --git a/commands/src/main/java/com/wizardlybump17/wlib/command/result/empty/EmptyCommandNode.java b/commands/src/main/java/com/wizardlybump17/wlib/command/result/empty/EmptyCommandNode.java deleted file mode 100644 index 12948786..00000000 --- a/commands/src/main/java/com/wizardlybump17/wlib/command/result/empty/EmptyCommandNode.java +++ /dev/null @@ -1,42 +0,0 @@ -package com.wizardlybump17.wlib.command.result.empty; - -import com.wizardlybump17.wlib.command.executor.CommandNodeExecutor; -import com.wizardlybump17.wlib.command.node.CommandNode; -import org.jetbrains.annotations.NotNull; -import org.jetbrains.annotations.Nullable; - -import java.util.List; - -final class EmptyCommandNode extends CommandNode { - - public static final @NotNull EmptyCommandNode INSTANCE = new EmptyCommandNode(); - - private EmptyCommandNode() { - super("EmptyNode", $ -> true); - } - - @Override - public @Nullable Object parse(@NotNull String input) { - return null; - } - - @Override - public @NotNull EmptyCommandNode withChildren(@NotNull List> children) { - return this; - } - - @Override - public @NotNull EmptyCommandNode withExecutor(@Nullable CommandNodeExecutor executor) { - return this; - } - - @Override - public @NotNull EmptyCommandNode withPermission(@Nullable String permission) { - return this; - } - - @Override - public String toString() { - return "EmptyCommandNode{}"; - } -} diff --git a/commands/src/main/java/com/wizardlybump17/wlib/command/result/empty/EmptyError.java b/commands/src/main/java/com/wizardlybump17/wlib/command/result/empty/EmptyError.java deleted file mode 100644 index 5b908e6e..00000000 --- a/commands/src/main/java/com/wizardlybump17/wlib/command/result/empty/EmptyError.java +++ /dev/null @@ -1,30 +0,0 @@ -package com.wizardlybump17.wlib.command.result.empty; - -import com.wizardlybump17.wlib.command.node.CommandNode; -import org.jetbrains.annotations.NotNull; -import org.jetbrains.annotations.Nullable; - -final class EmptyError implements EmptyResult { - - static final @NotNull EmptyError INSTANCE = new EmptyError<>(); - - @Override - public boolean success() { - return false; - } - - @Override - public @Nullable T data() { - return null; - } - - @Override - public @NotNull CommandNode lastNode() { - return EmptyCommandNode.INSTANCE; - } - - @Override - public String toString() { - return "EmptyError{}"; - } -} diff --git a/commands/src/main/java/com/wizardlybump17/wlib/command/result/empty/EmptyResult.java b/commands/src/main/java/com/wizardlybump17/wlib/command/result/empty/EmptyResult.java deleted file mode 100644 index 6d63571b..00000000 --- a/commands/src/main/java/com/wizardlybump17/wlib/command/result/empty/EmptyResult.java +++ /dev/null @@ -1,22 +0,0 @@ -package com.wizardlybump17.wlib.command.result.empty; - -import com.wizardlybump17.wlib.command.result.CommandResult; -import org.jetbrains.annotations.NotNull; - -public sealed interface EmptyResult extends CommandResult permits EmptySuccess, EmptyError { - - @Override - default int lastInputIndex() { - return -1; - } - - @SuppressWarnings("unchecked") - static @NotNull EmptyResult emptySuccess() { - return (EmptyResult) EmptySuccess.INSTANCE; - } - - @SuppressWarnings("unchecked") - static @NotNull EmptyResult emptyError() { - return (EmptyResult) EmptyError.INSTANCE; - } -} diff --git a/commands/src/main/java/com/wizardlybump17/wlib/command/result/empty/EmptySuccess.java b/commands/src/main/java/com/wizardlybump17/wlib/command/result/empty/EmptySuccess.java deleted file mode 100644 index bee0326c..00000000 --- a/commands/src/main/java/com/wizardlybump17/wlib/command/result/empty/EmptySuccess.java +++ /dev/null @@ -1,30 +0,0 @@ -package com.wizardlybump17.wlib.command.result.empty; - -import com.wizardlybump17.wlib.command.node.CommandNode; -import org.jetbrains.annotations.NotNull; -import org.jetbrains.annotations.Nullable; - -final class EmptySuccess implements EmptyResult { - - static final @NotNull EmptySuccess INSTANCE = new EmptySuccess<>(); - - @Override - public boolean success() { - return true; - } - - @Override - public @Nullable T data() { - return null; - } - - @Override - public @NotNull CommandNode lastNode() { - return EmptyCommandNode.INSTANCE; - } - - @Override - public String toString() { - return "EmptySuccess{}"; - } -} diff --git a/commands/src/test/java/com/wizardlybump17/wlib/test/command/extractor/method/MethodCommandExtractorTests.java b/commands/src/test/java/com/wizardlybump17/wlib/test/command/extractor/method/MethodCommandExtractorTests.java index 37c4288e..1c19d7ba 100644 --- a/commands/src/test/java/com/wizardlybump17/wlib/test/command/extractor/method/MethodCommandExtractorTests.java +++ b/commands/src/test/java/com/wizardlybump17/wlib/test/command/extractor/method/MethodCommandExtractorTests.java @@ -1055,7 +1055,7 @@ void testExecute() { manager.execute(CHAD_SENDER, "hello") ); Assertions.assertEquals( - CommandResult.emptySuccess(), + CommandResult.successful(1, hello.findNode("world"), null), manager.execute(CHAD_SENDER, "hello world") ); @@ -1064,7 +1064,7 @@ void testExecute() { manager.execute(CHAD_SENDER, "hi") ); Assertions.assertEquals( - CommandResult.emptySuccess(), + CommandResult.successful(1, hi.findNode("world"), null), manager.execute(CHAD_SENDER, "hi world") ); @@ -1082,7 +1082,7 @@ void testExecute() { manager.execute(CHAD_SENDER, "welcome test") ); Assertions.assertEquals( - CommandResult.emptySuccess(), + CommandResult.successful(2, welcome.findNode("world"), null), manager.execute(CHAD_SENDER, "welcome test world") ); @@ -1100,7 +1100,7 @@ void testExecute() { manager.execute(CHAD_SENDER, "aye test") ); Assertions.assertEquals( - CommandResult.emptySuccess(), + CommandResult.successful(2, aye.findNode("nice"), null), manager.execute(CHAD_SENDER, "aye test nice") ); } @@ -1112,8 +1112,8 @@ public void hello() { } @com.wizardlybump17.wlib.command.annotation.Command("hello world") - public @NotNull CommandResult helloWorld() { - return CommandResult.emptySuccess(); + public CommandResult helloWorld() { + return null; } @com.wizardlybump17.wlib.command.annotation.Command("hi") @@ -1122,7 +1122,7 @@ public void hi(@NotNull CommandSender sender) { @com.wizardlybump17.wlib.command.annotation.Command("hi world") public CommandResult hiWorld(@NotNull CommandSender sender) { - return CommandResult.emptySuccess(); + return null; } @com.wizardlybump17.wlib.command.annotation.Command("greetings") @@ -1140,7 +1140,7 @@ public void welcome(@NotNull CommandSender sender, @NotNull String name) { @com.wizardlybump17.wlib.command.annotation.Command("welcome world") public CommandResult welcomeWorld(@NotNull CommandSender sender, @NotNull String name) { - return CommandResult.emptySuccess(); + return null; } @com.wizardlybump17.wlib.command.annotation.Command("wassup ") @@ -1158,7 +1158,7 @@ public void aye(@NotNull String name) { @com.wizardlybump17.wlib.command.annotation.Command("aye nice") public CommandResult ayeNice(@NotNull String name) { - return CommandResult.emptySuccess(); + return null; } } } From d2227b8fd4d30ac73419c9df692291229179d281 Mon Sep 17 00:00:00 2001 From: WizardlyBump17 Date: Tue, 11 Nov 2025 23:52:29 -0300 Subject: [PATCH 136/363] returning a generic error if the last node or last input index was less than 0 --- .../src/main/java/com/wizardlybump17/wlib/command/Command.java | 2 ++ 1 file changed, 2 insertions(+) diff --git a/commands/src/main/java/com/wizardlybump17/wlib/command/Command.java b/commands/src/main/java/com/wizardlybump17/wlib/command/Command.java index 3ed30903..207d7048 100644 --- a/commands/src/main/java/com/wizardlybump17/wlib/command/Command.java +++ b/commands/src/main/java/com/wizardlybump17/wlib/command/Command.java @@ -100,6 +100,8 @@ public Command(@NotNull LiteralCommandNode root) { CommandResult result = executor.execute(context); if (result == null) return CommandResult.successful(context, null); + if (result.lastNode() == null || result.lastInputIndex() < 0) + return CommandResult.genericError(context); return result; } catch (Throwable throwable) { return CommandResult.exceptionally(lastInputIndex, lastNode, throwable); From 07d9f79802e14ba79075551cb4c467048f3e32cc Mon Sep 17 00:00:00 2001 From: WizardlyBump17 Date: Tue, 11 Nov 2025 23:54:49 -0300 Subject: [PATCH 137/363] zero --- .../com/wizardlybump17/wlib/command/result/CommandResult.java | 2 ++ .../wlib/command/result/error/CommandNotFoundResult.java | 2 +- 2 files changed, 3 insertions(+), 1 deletion(-) diff --git a/commands/src/main/java/com/wizardlybump17/wlib/command/result/CommandResult.java b/commands/src/main/java/com/wizardlybump17/wlib/command/result/CommandResult.java index d8ce73d4..e6c4330b 100644 --- a/commands/src/main/java/com/wizardlybump17/wlib/command/result/CommandResult.java +++ b/commands/src/main/java/com/wizardlybump17/wlib/command/result/CommandResult.java @@ -8,6 +8,7 @@ import com.wizardlybump17.wlib.command.sender.CommandSender; import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.Nullable; +import org.jetbrains.annotations.Range; public interface CommandResult { @@ -15,6 +16,7 @@ public interface CommandResult { @Nullable T data(); + @Range(from = 0, to = Integer.MAX_VALUE) int lastInputIndex(); @NotNull CommandNode lastNode(); diff --git a/commands/src/main/java/com/wizardlybump17/wlib/command/result/error/CommandNotFoundResult.java b/commands/src/main/java/com/wizardlybump17/wlib/command/result/error/CommandNotFoundResult.java index 0f8207f0..0e610b72 100644 --- a/commands/src/main/java/com/wizardlybump17/wlib/command/result/error/CommandNotFoundResult.java +++ b/commands/src/main/java/com/wizardlybump17/wlib/command/result/error/CommandNotFoundResult.java @@ -11,7 +11,7 @@ public record CommandNotFoundResult(@NotNull String input) implements Unsucce @Override public int lastInputIndex() { - return -1; + return 0; } @Override From 74499599d5735fea258a9395ba85046371491230 Mon Sep 17 00:00:00 2001 From: WizardlyBump17 Date: Tue, 11 Nov 2025 23:56:46 -0300 Subject: [PATCH 138/363] a better package --- .../wlib/command/extractor/method/MethodCommandExtractor.java | 1 + .../{ => executor}/AbstractMethodCommandNodeExecutor.java | 2 +- .../method/{ => executor}/MethodCommandNodeExecutor.java | 2 +- .../method/MethodCommandExtractorRightExecutorTests.java | 2 +- 4 files changed, 4 insertions(+), 3 deletions(-) rename commands/src/main/java/com/wizardlybump17/wlib/command/extractor/method/{ => executor}/AbstractMethodCommandNodeExecutor.java (99%) rename commands/src/main/java/com/wizardlybump17/wlib/command/extractor/method/{ => executor}/MethodCommandNodeExecutor.java (86%) diff --git a/commands/src/main/java/com/wizardlybump17/wlib/command/extractor/method/MethodCommandExtractor.java b/commands/src/main/java/com/wizardlybump17/wlib/command/extractor/method/MethodCommandExtractor.java index 1ec51712..39185e50 100644 --- a/commands/src/main/java/com/wizardlybump17/wlib/command/extractor/method/MethodCommandExtractor.java +++ b/commands/src/main/java/com/wizardlybump17/wlib/command/extractor/method/MethodCommandExtractor.java @@ -4,6 +4,7 @@ import com.wizardlybump17.wlib.command.context.CommandContext; import com.wizardlybump17.wlib.command.executor.CommandNodeExecutor; import com.wizardlybump17.wlib.command.extractor.CommandExtractor; +import com.wizardlybump17.wlib.command.extractor.method.executor.AbstractMethodCommandNodeExecutor; import com.wizardlybump17.wlib.command.input.AllowedNumberInputs; import com.wizardlybump17.wlib.command.input.string.AllowedStringInputs; import com.wizardlybump17.wlib.command.node.CommandNode; diff --git a/commands/src/main/java/com/wizardlybump17/wlib/command/extractor/method/AbstractMethodCommandNodeExecutor.java b/commands/src/main/java/com/wizardlybump17/wlib/command/extractor/method/executor/AbstractMethodCommandNodeExecutor.java similarity index 99% rename from commands/src/main/java/com/wizardlybump17/wlib/command/extractor/method/AbstractMethodCommandNodeExecutor.java rename to commands/src/main/java/com/wizardlybump17/wlib/command/extractor/method/executor/AbstractMethodCommandNodeExecutor.java index b0f084bd..f74a27ba 100644 --- a/commands/src/main/java/com/wizardlybump17/wlib/command/extractor/method/AbstractMethodCommandNodeExecutor.java +++ b/commands/src/main/java/com/wizardlybump17/wlib/command/extractor/method/executor/AbstractMethodCommandNodeExecutor.java @@ -1,4 +1,4 @@ -package com.wizardlybump17.wlib.command.extractor.method; +package com.wizardlybump17.wlib.command.extractor.method.executor; import com.wizardlybump17.wlib.command.context.CommandContext; import com.wizardlybump17.wlib.command.node.LiteralCommandNode; diff --git a/commands/src/main/java/com/wizardlybump17/wlib/command/extractor/method/MethodCommandNodeExecutor.java b/commands/src/main/java/com/wizardlybump17/wlib/command/extractor/method/executor/MethodCommandNodeExecutor.java similarity index 86% rename from commands/src/main/java/com/wizardlybump17/wlib/command/extractor/method/MethodCommandNodeExecutor.java rename to commands/src/main/java/com/wizardlybump17/wlib/command/extractor/method/executor/MethodCommandNodeExecutor.java index fc6a23f8..9b814159 100644 --- a/commands/src/main/java/com/wizardlybump17/wlib/command/extractor/method/MethodCommandNodeExecutor.java +++ b/commands/src/main/java/com/wizardlybump17/wlib/command/extractor/method/executor/MethodCommandNodeExecutor.java @@ -1,4 +1,4 @@ -package com.wizardlybump17.wlib.command.extractor.method; +package com.wizardlybump17.wlib.command.extractor.method.executor; import com.wizardlybump17.wlib.command.executor.CommandNodeExecutor; import org.jetbrains.annotations.NotNull; diff --git a/commands/src/test/java/com/wizardlybump17/wlib/test/command/extractor/method/MethodCommandExtractorRightExecutorTests.java b/commands/src/test/java/com/wizardlybump17/wlib/test/command/extractor/method/MethodCommandExtractorRightExecutorTests.java index 63301085..16b380f1 100644 --- a/commands/src/test/java/com/wizardlybump17/wlib/test/command/extractor/method/MethodCommandExtractorRightExecutorTests.java +++ b/commands/src/test/java/com/wizardlybump17/wlib/test/command/extractor/method/MethodCommandExtractorRightExecutorTests.java @@ -2,8 +2,8 @@ import com.wizardlybump17.wlib.command.context.CommandContext; import com.wizardlybump17.wlib.command.executor.CommandNodeExecutor; -import com.wizardlybump17.wlib.command.extractor.method.AbstractMethodCommandNodeExecutor; import com.wizardlybump17.wlib.command.extractor.method.MethodCommandExtractor; +import com.wizardlybump17.wlib.command.extractor.method.executor.AbstractMethodCommandNodeExecutor; import com.wizardlybump17.wlib.command.result.CommandResult; import com.wizardlybump17.wlib.command.sender.CommandSender; import org.jetbrains.annotations.NotNull; From 7cb19805f7ed1e2a86b63c661961e210cdbb307f Mon Sep 17 00:00:00 2001 From: WizardlyBump17 Date: Wed, 12 Nov 2025 00:06:06 -0300 Subject: [PATCH 139/363] added the MethodCommandNodeFactory system --- .../factory/MethodCommandNodeFactory.java | 13 +++++ .../MethodCommandNodeFactoryRegistry.java | 58 +++++++++++++++++++ 2 files changed, 71 insertions(+) create mode 100644 commands/src/main/java/com/wizardlybump17/wlib/command/extractor/method/factory/MethodCommandNodeFactory.java create mode 100644 commands/src/main/java/com/wizardlybump17/wlib/command/registry/MethodCommandNodeFactoryRegistry.java diff --git a/commands/src/main/java/com/wizardlybump17/wlib/command/extractor/method/factory/MethodCommandNodeFactory.java b/commands/src/main/java/com/wizardlybump17/wlib/command/extractor/method/factory/MethodCommandNodeFactory.java new file mode 100644 index 00000000..999b3efe --- /dev/null +++ b/commands/src/main/java/com/wizardlybump17/wlib/command/extractor/method/factory/MethodCommandNodeFactory.java @@ -0,0 +1,13 @@ +package com.wizardlybump17.wlib.command.extractor.method.factory; + +import com.wizardlybump17.wlib.command.annotation.Command; +import com.wizardlybump17.wlib.command.node.CommandNode; +import org.jetbrains.annotations.NotNull; + +import java.lang.reflect.Method; +import java.lang.reflect.Parameter; + +public abstract class MethodCommandNodeFactory { + + public abstract @NotNull CommandNode create(@NotNull Object object, @NotNull Method method, @NotNull Command commandAnnotation, @NotNull Parameter parameter); +} diff --git a/commands/src/main/java/com/wizardlybump17/wlib/command/registry/MethodCommandNodeFactoryRegistry.java b/commands/src/main/java/com/wizardlybump17/wlib/command/registry/MethodCommandNodeFactoryRegistry.java new file mode 100644 index 00000000..fbd7ffc3 --- /dev/null +++ b/commands/src/main/java/com/wizardlybump17/wlib/command/registry/MethodCommandNodeFactoryRegistry.java @@ -0,0 +1,58 @@ +package com.wizardlybump17.wlib.command.registry; + +import com.wizardlybump17.wlib.command.extractor.method.factory.MethodCommandNodeFactory; +import org.jetbrains.annotations.NotNull; +import org.jetbrains.annotations.Nullable; +import org.jetbrains.annotations.Unmodifiable; + +import java.util.Collections; +import java.util.HashMap; +import java.util.Map; + +public final class MethodCommandNodeFactoryRegistry { + + public static final @NotNull MethodCommandNodeFactoryRegistry INSTANCE = new MethodCommandNodeFactoryRegistry(); + + private MethodCommandNodeFactoryRegistry() { + } + + private final @NotNull Map, MethodCommandNodeFactory> factories = new HashMap<>(); + + public void addFactory(@NotNull Class clazz, @NotNull MethodCommandNodeFactory factory) { + factories.put(clazz, factory); + } + + public void addFactory(@NotNull MethodCommandNodeFactory factory, @NotNull Class ... classes) { + if (classes.length < 1) + throw new IllegalArgumentException("The classes array must contain at least one element"); + for (Class clazz : classes) + addFactory(clazz, factory); + } + + public @Nullable MethodCommandNodeFactory getFactory(@NotNull Class clazz) { + return factories.get(clazz); + } + + public void removeFactory(@NotNull Class clazz) { + factories.remove(clazz); + } + + public void removeFactory(@NotNull Class ... classes) { + if (classes.length < 1) + throw new IllegalArgumentException("The classes array must contain at least one element"); + for (Class clazz : classes) + removeFactory(clazz); + } + + public boolean hasFactory(@NotNull Class clazz) { + return factories.containsKey(clazz); + } + + public @NotNull @Unmodifiable Map, MethodCommandNodeFactory> getFactories() { + return Collections.unmodifiableMap(factories); + } + + public void clear() { + factories.clear(); + } +} From b5e3ad42644f74d26737d330a11670acc953654c Mon Sep 17 00:00:00 2001 From: WizardlyBump17 Date: Wed, 12 Nov 2025 00:11:00 -0300 Subject: [PATCH 140/363] using the factory to create the CommandNode --- .../method/MethodCommandExtractor.java | 51 ++++++++++--------- .../factory/MethodCommandNodeFactory.java | 2 +- 2 files changed, 27 insertions(+), 26 deletions(-) diff --git a/commands/src/main/java/com/wizardlybump17/wlib/command/extractor/method/MethodCommandExtractor.java b/commands/src/main/java/com/wizardlybump17/wlib/command/extractor/method/MethodCommandExtractor.java index 39185e50..fe17c62f 100644 --- a/commands/src/main/java/com/wizardlybump17/wlib/command/extractor/method/MethodCommandExtractor.java +++ b/commands/src/main/java/com/wizardlybump17/wlib/command/extractor/method/MethodCommandExtractor.java @@ -5,18 +5,17 @@ import com.wizardlybump17.wlib.command.executor.CommandNodeExecutor; import com.wizardlybump17.wlib.command.extractor.CommandExtractor; import com.wizardlybump17.wlib.command.extractor.method.executor.AbstractMethodCommandNodeExecutor; -import com.wizardlybump17.wlib.command.input.AllowedNumberInputs; -import com.wizardlybump17.wlib.command.input.string.AllowedStringInputs; +import com.wizardlybump17.wlib.command.extractor.method.factory.MethodCommandNodeFactory; import com.wizardlybump17.wlib.command.node.CommandNode; -import com.wizardlybump17.wlib.command.node.IntegerCommandNode; import com.wizardlybump17.wlib.command.node.LiteralCommandNode; -import com.wizardlybump17.wlib.command.node.StringCommandNode; +import com.wizardlybump17.wlib.command.registry.MethodCommandNodeFactoryRegistry; import com.wizardlybump17.wlib.command.result.CommandResult; import com.wizardlybump17.wlib.command.sender.CommandSender; import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.Nullable; import java.lang.reflect.Method; +import java.lang.reflect.Parameter; import java.util.ArrayList; import java.util.List; @@ -40,24 +39,24 @@ public boolean isAccepted(@NotNull Object object) { if (annotation == null) continue; - Class[] parameterTypes = method.getParameterTypes(); + Parameter[] parameters = method.getParameters(); Class returnType = method.getReturnType(); String[] commandParts = annotation.value().split(" "); CommandNode root = null; - int parameterIndex = parameterTypes.length - 1; + int parameterIndex = parameters.length - 1; for (int i = commandParts.length - 1; i >= 0; i--) { String part = commandParts[i]; CommandNode oldRoot = root; - root = createNode(part, parameterTypes, parameterIndex, root, annotation); + root = createNode(part, parameters, parameterIndex, root, annotation, object, method); if (!(root instanceof LiteralCommandNode)) parameterIndex--; if (oldRoot == null) - root = root.withExecutor(createExecutor(object, parameterTypes, returnType, method)); + root = root.withExecutor(createExecutor(object, parameters, returnType, method)); } if (root == null) @@ -69,7 +68,7 @@ public boolean isAccepted(@NotNull Object object) { return commands; } - private static @NotNull CommandNode createNode(@NotNull String part, @NotNull Class @NotNull [] parameterTypes, int parameterIndex, @Nullable CommandNode root, @NotNull com.wizardlybump17.wlib.command.annotation.Command annotation) { + private static @NotNull CommandNode createNode(@NotNull String part, @NotNull Parameter @NotNull [] parameters, int parameterIndex, @Nullable CommandNode root, @NotNull com.wizardlybump17.wlib.command.annotation.Command annotation, @NotNull Object object, @NotNull Method method) { CommandNode newNode; boolean argument = part.charAt(0) == '<' && part.charAt(part.length() - 1) == '>'; @@ -79,16 +78,15 @@ public boolean isAccepted(@NotNull Object object) { if (parameterIndex < 0) { newNode = new LiteralCommandNode(part, root == null ? List.of() : List.of(root)); } else { - Class parameterType = parameterTypes[parameterIndex]; - if (argument) { - if (parameterType == int.class || parameterType == Integer.class) { - newNode = new IntegerCommandNode(part, root == null ? List.of() : List.of(root), new AllowedNumberInputs.AllowedIntegerInputs.Unlimited()); - } else if (parameterType == String.class) { - newNode = new StringCommandNode(part, root == null ? List.of() : List.of(root), new AllowedStringInputs.Any()); - } else { + Parameter parameter = parameters[parameterIndex]; + Class parameterType = parameter.getType(); + + MethodCommandNodeFactory factory = MethodCommandNodeFactoryRegistry.INSTANCE.getFactory(parameterType); + if (factory == null) throw new UnsupportedOperationException(); - } + + newNode = factory.create(object, method, annotation, parameter, part); } else { newNode = new LiteralCommandNode(part, root == null ? List.of() : List.of(root)); } @@ -103,13 +101,13 @@ public boolean isAccepted(@NotNull Object object) { public static @NotNull CommandNodeExecutor createExecutor(@NotNull Object object, @NotNull String methodName, @NotNull Class @NotNull ... parameterTypes) { try { Method method = object.getClass().getMethod(methodName, parameterTypes); - return createExecutor(object, parameterTypes, method.getReturnType(), method); + return createExecutor(object, method.getParameters(), method.getReturnType(), method); } catch (NoSuchMethodException e) { throw new IllegalArgumentException(e); } } - private static @NotNull CommandNodeExecutor createExecutor(@NotNull Object object, @NotNull Class @NotNull [] parameterTypes, @NotNull Class returnType, @NotNull Method method) { + private static @NotNull CommandNodeExecutor createExecutor(@NotNull Object object, @NotNull Parameter @NotNull [] parameters, @NotNull Class returnType, @NotNull Method method) { /* If empty -> check the return type If CommandSender only -> pass only the command sender and check the return type @@ -119,7 +117,7 @@ public boolean isAccepted(@NotNull Object object) { If only parameters -> pass the parameters and check the return type */ - if (parameterTypes.length == 0) { //no parameters + if (parameters.length == 0) { //no parameters if (returnType.isAssignableFrom(CommandResult.class)) { //CommandResult return type return new AbstractMethodCommandNodeExecutor.NoArgumentsCommandResultExecutor<>(object, method); } else { @@ -127,14 +125,17 @@ public boolean isAccepted(@NotNull Object object) { } } - if (parameterTypes.length == 1) { - if (parameterTypes[0].isAssignableFrom(CommandSender.class)) { //CommandSender only + Parameter firstParameter = parameters[0]; + Class firstParameterType = firstParameter.getType(); + + if (parameters.length == 1) { + if (firstParameterType.isAssignableFrom(CommandSender.class)) { //CommandSender only if (returnType.isAssignableFrom(CommandResult.class)) { //CommandResult return type return new AbstractMethodCommandNodeExecutor.CommandSenderCommandResultExecutor<>(object, method); } else { //anything else return type return new AbstractMethodCommandNodeExecutor.CommandSenderExecutor<>(object, method); } - } else if (parameterTypes[0].isAssignableFrom(CommandContext.class)) { //CommandContext only + } else if (firstParameterType.isAssignableFrom(CommandContext.class)) { //CommandContext only if (returnType.isAssignableFrom(CommandResult.class)) { //CommandResult return type return new AbstractMethodCommandNodeExecutor.CommandContextCommandResultExecutor<>(object, method); } else { //anything else return type @@ -143,13 +144,13 @@ public boolean isAccepted(@NotNull Object object) { } } - if (parameterTypes[0].isAssignableFrom(CommandSender.class)) { //CommandSender + more arguments + if (firstParameterType.isAssignableFrom(CommandSender.class)) { //CommandSender + more arguments if (returnType.isAssignableFrom(CommandResult.class)) { //CommandResult return type return new AbstractMethodCommandNodeExecutor.CommandSenderAndArgumentsCommandResultExecutor<>(object, method); } else { //anything else return type return new AbstractMethodCommandNodeExecutor.CommandSenderAndArgumentsExecutor<>(object, method); } - } else if (parameterTypes[0].isAssignableFrom(CommandContext.class)) { //CommandContext + more arguments + } else if (firstParameterType.isAssignableFrom(CommandContext.class)) { //CommandContext + more arguments if (returnType.isAssignableFrom(CommandResult.class)) { //CommandResult return type return new AbstractMethodCommandNodeExecutor.CommandContextAndArgumentsCommandResultExecutor<>(object, method); } else { //anything else return type diff --git a/commands/src/main/java/com/wizardlybump17/wlib/command/extractor/method/factory/MethodCommandNodeFactory.java b/commands/src/main/java/com/wizardlybump17/wlib/command/extractor/method/factory/MethodCommandNodeFactory.java index 999b3efe..c4e2881f 100644 --- a/commands/src/main/java/com/wizardlybump17/wlib/command/extractor/method/factory/MethodCommandNodeFactory.java +++ b/commands/src/main/java/com/wizardlybump17/wlib/command/extractor/method/factory/MethodCommandNodeFactory.java @@ -9,5 +9,5 @@ public abstract class MethodCommandNodeFactory { - public abstract @NotNull CommandNode create(@NotNull Object object, @NotNull Method method, @NotNull Command commandAnnotation, @NotNull Parameter parameter); + public abstract @NotNull CommandNode create(@NotNull Object object, @NotNull Method method, @NotNull Command commandAnnotation, @NotNull Parameter parameter, @NotNull String name); } From d292b599312f26cea9dedd5998bbf5e84d324b02 Mon Sep 17 00:00:00 2001 From: WizardlyBump17 Date: Wed, 12 Nov 2025 00:13:49 -0300 Subject: [PATCH 141/363] throwing a better exception --- .../method/InvalidCombinationException.java | 11 ----------- ...MethodCommandNodeFactoryNotFoundException.java | 15 +++++++++++++++ .../extractor/method/MethodCommandExtractor.java | 7 ++++--- .../method/MethodCommandExtractorTests.java | 4 ++-- 4 files changed, 21 insertions(+), 16 deletions(-) delete mode 100644 commands/src/main/java/com/wizardlybump17/wlib/command/exception/extractor/method/InvalidCombinationException.java create mode 100644 commands/src/main/java/com/wizardlybump17/wlib/command/exception/extractor/method/MethodCommandNodeFactoryNotFoundException.java diff --git a/commands/src/main/java/com/wizardlybump17/wlib/command/exception/extractor/method/InvalidCombinationException.java b/commands/src/main/java/com/wizardlybump17/wlib/command/exception/extractor/method/InvalidCombinationException.java deleted file mode 100644 index 6df6ba7e..00000000 --- a/commands/src/main/java/com/wizardlybump17/wlib/command/exception/extractor/method/InvalidCombinationException.java +++ /dev/null @@ -1,11 +0,0 @@ -package com.wizardlybump17.wlib.command.exception.extractor.method; - -import com.wizardlybump17.wlib.command.exception.extractor.CommandExtractorException; -import org.jetbrains.annotations.NotNull; - -public class InvalidCombinationException extends CommandExtractorException { - - public InvalidCombinationException(@NotNull String message) { - super(message); - } -} diff --git a/commands/src/main/java/com/wizardlybump17/wlib/command/exception/extractor/method/MethodCommandNodeFactoryNotFoundException.java b/commands/src/main/java/com/wizardlybump17/wlib/command/exception/extractor/method/MethodCommandNodeFactoryNotFoundException.java new file mode 100644 index 00000000..2a3f5195 --- /dev/null +++ b/commands/src/main/java/com/wizardlybump17/wlib/command/exception/extractor/method/MethodCommandNodeFactoryNotFoundException.java @@ -0,0 +1,15 @@ +package com.wizardlybump17.wlib.command.exception.extractor.method; + +import com.wizardlybump17.wlib.command.exception.extractor.CommandExtractorException; +import org.jetbrains.annotations.NotNull; + +public class MethodCommandNodeFactoryNotFoundException extends CommandExtractorException { + + public MethodCommandNodeFactoryNotFoundException() { + super(); + } + + public MethodCommandNodeFactoryNotFoundException(@NotNull String message) { + super(message); + } +} diff --git a/commands/src/main/java/com/wizardlybump17/wlib/command/extractor/method/MethodCommandExtractor.java b/commands/src/main/java/com/wizardlybump17/wlib/command/extractor/method/MethodCommandExtractor.java index fe17c62f..8a3f289a 100644 --- a/commands/src/main/java/com/wizardlybump17/wlib/command/extractor/method/MethodCommandExtractor.java +++ b/commands/src/main/java/com/wizardlybump17/wlib/command/extractor/method/MethodCommandExtractor.java @@ -2,6 +2,7 @@ import com.wizardlybump17.wlib.command.Command; import com.wizardlybump17.wlib.command.context.CommandContext; +import com.wizardlybump17.wlib.command.exception.extractor.method.MethodCommandNodeFactoryNotFoundException; import com.wizardlybump17.wlib.command.executor.CommandNodeExecutor; import com.wizardlybump17.wlib.command.extractor.CommandExtractor; import com.wizardlybump17.wlib.command.extractor.method.executor.AbstractMethodCommandNodeExecutor; @@ -29,7 +30,7 @@ public boolean isAccepted(@NotNull Object object) { } @Override - public @NotNull List extract(@NotNull Object object) { + public @NotNull List extract(@NotNull Object object) throws MethodCommandNodeFactoryNotFoundException { List commands = new ArrayList<>(); Class clazz = object.getClass(); @@ -68,7 +69,7 @@ public boolean isAccepted(@NotNull Object object) { return commands; } - private static @NotNull CommandNode createNode(@NotNull String part, @NotNull Parameter @NotNull [] parameters, int parameterIndex, @Nullable CommandNode root, @NotNull com.wizardlybump17.wlib.command.annotation.Command annotation, @NotNull Object object, @NotNull Method method) { + private static @NotNull CommandNode createNode(@NotNull String part, @NotNull Parameter @NotNull [] parameters, int parameterIndex, @Nullable CommandNode root, @NotNull com.wizardlybump17.wlib.command.annotation.Command annotation, @NotNull Object object, @NotNull Method method) throws MethodCommandNodeFactoryNotFoundException { CommandNode newNode; boolean argument = part.charAt(0) == '<' && part.charAt(part.length() - 1) == '>'; @@ -84,7 +85,7 @@ public boolean isAccepted(@NotNull Object object) { MethodCommandNodeFactory factory = MethodCommandNodeFactoryRegistry.INSTANCE.getFactory(parameterType); if (factory == null) - throw new UnsupportedOperationException(); + throw new MethodCommandNodeFactoryNotFoundException("MethodCommandNodeFactory not found for the parameter " + parameter); newNode = factory.create(object, method, annotation, parameter, part); } else { diff --git a/commands/src/test/java/com/wizardlybump17/wlib/test/command/extractor/method/MethodCommandExtractorTests.java b/commands/src/test/java/com/wizardlybump17/wlib/test/command/extractor/method/MethodCommandExtractorTests.java index 1c19d7ba..979a7b91 100644 --- a/commands/src/test/java/com/wizardlybump17/wlib/test/command/extractor/method/MethodCommandExtractorTests.java +++ b/commands/src/test/java/com/wizardlybump17/wlib/test/command/extractor/method/MethodCommandExtractorTests.java @@ -66,7 +66,7 @@ void testNoParameters() { ) ) )); - List actual = CommandExtractor.METHOD.extract(object); + List actual = Assertions.assertDoesNotThrow(() -> CommandExtractor.METHOD.extract(object)); expected.sort(null); actual.sort(null); @@ -131,7 +131,7 @@ void testNoParametersCommandResult() { ) ) )); - List actual = CommandExtractor.METHOD.extract(object); + List actual = Assertions.assertDoesNotThrow(() -> CommandExtractor.METHOD.extract(object)); expected.sort(null); actual.sort(null); From 8637e3277fbadbbbcac7e9abc4d4cc370126097a Mon Sep 17 00:00:00 2001 From: WizardlyBump17 Date: Wed, 12 Nov 2025 00:37:48 -0300 Subject: [PATCH 142/363] silly me, I forgot about the children (need to add tests for that) --- .../method/MethodCommandExtractor.java | 4 +-- .../factory/MethodCommandNodeFactory.java | 5 +-- .../method/MethodCommandExtractorTests.java | 35 +++++++++++++++++++ 3 files changed, 40 insertions(+), 4 deletions(-) diff --git a/commands/src/main/java/com/wizardlybump17/wlib/command/extractor/method/MethodCommandExtractor.java b/commands/src/main/java/com/wizardlybump17/wlib/command/extractor/method/MethodCommandExtractor.java index 8a3f289a..b9e4c60e 100644 --- a/commands/src/main/java/com/wizardlybump17/wlib/command/extractor/method/MethodCommandExtractor.java +++ b/commands/src/main/java/com/wizardlybump17/wlib/command/extractor/method/MethodCommandExtractor.java @@ -83,11 +83,11 @@ public boolean isAccepted(@NotNull Object object) { Parameter parameter = parameters[parameterIndex]; Class parameterType = parameter.getType(); - MethodCommandNodeFactory factory = MethodCommandNodeFactoryRegistry.INSTANCE.getFactory(parameterType); + MethodCommandNodeFactory factory = MethodCommandNodeFactoryRegistry.INSTANCE.getFactory(parameterType); if (factory == null) throw new MethodCommandNodeFactoryNotFoundException("MethodCommandNodeFactory not found for the parameter " + parameter); - newNode = factory.create(object, method, annotation, parameter, part); + newNode = factory.create(object, method, annotation, parameter, part, root); } else { newNode = new LiteralCommandNode(part, root == null ? List.of() : List.of(root)); } diff --git a/commands/src/main/java/com/wizardlybump17/wlib/command/extractor/method/factory/MethodCommandNodeFactory.java b/commands/src/main/java/com/wizardlybump17/wlib/command/extractor/method/factory/MethodCommandNodeFactory.java index c4e2881f..2ccf2698 100644 --- a/commands/src/main/java/com/wizardlybump17/wlib/command/extractor/method/factory/MethodCommandNodeFactory.java +++ b/commands/src/main/java/com/wizardlybump17/wlib/command/extractor/method/factory/MethodCommandNodeFactory.java @@ -3,11 +3,12 @@ import com.wizardlybump17.wlib.command.annotation.Command; import com.wizardlybump17.wlib.command.node.CommandNode; import org.jetbrains.annotations.NotNull; +import org.jetbrains.annotations.Nullable; import java.lang.reflect.Method; import java.lang.reflect.Parameter; -public abstract class MethodCommandNodeFactory { +public abstract class MethodCommandNodeFactory> { - public abstract @NotNull CommandNode create(@NotNull Object object, @NotNull Method method, @NotNull Command commandAnnotation, @NotNull Parameter parameter, @NotNull String name); + public abstract @NotNull N create(@NotNull Object object, @NotNull Method method, @NotNull Command commandAnnotation, @NotNull Parameter parameter, @NotNull String name, @Nullable CommandNode root); } diff --git a/commands/src/test/java/com/wizardlybump17/wlib/test/command/extractor/method/MethodCommandExtractorTests.java b/commands/src/test/java/com/wizardlybump17/wlib/test/command/extractor/method/MethodCommandExtractorTests.java index 979a7b91..8245f81a 100644 --- a/commands/src/test/java/com/wizardlybump17/wlib/test/command/extractor/method/MethodCommandExtractorTests.java +++ b/commands/src/test/java/com/wizardlybump17/wlib/test/command/extractor/method/MethodCommandExtractorTests.java @@ -4,19 +4,27 @@ import com.wizardlybump17.wlib.command.context.CommandContext; import com.wizardlybump17.wlib.command.extractor.CommandExtractor; import com.wizardlybump17.wlib.command.extractor.method.MethodCommandExtractor; +import com.wizardlybump17.wlib.command.extractor.method.factory.MethodCommandNodeFactory; import com.wizardlybump17.wlib.command.input.AllowedNumberInputs; import com.wizardlybump17.wlib.command.input.string.AllowedStringInputs; import com.wizardlybump17.wlib.command.manager.CommandManager; +import com.wizardlybump17.wlib.command.node.CommandNode; import com.wizardlybump17.wlib.command.node.IntegerCommandNode; import com.wizardlybump17.wlib.command.node.LiteralCommandNode; import com.wizardlybump17.wlib.command.node.StringCommandNode; +import com.wizardlybump17.wlib.command.registry.MethodCommandNodeFactoryRegistry; import com.wizardlybump17.wlib.command.result.CommandResult; import com.wizardlybump17.wlib.command.sender.BasicCommandSender; import com.wizardlybump17.wlib.command.sender.CommandSender; import org.jetbrains.annotations.NotNull; +import org.jetbrains.annotations.Nullable; +import org.junit.jupiter.api.AfterAll; import org.junit.jupiter.api.Assertions; +import org.junit.jupiter.api.BeforeAll; import org.junit.jupiter.api.Test; +import java.lang.reflect.Method; +import java.lang.reflect.Parameter; import java.util.ArrayList; import java.util.List; import java.util.UUID; @@ -24,6 +32,33 @@ class MethodCommandExtractorTests { + @BeforeAll + static void setup() { + MethodCommandNodeFactoryRegistry.INSTANCE.addFactory( + int.class, + new MethodCommandNodeFactory() { + @Override + public @NotNull IntegerCommandNode create(@NotNull Object object, @NotNull Method method, com.wizardlybump17.wlib.command.annotation.@NotNull Command commandAnnotation, @NotNull Parameter parameter, @NotNull String name, @Nullable CommandNode root) { + return new IntegerCommandNode(name, root == null ? List.of() : List.of(root), new AllowedNumberInputs.AllowedIntegerInputs.Unlimited()); + } + } + ); + MethodCommandNodeFactoryRegistry.INSTANCE.addFactory( + String.class, + new MethodCommandNodeFactory() { + @Override + public @NotNull StringCommandNode create(@NotNull Object object, @NotNull Method method, com.wizardlybump17.wlib.command.annotation.@NotNull Command commandAnnotation, @NotNull Parameter parameter, @NotNull String name, @Nullable CommandNode root) { + return new StringCommandNode(name, root == null ? List.of() : List.of(root), new AllowedStringInputs.Any()); + } + } + ); + } + + @AfterAll + static void clear() { + MethodCommandNodeFactoryRegistry.INSTANCE.clear(); + } + /* No parameters */ From 912309b11750c87efbe482cfc66753a2db1db820 Mon Sep 17 00:00:00 2001 From: WizardlyBump17 Date: Thu, 20 Nov 2025 19:46:07 -0300 Subject: [PATCH 143/363] equalsIgnoreExecutor --- .../java/com/wizardlybump17/wlib/command/Command.java | 7 +++++++ .../wizardlybump17/wlib/command/node/CommandNode.java | 10 ++++++++++ 2 files changed, 17 insertions(+) diff --git a/commands/src/main/java/com/wizardlybump17/wlib/command/Command.java b/commands/src/main/java/com/wizardlybump17/wlib/command/Command.java index 207d7048..64821b77 100644 --- a/commands/src/main/java/com/wizardlybump17/wlib/command/Command.java +++ b/commands/src/main/java/com/wizardlybump17/wlib/command/Command.java @@ -195,6 +195,13 @@ public boolean equals(Object o) { return Objects.equals(root, command.root); } + public boolean equalsIgnoreExecutor(@Nullable Object other) { + if (other == null || getClass() != other.getClass()) + return false; + Command command = (Command) other; + return root.equalsIgnoreExecutor(command.root); + } + @Override public int hashCode() { return Objects.hashCode(root); diff --git a/commands/src/main/java/com/wizardlybump17/wlib/command/node/CommandNode.java b/commands/src/main/java/com/wizardlybump17/wlib/command/node/CommandNode.java index ce9de1c9..afe9d501 100644 --- a/commands/src/main/java/com/wizardlybump17/wlib/command/node/CommandNode.java +++ b/commands/src/main/java/com/wizardlybump17/wlib/command/node/CommandNode.java @@ -115,6 +115,16 @@ public boolean equals(Object o) { && Objects.equals(permission, that.permission); } + public boolean equalsIgnoreExecutor(@Nullable Object other) { + if (other == null || getClass() != other.getClass()) + return false; + CommandNode that = (CommandNode) other; + return Objects.equals(name, that.name) + && CollectionUtil.contentEquals(children, that.children) + && Objects.equals(allowedInputs, that.allowedInputs) + && Objects.equals(permission, that.permission); + } + @Override public int hashCode() { return Objects.hash(name, children, allowedInputs, executor, permission); From 6d131df61366763bbe911126afc92f1dabf1100e Mon Sep 17 00:00:00 2001 From: WizardlyBump17 Date: Thu, 20 Nov 2025 19:48:13 -0300 Subject: [PATCH 144/363] lets see if the structure keeps the same --- .../MethodCommandExtractorStructureTests.java | 64 +++++++++++++++++++ .../wlib/test/util/AssertionUtil.java | 62 ++++++++++++++++++ 2 files changed, 126 insertions(+) create mode 100644 commands/src/test/java/com/wizardlybump17/wlib/test/command/extractor/method/MethodCommandExtractorStructureTests.java create mode 100644 commands/src/test/java/com/wizardlybump17/wlib/test/util/AssertionUtil.java diff --git a/commands/src/test/java/com/wizardlybump17/wlib/test/command/extractor/method/MethodCommandExtractorStructureTests.java b/commands/src/test/java/com/wizardlybump17/wlib/test/command/extractor/method/MethodCommandExtractorStructureTests.java new file mode 100644 index 00000000..e206f30a --- /dev/null +++ b/commands/src/test/java/com/wizardlybump17/wlib/test/command/extractor/method/MethodCommandExtractorStructureTests.java @@ -0,0 +1,64 @@ +package com.wizardlybump17.wlib.test.command.extractor.method; + +import com.wizardlybump17.wlib.command.Command; +import com.wizardlybump17.wlib.command.extractor.CommandExtractor; +import com.wizardlybump17.wlib.command.node.LiteralCommandNode; +import com.wizardlybump17.wlib.test.util.AssertionUtil; +import org.junit.jupiter.api.Assertions; +import org.junit.jupiter.api.Test; + +import java.util.ArrayList; +import java.util.List; + +class MethodCommandExtractorStructureTests { + + @Test + void test0() { + Command test0 = new Command( + new LiteralCommandNode( + "test0", + List.of( + new LiteralCommandNode( + "123" + ) + ) + ) + ); + Command test1 = new Command( + new LiteralCommandNode( + "test1", + List.of( + new LiteralCommandNode( + "123", + List.of( + new LiteralCommandNode( + "456" + ) + ) + ) + ) + ) + ); + + Test0 object = new Test0(); + + List expected = new ArrayList<>(List.of(test0, test1)); + List actual = Assertions.assertDoesNotThrow(() -> CommandExtractor.METHOD.extract(object)); + + expected.sort(null); + actual.sort(null); + + AssertionUtil.assertCommandsEquals(expected, actual); + } + + public static class Test0 { + + @com.wizardlybump17.wlib.command.annotation.Command("test0 123") + public void test0() { + } + + @com.wizardlybump17.wlib.command.annotation.Command("test1 123 456") + public void test1() { + } + } +} diff --git a/commands/src/test/java/com/wizardlybump17/wlib/test/util/AssertionUtil.java b/commands/src/test/java/com/wizardlybump17/wlib/test/util/AssertionUtil.java new file mode 100644 index 00000000..ba29d398 --- /dev/null +++ b/commands/src/test/java/com/wizardlybump17/wlib/test/util/AssertionUtil.java @@ -0,0 +1,62 @@ +package com.wizardlybump17.wlib.test.util; + +import com.wizardlybump17.wlib.command.Command; +import org.jetbrains.annotations.Nullable; +import org.junit.jupiter.api.AssertionFailureBuilder; + +import java.util.List; + +public final class AssertionUtil { + + private AssertionUtil() { + } + + public static void assertCommandsEquals(@Nullable List expected, @Nullable List actual) { + if (expected == null) { + if (actual != null) { + AssertionFailureBuilder.assertionFailure() + .expected(null) + .actual(actual) + .buildAndThrow(); + return; + } else { + return; + } + } + + if (expected != null) { + if (actual == null) { + AssertionFailureBuilder.assertionFailure() + .expected(expected) + .actual(null) + .buildAndThrow(); + return; + } else { + return; + } + } + + if (expected.size() != actual.size()) { + AssertionFailureBuilder.assertionFailure() + .expected(expected) + .actual(actual) + .message("Expected and actual lists have different sizes") + .buildAndThrow(); + return; + } + + for (int i = 0; i < expected.size(); i++) { + Command expectedCommand = expected.get(i); + Command actualCommand = actual.get(i); + + if (!expectedCommand.equalsIgnoreExecutor(actualCommand)) { + AssertionFailureBuilder.assertionFailure() + .expected(expectedCommand) + .actual(actualCommand) + .message("Commands at index " + i + " are not equal") + .buildAndThrow(); + return; + } + } + } +} From 991d7dc9e6dcdb917a55012bbb0548f52d4b2f20 Mon Sep 17 00:00:00 2001 From: WizardlyBump17 Date: Sun, 23 Nov 2025 21:36:46 -0300 Subject: [PATCH 145/363] fixed the equals check --- .../wlib/command/node/CommandNode.java | 24 +++++++++++++++---- .../wlib/test/util/AssertionUtil.java | 6 +---- 2 files changed, 20 insertions(+), 10 deletions(-) diff --git a/commands/src/main/java/com/wizardlybump17/wlib/command/node/CommandNode.java b/commands/src/main/java/com/wizardlybump17/wlib/command/node/CommandNode.java index afe9d501..f13c05df 100644 --- a/commands/src/main/java/com/wizardlybump17/wlib/command/node/CommandNode.java +++ b/commands/src/main/java/com/wizardlybump17/wlib/command/node/CommandNode.java @@ -10,10 +10,7 @@ import org.jetbrains.annotations.Nullable; import org.jetbrains.annotations.Unmodifiable; -import java.util.ArrayList; -import java.util.List; -import java.util.Objects; -import java.util.Optional; +import java.util.*; public abstract class CommandNode { @@ -120,11 +117,28 @@ public boolean equalsIgnoreExecutor(@Nullable Object other) { return false; CommandNode that = (CommandNode) other; return Objects.equals(name, that.name) - && CollectionUtil.contentEquals(children, that.children) + && equalsIgnoreExecutor(children, that.children) && Objects.equals(allowedInputs, that.allowedInputs) && Objects.equals(permission, that.permission); } + public static boolean equalsIgnoreExecutor(@NotNull Collection> a, @NotNull Collection> b) { + if (a.size() != b.size()) + return false; + + Iterator> aIterator = a.iterator(); + Iterator> bIterator = b.iterator(); + + while (aIterator.hasNext() && bIterator.hasNext()) { + CommandNode aNode = aIterator.next(); + CommandNode bNode = bIterator.next(); + if (!aNode.equalsIgnoreExecutor(bNode)) + return false; + } + + return true; + } + @Override public int hashCode() { return Objects.hash(name, children, allowedInputs, executor, permission); diff --git a/commands/src/test/java/com/wizardlybump17/wlib/test/util/AssertionUtil.java b/commands/src/test/java/com/wizardlybump17/wlib/test/util/AssertionUtil.java index ba29d398..275ddec1 100644 --- a/commands/src/test/java/com/wizardlybump17/wlib/test/util/AssertionUtil.java +++ b/commands/src/test/java/com/wizardlybump17/wlib/test/util/AssertionUtil.java @@ -18,10 +18,8 @@ public static void assertCommandsEquals(@Nullable List expected, @Nulla .expected(null) .actual(actual) .buildAndThrow(); - return; - } else { - return; } + return; } if (expected != null) { @@ -31,8 +29,6 @@ public static void assertCommandsEquals(@Nullable List expected, @Nulla .actual(null) .buildAndThrow(); return; - } else { - return; } } From 8b1421e11a483249124b03f9c5ae7c6891b7c3e2 Mon Sep 17 00:00:00 2001 From: WizardlyBump17 Date: Sun, 23 Nov 2025 21:43:04 -0300 Subject: [PATCH 146/363] more tests --- .../MethodCommandExtractorStructureTests.java | 108 ++++++++++++++++++ 1 file changed, 108 insertions(+) diff --git a/commands/src/test/java/com/wizardlybump17/wlib/test/command/extractor/method/MethodCommandExtractorStructureTests.java b/commands/src/test/java/com/wizardlybump17/wlib/test/command/extractor/method/MethodCommandExtractorStructureTests.java index e206f30a..083abea9 100644 --- a/commands/src/test/java/com/wizardlybump17/wlib/test/command/extractor/method/MethodCommandExtractorStructureTests.java +++ b/commands/src/test/java/com/wizardlybump17/wlib/test/command/extractor/method/MethodCommandExtractorStructureTests.java @@ -2,16 +2,56 @@ import com.wizardlybump17.wlib.command.Command; import com.wizardlybump17.wlib.command.extractor.CommandExtractor; +import com.wizardlybump17.wlib.command.extractor.method.factory.MethodCommandNodeFactory; +import com.wizardlybump17.wlib.command.input.AllowedNumberInputs; +import com.wizardlybump17.wlib.command.input.string.AllowedStringInputs; +import com.wizardlybump17.wlib.command.node.CommandNode; +import com.wizardlybump17.wlib.command.node.IntegerCommandNode; import com.wizardlybump17.wlib.command.node.LiteralCommandNode; +import com.wizardlybump17.wlib.command.node.StringCommandNode; +import com.wizardlybump17.wlib.command.registry.MethodCommandNodeFactoryRegistry; import com.wizardlybump17.wlib.test.util.AssertionUtil; +import org.jetbrains.annotations.NotNull; +import org.jetbrains.annotations.Nullable; +import org.junit.jupiter.api.AfterAll; import org.junit.jupiter.api.Assertions; +import org.junit.jupiter.api.BeforeAll; import org.junit.jupiter.api.Test; +import java.lang.reflect.Method; +import java.lang.reflect.Parameter; import java.util.ArrayList; import java.util.List; class MethodCommandExtractorStructureTests { + @BeforeAll + static void setup() { + MethodCommandNodeFactoryRegistry.INSTANCE.addFactory( + int.class, + new MethodCommandNodeFactory() { + @Override + public @NotNull IntegerCommandNode create(@NotNull Object object, @NotNull Method method, com.wizardlybump17.wlib.command.annotation.@NotNull Command commandAnnotation, @NotNull Parameter parameter, @NotNull String name, @Nullable CommandNode root) { + return new IntegerCommandNode(name, root == null ? List.of() : List.of(root), new AllowedNumberInputs.AllowedIntegerInputs.Unlimited()); + } + } + ); + MethodCommandNodeFactoryRegistry.INSTANCE.addFactory( + String.class, + new MethodCommandNodeFactory() { + @Override + public @NotNull StringCommandNode create(@NotNull Object object, @NotNull Method method, com.wizardlybump17.wlib.command.annotation.@NotNull Command commandAnnotation, @NotNull Parameter parameter, @NotNull String name, @Nullable CommandNode root) { + return new StringCommandNode(name, root == null ? List.of() : List.of(root), new AllowedStringInputs.Any()); + } + } + ); + } + + @AfterAll + static void clear() { + MethodCommandNodeFactoryRegistry.INSTANCE.clear(); + } + @Test void test0() { Command test0 = new Command( @@ -61,4 +101,72 @@ public void test0() { public void test1() { } } + + @Test + void test1() { + Command test0 = new Command( + new LiteralCommandNode( + "test0", + List.of( + new IntegerCommandNode( + "int", + List.of( + new LiteralCommandNode( + "123" + ) + ), + new AllowedNumberInputs.AllowedIntegerInputs.Unlimited() + ) + ) + ) + ); + Command test1 = new Command( + new LiteralCommandNode( + "test1", + List.of( + new IntegerCommandNode( + "int0", + List.of( + new IntegerCommandNode( + "int1", + List.of( + new LiteralCommandNode( + "123", + List.of( + new LiteralCommandNode( + "abc" + ) + ) + ) + ), + new AllowedNumberInputs.AllowedIntegerInputs.Unlimited() + ) + ), + new AllowedNumberInputs.AllowedIntegerInputs.Unlimited() + ) + ) + ) + ); + + Test1 object = new Test1(); + + List expected = new ArrayList<>(List.of(test0, test1)); + List actual = Assertions.assertDoesNotThrow(() -> CommandExtractor.METHOD.extract(object)); + + expected.sort(null); + actual.sort(null); + + AssertionUtil.assertCommandsEquals(expected, actual); + } + + public static class Test1 { + + @com.wizardlybump17.wlib.command.annotation.Command("test0 123") + public void test0(int arg0) { + } + + @com.wizardlybump17.wlib.command.annotation.Command("test1 123 abc") + public void test1(int arg0, int arg1) { + } + } } From c6272645f4277bbf49900e22d1abdd31e108a049 Mon Sep 17 00:00:00 2001 From: WizardlyBump17 Date: Sun, 23 Nov 2025 22:45:22 -0300 Subject: [PATCH 147/363] reorganizing the AllowedInputs system --- .../wlib/command/input/AllowedListInputs.java | 10 +++ .../input/string/AllowedStringInputs.java | 89 +++++++++++++------ 2 files changed, 71 insertions(+), 28 deletions(-) create mode 100644 commands/src/main/java/com/wizardlybump17/wlib/command/input/AllowedListInputs.java diff --git a/commands/src/main/java/com/wizardlybump17/wlib/command/input/AllowedListInputs.java b/commands/src/main/java/com/wizardlybump17/wlib/command/input/AllowedListInputs.java new file mode 100644 index 00000000..790c4763 --- /dev/null +++ b/commands/src/main/java/com/wizardlybump17/wlib/command/input/AllowedListInputs.java @@ -0,0 +1,10 @@ +package com.wizardlybump17.wlib.command.input; + +import org.jetbrains.annotations.NotNull; + +import java.util.List; + +public interface AllowedListInputs extends AllowedInputs { + + @NotNull List getAllowedValues(); +} diff --git a/commands/src/main/java/com/wizardlybump17/wlib/command/input/string/AllowedStringInputs.java b/commands/src/main/java/com/wizardlybump17/wlib/command/input/string/AllowedStringInputs.java index 8f6e3a34..cfffc3c5 100644 --- a/commands/src/main/java/com/wizardlybump17/wlib/command/input/string/AllowedStringInputs.java +++ b/commands/src/main/java/com/wizardlybump17/wlib/command/input/string/AllowedStringInputs.java @@ -1,6 +1,7 @@ package com.wizardlybump17.wlib.command.input.string; import com.wizardlybump17.wlib.command.input.AllowedInputs; +import com.wizardlybump17.wlib.command.input.AllowedListInputs; import com.wizardlybump17.wlib.command.sender.CommandSender; import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.Nullable; @@ -11,55 +12,73 @@ public interface AllowedStringInputs extends AllowedInputs { - final class Listed implements AllowedStringInputs { + static @NotNull Values valuesIgnoreCase(@NotNull List values) { + return new Values(values, true); + } + + static @NotNull Values values(@NotNull List values) { + return new Values(values, false); + } - private final @NotNull List list; - private final @NotNull List listToCheck; + static @NotNull Any anyNullable() { + return Any.NULLABLE; + } + + static @NotNull Any anyNotNull() { + return Any.NOT_NULL; + } + + final class Values implements AllowedStringInputs, AllowedListInputs { + + private final @NotNull List values; + private final @NotNull List toCheck; private final boolean ignoreCase; - public Listed(@NotNull List list, boolean ignoreCase) { - this.list = List.copyOf(list); - if (ignoreCase) { - listToCheck = list.stream() - .map(String::toLowerCase) - .toList(); - } else { - listToCheck = list; - } + private Values(@NotNull List values, boolean ignoreCase) { + this.values = List.copyOf(values); this.ignoreCase = ignoreCase; + if (ignoreCase) + toCheck = values.stream().map(String::toLowerCase).toList(); + else + toCheck = this.values; } @Override - public boolean isAllowed(@Nullable String input) { - return listToCheck.contains(input); + public @NotNull @Unmodifiable List getAllowedValues() { + return values; } - public @NotNull @Unmodifiable List list() { - return list; + @Override + public @NotNull List getSuggestions(@NotNull CommandSender sender, @NotNull List input, @NotNull String current) { + return values; } - public boolean ignoreCase() { - return ignoreCase; + @Override + public boolean isAllowed(@Nullable String input) { + if (input == null) + return false; + if (ignoreCase) + return toCheck.contains(input.toLowerCase()); + return toCheck.contains(input); } @Override public boolean equals(Object object) { if (object == null || getClass() != object.getClass()) return false; - Listed listed = (Listed) object; - return ignoreCase == listed.ignoreCase && Objects.equals(list, listed.list) && Objects.equals(listToCheck, listed.listToCheck); + Values values1 = (Values) object; + return ignoreCase == values1.ignoreCase && Objects.equals(values, values1.values) && Objects.equals(toCheck, values1.toCheck); } @Override public int hashCode() { - return Objects.hash(list, listToCheck, ignoreCase); + return Objects.hash(values, toCheck, ignoreCase); } @Override public String toString() { - return "Listed{" + - "list=" + list + - ", listToCheck=" + listToCheck + + return "Values{" + + "values=" + values + ", ignoreCase=" + ignoreCase + '}'; } @@ -67,9 +86,18 @@ public String toString() { final class Any implements AllowedStringInputs { + private static final @NotNull Any NULLABLE = new Any(true); + private static final @NotNull Any NOT_NULL = new Any(false); + + private final boolean nullable; + + private Any(boolean nullable) { + this.nullable = nullable; + } + @Override public boolean isAllowed(@Nullable String input) { - return true; + return nullable || input != null; } @Override @@ -79,17 +107,22 @@ public boolean isAllowed(@Nullable String input) { @Override public boolean equals(Object object) { - return object != null && getClass() == object.getClass(); + if (object == null || getClass() != object.getClass()) + return false; + Any any = (Any) object; + return nullable == any.nullable; } @Override public int hashCode() { - return Objects.hash(); + return Objects.hashCode(nullable); } @Override public String toString() { - return "Any{}"; + return "Any{" + + "nullable=" + nullable + + '}'; } } } From 482aad5ffa7dd6c8d16d9c6bc69010c85c3ad878 Mon Sep 17 00:00:00 2001 From: WizardlyBump17 Date: Sun, 23 Nov 2025 22:46:19 -0300 Subject: [PATCH 148/363] using the new stuff --- .../method/MethodCommandExtractorStructureTests.java | 2 +- .../extractor/method/MethodCommandExtractorTests.java | 8 ++++---- 2 files changed, 5 insertions(+), 5 deletions(-) diff --git a/commands/src/test/java/com/wizardlybump17/wlib/test/command/extractor/method/MethodCommandExtractorStructureTests.java b/commands/src/test/java/com/wizardlybump17/wlib/test/command/extractor/method/MethodCommandExtractorStructureTests.java index 083abea9..079a4047 100644 --- a/commands/src/test/java/com/wizardlybump17/wlib/test/command/extractor/method/MethodCommandExtractorStructureTests.java +++ b/commands/src/test/java/com/wizardlybump17/wlib/test/command/extractor/method/MethodCommandExtractorStructureTests.java @@ -41,7 +41,7 @@ static void setup() { new MethodCommandNodeFactory() { @Override public @NotNull StringCommandNode create(@NotNull Object object, @NotNull Method method, com.wizardlybump17.wlib.command.annotation.@NotNull Command commandAnnotation, @NotNull Parameter parameter, @NotNull String name, @Nullable CommandNode root) { - return new StringCommandNode(name, root == null ? List.of() : List.of(root), new AllowedStringInputs.Any()); + return new StringCommandNode(name, root == null ? List.of() : List.of(root), AllowedStringInputs.anyNullable()); } } ); diff --git a/commands/src/test/java/com/wizardlybump17/wlib/test/command/extractor/method/MethodCommandExtractorTests.java b/commands/src/test/java/com/wizardlybump17/wlib/test/command/extractor/method/MethodCommandExtractorTests.java index 8245f81a..7fb31346 100644 --- a/commands/src/test/java/com/wizardlybump17/wlib/test/command/extractor/method/MethodCommandExtractorTests.java +++ b/commands/src/test/java/com/wizardlybump17/wlib/test/command/extractor/method/MethodCommandExtractorTests.java @@ -48,7 +48,7 @@ static void setup() { new MethodCommandNodeFactory() { @Override public @NotNull StringCommandNode create(@NotNull Object object, @NotNull Method method, com.wizardlybump17.wlib.command.annotation.@NotNull Command commandAnnotation, @NotNull Parameter parameter, @NotNull String name, @Nullable CommandNode root) { - return new StringCommandNode(name, root == null ? List.of() : List.of(root), new AllowedStringInputs.Any()); + return new StringCommandNode(name, root == null ? List.of() : List.of(root), AllowedStringInputs.anyNullable()); } } ); @@ -1019,7 +1019,7 @@ void testExecute() { Assertions.assertDoesNotThrow(() -> MethodCommandExtractor.createExecutor(object, "welcomeWorld", CommandSender.class, String.class)) ) ), - new AllowedStringInputs.Any(), + AllowedStringInputs.anyNullable(), Assertions.assertDoesNotThrow(() -> MethodCommandExtractor.createExecutor(object, "welcome", CommandSender.class, String.class)), null ) @@ -1038,7 +1038,7 @@ void testExecute() { Assertions.assertDoesNotThrow(() -> MethodCommandExtractor.createExecutor(object, "wassupNice", CommandContext.class, String.class)) ) ), - new AllowedStringInputs.Any(), + AllowedStringInputs.anyNullable(), Assertions.assertDoesNotThrow(() -> MethodCommandExtractor.createExecutor(object, "wassup", CommandContext.class, String.class)), null ) @@ -1057,7 +1057,7 @@ void testExecute() { Assertions.assertDoesNotThrow(() -> MethodCommandExtractor.createExecutor(object, "ayeNice", String.class)) ) ), - new AllowedStringInputs.Any(), + AllowedStringInputs.anyNullable(), Assertions.assertDoesNotThrow(() -> MethodCommandExtractor.createExecutor(object, "aye", String.class)), null ) From 03d10f9f35717ee78186f042e817eda21ff9b97c Mon Sep 17 00:00:00 2001 From: WizardlyBump17 Date: Sun, 23 Nov 2025 23:05:26 -0300 Subject: [PATCH 149/363] added the getter --- .../wlib/command/input/string/AllowedStringInputs.java | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/commands/src/main/java/com/wizardlybump17/wlib/command/input/string/AllowedStringInputs.java b/commands/src/main/java/com/wizardlybump17/wlib/command/input/string/AllowedStringInputs.java index cfffc3c5..1845aba5 100644 --- a/commands/src/main/java/com/wizardlybump17/wlib/command/input/string/AllowedStringInputs.java +++ b/commands/src/main/java/com/wizardlybump17/wlib/command/input/string/AllowedStringInputs.java @@ -100,6 +100,10 @@ public boolean isAllowed(@Nullable String input) { return nullable || input != null; } + public boolean isNullable() { + return nullable; + } + @Override public @NotNull List getSuggestions(@NotNull CommandSender sender, @NotNull List input, @NotNull String current) { return List.of(current); From 6b36f7a0df602a82ea1d2978b3a8db0aa569f88c Mon Sep 17 00:00:00 2001 From: WizardlyBump17 Date: Mon, 24 Nov 2025 17:55:20 -0300 Subject: [PATCH 150/363] improved the AllowedNumberInputs --- .../command/input/AllowedNumberInputs.java | 180 ------------------ .../wlib/command/input/SingleValueInput.java | 22 +++ .../input/number/AllowedIntegerInputs.java | 164 ++++++++++++++++ .../input/number/AllowedNumberInputs.java | 117 ++++++++++++ .../wlib/command/node/IntegerCommandNode.java | 22 +-- .../wlib/test/command/CommandTests.java | 4 +- .../wlib/test/command/SuggestionTests.java | 6 +- .../MethodCommandExtractorStructureTests.java | 10 +- .../method/MethodCommandExtractorTests.java | 40 ++-- .../CommandManagerSuggestionTests.java | 26 +-- 10 files changed, 357 insertions(+), 234 deletions(-) delete mode 100644 commands/src/main/java/com/wizardlybump17/wlib/command/input/AllowedNumberInputs.java create mode 100644 commands/src/main/java/com/wizardlybump17/wlib/command/input/SingleValueInput.java create mode 100644 commands/src/main/java/com/wizardlybump17/wlib/command/input/number/AllowedIntegerInputs.java create mode 100644 commands/src/main/java/com/wizardlybump17/wlib/command/input/number/AllowedNumberInputs.java diff --git a/commands/src/main/java/com/wizardlybump17/wlib/command/input/AllowedNumberInputs.java b/commands/src/main/java/com/wizardlybump17/wlib/command/input/AllowedNumberInputs.java deleted file mode 100644 index fc557477..00000000 --- a/commands/src/main/java/com/wizardlybump17/wlib/command/input/AllowedNumberInputs.java +++ /dev/null @@ -1,180 +0,0 @@ -package com.wizardlybump17.wlib.command.input; - -import com.wizardlybump17.wlib.command.sender.CommandSender; -import org.jetbrains.annotations.NotNull; -import org.jetbrains.annotations.Nullable; - -import java.util.List; -import java.util.stream.IntStream; - -public interface AllowedNumberInputs extends AllowedInputs { - - interface AllowedIntegerInputs extends AllowedInputs { - - record Range(@NotNull Integer from, @NotNull Integer to) implements AllowedIntegerInputs, RangedAllowedInputs { - - @Override - public boolean isInRange(@NotNull Integer number) { - return number.compareTo(from) >= 0 && number.compareTo(to) <= 0; - } - - @Override - public boolean isAllowed(@Nullable Integer input) { - if (input == null) - return false; - return isInRange(input); - } - - @Override - public @NotNull List getSuggestions(@NotNull CommandSender sender, @NotNull List input, @NotNull String current) { - if (to - from < 5) - return IntStream.rangeClosed(from, to).boxed().toList(); - - int fourth = (to - from) / 4; - return List.of(from, from + fourth, from + fourth * 2, from + fourth * 3, to); - } - } - - record Unlimited() implements AllowedIntegerInputs { - - @Override - public boolean isAllowed(@Nullable Integer input) { - return true; - } - - @Override - public @NotNull List getSuggestions(@NotNull CommandSender sender, @NotNull List input, @NotNull String current) { - return List.of( - -100000, - -50000, - -3000, - -200, - -50, - 0, - 50, - 200, - 3000, - 50000, - 100000 - ); - } - } - - record SingleValue(int value) implements AllowedIntegerInputs { - - @Override - public boolean isAllowed(@Nullable Integer input) { - return input != null && input.compareTo(value) == 0; - } - - @Override - public @NotNull List getSuggestions(@NotNull CommandSender sender, @NotNull List input, @NotNull String current) { - return List.of(value); - } - } - - record ValuesList(@NotNull List values) implements AllowedIntegerInputs { - - @Override - public boolean isAllowed(@Nullable Integer input) { - if (input == null) - return false; - - for (Integer value : values) - if (input.compareTo(value) == 0) - return true; - - return false; - } - - @Override - public @NotNull List getSuggestions(@NotNull CommandSender sender, @NotNull List input, @NotNull String current) { - if (values.size() < 5) - return values; - - int fourth = values.size() / 4; - return List.of( - values.get(0), - values.get(fourth), - values.get(fourth * 2), - values.get(fourth * 3), - values.get(values.size() - 1) - ); - } - } - - record Positive() implements AllowedIntegerInputs, RangedAllowedInputs { - - @Override - public @NotNull Integer from() { - return 0; - } - - @Override - public @NotNull Integer to() { - return Integer.MAX_VALUE; - } - - @Override - public boolean isInRange(@NotNull Integer input) { - return input > 0; - } - - @Override - public boolean isAllowed(@Nullable Integer input) { - if (input == null) - return false; - return isInRange(input); - } - - @Override - public @NotNull List getSuggestions(@NotNull CommandSender sender, @NotNull List input, @NotNull String current) { - return List.of( - 0, - 50, - 200, - 3000, - 50000, - 100000 - ); - } - } - - record Negative() implements AllowedIntegerInputs, RangedAllowedInputs { - - @Override - public @NotNull Integer from() { - return Integer.MIN_VALUE; - } - - @Override - public @NotNull Integer to() { - return -1; - } - - @Override - public boolean isInRange(@NotNull Integer input) { - return input < 0; - } - - @Override - public boolean isAllowed(@Nullable Integer input) { - if (input == null) - return false; - return isInRange(input); - } - - @Override - public @NotNull List getSuggestions(@NotNull CommandSender sender, @NotNull List input, @NotNull String current) { - return List.of( - -100000, - -50000, - -3000, - -200, - -50, - -1 - ); - } - } - } -} diff --git a/commands/src/main/java/com/wizardlybump17/wlib/command/input/SingleValueInput.java b/commands/src/main/java/com/wizardlybump17/wlib/command/input/SingleValueInput.java new file mode 100644 index 00000000..4a4b87e7 --- /dev/null +++ b/commands/src/main/java/com/wizardlybump17/wlib/command/input/SingleValueInput.java @@ -0,0 +1,22 @@ +package com.wizardlybump17.wlib.command.input; + +import com.wizardlybump17.wlib.command.sender.CommandSender; +import org.jetbrains.annotations.NotNull; +import org.jetbrains.annotations.Nullable; + +import java.util.List; + +public interface SingleValueInput extends AllowedInputs { + + @NotNull T value(); + + @Override + default boolean isAllowed(@Nullable T input) { + return value().equals(input); + } + + @Override + default @NotNull List getSuggestions(@NotNull CommandSender sender, @NotNull List input, @NotNull String current) { + return List.of(value()); + } +} diff --git a/commands/src/main/java/com/wizardlybump17/wlib/command/input/number/AllowedIntegerInputs.java b/commands/src/main/java/com/wizardlybump17/wlib/command/input/number/AllowedIntegerInputs.java new file mode 100644 index 00000000..05b72790 --- /dev/null +++ b/commands/src/main/java/com/wizardlybump17/wlib/command/input/number/AllowedIntegerInputs.java @@ -0,0 +1,164 @@ +package com.wizardlybump17.wlib.command.input.number; + +import com.wizardlybump17.wlib.command.sender.CommandSender; +import org.jetbrains.annotations.NotNull; + +import java.util.List; +import java.util.stream.IntStream; + +public interface AllowedIntegerInputs extends AllowedNumberInputs { + + static @NotNull Range range(int from, int to) { + return new Range(from, to); + } + + static @NotNull Unlimited unlimited() { + return Unlimited.INSTANCE; + } + + static @NotNull Positive positive() { + return Positive.INSTANCE; + } + + static @NotNull Negative negative() { + return Negative.INSTANCE; + } + + static @NotNull Values values(@NotNull List values) { + return new Values(values); + } + + static @NotNull Value value(int value) { + return new Value(value); + } + + final class Range extends AllowedNumberInputs.Ranged implements AllowedIntegerInputs { + + Range(@NotNull Integer from, @NotNull Integer to) { + super(from, to); + if (from >= to) + throw new IllegalArgumentException("from must be less than to"); + } + + @Override + public @NotNull List getSuggestions(@NotNull CommandSender sender, @NotNull List input, @NotNull String current) { + Integer to = to(); + Integer from = from(); + + if (to - from < 5) + return IntStream.rangeClosed(from, to).boxed().toList(); + + int fourth = (to - from) / 4; + return List.of(from, from + fourth, from + fourth * 2, from + fourth * 3, to); + } + } + + final class Unlimited implements AllowedNumberInputs.Unlimited, AllowedIntegerInputs{ + + static final @NotNull AllowedIntegerInputs.Unlimited INSTANCE = new AllowedIntegerInputs.Unlimited(); + + private Unlimited() { + } + + @Override + public @NotNull List getSuggestions(@NotNull CommandSender sender, @NotNull List input, @NotNull String current) { + return List.of( + -100000, + -50000, + -3000, + -200, + -50, + 0, + 50, + 200, + 3000, + 50000, + 100000 + ); + } + } + + final class Positive implements AllowedNumberInputs.Positive, AllowedIntegerInputs { + + static final @NotNull AllowedIntegerInputs.Positive INSTANCE = new AllowedIntegerInputs.Positive(); + + private Positive() { + } + + @Override + public @NotNull Integer from() { + return 0; + } + + @Override + public @NotNull Integer to() { + return Integer.MAX_VALUE; + } + + @Override + public boolean isInRange(@NotNull Integer input) { + return input > -1; + } + + @Override + public @NotNull List getSuggestions(@NotNull CommandSender sender, @NotNull List input, @NotNull String current) { + return List.of( + 0, + 50, + 200, + 3000, + 50000, + 100000 + ); + } + } + + final class Negative implements AllowedNumberInputs.Negative, AllowedIntegerInputs { + + static final @NotNull AllowedIntegerInputs.Negative INSTANCE = new AllowedIntegerInputs.Negative(); + + private Negative() { + } + + @Override + public @NotNull Integer from() { + return -1; + } + + @Override + public @NotNull Integer to() { + return Integer.MIN_VALUE; + } + + @Override + public boolean isInRange(@NotNull Integer input) { + return input < 0; + } + + @Override + public @NotNull List getSuggestions(@NotNull CommandSender sender, @NotNull List input, @NotNull String current) { + return List.of( + -100000, + -50000, + -3000, + -200, + -50, + -1 + ); + } + } + + final class Value extends AllowedNumberInputs.Value implements AllowedIntegerInputs { + + Value(@NotNull Integer value) { + super(value); + } + } + + final class Values extends AllowedNumberInputs.Values implements AllowedIntegerInputs { + + Values(@NotNull List values) { + super(values); + } + } +} diff --git a/commands/src/main/java/com/wizardlybump17/wlib/command/input/number/AllowedNumberInputs.java b/commands/src/main/java/com/wizardlybump17/wlib/command/input/number/AllowedNumberInputs.java new file mode 100644 index 00000000..87d46226 --- /dev/null +++ b/commands/src/main/java/com/wizardlybump17/wlib/command/input/number/AllowedNumberInputs.java @@ -0,0 +1,117 @@ +package com.wizardlybump17.wlib.command.input.number; + +import com.wizardlybump17.wlib.command.input.AllowedInputs; +import com.wizardlybump17.wlib.command.input.RangedAllowedInputs; +import com.wizardlybump17.wlib.command.input.SingleValueInput; +import com.wizardlybump17.wlib.command.sender.CommandSender; +import org.jetbrains.annotations.NotNull; +import org.jetbrains.annotations.Nullable; + +import java.util.List; + +public interface AllowedNumberInputs extends AllowedInputs { + + static @NotNull Value value(@NotNull N value) { + return new Value<>(value); + } + + static @NotNull Values values(@NotNull List values) { + return new Values<>(values); + } + + abstract class Ranged> implements AllowedNumberInputs, RangedAllowedInputs { + + private final @NotNull N from; + private final @NotNull N to; + + public Ranged(@NotNull N from, @NotNull N to) { + this.from = from; + this.to = to; + } + + @Override + public @NotNull N from() { + return from; + } + + @Override + public @NotNull N to() { + return to; + } + + @Override + public boolean isInRange(@NotNull N number) { + return number.compareTo(from) >= 0 && number.compareTo(to) <= 0; + } + + @Override + public boolean isAllowed(@Nullable N input) { + if (input == null) + return false; + return isInRange(input); + } + } + + interface Unlimited extends AllowedNumberInputs { + + @Override + default boolean isAllowed(@Nullable N input) { + return true; + } + } + + class Value implements AllowedNumberInputs, SingleValueInput { + + private final @NotNull N value; + + Value(@NotNull N value) { + this.value = value; + } + + @Override + public @NotNull N value() { + return value; + } + } + + class Values implements AllowedNumberInputs { + + private final @NotNull List values; + + Values(@NotNull List values) { + this.values = List.copyOf(values); + } + + @Override + public boolean isAllowed(@Nullable N input) { + if (input == null) + return false; + return values.contains(input); + } + + @Override + public @NotNull List getSuggestions(@NotNull CommandSender sender, @NotNull List input, @NotNull String current) { + return values; + } + } + + interface Positive extends AllowedNumberInputs, RangedAllowedInputs { + + @Override + default boolean isAllowed(@Nullable N input) { + if (input == null) + return false; + return isInRange(input); + } + } + + interface Negative extends AllowedNumberInputs, RangedAllowedInputs { + + @Override + default boolean isAllowed(@Nullable N input) { + if (input == null) + return false; + return isInRange(input); + } + } +} diff --git a/commands/src/main/java/com/wizardlybump17/wlib/command/node/IntegerCommandNode.java b/commands/src/main/java/com/wizardlybump17/wlib/command/node/IntegerCommandNode.java index 7fc45bba..77e56713 100644 --- a/commands/src/main/java/com/wizardlybump17/wlib/command/node/IntegerCommandNode.java +++ b/commands/src/main/java/com/wizardlybump17/wlib/command/node/IntegerCommandNode.java @@ -2,7 +2,7 @@ import com.wizardlybump17.wlib.command.exception.InputParsingException; import com.wizardlybump17.wlib.command.executor.CommandNodeExecutor; -import com.wizardlybump17.wlib.command.input.AllowedNumberInputs; +import com.wizardlybump17.wlib.command.input.number.AllowedNumberInputs; import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.Nullable; @@ -10,41 +10,41 @@ public class IntegerCommandNode extends CommandNode { - public IntegerCommandNode(@NotNull String name, @NotNull List> children, @NotNull AllowedNumberInputs.AllowedIntegerInputs allowedInputs, @Nullable CommandNodeExecutor executor, @Nullable String permission) { + public IntegerCommandNode(@NotNull String name, @NotNull List> children, @NotNull AllowedNumberInputs allowedInputs, @Nullable CommandNodeExecutor executor, @Nullable String permission) { super(name, children, allowedInputs, executor, permission); } - public IntegerCommandNode(@NotNull String name, @NotNull AllowedNumberInputs.AllowedIntegerInputs allowedInputs, @Nullable CommandNodeExecutor executor, @Nullable String permission) { + public IntegerCommandNode(@NotNull String name, @NotNull AllowedNumberInputs allowedInputs, @Nullable CommandNodeExecutor executor, @Nullable String permission) { this(name, List.of(), allowedInputs, executor, permission); } - public IntegerCommandNode(@NotNull String name, @NotNull List> children, @NotNull AllowedNumberInputs.AllowedIntegerInputs allowedInputs, @Nullable String permission) { + public IntegerCommandNode(@NotNull String name, @NotNull List> children, @NotNull AllowedNumberInputs allowedInputs, @Nullable String permission) { this(name, children, allowedInputs, null, permission); } - public IntegerCommandNode(@NotNull String name, @NotNull AllowedNumberInputs.AllowedIntegerInputs allowedInputs, @Nullable String permission) { + public IntegerCommandNode(@NotNull String name, @NotNull AllowedNumberInputs allowedInputs, @Nullable String permission) { this(name, List.of(), allowedInputs, null, permission); } - public IntegerCommandNode(@NotNull String name, @NotNull List> children, @NotNull AllowedNumberInputs.AllowedIntegerInputs allowedInputs, @Nullable CommandNodeExecutor executor) { + public IntegerCommandNode(@NotNull String name, @NotNull List> children, @NotNull AllowedNumberInputs allowedInputs, @Nullable CommandNodeExecutor executor) { super(name, children, allowedInputs, executor, null); } - public IntegerCommandNode(@NotNull String name, @NotNull AllowedNumberInputs.AllowedIntegerInputs allowedInputs, @Nullable CommandNodeExecutor executor) { + public IntegerCommandNode(@NotNull String name, @NotNull AllowedNumberInputs allowedInputs, @Nullable CommandNodeExecutor executor) { this(name, List.of(), allowedInputs, executor, null); } - public IntegerCommandNode(@NotNull String name, @NotNull List> children, @NotNull AllowedNumberInputs.AllowedIntegerInputs allowedInputs) { + public IntegerCommandNode(@NotNull String name, @NotNull List> children, @NotNull AllowedNumberInputs allowedInputs) { this(name, children, allowedInputs, null, null); } - public IntegerCommandNode(@NotNull String name, @NotNull AllowedNumberInputs.AllowedIntegerInputs allowedInputs) { + public IntegerCommandNode(@NotNull String name, @NotNull AllowedNumberInputs allowedInputs) { this(name, List.of(), allowedInputs, null, null); } @Override - public @NotNull AllowedNumberInputs.AllowedIntegerInputs getAllowedInputs() { - return (AllowedNumberInputs.AllowedIntegerInputs) super.getAllowedInputs(); + public @NotNull AllowedNumberInputs getAllowedInputs() { + return (AllowedNumberInputs) super.getAllowedInputs(); } @Override diff --git a/commands/src/test/java/com/wizardlybump17/wlib/test/command/CommandTests.java b/commands/src/test/java/com/wizardlybump17/wlib/test/command/CommandTests.java index 5ab0bbd1..06c22ad5 100644 --- a/commands/src/test/java/com/wizardlybump17/wlib/test/command/CommandTests.java +++ b/commands/src/test/java/com/wizardlybump17/wlib/test/command/CommandTests.java @@ -2,7 +2,7 @@ import com.wizardlybump17.wlib.command.Command; import com.wizardlybump17.wlib.command.exception.InputParsingException; -import com.wizardlybump17.wlib.command.input.AllowedNumberInputs; +import com.wizardlybump17.wlib.command.input.number.AllowedNumberInputs; import com.wizardlybump17.wlib.command.node.IntegerCommandNode; import com.wizardlybump17.wlib.command.node.LiteralCommandNode; import com.wizardlybump17.wlib.command.result.CommandResult; @@ -185,7 +185,7 @@ void testOutOfRange() { @Test void testParseInputException() { - IntegerCommandNode worldNode = new IntegerCommandNode("world", new AllowedNumberInputs.AllowedIntegerInputs.SingleValue(10), context -> CommandResult.successful(context, 10)); + IntegerCommandNode worldNode = new IntegerCommandNode("world", AllowedNumberInputs.value(10), context -> CommandResult.successful(context, 10)); Command command = new Command(new LiteralCommandNode("hello", List.of(worldNode))); ParseInputExceptionResult expected = CommandResult.parseInputException(1, worldNode, new InputParsingException("Could not parse as int: world", new NumberFormatException("For input string: \"world\""))); diff --git a/commands/src/test/java/com/wizardlybump17/wlib/test/command/SuggestionTests.java b/commands/src/test/java/com/wizardlybump17/wlib/test/command/SuggestionTests.java index 85613164..8dfeb089 100644 --- a/commands/src/test/java/com/wizardlybump17/wlib/test/command/SuggestionTests.java +++ b/commands/src/test/java/com/wizardlybump17/wlib/test/command/SuggestionTests.java @@ -1,7 +1,7 @@ package com.wizardlybump17.wlib.test.command; import com.wizardlybump17.wlib.command.Command; -import com.wizardlybump17.wlib.command.input.AllowedNumberInputs; +import com.wizardlybump17.wlib.command.input.number.AllowedIntegerInputs; import com.wizardlybump17.wlib.command.node.IntegerCommandNode; import com.wizardlybump17.wlib.command.node.LiteralCommandNode; import com.wizardlybump17.wlib.command.result.CommandResult; @@ -110,7 +110,7 @@ void testSuccess3() { ), new IntegerCommandNode( "there", - new AllowedNumberInputs.AllowedIntegerInputs.Range(1, 10), + AllowedIntegerInputs.range(1, 10), context -> CommandResult.successful(context, "hello there") ) ) @@ -140,7 +140,7 @@ void testSuccess4() { ), new IntegerCommandNode( "there", - new AllowedNumberInputs.AllowedIntegerInputs.Range(1, 10), + AllowedIntegerInputs.range(1, 10), context -> CommandResult.successful(context, "hello there") ), new LiteralCommandNode( diff --git a/commands/src/test/java/com/wizardlybump17/wlib/test/command/extractor/method/MethodCommandExtractorStructureTests.java b/commands/src/test/java/com/wizardlybump17/wlib/test/command/extractor/method/MethodCommandExtractorStructureTests.java index 079a4047..c007e014 100644 --- a/commands/src/test/java/com/wizardlybump17/wlib/test/command/extractor/method/MethodCommandExtractorStructureTests.java +++ b/commands/src/test/java/com/wizardlybump17/wlib/test/command/extractor/method/MethodCommandExtractorStructureTests.java @@ -3,7 +3,7 @@ import com.wizardlybump17.wlib.command.Command; import com.wizardlybump17.wlib.command.extractor.CommandExtractor; import com.wizardlybump17.wlib.command.extractor.method.factory.MethodCommandNodeFactory; -import com.wizardlybump17.wlib.command.input.AllowedNumberInputs; +import com.wizardlybump17.wlib.command.input.number.AllowedIntegerInputs; import com.wizardlybump17.wlib.command.input.string.AllowedStringInputs; import com.wizardlybump17.wlib.command.node.CommandNode; import com.wizardlybump17.wlib.command.node.IntegerCommandNode; @@ -32,7 +32,7 @@ static void setup() { new MethodCommandNodeFactory() { @Override public @NotNull IntegerCommandNode create(@NotNull Object object, @NotNull Method method, com.wizardlybump17.wlib.command.annotation.@NotNull Command commandAnnotation, @NotNull Parameter parameter, @NotNull String name, @Nullable CommandNode root) { - return new IntegerCommandNode(name, root == null ? List.of() : List.of(root), new AllowedNumberInputs.AllowedIntegerInputs.Unlimited()); + return new IntegerCommandNode(name, root == null ? List.of() : List.of(root), AllowedIntegerInputs.unlimited()); } } ); @@ -115,7 +115,7 @@ void test1() { "123" ) ), - new AllowedNumberInputs.AllowedIntegerInputs.Unlimited() + AllowedIntegerInputs.unlimited() ) ) ) @@ -139,10 +139,10 @@ void test1() { ) ) ), - new AllowedNumberInputs.AllowedIntegerInputs.Unlimited() + AllowedIntegerInputs.unlimited() ) ), - new AllowedNumberInputs.AllowedIntegerInputs.Unlimited() + AllowedIntegerInputs.unlimited() ) ) ) diff --git a/commands/src/test/java/com/wizardlybump17/wlib/test/command/extractor/method/MethodCommandExtractorTests.java b/commands/src/test/java/com/wizardlybump17/wlib/test/command/extractor/method/MethodCommandExtractorTests.java index 7fb31346..05e1a8cc 100644 --- a/commands/src/test/java/com/wizardlybump17/wlib/test/command/extractor/method/MethodCommandExtractorTests.java +++ b/commands/src/test/java/com/wizardlybump17/wlib/test/command/extractor/method/MethodCommandExtractorTests.java @@ -5,7 +5,7 @@ import com.wizardlybump17.wlib.command.extractor.CommandExtractor; import com.wizardlybump17.wlib.command.extractor.method.MethodCommandExtractor; import com.wizardlybump17.wlib.command.extractor.method.factory.MethodCommandNodeFactory; -import com.wizardlybump17.wlib.command.input.AllowedNumberInputs; +import com.wizardlybump17.wlib.command.input.number.AllowedIntegerInputs; import com.wizardlybump17.wlib.command.input.string.AllowedStringInputs; import com.wizardlybump17.wlib.command.manager.CommandManager; import com.wizardlybump17.wlib.command.node.CommandNode; @@ -39,7 +39,7 @@ static void setup() { new MethodCommandNodeFactory() { @Override public @NotNull IntegerCommandNode create(@NotNull Object object, @NotNull Method method, com.wizardlybump17.wlib.command.annotation.@NotNull Command commandAnnotation, @NotNull Parameter parameter, @NotNull String name, @Nullable CommandNode root) { - return new IntegerCommandNode(name, root == null ? List.of() : List.of(root), new AllowedNumberInputs.AllowedIntegerInputs.Unlimited()); + return new IntegerCommandNode(name, root == null ? List.of() : List.of(root), AllowedIntegerInputs.unlimited()); } } ); @@ -469,7 +469,7 @@ void testCommandSenderParameters() { List.of( new IntegerCommandNode( "int", - new AllowedNumberInputs.AllowedIntegerInputs.Unlimited(), + AllowedIntegerInputs.unlimited(), Assertions.assertDoesNotThrow(() -> MethodCommandExtractor.createExecutor(object, "hello", CommandSender.class, int.class)) ) ) @@ -484,7 +484,7 @@ void testCommandSenderParameters() { List.of( new IntegerCommandNode( "int", - new AllowedNumberInputs.AllowedIntegerInputs.Unlimited(), + AllowedIntegerInputs.unlimited(), Assertions.assertDoesNotThrow(() -> MethodCommandExtractor.createExecutor(object, "helloWorld", CommandSender.class, int.class)) ) ) @@ -504,7 +504,7 @@ void testCommandSenderParameters() { List.of( new IntegerCommandNode( "int", - new AllowedNumberInputs.AllowedIntegerInputs.Unlimited(), + AllowedIntegerInputs.unlimited(), Assertions.assertDoesNotThrow(() -> MethodCommandExtractor.createExecutor(object, "helloThereHi", CommandSender.class, int.class)) ) ) @@ -549,7 +549,7 @@ void testCommandContextParameters() { List.of( new IntegerCommandNode( "int", - new AllowedNumberInputs.AllowedIntegerInputs.Unlimited(), + AllowedIntegerInputs.unlimited(), Assertions.assertDoesNotThrow(() -> MethodCommandExtractor.createExecutor(object, "hello", CommandContext.class, int.class)) ) ) @@ -564,7 +564,7 @@ void testCommandContextParameters() { List.of( new IntegerCommandNode( "int", - new AllowedNumberInputs.AllowedIntegerInputs.Unlimited(), + AllowedIntegerInputs.unlimited(), Assertions.assertDoesNotThrow(() -> MethodCommandExtractor.createExecutor(object, "helloWorld", CommandContext.class, int.class)) ) ) @@ -584,7 +584,7 @@ void testCommandContextParameters() { List.of( new IntegerCommandNode( "int", - new AllowedNumberInputs.AllowedIntegerInputs.Unlimited(), + AllowedIntegerInputs.unlimited(), Assertions.assertDoesNotThrow(() -> MethodCommandExtractor.createExecutor(object, "helloThereHi", CommandContext.class, int.class)) ) ) @@ -633,7 +633,7 @@ void testCommandSenderParametersCommandResult() { List.of( new IntegerCommandNode( "int", - new AllowedNumberInputs.AllowedIntegerInputs.Unlimited(), + AllowedIntegerInputs.unlimited(), Assertions.assertDoesNotThrow(() -> MethodCommandExtractor.createExecutor(object, "hello", CommandSender.class, int.class)) ) ) @@ -648,7 +648,7 @@ void testCommandSenderParametersCommandResult() { List.of( new IntegerCommandNode( "int", - new AllowedNumberInputs.AllowedIntegerInputs.Unlimited(), + AllowedIntegerInputs.unlimited(), Assertions.assertDoesNotThrow(() -> MethodCommandExtractor.createExecutor(object, "helloWorld", CommandSender.class, int.class)) ) ) @@ -668,7 +668,7 @@ void testCommandSenderParametersCommandResult() { List.of( new IntegerCommandNode( "int", - new AllowedNumberInputs.AllowedIntegerInputs.Unlimited(), + AllowedIntegerInputs.unlimited(), Assertions.assertDoesNotThrow(() -> MethodCommandExtractor.createExecutor(object, "helloThereHi", CommandSender.class, int.class)) ) ) @@ -716,7 +716,7 @@ void testCommandContextParametersCommandResult() { List.of( new IntegerCommandNode( "int", - new AllowedNumberInputs.AllowedIntegerInputs.Unlimited(), + AllowedIntegerInputs.unlimited(), Assertions.assertDoesNotThrow(() -> MethodCommandExtractor.createExecutor(object, "hello", CommandContext.class, int.class)) ) ) @@ -731,7 +731,7 @@ void testCommandContextParametersCommandResult() { List.of( new IntegerCommandNode( "int", - new AllowedNumberInputs.AllowedIntegerInputs.Unlimited(), + AllowedIntegerInputs.unlimited(), Assertions.assertDoesNotThrow(() -> MethodCommandExtractor.createExecutor(object, "helloWorld", CommandContext.class, int.class)) ) ) @@ -751,7 +751,7 @@ void testCommandContextParametersCommandResult() { List.of( new IntegerCommandNode( "int", - new AllowedNumberInputs.AllowedIntegerInputs.Unlimited(), + AllowedIntegerInputs.unlimited(), Assertions.assertDoesNotThrow(() -> MethodCommandExtractor.createExecutor(object, "helloThereHi", CommandContext.class, int.class)) ) ) @@ -803,7 +803,7 @@ void testParametersPure() { List.of( new IntegerCommandNode( "int", - new AllowedNumberInputs.AllowedIntegerInputs.Unlimited(), + AllowedIntegerInputs.unlimited(), Assertions.assertDoesNotThrow(() -> MethodCommandExtractor.createExecutor(object, "hello", int.class)) ) ) @@ -818,7 +818,7 @@ void testParametersPure() { List.of( new IntegerCommandNode( "int", - new AllowedNumberInputs.AllowedIntegerInputs.Unlimited(), + AllowedIntegerInputs.unlimited(), Assertions.assertDoesNotThrow(() -> MethodCommandExtractor.createExecutor(object, "helloWorld", int.class)) ) ) @@ -838,7 +838,7 @@ void testParametersPure() { List.of( new IntegerCommandNode( "int", - new AllowedNumberInputs.AllowedIntegerInputs.Unlimited(), + AllowedIntegerInputs.unlimited(), Assertions.assertDoesNotThrow(() -> MethodCommandExtractor.createExecutor(object, "helloThereHi", int.class)) ) ) @@ -887,7 +887,7 @@ void testParametersPureCommandResult() { List.of( new IntegerCommandNode( "int", - new AllowedNumberInputs.AllowedIntegerInputs.Unlimited(), + AllowedIntegerInputs.unlimited(), Assertions.assertDoesNotThrow(() -> MethodCommandExtractor.createExecutor(object, "hello", int.class)) ) ) @@ -902,7 +902,7 @@ void testParametersPureCommandResult() { List.of( new IntegerCommandNode( "int", - new AllowedNumberInputs.AllowedIntegerInputs.Unlimited(), + AllowedIntegerInputs.unlimited(), Assertions.assertDoesNotThrow(() -> MethodCommandExtractor.createExecutor(object, "helloWorld", int.class)) ) ) @@ -922,7 +922,7 @@ void testParametersPureCommandResult() { List.of( new IntegerCommandNode( "int", - new AllowedNumberInputs.AllowedIntegerInputs.Unlimited(), + AllowedIntegerInputs.unlimited(), Assertions.assertDoesNotThrow(() -> MethodCommandExtractor.createExecutor(object, "helloThereHi", int.class)) ) ) diff --git a/commands/src/test/java/com/wizardlybump17/wlib/test/command/manager/CommandManagerSuggestionTests.java b/commands/src/test/java/com/wizardlybump17/wlib/test/command/manager/CommandManagerSuggestionTests.java index 16ca8ce0..80f21a51 100644 --- a/commands/src/test/java/com/wizardlybump17/wlib/test/command/manager/CommandManagerSuggestionTests.java +++ b/commands/src/test/java/com/wizardlybump17/wlib/test/command/manager/CommandManagerSuggestionTests.java @@ -1,7 +1,7 @@ package com.wizardlybump17.wlib.test.command.manager; import com.wizardlybump17.wlib.command.Command; -import com.wizardlybump17.wlib.command.input.AllowedNumberInputs; +import com.wizardlybump17.wlib.command.input.number.AllowedIntegerInputs; import com.wizardlybump17.wlib.command.manager.CommandManager; import com.wizardlybump17.wlib.command.node.IntegerCommandNode; import com.wizardlybump17.wlib.command.node.LiteralCommandNode; @@ -205,7 +205,7 @@ void testSuggestionsSuccessListChad4() { List.of( new IntegerCommandNode( "repeat", - new AllowedNumberInputs.AllowedIntegerInputs.Positive(), + AllowedIntegerInputs.positive(), context -> CommandResult.successful(context, "welcome".repeat(context.arguments().getArgument("repeat").orElseThrow().data())), "permission" ) @@ -252,7 +252,7 @@ void testSuggestionsSuccessListChad6() { List.of( new IntegerCommandNode( "repeat", - new AllowedNumberInputs.AllowedIntegerInputs.Positive(), + AllowedIntegerInputs.positive(), context -> CommandResult.successful(context, "welcome".repeat(context.arguments().getArgument("repeat").orElseThrow().data())), "permission" ) @@ -338,7 +338,7 @@ void testSuggestionsSuccessStringChad0() { List.of( new IntegerCommandNode( "repeat", - new AllowedNumberInputs.AllowedIntegerInputs.Positive(), + AllowedIntegerInputs.positive(), context -> CommandResult.successful(context, "welcome".repeat(context.arguments().getArgument("repeat").orElseThrow().data())), "permission" ) @@ -385,7 +385,7 @@ void testSuggestionsSuccessStringChad1() { List.of( new IntegerCommandNode( "repeat", - new AllowedNumberInputs.AllowedIntegerInputs.Positive(), + AllowedIntegerInputs.positive(), context -> CommandResult.successful(context, "welcome".repeat(context.arguments().getArgument("repeat").orElseThrow().data())), "permission" ) @@ -432,7 +432,7 @@ void testSuggestionsSuccessStringChad2() { List.of( new IntegerCommandNode( "repeat", - new AllowedNumberInputs.AllowedIntegerInputs.Positive(), + AllowedIntegerInputs.positive(), context -> CommandResult.successful(context, "welcome".repeat(context.arguments().getArgument("repeat").orElseThrow().data())), "permission" ) @@ -479,7 +479,7 @@ void testSuggestionsSuccessStringChad3() { List.of( new IntegerCommandNode( "repeat", - new AllowedNumberInputs.AllowedIntegerInputs.Positive(), + AllowedIntegerInputs.positive(), context -> CommandResult.successful(context, "welcome".repeat(context.arguments().getArgument("repeat").orElseThrow().data())), "permission" ) @@ -540,7 +540,7 @@ void testSuggestionsSuccessStringArrayChad0() { List.of( new IntegerCommandNode( "repeat", - new AllowedNumberInputs.AllowedIntegerInputs.Positive(), + AllowedIntegerInputs.positive(), context -> CommandResult.successful(context, "welcome".repeat(context.arguments().getArgument("repeat").orElseThrow().data())), "permission" ) @@ -601,7 +601,7 @@ void testSuggestionsSuccessStringArrayChad1() { List.of( new IntegerCommandNode( "repeat", - new AllowedNumberInputs.AllowedIntegerInputs.Positive(), + AllowedIntegerInputs.positive(), context -> CommandResult.successful(context, "welcome".repeat(context.arguments().getArgument("repeat").orElseThrow().data())), "permission" ) @@ -662,7 +662,7 @@ void testSuggestionsSuccessStringArrayChad2() { List.of( new IntegerCommandNode( "repeat", - new AllowedNumberInputs.AllowedIntegerInputs.Positive(), + AllowedIntegerInputs.positive(), context -> CommandResult.successful(context, "welcome".repeat(context.arguments().getArgument("repeat").orElseThrow().data())), "permission" ) @@ -723,7 +723,7 @@ void testSuggestionsSuccessStringArrayChad3() { List.of( new IntegerCommandNode( "repeat", - new AllowedNumberInputs.AllowedIntegerInputs.Positive(), + AllowedIntegerInputs.positive(), context -> CommandResult.successful(context, "welcome".repeat(context.arguments().getArgument("repeat").orElseThrow().data())), "permission" ) @@ -784,7 +784,7 @@ void testSuggestionsSuccessStringArrayChad4() { List.of( new IntegerCommandNode( "repeat", - new AllowedNumberInputs.AllowedIntegerInputs.Positive(), + AllowedIntegerInputs.positive(), context -> CommandResult.successful(context, "welcome".repeat(context.arguments().getArgument("repeat").orElseThrow().data())), "permission" ) @@ -845,7 +845,7 @@ void testSuggestionsSuccessStringArrayChad5() { List.of( new IntegerCommandNode( "repeat", - new AllowedNumberInputs.AllowedIntegerInputs.Positive(), + AllowedIntegerInputs.positive(), context -> CommandResult.successful(context, "welcome".repeat(context.arguments().getArgument("repeat").orElseThrow().data())), "permission" ) From 8247df0dc1f2778d4bda83f3e965044be77aea38 Mon Sep 17 00:00:00 2001 From: WizardlyBump17 Date: Mon, 24 Nov 2025 18:26:42 -0300 Subject: [PATCH 151/363] improved the String input --- .../command/input/LiteralAllowedInput.java | 16 ------ .../input/string/AllowedStringInputs.java | 57 +++++++++++++++++++ .../wlib/command/node/LiteralCommandNode.java | 10 ++-- 3 files changed, 62 insertions(+), 21 deletions(-) delete mode 100644 commands/src/main/java/com/wizardlybump17/wlib/command/input/LiteralAllowedInput.java diff --git a/commands/src/main/java/com/wizardlybump17/wlib/command/input/LiteralAllowedInput.java b/commands/src/main/java/com/wizardlybump17/wlib/command/input/LiteralAllowedInput.java deleted file mode 100644 index 3a7bd726..00000000 --- a/commands/src/main/java/com/wizardlybump17/wlib/command/input/LiteralAllowedInput.java +++ /dev/null @@ -1,16 +0,0 @@ -package com.wizardlybump17.wlib.command.input; - -import org.jetbrains.annotations.NotNull; -import org.jetbrains.annotations.Nullable; - -public record LiteralAllowedInput(@NotNull String value, boolean caseSensitive) implements AllowedInputs { - - @Override - public boolean isAllowed(@Nullable String input) { - if (input == null) - return false; - if (caseSensitive) - return input.equals(value); - return input.equalsIgnoreCase(value); - } -} diff --git a/commands/src/main/java/com/wizardlybump17/wlib/command/input/string/AllowedStringInputs.java b/commands/src/main/java/com/wizardlybump17/wlib/command/input/string/AllowedStringInputs.java index 1845aba5..4d2ad704 100644 --- a/commands/src/main/java/com/wizardlybump17/wlib/command/input/string/AllowedStringInputs.java +++ b/commands/src/main/java/com/wizardlybump17/wlib/command/input/string/AllowedStringInputs.java @@ -20,6 +20,14 @@ public interface AllowedStringInputs extends AllowedInputs { return new Values(values, false); } + static @NotNull Value valueIgnoreCase(@NotNull String value) { + return new Value(value, true); + } + + static @NotNull Value value(@NotNull String value) { + return new Value(value, false); + } + static @NotNull Any anyNullable() { return Any.NULLABLE; } @@ -84,6 +92,55 @@ public String toString() { } } + final class Value implements AllowedStringInputs { + + private final @NotNull String value; + private final boolean ignoreCase; + + public Value(@NotNull String value, boolean ignoreCase) { + this.value = value; + this.ignoreCase = ignoreCase; + } + + public @NotNull String value() { + return value; + } + + public boolean ignoreCase() { + return ignoreCase; + } + + @Override + public boolean isAllowed(@Nullable String input) { + if (input == null) + return false; + if (ignoreCase) + return value.equalsIgnoreCase(input); + return value.equals(input); + } + + @Override + public boolean equals(Object object) { + if (object == null || getClass() != object.getClass()) + return false; + Value value1 = (Value) object; + return ignoreCase == value1.ignoreCase && Objects.equals(value, value1.value); + } + + @Override + public int hashCode() { + return Objects.hash(value, ignoreCase); + } + + @Override + public String toString() { + return "Value{" + + "value='" + value + '\'' + + ", ignoreCase=" + ignoreCase + + '}'; + } + } + final class Any implements AllowedStringInputs { private static final @NotNull Any NULLABLE = new Any(true); diff --git a/commands/src/main/java/com/wizardlybump17/wlib/command/node/LiteralCommandNode.java b/commands/src/main/java/com/wizardlybump17/wlib/command/node/LiteralCommandNode.java index 0d53e5dc..165511a9 100644 --- a/commands/src/main/java/com/wizardlybump17/wlib/command/node/LiteralCommandNode.java +++ b/commands/src/main/java/com/wizardlybump17/wlib/command/node/LiteralCommandNode.java @@ -1,7 +1,7 @@ package com.wizardlybump17.wlib.command.node; import com.wizardlybump17.wlib.command.executor.CommandNodeExecutor; -import com.wizardlybump17.wlib.command.input.LiteralAllowedInput; +import com.wizardlybump17.wlib.command.input.string.AllowedStringInputs; import com.wizardlybump17.wlib.command.sender.CommandSender; import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.Nullable; @@ -11,7 +11,7 @@ public class LiteralCommandNode extends CommandNode { public LiteralCommandNode(@NotNull String name, @NotNull List> children, @Nullable CommandNodeExecutor executor, @Nullable String permission) { - super(name, children, new LiteralAllowedInput(name, false), executor, permission); + super(name, children, AllowedStringInputs.valueIgnoreCase(name), executor, permission); } public LiteralCommandNode(@NotNull String name, @Nullable CommandNodeExecutor executor, @Nullable String permission) { @@ -27,7 +27,7 @@ public LiteralCommandNode(@NotNull String name, @Nullable String permission) { } public LiteralCommandNode(@NotNull String name, @NotNull List> children, @Nullable CommandNodeExecutor executor) { - super(name, children, new LiteralAllowedInput(name, false), executor, null); + super(name, children, AllowedStringInputs.valueIgnoreCase(name), executor, null); } public LiteralCommandNode(@NotNull String name, @Nullable CommandNodeExecutor executor) { @@ -43,8 +43,8 @@ public LiteralCommandNode(@NotNull String name) { } @Override - public @NotNull LiteralAllowedInput getAllowedInputs() { - return (LiteralAllowedInput) super.getAllowedInputs(); + public @NotNull AllowedStringInputs.Value getAllowedInputs() { + return (AllowedStringInputs.Value) super.getAllowedInputs(); } @Override From 3fd757806afe6047f282babdff5eb1f1426ea3dd Mon Sep 17 00:00:00 2001 From: WizardlyBump17 Date: Mon, 24 Nov 2025 18:31:19 -0300 Subject: [PATCH 152/363] minor changes --- .../wlib/command/input/AllowedListInputs.java | 2 +- .../wlib/command/input/string/AllowedStringInputs.java | 9 +++++++-- 2 files changed, 8 insertions(+), 3 deletions(-) diff --git a/commands/src/main/java/com/wizardlybump17/wlib/command/input/AllowedListInputs.java b/commands/src/main/java/com/wizardlybump17/wlib/command/input/AllowedListInputs.java index 790c4763..86d1928a 100644 --- a/commands/src/main/java/com/wizardlybump17/wlib/command/input/AllowedListInputs.java +++ b/commands/src/main/java/com/wizardlybump17/wlib/command/input/AllowedListInputs.java @@ -6,5 +6,5 @@ public interface AllowedListInputs extends AllowedInputs { - @NotNull List getAllowedValues(); + @NotNull List allowedValues(); } diff --git a/commands/src/main/java/com/wizardlybump17/wlib/command/input/string/AllowedStringInputs.java b/commands/src/main/java/com/wizardlybump17/wlib/command/input/string/AllowedStringInputs.java index 4d2ad704..693e994e 100644 --- a/commands/src/main/java/com/wizardlybump17/wlib/command/input/string/AllowedStringInputs.java +++ b/commands/src/main/java/com/wizardlybump17/wlib/command/input/string/AllowedStringInputs.java @@ -52,7 +52,7 @@ private Values(@NotNull List values, boolean ignoreCase) { } @Override - public @NotNull @Unmodifiable List getAllowedValues() { + public @NotNull @Unmodifiable List allowedValues() { return values; } @@ -110,6 +110,11 @@ public boolean ignoreCase() { return ignoreCase; } + @Override + public @NotNull List getSuggestions(@NotNull CommandSender sender, @NotNull List input, @NotNull String current) { + return List.of(value); + } + @Override public boolean isAllowed(@Nullable String input) { if (input == null) @@ -157,7 +162,7 @@ public boolean isAllowed(@Nullable String input) { return nullable || input != null; } - public boolean isNullable() { + public boolean nullable() { return nullable; } From c47dbb7d9b9117492ba9be6f98b025e524da4c4a Mon Sep 17 00:00:00 2001 From: WizardlyBump17 Date: Mon, 24 Nov 2025 22:53:12 -0300 Subject: [PATCH 153/363] all primitive numbers --- .../input/number/AllowedByteInputs.java | 165 +++++++++++++++++ .../input/number/AllowedDoubleInputs.java | 173 ++++++++++++++++++ .../input/number/AllowedFloatInputs.java | 173 ++++++++++++++++++ .../input/number/AllowedIntegerInputs.java | 6 +- .../input/number/AllowedLongInputs.java | 173 ++++++++++++++++++ .../input/number/AllowedShortInputs.java | 169 +++++++++++++++++ 6 files changed, 856 insertions(+), 3 deletions(-) create mode 100644 commands/src/main/java/com/wizardlybump17/wlib/command/input/number/AllowedByteInputs.java create mode 100644 commands/src/main/java/com/wizardlybump17/wlib/command/input/number/AllowedDoubleInputs.java create mode 100644 commands/src/main/java/com/wizardlybump17/wlib/command/input/number/AllowedFloatInputs.java create mode 100644 commands/src/main/java/com/wizardlybump17/wlib/command/input/number/AllowedLongInputs.java create mode 100644 commands/src/main/java/com/wizardlybump17/wlib/command/input/number/AllowedShortInputs.java diff --git a/commands/src/main/java/com/wizardlybump17/wlib/command/input/number/AllowedByteInputs.java b/commands/src/main/java/com/wizardlybump17/wlib/command/input/number/AllowedByteInputs.java new file mode 100644 index 00000000..0ea350f4 --- /dev/null +++ b/commands/src/main/java/com/wizardlybump17/wlib/command/input/number/AllowedByteInputs.java @@ -0,0 +1,165 @@ +package com.wizardlybump17.wlib.command.input.number; + +import com.wizardlybump17.wlib.command.sender.CommandSender; +import org.jetbrains.annotations.NotNull; + +import java.util.List; + +public interface AllowedByteInputs extends AllowedNumberInputs { + + static @NotNull Range range(byte from, byte to) { + return new Range(from, to); + } + + static @NotNull Unlimited unlimited() { + return Unlimited.INSTANCE; + } + + static @NotNull Positive positive() { + return Positive.INSTANCE; + } + + static @NotNull Negative negative() { + return Negative.INSTANCE; + } + + static @NotNull Values values(@NotNull List values) { + return new Values(values); + } + + static @NotNull Value value(byte value) { + return new Value(value); + } + + final class Range extends Ranged implements AllowedByteInputs { + + Range(byte from, byte to) { + super(from, to); + if (from >= to) + throw new IllegalArgumentException("from must be less than to"); + } + + @Override + public @NotNull List getSuggestions(@NotNull CommandSender sender, @NotNull List input, @NotNull String current) { + byte to = to(); + byte from = from(); + + if (to - from < 5) { + Byte[] bytes = new Byte[to - from]; + for (int i = 0; i < bytes.length; i++) + bytes[i] = (byte) (to - from - i); + return List.of(bytes); + } + + byte fourth = (byte) ((to - from) / 4); + return List.of( + from, + (byte) (from + fourth), + (byte) (from + fourth * 2), + (byte) (from + fourth * 3), + to + ); + } + } + + final class Unlimited implements AllowedNumberInputs.Unlimited, AllowedByteInputs { + + static final @NotNull AllowedByteInputs.Unlimited INSTANCE = new AllowedByteInputs.Unlimited(); + + private Unlimited() { + } + + @Override + public @NotNull List getSuggestions(@NotNull CommandSender sender, @NotNull List input, @NotNull String current) { + return List.of( + (byte) -128, + (byte) -100, + (byte) -50, + (byte) 0, + (byte) 50, + (byte) 100, + (byte) 127 + ); + } + } + + final class Positive implements AllowedNumberInputs.Positive, AllowedByteInputs { + + static final @NotNull AllowedByteInputs.Positive INSTANCE = new AllowedByteInputs.Positive(); + + private Positive() { + } + + @Override + public @NotNull Byte from() { + return 0; + } + + @Override + public @NotNull Byte to() { + return Byte.MAX_VALUE; + } + + @Override + public boolean isInRange(@NotNull Byte input) { + return input > -1; + } + + @Override + public @NotNull List getSuggestions(@NotNull CommandSender sender, @NotNull List input, @NotNull String current) { + return List.of( + (byte) 0, + (byte) 50, + (byte) 100, + (byte) 127 + ); + } + } + + final class Negative implements AllowedNumberInputs.Negative, AllowedByteInputs { + + static final @NotNull AllowedByteInputs.Negative INSTANCE = new AllowedByteInputs.Negative(); + + private Negative() { + } + + @Override + public @NotNull Byte from() { + return -1; + } + + @Override + public @NotNull Byte to() { + return Byte.MIN_VALUE; + } + + @Override + public boolean isInRange(@NotNull Byte input) { + return input < 0; + } + + @Override + public @NotNull List getSuggestions(@NotNull CommandSender sender, @NotNull List input, @NotNull String current) { + return List.of( + (byte) -128, + (byte) -100, + (byte) -50, + (byte) -1 + ); + } + } + + final class Value extends AllowedNumberInputs.Value implements AllowedByteInputs { + + Value(byte value) { + super(value); + } + } + + final class Values extends AllowedNumberInputs.Values implements AllowedByteInputs { + + Values(@NotNull List values) { + super(values); + } + } +} diff --git a/commands/src/main/java/com/wizardlybump17/wlib/command/input/number/AllowedDoubleInputs.java b/commands/src/main/java/com/wizardlybump17/wlib/command/input/number/AllowedDoubleInputs.java new file mode 100644 index 00000000..3eeccade --- /dev/null +++ b/commands/src/main/java/com/wizardlybump17/wlib/command/input/number/AllowedDoubleInputs.java @@ -0,0 +1,173 @@ +package com.wizardlybump17.wlib.command.input.number; + +import com.wizardlybump17.wlib.command.sender.CommandSender; +import org.jetbrains.annotations.NotNull; + +import java.util.List; + +public interface AllowedDoubleInputs extends AllowedNumberInputs { + + static @NotNull Range range(double from, double to) { + return new Range(from, to); + } + + static @NotNull Unlimited unlimited() { + return Unlimited.INSTANCE; + } + + static @NotNull Positive positive() { + return Positive.INSTANCE; + } + + static @NotNull Negative negative() { + return Negative.INSTANCE; + } + + static @NotNull Values values(@NotNull List values) { + return new Values(values); + } + + static @NotNull Value value(double value) { + return new Value(value); + } + + final class Range extends Ranged implements AllowedDoubleInputs { + + Range(double from, double to) { + super(from, to); + if (from >= to) + throw new IllegalArgumentException("from must be less than to"); + } + + @Override + public @NotNull List getSuggestions(@NotNull CommandSender sender, @NotNull List input, @NotNull String current) { + double to = to(); + double from = from(); + + if (to - from < 5) { + Double[] doubles = new Double[(int) (to - from)]; + for (int i = 0; i < doubles.length; i++) + doubles[i] = to - from - i; + return List.of(doubles); + } + + double fourth = (to - from) / 4; + return List.of( + from, + from + fourth, + from + fourth * 2, + from + fourth * 3, + to + ); + } + } + + final class Unlimited implements AllowedNumberInputs.Unlimited, AllowedDoubleInputs { + + static final @NotNull AllowedDoubleInputs.Unlimited INSTANCE = new AllowedDoubleInputs.Unlimited(); + + private Unlimited() { + } + + @Override + public @NotNull List getSuggestions(@NotNull CommandSender sender, @NotNull List input, @NotNull String current) { + return List.of( + -100000.5, + -50000.5, + -3000.5, + -200.5, + -50.5, + 0.0, + 50.5, + 200.5, + 3000.5, + 50000.5, + 100000.5 + ); + } + } + + final class Positive implements AllowedNumberInputs.Positive, AllowedDoubleInputs { + + static final @NotNull AllowedDoubleInputs.Positive INSTANCE = new AllowedDoubleInputs.Positive(); + + private Positive() { + } + + @Override + public @NotNull Double from() { + return 0.0; + } + + @Override + public @NotNull Double to() { + return Double.MAX_VALUE; + } + + @Override + public boolean isInRange(@NotNull Double input) { + return input > -1; + } + + @Override + public @NotNull List getSuggestions(@NotNull CommandSender sender, @NotNull List input, @NotNull String current) { + return List.of( + 0.0, + 50.5, + 200.5, + 3000.5, + 50000.5, + 100000.5 + ); + } + } + + final class Negative implements AllowedNumberInputs.Negative, AllowedDoubleInputs { + + static final @NotNull AllowedDoubleInputs.Negative INSTANCE = new AllowedDoubleInputs.Negative(); + + private Negative() { + } + + @Override + public @NotNull Double from() { + return -1.0; + } + + @Override + public @NotNull Double to() { + return Double.MIN_VALUE; + } + + @Override + public boolean isInRange(@NotNull Double input) { + return input < 0; + } + + @Override + public @NotNull List getSuggestions(@NotNull CommandSender sender, @NotNull List input, @NotNull String current) { + return List.of( + -100000.5, + -50000.5, + -3000.5, + -200.5, + -50.5, + -1.0 + ); + } + } + + final class Value extends AllowedNumberInputs.Value implements AllowedDoubleInputs { + + Value(double value) { + super(value); + } + } + + final class Values extends AllowedNumberInputs.Values implements AllowedDoubleInputs { + + Values(@NotNull List values) { + super(values); + } + } +} diff --git a/commands/src/main/java/com/wizardlybump17/wlib/command/input/number/AllowedFloatInputs.java b/commands/src/main/java/com/wizardlybump17/wlib/command/input/number/AllowedFloatInputs.java new file mode 100644 index 00000000..2c144b23 --- /dev/null +++ b/commands/src/main/java/com/wizardlybump17/wlib/command/input/number/AllowedFloatInputs.java @@ -0,0 +1,173 @@ +package com.wizardlybump17.wlib.command.input.number; + +import com.wizardlybump17.wlib.command.sender.CommandSender; +import org.jetbrains.annotations.NotNull; + +import java.util.List; + +public interface AllowedFloatInputs extends AllowedNumberInputs { + + static @NotNull Range range(float from, float to) { + return new Range(from, to); + } + + static @NotNull Unlimited unlimited() { + return Unlimited.INSTANCE; + } + + static @NotNull Positive positive() { + return Positive.INSTANCE; + } + + static @NotNull Negative negative() { + return Negative.INSTANCE; + } + + static @NotNull Values values(@NotNull List values) { + return new Values(values); + } + + static @NotNull Value value(float value) { + return new Value(value); + } + + final class Range extends Ranged implements AllowedFloatInputs { + + Range(float from, float to) { + super(from, to); + if (from >= to) + throw new IllegalArgumentException("from must be less than to"); + } + + @Override + public @NotNull List getSuggestions(@NotNull CommandSender sender, @NotNull List input, @NotNull String current) { + float to = to(); + float from = from(); + + if (to - from < 5) { + Float[] floats = new Float[(int) (to - from)]; + for (int i = 0; i < floats.length; i++) + floats[i] = to - from - i; + return List.of(floats); + } + + float fourth = (to - from) / 4; + return List.of( + from, + from + fourth, + from + fourth * 2, + from + fourth * 3, + to + ); + } + } + + final class Unlimited implements AllowedNumberInputs.Unlimited, AllowedFloatInputs { + + static final @NotNull AllowedFloatInputs.Unlimited INSTANCE = new AllowedFloatInputs.Unlimited(); + + private Unlimited() { + } + + @Override + public @NotNull List getSuggestions(@NotNull CommandSender sender, @NotNull List input, @NotNull String current) { + return List.of( + -100000.5F, + -50000.5F, + -3000.5F, + -200.5F, + -50.5F, + 0.0F, + 50.5F, + 200.5F, + 3000.5F, + 50000.5F, + 100000.5F + ); + } + } + + final class Positive implements AllowedNumberInputs.Positive, AllowedFloatInputs { + + static final @NotNull AllowedFloatInputs.Positive INSTANCE = new AllowedFloatInputs.Positive(); + + private Positive() { + } + + @Override + public @NotNull Float from() { + return 0.0F; + } + + @Override + public @NotNull Float to() { + return Float.MAX_VALUE; + } + + @Override + public boolean isInRange(@NotNull Float input) { + return input > -1; + } + + @Override + public @NotNull List getSuggestions(@NotNull CommandSender sender, @NotNull List input, @NotNull String current) { + return List.of( + 0.0F, + 50.5F, + 200.5F, + 3000.5F, + 50000.5F, + 100000.5F + ); + } + } + + final class Negative implements AllowedNumberInputs.Negative, AllowedFloatInputs { + + static final @NotNull AllowedFloatInputs.Negative INSTANCE = new AllowedFloatInputs.Negative(); + + private Negative() { + } + + @Override + public @NotNull Float from() { + return -1.0F; + } + + @Override + public @NotNull Float to() { + return Float.MIN_VALUE; + } + + @Override + public boolean isInRange(@NotNull Float input) { + return input < 0; + } + + @Override + public @NotNull List getSuggestions(@NotNull CommandSender sender, @NotNull List input, @NotNull String current) { + return List.of( + -100000.5F, + -50000.5F, + -3000.5F, + -200.5F, + -50.5F, + -1.0F + ); + } + } + + final class Value extends AllowedNumberInputs.Value implements AllowedFloatInputs { + + Value(float value) { + super(value); + } + } + + final class Values extends AllowedNumberInputs.Values implements AllowedFloatInputs { + + Values(@NotNull List values) { + super(values); + } + } +} diff --git a/commands/src/main/java/com/wizardlybump17/wlib/command/input/number/AllowedIntegerInputs.java b/commands/src/main/java/com/wizardlybump17/wlib/command/input/number/AllowedIntegerInputs.java index 05b72790..78f00cbb 100644 --- a/commands/src/main/java/com/wizardlybump17/wlib/command/input/number/AllowedIntegerInputs.java +++ b/commands/src/main/java/com/wizardlybump17/wlib/command/input/number/AllowedIntegerInputs.java @@ -34,7 +34,7 @@ public interface AllowedIntegerInputs extends AllowedNumberInputs { final class Range extends AllowedNumberInputs.Ranged implements AllowedIntegerInputs { - Range(@NotNull Integer from, @NotNull Integer to) { + Range(int from, int to) { super(from, to); if (from >= to) throw new IllegalArgumentException("from must be less than to"); @@ -42,8 +42,8 @@ final class Range extends AllowedNumberInputs.Ranged implements Allowed @Override public @NotNull List getSuggestions(@NotNull CommandSender sender, @NotNull List input, @NotNull String current) { - Integer to = to(); - Integer from = from(); + int to = to(); + int from = from(); if (to - from < 5) return IntStream.rangeClosed(from, to).boxed().toList(); diff --git a/commands/src/main/java/com/wizardlybump17/wlib/command/input/number/AllowedLongInputs.java b/commands/src/main/java/com/wizardlybump17/wlib/command/input/number/AllowedLongInputs.java new file mode 100644 index 00000000..b2b4e0de --- /dev/null +++ b/commands/src/main/java/com/wizardlybump17/wlib/command/input/number/AllowedLongInputs.java @@ -0,0 +1,173 @@ +package com.wizardlybump17.wlib.command.input.number; + +import com.wizardlybump17.wlib.command.sender.CommandSender; +import org.jetbrains.annotations.NotNull; + +import java.util.List; + +public interface AllowedLongInputs extends AllowedNumberInputs { + + static @NotNull Range range(long from, long to) { + return new Range(from, to); + } + + static @NotNull Unlimited unlimited() { + return Unlimited.INSTANCE; + } + + static @NotNull Positive positive() { + return Positive.INSTANCE; + } + + static @NotNull Negative negative() { + return Negative.INSTANCE; + } + + static @NotNull Values values(@NotNull List values) { + return new Values(values); + } + + static @NotNull Value value(long value) { + return new Value(value); + } + + final class Range extends Ranged implements AllowedLongInputs { + + Range(long from, long to) { + super(from, to); + if (from >= to) + throw new IllegalArgumentException("from must be less than to"); + } + + @Override + public @NotNull List getSuggestions(@NotNull CommandSender sender, @NotNull List input, @NotNull String current) { + long to = to(); + long from = from(); + + if (to - from < 5) { + Long[] longs = new Long[(int) (to - from)]; + for (int i = 0; i < longs.length; i++) + longs[i] = to - from - i; + return List.of(longs); + } + + long fourth = (to - from) / 4; + return List.of( + from, + from + fourth, + from + fourth * 2, + from + fourth * 3, + to + ); + } + } + + final class Unlimited implements AllowedNumberInputs.Unlimited, AllowedLongInputs { + + static final @NotNull AllowedLongInputs.Unlimited INSTANCE = new AllowedLongInputs.Unlimited(); + + private Unlimited() { + } + + @Override + public @NotNull List getSuggestions(@NotNull CommandSender sender, @NotNull List input, @NotNull String current) { + return List.of( + -100000L, + -50000L, + -3000L, + -200L, + -50L, + 0L, + 50L, + 200L, + 3000L, + 50000L, + 100000L + ); + } + } + + final class Positive implements AllowedNumberInputs.Positive, AllowedLongInputs { + + static final @NotNull AllowedLongInputs.Positive INSTANCE = new AllowedLongInputs.Positive(); + + private Positive() { + } + + @Override + public @NotNull Long from() { + return 0L; + } + + @Override + public @NotNull Long to() { + return Long.MAX_VALUE; + } + + @Override + public boolean isInRange(@NotNull Long input) { + return input > -1; + } + + @Override + public @NotNull List getSuggestions(@NotNull CommandSender sender, @NotNull List input, @NotNull String current) { + return List.of( + 0L, + 50L, + 200L, + 3000L, + 50000L, + 100000L + ); + } + } + + final class Negative implements AllowedNumberInputs.Negative, AllowedLongInputs { + + static final @NotNull AllowedLongInputs.Negative INSTANCE = new AllowedLongInputs.Negative(); + + private Negative() { + } + + @Override + public @NotNull Long from() { + return -1L; + } + + @Override + public @NotNull Long to() { + return Long.MIN_VALUE; + } + + @Override + public boolean isInRange(@NotNull Long input) { + return input < 0; + } + + @Override + public @NotNull List getSuggestions(@NotNull CommandSender sender, @NotNull List input, @NotNull String current) { + return List.of( + -100000L, + -50000L, + -3000L, + -200L, + -50L, + -1L + ); + } + } + + final class Value extends AllowedNumberInputs.Value implements AllowedLongInputs { + + Value(long value) { + super(value); + } + } + + final class Values extends AllowedNumberInputs.Values implements AllowedLongInputs { + + Values(@NotNull List values) { + super(values); + } + } +} diff --git a/commands/src/main/java/com/wizardlybump17/wlib/command/input/number/AllowedShortInputs.java b/commands/src/main/java/com/wizardlybump17/wlib/command/input/number/AllowedShortInputs.java new file mode 100644 index 00000000..b555e698 --- /dev/null +++ b/commands/src/main/java/com/wizardlybump17/wlib/command/input/number/AllowedShortInputs.java @@ -0,0 +1,169 @@ +package com.wizardlybump17.wlib.command.input.number; + +import com.wizardlybump17.wlib.command.sender.CommandSender; +import org.jetbrains.annotations.NotNull; + +import java.util.List; + +public interface AllowedShortInputs extends AllowedNumberInputs { + + static @NotNull Range range(short from, short to) { + return new Range(from, to); + } + + static @NotNull Unlimited unlimited() { + return Unlimited.INSTANCE; + } + + static @NotNull Positive positive() { + return Positive.INSTANCE; + } + + static @NotNull Negative negative() { + return Negative.INSTANCE; + } + + static @NotNull Values values(@NotNull List values) { + return new Values(values); + } + + static @NotNull Value value(short value) { + return new Value(value); + } + + final class Range extends Ranged implements AllowedShortInputs { + + Range(short from, short to) { + super(from, to); + if (from >= to) + throw new IllegalArgumentException("from must be less than to"); + } + + @Override + public @NotNull List getSuggestions(@NotNull CommandSender sender, @NotNull List input, @NotNull String current) { + short to = to(); + short from = from(); + + if (to - from < 5) { + Short[] shorts = new Short[to - from]; + for (int i = 0; i < shorts.length; i++) + shorts[i] = (short) (to - from - i); + return List.of(shorts); + } + + short fourth = (short) ((to - from) / 4); + return List.of( + from, + (short) (from + fourth), + (short) (from + fourth * 2), + (short) (from + fourth * 3), + to + ); + } + } + + final class Unlimited implements AllowedNumberInputs.Unlimited, AllowedShortInputs { + + static final @NotNull AllowedShortInputs.Unlimited INSTANCE = new AllowedShortInputs.Unlimited(); + + private Unlimited() { + } + + @Override + public @NotNull List getSuggestions(@NotNull CommandSender sender, @NotNull List input, @NotNull String current) { + return List.of( + (short) -32768, + (short) -3000, + (short) -100, + (short) -50, + (short) 0, + (short) 50, + (short) 100, + (short) 3000, + (short) 32767 + ); + } + } + + final class Positive implements AllowedNumberInputs.Positive, AllowedShortInputs { + + static final @NotNull AllowedShortInputs.Positive INSTANCE = new AllowedShortInputs.Positive(); + + private Positive() { + } + + @Override + public @NotNull Short from() { + return 0; + } + + @Override + public @NotNull Short to() { + return Short.MAX_VALUE; + } + + @Override + public boolean isInRange(@NotNull Short input) { + return input > -1; + } + + @Override + public @NotNull List getSuggestions(@NotNull CommandSender sender, @NotNull List input, @NotNull String current) { + return List.of( + (short) 0, + (short) 50, + (short) 100, + (short) 3000, + (short) 32767 + ); + } + } + + final class Negative implements AllowedNumberInputs.Negative, AllowedShortInputs { + + static final @NotNull AllowedShortInputs.Negative INSTANCE = new AllowedShortInputs.Negative(); + + private Negative() { + } + + @Override + public @NotNull Short from() { + return -1; + } + + @Override + public @NotNull Short to() { + return Short.MIN_VALUE; + } + + @Override + public boolean isInRange(@NotNull Short input) { + return input < 0; + } + + @Override + public @NotNull List getSuggestions(@NotNull CommandSender sender, @NotNull List input, @NotNull String current) { + return List.of( + (short) -32768, + (short) -3000, + (short) -100, + (short) -50, + (short) -1 + ); + } + } + + final class Value extends AllowedNumberInputs.Value implements AllowedShortInputs { + + Value(short value) { + super(value); + } + } + + final class Values extends AllowedNumberInputs.Values implements AllowedShortInputs { + + Values(@NotNull List values) { + super(values); + } + } +} From 6816a7c0a2f6759062cfa3e77edb24969732c430 Mon Sep 17 00:00:00 2001 From: WizardlyBump17 Date: Mon, 24 Nov 2025 23:28:29 -0300 Subject: [PATCH 154/363] the last primitives --- .../character/AllowedCharacterInputs.java | 191 ++++++++++++++++++ .../input/logical/BooleanAllowedInputs.java | 104 ++++++++++ 2 files changed, 295 insertions(+) create mode 100644 commands/src/main/java/com/wizardlybump17/wlib/command/input/character/AllowedCharacterInputs.java create mode 100644 commands/src/main/java/com/wizardlybump17/wlib/command/input/logical/BooleanAllowedInputs.java diff --git a/commands/src/main/java/com/wizardlybump17/wlib/command/input/character/AllowedCharacterInputs.java b/commands/src/main/java/com/wizardlybump17/wlib/command/input/character/AllowedCharacterInputs.java new file mode 100644 index 00000000..85fc2400 --- /dev/null +++ b/commands/src/main/java/com/wizardlybump17/wlib/command/input/character/AllowedCharacterInputs.java @@ -0,0 +1,191 @@ +package com.wizardlybump17.wlib.command.input.character; + +import com.wizardlybump17.wlib.command.input.AllowedInputs; +import com.wizardlybump17.wlib.command.input.AllowedListInputs; +import com.wizardlybump17.wlib.command.input.SingleValueInput; +import org.jetbrains.annotations.NotNull; +import org.jetbrains.annotations.Nullable; + +import java.util.List; +import java.util.Objects; +import java.util.stream.Collectors; + +public interface AllowedCharacterInputs extends AllowedInputs { + + static @NotNull Value value(char value) { + return new Value(value, false); + } + + static @NotNull Value valueIgnoreCase(char value) { + return new Value(value, true); + } + + static @NotNull Values values(@NotNull List values) { + values = List.copyOf(values); + return new Values(values, values, false); + } + + static @NotNull Values values(@NotNull Character @NotNull ... values) { + List valuesList = List.of(values); + return new Values(valuesList, valuesList, false); + } + + static @NotNull Values valuesIgnoreCase(@NotNull List values) { + return new Values( + List.copyOf(values), + values.stream() + .map(Character::toLowerCase) + .collect(Collectors.toList()), + true + ); + } + + static @NotNull Any anyNullable() { + return Any.NULLABLE; + } + + static @NotNull Any anyNotNull() { + return Any.NOT_NULL; + } + + final class Value implements AllowedCharacterInputs, SingleValueInput { + + private final char value; + private final boolean ignoreCase; + + private Value(char value, boolean ignoreCase) { + this.value = value; + this.ignoreCase = ignoreCase; + } + + @Override + public boolean isAllowed(@Nullable Character input) { + if (input == null) + return false; + return ignoreCase ? Character.toLowerCase(input) == Character.toLowerCase(value) : input == value; + } + + @Override + public @NotNull Character value() { + return value; + } + + public boolean ignoreCase() { + return ignoreCase; + } + + @Override + public boolean equals(Object object) { + if (object == null || getClass() != object.getClass()) + return false; + Value value1 = (Value) object; + return value == value1.value && ignoreCase == value1.ignoreCase; + } + + @Override + public int hashCode() { + return Objects.hash(value, ignoreCase); + } + + @Override + public String toString() { + return "Value{" + + "value=" + value + + ", ignoreCase=" + ignoreCase + + '}'; + } + } + + final class Values implements AllowedCharacterInputs, AllowedListInputs { + + private final @NotNull List values; + private final @NotNull List toCheck; + private final boolean ignoreCase; + + private Values(@NotNull List values, @NotNull List toCheck, boolean ignoreCase) { + this.values = values; + this.toCheck = toCheck; + this.ignoreCase = ignoreCase; + } + + @Override + public @NotNull List allowedValues() { + return values; + } + + public boolean isIgnoreCase() { + return ignoreCase; + } + + @Override + public boolean isAllowed(@Nullable Character input) { + if (input == null) + return false; + if (ignoreCase) + return toCheck.contains(Character.toLowerCase(input)); + return toCheck.contains(input); + } + + @Override + public boolean equals(Object object) { + if (object == null || getClass() != object.getClass()) + return false; + Values values1 = (Values) object; + return ignoreCase == values1.ignoreCase && Objects.equals(values, values1.values) && Objects.equals(toCheck, values1.toCheck); + } + + @Override + public int hashCode() { + return Objects.hash(values, toCheck, ignoreCase); + } + + @Override + public String toString() { + return "Values{" + + "values=" + values + + ", ignoreCase=" + ignoreCase + + '}'; + } + } + + final class Any implements AllowedCharacterInputs { + + private static final @NotNull Any NULLABLE = new Any(true); + private static final @NotNull Any NOT_NULL = new Any(false); + + private final boolean nullable; + + private Any(boolean nullable) { + this.nullable = nullable; + } + + public boolean nullable() { + return nullable; + } + + @Override + public boolean isAllowed(@Nullable Character input) { + return nullable || input != null; + } + + @Override + public boolean equals(Object object) { + if (object == null || getClass() != object.getClass()) + return false; + Any any = (Any) object; + return nullable == any.nullable; + } + + @Override + public int hashCode() { + return Objects.hashCode(nullable); + } + + @Override + public String toString() { + return "Any{" + + "nullable=" + nullable + + '}'; + } + } +} diff --git a/commands/src/main/java/com/wizardlybump17/wlib/command/input/logical/BooleanAllowedInputs.java b/commands/src/main/java/com/wizardlybump17/wlib/command/input/logical/BooleanAllowedInputs.java new file mode 100644 index 00000000..714c10fb --- /dev/null +++ b/commands/src/main/java/com/wizardlybump17/wlib/command/input/logical/BooleanAllowedInputs.java @@ -0,0 +1,104 @@ +package com.wizardlybump17.wlib.command.input.logical; + +import com.wizardlybump17.wlib.command.input.AllowedInputs; +import com.wizardlybump17.wlib.command.input.SingleValueInput; +import org.jetbrains.annotations.NotNull; +import org.jetbrains.annotations.Nullable; + +import java.util.Objects; + +public interface BooleanAllowedInputs extends AllowedInputs { + + static @NotNull True trueValue() { + return True.INSTANCE; + } + + static @NotNull False falseValue() { + return False.INSTANCE; + } + + static @NotNull Any anyNullable() { + return Any.NULLABLE; + } + + static @NotNull Any anyNotNull() { + return Any.NOT_NULL; + } + + final class True implements BooleanAllowedInputs, SingleValueInput { + + private static final @NotNull True INSTANCE = new True(); + + private True() { + } + + @Override + public @NotNull Boolean value() { + return true; + } + + @Override + public String toString() { + return "True{}"; + } + } + + final class False implements BooleanAllowedInputs, SingleValueInput { + + private static final @NotNull False INSTANCE = new False(); + + private False() { + } + + @Override + public @NotNull Boolean value() { + return false; + } + + @Override + public String toString() { + return "False{}"; + } + } + + final class Any implements BooleanAllowedInputs { + + private static final @NotNull Any NULLABLE = new Any(true); + private static final @NotNull Any NOT_NULL = new Any(false); + + private final boolean nullable; + + private Any(boolean nullable) { + this.nullable = nullable; + } + + public boolean nullable() { + return nullable; + } + + @Override + public boolean isAllowed(@Nullable Boolean input) { + return nullable || input != null; + } + + @Override + public boolean equals(Object object) { + if (object == null || getClass() != object.getClass()) + return false; + Any any = (Any) object; + return nullable == any.nullable; + } + + @Override + public int hashCode() { + return Objects.hashCode(nullable); + } + + @Override + public String toString() { + return "Any{" + + "nullable=" + nullable + + '}'; + } + } +} From 659968c01e04052bc5e38499807763225b2d8934 Mon Sep 17 00:00:00 2001 From: WizardlyBump17 Date: Mon, 24 Nov 2025 23:38:22 -0300 Subject: [PATCH 155/363] minor changes --- .../input/number/AllowedByteInputs.java | 6 +- .../input/number/AllowedDoubleInputs.java | 6 +- .../input/number/AllowedFloatInputs.java | 6 +- .../input/number/AllowedIntegerInputs.java | 6 +- .../input/number/AllowedLongInputs.java | 6 +- .../input/number/AllowedNumberInputs.java | 89 +++++++++++++++++-- .../input/number/AllowedShortInputs.java | 6 +- 7 files changed, 101 insertions(+), 24 deletions(-) diff --git a/commands/src/main/java/com/wizardlybump17/wlib/command/input/number/AllowedByteInputs.java b/commands/src/main/java/com/wizardlybump17/wlib/command/input/number/AllowedByteInputs.java index 0ea350f4..f5eb24df 100644 --- a/commands/src/main/java/com/wizardlybump17/wlib/command/input/number/AllowedByteInputs.java +++ b/commands/src/main/java/com/wizardlybump17/wlib/command/input/number/AllowedByteInputs.java @@ -62,7 +62,7 @@ final class Range extends Ranged implements AllowedByteInputs { } } - final class Unlimited implements AllowedNumberInputs.Unlimited, AllowedByteInputs { + final class Unlimited extends AllowedNumberInputs.Unlimited implements AllowedByteInputs { static final @NotNull AllowedByteInputs.Unlimited INSTANCE = new AllowedByteInputs.Unlimited(); @@ -83,7 +83,7 @@ private Unlimited() { } } - final class Positive implements AllowedNumberInputs.Positive, AllowedByteInputs { + final class Positive extends AllowedNumberInputs.Positive implements AllowedByteInputs { static final @NotNull AllowedByteInputs.Positive INSTANCE = new AllowedByteInputs.Positive(); @@ -116,7 +116,7 @@ public boolean isInRange(@NotNull Byte input) { } } - final class Negative implements AllowedNumberInputs.Negative, AllowedByteInputs { + final class Negative extends AllowedNumberInputs.Negative implements AllowedByteInputs { static final @NotNull AllowedByteInputs.Negative INSTANCE = new AllowedByteInputs.Negative(); diff --git a/commands/src/main/java/com/wizardlybump17/wlib/command/input/number/AllowedDoubleInputs.java b/commands/src/main/java/com/wizardlybump17/wlib/command/input/number/AllowedDoubleInputs.java index 3eeccade..564fb3a7 100644 --- a/commands/src/main/java/com/wizardlybump17/wlib/command/input/number/AllowedDoubleInputs.java +++ b/commands/src/main/java/com/wizardlybump17/wlib/command/input/number/AllowedDoubleInputs.java @@ -62,7 +62,7 @@ final class Range extends Ranged implements AllowedDoubleInputs { } } - final class Unlimited implements AllowedNumberInputs.Unlimited, AllowedDoubleInputs { + final class Unlimited extends AllowedNumberInputs.Unlimited implements AllowedDoubleInputs { static final @NotNull AllowedDoubleInputs.Unlimited INSTANCE = new AllowedDoubleInputs.Unlimited(); @@ -87,7 +87,7 @@ private Unlimited() { } } - final class Positive implements AllowedNumberInputs.Positive, AllowedDoubleInputs { + final class Positive extends AllowedNumberInputs.Positive implements AllowedDoubleInputs { static final @NotNull AllowedDoubleInputs.Positive INSTANCE = new AllowedDoubleInputs.Positive(); @@ -122,7 +122,7 @@ public boolean isInRange(@NotNull Double input) { } } - final class Negative implements AllowedNumberInputs.Negative, AllowedDoubleInputs { + final class Negative extends AllowedNumberInputs.Negative implements AllowedDoubleInputs { static final @NotNull AllowedDoubleInputs.Negative INSTANCE = new AllowedDoubleInputs.Negative(); diff --git a/commands/src/main/java/com/wizardlybump17/wlib/command/input/number/AllowedFloatInputs.java b/commands/src/main/java/com/wizardlybump17/wlib/command/input/number/AllowedFloatInputs.java index 2c144b23..4057f62d 100644 --- a/commands/src/main/java/com/wizardlybump17/wlib/command/input/number/AllowedFloatInputs.java +++ b/commands/src/main/java/com/wizardlybump17/wlib/command/input/number/AllowedFloatInputs.java @@ -62,7 +62,7 @@ final class Range extends Ranged implements AllowedFloatInputs { } } - final class Unlimited implements AllowedNumberInputs.Unlimited, AllowedFloatInputs { + final class Unlimited extends AllowedNumberInputs.Unlimited implements AllowedFloatInputs { static final @NotNull AllowedFloatInputs.Unlimited INSTANCE = new AllowedFloatInputs.Unlimited(); @@ -87,7 +87,7 @@ private Unlimited() { } } - final class Positive implements AllowedNumberInputs.Positive, AllowedFloatInputs { + final class Positive extends AllowedNumberInputs.Positive implements AllowedFloatInputs { static final @NotNull AllowedFloatInputs.Positive INSTANCE = new AllowedFloatInputs.Positive(); @@ -122,7 +122,7 @@ public boolean isInRange(@NotNull Float input) { } } - final class Negative implements AllowedNumberInputs.Negative, AllowedFloatInputs { + final class Negative extends AllowedNumberInputs.Negative implements AllowedFloatInputs { static final @NotNull AllowedFloatInputs.Negative INSTANCE = new AllowedFloatInputs.Negative(); diff --git a/commands/src/main/java/com/wizardlybump17/wlib/command/input/number/AllowedIntegerInputs.java b/commands/src/main/java/com/wizardlybump17/wlib/command/input/number/AllowedIntegerInputs.java index 78f00cbb..2856503e 100644 --- a/commands/src/main/java/com/wizardlybump17/wlib/command/input/number/AllowedIntegerInputs.java +++ b/commands/src/main/java/com/wizardlybump17/wlib/command/input/number/AllowedIntegerInputs.java @@ -53,7 +53,7 @@ final class Range extends AllowedNumberInputs.Ranged implements Allowed } } - final class Unlimited implements AllowedNumberInputs.Unlimited, AllowedIntegerInputs{ + final class Unlimited extends AllowedNumberInputs.Unlimited implements AllowedIntegerInputs{ static final @NotNull AllowedIntegerInputs.Unlimited INSTANCE = new AllowedIntegerInputs.Unlimited(); @@ -78,7 +78,7 @@ private Unlimited() { } } - final class Positive implements AllowedNumberInputs.Positive, AllowedIntegerInputs { + final class Positive extends AllowedNumberInputs.Positive implements AllowedIntegerInputs { static final @NotNull AllowedIntegerInputs.Positive INSTANCE = new AllowedIntegerInputs.Positive(); @@ -113,7 +113,7 @@ public boolean isInRange(@NotNull Integer input) { } } - final class Negative implements AllowedNumberInputs.Negative, AllowedIntegerInputs { + final class Negative extends AllowedNumberInputs.Negative implements AllowedIntegerInputs { static final @NotNull AllowedIntegerInputs.Negative INSTANCE = new AllowedIntegerInputs.Negative(); diff --git a/commands/src/main/java/com/wizardlybump17/wlib/command/input/number/AllowedLongInputs.java b/commands/src/main/java/com/wizardlybump17/wlib/command/input/number/AllowedLongInputs.java index b2b4e0de..f4cfa5f2 100644 --- a/commands/src/main/java/com/wizardlybump17/wlib/command/input/number/AllowedLongInputs.java +++ b/commands/src/main/java/com/wizardlybump17/wlib/command/input/number/AllowedLongInputs.java @@ -62,7 +62,7 @@ final class Range extends Ranged implements AllowedLongInputs { } } - final class Unlimited implements AllowedNumberInputs.Unlimited, AllowedLongInputs { + final class Unlimited extends AllowedNumberInputs.Unlimited implements AllowedLongInputs { static final @NotNull AllowedLongInputs.Unlimited INSTANCE = new AllowedLongInputs.Unlimited(); @@ -87,7 +87,7 @@ private Unlimited() { } } - final class Positive implements AllowedNumberInputs.Positive, AllowedLongInputs { + final class Positive extends AllowedNumberInputs.Positive implements AllowedLongInputs { static final @NotNull AllowedLongInputs.Positive INSTANCE = new AllowedLongInputs.Positive(); @@ -122,7 +122,7 @@ public boolean isInRange(@NotNull Long input) { } } - final class Negative implements AllowedNumberInputs.Negative, AllowedLongInputs { + final class Negative extends AllowedNumberInputs.Negative implements AllowedLongInputs { static final @NotNull AllowedLongInputs.Negative INSTANCE = new AllowedLongInputs.Negative(); diff --git a/commands/src/main/java/com/wizardlybump17/wlib/command/input/number/AllowedNumberInputs.java b/commands/src/main/java/com/wizardlybump17/wlib/command/input/number/AllowedNumberInputs.java index 87d46226..c50e473a 100644 --- a/commands/src/main/java/com/wizardlybump17/wlib/command/input/number/AllowedNumberInputs.java +++ b/commands/src/main/java/com/wizardlybump17/wlib/command/input/number/AllowedNumberInputs.java @@ -8,6 +8,7 @@ import org.jetbrains.annotations.Nullable; import java.util.List; +import java.util.Objects; public interface AllowedNumberInputs extends AllowedInputs { @@ -50,14 +51,40 @@ public boolean isAllowed(@Nullable N input) { return false; return isInRange(input); } + + @Override + public boolean equals(Object object) { + if (object == null || getClass() != object.getClass()) + return false; + Ranged ranged = (Ranged) object; + return Objects.equals(from, ranged.from) && Objects.equals(to, ranged.to); + } + + @Override + public int hashCode() { + return Objects.hash(from, to); + } + + @Override + public String toString() { + return "Ranged{" + + "from=" + from + + ", to=" + to + + '}'; + } } - interface Unlimited extends AllowedNumberInputs { + abstract class Unlimited implements AllowedNumberInputs { @Override - default boolean isAllowed(@Nullable N input) { + public boolean isAllowed(@Nullable N input) { return true; } + + @Override + public String toString() { + return "Unlimited{}"; + } } class Value implements AllowedNumberInputs, SingleValueInput { @@ -72,6 +99,26 @@ class Value implements AllowedNumberInputs, SingleValueInpu public @NotNull N value() { return value; } + + @Override + public boolean equals(Object object) { + if (object == null || getClass() != object.getClass()) + return false; + Value value1 = (Value) object; + return Objects.equals(value, value1.value); + } + + @Override + public int hashCode() { + return Objects.hashCode(value); + } + + @Override + public String toString() { + return "Value{" + + "value=" + value + + '}'; + } } class Values implements AllowedNumberInputs { @@ -93,25 +140,55 @@ public boolean isAllowed(@Nullable N input) { public @NotNull List getSuggestions(@NotNull CommandSender sender, @NotNull List input, @NotNull String current) { return values; } + + @Override + public boolean equals(Object object) { + if (object == null || getClass() != object.getClass()) + return false; + Values values1 = (Values) object; + return Objects.equals(values, values1.values); + } + + @Override + public int hashCode() { + return Objects.hashCode(values); + } + + @Override + public String toString() { + return "Values{" + + "values=" + values + + '}'; + } } - interface Positive extends AllowedNumberInputs, RangedAllowedInputs { + abstract class Positive implements AllowedNumberInputs, RangedAllowedInputs { @Override - default boolean isAllowed(@Nullable N input) { + public boolean isAllowed(@Nullable N input) { if (input == null) return false; return isInRange(input); } + + @Override + public String toString() { + return "Positive{}"; + } } - interface Negative extends AllowedNumberInputs, RangedAllowedInputs { + abstract class Negative implements AllowedNumberInputs, RangedAllowedInputs { @Override - default boolean isAllowed(@Nullable N input) { + public boolean isAllowed(@Nullable N input) { if (input == null) return false; return isInRange(input); } + + @Override + public String toString() { + return "Negative{}"; + } } } diff --git a/commands/src/main/java/com/wizardlybump17/wlib/command/input/number/AllowedShortInputs.java b/commands/src/main/java/com/wizardlybump17/wlib/command/input/number/AllowedShortInputs.java index b555e698..484d348b 100644 --- a/commands/src/main/java/com/wizardlybump17/wlib/command/input/number/AllowedShortInputs.java +++ b/commands/src/main/java/com/wizardlybump17/wlib/command/input/number/AllowedShortInputs.java @@ -62,7 +62,7 @@ final class Range extends Ranged implements AllowedShortInputs { } } - final class Unlimited implements AllowedNumberInputs.Unlimited, AllowedShortInputs { + final class Unlimited extends AllowedNumberInputs.Unlimited implements AllowedShortInputs { static final @NotNull AllowedShortInputs.Unlimited INSTANCE = new AllowedShortInputs.Unlimited(); @@ -85,7 +85,7 @@ private Unlimited() { } } - final class Positive implements AllowedNumberInputs.Positive, AllowedShortInputs { + final class Positive extends AllowedNumberInputs.Positive implements AllowedShortInputs { static final @NotNull AllowedShortInputs.Positive INSTANCE = new AllowedShortInputs.Positive(); @@ -119,7 +119,7 @@ public boolean isInRange(@NotNull Short input) { } } - final class Negative implements AllowedNumberInputs.Negative, AllowedShortInputs { + final class Negative extends AllowedNumberInputs.Negative implements AllowedShortInputs { static final @NotNull AllowedShortInputs.Negative INSTANCE = new AllowedShortInputs.Negative(); From 0fb21d7dd4ddfdcf0ed0bc7a19aae6b4606255e9 Mon Sep 17 00:00:00 2001 From: WizardlyBump17 Date: Mon, 24 Nov 2025 23:45:12 -0300 Subject: [PATCH 156/363] UUIDs --- .../wlib/command/input/AllowedListInputs.java | 6 + .../input/object/AllowedUUIDInputs.java | 139 ++++++++++++++++++ 2 files changed, 145 insertions(+) create mode 100644 commands/src/main/java/com/wizardlybump17/wlib/command/input/object/AllowedUUIDInputs.java diff --git a/commands/src/main/java/com/wizardlybump17/wlib/command/input/AllowedListInputs.java b/commands/src/main/java/com/wizardlybump17/wlib/command/input/AllowedListInputs.java index 86d1928a..38984d3c 100644 --- a/commands/src/main/java/com/wizardlybump17/wlib/command/input/AllowedListInputs.java +++ b/commands/src/main/java/com/wizardlybump17/wlib/command/input/AllowedListInputs.java @@ -1,10 +1,16 @@ package com.wizardlybump17.wlib.command.input; import org.jetbrains.annotations.NotNull; +import org.jetbrains.annotations.Nullable; import java.util.List; public interface AllowedListInputs extends AllowedInputs { @NotNull List allowedValues(); + + @Override + default boolean isAllowed(@Nullable T input) { + return allowedValues().contains(input); + } } diff --git a/commands/src/main/java/com/wizardlybump17/wlib/command/input/object/AllowedUUIDInputs.java b/commands/src/main/java/com/wizardlybump17/wlib/command/input/object/AllowedUUIDInputs.java new file mode 100644 index 00000000..ae1b0f2d --- /dev/null +++ b/commands/src/main/java/com/wizardlybump17/wlib/command/input/object/AllowedUUIDInputs.java @@ -0,0 +1,139 @@ +package com.wizardlybump17.wlib.command.input.object; + +import com.wizardlybump17.wlib.command.input.AllowedInputs; +import com.wizardlybump17.wlib.command.input.AllowedListInputs; +import com.wizardlybump17.wlib.command.input.SingleValueInput; +import org.jetbrains.annotations.NotNull; +import org.jetbrains.annotations.Nullable; + +import java.util.List; +import java.util.Objects; +import java.util.UUID; + +public interface AllowedUUIDInputs extends AllowedInputs { + + static @NotNull Value value(@NotNull UUID value) { + return new Value(value); + } + + static @NotNull Values values(@NotNull List values) { + return new Values(List.copyOf(values)); + } + + static @NotNull Values values(@NotNull UUID @NotNull ... values) { + return new Values(List.of(values)); + } + + static @NotNull Any anyNullable() { + return Any.NULLABLE; + } + + static @NotNull Any anyNotNull() { + return Any.NOT_NULL; + } + + final class Value implements AllowedUUIDInputs, SingleValueInput { + + private final @NotNull UUID value; + + Value(@NotNull UUID value) { + this.value = value; + } + + @Override + public @NotNull UUID value() { + return value; + } + + @Override + public boolean equals(Object object) { + if (object == null || getClass() != object.getClass()) + return false; + Value value1 = (Value) object; + return Objects.equals(value, value1.value); + } + + @Override + public int hashCode() { + return Objects.hashCode(value); + } + + @Override + public String toString() { + return "Value{" + + "value=" + value + + '}'; + } + } + + final class Values implements AllowedUUIDInputs, AllowedListInputs { + + private final @NotNull List values; + + private Values(@NotNull List values) { + this.values = values; + } + + @Override + public @NotNull List allowedValues() { + return values; + } + + @Override + public boolean equals(Object object) { + if (object == null || getClass() != object.getClass()) + return false; + Values values1 = (Values) object; + return Objects.equals(values, values1.values); + } + + @Override + public int hashCode() { + return Objects.hashCode(values); + } + + @Override + public String toString() { + return "Values{" + + "values=" + values + + '}'; + } + } + + final class Any implements AllowedUUIDInputs { + + private static final @NotNull Any NULLABLE = new Any(true); + private static final @NotNull Any NOT_NULL = new Any(false); + + private final boolean nullable; + + private Any(boolean nullable) { + this.nullable = nullable; + } + + @Override + public boolean isAllowed(@Nullable UUID input) { + return nullable || input != null; + } + + @Override + public boolean equals(Object object) { + if (object == null || getClass() != object.getClass()) + return false; + Any any = (Any) object; + return nullable == any.nullable; + } + + @Override + public int hashCode() { + return Objects.hashCode(nullable); + } + + @Override + public String toString() { + return "Any{" + + "nullable=" + nullable + + '}'; + } + } +} From 7aaaa4bbcdb76e036d8265e67da2369b6bb86e46 Mon Sep 17 00:00:00 2001 From: WizardlyBump17 Date: Mon, 24 Nov 2025 23:46:28 -0300 Subject: [PATCH 157/363] made them implement AllowedListInputs --- .../wlib/command/input/AllowedListInputs.java | 2 ++ .../wlib/command/input/number/AllowedNumberInputs.java | 9 ++++----- 2 files changed, 6 insertions(+), 5 deletions(-) diff --git a/commands/src/main/java/com/wizardlybump17/wlib/command/input/AllowedListInputs.java b/commands/src/main/java/com/wizardlybump17/wlib/command/input/AllowedListInputs.java index 38984d3c..2eeb37ff 100644 --- a/commands/src/main/java/com/wizardlybump17/wlib/command/input/AllowedListInputs.java +++ b/commands/src/main/java/com/wizardlybump17/wlib/command/input/AllowedListInputs.java @@ -11,6 +11,8 @@ public interface AllowedListInputs extends AllowedInputs { @Override default boolean isAllowed(@Nullable T input) { + if (input == null) + return false; return allowedValues().contains(input); } } diff --git a/commands/src/main/java/com/wizardlybump17/wlib/command/input/number/AllowedNumberInputs.java b/commands/src/main/java/com/wizardlybump17/wlib/command/input/number/AllowedNumberInputs.java index c50e473a..34773563 100644 --- a/commands/src/main/java/com/wizardlybump17/wlib/command/input/number/AllowedNumberInputs.java +++ b/commands/src/main/java/com/wizardlybump17/wlib/command/input/number/AllowedNumberInputs.java @@ -1,6 +1,7 @@ package com.wizardlybump17.wlib.command.input.number; import com.wizardlybump17.wlib.command.input.AllowedInputs; +import com.wizardlybump17.wlib.command.input.AllowedListInputs; import com.wizardlybump17.wlib.command.input.RangedAllowedInputs; import com.wizardlybump17.wlib.command.input.SingleValueInput; import com.wizardlybump17.wlib.command.sender.CommandSender; @@ -121,7 +122,7 @@ public String toString() { } } - class Values implements AllowedNumberInputs { + class Values implements AllowedNumberInputs, AllowedListInputs { private final @NotNull List values; @@ -130,10 +131,8 @@ class Values implements AllowedNumberInputs { } @Override - public boolean isAllowed(@Nullable N input) { - if (input == null) - return false; - return values.contains(input); + public @NotNull List allowedValues() { + return values; } @Override From 05ad28a5878098d39ccc755987cec30ccd9a23a4 Mon Sep 17 00:00:00 2001 From: WizardlyBump17 Date: Mon, 24 Nov 2025 23:48:36 -0300 Subject: [PATCH 158/363] ? --- .../registry/MethodCommandNodeFactoryRegistry.java | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/commands/src/main/java/com/wizardlybump17/wlib/command/registry/MethodCommandNodeFactoryRegistry.java b/commands/src/main/java/com/wizardlybump17/wlib/command/registry/MethodCommandNodeFactoryRegistry.java index fbd7ffc3..ad366572 100644 --- a/commands/src/main/java/com/wizardlybump17/wlib/command/registry/MethodCommandNodeFactoryRegistry.java +++ b/commands/src/main/java/com/wizardlybump17/wlib/command/registry/MethodCommandNodeFactoryRegistry.java @@ -16,20 +16,20 @@ public final class MethodCommandNodeFactoryRegistry { private MethodCommandNodeFactoryRegistry() { } - private final @NotNull Map, MethodCommandNodeFactory> factories = new HashMap<>(); + private final @NotNull Map, MethodCommandNodeFactory> factories = new HashMap<>(); - public void addFactory(@NotNull Class clazz, @NotNull MethodCommandNodeFactory factory) { + public void addFactory(@NotNull Class clazz, @NotNull MethodCommandNodeFactory factory) { factories.put(clazz, factory); } - public void addFactory(@NotNull MethodCommandNodeFactory factory, @NotNull Class ... classes) { + public void addFactory(@NotNull MethodCommandNodeFactory factory, @NotNull Class ... classes) { if (classes.length < 1) throw new IllegalArgumentException("The classes array must contain at least one element"); for (Class clazz : classes) addFactory(clazz, factory); } - public @Nullable MethodCommandNodeFactory getFactory(@NotNull Class clazz) { + public @Nullable MethodCommandNodeFactory getFactory(@NotNull Class clazz) { return factories.get(clazz); } @@ -48,7 +48,7 @@ public boolean hasFactory(@NotNull Class clazz) { return factories.containsKey(clazz); } - public @NotNull @Unmodifiable Map, MethodCommandNodeFactory> getFactories() { + public @NotNull @Unmodifiable Map, MethodCommandNodeFactory> getFactories() { return Collections.unmodifiableMap(factories); } From 032eebe4f22925dfa21f2fd9cc20f449c42e530b Mon Sep 17 00:00:00 2001 From: WizardlyBump17 Date: Tue, 25 Nov 2025 18:28:03 -0300 Subject: [PATCH 159/363] better packages --- .../input/{character => primitive}/AllowedCharacterInputs.java | 2 +- .../input/{logical => primitive}/BooleanAllowedInputs.java | 2 +- .../command/input/{ => primitive}/number/AllowedByteInputs.java | 2 +- .../input/{ => primitive}/number/AllowedDoubleInputs.java | 2 +- .../input/{ => primitive}/number/AllowedFloatInputs.java | 2 +- .../input/{ => primitive}/number/AllowedIntegerInputs.java | 2 +- .../command/input/{ => primitive}/number/AllowedLongInputs.java | 2 +- .../input/{ => primitive}/number/AllowedNumberInputs.java | 2 +- .../input/{ => primitive}/number/AllowedShortInputs.java | 2 +- .../wizardlybump17/wlib/command/node/IntegerCommandNode.java | 2 +- .../java/com/wizardlybump17/wlib/test/command/CommandTests.java | 2 +- .../com/wizardlybump17/wlib/test/command/SuggestionTests.java | 2 +- .../extractor/method/MethodCommandExtractorStructureTests.java | 2 +- .../command/extractor/method/MethodCommandExtractorTests.java | 2 +- .../test/command/manager/CommandManagerSuggestionTests.java | 2 +- 15 files changed, 15 insertions(+), 15 deletions(-) rename commands/src/main/java/com/wizardlybump17/wlib/command/input/{character => primitive}/AllowedCharacterInputs.java (98%) rename commands/src/main/java/com/wizardlybump17/wlib/command/input/{logical => primitive}/BooleanAllowedInputs.java (97%) rename commands/src/main/java/com/wizardlybump17/wlib/command/input/{ => primitive}/number/AllowedByteInputs.java (98%) rename commands/src/main/java/com/wizardlybump17/wlib/command/input/{ => primitive}/number/AllowedDoubleInputs.java (98%) rename commands/src/main/java/com/wizardlybump17/wlib/command/input/{ => primitive}/number/AllowedFloatInputs.java (98%) rename commands/src/main/java/com/wizardlybump17/wlib/command/input/{ => primitive}/number/AllowedIntegerInputs.java (98%) rename commands/src/main/java/com/wizardlybump17/wlib/command/input/{ => primitive}/number/AllowedLongInputs.java (98%) rename commands/src/main/java/com/wizardlybump17/wlib/command/input/{ => primitive}/number/AllowedNumberInputs.java (98%) rename commands/src/main/java/com/wizardlybump17/wlib/command/input/{ => primitive}/number/AllowedShortInputs.java (98%) diff --git a/commands/src/main/java/com/wizardlybump17/wlib/command/input/character/AllowedCharacterInputs.java b/commands/src/main/java/com/wizardlybump17/wlib/command/input/primitive/AllowedCharacterInputs.java similarity index 98% rename from commands/src/main/java/com/wizardlybump17/wlib/command/input/character/AllowedCharacterInputs.java rename to commands/src/main/java/com/wizardlybump17/wlib/command/input/primitive/AllowedCharacterInputs.java index 85fc2400..d275de83 100644 --- a/commands/src/main/java/com/wizardlybump17/wlib/command/input/character/AllowedCharacterInputs.java +++ b/commands/src/main/java/com/wizardlybump17/wlib/command/input/primitive/AllowedCharacterInputs.java @@ -1,4 +1,4 @@ -package com.wizardlybump17.wlib.command.input.character; +package com.wizardlybump17.wlib.command.input.primitive; import com.wizardlybump17.wlib.command.input.AllowedInputs; import com.wizardlybump17.wlib.command.input.AllowedListInputs; diff --git a/commands/src/main/java/com/wizardlybump17/wlib/command/input/logical/BooleanAllowedInputs.java b/commands/src/main/java/com/wizardlybump17/wlib/command/input/primitive/BooleanAllowedInputs.java similarity index 97% rename from commands/src/main/java/com/wizardlybump17/wlib/command/input/logical/BooleanAllowedInputs.java rename to commands/src/main/java/com/wizardlybump17/wlib/command/input/primitive/BooleanAllowedInputs.java index 714c10fb..4ffdac69 100644 --- a/commands/src/main/java/com/wizardlybump17/wlib/command/input/logical/BooleanAllowedInputs.java +++ b/commands/src/main/java/com/wizardlybump17/wlib/command/input/primitive/BooleanAllowedInputs.java @@ -1,4 +1,4 @@ -package com.wizardlybump17.wlib.command.input.logical; +package com.wizardlybump17.wlib.command.input.primitive; import com.wizardlybump17.wlib.command.input.AllowedInputs; import com.wizardlybump17.wlib.command.input.SingleValueInput; diff --git a/commands/src/main/java/com/wizardlybump17/wlib/command/input/number/AllowedByteInputs.java b/commands/src/main/java/com/wizardlybump17/wlib/command/input/primitive/number/AllowedByteInputs.java similarity index 98% rename from commands/src/main/java/com/wizardlybump17/wlib/command/input/number/AllowedByteInputs.java rename to commands/src/main/java/com/wizardlybump17/wlib/command/input/primitive/number/AllowedByteInputs.java index f5eb24df..338dfff6 100644 --- a/commands/src/main/java/com/wizardlybump17/wlib/command/input/number/AllowedByteInputs.java +++ b/commands/src/main/java/com/wizardlybump17/wlib/command/input/primitive/number/AllowedByteInputs.java @@ -1,4 +1,4 @@ -package com.wizardlybump17.wlib.command.input.number; +package com.wizardlybump17.wlib.command.input.primitive.number; import com.wizardlybump17.wlib.command.sender.CommandSender; import org.jetbrains.annotations.NotNull; diff --git a/commands/src/main/java/com/wizardlybump17/wlib/command/input/number/AllowedDoubleInputs.java b/commands/src/main/java/com/wizardlybump17/wlib/command/input/primitive/number/AllowedDoubleInputs.java similarity index 98% rename from commands/src/main/java/com/wizardlybump17/wlib/command/input/number/AllowedDoubleInputs.java rename to commands/src/main/java/com/wizardlybump17/wlib/command/input/primitive/number/AllowedDoubleInputs.java index 564fb3a7..29521f1b 100644 --- a/commands/src/main/java/com/wizardlybump17/wlib/command/input/number/AllowedDoubleInputs.java +++ b/commands/src/main/java/com/wizardlybump17/wlib/command/input/primitive/number/AllowedDoubleInputs.java @@ -1,4 +1,4 @@ -package com.wizardlybump17.wlib.command.input.number; +package com.wizardlybump17.wlib.command.input.primitive.number; import com.wizardlybump17.wlib.command.sender.CommandSender; import org.jetbrains.annotations.NotNull; diff --git a/commands/src/main/java/com/wizardlybump17/wlib/command/input/number/AllowedFloatInputs.java b/commands/src/main/java/com/wizardlybump17/wlib/command/input/primitive/number/AllowedFloatInputs.java similarity index 98% rename from commands/src/main/java/com/wizardlybump17/wlib/command/input/number/AllowedFloatInputs.java rename to commands/src/main/java/com/wizardlybump17/wlib/command/input/primitive/number/AllowedFloatInputs.java index 4057f62d..a0ee44b0 100644 --- a/commands/src/main/java/com/wizardlybump17/wlib/command/input/number/AllowedFloatInputs.java +++ b/commands/src/main/java/com/wizardlybump17/wlib/command/input/primitive/number/AllowedFloatInputs.java @@ -1,4 +1,4 @@ -package com.wizardlybump17.wlib.command.input.number; +package com.wizardlybump17.wlib.command.input.primitive.number; import com.wizardlybump17.wlib.command.sender.CommandSender; import org.jetbrains.annotations.NotNull; diff --git a/commands/src/main/java/com/wizardlybump17/wlib/command/input/number/AllowedIntegerInputs.java b/commands/src/main/java/com/wizardlybump17/wlib/command/input/primitive/number/AllowedIntegerInputs.java similarity index 98% rename from commands/src/main/java/com/wizardlybump17/wlib/command/input/number/AllowedIntegerInputs.java rename to commands/src/main/java/com/wizardlybump17/wlib/command/input/primitive/number/AllowedIntegerInputs.java index 2856503e..9602b4b5 100644 --- a/commands/src/main/java/com/wizardlybump17/wlib/command/input/number/AllowedIntegerInputs.java +++ b/commands/src/main/java/com/wizardlybump17/wlib/command/input/primitive/number/AllowedIntegerInputs.java @@ -1,4 +1,4 @@ -package com.wizardlybump17.wlib.command.input.number; +package com.wizardlybump17.wlib.command.input.primitive.number; import com.wizardlybump17.wlib.command.sender.CommandSender; import org.jetbrains.annotations.NotNull; diff --git a/commands/src/main/java/com/wizardlybump17/wlib/command/input/number/AllowedLongInputs.java b/commands/src/main/java/com/wizardlybump17/wlib/command/input/primitive/number/AllowedLongInputs.java similarity index 98% rename from commands/src/main/java/com/wizardlybump17/wlib/command/input/number/AllowedLongInputs.java rename to commands/src/main/java/com/wizardlybump17/wlib/command/input/primitive/number/AllowedLongInputs.java index f4cfa5f2..d97e51f9 100644 --- a/commands/src/main/java/com/wizardlybump17/wlib/command/input/number/AllowedLongInputs.java +++ b/commands/src/main/java/com/wizardlybump17/wlib/command/input/primitive/number/AllowedLongInputs.java @@ -1,4 +1,4 @@ -package com.wizardlybump17.wlib.command.input.number; +package com.wizardlybump17.wlib.command.input.primitive.number; import com.wizardlybump17.wlib.command.sender.CommandSender; import org.jetbrains.annotations.NotNull; diff --git a/commands/src/main/java/com/wizardlybump17/wlib/command/input/number/AllowedNumberInputs.java b/commands/src/main/java/com/wizardlybump17/wlib/command/input/primitive/number/AllowedNumberInputs.java similarity index 98% rename from commands/src/main/java/com/wizardlybump17/wlib/command/input/number/AllowedNumberInputs.java rename to commands/src/main/java/com/wizardlybump17/wlib/command/input/primitive/number/AllowedNumberInputs.java index 34773563..09fb1375 100644 --- a/commands/src/main/java/com/wizardlybump17/wlib/command/input/number/AllowedNumberInputs.java +++ b/commands/src/main/java/com/wizardlybump17/wlib/command/input/primitive/number/AllowedNumberInputs.java @@ -1,4 +1,4 @@ -package com.wizardlybump17.wlib.command.input.number; +package com.wizardlybump17.wlib.command.input.primitive.number; import com.wizardlybump17.wlib.command.input.AllowedInputs; import com.wizardlybump17.wlib.command.input.AllowedListInputs; diff --git a/commands/src/main/java/com/wizardlybump17/wlib/command/input/number/AllowedShortInputs.java b/commands/src/main/java/com/wizardlybump17/wlib/command/input/primitive/number/AllowedShortInputs.java similarity index 98% rename from commands/src/main/java/com/wizardlybump17/wlib/command/input/number/AllowedShortInputs.java rename to commands/src/main/java/com/wizardlybump17/wlib/command/input/primitive/number/AllowedShortInputs.java index 484d348b..94b5944e 100644 --- a/commands/src/main/java/com/wizardlybump17/wlib/command/input/number/AllowedShortInputs.java +++ b/commands/src/main/java/com/wizardlybump17/wlib/command/input/primitive/number/AllowedShortInputs.java @@ -1,4 +1,4 @@ -package com.wizardlybump17.wlib.command.input.number; +package com.wizardlybump17.wlib.command.input.primitive.number; import com.wizardlybump17.wlib.command.sender.CommandSender; import org.jetbrains.annotations.NotNull; diff --git a/commands/src/main/java/com/wizardlybump17/wlib/command/node/IntegerCommandNode.java b/commands/src/main/java/com/wizardlybump17/wlib/command/node/IntegerCommandNode.java index 77e56713..38af6b71 100644 --- a/commands/src/main/java/com/wizardlybump17/wlib/command/node/IntegerCommandNode.java +++ b/commands/src/main/java/com/wizardlybump17/wlib/command/node/IntegerCommandNode.java @@ -2,7 +2,7 @@ import com.wizardlybump17.wlib.command.exception.InputParsingException; import com.wizardlybump17.wlib.command.executor.CommandNodeExecutor; -import com.wizardlybump17.wlib.command.input.number.AllowedNumberInputs; +import com.wizardlybump17.wlib.command.input.primitive.number.AllowedNumberInputs; import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.Nullable; diff --git a/commands/src/test/java/com/wizardlybump17/wlib/test/command/CommandTests.java b/commands/src/test/java/com/wizardlybump17/wlib/test/command/CommandTests.java index 06c22ad5..54dcc0d4 100644 --- a/commands/src/test/java/com/wizardlybump17/wlib/test/command/CommandTests.java +++ b/commands/src/test/java/com/wizardlybump17/wlib/test/command/CommandTests.java @@ -2,7 +2,7 @@ import com.wizardlybump17.wlib.command.Command; import com.wizardlybump17.wlib.command.exception.InputParsingException; -import com.wizardlybump17.wlib.command.input.number.AllowedNumberInputs; +import com.wizardlybump17.wlib.command.input.primitive.number.AllowedNumberInputs; import com.wizardlybump17.wlib.command.node.IntegerCommandNode; import com.wizardlybump17.wlib.command.node.LiteralCommandNode; import com.wizardlybump17.wlib.command.result.CommandResult; diff --git a/commands/src/test/java/com/wizardlybump17/wlib/test/command/SuggestionTests.java b/commands/src/test/java/com/wizardlybump17/wlib/test/command/SuggestionTests.java index 8dfeb089..73a29e8d 100644 --- a/commands/src/test/java/com/wizardlybump17/wlib/test/command/SuggestionTests.java +++ b/commands/src/test/java/com/wizardlybump17/wlib/test/command/SuggestionTests.java @@ -1,7 +1,7 @@ package com.wizardlybump17.wlib.test.command; import com.wizardlybump17.wlib.command.Command; -import com.wizardlybump17.wlib.command.input.number.AllowedIntegerInputs; +import com.wizardlybump17.wlib.command.input.primitive.number.AllowedIntegerInputs; import com.wizardlybump17.wlib.command.node.IntegerCommandNode; import com.wizardlybump17.wlib.command.node.LiteralCommandNode; import com.wizardlybump17.wlib.command.result.CommandResult; diff --git a/commands/src/test/java/com/wizardlybump17/wlib/test/command/extractor/method/MethodCommandExtractorStructureTests.java b/commands/src/test/java/com/wizardlybump17/wlib/test/command/extractor/method/MethodCommandExtractorStructureTests.java index c007e014..b0cd1bbf 100644 --- a/commands/src/test/java/com/wizardlybump17/wlib/test/command/extractor/method/MethodCommandExtractorStructureTests.java +++ b/commands/src/test/java/com/wizardlybump17/wlib/test/command/extractor/method/MethodCommandExtractorStructureTests.java @@ -3,7 +3,7 @@ import com.wizardlybump17.wlib.command.Command; import com.wizardlybump17.wlib.command.extractor.CommandExtractor; import com.wizardlybump17.wlib.command.extractor.method.factory.MethodCommandNodeFactory; -import com.wizardlybump17.wlib.command.input.number.AllowedIntegerInputs; +import com.wizardlybump17.wlib.command.input.primitive.number.AllowedIntegerInputs; import com.wizardlybump17.wlib.command.input.string.AllowedStringInputs; import com.wizardlybump17.wlib.command.node.CommandNode; import com.wizardlybump17.wlib.command.node.IntegerCommandNode; diff --git a/commands/src/test/java/com/wizardlybump17/wlib/test/command/extractor/method/MethodCommandExtractorTests.java b/commands/src/test/java/com/wizardlybump17/wlib/test/command/extractor/method/MethodCommandExtractorTests.java index 05e1a8cc..69037da0 100644 --- a/commands/src/test/java/com/wizardlybump17/wlib/test/command/extractor/method/MethodCommandExtractorTests.java +++ b/commands/src/test/java/com/wizardlybump17/wlib/test/command/extractor/method/MethodCommandExtractorTests.java @@ -5,7 +5,7 @@ import com.wizardlybump17.wlib.command.extractor.CommandExtractor; import com.wizardlybump17.wlib.command.extractor.method.MethodCommandExtractor; import com.wizardlybump17.wlib.command.extractor.method.factory.MethodCommandNodeFactory; -import com.wizardlybump17.wlib.command.input.number.AllowedIntegerInputs; +import com.wizardlybump17.wlib.command.input.primitive.number.AllowedIntegerInputs; import com.wizardlybump17.wlib.command.input.string.AllowedStringInputs; import com.wizardlybump17.wlib.command.manager.CommandManager; import com.wizardlybump17.wlib.command.node.CommandNode; diff --git a/commands/src/test/java/com/wizardlybump17/wlib/test/command/manager/CommandManagerSuggestionTests.java b/commands/src/test/java/com/wizardlybump17/wlib/test/command/manager/CommandManagerSuggestionTests.java index 80f21a51..5cc62aa0 100644 --- a/commands/src/test/java/com/wizardlybump17/wlib/test/command/manager/CommandManagerSuggestionTests.java +++ b/commands/src/test/java/com/wizardlybump17/wlib/test/command/manager/CommandManagerSuggestionTests.java @@ -1,7 +1,7 @@ package com.wizardlybump17.wlib.test.command.manager; import com.wizardlybump17.wlib.command.Command; -import com.wizardlybump17.wlib.command.input.number.AllowedIntegerInputs; +import com.wizardlybump17.wlib.command.input.primitive.number.AllowedIntegerInputs; import com.wizardlybump17.wlib.command.manager.CommandManager; import com.wizardlybump17.wlib.command.node.IntegerCommandNode; import com.wizardlybump17.wlib.command.node.LiteralCommandNode; From 72a9a7e43e899b5f3863beddfb4091ebf5d7d0c2 Mon Sep 17 00:00:00 2001 From: WizardlyBump17 Date: Tue, 25 Nov 2025 19:31:06 -0300 Subject: [PATCH 160/363] more --- ...nputs.java => CharacterAllowedInputs.java} | 8 +- .../node/primitive/BooleanCommandNode.java | 70 ++++++++++++++++++ .../node/primitive/CharacterCommandNode.java | 68 +++++++++++++++++ .../primitive/number/ByteCommandNode.java | 74 +++++++++++++++++++ .../primitive/number/DoubleCommandNode.java | 74 +++++++++++++++++++ .../primitive/number/FloatCommandNode.java | 74 +++++++++++++++++++ .../number}/IntegerCommandNode.java | 27 +++---- .../primitive/number/LongCommandNode.java | 74 +++++++++++++++++++ .../primitive/number/ShortCommandNode.java | 74 +++++++++++++++++++ .../wlib/test/command/CommandTests.java | 2 +- .../wlib/test/command/SuggestionTests.java | 2 +- .../MethodCommandExtractorStructureTests.java | 2 +- .../method/MethodCommandExtractorTests.java | 2 +- .../CommandManagerSuggestionTests.java | 2 +- 14 files changed, 531 insertions(+), 22 deletions(-) rename commands/src/main/java/com/wizardlybump17/wlib/command/input/primitive/{AllowedCharacterInputs.java => CharacterAllowedInputs.java} (95%) create mode 100644 commands/src/main/java/com/wizardlybump17/wlib/command/node/primitive/BooleanCommandNode.java create mode 100644 commands/src/main/java/com/wizardlybump17/wlib/command/node/primitive/CharacterCommandNode.java create mode 100644 commands/src/main/java/com/wizardlybump17/wlib/command/node/primitive/number/ByteCommandNode.java create mode 100644 commands/src/main/java/com/wizardlybump17/wlib/command/node/primitive/number/DoubleCommandNode.java create mode 100644 commands/src/main/java/com/wizardlybump17/wlib/command/node/primitive/number/FloatCommandNode.java rename commands/src/main/java/com/wizardlybump17/wlib/command/node/{ => primitive/number}/IntegerCommandNode.java (68%) create mode 100644 commands/src/main/java/com/wizardlybump17/wlib/command/node/primitive/number/LongCommandNode.java create mode 100644 commands/src/main/java/com/wizardlybump17/wlib/command/node/primitive/number/ShortCommandNode.java diff --git a/commands/src/main/java/com/wizardlybump17/wlib/command/input/primitive/AllowedCharacterInputs.java b/commands/src/main/java/com/wizardlybump17/wlib/command/input/primitive/CharacterAllowedInputs.java similarity index 95% rename from commands/src/main/java/com/wizardlybump17/wlib/command/input/primitive/AllowedCharacterInputs.java rename to commands/src/main/java/com/wizardlybump17/wlib/command/input/primitive/CharacterAllowedInputs.java index d275de83..6a27f3e2 100644 --- a/commands/src/main/java/com/wizardlybump17/wlib/command/input/primitive/AllowedCharacterInputs.java +++ b/commands/src/main/java/com/wizardlybump17/wlib/command/input/primitive/CharacterAllowedInputs.java @@ -10,7 +10,7 @@ import java.util.Objects; import java.util.stream.Collectors; -public interface AllowedCharacterInputs extends AllowedInputs { +public interface CharacterAllowedInputs extends AllowedInputs { static @NotNull Value value(char value) { return new Value(value, false); @@ -48,7 +48,7 @@ public interface AllowedCharacterInputs extends AllowedInputs { return Any.NOT_NULL; } - final class Value implements AllowedCharacterInputs, SingleValueInput { + final class Value implements CharacterAllowedInputs, SingleValueInput { private final char value; private final boolean ignoreCase; @@ -96,7 +96,7 @@ public String toString() { } } - final class Values implements AllowedCharacterInputs, AllowedListInputs { + final class Values implements CharacterAllowedInputs, AllowedListInputs { private final @NotNull List values; private final @NotNull List toCheck; @@ -148,7 +148,7 @@ public String toString() { } } - final class Any implements AllowedCharacterInputs { + final class Any implements CharacterAllowedInputs { private static final @NotNull Any NULLABLE = new Any(true); private static final @NotNull Any NOT_NULL = new Any(false); diff --git a/commands/src/main/java/com/wizardlybump17/wlib/command/node/primitive/BooleanCommandNode.java b/commands/src/main/java/com/wizardlybump17/wlib/command/node/primitive/BooleanCommandNode.java new file mode 100644 index 00000000..082d4e25 --- /dev/null +++ b/commands/src/main/java/com/wizardlybump17/wlib/command/node/primitive/BooleanCommandNode.java @@ -0,0 +1,70 @@ +package com.wizardlybump17.wlib.command.node.primitive; + +import com.wizardlybump17.wlib.command.exception.InputParsingException; +import com.wizardlybump17.wlib.command.executor.CommandNodeExecutor; +import com.wizardlybump17.wlib.command.input.primitive.BooleanAllowedInputs; +import com.wizardlybump17.wlib.command.node.CommandNode; +import org.jetbrains.annotations.NotNull; +import org.jetbrains.annotations.Nullable; + +import java.util.List; + +public class BooleanCommandNode extends CommandNode { + + public BooleanCommandNode(@NotNull String name, @NotNull List> children, @NotNull BooleanAllowedInputs allowedInputs, @Nullable CommandNodeExecutor executor, @Nullable String permission) { + super(name, children, allowedInputs, executor, permission); + } + + public BooleanCommandNode(@NotNull String name, @NotNull BooleanAllowedInputs allowedInputs, @Nullable CommandNodeExecutor executor, @Nullable String permission) { + super(name, allowedInputs, executor, permission); + } + + public BooleanCommandNode(@NotNull String name, @NotNull List> children, @NotNull BooleanAllowedInputs allowedInputs, @Nullable String permission) { + super(name, children, allowedInputs, permission); + } + + public BooleanCommandNode(@NotNull String name, @NotNull BooleanAllowedInputs allowedInputs, @Nullable String permission) { + super(name, allowedInputs, permission); + } + + public BooleanCommandNode(@NotNull String name, @NotNull BooleanAllowedInputs allowedInputs, @Nullable CommandNodeExecutor executor) { + super(name, allowedInputs, executor); + } + + public BooleanCommandNode(@NotNull String name, @NotNull List> children, @NotNull BooleanAllowedInputs allowedInputs) { + super(name, children, allowedInputs); + } + + public BooleanCommandNode(@NotNull String name, @NotNull BooleanAllowedInputs allowedInputs) { + super(name, allowedInputs); + } + + @Override + public @NotNull BooleanAllowedInputs getAllowedInputs() { + return (BooleanAllowedInputs) super.getAllowedInputs(); + } + + @Override + public @Nullable Boolean parse(@NotNull String input) throws InputParsingException { + if (input.equalsIgnoreCase("true")) + return true; + if (input.equalsIgnoreCase("false")) + return false; + throw new InputParsingException("Could not parse as boolean: " + input); + } + + @Override + public @NotNull BooleanCommandNode withChildren(@NotNull List> children) { + return new BooleanCommandNode(getName(), children, getAllowedInputs(), getExecutor(), getPermission()); + } + + @Override + public @NotNull BooleanCommandNode withExecutor(@Nullable CommandNodeExecutor executor) { + return new BooleanCommandNode(getName(), getChildren(), getAllowedInputs(), executor, getPermission()); + } + + @Override + public @NotNull BooleanCommandNode withPermission(@Nullable String permission) { + return new BooleanCommandNode(getName(), getChildren(), getAllowedInputs(), getExecutor(), permission); + } +} diff --git a/commands/src/main/java/com/wizardlybump17/wlib/command/node/primitive/CharacterCommandNode.java b/commands/src/main/java/com/wizardlybump17/wlib/command/node/primitive/CharacterCommandNode.java new file mode 100644 index 00000000..22946afa --- /dev/null +++ b/commands/src/main/java/com/wizardlybump17/wlib/command/node/primitive/CharacterCommandNode.java @@ -0,0 +1,68 @@ +package com.wizardlybump17.wlib.command.node.primitive; + +import com.wizardlybump17.wlib.command.exception.InputParsingException; +import com.wizardlybump17.wlib.command.executor.CommandNodeExecutor; +import com.wizardlybump17.wlib.command.input.primitive.CharacterAllowedInputs; +import com.wizardlybump17.wlib.command.node.CommandNode; +import org.jetbrains.annotations.NotNull; +import org.jetbrains.annotations.Nullable; + +import java.util.List; + +public class CharacterCommandNode extends CommandNode { + + public CharacterCommandNode(@NotNull String name, @NotNull List> children, @NotNull CharacterAllowedInputs allowedInputs, @Nullable CommandNodeExecutor executor, @Nullable String permission) { + super(name, children, allowedInputs, executor, permission); + } + + public CharacterCommandNode(@NotNull String name, @NotNull CharacterAllowedInputs allowedInputs, @Nullable CommandNodeExecutor executor, @Nullable String permission) { + super(name, allowedInputs, executor, permission); + } + + public CharacterCommandNode(@NotNull String name, @NotNull List> children, @NotNull CharacterAllowedInputs allowedInputs, @Nullable String permission) { + super(name, children, allowedInputs, permission); + } + + public CharacterCommandNode(@NotNull String name, @NotNull CharacterAllowedInputs allowedInputs, @Nullable String permission) { + super(name, allowedInputs, permission); + } + + public CharacterCommandNode(@NotNull String name, @NotNull CharacterAllowedInputs allowedInputs, @Nullable CommandNodeExecutor executor) { + super(name, allowedInputs, executor); + } + + public CharacterCommandNode(@NotNull String name, @NotNull List> children, @NotNull CharacterAllowedInputs allowedInputs) { + super(name, children, allowedInputs); + } + + public CharacterCommandNode(@NotNull String name, @NotNull CharacterAllowedInputs allowedInputs) { + super(name, allowedInputs); + } + + @Override + public @NotNull CharacterAllowedInputs getAllowedInputs() { + return (CharacterAllowedInputs) super.getAllowedInputs(); + } + + @Override + public @Nullable Character parse(@NotNull String input) throws InputParsingException { + if (input.length() != 1) + throw new InputParsingException("Invalid input length. Expected exactly one char: " + input); + return input.charAt(0); + } + + @Override + public @NotNull CharacterCommandNode withChildren(@NotNull List> children) { + return new CharacterCommandNode(getName(), children, getAllowedInputs(), getExecutor(), getPermission()); + } + + @Override + public @NotNull CharacterCommandNode withExecutor(@Nullable CommandNodeExecutor executor) { + return new CharacterCommandNode(getName(), getChildren(), getAllowedInputs(), executor, getPermission()); + } + + @Override + public @NotNull CharacterCommandNode withPermission(@Nullable String permission) { + return new CharacterCommandNode(getName(), getChildren(), getAllowedInputs(), getExecutor(), permission); + } +} diff --git a/commands/src/main/java/com/wizardlybump17/wlib/command/node/primitive/number/ByteCommandNode.java b/commands/src/main/java/com/wizardlybump17/wlib/command/node/primitive/number/ByteCommandNode.java new file mode 100644 index 00000000..ab9ed6ab --- /dev/null +++ b/commands/src/main/java/com/wizardlybump17/wlib/command/node/primitive/number/ByteCommandNode.java @@ -0,0 +1,74 @@ +package com.wizardlybump17.wlib.command.node.primitive.number; + +import com.wizardlybump17.wlib.command.exception.InputParsingException; +import com.wizardlybump17.wlib.command.executor.CommandNodeExecutor; +import com.wizardlybump17.wlib.command.input.primitive.number.AllowedByteInputs; +import com.wizardlybump17.wlib.command.node.CommandNode; +import org.jetbrains.annotations.NotNull; +import org.jetbrains.annotations.Nullable; + +import java.util.List; + +public class ByteCommandNode extends CommandNode { + + public ByteCommandNode(@NotNull String name, @NotNull List> children, @NotNull AllowedByteInputs allowedInputs, @Nullable CommandNodeExecutor executor, @Nullable String permission) { + super(name, children, allowedInputs, executor, permission); + } + + public ByteCommandNode(@NotNull String name, @NotNull AllowedByteInputs allowedInputs, @Nullable CommandNodeExecutor executor, @Nullable String permission) { + this(name, List.of(), allowedInputs, executor, permission); + } + + public ByteCommandNode(@NotNull String name, @NotNull List> children, @NotNull AllowedByteInputs allowedInputs, @Nullable String permission) { + this(name, children, allowedInputs, null, permission); + } + + public ByteCommandNode(@NotNull String name, @NotNull AllowedByteInputs allowedInputs, @Nullable String permission) { + this(name, List.of(), allowedInputs, null, permission); + } + + public ByteCommandNode(@NotNull String name, @NotNull List> children, @NotNull AllowedByteInputs allowedInputs, @Nullable CommandNodeExecutor executor) { + super(name, children, allowedInputs, executor, null); + } + + public ByteCommandNode(@NotNull String name, @NotNull AllowedByteInputs allowedInputs, @Nullable CommandNodeExecutor executor) { + this(name, List.of(), allowedInputs, executor, null); + } + + public ByteCommandNode(@NotNull String name, @NotNull List> children, @NotNull AllowedByteInputs allowedInputs) { + this(name, children, allowedInputs, null, null); + } + + public ByteCommandNode(@NotNull String name, @NotNull AllowedByteInputs allowedInputs) { + this(name, List.of(), allowedInputs, null, null); + } + + @Override + public @NotNull AllowedByteInputs getAllowedInputs() { + return (AllowedByteInputs) super.getAllowedInputs(); + } + + @Override + public @NotNull Byte parse(@NotNull String input) throws InputParsingException { + try { + return Byte.parseByte(input); + } catch (NumberFormatException e) { + throw new InputParsingException("Could not parse as byte: " + input, e); + } + } + + @Override + public @NotNull ByteCommandNode withChildren(@NotNull List> children) { + return new ByteCommandNode(getName(), children, getAllowedInputs(), getExecutor(), getPermission()); + } + + @Override + public @NotNull ByteCommandNode withExecutor(@Nullable CommandNodeExecutor executor) { + return new ByteCommandNode(getName(), getChildren(), getAllowedInputs(), executor, getPermission()); + } + + @Override + public @NotNull ByteCommandNode withPermission(@Nullable String permission) { + return new ByteCommandNode(getName(), getChildren(), getAllowedInputs(), getExecutor(), permission); + } +} diff --git a/commands/src/main/java/com/wizardlybump17/wlib/command/node/primitive/number/DoubleCommandNode.java b/commands/src/main/java/com/wizardlybump17/wlib/command/node/primitive/number/DoubleCommandNode.java new file mode 100644 index 00000000..3ebb1759 --- /dev/null +++ b/commands/src/main/java/com/wizardlybump17/wlib/command/node/primitive/number/DoubleCommandNode.java @@ -0,0 +1,74 @@ +package com.wizardlybump17.wlib.command.node.primitive.number; + +import com.wizardlybump17.wlib.command.exception.InputParsingException; +import com.wizardlybump17.wlib.command.executor.CommandNodeExecutor; +import com.wizardlybump17.wlib.command.input.primitive.number.AllowedDoubleInputs; +import com.wizardlybump17.wlib.command.node.CommandNode; +import org.jetbrains.annotations.NotNull; +import org.jetbrains.annotations.Nullable; + +import java.util.List; + +public class DoubleCommandNode extends CommandNode { + + public DoubleCommandNode(@NotNull String name, @NotNull List> children, @NotNull AllowedDoubleInputs allowedInputs, @Nullable CommandNodeExecutor executor, @Nullable String permission) { + super(name, children, allowedInputs, executor, permission); + } + + public DoubleCommandNode(@NotNull String name, @NotNull AllowedDoubleInputs allowedInputs, @Nullable CommandNodeExecutor executor, @Nullable String permission) { + this(name, List.of(), allowedInputs, executor, permission); + } + + public DoubleCommandNode(@NotNull String name, @NotNull List> children, @NotNull AllowedDoubleInputs allowedInputs, @Nullable String permission) { + this(name, children, allowedInputs, null, permission); + } + + public DoubleCommandNode(@NotNull String name, @NotNull AllowedDoubleInputs allowedInputs, @Nullable String permission) { + this(name, List.of(), allowedInputs, null, permission); + } + + public DoubleCommandNode(@NotNull String name, @NotNull List> children, @NotNull AllowedDoubleInputs allowedInputs, @Nullable CommandNodeExecutor executor) { + super(name, children, allowedInputs, executor, null); + } + + public DoubleCommandNode(@NotNull String name, @NotNull AllowedDoubleInputs allowedInputs, @Nullable CommandNodeExecutor executor) { + this(name, List.of(), allowedInputs, executor, null); + } + + public DoubleCommandNode(@NotNull String name, @NotNull List> children, @NotNull AllowedDoubleInputs allowedInputs) { + this(name, children, allowedInputs, null, null); + } + + public DoubleCommandNode(@NotNull String name, @NotNull AllowedDoubleInputs allowedInputs) { + this(name, List.of(), allowedInputs, null, null); + } + + @Override + public @NotNull AllowedDoubleInputs getAllowedInputs() { + return (AllowedDoubleInputs) super.getAllowedInputs(); + } + + @Override + public @NotNull Double parse(@NotNull String input) throws InputParsingException { + try { + return Double.parseDouble(input); + } catch (NumberFormatException e) { + throw new InputParsingException("Could not parse as double: " + input, e); + } + } + + @Override + public @NotNull DoubleCommandNode withChildren(@NotNull List> children) { + return new DoubleCommandNode(getName(), children, getAllowedInputs(), getExecutor(), getPermission()); + } + + @Override + public @NotNull DoubleCommandNode withExecutor(@Nullable CommandNodeExecutor executor) { + return new DoubleCommandNode(getName(), getChildren(), getAllowedInputs(), executor, getPermission()); + } + + @Override + public @NotNull DoubleCommandNode withPermission(@Nullable String permission) { + return new DoubleCommandNode(getName(), getChildren(), getAllowedInputs(), getExecutor(), permission); + } +} diff --git a/commands/src/main/java/com/wizardlybump17/wlib/command/node/primitive/number/FloatCommandNode.java b/commands/src/main/java/com/wizardlybump17/wlib/command/node/primitive/number/FloatCommandNode.java new file mode 100644 index 00000000..b3544af1 --- /dev/null +++ b/commands/src/main/java/com/wizardlybump17/wlib/command/node/primitive/number/FloatCommandNode.java @@ -0,0 +1,74 @@ +package com.wizardlybump17.wlib.command.node.primitive.number; + +import com.wizardlybump17.wlib.command.exception.InputParsingException; +import com.wizardlybump17.wlib.command.executor.CommandNodeExecutor; +import com.wizardlybump17.wlib.command.input.primitive.number.AllowedFloatInputs; +import com.wizardlybump17.wlib.command.node.CommandNode; +import org.jetbrains.annotations.NotNull; +import org.jetbrains.annotations.Nullable; + +import java.util.List; + +public class FloatCommandNode extends CommandNode { + + public FloatCommandNode(@NotNull String name, @NotNull List> children, @NotNull AllowedFloatInputs allowedInputs, @Nullable CommandNodeExecutor executor, @Nullable String permission) { + super(name, children, allowedInputs, executor, permission); + } + + public FloatCommandNode(@NotNull String name, @NotNull AllowedFloatInputs allowedInputs, @Nullable CommandNodeExecutor executor, @Nullable String permission) { + this(name, List.of(), allowedInputs, executor, permission); + } + + public FloatCommandNode(@NotNull String name, @NotNull List> children, @NotNull AllowedFloatInputs allowedInputs, @Nullable String permission) { + this(name, children, allowedInputs, null, permission); + } + + public FloatCommandNode(@NotNull String name, @NotNull AllowedFloatInputs allowedInputs, @Nullable String permission) { + this(name, List.of(), allowedInputs, null, permission); + } + + public FloatCommandNode(@NotNull String name, @NotNull List> children, @NotNull AllowedFloatInputs allowedInputs, @Nullable CommandNodeExecutor executor) { + super(name, children, allowedInputs, executor, null); + } + + public FloatCommandNode(@NotNull String name, @NotNull AllowedFloatInputs allowedInputs, @Nullable CommandNodeExecutor executor) { + this(name, List.of(), allowedInputs, executor, null); + } + + public FloatCommandNode(@NotNull String name, @NotNull List> children, @NotNull AllowedFloatInputs allowedInputs) { + this(name, children, allowedInputs, null, null); + } + + public FloatCommandNode(@NotNull String name, @NotNull AllowedFloatInputs allowedInputs) { + this(name, List.of(), allowedInputs, null, null); + } + + @Override + public @NotNull AllowedFloatInputs getAllowedInputs() { + return (AllowedFloatInputs) super.getAllowedInputs(); + } + + @Override + public @NotNull Float parse(@NotNull String input) throws InputParsingException { + try { + return Float.parseFloat(input); + } catch (NumberFormatException e) { + throw new InputParsingException("Could not parse as float: " + input, e); + } + } + + @Override + public @NotNull FloatCommandNode withChildren(@NotNull List> children) { + return new FloatCommandNode(getName(), children, getAllowedInputs(), getExecutor(), getPermission()); + } + + @Override + public @NotNull FloatCommandNode withExecutor(@Nullable CommandNodeExecutor executor) { + return new FloatCommandNode(getName(), getChildren(), getAllowedInputs(), executor, getPermission()); + } + + @Override + public @NotNull FloatCommandNode withPermission(@Nullable String permission) { + return new FloatCommandNode(getName(), getChildren(), getAllowedInputs(), getExecutor(), permission); + } +} diff --git a/commands/src/main/java/com/wizardlybump17/wlib/command/node/IntegerCommandNode.java b/commands/src/main/java/com/wizardlybump17/wlib/command/node/primitive/number/IntegerCommandNode.java similarity index 68% rename from commands/src/main/java/com/wizardlybump17/wlib/command/node/IntegerCommandNode.java rename to commands/src/main/java/com/wizardlybump17/wlib/command/node/primitive/number/IntegerCommandNode.java index 38af6b71..97a389d9 100644 --- a/commands/src/main/java/com/wizardlybump17/wlib/command/node/IntegerCommandNode.java +++ b/commands/src/main/java/com/wizardlybump17/wlib/command/node/primitive/number/IntegerCommandNode.java @@ -1,8 +1,9 @@ -package com.wizardlybump17.wlib.command.node; +package com.wizardlybump17.wlib.command.node.primitive.number; import com.wizardlybump17.wlib.command.exception.InputParsingException; import com.wizardlybump17.wlib.command.executor.CommandNodeExecutor; -import com.wizardlybump17.wlib.command.input.primitive.number.AllowedNumberInputs; +import com.wizardlybump17.wlib.command.input.primitive.number.AllowedIntegerInputs; +import com.wizardlybump17.wlib.command.node.CommandNode; import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.Nullable; @@ -10,41 +11,41 @@ public class IntegerCommandNode extends CommandNode { - public IntegerCommandNode(@NotNull String name, @NotNull List> children, @NotNull AllowedNumberInputs allowedInputs, @Nullable CommandNodeExecutor executor, @Nullable String permission) { + public IntegerCommandNode(@NotNull String name, @NotNull List> children, @NotNull AllowedIntegerInputs allowedInputs, @Nullable CommandNodeExecutor executor, @Nullable String permission) { super(name, children, allowedInputs, executor, permission); } - public IntegerCommandNode(@NotNull String name, @NotNull AllowedNumberInputs allowedInputs, @Nullable CommandNodeExecutor executor, @Nullable String permission) { + public IntegerCommandNode(@NotNull String name, @NotNull AllowedIntegerInputs allowedInputs, @Nullable CommandNodeExecutor executor, @Nullable String permission) { this(name, List.of(), allowedInputs, executor, permission); } - public IntegerCommandNode(@NotNull String name, @NotNull List> children, @NotNull AllowedNumberInputs allowedInputs, @Nullable String permission) { + public IntegerCommandNode(@NotNull String name, @NotNull List> children, @NotNull AllowedIntegerInputs allowedInputs, @Nullable String permission) { this(name, children, allowedInputs, null, permission); } - public IntegerCommandNode(@NotNull String name, @NotNull AllowedNumberInputs allowedInputs, @Nullable String permission) { + public IntegerCommandNode(@NotNull String name, @NotNull AllowedIntegerInputs allowedInputs, @Nullable String permission) { this(name, List.of(), allowedInputs, null, permission); } - public IntegerCommandNode(@NotNull String name, @NotNull List> children, @NotNull AllowedNumberInputs allowedInputs, @Nullable CommandNodeExecutor executor) { + public IntegerCommandNode(@NotNull String name, @NotNull List> children, @NotNull AllowedIntegerInputs allowedInputs, @Nullable CommandNodeExecutor executor) { super(name, children, allowedInputs, executor, null); } - public IntegerCommandNode(@NotNull String name, @NotNull AllowedNumberInputs allowedInputs, @Nullable CommandNodeExecutor executor) { + public IntegerCommandNode(@NotNull String name, @NotNull AllowedIntegerInputs allowedInputs, @Nullable CommandNodeExecutor executor) { this(name, List.of(), allowedInputs, executor, null); } - public IntegerCommandNode(@NotNull String name, @NotNull List> children, @NotNull AllowedNumberInputs allowedInputs) { + public IntegerCommandNode(@NotNull String name, @NotNull List> children, @NotNull AllowedIntegerInputs allowedInputs) { this(name, children, allowedInputs, null, null); } - public IntegerCommandNode(@NotNull String name, @NotNull AllowedNumberInputs allowedInputs) { + public IntegerCommandNode(@NotNull String name, @NotNull AllowedIntegerInputs allowedInputs) { this(name, List.of(), allowedInputs, null, null); } @Override - public @NotNull AllowedNumberInputs getAllowedInputs() { - return (AllowedNumberInputs) super.getAllowedInputs(); + public @NotNull AllowedIntegerInputs getAllowedInputs() { + return (AllowedIntegerInputs) super.getAllowedInputs(); } @Override @@ -67,7 +68,7 @@ public IntegerCommandNode(@NotNull String name, @NotNull AllowedNumberInputs withPermission(@Nullable String permission) { + public @NotNull IntegerCommandNode withPermission(@Nullable String permission) { return new IntegerCommandNode(getName(), getChildren(), getAllowedInputs(), getExecutor(), permission); } } diff --git a/commands/src/main/java/com/wizardlybump17/wlib/command/node/primitive/number/LongCommandNode.java b/commands/src/main/java/com/wizardlybump17/wlib/command/node/primitive/number/LongCommandNode.java new file mode 100644 index 00000000..3d6fc919 --- /dev/null +++ b/commands/src/main/java/com/wizardlybump17/wlib/command/node/primitive/number/LongCommandNode.java @@ -0,0 +1,74 @@ +package com.wizardlybump17.wlib.command.node.primitive.number; + +import com.wizardlybump17.wlib.command.exception.InputParsingException; +import com.wizardlybump17.wlib.command.executor.CommandNodeExecutor; +import com.wizardlybump17.wlib.command.input.primitive.number.AllowedLongInputs; +import com.wizardlybump17.wlib.command.node.CommandNode; +import org.jetbrains.annotations.NotNull; +import org.jetbrains.annotations.Nullable; + +import java.util.List; + +public class LongCommandNode extends CommandNode { + + public LongCommandNode(@NotNull String name, @NotNull List> children, @NotNull AllowedLongInputs allowedInputs, @Nullable CommandNodeExecutor executor, @Nullable String permission) { + super(name, children, allowedInputs, executor, permission); + } + + public LongCommandNode(@NotNull String name, @NotNull AllowedLongInputs allowedInputs, @Nullable CommandNodeExecutor executor, @Nullable String permission) { + this(name, List.of(), allowedInputs, executor, permission); + } + + public LongCommandNode(@NotNull String name, @NotNull List> children, @NotNull AllowedLongInputs allowedInputs, @Nullable String permission) { + this(name, children, allowedInputs, null, permission); + } + + public LongCommandNode(@NotNull String name, @NotNull AllowedLongInputs allowedInputs, @Nullable String permission) { + this(name, List.of(), allowedInputs, null, permission); + } + + public LongCommandNode(@NotNull String name, @NotNull List> children, @NotNull AllowedLongInputs allowedInputs, @Nullable CommandNodeExecutor executor) { + super(name, children, allowedInputs, executor, null); + } + + public LongCommandNode(@NotNull String name, @NotNull AllowedLongInputs allowedInputs, @Nullable CommandNodeExecutor executor) { + this(name, List.of(), allowedInputs, executor, null); + } + + public LongCommandNode(@NotNull String name, @NotNull List> children, @NotNull AllowedLongInputs allowedInputs) { + this(name, children, allowedInputs, null, null); + } + + public LongCommandNode(@NotNull String name, @NotNull AllowedLongInputs allowedInputs) { + this(name, List.of(), allowedInputs, null, null); + } + + @Override + public @NotNull AllowedLongInputs getAllowedInputs() { + return (AllowedLongInputs) super.getAllowedInputs(); + } + + @Override + public @NotNull Long parse(@NotNull String input) throws InputParsingException { + try { + return Long.parseLong(input); + } catch (NumberFormatException e) { + throw new InputParsingException("Could not parse as short: " + input, e); + } + } + + @Override + public @NotNull LongCommandNode withChildren(@NotNull List> children) { + return new LongCommandNode(getName(), children, getAllowedInputs(), getExecutor(), getPermission()); + } + + @Override + public @NotNull LongCommandNode withExecutor(@Nullable CommandNodeExecutor executor) { + return new LongCommandNode(getName(), getChildren(), getAllowedInputs(), executor, getPermission()); + } + + @Override + public @NotNull LongCommandNode withPermission(@Nullable String permission) { + return new LongCommandNode(getName(), getChildren(), getAllowedInputs(), getExecutor(), permission); + } +} diff --git a/commands/src/main/java/com/wizardlybump17/wlib/command/node/primitive/number/ShortCommandNode.java b/commands/src/main/java/com/wizardlybump17/wlib/command/node/primitive/number/ShortCommandNode.java new file mode 100644 index 00000000..436cd7ea --- /dev/null +++ b/commands/src/main/java/com/wizardlybump17/wlib/command/node/primitive/number/ShortCommandNode.java @@ -0,0 +1,74 @@ +package com.wizardlybump17.wlib.command.node.primitive.number; + +import com.wizardlybump17.wlib.command.exception.InputParsingException; +import com.wizardlybump17.wlib.command.executor.CommandNodeExecutor; +import com.wizardlybump17.wlib.command.input.primitive.number.AllowedShortInputs; +import com.wizardlybump17.wlib.command.node.CommandNode; +import org.jetbrains.annotations.NotNull; +import org.jetbrains.annotations.Nullable; + +import java.util.List; + +public class ShortCommandNode extends CommandNode { + + public ShortCommandNode(@NotNull String name, @NotNull List> children, @NotNull AllowedShortInputs allowedInputs, @Nullable CommandNodeExecutor executor, @Nullable String permission) { + super(name, children, allowedInputs, executor, permission); + } + + public ShortCommandNode(@NotNull String name, @NotNull AllowedShortInputs allowedInputs, @Nullable CommandNodeExecutor executor, @Nullable String permission) { + this(name, List.of(), allowedInputs, executor, permission); + } + + public ShortCommandNode(@NotNull String name, @NotNull List> children, @NotNull AllowedShortInputs allowedInputs, @Nullable String permission) { + this(name, children, allowedInputs, null, permission); + } + + public ShortCommandNode(@NotNull String name, @NotNull AllowedShortInputs allowedInputs, @Nullable String permission) { + this(name, List.of(), allowedInputs, null, permission); + } + + public ShortCommandNode(@NotNull String name, @NotNull List> children, @NotNull AllowedShortInputs allowedInputs, @Nullable CommandNodeExecutor executor) { + super(name, children, allowedInputs, executor, null); + } + + public ShortCommandNode(@NotNull String name, @NotNull AllowedShortInputs allowedInputs, @Nullable CommandNodeExecutor executor) { + this(name, List.of(), allowedInputs, executor, null); + } + + public ShortCommandNode(@NotNull String name, @NotNull List> children, @NotNull AllowedShortInputs allowedInputs) { + this(name, children, allowedInputs, null, null); + } + + public ShortCommandNode(@NotNull String name, @NotNull AllowedShortInputs allowedInputs) { + this(name, List.of(), allowedInputs, null, null); + } + + @Override + public @NotNull AllowedShortInputs getAllowedInputs() { + return (AllowedShortInputs) super.getAllowedInputs(); + } + + @Override + public @NotNull Short parse(@NotNull String input) throws InputParsingException { + try { + return Short.parseShort(input); + } catch (NumberFormatException e) { + throw new InputParsingException("Could not parse as short: " + input, e); + } + } + + @Override + public @NotNull ShortCommandNode withChildren(@NotNull List> children) { + return new ShortCommandNode(getName(), children, getAllowedInputs(), getExecutor(), getPermission()); + } + + @Override + public @NotNull ShortCommandNode withExecutor(@Nullable CommandNodeExecutor executor) { + return new ShortCommandNode(getName(), getChildren(), getAllowedInputs(), executor, getPermission()); + } + + @Override + public @NotNull ShortCommandNode withPermission(@Nullable String permission) { + return new ShortCommandNode(getName(), getChildren(), getAllowedInputs(), getExecutor(), permission); + } +} diff --git a/commands/src/test/java/com/wizardlybump17/wlib/test/command/CommandTests.java b/commands/src/test/java/com/wizardlybump17/wlib/test/command/CommandTests.java index 54dcc0d4..95985fc9 100644 --- a/commands/src/test/java/com/wizardlybump17/wlib/test/command/CommandTests.java +++ b/commands/src/test/java/com/wizardlybump17/wlib/test/command/CommandTests.java @@ -3,8 +3,8 @@ import com.wizardlybump17.wlib.command.Command; import com.wizardlybump17.wlib.command.exception.InputParsingException; import com.wizardlybump17.wlib.command.input.primitive.number.AllowedNumberInputs; -import com.wizardlybump17.wlib.command.node.IntegerCommandNode; import com.wizardlybump17.wlib.command.node.LiteralCommandNode; +import com.wizardlybump17.wlib.command.node.primitive.number.IntegerCommandNode; import com.wizardlybump17.wlib.command.result.CommandResult; import com.wizardlybump17.wlib.command.result.error.*; import com.wizardlybump17.wlib.command.sender.BasicCommandSender; diff --git a/commands/src/test/java/com/wizardlybump17/wlib/test/command/SuggestionTests.java b/commands/src/test/java/com/wizardlybump17/wlib/test/command/SuggestionTests.java index 73a29e8d..54ba2ccf 100644 --- a/commands/src/test/java/com/wizardlybump17/wlib/test/command/SuggestionTests.java +++ b/commands/src/test/java/com/wizardlybump17/wlib/test/command/SuggestionTests.java @@ -2,8 +2,8 @@ import com.wizardlybump17.wlib.command.Command; import com.wizardlybump17.wlib.command.input.primitive.number.AllowedIntegerInputs; -import com.wizardlybump17.wlib.command.node.IntegerCommandNode; import com.wizardlybump17.wlib.command.node.LiteralCommandNode; +import com.wizardlybump17.wlib.command.node.primitive.number.IntegerCommandNode; import com.wizardlybump17.wlib.command.result.CommandResult; import com.wizardlybump17.wlib.command.sender.BasicCommandSender; import com.wizardlybump17.wlib.command.sender.CommandSender; diff --git a/commands/src/test/java/com/wizardlybump17/wlib/test/command/extractor/method/MethodCommandExtractorStructureTests.java b/commands/src/test/java/com/wizardlybump17/wlib/test/command/extractor/method/MethodCommandExtractorStructureTests.java index b0cd1bbf..dbc8e493 100644 --- a/commands/src/test/java/com/wizardlybump17/wlib/test/command/extractor/method/MethodCommandExtractorStructureTests.java +++ b/commands/src/test/java/com/wizardlybump17/wlib/test/command/extractor/method/MethodCommandExtractorStructureTests.java @@ -6,9 +6,9 @@ import com.wizardlybump17.wlib.command.input.primitive.number.AllowedIntegerInputs; import com.wizardlybump17.wlib.command.input.string.AllowedStringInputs; import com.wizardlybump17.wlib.command.node.CommandNode; -import com.wizardlybump17.wlib.command.node.IntegerCommandNode; import com.wizardlybump17.wlib.command.node.LiteralCommandNode; import com.wizardlybump17.wlib.command.node.StringCommandNode; +import com.wizardlybump17.wlib.command.node.primitive.number.IntegerCommandNode; import com.wizardlybump17.wlib.command.registry.MethodCommandNodeFactoryRegistry; import com.wizardlybump17.wlib.test.util.AssertionUtil; import org.jetbrains.annotations.NotNull; diff --git a/commands/src/test/java/com/wizardlybump17/wlib/test/command/extractor/method/MethodCommandExtractorTests.java b/commands/src/test/java/com/wizardlybump17/wlib/test/command/extractor/method/MethodCommandExtractorTests.java index 69037da0..d4317f9c 100644 --- a/commands/src/test/java/com/wizardlybump17/wlib/test/command/extractor/method/MethodCommandExtractorTests.java +++ b/commands/src/test/java/com/wizardlybump17/wlib/test/command/extractor/method/MethodCommandExtractorTests.java @@ -9,9 +9,9 @@ import com.wizardlybump17.wlib.command.input.string.AllowedStringInputs; import com.wizardlybump17.wlib.command.manager.CommandManager; import com.wizardlybump17.wlib.command.node.CommandNode; -import com.wizardlybump17.wlib.command.node.IntegerCommandNode; import com.wizardlybump17.wlib.command.node.LiteralCommandNode; import com.wizardlybump17.wlib.command.node.StringCommandNode; +import com.wizardlybump17.wlib.command.node.primitive.number.IntegerCommandNode; import com.wizardlybump17.wlib.command.registry.MethodCommandNodeFactoryRegistry; import com.wizardlybump17.wlib.command.result.CommandResult; import com.wizardlybump17.wlib.command.sender.BasicCommandSender; diff --git a/commands/src/test/java/com/wizardlybump17/wlib/test/command/manager/CommandManagerSuggestionTests.java b/commands/src/test/java/com/wizardlybump17/wlib/test/command/manager/CommandManagerSuggestionTests.java index 5cc62aa0..2121effb 100644 --- a/commands/src/test/java/com/wizardlybump17/wlib/test/command/manager/CommandManagerSuggestionTests.java +++ b/commands/src/test/java/com/wizardlybump17/wlib/test/command/manager/CommandManagerSuggestionTests.java @@ -3,8 +3,8 @@ import com.wizardlybump17.wlib.command.Command; import com.wizardlybump17.wlib.command.input.primitive.number.AllowedIntegerInputs; import com.wizardlybump17.wlib.command.manager.CommandManager; -import com.wizardlybump17.wlib.command.node.IntegerCommandNode; import com.wizardlybump17.wlib.command.node.LiteralCommandNode; +import com.wizardlybump17.wlib.command.node.primitive.number.IntegerCommandNode; import com.wizardlybump17.wlib.command.result.CommandResult; import com.wizardlybump17.wlib.command.sender.BasicCommandSender; import com.wizardlybump17.wlib.command.sender.CommandSender; From 035077d9326642b867d592e50c8ecf3659ee1f6d Mon Sep 17 00:00:00 2001 From: WizardlyBump17 Date: Tue, 25 Nov 2025 20:10:04 -0300 Subject: [PATCH 161/363] more! --- .../command/node/object/UUIDCommandNode.java | 71 +++++++++++++++++++ .../node/{ => string}/StringCommandNode.java | 3 +- .../MethodCommandNodeFactoryRegistry.java | 9 +++ .../MethodCommandExtractorStructureTests.java | 2 +- .../method/MethodCommandExtractorTests.java | 2 +- 5 files changed, 84 insertions(+), 3 deletions(-) create mode 100644 commands/src/main/java/com/wizardlybump17/wlib/command/node/object/UUIDCommandNode.java rename commands/src/main/java/com/wizardlybump17/wlib/command/node/{ => string}/StringCommandNode.java (96%) diff --git a/commands/src/main/java/com/wizardlybump17/wlib/command/node/object/UUIDCommandNode.java b/commands/src/main/java/com/wizardlybump17/wlib/command/node/object/UUIDCommandNode.java new file mode 100644 index 00000000..e0a8263f --- /dev/null +++ b/commands/src/main/java/com/wizardlybump17/wlib/command/node/object/UUIDCommandNode.java @@ -0,0 +1,71 @@ +package com.wizardlybump17.wlib.command.node.object; + +import com.wizardlybump17.wlib.command.exception.InputParsingException; +import com.wizardlybump17.wlib.command.executor.CommandNodeExecutor; +import com.wizardlybump17.wlib.command.input.object.AllowedUUIDInputs; +import com.wizardlybump17.wlib.command.node.CommandNode; +import org.jetbrains.annotations.NotNull; +import org.jetbrains.annotations.Nullable; + +import java.util.List; +import java.util.UUID; + +public class UUIDCommandNode extends CommandNode { + + public UUIDCommandNode(@NotNull String name, @NotNull List> children, @NotNull AllowedUUIDInputs allowedInputs, @Nullable CommandNodeExecutor executor, @Nullable String permission) { + super(name, children, allowedInputs, executor, permission); + } + + public UUIDCommandNode(@NotNull String name, @NotNull AllowedUUIDInputs allowedInputs, @Nullable CommandNodeExecutor executor, @Nullable String permission) { + super(name, allowedInputs, executor, permission); + } + + public UUIDCommandNode(@NotNull String name, @NotNull List> children, @NotNull AllowedUUIDInputs allowedInputs, @Nullable String permission) { + super(name, children, allowedInputs, permission); + } + + public UUIDCommandNode(@NotNull String name, @NotNull AllowedUUIDInputs allowedInputs, @Nullable String permission) { + super(name, allowedInputs, permission); + } + + public UUIDCommandNode(@NotNull String name, @NotNull AllowedUUIDInputs allowedInputs, @Nullable CommandNodeExecutor executor) { + super(name, allowedInputs, executor); + } + + public UUIDCommandNode(@NotNull String name, @NotNull List> children, @NotNull AllowedUUIDInputs allowedInputs) { + super(name, children, allowedInputs); + } + + public UUIDCommandNode(@NotNull String name, @NotNull AllowedUUIDInputs allowedInputs) { + super(name, allowedInputs); + } + + @Override + public @NotNull AllowedUUIDInputs getAllowedInputs() { + return (AllowedUUIDInputs) super.getAllowedInputs(); + } + + @Override + public @Nullable UUID parse(@NotNull String input) throws InputParsingException { + try { + return UUID.fromString(input); + } catch (IllegalArgumentException e) { + throw new InputParsingException("Could not parse as UUID: " + input, e); + } + } + + @Override + public @NotNull UUIDCommandNode withChildren(@NotNull List> children) { + return new UUIDCommandNode(getName(), children, getAllowedInputs(), getExecutor(), getPermission()); + } + + @Override + public @NotNull UUIDCommandNode withExecutor(@Nullable CommandNodeExecutor executor) { + return new UUIDCommandNode(getName(), getChildren(), getAllowedInputs(), executor, getPermission()); + } + + @Override + public @NotNull UUIDCommandNode withPermission(@Nullable String permission) { + return new UUIDCommandNode(getName(), getChildren(), getAllowedInputs(), getExecutor(), permission); + } +} diff --git a/commands/src/main/java/com/wizardlybump17/wlib/command/node/StringCommandNode.java b/commands/src/main/java/com/wizardlybump17/wlib/command/node/string/StringCommandNode.java similarity index 96% rename from commands/src/main/java/com/wizardlybump17/wlib/command/node/StringCommandNode.java rename to commands/src/main/java/com/wizardlybump17/wlib/command/node/string/StringCommandNode.java index 578a9aea..a34be7b8 100644 --- a/commands/src/main/java/com/wizardlybump17/wlib/command/node/StringCommandNode.java +++ b/commands/src/main/java/com/wizardlybump17/wlib/command/node/string/StringCommandNode.java @@ -1,8 +1,9 @@ -package com.wizardlybump17.wlib.command.node; +package com.wizardlybump17.wlib.command.node.string; import com.wizardlybump17.wlib.command.exception.InputParsingException; import com.wizardlybump17.wlib.command.executor.CommandNodeExecutor; import com.wizardlybump17.wlib.command.input.AllowedInputs; +import com.wizardlybump17.wlib.command.node.CommandNode; import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.Nullable; diff --git a/commands/src/main/java/com/wizardlybump17/wlib/command/registry/MethodCommandNodeFactoryRegistry.java b/commands/src/main/java/com/wizardlybump17/wlib/command/registry/MethodCommandNodeFactoryRegistry.java index ad366572..3dcdc5d8 100644 --- a/commands/src/main/java/com/wizardlybump17/wlib/command/registry/MethodCommandNodeFactoryRegistry.java +++ b/commands/src/main/java/com/wizardlybump17/wlib/command/registry/MethodCommandNodeFactoryRegistry.java @@ -1,6 +1,7 @@ package com.wizardlybump17.wlib.command.registry; import com.wizardlybump17.wlib.command.extractor.method.factory.MethodCommandNodeFactory; +import org.jetbrains.annotations.ApiStatus; import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.Nullable; import org.jetbrains.annotations.Unmodifiable; @@ -55,4 +56,12 @@ public boolean hasFactory(@NotNull Class clazz) { public void clear() { factories.clear(); } + + @ApiStatus.Internal + public void registerDefaults() { + } + + @ApiStatus.Internal + public void unregisterDefaults() { + } } diff --git a/commands/src/test/java/com/wizardlybump17/wlib/test/command/extractor/method/MethodCommandExtractorStructureTests.java b/commands/src/test/java/com/wizardlybump17/wlib/test/command/extractor/method/MethodCommandExtractorStructureTests.java index dbc8e493..f9604a01 100644 --- a/commands/src/test/java/com/wizardlybump17/wlib/test/command/extractor/method/MethodCommandExtractorStructureTests.java +++ b/commands/src/test/java/com/wizardlybump17/wlib/test/command/extractor/method/MethodCommandExtractorStructureTests.java @@ -7,8 +7,8 @@ import com.wizardlybump17.wlib.command.input.string.AllowedStringInputs; import com.wizardlybump17.wlib.command.node.CommandNode; import com.wizardlybump17.wlib.command.node.LiteralCommandNode; -import com.wizardlybump17.wlib.command.node.StringCommandNode; import com.wizardlybump17.wlib.command.node.primitive.number.IntegerCommandNode; +import com.wizardlybump17.wlib.command.node.string.StringCommandNode; import com.wizardlybump17.wlib.command.registry.MethodCommandNodeFactoryRegistry; import com.wizardlybump17.wlib.test.util.AssertionUtil; import org.jetbrains.annotations.NotNull; diff --git a/commands/src/test/java/com/wizardlybump17/wlib/test/command/extractor/method/MethodCommandExtractorTests.java b/commands/src/test/java/com/wizardlybump17/wlib/test/command/extractor/method/MethodCommandExtractorTests.java index d4317f9c..ea77b833 100644 --- a/commands/src/test/java/com/wizardlybump17/wlib/test/command/extractor/method/MethodCommandExtractorTests.java +++ b/commands/src/test/java/com/wizardlybump17/wlib/test/command/extractor/method/MethodCommandExtractorTests.java @@ -10,8 +10,8 @@ import com.wizardlybump17.wlib.command.manager.CommandManager; import com.wizardlybump17.wlib.command.node.CommandNode; import com.wizardlybump17.wlib.command.node.LiteralCommandNode; -import com.wizardlybump17.wlib.command.node.StringCommandNode; import com.wizardlybump17.wlib.command.node.primitive.number.IntegerCommandNode; +import com.wizardlybump17.wlib.command.node.string.StringCommandNode; import com.wizardlybump17.wlib.command.registry.MethodCommandNodeFactoryRegistry; import com.wizardlybump17.wlib.command.result.CommandResult; import com.wizardlybump17.wlib.command.sender.BasicCommandSender; From b22afd12cb9e0630219a6efeec6ff005da0036c0 Mon Sep 17 00:00:00 2001 From: WizardlyBump17 Date: Tue, 25 Nov 2025 20:10:37 -0300 Subject: [PATCH 162/363] renamed --- ...dInputs.java => AllowedBooleanInputs.java} | 8 ++++---- ...nputs.java => AllowedCharacterInputs.java} | 8 ++++---- .../node/primitive/BooleanCommandNode.java | 20 +++++++++---------- .../node/primitive/CharacterCommandNode.java | 20 +++++++++---------- 4 files changed, 28 insertions(+), 28 deletions(-) rename commands/src/main/java/com/wizardlybump17/wlib/command/input/primitive/{BooleanAllowedInputs.java => AllowedBooleanInputs.java} (90%) rename commands/src/main/java/com/wizardlybump17/wlib/command/input/primitive/{CharacterAllowedInputs.java => AllowedCharacterInputs.java} (95%) diff --git a/commands/src/main/java/com/wizardlybump17/wlib/command/input/primitive/BooleanAllowedInputs.java b/commands/src/main/java/com/wizardlybump17/wlib/command/input/primitive/AllowedBooleanInputs.java similarity index 90% rename from commands/src/main/java/com/wizardlybump17/wlib/command/input/primitive/BooleanAllowedInputs.java rename to commands/src/main/java/com/wizardlybump17/wlib/command/input/primitive/AllowedBooleanInputs.java index 4ffdac69..b4c7c5bd 100644 --- a/commands/src/main/java/com/wizardlybump17/wlib/command/input/primitive/BooleanAllowedInputs.java +++ b/commands/src/main/java/com/wizardlybump17/wlib/command/input/primitive/AllowedBooleanInputs.java @@ -7,7 +7,7 @@ import java.util.Objects; -public interface BooleanAllowedInputs extends AllowedInputs { +public interface AllowedBooleanInputs extends AllowedInputs { static @NotNull True trueValue() { return True.INSTANCE; @@ -25,7 +25,7 @@ public interface BooleanAllowedInputs extends AllowedInputs { return Any.NOT_NULL; } - final class True implements BooleanAllowedInputs, SingleValueInput { + final class True implements AllowedBooleanInputs, SingleValueInput { private static final @NotNull True INSTANCE = new True(); @@ -43,7 +43,7 @@ public String toString() { } } - final class False implements BooleanAllowedInputs, SingleValueInput { + final class False implements AllowedBooleanInputs, SingleValueInput { private static final @NotNull False INSTANCE = new False(); @@ -61,7 +61,7 @@ public String toString() { } } - final class Any implements BooleanAllowedInputs { + final class Any implements AllowedBooleanInputs { private static final @NotNull Any NULLABLE = new Any(true); private static final @NotNull Any NOT_NULL = new Any(false); diff --git a/commands/src/main/java/com/wizardlybump17/wlib/command/input/primitive/CharacterAllowedInputs.java b/commands/src/main/java/com/wizardlybump17/wlib/command/input/primitive/AllowedCharacterInputs.java similarity index 95% rename from commands/src/main/java/com/wizardlybump17/wlib/command/input/primitive/CharacterAllowedInputs.java rename to commands/src/main/java/com/wizardlybump17/wlib/command/input/primitive/AllowedCharacterInputs.java index 6a27f3e2..d275de83 100644 --- a/commands/src/main/java/com/wizardlybump17/wlib/command/input/primitive/CharacterAllowedInputs.java +++ b/commands/src/main/java/com/wizardlybump17/wlib/command/input/primitive/AllowedCharacterInputs.java @@ -10,7 +10,7 @@ import java.util.Objects; import java.util.stream.Collectors; -public interface CharacterAllowedInputs extends AllowedInputs { +public interface AllowedCharacterInputs extends AllowedInputs { static @NotNull Value value(char value) { return new Value(value, false); @@ -48,7 +48,7 @@ public interface CharacterAllowedInputs extends AllowedInputs { return Any.NOT_NULL; } - final class Value implements CharacterAllowedInputs, SingleValueInput { + final class Value implements AllowedCharacterInputs, SingleValueInput { private final char value; private final boolean ignoreCase; @@ -96,7 +96,7 @@ public String toString() { } } - final class Values implements CharacterAllowedInputs, AllowedListInputs { + final class Values implements AllowedCharacterInputs, AllowedListInputs { private final @NotNull List values; private final @NotNull List toCheck; @@ -148,7 +148,7 @@ public String toString() { } } - final class Any implements CharacterAllowedInputs { + final class Any implements AllowedCharacterInputs { private static final @NotNull Any NULLABLE = new Any(true); private static final @NotNull Any NOT_NULL = new Any(false); diff --git a/commands/src/main/java/com/wizardlybump17/wlib/command/node/primitive/BooleanCommandNode.java b/commands/src/main/java/com/wizardlybump17/wlib/command/node/primitive/BooleanCommandNode.java index 082d4e25..d3689adb 100644 --- a/commands/src/main/java/com/wizardlybump17/wlib/command/node/primitive/BooleanCommandNode.java +++ b/commands/src/main/java/com/wizardlybump17/wlib/command/node/primitive/BooleanCommandNode.java @@ -2,7 +2,7 @@ import com.wizardlybump17.wlib.command.exception.InputParsingException; import com.wizardlybump17.wlib.command.executor.CommandNodeExecutor; -import com.wizardlybump17.wlib.command.input.primitive.BooleanAllowedInputs; +import com.wizardlybump17.wlib.command.input.primitive.AllowedBooleanInputs; import com.wizardlybump17.wlib.command.node.CommandNode; import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.Nullable; @@ -11,37 +11,37 @@ public class BooleanCommandNode extends CommandNode { - public BooleanCommandNode(@NotNull String name, @NotNull List> children, @NotNull BooleanAllowedInputs allowedInputs, @Nullable CommandNodeExecutor executor, @Nullable String permission) { + public BooleanCommandNode(@NotNull String name, @NotNull List> children, @NotNull AllowedBooleanInputs allowedInputs, @Nullable CommandNodeExecutor executor, @Nullable String permission) { super(name, children, allowedInputs, executor, permission); } - public BooleanCommandNode(@NotNull String name, @NotNull BooleanAllowedInputs allowedInputs, @Nullable CommandNodeExecutor executor, @Nullable String permission) { + public BooleanCommandNode(@NotNull String name, @NotNull AllowedBooleanInputs allowedInputs, @Nullable CommandNodeExecutor executor, @Nullable String permission) { super(name, allowedInputs, executor, permission); } - public BooleanCommandNode(@NotNull String name, @NotNull List> children, @NotNull BooleanAllowedInputs allowedInputs, @Nullable String permission) { + public BooleanCommandNode(@NotNull String name, @NotNull List> children, @NotNull AllowedBooleanInputs allowedInputs, @Nullable String permission) { super(name, children, allowedInputs, permission); } - public BooleanCommandNode(@NotNull String name, @NotNull BooleanAllowedInputs allowedInputs, @Nullable String permission) { + public BooleanCommandNode(@NotNull String name, @NotNull AllowedBooleanInputs allowedInputs, @Nullable String permission) { super(name, allowedInputs, permission); } - public BooleanCommandNode(@NotNull String name, @NotNull BooleanAllowedInputs allowedInputs, @Nullable CommandNodeExecutor executor) { + public BooleanCommandNode(@NotNull String name, @NotNull AllowedBooleanInputs allowedInputs, @Nullable CommandNodeExecutor executor) { super(name, allowedInputs, executor); } - public BooleanCommandNode(@NotNull String name, @NotNull List> children, @NotNull BooleanAllowedInputs allowedInputs) { + public BooleanCommandNode(@NotNull String name, @NotNull List> children, @NotNull AllowedBooleanInputs allowedInputs) { super(name, children, allowedInputs); } - public BooleanCommandNode(@NotNull String name, @NotNull BooleanAllowedInputs allowedInputs) { + public BooleanCommandNode(@NotNull String name, @NotNull AllowedBooleanInputs allowedInputs) { super(name, allowedInputs); } @Override - public @NotNull BooleanAllowedInputs getAllowedInputs() { - return (BooleanAllowedInputs) super.getAllowedInputs(); + public @NotNull AllowedBooleanInputs getAllowedInputs() { + return (AllowedBooleanInputs) super.getAllowedInputs(); } @Override diff --git a/commands/src/main/java/com/wizardlybump17/wlib/command/node/primitive/CharacterCommandNode.java b/commands/src/main/java/com/wizardlybump17/wlib/command/node/primitive/CharacterCommandNode.java index 22946afa..3f963b68 100644 --- a/commands/src/main/java/com/wizardlybump17/wlib/command/node/primitive/CharacterCommandNode.java +++ b/commands/src/main/java/com/wizardlybump17/wlib/command/node/primitive/CharacterCommandNode.java @@ -2,7 +2,7 @@ import com.wizardlybump17.wlib.command.exception.InputParsingException; import com.wizardlybump17.wlib.command.executor.CommandNodeExecutor; -import com.wizardlybump17.wlib.command.input.primitive.CharacterAllowedInputs; +import com.wizardlybump17.wlib.command.input.primitive.AllowedCharacterInputs; import com.wizardlybump17.wlib.command.node.CommandNode; import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.Nullable; @@ -11,37 +11,37 @@ public class CharacterCommandNode extends CommandNode { - public CharacterCommandNode(@NotNull String name, @NotNull List> children, @NotNull CharacterAllowedInputs allowedInputs, @Nullable CommandNodeExecutor executor, @Nullable String permission) { + public CharacterCommandNode(@NotNull String name, @NotNull List> children, @NotNull AllowedCharacterInputs allowedInputs, @Nullable CommandNodeExecutor executor, @Nullable String permission) { super(name, children, allowedInputs, executor, permission); } - public CharacterCommandNode(@NotNull String name, @NotNull CharacterAllowedInputs allowedInputs, @Nullable CommandNodeExecutor executor, @Nullable String permission) { + public CharacterCommandNode(@NotNull String name, @NotNull AllowedCharacterInputs allowedInputs, @Nullable CommandNodeExecutor executor, @Nullable String permission) { super(name, allowedInputs, executor, permission); } - public CharacterCommandNode(@NotNull String name, @NotNull List> children, @NotNull CharacterAllowedInputs allowedInputs, @Nullable String permission) { + public CharacterCommandNode(@NotNull String name, @NotNull List> children, @NotNull AllowedCharacterInputs allowedInputs, @Nullable String permission) { super(name, children, allowedInputs, permission); } - public CharacterCommandNode(@NotNull String name, @NotNull CharacterAllowedInputs allowedInputs, @Nullable String permission) { + public CharacterCommandNode(@NotNull String name, @NotNull AllowedCharacterInputs allowedInputs, @Nullable String permission) { super(name, allowedInputs, permission); } - public CharacterCommandNode(@NotNull String name, @NotNull CharacterAllowedInputs allowedInputs, @Nullable CommandNodeExecutor executor) { + public CharacterCommandNode(@NotNull String name, @NotNull AllowedCharacterInputs allowedInputs, @Nullable CommandNodeExecutor executor) { super(name, allowedInputs, executor); } - public CharacterCommandNode(@NotNull String name, @NotNull List> children, @NotNull CharacterAllowedInputs allowedInputs) { + public CharacterCommandNode(@NotNull String name, @NotNull List> children, @NotNull AllowedCharacterInputs allowedInputs) { super(name, children, allowedInputs); } - public CharacterCommandNode(@NotNull String name, @NotNull CharacterAllowedInputs allowedInputs) { + public CharacterCommandNode(@NotNull String name, @NotNull AllowedCharacterInputs allowedInputs) { super(name, allowedInputs); } @Override - public @NotNull CharacterAllowedInputs getAllowedInputs() { - return (CharacterAllowedInputs) super.getAllowedInputs(); + public @NotNull AllowedCharacterInputs getAllowedInputs() { + return (AllowedCharacterInputs) super.getAllowedInputs(); } @Override From 62d5cfec7c761cc1459452740110cd855fc9660e Mon Sep 17 00:00:00 2001 From: WizardlyBump17 Date: Tue, 25 Nov 2025 20:12:32 -0300 Subject: [PATCH 163/363] yea, i did that --- .../com/wizardlybump17/wlib/test/command/CommandTests.java | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/commands/src/test/java/com/wizardlybump17/wlib/test/command/CommandTests.java b/commands/src/test/java/com/wizardlybump17/wlib/test/command/CommandTests.java index 95985fc9..4d17f82f 100644 --- a/commands/src/test/java/com/wizardlybump17/wlib/test/command/CommandTests.java +++ b/commands/src/test/java/com/wizardlybump17/wlib/test/command/CommandTests.java @@ -2,7 +2,7 @@ import com.wizardlybump17.wlib.command.Command; import com.wizardlybump17.wlib.command.exception.InputParsingException; -import com.wizardlybump17.wlib.command.input.primitive.number.AllowedNumberInputs; +import com.wizardlybump17.wlib.command.input.primitive.number.AllowedIntegerInputs; import com.wizardlybump17.wlib.command.node.LiteralCommandNode; import com.wizardlybump17.wlib.command.node.primitive.number.IntegerCommandNode; import com.wizardlybump17.wlib.command.result.CommandResult; @@ -185,7 +185,7 @@ void testOutOfRange() { @Test void testParseInputException() { - IntegerCommandNode worldNode = new IntegerCommandNode("world", AllowedNumberInputs.value(10), context -> CommandResult.successful(context, 10)); + IntegerCommandNode worldNode = new IntegerCommandNode("world", AllowedIntegerInputs.value(10), context -> CommandResult.successful(context, 10)); Command command = new Command(new LiteralCommandNode("hello", List.of(worldNode))); ParseInputExceptionResult expected = CommandResult.parseInputException(1, worldNode, new InputParsingException("Could not parse as int: world", new NumberFormatException("For input string: \"world\""))); From 46a5a00e09410dbe059d2082812609773baa8977 Mon Sep 17 00:00:00 2001 From: WizardlyBump17 Date: Tue, 25 Nov 2025 20:19:37 -0300 Subject: [PATCH 164/363] always be sure --- .../extractor/method/MethodCommandExtractor.java | 2 +- .../method/factory/MethodCommandNodeFactory.java | 4 ++-- .../registry/MethodCommandNodeFactoryRegistry.java | 10 +++++----- .../method/MethodCommandExtractorStructureTests.java | 4 ++-- .../extractor/method/MethodCommandExtractorTests.java | 4 ++-- 5 files changed, 12 insertions(+), 12 deletions(-) diff --git a/commands/src/main/java/com/wizardlybump17/wlib/command/extractor/method/MethodCommandExtractor.java b/commands/src/main/java/com/wizardlybump17/wlib/command/extractor/method/MethodCommandExtractor.java index b9e4c60e..8a67389a 100644 --- a/commands/src/main/java/com/wizardlybump17/wlib/command/extractor/method/MethodCommandExtractor.java +++ b/commands/src/main/java/com/wizardlybump17/wlib/command/extractor/method/MethodCommandExtractor.java @@ -83,7 +83,7 @@ public boolean isAccepted(@NotNull Object object) { Parameter parameter = parameters[parameterIndex]; Class parameterType = parameter.getType(); - MethodCommandNodeFactory factory = MethodCommandNodeFactoryRegistry.INSTANCE.getFactory(parameterType); + MethodCommandNodeFactory factory = MethodCommandNodeFactoryRegistry.INSTANCE.getFactory(parameterType); if (factory == null) throw new MethodCommandNodeFactoryNotFoundException("MethodCommandNodeFactory not found for the parameter " + parameter); diff --git a/commands/src/main/java/com/wizardlybump17/wlib/command/extractor/method/factory/MethodCommandNodeFactory.java b/commands/src/main/java/com/wizardlybump17/wlib/command/extractor/method/factory/MethodCommandNodeFactory.java index 2ccf2698..2af68d81 100644 --- a/commands/src/main/java/com/wizardlybump17/wlib/command/extractor/method/factory/MethodCommandNodeFactory.java +++ b/commands/src/main/java/com/wizardlybump17/wlib/command/extractor/method/factory/MethodCommandNodeFactory.java @@ -8,7 +8,7 @@ import java.lang.reflect.Method; import java.lang.reflect.Parameter; -public abstract class MethodCommandNodeFactory> { +public abstract class MethodCommandNodeFactory { - public abstract @NotNull N create(@NotNull Object object, @NotNull Method method, @NotNull Command commandAnnotation, @NotNull Parameter parameter, @NotNull String name, @Nullable CommandNode root); + public abstract @NotNull CommandNode create(@NotNull Object object, @NotNull Method method, @NotNull Command commandAnnotation, @NotNull Parameter parameter, @NotNull String name, @Nullable CommandNode root); } diff --git a/commands/src/main/java/com/wizardlybump17/wlib/command/registry/MethodCommandNodeFactoryRegistry.java b/commands/src/main/java/com/wizardlybump17/wlib/command/registry/MethodCommandNodeFactoryRegistry.java index 3dcdc5d8..2b37db34 100644 --- a/commands/src/main/java/com/wizardlybump17/wlib/command/registry/MethodCommandNodeFactoryRegistry.java +++ b/commands/src/main/java/com/wizardlybump17/wlib/command/registry/MethodCommandNodeFactoryRegistry.java @@ -17,20 +17,20 @@ public final class MethodCommandNodeFactoryRegistry { private MethodCommandNodeFactoryRegistry() { } - private final @NotNull Map, MethodCommandNodeFactory> factories = new HashMap<>(); + private final @NotNull Map, MethodCommandNodeFactory> factories = new HashMap<>(); - public void addFactory(@NotNull Class clazz, @NotNull MethodCommandNodeFactory factory) { + public void addFactory(@NotNull Class clazz, @NotNull MethodCommandNodeFactory factory) { factories.put(clazz, factory); } - public void addFactory(@NotNull MethodCommandNodeFactory factory, @NotNull Class ... classes) { + public void addFactory(@NotNull MethodCommandNodeFactory factory, @NotNull Class ... classes) { if (classes.length < 1) throw new IllegalArgumentException("The classes array must contain at least one element"); for (Class clazz : classes) addFactory(clazz, factory); } - public @Nullable MethodCommandNodeFactory getFactory(@NotNull Class clazz) { + public @Nullable MethodCommandNodeFactory getFactory(@NotNull Class clazz) { return factories.get(clazz); } @@ -49,7 +49,7 @@ public boolean hasFactory(@NotNull Class clazz) { return factories.containsKey(clazz); } - public @NotNull @Unmodifiable Map, MethodCommandNodeFactory> getFactories() { + public @NotNull @Unmodifiable Map, MethodCommandNodeFactory> getFactories() { return Collections.unmodifiableMap(factories); } diff --git a/commands/src/test/java/com/wizardlybump17/wlib/test/command/extractor/method/MethodCommandExtractorStructureTests.java b/commands/src/test/java/com/wizardlybump17/wlib/test/command/extractor/method/MethodCommandExtractorStructureTests.java index f9604a01..13aa6cc0 100644 --- a/commands/src/test/java/com/wizardlybump17/wlib/test/command/extractor/method/MethodCommandExtractorStructureTests.java +++ b/commands/src/test/java/com/wizardlybump17/wlib/test/command/extractor/method/MethodCommandExtractorStructureTests.java @@ -29,7 +29,7 @@ class MethodCommandExtractorStructureTests { static void setup() { MethodCommandNodeFactoryRegistry.INSTANCE.addFactory( int.class, - new MethodCommandNodeFactory() { + new MethodCommandNodeFactory() { @Override public @NotNull IntegerCommandNode create(@NotNull Object object, @NotNull Method method, com.wizardlybump17.wlib.command.annotation.@NotNull Command commandAnnotation, @NotNull Parameter parameter, @NotNull String name, @Nullable CommandNode root) { return new IntegerCommandNode(name, root == null ? List.of() : List.of(root), AllowedIntegerInputs.unlimited()); @@ -38,7 +38,7 @@ static void setup() { ); MethodCommandNodeFactoryRegistry.INSTANCE.addFactory( String.class, - new MethodCommandNodeFactory() { + new MethodCommandNodeFactory() { @Override public @NotNull StringCommandNode create(@NotNull Object object, @NotNull Method method, com.wizardlybump17.wlib.command.annotation.@NotNull Command commandAnnotation, @NotNull Parameter parameter, @NotNull String name, @Nullable CommandNode root) { return new StringCommandNode(name, root == null ? List.of() : List.of(root), AllowedStringInputs.anyNullable()); diff --git a/commands/src/test/java/com/wizardlybump17/wlib/test/command/extractor/method/MethodCommandExtractorTests.java b/commands/src/test/java/com/wizardlybump17/wlib/test/command/extractor/method/MethodCommandExtractorTests.java index ea77b833..1582f95c 100644 --- a/commands/src/test/java/com/wizardlybump17/wlib/test/command/extractor/method/MethodCommandExtractorTests.java +++ b/commands/src/test/java/com/wizardlybump17/wlib/test/command/extractor/method/MethodCommandExtractorTests.java @@ -36,7 +36,7 @@ class MethodCommandExtractorTests { static void setup() { MethodCommandNodeFactoryRegistry.INSTANCE.addFactory( int.class, - new MethodCommandNodeFactory() { + new MethodCommandNodeFactory() { @Override public @NotNull IntegerCommandNode create(@NotNull Object object, @NotNull Method method, com.wizardlybump17.wlib.command.annotation.@NotNull Command commandAnnotation, @NotNull Parameter parameter, @NotNull String name, @Nullable CommandNode root) { return new IntegerCommandNode(name, root == null ? List.of() : List.of(root), AllowedIntegerInputs.unlimited()); @@ -45,7 +45,7 @@ static void setup() { ); MethodCommandNodeFactoryRegistry.INSTANCE.addFactory( String.class, - new MethodCommandNodeFactory() { + new MethodCommandNodeFactory() { @Override public @NotNull StringCommandNode create(@NotNull Object object, @NotNull Method method, com.wizardlybump17.wlib.command.annotation.@NotNull Command commandAnnotation, @NotNull Parameter parameter, @NotNull String name, @Nullable CommandNode root) { return new StringCommandNode(name, root == null ? List.of() : List.of(root), AllowedStringInputs.anyNullable()); From 9f71a0daf1eab104c3094b99084eb19164198fc4 Mon Sep 17 00:00:00 2001 From: WizardlyBump17 Date: Tue, 25 Nov 2025 20:24:25 -0300 Subject: [PATCH 165/363] back to the stone age --- .../input/primitive/AllowedBooleanInputs.java | 3 +- .../primitive/AllowedCharacterInputs.java | 3 +- .../primitive/PrimitiveAllowedInputs.java | 6 +++ .../primitive/number/AllowedByteInputs.java | 5 ++- .../primitive/number/AllowedDoubleInputs.java | 5 ++- .../primitive/number/AllowedFloatInputs.java | 5 ++- .../number/AllowedIntegerInputs.java | 3 +- .../primitive/number/AllowedLongInputs.java | 5 ++- .../primitive/number/AllowedShortInputs.java | 5 ++- .../node/primitive/BooleanCommandNode.java | 2 +- .../node/primitive/CharacterCommandNode.java | 2 +- .../node/primitive/PrimitiveCommandNode.java | 40 +++++++++++++++++++ .../primitive/number/ByteCommandNode.java | 3 +- .../primitive/number/DoubleCommandNode.java | 3 +- .../primitive/number/FloatCommandNode.java | 3 +- .../primitive/number/IntegerCommandNode.java | 3 +- .../primitive/number/LongCommandNode.java | 3 +- .../primitive/number/ShortCommandNode.java | 3 +- 18 files changed, 79 insertions(+), 23 deletions(-) create mode 100644 commands/src/main/java/com/wizardlybump17/wlib/command/input/primitive/PrimitiveAllowedInputs.java create mode 100644 commands/src/main/java/com/wizardlybump17/wlib/command/node/primitive/PrimitiveCommandNode.java diff --git a/commands/src/main/java/com/wizardlybump17/wlib/command/input/primitive/AllowedBooleanInputs.java b/commands/src/main/java/com/wizardlybump17/wlib/command/input/primitive/AllowedBooleanInputs.java index b4c7c5bd..c755a70c 100644 --- a/commands/src/main/java/com/wizardlybump17/wlib/command/input/primitive/AllowedBooleanInputs.java +++ b/commands/src/main/java/com/wizardlybump17/wlib/command/input/primitive/AllowedBooleanInputs.java @@ -1,13 +1,12 @@ package com.wizardlybump17.wlib.command.input.primitive; -import com.wizardlybump17.wlib.command.input.AllowedInputs; import com.wizardlybump17.wlib.command.input.SingleValueInput; import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.Nullable; import java.util.Objects; -public interface AllowedBooleanInputs extends AllowedInputs { +public interface AllowedBooleanInputs extends PrimitiveAllowedInputs { static @NotNull True trueValue() { return True.INSTANCE; diff --git a/commands/src/main/java/com/wizardlybump17/wlib/command/input/primitive/AllowedCharacterInputs.java b/commands/src/main/java/com/wizardlybump17/wlib/command/input/primitive/AllowedCharacterInputs.java index d275de83..5a4123b1 100644 --- a/commands/src/main/java/com/wizardlybump17/wlib/command/input/primitive/AllowedCharacterInputs.java +++ b/commands/src/main/java/com/wizardlybump17/wlib/command/input/primitive/AllowedCharacterInputs.java @@ -1,6 +1,5 @@ package com.wizardlybump17.wlib.command.input.primitive; -import com.wizardlybump17.wlib.command.input.AllowedInputs; import com.wizardlybump17.wlib.command.input.AllowedListInputs; import com.wizardlybump17.wlib.command.input.SingleValueInput; import org.jetbrains.annotations.NotNull; @@ -10,7 +9,7 @@ import java.util.Objects; import java.util.stream.Collectors; -public interface AllowedCharacterInputs extends AllowedInputs { +public interface AllowedCharacterInputs extends PrimitiveAllowedInputs { static @NotNull Value value(char value) { return new Value(value, false); diff --git a/commands/src/main/java/com/wizardlybump17/wlib/command/input/primitive/PrimitiveAllowedInputs.java b/commands/src/main/java/com/wizardlybump17/wlib/command/input/primitive/PrimitiveAllowedInputs.java new file mode 100644 index 00000000..4c815ba3 --- /dev/null +++ b/commands/src/main/java/com/wizardlybump17/wlib/command/input/primitive/PrimitiveAllowedInputs.java @@ -0,0 +1,6 @@ +package com.wizardlybump17.wlib.command.input.primitive; + +import com.wizardlybump17.wlib.command.input.AllowedInputs; + +public interface PrimitiveAllowedInputs

extends AllowedInputs

{ +} diff --git a/commands/src/main/java/com/wizardlybump17/wlib/command/input/primitive/number/AllowedByteInputs.java b/commands/src/main/java/com/wizardlybump17/wlib/command/input/primitive/number/AllowedByteInputs.java index 338dfff6..0a19b97d 100644 --- a/commands/src/main/java/com/wizardlybump17/wlib/command/input/primitive/number/AllowedByteInputs.java +++ b/commands/src/main/java/com/wizardlybump17/wlib/command/input/primitive/number/AllowedByteInputs.java @@ -1,11 +1,12 @@ package com.wizardlybump17.wlib.command.input.primitive.number; +import com.wizardlybump17.wlib.command.input.primitive.PrimitiveAllowedInputs; import com.wizardlybump17.wlib.command.sender.CommandSender; import org.jetbrains.annotations.NotNull; import java.util.List; -public interface AllowedByteInputs extends AllowedNumberInputs { +public interface AllowedByteInputs extends PrimitiveAllowedInputs { static @NotNull Range range(byte from, byte to) { return new Range(from, to); @@ -31,7 +32,7 @@ public interface AllowedByteInputs extends AllowedNumberInputs { return new Value(value); } - final class Range extends Ranged implements AllowedByteInputs { + final class Range extends AllowedNumberInputs.Ranged implements AllowedByteInputs { Range(byte from, byte to) { super(from, to); diff --git a/commands/src/main/java/com/wizardlybump17/wlib/command/input/primitive/number/AllowedDoubleInputs.java b/commands/src/main/java/com/wizardlybump17/wlib/command/input/primitive/number/AllowedDoubleInputs.java index 29521f1b..b02eef66 100644 --- a/commands/src/main/java/com/wizardlybump17/wlib/command/input/primitive/number/AllowedDoubleInputs.java +++ b/commands/src/main/java/com/wizardlybump17/wlib/command/input/primitive/number/AllowedDoubleInputs.java @@ -1,11 +1,12 @@ package com.wizardlybump17.wlib.command.input.primitive.number; +import com.wizardlybump17.wlib.command.input.primitive.PrimitiveAllowedInputs; import com.wizardlybump17.wlib.command.sender.CommandSender; import org.jetbrains.annotations.NotNull; import java.util.List; -public interface AllowedDoubleInputs extends AllowedNumberInputs { +public interface AllowedDoubleInputs extends PrimitiveAllowedInputs { static @NotNull Range range(double from, double to) { return new Range(from, to); @@ -31,7 +32,7 @@ public interface AllowedDoubleInputs extends AllowedNumberInputs { return new Value(value); } - final class Range extends Ranged implements AllowedDoubleInputs { + final class Range extends AllowedNumberInputs.Ranged implements AllowedDoubleInputs { Range(double from, double to) { super(from, to); diff --git a/commands/src/main/java/com/wizardlybump17/wlib/command/input/primitive/number/AllowedFloatInputs.java b/commands/src/main/java/com/wizardlybump17/wlib/command/input/primitive/number/AllowedFloatInputs.java index a0ee44b0..401d1dd0 100644 --- a/commands/src/main/java/com/wizardlybump17/wlib/command/input/primitive/number/AllowedFloatInputs.java +++ b/commands/src/main/java/com/wizardlybump17/wlib/command/input/primitive/number/AllowedFloatInputs.java @@ -1,11 +1,12 @@ package com.wizardlybump17.wlib.command.input.primitive.number; +import com.wizardlybump17.wlib.command.input.primitive.PrimitiveAllowedInputs; import com.wizardlybump17.wlib.command.sender.CommandSender; import org.jetbrains.annotations.NotNull; import java.util.List; -public interface AllowedFloatInputs extends AllowedNumberInputs { +public interface AllowedFloatInputs extends PrimitiveAllowedInputs { static @NotNull Range range(float from, float to) { return new Range(from, to); @@ -31,7 +32,7 @@ public interface AllowedFloatInputs extends AllowedNumberInputs { return new Value(value); } - final class Range extends Ranged implements AllowedFloatInputs { + final class Range extends AllowedNumberInputs.Ranged implements AllowedFloatInputs { Range(float from, float to) { super(from, to); diff --git a/commands/src/main/java/com/wizardlybump17/wlib/command/input/primitive/number/AllowedIntegerInputs.java b/commands/src/main/java/com/wizardlybump17/wlib/command/input/primitive/number/AllowedIntegerInputs.java index 9602b4b5..98f42c74 100644 --- a/commands/src/main/java/com/wizardlybump17/wlib/command/input/primitive/number/AllowedIntegerInputs.java +++ b/commands/src/main/java/com/wizardlybump17/wlib/command/input/primitive/number/AllowedIntegerInputs.java @@ -1,12 +1,13 @@ package com.wizardlybump17.wlib.command.input.primitive.number; +import com.wizardlybump17.wlib.command.input.primitive.PrimitiveAllowedInputs; import com.wizardlybump17.wlib.command.sender.CommandSender; import org.jetbrains.annotations.NotNull; import java.util.List; import java.util.stream.IntStream; -public interface AllowedIntegerInputs extends AllowedNumberInputs { +public interface AllowedIntegerInputs extends PrimitiveAllowedInputs { static @NotNull Range range(int from, int to) { return new Range(from, to); diff --git a/commands/src/main/java/com/wizardlybump17/wlib/command/input/primitive/number/AllowedLongInputs.java b/commands/src/main/java/com/wizardlybump17/wlib/command/input/primitive/number/AllowedLongInputs.java index d97e51f9..b4ecda74 100644 --- a/commands/src/main/java/com/wizardlybump17/wlib/command/input/primitive/number/AllowedLongInputs.java +++ b/commands/src/main/java/com/wizardlybump17/wlib/command/input/primitive/number/AllowedLongInputs.java @@ -1,11 +1,12 @@ package com.wizardlybump17.wlib.command.input.primitive.number; +import com.wizardlybump17.wlib.command.input.primitive.PrimitiveAllowedInputs; import com.wizardlybump17.wlib.command.sender.CommandSender; import org.jetbrains.annotations.NotNull; import java.util.List; -public interface AllowedLongInputs extends AllowedNumberInputs { +public interface AllowedLongInputs extends PrimitiveAllowedInputs { static @NotNull Range range(long from, long to) { return new Range(from, to); @@ -31,7 +32,7 @@ public interface AllowedLongInputs extends AllowedNumberInputs { return new Value(value); } - final class Range extends Ranged implements AllowedLongInputs { + final class Range extends AllowedNumberInputs.Ranged implements AllowedLongInputs { Range(long from, long to) { super(from, to); diff --git a/commands/src/main/java/com/wizardlybump17/wlib/command/input/primitive/number/AllowedShortInputs.java b/commands/src/main/java/com/wizardlybump17/wlib/command/input/primitive/number/AllowedShortInputs.java index 94b5944e..80069f77 100644 --- a/commands/src/main/java/com/wizardlybump17/wlib/command/input/primitive/number/AllowedShortInputs.java +++ b/commands/src/main/java/com/wizardlybump17/wlib/command/input/primitive/number/AllowedShortInputs.java @@ -1,11 +1,12 @@ package com.wizardlybump17.wlib.command.input.primitive.number; +import com.wizardlybump17.wlib.command.input.primitive.PrimitiveAllowedInputs; import com.wizardlybump17.wlib.command.sender.CommandSender; import org.jetbrains.annotations.NotNull; import java.util.List; -public interface AllowedShortInputs extends AllowedNumberInputs { +public interface AllowedShortInputs extends PrimitiveAllowedInputs { static @NotNull Range range(short from, short to) { return new Range(from, to); @@ -31,7 +32,7 @@ public interface AllowedShortInputs extends AllowedNumberInputs { return new Value(value); } - final class Range extends Ranged implements AllowedShortInputs { + final class Range extends AllowedNumberInputs.Ranged implements AllowedShortInputs { Range(short from, short to) { super(from, to); diff --git a/commands/src/main/java/com/wizardlybump17/wlib/command/node/primitive/BooleanCommandNode.java b/commands/src/main/java/com/wizardlybump17/wlib/command/node/primitive/BooleanCommandNode.java index d3689adb..2e4429cd 100644 --- a/commands/src/main/java/com/wizardlybump17/wlib/command/node/primitive/BooleanCommandNode.java +++ b/commands/src/main/java/com/wizardlybump17/wlib/command/node/primitive/BooleanCommandNode.java @@ -9,7 +9,7 @@ import java.util.List; -public class BooleanCommandNode extends CommandNode { +public class BooleanCommandNode extends PrimitiveCommandNode { public BooleanCommandNode(@NotNull String name, @NotNull List> children, @NotNull AllowedBooleanInputs allowedInputs, @Nullable CommandNodeExecutor executor, @Nullable String permission) { super(name, children, allowedInputs, executor, permission); diff --git a/commands/src/main/java/com/wizardlybump17/wlib/command/node/primitive/CharacterCommandNode.java b/commands/src/main/java/com/wizardlybump17/wlib/command/node/primitive/CharacterCommandNode.java index 3f963b68..c9c8d83e 100644 --- a/commands/src/main/java/com/wizardlybump17/wlib/command/node/primitive/CharacterCommandNode.java +++ b/commands/src/main/java/com/wizardlybump17/wlib/command/node/primitive/CharacterCommandNode.java @@ -9,7 +9,7 @@ import java.util.List; -public class CharacterCommandNode extends CommandNode { +public class CharacterCommandNode extends PrimitiveCommandNode { public CharacterCommandNode(@NotNull String name, @NotNull List> children, @NotNull AllowedCharacterInputs allowedInputs, @Nullable CommandNodeExecutor executor, @Nullable String permission) { super(name, children, allowedInputs, executor, permission); diff --git a/commands/src/main/java/com/wizardlybump17/wlib/command/node/primitive/PrimitiveCommandNode.java b/commands/src/main/java/com/wizardlybump17/wlib/command/node/primitive/PrimitiveCommandNode.java new file mode 100644 index 00000000..88e10c1f --- /dev/null +++ b/commands/src/main/java/com/wizardlybump17/wlib/command/node/primitive/PrimitiveCommandNode.java @@ -0,0 +1,40 @@ +package com.wizardlybump17.wlib.command.node.primitive; + +import com.wizardlybump17.wlib.command.executor.CommandNodeExecutor; +import com.wizardlybump17.wlib.command.input.primitive.PrimitiveAllowedInputs; +import com.wizardlybump17.wlib.command.node.CommandNode; +import org.jetbrains.annotations.NotNull; +import org.jetbrains.annotations.Nullable; + +import java.util.List; + +public abstract class PrimitiveCommandNode

extends CommandNode

{ + + public PrimitiveCommandNode(@NotNull String name, @NotNull List> children, @NotNull PrimitiveAllowedInputs

allowedInputs, @Nullable CommandNodeExecutor executor, @Nullable String permission) { + super(name, children, allowedInputs, executor, permission); + } + + public PrimitiveCommandNode(@NotNull String name, @NotNull PrimitiveAllowedInputs

allowedInputs, @Nullable CommandNodeExecutor executor, @Nullable String permission) { + super(name, allowedInputs, executor, permission); + } + + public PrimitiveCommandNode(@NotNull String name, @NotNull List> children, @NotNull PrimitiveAllowedInputs

allowedInputs, @Nullable String permission) { + super(name, children, allowedInputs, permission); + } + + public PrimitiveCommandNode(@NotNull String name, @NotNull PrimitiveAllowedInputs

allowedInputs, @Nullable String permission) { + super(name, allowedInputs, permission); + } + + public PrimitiveCommandNode(@NotNull String name, @NotNull PrimitiveAllowedInputs

allowedInputs, @Nullable CommandNodeExecutor executor) { + super(name, allowedInputs, executor); + } + + public PrimitiveCommandNode(@NotNull String name, @NotNull List> children, @NotNull PrimitiveAllowedInputs

allowedInputs) { + super(name, children, allowedInputs); + } + + public PrimitiveCommandNode(@NotNull String name, @NotNull PrimitiveAllowedInputs

allowedInputs) { + super(name, allowedInputs); + } +} diff --git a/commands/src/main/java/com/wizardlybump17/wlib/command/node/primitive/number/ByteCommandNode.java b/commands/src/main/java/com/wizardlybump17/wlib/command/node/primitive/number/ByteCommandNode.java index ab9ed6ab..97d42039 100644 --- a/commands/src/main/java/com/wizardlybump17/wlib/command/node/primitive/number/ByteCommandNode.java +++ b/commands/src/main/java/com/wizardlybump17/wlib/command/node/primitive/number/ByteCommandNode.java @@ -4,12 +4,13 @@ import com.wizardlybump17.wlib.command.executor.CommandNodeExecutor; import com.wizardlybump17.wlib.command.input.primitive.number.AllowedByteInputs; import com.wizardlybump17.wlib.command.node.CommandNode; +import com.wizardlybump17.wlib.command.node.primitive.PrimitiveCommandNode; import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.Nullable; import java.util.List; -public class ByteCommandNode extends CommandNode { +public class ByteCommandNode extends PrimitiveCommandNode { public ByteCommandNode(@NotNull String name, @NotNull List> children, @NotNull AllowedByteInputs allowedInputs, @Nullable CommandNodeExecutor executor, @Nullable String permission) { super(name, children, allowedInputs, executor, permission); diff --git a/commands/src/main/java/com/wizardlybump17/wlib/command/node/primitive/number/DoubleCommandNode.java b/commands/src/main/java/com/wizardlybump17/wlib/command/node/primitive/number/DoubleCommandNode.java index 3ebb1759..96044336 100644 --- a/commands/src/main/java/com/wizardlybump17/wlib/command/node/primitive/number/DoubleCommandNode.java +++ b/commands/src/main/java/com/wizardlybump17/wlib/command/node/primitive/number/DoubleCommandNode.java @@ -4,12 +4,13 @@ import com.wizardlybump17.wlib.command.executor.CommandNodeExecutor; import com.wizardlybump17.wlib.command.input.primitive.number.AllowedDoubleInputs; import com.wizardlybump17.wlib.command.node.CommandNode; +import com.wizardlybump17.wlib.command.node.primitive.PrimitiveCommandNode; import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.Nullable; import java.util.List; -public class DoubleCommandNode extends CommandNode { +public class DoubleCommandNode extends PrimitiveCommandNode { public DoubleCommandNode(@NotNull String name, @NotNull List> children, @NotNull AllowedDoubleInputs allowedInputs, @Nullable CommandNodeExecutor executor, @Nullable String permission) { super(name, children, allowedInputs, executor, permission); diff --git a/commands/src/main/java/com/wizardlybump17/wlib/command/node/primitive/number/FloatCommandNode.java b/commands/src/main/java/com/wizardlybump17/wlib/command/node/primitive/number/FloatCommandNode.java index b3544af1..0ec14d23 100644 --- a/commands/src/main/java/com/wizardlybump17/wlib/command/node/primitive/number/FloatCommandNode.java +++ b/commands/src/main/java/com/wizardlybump17/wlib/command/node/primitive/number/FloatCommandNode.java @@ -4,12 +4,13 @@ import com.wizardlybump17.wlib.command.executor.CommandNodeExecutor; import com.wizardlybump17.wlib.command.input.primitive.number.AllowedFloatInputs; import com.wizardlybump17.wlib.command.node.CommandNode; +import com.wizardlybump17.wlib.command.node.primitive.PrimitiveCommandNode; import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.Nullable; import java.util.List; -public class FloatCommandNode extends CommandNode { +public class FloatCommandNode extends PrimitiveCommandNode { public FloatCommandNode(@NotNull String name, @NotNull List> children, @NotNull AllowedFloatInputs allowedInputs, @Nullable CommandNodeExecutor executor, @Nullable String permission) { super(name, children, allowedInputs, executor, permission); diff --git a/commands/src/main/java/com/wizardlybump17/wlib/command/node/primitive/number/IntegerCommandNode.java b/commands/src/main/java/com/wizardlybump17/wlib/command/node/primitive/number/IntegerCommandNode.java index 97a389d9..a2aca4c4 100644 --- a/commands/src/main/java/com/wizardlybump17/wlib/command/node/primitive/number/IntegerCommandNode.java +++ b/commands/src/main/java/com/wizardlybump17/wlib/command/node/primitive/number/IntegerCommandNode.java @@ -4,12 +4,13 @@ import com.wizardlybump17.wlib.command.executor.CommandNodeExecutor; import com.wizardlybump17.wlib.command.input.primitive.number.AllowedIntegerInputs; import com.wizardlybump17.wlib.command.node.CommandNode; +import com.wizardlybump17.wlib.command.node.primitive.PrimitiveCommandNode; import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.Nullable; import java.util.List; -public class IntegerCommandNode extends CommandNode { +public class IntegerCommandNode extends PrimitiveCommandNode { public IntegerCommandNode(@NotNull String name, @NotNull List> children, @NotNull AllowedIntegerInputs allowedInputs, @Nullable CommandNodeExecutor executor, @Nullable String permission) { super(name, children, allowedInputs, executor, permission); diff --git a/commands/src/main/java/com/wizardlybump17/wlib/command/node/primitive/number/LongCommandNode.java b/commands/src/main/java/com/wizardlybump17/wlib/command/node/primitive/number/LongCommandNode.java index 3d6fc919..c961b28c 100644 --- a/commands/src/main/java/com/wizardlybump17/wlib/command/node/primitive/number/LongCommandNode.java +++ b/commands/src/main/java/com/wizardlybump17/wlib/command/node/primitive/number/LongCommandNode.java @@ -4,12 +4,13 @@ import com.wizardlybump17.wlib.command.executor.CommandNodeExecutor; import com.wizardlybump17.wlib.command.input.primitive.number.AllowedLongInputs; import com.wizardlybump17.wlib.command.node.CommandNode; +import com.wizardlybump17.wlib.command.node.primitive.PrimitiveCommandNode; import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.Nullable; import java.util.List; -public class LongCommandNode extends CommandNode { +public class LongCommandNode extends PrimitiveCommandNode { public LongCommandNode(@NotNull String name, @NotNull List> children, @NotNull AllowedLongInputs allowedInputs, @Nullable CommandNodeExecutor executor, @Nullable String permission) { super(name, children, allowedInputs, executor, permission); diff --git a/commands/src/main/java/com/wizardlybump17/wlib/command/node/primitive/number/ShortCommandNode.java b/commands/src/main/java/com/wizardlybump17/wlib/command/node/primitive/number/ShortCommandNode.java index 436cd7ea..d66da203 100644 --- a/commands/src/main/java/com/wizardlybump17/wlib/command/node/primitive/number/ShortCommandNode.java +++ b/commands/src/main/java/com/wizardlybump17/wlib/command/node/primitive/number/ShortCommandNode.java @@ -4,12 +4,13 @@ import com.wizardlybump17.wlib.command.executor.CommandNodeExecutor; import com.wizardlybump17.wlib.command.input.primitive.number.AllowedShortInputs; import com.wizardlybump17.wlib.command.node.CommandNode; +import com.wizardlybump17.wlib.command.node.primitive.PrimitiveCommandNode; import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.Nullable; import java.util.List; -public class ShortCommandNode extends CommandNode { +public class ShortCommandNode extends PrimitiveCommandNode { public ShortCommandNode(@NotNull String name, @NotNull List> children, @NotNull AllowedShortInputs allowedInputs, @Nullable CommandNodeExecutor executor, @Nullable String permission) { super(name, children, allowedInputs, executor, permission); From e53bccbe3d851b93d08d9f3e700361c5cd162278 Mon Sep 17 00:00:00 2001 From: WizardlyBump17 Date: Tue, 25 Nov 2025 20:42:32 -0300 Subject: [PATCH 166/363] made some work on some monkeys --- .../BooleanMethodCommandNodeFactory.java | 31 ++++++++++++ .../CharacterMethodCommandNodeFactory.java | 32 ++++++++++++ .../NumberMethodCommandNodeFactory.java | 37 ++++++++++++++ .../PrimitiveMethodCommandNodeFactory.java | 16 ++++++ .../node/primitive/BooleanCommandNode.java | 2 +- .../node/primitive/CharacterCommandNode.java | 2 +- .../node/primitive/PrimitiveCommandNode.java | 38 +------------- .../primitive/number/ByteCommandNode.java | 2 +- .../primitive/number/DoubleCommandNode.java | 2 +- .../primitive/number/FloatCommandNode.java | 2 +- .../primitive/number/IntegerCommandNode.java | 2 +- .../primitive/number/LongCommandNode.java | 2 +- .../primitive/number/NumberCommandNode.java | 49 +++++++++++++++++++ .../primitive/number/ShortCommandNode.java | 2 +- 14 files changed, 174 insertions(+), 45 deletions(-) create mode 100644 commands/src/main/java/com/wizardlybump17/wlib/command/extractor/method/factory/primitive/BooleanMethodCommandNodeFactory.java create mode 100644 commands/src/main/java/com/wizardlybump17/wlib/command/extractor/method/factory/primitive/CharacterMethodCommandNodeFactory.java create mode 100644 commands/src/main/java/com/wizardlybump17/wlib/command/extractor/method/factory/primitive/NumberMethodCommandNodeFactory.java create mode 100644 commands/src/main/java/com/wizardlybump17/wlib/command/extractor/method/factory/primitive/PrimitiveMethodCommandNodeFactory.java create mode 100644 commands/src/main/java/com/wizardlybump17/wlib/command/node/primitive/number/NumberCommandNode.java diff --git a/commands/src/main/java/com/wizardlybump17/wlib/command/extractor/method/factory/primitive/BooleanMethodCommandNodeFactory.java b/commands/src/main/java/com/wizardlybump17/wlib/command/extractor/method/factory/primitive/BooleanMethodCommandNodeFactory.java new file mode 100644 index 00000000..a0b9a908 --- /dev/null +++ b/commands/src/main/java/com/wizardlybump17/wlib/command/extractor/method/factory/primitive/BooleanMethodCommandNodeFactory.java @@ -0,0 +1,31 @@ +package com.wizardlybump17.wlib.command.extractor.method.factory.primitive; + +import com.wizardlybump17.wlib.command.annotation.Command; +import com.wizardlybump17.wlib.command.input.primitive.AllowedBooleanInputs; +import com.wizardlybump17.wlib.command.node.CommandNode; +import com.wizardlybump17.wlib.command.node.primitive.BooleanCommandNode; +import org.jetbrains.annotations.NotNull; +import org.jetbrains.annotations.Nullable; + +import java.lang.reflect.Method; +import java.lang.reflect.Parameter; +import java.util.List; + +public class BooleanMethodCommandNodeFactory extends PrimitiveMethodCommandNodeFactory { + + @Override + public @NotNull BooleanCommandNode create(@NotNull Object object, @NotNull Method method, @NotNull Command commandAnnotation, @NotNull Parameter parameter, @NotNull String name, @Nullable CommandNode root) { + Class type = parameter.getType(); + + if (type != boolean.class && type != Boolean.class) + throw new IllegalArgumentException("Unsupported type. We only accept booleans: " + type); + + return new BooleanCommandNode( + name, + root == null ? List.of() : List.of(root), + AllowedBooleanInputs.anyNotNull(), + null, + null + ); + } +} diff --git a/commands/src/main/java/com/wizardlybump17/wlib/command/extractor/method/factory/primitive/CharacterMethodCommandNodeFactory.java b/commands/src/main/java/com/wizardlybump17/wlib/command/extractor/method/factory/primitive/CharacterMethodCommandNodeFactory.java new file mode 100644 index 00000000..56a108b8 --- /dev/null +++ b/commands/src/main/java/com/wizardlybump17/wlib/command/extractor/method/factory/primitive/CharacterMethodCommandNodeFactory.java @@ -0,0 +1,32 @@ +package com.wizardlybump17.wlib.command.extractor.method.factory.primitive; + +import com.wizardlybump17.wlib.command.annotation.Command; +import com.wizardlybump17.wlib.command.input.primitive.AllowedCharacterInputs; +import com.wizardlybump17.wlib.command.node.CommandNode; +import com.wizardlybump17.wlib.command.node.primitive.AbstractPrimitiveCommandNode; +import com.wizardlybump17.wlib.command.node.primitive.CharacterCommandNode; +import org.jetbrains.annotations.NotNull; +import org.jetbrains.annotations.Nullable; + +import java.lang.reflect.Method; +import java.lang.reflect.Parameter; +import java.util.List; + +public class CharacterMethodCommandNodeFactory extends PrimitiveMethodCommandNodeFactory { + + @Override + public @NotNull AbstractPrimitiveCommandNode create(@NotNull Object object, @NotNull Method method, @NotNull Command commandAnnotation, @NotNull Parameter parameter, @NotNull String name, @Nullable CommandNode root) { + Class type = parameter.getType(); + + if (type != char.class && type != Character.class) + throw new IllegalArgumentException("Unsupported type. We only accept chars: " + type); + + return new CharacterCommandNode( + name, + root == null ? List.of() : List.of(root), + AllowedCharacterInputs.anyNotNull(), + null, + null + ); + } +} diff --git a/commands/src/main/java/com/wizardlybump17/wlib/command/extractor/method/factory/primitive/NumberMethodCommandNodeFactory.java b/commands/src/main/java/com/wizardlybump17/wlib/command/extractor/method/factory/primitive/NumberMethodCommandNodeFactory.java new file mode 100644 index 00000000..aa8282e6 --- /dev/null +++ b/commands/src/main/java/com/wizardlybump17/wlib/command/extractor/method/factory/primitive/NumberMethodCommandNodeFactory.java @@ -0,0 +1,37 @@ +package com.wizardlybump17.wlib.command.extractor.method.factory.primitive; + +import com.wizardlybump17.wlib.command.annotation.Command; +import com.wizardlybump17.wlib.command.input.primitive.number.*; +import com.wizardlybump17.wlib.command.node.CommandNode; +import com.wizardlybump17.wlib.command.node.primitive.number.*; +import org.jetbrains.annotations.NotNull; +import org.jetbrains.annotations.Nullable; + +import java.lang.reflect.Method; +import java.lang.reflect.Parameter; +import java.util.List; + +public class NumberMethodCommandNodeFactory extends PrimitiveMethodCommandNodeFactory { + + @Override + public @NotNull NumberCommandNode create(@NotNull Object object, @NotNull Method method, @NotNull Command commandAnnotation, @NotNull Parameter parameter, @NotNull String name, @Nullable CommandNode root) { + Class type = parameter.getType(); + + List> children = root == null ? List.of() : List.of(root); + + if (type == byte.class || type == Byte.class) + return new ByteCommandNode(name, children, AllowedByteInputs.unlimited()); + if (type == short.class || type == Short.class) + return new ShortCommandNode(name, children, AllowedShortInputs.unlimited()); + if (type == int.class || type == Integer.class) + return new IntegerCommandNode(name, children, AllowedIntegerInputs.unlimited()); + if (type == long.class || type == Long.class) + return new LongCommandNode(name, children, AllowedLongInputs.unlimited()); + if (type == float.class || type == Float.class) + return new FloatCommandNode(name, children, AllowedFloatInputs.unlimited()); + if (type == double.class || type == Double.class) + return new DoubleCommandNode(name, children, AllowedDoubleInputs.unlimited()); + + throw new IllegalArgumentException("Unsupported type. We accept only primitive numbers: " + type); + } +} diff --git a/commands/src/main/java/com/wizardlybump17/wlib/command/extractor/method/factory/primitive/PrimitiveMethodCommandNodeFactory.java b/commands/src/main/java/com/wizardlybump17/wlib/command/extractor/method/factory/primitive/PrimitiveMethodCommandNodeFactory.java new file mode 100644 index 00000000..1ded737b --- /dev/null +++ b/commands/src/main/java/com/wizardlybump17/wlib/command/extractor/method/factory/primitive/PrimitiveMethodCommandNodeFactory.java @@ -0,0 +1,16 @@ +package com.wizardlybump17.wlib.command.extractor.method.factory.primitive; + +import com.wizardlybump17.wlib.command.annotation.Command; +import com.wizardlybump17.wlib.command.extractor.method.factory.MethodCommandNodeFactory; +import com.wizardlybump17.wlib.command.node.CommandNode; +import org.jetbrains.annotations.NotNull; +import org.jetbrains.annotations.Nullable; + +import java.lang.reflect.Method; +import java.lang.reflect.Parameter; + +public abstract class PrimitiveMethodCommandNodeFactory extends MethodCommandNodeFactory { + + @Override + public abstract @NotNull CommandNode create(@NotNull Object object, @NotNull Method method, @NotNull Command commandAnnotation, @NotNull Parameter parameter, @NotNull String name, @Nullable CommandNode root); +} diff --git a/commands/src/main/java/com/wizardlybump17/wlib/command/node/primitive/BooleanCommandNode.java b/commands/src/main/java/com/wizardlybump17/wlib/command/node/primitive/BooleanCommandNode.java index 2e4429cd..992d11e5 100644 --- a/commands/src/main/java/com/wizardlybump17/wlib/command/node/primitive/BooleanCommandNode.java +++ b/commands/src/main/java/com/wizardlybump17/wlib/command/node/primitive/BooleanCommandNode.java @@ -9,7 +9,7 @@ import java.util.List; -public class BooleanCommandNode extends PrimitiveCommandNode { +public class BooleanCommandNode extends AbstractPrimitiveCommandNode { public BooleanCommandNode(@NotNull String name, @NotNull List> children, @NotNull AllowedBooleanInputs allowedInputs, @Nullable CommandNodeExecutor executor, @Nullable String permission) { super(name, children, allowedInputs, executor, permission); diff --git a/commands/src/main/java/com/wizardlybump17/wlib/command/node/primitive/CharacterCommandNode.java b/commands/src/main/java/com/wizardlybump17/wlib/command/node/primitive/CharacterCommandNode.java index c9c8d83e..f63a7b08 100644 --- a/commands/src/main/java/com/wizardlybump17/wlib/command/node/primitive/CharacterCommandNode.java +++ b/commands/src/main/java/com/wizardlybump17/wlib/command/node/primitive/CharacterCommandNode.java @@ -9,7 +9,7 @@ import java.util.List; -public class CharacterCommandNode extends PrimitiveCommandNode { +public class CharacterCommandNode extends AbstractPrimitiveCommandNode { public CharacterCommandNode(@NotNull String name, @NotNull List> children, @NotNull AllowedCharacterInputs allowedInputs, @Nullable CommandNodeExecutor executor, @Nullable String permission) { super(name, children, allowedInputs, executor, permission); diff --git a/commands/src/main/java/com/wizardlybump17/wlib/command/node/primitive/PrimitiveCommandNode.java b/commands/src/main/java/com/wizardlybump17/wlib/command/node/primitive/PrimitiveCommandNode.java index 88e10c1f..b0564f5c 100644 --- a/commands/src/main/java/com/wizardlybump17/wlib/command/node/primitive/PrimitiveCommandNode.java +++ b/commands/src/main/java/com/wizardlybump17/wlib/command/node/primitive/PrimitiveCommandNode.java @@ -1,40 +1,4 @@ package com.wizardlybump17.wlib.command.node.primitive; -import com.wizardlybump17.wlib.command.executor.CommandNodeExecutor; -import com.wizardlybump17.wlib.command.input.primitive.PrimitiveAllowedInputs; -import com.wizardlybump17.wlib.command.node.CommandNode; -import org.jetbrains.annotations.NotNull; -import org.jetbrains.annotations.Nullable; - -import java.util.List; - -public abstract class PrimitiveCommandNode

extends CommandNode

{ - - public PrimitiveCommandNode(@NotNull String name, @NotNull List> children, @NotNull PrimitiveAllowedInputs

allowedInputs, @Nullable CommandNodeExecutor executor, @Nullable String permission) { - super(name, children, allowedInputs, executor, permission); - } - - public PrimitiveCommandNode(@NotNull String name, @NotNull PrimitiveAllowedInputs

allowedInputs, @Nullable CommandNodeExecutor executor, @Nullable String permission) { - super(name, allowedInputs, executor, permission); - } - - public PrimitiveCommandNode(@NotNull String name, @NotNull List> children, @NotNull PrimitiveAllowedInputs

allowedInputs, @Nullable String permission) { - super(name, children, allowedInputs, permission); - } - - public PrimitiveCommandNode(@NotNull String name, @NotNull PrimitiveAllowedInputs

allowedInputs, @Nullable String permission) { - super(name, allowedInputs, permission); - } - - public PrimitiveCommandNode(@NotNull String name, @NotNull PrimitiveAllowedInputs

allowedInputs, @Nullable CommandNodeExecutor executor) { - super(name, allowedInputs, executor); - } - - public PrimitiveCommandNode(@NotNull String name, @NotNull List> children, @NotNull PrimitiveAllowedInputs

allowedInputs) { - super(name, children, allowedInputs); - } - - public PrimitiveCommandNode(@NotNull String name, @NotNull PrimitiveAllowedInputs

allowedInputs) { - super(name, allowedInputs); - } +public interface PrimitiveCommandNode { } diff --git a/commands/src/main/java/com/wizardlybump17/wlib/command/node/primitive/number/ByteCommandNode.java b/commands/src/main/java/com/wizardlybump17/wlib/command/node/primitive/number/ByteCommandNode.java index 97d42039..6dc57fa7 100644 --- a/commands/src/main/java/com/wizardlybump17/wlib/command/node/primitive/number/ByteCommandNode.java +++ b/commands/src/main/java/com/wizardlybump17/wlib/command/node/primitive/number/ByteCommandNode.java @@ -10,7 +10,7 @@ import java.util.List; -public class ByteCommandNode extends PrimitiveCommandNode { +public class ByteCommandNode extends NumberCommandNode implements PrimitiveCommandNode { public ByteCommandNode(@NotNull String name, @NotNull List> children, @NotNull AllowedByteInputs allowedInputs, @Nullable CommandNodeExecutor executor, @Nullable String permission) { super(name, children, allowedInputs, executor, permission); diff --git a/commands/src/main/java/com/wizardlybump17/wlib/command/node/primitive/number/DoubleCommandNode.java b/commands/src/main/java/com/wizardlybump17/wlib/command/node/primitive/number/DoubleCommandNode.java index 96044336..c26db2e5 100644 --- a/commands/src/main/java/com/wizardlybump17/wlib/command/node/primitive/number/DoubleCommandNode.java +++ b/commands/src/main/java/com/wizardlybump17/wlib/command/node/primitive/number/DoubleCommandNode.java @@ -10,7 +10,7 @@ import java.util.List; -public class DoubleCommandNode extends PrimitiveCommandNode { +public class DoubleCommandNode extends NumberCommandNode implements PrimitiveCommandNode { public DoubleCommandNode(@NotNull String name, @NotNull List> children, @NotNull AllowedDoubleInputs allowedInputs, @Nullable CommandNodeExecutor executor, @Nullable String permission) { super(name, children, allowedInputs, executor, permission); diff --git a/commands/src/main/java/com/wizardlybump17/wlib/command/node/primitive/number/FloatCommandNode.java b/commands/src/main/java/com/wizardlybump17/wlib/command/node/primitive/number/FloatCommandNode.java index 0ec14d23..073e7997 100644 --- a/commands/src/main/java/com/wizardlybump17/wlib/command/node/primitive/number/FloatCommandNode.java +++ b/commands/src/main/java/com/wizardlybump17/wlib/command/node/primitive/number/FloatCommandNode.java @@ -10,7 +10,7 @@ import java.util.List; -public class FloatCommandNode extends PrimitiveCommandNode { +public class FloatCommandNode extends NumberCommandNode implements PrimitiveCommandNode { public FloatCommandNode(@NotNull String name, @NotNull List> children, @NotNull AllowedFloatInputs allowedInputs, @Nullable CommandNodeExecutor executor, @Nullable String permission) { super(name, children, allowedInputs, executor, permission); diff --git a/commands/src/main/java/com/wizardlybump17/wlib/command/node/primitive/number/IntegerCommandNode.java b/commands/src/main/java/com/wizardlybump17/wlib/command/node/primitive/number/IntegerCommandNode.java index a2aca4c4..f243fa3b 100644 --- a/commands/src/main/java/com/wizardlybump17/wlib/command/node/primitive/number/IntegerCommandNode.java +++ b/commands/src/main/java/com/wizardlybump17/wlib/command/node/primitive/number/IntegerCommandNode.java @@ -10,7 +10,7 @@ import java.util.List; -public class IntegerCommandNode extends PrimitiveCommandNode { +public class IntegerCommandNode extends NumberCommandNode implements PrimitiveCommandNode { public IntegerCommandNode(@NotNull String name, @NotNull List> children, @NotNull AllowedIntegerInputs allowedInputs, @Nullable CommandNodeExecutor executor, @Nullable String permission) { super(name, children, allowedInputs, executor, permission); diff --git a/commands/src/main/java/com/wizardlybump17/wlib/command/node/primitive/number/LongCommandNode.java b/commands/src/main/java/com/wizardlybump17/wlib/command/node/primitive/number/LongCommandNode.java index c961b28c..e00458f3 100644 --- a/commands/src/main/java/com/wizardlybump17/wlib/command/node/primitive/number/LongCommandNode.java +++ b/commands/src/main/java/com/wizardlybump17/wlib/command/node/primitive/number/LongCommandNode.java @@ -10,7 +10,7 @@ import java.util.List; -public class LongCommandNode extends PrimitiveCommandNode { +public class LongCommandNode extends NumberCommandNode implements PrimitiveCommandNode { public LongCommandNode(@NotNull String name, @NotNull List> children, @NotNull AllowedLongInputs allowedInputs, @Nullable CommandNodeExecutor executor, @Nullable String permission) { super(name, children, allowedInputs, executor, permission); diff --git a/commands/src/main/java/com/wizardlybump17/wlib/command/node/primitive/number/NumberCommandNode.java b/commands/src/main/java/com/wizardlybump17/wlib/command/node/primitive/number/NumberCommandNode.java new file mode 100644 index 00000000..27c2483d --- /dev/null +++ b/commands/src/main/java/com/wizardlybump17/wlib/command/node/primitive/number/NumberCommandNode.java @@ -0,0 +1,49 @@ +package com.wizardlybump17.wlib.command.node.primitive.number; + +import com.wizardlybump17.wlib.command.executor.CommandNodeExecutor; +import com.wizardlybump17.wlib.command.input.AllowedInputs; +import com.wizardlybump17.wlib.command.node.CommandNode; +import org.jetbrains.annotations.NotNull; +import org.jetbrains.annotations.Nullable; + +import java.util.List; + +public abstract class NumberCommandNode extends CommandNode { + + public NumberCommandNode(@NotNull String name, @NotNull List> children, @NotNull AllowedInputs allowedInputs, @Nullable CommandNodeExecutor executor, @Nullable String permission) { + super(name, children, allowedInputs, executor, permission); + } + + public NumberCommandNode(@NotNull String name, @NotNull AllowedInputs allowedInputs, @Nullable CommandNodeExecutor executor, @Nullable String permission) { + super(name, allowedInputs, executor, permission); + } + + public NumberCommandNode(@NotNull String name, @NotNull List> children, @NotNull AllowedInputs allowedInputs, @Nullable String permission) { + super(name, children, allowedInputs, permission); + } + + public NumberCommandNode(@NotNull String name, @NotNull AllowedInputs allowedInputs, @Nullable String permission) { + super(name, allowedInputs, permission); + } + + public NumberCommandNode(@NotNull String name, @NotNull AllowedInputs allowedInputs, @Nullable CommandNodeExecutor executor) { + super(name, allowedInputs, executor); + } + + public NumberCommandNode(@NotNull String name, @NotNull List> children, @NotNull AllowedInputs allowedInputs) { + super(name, children, allowedInputs); + } + + public NumberCommandNode(@NotNull String name, @NotNull AllowedInputs allowedInputs) { + super(name, allowedInputs); + } + + @Override + public abstract @NotNull NumberCommandNode withChildren(@NotNull List> children); + + @Override + public abstract @NotNull NumberCommandNode withExecutor(@Nullable CommandNodeExecutor executor); + + @Override + public abstract @NotNull NumberCommandNode withPermission(@Nullable String permission); +} diff --git a/commands/src/main/java/com/wizardlybump17/wlib/command/node/primitive/number/ShortCommandNode.java b/commands/src/main/java/com/wizardlybump17/wlib/command/node/primitive/number/ShortCommandNode.java index d66da203..54092659 100644 --- a/commands/src/main/java/com/wizardlybump17/wlib/command/node/primitive/number/ShortCommandNode.java +++ b/commands/src/main/java/com/wizardlybump17/wlib/command/node/primitive/number/ShortCommandNode.java @@ -10,7 +10,7 @@ import java.util.List; -public class ShortCommandNode extends PrimitiveCommandNode { +public class ShortCommandNode extends NumberCommandNode implements PrimitiveCommandNode { public ShortCommandNode(@NotNull String name, @NotNull List> children, @NotNull AllowedShortInputs allowedInputs, @Nullable CommandNodeExecutor executor, @Nullable String permission) { super(name, children, allowedInputs, executor, permission); From 3b5f860fa9c3e902602a06c72eaa79b4a9219ef2 Mon Sep 17 00:00:00 2001 From: WizardlyBump17 Date: Tue, 25 Nov 2025 21:01:06 -0300 Subject: [PATCH 167/363] using the AllowedStringInputs --- .../node/string/StringCommandNode.java | 21 ++++++++++++------- 1 file changed, 13 insertions(+), 8 deletions(-) diff --git a/commands/src/main/java/com/wizardlybump17/wlib/command/node/string/StringCommandNode.java b/commands/src/main/java/com/wizardlybump17/wlib/command/node/string/StringCommandNode.java index a34be7b8..e977f0b9 100644 --- a/commands/src/main/java/com/wizardlybump17/wlib/command/node/string/StringCommandNode.java +++ b/commands/src/main/java/com/wizardlybump17/wlib/command/node/string/StringCommandNode.java @@ -2,7 +2,7 @@ import com.wizardlybump17.wlib.command.exception.InputParsingException; import com.wizardlybump17.wlib.command.executor.CommandNodeExecutor; -import com.wizardlybump17.wlib.command.input.AllowedInputs; +import com.wizardlybump17.wlib.command.input.string.AllowedStringInputs; import com.wizardlybump17.wlib.command.node.CommandNode; import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.Nullable; @@ -11,34 +11,39 @@ public class StringCommandNode extends CommandNode { - public StringCommandNode(@NotNull String name, @NotNull List> children, @NotNull AllowedInputs allowedInputs, @Nullable CommandNodeExecutor executor, @Nullable String permission) { + public StringCommandNode(@NotNull String name, @NotNull List> children, @NotNull AllowedStringInputs allowedInputs, @Nullable CommandNodeExecutor executor, @Nullable String permission) { super(name, children, allowedInputs, executor, permission); } - public StringCommandNode(@NotNull String name, @NotNull AllowedInputs allowedInputs, @Nullable CommandNodeExecutor executor, @Nullable String permission) { + public StringCommandNode(@NotNull String name, @NotNull AllowedStringInputs allowedInputs, @Nullable CommandNodeExecutor executor, @Nullable String permission) { super(name, allowedInputs, executor, permission); } - public StringCommandNode(@NotNull String name, @NotNull List> children, @NotNull AllowedInputs allowedInputs, @Nullable String permission) { + public StringCommandNode(@NotNull String name, @NotNull List> children, @NotNull AllowedStringInputs allowedInputs, @Nullable String permission) { super(name, children, allowedInputs, permission); } - public StringCommandNode(@NotNull String name, @NotNull AllowedInputs allowedInputs, @Nullable String permission) { + public StringCommandNode(@NotNull String name, @NotNull AllowedStringInputs allowedInputs, @Nullable String permission) { super(name, allowedInputs, permission); } - public StringCommandNode(@NotNull String name, @NotNull AllowedInputs allowedInputs, @Nullable CommandNodeExecutor executor) { + public StringCommandNode(@NotNull String name, @NotNull AllowedStringInputs allowedInputs, @Nullable CommandNodeExecutor executor) { super(name, allowedInputs, executor); } - public StringCommandNode(@NotNull String name, @NotNull List> children, @NotNull AllowedInputs allowedInputs) { + public StringCommandNode(@NotNull String name, @NotNull List> children, @NotNull AllowedStringInputs allowedInputs) { super(name, children, allowedInputs); } - public StringCommandNode(@NotNull String name, @NotNull AllowedInputs allowedInputs) { + public StringCommandNode(@NotNull String name, @NotNull AllowedStringInputs allowedInputs) { super(name, allowedInputs); } + @Override + public @NotNull AllowedStringInputs getAllowedInputs() { + return (AllowedStringInputs) super.getAllowedInputs(); + } + @Override public @Nullable String parse(@NotNull String input) throws InputParsingException { return input; From 9f2b8dcc10a46d0e0432515fcd0d0a575af42038 Mon Sep 17 00:00:00 2001 From: WizardlyBump17 Date: Tue, 25 Nov 2025 21:03:23 -0300 Subject: [PATCH 168/363] registering the default factories --- .../factory/MethodCommandNodeFactory.java | 2 + .../BooleanMethodCommandNodeFactory.java | 5 +++ .../CharacterMethodCommandNodeFactory.java | 5 +++ .../NumberMethodCommandNodeFactory.java | 12 ++++++ .../StringMethodCommandNodeFactory.java | 37 +++++++++++++++++ .../AbstractPrimitiveCommandNode.java | 40 +++++++++++++++++++ .../MethodCommandNodeFactoryRegistry.java | 31 ++++++++++++++ .../MethodCommandExtractorStructureTests.java | 27 +------------ .../method/MethodCommandExtractorTests.java | 30 ++------------ 9 files changed, 137 insertions(+), 52 deletions(-) create mode 100644 commands/src/main/java/com/wizardlybump17/wlib/command/extractor/method/factory/string/StringMethodCommandNodeFactory.java create mode 100644 commands/src/main/java/com/wizardlybump17/wlib/command/node/primitive/AbstractPrimitiveCommandNode.java diff --git a/commands/src/main/java/com/wizardlybump17/wlib/command/extractor/method/factory/MethodCommandNodeFactory.java b/commands/src/main/java/com/wizardlybump17/wlib/command/extractor/method/factory/MethodCommandNodeFactory.java index 2af68d81..39441cd3 100644 --- a/commands/src/main/java/com/wizardlybump17/wlib/command/extractor/method/factory/MethodCommandNodeFactory.java +++ b/commands/src/main/java/com/wizardlybump17/wlib/command/extractor/method/factory/MethodCommandNodeFactory.java @@ -11,4 +11,6 @@ public abstract class MethodCommandNodeFactory { public abstract @NotNull CommandNode create(@NotNull Object object, @NotNull Method method, @NotNull Command commandAnnotation, @NotNull Parameter parameter, @NotNull String name, @Nullable CommandNode root); + + public abstract @NotNull Class @NotNull [] getSupportedTypes(); } diff --git a/commands/src/main/java/com/wizardlybump17/wlib/command/extractor/method/factory/primitive/BooleanMethodCommandNodeFactory.java b/commands/src/main/java/com/wizardlybump17/wlib/command/extractor/method/factory/primitive/BooleanMethodCommandNodeFactory.java index a0b9a908..b9edf057 100644 --- a/commands/src/main/java/com/wizardlybump17/wlib/command/extractor/method/factory/primitive/BooleanMethodCommandNodeFactory.java +++ b/commands/src/main/java/com/wizardlybump17/wlib/command/extractor/method/factory/primitive/BooleanMethodCommandNodeFactory.java @@ -28,4 +28,9 @@ public class BooleanMethodCommandNodeFactory extends PrimitiveMethodCommandNodeF null ); } + + @Override + public @NotNull Class @NotNull [] getSupportedTypes() { + return new Class[] {boolean.class, Boolean.class}; + } } diff --git a/commands/src/main/java/com/wizardlybump17/wlib/command/extractor/method/factory/primitive/CharacterMethodCommandNodeFactory.java b/commands/src/main/java/com/wizardlybump17/wlib/command/extractor/method/factory/primitive/CharacterMethodCommandNodeFactory.java index 56a108b8..9f95ead7 100644 --- a/commands/src/main/java/com/wizardlybump17/wlib/command/extractor/method/factory/primitive/CharacterMethodCommandNodeFactory.java +++ b/commands/src/main/java/com/wizardlybump17/wlib/command/extractor/method/factory/primitive/CharacterMethodCommandNodeFactory.java @@ -29,4 +29,9 @@ public class CharacterMethodCommandNodeFactory extends PrimitiveMethodCommandNod null ); } + + @Override + public @NotNull Class @NotNull [] getSupportedTypes() { + return new Class[] {char.class, Character.class}; + } } diff --git a/commands/src/main/java/com/wizardlybump17/wlib/command/extractor/method/factory/primitive/NumberMethodCommandNodeFactory.java b/commands/src/main/java/com/wizardlybump17/wlib/command/extractor/method/factory/primitive/NumberMethodCommandNodeFactory.java index aa8282e6..5c8eb168 100644 --- a/commands/src/main/java/com/wizardlybump17/wlib/command/extractor/method/factory/primitive/NumberMethodCommandNodeFactory.java +++ b/commands/src/main/java/com/wizardlybump17/wlib/command/extractor/method/factory/primitive/NumberMethodCommandNodeFactory.java @@ -34,4 +34,16 @@ public class NumberMethodCommandNodeFactory extends PrimitiveMethodCommandNodeFa throw new IllegalArgumentException("Unsupported type. We accept only primitive numbers: " + type); } + + @Override + public @NotNull Class @NotNull [] getSupportedTypes() { + return new Class[] { + byte.class, Byte.class, + short.class, Short.class, + int.class, Integer.class, + long.class, Long.class, + float.class, Float.class, + double.class, Double.class + }; + } } diff --git a/commands/src/main/java/com/wizardlybump17/wlib/command/extractor/method/factory/string/StringMethodCommandNodeFactory.java b/commands/src/main/java/com/wizardlybump17/wlib/command/extractor/method/factory/string/StringMethodCommandNodeFactory.java new file mode 100644 index 00000000..f8a3c9e0 --- /dev/null +++ b/commands/src/main/java/com/wizardlybump17/wlib/command/extractor/method/factory/string/StringMethodCommandNodeFactory.java @@ -0,0 +1,37 @@ +package com.wizardlybump17.wlib.command.extractor.method.factory.string; + +import com.wizardlybump17.wlib.command.annotation.Command; +import com.wizardlybump17.wlib.command.extractor.method.factory.MethodCommandNodeFactory; +import com.wizardlybump17.wlib.command.input.string.AllowedStringInputs; +import com.wizardlybump17.wlib.command.node.CommandNode; +import com.wizardlybump17.wlib.command.node.string.StringCommandNode; +import org.jetbrains.annotations.NotNull; +import org.jetbrains.annotations.Nullable; + +import java.lang.reflect.Method; +import java.lang.reflect.Parameter; +import java.util.List; + +public class StringMethodCommandNodeFactory extends MethodCommandNodeFactory { + + @Override + public @NotNull CommandNode create(@NotNull Object object, @NotNull Method method, @NotNull Command commandAnnotation, @NotNull Parameter parameter, @NotNull String name, @Nullable CommandNode root) { + Class type = parameter.getType(); + + if (type != String.class) + throw new IllegalArgumentException("Unsupported type. We accept only primitive Strings: " + type); + + return new StringCommandNode( + name, + root == null ? List.of() : List.of(root), + AllowedStringInputs.anyNotNull(), + null, + null + ); + } + + @Override + public @NotNull Class @NotNull [] getSupportedTypes() { + return new Class[] {String.class}; + } +} diff --git a/commands/src/main/java/com/wizardlybump17/wlib/command/node/primitive/AbstractPrimitiveCommandNode.java b/commands/src/main/java/com/wizardlybump17/wlib/command/node/primitive/AbstractPrimitiveCommandNode.java new file mode 100644 index 00000000..be30d4e2 --- /dev/null +++ b/commands/src/main/java/com/wizardlybump17/wlib/command/node/primitive/AbstractPrimitiveCommandNode.java @@ -0,0 +1,40 @@ +package com.wizardlybump17.wlib.command.node.primitive; + +import com.wizardlybump17.wlib.command.executor.CommandNodeExecutor; +import com.wizardlybump17.wlib.command.input.primitive.PrimitiveAllowedInputs; +import com.wizardlybump17.wlib.command.node.CommandNode; +import org.jetbrains.annotations.NotNull; +import org.jetbrains.annotations.Nullable; + +import java.util.List; + +public abstract class AbstractPrimitiveCommandNode

extends CommandNode

implements PrimitiveCommandNode { + + public AbstractPrimitiveCommandNode(@NotNull String name, @NotNull List> children, @NotNull PrimitiveAllowedInputs

allowedInputs, @Nullable CommandNodeExecutor executor, @Nullable String permission) { + super(name, children, allowedInputs, executor, permission); + } + + public AbstractPrimitiveCommandNode(@NotNull String name, @NotNull PrimitiveAllowedInputs

allowedInputs, @Nullable CommandNodeExecutor executor, @Nullable String permission) { + super(name, allowedInputs, executor, permission); + } + + public AbstractPrimitiveCommandNode(@NotNull String name, @NotNull List> children, @NotNull PrimitiveAllowedInputs

allowedInputs, @Nullable String permission) { + super(name, children, allowedInputs, permission); + } + + public AbstractPrimitiveCommandNode(@NotNull String name, @NotNull PrimitiveAllowedInputs

allowedInputs, @Nullable String permission) { + super(name, allowedInputs, permission); + } + + public AbstractPrimitiveCommandNode(@NotNull String name, @NotNull PrimitiveAllowedInputs

allowedInputs, @Nullable CommandNodeExecutor executor) { + super(name, allowedInputs, executor); + } + + public AbstractPrimitiveCommandNode(@NotNull String name, @NotNull List> children, @NotNull PrimitiveAllowedInputs

allowedInputs) { + super(name, children, allowedInputs); + } + + public AbstractPrimitiveCommandNode(@NotNull String name, @NotNull PrimitiveAllowedInputs

allowedInputs) { + super(name, allowedInputs); + } +} diff --git a/commands/src/main/java/com/wizardlybump17/wlib/command/registry/MethodCommandNodeFactoryRegistry.java b/commands/src/main/java/com/wizardlybump17/wlib/command/registry/MethodCommandNodeFactoryRegistry.java index 2b37db34..3908c759 100644 --- a/commands/src/main/java/com/wizardlybump17/wlib/command/registry/MethodCommandNodeFactoryRegistry.java +++ b/commands/src/main/java/com/wizardlybump17/wlib/command/registry/MethodCommandNodeFactoryRegistry.java @@ -1,6 +1,10 @@ package com.wizardlybump17.wlib.command.registry; import com.wizardlybump17.wlib.command.extractor.method.factory.MethodCommandNodeFactory; +import com.wizardlybump17.wlib.command.extractor.method.factory.primitive.BooleanMethodCommandNodeFactory; +import com.wizardlybump17.wlib.command.extractor.method.factory.primitive.CharacterMethodCommandNodeFactory; +import com.wizardlybump17.wlib.command.extractor.method.factory.primitive.NumberMethodCommandNodeFactory; +import com.wizardlybump17.wlib.command.extractor.method.factory.string.StringMethodCommandNodeFactory; import org.jetbrains.annotations.ApiStatus; import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.Nullable; @@ -30,6 +34,10 @@ public void addFactory(@NotNull MethodCommandNodeFactory factory, @NotNull Class addFactory(clazz, factory); } + public void addFactory(@NotNull MethodCommandNodeFactory factory) { + addFactory(factory, factory.getSupportedTypes()); + } + public @Nullable MethodCommandNodeFactory getFactory(@NotNull Class clazz) { return factories.get(clazz); } @@ -59,9 +67,32 @@ public void clear() { @ApiStatus.Internal public void registerDefaults() { + addFactory(new BooleanMethodCommandNodeFactory()); + addFactory(new CharacterMethodCommandNodeFactory()); + addFactory(new NumberMethodCommandNodeFactory()); + addFactory(new StringMethodCommandNodeFactory()); } @ApiStatus.Internal public void unregisterDefaults() { + removeFactory( + boolean.class, + Boolean.class, + char.class, + Character.class, + byte.class, + Byte.class, + short.class, + Short.class, + int.class, + Integer.class, + long.class, + Long.class, + float.class, + Float.class, + double.class, + Double.class, + String.class + ); } } diff --git a/commands/src/test/java/com/wizardlybump17/wlib/test/command/extractor/method/MethodCommandExtractorStructureTests.java b/commands/src/test/java/com/wizardlybump17/wlib/test/command/extractor/method/MethodCommandExtractorStructureTests.java index 13aa6cc0..55791539 100644 --- a/commands/src/test/java/com/wizardlybump17/wlib/test/command/extractor/method/MethodCommandExtractorStructureTests.java +++ b/commands/src/test/java/com/wizardlybump17/wlib/test/command/extractor/method/MethodCommandExtractorStructureTests.java @@ -2,24 +2,16 @@ import com.wizardlybump17.wlib.command.Command; import com.wizardlybump17.wlib.command.extractor.CommandExtractor; -import com.wizardlybump17.wlib.command.extractor.method.factory.MethodCommandNodeFactory; import com.wizardlybump17.wlib.command.input.primitive.number.AllowedIntegerInputs; -import com.wizardlybump17.wlib.command.input.string.AllowedStringInputs; -import com.wizardlybump17.wlib.command.node.CommandNode; import com.wizardlybump17.wlib.command.node.LiteralCommandNode; import com.wizardlybump17.wlib.command.node.primitive.number.IntegerCommandNode; -import com.wizardlybump17.wlib.command.node.string.StringCommandNode; import com.wizardlybump17.wlib.command.registry.MethodCommandNodeFactoryRegistry; import com.wizardlybump17.wlib.test.util.AssertionUtil; -import org.jetbrains.annotations.NotNull; -import org.jetbrains.annotations.Nullable; import org.junit.jupiter.api.AfterAll; import org.junit.jupiter.api.Assertions; import org.junit.jupiter.api.BeforeAll; import org.junit.jupiter.api.Test; -import java.lang.reflect.Method; -import java.lang.reflect.Parameter; import java.util.ArrayList; import java.util.List; @@ -27,24 +19,7 @@ class MethodCommandExtractorStructureTests { @BeforeAll static void setup() { - MethodCommandNodeFactoryRegistry.INSTANCE.addFactory( - int.class, - new MethodCommandNodeFactory() { - @Override - public @NotNull IntegerCommandNode create(@NotNull Object object, @NotNull Method method, com.wizardlybump17.wlib.command.annotation.@NotNull Command commandAnnotation, @NotNull Parameter parameter, @NotNull String name, @Nullable CommandNode root) { - return new IntegerCommandNode(name, root == null ? List.of() : List.of(root), AllowedIntegerInputs.unlimited()); - } - } - ); - MethodCommandNodeFactoryRegistry.INSTANCE.addFactory( - String.class, - new MethodCommandNodeFactory() { - @Override - public @NotNull StringCommandNode create(@NotNull Object object, @NotNull Method method, com.wizardlybump17.wlib.command.annotation.@NotNull Command commandAnnotation, @NotNull Parameter parameter, @NotNull String name, @Nullable CommandNode root) { - return new StringCommandNode(name, root == null ? List.of() : List.of(root), AllowedStringInputs.anyNullable()); - } - } - ); + MethodCommandNodeFactoryRegistry.INSTANCE.registerDefaults(); } @AfterAll diff --git a/commands/src/test/java/com/wizardlybump17/wlib/test/command/extractor/method/MethodCommandExtractorTests.java b/commands/src/test/java/com/wizardlybump17/wlib/test/command/extractor/method/MethodCommandExtractorTests.java index 1582f95c..47ec9f61 100644 --- a/commands/src/test/java/com/wizardlybump17/wlib/test/command/extractor/method/MethodCommandExtractorTests.java +++ b/commands/src/test/java/com/wizardlybump17/wlib/test/command/extractor/method/MethodCommandExtractorTests.java @@ -4,11 +4,9 @@ import com.wizardlybump17.wlib.command.context.CommandContext; import com.wizardlybump17.wlib.command.extractor.CommandExtractor; import com.wizardlybump17.wlib.command.extractor.method.MethodCommandExtractor; -import com.wizardlybump17.wlib.command.extractor.method.factory.MethodCommandNodeFactory; import com.wizardlybump17.wlib.command.input.primitive.number.AllowedIntegerInputs; import com.wizardlybump17.wlib.command.input.string.AllowedStringInputs; import com.wizardlybump17.wlib.command.manager.CommandManager; -import com.wizardlybump17.wlib.command.node.CommandNode; import com.wizardlybump17.wlib.command.node.LiteralCommandNode; import com.wizardlybump17.wlib.command.node.primitive.number.IntegerCommandNode; import com.wizardlybump17.wlib.command.node.string.StringCommandNode; @@ -17,14 +15,11 @@ import com.wizardlybump17.wlib.command.sender.BasicCommandSender; import com.wizardlybump17.wlib.command.sender.CommandSender; import org.jetbrains.annotations.NotNull; -import org.jetbrains.annotations.Nullable; import org.junit.jupiter.api.AfterAll; import org.junit.jupiter.api.Assertions; import org.junit.jupiter.api.BeforeAll; import org.junit.jupiter.api.Test; -import java.lang.reflect.Method; -import java.lang.reflect.Parameter; import java.util.ArrayList; import java.util.List; import java.util.UUID; @@ -34,24 +29,7 @@ class MethodCommandExtractorTests { @BeforeAll static void setup() { - MethodCommandNodeFactoryRegistry.INSTANCE.addFactory( - int.class, - new MethodCommandNodeFactory() { - @Override - public @NotNull IntegerCommandNode create(@NotNull Object object, @NotNull Method method, com.wizardlybump17.wlib.command.annotation.@NotNull Command commandAnnotation, @NotNull Parameter parameter, @NotNull String name, @Nullable CommandNode root) { - return new IntegerCommandNode(name, root == null ? List.of() : List.of(root), AllowedIntegerInputs.unlimited()); - } - } - ); - MethodCommandNodeFactoryRegistry.INSTANCE.addFactory( - String.class, - new MethodCommandNodeFactory() { - @Override - public @NotNull StringCommandNode create(@NotNull Object object, @NotNull Method method, com.wizardlybump17.wlib.command.annotation.@NotNull Command commandAnnotation, @NotNull Parameter parameter, @NotNull String name, @Nullable CommandNode root) { - return new StringCommandNode(name, root == null ? List.of() : List.of(root), AllowedStringInputs.anyNullable()); - } - } - ); + MethodCommandNodeFactoryRegistry.INSTANCE.registerDefaults(); } @AfterAll @@ -1019,7 +997,7 @@ void testExecute() { Assertions.assertDoesNotThrow(() -> MethodCommandExtractor.createExecutor(object, "welcomeWorld", CommandSender.class, String.class)) ) ), - AllowedStringInputs.anyNullable(), + AllowedStringInputs.anyNotNull(), Assertions.assertDoesNotThrow(() -> MethodCommandExtractor.createExecutor(object, "welcome", CommandSender.class, String.class)), null ) @@ -1038,7 +1016,7 @@ void testExecute() { Assertions.assertDoesNotThrow(() -> MethodCommandExtractor.createExecutor(object, "wassupNice", CommandContext.class, String.class)) ) ), - AllowedStringInputs.anyNullable(), + AllowedStringInputs.anyNotNull(), Assertions.assertDoesNotThrow(() -> MethodCommandExtractor.createExecutor(object, "wassup", CommandContext.class, String.class)), null ) @@ -1057,7 +1035,7 @@ void testExecute() { Assertions.assertDoesNotThrow(() -> MethodCommandExtractor.createExecutor(object, "ayeNice", String.class)) ) ), - AllowedStringInputs.anyNullable(), + AllowedStringInputs.anyNotNull(), Assertions.assertDoesNotThrow(() -> MethodCommandExtractor.createExecutor(object, "aye", String.class)), null ) From d68b1f51b7a1df2f8202c5170e5a539e5b174d15 Mon Sep 17 00:00:00 2001 From: WizardlyBump17 Date: Tue, 25 Nov 2025 21:06:29 -0300 Subject: [PATCH 169/363] are we liberal or conservative? --- .../factory/MethodCommandNodeFactory.java | 18 ++++++++++++++++++ .../BooleanMethodCommandNodeFactory.java | 3 +-- .../CharacterMethodCommandNodeFactory.java | 3 +-- .../NumberMethodCommandNodeFactory.java | 2 ++ .../string/StringMethodCommandNodeFactory.java | 3 +-- 5 files changed, 23 insertions(+), 6 deletions(-) diff --git a/commands/src/main/java/com/wizardlybump17/wlib/command/extractor/method/factory/MethodCommandNodeFactory.java b/commands/src/main/java/com/wizardlybump17/wlib/command/extractor/method/factory/MethodCommandNodeFactory.java index 39441cd3..9ed8be17 100644 --- a/commands/src/main/java/com/wizardlybump17/wlib/command/extractor/method/factory/MethodCommandNodeFactory.java +++ b/commands/src/main/java/com/wizardlybump17/wlib/command/extractor/method/factory/MethodCommandNodeFactory.java @@ -13,4 +13,22 @@ public abstract class MethodCommandNodeFactory { public abstract @NotNull CommandNode create(@NotNull Object object, @NotNull Method method, @NotNull Command commandAnnotation, @NotNull Parameter parameter, @NotNull String name, @Nullable CommandNode root); public abstract @NotNull Class @NotNull [] getSupportedTypes(); + + public boolean isSupported(@NotNull Class type) { + if (isStrict()) { + for (Class supportedType : getSupportedTypes()) + if (supportedType.equals(type)) + return true; + return false; + } + + for (Class supportedType : getSupportedTypes()) + if (supportedType.isAssignableFrom(type)) + return true; + return false; + } + + public boolean isStrict() { + return true; + } } diff --git a/commands/src/main/java/com/wizardlybump17/wlib/command/extractor/method/factory/primitive/BooleanMethodCommandNodeFactory.java b/commands/src/main/java/com/wizardlybump17/wlib/command/extractor/method/factory/primitive/BooleanMethodCommandNodeFactory.java index b9edf057..ca4e1174 100644 --- a/commands/src/main/java/com/wizardlybump17/wlib/command/extractor/method/factory/primitive/BooleanMethodCommandNodeFactory.java +++ b/commands/src/main/java/com/wizardlybump17/wlib/command/extractor/method/factory/primitive/BooleanMethodCommandNodeFactory.java @@ -16,8 +16,7 @@ public class BooleanMethodCommandNodeFactory extends PrimitiveMethodCommandNodeF @Override public @NotNull BooleanCommandNode create(@NotNull Object object, @NotNull Method method, @NotNull Command commandAnnotation, @NotNull Parameter parameter, @NotNull String name, @Nullable CommandNode root) { Class type = parameter.getType(); - - if (type != boolean.class && type != Boolean.class) + if (isSupported(type)) throw new IllegalArgumentException("Unsupported type. We only accept booleans: " + type); return new BooleanCommandNode( diff --git a/commands/src/main/java/com/wizardlybump17/wlib/command/extractor/method/factory/primitive/CharacterMethodCommandNodeFactory.java b/commands/src/main/java/com/wizardlybump17/wlib/command/extractor/method/factory/primitive/CharacterMethodCommandNodeFactory.java index 9f95ead7..ebb0eba8 100644 --- a/commands/src/main/java/com/wizardlybump17/wlib/command/extractor/method/factory/primitive/CharacterMethodCommandNodeFactory.java +++ b/commands/src/main/java/com/wizardlybump17/wlib/command/extractor/method/factory/primitive/CharacterMethodCommandNodeFactory.java @@ -17,8 +17,7 @@ public class CharacterMethodCommandNodeFactory extends PrimitiveMethodCommandNod @Override public @NotNull AbstractPrimitiveCommandNode create(@NotNull Object object, @NotNull Method method, @NotNull Command commandAnnotation, @NotNull Parameter parameter, @NotNull String name, @Nullable CommandNode root) { Class type = parameter.getType(); - - if (type != char.class && type != Character.class) + if (!isSupported(type)) throw new IllegalArgumentException("Unsupported type. We only accept chars: " + type); return new CharacterCommandNode( diff --git a/commands/src/main/java/com/wizardlybump17/wlib/command/extractor/method/factory/primitive/NumberMethodCommandNodeFactory.java b/commands/src/main/java/com/wizardlybump17/wlib/command/extractor/method/factory/primitive/NumberMethodCommandNodeFactory.java index 5c8eb168..82b371f3 100644 --- a/commands/src/main/java/com/wizardlybump17/wlib/command/extractor/method/factory/primitive/NumberMethodCommandNodeFactory.java +++ b/commands/src/main/java/com/wizardlybump17/wlib/command/extractor/method/factory/primitive/NumberMethodCommandNodeFactory.java @@ -16,6 +16,8 @@ public class NumberMethodCommandNodeFactory extends PrimitiveMethodCommandNodeFa @Override public @NotNull NumberCommandNode create(@NotNull Object object, @NotNull Method method, @NotNull Command commandAnnotation, @NotNull Parameter parameter, @NotNull String name, @Nullable CommandNode root) { Class type = parameter.getType(); + if (!isSupported(type)) + throw new IllegalArgumentException("Unsupported type. We accept only primitive numbers: " + type); List> children = root == null ? List.of() : List.of(root); diff --git a/commands/src/main/java/com/wizardlybump17/wlib/command/extractor/method/factory/string/StringMethodCommandNodeFactory.java b/commands/src/main/java/com/wizardlybump17/wlib/command/extractor/method/factory/string/StringMethodCommandNodeFactory.java index f8a3c9e0..393dddf0 100644 --- a/commands/src/main/java/com/wizardlybump17/wlib/command/extractor/method/factory/string/StringMethodCommandNodeFactory.java +++ b/commands/src/main/java/com/wizardlybump17/wlib/command/extractor/method/factory/string/StringMethodCommandNodeFactory.java @@ -17,8 +17,7 @@ public class StringMethodCommandNodeFactory extends MethodCommandNodeFactory { @Override public @NotNull CommandNode create(@NotNull Object object, @NotNull Method method, @NotNull Command commandAnnotation, @NotNull Parameter parameter, @NotNull String name, @Nullable CommandNode root) { Class type = parameter.getType(); - - if (type != String.class) + if (!isSupported(type)) throw new IllegalArgumentException("Unsupported type. We accept only primitive Strings: " + type); return new StringCommandNode( From 2ad62087a9cfc315da7526b17ef38028cfbbad3e Mon Sep 17 00:00:00 2001 From: WizardlyBump17 Date: Tue, 25 Nov 2025 21:11:48 -0300 Subject: [PATCH 170/363] CTRL C CTRL V moment --- .../method/factory/string/StringMethodCommandNodeFactory.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/commands/src/main/java/com/wizardlybump17/wlib/command/extractor/method/factory/string/StringMethodCommandNodeFactory.java b/commands/src/main/java/com/wizardlybump17/wlib/command/extractor/method/factory/string/StringMethodCommandNodeFactory.java index 393dddf0..711cdf54 100644 --- a/commands/src/main/java/com/wizardlybump17/wlib/command/extractor/method/factory/string/StringMethodCommandNodeFactory.java +++ b/commands/src/main/java/com/wizardlybump17/wlib/command/extractor/method/factory/string/StringMethodCommandNodeFactory.java @@ -18,7 +18,7 @@ public class StringMethodCommandNodeFactory extends MethodCommandNodeFactory { public @NotNull CommandNode create(@NotNull Object object, @NotNull Method method, @NotNull Command commandAnnotation, @NotNull Parameter parameter, @NotNull String name, @Nullable CommandNode root) { Class type = parameter.getType(); if (!isSupported(type)) - throw new IllegalArgumentException("Unsupported type. We accept only primitive Strings: " + type); + throw new IllegalArgumentException("Unsupported type. We accept only Strings: " + type); return new StringCommandNode( name, From 7388a42c6e940373d22c407c860e767cb57e0ad5 Mon Sep 17 00:00:00 2001 From: WizardlyBump17 Date: Tue, 25 Nov 2025 21:13:39 -0300 Subject: [PATCH 171/363] added the UUID CommandNode extractor --- .../object/UUIDMethodCommandNodeFactory.java | 36 +++++++++++++++++++ .../MethodCommandNodeFactoryRegistry.java | 6 +++- 2 files changed, 41 insertions(+), 1 deletion(-) create mode 100644 commands/src/main/java/com/wizardlybump17/wlib/command/extractor/method/factory/object/UUIDMethodCommandNodeFactory.java diff --git a/commands/src/main/java/com/wizardlybump17/wlib/command/extractor/method/factory/object/UUIDMethodCommandNodeFactory.java b/commands/src/main/java/com/wizardlybump17/wlib/command/extractor/method/factory/object/UUIDMethodCommandNodeFactory.java new file mode 100644 index 00000000..cc928a37 --- /dev/null +++ b/commands/src/main/java/com/wizardlybump17/wlib/command/extractor/method/factory/object/UUIDMethodCommandNodeFactory.java @@ -0,0 +1,36 @@ +package com.wizardlybump17.wlib.command.extractor.method.factory.object; + +import com.wizardlybump17.wlib.command.annotation.Command; +import com.wizardlybump17.wlib.command.extractor.method.factory.MethodCommandNodeFactory; +import com.wizardlybump17.wlib.command.input.object.AllowedUUIDInputs; +import com.wizardlybump17.wlib.command.node.CommandNode; +import com.wizardlybump17.wlib.command.node.object.UUIDCommandNode; +import org.jetbrains.annotations.NotNull; +import org.jetbrains.annotations.Nullable; + +import java.lang.reflect.Method; +import java.lang.reflect.Parameter; +import java.util.List; +import java.util.UUID; + +public class UUIDMethodCommandNodeFactory extends MethodCommandNodeFactory { + + @Override + public @NotNull CommandNode create(@NotNull Object object, @NotNull Method method, @NotNull Command commandAnnotation, @NotNull Parameter parameter, @NotNull String name, @Nullable CommandNode root) { + if (!isSupported(parameter.getType())) + throw new IllegalArgumentException("Unsupported type. We only accept UUIDs: " + parameter); + + return new UUIDCommandNode( + name, + root == null ? List.of() : List.of(root), + AllowedUUIDInputs.anyNotNull(), + null, + null + ); + } + + @Override + public @NotNull Class @NotNull [] getSupportedTypes() { + return new Class[] {UUID.class}; + } +} diff --git a/commands/src/main/java/com/wizardlybump17/wlib/command/registry/MethodCommandNodeFactoryRegistry.java b/commands/src/main/java/com/wizardlybump17/wlib/command/registry/MethodCommandNodeFactoryRegistry.java index 3908c759..0d515d86 100644 --- a/commands/src/main/java/com/wizardlybump17/wlib/command/registry/MethodCommandNodeFactoryRegistry.java +++ b/commands/src/main/java/com/wizardlybump17/wlib/command/registry/MethodCommandNodeFactoryRegistry.java @@ -1,6 +1,7 @@ package com.wizardlybump17.wlib.command.registry; import com.wizardlybump17.wlib.command.extractor.method.factory.MethodCommandNodeFactory; +import com.wizardlybump17.wlib.command.extractor.method.factory.object.UUIDMethodCommandNodeFactory; import com.wizardlybump17.wlib.command.extractor.method.factory.primitive.BooleanMethodCommandNodeFactory; import com.wizardlybump17.wlib.command.extractor.method.factory.primitive.CharacterMethodCommandNodeFactory; import com.wizardlybump17.wlib.command.extractor.method.factory.primitive.NumberMethodCommandNodeFactory; @@ -13,6 +14,7 @@ import java.util.Collections; import java.util.HashMap; import java.util.Map; +import java.util.UUID; public final class MethodCommandNodeFactoryRegistry { @@ -71,6 +73,7 @@ public void registerDefaults() { addFactory(new CharacterMethodCommandNodeFactory()); addFactory(new NumberMethodCommandNodeFactory()); addFactory(new StringMethodCommandNodeFactory()); + addFactory(new UUIDMethodCommandNodeFactory()); } @ApiStatus.Internal @@ -92,7 +95,8 @@ public void unregisterDefaults() { Float.class, double.class, Double.class, - String.class + String.class, + UUID.class ); } } From 8b9babd0ff5ee0cfe4ce59dfed3cd4d45ee59bb0 Mon Sep 17 00:00:00 2001 From: WizardlyBump17 Date: Sat, 29 Nov 2025 23:02:42 -0300 Subject: [PATCH 172/363] dependency injection --- .../command/extractor/CommandExtractor.java | 7 +++- .../method/MethodCommandExtractor.java | 16 ++++++-- .../MethodCommandNodeFactoryRegistry.java | 5 --- .../MethodCommandExtractorStructureTests.java | 18 +++++++-- .../method/MethodCommandExtractorTests.java | 39 ++++++++++++------- 5 files changed, 55 insertions(+), 30 deletions(-) diff --git a/commands/src/main/java/com/wizardlybump17/wlib/command/extractor/CommandExtractor.java b/commands/src/main/java/com/wizardlybump17/wlib/command/extractor/CommandExtractor.java index b70eb4f8..d6dc28e4 100644 --- a/commands/src/main/java/com/wizardlybump17/wlib/command/extractor/CommandExtractor.java +++ b/commands/src/main/java/com/wizardlybump17/wlib/command/extractor/CommandExtractor.java @@ -3,15 +3,18 @@ import com.wizardlybump17.wlib.command.Command; import com.wizardlybump17.wlib.command.exception.extractor.CommandExtractorException; import com.wizardlybump17.wlib.command.extractor.method.MethodCommandExtractor; +import com.wizardlybump17.wlib.command.registry.MethodCommandNodeFactoryRegistry; import org.jetbrains.annotations.NotNull; import java.util.List; public interface CommandExtractor { - @NotNull MethodCommandExtractor METHOD = MethodCommandExtractor.INSTANCE; - boolean isAccepted(@NotNull Object object); @NotNull List extract(@NotNull Object object) throws CommandExtractorException; + + static @NotNull MethodCommandExtractor method(@NotNull MethodCommandNodeFactoryRegistry factoryRegistry) { + return new MethodCommandExtractor(factoryRegistry); + } } diff --git a/commands/src/main/java/com/wizardlybump17/wlib/command/extractor/method/MethodCommandExtractor.java b/commands/src/main/java/com/wizardlybump17/wlib/command/extractor/method/MethodCommandExtractor.java index 8a67389a..aae7f624 100644 --- a/commands/src/main/java/com/wizardlybump17/wlib/command/extractor/method/MethodCommandExtractor.java +++ b/commands/src/main/java/com/wizardlybump17/wlib/command/extractor/method/MethodCommandExtractor.java @@ -22,13 +22,21 @@ public class MethodCommandExtractor implements CommandExtractor { - public static final @NotNull MethodCommandExtractor INSTANCE = new MethodCommandExtractor(); + private final @NotNull MethodCommandNodeFactoryRegistry factoryRegistry; + + public MethodCommandExtractor(@NotNull MethodCommandNodeFactoryRegistry factoryRegistry) { + this.factoryRegistry = factoryRegistry; + } @Override public boolean isAccepted(@NotNull Object object) { return true; } + public @NotNull MethodCommandNodeFactoryRegistry getFactoryRegistry() { + return factoryRegistry; + } + @Override public @NotNull List extract(@NotNull Object object) throws MethodCommandNodeFactoryNotFoundException { List commands = new ArrayList<>(); @@ -52,7 +60,7 @@ public boolean isAccepted(@NotNull Object object) { String part = commandParts[i]; CommandNode oldRoot = root; - root = createNode(part, parameters, parameterIndex, root, annotation, object, method); + root = createNode(factoryRegistry, part, parameters, parameterIndex, root, annotation, object, method); if (!(root instanceof LiteralCommandNode)) parameterIndex--; @@ -69,7 +77,7 @@ public boolean isAccepted(@NotNull Object object) { return commands; } - private static @NotNull CommandNode createNode(@NotNull String part, @NotNull Parameter @NotNull [] parameters, int parameterIndex, @Nullable CommandNode root, @NotNull com.wizardlybump17.wlib.command.annotation.Command annotation, @NotNull Object object, @NotNull Method method) throws MethodCommandNodeFactoryNotFoundException { + private static @NotNull CommandNode createNode(@NotNull MethodCommandNodeFactoryRegistry factoryRegistry, @NotNull String part, @NotNull Parameter @NotNull [] parameters, int parameterIndex, @Nullable CommandNode root, @NotNull com.wizardlybump17.wlib.command.annotation.Command annotation, @NotNull Object object, @NotNull Method method) throws MethodCommandNodeFactoryNotFoundException { CommandNode newNode; boolean argument = part.charAt(0) == '<' && part.charAt(part.length() - 1) == '>'; @@ -83,7 +91,7 @@ public boolean isAccepted(@NotNull Object object) { Parameter parameter = parameters[parameterIndex]; Class parameterType = parameter.getType(); - MethodCommandNodeFactory factory = MethodCommandNodeFactoryRegistry.INSTANCE.getFactory(parameterType); + MethodCommandNodeFactory factory = factoryRegistry.getFactory(parameterType); if (factory == null) throw new MethodCommandNodeFactoryNotFoundException("MethodCommandNodeFactory not found for the parameter " + parameter); diff --git a/commands/src/main/java/com/wizardlybump17/wlib/command/registry/MethodCommandNodeFactoryRegistry.java b/commands/src/main/java/com/wizardlybump17/wlib/command/registry/MethodCommandNodeFactoryRegistry.java index 0d515d86..f8df2b2e 100644 --- a/commands/src/main/java/com/wizardlybump17/wlib/command/registry/MethodCommandNodeFactoryRegistry.java +++ b/commands/src/main/java/com/wizardlybump17/wlib/command/registry/MethodCommandNodeFactoryRegistry.java @@ -18,11 +18,6 @@ public final class MethodCommandNodeFactoryRegistry { - public static final @NotNull MethodCommandNodeFactoryRegistry INSTANCE = new MethodCommandNodeFactoryRegistry(); - - private MethodCommandNodeFactoryRegistry() { - } - private final @NotNull Map, MethodCommandNodeFactory> factories = new HashMap<>(); public void addFactory(@NotNull Class clazz, @NotNull MethodCommandNodeFactory factory) { diff --git a/commands/src/test/java/com/wizardlybump17/wlib/test/command/extractor/method/MethodCommandExtractorStructureTests.java b/commands/src/test/java/com/wizardlybump17/wlib/test/command/extractor/method/MethodCommandExtractorStructureTests.java index 55791539..a7e6fc39 100644 --- a/commands/src/test/java/com/wizardlybump17/wlib/test/command/extractor/method/MethodCommandExtractorStructureTests.java +++ b/commands/src/test/java/com/wizardlybump17/wlib/test/command/extractor/method/MethodCommandExtractorStructureTests.java @@ -2,6 +2,7 @@ import com.wizardlybump17.wlib.command.Command; import com.wizardlybump17.wlib.command.extractor.CommandExtractor; +import com.wizardlybump17.wlib.command.extractor.method.MethodCommandExtractor; import com.wizardlybump17.wlib.command.input.primitive.number.AllowedIntegerInputs; import com.wizardlybump17.wlib.command.node.LiteralCommandNode; import com.wizardlybump17.wlib.command.node.primitive.number.IntegerCommandNode; @@ -17,14 +18,23 @@ class MethodCommandExtractorStructureTests { + static MethodCommandExtractor methodCommandExtractor; + @BeforeAll static void setup() { - MethodCommandNodeFactoryRegistry.INSTANCE.registerDefaults(); + MethodCommandNodeFactoryRegistry registry = new MethodCommandNodeFactoryRegistry(); + registry.registerDefaults(); + methodCommandExtractor = CommandExtractor.method(registry); } @AfterAll static void clear() { - MethodCommandNodeFactoryRegistry.INSTANCE.clear(); + if (methodCommandExtractor == null) + return; + + MethodCommandNodeFactoryRegistry registry = methodCommandExtractor.getFactoryRegistry(); + registry.clear(); + methodCommandExtractor = null; } @Test @@ -58,7 +68,7 @@ void test0() { Test0 object = new Test0(); List expected = new ArrayList<>(List.of(test0, test1)); - List actual = Assertions.assertDoesNotThrow(() -> CommandExtractor.METHOD.extract(object)); + List actual = Assertions.assertDoesNotThrow(() -> methodCommandExtractor.extract(object)); expected.sort(null); actual.sort(null); @@ -126,7 +136,7 @@ void test1() { Test1 object = new Test1(); List expected = new ArrayList<>(List.of(test0, test1)); - List actual = Assertions.assertDoesNotThrow(() -> CommandExtractor.METHOD.extract(object)); + List actual = Assertions.assertDoesNotThrow(() -> methodCommandExtractor.extract(object)); expected.sort(null); actual.sort(null); diff --git a/commands/src/test/java/com/wizardlybump17/wlib/test/command/extractor/method/MethodCommandExtractorTests.java b/commands/src/test/java/com/wizardlybump17/wlib/test/command/extractor/method/MethodCommandExtractorTests.java index 47ec9f61..cba0cd14 100644 --- a/commands/src/test/java/com/wizardlybump17/wlib/test/command/extractor/method/MethodCommandExtractorTests.java +++ b/commands/src/test/java/com/wizardlybump17/wlib/test/command/extractor/method/MethodCommandExtractorTests.java @@ -27,14 +27,23 @@ class MethodCommandExtractorTests { + static MethodCommandExtractor methodCommandExtractor; + @BeforeAll static void setup() { - MethodCommandNodeFactoryRegistry.INSTANCE.registerDefaults(); + MethodCommandNodeFactoryRegistry registry = new MethodCommandNodeFactoryRegistry(); + registry.registerDefaults(); + methodCommandExtractor = CommandExtractor.method(registry); } @AfterAll static void clear() { - MethodCommandNodeFactoryRegistry.INSTANCE.clear(); + if (methodCommandExtractor == null) + return; + + MethodCommandNodeFactoryRegistry registry = methodCommandExtractor.getFactoryRegistry(); + registry.clear(); + methodCommandExtractor = null; } /* @@ -79,7 +88,7 @@ void testNoParameters() { ) ) )); - List actual = Assertions.assertDoesNotThrow(() -> CommandExtractor.METHOD.extract(object)); + List actual = Assertions.assertDoesNotThrow(() -> methodCommandExtractor.extract(object)); expected.sort(null); actual.sort(null); @@ -144,7 +153,7 @@ void testNoParametersCommandResult() { ) ) )); - List actual = Assertions.assertDoesNotThrow(() -> CommandExtractor.METHOD.extract(object)); + List actual = Assertions.assertDoesNotThrow(() -> methodCommandExtractor.extract(object)); expected.sort(null); actual.sort(null); @@ -213,7 +222,7 @@ void testCommandSender() { ) ) )); - List actual = Assertions.assertDoesNotThrow(() -> CommandExtractor.METHOD.extract(object)); + List actual = Assertions.assertDoesNotThrow(() -> methodCommandExtractor.extract(object)); expected.sort(null); actual.sort(null); @@ -275,7 +284,7 @@ void testCommandContext() { ) ) )); - List actual = Assertions.assertDoesNotThrow(() -> CommandExtractor.METHOD.extract(object)); + List actual = Assertions.assertDoesNotThrow(() -> methodCommandExtractor.extract(object)); expected.sort(null); actual.sort(null); @@ -341,7 +350,7 @@ void testCommandContextCommandResult() { ) ) )); - List actual = Assertions.assertDoesNotThrow(() -> CommandExtractor.METHOD.extract(object)); + List actual = Assertions.assertDoesNotThrow(() -> methodCommandExtractor.extract(object)); expected.sort(null); actual.sort(null); @@ -406,7 +415,7 @@ void testCommandSenderCommandResult() { ) ) )); - List actual = Assertions.assertDoesNotThrow(() -> CommandExtractor.METHOD.extract(object)); + List actual = Assertions.assertDoesNotThrow(() -> methodCommandExtractor.extract(object)); expected.sort(null); actual.sort(null); @@ -493,7 +502,7 @@ void testCommandSenderParameters() { ) ) )); - List actual = Assertions.assertDoesNotThrow(() -> CommandExtractor.METHOD.extract(object)); + List actual = Assertions.assertDoesNotThrow(() -> methodCommandExtractor.extract(object)); expected.sort(null); actual.sort(null); @@ -573,7 +582,7 @@ void testCommandContextParameters() { ) ) )); - List actual = Assertions.assertDoesNotThrow(() -> CommandExtractor.METHOD.extract(object)); + List actual = Assertions.assertDoesNotThrow(() -> methodCommandExtractor.extract(object)); expected.sort(null); actual.sort(null); @@ -657,7 +666,7 @@ void testCommandSenderParametersCommandResult() { ) ) )); - List actual = Assertions.assertDoesNotThrow(() -> CommandExtractor.METHOD.extract(object)); + List actual = Assertions.assertDoesNotThrow(() -> methodCommandExtractor.extract(object)); expected.sort(null); actual.sort(null); @@ -740,7 +749,7 @@ void testCommandContextParametersCommandResult() { ) ) )); - List actual = Assertions.assertDoesNotThrow(() -> CommandExtractor.METHOD.extract(object)); + List actual = Assertions.assertDoesNotThrow(() -> methodCommandExtractor.extract(object)); expected.sort(null); actual.sort(null); @@ -827,7 +836,7 @@ void testParametersPure() { ) ) )); - List actual = Assertions.assertDoesNotThrow(() -> CommandExtractor.METHOD.extract(object)); + List actual = Assertions.assertDoesNotThrow(() -> methodCommandExtractor.extract(object)); expected.sort(null); actual.sort(null); @@ -911,7 +920,7 @@ void testParametersPureCommandResult() { ) ) )); - List actual = Assertions.assertDoesNotThrow(() -> CommandExtractor.METHOD.extract(object)); + List actual = Assertions.assertDoesNotThrow(() -> methodCommandExtractor.extract(object)); expected.sort(null); actual.sort(null); @@ -1043,7 +1052,7 @@ void testExecute() { ) ); - List extractedCommands = Assertions.assertDoesNotThrow(() -> CommandExtractor.METHOD.extract(object)); + List extractedCommands = Assertions.assertDoesNotThrow(() -> methodCommandExtractor.extract(object)); CommandManager manager = new CommandManager(); From 95dd2833c29cef13bb94032a2188665bb37feb3f Mon Sep 17 00:00:00 2001 From: WizardlyBump17 Date: Sun, 30 Nov 2025 15:56:32 -0300 Subject: [PATCH 173/363] different toStrings --- .../command/input/primitive/number/AllowedByteInputs.java | 5 +++++ .../command/input/primitive/number/AllowedDoubleInputs.java | 5 +++++ .../command/input/primitive/number/AllowedFloatInputs.java | 5 +++++ .../command/input/primitive/number/AllowedIntegerInputs.java | 5 +++++ .../command/input/primitive/number/AllowedLongInputs.java | 5 +++++ .../command/input/primitive/number/AllowedNumberInputs.java | 5 ----- .../command/input/primitive/number/AllowedShortInputs.java | 5 +++++ 7 files changed, 30 insertions(+), 5 deletions(-) diff --git a/commands/src/main/java/com/wizardlybump17/wlib/command/input/primitive/number/AllowedByteInputs.java b/commands/src/main/java/com/wizardlybump17/wlib/command/input/primitive/number/AllowedByteInputs.java index 0a19b97d..0988a0e5 100644 --- a/commands/src/main/java/com/wizardlybump17/wlib/command/input/primitive/number/AllowedByteInputs.java +++ b/commands/src/main/java/com/wizardlybump17/wlib/command/input/primitive/number/AllowedByteInputs.java @@ -82,6 +82,11 @@ private Unlimited() { (byte) 127 ); } + + @Override + public String toString() { + return "AllowedByteInputs$Unlimited{}"; + } } final class Positive extends AllowedNumberInputs.Positive implements AllowedByteInputs { diff --git a/commands/src/main/java/com/wizardlybump17/wlib/command/input/primitive/number/AllowedDoubleInputs.java b/commands/src/main/java/com/wizardlybump17/wlib/command/input/primitive/number/AllowedDoubleInputs.java index b02eef66..6d49813a 100644 --- a/commands/src/main/java/com/wizardlybump17/wlib/command/input/primitive/number/AllowedDoubleInputs.java +++ b/commands/src/main/java/com/wizardlybump17/wlib/command/input/primitive/number/AllowedDoubleInputs.java @@ -86,6 +86,11 @@ private Unlimited() { 100000.5 ); } + + @Override + public String toString() { + return "AllowedDoubleInputs$Unlimited{}"; + } } final class Positive extends AllowedNumberInputs.Positive implements AllowedDoubleInputs { diff --git a/commands/src/main/java/com/wizardlybump17/wlib/command/input/primitive/number/AllowedFloatInputs.java b/commands/src/main/java/com/wizardlybump17/wlib/command/input/primitive/number/AllowedFloatInputs.java index 401d1dd0..97bbd0e2 100644 --- a/commands/src/main/java/com/wizardlybump17/wlib/command/input/primitive/number/AllowedFloatInputs.java +++ b/commands/src/main/java/com/wizardlybump17/wlib/command/input/primitive/number/AllowedFloatInputs.java @@ -86,6 +86,11 @@ private Unlimited() { 100000.5F ); } + + @Override + public String toString() { + return "AllowedFloatInputs$Unlimited{}"; + } } final class Positive extends AllowedNumberInputs.Positive implements AllowedFloatInputs { diff --git a/commands/src/main/java/com/wizardlybump17/wlib/command/input/primitive/number/AllowedIntegerInputs.java b/commands/src/main/java/com/wizardlybump17/wlib/command/input/primitive/number/AllowedIntegerInputs.java index 98f42c74..3ec19cab 100644 --- a/commands/src/main/java/com/wizardlybump17/wlib/command/input/primitive/number/AllowedIntegerInputs.java +++ b/commands/src/main/java/com/wizardlybump17/wlib/command/input/primitive/number/AllowedIntegerInputs.java @@ -77,6 +77,11 @@ private Unlimited() { 100000 ); } + + @Override + public String toString() { + return "AllowedIntegerInputs$Unlimited{}"; + } } final class Positive extends AllowedNumberInputs.Positive implements AllowedIntegerInputs { diff --git a/commands/src/main/java/com/wizardlybump17/wlib/command/input/primitive/number/AllowedLongInputs.java b/commands/src/main/java/com/wizardlybump17/wlib/command/input/primitive/number/AllowedLongInputs.java index b4ecda74..932781ef 100644 --- a/commands/src/main/java/com/wizardlybump17/wlib/command/input/primitive/number/AllowedLongInputs.java +++ b/commands/src/main/java/com/wizardlybump17/wlib/command/input/primitive/number/AllowedLongInputs.java @@ -86,6 +86,11 @@ private Unlimited() { 100000L ); } + + @Override + public String toString() { + return "AllowedLongInputs$Unlimited{}"; + } } final class Positive extends AllowedNumberInputs.Positive implements AllowedLongInputs { diff --git a/commands/src/main/java/com/wizardlybump17/wlib/command/input/primitive/number/AllowedNumberInputs.java b/commands/src/main/java/com/wizardlybump17/wlib/command/input/primitive/number/AllowedNumberInputs.java index 09fb1375..dd94fbe4 100644 --- a/commands/src/main/java/com/wizardlybump17/wlib/command/input/primitive/number/AllowedNumberInputs.java +++ b/commands/src/main/java/com/wizardlybump17/wlib/command/input/primitive/number/AllowedNumberInputs.java @@ -81,11 +81,6 @@ abstract class Unlimited implements AllowedNumberInputs { public boolean isAllowed(@Nullable N input) { return true; } - - @Override - public String toString() { - return "Unlimited{}"; - } } class Value implements AllowedNumberInputs, SingleValueInput { diff --git a/commands/src/main/java/com/wizardlybump17/wlib/command/input/primitive/number/AllowedShortInputs.java b/commands/src/main/java/com/wizardlybump17/wlib/command/input/primitive/number/AllowedShortInputs.java index 80069f77..6af34cae 100644 --- a/commands/src/main/java/com/wizardlybump17/wlib/command/input/primitive/number/AllowedShortInputs.java +++ b/commands/src/main/java/com/wizardlybump17/wlib/command/input/primitive/number/AllowedShortInputs.java @@ -84,6 +84,11 @@ private Unlimited() { (short) 32767 ); } + + @Override + public String toString() { + return "AllowedShortInputs$Unlimited{}"; + } } final class Positive extends AllowedNumberInputs.Positive implements AllowedShortInputs { From 393a9c0907a5b66895892a520e814990f8cc0713 Mon Sep 17 00:00:00 2001 From: WizardlyBump17 Date: Mon, 1 Dec 2025 20:30:18 -0300 Subject: [PATCH 174/363] versions --- build.gradle | 12 ++++++------ bungee/build.gradle | 2 +- gradle/wrapper/gradle-wrapper.properties | 2 +- 3 files changed, 8 insertions(+), 8 deletions(-) diff --git a/build.gradle b/build.gradle index 7be6cc7e..a87f0d6f 100644 --- a/build.gradle +++ b/build.gradle @@ -1,5 +1,5 @@ plugins { - id("com.gradleup.shadow") version "8.3.2" + id("com.gradleup.shadow") version "9.2.2" id 'maven-publish' } @@ -20,9 +20,6 @@ subprojects { } } - sourceCompatibility = '21' - targetCompatibility = '21' - tasks { compileJava { options.encoding = 'UTF-8' @@ -38,13 +35,16 @@ subprojects { java { withSourcesJar() + sourceCompatibility = 21 + targetCompatibility = 21 } } subprojects { dependencies { - testImplementation(platform("org.junit:junit-bom:5.10.3")) - testImplementation("org.junit.jupiter:junit-jupiter:5.10.3") + testImplementation(platform("org.junit:junit-bom:6.0.0")) + testImplementation("org.junit.jupiter:junit-jupiter") + testImplementation("org.junit.platform:junit-platform-launcher") } test { diff --git a/bungee/build.gradle b/bungee/build.gradle index 9b89a640..713c008e 100644 --- a/bungee/build.gradle +++ b/bungee/build.gradle @@ -8,7 +8,7 @@ dependencies { compileOnly( 'org.projectlombok:lombok:1.18.32', 'org.jetbrains:annotations:23.0.0', - 'net.md-5:bungeecord-api:1.18-R0.1-SNAPSHOT', + 'net.md-5:bungeecord-api:1.21-R0.3', ) annotationProcessor('org.projectlombok:lombok:1.18.32') implementation( diff --git a/gradle/wrapper/gradle-wrapper.properties b/gradle/wrapper/gradle-wrapper.properties index 5c82cb03..ac57dd15 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-8.14-bin.zip +distributionUrl=https\://services.gradle.org/distributions/gradle-9.2.1-bin.zip zipStoreBase=GRADLE_USER_HOME zipStorePath=wrapper/dists From 54196bc9920abdf34e47efd1a2bc7a69b1217324 Mon Sep 17 00:00:00 2001 From: WizardlyBump17 Date: Mon, 1 Dec 2025 20:42:39 -0300 Subject: [PATCH 175/363] properly loading the skull skin --- .../wlib/item/handler/SkullMetaHandler.java | 18 ++++++++++-------- 1 file changed, 10 insertions(+), 8 deletions(-) diff --git a/core/src/main/java/com/wizardlybump17/wlib/item/handler/SkullMetaHandler.java b/core/src/main/java/com/wizardlybump17/wlib/item/handler/SkullMetaHandler.java index 900b7563..a66017c4 100644 --- a/core/src/main/java/com/wizardlybump17/wlib/item/handler/SkullMetaHandler.java +++ b/core/src/main/java/com/wizardlybump17/wlib/item/handler/SkullMetaHandler.java @@ -3,22 +3,19 @@ import com.destroystokyo.paper.profile.PlayerProfile; import com.wizardlybump17.wlib.item.ItemBuilder; import com.wizardlybump17.wlib.item.handler.model.SkullMetaHandlerModel; -import lombok.NonNull; import org.bukkit.Bukkit; import org.bukkit.OfflinePlayer; import org.bukkit.inventory.meta.SkullMeta; +import org.bukkit.profile.PlayerTextures; import java.net.MalformedURLException; import java.net.URI; import java.net.URL; import java.util.Map; import java.util.UUID; -import java.util.concurrent.ConcurrentHashMap; public class SkullMetaHandler extends ItemMetaHandler { - private final @NonNull Map profileCache = new ConcurrentHashMap<>(); - public SkullMetaHandler(SkullMetaHandlerModel model, ItemBuilder builder) { super(model, builder); } @@ -56,15 +53,20 @@ public String skullUrl() { } public SkullMetaHandler skull(String url) { - getBuilder().consumeMeta(meta -> meta.setPlayerProfile(profileCache.computeIfAbsent(url, $ -> { + getBuilder().consumeMeta(meta -> { try { PlayerProfile profile = Bukkit.createProfile(UUID.nameUUIDFromBytes(url.getBytes())); - profile.getTextures().setSkin(URI.create(url).toURL()); - return profile; + + PlayerTextures textures = profile.getTextures(); + textures.setSkin(URI.create(url).toURL()); + + profile.setTextures(textures); + + meta.setPlayerProfile(profile); } catch (MalformedURLException e) { throw new IllegalArgumentException("Invalid URL " + url, e); } - }))); + }); return this; } From af17e03ebb404caf2d70fdddf9da9caabd4de9cc Mon Sep 17 00:00:00 2001 From: WizardlyBump17 Date: Mon, 1 Dec 2025 18:39:09 -0300 Subject: [PATCH 176/363] override and test --- .../input/object/AllowedUUIDInputs.java | 6 +- .../input/primitive/AllowedBooleanInputs.java | 6 +- .../primitive/AllowedCharacterInputs.java | 6 +- .../primitive/number/AllowedByteInputs.java | 32 ++++ .../primitive/number/AllowedDoubleInputs.java | 32 ++++ .../primitive/number/AllowedFloatInputs.java | 32 ++++ .../number/AllowedIntegerInputs.java | 32 ++++ .../primitive/number/AllowedLongInputs.java | 32 ++++ .../primitive/number/AllowedShortInputs.java | 32 ++++ .../input/string/AllowedStringInputs.java | 6 +- .../method/MethodCommandNodeFactoryTests.java | 160 ++++++++++++++++++ 11 files changed, 364 insertions(+), 12 deletions(-) create mode 100644 commands/src/test/java/com/wizardlybump17/wlib/test/command/extractor/method/MethodCommandNodeFactoryTests.java diff --git a/commands/src/main/java/com/wizardlybump17/wlib/command/input/object/AllowedUUIDInputs.java b/commands/src/main/java/com/wizardlybump17/wlib/command/input/object/AllowedUUIDInputs.java index ae1b0f2d..bd246aff 100644 --- a/commands/src/main/java/com/wizardlybump17/wlib/command/input/object/AllowedUUIDInputs.java +++ b/commands/src/main/java/com/wizardlybump17/wlib/command/input/object/AllowedUUIDInputs.java @@ -60,7 +60,7 @@ public int hashCode() { @Override public String toString() { - return "Value{" + + return "AllowedUUIDInputs$Value{" + "value=" + value + '}'; } @@ -94,7 +94,7 @@ public int hashCode() { @Override public String toString() { - return "Values{" + + return "AllowedUUIDInputs$Values{" + "values=" + values + '}'; } @@ -131,7 +131,7 @@ public int hashCode() { @Override public String toString() { - return "Any{" + + return "AllowedUUIDInputs$Any{" + "nullable=" + nullable + '}'; } diff --git a/commands/src/main/java/com/wizardlybump17/wlib/command/input/primitive/AllowedBooleanInputs.java b/commands/src/main/java/com/wizardlybump17/wlib/command/input/primitive/AllowedBooleanInputs.java index c755a70c..154211a6 100644 --- a/commands/src/main/java/com/wizardlybump17/wlib/command/input/primitive/AllowedBooleanInputs.java +++ b/commands/src/main/java/com/wizardlybump17/wlib/command/input/primitive/AllowedBooleanInputs.java @@ -38,7 +38,7 @@ private True() { @Override public String toString() { - return "True{}"; + return "AllowedBooleanInputs$True{}"; } } @@ -56,7 +56,7 @@ private False() { @Override public String toString() { - return "False{}"; + return "AllowedBooleanInputs$False{}"; } } @@ -95,7 +95,7 @@ public int hashCode() { @Override public String toString() { - return "Any{" + + return "AllowedBooleanInputs$Any{" + "nullable=" + nullable + '}'; } diff --git a/commands/src/main/java/com/wizardlybump17/wlib/command/input/primitive/AllowedCharacterInputs.java b/commands/src/main/java/com/wizardlybump17/wlib/command/input/primitive/AllowedCharacterInputs.java index 5a4123b1..5bdecdc3 100644 --- a/commands/src/main/java/com/wizardlybump17/wlib/command/input/primitive/AllowedCharacterInputs.java +++ b/commands/src/main/java/com/wizardlybump17/wlib/command/input/primitive/AllowedCharacterInputs.java @@ -88,7 +88,7 @@ public int hashCode() { @Override public String toString() { - return "Value{" + + return "AllowedCharacterInputs$Value{" + "value=" + value + ", ignoreCase=" + ignoreCase + '}'; @@ -140,7 +140,7 @@ public int hashCode() { @Override public String toString() { - return "Values{" + + return "AllowedCharacterInputs$Values{" + "values=" + values + ", ignoreCase=" + ignoreCase + '}'; @@ -182,7 +182,7 @@ public int hashCode() { @Override public String toString() { - return "Any{" + + return "AllowedCharacterInputs$Any{" + "nullable=" + nullable + '}'; } diff --git a/commands/src/main/java/com/wizardlybump17/wlib/command/input/primitive/number/AllowedByteInputs.java b/commands/src/main/java/com/wizardlybump17/wlib/command/input/primitive/number/AllowedByteInputs.java index 0988a0e5..7aea615d 100644 --- a/commands/src/main/java/com/wizardlybump17/wlib/command/input/primitive/number/AllowedByteInputs.java +++ b/commands/src/main/java/com/wizardlybump17/wlib/command/input/primitive/number/AllowedByteInputs.java @@ -61,6 +61,14 @@ final class Range extends AllowedNumberInputs.Ranged implements AllowedByt to ); } + + @Override + public String toString() { + return "AllowedByteInputs$Range{" + + "from=" + from() + + ", to=" + to() + + "}"; + } } final class Unlimited extends AllowedNumberInputs.Unlimited implements AllowedByteInputs { @@ -120,6 +128,11 @@ public boolean isInRange(@NotNull Byte input) { (byte) 127 ); } + + @Override + public String toString() { + return "AllowedByteInputs$Positive{}"; + } } final class Negative extends AllowedNumberInputs.Negative implements AllowedByteInputs { @@ -153,6 +166,11 @@ public boolean isInRange(@NotNull Byte input) { (byte) -1 ); } + + @Override + public String toString() { + return "AllowedByteInputs$Negative{}"; + } } final class Value extends AllowedNumberInputs.Value implements AllowedByteInputs { @@ -160,6 +178,13 @@ final class Value extends AllowedNumberInputs.Value implements AllowedByte Value(byte value) { super(value); } + + @Override + public String toString() { + return "AllowedByteInputs$Value{" + + "value=" + value() + + '}'; + } } final class Values extends AllowedNumberInputs.Values implements AllowedByteInputs { @@ -167,5 +192,12 @@ final class Values extends AllowedNumberInputs.Values implements AllowedBy Values(@NotNull List values) { super(values); } + + @Override + public String toString() { + return "AllowedByteInputs$Values{" + + "values=" + allowedValues() + + '}'; + } } } diff --git a/commands/src/main/java/com/wizardlybump17/wlib/command/input/primitive/number/AllowedDoubleInputs.java b/commands/src/main/java/com/wizardlybump17/wlib/command/input/primitive/number/AllowedDoubleInputs.java index 6d49813a..aa563883 100644 --- a/commands/src/main/java/com/wizardlybump17/wlib/command/input/primitive/number/AllowedDoubleInputs.java +++ b/commands/src/main/java/com/wizardlybump17/wlib/command/input/primitive/number/AllowedDoubleInputs.java @@ -61,6 +61,14 @@ final class Range extends AllowedNumberInputs.Ranged implements AllowedD to ); } + + @Override + public String toString() { + return "AllowedByteInputs$Range{" + + "from=" + from() + + ", to=" + to() + + "}"; + } } final class Unlimited extends AllowedNumberInputs.Unlimited implements AllowedDoubleInputs { @@ -126,6 +134,11 @@ public boolean isInRange(@NotNull Double input) { 100000.5 ); } + + @Override + public String toString() { + return "AllowedDoubleInputs$Positive{}"; + } } final class Negative extends AllowedNumberInputs.Negative implements AllowedDoubleInputs { @@ -161,6 +174,11 @@ public boolean isInRange(@NotNull Double input) { -1.0 ); } + + @Override + public String toString() { + return "AllowedDoubleInputs$Negative{}"; + } } final class Value extends AllowedNumberInputs.Value implements AllowedDoubleInputs { @@ -168,6 +186,13 @@ final class Value extends AllowedNumberInputs.Value implements AllowedDo Value(double value) { super(value); } + + @Override + public String toString() { + return "AllowedDoubleInputs$Value{" + + "value=" + value() + + "}"; + } } final class Values extends AllowedNumberInputs.Values implements AllowedDoubleInputs { @@ -175,5 +200,12 @@ final class Values extends AllowedNumberInputs.Values implements Allowed Values(@NotNull List values) { super(values); } + + @Override + public String toString() { + return "AllowedDoubleInputs$Values{" + + "values=" + allowedValues() + + '}'; + } } } diff --git a/commands/src/main/java/com/wizardlybump17/wlib/command/input/primitive/number/AllowedFloatInputs.java b/commands/src/main/java/com/wizardlybump17/wlib/command/input/primitive/number/AllowedFloatInputs.java index 97bbd0e2..e85316a8 100644 --- a/commands/src/main/java/com/wizardlybump17/wlib/command/input/primitive/number/AllowedFloatInputs.java +++ b/commands/src/main/java/com/wizardlybump17/wlib/command/input/primitive/number/AllowedFloatInputs.java @@ -61,6 +61,14 @@ final class Range extends AllowedNumberInputs.Ranged implements AllowedFl to ); } + + @Override + public String toString() { + return "AllowedFloatInputs$Range{" + + "from=" + from() + + ", to=" + to() + + "}"; + } } final class Unlimited extends AllowedNumberInputs.Unlimited implements AllowedFloatInputs { @@ -126,6 +134,11 @@ public boolean isInRange(@NotNull Float input) { 100000.5F ); } + + @Override + public String toString() { + return "AllowedFloatInputs$Positive{}"; + } } final class Negative extends AllowedNumberInputs.Negative implements AllowedFloatInputs { @@ -161,6 +174,11 @@ public boolean isInRange(@NotNull Float input) { -1.0F ); } + + @Override + public String toString() { + return "AllowedFloatInputs$Negative{}"; + } } final class Value extends AllowedNumberInputs.Value implements AllowedFloatInputs { @@ -168,6 +186,13 @@ final class Value extends AllowedNumberInputs.Value implements AllowedFlo Value(float value) { super(value); } + + @Override + public String toString() { + return "AllowedFloatInputs$Value{" + + "value=" + value() + + "}"; + } } final class Values extends AllowedNumberInputs.Values implements AllowedFloatInputs { @@ -175,5 +200,12 @@ final class Values extends AllowedNumberInputs.Values implements AllowedF Values(@NotNull List values) { super(values); } + + @Override + public String toString() { + return "AllowedFloatInputs$Values{" + + "values=" + allowedValues() + + '}'; + } } } diff --git a/commands/src/main/java/com/wizardlybump17/wlib/command/input/primitive/number/AllowedIntegerInputs.java b/commands/src/main/java/com/wizardlybump17/wlib/command/input/primitive/number/AllowedIntegerInputs.java index 3ec19cab..c9a7ec45 100644 --- a/commands/src/main/java/com/wizardlybump17/wlib/command/input/primitive/number/AllowedIntegerInputs.java +++ b/commands/src/main/java/com/wizardlybump17/wlib/command/input/primitive/number/AllowedIntegerInputs.java @@ -52,6 +52,14 @@ final class Range extends AllowedNumberInputs.Ranged implements Allowed int fourth = (to - from) / 4; return List.of(from, from + fourth, from + fourth * 2, from + fourth * 3, to); } + + @Override + public String toString() { + return "AllowedIntegerInputs$Range{" + + "from=" + from() + + ", to=" + to() + + "}"; + } } final class Unlimited extends AllowedNumberInputs.Unlimited implements AllowedIntegerInputs{ @@ -117,6 +125,11 @@ public boolean isInRange(@NotNull Integer input) { 100000 ); } + + @Override + public String toString() { + return "AllowedIntegerInputs$Positive{}"; + } } final class Negative extends AllowedNumberInputs.Negative implements AllowedIntegerInputs { @@ -152,6 +165,11 @@ public boolean isInRange(@NotNull Integer input) { -1 ); } + + @Override + public String toString() { + return "AllowedIntegerInputs$Negative{}"; + } } final class Value extends AllowedNumberInputs.Value implements AllowedIntegerInputs { @@ -159,6 +177,13 @@ final class Value extends AllowedNumberInputs.Value implements AllowedI Value(@NotNull Integer value) { super(value); } + + @Override + public String toString() { + return "AllowedIntegerInputs$Value{" + + "value=" + value() + + "}"; + } } final class Values extends AllowedNumberInputs.Values implements AllowedIntegerInputs { @@ -166,5 +191,12 @@ final class Values extends AllowedNumberInputs.Values implements Allowe Values(@NotNull List values) { super(values); } + + @Override + public String toString() { + return "AllowedIntegerInputs$Values{" + + "values=" + allowedValues() + + '}'; + } } } diff --git a/commands/src/main/java/com/wizardlybump17/wlib/command/input/primitive/number/AllowedLongInputs.java b/commands/src/main/java/com/wizardlybump17/wlib/command/input/primitive/number/AllowedLongInputs.java index 932781ef..9b2fd357 100644 --- a/commands/src/main/java/com/wizardlybump17/wlib/command/input/primitive/number/AllowedLongInputs.java +++ b/commands/src/main/java/com/wizardlybump17/wlib/command/input/primitive/number/AllowedLongInputs.java @@ -61,6 +61,14 @@ final class Range extends AllowedNumberInputs.Ranged implements AllowedLon to ); } + + @Override + public String toString() { + return "AllowedLongInputs$Range{" + + "from=" + from() + + ", to=" + to() + + "}"; + } } final class Unlimited extends AllowedNumberInputs.Unlimited implements AllowedLongInputs { @@ -126,6 +134,11 @@ public boolean isInRange(@NotNull Long input) { 100000L ); } + + @Override + public String toString() { + return "AllowedLongInputs$Positive{}"; + } } final class Negative extends AllowedNumberInputs.Negative implements AllowedLongInputs { @@ -161,6 +174,11 @@ public boolean isInRange(@NotNull Long input) { -1L ); } + + @Override + public String toString() { + return "AllowedLongInputs$Negative{}"; + } } final class Value extends AllowedNumberInputs.Value implements AllowedLongInputs { @@ -168,6 +186,13 @@ final class Value extends AllowedNumberInputs.Value implements AllowedLong Value(long value) { super(value); } + + @Override + public String toString() { + return "AllowedLongInputs$Value{" + + "value=" + value() + + "}"; + } } final class Values extends AllowedNumberInputs.Values implements AllowedLongInputs { @@ -175,5 +200,12 @@ final class Values extends AllowedNumberInputs.Values implements AllowedLo Values(@NotNull List values) { super(values); } + + @Override + public String toString() { + return "AllowedLongInputs$Values{" + + "values=" + allowedValues() + + '}'; + } } } diff --git a/commands/src/main/java/com/wizardlybump17/wlib/command/input/primitive/number/AllowedShortInputs.java b/commands/src/main/java/com/wizardlybump17/wlib/command/input/primitive/number/AllowedShortInputs.java index 6af34cae..506505f9 100644 --- a/commands/src/main/java/com/wizardlybump17/wlib/command/input/primitive/number/AllowedShortInputs.java +++ b/commands/src/main/java/com/wizardlybump17/wlib/command/input/primitive/number/AllowedShortInputs.java @@ -61,6 +61,14 @@ final class Range extends AllowedNumberInputs.Ranged implements AllowedSh to ); } + + @Override + public String toString() { + return "AllowedShortInputs$Range{" + + "from=" + from() + + ", to=" + to() + + "}"; + } } final class Unlimited extends AllowedNumberInputs.Unlimited implements AllowedShortInputs { @@ -123,6 +131,11 @@ public boolean isInRange(@NotNull Short input) { (short) 32767 ); } + + @Override + public String toString() { + return "AllowedShortInputs$Positive{}"; + } } final class Negative extends AllowedNumberInputs.Negative implements AllowedShortInputs { @@ -157,6 +170,11 @@ public boolean isInRange(@NotNull Short input) { (short) -1 ); } + + @Override + public String toString() { + return "AllowedShortInputs$Negative{}"; + } } final class Value extends AllowedNumberInputs.Value implements AllowedShortInputs { @@ -164,6 +182,13 @@ final class Value extends AllowedNumberInputs.Value implements AllowedSho Value(short value) { super(value); } + + @Override + public String toString() { + return "AllowedShortInputs$Value{" + + "value=" + value() + + "}"; + } } final class Values extends AllowedNumberInputs.Values implements AllowedShortInputs { @@ -171,5 +196,12 @@ final class Values extends AllowedNumberInputs.Values implements AllowedS Values(@NotNull List values) { super(values); } + + @Override + public String toString() { + return "AllowedShortInputs$Values{" + + "values=" + allowedValues() + + '}'; + } } } diff --git a/commands/src/main/java/com/wizardlybump17/wlib/command/input/string/AllowedStringInputs.java b/commands/src/main/java/com/wizardlybump17/wlib/command/input/string/AllowedStringInputs.java index 693e994e..b2cfee87 100644 --- a/commands/src/main/java/com/wizardlybump17/wlib/command/input/string/AllowedStringInputs.java +++ b/commands/src/main/java/com/wizardlybump17/wlib/command/input/string/AllowedStringInputs.java @@ -85,7 +85,7 @@ public int hashCode() { @Override public String toString() { - return "Values{" + + return "AllowedStringInputs$Values{" + "values=" + values + ", ignoreCase=" + ignoreCase + '}'; @@ -139,7 +139,7 @@ public int hashCode() { @Override public String toString() { - return "Value{" + + return "AllowedStringInputs$Value{" + "value='" + value + '\'' + ", ignoreCase=" + ignoreCase + '}'; @@ -186,7 +186,7 @@ public int hashCode() { @Override public String toString() { - return "Any{" + + return "AllowedStringInput$Any{" + "nullable=" + nullable + '}'; } diff --git a/commands/src/test/java/com/wizardlybump17/wlib/test/command/extractor/method/MethodCommandNodeFactoryTests.java b/commands/src/test/java/com/wizardlybump17/wlib/test/command/extractor/method/MethodCommandNodeFactoryTests.java new file mode 100644 index 00000000..7d1a1137 --- /dev/null +++ b/commands/src/test/java/com/wizardlybump17/wlib/test/command/extractor/method/MethodCommandNodeFactoryTests.java @@ -0,0 +1,160 @@ +package com.wizardlybump17.wlib.test.command.extractor.method; + +import com.wizardlybump17.wlib.command.Command; +import com.wizardlybump17.wlib.command.extractor.method.MethodCommandExtractor; +import com.wizardlybump17.wlib.command.input.primitive.number.AllowedByteInputs; +import com.wizardlybump17.wlib.command.input.primitive.number.AllowedIntegerInputs; +import com.wizardlybump17.wlib.command.node.LiteralCommandNode; +import com.wizardlybump17.wlib.command.node.primitive.number.ByteCommandNode; +import com.wizardlybump17.wlib.command.node.primitive.number.IntegerCommandNode; +import com.wizardlybump17.wlib.command.registry.MethodCommandNodeFactoryRegistry; +import com.wizardlybump17.wlib.test.util.AssertionUtil; +import org.junit.jupiter.api.AfterAll; +import org.junit.jupiter.api.Assertions; +import org.junit.jupiter.api.BeforeAll; +import org.junit.jupiter.api.Test; + +import java.util.ArrayList; +import java.util.List; + +class MethodCommandNodeFactoryTests { + + static MethodCommandExtractor commandExtractor; + + @BeforeAll + static void setup() { + MethodCommandNodeFactoryRegistry registry = new MethodCommandNodeFactoryRegistry(); + registry.registerDefaults(); + commandExtractor = new MethodCommandExtractor(registry); + } + + @AfterAll + static void shutdown() { + if (commandExtractor == null) + return; + + MethodCommandNodeFactoryRegistry registry = commandExtractor.getFactoryRegistry(); + registry.clear(); + commandExtractor = null; + } + + @Test + void testByte() { + Command test0 = new Command( + new LiteralCommandNode( + "test", + List.of( + new ByteCommandNode( + "byte0", + AllowedByteInputs.unlimited() + ) + ) + ) + ); + Command test1 = new Command( + new LiteralCommandNode( + "test", + List.of( + new ByteCommandNode( + "byte0", + List.of( + new LiteralCommandNode( + "test1", + List.of( + new ByteCommandNode( + "byte1", + AllowedByteInputs.unlimited() + ) + ) + ) + ), + AllowedByteInputs.unlimited(), + null, + null + ) + ) + ) + ); + + TestByte object = new TestByte(); + + List expected = new ArrayList<>(List.of(test0, test1)); + List actual = Assertions.assertDoesNotThrow(() -> commandExtractor.extract(object)); + + expected.sort(null); + actual.sort(null); + + AssertionUtil.assertCommandsEquals(expected, actual); + } + + public static final class TestByte { + + @com.wizardlybump17.wlib.command.annotation.Command("test ") + public void test(byte int0) { + } + + @com.wizardlybump17.wlib.command.annotation.Command("test test1 ") + public void test(byte int0, byte int1) { + } + } + + @Test + void testInt() { + Command test0 = new Command( + new LiteralCommandNode( + "test", + List.of( + new IntegerCommandNode( + "int0", + AllowedIntegerInputs.unlimited() + ) + ) + ) + ); + Command test1 = new Command( + new LiteralCommandNode( + "test", + List.of( + new IntegerCommandNode( + "int0", + List.of( + new LiteralCommandNode( + "test1", + List.of( + new IntegerCommandNode( + "int1", + AllowedIntegerInputs.unlimited() + ) + ) + ) + ), + AllowedIntegerInputs.unlimited(), + null, + null + ) + ) + ) + ); + + TestInt object = new TestInt(); + + List expected = new ArrayList<>(List.of(test0, test1)); + List actual = Assertions.assertDoesNotThrow(() -> commandExtractor.extract(object)); + + expected.sort(null); + actual.sort(null); + + AssertionUtil.assertCommandsEquals(expected, actual); + } + + public static final class TestInt { + + @com.wizardlybump17.wlib.command.annotation.Command("test ") + public void test(int int0) { + } + + @com.wizardlybump17.wlib.command.annotation.Command("test test1 ") + public void test(int int0, int int1) { + } + } +} From 61db26915de849dc218a25b040db90a8205a7fe7 Mon Sep 17 00:00:00 2001 From: WizardlyBump17 Date: Fri, 5 Dec 2025 18:05:35 -0300 Subject: [PATCH 177/363] small tests --- .../method/MethodCommandNodeFactoryTests.java | 672 +++++++++++++++++- 1 file changed, 654 insertions(+), 18 deletions(-) diff --git a/commands/src/test/java/com/wizardlybump17/wlib/test/command/extractor/method/MethodCommandNodeFactoryTests.java b/commands/src/test/java/com/wizardlybump17/wlib/test/command/extractor/method/MethodCommandNodeFactoryTests.java index 7d1a1137..6664c4c6 100644 --- a/commands/src/test/java/com/wizardlybump17/wlib/test/command/extractor/method/MethodCommandNodeFactoryTests.java +++ b/commands/src/test/java/com/wizardlybump17/wlib/test/command/extractor/method/MethodCommandNodeFactoryTests.java @@ -2,11 +2,15 @@ import com.wizardlybump17.wlib.command.Command; import com.wizardlybump17.wlib.command.extractor.method.MethodCommandExtractor; -import com.wizardlybump17.wlib.command.input.primitive.number.AllowedByteInputs; -import com.wizardlybump17.wlib.command.input.primitive.number.AllowedIntegerInputs; +import com.wizardlybump17.wlib.command.input.object.AllowedUUIDInputs; +import com.wizardlybump17.wlib.command.input.primitive.AllowedCharacterInputs; +import com.wizardlybump17.wlib.command.input.primitive.number.*; +import com.wizardlybump17.wlib.command.input.string.AllowedStringInputs; import com.wizardlybump17.wlib.command.node.LiteralCommandNode; -import com.wizardlybump17.wlib.command.node.primitive.number.ByteCommandNode; -import com.wizardlybump17.wlib.command.node.primitive.number.IntegerCommandNode; +import com.wizardlybump17.wlib.command.node.object.UUIDCommandNode; +import com.wizardlybump17.wlib.command.node.primitive.CharacterCommandNode; +import com.wizardlybump17.wlib.command.node.primitive.number.*; +import com.wizardlybump17.wlib.command.node.string.StringCommandNode; import com.wizardlybump17.wlib.command.registry.MethodCommandNodeFactoryRegistry; import com.wizardlybump17.wlib.test.util.AssertionUtil; import org.junit.jupiter.api.AfterAll; @@ -16,6 +20,7 @@ import java.util.ArrayList; import java.util.List; +import java.util.UUID; class MethodCommandNodeFactoryTests { @@ -45,7 +50,7 @@ void testByte() { "test", List.of( new ByteCommandNode( - "byte0", + "arg0", AllowedByteInputs.unlimited() ) ) @@ -56,13 +61,13 @@ void testByte() { "test", List.of( new ByteCommandNode( - "byte0", + "arg0", List.of( new LiteralCommandNode( "test1", List.of( new ByteCommandNode( - "byte1", + "arg1", AllowedByteInputs.unlimited() ) ) @@ -89,12 +94,72 @@ void testByte() { public static final class TestByte { - @com.wizardlybump17.wlib.command.annotation.Command("test ") - public void test(byte int0) { + @com.wizardlybump17.wlib.command.annotation.Command("test ") + public void test(byte arg0) { } - @com.wizardlybump17.wlib.command.annotation.Command("test test1 ") - public void test(byte int0, byte int1) { + @com.wizardlybump17.wlib.command.annotation.Command("test test1 ") + public void test(byte arg0, byte arg1) { + } + } + + @Test + void testShort() { + Command test0 = new Command( + new LiteralCommandNode( + "test", + List.of( + new ShortCommandNode( + "arg0", + AllowedShortInputs.unlimited() + ) + ) + ) + ); + Command test1 = new Command( + new LiteralCommandNode( + "test", + List.of( + new ShortCommandNode( + "arg0", + List.of( + new LiteralCommandNode( + "test1", + List.of( + new ShortCommandNode( + "arg1", + AllowedShortInputs.unlimited() + ) + ) + ) + ), + AllowedShortInputs.unlimited(), + null, + null + ) + ) + ) + ); + + TestShort object = new TestShort(); + + List expected = new ArrayList<>(List.of(test0, test1)); + List actual = Assertions.assertDoesNotThrow(() -> commandExtractor.extract(object)); + + expected.sort(null); + actual.sort(null); + + AssertionUtil.assertCommandsEquals(expected, actual); + } + + public static final class TestShort { + + @com.wizardlybump17.wlib.command.annotation.Command("test ") + public void test(short arg0) { + } + + @com.wizardlybump17.wlib.command.annotation.Command("test test1 ") + public void test(short arg0, short arg1) { } } @@ -105,7 +170,7 @@ void testInt() { "test", List.of( new IntegerCommandNode( - "int0", + "arg0", AllowedIntegerInputs.unlimited() ) ) @@ -116,13 +181,13 @@ void testInt() { "test", List.of( new IntegerCommandNode( - "int0", + "arg0", List.of( new LiteralCommandNode( "test1", List.of( new IntegerCommandNode( - "int1", + "arg1", AllowedIntegerInputs.unlimited() ) ) @@ -149,12 +214,583 @@ void testInt() { public static final class TestInt { - @com.wizardlybump17.wlib.command.annotation.Command("test ") - public void test(int int0) { + @com.wizardlybump17.wlib.command.annotation.Command("test ") + public void test(int arg0) { + } + + @com.wizardlybump17.wlib.command.annotation.Command("test test1 ") + public void test(int arg0, int arg1) { + } + } + + @Test + void testLong() { + Command test0 = new Command( + new LiteralCommandNode( + "test", + List.of( + new LongCommandNode( + "arg0", + AllowedLongInputs.unlimited() + ) + ) + ) + ); + Command test1 = new Command( + new LiteralCommandNode( + "test", + List.of( + new LongCommandNode( + "arg0", + List.of( + new LiteralCommandNode( + "test1", + List.of( + new LongCommandNode( + "arg1", + AllowedLongInputs.unlimited() + ) + ) + ) + ), + AllowedLongInputs.unlimited(), + null, + null + ) + ) + ) + ); + + TestLong object = new TestLong(); + + List expected = new ArrayList<>(List.of(test0, test1)); + List actual = Assertions.assertDoesNotThrow(() -> commandExtractor.extract(object)); + + expected.sort(null); + actual.sort(null); + + AssertionUtil.assertCommandsEquals(expected, actual); + } + + public static final class TestLong { + + @com.wizardlybump17.wlib.command.annotation.Command("test ") + public void test(long arg0) { + } + + @com.wizardlybump17.wlib.command.annotation.Command("test test1 ") + public void test(long arg0, long arg1) { + } + } + + @Test + void testFloat() { + Command test0 = new Command( + new LiteralCommandNode( + "test", + List.of( + new FloatCommandNode( + "arg0", + AllowedFloatInputs.unlimited() + ) + ) + ) + ); + Command test1 = new Command( + new LiteralCommandNode( + "test", + List.of( + new FloatCommandNode( + "arg0", + List.of( + new LiteralCommandNode( + "test1", + List.of( + new FloatCommandNode( + "arg1", + AllowedFloatInputs.unlimited() + ) + ) + ) + ), + AllowedFloatInputs.unlimited(), + null, + null + ) + ) + ) + ); + + TestFloat object = new TestFloat(); + + List expected = new ArrayList<>(List.of(test0, test1)); + List actual = Assertions.assertDoesNotThrow(() -> commandExtractor.extract(object)); + + expected.sort(null); + actual.sort(null); + + AssertionUtil.assertCommandsEquals(expected, actual); + } + + public static final class TestFloat { + + @com.wizardlybump17.wlib.command.annotation.Command("test ") + public void test(float arg0) { + } + + @com.wizardlybump17.wlib.command.annotation.Command("test test1 ") + public void test(float arg0, float arg1) { } + } + + @Test + void testDouble() { + Command test0 = new Command( + new LiteralCommandNode( + "test", + List.of( + new DoubleCommandNode( + "arg0", + AllowedDoubleInputs.unlimited() + ) + ) + ) + ); + Command test1 = new Command( + new LiteralCommandNode( + "test", + List.of( + new DoubleCommandNode( + "arg0", + List.of( + new LiteralCommandNode( + "test1", + List.of( + new DoubleCommandNode( + "arg1", + AllowedDoubleInputs.unlimited() + ) + ) + ) + ), + AllowedDoubleInputs.unlimited(), + null, + null + ) + ) + ) + ); + + TestDouble object = new TestDouble(); + + List expected = new ArrayList<>(List.of(test0, test1)); + List actual = Assertions.assertDoesNotThrow(() -> commandExtractor.extract(object)); + + expected.sort(null); + actual.sort(null); + + AssertionUtil.assertCommandsEquals(expected, actual); + } + + public static final class TestDouble { + + @com.wizardlybump17.wlib.command.annotation.Command("test ") + public void test(double arg0) { + } + + @com.wizardlybump17.wlib.command.annotation.Command("test test1 ") + public void test(double arg0, double arg1) { + } + } + + @Test + void testChar() { + Command test0 = new Command( + new LiteralCommandNode( + "test", + List.of( + new CharacterCommandNode( + "arg0", + AllowedCharacterInputs.anyNotNull() + ) + ) + ) + ); + Command test1 = new Command( + new LiteralCommandNode( + "test", + List.of( + new CharacterCommandNode( + "arg0", + List.of( + new LiteralCommandNode( + "test1", + List.of( + new CharacterCommandNode( + "arg1", + AllowedCharacterInputs.anyNotNull() + ) + ) + ) + ), + AllowedCharacterInputs.anyNotNull(), + null, + null + ) + ) + ) + ); + + TestChar object = new TestChar(); + + List expected = new ArrayList<>(List.of(test0, test1)); + List actual = Assertions.assertDoesNotThrow(() -> commandExtractor.extract(object)); + + expected.sort(null); + actual.sort(null); + + AssertionUtil.assertCommandsEquals(expected, actual); + } + + public static final class TestChar { + + @com.wizardlybump17.wlib.command.annotation.Command("test ") + public void test(char arg0) { + } + + @com.wizardlybump17.wlib.command.annotation.Command("test test1 ") + public void test(char arg0, char arg1) { + } + } + + @Test + void testString() { + Command test0 = new Command( + new LiteralCommandNode( + "test", + List.of( + new StringCommandNode( + "arg0", + AllowedStringInputs.anyNotNull() + ) + ) + ) + ); + Command test1 = new Command( + new LiteralCommandNode( + "test", + List.of( + new StringCommandNode( + "arg0", + List.of( + new LiteralCommandNode( + "test1", + List.of( + new StringCommandNode( + "arg1", + AllowedStringInputs.anyNotNull() + ) + ) + ) + ), + AllowedStringInputs.anyNotNull(), + null, + null + ) + ) + ) + ); + + TestString object = new TestString(); + + List expected = new ArrayList<>(List.of(test0, test1)); + List actual = Assertions.assertDoesNotThrow(() -> commandExtractor.extract(object)); + + expected.sort(null); + actual.sort(null); + + AssertionUtil.assertCommandsEquals(expected, actual); + } + + public static final class TestString { + + @com.wizardlybump17.wlib.command.annotation.Command("test ") + public void test(String arg0) { + } + + @com.wizardlybump17.wlib.command.annotation.Command("test test1 ") + public void test(String arg0, String arg1) { + } + } + + @Test + void testUUID() { + Command test0 = new Command( + new LiteralCommandNode( + "test", + List.of( + new UUIDCommandNode( + "arg0", + AllowedUUIDInputs.anyNotNull() + ) + ) + ) + ); + Command test1 = new Command( + new LiteralCommandNode( + "test", + List.of( + new UUIDCommandNode( + "arg0", + List.of( + new LiteralCommandNode( + "test1", + List.of( + new UUIDCommandNode( + "arg1", + AllowedUUIDInputs.anyNotNull() + ) + ) + ) + ), + AllowedUUIDInputs.anyNotNull(), + null, + null + ) + ) + ) + ); + + TestUUID object = new TestUUID(); + + List expected = new ArrayList<>(List.of(test0, test1)); + List actual = Assertions.assertDoesNotThrow(() -> commandExtractor.extract(object)); + + expected.sort(null); + actual.sort(null); + + AssertionUtil.assertCommandsEquals(expected, actual); + } + + public static final class TestUUID { + + @com.wizardlybump17.wlib.command.annotation.Command("test ") + public void test(UUID arg0) { + } + + @com.wizardlybump17.wlib.command.annotation.Command("test test1 ") + public void test(UUID arg0, UUID arg1) { + } + } + + @Test + void testMix() { + Command test0 = new Command(new LiteralCommandNode( + "test", + List.of( + new IntegerCommandNode( + "int0", + List.of( + new IntegerCommandNode( + "int1", + List.of( + new LiteralCommandNode( + "test1", + List.of( + new ByteCommandNode( + "byte0", + List.of( + new ByteCommandNode( + "byte1", + List.of( + new LiteralCommandNode( + "test2", + List.of( + new FloatCommandNode( + "float0", + List.of( + new LiteralCommandNode( + "test3", + List.of( + new FloatCommandNode( + "float1", + List.of( + new LongCommandNode( + "long0", + List.of( + new LongCommandNode( + "long1", + List.of( + new LiteralCommandNode( + "test4", + List.of( + new ShortCommandNode( + "short0", + List.of( + new ShortCommandNode( + "short1", + List.of( + new LiteralCommandNode( + "test5", + List.of( + new DoubleCommandNode( + "double0", + List.of( + new DoubleCommandNode( + "double1", + List.of( + new LiteralCommandNode( + "test6", + List.of( + new CharacterCommandNode( + "char0", + List.of( + new CharacterCommandNode( + "char1", + List.of( + new LiteralCommandNode( + "test7", + List.of( + new StringCommandNode( + "string0", + List.of( + new LiteralCommandNode( + "test8", + List.of( + new StringCommandNode( + "string1", + List.of( + new UUIDCommandNode( + "uuid0", + List.of( + new LiteralCommandNode( + "test9", + List.of( + new UUIDCommandNode( + "uuid1", + AllowedUUIDInputs.anyNotNull() + ) + ) + ) + ), + AllowedUUIDInputs.anyNotNull(), + null, + null + ) + ), + AllowedStringInputs.anyNotNull(), + null, + null + ) + ) + ) + ), + AllowedStringInputs.anyNotNull(), + null, + null + ) + ) + ) + ), + AllowedCharacterInputs.anyNotNull(), + null, + null + ) + ), + AllowedCharacterInputs.anyNotNull(), + null, + null + ) + ) + ) + ), + AllowedDoubleInputs.unlimited(), + null, + null + ) + ), + AllowedDoubleInputs.unlimited(), + null, + null + ) + ) + ) + ), + AllowedShortInputs.unlimited(), + null, + null + ) + ), + AllowedShortInputs.unlimited(), + null, + null + ) + ) + ) + ), + AllowedLongInputs.unlimited(), + null, + null + ) + ), + AllowedLongInputs.unlimited(), + null, + null + ) + ), + AllowedFloatInputs.unlimited(), + null, + null + ) + ) + ) + ), + AllowedFloatInputs.unlimited(), + null, + null + ) + ) + ) + ), + AllowedByteInputs.unlimited(), + null, + null + ) + ), + AllowedByteInputs.unlimited(), + null, + null + ) + ) + ) + ), + AllowedIntegerInputs.unlimited(), + null, + null + ) + ), + AllowedIntegerInputs.unlimited(), + null, + null + ) + ) + )); + + TestMix object = new TestMix(); + + List expected = new ArrayList<>(List.of(test0)); + List actual = Assertions.assertDoesNotThrow(() -> commandExtractor.extract(object)); + + expected.sort(null); + actual.sort(null); + + AssertionUtil.assertCommandsEquals(expected, actual); + } + + public static final class TestMix { - @com.wizardlybump17.wlib.command.annotation.Command("test test1 ") - public void test(int int0, int int1) { + @com.wizardlybump17.wlib.command.annotation.Command("test test1 test2 test3 test4 test5 test6 test7 test8 test9 ") + public void test(int int0, int int1, byte byte0, byte byte1, float float0, float float1, long long0, long log1, short short0, short short1, double double0, double double1, char char0, char char1, String string0, String string1, UUID uuid0, UUID uuid1) { } } } From 74efe1cf218c572c0c6e2d69eef987459c0250e5 Mon Sep 17 00:00:00 2001 From: WizardlyBump17 Date: Fri, 5 Dec 2025 18:48:02 -0300 Subject: [PATCH 178/363] using the latest version --- core/build.gradle | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/core/build.gradle b/core/build.gradle index 41d1f181..b1570761 100644 --- a/core/build.gradle +++ b/core/build.gradle @@ -2,7 +2,7 @@ dependencies { compileOnly( 'org.projectlombok:lombok:1.18.32', 'org.jetbrains:annotations:23.1.0', - "io.papermc.paper:paper-api:1.20.6-R0.1-20240702.153951-124", + "io.papermc.paper:paper-api:1.20.6-R0.1-SNAPSHOT", ) annotationProcessor('org.projectlombok:lombok:1.18.32') From 2b4ebfd5167f616d21e55e12affb908ba04f283d Mon Sep 17 00:00:00 2001 From: WizardlyBump17 Date: Fri, 5 Dec 2025 18:50:39 -0300 Subject: [PATCH 179/363] Gradle KTS and minor changes --- commands/build.gradle | 19 ------------------- commands/build.gradle.kts | 9 +++++++++ 2 files changed, 9 insertions(+), 19 deletions(-) delete mode 100644 commands/build.gradle create mode 100644 commands/build.gradle.kts diff --git a/commands/build.gradle b/commands/build.gradle deleted file mode 100644 index 5cf5fae7..00000000 --- a/commands/build.gradle +++ /dev/null @@ -1,19 +0,0 @@ -dependencies { - compileOnly( - 'org.projectlombok:lombok:1.18.32', - 'org.jetbrains:annotations:26.0.1', - ) - annotationProcessor('org.projectlombok:lombok:1.18.32') - implementation( - project(':objects'), - project(':utils') - ) - implementation("com.github.sisyphsu:dateparser:1.0.11") { - exclude(group: "org.projectlombok", module: "lombok") - } - testCompileOnly("org.jetbrains:annotations:26.0.1") -} - -shadowJar { - relocate("com.github.sisyphsu", "com.wizardlybump17.wlib.libs.com.github.sisyphsu") -} diff --git a/commands/build.gradle.kts b/commands/build.gradle.kts new file mode 100644 index 00000000..cd1213cb --- /dev/null +++ b/commands/build.gradle.kts @@ -0,0 +1,9 @@ +val annotations = "26.0.1" + +dependencies { + compileOnly("org.jetbrains:annotations:${annotations}") + implementation(project(":objects")) + implementation(project(":utils")) + + testCompileOnly("org.jetbrains:annotations:${annotations}") +} From 446f50cf90e24acae06903a00610e76748a5857d Mon Sep 17 00:00:00 2001 From: WizardlyBump17 Date: Fri, 5 Dec 2025 18:56:49 -0300 Subject: [PATCH 180/363] some of them can be nullable --- commands/build.gradle.kts | 4 ++-- .../object/UUIDMethodCommandNodeFactory.java | 2 +- .../StringMethodCommandNodeFactory.java | 2 +- .../method/MethodCommandExtractorTests.java | 6 +++--- .../method/MethodCommandNodeFactoryTests.java | 20 +++++++++---------- 5 files changed, 17 insertions(+), 17 deletions(-) diff --git a/commands/build.gradle.kts b/commands/build.gradle.kts index cd1213cb..a133d837 100644 --- a/commands/build.gradle.kts +++ b/commands/build.gradle.kts @@ -1,9 +1,9 @@ val annotations = "26.0.1" dependencies { - compileOnly("org.jetbrains:annotations:${annotations}") + implementation("org.jetbrains:annotations:${annotations}") implementation(project(":objects")) implementation(project(":utils")) - testCompileOnly("org.jetbrains:annotations:${annotations}") + testImplementation("org.jetbrains:annotations:${annotations}") } diff --git a/commands/src/main/java/com/wizardlybump17/wlib/command/extractor/method/factory/object/UUIDMethodCommandNodeFactory.java b/commands/src/main/java/com/wizardlybump17/wlib/command/extractor/method/factory/object/UUIDMethodCommandNodeFactory.java index cc928a37..cb2c3dc4 100644 --- a/commands/src/main/java/com/wizardlybump17/wlib/command/extractor/method/factory/object/UUIDMethodCommandNodeFactory.java +++ b/commands/src/main/java/com/wizardlybump17/wlib/command/extractor/method/factory/object/UUIDMethodCommandNodeFactory.java @@ -23,7 +23,7 @@ public class UUIDMethodCommandNodeFactory extends MethodCommandNodeFactory { return new UUIDCommandNode( name, root == null ? List.of() : List.of(root), - AllowedUUIDInputs.anyNotNull(), + parameter.isAnnotationPresent(NotNull.class) ? AllowedUUIDInputs.anyNotNull() : AllowedUUIDInputs.anyNullable(), null, null ); diff --git a/commands/src/main/java/com/wizardlybump17/wlib/command/extractor/method/factory/string/StringMethodCommandNodeFactory.java b/commands/src/main/java/com/wizardlybump17/wlib/command/extractor/method/factory/string/StringMethodCommandNodeFactory.java index 711cdf54..a627e218 100644 --- a/commands/src/main/java/com/wizardlybump17/wlib/command/extractor/method/factory/string/StringMethodCommandNodeFactory.java +++ b/commands/src/main/java/com/wizardlybump17/wlib/command/extractor/method/factory/string/StringMethodCommandNodeFactory.java @@ -23,7 +23,7 @@ public class StringMethodCommandNodeFactory extends MethodCommandNodeFactory { return new StringCommandNode( name, root == null ? List.of() : List.of(root), - AllowedStringInputs.anyNotNull(), + parameter.isAnnotationPresent(NotNull.class) ? AllowedStringInputs.anyNotNull() : AllowedStringInputs.anyNullable(), null, null ); diff --git a/commands/src/test/java/com/wizardlybump17/wlib/test/command/extractor/method/MethodCommandExtractorTests.java b/commands/src/test/java/com/wizardlybump17/wlib/test/command/extractor/method/MethodCommandExtractorTests.java index cba0cd14..17eaa65b 100644 --- a/commands/src/test/java/com/wizardlybump17/wlib/test/command/extractor/method/MethodCommandExtractorTests.java +++ b/commands/src/test/java/com/wizardlybump17/wlib/test/command/extractor/method/MethodCommandExtractorTests.java @@ -1006,7 +1006,7 @@ void testExecute() { Assertions.assertDoesNotThrow(() -> MethodCommandExtractor.createExecutor(object, "welcomeWorld", CommandSender.class, String.class)) ) ), - AllowedStringInputs.anyNotNull(), + AllowedStringInputs.anyNullable(), Assertions.assertDoesNotThrow(() -> MethodCommandExtractor.createExecutor(object, "welcome", CommandSender.class, String.class)), null ) @@ -1025,7 +1025,7 @@ void testExecute() { Assertions.assertDoesNotThrow(() -> MethodCommandExtractor.createExecutor(object, "wassupNice", CommandContext.class, String.class)) ) ), - AllowedStringInputs.anyNotNull(), + AllowedStringInputs.anyNullable(), Assertions.assertDoesNotThrow(() -> MethodCommandExtractor.createExecutor(object, "wassup", CommandContext.class, String.class)), null ) @@ -1044,7 +1044,7 @@ void testExecute() { Assertions.assertDoesNotThrow(() -> MethodCommandExtractor.createExecutor(object, "ayeNice", String.class)) ) ), - AllowedStringInputs.anyNotNull(), + AllowedStringInputs.anyNullable(), Assertions.assertDoesNotThrow(() -> MethodCommandExtractor.createExecutor(object, "aye", String.class)), null ) diff --git a/commands/src/test/java/com/wizardlybump17/wlib/test/command/extractor/method/MethodCommandNodeFactoryTests.java b/commands/src/test/java/com/wizardlybump17/wlib/test/command/extractor/method/MethodCommandNodeFactoryTests.java index 6664c4c6..d18678d2 100644 --- a/commands/src/test/java/com/wizardlybump17/wlib/test/command/extractor/method/MethodCommandNodeFactoryTests.java +++ b/commands/src/test/java/com/wizardlybump17/wlib/test/command/extractor/method/MethodCommandNodeFactoryTests.java @@ -471,7 +471,7 @@ void testString() { List.of( new StringCommandNode( "arg0", - AllowedStringInputs.anyNotNull() + AllowedStringInputs.anyNullable() ) ) ) @@ -488,12 +488,12 @@ void testString() { List.of( new StringCommandNode( "arg1", - AllowedStringInputs.anyNotNull() + AllowedStringInputs.anyNullable() ) ) ) ), - AllowedStringInputs.anyNotNull(), + AllowedStringInputs.anyNullable(), null, null ) @@ -531,7 +531,7 @@ void testUUID() { List.of( new UUIDCommandNode( "arg0", - AllowedUUIDInputs.anyNotNull() + AllowedUUIDInputs.anyNullable() ) ) ) @@ -548,12 +548,12 @@ void testUUID() { List.of( new UUIDCommandNode( "arg1", - AllowedUUIDInputs.anyNotNull() + AllowedUUIDInputs.anyNullable() ) ) ) ), - AllowedUUIDInputs.anyNotNull(), + AllowedUUIDInputs.anyNullable(), null, null ) @@ -668,24 +668,24 @@ void testMix() { List.of( new UUIDCommandNode( "uuid1", - AllowedUUIDInputs.anyNotNull() + AllowedUUIDInputs.anyNullable() ) ) ) ), - AllowedUUIDInputs.anyNotNull(), + AllowedUUIDInputs.anyNullable(), null, null ) ), - AllowedStringInputs.anyNotNull(), + AllowedStringInputs.anyNullable(), null, null ) ) ) ), - AllowedStringInputs.anyNotNull(), + AllowedStringInputs.anyNullable(), null, null ) From 32106312ba0236a0e01fdc5da774f9d17a1218e8 Mon Sep 17 00:00:00 2001 From: WizardlyBump17 Date: Fri, 5 Dec 2025 21:08:41 -0300 Subject: [PATCH 181/363] better documentation --- .../method/MethodCommandExtractor.java | 26 ++++++++++++------- 1 file changed, 17 insertions(+), 9 deletions(-) diff --git a/commands/src/main/java/com/wizardlybump17/wlib/command/extractor/method/MethodCommandExtractor.java b/commands/src/main/java/com/wizardlybump17/wlib/command/extractor/method/MethodCommandExtractor.java index aae7f624..ecd69d1b 100644 --- a/commands/src/main/java/com/wizardlybump17/wlib/command/extractor/method/MethodCommandExtractor.java +++ b/commands/src/main/java/com/wizardlybump17/wlib/command/extractor/method/MethodCommandExtractor.java @@ -116,16 +116,24 @@ public boolean isAccepted(@NotNull Object object) { } } - private static @NotNull CommandNodeExecutor createExecutor(@NotNull Object object, @NotNull Parameter @NotNull [] parameters, @NotNull Class returnType, @NotNull Method method) { - /* - If empty -> check the return type - If CommandSender only -> pass only the command sender and check the return type - If CommandContext only -> pass only the command context and check the return type - If CommandSender + more parameters -> pass the command sender and the parameters and check the return type - If CommandContext + more parameters -> pass the command context and the parameters and check the return type - If only parameters -> pass the parameters and check the return type - */ + /** + *

    + *
  • If empty -> check the return type;
  • + *
  • If CommandSender only -> pass only the command sender and check the return type;
  • + *
  • If CommandContext only -> pass only the command context and check the return type;
  • + *
  • If CommandSender + more parameters -> pass the command sender and the parameters and check the return type;
  • + *
  • If CommandContext + more parameters -> pass the command context and the parameters and check the return type;
  • + *
  • If only parameters -> pass the parameters and check the return type.
  • + *
+ * + * @param object the object containing the method + * @param parameters the parameters of the method + * @param returnType the return type of the method + * @param method the {@link Method} + * @return the appropriate CommandNodeExecutor based on the parameters and return type of the method + */ + private static @NotNull CommandNodeExecutor createExecutor(@NotNull Object object, @NotNull Parameter @NotNull [] parameters, @NotNull Class returnType, @NotNull Method method) { if (parameters.length == 0) { //no parameters if (returnType.isAssignableFrom(CommandResult.class)) { //CommandResult return type return new AbstractMethodCommandNodeExecutor.NoArgumentsCommandResultExecutor<>(object, method); From b61e8e6b6d4d21be026e7e9411e4e8daf4cad9ff Mon Sep 17 00:00:00 2001 From: WizardlyBump17 Date: Fri, 5 Dec 2025 21:10:48 -0300 Subject: [PATCH 182/363] starting the command system --- .../java/com/wizardlybump17/wlib/WLib.java | 37 ++++++++++++++++++- 1 file changed, 35 insertions(+), 2 deletions(-) diff --git a/core/src/main/java/com/wizardlybump17/wlib/WLib.java b/core/src/main/java/com/wizardlybump17/wlib/WLib.java index c02b83ca..d8944c17 100644 --- a/core/src/main/java/com/wizardlybump17/wlib/WLib.java +++ b/core/src/main/java/com/wizardlybump17/wlib/WLib.java @@ -4,6 +4,9 @@ import com.wizardlybump17.wlib.adapter.ItemAdapter; import com.wizardlybump17.wlib.adapter.command.CommandMapAdapter; import com.wizardlybump17.wlib.adapter.player.PlayerAdapter; +import com.wizardlybump17.wlib.command.extractor.method.MethodCommandExtractor; +import com.wizardlybump17.wlib.command.manager.CommandManager; +import com.wizardlybump17.wlib.command.registry.MethodCommandNodeFactoryRegistry; import com.wizardlybump17.wlib.config.holder.BukkitConfigHolderFactory; import com.wizardlybump17.wlib.config.registry.ConfigHandlerRegistry; import com.wizardlybump17.wlib.config.registry.ConfigHolderFactoryRegistry; @@ -35,13 +38,16 @@ public class WLib extends JavaPlugin { private final SaveControllersTask saveControllersTask = new SaveControllersTask(getLogger()); + private MethodCommandExtractor methodCommandExtractor; + private MethodCommandNodeFactoryRegistry methodCommandNodeFactoryRegistry; + private CommandManager commandManager; @Override public void onLoad() { + initCommandSystem(); ItemMetaHandlerModel.initModels(); initAdapters(); initSerializables(); - initCommandSystem(); DatabaseRegister databaseRegister = DatabaseRegister.getInstance(); databaseRegister.registerDatabaseModel(new MySQLDatabaseModel()); @@ -50,6 +56,15 @@ public void onLoad() { initConfigs(); } + private void initCommandSystem() { + methodCommandNodeFactoryRegistry = new MethodCommandNodeFactoryRegistry(); + methodCommandExtractor = new MethodCommandExtractor(methodCommandNodeFactoryRegistry); + + methodCommandNodeFactoryRegistry.registerDefaults(); + + commandManager = new CommandManager(); + } + protected void initConfigs() { getLogger().info("Initializing configs..."); @@ -71,11 +86,21 @@ public void onEnable() { @Override public void onDisable() { + clearCommandSystem(); HandlerList.unregisterAll(this); saveControllersTask.cancel(); } - private void initCommandSystem() { + private void clearCommandSystem() { + if (methodCommandNodeFactoryRegistry != null) + methodCommandNodeFactoryRegistry.clear(); + methodCommandNodeFactoryRegistry = null; + + methodCommandExtractor = null; + + if (commandManager != null) + commandManager.clear(); + commandManager = null; } private void initSerializables() { @@ -141,4 +166,12 @@ public static WLib getInstance() { public static @NonNull String getServerVersion() { return Bukkit.getServer().getClass().getName().split("\\.")[3]; } + + public MethodCommandExtractor getMethodCommandExtractor() { + return methodCommandExtractor; + } + + public MethodCommandNodeFactoryRegistry getMethodCommandNodeFactoryRegistry() { + return methodCommandNodeFactoryRegistry; + } } From fc355b7f0f54e1747560090c8c34336d866f3567 Mon Sep 17 00:00:00 2001 From: WizardlyBump17 Date: Fri, 5 Dec 2025 21:12:00 -0300 Subject: [PATCH 183/363] added the CommandManager#clear() method --- .../wizardlybump17/wlib/command/manager/CommandManager.java | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/commands/src/main/java/com/wizardlybump17/wlib/command/manager/CommandManager.java b/commands/src/main/java/com/wizardlybump17/wlib/command/manager/CommandManager.java index 448f67e7..40a5b76a 100644 --- a/commands/src/main/java/com/wizardlybump17/wlib/command/manager/CommandManager.java +++ b/commands/src/main/java/com/wizardlybump17/wlib/command/manager/CommandManager.java @@ -114,4 +114,9 @@ public class CommandManager { .ofNullable(commandsByFullName.get(name)) .or(() -> Optional.ofNullable(commandsByName.get(name))); } + + public void clear() { + commandsByName.clear(); + commandsByFullName.clear(); + } } From 1a2bcf613efea236d9a103991b84b247bc828fde Mon Sep 17 00:00:00 2001 From: WizardlyBump17 Date: Fri, 5 Dec 2025 21:12:18 -0300 Subject: [PATCH 184/363] you never know when someone is doing async --- .../wlib/command/manager/CommandManager.java | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/commands/src/main/java/com/wizardlybump17/wlib/command/manager/CommandManager.java b/commands/src/main/java/com/wizardlybump17/wlib/command/manager/CommandManager.java index 40a5b76a..71f617b9 100644 --- a/commands/src/main/java/com/wizardlybump17/wlib/command/manager/CommandManager.java +++ b/commands/src/main/java/com/wizardlybump17/wlib/command/manager/CommandManager.java @@ -8,14 +8,18 @@ import com.wizardlybump17.wlib.util.exception.QuotedStringException; import org.jetbrains.annotations.NotNull; -import java.util.*; +import java.util.ArrayList; +import java.util.List; +import java.util.Map; +import java.util.Optional; +import java.util.concurrent.ConcurrentHashMap; public class CommandManager { private static final char SEPARATOR = ':'; - private final @NotNull Map commandsByFullName = new HashMap<>(); - private final @NotNull Map commandsByName = new HashMap<>(); + private final @NotNull Map commandsByFullName = new ConcurrentHashMap<>(); + private final @NotNull Map commandsByName = new ConcurrentHashMap<>(); public @NotNull Command registerCommand(@NotNull String identifier, @NotNull Command command) { String commandName = command.getRoot().getName().toLowerCase(); From 0f2a394fac1b6fc5731588bbf65b3035e3aabcdc Mon Sep 17 00:00:00 2001 From: WizardlyBump17 Date: Fri, 5 Dec 2025 21:13:09 -0300 Subject: [PATCH 185/363] added some getters --- .../wlib/command/manager/CommandManager.java | 13 +++++++++---- 1 file changed, 9 insertions(+), 4 deletions(-) diff --git a/commands/src/main/java/com/wizardlybump17/wlib/command/manager/CommandManager.java b/commands/src/main/java/com/wizardlybump17/wlib/command/manager/CommandManager.java index 71f617b9..6a1327d0 100644 --- a/commands/src/main/java/com/wizardlybump17/wlib/command/manager/CommandManager.java +++ b/commands/src/main/java/com/wizardlybump17/wlib/command/manager/CommandManager.java @@ -8,10 +8,7 @@ import com.wizardlybump17.wlib.util.exception.QuotedStringException; import org.jetbrains.annotations.NotNull; -import java.util.ArrayList; -import java.util.List; -import java.util.Map; -import java.util.Optional; +import java.util.*; import java.util.concurrent.ConcurrentHashMap; public class CommandManager { @@ -123,4 +120,12 @@ public void clear() { commandsByName.clear(); commandsByFullName.clear(); } + + public @NotNull Map getCommandsByFullName() { + return Collections.unmodifiableMap(commandsByFullName); + } + + public @NotNull Map getCommandsByName() { + return Collections.unmodifiableMap(commandsByName); + } } From c5588f138c4f37fbf71313cced4a3e9f95b3e285 Mon Sep 17 00:00:00 2001 From: WizardlyBump17 Date: Fri, 5 Dec 2025 21:29:27 -0300 Subject: [PATCH 186/363] added the command executor --- .../java/com/wizardlybump17/wlib/WLib.java | 10 +++ .../wlib/command/WLibCommandExecutor.java | 71 +++++++++++++++++++ 2 files changed, 81 insertions(+) create mode 100644 core/src/main/java/com/wizardlybump17/wlib/command/WLibCommandExecutor.java diff --git a/core/src/main/java/com/wizardlybump17/wlib/WLib.java b/core/src/main/java/com/wizardlybump17/wlib/WLib.java index d8944c17..96735d4d 100644 --- a/core/src/main/java/com/wizardlybump17/wlib/WLib.java +++ b/core/src/main/java/com/wizardlybump17/wlib/WLib.java @@ -4,6 +4,7 @@ import com.wizardlybump17.wlib.adapter.ItemAdapter; import com.wizardlybump17.wlib.adapter.command.CommandMapAdapter; import com.wizardlybump17.wlib.adapter.player.PlayerAdapter; +import com.wizardlybump17.wlib.command.WLibCommandExecutor; import com.wizardlybump17.wlib.command.extractor.method.MethodCommandExtractor; import com.wizardlybump17.wlib.command.manager.CommandManager; import com.wizardlybump17.wlib.command.registry.MethodCommandNodeFactoryRegistry; @@ -41,6 +42,7 @@ public class WLib extends JavaPlugin { private MethodCommandExtractor methodCommandExtractor; private MethodCommandNodeFactoryRegistry methodCommandNodeFactoryRegistry; private CommandManager commandManager; + private WLibCommandExecutor commandExecutor; @Override public void onLoad() { @@ -63,6 +65,8 @@ private void initCommandSystem() { methodCommandNodeFactoryRegistry.registerDefaults(); commandManager = new CommandManager(); + + commandExecutor = new WLibCommandExecutor(commandManager); } protected void initConfigs() { @@ -101,6 +105,8 @@ private void clearCommandSystem() { if (commandManager != null) commandManager.clear(); commandManager = null; + + commandExecutor = null; } private void initSerializables() { @@ -174,4 +180,8 @@ public MethodCommandExtractor getMethodCommandExtractor() { public MethodCommandNodeFactoryRegistry getMethodCommandNodeFactoryRegistry() { return methodCommandNodeFactoryRegistry; } + + public CommandManager getCommandManager() { + return commandManager; + } } diff --git a/core/src/main/java/com/wizardlybump17/wlib/command/WLibCommandExecutor.java b/core/src/main/java/com/wizardlybump17/wlib/command/WLibCommandExecutor.java new file mode 100644 index 00000000..285ddaa4 --- /dev/null +++ b/core/src/main/java/com/wizardlybump17/wlib/command/WLibCommandExecutor.java @@ -0,0 +1,71 @@ +package com.wizardlybump17.wlib.command; + +import com.wizardlybump17.wlib.command.manager.CommandManager; +import com.wizardlybump17.wlib.command.result.CommandResult; +import com.wizardlybump17.wlib.command.result.SuccessResult; +import com.wizardlybump17.wlib.command.result.error.*; +import com.wizardlybump17.wlib.command.sender.BukkitCommandSender; +import org.bukkit.command.Command; +import org.bukkit.command.CommandExecutor; +import org.bukkit.command.CommandSender; +import org.bukkit.command.TabCompleter; +import org.jetbrains.annotations.NotNull; +import org.jetbrains.annotations.Nullable; + +import java.util.ArrayList; +import java.util.Collections; +import java.util.List; + +public class WLibCommandExecutor implements CommandExecutor, TabCompleter { + + private final @NotNull CommandManager commandManager; + + public WLibCommandExecutor(@NotNull CommandManager commandManager) { + this.commandManager = commandManager; + } + + public @NotNull CommandManager getCommandManager() { + return commandManager; + } + + @Override + public boolean onCommand(@NotNull CommandSender sender, @NotNull Command command, @NotNull String label, @NotNull String[] args) { + com.wizardlybump17.wlib.command.sender.CommandSender wlibSender = new BukkitCommandSender(sender); + + List wlibArgs = new ArrayList<>(); + wlibArgs.add(command.getName()); + Collections.addAll(wlibArgs, args); + + CommandResult result = commandManager.execute(wlibSender, wlibArgs); + switch (result) { + case SuccessResult successResult -> {} + case ExceptionResult exceptionResult -> sender.sendMessage("§cAn internal error occurred while executing this command."); + case OutOfRangeInputResult outOfRangeInputResult -> sender.sendMessage("§cInvalid input at index " + outOfRangeInputResult.lastInputIndex() + "."); + case ExtraArgumentsResult extraArgumentsResult -> sender.sendMessage("§cExtra arguments provided at index " + extraArgumentsResult.lastInputIndex() + "."); + case InsufficientArgumentsResult insufficientArgumentsResult -> sender.sendMessage("§cInsufficient arguments provided."); + case ParseInputExceptionResult parseInputExceptionResult -> sender.sendMessage("§cInvalid input at index " + parseInputExceptionResult.lastInputIndex() + ": " + parseInputExceptionResult.exception().getMessage()); + case CommandNodeExecutorNotFoundResult notFoundResult -> sender.sendMessage("§cNo executor found for this command."); + case GenericErrorResult genericErrorResult -> sender.sendMessage("§cAn error occurred while executing the command."); + case NoPermissionResult noPermissionResult -> sender.sendMessage("§cYou do not have permission to execute this command."); + case CommandNotFoundResult notFoundResult -> sender.sendMessage("§cCommand not found."); + case InvalidSenderResult invalidSenderResult -> sender.sendMessage("§cYou can not execute this command."); + default -> {} + } + + return false; + } + + @Override + public @Nullable List onTabComplete(@NotNull CommandSender sender, @NotNull Command command, @NotNull String label, @NotNull String[] args) { + com.wizardlybump17.wlib.command.sender.CommandSender wlibSender = new BukkitCommandSender(sender); + + List wlibArgs = new ArrayList<>(); + wlibArgs.add(command.getName()); + Collections.addAll(wlibArgs, args); + + return commandManager.getSuggestions(wlibSender, wlibArgs) + .stream() + .map(Object::toString) + .toList(); + } +} From 622c196d64c3267968c707ad20f0ba63c5dcd580 Mon Sep 17 00:00:00 2001 From: WizardlyBump17 Date: Fri, 5 Dec 2025 21:34:59 -0300 Subject: [PATCH 187/363] added listeners for hte CommandManager --- .../wlib/command/manager/CommandManager.java | 15 +++++++++++++++ .../manager/listener/CommandManagerListener.java | 12 ++++++++++++ 2 files changed, 27 insertions(+) create mode 100644 commands/src/main/java/com/wizardlybump17/wlib/command/manager/listener/CommandManagerListener.java diff --git a/commands/src/main/java/com/wizardlybump17/wlib/command/manager/CommandManager.java b/commands/src/main/java/com/wizardlybump17/wlib/command/manager/CommandManager.java index 6a1327d0..e2dfc51c 100644 --- a/commands/src/main/java/com/wizardlybump17/wlib/command/manager/CommandManager.java +++ b/commands/src/main/java/com/wizardlybump17/wlib/command/manager/CommandManager.java @@ -1,12 +1,14 @@ package com.wizardlybump17.wlib.command.manager; import com.wizardlybump17.wlib.command.Command; +import com.wizardlybump17.wlib.command.manager.listener.CommandManagerListener; import com.wizardlybump17.wlib.command.node.CommandNode; import com.wizardlybump17.wlib.command.result.CommandResult; import com.wizardlybump17.wlib.command.sender.CommandSender; import com.wizardlybump17.wlib.util.StringUtil; import com.wizardlybump17.wlib.util.exception.QuotedStringException; import org.jetbrains.annotations.NotNull; +import org.jetbrains.annotations.UnmodifiableView; import java.util.*; import java.util.concurrent.ConcurrentHashMap; @@ -17,6 +19,7 @@ public class CommandManager { private final @NotNull Map commandsByFullName = new ConcurrentHashMap<>(); private final @NotNull Map commandsByName = new ConcurrentHashMap<>(); + private final @NotNull Set listeners = ConcurrentHashMap.newKeySet(); public @NotNull Command registerCommand(@NotNull String identifier, @NotNull Command command) { String commandName = command.getRoot().getName().toLowerCase(); @@ -128,4 +131,16 @@ public void clear() { public @NotNull Map getCommandsByName() { return Collections.unmodifiableMap(commandsByName); } + + public void addListener(@NotNull CommandManagerListener listener) { + listeners.add(listener); + } + + public void clearListeners() { + listeners.clear(); + } + + public @NotNull @UnmodifiableView Set getListeners() { + return Collections.unmodifiableSet(listeners); + } } diff --git a/commands/src/main/java/com/wizardlybump17/wlib/command/manager/listener/CommandManagerListener.java b/commands/src/main/java/com/wizardlybump17/wlib/command/manager/listener/CommandManagerListener.java new file mode 100644 index 00000000..b4a64b95 --- /dev/null +++ b/commands/src/main/java/com/wizardlybump17/wlib/command/manager/listener/CommandManagerListener.java @@ -0,0 +1,12 @@ +package com.wizardlybump17.wlib.command.manager.listener; + +import com.wizardlybump17.wlib.command.Command; +import com.wizardlybump17.wlib.command.manager.CommandManager; +import org.jetbrains.annotations.NotNull; + +public interface CommandManagerListener { + + void onRegister(@NotNull String identifier, @NotNull Command command, @NotNull CommandManager manager); + + void onClear(@NotNull CommandManager manager); +} From 440cd476a74b187318a194472c0af235a0b185f6 Mon Sep 17 00:00:00 2001 From: WizardlyBump17 Date: Fri, 5 Dec 2025 21:40:09 -0300 Subject: [PATCH 188/363] you are unmodifiable, but the underlying Map is not --- .../wizardlybump17/wlib/command/manager/CommandManager.java | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/commands/src/main/java/com/wizardlybump17/wlib/command/manager/CommandManager.java b/commands/src/main/java/com/wizardlybump17/wlib/command/manager/CommandManager.java index e2dfc51c..5701e86b 100644 --- a/commands/src/main/java/com/wizardlybump17/wlib/command/manager/CommandManager.java +++ b/commands/src/main/java/com/wizardlybump17/wlib/command/manager/CommandManager.java @@ -124,11 +124,11 @@ public void clear() { commandsByFullName.clear(); } - public @NotNull Map getCommandsByFullName() { + public @NotNull @UnmodifiableView Map getCommandsByFullName() { return Collections.unmodifiableMap(commandsByFullName); } - public @NotNull Map getCommandsByName() { + public @NotNull @UnmodifiableView Map getCommandsByName() { return Collections.unmodifiableMap(commandsByName); } From 268313a2b2b240b5af288b27877ddbfda4162205 Mon Sep 17 00:00:00 2001 From: WizardlyBump17 Date: Fri, 5 Dec 2025 21:45:54 -0300 Subject: [PATCH 189/363] commands can have holders now --- .../wlib/command/manager/CommandManager.java | 31 +++++++++++++++++-- .../listener/CommandManagerListener.java | 3 +- 2 files changed, 30 insertions(+), 4 deletions(-) diff --git a/commands/src/main/java/com/wizardlybump17/wlib/command/manager/CommandManager.java b/commands/src/main/java/com/wizardlybump17/wlib/command/manager/CommandManager.java index 5701e86b..297ec71e 100644 --- a/commands/src/main/java/com/wizardlybump17/wlib/command/manager/CommandManager.java +++ b/commands/src/main/java/com/wizardlybump17/wlib/command/manager/CommandManager.java @@ -8,6 +8,7 @@ import com.wizardlybump17.wlib.util.StringUtil; import com.wizardlybump17.wlib.util.exception.QuotedStringException; import org.jetbrains.annotations.NotNull; +import org.jetbrains.annotations.Nullable; import org.jetbrains.annotations.UnmodifiableView; import java.util.*; @@ -20,8 +21,9 @@ public class CommandManager { private final @NotNull Map commandsByFullName = new ConcurrentHashMap<>(); private final @NotNull Map commandsByName = new ConcurrentHashMap<>(); private final @NotNull Set listeners = ConcurrentHashMap.newKeySet(); + private final @NotNull Map> commandsByHolder = new ConcurrentHashMap<>(); - public @NotNull Command registerCommand(@NotNull String identifier, @NotNull Command command) { + public @NotNull Command registerCommand(@NotNull String identifier, @NotNull Command command, @Nullable Object holder) { String commandName = command.getRoot().getName().toLowerCase(); String fullCommandName = identifier + SEPARATOR + commandName; @@ -32,23 +34,35 @@ public class CommandManager { commandsByFullName.put(fullCommandName, newCommand); commandsByName.put(commandName, newCommand); + if (holder != null) + commandsByHolder.computeIfAbsent(holder, $ -> ConcurrentHashMap.newKeySet()).add(command); return newCommand; } commandsByFullName.put(fullCommandName, command); commandsByName.put(commandName, command); + if (holder != null) + commandsByHolder.computeIfAbsent(holder, $ -> ConcurrentHashMap.newKeySet()).add(command); return command; } - public @NotNull List registerCommands(@NotNull String identifier, @NotNull List commands) { + public @NotNull Command registerCommand(@NotNull String identifier, @NotNull Command command) { + return registerCommand(identifier, command, null); + } + + public @NotNull List registerCommands(@NotNull String identifier, @NotNull List commands, @Nullable Object holder) { List newCommands = new ArrayList<>(commands.size()); for (Command command : commands) - newCommands.add(registerCommand(identifier, command)); + newCommands.add(registerCommand(identifier, command, holder)); return newCommands; } + public @NotNull List registerCommands(@NotNull String identifier, @NotNull List commands) { + return registerCommands(identifier, commands, null); + } + protected @NotNull Command mergeCommand(@NotNull Command left, @NotNull Command right) { return left.merge(right); } @@ -122,6 +136,9 @@ public class CommandManager { public void clear() { commandsByName.clear(); commandsByFullName.clear(); + + commandsByHolder.forEach((holder, commands) -> commands.clear()); + commandsByHolder.clear(); } public @NotNull @UnmodifiableView Map getCommandsByFullName() { @@ -132,6 +149,14 @@ public void clear() { return Collections.unmodifiableMap(commandsByName); } + public @NotNull @UnmodifiableView Map> getCommandsByHolder() { + return Collections.unmodifiableMap(commandsByHolder); + } + + public @NotNull @UnmodifiableView Set getCommandsByHolder(@NotNull Object holder) { + return Collections.unmodifiableSet(commandsByHolder.getOrDefault(holder, Set.of())); + } + public void addListener(@NotNull CommandManagerListener listener) { listeners.add(listener); } diff --git a/commands/src/main/java/com/wizardlybump17/wlib/command/manager/listener/CommandManagerListener.java b/commands/src/main/java/com/wizardlybump17/wlib/command/manager/listener/CommandManagerListener.java index b4a64b95..e8b2c13d 100644 --- a/commands/src/main/java/com/wizardlybump17/wlib/command/manager/listener/CommandManagerListener.java +++ b/commands/src/main/java/com/wizardlybump17/wlib/command/manager/listener/CommandManagerListener.java @@ -3,10 +3,11 @@ import com.wizardlybump17.wlib.command.Command; import com.wizardlybump17.wlib.command.manager.CommandManager; import org.jetbrains.annotations.NotNull; +import org.jetbrains.annotations.Nullable; public interface CommandManagerListener { - void onRegister(@NotNull String identifier, @NotNull Command command, @NotNull CommandManager manager); + void onRegister(@NotNull String identifier, @NotNull Command command, @Nullable Object holder, @NotNull CommandManager manager); void onClear(@NotNull CommandManager manager); } From 3b864059fbf7924f85685f7dc0c9d32e3b2fa8f4 Mon Sep 17 00:00:00 2001 From: WizardlyBump17 Date: Fri, 5 Dec 2025 21:48:53 -0300 Subject: [PATCH 190/363] actually calling the listeners --- .../wlib/command/manager/CommandManager.java | 26 +++++++++++-------- 1 file changed, 15 insertions(+), 11 deletions(-) diff --git a/commands/src/main/java/com/wizardlybump17/wlib/command/manager/CommandManager.java b/commands/src/main/java/com/wizardlybump17/wlib/command/manager/CommandManager.java index 297ec71e..c56c4506 100644 --- a/commands/src/main/java/com/wizardlybump17/wlib/command/manager/CommandManager.java +++ b/commands/src/main/java/com/wizardlybump17/wlib/command/manager/CommandManager.java @@ -23,6 +23,16 @@ public class CommandManager { private final @NotNull Set listeners = ConcurrentHashMap.newKeySet(); private final @NotNull Map> commandsByHolder = new ConcurrentHashMap<>(); + protected void addCommand(@NotNull String identifier, @NotNull String fullName, @NotNull String name, @NotNull Command command, @Nullable Object holder) { + commandsByFullName.put(fullName, command); + commandsByName.put(name, command); + if (holder != null) + commandsByHolder.computeIfAbsent(holder, $ -> ConcurrentHashMap.newKeySet()).add(command); + + for (CommandManagerListener listener : listeners) + listener.onRegister(identifier, command, holder, this); + } + public @NotNull Command registerCommand(@NotNull String identifier, @NotNull Command command, @Nullable Object holder) { String commandName = command.getRoot().getName().toLowerCase(); String fullCommandName = identifier + SEPARATOR + commandName; @@ -31,20 +41,11 @@ public class CommandManager { if (existingCommand != null) { Command newCommand = mergeCommand(existingCommand, command); - - commandsByFullName.put(fullCommandName, newCommand); - commandsByName.put(commandName, newCommand); - if (holder != null) - commandsByHolder.computeIfAbsent(holder, $ -> ConcurrentHashMap.newKeySet()).add(command); - + addCommand(identifier, fullCommandName, commandName, newCommand, holder); return newCommand; } - commandsByFullName.put(fullCommandName, command); - commandsByName.put(commandName, command); - if (holder != null) - commandsByHolder.computeIfAbsent(holder, $ -> ConcurrentHashMap.newKeySet()).add(command); - + addCommand(identifier, fullCommandName, commandName, command, holder); return command; } @@ -139,6 +140,9 @@ public void clear() { commandsByHolder.forEach((holder, commands) -> commands.clear()); commandsByHolder.clear(); + + for (CommandManagerListener listener : listeners) + listener.onClear(this); } public @NotNull @UnmodifiableView Map getCommandsByFullName() { From 7bfc602353df0069459d0a20987b8b85a04daf18 Mon Sep 17 00:00:00 2001 From: WizardlyBump17 Date: Fri, 5 Dec 2025 21:56:24 -0300 Subject: [PATCH 191/363] made it be public --- .../com/wizardlybump17/wlib/command/manager/CommandManager.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/commands/src/main/java/com/wizardlybump17/wlib/command/manager/CommandManager.java b/commands/src/main/java/com/wizardlybump17/wlib/command/manager/CommandManager.java index c56c4506..8c3a7a49 100644 --- a/commands/src/main/java/com/wizardlybump17/wlib/command/manager/CommandManager.java +++ b/commands/src/main/java/com/wizardlybump17/wlib/command/manager/CommandManager.java @@ -16,7 +16,7 @@ public class CommandManager { - private static final char SEPARATOR = ':'; + public static final char SEPARATOR = ':'; private final @NotNull Map commandsByFullName = new ConcurrentHashMap<>(); private final @NotNull Map commandsByName = new ConcurrentHashMap<>(); From db1b0678bbc302d6dd9d0c0920e81f96d52d2908 Mon Sep 17 00:00:00 2001 From: WizardlyBump17 Date: Fri, 5 Dec 2025 21:56:35 -0300 Subject: [PATCH 192/363] added the CommandManager#isEmpty() method --- .../wizardlybump17/wlib/command/manager/CommandManager.java | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/commands/src/main/java/com/wizardlybump17/wlib/command/manager/CommandManager.java b/commands/src/main/java/com/wizardlybump17/wlib/command/manager/CommandManager.java index 8c3a7a49..91712df0 100644 --- a/commands/src/main/java/com/wizardlybump17/wlib/command/manager/CommandManager.java +++ b/commands/src/main/java/com/wizardlybump17/wlib/command/manager/CommandManager.java @@ -172,4 +172,8 @@ public void clearListeners() { public @NotNull @UnmodifiableView Set getListeners() { return Collections.unmodifiableSet(listeners); } + + public boolean isEmpty() { + return commandsByFullName.isEmpty(); + } } From d26cc0e2e607da22b519a5505b073f43cefbb6c9 Mon Sep 17 00:00:00 2001 From: WizardlyBump17 Date: Fri, 5 Dec 2025 21:56:48 -0300 Subject: [PATCH 193/363] added tests for the CommandManagerListener --- .../listener/CommandManagerListenerTests.java | 98 +++++++++++++++++++ 1 file changed, 98 insertions(+) create mode 100644 commands/src/test/java/com/wizardlybump17/wlib/test/command/manager/listener/CommandManagerListenerTests.java diff --git a/commands/src/test/java/com/wizardlybump17/wlib/test/command/manager/listener/CommandManagerListenerTests.java b/commands/src/test/java/com/wizardlybump17/wlib/test/command/manager/listener/CommandManagerListenerTests.java new file mode 100644 index 00000000..1bd888cb --- /dev/null +++ b/commands/src/test/java/com/wizardlybump17/wlib/test/command/manager/listener/CommandManagerListenerTests.java @@ -0,0 +1,98 @@ +package com.wizardlybump17.wlib.test.command.manager.listener; + +import com.wizardlybump17.wlib.command.Command; +import com.wizardlybump17.wlib.command.manager.CommandManager; +import com.wizardlybump17.wlib.command.manager.listener.CommandManagerListener; +import com.wizardlybump17.wlib.command.node.LiteralCommandNode; +import org.jetbrains.annotations.NotNull; +import org.jetbrains.annotations.Nullable; +import org.junit.jupiter.api.Assertions; +import org.junit.jupiter.api.Test; + +import java.util.ArrayList; +import java.util.List; +import java.util.concurrent.atomic.AtomicBoolean; +import java.util.concurrent.atomic.AtomicInteger; + +class CommandManagerListenerTests { + + @Test + void testBeingCalledRegister() { + AtomicInteger counter = new AtomicInteger(); + + CommandManager manager = new CommandManager(); + manager.addListener(new CommandManagerListener() { + @Override + public void onRegister(@NotNull String identifier, @NotNull Command command, @Nullable Object holder, @NotNull CommandManager manager) { + counter.incrementAndGet(); + } + + @Override + public void onClear(@NotNull CommandManager manager) { + } + }); + + manager.registerCommand("test", new Command(new LiteralCommandNode("test"))); + manager.registerCommand("test", new Command(new LiteralCommandNode("test"))); + manager.registerCommand("test", new Command(new LiteralCommandNode("test"))); + + Assertions.assertEquals(3, counter.get()); + } + + @Test + void testSeeingRightCommands() { + List seenCommands = new ArrayList<>(); + + CommandManager manager = new CommandManager(); + manager.addListener(new CommandManagerListener() { + @Override + public void onRegister(@NotNull String identifier, @NotNull Command command, @Nullable Object holder, @NotNull CommandManager manager) { + seenCommands.add(identifier + CommandManager.SEPARATOR + command.getRoot().getName()); + } + + @Override + public void onClear(@NotNull CommandManager manager) { + } + }); + + manager.registerCommand("test", new Command(new LiteralCommandNode("test0"))); + manager.registerCommand("test", new Command(new LiteralCommandNode("test1"))); + manager.registerCommand("test", new Command(new LiteralCommandNode("test2"))); + + Assertions.assertEquals( + List.of( + "test:test0", + "test:test1", + "test:test2" + ), + seenCommands + ); + } + + @Test + void testBeingCalledClear() { + AtomicBoolean called = new AtomicBoolean(); + + CommandManager manager = new CommandManager(); + + manager.addListener(new CommandManagerListener() { + @Override + public void onRegister(@NotNull String identifier, @NotNull Command command, @Nullable Object holder, @NotNull CommandManager manager) { + } + + @Override + public void onClear(@NotNull CommandManager manager) { + Assertions.assertTrue(manager.isEmpty()); + called.set(true); + } + }); + + manager.registerCommand("test", new Command(new LiteralCommandNode("test0"))); + manager.registerCommand("test", new Command(new LiteralCommandNode("test1"))); + manager.registerCommand("test", new Command(new LiteralCommandNode("test2"))); + + manager.clear(); + + Assertions.assertTrue(called.get()); + } +} From a7912a2a339d3136eb6b27ab7bafa525477f2472 Mon Sep 17 00:00:00 2001 From: WizardlyBump17 Date: Fri, 5 Dec 2025 21:58:22 -0300 Subject: [PATCH 194/363] added the Command#getName() method --- .../main/java/com/wizardlybump17/wlib/command/Command.java | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/commands/src/main/java/com/wizardlybump17/wlib/command/Command.java b/commands/src/main/java/com/wizardlybump17/wlib/command/Command.java index 64821b77..c700f265 100644 --- a/commands/src/main/java/com/wizardlybump17/wlib/command/Command.java +++ b/commands/src/main/java/com/wizardlybump17/wlib/command/Command.java @@ -221,4 +221,8 @@ public int compareTo(@NotNull Command other) { public @Nullable CommandNode findNode(@NotNull String name) { return root.findChild(name); } + + public @NotNull String getName() { + return root.getName(); + } } From 5fc553bd6772e03dd1d6f5528aef59a471faa804 Mon Sep 17 00:00:00 2001 From: WizardlyBump17 Date: Fri, 5 Dec 2025 22:06:46 -0300 Subject: [PATCH 195/363] added the BukkitCommandManagerListener --- .../java/com/wizardlybump17/wlib/WLib.java | 12 +++++- .../BukkitCommandManagerListener.java | 43 +++++++++++++++++++ 2 files changed, 54 insertions(+), 1 deletion(-) create mode 100644 core/src/main/java/com/wizardlybump17/wlib/command/listener/BukkitCommandManagerListener.java diff --git a/core/src/main/java/com/wizardlybump17/wlib/WLib.java b/core/src/main/java/com/wizardlybump17/wlib/WLib.java index 96735d4d..0115e175 100644 --- a/core/src/main/java/com/wizardlybump17/wlib/WLib.java +++ b/core/src/main/java/com/wizardlybump17/wlib/WLib.java @@ -6,6 +6,7 @@ import com.wizardlybump17.wlib.adapter.player.PlayerAdapter; import com.wizardlybump17.wlib.command.WLibCommandExecutor; import com.wizardlybump17.wlib.command.extractor.method.MethodCommandExtractor; +import com.wizardlybump17.wlib.command.listener.BukkitCommandManagerListener; import com.wizardlybump17.wlib.command.manager.CommandManager; import com.wizardlybump17.wlib.command.registry.MethodCommandNodeFactoryRegistry; import com.wizardlybump17.wlib.config.holder.BukkitConfigHolderFactory; @@ -39,10 +40,12 @@ public class WLib extends JavaPlugin { private final SaveControllersTask saveControllersTask = new SaveControllersTask(getLogger()); + private MethodCommandExtractor methodCommandExtractor; private MethodCommandNodeFactoryRegistry methodCommandNodeFactoryRegistry; private CommandManager commandManager; private WLibCommandExecutor commandExecutor; + private BukkitCommandManagerListener commandManagerListener; @Override public void onLoad() { @@ -67,6 +70,9 @@ private void initCommandSystem() { commandManager = new CommandManager(); commandExecutor = new WLibCommandExecutor(commandManager); + + commandManagerListener = new BukkitCommandManagerListener(commandExecutor); + commandManager.addListener(commandManagerListener); } protected void initConfigs() { @@ -102,11 +108,15 @@ private void clearCommandSystem() { methodCommandExtractor = null; - if (commandManager != null) + if (commandManager != null) { commandManager.clear(); + commandManager.clearListeners(); + } commandManager = null; commandExecutor = null; + + commandManagerListener = null; } private void initSerializables() { diff --git a/core/src/main/java/com/wizardlybump17/wlib/command/listener/BukkitCommandManagerListener.java b/core/src/main/java/com/wizardlybump17/wlib/command/listener/BukkitCommandManagerListener.java new file mode 100644 index 00000000..1a946138 --- /dev/null +++ b/core/src/main/java/com/wizardlybump17/wlib/command/listener/BukkitCommandManagerListener.java @@ -0,0 +1,43 @@ +package com.wizardlybump17.wlib.command.listener; + +import com.wizardlybump17.wlib.command.Command; +import com.wizardlybump17.wlib.command.WLibCommandExecutor; +import com.wizardlybump17.wlib.command.manager.CommandManager; +import com.wizardlybump17.wlib.command.manager.listener.CommandManagerListener; +import org.bukkit.command.PluginCommand; +import org.bukkit.plugin.java.JavaPlugin; +import org.jetbrains.annotations.NotNull; +import org.jetbrains.annotations.Nullable; + +import java.util.logging.Level; + +public class BukkitCommandManagerListener implements CommandManagerListener { + + private final @NotNull WLibCommandExecutor commandExecutor; + + public BukkitCommandManagerListener(@NotNull WLibCommandExecutor commandExecutor) { + this.commandExecutor = commandExecutor; + } + + @Override + public void onRegister(@NotNull String identifier, @NotNull Command command, @Nullable Object holder, @NotNull CommandManager manager) { + if (!(holder instanceof JavaPlugin plugin)) + return; + + PluginCommand pluginCommand = plugin.getCommand(command.getName()); + if (pluginCommand == null) { + plugin.getLogger().log(Level.WARNING, "Command not found on plugin.yml while trying to register it to WLib: " + command.getName()); + return; + } + + pluginCommand.setExecutor(commandExecutor); + } + + @Override + public void onClear(@NotNull CommandManager manager) { + } + + public @NotNull WLibCommandExecutor getCommandExecutor() { + return commandExecutor; + } +} From 014d4d8323f1e406395f0202867b29a3d59c5abf Mon Sep 17 00:00:00 2001 From: WizardlyBump17 Date: Sat, 6 Dec 2025 16:18:52 -0300 Subject: [PATCH 196/363] I think snapshots will be better now --- .github/workflows/build.yml | 4 +--- .github/workflows/publish.yml | 4 +--- build.gradle | 2 +- 3 files changed, 3 insertions(+), 7 deletions(-) diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml index aae6a066..85681fff 100644 --- a/.github/workflows/build.yml +++ b/.github/workflows/build.yml @@ -11,7 +11,7 @@ on: env: USERNAME: ${{ github.actor }} TOKEN: ${{ secrets.GITHUB_TOKEN }} - WLIB_SNAPSHOT: ${{ github.event_name != 'release' }} + WLIB_RELEASE: ${{ github.event_name == 'release' }} jobs: build: @@ -21,8 +21,6 @@ jobs: steps: - name: Get current date run: echo "WLIB_BUILD_DATE=$(date +'%Y-%m-%d_%H-%M-%S')" >> "$GITHUB_ENV" - - name: Get snapshot number - run: echo "WLIB_SNAPSHOT_NUMBER=$((${{ github.run_number }}+${{ github.run_attempt }}))" >> $GITHUB_ENV - uses: actions/checkout@v4 - name: Set up JDK 21 uses: actions/setup-java@v4 diff --git a/.github/workflows/publish.yml b/.github/workflows/publish.yml index eb18b0c8..15cede0a 100644 --- a/.github/workflows/publish.yml +++ b/.github/workflows/publish.yml @@ -11,7 +11,7 @@ on: env: USERNAME: ${{ github.actor }} TOKEN: ${{ secrets.GITHUB_TOKEN }} - WLIB_SNAPSHOT: ${{ github.event_name != 'release' }} + WLIB_RELEASE: ${{ github.event_name == 'release' }} jobs: build: @@ -22,8 +22,6 @@ jobs: steps: - name: Get current date run: echo "WLIB_BUILD_DATE=$(date +'%Y-%m-%d_%H-%M-%S')" >> "$GITHUB_ENV" - - name: Get snapshot number - run: echo "WLIB_SNAPSHOT_NUMBER=$((${{ github.run_number }}+${{ github.run_attempt }}))" >> $GITHUB_ENV - uses: actions/checkout@v4 - name: Set up JDK 21 uses: actions/setup-java@v4 diff --git a/build.gradle b/build.gradle index fa2419ba..fb3a2543 100644 --- a/build.gradle +++ b/build.gradle @@ -9,7 +9,7 @@ subprojects { apply plugin: 'maven-publish' group = 'com.wizardlybump17.wlib' - version = "1.6.8-ncs-1.20.6+" + ("true".equalsIgnoreCase(System.getenv("WLIB_SNAPSHOT")) ? "-SNAPSHOT." + System.getenv("WLIB_SNAPSHOT_NUMBER") : "") + version = "1.6.8-ncs-2-1.20.6+" + ("true".equalsIgnoreCase(System.getenv("WLIB_RELEASE")) ? "" : "-SNAPSHOT") repositories { mavenLocal() From 3672d77ea0cf8b48856afabdd68a90fecb9a9d21 Mon Sep 17 00:00:00 2001 From: WizardlyBump17 Date: Sat, 6 Dec 2025 16:24:40 -0300 Subject: [PATCH 197/363] forgot the -2 --- .github/workflows/publish.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/publish.yml b/.github/workflows/publish.yml index 15cede0a..65aff338 100644 --- a/.github/workflows/publish.yml +++ b/.github/workflows/publish.yml @@ -6,7 +6,7 @@ on: - published push: branches: - - new-command-system-1.20.6 + - new-command-system-1.20.6-2 env: USERNAME: ${{ github.actor }} From 6f0fb0714d00da906293c7d4ecdbb306425c5fac Mon Sep 17 00:00:00 2001 From: WizardlyBump17 Date: Sat, 6 Dec 2025 16:28:18 -0300 Subject: [PATCH 198/363] manual dispatches --- .github/workflows/publish.yml | 1 + 1 file changed, 1 insertion(+) diff --git a/.github/workflows/publish.yml b/.github/workflows/publish.yml index 65aff338..64bceeeb 100644 --- a/.github/workflows/publish.yml +++ b/.github/workflows/publish.yml @@ -7,6 +7,7 @@ on: push: branches: - new-command-system-1.20.6-2 + workflow_dispatch: env: USERNAME: ${{ github.actor }} From 850b587634d1b06d29e2dc24f7fa1bb13d33c74d Mon Sep 17 00:00:00 2001 From: WizardlyBump17 Date: Sat, 6 Dec 2025 16:36:29 -0300 Subject: [PATCH 199/363] Revert "manual dispatches" This reverts commit 6f0fb0714d00da906293c7d4ecdbb306425c5fac. --- .github/workflows/publish.yml | 1 - 1 file changed, 1 deletion(-) diff --git a/.github/workflows/publish.yml b/.github/workflows/publish.yml index 64bceeeb..65aff338 100644 --- a/.github/workflows/publish.yml +++ b/.github/workflows/publish.yml @@ -7,7 +7,6 @@ on: push: branches: - new-command-system-1.20.6-2 - workflow_dispatch: env: USERNAME: ${{ github.actor }} From f59de39a0caf19955cc7b8c6965eb067aca7f90b Mon Sep 17 00:00:00 2001 From: WizardlyBump17 Date: Sat, 6 Dec 2025 16:36:29 -0300 Subject: [PATCH 200/363] Revert "forgot the -2" This reverts commit 3672d77ea0cf8b48856afabdd68a90fecb9a9d21. --- .github/workflows/publish.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/publish.yml b/.github/workflows/publish.yml index 65aff338..15cede0a 100644 --- a/.github/workflows/publish.yml +++ b/.github/workflows/publish.yml @@ -6,7 +6,7 @@ on: - published push: branches: - - new-command-system-1.20.6-2 + - new-command-system-1.20.6 env: USERNAME: ${{ github.actor }} From 551e136c843bd6365913dca47ced2c0c57241409 Mon Sep 17 00:00:00 2001 From: WizardlyBump17 Date: Sat, 6 Dec 2025 16:36:30 -0300 Subject: [PATCH 201/363] Revert "I think snapshots will be better now" This reverts commit 014d4d8323f1e406395f0202867b29a3d59c5abf. --- .github/workflows/build.yml | 4 +++- .github/workflows/publish.yml | 4 +++- build.gradle | 2 +- 3 files changed, 7 insertions(+), 3 deletions(-) diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml index 85681fff..aae6a066 100644 --- a/.github/workflows/build.yml +++ b/.github/workflows/build.yml @@ -11,7 +11,7 @@ on: env: USERNAME: ${{ github.actor }} TOKEN: ${{ secrets.GITHUB_TOKEN }} - WLIB_RELEASE: ${{ github.event_name == 'release' }} + WLIB_SNAPSHOT: ${{ github.event_name != 'release' }} jobs: build: @@ -21,6 +21,8 @@ jobs: steps: - name: Get current date run: echo "WLIB_BUILD_DATE=$(date +'%Y-%m-%d_%H-%M-%S')" >> "$GITHUB_ENV" + - name: Get snapshot number + run: echo "WLIB_SNAPSHOT_NUMBER=$((${{ github.run_number }}+${{ github.run_attempt }}))" >> $GITHUB_ENV - uses: actions/checkout@v4 - name: Set up JDK 21 uses: actions/setup-java@v4 diff --git a/.github/workflows/publish.yml b/.github/workflows/publish.yml index 15cede0a..eb18b0c8 100644 --- a/.github/workflows/publish.yml +++ b/.github/workflows/publish.yml @@ -11,7 +11,7 @@ on: env: USERNAME: ${{ github.actor }} TOKEN: ${{ secrets.GITHUB_TOKEN }} - WLIB_RELEASE: ${{ github.event_name == 'release' }} + WLIB_SNAPSHOT: ${{ github.event_name != 'release' }} jobs: build: @@ -22,6 +22,8 @@ jobs: steps: - name: Get current date run: echo "WLIB_BUILD_DATE=$(date +'%Y-%m-%d_%H-%M-%S')" >> "$GITHUB_ENV" + - name: Get snapshot number + run: echo "WLIB_SNAPSHOT_NUMBER=$((${{ github.run_number }}+${{ github.run_attempt }}))" >> $GITHUB_ENV - uses: actions/checkout@v4 - name: Set up JDK 21 uses: actions/setup-java@v4 diff --git a/build.gradle b/build.gradle index fb3a2543..fa2419ba 100644 --- a/build.gradle +++ b/build.gradle @@ -9,7 +9,7 @@ subprojects { apply plugin: 'maven-publish' group = 'com.wizardlybump17.wlib' - version = "1.6.8-ncs-2-1.20.6+" + ("true".equalsIgnoreCase(System.getenv("WLIB_RELEASE")) ? "" : "-SNAPSHOT") + version = "1.6.8-ncs-1.20.6+" + ("true".equalsIgnoreCase(System.getenv("WLIB_SNAPSHOT")) ? "-SNAPSHOT." + System.getenv("WLIB_SNAPSHOT_NUMBER") : "") repositories { mavenLocal() From 7f3a55dc1d6ea0a41c0b2c281c522834338883d4 Mon Sep 17 00:00:00 2001 From: WizardlyBump17 Date: Sat, 6 Dec 2025 16:38:39 -0300 Subject: [PATCH 202/363] fuck --- .github/workflows/publish.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/publish.yml b/.github/workflows/publish.yml index eb18b0c8..a3653164 100644 --- a/.github/workflows/publish.yml +++ b/.github/workflows/publish.yml @@ -6,7 +6,7 @@ on: - published push: branches: - - new-command-system-1.20.6 + - new-command-system-1.20.6-2 env: USERNAME: ${{ github.actor }} From be582d34dd6d4da50b79abffed7ebe2a5a564f02 Mon Sep 17 00:00:00 2001 From: WizardlyBump17 Date: Sat, 6 Dec 2025 17:52:10 -0300 Subject: [PATCH 203/363] added support for OfflinePlayer in the command system --- .../java/com/wizardlybump17/wlib/WLib.java | 2 + ...OfflinePlayerMethodCommandNodeFactory.java | 37 +++++ .../input/AllowedOfflinePlayerInputs.java | 136 ++++++++++++++++++ .../node/OfflinePlayerCommandNode.java | 83 +++++++++++ 4 files changed, 258 insertions(+) create mode 100644 core/src/main/java/com/wizardlybump17/wlib/command/extractor/method/factory/OfflinePlayerMethodCommandNodeFactory.java create mode 100644 core/src/main/java/com/wizardlybump17/wlib/command/input/AllowedOfflinePlayerInputs.java create mode 100644 core/src/main/java/com/wizardlybump17/wlib/command/node/OfflinePlayerCommandNode.java diff --git a/core/src/main/java/com/wizardlybump17/wlib/WLib.java b/core/src/main/java/com/wizardlybump17/wlib/WLib.java index 0115e175..e11934b7 100644 --- a/core/src/main/java/com/wizardlybump17/wlib/WLib.java +++ b/core/src/main/java/com/wizardlybump17/wlib/WLib.java @@ -6,6 +6,7 @@ import com.wizardlybump17.wlib.adapter.player.PlayerAdapter; import com.wizardlybump17.wlib.command.WLibCommandExecutor; import com.wizardlybump17.wlib.command.extractor.method.MethodCommandExtractor; +import com.wizardlybump17.wlib.command.extractor.method.factory.OfflinePlayerMethodCommandNodeFactory; import com.wizardlybump17.wlib.command.listener.BukkitCommandManagerListener; import com.wizardlybump17.wlib.command.manager.CommandManager; import com.wizardlybump17.wlib.command.registry.MethodCommandNodeFactoryRegistry; @@ -66,6 +67,7 @@ private void initCommandSystem() { methodCommandExtractor = new MethodCommandExtractor(methodCommandNodeFactoryRegistry); methodCommandNodeFactoryRegistry.registerDefaults(); + methodCommandNodeFactoryRegistry.addFactory(new OfflinePlayerMethodCommandNodeFactory()); commandManager = new CommandManager(); diff --git a/core/src/main/java/com/wizardlybump17/wlib/command/extractor/method/factory/OfflinePlayerMethodCommandNodeFactory.java b/core/src/main/java/com/wizardlybump17/wlib/command/extractor/method/factory/OfflinePlayerMethodCommandNodeFactory.java new file mode 100644 index 00000000..f7ea63fe --- /dev/null +++ b/core/src/main/java/com/wizardlybump17/wlib/command/extractor/method/factory/OfflinePlayerMethodCommandNodeFactory.java @@ -0,0 +1,37 @@ +package com.wizardlybump17.wlib.command.extractor.method.factory; + +import com.wizardlybump17.wlib.command.annotation.Command; +import com.wizardlybump17.wlib.command.input.AllowedOfflinePlayerInputs; +import com.wizardlybump17.wlib.command.node.CommandNode; +import com.wizardlybump17.wlib.command.node.OfflinePlayerCommandNode; +import org.bukkit.OfflinePlayer; +import org.jetbrains.annotations.NotNull; +import org.jetbrains.annotations.Nullable; + +import java.lang.reflect.Method; +import java.lang.reflect.Parameter; +import java.util.List; + +public class OfflinePlayerMethodCommandNodeFactory extends MethodCommandNodeFactory { + + @Override + public @NotNull CommandNode create(@NotNull Object object, @NotNull Method method, @NotNull Command commandAnnotation, @NotNull Parameter parameter, @NotNull String name, @Nullable CommandNode root) { + return new OfflinePlayerCommandNode( + name, + root == null ? List.of() : List.of(root), + parameter.isAnnotationPresent(NotNull.class) ? AllowedOfflinePlayerInputs.anyNotNull() : AllowedOfflinePlayerInputs.anyNullable(), + null, + null + ); + } + + @Override + public @NotNull Class @NotNull [] getSupportedTypes() { + return new Class[] {OfflinePlayer.class}; + } + + @Override + public boolean isStrict() { + return false; + } +} diff --git a/core/src/main/java/com/wizardlybump17/wlib/command/input/AllowedOfflinePlayerInputs.java b/core/src/main/java/com/wizardlybump17/wlib/command/input/AllowedOfflinePlayerInputs.java new file mode 100644 index 00000000..51a5c4d9 --- /dev/null +++ b/core/src/main/java/com/wizardlybump17/wlib/command/input/AllowedOfflinePlayerInputs.java @@ -0,0 +1,136 @@ +package com.wizardlybump17.wlib.command.input; + +import org.bukkit.OfflinePlayer; +import org.jetbrains.annotations.NotNull; +import org.jetbrains.annotations.Nullable; + +import java.util.List; +import java.util.Objects; + +public interface AllowedOfflinePlayerInputs extends AllowedInputs { + + static @NotNull AllowedOfflinePlayerInputs.Value value(@NotNull OfflinePlayer value) { + return new AllowedOfflinePlayerInputs.Value(value); + } + + static @NotNull AllowedOfflinePlayerInputs.Values values(@NotNull List values) { + return new AllowedOfflinePlayerInputs.Values(List.copyOf(values)); + } + + static @NotNull AllowedOfflinePlayerInputs.Values values(@NotNull OfflinePlayer @NotNull ... values) { + return new AllowedOfflinePlayerInputs.Values(List.of(values)); + } + + static @NotNull AllowedOfflinePlayerInputs.Any anyNullable() { + return AllowedOfflinePlayerInputs.Any.NULLABLE; + } + + static @NotNull AllowedOfflinePlayerInputs.Any anyNotNull() { + return AllowedOfflinePlayerInputs.Any.NOT_NULL; + } + + final class Value implements AllowedOfflinePlayerInputs, SingleValueInput { + + private final @NotNull OfflinePlayer value; + + Value(@NotNull OfflinePlayer value) { + this.value = value; + } + + @Override + public @NotNull OfflinePlayer value() { + return value; + } + + @Override + public boolean equals(Object object) { + if (object == null || getClass() != object.getClass()) + return false; + Value value1 = (Value) object; + return Objects.equals(value, value1.value); + } + + @Override + public int hashCode() { + return Objects.hashCode(value); + } + + @Override + public String toString() { + return "AllowedOfflinePlayerInputs$Value{" + + "value=" + value + + '}'; + } + } + + final class Values implements AllowedOfflinePlayerInputs, AllowedListInputs { + + private final @NotNull List values; + + private Values(@NotNull List values) { + this.values = values; + } + + @Override + public @NotNull List allowedValues() { + return values; + } + + @Override + public boolean equals(Object object) { + if (object == null || getClass() != object.getClass()) + return false; + Values values1 = (Values) object; + return Objects.equals(values, values1.values); + } + + @Override + public int hashCode() { + return Objects.hashCode(values); + } + + @Override + public String toString() { + return "AllowedOfflinePlayerInputs$Values{" + + "values=" + values + + '}'; + } + } + + final class Any implements AllowedOfflinePlayerInputs { + + private static final @NotNull Any NULLABLE = new Any(true); + private static final @NotNull Any NOT_NULL = new Any(false); + + private final boolean nullable; + + private Any(boolean nullable) { + this.nullable = nullable; + } + + @Override + public boolean isAllowed(@Nullable OfflinePlayer input) { + return nullable || input != null; + } + + @Override + public boolean equals(Object object) { + if (object == null || getClass() != object.getClass()) + return false; + Any any = (Any) object; + return nullable == any.nullable; + } + + @Override + public int hashCode() { + return Objects.hashCode(nullable); + } + + @Override + public String toString() { + return "AllowedOfflinePlayerInputs$Any{" + + "nullable=" + nullable + + '}'; + } + } +} diff --git a/core/src/main/java/com/wizardlybump17/wlib/command/node/OfflinePlayerCommandNode.java b/core/src/main/java/com/wizardlybump17/wlib/command/node/OfflinePlayerCommandNode.java new file mode 100644 index 00000000..a8f0e533 --- /dev/null +++ b/core/src/main/java/com/wizardlybump17/wlib/command/node/OfflinePlayerCommandNode.java @@ -0,0 +1,83 @@ +package com.wizardlybump17.wlib.command.node; + +import com.wizardlybump17.wlib.command.exception.InputParsingException; +import com.wizardlybump17.wlib.command.executor.CommandNodeExecutor; +import com.wizardlybump17.wlib.command.input.AllowedOfflinePlayerInputs; +import org.bukkit.Bukkit; +import org.bukkit.OfflinePlayer; +import org.jetbrains.annotations.NotNull; +import org.jetbrains.annotations.Nullable; + +import java.util.List; +import java.util.UUID; + +public class OfflinePlayerCommandNode extends CommandNode { + + public OfflinePlayerCommandNode(@NotNull String name, @NotNull List> children, @NotNull AllowedOfflinePlayerInputs allowedInputs, @Nullable CommandNodeExecutor executor, @Nullable String permission) { + super(name, children, allowedInputs, executor, permission); + } + + public OfflinePlayerCommandNode(@NotNull String name, @NotNull AllowedOfflinePlayerInputs allowedInputs, @Nullable CommandNodeExecutor executor, @Nullable String permission) { + super(name, allowedInputs, executor, permission); + } + + public OfflinePlayerCommandNode(@NotNull String name, @NotNull List> children, @NotNull AllowedOfflinePlayerInputs allowedInputs, @Nullable String permission) { + super(name, children, allowedInputs, permission); + } + + public OfflinePlayerCommandNode(@NotNull String name, @NotNull AllowedOfflinePlayerInputs allowedInputs, @Nullable String permission) { + super(name, allowedInputs, permission); + } + + public OfflinePlayerCommandNode(@NotNull String name, @NotNull AllowedOfflinePlayerInputs allowedInputs, @Nullable CommandNodeExecutor executor) { + super(name, allowedInputs, executor); + } + + public OfflinePlayerCommandNode(@NotNull String name, @NotNull List> children, @NotNull AllowedOfflinePlayerInputs allowedInputs) { + super(name, children, allowedInputs); + } + + public OfflinePlayerCommandNode(@NotNull String name, @NotNull AllowedOfflinePlayerInputs allowedInputs) { + super(name, allowedInputs); + } + + @Override + public @Nullable OfflinePlayer parse(@Nullable String input) throws InputParsingException { + if (input == null) + throw new InputParsingException("The input cannot be null"); + + OfflinePlayer player = Bukkit.getOfflinePlayerIfCached(input); + if (player != null) + return player; + + if (input.length() == 36) { + try { + return Bukkit.getOfflinePlayer(UUID.fromString(input)); + } catch (IllegalArgumentException e) { + throw new InputParsingException("Could not parse as UUID to get an OfflinePlayer: " + input, e); + } + } + + return null; + } + + @Override + public @NotNull AllowedOfflinePlayerInputs getAllowedInputs() { + return (AllowedOfflinePlayerInputs) super.getAllowedInputs(); + } + + @Override + public @NotNull OfflinePlayerCommandNode withChildren(@NotNull List> children) { + return new OfflinePlayerCommandNode(getName(), children, getAllowedInputs(), getExecutor(), getPermission()); + } + + @Override + public @NotNull OfflinePlayerCommandNode withExecutor(@Nullable CommandNodeExecutor executor) { + return new OfflinePlayerCommandNode(getName(), getChildren(), getAllowedInputs(), executor, getPermission()); + } + + @Override + public @NotNull OfflinePlayerCommandNode withPermission(@Nullable String permission) { + return new OfflinePlayerCommandNode(getName(), getChildren(), getAllowedInputs(), getExecutor(), permission); + } +} From 6ba8c53bc6db488a081b7d02dbf74ae198051968 Mon Sep 17 00:00:00 2001 From: WizardlyBump17 Date: Sat, 6 Dec 2025 19:20:15 -0300 Subject: [PATCH 204/363] unregistering commands --- .../wlib/command/manager/CommandManager.java | 47 ++++- .../listener/CommandManagerListener.java | 2 + .../listener/CommandManagerListenerTests.java | 172 ++++++++++++++++++ .../wlib/test/util/AssertionUtil.java | 42 +++++ .../BukkitCommandManagerListener.java | 12 ++ 5 files changed, 271 insertions(+), 4 deletions(-) diff --git a/commands/src/main/java/com/wizardlybump17/wlib/command/manager/CommandManager.java b/commands/src/main/java/com/wizardlybump17/wlib/command/manager/CommandManager.java index 91712df0..31a86997 100644 --- a/commands/src/main/java/com/wizardlybump17/wlib/command/manager/CommandManager.java +++ b/commands/src/main/java/com/wizardlybump17/wlib/command/manager/CommandManager.java @@ -22,12 +22,18 @@ public class CommandManager { private final @NotNull Map commandsByName = new ConcurrentHashMap<>(); private final @NotNull Set listeners = ConcurrentHashMap.newKeySet(); private final @NotNull Map> commandsByHolder = new ConcurrentHashMap<>(); + private final @NotNull Map holdersByFullName = new ConcurrentHashMap<>(); + + protected void addCommand(@NotNull String identifier, @NotNull String name, @NotNull Command command, @Nullable Object holder) { + String fullName = identifier + SEPARATOR + name; - protected void addCommand(@NotNull String identifier, @NotNull String fullName, @NotNull String name, @NotNull Command command, @Nullable Object holder) { commandsByFullName.put(fullName, command); commandsByName.put(name, command); - if (holder != null) + + if (holder != null) { commandsByHolder.computeIfAbsent(holder, $ -> ConcurrentHashMap.newKeySet()).add(command); + holdersByFullName.put(fullName, holder); + } for (CommandManagerListener listener : listeners) listener.onRegister(identifier, command, holder, this); @@ -41,11 +47,11 @@ protected void addCommand(@NotNull String identifier, @NotNull String fullName, if (existingCommand != null) { Command newCommand = mergeCommand(existingCommand, command); - addCommand(identifier, fullCommandName, commandName, newCommand, holder); + addCommand(identifier, commandName, newCommand, holder); return newCommand; } - addCommand(identifier, fullCommandName, commandName, command, holder); + addCommand(identifier, commandName, command, holder); return command; } @@ -176,4 +182,37 @@ public void clearListeners() { public boolean isEmpty() { return commandsByFullName.isEmpty(); } + + public void unregister(@NotNull String identifier, @NotNull Command command) { + unregister(identifier, command.getName()); + } + + public void unregister(@NotNull String identifier, @NotNull String name) { + String fullName = identifier + SEPARATOR + name; + + Command command = commandsByFullName.remove(fullName); + if (command == null) + return; + + commandsByName.remove(name); + + Object holder = holdersByFullName.remove(fullName); + if (holder != null) { + Set commands = commandsByHolder.get(holder); + if (commands != null) + commands.remove(command); + } + + for (CommandManagerListener listener : listeners) + listener.onUnregister(identifier, command, holder, this); + } + + public void unregisterByHolder(@NotNull String identifier, @NotNull Object holder) { + Set commands = commandsByHolder.get(holder); + if (commands == null) + return; + + for (Command command : commands) + unregister(identifier, command); + } } diff --git a/commands/src/main/java/com/wizardlybump17/wlib/command/manager/listener/CommandManagerListener.java b/commands/src/main/java/com/wizardlybump17/wlib/command/manager/listener/CommandManagerListener.java index e8b2c13d..82de9cb0 100644 --- a/commands/src/main/java/com/wizardlybump17/wlib/command/manager/listener/CommandManagerListener.java +++ b/commands/src/main/java/com/wizardlybump17/wlib/command/manager/listener/CommandManagerListener.java @@ -10,4 +10,6 @@ public interface CommandManagerListener { void onRegister(@NotNull String identifier, @NotNull Command command, @Nullable Object holder, @NotNull CommandManager manager); void onClear(@NotNull CommandManager manager); + + void onUnregister(@NotNull String identifier, @NotNull Command command, @Nullable Object holder, @NotNull CommandManager manager); } diff --git a/commands/src/test/java/com/wizardlybump17/wlib/test/command/manager/listener/CommandManagerListenerTests.java b/commands/src/test/java/com/wizardlybump17/wlib/test/command/manager/listener/CommandManagerListenerTests.java index 1bd888cb..6c37129c 100644 --- a/commands/src/test/java/com/wizardlybump17/wlib/test/command/manager/listener/CommandManagerListenerTests.java +++ b/commands/src/test/java/com/wizardlybump17/wlib/test/command/manager/listener/CommandManagerListenerTests.java @@ -4,6 +4,7 @@ import com.wizardlybump17.wlib.command.manager.CommandManager; import com.wizardlybump17.wlib.command.manager.listener.CommandManagerListener; import com.wizardlybump17.wlib.command.node.LiteralCommandNode; +import com.wizardlybump17.wlib.test.util.AssertionUtil; import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.Nullable; import org.junit.jupiter.api.Assertions; @@ -30,6 +31,10 @@ public void onRegister(@NotNull String identifier, @NotNull Command command, @Nu @Override public void onClear(@NotNull CommandManager manager) { } + + @Override + public void onUnregister(@NotNull String identifier, @NotNull Command command, @Nullable Object holder, @NotNull CommandManager manager) { + } }); manager.registerCommand("test", new Command(new LiteralCommandNode("test"))); @@ -53,6 +58,10 @@ public void onRegister(@NotNull String identifier, @NotNull Command command, @Nu @Override public void onClear(@NotNull CommandManager manager) { } + + @Override + public void onUnregister(@NotNull String identifier, @NotNull Command command, @Nullable Object holder, @NotNull CommandManager manager) { + } }); manager.registerCommand("test", new Command(new LiteralCommandNode("test0"))); @@ -85,6 +94,10 @@ public void onClear(@NotNull CommandManager manager) { Assertions.assertTrue(manager.isEmpty()); called.set(true); } + + @Override + public void onUnregister(@NotNull String identifier, @NotNull Command command, @Nullable Object holder, @NotNull CommandManager manager) { + } }); manager.registerCommand("test", new Command(new LiteralCommandNode("test0"))); @@ -95,4 +108,163 @@ public void onClear(@NotNull CommandManager manager) { Assertions.assertTrue(called.get()); } + + @Test + void testBeingCalledUnregisterByIdentifierAndName() { + List seenCommands = new ArrayList<>(); + + CommandManager manager = new CommandManager(); + manager.addListener(new CommandManagerListener() { + @Override + public void onRegister(@NotNull String identifier, @NotNull Command command, @Nullable Object holder, @NotNull CommandManager manager) { + } + + @Override + public void onClear(@NotNull CommandManager manager) { + } + + @Override + public void onUnregister(@NotNull String identifier, @NotNull Command command, @Nullable Object holder, @NotNull CommandManager manager) { + seenCommands.add(identifier + CommandManager.SEPARATOR + command.getName()); + } + }); + + manager.registerCommand("test", new Command(new LiteralCommandNode("test0"))); + manager.registerCommand("test", new Command(new LiteralCommandNode("test1"))); + manager.registerCommand("test", new Command(new LiteralCommandNode("test2"))); + + manager.unregister("test", "test0"); + manager.unregister("test", "test1"); + manager.unregister("test", "test2"); + + Assertions.assertEquals( + List.of( + "test:test0", + "test:test1", + "test:test2" + ), + seenCommands + ); + } + + @Test + void testBeingCalledUnregisterByIdentifierAndHolder0() { + List seenCommands = new ArrayList<>(); + + CommandManager manager = new CommandManager(); + manager.addListener(new CommandManagerListener() { + @Override + public void onRegister(@NotNull String identifier, @NotNull Command command, @Nullable Object holder, @NotNull CommandManager manager) { + } + + @Override + public void onClear(@NotNull CommandManager manager) { + } + + @Override + public void onUnregister(@NotNull String identifier, @NotNull Command command, @Nullable Object holder, @NotNull CommandManager manager) { + seenCommands.add(identifier + CommandManager.SEPARATOR + command.getName()); + } + }); + + manager.registerCommand("test", new Command(new LiteralCommandNode("test0")), "test"); + manager.registerCommand("test", new Command(new LiteralCommandNode("test1")), "test"); + manager.registerCommand("test", new Command(new LiteralCommandNode("test2")), "test"); + manager.registerCommand("test1", new Command(new LiteralCommandNode("test10")), "test1"); + manager.registerCommand("test1", new Command(new LiteralCommandNode("test11")), "test1"); + manager.registerCommand("test1", new Command(new LiteralCommandNode("test12")), "test1"); + + manager.unregisterByHolder("test", "test"); + + AssertionUtil.assertContentEquals( + List.of( + "test:test0", + "test:test1", + "test:test2" + ), + seenCommands + ); + } + + @Test + void testBeingCalledUnregisterByIdentifierAndHolder1() { + List seenCommands = new ArrayList<>(); + + CommandManager manager = new CommandManager(); + manager.addListener(new CommandManagerListener() { + @Override + public void onRegister(@NotNull String identifier, @NotNull Command command, @Nullable Object holder, @NotNull CommandManager manager) { + } + + @Override + public void onClear(@NotNull CommandManager manager) { + } + + @Override + public void onUnregister(@NotNull String identifier, @NotNull Command command, @Nullable Object holder, @NotNull CommandManager manager) { + seenCommands.add(identifier + CommandManager.SEPARATOR + command.getName()); + } + }); + + manager.registerCommand("test", new Command(new LiteralCommandNode("test0")), "test"); + manager.registerCommand("test", new Command(new LiteralCommandNode("test1")), "test"); + manager.registerCommand("test", new Command(new LiteralCommandNode("test2")), "test"); + manager.registerCommand("test1", new Command(new LiteralCommandNode("test10")), "test1"); + manager.registerCommand("test1", new Command(new LiteralCommandNode("test11")), "test1"); + manager.registerCommand("test1", new Command(new LiteralCommandNode("test12")), "test1"); + + manager.unregisterByHolder("test1", "test1"); + + AssertionUtil.assertContentEquals( + List.of( + "test1:test10", + "test1:test11", + "test1:test12" + ), + seenCommands + ); + } + + @Test + void testBeingCalledUnregisterByIdentifierAndHolder2() { + List seenCommands = new ArrayList<>(); + + CommandManager manager = new CommandManager(); + manager.addListener(new CommandManagerListener() { + @Override + public void onRegister(@NotNull String identifier, @NotNull Command command, @Nullable Object holder, @NotNull CommandManager manager) { + } + + @Override + public void onClear(@NotNull CommandManager manager) { + } + + @Override + public void onUnregister(@NotNull String identifier, @NotNull Command command, @Nullable Object holder, @NotNull CommandManager manager) { + seenCommands.add(identifier + CommandManager.SEPARATOR + command.getName()); + } + }); + + manager.registerCommand("test", new Command(new LiteralCommandNode("test0")), "test"); + manager.registerCommand("test", new Command(new LiteralCommandNode("test1")), "test"); + manager.registerCommand("test", new Command(new LiteralCommandNode("test2")), "test"); + manager.registerCommand("test1", new Command(new LiteralCommandNode("test10")), "test1"); + manager.registerCommand("test1", new Command(new LiteralCommandNode("test11")), "test1"); + manager.registerCommand("test1", new Command(new LiteralCommandNode("test12")), "test1"); + + manager.unregisterByHolder("test", "test"); + manager.unregisterByHolder("test1", "test1"); + + AssertionUtil.assertContentEquals( + List.of( + "test:test0", + "test:test1", + "test:test2", + "test1:test10", + "test1:test11", + "test1:test12" + ), + seenCommands + ); + } } diff --git a/commands/src/test/java/com/wizardlybump17/wlib/test/util/AssertionUtil.java b/commands/src/test/java/com/wizardlybump17/wlib/test/util/AssertionUtil.java index 275ddec1..a1823079 100644 --- a/commands/src/test/java/com/wizardlybump17/wlib/test/util/AssertionUtil.java +++ b/commands/src/test/java/com/wizardlybump17/wlib/test/util/AssertionUtil.java @@ -1,9 +1,11 @@ package com.wizardlybump17.wlib.test.util; import com.wizardlybump17.wlib.command.Command; +import com.wizardlybump17.wlib.util.CollectionUtil; import org.jetbrains.annotations.Nullable; import org.junit.jupiter.api.AssertionFailureBuilder; +import java.util.Collection; import java.util.List; public final class AssertionUtil { @@ -55,4 +57,44 @@ public static void assertCommandsEquals(@Nullable List expected, @Nulla } } } + + public static void assertContentEquals(@Nullable Collection expected, @Nullable Collection actual) { + if (expected == null) { + if (actual != null) { + AssertionFailureBuilder.assertionFailure() + .expected(null) + .actual(actual) + .buildAndThrow(); + } + return; + } + + if (expected != null) { + if (actual == null) { + AssertionFailureBuilder.assertionFailure() + .expected(expected) + .actual(null) + .buildAndThrow(); + return; + } + } + + if (expected.size() != actual.size()) { + AssertionFailureBuilder.assertionFailure() + .expected(expected) + .actual(actual) + .message("Expected and actual collections have different sizes") + .buildAndThrow(); + return; + } + + if (!CollectionUtil.contentEquals(expected, actual)) { + AssertionFailureBuilder.assertionFailure() + .expected(expected) + .actual(actual) + .message("Expected and actual collections do not contain the same elements") + .buildAndThrow(); + return; + } + } } diff --git a/core/src/main/java/com/wizardlybump17/wlib/command/listener/BukkitCommandManagerListener.java b/core/src/main/java/com/wizardlybump17/wlib/command/listener/BukkitCommandManagerListener.java index 1a946138..3d67865e 100644 --- a/core/src/main/java/com/wizardlybump17/wlib/command/listener/BukkitCommandManagerListener.java +++ b/core/src/main/java/com/wizardlybump17/wlib/command/listener/BukkitCommandManagerListener.java @@ -37,6 +37,18 @@ public void onRegister(@NotNull String identifier, @NotNull Command command, @Nu public void onClear(@NotNull CommandManager manager) { } + @Override + public void onUnregister(@NotNull String identifier, @NotNull Command command, @Nullable Object holder, @NotNull CommandManager manager) { + if (!(holder instanceof JavaPlugin plugin)) + return; + + PluginCommand pluginCommand = plugin.getCommand(command.getName()); + if (pluginCommand == null) + return; + + pluginCommand.setExecutor(null); + } + public @NotNull WLibCommandExecutor getCommandExecutor() { return commandExecutor; } From 648ce14c8e1c473a42fce72b16f50343be27979e Mon Sep 17 00:00:00 2001 From: WizardlyBump17 Date: Sat, 6 Dec 2025 19:38:43 -0300 Subject: [PATCH 205/363] renamed --- .../MethodCommandExtractorStructureTests.java | 4 ++-- .../method/MethodCommandNodeFactoryTests.java | 20 +++++++++---------- .../wlib/test/util/AssertionUtil.java | 2 +- 3 files changed, 13 insertions(+), 13 deletions(-) diff --git a/commands/src/test/java/com/wizardlybump17/wlib/test/command/extractor/method/MethodCommandExtractorStructureTests.java b/commands/src/test/java/com/wizardlybump17/wlib/test/command/extractor/method/MethodCommandExtractorStructureTests.java index a7e6fc39..3593652a 100644 --- a/commands/src/test/java/com/wizardlybump17/wlib/test/command/extractor/method/MethodCommandExtractorStructureTests.java +++ b/commands/src/test/java/com/wizardlybump17/wlib/test/command/extractor/method/MethodCommandExtractorStructureTests.java @@ -73,7 +73,7 @@ void test0() { expected.sort(null); actual.sort(null); - AssertionUtil.assertCommandsEquals(expected, actual); + AssertionUtil.assertCommandsEqualsIgnoreExecutor(expected, actual); } public static class Test0 { @@ -141,7 +141,7 @@ void test1() { expected.sort(null); actual.sort(null); - AssertionUtil.assertCommandsEquals(expected, actual); + AssertionUtil.assertCommandsEqualsIgnoreExecutor(expected, actual); } public static class Test1 { diff --git a/commands/src/test/java/com/wizardlybump17/wlib/test/command/extractor/method/MethodCommandNodeFactoryTests.java b/commands/src/test/java/com/wizardlybump17/wlib/test/command/extractor/method/MethodCommandNodeFactoryTests.java index d18678d2..7dc1c325 100644 --- a/commands/src/test/java/com/wizardlybump17/wlib/test/command/extractor/method/MethodCommandNodeFactoryTests.java +++ b/commands/src/test/java/com/wizardlybump17/wlib/test/command/extractor/method/MethodCommandNodeFactoryTests.java @@ -89,7 +89,7 @@ void testByte() { expected.sort(null); actual.sort(null); - AssertionUtil.assertCommandsEquals(expected, actual); + AssertionUtil.assertCommandsEqualsIgnoreExecutor(expected, actual); } public static final class TestByte { @@ -149,7 +149,7 @@ void testShort() { expected.sort(null); actual.sort(null); - AssertionUtil.assertCommandsEquals(expected, actual); + AssertionUtil.assertCommandsEqualsIgnoreExecutor(expected, actual); } public static final class TestShort { @@ -209,7 +209,7 @@ void testInt() { expected.sort(null); actual.sort(null); - AssertionUtil.assertCommandsEquals(expected, actual); + AssertionUtil.assertCommandsEqualsIgnoreExecutor(expected, actual); } public static final class TestInt { @@ -269,7 +269,7 @@ void testLong() { expected.sort(null); actual.sort(null); - AssertionUtil.assertCommandsEquals(expected, actual); + AssertionUtil.assertCommandsEqualsIgnoreExecutor(expected, actual); } public static final class TestLong { @@ -329,7 +329,7 @@ void testFloat() { expected.sort(null); actual.sort(null); - AssertionUtil.assertCommandsEquals(expected, actual); + AssertionUtil.assertCommandsEqualsIgnoreExecutor(expected, actual); } public static final class TestFloat { @@ -389,7 +389,7 @@ void testDouble() { expected.sort(null); actual.sort(null); - AssertionUtil.assertCommandsEquals(expected, actual); + AssertionUtil.assertCommandsEqualsIgnoreExecutor(expected, actual); } public static final class TestDouble { @@ -449,7 +449,7 @@ void testChar() { expected.sort(null); actual.sort(null); - AssertionUtil.assertCommandsEquals(expected, actual); + AssertionUtil.assertCommandsEqualsIgnoreExecutor(expected, actual); } public static final class TestChar { @@ -509,7 +509,7 @@ void testString() { expected.sort(null); actual.sort(null); - AssertionUtil.assertCommandsEquals(expected, actual); + AssertionUtil.assertCommandsEqualsIgnoreExecutor(expected, actual); } public static final class TestString { @@ -569,7 +569,7 @@ void testUUID() { expected.sort(null); actual.sort(null); - AssertionUtil.assertCommandsEquals(expected, actual); + AssertionUtil.assertCommandsEqualsIgnoreExecutor(expected, actual); } public static final class TestUUID { @@ -784,7 +784,7 @@ void testMix() { expected.sort(null); actual.sort(null); - AssertionUtil.assertCommandsEquals(expected, actual); + AssertionUtil.assertCommandsEqualsIgnoreExecutor(expected, actual); } public static final class TestMix { diff --git a/commands/src/test/java/com/wizardlybump17/wlib/test/util/AssertionUtil.java b/commands/src/test/java/com/wizardlybump17/wlib/test/util/AssertionUtil.java index a1823079..7f332bf8 100644 --- a/commands/src/test/java/com/wizardlybump17/wlib/test/util/AssertionUtil.java +++ b/commands/src/test/java/com/wizardlybump17/wlib/test/util/AssertionUtil.java @@ -13,7 +13,7 @@ public final class AssertionUtil { private AssertionUtil() { } - public static void assertCommandsEquals(@Nullable List expected, @Nullable List actual) { + public static void assertCommandsEqualsIgnoreExecutor(@Nullable List expected, @Nullable List actual) { if (expected == null) { if (actual != null) { AssertionFailureBuilder.assertionFailure() From 3e778265fe0247c72d509ca784210e0619446905 Mon Sep 17 00:00:00 2001 From: WizardlyBump17 Date: Sat, 6 Dec 2025 21:26:38 -0300 Subject: [PATCH 206/363] testing the AssertionUtil --- .../wlib/test/util/AssertionUtilTests.java | 282 ++++++++++++++++++ 1 file changed, 282 insertions(+) create mode 100644 commands/src/test/java/com/wizardlybump17/wlib/test/util/AssertionUtilTests.java diff --git a/commands/src/test/java/com/wizardlybump17/wlib/test/util/AssertionUtilTests.java b/commands/src/test/java/com/wizardlybump17/wlib/test/util/AssertionUtilTests.java new file mode 100644 index 00000000..eb1548ea --- /dev/null +++ b/commands/src/test/java/com/wizardlybump17/wlib/test/util/AssertionUtilTests.java @@ -0,0 +1,282 @@ +package com.wizardlybump17.wlib.test.util; + +import com.wizardlybump17.wlib.command.Command; +import com.wizardlybump17.wlib.command.node.LiteralCommandNode; +import com.wizardlybump17.wlib.command.result.CommandResult; +import org.junit.jupiter.api.Assertions; +import org.junit.jupiter.api.Test; +import org.opentest4j.AssertionFailedError; + +import java.util.List; +import java.util.Set; + +class AssertionUtilTests { + + @Test + void testCommandsEqualsIgnoreExecutorTrue() { + List left = List.of( + new Command( + new LiteralCommandNode( + "test0", + List.of(), + context -> CommandResult.successful(context, "Hi"), + "test0" + ) + ), + new Command( + new LiteralCommandNode( + "test1", + List.of( + new LiteralCommandNode( + "test1_0", + List.of( + new LiteralCommandNode( + "test1_0_0", + List.of(), + context -> CommandResult.successful(context, "Hello world"), + null + ) + ), + context -> CommandResult.successful(context, "Hello there"), + null + ), + new LiteralCommandNode( + "test1_1", + List.of(), + context -> CommandResult.successful(context, "I ran out of ideas"), + null + ) + ), + context -> CommandResult.successful(context, "Hello"), + "test1" + ) + ) + ); + List right = List.of( + new Command( + new LiteralCommandNode( + "test0", + List.of(), + null, + "test0" + ) + ), + new Command( + new LiteralCommandNode( + "test1", + List.of( + new LiteralCommandNode( + "test1_0", + List.of( + new LiteralCommandNode( + "test1_0_0", + List.of(), + context -> CommandResult.successful(context, "Welcome"), + null + ) + ), + CommandResult::genericError, + null + ), + new LiteralCommandNode( + "test1_1", + List.of(), + CommandResult::noPermission, + null + ) + ), + context -> CommandResult.successful(context, "Hello"), + "test1" + ) + ) + ); + + Assertions.assertDoesNotThrow(() -> AssertionUtil.assertCommandsEqualsIgnoreExecutor(left, right)); + } + + @Test + void testCommandsEqualsIgnoreExecutorFalse() { + List left = List.of( + new Command( + new LiteralCommandNode( + "test0", + List.of(), + context -> CommandResult.successful(context, "Hi"), + "test0" + ) + ), + new Command( + new LiteralCommandNode( + "test1", + List.of( + new LiteralCommandNode( + "test1_0", + List.of( + new LiteralCommandNode( + "test1_0_0", + List.of(), + context -> CommandResult.successful(context, "Hello world"), + null + ) + ), + context -> CommandResult.successful(context, "Hello there"), + null + ), + new LiteralCommandNode( + "test1_1", + List.of(), + context -> CommandResult.successful(context, "I ran out of ideas"), + null + ) + ), + context -> CommandResult.successful(context, "Hello"), + "test1" + ) + ) + ); + List right = List.of( + new Command( + new LiteralCommandNode( + "test1", + List.of(), + null, + "test0" + ) + ), + new Command( + new LiteralCommandNode( + "test1", + List.of( + new LiteralCommandNode( + "test1_0", + List.of( + new LiteralCommandNode( + "test1_0_0", + List.of(), + context -> CommandResult.successful(context, "Welcome"), + null + ) + ), + CommandResult::genericError, + null + ), + new LiteralCommandNode( + "test1_3", + List.of(), + CommandResult::noPermission, + null + ) + ), + context -> CommandResult.successful(context, "Hello"), + "test1" + ) + ) + ); + + Assertions.assertThrows(AssertionFailedError.class, () -> AssertionUtil.assertCommandsEqualsIgnoreExecutor(left, right)); + } + + @Test + void testContentEqualsTrueLists() { + List right = List.of( + "hi", + "welcome", + "hello", + "nice to see you" + ); + List left = List.of( + "welcome", + "hi", + "nice to see you", + "hello" + ); + + Assertions.assertDoesNotThrow(() -> AssertionUtil.assertContentEquals(right, left)); + } + + @Test + void testContentEqualsTrueListAndSet() { + List right = List.of( + "hi", + "welcome", + "hello", + "nice to see you" + ); + Set left = Set.of( + "welcome", + "hi", + "nice to see you", + "hello" + ); + + Assertions.assertDoesNotThrow(() -> AssertionUtil.assertContentEquals(right, left)); + } + + @Test + void testContentEqualsFalseExtra() { + List right = List.of( + "hi", + "welcome", + "hello", + "nice to see you", + "nice to see you" + ); + List left = List.of( + "welcome", + "hi", + "nice to see you", + "hello" + ); + + Assertions.assertThrows(AssertionFailedError.class, () -> AssertionUtil.assertContentEquals(right, left)); + } + + @Test + void testContentEqualsFalseMissing() { + List right = List.of( + "hi", + "welcome", + "hello" + ); + List left = List.of( + "welcome", + "hi", + "nice to see you", + "hello" + ); + + Assertions.assertThrows(AssertionFailedError.class, () -> AssertionUtil.assertContentEquals(right, left)); + } + + @Test + void testContentEqualsFalseDifferent0() { + List right = List.of( + "test0", + "test1" + ); + List left = List.of( + "welcome", + "hi", + "nice to see you", + "hello" + ); + + Assertions.assertThrows(AssertionFailedError.class, () -> AssertionUtil.assertContentEquals(right, left)); + } + + @Test + void testContentEqualsFalseDifferent1() { + List right = List.of( + "test0", + "test1" + ); + Set left = Set.of( + "welcome", + "hi", + "nice to see you", + "hello" + ); + + Assertions.assertThrows(AssertionFailedError.class, () -> AssertionUtil.assertContentEquals(right, left)); + } +} From 2939bdb25152f1edaf13d0f39c5fe3c85ce8b1b9 Mon Sep 17 00:00:00 2001 From: WizardlyBump17 Date: Sat, 6 Dec 2025 21:39:40 -0300 Subject: [PATCH 207/363] log the error --- .../main/java/com/wizardlybump17/wlib/WLib.java | 2 +- .../wlib/command/WLibCommandExecutor.java | 15 +++++++++++++-- 2 files changed, 14 insertions(+), 3 deletions(-) diff --git a/core/src/main/java/com/wizardlybump17/wlib/WLib.java b/core/src/main/java/com/wizardlybump17/wlib/WLib.java index e11934b7..fbb3fda1 100644 --- a/core/src/main/java/com/wizardlybump17/wlib/WLib.java +++ b/core/src/main/java/com/wizardlybump17/wlib/WLib.java @@ -71,7 +71,7 @@ private void initCommandSystem() { commandManager = new CommandManager(); - commandExecutor = new WLibCommandExecutor(commandManager); + commandExecutor = new WLibCommandExecutor(commandManager, getLogger()); commandManagerListener = new BukkitCommandManagerListener(commandExecutor); commandManager.addListener(commandManagerListener); diff --git a/core/src/main/java/com/wizardlybump17/wlib/command/WLibCommandExecutor.java b/core/src/main/java/com/wizardlybump17/wlib/command/WLibCommandExecutor.java index 285ddaa4..55b6bd8f 100644 --- a/core/src/main/java/com/wizardlybump17/wlib/command/WLibCommandExecutor.java +++ b/core/src/main/java/com/wizardlybump17/wlib/command/WLibCommandExecutor.java @@ -15,19 +15,27 @@ import java.util.ArrayList; import java.util.Collections; import java.util.List; +import java.util.logging.Level; +import java.util.logging.Logger; public class WLibCommandExecutor implements CommandExecutor, TabCompleter { private final @NotNull CommandManager commandManager; + private final @NotNull Logger logger; - public WLibCommandExecutor(@NotNull CommandManager commandManager) { + public WLibCommandExecutor(@NotNull CommandManager commandManager, @NotNull Logger logger) { this.commandManager = commandManager; + this.logger = logger; } public @NotNull CommandManager getCommandManager() { return commandManager; } + public @NotNull Logger getLogger() { + return logger; + } + @Override public boolean onCommand(@NotNull CommandSender sender, @NotNull Command command, @NotNull String label, @NotNull String[] args) { com.wizardlybump17.wlib.command.sender.CommandSender wlibSender = new BukkitCommandSender(sender); @@ -39,7 +47,10 @@ public boolean onCommand(@NotNull CommandSender sender, @NotNull Command command CommandResult result = commandManager.execute(wlibSender, wlibArgs); switch (result) { case SuccessResult successResult -> {} - case ExceptionResult exceptionResult -> sender.sendMessage("§cAn internal error occurred while executing this command."); + case ExceptionResult exceptionResult -> { + sender.sendMessage("§cAn internal error occurred while executing this command."); + logger.log(Level.SEVERE, "Error while " + sender + " tried to execute " + wlibArgs, exceptionResult.exception()); + } case OutOfRangeInputResult outOfRangeInputResult -> sender.sendMessage("§cInvalid input at index " + outOfRangeInputResult.lastInputIndex() + "."); case ExtraArgumentsResult extraArgumentsResult -> sender.sendMessage("§cExtra arguments provided at index " + extraArgumentsResult.lastInputIndex() + "."); case InsufficientArgumentsResult insufficientArgumentsResult -> sender.sendMessage("§cInsufficient arguments provided."); From 841fe867282606769e74586269d1dc1a3758a587 Mon Sep 17 00:00:00 2001 From: WizardlyBump17 Date: Sat, 6 Dec 2025 23:42:49 -0300 Subject: [PATCH 208/363] not allowing the creation of duplicate node names --- .../wizardlybump17/wlib/command/Command.java | 23 ++++++++-- .../wlib/test/command/CommandTests.java | 42 +++++++++++++++++-- 2 files changed, 57 insertions(+), 8 deletions(-) diff --git a/commands/src/main/java/com/wizardlybump17/wlib/command/Command.java b/commands/src/main/java/com/wizardlybump17/wlib/command/Command.java index c700f265..1bb8034b 100644 --- a/commands/src/main/java/com/wizardlybump17/wlib/command/Command.java +++ b/commands/src/main/java/com/wizardlybump17/wlib/command/Command.java @@ -12,19 +12,34 @@ import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.Nullable; -import java.util.ArrayList; -import java.util.Collection; -import java.util.List; -import java.util.Objects; +import java.util.*; public class Command implements Comparable { private final @NotNull LiteralCommandNode root; public Command(@NotNull LiteralCommandNode root) { + if (hasDuplicateNodeNames(root)) + throw new IllegalArgumentException("The command tree has duplicate node names"); this.root = root; } + public static boolean hasDuplicateNodeNames(@NotNull CommandNode root) { + return hasDuplicateNodeNames0(root, new HashSet<>()); + } + + private static boolean hasDuplicateNodeNames0(@NotNull CommandNode current, @NotNull Set seen) { + if (seen.contains(current.getName())) + return true; + + seen.add(current.getName()); + for (CommandNode child : current.getChildren()) + if (hasDuplicateNodeNames0(child, seen)) + return true; + + return false; + } + public @NotNull LiteralCommandNode getRoot() { return root; } diff --git a/commands/src/test/java/com/wizardlybump17/wlib/test/command/CommandTests.java b/commands/src/test/java/com/wizardlybump17/wlib/test/command/CommandTests.java index 4d17f82f..3cedfab1 100644 --- a/commands/src/test/java/com/wizardlybump17/wlib/test/command/CommandTests.java +++ b/commands/src/test/java/com/wizardlybump17/wlib/test/command/CommandTests.java @@ -78,7 +78,7 @@ void test0() { @Test @DisplayName("Multiple children 1 (hello, hi, world): success") void test1() { - LiteralCommandNode hiWorldNode = new LiteralCommandNode("world", context -> CommandResult.successful(context, "hello hi world")); + LiteralCommandNode hiWorldNode = new LiteralCommandNode("world0", context -> CommandResult.successful(context, "hello hi world")); Command command = new Command(new LiteralCommandNode( "hello", List.of( @@ -88,7 +88,7 @@ void test1() { )); CommandResult expected = CommandResult.successful(2, hiWorldNode, "hello hi world"); - CommandResult actual = command.execute(CHAD_SENDER, List.of("hello", "hi", "world")); + CommandResult actual = command.execute(CHAD_SENDER, List.of("hello", "hi", "world0")); Assertions.assertEquals(expected, actual); } @@ -122,7 +122,7 @@ void testExtraArguments1() { @Test void testExtraArguments2() { - LiteralCommandNode hiWorldNode = new LiteralCommandNode("world", context -> CommandResult.successful(context, "hello hi world")); + LiteralCommandNode hiWorldNode = new LiteralCommandNode("world0", context -> CommandResult.successful(context, "hello hi world")); Command command = new Command(new LiteralCommandNode( "hello", List.of( @@ -132,7 +132,7 @@ void testExtraArguments2() { )); ExtraArgumentsResult expected = CommandResult.extraArguments(3, hiWorldNode); - CommandResult actual = command.execute(CHAD_SENDER, List.of("hello", "hi", "world", "extra")); + CommandResult actual = command.execute(CHAD_SENDER, List.of("hello", "hi", "world0", "extra")); Assertions.assertEquals(expected, actual); } @@ -210,4 +210,38 @@ void testCommandNodeExecutorNotFound() { Assertions.assertEquals(expected, actual); } + + /** + *

+ * Because we used a Map to represent the arguments and the keys were the node names, + * this caused the arguments to be overwritten if the node names were the same. + *

+ *

+ * This test will make sure that we wont allow nodes to have the same name. + *

+ */ + @Test + void testCommandWithSameNodeName() { + Assertions.assertThrows( + IllegalArgumentException.class, + () -> new Command( + new LiteralCommandNode( + "test", + List.of( + new LiteralCommandNode( + "child0", + List.of( + new IntegerCommandNode( + "test", + List.of(), + AllowedIntegerInputs.unlimited(), + context -> CommandResult.successful(context, context.arguments().getArgumentData("test").orElse(null)) + ) + ) + ) + ) + ) + ) + ); + } } From 1cb20c3c010e3f6d342a90b3d9b091c3a4564941 Mon Sep 17 00:00:00 2001 From: WizardlyBump17 Date: Sun, 7 Dec 2025 23:49:33 -0300 Subject: [PATCH 209/363] merging the executor and permission too --- .../wizardlybump17/wlib/command/node/CommandNode.java | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/commands/src/main/java/com/wizardlybump17/wlib/command/node/CommandNode.java b/commands/src/main/java/com/wizardlybump17/wlib/command/node/CommandNode.java index f13c05df..dbe89dbf 100644 --- a/commands/src/main/java/com/wizardlybump17/wlib/command/node/CommandNode.java +++ b/commands/src/main/java/com/wizardlybump17/wlib/command/node/CommandNode.java @@ -191,7 +191,14 @@ public int hashCode() { newChildrenLeft.addAll(newChildrenRight); - return withChildren(newChildrenLeft); + CommandNode newNode = withChildren(newChildrenLeft); + + if (executor == null && right.getExecutor() != null) + newNode = newNode.withExecutor(right.getExecutor()); + if (permission == null && right.getPermission() != null) + newNode = newNode.withPermission(right.getPermission()); + + return newNode; } private static @Nullable CommandNodeExecutor getNewExecutor(@NotNull CommandNode left, @NotNull CommandNode right) { From 2e83a29568c5e2f4b5de4f0b6fc0b013aaa780fb Mon Sep 17 00:00:00 2001 From: WizardlyBump17 Date: Sun, 7 Dec 2025 23:51:38 -0300 Subject: [PATCH 210/363] getting the total nodes --- .../main/java/com/wizardlybump17/wlib/command/Command.java | 4 ++++ .../com/wizardlybump17/wlib/command/node/CommandNode.java | 7 +++++++ 2 files changed, 11 insertions(+) diff --git a/commands/src/main/java/com/wizardlybump17/wlib/command/Command.java b/commands/src/main/java/com/wizardlybump17/wlib/command/Command.java index 1bb8034b..6afa7d13 100644 --- a/commands/src/main/java/com/wizardlybump17/wlib/command/Command.java +++ b/commands/src/main/java/com/wizardlybump17/wlib/command/Command.java @@ -240,4 +240,8 @@ public int compareTo(@NotNull Command other) { public @NotNull String getName() { return root.getName(); } + + public int getTotalNodes() { + return root.getTotalNodes(); + } } diff --git a/commands/src/main/java/com/wizardlybump17/wlib/command/node/CommandNode.java b/commands/src/main/java/com/wizardlybump17/wlib/command/node/CommandNode.java index dbe89dbf..83bba322 100644 --- a/commands/src/main/java/com/wizardlybump17/wlib/command/node/CommandNode.java +++ b/commands/src/main/java/com/wizardlybump17/wlib/command/node/CommandNode.java @@ -260,4 +260,11 @@ public boolean canExecute(@NotNull CommandSender sender) { return null; } + + public int getTotalNodes() { + int total = 1; + for (CommandNode child : children) + total += child.getTotalNodes(); + return total; + } } From 48338922b076db2abfba0721f5d1c4c17406a1eb Mon Sep 17 00:00:00 2001 From: WizardlyBump17 Date: Sun, 7 Dec 2025 23:51:59 -0300 Subject: [PATCH 211/363] comparing using a Comparator --- .../main/java/com/wizardlybump17/wlib/command/Command.java | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/commands/src/main/java/com/wizardlybump17/wlib/command/Command.java b/commands/src/main/java/com/wizardlybump17/wlib/command/Command.java index 6afa7d13..990b2a9c 100644 --- a/commands/src/main/java/com/wizardlybump17/wlib/command/Command.java +++ b/commands/src/main/java/com/wizardlybump17/wlib/command/Command.java @@ -16,6 +16,9 @@ public class Command implements Comparable { + public static final @NotNull Comparator COMPARATOR = Comparator + .comparing(Command::getFullCommand); + private final @NotNull LiteralCommandNode root; public Command(@NotNull LiteralCommandNode root) { @@ -224,9 +227,7 @@ public int hashCode() { @Override public int compareTo(@NotNull Command other) { - String fullCommand = getFullCommand(); - String otherFullCommand = other.getFullCommand(); - return fullCommand.compareTo(otherFullCommand); + return COMPARATOR.compare(this, other); } public @NotNull String getFullCommand() { From 2dff49031200ccd7d28fde11fa519400a183effd Mon Sep 17 00:00:00 2001 From: WizardlyBump17 Date: Sun, 7 Dec 2025 23:52:26 -0300 Subject: [PATCH 212/363] testing the merge --- .../wlib/test/command/CommandTests.java | 48 +++++++++++++++++++ 1 file changed, 48 insertions(+) diff --git a/commands/src/test/java/com/wizardlybump17/wlib/test/command/CommandTests.java b/commands/src/test/java/com/wizardlybump17/wlib/test/command/CommandTests.java index 3cedfab1..4adba4d3 100644 --- a/commands/src/test/java/com/wizardlybump17/wlib/test/command/CommandTests.java +++ b/commands/src/test/java/com/wizardlybump17/wlib/test/command/CommandTests.java @@ -2,7 +2,9 @@ import com.wizardlybump17.wlib.command.Command; import com.wizardlybump17.wlib.command.exception.InputParsingException; +import com.wizardlybump17.wlib.command.executor.CommandNodeExecutor; import com.wizardlybump17.wlib.command.input.primitive.number.AllowedIntegerInputs; +import com.wizardlybump17.wlib.command.node.CommandNode; import com.wizardlybump17.wlib.command.node.LiteralCommandNode; import com.wizardlybump17.wlib.command.node.primitive.number.IntegerCommandNode; import com.wizardlybump17.wlib.command.result.CommandResult; @@ -244,4 +246,50 @@ void testCommandWithSameNodeName() { ) ); } + + /** + *

+ * The CommandNode#merge(CommandNode) method wasnt merging the executor and permission. + * This test will ensure that we have the correct executor and permission after merging. + *

+ */ + @Test + void testMerge() { + CommandNodeExecutor test0Executor = context -> CommandResult.successful(context, "It works 0!"); + CommandNodeExecutor test1Executor = context -> CommandResult.successful(context, "It works 1!"); + + CommandNode expected = new LiteralCommandNode( + "test0", + List.of( + new LiteralCommandNode( + "test1", + List.of(), + test1Executor, + "permission1" + ) + ), + test0Executor, + "permission0" + ); + CommandNode actual = new LiteralCommandNode( + "test0", + List.of(), + null, + null + ).merge(new LiteralCommandNode( + "test0", + List.of( + new LiteralCommandNode( + "test1", + List.of(), + test1Executor, + "permission1" + ) + ), + test0Executor, + "permission0" + )); + + Assertions.assertEquals(expected, actual); + } } From 09aa9b50d4c3f6ff51b4bfbd558962e9d4a556e4 Mon Sep 17 00:00:00 2001 From: WizardlyBump17 Date: Sun, 7 Dec 2025 23:52:54 -0300 Subject: [PATCH 213/363] appending a suffix to arguments --- .../command/extractor/CommandExtractor.java | 6 +- .../method/MethodCommandExtractor.java | 21 ++++- .../MethodCommandExtractorStructureTests.java | 6 +- .../method/MethodCommandExtractorTests.java | 48 +++++----- .../method/MethodCommandNodeFactoryTests.java | 90 +++++++++---------- 5 files changed, 94 insertions(+), 77 deletions(-) diff --git a/commands/src/main/java/com/wizardlybump17/wlib/command/extractor/CommandExtractor.java b/commands/src/main/java/com/wizardlybump17/wlib/command/extractor/CommandExtractor.java index d6dc28e4..045e888d 100644 --- a/commands/src/main/java/com/wizardlybump17/wlib/command/extractor/CommandExtractor.java +++ b/commands/src/main/java/com/wizardlybump17/wlib/command/extractor/CommandExtractor.java @@ -15,6 +15,10 @@ public interface CommandExtractor { @NotNull List extract(@NotNull Object object) throws CommandExtractorException; static @NotNull MethodCommandExtractor method(@NotNull MethodCommandNodeFactoryRegistry factoryRegistry) { - return new MethodCommandExtractor(factoryRegistry); + return new MethodCommandExtractor(factoryRegistry, MethodCommandExtractor.DEFAULT_ARGUMENT_SUFFIX); + } + + static @NotNull MethodCommandExtractor method(@NotNull MethodCommandNodeFactoryRegistry factoryRegistry, @NotNull String argumentSuffix) { + return new MethodCommandExtractor(factoryRegistry, argumentSuffix); } } diff --git a/commands/src/main/java/com/wizardlybump17/wlib/command/extractor/method/MethodCommandExtractor.java b/commands/src/main/java/com/wizardlybump17/wlib/command/extractor/method/MethodCommandExtractor.java index ecd69d1b..a62c1b14 100644 --- a/commands/src/main/java/com/wizardlybump17/wlib/command/extractor/method/MethodCommandExtractor.java +++ b/commands/src/main/java/com/wizardlybump17/wlib/command/extractor/method/MethodCommandExtractor.java @@ -22,10 +22,18 @@ public class MethodCommandExtractor implements CommandExtractor { + public static final @NotNull String DEFAULT_ARGUMENT_SUFFIX = "-arg"; + private final @NotNull MethodCommandNodeFactoryRegistry factoryRegistry; + private final @NotNull String argumentSuffix; - public MethodCommandExtractor(@NotNull MethodCommandNodeFactoryRegistry factoryRegistry) { + public MethodCommandExtractor(@NotNull MethodCommandNodeFactoryRegistry factoryRegistry, @NotNull String argumentSuffix) { this.factoryRegistry = factoryRegistry; + this.argumentSuffix = argumentSuffix; + } + + public MethodCommandExtractor(@NotNull MethodCommandNodeFactoryRegistry factoryRegistry) { + this(factoryRegistry, DEFAULT_ARGUMENT_SUFFIX); } @Override @@ -43,7 +51,12 @@ public boolean isAccepted(@NotNull Object object) { Class clazz = object.getClass(); + boolean b = false; + for (Method method : clazz.getMethods()) { + if (method.getName().toLowerCase().contains("gree")) + b = true; + com.wizardlybump17.wlib.command.annotation.Command annotation = method.getAnnotation(com.wizardlybump17.wlib.command.annotation.Command.class); if (annotation == null) continue; @@ -60,7 +73,7 @@ public boolean isAccepted(@NotNull Object object) { String part = commandParts[i]; CommandNode oldRoot = root; - root = createNode(factoryRegistry, part, parameters, parameterIndex, root, annotation, object, method); + root = createNode(factoryRegistry, part, parameters, parameterIndex, root, annotation, object, method, argumentSuffix); if (!(root instanceof LiteralCommandNode)) parameterIndex--; @@ -77,7 +90,7 @@ public boolean isAccepted(@NotNull Object object) { return commands; } - private static @NotNull CommandNode createNode(@NotNull MethodCommandNodeFactoryRegistry factoryRegistry, @NotNull String part, @NotNull Parameter @NotNull [] parameters, int parameterIndex, @Nullable CommandNode root, @NotNull com.wizardlybump17.wlib.command.annotation.Command annotation, @NotNull Object object, @NotNull Method method) throws MethodCommandNodeFactoryNotFoundException { + private static @NotNull CommandNode createNode(@NotNull MethodCommandNodeFactoryRegistry factoryRegistry, @NotNull String part, @NotNull Parameter @NotNull [] parameters, int parameterIndex, @Nullable CommandNode root, @NotNull com.wizardlybump17.wlib.command.annotation.Command annotation, @NotNull Object object, @NotNull Method method, @NotNull String argumentSuffix) throws MethodCommandNodeFactoryNotFoundException { CommandNode newNode; boolean argument = part.charAt(0) == '<' && part.charAt(part.length() - 1) == '>'; @@ -95,7 +108,7 @@ public boolean isAccepted(@NotNull Object object) { if (factory == null) throw new MethodCommandNodeFactoryNotFoundException("MethodCommandNodeFactory not found for the parameter " + parameter); - newNode = factory.create(object, method, annotation, parameter, part, root); + newNode = factory.create(object, method, annotation, parameter, part + argumentSuffix, root); } else { newNode = new LiteralCommandNode(part, root == null ? List.of() : List.of(root)); } diff --git a/commands/src/test/java/com/wizardlybump17/wlib/test/command/extractor/method/MethodCommandExtractorStructureTests.java b/commands/src/test/java/com/wizardlybump17/wlib/test/command/extractor/method/MethodCommandExtractorStructureTests.java index 3593652a..1c4da0ca 100644 --- a/commands/src/test/java/com/wizardlybump17/wlib/test/command/extractor/method/MethodCommandExtractorStructureTests.java +++ b/commands/src/test/java/com/wizardlybump17/wlib/test/command/extractor/method/MethodCommandExtractorStructureTests.java @@ -94,7 +94,7 @@ void test1() { "test0", List.of( new IntegerCommandNode( - "int", + "int-arg", List.of( new LiteralCommandNode( "123" @@ -110,10 +110,10 @@ void test1() { "test1", List.of( new IntegerCommandNode( - "int0", + "int0-arg", List.of( new IntegerCommandNode( - "int1", + "int1-arg", List.of( new LiteralCommandNode( "123", diff --git a/commands/src/test/java/com/wizardlybump17/wlib/test/command/extractor/method/MethodCommandExtractorTests.java b/commands/src/test/java/com/wizardlybump17/wlib/test/command/extractor/method/MethodCommandExtractorTests.java index 17eaa65b..ea278b75 100644 --- a/commands/src/test/java/com/wizardlybump17/wlib/test/command/extractor/method/MethodCommandExtractorTests.java +++ b/commands/src/test/java/com/wizardlybump17/wlib/test/command/extractor/method/MethodCommandExtractorTests.java @@ -455,7 +455,7 @@ void testCommandSenderParameters() { "hello", List.of( new IntegerCommandNode( - "int", + "int-arg", AllowedIntegerInputs.unlimited(), Assertions.assertDoesNotThrow(() -> MethodCommandExtractor.createExecutor(object, "hello", CommandSender.class, int.class)) ) @@ -470,7 +470,7 @@ void testCommandSenderParameters() { "world", List.of( new IntegerCommandNode( - "int", + "int-arg", AllowedIntegerInputs.unlimited(), Assertions.assertDoesNotThrow(() -> MethodCommandExtractor.createExecutor(object, "helloWorld", CommandSender.class, int.class)) ) @@ -490,7 +490,7 @@ void testCommandSenderParameters() { "hi", List.of( new IntegerCommandNode( - "int", + "int-arg", AllowedIntegerInputs.unlimited(), Assertions.assertDoesNotThrow(() -> MethodCommandExtractor.createExecutor(object, "helloThereHi", CommandSender.class, int.class)) ) @@ -535,7 +535,7 @@ void testCommandContextParameters() { "hello", List.of( new IntegerCommandNode( - "int", + "int-arg", AllowedIntegerInputs.unlimited(), Assertions.assertDoesNotThrow(() -> MethodCommandExtractor.createExecutor(object, "hello", CommandContext.class, int.class)) ) @@ -550,7 +550,7 @@ void testCommandContextParameters() { "world", List.of( new IntegerCommandNode( - "int", + "int-arg", AllowedIntegerInputs.unlimited(), Assertions.assertDoesNotThrow(() -> MethodCommandExtractor.createExecutor(object, "helloWorld", CommandContext.class, int.class)) ) @@ -570,7 +570,7 @@ void testCommandContextParameters() { "hi", List.of( new IntegerCommandNode( - "int", + "int-arg", AllowedIntegerInputs.unlimited(), Assertions.assertDoesNotThrow(() -> MethodCommandExtractor.createExecutor(object, "helloThereHi", CommandContext.class, int.class)) ) @@ -619,7 +619,7 @@ void testCommandSenderParametersCommandResult() { "hello", List.of( new IntegerCommandNode( - "int", + "int-arg", AllowedIntegerInputs.unlimited(), Assertions.assertDoesNotThrow(() -> MethodCommandExtractor.createExecutor(object, "hello", CommandSender.class, int.class)) ) @@ -634,7 +634,7 @@ void testCommandSenderParametersCommandResult() { "world", List.of( new IntegerCommandNode( - "int", + "int-arg", AllowedIntegerInputs.unlimited(), Assertions.assertDoesNotThrow(() -> MethodCommandExtractor.createExecutor(object, "helloWorld", CommandSender.class, int.class)) ) @@ -654,7 +654,7 @@ void testCommandSenderParametersCommandResult() { "hi", List.of( new IntegerCommandNode( - "int", + "int-arg", AllowedIntegerInputs.unlimited(), Assertions.assertDoesNotThrow(() -> MethodCommandExtractor.createExecutor(object, "helloThereHi", CommandSender.class, int.class)) ) @@ -702,7 +702,7 @@ void testCommandContextParametersCommandResult() { "hello", List.of( new IntegerCommandNode( - "int", + "int-arg", AllowedIntegerInputs.unlimited(), Assertions.assertDoesNotThrow(() -> MethodCommandExtractor.createExecutor(object, "hello", CommandContext.class, int.class)) ) @@ -717,7 +717,7 @@ void testCommandContextParametersCommandResult() { "world", List.of( new IntegerCommandNode( - "int", + "int-arg", AllowedIntegerInputs.unlimited(), Assertions.assertDoesNotThrow(() -> MethodCommandExtractor.createExecutor(object, "helloWorld", CommandContext.class, int.class)) ) @@ -737,7 +737,7 @@ void testCommandContextParametersCommandResult() { "hi", List.of( new IntegerCommandNode( - "int", + "int-arg", AllowedIntegerInputs.unlimited(), Assertions.assertDoesNotThrow(() -> MethodCommandExtractor.createExecutor(object, "helloThereHi", CommandContext.class, int.class)) ) @@ -789,7 +789,7 @@ void testParametersPure() { "hello", List.of( new IntegerCommandNode( - "int", + "int-arg", AllowedIntegerInputs.unlimited(), Assertions.assertDoesNotThrow(() -> MethodCommandExtractor.createExecutor(object, "hello", int.class)) ) @@ -804,7 +804,7 @@ void testParametersPure() { "world", List.of( new IntegerCommandNode( - "int", + "int-arg", AllowedIntegerInputs.unlimited(), Assertions.assertDoesNotThrow(() -> MethodCommandExtractor.createExecutor(object, "helloWorld", int.class)) ) @@ -824,7 +824,7 @@ void testParametersPure() { "hi", List.of( new IntegerCommandNode( - "int", + "int-arg", AllowedIntegerInputs.unlimited(), Assertions.assertDoesNotThrow(() -> MethodCommandExtractor.createExecutor(object, "helloThereHi", int.class)) ) @@ -873,7 +873,7 @@ void testParametersPureCommandResult() { "hello", List.of( new IntegerCommandNode( - "int", + "int-arg", AllowedIntegerInputs.unlimited(), Assertions.assertDoesNotThrow(() -> MethodCommandExtractor.createExecutor(object, "hello", int.class)) ) @@ -888,7 +888,7 @@ void testParametersPureCommandResult() { "world", List.of( new IntegerCommandNode( - "int", + "int-arg", AllowedIntegerInputs.unlimited(), Assertions.assertDoesNotThrow(() -> MethodCommandExtractor.createExecutor(object, "helloWorld", int.class)) ) @@ -908,7 +908,7 @@ void testParametersPureCommandResult() { "hi", List.of( new IntegerCommandNode( - "int", + "int-arg", AllowedIntegerInputs.unlimited(), Assertions.assertDoesNotThrow(() -> MethodCommandExtractor.createExecutor(object, "helloThereHi", int.class)) ) @@ -999,7 +999,7 @@ void testExecute() { "welcome", List.of( new StringCommandNode( - "name", + "name-arg", List.of( new LiteralCommandNode( "world", @@ -1018,7 +1018,7 @@ void testExecute() { "wassup", List.of( new StringCommandNode( - "name", + "name-arg", List.of( new LiteralCommandNode( "nice", @@ -1037,7 +1037,7 @@ void testExecute() { "aye", List.of( new StringCommandNode( - "name", + "name-arg", List.of( new LiteralCommandNode( "nice", @@ -1100,7 +1100,7 @@ void testExecute() { ); Assertions.assertEquals( - CommandResult.successful(1, welcome.findNode("name"), null), + CommandResult.successful(1, welcome.findNode("name-arg"), null), manager.execute(CHAD_SENDER, "welcome test") ); Assertions.assertEquals( @@ -1109,7 +1109,7 @@ void testExecute() { ); Assertions.assertEquals( - CommandResult.successful(1, wassup.findNode("name"), null), + CommandResult.successful(1, wassup.findNode("name-arg"), null), manager.execute(CHAD_SENDER, "wassup test") ); Assertions.assertEquals( @@ -1118,7 +1118,7 @@ void testExecute() { ); Assertions.assertEquals( - CommandResult.successful(1, aye.findNode("name"), null), + CommandResult.successful(1, aye.findNode("name-arg"), null), manager.execute(CHAD_SENDER, "aye test") ); Assertions.assertEquals( diff --git a/commands/src/test/java/com/wizardlybump17/wlib/test/command/extractor/method/MethodCommandNodeFactoryTests.java b/commands/src/test/java/com/wizardlybump17/wlib/test/command/extractor/method/MethodCommandNodeFactoryTests.java index 7dc1c325..8feb0a66 100644 --- a/commands/src/test/java/com/wizardlybump17/wlib/test/command/extractor/method/MethodCommandNodeFactoryTests.java +++ b/commands/src/test/java/com/wizardlybump17/wlib/test/command/extractor/method/MethodCommandNodeFactoryTests.java @@ -50,7 +50,7 @@ void testByte() { "test", List.of( new ByteCommandNode( - "arg0", + "arg0-arg", AllowedByteInputs.unlimited() ) ) @@ -61,13 +61,13 @@ void testByte() { "test", List.of( new ByteCommandNode( - "arg0", + "arg0-arg", List.of( new LiteralCommandNode( "test1", List.of( new ByteCommandNode( - "arg1", + "arg1-arg", AllowedByteInputs.unlimited() ) ) @@ -110,7 +110,7 @@ void testShort() { "test", List.of( new ShortCommandNode( - "arg0", + "arg0-arg", AllowedShortInputs.unlimited() ) ) @@ -121,13 +121,13 @@ void testShort() { "test", List.of( new ShortCommandNode( - "arg0", + "arg0-arg", List.of( new LiteralCommandNode( "test1", List.of( new ShortCommandNode( - "arg1", + "arg1-arg", AllowedShortInputs.unlimited() ) ) @@ -170,7 +170,7 @@ void testInt() { "test", List.of( new IntegerCommandNode( - "arg0", + "arg0-arg", AllowedIntegerInputs.unlimited() ) ) @@ -181,13 +181,13 @@ void testInt() { "test", List.of( new IntegerCommandNode( - "arg0", + "arg0-arg", List.of( new LiteralCommandNode( "test1", List.of( new IntegerCommandNode( - "arg1", + "arg1-arg", AllowedIntegerInputs.unlimited() ) ) @@ -230,7 +230,7 @@ void testLong() { "test", List.of( new LongCommandNode( - "arg0", + "arg0-arg", AllowedLongInputs.unlimited() ) ) @@ -241,13 +241,13 @@ void testLong() { "test", List.of( new LongCommandNode( - "arg0", + "arg0-arg", List.of( new LiteralCommandNode( "test1", List.of( new LongCommandNode( - "arg1", + "arg1-arg", AllowedLongInputs.unlimited() ) ) @@ -290,7 +290,7 @@ void testFloat() { "test", List.of( new FloatCommandNode( - "arg0", + "arg0-arg", AllowedFloatInputs.unlimited() ) ) @@ -301,13 +301,13 @@ void testFloat() { "test", List.of( new FloatCommandNode( - "arg0", + "arg0-arg", List.of( new LiteralCommandNode( "test1", List.of( new FloatCommandNode( - "arg1", + "arg1-arg", AllowedFloatInputs.unlimited() ) ) @@ -350,7 +350,7 @@ void testDouble() { "test", List.of( new DoubleCommandNode( - "arg0", + "arg0-arg", AllowedDoubleInputs.unlimited() ) ) @@ -361,13 +361,13 @@ void testDouble() { "test", List.of( new DoubleCommandNode( - "arg0", + "arg0-arg", List.of( new LiteralCommandNode( "test1", List.of( new DoubleCommandNode( - "arg1", + "arg1-arg", AllowedDoubleInputs.unlimited() ) ) @@ -410,7 +410,7 @@ void testChar() { "test", List.of( new CharacterCommandNode( - "arg0", + "arg0-arg", AllowedCharacterInputs.anyNotNull() ) ) @@ -421,13 +421,13 @@ void testChar() { "test", List.of( new CharacterCommandNode( - "arg0", + "arg0-arg", List.of( new LiteralCommandNode( "test1", List.of( new CharacterCommandNode( - "arg1", + "arg1-arg", AllowedCharacterInputs.anyNotNull() ) ) @@ -470,7 +470,7 @@ void testString() { "test", List.of( new StringCommandNode( - "arg0", + "arg0-arg", AllowedStringInputs.anyNullable() ) ) @@ -481,13 +481,13 @@ void testString() { "test", List.of( new StringCommandNode( - "arg0", + "arg0-arg", List.of( new LiteralCommandNode( "test1", List.of( new StringCommandNode( - "arg1", + "arg1-arg", AllowedStringInputs.anyNullable() ) ) @@ -530,7 +530,7 @@ void testUUID() { "test", List.of( new UUIDCommandNode( - "arg0", + "arg0-arg", AllowedUUIDInputs.anyNullable() ) ) @@ -541,13 +541,13 @@ void testUUID() { "test", List.of( new UUIDCommandNode( - "arg0", + "arg0-arg", List.of( new LiteralCommandNode( "test1", List.of( new UUIDCommandNode( - "arg1", + "arg1-arg", AllowedUUIDInputs.anyNullable() ) ) @@ -589,85 +589,85 @@ void testMix() { "test", List.of( new IntegerCommandNode( - "int0", + "int0-arg", List.of( new IntegerCommandNode( - "int1", + "int1-arg", List.of( new LiteralCommandNode( "test1", List.of( new ByteCommandNode( - "byte0", + "byte0-arg", List.of( new ByteCommandNode( - "byte1", + "byte1-arg", List.of( new LiteralCommandNode( "test2", List.of( new FloatCommandNode( - "float0", + "float0-arg", List.of( new LiteralCommandNode( "test3", List.of( new FloatCommandNode( - "float1", + "float1-arg", List.of( new LongCommandNode( - "long0", + "long0-arg", List.of( new LongCommandNode( - "long1", + "long1-arg", List.of( new LiteralCommandNode( "test4", List.of( new ShortCommandNode( - "short0", + "short0-arg", List.of( new ShortCommandNode( - "short1", + "short1-arg", List.of( new LiteralCommandNode( "test5", List.of( new DoubleCommandNode( - "double0", + "double0-arg", List.of( new DoubleCommandNode( - "double1", + "double1-arg", List.of( new LiteralCommandNode( "test6", List.of( new CharacterCommandNode( - "char0", + "char0-arg", List.of( new CharacterCommandNode( - "char1", + "char1-arg", List.of( new LiteralCommandNode( "test7", List.of( new StringCommandNode( - "string0", + "string0-arg", List.of( new LiteralCommandNode( "test8", List.of( new StringCommandNode( - "string1", + "string1-arg", List.of( new UUIDCommandNode( - "uuid0", + "uuid0-arg", List.of( new LiteralCommandNode( "test9", List.of( new UUIDCommandNode( - "uuid1", + "uuid1-arg", AllowedUUIDInputs.anyNullable() ) ) From 947d987400e86980b726eb6494f116486e53a0f8 Mon Sep 17 00:00:00 2001 From: WizardlyBump17 Date: Sun, 7 Dec 2025 23:55:04 -0300 Subject: [PATCH 214/363] it has a 2 --- build.gradle | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/build.gradle b/build.gradle index fa2419ba..5445af38 100644 --- a/build.gradle +++ b/build.gradle @@ -9,7 +9,7 @@ subprojects { apply plugin: 'maven-publish' group = 'com.wizardlybump17.wlib' - version = "1.6.8-ncs-1.20.6+" + ("true".equalsIgnoreCase(System.getenv("WLIB_SNAPSHOT")) ? "-SNAPSHOT." + System.getenv("WLIB_SNAPSHOT_NUMBER") : "") + version = "1.6.8-ncs-2-1.20.6+" + ("true".equalsIgnoreCase(System.getenv("WLIB_SNAPSHOT")) ? "-SNAPSHOT." + System.getenv("WLIB_SNAPSHOT_NUMBER") : "") repositories { mavenLocal() From d69e63a1244d51696c858d67f39fe37d1773a4dc Mon Sep 17 00:00:00 2001 From: WizardlyBump17 Date: Mon, 8 Dec 2025 19:56:07 -0300 Subject: [PATCH 215/363] removed the debug code --- .../command/extractor/method/MethodCommandExtractor.java | 5 ----- 1 file changed, 5 deletions(-) diff --git a/commands/src/main/java/com/wizardlybump17/wlib/command/extractor/method/MethodCommandExtractor.java b/commands/src/main/java/com/wizardlybump17/wlib/command/extractor/method/MethodCommandExtractor.java index a62c1b14..693bba8e 100644 --- a/commands/src/main/java/com/wizardlybump17/wlib/command/extractor/method/MethodCommandExtractor.java +++ b/commands/src/main/java/com/wizardlybump17/wlib/command/extractor/method/MethodCommandExtractor.java @@ -51,12 +51,7 @@ public boolean isAccepted(@NotNull Object object) { Class clazz = object.getClass(); - boolean b = false; - for (Method method : clazz.getMethods()) { - if (method.getName().toLowerCase().contains("gree")) - b = true; - com.wizardlybump17.wlib.command.annotation.Command annotation = method.getAnnotation(com.wizardlybump17.wlib.command.annotation.Command.class); if (annotation == null) continue; From 53e85ab49e5d9ad784bfff5f79f9c81b4344b945 Mon Sep 17 00:00:00 2001 From: WizardlyBump17 Date: Mon, 8 Dec 2025 19:59:11 -0300 Subject: [PATCH 216/363] nah, it doesnt need a suffix. The CommandArguments need a small rework --- .../wizardlybump17/wlib/command/Command.java | 18 ---- .../command/extractor/CommandExtractor.java | 6 +- .../method/MethodCommandExtractor.java | 16 +--- .../wlib/test/command/CommandTests.java | 34 ------- .../MethodCommandExtractorStructureTests.java | 6 +- .../method/MethodCommandExtractorTests.java | 48 +++++----- .../method/MethodCommandNodeFactoryTests.java | 90 +++++++++---------- 7 files changed, 77 insertions(+), 141 deletions(-) diff --git a/commands/src/main/java/com/wizardlybump17/wlib/command/Command.java b/commands/src/main/java/com/wizardlybump17/wlib/command/Command.java index 990b2a9c..9540dcec 100644 --- a/commands/src/main/java/com/wizardlybump17/wlib/command/Command.java +++ b/commands/src/main/java/com/wizardlybump17/wlib/command/Command.java @@ -22,27 +22,9 @@ public class Command implements Comparable { private final @NotNull LiteralCommandNode root; public Command(@NotNull LiteralCommandNode root) { - if (hasDuplicateNodeNames(root)) - throw new IllegalArgumentException("The command tree has duplicate node names"); this.root = root; } - public static boolean hasDuplicateNodeNames(@NotNull CommandNode root) { - return hasDuplicateNodeNames0(root, new HashSet<>()); - } - - private static boolean hasDuplicateNodeNames0(@NotNull CommandNode current, @NotNull Set seen) { - if (seen.contains(current.getName())) - return true; - - seen.add(current.getName()); - for (CommandNode child : current.getChildren()) - if (hasDuplicateNodeNames0(child, seen)) - return true; - - return false; - } - public @NotNull LiteralCommandNode getRoot() { return root; } diff --git a/commands/src/main/java/com/wizardlybump17/wlib/command/extractor/CommandExtractor.java b/commands/src/main/java/com/wizardlybump17/wlib/command/extractor/CommandExtractor.java index 045e888d..d6dc28e4 100644 --- a/commands/src/main/java/com/wizardlybump17/wlib/command/extractor/CommandExtractor.java +++ b/commands/src/main/java/com/wizardlybump17/wlib/command/extractor/CommandExtractor.java @@ -15,10 +15,6 @@ public interface CommandExtractor { @NotNull List extract(@NotNull Object object) throws CommandExtractorException; static @NotNull MethodCommandExtractor method(@NotNull MethodCommandNodeFactoryRegistry factoryRegistry) { - return new MethodCommandExtractor(factoryRegistry, MethodCommandExtractor.DEFAULT_ARGUMENT_SUFFIX); - } - - static @NotNull MethodCommandExtractor method(@NotNull MethodCommandNodeFactoryRegistry factoryRegistry, @NotNull String argumentSuffix) { - return new MethodCommandExtractor(factoryRegistry, argumentSuffix); + return new MethodCommandExtractor(factoryRegistry); } } diff --git a/commands/src/main/java/com/wizardlybump17/wlib/command/extractor/method/MethodCommandExtractor.java b/commands/src/main/java/com/wizardlybump17/wlib/command/extractor/method/MethodCommandExtractor.java index 693bba8e..ecd69d1b 100644 --- a/commands/src/main/java/com/wizardlybump17/wlib/command/extractor/method/MethodCommandExtractor.java +++ b/commands/src/main/java/com/wizardlybump17/wlib/command/extractor/method/MethodCommandExtractor.java @@ -22,18 +22,10 @@ public class MethodCommandExtractor implements CommandExtractor { - public static final @NotNull String DEFAULT_ARGUMENT_SUFFIX = "-arg"; - private final @NotNull MethodCommandNodeFactoryRegistry factoryRegistry; - private final @NotNull String argumentSuffix; - - public MethodCommandExtractor(@NotNull MethodCommandNodeFactoryRegistry factoryRegistry, @NotNull String argumentSuffix) { - this.factoryRegistry = factoryRegistry; - this.argumentSuffix = argumentSuffix; - } public MethodCommandExtractor(@NotNull MethodCommandNodeFactoryRegistry factoryRegistry) { - this(factoryRegistry, DEFAULT_ARGUMENT_SUFFIX); + this.factoryRegistry = factoryRegistry; } @Override @@ -68,7 +60,7 @@ public boolean isAccepted(@NotNull Object object) { String part = commandParts[i]; CommandNode oldRoot = root; - root = createNode(factoryRegistry, part, parameters, parameterIndex, root, annotation, object, method, argumentSuffix); + root = createNode(factoryRegistry, part, parameters, parameterIndex, root, annotation, object, method); if (!(root instanceof LiteralCommandNode)) parameterIndex--; @@ -85,7 +77,7 @@ public boolean isAccepted(@NotNull Object object) { return commands; } - private static @NotNull CommandNode createNode(@NotNull MethodCommandNodeFactoryRegistry factoryRegistry, @NotNull String part, @NotNull Parameter @NotNull [] parameters, int parameterIndex, @Nullable CommandNode root, @NotNull com.wizardlybump17.wlib.command.annotation.Command annotation, @NotNull Object object, @NotNull Method method, @NotNull String argumentSuffix) throws MethodCommandNodeFactoryNotFoundException { + private static @NotNull CommandNode createNode(@NotNull MethodCommandNodeFactoryRegistry factoryRegistry, @NotNull String part, @NotNull Parameter @NotNull [] parameters, int parameterIndex, @Nullable CommandNode root, @NotNull com.wizardlybump17.wlib.command.annotation.Command annotation, @NotNull Object object, @NotNull Method method) throws MethodCommandNodeFactoryNotFoundException { CommandNode newNode; boolean argument = part.charAt(0) == '<' && part.charAt(part.length() - 1) == '>'; @@ -103,7 +95,7 @@ public boolean isAccepted(@NotNull Object object) { if (factory == null) throw new MethodCommandNodeFactoryNotFoundException("MethodCommandNodeFactory not found for the parameter " + parameter); - newNode = factory.create(object, method, annotation, parameter, part + argumentSuffix, root); + newNode = factory.create(object, method, annotation, parameter, part, root); } else { newNode = new LiteralCommandNode(part, root == null ? List.of() : List.of(root)); } diff --git a/commands/src/test/java/com/wizardlybump17/wlib/test/command/CommandTests.java b/commands/src/test/java/com/wizardlybump17/wlib/test/command/CommandTests.java index 4adba4d3..e35ccc29 100644 --- a/commands/src/test/java/com/wizardlybump17/wlib/test/command/CommandTests.java +++ b/commands/src/test/java/com/wizardlybump17/wlib/test/command/CommandTests.java @@ -213,40 +213,6 @@ void testCommandNodeExecutorNotFound() { Assertions.assertEquals(expected, actual); } - /** - *

- * Because we used a Map to represent the arguments and the keys were the node names, - * this caused the arguments to be overwritten if the node names were the same. - *

- *

- * This test will make sure that we wont allow nodes to have the same name. - *

- */ - @Test - void testCommandWithSameNodeName() { - Assertions.assertThrows( - IllegalArgumentException.class, - () -> new Command( - new LiteralCommandNode( - "test", - List.of( - new LiteralCommandNode( - "child0", - List.of( - new IntegerCommandNode( - "test", - List.of(), - AllowedIntegerInputs.unlimited(), - context -> CommandResult.successful(context, context.arguments().getArgumentData("test").orElse(null)) - ) - ) - ) - ) - ) - ) - ); - } - /** *

* The CommandNode#merge(CommandNode) method wasnt merging the executor and permission. diff --git a/commands/src/test/java/com/wizardlybump17/wlib/test/command/extractor/method/MethodCommandExtractorStructureTests.java b/commands/src/test/java/com/wizardlybump17/wlib/test/command/extractor/method/MethodCommandExtractorStructureTests.java index 1c4da0ca..3593652a 100644 --- a/commands/src/test/java/com/wizardlybump17/wlib/test/command/extractor/method/MethodCommandExtractorStructureTests.java +++ b/commands/src/test/java/com/wizardlybump17/wlib/test/command/extractor/method/MethodCommandExtractorStructureTests.java @@ -94,7 +94,7 @@ void test1() { "test0", List.of( new IntegerCommandNode( - "int-arg", + "int", List.of( new LiteralCommandNode( "123" @@ -110,10 +110,10 @@ void test1() { "test1", List.of( new IntegerCommandNode( - "int0-arg", + "int0", List.of( new IntegerCommandNode( - "int1-arg", + "int1", List.of( new LiteralCommandNode( "123", diff --git a/commands/src/test/java/com/wizardlybump17/wlib/test/command/extractor/method/MethodCommandExtractorTests.java b/commands/src/test/java/com/wizardlybump17/wlib/test/command/extractor/method/MethodCommandExtractorTests.java index ea278b75..17eaa65b 100644 --- a/commands/src/test/java/com/wizardlybump17/wlib/test/command/extractor/method/MethodCommandExtractorTests.java +++ b/commands/src/test/java/com/wizardlybump17/wlib/test/command/extractor/method/MethodCommandExtractorTests.java @@ -455,7 +455,7 @@ void testCommandSenderParameters() { "hello", List.of( new IntegerCommandNode( - "int-arg", + "int", AllowedIntegerInputs.unlimited(), Assertions.assertDoesNotThrow(() -> MethodCommandExtractor.createExecutor(object, "hello", CommandSender.class, int.class)) ) @@ -470,7 +470,7 @@ void testCommandSenderParameters() { "world", List.of( new IntegerCommandNode( - "int-arg", + "int", AllowedIntegerInputs.unlimited(), Assertions.assertDoesNotThrow(() -> MethodCommandExtractor.createExecutor(object, "helloWorld", CommandSender.class, int.class)) ) @@ -490,7 +490,7 @@ void testCommandSenderParameters() { "hi", List.of( new IntegerCommandNode( - "int-arg", + "int", AllowedIntegerInputs.unlimited(), Assertions.assertDoesNotThrow(() -> MethodCommandExtractor.createExecutor(object, "helloThereHi", CommandSender.class, int.class)) ) @@ -535,7 +535,7 @@ void testCommandContextParameters() { "hello", List.of( new IntegerCommandNode( - "int-arg", + "int", AllowedIntegerInputs.unlimited(), Assertions.assertDoesNotThrow(() -> MethodCommandExtractor.createExecutor(object, "hello", CommandContext.class, int.class)) ) @@ -550,7 +550,7 @@ void testCommandContextParameters() { "world", List.of( new IntegerCommandNode( - "int-arg", + "int", AllowedIntegerInputs.unlimited(), Assertions.assertDoesNotThrow(() -> MethodCommandExtractor.createExecutor(object, "helloWorld", CommandContext.class, int.class)) ) @@ -570,7 +570,7 @@ void testCommandContextParameters() { "hi", List.of( new IntegerCommandNode( - "int-arg", + "int", AllowedIntegerInputs.unlimited(), Assertions.assertDoesNotThrow(() -> MethodCommandExtractor.createExecutor(object, "helloThereHi", CommandContext.class, int.class)) ) @@ -619,7 +619,7 @@ void testCommandSenderParametersCommandResult() { "hello", List.of( new IntegerCommandNode( - "int-arg", + "int", AllowedIntegerInputs.unlimited(), Assertions.assertDoesNotThrow(() -> MethodCommandExtractor.createExecutor(object, "hello", CommandSender.class, int.class)) ) @@ -634,7 +634,7 @@ void testCommandSenderParametersCommandResult() { "world", List.of( new IntegerCommandNode( - "int-arg", + "int", AllowedIntegerInputs.unlimited(), Assertions.assertDoesNotThrow(() -> MethodCommandExtractor.createExecutor(object, "helloWorld", CommandSender.class, int.class)) ) @@ -654,7 +654,7 @@ void testCommandSenderParametersCommandResult() { "hi", List.of( new IntegerCommandNode( - "int-arg", + "int", AllowedIntegerInputs.unlimited(), Assertions.assertDoesNotThrow(() -> MethodCommandExtractor.createExecutor(object, "helloThereHi", CommandSender.class, int.class)) ) @@ -702,7 +702,7 @@ void testCommandContextParametersCommandResult() { "hello", List.of( new IntegerCommandNode( - "int-arg", + "int", AllowedIntegerInputs.unlimited(), Assertions.assertDoesNotThrow(() -> MethodCommandExtractor.createExecutor(object, "hello", CommandContext.class, int.class)) ) @@ -717,7 +717,7 @@ void testCommandContextParametersCommandResult() { "world", List.of( new IntegerCommandNode( - "int-arg", + "int", AllowedIntegerInputs.unlimited(), Assertions.assertDoesNotThrow(() -> MethodCommandExtractor.createExecutor(object, "helloWorld", CommandContext.class, int.class)) ) @@ -737,7 +737,7 @@ void testCommandContextParametersCommandResult() { "hi", List.of( new IntegerCommandNode( - "int-arg", + "int", AllowedIntegerInputs.unlimited(), Assertions.assertDoesNotThrow(() -> MethodCommandExtractor.createExecutor(object, "helloThereHi", CommandContext.class, int.class)) ) @@ -789,7 +789,7 @@ void testParametersPure() { "hello", List.of( new IntegerCommandNode( - "int-arg", + "int", AllowedIntegerInputs.unlimited(), Assertions.assertDoesNotThrow(() -> MethodCommandExtractor.createExecutor(object, "hello", int.class)) ) @@ -804,7 +804,7 @@ void testParametersPure() { "world", List.of( new IntegerCommandNode( - "int-arg", + "int", AllowedIntegerInputs.unlimited(), Assertions.assertDoesNotThrow(() -> MethodCommandExtractor.createExecutor(object, "helloWorld", int.class)) ) @@ -824,7 +824,7 @@ void testParametersPure() { "hi", List.of( new IntegerCommandNode( - "int-arg", + "int", AllowedIntegerInputs.unlimited(), Assertions.assertDoesNotThrow(() -> MethodCommandExtractor.createExecutor(object, "helloThereHi", int.class)) ) @@ -873,7 +873,7 @@ void testParametersPureCommandResult() { "hello", List.of( new IntegerCommandNode( - "int-arg", + "int", AllowedIntegerInputs.unlimited(), Assertions.assertDoesNotThrow(() -> MethodCommandExtractor.createExecutor(object, "hello", int.class)) ) @@ -888,7 +888,7 @@ void testParametersPureCommandResult() { "world", List.of( new IntegerCommandNode( - "int-arg", + "int", AllowedIntegerInputs.unlimited(), Assertions.assertDoesNotThrow(() -> MethodCommandExtractor.createExecutor(object, "helloWorld", int.class)) ) @@ -908,7 +908,7 @@ void testParametersPureCommandResult() { "hi", List.of( new IntegerCommandNode( - "int-arg", + "int", AllowedIntegerInputs.unlimited(), Assertions.assertDoesNotThrow(() -> MethodCommandExtractor.createExecutor(object, "helloThereHi", int.class)) ) @@ -999,7 +999,7 @@ void testExecute() { "welcome", List.of( new StringCommandNode( - "name-arg", + "name", List.of( new LiteralCommandNode( "world", @@ -1018,7 +1018,7 @@ void testExecute() { "wassup", List.of( new StringCommandNode( - "name-arg", + "name", List.of( new LiteralCommandNode( "nice", @@ -1037,7 +1037,7 @@ void testExecute() { "aye", List.of( new StringCommandNode( - "name-arg", + "name", List.of( new LiteralCommandNode( "nice", @@ -1100,7 +1100,7 @@ void testExecute() { ); Assertions.assertEquals( - CommandResult.successful(1, welcome.findNode("name-arg"), null), + CommandResult.successful(1, welcome.findNode("name"), null), manager.execute(CHAD_SENDER, "welcome test") ); Assertions.assertEquals( @@ -1109,7 +1109,7 @@ void testExecute() { ); Assertions.assertEquals( - CommandResult.successful(1, wassup.findNode("name-arg"), null), + CommandResult.successful(1, wassup.findNode("name"), null), manager.execute(CHAD_SENDER, "wassup test") ); Assertions.assertEquals( @@ -1118,7 +1118,7 @@ void testExecute() { ); Assertions.assertEquals( - CommandResult.successful(1, aye.findNode("name-arg"), null), + CommandResult.successful(1, aye.findNode("name"), null), manager.execute(CHAD_SENDER, "aye test") ); Assertions.assertEquals( diff --git a/commands/src/test/java/com/wizardlybump17/wlib/test/command/extractor/method/MethodCommandNodeFactoryTests.java b/commands/src/test/java/com/wizardlybump17/wlib/test/command/extractor/method/MethodCommandNodeFactoryTests.java index 8feb0a66..7dc1c325 100644 --- a/commands/src/test/java/com/wizardlybump17/wlib/test/command/extractor/method/MethodCommandNodeFactoryTests.java +++ b/commands/src/test/java/com/wizardlybump17/wlib/test/command/extractor/method/MethodCommandNodeFactoryTests.java @@ -50,7 +50,7 @@ void testByte() { "test", List.of( new ByteCommandNode( - "arg0-arg", + "arg0", AllowedByteInputs.unlimited() ) ) @@ -61,13 +61,13 @@ void testByte() { "test", List.of( new ByteCommandNode( - "arg0-arg", + "arg0", List.of( new LiteralCommandNode( "test1", List.of( new ByteCommandNode( - "arg1-arg", + "arg1", AllowedByteInputs.unlimited() ) ) @@ -110,7 +110,7 @@ void testShort() { "test", List.of( new ShortCommandNode( - "arg0-arg", + "arg0", AllowedShortInputs.unlimited() ) ) @@ -121,13 +121,13 @@ void testShort() { "test", List.of( new ShortCommandNode( - "arg0-arg", + "arg0", List.of( new LiteralCommandNode( "test1", List.of( new ShortCommandNode( - "arg1-arg", + "arg1", AllowedShortInputs.unlimited() ) ) @@ -170,7 +170,7 @@ void testInt() { "test", List.of( new IntegerCommandNode( - "arg0-arg", + "arg0", AllowedIntegerInputs.unlimited() ) ) @@ -181,13 +181,13 @@ void testInt() { "test", List.of( new IntegerCommandNode( - "arg0-arg", + "arg0", List.of( new LiteralCommandNode( "test1", List.of( new IntegerCommandNode( - "arg1-arg", + "arg1", AllowedIntegerInputs.unlimited() ) ) @@ -230,7 +230,7 @@ void testLong() { "test", List.of( new LongCommandNode( - "arg0-arg", + "arg0", AllowedLongInputs.unlimited() ) ) @@ -241,13 +241,13 @@ void testLong() { "test", List.of( new LongCommandNode( - "arg0-arg", + "arg0", List.of( new LiteralCommandNode( "test1", List.of( new LongCommandNode( - "arg1-arg", + "arg1", AllowedLongInputs.unlimited() ) ) @@ -290,7 +290,7 @@ void testFloat() { "test", List.of( new FloatCommandNode( - "arg0-arg", + "arg0", AllowedFloatInputs.unlimited() ) ) @@ -301,13 +301,13 @@ void testFloat() { "test", List.of( new FloatCommandNode( - "arg0-arg", + "arg0", List.of( new LiteralCommandNode( "test1", List.of( new FloatCommandNode( - "arg1-arg", + "arg1", AllowedFloatInputs.unlimited() ) ) @@ -350,7 +350,7 @@ void testDouble() { "test", List.of( new DoubleCommandNode( - "arg0-arg", + "arg0", AllowedDoubleInputs.unlimited() ) ) @@ -361,13 +361,13 @@ void testDouble() { "test", List.of( new DoubleCommandNode( - "arg0-arg", + "arg0", List.of( new LiteralCommandNode( "test1", List.of( new DoubleCommandNode( - "arg1-arg", + "arg1", AllowedDoubleInputs.unlimited() ) ) @@ -410,7 +410,7 @@ void testChar() { "test", List.of( new CharacterCommandNode( - "arg0-arg", + "arg0", AllowedCharacterInputs.anyNotNull() ) ) @@ -421,13 +421,13 @@ void testChar() { "test", List.of( new CharacterCommandNode( - "arg0-arg", + "arg0", List.of( new LiteralCommandNode( "test1", List.of( new CharacterCommandNode( - "arg1-arg", + "arg1", AllowedCharacterInputs.anyNotNull() ) ) @@ -470,7 +470,7 @@ void testString() { "test", List.of( new StringCommandNode( - "arg0-arg", + "arg0", AllowedStringInputs.anyNullable() ) ) @@ -481,13 +481,13 @@ void testString() { "test", List.of( new StringCommandNode( - "arg0-arg", + "arg0", List.of( new LiteralCommandNode( "test1", List.of( new StringCommandNode( - "arg1-arg", + "arg1", AllowedStringInputs.anyNullable() ) ) @@ -530,7 +530,7 @@ void testUUID() { "test", List.of( new UUIDCommandNode( - "arg0-arg", + "arg0", AllowedUUIDInputs.anyNullable() ) ) @@ -541,13 +541,13 @@ void testUUID() { "test", List.of( new UUIDCommandNode( - "arg0-arg", + "arg0", List.of( new LiteralCommandNode( "test1", List.of( new UUIDCommandNode( - "arg1-arg", + "arg1", AllowedUUIDInputs.anyNullable() ) ) @@ -589,85 +589,85 @@ void testMix() { "test", List.of( new IntegerCommandNode( - "int0-arg", + "int0", List.of( new IntegerCommandNode( - "int1-arg", + "int1", List.of( new LiteralCommandNode( "test1", List.of( new ByteCommandNode( - "byte0-arg", + "byte0", List.of( new ByteCommandNode( - "byte1-arg", + "byte1", List.of( new LiteralCommandNode( "test2", List.of( new FloatCommandNode( - "float0-arg", + "float0", List.of( new LiteralCommandNode( "test3", List.of( new FloatCommandNode( - "float1-arg", + "float1", List.of( new LongCommandNode( - "long0-arg", + "long0", List.of( new LongCommandNode( - "long1-arg", + "long1", List.of( new LiteralCommandNode( "test4", List.of( new ShortCommandNode( - "short0-arg", + "short0", List.of( new ShortCommandNode( - "short1-arg", + "short1", List.of( new LiteralCommandNode( "test5", List.of( new DoubleCommandNode( - "double0-arg", + "double0", List.of( new DoubleCommandNode( - "double1-arg", + "double1", List.of( new LiteralCommandNode( "test6", List.of( new CharacterCommandNode( - "char0-arg", + "char0", List.of( new CharacterCommandNode( - "char1-arg", + "char1", List.of( new LiteralCommandNode( "test7", List.of( new StringCommandNode( - "string0-arg", + "string0", List.of( new LiteralCommandNode( "test8", List.of( new StringCommandNode( - "string1-arg", + "string1", List.of( new UUIDCommandNode( - "uuid0-arg", + "uuid0", List.of( new LiteralCommandNode( "test9", List.of( new UUIDCommandNode( - "uuid1-arg", + "uuid1", AllowedUUIDInputs.anyNullable() ) ) From 1f980123b3ac5f0b2519db48dbdfe7488ff44e89 Mon Sep 17 00:00:00 2001 From: WizardlyBump17 Date: Mon, 8 Dec 2025 20:02:45 -0300 Subject: [PATCH 217/363] not passing LiteralCommandNode results --- .../com/wizardlybump17/wlib/command/Command.java | 3 ++- .../wlib/command/context/CommandContext.java | 14 ++++++-------- 2 files changed, 8 insertions(+), 9 deletions(-) diff --git a/commands/src/main/java/com/wizardlybump17/wlib/command/Command.java b/commands/src/main/java/com/wizardlybump17/wlib/command/Command.java index 9540dcec..fd144b69 100644 --- a/commands/src/main/java/com/wizardlybump17/wlib/command/Command.java +++ b/commands/src/main/java/com/wizardlybump17/wlib/command/Command.java @@ -57,7 +57,8 @@ public Command(@NotNull LiteralCommandNode root) { try { Object result = child.parseOrInvalid(inputString); - arguments.add(new CommandContext.CommandNodeArgument<>((CommandNode) child, inputString, result)); + if (!(child instanceof LiteralCommandNode)) + arguments.add(new CommandContext.CommandNodeArgument<>((CommandNode) child, inputString, result)); children = child.getChildren(); diff --git a/commands/src/main/java/com/wizardlybump17/wlib/command/context/CommandContext.java b/commands/src/main/java/com/wizardlybump17/wlib/command/context/CommandContext.java index 5840c35d..ec88f63e 100644 --- a/commands/src/main/java/com/wizardlybump17/wlib/command/context/CommandContext.java +++ b/commands/src/main/java/com/wizardlybump17/wlib/command/context/CommandContext.java @@ -3,7 +3,6 @@ import com.wizardlybump17.wlib.command.Command; import com.wizardlybump17.wlib.command.node.CommandNode; import com.wizardlybump17.wlib.command.sender.CommandSender; -import com.wizardlybump17.wlib.util.MapUtils; import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.Nullable; import org.jetbrains.annotations.Unmodifiable; @@ -17,14 +16,13 @@ public record CommandNodeArgument(@NotNull CommandNode node, @NotNull Stri public static final class CommandNodeArguments { - private final @NotNull LinkedHashMap> arguments; - - private CommandNodeArguments(@NotNull LinkedHashMap> arguments) { - this.arguments = arguments; - } + private final @NotNull @Unmodifiable Map> arguments; public CommandNodeArguments(@NotNull List> arguments) { - this((LinkedHashMap>) MapUtils.collectionToMap(LinkedHashMap::new, arguments, argument -> argument.node().getName())); + Map> argumentsMap = new HashMap<>(); + for (CommandNodeArgument argument : arguments) + argumentsMap.put(argument.node().getName(), argument); + this.arguments = Map.copyOf(argumentsMap); } public boolean hasArgument(@NotNull String key) { @@ -42,7 +40,7 @@ public boolean hasArgument(@NotNull String key) { } public @NotNull @Unmodifiable Map> getArguments() { - return Collections.unmodifiableMap(arguments); + return arguments; } @Override From 5c7e3fdeedc046c03e04a71da2deffad0d1926ad Mon Sep 17 00:00:00 2001 From: WizardlyBump17 Date: Tue, 9 Dec 2025 17:47:46 -0300 Subject: [PATCH 218/363] removed the commented code --- .../wlib/command/executor/CommandNodeExecutor.java | 5 ----- 1 file changed, 5 deletions(-) diff --git a/commands/src/main/java/com/wizardlybump17/wlib/command/executor/CommandNodeExecutor.java b/commands/src/main/java/com/wizardlybump17/wlib/command/executor/CommandNodeExecutor.java index acf4a4f0..60fbdf03 100644 --- a/commands/src/main/java/com/wizardlybump17/wlib/command/executor/CommandNodeExecutor.java +++ b/commands/src/main/java/com/wizardlybump17/wlib/command/executor/CommandNodeExecutor.java @@ -7,10 +7,5 @@ public interface CommandNodeExecutor { -// @NotNull CommandExecutor TEST_EXECUTOR = context -> { -// System.out.println(context); -// return CommandResult.successful(""); -// }; - @Nullable CommandResult execute(@NotNull CommandContext context); } From 8a5580e35e6bf0af081ab92136d464552403936e Mon Sep 17 00:00:00 2001 From: WizardlyBump17 Date: Tue, 9 Dec 2025 18:26:32 -0300 Subject: [PATCH 219/363] testing the command arguments --- .../wlib/test/command/CommandTests.java | 75 +++++++++++++++++++ 1 file changed, 75 insertions(+) diff --git a/commands/src/test/java/com/wizardlybump17/wlib/test/command/CommandTests.java b/commands/src/test/java/com/wizardlybump17/wlib/test/command/CommandTests.java index e35ccc29..49118175 100644 --- a/commands/src/test/java/com/wizardlybump17/wlib/test/command/CommandTests.java +++ b/commands/src/test/java/com/wizardlybump17/wlib/test/command/CommandTests.java @@ -1,6 +1,7 @@ package com.wizardlybump17.wlib.test.command; import com.wizardlybump17.wlib.command.Command; +import com.wizardlybump17.wlib.command.context.CommandContext; import com.wizardlybump17.wlib.command.exception.InputParsingException; import com.wizardlybump17.wlib.command.executor.CommandNodeExecutor; import com.wizardlybump17.wlib.command.input.primitive.number.AllowedIntegerInputs; @@ -17,7 +18,9 @@ import org.junit.jupiter.api.Test; import java.util.List; +import java.util.Map; import java.util.UUID; +import java.util.concurrent.atomic.AtomicReference; import java.util.function.Consumer; public class CommandTests { @@ -258,4 +261,76 @@ void testMerge() { Assertions.assertEquals(expected, actual); } + + @Test + void testCommandArguments() { + { + LiteralCommandNode world = new LiteralCommandNode( + "world", + context -> { + Assertions.assertEquals(Map.of(), context.arguments().getArguments()); + return CommandResult.successful(context, "Hello World"); + } + ); + CommandResult result = new Command( + new LiteralCommandNode( + "hello", + List.of(world) + ) + ).execute(CHAD_SENDER, List.of("hello", "world")); + + Assertions.assertEquals(CommandResult.successful(1, world, "Hello World"), result); + } + + { + AtomicReference worldReference = new AtomicReference<>(); + IntegerCommandNode world = new IntegerCommandNode( + "world", + AllowedIntegerInputs.unlimited(), + context -> { + Assertions.assertEquals(Map.of("world", new CommandContext.CommandNodeArgument<>(worldReference.get(), "10", 10)), context.arguments().getArguments()); + return CommandResult.successful(context, context.arguments().getArgumentData("world").orElseThrow()); + }, + null + ); + worldReference.set(world); + + CommandResult result = new Command( + new LiteralCommandNode( + "hello", + List.of(world) + ) + ).execute(CHAD_SENDER, List.of("hello", "10")); + + Assertions.assertEquals(CommandResult.successful(1, world, 10), result); + } + + { + AtomicReference worldReference = new AtomicReference<>(); + LiteralCommandNode test = new LiteralCommandNode( + "test", + context -> { + Assertions.assertEquals(Map.of("world", new CommandContext.CommandNodeArgument<>(worldReference.get(), "10", 10)), context.arguments().getArguments()); + return CommandResult.successful(context, "Hello " + context.arguments().getArgumentData("world").orElseThrow() + " world"); + } + ); + IntegerCommandNode world = new IntegerCommandNode( + "world", + List.of(test), + AllowedIntegerInputs.unlimited(), + null, + null + ); + worldReference.set(world); + + CommandResult result = new Command( + new LiteralCommandNode( + "hello", + List.of(world) + ) + ).execute(CHAD_SENDER, List.of("hello", "10", "test")); + + Assertions.assertEquals(CommandResult.successful(2, test, "Hello 10 world"), result); + } + } } From 72056216c58cc2dfe737e41f2a9bb265a2adc3d4 Mon Sep 17 00:00:00 2001 From: WizardlyBump17 Date: Tue, 9 Dec 2025 18:54:15 -0300 Subject: [PATCH 220/363] it is the other way around --- .../method/MethodCommandExtractor.java | 20 +++++++++---------- 1 file changed, 10 insertions(+), 10 deletions(-) diff --git a/commands/src/main/java/com/wizardlybump17/wlib/command/extractor/method/MethodCommandExtractor.java b/commands/src/main/java/com/wizardlybump17/wlib/command/extractor/method/MethodCommandExtractor.java index ecd69d1b..1dbf82b3 100644 --- a/commands/src/main/java/com/wizardlybump17/wlib/command/extractor/method/MethodCommandExtractor.java +++ b/commands/src/main/java/com/wizardlybump17/wlib/command/extractor/method/MethodCommandExtractor.java @@ -135,7 +135,7 @@ public boolean isAccepted(@NotNull Object object) { */ private static @NotNull CommandNodeExecutor createExecutor(@NotNull Object object, @NotNull Parameter @NotNull [] parameters, @NotNull Class returnType, @NotNull Method method) { if (parameters.length == 0) { //no parameters - if (returnType.isAssignableFrom(CommandResult.class)) { //CommandResult return type + if (CommandResult.class.isAssignableFrom(returnType)) { //CommandResult return type return new AbstractMethodCommandNodeExecutor.NoArgumentsCommandResultExecutor<>(object, method); } else { return new AbstractMethodCommandNodeExecutor.NoArgumentsExecutor<>(object, method); @@ -146,14 +146,14 @@ public boolean isAccepted(@NotNull Object object) { Class firstParameterType = firstParameter.getType(); if (parameters.length == 1) { - if (firstParameterType.isAssignableFrom(CommandSender.class)) { //CommandSender only - if (returnType.isAssignableFrom(CommandResult.class)) { //CommandResult return type + if (CommandSender.class.isAssignableFrom(firstParameterType)) { //CommandSender only + if (CommandResult.class.isAssignableFrom(returnType)) { //CommandResult return type return new AbstractMethodCommandNodeExecutor.CommandSenderCommandResultExecutor<>(object, method); } else { //anything else return type return new AbstractMethodCommandNodeExecutor.CommandSenderExecutor<>(object, method); } - } else if (firstParameterType.isAssignableFrom(CommandContext.class)) { //CommandContext only - if (returnType.isAssignableFrom(CommandResult.class)) { //CommandResult return type + } else if (CommandContext.class.isAssignableFrom(returnType)) { //CommandContext only + if (CommandResult.class.isAssignableFrom(returnType)) { //CommandResult return type return new AbstractMethodCommandNodeExecutor.CommandContextCommandResultExecutor<>(object, method); } else { //anything else return type return new AbstractMethodCommandNodeExecutor.CommandContextExecutor<>(object, method); @@ -161,20 +161,20 @@ public boolean isAccepted(@NotNull Object object) { } } - if (firstParameterType.isAssignableFrom(CommandSender.class)) { //CommandSender + more arguments - if (returnType.isAssignableFrom(CommandResult.class)) { //CommandResult return type + if (CommandSender.class.isAssignableFrom(firstParameterType)) { //CommandSender + more arguments + if (CommandResult.class.isAssignableFrom(returnType)) { //CommandResult return type return new AbstractMethodCommandNodeExecutor.CommandSenderAndArgumentsCommandResultExecutor<>(object, method); } else { //anything else return type return new AbstractMethodCommandNodeExecutor.CommandSenderAndArgumentsExecutor<>(object, method); } - } else if (firstParameterType.isAssignableFrom(CommandContext.class)) { //CommandContext + more arguments - if (returnType.isAssignableFrom(CommandResult.class)) { //CommandResult return type + } else if (CommandContext.class.isAssignableFrom(returnType)) { //CommandContext + more arguments + if (CommandResult.class.isAssignableFrom(returnType)) { //CommandResult return type return new AbstractMethodCommandNodeExecutor.CommandContextAndArgumentsCommandResultExecutor<>(object, method); } else { //anything else return type return new AbstractMethodCommandNodeExecutor.CommandContextAndArgumentsExecutor<>(object, method); } } else { - if (returnType.isAssignableFrom(CommandResult.class)) { //CommandResult return type + if (CommandResult.class.isAssignableFrom(returnType)) { //CommandResult return type return new AbstractMethodCommandNodeExecutor.ArgumentsCommandResultExecutor<>(object, method); } else { //anything else return type return new AbstractMethodCommandNodeExecutor.ArgumentsExecutor<>(object, method); From f84fd3c1a54952ef53c763d593db8177c57f93bb Mon Sep 17 00:00:00 2001 From: WizardlyBump17 Date: Tue, 9 Dec 2025 18:59:49 -0300 Subject: [PATCH 221/363] fuck 2 --- .../wlib/command/extractor/method/MethodCommandExtractor.java | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/commands/src/main/java/com/wizardlybump17/wlib/command/extractor/method/MethodCommandExtractor.java b/commands/src/main/java/com/wizardlybump17/wlib/command/extractor/method/MethodCommandExtractor.java index 1dbf82b3..afd1c784 100644 --- a/commands/src/main/java/com/wizardlybump17/wlib/command/extractor/method/MethodCommandExtractor.java +++ b/commands/src/main/java/com/wizardlybump17/wlib/command/extractor/method/MethodCommandExtractor.java @@ -152,7 +152,7 @@ public boolean isAccepted(@NotNull Object object) { } else { //anything else return type return new AbstractMethodCommandNodeExecutor.CommandSenderExecutor<>(object, method); } - } else if (CommandContext.class.isAssignableFrom(returnType)) { //CommandContext only + } else if (CommandContext.class.isAssignableFrom(firstParameterType)) { //CommandContext only if (CommandResult.class.isAssignableFrom(returnType)) { //CommandResult return type return new AbstractMethodCommandNodeExecutor.CommandContextCommandResultExecutor<>(object, method); } else { //anything else return type @@ -167,7 +167,7 @@ public boolean isAccepted(@NotNull Object object) { } else { //anything else return type return new AbstractMethodCommandNodeExecutor.CommandSenderAndArgumentsExecutor<>(object, method); } - } else if (CommandContext.class.isAssignableFrom(returnType)) { //CommandContext + more arguments + } else if (CommandContext.class.isAssignableFrom(firstParameterType)) { //CommandContext + more arguments if (CommandResult.class.isAssignableFrom(returnType)) { //CommandResult return type return new AbstractMethodCommandNodeExecutor.CommandContextAndArgumentsCommandResultExecutor<>(object, method); } else { //anything else return type From 91d7a398586daa1e7e2bd6f2fb58128a1f2689f0 Mon Sep 17 00:00:00 2001 From: WizardlyBump17 Date: Tue, 9 Dec 2025 19:17:13 -0300 Subject: [PATCH 222/363] starting a better suggestion system --- .../wlib/command/suggestion/Suggester.java | 14 ++++++++++++++ 1 file changed, 14 insertions(+) create mode 100644 commands/src/main/java/com/wizardlybump17/wlib/command/suggestion/Suggester.java diff --git a/commands/src/main/java/com/wizardlybump17/wlib/command/suggestion/Suggester.java b/commands/src/main/java/com/wizardlybump17/wlib/command/suggestion/Suggester.java new file mode 100644 index 00000000..f594c59c --- /dev/null +++ b/commands/src/main/java/com/wizardlybump17/wlib/command/suggestion/Suggester.java @@ -0,0 +1,14 @@ +package com.wizardlybump17.wlib.command.suggestion; + +import com.wizardlybump17.wlib.command.node.CommandNode; +import com.wizardlybump17.wlib.command.sender.CommandSender; +import org.jetbrains.annotations.NotNull; + +import java.util.List; + +public interface Suggester { + + @NotNull List getSuggestions(@NotNull CommandSender sender, @NotNull List input, @NotNull String current, @NotNull CommandNode currentNode); + + @NotNull String getStringRepresentation(@NotNull T value); +} From fbeaec20de9b6db9831a30be094023bff0ade1bc Mon Sep 17 00:00:00 2001 From: WizardlyBump17 Date: Tue, 9 Dec 2025 19:55:17 -0300 Subject: [PATCH 223/363] added some suggestions --- .../suggestion/AbstractValuesSuggester.java | 26 ++++++++++++ .../wlib/command/suggestion/Suggester.java | 4 +- .../command/suggestion/ValuesSuggester.java | 10 +++++ .../suggestion/object/UUIDSuggester.java | 37 +++++++++++++++++ .../primitive/PrimitiveSuggester.java | 6 +++ .../primitive/number/ByteSuggester.java | 40 +++++++++++++++++++ .../primitive/number/DoubleSuggester.java | 40 +++++++++++++++++++ .../primitive/number/FloatSuggester.java | 40 +++++++++++++++++++ .../primitive/number/IntegerSuggester.java | 40 +++++++++++++++++++ .../primitive/number/LongSuggester.java | 40 +++++++++++++++++++ .../primitive/number/NumberSuggester.java | 6 +++ .../primitive/number/ShortSuggester.java | 40 +++++++++++++++++++ .../suggestion/string/StringSuggester.java | 36 +++++++++++++++++ 13 files changed, 364 insertions(+), 1 deletion(-) create mode 100644 commands/src/main/java/com/wizardlybump17/wlib/command/suggestion/AbstractValuesSuggester.java create mode 100644 commands/src/main/java/com/wizardlybump17/wlib/command/suggestion/ValuesSuggester.java create mode 100644 commands/src/main/java/com/wizardlybump17/wlib/command/suggestion/object/UUIDSuggester.java create mode 100644 commands/src/main/java/com/wizardlybump17/wlib/command/suggestion/primitive/PrimitiveSuggester.java create mode 100644 commands/src/main/java/com/wizardlybump17/wlib/command/suggestion/primitive/number/ByteSuggester.java create mode 100644 commands/src/main/java/com/wizardlybump17/wlib/command/suggestion/primitive/number/DoubleSuggester.java create mode 100644 commands/src/main/java/com/wizardlybump17/wlib/command/suggestion/primitive/number/FloatSuggester.java create mode 100644 commands/src/main/java/com/wizardlybump17/wlib/command/suggestion/primitive/number/IntegerSuggester.java create mode 100644 commands/src/main/java/com/wizardlybump17/wlib/command/suggestion/primitive/number/LongSuggester.java create mode 100644 commands/src/main/java/com/wizardlybump17/wlib/command/suggestion/primitive/number/NumberSuggester.java create mode 100644 commands/src/main/java/com/wizardlybump17/wlib/command/suggestion/primitive/number/ShortSuggester.java create mode 100644 commands/src/main/java/com/wizardlybump17/wlib/command/suggestion/string/StringSuggester.java diff --git a/commands/src/main/java/com/wizardlybump17/wlib/command/suggestion/AbstractValuesSuggester.java b/commands/src/main/java/com/wizardlybump17/wlib/command/suggestion/AbstractValuesSuggester.java new file mode 100644 index 00000000..b1a148b2 --- /dev/null +++ b/commands/src/main/java/com/wizardlybump17/wlib/command/suggestion/AbstractValuesSuggester.java @@ -0,0 +1,26 @@ +package com.wizardlybump17.wlib.command.suggestion; + +import com.wizardlybump17.wlib.command.node.CommandNode; +import com.wizardlybump17.wlib.command.sender.CommandSender; +import org.jetbrains.annotations.NotNull; + +import java.util.List; + +public abstract class AbstractValuesSuggester implements ValuesSuggester { + + private final @NotNull List suggestions; + + public AbstractValuesSuggester(@NotNull List suggestions) { + this.suggestions = List.copyOf(suggestions); + } + + @Override + public @NotNull List getSuggestions(@NotNull CommandSender sender, @NotNull List input, @NotNull String current, @NotNull CommandNode currentNode) { + return suggestions; + } + + @Override + public @NotNull List values() { + return suggestions; + } +} diff --git a/commands/src/main/java/com/wizardlybump17/wlib/command/suggestion/Suggester.java b/commands/src/main/java/com/wizardlybump17/wlib/command/suggestion/Suggester.java index f594c59c..dcb79b27 100644 --- a/commands/src/main/java/com/wizardlybump17/wlib/command/suggestion/Suggester.java +++ b/commands/src/main/java/com/wizardlybump17/wlib/command/suggestion/Suggester.java @@ -10,5 +10,7 @@ public interface Suggester { @NotNull List getSuggestions(@NotNull CommandSender sender, @NotNull List input, @NotNull String current, @NotNull CommandNode currentNode); - @NotNull String getStringRepresentation(@NotNull T value); + default @NotNull String getStringRepresentation(@NotNull T value) { + return value.toString(); + } } diff --git a/commands/src/main/java/com/wizardlybump17/wlib/command/suggestion/ValuesSuggester.java b/commands/src/main/java/com/wizardlybump17/wlib/command/suggestion/ValuesSuggester.java new file mode 100644 index 00000000..18b41826 --- /dev/null +++ b/commands/src/main/java/com/wizardlybump17/wlib/command/suggestion/ValuesSuggester.java @@ -0,0 +1,10 @@ +package com.wizardlybump17.wlib.command.suggestion; + +import org.jetbrains.annotations.NotNull; + +import java.util.List; + +public interface ValuesSuggester extends Suggester { + + @NotNull List values(); +} diff --git a/commands/src/main/java/com/wizardlybump17/wlib/command/suggestion/object/UUIDSuggester.java b/commands/src/main/java/com/wizardlybump17/wlib/command/suggestion/object/UUIDSuggester.java new file mode 100644 index 00000000..062a1c24 --- /dev/null +++ b/commands/src/main/java/com/wizardlybump17/wlib/command/suggestion/object/UUIDSuggester.java @@ -0,0 +1,37 @@ +package com.wizardlybump17.wlib.command.suggestion.object; + +import com.wizardlybump17.wlib.command.suggestion.AbstractValuesSuggester; +import com.wizardlybump17.wlib.command.suggestion.Suggester; +import org.jetbrains.annotations.NotNull; + +import java.util.List; +import java.util.UUID; + +public interface UUIDSuggester extends Suggester { + + static @NotNull Values value(@NotNull UUID value) { + return new Values(List.of(value)); + } + + static @NotNull Values values(@NotNull List values) { + return new Values(values); + } + + static @NotNull Values values(UUID... values) { + return new Values(List.of(values)); + } + + final class Values extends AbstractValuesSuggester implements UUIDSuggester { + + Values(@NotNull List values) { + super(values); + } + + @Override + public String toString() { + return "UUIDSuggester$Values{" + + "values=" + values() + + '}'; + } + } +} diff --git a/commands/src/main/java/com/wizardlybump17/wlib/command/suggestion/primitive/PrimitiveSuggester.java b/commands/src/main/java/com/wizardlybump17/wlib/command/suggestion/primitive/PrimitiveSuggester.java new file mode 100644 index 00000000..568178db --- /dev/null +++ b/commands/src/main/java/com/wizardlybump17/wlib/command/suggestion/primitive/PrimitiveSuggester.java @@ -0,0 +1,6 @@ +package com.wizardlybump17.wlib.command.suggestion.primitive; + +import com.wizardlybump17.wlib.command.suggestion.Suggester; + +public interface PrimitiveSuggester extends Suggester { +} diff --git a/commands/src/main/java/com/wizardlybump17/wlib/command/suggestion/primitive/number/ByteSuggester.java b/commands/src/main/java/com/wizardlybump17/wlib/command/suggestion/primitive/number/ByteSuggester.java new file mode 100644 index 00000000..9623c23e --- /dev/null +++ b/commands/src/main/java/com/wizardlybump17/wlib/command/suggestion/primitive/number/ByteSuggester.java @@ -0,0 +1,40 @@ +package com.wizardlybump17.wlib.command.suggestion.primitive.number; + +import com.wizardlybump17.wlib.command.suggestion.AbstractValuesSuggester; +import com.wizardlybump17.wlib.command.suggestion.primitive.PrimitiveSuggester; +import org.jetbrains.annotations.NotNull; + +import java.util.ArrayList; +import java.util.List; + +public interface ByteSuggester extends PrimitiveSuggester, NumberSuggester { + + static @NotNull Values value(byte value) { + return new Values(List.of(value)); + } + + static @NotNull Values values(@NotNull List values) { + return new Values(values); + } + + static @NotNull Values values(byte @NotNull ... values) { + List list = new ArrayList<>(values.length); + for (byte value : values) + list.add(value); + return new Values(List.copyOf(list)); + } + + final class Values extends AbstractValuesSuggester implements ByteSuggester { + + Values(@NotNull List values) { + super(values); + } + + @Override + public String toString() { + return "ByteSuggester$Values{" + + "values=" + values() + + '}'; + } + } +} diff --git a/commands/src/main/java/com/wizardlybump17/wlib/command/suggestion/primitive/number/DoubleSuggester.java b/commands/src/main/java/com/wizardlybump17/wlib/command/suggestion/primitive/number/DoubleSuggester.java new file mode 100644 index 00000000..d61d12b9 --- /dev/null +++ b/commands/src/main/java/com/wizardlybump17/wlib/command/suggestion/primitive/number/DoubleSuggester.java @@ -0,0 +1,40 @@ +package com.wizardlybump17.wlib.command.suggestion.primitive.number; + +import com.wizardlybump17.wlib.command.suggestion.AbstractValuesSuggester; +import com.wizardlybump17.wlib.command.suggestion.primitive.PrimitiveSuggester; +import org.jetbrains.annotations.NotNull; + +import java.util.ArrayList; +import java.util.List; + +public interface DoubleSuggester extends PrimitiveSuggester, NumberSuggester { + + static @NotNull Values value(double value) { + return new Values(List.of(value)); + } + + static @NotNull Values values(@NotNull List values) { + return new Values(values); + } + + static @NotNull Values values(double @NotNull ... values) { + List list = new ArrayList<>(values.length); + for (double value : values) + list.add(value); + return new Values(List.copyOf(list)); + } + + final class Values extends AbstractValuesSuggester implements DoubleSuggester { + + Values(@NotNull List values) { + super(values); + } + + @Override + public String toString() { + return "DoubleSuggester$Values{" + + "values=" + values() + + '}'; + } + } +} diff --git a/commands/src/main/java/com/wizardlybump17/wlib/command/suggestion/primitive/number/FloatSuggester.java b/commands/src/main/java/com/wizardlybump17/wlib/command/suggestion/primitive/number/FloatSuggester.java new file mode 100644 index 00000000..2819a32d --- /dev/null +++ b/commands/src/main/java/com/wizardlybump17/wlib/command/suggestion/primitive/number/FloatSuggester.java @@ -0,0 +1,40 @@ +package com.wizardlybump17.wlib.command.suggestion.primitive.number; + +import com.wizardlybump17.wlib.command.suggestion.AbstractValuesSuggester; +import com.wizardlybump17.wlib.command.suggestion.primitive.PrimitiveSuggester; +import org.jetbrains.annotations.NotNull; + +import java.util.ArrayList; +import java.util.List; + +public interface FloatSuggester extends PrimitiveSuggester, NumberSuggester { + + static @NotNull Values value(float value) { + return new Values(List.of(value)); + } + + static @NotNull Values values(@NotNull List values) { + return new Values(values); + } + + static @NotNull Values values(float @NotNull ... values) { + List list = new ArrayList<>(values.length); + for (float value : values) + list.add(value); + return new Values(List.copyOf(list)); + } + + final class Values extends AbstractValuesSuggester implements FloatSuggester { + + Values(@NotNull List values) { + super(values); + } + + @Override + public String toString() { + return "FloatSuggester$Values{" + + "values=" + values() + + '}'; + } + } +} diff --git a/commands/src/main/java/com/wizardlybump17/wlib/command/suggestion/primitive/number/IntegerSuggester.java b/commands/src/main/java/com/wizardlybump17/wlib/command/suggestion/primitive/number/IntegerSuggester.java new file mode 100644 index 00000000..7fb9abe2 --- /dev/null +++ b/commands/src/main/java/com/wizardlybump17/wlib/command/suggestion/primitive/number/IntegerSuggester.java @@ -0,0 +1,40 @@ +package com.wizardlybump17.wlib.command.suggestion.primitive.number; + +import com.wizardlybump17.wlib.command.suggestion.AbstractValuesSuggester; +import com.wizardlybump17.wlib.command.suggestion.primitive.PrimitiveSuggester; +import org.jetbrains.annotations.NotNull; + +import java.util.ArrayList; +import java.util.List; + +public interface IntegerSuggester extends PrimitiveSuggester, NumberSuggester { + + static @NotNull Values value(int value) { + return new Values(List.of(value)); + } + + static @NotNull Values values(@NotNull List values) { + return new Values(values); + } + + static @NotNull Values values(int @NotNull ... values) { + List list = new ArrayList<>(values.length); + for (int value : values) + list.add(value); + return new Values(List.copyOf(list)); + } + + final class Values extends AbstractValuesSuggester implements IntegerSuggester { + + Values(@NotNull List values) { + super(values); + } + + @Override + public String toString() { + return "IntegerSuggester$Values{" + + "values=" + values() + + '}'; + } + } +} diff --git a/commands/src/main/java/com/wizardlybump17/wlib/command/suggestion/primitive/number/LongSuggester.java b/commands/src/main/java/com/wizardlybump17/wlib/command/suggestion/primitive/number/LongSuggester.java new file mode 100644 index 00000000..13c2b6cd --- /dev/null +++ b/commands/src/main/java/com/wizardlybump17/wlib/command/suggestion/primitive/number/LongSuggester.java @@ -0,0 +1,40 @@ +package com.wizardlybump17.wlib.command.suggestion.primitive.number; + +import com.wizardlybump17.wlib.command.suggestion.AbstractValuesSuggester; +import com.wizardlybump17.wlib.command.suggestion.primitive.PrimitiveSuggester; +import org.jetbrains.annotations.NotNull; + +import java.util.ArrayList; +import java.util.List; + +public interface LongSuggester extends PrimitiveSuggester, NumberSuggester { + + static @NotNull Values value(long value) { + return new Values(List.of(value)); + } + + static @NotNull Values values(@NotNull List values) { + return new Values(values); + } + + static @NotNull Values values(long @NotNull ... values) { + List list = new ArrayList<>(values.length); + for (long value : values) + list.add(value); + return new Values(List.copyOf(list)); + } + + final class Values extends AbstractValuesSuggester implements LongSuggester { + + Values(@NotNull List values) { + super(values); + } + + @Override + public String toString() { + return "LongSuggester$Values{" + + "values=" + values() + + '}'; + } + } +} diff --git a/commands/src/main/java/com/wizardlybump17/wlib/command/suggestion/primitive/number/NumberSuggester.java b/commands/src/main/java/com/wizardlybump17/wlib/command/suggestion/primitive/number/NumberSuggester.java new file mode 100644 index 00000000..de51aecb --- /dev/null +++ b/commands/src/main/java/com/wizardlybump17/wlib/command/suggestion/primitive/number/NumberSuggester.java @@ -0,0 +1,6 @@ +package com.wizardlybump17.wlib.command.suggestion.primitive.number; + +import com.wizardlybump17.wlib.command.suggestion.Suggester; + +public interface NumberSuggester extends Suggester { +} diff --git a/commands/src/main/java/com/wizardlybump17/wlib/command/suggestion/primitive/number/ShortSuggester.java b/commands/src/main/java/com/wizardlybump17/wlib/command/suggestion/primitive/number/ShortSuggester.java new file mode 100644 index 00000000..805b7c34 --- /dev/null +++ b/commands/src/main/java/com/wizardlybump17/wlib/command/suggestion/primitive/number/ShortSuggester.java @@ -0,0 +1,40 @@ +package com.wizardlybump17.wlib.command.suggestion.primitive.number; + +import com.wizardlybump17.wlib.command.suggestion.AbstractValuesSuggester; +import com.wizardlybump17.wlib.command.suggestion.primitive.PrimitiveSuggester; +import org.jetbrains.annotations.NotNull; + +import java.util.ArrayList; +import java.util.List; + +public interface ShortSuggester extends PrimitiveSuggester, NumberSuggester { + + static @NotNull Values value(short value) { + return new Values(List.of(value)); + } + + static @NotNull Values values(@NotNull List values) { + return new Values(values); + } + + static @NotNull Values values(short @NotNull ... values) { + List list = new ArrayList<>(values.length); + for (short value : values) + list.add(value); + return new Values(List.copyOf(list)); + } + + final class Values extends AbstractValuesSuggester implements ShortSuggester { + + Values(@NotNull List values) { + super(values); + } + + @Override + public String toString() { + return "ShortSuggester$Values{" + + "values=" + values() + + '}'; + } + } +} diff --git a/commands/src/main/java/com/wizardlybump17/wlib/command/suggestion/string/StringSuggester.java b/commands/src/main/java/com/wizardlybump17/wlib/command/suggestion/string/StringSuggester.java new file mode 100644 index 00000000..dbecab84 --- /dev/null +++ b/commands/src/main/java/com/wizardlybump17/wlib/command/suggestion/string/StringSuggester.java @@ -0,0 +1,36 @@ +package com.wizardlybump17.wlib.command.suggestion.string; + +import com.wizardlybump17.wlib.command.suggestion.AbstractValuesSuggester; +import com.wizardlybump17.wlib.command.suggestion.primitive.PrimitiveSuggester; +import org.jetbrains.annotations.NotNull; + +import java.util.List; + +public interface StringSuggester extends PrimitiveSuggester { + + static @NotNull Values value(String value) { + return new Values(List.of(value)); + } + + static @NotNull Values values(@NotNull List values) { + return new Values(values); + } + + static @NotNull Values values(String @NotNull ... values) { + return new Values(List.of(values)); + } + + final class Values extends AbstractValuesSuggester implements StringSuggester { + + Values(@NotNull List values) { + super(values); + } + + @Override + public String toString() { + return "StringSuggester$Values{" + + "values=" + values() + + '}'; + } + } +} From acee67a085bab3d2c5c48c26a9655829e0f9c45b Mon Sep 17 00:00:00 2001 From: WizardlyBump17 Date: Tue, 9 Dec 2025 19:56:10 -0300 Subject: [PATCH 224/363] toString --- .../suggestion/AbstractValuesSuggester.java | 21 +++++++++++++++++++ 1 file changed, 21 insertions(+) diff --git a/commands/src/main/java/com/wizardlybump17/wlib/command/suggestion/AbstractValuesSuggester.java b/commands/src/main/java/com/wizardlybump17/wlib/command/suggestion/AbstractValuesSuggester.java index b1a148b2..8e081a11 100644 --- a/commands/src/main/java/com/wizardlybump17/wlib/command/suggestion/AbstractValuesSuggester.java +++ b/commands/src/main/java/com/wizardlybump17/wlib/command/suggestion/AbstractValuesSuggester.java @@ -5,6 +5,7 @@ import org.jetbrains.annotations.NotNull; import java.util.List; +import java.util.Objects; public abstract class AbstractValuesSuggester implements ValuesSuggester { @@ -23,4 +24,24 @@ public AbstractValuesSuggester(@NotNull List suggestions) { public @NotNull List values() { return suggestions; } + + @Override + public boolean equals(Object object) { + if (object == null || getClass() != object.getClass()) + return false; + AbstractValuesSuggester that = (AbstractValuesSuggester) object; + return Objects.equals(suggestions, that.suggestions); + } + + @Override + public int hashCode() { + return Objects.hashCode(suggestions); + } + + @Override + public String toString() { + return "AbstractValuesSuggester{" + + "suggestions=" + suggestions + + '}'; + } } From bb354c25ce7f37655244e40c492381fbc31b66ee Mon Sep 17 00:00:00 2001 From: WizardlyBump17 Date: Tue, 9 Dec 2025 20:31:16 -0300 Subject: [PATCH 225/363] working on the suggestion system --- .../wlib/command/input/AllowedInputs.java | 8 --- .../wlib/command/input/SingleValueInput.java | 8 --- .../primitive/number/AllowedByteInputs.java | 56 --------------- .../primitive/number/AllowedDoubleInputs.java | 64 ----------------- .../primitive/number/AllowedFloatInputs.java | 64 ----------------- .../number/AllowedIntegerInputs.java | 55 --------------- .../primitive/number/AllowedLongInputs.java | 64 ----------------- .../primitive/number/AllowedShortInputs.java | 60 ---------------- .../primitive/BooleanSuggester.java | 70 +++++++++++++++++++ .../primitive/CharacterSuggester.java | 64 +++++++++++++++++ .../primitive/number/ByteSuggester.java | 53 ++++++++++++++ .../primitive/number/DoubleSuggester.java | 50 +++++++++++++ .../primitive/number/FloatSuggester.java | 50 +++++++++++++ .../primitive/number/IntegerSuggester.java | 58 +++++++++++++++ .../primitive/number/LongSuggester.java | 61 ++++++++++++++++ .../primitive/number/ShortSuggester.java | 57 +++++++++++++++ .../suggestion/string/StringSuggester.java | 16 +++++ 17 files changed, 479 insertions(+), 379 deletions(-) create mode 100644 commands/src/main/java/com/wizardlybump17/wlib/command/suggestion/primitive/BooleanSuggester.java create mode 100644 commands/src/main/java/com/wizardlybump17/wlib/command/suggestion/primitive/CharacterSuggester.java diff --git a/commands/src/main/java/com/wizardlybump17/wlib/command/input/AllowedInputs.java b/commands/src/main/java/com/wizardlybump17/wlib/command/input/AllowedInputs.java index 65ce2053..3aef4108 100644 --- a/commands/src/main/java/com/wizardlybump17/wlib/command/input/AllowedInputs.java +++ b/commands/src/main/java/com/wizardlybump17/wlib/command/input/AllowedInputs.java @@ -1,16 +1,8 @@ package com.wizardlybump17.wlib.command.input; -import com.wizardlybump17.wlib.command.sender.CommandSender; -import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.Nullable; -import java.util.List; - public interface AllowedInputs { boolean isAllowed(@Nullable T input); - - default @NotNull List getSuggestions(@NotNull CommandSender sender, @NotNull List input, @NotNull String current) { - return List.of(); - } } diff --git a/commands/src/main/java/com/wizardlybump17/wlib/command/input/SingleValueInput.java b/commands/src/main/java/com/wizardlybump17/wlib/command/input/SingleValueInput.java index 4a4b87e7..a78c8a29 100644 --- a/commands/src/main/java/com/wizardlybump17/wlib/command/input/SingleValueInput.java +++ b/commands/src/main/java/com/wizardlybump17/wlib/command/input/SingleValueInput.java @@ -1,11 +1,8 @@ package com.wizardlybump17.wlib.command.input; -import com.wizardlybump17.wlib.command.sender.CommandSender; import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.Nullable; -import java.util.List; - public interface SingleValueInput extends AllowedInputs { @NotNull T value(); @@ -14,9 +11,4 @@ public interface SingleValueInput extends AllowedInputs { default boolean isAllowed(@Nullable T input) { return value().equals(input); } - - @Override - default @NotNull List getSuggestions(@NotNull CommandSender sender, @NotNull List input, @NotNull String current) { - return List.of(value()); - } } diff --git a/commands/src/main/java/com/wizardlybump17/wlib/command/input/primitive/number/AllowedByteInputs.java b/commands/src/main/java/com/wizardlybump17/wlib/command/input/primitive/number/AllowedByteInputs.java index 7aea615d..93d349d9 100644 --- a/commands/src/main/java/com/wizardlybump17/wlib/command/input/primitive/number/AllowedByteInputs.java +++ b/commands/src/main/java/com/wizardlybump17/wlib/command/input/primitive/number/AllowedByteInputs.java @@ -1,7 +1,6 @@ package com.wizardlybump17.wlib.command.input.primitive.number; import com.wizardlybump17.wlib.command.input.primitive.PrimitiveAllowedInputs; -import com.wizardlybump17.wlib.command.sender.CommandSender; import org.jetbrains.annotations.NotNull; import java.util.List; @@ -40,28 +39,6 @@ final class Range extends AllowedNumberInputs.Ranged implements AllowedByt throw new IllegalArgumentException("from must be less than to"); } - @Override - public @NotNull List getSuggestions(@NotNull CommandSender sender, @NotNull List input, @NotNull String current) { - byte to = to(); - byte from = from(); - - if (to - from < 5) { - Byte[] bytes = new Byte[to - from]; - for (int i = 0; i < bytes.length; i++) - bytes[i] = (byte) (to - from - i); - return List.of(bytes); - } - - byte fourth = (byte) ((to - from) / 4); - return List.of( - from, - (byte) (from + fourth), - (byte) (from + fourth * 2), - (byte) (from + fourth * 3), - to - ); - } - @Override public String toString() { return "AllowedByteInputs$Range{" + @@ -78,19 +55,6 @@ final class Unlimited extends AllowedNumberInputs.Unlimited implements All private Unlimited() { } - @Override - public @NotNull List getSuggestions(@NotNull CommandSender sender, @NotNull List input, @NotNull String current) { - return List.of( - (byte) -128, - (byte) -100, - (byte) -50, - (byte) 0, - (byte) 50, - (byte) 100, - (byte) 127 - ); - } - @Override public String toString() { return "AllowedByteInputs$Unlimited{}"; @@ -119,16 +83,6 @@ public boolean isInRange(@NotNull Byte input) { return input > -1; } - @Override - public @NotNull List getSuggestions(@NotNull CommandSender sender, @NotNull List input, @NotNull String current) { - return List.of( - (byte) 0, - (byte) 50, - (byte) 100, - (byte) 127 - ); - } - @Override public String toString() { return "AllowedByteInputs$Positive{}"; @@ -157,16 +111,6 @@ public boolean isInRange(@NotNull Byte input) { return input < 0; } - @Override - public @NotNull List getSuggestions(@NotNull CommandSender sender, @NotNull List input, @NotNull String current) { - return List.of( - (byte) -128, - (byte) -100, - (byte) -50, - (byte) -1 - ); - } - @Override public String toString() { return "AllowedByteInputs$Negative{}"; diff --git a/commands/src/main/java/com/wizardlybump17/wlib/command/input/primitive/number/AllowedDoubleInputs.java b/commands/src/main/java/com/wizardlybump17/wlib/command/input/primitive/number/AllowedDoubleInputs.java index aa563883..e4124abc 100644 --- a/commands/src/main/java/com/wizardlybump17/wlib/command/input/primitive/number/AllowedDoubleInputs.java +++ b/commands/src/main/java/com/wizardlybump17/wlib/command/input/primitive/number/AllowedDoubleInputs.java @@ -1,7 +1,6 @@ package com.wizardlybump17.wlib.command.input.primitive.number; import com.wizardlybump17.wlib.command.input.primitive.PrimitiveAllowedInputs; -import com.wizardlybump17.wlib.command.sender.CommandSender; import org.jetbrains.annotations.NotNull; import java.util.List; @@ -40,28 +39,6 @@ final class Range extends AllowedNumberInputs.Ranged implements AllowedD throw new IllegalArgumentException("from must be less than to"); } - @Override - public @NotNull List getSuggestions(@NotNull CommandSender sender, @NotNull List input, @NotNull String current) { - double to = to(); - double from = from(); - - if (to - from < 5) { - Double[] doubles = new Double[(int) (to - from)]; - for (int i = 0; i < doubles.length; i++) - doubles[i] = to - from - i; - return List.of(doubles); - } - - double fourth = (to - from) / 4; - return List.of( - from, - from + fourth, - from + fourth * 2, - from + fourth * 3, - to - ); - } - @Override public String toString() { return "AllowedByteInputs$Range{" + @@ -78,23 +55,6 @@ final class Unlimited extends AllowedNumberInputs.Unlimited implements A private Unlimited() { } - @Override - public @NotNull List getSuggestions(@NotNull CommandSender sender, @NotNull List input, @NotNull String current) { - return List.of( - -100000.5, - -50000.5, - -3000.5, - -200.5, - -50.5, - 0.0, - 50.5, - 200.5, - 3000.5, - 50000.5, - 100000.5 - ); - } - @Override public String toString() { return "AllowedDoubleInputs$Unlimited{}"; @@ -123,18 +83,6 @@ public boolean isInRange(@NotNull Double input) { return input > -1; } - @Override - public @NotNull List getSuggestions(@NotNull CommandSender sender, @NotNull List input, @NotNull String current) { - return List.of( - 0.0, - 50.5, - 200.5, - 3000.5, - 50000.5, - 100000.5 - ); - } - @Override public String toString() { return "AllowedDoubleInputs$Positive{}"; @@ -163,18 +111,6 @@ public boolean isInRange(@NotNull Double input) { return input < 0; } - @Override - public @NotNull List getSuggestions(@NotNull CommandSender sender, @NotNull List input, @NotNull String current) { - return List.of( - -100000.5, - -50000.5, - -3000.5, - -200.5, - -50.5, - -1.0 - ); - } - @Override public String toString() { return "AllowedDoubleInputs$Negative{}"; diff --git a/commands/src/main/java/com/wizardlybump17/wlib/command/input/primitive/number/AllowedFloatInputs.java b/commands/src/main/java/com/wizardlybump17/wlib/command/input/primitive/number/AllowedFloatInputs.java index e85316a8..f1c606a3 100644 --- a/commands/src/main/java/com/wizardlybump17/wlib/command/input/primitive/number/AllowedFloatInputs.java +++ b/commands/src/main/java/com/wizardlybump17/wlib/command/input/primitive/number/AllowedFloatInputs.java @@ -1,7 +1,6 @@ package com.wizardlybump17.wlib.command.input.primitive.number; import com.wizardlybump17.wlib.command.input.primitive.PrimitiveAllowedInputs; -import com.wizardlybump17.wlib.command.sender.CommandSender; import org.jetbrains.annotations.NotNull; import java.util.List; @@ -40,28 +39,6 @@ final class Range extends AllowedNumberInputs.Ranged implements AllowedFl throw new IllegalArgumentException("from must be less than to"); } - @Override - public @NotNull List getSuggestions(@NotNull CommandSender sender, @NotNull List input, @NotNull String current) { - float to = to(); - float from = from(); - - if (to - from < 5) { - Float[] floats = new Float[(int) (to - from)]; - for (int i = 0; i < floats.length; i++) - floats[i] = to - from - i; - return List.of(floats); - } - - float fourth = (to - from) / 4; - return List.of( - from, - from + fourth, - from + fourth * 2, - from + fourth * 3, - to - ); - } - @Override public String toString() { return "AllowedFloatInputs$Range{" + @@ -78,23 +55,6 @@ final class Unlimited extends AllowedNumberInputs.Unlimited implements Al private Unlimited() { } - @Override - public @NotNull List getSuggestions(@NotNull CommandSender sender, @NotNull List input, @NotNull String current) { - return List.of( - -100000.5F, - -50000.5F, - -3000.5F, - -200.5F, - -50.5F, - 0.0F, - 50.5F, - 200.5F, - 3000.5F, - 50000.5F, - 100000.5F - ); - } - @Override public String toString() { return "AllowedFloatInputs$Unlimited{}"; @@ -123,18 +83,6 @@ public boolean isInRange(@NotNull Float input) { return input > -1; } - @Override - public @NotNull List getSuggestions(@NotNull CommandSender sender, @NotNull List input, @NotNull String current) { - return List.of( - 0.0F, - 50.5F, - 200.5F, - 3000.5F, - 50000.5F, - 100000.5F - ); - } - @Override public String toString() { return "AllowedFloatInputs$Positive{}"; @@ -163,18 +111,6 @@ public boolean isInRange(@NotNull Float input) { return input < 0; } - @Override - public @NotNull List getSuggestions(@NotNull CommandSender sender, @NotNull List input, @NotNull String current) { - return List.of( - -100000.5F, - -50000.5F, - -3000.5F, - -200.5F, - -50.5F, - -1.0F - ); - } - @Override public String toString() { return "AllowedFloatInputs$Negative{}"; diff --git a/commands/src/main/java/com/wizardlybump17/wlib/command/input/primitive/number/AllowedIntegerInputs.java b/commands/src/main/java/com/wizardlybump17/wlib/command/input/primitive/number/AllowedIntegerInputs.java index c9a7ec45..87a2648b 100644 --- a/commands/src/main/java/com/wizardlybump17/wlib/command/input/primitive/number/AllowedIntegerInputs.java +++ b/commands/src/main/java/com/wizardlybump17/wlib/command/input/primitive/number/AllowedIntegerInputs.java @@ -1,11 +1,9 @@ package com.wizardlybump17.wlib.command.input.primitive.number; import com.wizardlybump17.wlib.command.input.primitive.PrimitiveAllowedInputs; -import com.wizardlybump17.wlib.command.sender.CommandSender; import org.jetbrains.annotations.NotNull; import java.util.List; -import java.util.stream.IntStream; public interface AllowedIntegerInputs extends PrimitiveAllowedInputs { @@ -41,18 +39,6 @@ final class Range extends AllowedNumberInputs.Ranged implements Allowed throw new IllegalArgumentException("from must be less than to"); } - @Override - public @NotNull List getSuggestions(@NotNull CommandSender sender, @NotNull List input, @NotNull String current) { - int to = to(); - int from = from(); - - if (to - from < 5) - return IntStream.rangeClosed(from, to).boxed().toList(); - - int fourth = (to - from) / 4; - return List.of(from, from + fourth, from + fourth * 2, from + fourth * 3, to); - } - @Override public String toString() { return "AllowedIntegerInputs$Range{" + @@ -69,23 +55,6 @@ final class Unlimited extends AllowedNumberInputs.Unlimited implements private Unlimited() { } - @Override - public @NotNull List getSuggestions(@NotNull CommandSender sender, @NotNull List input, @NotNull String current) { - return List.of( - -100000, - -50000, - -3000, - -200, - -50, - 0, - 50, - 200, - 3000, - 50000, - 100000 - ); - } - @Override public String toString() { return "AllowedIntegerInputs$Unlimited{}"; @@ -114,18 +83,6 @@ public boolean isInRange(@NotNull Integer input) { return input > -1; } - @Override - public @NotNull List getSuggestions(@NotNull CommandSender sender, @NotNull List input, @NotNull String current) { - return List.of( - 0, - 50, - 200, - 3000, - 50000, - 100000 - ); - } - @Override public String toString() { return "AllowedIntegerInputs$Positive{}"; @@ -154,18 +111,6 @@ public boolean isInRange(@NotNull Integer input) { return input < 0; } - @Override - public @NotNull List getSuggestions(@NotNull CommandSender sender, @NotNull List input, @NotNull String current) { - return List.of( - -100000, - -50000, - -3000, - -200, - -50, - -1 - ); - } - @Override public String toString() { return "AllowedIntegerInputs$Negative{}"; diff --git a/commands/src/main/java/com/wizardlybump17/wlib/command/input/primitive/number/AllowedLongInputs.java b/commands/src/main/java/com/wizardlybump17/wlib/command/input/primitive/number/AllowedLongInputs.java index 9b2fd357..080ecfc4 100644 --- a/commands/src/main/java/com/wizardlybump17/wlib/command/input/primitive/number/AllowedLongInputs.java +++ b/commands/src/main/java/com/wizardlybump17/wlib/command/input/primitive/number/AllowedLongInputs.java @@ -1,7 +1,6 @@ package com.wizardlybump17.wlib.command.input.primitive.number; import com.wizardlybump17.wlib.command.input.primitive.PrimitiveAllowedInputs; -import com.wizardlybump17.wlib.command.sender.CommandSender; import org.jetbrains.annotations.NotNull; import java.util.List; @@ -40,28 +39,6 @@ final class Range extends AllowedNumberInputs.Ranged implements AllowedLon throw new IllegalArgumentException("from must be less than to"); } - @Override - public @NotNull List getSuggestions(@NotNull CommandSender sender, @NotNull List input, @NotNull String current) { - long to = to(); - long from = from(); - - if (to - from < 5) { - Long[] longs = new Long[(int) (to - from)]; - for (int i = 0; i < longs.length; i++) - longs[i] = to - from - i; - return List.of(longs); - } - - long fourth = (to - from) / 4; - return List.of( - from, - from + fourth, - from + fourth * 2, - from + fourth * 3, - to - ); - } - @Override public String toString() { return "AllowedLongInputs$Range{" + @@ -78,23 +55,6 @@ final class Unlimited extends AllowedNumberInputs.Unlimited implements All private Unlimited() { } - @Override - public @NotNull List getSuggestions(@NotNull CommandSender sender, @NotNull List input, @NotNull String current) { - return List.of( - -100000L, - -50000L, - -3000L, - -200L, - -50L, - 0L, - 50L, - 200L, - 3000L, - 50000L, - 100000L - ); - } - @Override public String toString() { return "AllowedLongInputs$Unlimited{}"; @@ -123,18 +83,6 @@ public boolean isInRange(@NotNull Long input) { return input > -1; } - @Override - public @NotNull List getSuggestions(@NotNull CommandSender sender, @NotNull List input, @NotNull String current) { - return List.of( - 0L, - 50L, - 200L, - 3000L, - 50000L, - 100000L - ); - } - @Override public String toString() { return "AllowedLongInputs$Positive{}"; @@ -163,18 +111,6 @@ public boolean isInRange(@NotNull Long input) { return input < 0; } - @Override - public @NotNull List getSuggestions(@NotNull CommandSender sender, @NotNull List input, @NotNull String current) { - return List.of( - -100000L, - -50000L, - -3000L, - -200L, - -50L, - -1L - ); - } - @Override public String toString() { return "AllowedLongInputs$Negative{}"; diff --git a/commands/src/main/java/com/wizardlybump17/wlib/command/input/primitive/number/AllowedShortInputs.java b/commands/src/main/java/com/wizardlybump17/wlib/command/input/primitive/number/AllowedShortInputs.java index 506505f9..45ca67e6 100644 --- a/commands/src/main/java/com/wizardlybump17/wlib/command/input/primitive/number/AllowedShortInputs.java +++ b/commands/src/main/java/com/wizardlybump17/wlib/command/input/primitive/number/AllowedShortInputs.java @@ -1,7 +1,6 @@ package com.wizardlybump17.wlib.command.input.primitive.number; import com.wizardlybump17.wlib.command.input.primitive.PrimitiveAllowedInputs; -import com.wizardlybump17.wlib.command.sender.CommandSender; import org.jetbrains.annotations.NotNull; import java.util.List; @@ -40,28 +39,6 @@ final class Range extends AllowedNumberInputs.Ranged implements AllowedSh throw new IllegalArgumentException("from must be less than to"); } - @Override - public @NotNull List getSuggestions(@NotNull CommandSender sender, @NotNull List input, @NotNull String current) { - short to = to(); - short from = from(); - - if (to - from < 5) { - Short[] shorts = new Short[to - from]; - for (int i = 0; i < shorts.length; i++) - shorts[i] = (short) (to - from - i); - return List.of(shorts); - } - - short fourth = (short) ((to - from) / 4); - return List.of( - from, - (short) (from + fourth), - (short) (from + fourth * 2), - (short) (from + fourth * 3), - to - ); - } - @Override public String toString() { return "AllowedShortInputs$Range{" + @@ -78,21 +55,6 @@ final class Unlimited extends AllowedNumberInputs.Unlimited implements Al private Unlimited() { } - @Override - public @NotNull List getSuggestions(@NotNull CommandSender sender, @NotNull List input, @NotNull String current) { - return List.of( - (short) -32768, - (short) -3000, - (short) -100, - (short) -50, - (short) 0, - (short) 50, - (short) 100, - (short) 3000, - (short) 32767 - ); - } - @Override public String toString() { return "AllowedShortInputs$Unlimited{}"; @@ -121,17 +83,6 @@ public boolean isInRange(@NotNull Short input) { return input > -1; } - @Override - public @NotNull List getSuggestions(@NotNull CommandSender sender, @NotNull List input, @NotNull String current) { - return List.of( - (short) 0, - (short) 50, - (short) 100, - (short) 3000, - (short) 32767 - ); - } - @Override public String toString() { return "AllowedShortInputs$Positive{}"; @@ -160,17 +111,6 @@ public boolean isInRange(@NotNull Short input) { return input < 0; } - @Override - public @NotNull List getSuggestions(@NotNull CommandSender sender, @NotNull List input, @NotNull String current) { - return List.of( - (short) -32768, - (short) -3000, - (short) -100, - (short) -50, - (short) -1 - ); - } - @Override public String toString() { return "AllowedShortInputs$Negative{}"; diff --git a/commands/src/main/java/com/wizardlybump17/wlib/command/suggestion/primitive/BooleanSuggester.java b/commands/src/main/java/com/wizardlybump17/wlib/command/suggestion/primitive/BooleanSuggester.java new file mode 100644 index 00000000..1bbbdac2 --- /dev/null +++ b/commands/src/main/java/com/wizardlybump17/wlib/command/suggestion/primitive/BooleanSuggester.java @@ -0,0 +1,70 @@ +package com.wizardlybump17.wlib.command.suggestion.primitive; + +import com.wizardlybump17.wlib.command.node.CommandNode; +import com.wizardlybump17.wlib.command.sender.CommandSender; +import org.jetbrains.annotations.NotNull; + +import java.util.List; + +public interface BooleanSuggester extends PrimitiveSuggester { + + static @NotNull True trueValue() { + return True.INSTANCE; + } + + static @NotNull False falseValue() { + return False.INSTANCE; + } + + static @NotNull Any any() { + return Any.INSTANCE; + } + + final class True implements BooleanSuggester { + + private static final @NotNull List LIST = List.of(true); + private static final @NotNull True INSTANCE = new True(); + + @Override + public @NotNull List getSuggestions(@NotNull CommandSender sender, @NotNull List input, @NotNull String current, @NotNull CommandNode currentNode) { + return LIST; + } + + @Override + public String toString() { + return "BooleanSuggester$True{}"; + } + } + + final class False implements BooleanSuggester { + + private static final @NotNull List LIST = List.of(false); + private static final @NotNull False INSTANCE = new False(); + + @Override + public @NotNull List getSuggestions(@NotNull CommandSender sender, @NotNull List input, @NotNull String current, @NotNull CommandNode currentNode) { + return LIST; + } + + @Override + public String toString() { + return "BooleanSuggester$False{}"; + } + } + + final class Any implements BooleanSuggester { + + private static final @NotNull List LIST = List.of(true, false); + private static final @NotNull Any INSTANCE = new Any(); + + @Override + public @NotNull List getSuggestions(@NotNull CommandSender sender, @NotNull List input, @NotNull String current, @NotNull CommandNode currentNode) { + return LIST; + } + + @Override + public String toString() { + return "BooleanSuggester$Any{}"; + } + } +} diff --git a/commands/src/main/java/com/wizardlybump17/wlib/command/suggestion/primitive/CharacterSuggester.java b/commands/src/main/java/com/wizardlybump17/wlib/command/suggestion/primitive/CharacterSuggester.java new file mode 100644 index 00000000..dd220b21 --- /dev/null +++ b/commands/src/main/java/com/wizardlybump17/wlib/command/suggestion/primitive/CharacterSuggester.java @@ -0,0 +1,64 @@ +package com.wizardlybump17.wlib.command.suggestion.primitive; + +import com.wizardlybump17.wlib.command.suggestion.AbstractValuesSuggester; +import org.jetbrains.annotations.NotNull; + +import java.util.ArrayList; +import java.util.List; + +public interface CharacterSuggester extends PrimitiveSuggester { + + static @NotNull Values value(char value) { + return new Values(List.of(value)); + } + + static @NotNull Values values(@NotNull List values) { + return new Values(values); + } + + static @NotNull Values values(char @NotNull ... values) { + List list = new ArrayList<>(values.length); + for (char value : values) + list.add(value); + return new Values(List.copyOf(list)); + } + + static @NotNull Values range(char from, char to, int amount) { + if (to - from < amount) { + Character[] values = new Character[(int) (to - from)]; + for (int i = 0; i < values.length; i++) + values[i] = (char) (to - from - i); + return new Values(List.of(values)); + } + + char part = (char) ((to - from) / amount); + List values = new ArrayList<>(amount); + for (char i = 0; i < amount; i++) + values.add((char) (from + part * amount)); + return new Values(List.copyOf(values)); + } + + static @NotNull Values range(char from, char to) { + return range(from, to, 4); + } + + static @NotNull Values any() { + return Values.ANY; + } + + final class Values extends AbstractValuesSuggester implements CharacterSuggester { + + private static final @NotNull Values ANY = new Values(List.of()); + + Values(@NotNull List values) { + super(values); + } + + @Override + public String toString() { + return "CharacterSuggester$Values{" + + "values=" + values() + + '}'; + } + } +} diff --git a/commands/src/main/java/com/wizardlybump17/wlib/command/suggestion/primitive/number/ByteSuggester.java b/commands/src/main/java/com/wizardlybump17/wlib/command/suggestion/primitive/number/ByteSuggester.java index 9623c23e..5b6d9d25 100644 --- a/commands/src/main/java/com/wizardlybump17/wlib/command/suggestion/primitive/number/ByteSuggester.java +++ b/commands/src/main/java/com/wizardlybump17/wlib/command/suggestion/primitive/number/ByteSuggester.java @@ -24,8 +24,61 @@ public interface ByteSuggester extends PrimitiveSuggester, NumberSuggester return new Values(List.copyOf(list)); } + static @NotNull Values range(byte from, byte to, int amount) { + if (to - from < amount) { + Byte[] values = new Byte[to - from]; + for (int i = 0; i < values.length; i++) + values[i] = (byte) (to - from - i); + return new Values(List.of(values)); + } + + byte part = (byte) ((to - from) / amount); + List values = new ArrayList<>(amount); + for (int i = 0; i < amount; i++) + values.add((byte) (from + part * amount)); + return new Values(List.copyOf(values)); + } + + static @NotNull Values range(byte from, byte to) { + return range(from, to, 4); + } + + static @NotNull Values positive() { + return Values.POSITIVE; + } + + static @NotNull Values negative() { + return Values.NEGATIVE; + } + + static @NotNull Values unlimited() { + return Values.UNLIMITED; + } + final class Values extends AbstractValuesSuggester implements ByteSuggester { + private static final @NotNull Values POSITIVE = new Values(List.of( + (byte) 0, + (byte) 50, + (byte) 100, + (byte) 127 + )); + private static final @NotNull Values NEGATIVE = new Values(List.of( + (byte) -128, + (byte) -100, + (byte) -50, + (byte) -1 + )); + private static final @NotNull Values UNLIMITED = new Values(List.of( + (byte) -128, + (byte) -100, + (byte) -50, + (byte) 0, + (byte) 50, + (byte) 100, + (byte) 127 + )); + Values(@NotNull List values) { super(values); } diff --git a/commands/src/main/java/com/wizardlybump17/wlib/command/suggestion/primitive/number/DoubleSuggester.java b/commands/src/main/java/com/wizardlybump17/wlib/command/suggestion/primitive/number/DoubleSuggester.java index d61d12b9..58e45291 100644 --- a/commands/src/main/java/com/wizardlybump17/wlib/command/suggestion/primitive/number/DoubleSuggester.java +++ b/commands/src/main/java/com/wizardlybump17/wlib/command/suggestion/primitive/number/DoubleSuggester.java @@ -24,6 +24,56 @@ public interface DoubleSuggester extends PrimitiveSuggester, NumberSugge return new Values(List.copyOf(list)); } + static @NotNull Values range(double from, double to, int amount) { + double part = (to - from) / amount; + List values = new ArrayList<>(amount); + for (double i = 0; i < amount; i++) + values.add(from + part * amount); + return new Values(List.copyOf(values)); + } + + static @NotNull Values range(double from, double to) { + return range(from, to, 4); + } + + static @NotNull Values positive() { + return new Values(List.of( + 0.0, + 50.5, + 200.5, + 3000.5, + 50000.5, + 100000.5 + )); + } + + static @NotNull Values negative() { + return new Values(List.of( + -100000.5, + -50000.5, + -3000.5, + -200.5, + -50.5, + -1.0 + )); + } + + static @NotNull Values unlimited() { + return new Values(List.of( + -100000.5, + -50000.5, + -3000.5, + -200.5, + -50.5, + 0.0, + 50.5, + 200.5, + 3000.5, + 50000.5, + 100000.5 + )); + } + final class Values extends AbstractValuesSuggester implements DoubleSuggester { Values(@NotNull List values) { diff --git a/commands/src/main/java/com/wizardlybump17/wlib/command/suggestion/primitive/number/FloatSuggester.java b/commands/src/main/java/com/wizardlybump17/wlib/command/suggestion/primitive/number/FloatSuggester.java index 2819a32d..d72d740d 100644 --- a/commands/src/main/java/com/wizardlybump17/wlib/command/suggestion/primitive/number/FloatSuggester.java +++ b/commands/src/main/java/com/wizardlybump17/wlib/command/suggestion/primitive/number/FloatSuggester.java @@ -24,6 +24,56 @@ public interface FloatSuggester extends PrimitiveSuggester, NumberSuggest return new Values(List.copyOf(list)); } + static @NotNull Values range(float from, float to, int amount) { + float part = (to - from) / amount; + List values = new ArrayList<>(amount); + for (float i = 0; i < amount; i++) + values.add(from + part * amount); + return new Values(List.copyOf(values)); + } + + static @NotNull Values range(float from, float to) { + return range(from, to, 4); + } + + static @NotNull Values positive() { + return new Values(List.of( + 0.0F, + 50.5F, + 200.5F, + 3000.5F, + 50000.5F, + 100000.5F + )); + } + + static @NotNull Values negative() { + return new Values(List.of( + -100000.5F, + -50000.5F, + -3000.5F, + -200.5F, + -50.5F, + -1.0F + )); + } + + static @NotNull Values unlimited() { + return new Values(List.of( + -100000.5F, + -50000.5F, + -3000.5F, + -200.5F, + -50.5F, + 0.0F, + 50.5F, + 200.5F, + 3000.5F, + 50000.5F, + 100000.5F + )); + } + final class Values extends AbstractValuesSuggester implements FloatSuggester { Values(@NotNull List values) { diff --git a/commands/src/main/java/com/wizardlybump17/wlib/command/suggestion/primitive/number/IntegerSuggester.java b/commands/src/main/java/com/wizardlybump17/wlib/command/suggestion/primitive/number/IntegerSuggester.java index 7fb9abe2..d37011c8 100644 --- a/commands/src/main/java/com/wizardlybump17/wlib/command/suggestion/primitive/number/IntegerSuggester.java +++ b/commands/src/main/java/com/wizardlybump17/wlib/command/suggestion/primitive/number/IntegerSuggester.java @@ -6,6 +6,7 @@ import java.util.ArrayList; import java.util.List; +import java.util.stream.IntStream; public interface IntegerSuggester extends PrimitiveSuggester, NumberSuggester { @@ -24,8 +25,65 @@ public interface IntegerSuggester extends PrimitiveSuggester, NumberSug return new Values(List.copyOf(list)); } + static @NotNull Values range(int from, int to, int amount) { + if (to - from < amount) + return new Values(IntStream.rangeClosed(from, to).boxed().toList()); + + int part = (to - from) / amount; + List values = new ArrayList<>(amount); + for (int i = 0; i < amount; i++) + values.add(from + part * amount); + return new Values(List.copyOf(values)); + } + + static @NotNull Values range(int from, int to) { + return range(from, to, 4); + } + + static @NotNull Values positive() { + return Values.POSITIVE; + } + + static @NotNull Values negative() { + return Values.NEGATIVE; + } + + static @NotNull Values unlimited() { + return Values.UNLIMITED; + } + final class Values extends AbstractValuesSuggester implements IntegerSuggester { + private static final @NotNull Values POSITIVE = new Values(List.of( + 0, + 50, + 200, + 3000, + 50000, + 100000 + )); + private static final @NotNull Values NEGATIVE = new Values(List.of( + -100000, + -50000, + -3000, + -200, + -50, + -1 + )); + private static final @NotNull Values UNLIMITED = new Values(List.of( + -100000, + -50000, + -3000, + -200, + -50, + 0, + 50, + 200, + 3000, + 50000, + 100000 + )); + Values(@NotNull List values) { super(values); } diff --git a/commands/src/main/java/com/wizardlybump17/wlib/command/suggestion/primitive/number/LongSuggester.java b/commands/src/main/java/com/wizardlybump17/wlib/command/suggestion/primitive/number/LongSuggester.java index 13c2b6cd..e0ae05ad 100644 --- a/commands/src/main/java/com/wizardlybump17/wlib/command/suggestion/primitive/number/LongSuggester.java +++ b/commands/src/main/java/com/wizardlybump17/wlib/command/suggestion/primitive/number/LongSuggester.java @@ -24,8 +24,69 @@ public interface LongSuggester extends PrimitiveSuggester, NumberSuggester return new Values(List.copyOf(list)); } + static @NotNull Values range(long from, long to, int amount) { + if (to - from < amount) { + Long[] longs = new Long[(int) (to - from)]; + for (int i = 0; i < longs.length; i++) + longs[i] = to - from - i; + return new Values(List.of(longs)); + } + + long part = (to - from) / amount; + List values = new ArrayList<>(amount); + for (long i = 0; i < amount; i++) + values.add(from + part * amount); + return new Values(List.copyOf(values)); + } + + static @NotNull Values range(long from, long to) { + return range(from, to, 4); + } + + static @NotNull Values positive() { + return Values.POSITIVE; + } + + static @NotNull Values negative() { + return Values.NEGATIVE; + } + + static @NotNull Values unlimited() { + return Values.UNLIMITED; + } + final class Values extends AbstractValuesSuggester implements LongSuggester { + private static final @NotNull Values POSITIVE = new Values(List.of( + 0L, + 50L, + 200L, + 3000L, + 50000L, + 100000L + )); + private static final @NotNull Values NEGATIVE = new Values(List.of( + -100000L, + -50000L, + -3000L, + -200L, + -50L, + -1L + )); + private static final @NotNull Values UNLIMITED = new Values(List.of( + -100000L, + -50000L, + -3000L, + -200L, + -50L, + 0L, + 50L, + 200L, + 3000L, + 50000L, + 100000L + )); + Values(@NotNull List values) { super(values); } diff --git a/commands/src/main/java/com/wizardlybump17/wlib/command/suggestion/primitive/number/ShortSuggester.java b/commands/src/main/java/com/wizardlybump17/wlib/command/suggestion/primitive/number/ShortSuggester.java index 805b7c34..bde37d1d 100644 --- a/commands/src/main/java/com/wizardlybump17/wlib/command/suggestion/primitive/number/ShortSuggester.java +++ b/commands/src/main/java/com/wizardlybump17/wlib/command/suggestion/primitive/number/ShortSuggester.java @@ -24,8 +24,65 @@ public interface ShortSuggester extends PrimitiveSuggester, NumberSuggest return new Values(List.copyOf(list)); } + static @NotNull Values range(short from, short to, int amount) { + if (to - from < amount) { + Short[] values = new Short[to - from]; + for (int i = 0; i < values.length; i++) + values[i] = (short) (to - from - i); + return new Values(List.of(values)); + } + + short part = (short) ((to - from) / amount); + List values = new ArrayList<>(amount); + for (short i = 0; i < amount; i++) + values.add((short) (from + part * amount)); + return new Values(List.copyOf(values)); + } + + static @NotNull Values range(short from, short to) { + return range(from, to, 4); + } + + static @NotNull Values positive() { + return Values.POSITIVE; + } + + static @NotNull Values negative() { + return Values.NEGATIVE; + } + + static @NotNull Values unlimited() { + return Values.UNLIMITED; + } + final class Values extends AbstractValuesSuggester implements ShortSuggester { + private static final @NotNull Values POSITIVE = new Values(List.of( + (short) 0, + (short) 50, + (short) 100, + (short) 3000, + (short) 32767 + )); + private static final @NotNull Values NEGATIVE = new Values(List.of( + (short) -32768, + (short) -3000, + (short) -100, + (short) -50, + (short) -1 + )); + private static final @NotNull Values UNLIMITED = new Values(List.of( + (short) -32768, + (short) -3000, + (short) -100, + (short) -50, + (short) 0, + (short) 50, + (short) 100, + (short) 3000, + (short) 32767 + )); + Values(@NotNull List values) { super(values); } diff --git a/commands/src/main/java/com/wizardlybump17/wlib/command/suggestion/string/StringSuggester.java b/commands/src/main/java/com/wizardlybump17/wlib/command/suggestion/string/StringSuggester.java index dbecab84..22166696 100644 --- a/commands/src/main/java/com/wizardlybump17/wlib/command/suggestion/string/StringSuggester.java +++ b/commands/src/main/java/com/wizardlybump17/wlib/command/suggestion/string/StringSuggester.java @@ -1,5 +1,7 @@ package com.wizardlybump17.wlib.command.suggestion.string; +import com.wizardlybump17.wlib.command.node.CommandNode; +import com.wizardlybump17.wlib.command.sender.CommandSender; import com.wizardlybump17.wlib.command.suggestion.AbstractValuesSuggester; import com.wizardlybump17.wlib.command.suggestion.primitive.PrimitiveSuggester; import org.jetbrains.annotations.NotNull; @@ -20,6 +22,10 @@ public interface StringSuggester extends PrimitiveSuggester { return new Values(List.of(values)); } + static @NotNull Any any() { + return Any.INSTANCE; + } + final class Values extends AbstractValuesSuggester implements StringSuggester { Values(@NotNull List values) { @@ -33,4 +39,14 @@ public String toString() { '}'; } } + + final class Any implements StringSuggester { + + private static final @NotNull Any INSTANCE = new Any(); + + @Override + public @NotNull List getSuggestions(@NotNull CommandSender sender, @NotNull List input, @NotNull String current, @NotNull CommandNode currentNode) { + return List.of(current); + } + } } From 540043dd42fc4009bf0b80267cad00286cf1ae63 Mon Sep 17 00:00:00 2001 From: WizardlyBump17 Date: Tue, 9 Dec 2025 20:34:02 -0300 Subject: [PATCH 226/363] working on the suggestion system --- .../primitive/number/AllowedNumberInputs.java | 6 ------ .../input/string/AllowedStringInputs.java | 16 --------------- .../wlib/command/node/CommandNode.java | 20 +++++++++++++------ 3 files changed, 14 insertions(+), 28 deletions(-) diff --git a/commands/src/main/java/com/wizardlybump17/wlib/command/input/primitive/number/AllowedNumberInputs.java b/commands/src/main/java/com/wizardlybump17/wlib/command/input/primitive/number/AllowedNumberInputs.java index dd94fbe4..1f54d839 100644 --- a/commands/src/main/java/com/wizardlybump17/wlib/command/input/primitive/number/AllowedNumberInputs.java +++ b/commands/src/main/java/com/wizardlybump17/wlib/command/input/primitive/number/AllowedNumberInputs.java @@ -4,7 +4,6 @@ import com.wizardlybump17.wlib.command.input.AllowedListInputs; import com.wizardlybump17.wlib.command.input.RangedAllowedInputs; import com.wizardlybump17.wlib.command.input.SingleValueInput; -import com.wizardlybump17.wlib.command.sender.CommandSender; import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.Nullable; @@ -130,11 +129,6 @@ class Values implements AllowedNumberInputs, AllowedListInp return values; } - @Override - public @NotNull List getSuggestions(@NotNull CommandSender sender, @NotNull List input, @NotNull String current) { - return values; - } - @Override public boolean equals(Object object) { if (object == null || getClass() != object.getClass()) diff --git a/commands/src/main/java/com/wizardlybump17/wlib/command/input/string/AllowedStringInputs.java b/commands/src/main/java/com/wizardlybump17/wlib/command/input/string/AllowedStringInputs.java index b2cfee87..a5be18b2 100644 --- a/commands/src/main/java/com/wizardlybump17/wlib/command/input/string/AllowedStringInputs.java +++ b/commands/src/main/java/com/wizardlybump17/wlib/command/input/string/AllowedStringInputs.java @@ -2,7 +2,6 @@ import com.wizardlybump17.wlib.command.input.AllowedInputs; import com.wizardlybump17.wlib.command.input.AllowedListInputs; -import com.wizardlybump17.wlib.command.sender.CommandSender; import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.Nullable; import org.jetbrains.annotations.Unmodifiable; @@ -56,11 +55,6 @@ private Values(@NotNull List values, boolean ignoreCase) { return values; } - @Override - public @NotNull List getSuggestions(@NotNull CommandSender sender, @NotNull List input, @NotNull String current) { - return values; - } - @Override public boolean isAllowed(@Nullable String input) { if (input == null) @@ -110,11 +104,6 @@ public boolean ignoreCase() { return ignoreCase; } - @Override - public @NotNull List getSuggestions(@NotNull CommandSender sender, @NotNull List input, @NotNull String current) { - return List.of(value); - } - @Override public boolean isAllowed(@Nullable String input) { if (input == null) @@ -166,11 +155,6 @@ public boolean nullable() { return nullable; } - @Override - public @NotNull List getSuggestions(@NotNull CommandSender sender, @NotNull List input, @NotNull String current) { - return List.of(current); - } - @Override public boolean equals(Object object) { if (object == null || getClass() != object.getClass()) diff --git a/commands/src/main/java/com/wizardlybump17/wlib/command/node/CommandNode.java b/commands/src/main/java/com/wizardlybump17/wlib/command/node/CommandNode.java index 83bba322..d606d086 100644 --- a/commands/src/main/java/com/wizardlybump17/wlib/command/node/CommandNode.java +++ b/commands/src/main/java/com/wizardlybump17/wlib/command/node/CommandNode.java @@ -5,6 +5,7 @@ import com.wizardlybump17.wlib.command.executor.CommandNodeExecutor; import com.wizardlybump17.wlib.command.input.AllowedInputs; import com.wizardlybump17.wlib.command.sender.CommandSender; +import com.wizardlybump17.wlib.command.suggestion.Suggester; import com.wizardlybump17.wlib.util.CollectionUtil; import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.Nullable; @@ -17,15 +18,12 @@ public abstract class CommandNode { private final @NotNull String name; private final @NotNull @Unmodifiable List> children; private final @NotNull AllowedInputs allowedInputs; + private final @Nullable Suggester suggester; private final @Nullable CommandNodeExecutor executor; private final @Nullable String permission; public CommandNode(@NotNull String name, @NotNull List> children, @NotNull AllowedInputs allowedInputs, @Nullable CommandNodeExecutor executor, @Nullable String permission) { - this.name = name.toLowerCase(); - this.children = List.copyOf(children); - this.allowedInputs = allowedInputs; - this.executor = executor; - this.permission = permission; + this(name, children, allowedInputs, null, executor, permission); } public CommandNode(@NotNull String name, @NotNull AllowedInputs allowedInputs, @Nullable CommandNodeExecutor executor, @Nullable String permission) { @@ -52,6 +50,15 @@ public CommandNode(@NotNull String name, @NotNull AllowedInputs allowedInputs this(name, List.of(), allowedInputs, null, null); } + public CommandNode(@NotNull String name, @NotNull @Unmodifiable List> children, @NotNull AllowedInputs allowedInputs, @Nullable Suggester suggester, @Nullable CommandNodeExecutor executor, @Nullable String permission) { + this.name = name; + this.children = List.copyOf(children); + this.allowedInputs = allowedInputs; + this.suggester = suggester; + this.executor = executor; + this.permission = permission; + } + public @NotNull String getName() { return name; } @@ -78,7 +85,7 @@ public final boolean isValidInput(@Nullable T input) { } public @NotNull List getSuggestions(@NotNull CommandSender sender, @NotNull List args, @NotNull String currentInput) { - return allowedInputs.getSuggestions(sender, args, currentInput); + return suggester == null ? List.of() : suggester.getSuggestions(sender, args, currentInput, this); } public @Nullable CommandNodeExecutor getExecutor() { @@ -95,6 +102,7 @@ public String toString() { "name='" + name + '\'' + ", children=" + children + ", allowedInputs=" + allowedInputs + + ", suggester=" + suggester + ", executor=" + executor + ", permission='" + permission + '\'' + '}'; From fa497f3a132477f12717225e285738dbe334b7c1 Mon Sep 17 00:00:00 2001 From: WizardlyBump17 Date: Tue, 9 Dec 2025 20:42:37 -0300 Subject: [PATCH 227/363] fixed the tests --- .../node/primitive/number/IntegerCommandNode.java | 6 ++++++ .../node/primitive/number/NumberCommandNode.java | 5 +++++ .../suggestion/primitive/number/IntegerSuggester.java | 3 ++- .../wlib/test/command/SuggestionTests.java | 6 +++++- .../manager/CommandManagerSuggestionTests.java | 11 ++++++++++- 5 files changed, 28 insertions(+), 3 deletions(-) diff --git a/commands/src/main/java/com/wizardlybump17/wlib/command/node/primitive/number/IntegerCommandNode.java b/commands/src/main/java/com/wizardlybump17/wlib/command/node/primitive/number/IntegerCommandNode.java index f243fa3b..dc89497e 100644 --- a/commands/src/main/java/com/wizardlybump17/wlib/command/node/primitive/number/IntegerCommandNode.java +++ b/commands/src/main/java/com/wizardlybump17/wlib/command/node/primitive/number/IntegerCommandNode.java @@ -2,9 +2,11 @@ import com.wizardlybump17.wlib.command.exception.InputParsingException; import com.wizardlybump17.wlib.command.executor.CommandNodeExecutor; +import com.wizardlybump17.wlib.command.input.AllowedInputs; import com.wizardlybump17.wlib.command.input.primitive.number.AllowedIntegerInputs; import com.wizardlybump17.wlib.command.node.CommandNode; import com.wizardlybump17.wlib.command.node.primitive.PrimitiveCommandNode; +import com.wizardlybump17.wlib.command.suggestion.Suggester; import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.Nullable; @@ -44,6 +46,10 @@ public IntegerCommandNode(@NotNull String name, @NotNull AllowedIntegerInputs al this(name, List.of(), allowedInputs, null, null); } + public IntegerCommandNode(@NotNull String name, @NotNull List> children, @NotNull AllowedInputs allowedInputs, @Nullable Suggester suggester, @Nullable CommandNodeExecutor executor, @Nullable String permission) { + super(name, children, allowedInputs, suggester, executor, permission); + } + @Override public @NotNull AllowedIntegerInputs getAllowedInputs() { return (AllowedIntegerInputs) super.getAllowedInputs(); diff --git a/commands/src/main/java/com/wizardlybump17/wlib/command/node/primitive/number/NumberCommandNode.java b/commands/src/main/java/com/wizardlybump17/wlib/command/node/primitive/number/NumberCommandNode.java index 27c2483d..6f89748e 100644 --- a/commands/src/main/java/com/wizardlybump17/wlib/command/node/primitive/number/NumberCommandNode.java +++ b/commands/src/main/java/com/wizardlybump17/wlib/command/node/primitive/number/NumberCommandNode.java @@ -3,6 +3,7 @@ import com.wizardlybump17.wlib.command.executor.CommandNodeExecutor; import com.wizardlybump17.wlib.command.input.AllowedInputs; import com.wizardlybump17.wlib.command.node.CommandNode; +import com.wizardlybump17.wlib.command.suggestion.Suggester; import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.Nullable; @@ -38,6 +39,10 @@ public NumberCommandNode(@NotNull String name, @NotNull AllowedInputs allowed super(name, allowedInputs); } + public NumberCommandNode(@NotNull String name, @NotNull List> children, @NotNull AllowedInputs allowedInputs, @Nullable Suggester suggester, @Nullable CommandNodeExecutor executor, @Nullable String permission) { + super(name, children, allowedInputs, suggester, executor, permission); + } + @Override public abstract @NotNull NumberCommandNode withChildren(@NotNull List> children); diff --git a/commands/src/main/java/com/wizardlybump17/wlib/command/suggestion/primitive/number/IntegerSuggester.java b/commands/src/main/java/com/wizardlybump17/wlib/command/suggestion/primitive/number/IntegerSuggester.java index d37011c8..a05f951c 100644 --- a/commands/src/main/java/com/wizardlybump17/wlib/command/suggestion/primitive/number/IntegerSuggester.java +++ b/commands/src/main/java/com/wizardlybump17/wlib/command/suggestion/primitive/number/IntegerSuggester.java @@ -32,7 +32,8 @@ public interface IntegerSuggester extends PrimitiveSuggester, NumberSug int part = (to - from) / amount; List values = new ArrayList<>(amount); for (int i = 0; i < amount; i++) - values.add(from + part * amount); + values.add(from + part * i); + values.add(to); return new Values(List.copyOf(values)); } diff --git a/commands/src/test/java/com/wizardlybump17/wlib/test/command/SuggestionTests.java b/commands/src/test/java/com/wizardlybump17/wlib/test/command/SuggestionTests.java index 54ba2ccf..097da772 100644 --- a/commands/src/test/java/com/wizardlybump17/wlib/test/command/SuggestionTests.java +++ b/commands/src/test/java/com/wizardlybump17/wlib/test/command/SuggestionTests.java @@ -7,6 +7,7 @@ import com.wizardlybump17.wlib.command.result.CommandResult; import com.wizardlybump17.wlib.command.sender.BasicCommandSender; import com.wizardlybump17.wlib.command.sender.CommandSender; +import com.wizardlybump17.wlib.command.suggestion.primitive.number.IntegerSuggester; import org.jetbrains.annotations.NotNull; import org.junit.jupiter.api.Assertions; import org.junit.jupiter.api.DisplayName; @@ -110,8 +111,11 @@ void testSuccess3() { ), new IntegerCommandNode( "there", + List.of(), AllowedIntegerInputs.range(1, 10), - context -> CommandResult.successful(context, "hello there") + IntegerSuggester.range(1, 10), + context -> CommandResult.successful(context, "hello there"), + null ) ) ) diff --git a/commands/src/test/java/com/wizardlybump17/wlib/test/command/manager/CommandManagerSuggestionTests.java b/commands/src/test/java/com/wizardlybump17/wlib/test/command/manager/CommandManagerSuggestionTests.java index 2121effb..a84d35d2 100644 --- a/commands/src/test/java/com/wizardlybump17/wlib/test/command/manager/CommandManagerSuggestionTests.java +++ b/commands/src/test/java/com/wizardlybump17/wlib/test/command/manager/CommandManagerSuggestionTests.java @@ -8,6 +8,7 @@ import com.wizardlybump17.wlib.command.result.CommandResult; import com.wizardlybump17.wlib.command.sender.BasicCommandSender; import com.wizardlybump17.wlib.command.sender.CommandSender; +import com.wizardlybump17.wlib.command.suggestion.primitive.number.IntegerSuggester; import com.wizardlybump17.wlib.util.CollectionUtil; import org.jetbrains.annotations.NotNull; import org.junit.jupiter.api.Assertions; @@ -205,7 +206,9 @@ void testSuggestionsSuccessListChad4() { List.of( new IntegerCommandNode( "repeat", + List.of(), AllowedIntegerInputs.positive(), + IntegerSuggester.positive(), context -> CommandResult.successful(context, "welcome".repeat(context.arguments().getArgument("repeat").orElseThrow().data())), "permission" ) @@ -223,7 +226,7 @@ void testSuggestionsSuccessListChad4() { List expected = List.of(0, 50, 200, 3000, 50000, 100000); List actual = manager.getSuggestions(CHAD_SENDER, List.of("welcome", "")); - Assertions.assertTrue(CollectionUtil.contentEquals(expected, actual)); + Assertions.assertEquals(expected, actual); } @Test @@ -252,7 +255,9 @@ void testSuggestionsSuccessListChad6() { List.of( new IntegerCommandNode( "repeat", + List.of(), AllowedIntegerInputs.positive(), + IntegerSuggester.positive(), context -> CommandResult.successful(context, "welcome".repeat(context.arguments().getArgument("repeat").orElseThrow().data())), "permission" ) @@ -432,7 +437,9 @@ void testSuggestionsSuccessStringChad2() { List.of( new IntegerCommandNode( "repeat", + List.of(), AllowedIntegerInputs.positive(), + IntegerSuggester.positive(), context -> CommandResult.successful(context, "welcome".repeat(context.arguments().getArgument("repeat").orElseThrow().data())), "permission" ) @@ -662,7 +669,9 @@ void testSuggestionsSuccessStringArrayChad2() { List.of( new IntegerCommandNode( "repeat", + List.of(), AllowedIntegerInputs.positive(), + IntegerSuggester.positive(), context -> CommandResult.successful(context, "welcome".repeat(context.arguments().getArgument("repeat").orElseThrow().data())), "permission" ) From b08aba6d0e94819eb225824911d27e4987348523 Mon Sep 17 00:00:00 2001 From: WizardlyBump17 Date: Tue, 9 Dec 2025 21:11:08 -0300 Subject: [PATCH 228/363] using a List instead --- .../main/java/com/wizardlybump17/wlib/command/Command.java | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/commands/src/main/java/com/wizardlybump17/wlib/command/Command.java b/commands/src/main/java/com/wizardlybump17/wlib/command/Command.java index fd144b69..459fc0d4 100644 --- a/commands/src/main/java/com/wizardlybump17/wlib/command/Command.java +++ b/commands/src/main/java/com/wizardlybump17/wlib/command/Command.java @@ -40,7 +40,7 @@ public Command(@NotNull LiteralCommandNode root) { return CommandResult.insufficientArguments(this); List> arguments = new ArrayList<>(); - Collection> children = List.of(root); + List> children = List.of(root); CommandNode lastNode = null; int lastInputIndex = 0; @@ -120,7 +120,7 @@ public Command(@NotNull LiteralCommandNode root) { String currentInput = input.getLast(); List suggestions = new ArrayList<>(); - Collection> children = List.of(root); + List> children = List.of(root); CommandNode lastNode = null; InputParsingException lastParsingError = null; From d65c0bc59aa15bbc9c958163ab5b0ee7fc5801d1 Mon Sep 17 00:00:00 2001 From: WizardlyBump17 Date: Tue, 9 Dec 2025 21:13:15 -0300 Subject: [PATCH 229/363] returning the last child --- .../main/java/com/wizardlybump17/wlib/command/Command.java | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/commands/src/main/java/com/wizardlybump17/wlib/command/Command.java b/commands/src/main/java/com/wizardlybump17/wlib/command/Command.java index 459fc0d4..9df93f7e 100644 --- a/commands/src/main/java/com/wizardlybump17/wlib/command/Command.java +++ b/commands/src/main/java/com/wizardlybump17/wlib/command/Command.java @@ -12,7 +12,10 @@ import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.Nullable; -import java.util.*; +import java.util.ArrayList; +import java.util.Comparator; +import java.util.List; +import java.util.Objects; public class Command implements Comparable { @@ -135,6 +138,8 @@ public Command(@NotNull LiteralCommandNode root) { if (permission == null || sender.hasPermission(permission)) suggestions.addAll(child.getSuggestions(sender, input, "")); } + if (!children.isEmpty()) + lastNode = children.getLast(); break; } From a0acbd046d6cf52130d5bb5a3158832aec6b5fc5 Mon Sep 17 00:00:00 2001 From: WizardlyBump17 Date: Tue, 9 Dec 2025 21:13:43 -0300 Subject: [PATCH 230/363] added the Suggester --- .../wizardlybump17/wlib/command/node/LiteralCommandNode.java | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/commands/src/main/java/com/wizardlybump17/wlib/command/node/LiteralCommandNode.java b/commands/src/main/java/com/wizardlybump17/wlib/command/node/LiteralCommandNode.java index 165511a9..a511151f 100644 --- a/commands/src/main/java/com/wizardlybump17/wlib/command/node/LiteralCommandNode.java +++ b/commands/src/main/java/com/wizardlybump17/wlib/command/node/LiteralCommandNode.java @@ -3,6 +3,7 @@ import com.wizardlybump17.wlib.command.executor.CommandNodeExecutor; import com.wizardlybump17.wlib.command.input.string.AllowedStringInputs; import com.wizardlybump17.wlib.command.sender.CommandSender; +import com.wizardlybump17.wlib.command.suggestion.string.StringSuggester; import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.Nullable; @@ -11,7 +12,7 @@ public class LiteralCommandNode extends CommandNode { public LiteralCommandNode(@NotNull String name, @NotNull List> children, @Nullable CommandNodeExecutor executor, @Nullable String permission) { - super(name, children, AllowedStringInputs.valueIgnoreCase(name), executor, permission); + super(name, children, AllowedStringInputs.valueIgnoreCase(name), StringSuggester.value(name), executor, permission); } public LiteralCommandNode(@NotNull String name, @Nullable CommandNodeExecutor executor, @Nullable String permission) { From 9aa14ee039443663ecea6f56eb00f6fa844c9c2f Mon Sep 17 00:00:00 2001 From: WizardlyBump17 Date: Fri, 12 Dec 2025 11:56:36 -0300 Subject: [PATCH 231/363] suggestions --- .../object/UUIDMethodCommandNodeFactory.java | 1 + .../BooleanMethodCommandNodeFactory.java | 2 + .../CharacterMethodCommandNodeFactory.java | 1 + .../NumberMethodCommandNodeFactory.java | 73 ++++- .../StringMethodCommandNodeFactory.java | 2 + .../wlib/command/node/CommandNode.java | 22 +- .../wlib/command/node/LiteralCommandNode.java | 7 +- .../command/node/object/UUIDCommandNode.java | 6 + .../AbstractPrimitiveCommandNode.java | 7 + .../node/primitive/BooleanCommandNode.java | 6 + .../node/primitive/CharacterCommandNode.java | 6 + .../primitive/number/ByteCommandNode.java | 32 ++- .../primitive/number/DoubleCommandNode.java | 5 + .../primitive/number/FloatCommandNode.java | 5 + .../primitive/number/IntegerCommandNode.java | 36 +-- .../primitive/number/LongCommandNode.java | 32 ++- .../primitive/number/NumberCommandNode.java | 8 +- .../primitive/number/ShortCommandNode.java | 34 ++- .../node/string/StringCommandNode.java | 6 + .../primitive/CharacterSuggester.java | 6 - .../wlib/test/command/SuggestionTests.java | 253 ++++++++++++++++++ 21 files changed, 470 insertions(+), 80 deletions(-) diff --git a/commands/src/main/java/com/wizardlybump17/wlib/command/extractor/method/factory/object/UUIDMethodCommandNodeFactory.java b/commands/src/main/java/com/wizardlybump17/wlib/command/extractor/method/factory/object/UUIDMethodCommandNodeFactory.java index cb2c3dc4..23203dff 100644 --- a/commands/src/main/java/com/wizardlybump17/wlib/command/extractor/method/factory/object/UUIDMethodCommandNodeFactory.java +++ b/commands/src/main/java/com/wizardlybump17/wlib/command/extractor/method/factory/object/UUIDMethodCommandNodeFactory.java @@ -25,6 +25,7 @@ public class UUIDMethodCommandNodeFactory extends MethodCommandNodeFactory { root == null ? List.of() : List.of(root), parameter.isAnnotationPresent(NotNull.class) ? AllowedUUIDInputs.anyNotNull() : AllowedUUIDInputs.anyNullable(), null, + null, null ); } diff --git a/commands/src/main/java/com/wizardlybump17/wlib/command/extractor/method/factory/primitive/BooleanMethodCommandNodeFactory.java b/commands/src/main/java/com/wizardlybump17/wlib/command/extractor/method/factory/primitive/BooleanMethodCommandNodeFactory.java index ca4e1174..9cbe2856 100644 --- a/commands/src/main/java/com/wizardlybump17/wlib/command/extractor/method/factory/primitive/BooleanMethodCommandNodeFactory.java +++ b/commands/src/main/java/com/wizardlybump17/wlib/command/extractor/method/factory/primitive/BooleanMethodCommandNodeFactory.java @@ -4,6 +4,7 @@ import com.wizardlybump17.wlib.command.input.primitive.AllowedBooleanInputs; import com.wizardlybump17.wlib.command.node.CommandNode; import com.wizardlybump17.wlib.command.node.primitive.BooleanCommandNode; +import com.wizardlybump17.wlib.command.suggestion.primitive.BooleanSuggester; import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.Nullable; @@ -23,6 +24,7 @@ public class BooleanMethodCommandNodeFactory extends PrimitiveMethodCommandNodeF name, root == null ? List.of() : List.of(root), AllowedBooleanInputs.anyNotNull(), + BooleanSuggester.any(), null, null ); diff --git a/commands/src/main/java/com/wizardlybump17/wlib/command/extractor/method/factory/primitive/CharacterMethodCommandNodeFactory.java b/commands/src/main/java/com/wizardlybump17/wlib/command/extractor/method/factory/primitive/CharacterMethodCommandNodeFactory.java index ebb0eba8..cd662956 100644 --- a/commands/src/main/java/com/wizardlybump17/wlib/command/extractor/method/factory/primitive/CharacterMethodCommandNodeFactory.java +++ b/commands/src/main/java/com/wizardlybump17/wlib/command/extractor/method/factory/primitive/CharacterMethodCommandNodeFactory.java @@ -25,6 +25,7 @@ public class CharacterMethodCommandNodeFactory extends PrimitiveMethodCommandNod root == null ? List.of() : List.of(root), AllowedCharacterInputs.anyNotNull(), null, + null, null ); } diff --git a/commands/src/main/java/com/wizardlybump17/wlib/command/extractor/method/factory/primitive/NumberMethodCommandNodeFactory.java b/commands/src/main/java/com/wizardlybump17/wlib/command/extractor/method/factory/primitive/NumberMethodCommandNodeFactory.java index 82b371f3..2210ae5d 100644 --- a/commands/src/main/java/com/wizardlybump17/wlib/command/extractor/method/factory/primitive/NumberMethodCommandNodeFactory.java +++ b/commands/src/main/java/com/wizardlybump17/wlib/command/extractor/method/factory/primitive/NumberMethodCommandNodeFactory.java @@ -4,6 +4,7 @@ import com.wizardlybump17.wlib.command.input.primitive.number.*; import com.wizardlybump17.wlib.command.node.CommandNode; import com.wizardlybump17.wlib.command.node.primitive.number.*; +import com.wizardlybump17.wlib.command.suggestion.primitive.number.*; import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.Nullable; @@ -21,18 +22,66 @@ public class NumberMethodCommandNodeFactory extends PrimitiveMethodCommandNodeFa List> children = root == null ? List.of() : List.of(root); - if (type == byte.class || type == Byte.class) - return new ByteCommandNode(name, children, AllowedByteInputs.unlimited()); - if (type == short.class || type == Short.class) - return new ShortCommandNode(name, children, AllowedShortInputs.unlimited()); - if (type == int.class || type == Integer.class) - return new IntegerCommandNode(name, children, AllowedIntegerInputs.unlimited()); - if (type == long.class || type == Long.class) - return new LongCommandNode(name, children, AllowedLongInputs.unlimited()); - if (type == float.class || type == Float.class) - return new FloatCommandNode(name, children, AllowedFloatInputs.unlimited()); - if (type == double.class || type == Double.class) - return new DoubleCommandNode(name, children, AllowedDoubleInputs.unlimited()); + if (type == byte.class || type == Byte.class) { + return new ByteCommandNode( + name, + children, + AllowedByteInputs.unlimited(), + ByteSuggester.unlimited(), + null, + null + ); + } + if (type == short.class || type == Short.class) { + return new ShortCommandNode( + name, + children, + AllowedShortInputs.unlimited(), + ShortSuggester.unlimited(), + null, + null + ); + } + if (type == int.class || type == Integer.class) { + return new IntegerCommandNode( + name, + children, + AllowedIntegerInputs.unlimited(), + IntegerSuggester.unlimited(), + null, + null + ); + } + if (type == long.class || type == Long.class) { + return new LongCommandNode( + name, + children, + AllowedLongInputs.unlimited(), + LongSuggester.unlimited(), + null, + null + ); + } + if (type == float.class || type == Float.class) { + return new FloatCommandNode( + name, + children, + AllowedFloatInputs.unlimited(), + FloatSuggester.unlimited(), + null, + null + ); + } + if (type == double.class || type == Double.class) { + return new DoubleCommandNode( + name, + children, + AllowedDoubleInputs.unlimited(), + DoubleSuggester.unlimited(), + null, + null + ); + } throw new IllegalArgumentException("Unsupported type. We accept only primitive numbers: " + type); } diff --git a/commands/src/main/java/com/wizardlybump17/wlib/command/extractor/method/factory/string/StringMethodCommandNodeFactory.java b/commands/src/main/java/com/wizardlybump17/wlib/command/extractor/method/factory/string/StringMethodCommandNodeFactory.java index a627e218..fd80c142 100644 --- a/commands/src/main/java/com/wizardlybump17/wlib/command/extractor/method/factory/string/StringMethodCommandNodeFactory.java +++ b/commands/src/main/java/com/wizardlybump17/wlib/command/extractor/method/factory/string/StringMethodCommandNodeFactory.java @@ -5,6 +5,7 @@ import com.wizardlybump17.wlib.command.input.string.AllowedStringInputs; import com.wizardlybump17.wlib.command.node.CommandNode; import com.wizardlybump17.wlib.command.node.string.StringCommandNode; +import com.wizardlybump17.wlib.command.suggestion.string.StringSuggester; import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.Nullable; @@ -24,6 +25,7 @@ public class StringMethodCommandNodeFactory extends MethodCommandNodeFactory { name, root == null ? List.of() : List.of(root), parameter.isAnnotationPresent(NotNull.class) ? AllowedStringInputs.anyNotNull() : AllowedStringInputs.anyNullable(), + StringSuggester.any(), null, null ); diff --git a/commands/src/main/java/com/wizardlybump17/wlib/command/node/CommandNode.java b/commands/src/main/java/com/wizardlybump17/wlib/command/node/CommandNode.java index d606d086..710953ef 100644 --- a/commands/src/main/java/com/wizardlybump17/wlib/command/node/CommandNode.java +++ b/commands/src/main/java/com/wizardlybump17/wlib/command/node/CommandNode.java @@ -22,6 +22,15 @@ public abstract class CommandNode { private final @Nullable CommandNodeExecutor executor; private final @Nullable String permission; + public CommandNode(@NotNull String name, @NotNull @Unmodifiable List> children, @NotNull AllowedInputs allowedInputs, @Nullable Suggester suggester, @Nullable CommandNodeExecutor executor, @Nullable String permission) { + this.name = name; + this.children = List.copyOf(children); + this.allowedInputs = allowedInputs; + this.suggester = suggester; + this.executor = executor; + this.permission = permission; + } + public CommandNode(@NotNull String name, @NotNull List> children, @NotNull AllowedInputs allowedInputs, @Nullable CommandNodeExecutor executor, @Nullable String permission) { this(name, children, allowedInputs, null, executor, permission); } @@ -50,15 +59,6 @@ public CommandNode(@NotNull String name, @NotNull AllowedInputs allowedInputs this(name, List.of(), allowedInputs, null, null); } - public CommandNode(@NotNull String name, @NotNull @Unmodifiable List> children, @NotNull AllowedInputs allowedInputs, @Nullable Suggester suggester, @Nullable CommandNodeExecutor executor, @Nullable String permission) { - this.name = name; - this.children = List.copyOf(children); - this.allowedInputs = allowedInputs; - this.suggester = suggester; - this.executor = executor; - this.permission = permission; - } - public @NotNull String getName() { return name; } @@ -71,6 +71,10 @@ public CommandNode(@NotNull String name, @NotNull @Unmodifiable List getSuggester() { + return suggester; + } + public abstract @Nullable T parse(@NotNull String input) throws InputParsingException; public final boolean isValidInput(@Nullable T input) { diff --git a/commands/src/main/java/com/wizardlybump17/wlib/command/node/LiteralCommandNode.java b/commands/src/main/java/com/wizardlybump17/wlib/command/node/LiteralCommandNode.java index a511151f..3ca15e83 100644 --- a/commands/src/main/java/com/wizardlybump17/wlib/command/node/LiteralCommandNode.java +++ b/commands/src/main/java/com/wizardlybump17/wlib/command/node/LiteralCommandNode.java @@ -28,7 +28,7 @@ public LiteralCommandNode(@NotNull String name, @Nullable String permission) { } public LiteralCommandNode(@NotNull String name, @NotNull List> children, @Nullable CommandNodeExecutor executor) { - super(name, children, AllowedStringInputs.valueIgnoreCase(name), executor, null); + this(name, children, executor, null); } public LiteralCommandNode(@NotNull String name, @Nullable CommandNodeExecutor executor) { @@ -48,6 +48,11 @@ public LiteralCommandNode(@NotNull String name) { return (AllowedStringInputs.Value) super.getAllowedInputs(); } + @Override + public @NotNull StringSuggester.Values getSuggester() { + return (StringSuggester.Values) super.getSuggester(); + } + @Override public @NotNull String parse(@NotNull String input) { return input; diff --git a/commands/src/main/java/com/wizardlybump17/wlib/command/node/object/UUIDCommandNode.java b/commands/src/main/java/com/wizardlybump17/wlib/command/node/object/UUIDCommandNode.java index e0a8263f..71906849 100644 --- a/commands/src/main/java/com/wizardlybump17/wlib/command/node/object/UUIDCommandNode.java +++ b/commands/src/main/java/com/wizardlybump17/wlib/command/node/object/UUIDCommandNode.java @@ -4,14 +4,20 @@ import com.wizardlybump17.wlib.command.executor.CommandNodeExecutor; import com.wizardlybump17.wlib.command.input.object.AllowedUUIDInputs; import com.wizardlybump17.wlib.command.node.CommandNode; +import com.wizardlybump17.wlib.command.suggestion.object.UUIDSuggester; import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.Nullable; +import org.jetbrains.annotations.Unmodifiable; import java.util.List; import java.util.UUID; public class UUIDCommandNode extends CommandNode { + public UUIDCommandNode(@NotNull String name, @NotNull @Unmodifiable List> children, @NotNull AllowedUUIDInputs allowedInputs, @Nullable UUIDSuggester suggester, @Nullable CommandNodeExecutor executor, @Nullable String permission) { + super(name, children, allowedInputs, suggester, executor, permission); + } + public UUIDCommandNode(@NotNull String name, @NotNull List> children, @NotNull AllowedUUIDInputs allowedInputs, @Nullable CommandNodeExecutor executor, @Nullable String permission) { super(name, children, allowedInputs, executor, permission); } diff --git a/commands/src/main/java/com/wizardlybump17/wlib/command/node/primitive/AbstractPrimitiveCommandNode.java b/commands/src/main/java/com/wizardlybump17/wlib/command/node/primitive/AbstractPrimitiveCommandNode.java index be30d4e2..02271272 100644 --- a/commands/src/main/java/com/wizardlybump17/wlib/command/node/primitive/AbstractPrimitiveCommandNode.java +++ b/commands/src/main/java/com/wizardlybump17/wlib/command/node/primitive/AbstractPrimitiveCommandNode.java @@ -1,15 +1,22 @@ package com.wizardlybump17.wlib.command.node.primitive; import com.wizardlybump17.wlib.command.executor.CommandNodeExecutor; +import com.wizardlybump17.wlib.command.input.AllowedInputs; import com.wizardlybump17.wlib.command.input.primitive.PrimitiveAllowedInputs; import com.wizardlybump17.wlib.command.node.CommandNode; +import com.wizardlybump17.wlib.command.suggestion.Suggester; import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.Nullable; +import org.jetbrains.annotations.Unmodifiable; import java.util.List; public abstract class AbstractPrimitiveCommandNode

extends CommandNode

implements PrimitiveCommandNode { + public AbstractPrimitiveCommandNode(@NotNull String name, @NotNull @Unmodifiable List> children, @NotNull AllowedInputs

allowedInputs, @Nullable Suggester

suggester, @Nullable CommandNodeExecutor executor, @Nullable String permission) { + super(name, children, allowedInputs, suggester, executor, permission); + } + public AbstractPrimitiveCommandNode(@NotNull String name, @NotNull List> children, @NotNull PrimitiveAllowedInputs

allowedInputs, @Nullable CommandNodeExecutor executor, @Nullable String permission) { super(name, children, allowedInputs, executor, permission); } diff --git a/commands/src/main/java/com/wizardlybump17/wlib/command/node/primitive/BooleanCommandNode.java b/commands/src/main/java/com/wizardlybump17/wlib/command/node/primitive/BooleanCommandNode.java index 992d11e5..8bd5e763 100644 --- a/commands/src/main/java/com/wizardlybump17/wlib/command/node/primitive/BooleanCommandNode.java +++ b/commands/src/main/java/com/wizardlybump17/wlib/command/node/primitive/BooleanCommandNode.java @@ -4,13 +4,19 @@ import com.wizardlybump17.wlib.command.executor.CommandNodeExecutor; import com.wizardlybump17.wlib.command.input.primitive.AllowedBooleanInputs; import com.wizardlybump17.wlib.command.node.CommandNode; +import com.wizardlybump17.wlib.command.suggestion.primitive.BooleanSuggester; import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.Nullable; +import org.jetbrains.annotations.Unmodifiable; import java.util.List; public class BooleanCommandNode extends AbstractPrimitiveCommandNode { + public BooleanCommandNode(@NotNull String name, @NotNull @Unmodifiable List> children, @NotNull AllowedBooleanInputs allowedInputs, @Nullable BooleanSuggester suggester, @Nullable CommandNodeExecutor executor, @Nullable String permission) { + super(name, children, allowedInputs, suggester, executor, permission); + } + public BooleanCommandNode(@NotNull String name, @NotNull List> children, @NotNull AllowedBooleanInputs allowedInputs, @Nullable CommandNodeExecutor executor, @Nullable String permission) { super(name, children, allowedInputs, executor, permission); } diff --git a/commands/src/main/java/com/wizardlybump17/wlib/command/node/primitive/CharacterCommandNode.java b/commands/src/main/java/com/wizardlybump17/wlib/command/node/primitive/CharacterCommandNode.java index f63a7b08..3d2a86ea 100644 --- a/commands/src/main/java/com/wizardlybump17/wlib/command/node/primitive/CharacterCommandNode.java +++ b/commands/src/main/java/com/wizardlybump17/wlib/command/node/primitive/CharacterCommandNode.java @@ -4,13 +4,19 @@ import com.wizardlybump17.wlib.command.executor.CommandNodeExecutor; import com.wizardlybump17.wlib.command.input.primitive.AllowedCharacterInputs; import com.wizardlybump17.wlib.command.node.CommandNode; +import com.wizardlybump17.wlib.command.suggestion.primitive.CharacterSuggester; import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.Nullable; +import org.jetbrains.annotations.Unmodifiable; import java.util.List; public class CharacterCommandNode extends AbstractPrimitiveCommandNode { + public CharacterCommandNode(@NotNull String name, @NotNull @Unmodifiable List> children, @NotNull AllowedCharacterInputs allowedInputs, @Nullable CharacterSuggester suggester, @Nullable CommandNodeExecutor executor, @Nullable String permission) { + super(name, children, allowedInputs, suggester, executor, permission); + } + public CharacterCommandNode(@NotNull String name, @NotNull List> children, @NotNull AllowedCharacterInputs allowedInputs, @Nullable CommandNodeExecutor executor, @Nullable String permission) { super(name, children, allowedInputs, executor, permission); } diff --git a/commands/src/main/java/com/wizardlybump17/wlib/command/node/primitive/number/ByteCommandNode.java b/commands/src/main/java/com/wizardlybump17/wlib/command/node/primitive/number/ByteCommandNode.java index 6dc57fa7..3c0999eb 100644 --- a/commands/src/main/java/com/wizardlybump17/wlib/command/node/primitive/number/ByteCommandNode.java +++ b/commands/src/main/java/com/wizardlybump17/wlib/command/node/primitive/number/ByteCommandNode.java @@ -5,6 +5,7 @@ import com.wizardlybump17.wlib.command.input.primitive.number.AllowedByteInputs; import com.wizardlybump17.wlib.command.node.CommandNode; import com.wizardlybump17.wlib.command.node.primitive.PrimitiveCommandNode; +import com.wizardlybump17.wlib.command.suggestion.primitive.number.ByteSuggester; import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.Nullable; @@ -12,36 +13,40 @@ public class ByteCommandNode extends NumberCommandNode implements PrimitiveCommandNode { + public ByteCommandNode(@NotNull String name, @NotNull List> children, @NotNull AllowedByteInputs allowedInputs, @Nullable ByteSuggester suggester, @Nullable CommandNodeExecutor executor, @Nullable String permission) { + super(name, children, allowedInputs, suggester, executor, permission); + } + public ByteCommandNode(@NotNull String name, @NotNull List> children, @NotNull AllowedByteInputs allowedInputs, @Nullable CommandNodeExecutor executor, @Nullable String permission) { - super(name, children, allowedInputs, executor, permission); + this(name, children, allowedInputs, null, executor, permission); } public ByteCommandNode(@NotNull String name, @NotNull AllowedByteInputs allowedInputs, @Nullable CommandNodeExecutor executor, @Nullable String permission) { - this(name, List.of(), allowedInputs, executor, permission); + this(name, List.of(), allowedInputs, null, executor, permission); } public ByteCommandNode(@NotNull String name, @NotNull List> children, @NotNull AllowedByteInputs allowedInputs, @Nullable String permission) { - this(name, children, allowedInputs, null, permission); + this(name, children, allowedInputs, null, null, permission); } public ByteCommandNode(@NotNull String name, @NotNull AllowedByteInputs allowedInputs, @Nullable String permission) { - this(name, List.of(), allowedInputs, null, permission); + this(name, List.of(), allowedInputs, null, null, permission); } public ByteCommandNode(@NotNull String name, @NotNull List> children, @NotNull AllowedByteInputs allowedInputs, @Nullable CommandNodeExecutor executor) { - super(name, children, allowedInputs, executor, null); + this(name, children, allowedInputs, null, executor, null); } public ByteCommandNode(@NotNull String name, @NotNull AllowedByteInputs allowedInputs, @Nullable CommandNodeExecutor executor) { - this(name, List.of(), allowedInputs, executor, null); + this(name, List.of(), allowedInputs, null, executor, null); } public ByteCommandNode(@NotNull String name, @NotNull List> children, @NotNull AllowedByteInputs allowedInputs) { - this(name, children, allowedInputs, null, null); + this(name, children, allowedInputs, null, null, null); } public ByteCommandNode(@NotNull String name, @NotNull AllowedByteInputs allowedInputs) { - this(name, List.of(), allowedInputs, null, null); + this(name, List.of(), allowedInputs, null, null, null); } @Override @@ -49,6 +54,11 @@ public ByteCommandNode(@NotNull String name, @NotNull AllowedByteInputs allowedI return (AllowedByteInputs) super.getAllowedInputs(); } + @Override + public @Nullable ByteSuggester getSuggester() { + return (ByteSuggester) super.getSuggester(); + } + @Override public @NotNull Byte parse(@NotNull String input) throws InputParsingException { try { @@ -60,16 +70,16 @@ public ByteCommandNode(@NotNull String name, @NotNull AllowedByteInputs allowedI @Override public @NotNull ByteCommandNode withChildren(@NotNull List> children) { - return new ByteCommandNode(getName(), children, getAllowedInputs(), getExecutor(), getPermission()); + return new ByteCommandNode(getName(), children, getAllowedInputs(), getSuggester(), getExecutor(), getPermission()); } @Override public @NotNull ByteCommandNode withExecutor(@Nullable CommandNodeExecutor executor) { - return new ByteCommandNode(getName(), getChildren(), getAllowedInputs(), executor, getPermission()); + return new ByteCommandNode(getName(), getChildren(), getAllowedInputs(), getSuggester(), executor, getPermission()); } @Override public @NotNull ByteCommandNode withPermission(@Nullable String permission) { - return new ByteCommandNode(getName(), getChildren(), getAllowedInputs(), getExecutor(), permission); + return new ByteCommandNode(getName(), getChildren(), getAllowedInputs(), getSuggester(), getExecutor(), permission); } } diff --git a/commands/src/main/java/com/wizardlybump17/wlib/command/node/primitive/number/DoubleCommandNode.java b/commands/src/main/java/com/wizardlybump17/wlib/command/node/primitive/number/DoubleCommandNode.java index c26db2e5..e2dc9c6b 100644 --- a/commands/src/main/java/com/wizardlybump17/wlib/command/node/primitive/number/DoubleCommandNode.java +++ b/commands/src/main/java/com/wizardlybump17/wlib/command/node/primitive/number/DoubleCommandNode.java @@ -5,6 +5,7 @@ import com.wizardlybump17.wlib.command.input.primitive.number.AllowedDoubleInputs; import com.wizardlybump17.wlib.command.node.CommandNode; import com.wizardlybump17.wlib.command.node.primitive.PrimitiveCommandNode; +import com.wizardlybump17.wlib.command.suggestion.primitive.number.DoubleSuggester; import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.Nullable; @@ -12,6 +13,10 @@ public class DoubleCommandNode extends NumberCommandNode implements PrimitiveCommandNode { + public DoubleCommandNode(@NotNull String name, @NotNull List> children, @NotNull AllowedDoubleInputs allowedInputs, @Nullable DoubleSuggester suggester, @Nullable CommandNodeExecutor executor, @Nullable String permission) { + super(name, children, allowedInputs, suggester, executor, permission); + } + public DoubleCommandNode(@NotNull String name, @NotNull List> children, @NotNull AllowedDoubleInputs allowedInputs, @Nullable CommandNodeExecutor executor, @Nullable String permission) { super(name, children, allowedInputs, executor, permission); } diff --git a/commands/src/main/java/com/wizardlybump17/wlib/command/node/primitive/number/FloatCommandNode.java b/commands/src/main/java/com/wizardlybump17/wlib/command/node/primitive/number/FloatCommandNode.java index 073e7997..a58910e0 100644 --- a/commands/src/main/java/com/wizardlybump17/wlib/command/node/primitive/number/FloatCommandNode.java +++ b/commands/src/main/java/com/wizardlybump17/wlib/command/node/primitive/number/FloatCommandNode.java @@ -5,6 +5,7 @@ import com.wizardlybump17.wlib.command.input.primitive.number.AllowedFloatInputs; import com.wizardlybump17.wlib.command.node.CommandNode; import com.wizardlybump17.wlib.command.node.primitive.PrimitiveCommandNode; +import com.wizardlybump17.wlib.command.suggestion.primitive.number.FloatSuggester; import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.Nullable; @@ -12,6 +13,10 @@ public class FloatCommandNode extends NumberCommandNode implements PrimitiveCommandNode { + public FloatCommandNode(@NotNull String name, @NotNull List> children, @NotNull AllowedFloatInputs allowedInputs, @Nullable FloatSuggester suggester, @Nullable CommandNodeExecutor executor, @Nullable String permission) { + super(name, children, allowedInputs, suggester, executor, permission); + } + public FloatCommandNode(@NotNull String name, @NotNull List> children, @NotNull AllowedFloatInputs allowedInputs, @Nullable CommandNodeExecutor executor, @Nullable String permission) { super(name, children, allowedInputs, executor, permission); } diff --git a/commands/src/main/java/com/wizardlybump17/wlib/command/node/primitive/number/IntegerCommandNode.java b/commands/src/main/java/com/wizardlybump17/wlib/command/node/primitive/number/IntegerCommandNode.java index dc89497e..eb7cd3cb 100644 --- a/commands/src/main/java/com/wizardlybump17/wlib/command/node/primitive/number/IntegerCommandNode.java +++ b/commands/src/main/java/com/wizardlybump17/wlib/command/node/primitive/number/IntegerCommandNode.java @@ -7,6 +7,7 @@ import com.wizardlybump17.wlib.command.node.CommandNode; import com.wizardlybump17.wlib.command.node.primitive.PrimitiveCommandNode; import com.wizardlybump17.wlib.command.suggestion.Suggester; +import com.wizardlybump17.wlib.command.suggestion.primitive.number.IntegerSuggester; import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.Nullable; @@ -14,40 +15,40 @@ public class IntegerCommandNode extends NumberCommandNode implements PrimitiveCommandNode { + public IntegerCommandNode(@NotNull String name, @NotNull List> children, @NotNull AllowedInputs allowedInputs, @Nullable Suggester suggester, @Nullable CommandNodeExecutor executor, @Nullable String permission) { + super(name, children, allowedInputs, suggester, executor, permission); + } + public IntegerCommandNode(@NotNull String name, @NotNull List> children, @NotNull AllowedIntegerInputs allowedInputs, @Nullable CommandNodeExecutor executor, @Nullable String permission) { - super(name, children, allowedInputs, executor, permission); + this(name, children, allowedInputs, null, executor, permission); } public IntegerCommandNode(@NotNull String name, @NotNull AllowedIntegerInputs allowedInputs, @Nullable CommandNodeExecutor executor, @Nullable String permission) { - this(name, List.of(), allowedInputs, executor, permission); + this(name, List.of(), allowedInputs, null, executor, permission); } public IntegerCommandNode(@NotNull String name, @NotNull List> children, @NotNull AllowedIntegerInputs allowedInputs, @Nullable String permission) { - this(name, children, allowedInputs, null, permission); + this(name, children, allowedInputs, null, null, permission); } public IntegerCommandNode(@NotNull String name, @NotNull AllowedIntegerInputs allowedInputs, @Nullable String permission) { - this(name, List.of(), allowedInputs, null, permission); + this(name, List.of(), allowedInputs, null, null, permission); } public IntegerCommandNode(@NotNull String name, @NotNull List> children, @NotNull AllowedIntegerInputs allowedInputs, @Nullable CommandNodeExecutor executor) { - super(name, children, allowedInputs, executor, null); + this(name, children, allowedInputs, null, executor, null); } public IntegerCommandNode(@NotNull String name, @NotNull AllowedIntegerInputs allowedInputs, @Nullable CommandNodeExecutor executor) { - this(name, List.of(), allowedInputs, executor, null); + this(name, List.of(), allowedInputs, null, executor, null); } public IntegerCommandNode(@NotNull String name, @NotNull List> children, @NotNull AllowedIntegerInputs allowedInputs) { - this(name, children, allowedInputs, null, null); + this(name, children, allowedInputs, null, null, null); } public IntegerCommandNode(@NotNull String name, @NotNull AllowedIntegerInputs allowedInputs) { - this(name, List.of(), allowedInputs, null, null); - } - - public IntegerCommandNode(@NotNull String name, @NotNull List> children, @NotNull AllowedInputs allowedInputs, @Nullable Suggester suggester, @Nullable CommandNodeExecutor executor, @Nullable String permission) { - super(name, children, allowedInputs, suggester, executor, permission); + this(name, List.of(), allowedInputs, null, null, null); } @Override @@ -55,6 +56,11 @@ public IntegerCommandNode(@NotNull String name, @NotNull List> ch return (AllowedIntegerInputs) super.getAllowedInputs(); } + @Override + public @Nullable IntegerSuggester getSuggester() { + return (IntegerSuggester) super.getSuggester(); + } + @Override public @NotNull Integer parse(@NotNull String input) throws InputParsingException { try { @@ -66,16 +72,16 @@ public IntegerCommandNode(@NotNull String name, @NotNull List> ch @Override public @NotNull IntegerCommandNode withChildren(@NotNull List> children) { - return new IntegerCommandNode(getName(), children, getAllowedInputs(), getExecutor(), getPermission()); + return new IntegerCommandNode(getName(), children, getAllowedInputs(), getSuggester(), getExecutor(), getPermission()); } @Override public @NotNull IntegerCommandNode withExecutor(@Nullable CommandNodeExecutor executor) { - return new IntegerCommandNode(getName(), getChildren(), getAllowedInputs(), executor, getPermission()); + return new IntegerCommandNode(getName(), getChildren(), getAllowedInputs(), getSuggester(), executor, getPermission()); } @Override public @NotNull IntegerCommandNode withPermission(@Nullable String permission) { - return new IntegerCommandNode(getName(), getChildren(), getAllowedInputs(), getExecutor(), permission); + return new IntegerCommandNode(getName(), getChildren(), getAllowedInputs(), getSuggester(), getExecutor(), permission); } } diff --git a/commands/src/main/java/com/wizardlybump17/wlib/command/node/primitive/number/LongCommandNode.java b/commands/src/main/java/com/wizardlybump17/wlib/command/node/primitive/number/LongCommandNode.java index e00458f3..b2bf0446 100644 --- a/commands/src/main/java/com/wizardlybump17/wlib/command/node/primitive/number/LongCommandNode.java +++ b/commands/src/main/java/com/wizardlybump17/wlib/command/node/primitive/number/LongCommandNode.java @@ -5,6 +5,7 @@ import com.wizardlybump17.wlib.command.input.primitive.number.AllowedLongInputs; import com.wizardlybump17.wlib.command.node.CommandNode; import com.wizardlybump17.wlib.command.node.primitive.PrimitiveCommandNode; +import com.wizardlybump17.wlib.command.suggestion.primitive.number.LongSuggester; import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.Nullable; @@ -12,36 +13,40 @@ public class LongCommandNode extends NumberCommandNode implements PrimitiveCommandNode { + public LongCommandNode(@NotNull String name, @NotNull List> children, @NotNull AllowedLongInputs allowedInputs, @Nullable LongSuggester suggester, @Nullable CommandNodeExecutor executor, @Nullable String permission) { + super(name, children, allowedInputs, suggester, executor, permission); + } + public LongCommandNode(@NotNull String name, @NotNull List> children, @NotNull AllowedLongInputs allowedInputs, @Nullable CommandNodeExecutor executor, @Nullable String permission) { - super(name, children, allowedInputs, executor, permission); + this(name, children, allowedInputs, null, executor, permission); } public LongCommandNode(@NotNull String name, @NotNull AllowedLongInputs allowedInputs, @Nullable CommandNodeExecutor executor, @Nullable String permission) { - this(name, List.of(), allowedInputs, executor, permission); + this(name, List.of(), allowedInputs, null, executor, permission); } public LongCommandNode(@NotNull String name, @NotNull List> children, @NotNull AllowedLongInputs allowedInputs, @Nullable String permission) { - this(name, children, allowedInputs, null, permission); + this(name, children, allowedInputs, null, null, permission); } public LongCommandNode(@NotNull String name, @NotNull AllowedLongInputs allowedInputs, @Nullable String permission) { - this(name, List.of(), allowedInputs, null, permission); + this(name, List.of(), allowedInputs, null, null, permission); } public LongCommandNode(@NotNull String name, @NotNull List> children, @NotNull AllowedLongInputs allowedInputs, @Nullable CommandNodeExecutor executor) { - super(name, children, allowedInputs, executor, null); + this(name, children, allowedInputs, null, executor, null); } public LongCommandNode(@NotNull String name, @NotNull AllowedLongInputs allowedInputs, @Nullable CommandNodeExecutor executor) { - this(name, List.of(), allowedInputs, executor, null); + this(name, List.of(), allowedInputs, null, executor, null); } public LongCommandNode(@NotNull String name, @NotNull List> children, @NotNull AllowedLongInputs allowedInputs) { - this(name, children, allowedInputs, null, null); + this(name, children, allowedInputs, null, null, null); } public LongCommandNode(@NotNull String name, @NotNull AllowedLongInputs allowedInputs) { - this(name, List.of(), allowedInputs, null, null); + this(name, List.of(), allowedInputs, null, null, null); } @Override @@ -49,6 +54,11 @@ public LongCommandNode(@NotNull String name, @NotNull AllowedLongInputs allowedI return (AllowedLongInputs) super.getAllowedInputs(); } + @Override + public @Nullable LongSuggester getSuggester() { + return (LongSuggester) super.getSuggester(); + } + @Override public @NotNull Long parse(@NotNull String input) throws InputParsingException { try { @@ -60,16 +70,16 @@ public LongCommandNode(@NotNull String name, @NotNull AllowedLongInputs allowedI @Override public @NotNull LongCommandNode withChildren(@NotNull List> children) { - return new LongCommandNode(getName(), children, getAllowedInputs(), getExecutor(), getPermission()); + return new LongCommandNode(getName(), children, getAllowedInputs(), getSuggester(), getExecutor(), getPermission()); } @Override public @NotNull LongCommandNode withExecutor(@Nullable CommandNodeExecutor executor) { - return new LongCommandNode(getName(), getChildren(), getAllowedInputs(), executor, getPermission()); + return new LongCommandNode(getName(), getChildren(), getAllowedInputs(), getSuggester(), executor, getPermission()); } @Override public @NotNull LongCommandNode withPermission(@Nullable String permission) { - return new LongCommandNode(getName(), getChildren(), getAllowedInputs(), getExecutor(), permission); + return new LongCommandNode(getName(), getChildren(), getAllowedInputs(), getSuggester(), getExecutor(), permission); } } diff --git a/commands/src/main/java/com/wizardlybump17/wlib/command/node/primitive/number/NumberCommandNode.java b/commands/src/main/java/com/wizardlybump17/wlib/command/node/primitive/number/NumberCommandNode.java index 6f89748e..a101e916 100644 --- a/commands/src/main/java/com/wizardlybump17/wlib/command/node/primitive/number/NumberCommandNode.java +++ b/commands/src/main/java/com/wizardlybump17/wlib/command/node/primitive/number/NumberCommandNode.java @@ -11,6 +11,10 @@ public abstract class NumberCommandNode extends CommandNode { + public NumberCommandNode(@NotNull String name, @NotNull List> children, @NotNull AllowedInputs allowedInputs, @Nullable Suggester suggester, @Nullable CommandNodeExecutor executor, @Nullable String permission) { + super(name, children, allowedInputs, suggester, executor, permission); + } + public NumberCommandNode(@NotNull String name, @NotNull List> children, @NotNull AllowedInputs allowedInputs, @Nullable CommandNodeExecutor executor, @Nullable String permission) { super(name, children, allowedInputs, executor, permission); } @@ -39,10 +43,6 @@ public NumberCommandNode(@NotNull String name, @NotNull AllowedInputs allowed super(name, allowedInputs); } - public NumberCommandNode(@NotNull String name, @NotNull List> children, @NotNull AllowedInputs allowedInputs, @Nullable Suggester suggester, @Nullable CommandNodeExecutor executor, @Nullable String permission) { - super(name, children, allowedInputs, suggester, executor, permission); - } - @Override public abstract @NotNull NumberCommandNode withChildren(@NotNull List> children); diff --git a/commands/src/main/java/com/wizardlybump17/wlib/command/node/primitive/number/ShortCommandNode.java b/commands/src/main/java/com/wizardlybump17/wlib/command/node/primitive/number/ShortCommandNode.java index 54092659..b6efa6e5 100644 --- a/commands/src/main/java/com/wizardlybump17/wlib/command/node/primitive/number/ShortCommandNode.java +++ b/commands/src/main/java/com/wizardlybump17/wlib/command/node/primitive/number/ShortCommandNode.java @@ -2,9 +2,12 @@ import com.wizardlybump17.wlib.command.exception.InputParsingException; import com.wizardlybump17.wlib.command.executor.CommandNodeExecutor; +import com.wizardlybump17.wlib.command.input.AllowedInputs; import com.wizardlybump17.wlib.command.input.primitive.number.AllowedShortInputs; import com.wizardlybump17.wlib.command.node.CommandNode; import com.wizardlybump17.wlib.command.node.primitive.PrimitiveCommandNode; +import com.wizardlybump17.wlib.command.suggestion.Suggester; +import com.wizardlybump17.wlib.command.suggestion.primitive.number.ShortSuggester; import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.Nullable; @@ -12,36 +15,40 @@ public class ShortCommandNode extends NumberCommandNode implements PrimitiveCommandNode { + public ShortCommandNode(@NotNull String name, @NotNull List> children, @NotNull AllowedInputs allowedInputs, @Nullable Suggester suggester, @Nullable CommandNodeExecutor executor, @Nullable String permission) { + super(name, children, allowedInputs, suggester, executor, permission); + } + public ShortCommandNode(@NotNull String name, @NotNull List> children, @NotNull AllowedShortInputs allowedInputs, @Nullable CommandNodeExecutor executor, @Nullable String permission) { - super(name, children, allowedInputs, executor, permission); + this(name, children, allowedInputs, null, executor, permission); } public ShortCommandNode(@NotNull String name, @NotNull AllowedShortInputs allowedInputs, @Nullable CommandNodeExecutor executor, @Nullable String permission) { - this(name, List.of(), allowedInputs, executor, permission); + this(name, List.of(), allowedInputs, null, executor, permission); } public ShortCommandNode(@NotNull String name, @NotNull List> children, @NotNull AllowedShortInputs allowedInputs, @Nullable String permission) { - this(name, children, allowedInputs, null, permission); + this(name, children, allowedInputs, null, null, permission); } public ShortCommandNode(@NotNull String name, @NotNull AllowedShortInputs allowedInputs, @Nullable String permission) { - this(name, List.of(), allowedInputs, null, permission); + this(name, List.of(), allowedInputs, null, null, permission); } public ShortCommandNode(@NotNull String name, @NotNull List> children, @NotNull AllowedShortInputs allowedInputs, @Nullable CommandNodeExecutor executor) { - super(name, children, allowedInputs, executor, null); + this(name, children, allowedInputs, null, executor, null); } public ShortCommandNode(@NotNull String name, @NotNull AllowedShortInputs allowedInputs, @Nullable CommandNodeExecutor executor) { - this(name, List.of(), allowedInputs, executor, null); + this(name, List.of(), allowedInputs, null, executor, null); } public ShortCommandNode(@NotNull String name, @NotNull List> children, @NotNull AllowedShortInputs allowedInputs) { - this(name, children, allowedInputs, null, null); + this(name, children, allowedInputs, null, null, null); } public ShortCommandNode(@NotNull String name, @NotNull AllowedShortInputs allowedInputs) { - this(name, List.of(), allowedInputs, null, null); + this(name, List.of(), allowedInputs, null, null, null); } @Override @@ -49,6 +56,11 @@ public ShortCommandNode(@NotNull String name, @NotNull AllowedShortInputs allowe return (AllowedShortInputs) super.getAllowedInputs(); } + @Override + public @Nullable ShortSuggester getSuggester() { + return (ShortSuggester) super.getSuggester(); + } + @Override public @NotNull Short parse(@NotNull String input) throws InputParsingException { try { @@ -60,16 +72,16 @@ public ShortCommandNode(@NotNull String name, @NotNull AllowedShortInputs allowe @Override public @NotNull ShortCommandNode withChildren(@NotNull List> children) { - return new ShortCommandNode(getName(), children, getAllowedInputs(), getExecutor(), getPermission()); + return new ShortCommandNode(getName(), children, getAllowedInputs(), getSuggester(), getExecutor(), getPermission()); } @Override public @NotNull ShortCommandNode withExecutor(@Nullable CommandNodeExecutor executor) { - return new ShortCommandNode(getName(), getChildren(), getAllowedInputs(), executor, getPermission()); + return new ShortCommandNode(getName(), getChildren(), getAllowedInputs(), getSuggester(), executor, getPermission()); } @Override public @NotNull ShortCommandNode withPermission(@Nullable String permission) { - return new ShortCommandNode(getName(), getChildren(), getAllowedInputs(), getExecutor(), permission); + return new ShortCommandNode(getName(), getChildren(), getAllowedInputs(), getSuggester(), getExecutor(), permission); } } diff --git a/commands/src/main/java/com/wizardlybump17/wlib/command/node/string/StringCommandNode.java b/commands/src/main/java/com/wizardlybump17/wlib/command/node/string/StringCommandNode.java index e977f0b9..4f4f4fb8 100644 --- a/commands/src/main/java/com/wizardlybump17/wlib/command/node/string/StringCommandNode.java +++ b/commands/src/main/java/com/wizardlybump17/wlib/command/node/string/StringCommandNode.java @@ -4,13 +4,19 @@ import com.wizardlybump17.wlib.command.executor.CommandNodeExecutor; import com.wizardlybump17.wlib.command.input.string.AllowedStringInputs; import com.wizardlybump17.wlib.command.node.CommandNode; +import com.wizardlybump17.wlib.command.suggestion.string.StringSuggester; import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.Nullable; +import org.jetbrains.annotations.Unmodifiable; import java.util.List; public class StringCommandNode extends CommandNode { + public StringCommandNode(@NotNull String name, @NotNull @Unmodifiable List> children, @NotNull AllowedStringInputs allowedInputs, @Nullable StringSuggester suggester, @Nullable CommandNodeExecutor executor, @Nullable String permission) { + super(name, children, allowedInputs, suggester, executor, permission); + } + public StringCommandNode(@NotNull String name, @NotNull List> children, @NotNull AllowedStringInputs allowedInputs, @Nullable CommandNodeExecutor executor, @Nullable String permission) { super(name, children, allowedInputs, executor, permission); } diff --git a/commands/src/main/java/com/wizardlybump17/wlib/command/suggestion/primitive/CharacterSuggester.java b/commands/src/main/java/com/wizardlybump17/wlib/command/suggestion/primitive/CharacterSuggester.java index dd220b21..a4b10a12 100644 --- a/commands/src/main/java/com/wizardlybump17/wlib/command/suggestion/primitive/CharacterSuggester.java +++ b/commands/src/main/java/com/wizardlybump17/wlib/command/suggestion/primitive/CharacterSuggester.java @@ -42,14 +42,8 @@ public interface CharacterSuggester extends PrimitiveSuggester { return range(from, to, 4); } - static @NotNull Values any() { - return Values.ANY; - } - final class Values extends AbstractValuesSuggester implements CharacterSuggester { - private static final @NotNull Values ANY = new Values(List.of()); - Values(@NotNull List values) { super(values); } diff --git a/commands/src/test/java/com/wizardlybump17/wlib/test/command/SuggestionTests.java b/commands/src/test/java/com/wizardlybump17/wlib/test/command/SuggestionTests.java index 097da772..438c6ba6 100644 --- a/commands/src/test/java/com/wizardlybump17/wlib/test/command/SuggestionTests.java +++ b/commands/src/test/java/com/wizardlybump17/wlib/test/command/SuggestionTests.java @@ -1,13 +1,22 @@ package com.wizardlybump17.wlib.test.command; import com.wizardlybump17.wlib.command.Command; +import com.wizardlybump17.wlib.command.input.primitive.number.AllowedByteInputs; import com.wizardlybump17.wlib.command.input.primitive.number.AllowedIntegerInputs; +import com.wizardlybump17.wlib.command.input.primitive.number.AllowedLongInputs; +import com.wizardlybump17.wlib.command.input.primitive.number.AllowedShortInputs; import com.wizardlybump17.wlib.command.node.LiteralCommandNode; +import com.wizardlybump17.wlib.command.node.primitive.number.ByteCommandNode; import com.wizardlybump17.wlib.command.node.primitive.number.IntegerCommandNode; +import com.wizardlybump17.wlib.command.node.primitive.number.LongCommandNode; +import com.wizardlybump17.wlib.command.node.primitive.number.ShortCommandNode; import com.wizardlybump17.wlib.command.result.CommandResult; import com.wizardlybump17.wlib.command.sender.BasicCommandSender; import com.wizardlybump17.wlib.command.sender.CommandSender; +import com.wizardlybump17.wlib.command.suggestion.primitive.number.ByteSuggester; import com.wizardlybump17.wlib.command.suggestion.primitive.number.IntegerSuggester; +import com.wizardlybump17.wlib.command.suggestion.primitive.number.LongSuggester; +import com.wizardlybump17.wlib.command.suggestion.primitive.number.ShortSuggester; import org.jetbrains.annotations.NotNull; import org.junit.jupiter.api.Assertions; import org.junit.jupiter.api.DisplayName; @@ -160,4 +169,248 @@ void testSuccess4() { Assertions.assertEquals(expected, actual); } + + @Test + void testDefaultSuggestions() { + //literal + Assertions.assertEquals( + List.of("hello"), + new Command(new LiteralCommandNode("hello")) + .getSuggestions(CHAD_SENDER, List.of()) + ); + Assertions.assertEquals( + List.of("hello"), + new Command(new LiteralCommandNode("hello")) + .getSuggestions(CHAD_SENDER, List.of("")) + ); + Assertions.assertEquals( + List.of("hello"), + new Command(new LiteralCommandNode("hello")) + .getSuggestions(CHAD_SENDER, List.of("hel")) + ); + + //byte + Assertions.assertEquals( + List.of((byte) -128, (byte) -100, (byte) -50, (byte) 0, (byte) 50, (byte) 100, (byte) 127), + new Command( + new LiteralCommandNode( + "hello", + List.of( + new ByteCommandNode( + "world", + List.of(), + AllowedByteInputs.unlimited(), + ByteSuggester.unlimited(), + null, + null + ) + ) + ) + ).getSuggestions(CHAD_SENDER, List.of("hello", "")) + ); + Assertions.assertEquals( + List.of((byte) -128, (byte) -100, (byte) -50, (byte) 0, (byte) 50, (byte) 100, (byte) 127), + new Command( + new LiteralCommandNode( + "hello", + List.of( + new ByteCommandNode( + "world", + List.of(), + AllowedByteInputs.unlimited(), + ByteSuggester.unlimited(), + null, + null + ) + ) + ) + ).getSuggestions(CHAD_SENDER, List.of("hello", "0")) + ); + Assertions.assertEquals( + List.of((byte) -128, (byte) -100, (byte) -50, (byte) 0, (byte) 50, (byte) 100, (byte) 127), + new Command( + new LiteralCommandNode( + "hello", + List.of( + new ByteCommandNode( + "world", + List.of(), + AllowedByteInputs.unlimited(), + ByteSuggester.unlimited(), + null, + null + ) + ) + ) + ).getSuggestions(CHAD_SENDER, List.of("hello", "10")) + ); + + //short + Assertions.assertEquals( + List.of((short) -32768, (short) -3000, (short) -100, (short) -50, (short) 0, (short) 50, (short) 100, (short) 3000, (short) 32767), + new Command( + new LiteralCommandNode( + "hello", + List.of( + new ShortCommandNode( + "world", + List.of(), + AllowedShortInputs.unlimited(), + ShortSuggester.unlimited(), + null, + null + ) + ) + ) + ).getSuggestions(CHAD_SENDER, List.of("hello", "")) + ); + Assertions.assertEquals( + List.of((short) -32768, (short) -3000, (short) -100, (short) -50, (short) 0, (short) 50, (short) 100, (short) 3000, (short) 32767), + new Command( + new LiteralCommandNode( + "hello", + List.of( + new ShortCommandNode( + "world", + List.of(), + AllowedShortInputs.unlimited(), + ShortSuggester.unlimited(), + null, + null + ) + ) + ) + ).getSuggestions(CHAD_SENDER, List.of("hello", "0")) + ); + Assertions.assertEquals( + List.of((short) -32768, (short) -3000, (short) -100, (short) -50, (short) 0, (short) 50, (short) 100, (short) 3000, (short) 32767), + new Command( + new LiteralCommandNode( + "hello", + List.of( + new ShortCommandNode( + "world", + List.of(), + AllowedShortInputs.unlimited(), + ShortSuggester.unlimited(), + null, + null + ) + ) + ) + ).getSuggestions(CHAD_SENDER, List.of("hello", "10")) + ); + + //int + Assertions.assertEquals( + List.of(-100000, -50000, -3000, -200, -50, 0, 50, 200, 3000, 50000, 100000), + new Command( + new LiteralCommandNode( + "hello", + List.of( + new IntegerCommandNode( + "world", + List.of(), + AllowedIntegerInputs.unlimited(), + IntegerSuggester.unlimited(), + null, + null + ) + ) + ) + ).getSuggestions(CHAD_SENDER, List.of("hello", "")) + ); + Assertions.assertEquals( + List.of(-100000, -50000, -3000, -200, -50, 0, 50, 200, 3000, 50000, 100000), + new Command( + new LiteralCommandNode( + "hello", + List.of( + new IntegerCommandNode( + "world", + List.of(), + AllowedIntegerInputs.unlimited(), + IntegerSuggester.unlimited(), + null, + null + ) + ) + ) + ).getSuggestions(CHAD_SENDER, List.of("hello", "0")) + ); + Assertions.assertEquals( + List.of(-100000, -50000, -3000, -200, -50, 0, 50, 200, 3000, 50000, 100000), + new Command( + new LiteralCommandNode( + "hello", + List.of( + new IntegerCommandNode( + "world", + List.of(), + AllowedIntegerInputs.unlimited(), + IntegerSuggester.unlimited(), + null, + null + ) + ) + ) + ).getSuggestions(CHAD_SENDER, List.of("hello", "10")) + ); + + //long + Assertions.assertEquals( + List.of(-100000L, -50000L, -3000L, -200L, -50L, 0L, 50L, 200L, 3000L, 50000L, 100000L), + new Command( + new LiteralCommandNode( + "hello", + List.of( + new LongCommandNode( + "world", + List.of(), + AllowedLongInputs.unlimited(), + LongSuggester.unlimited(), + null, + null + ) + ) + ) + ).getSuggestions(CHAD_SENDER, List.of("hello", "")) + ); + Assertions.assertEquals( + List.of(-100000L, -50000L, -3000L, -200L, -50L, 0L, 50L, 200L, 3000L, 50000L, 100000L), + new Command( + new LiteralCommandNode( + "hello", + List.of( + new LongCommandNode( + "world", + List.of(), + AllowedLongInputs.unlimited(), + LongSuggester.unlimited(), + null, + null + ) + ) + ) + ).getSuggestions(CHAD_SENDER, List.of("hello", "0")) + ); + Assertions.assertEquals( + List.of(-100000L, -50000L, -3000L, -200L, -50L, 0L, 50L, 200L, 3000L, 50000L, 100000L), + new Command( + new LiteralCommandNode( + "hello", + List.of( + new LongCommandNode( + "world", + List.of(), + AllowedLongInputs.unlimited(), + LongSuggester.unlimited(), + null, + null + ) + ) + ) + ).getSuggestions(CHAD_SENDER, List.of("hello", "10")) + ); + } } From 7996d990c2461f83e1900f7835ca22148e82c3be Mon Sep 17 00:00:00 2001 From: WizardlyBump17 Date: Fri, 12 Dec 2025 14:56:48 -0300 Subject: [PATCH 232/363] using only one constructor --- .../wlib/command/node/CommandNode.java | 28 ------------ .../wlib/command/node/LiteralCommandNode.java | 28 ------------ .../command/node/object/UUIDCommandNode.java | 39 ++++------------- .../AbstractPrimitiveCommandNode.java | 29 ------------- .../node/primitive/BooleanCommandNode.java | 39 ++++------------- .../node/primitive/CharacterCommandNode.java | 39 ++++------------- .../primitive/number/ByteCommandNode.java | 32 -------------- .../primitive/number/DoubleCommandNode.java | 43 ++++--------------- .../primitive/number/FloatCommandNode.java | 43 ++++--------------- .../primitive/number/IntegerCommandNode.java | 32 -------------- .../primitive/number/LongCommandNode.java | 32 -------------- .../primitive/number/NumberCommandNode.java | 30 ++----------- .../primitive/number/ShortCommandNode.java | 32 -------------- .../node/string/StringCommandNode.java | 39 ++++------------- 14 files changed, 52 insertions(+), 433 deletions(-) diff --git a/commands/src/main/java/com/wizardlybump17/wlib/command/node/CommandNode.java b/commands/src/main/java/com/wizardlybump17/wlib/command/node/CommandNode.java index 710953ef..aba682f0 100644 --- a/commands/src/main/java/com/wizardlybump17/wlib/command/node/CommandNode.java +++ b/commands/src/main/java/com/wizardlybump17/wlib/command/node/CommandNode.java @@ -31,34 +31,6 @@ public CommandNode(@NotNull String name, @NotNull @Unmodifiable List> children, @NotNull AllowedInputs allowedInputs, @Nullable CommandNodeExecutor executor, @Nullable String permission) { - this(name, children, allowedInputs, null, executor, permission); - } - - public CommandNode(@NotNull String name, @NotNull AllowedInputs allowedInputs, @Nullable CommandNodeExecutor executor, @Nullable String permission) { - this(name, List.of(), allowedInputs, executor, permission); - } - - public CommandNode(@NotNull String name, @NotNull List> children, @NotNull AllowedInputs allowedInputs, @Nullable String permission) { - this(name, children, allowedInputs, null, permission); - } - - public CommandNode(@NotNull String name, @NotNull AllowedInputs allowedInputs, @Nullable String permission) { - this(name, List.of(), allowedInputs, null, permission); - } - - public CommandNode(@NotNull String name, @NotNull AllowedInputs allowedInputs, @Nullable CommandNodeExecutor executor) { - this(name, List.of(), allowedInputs, executor, null); - } - - public CommandNode(@NotNull String name, @NotNull List> children, @NotNull AllowedInputs allowedInputs) { - this(name, children, allowedInputs, null, null); - } - - public CommandNode(@NotNull String name, @NotNull AllowedInputs allowedInputs) { - this(name, List.of(), allowedInputs, null, null); - } - public @NotNull String getName() { return name; } diff --git a/commands/src/main/java/com/wizardlybump17/wlib/command/node/LiteralCommandNode.java b/commands/src/main/java/com/wizardlybump17/wlib/command/node/LiteralCommandNode.java index 3ca15e83..180774ac 100644 --- a/commands/src/main/java/com/wizardlybump17/wlib/command/node/LiteralCommandNode.java +++ b/commands/src/main/java/com/wizardlybump17/wlib/command/node/LiteralCommandNode.java @@ -15,34 +15,6 @@ public LiteralCommandNode(@NotNull String name, @NotNull List> ch super(name, children, AllowedStringInputs.valueIgnoreCase(name), StringSuggester.value(name), executor, permission); } - public LiteralCommandNode(@NotNull String name, @Nullable CommandNodeExecutor executor, @Nullable String permission) { - this(name, List.of(), executor, permission); - } - - public LiteralCommandNode(@NotNull String name, @NotNull List> children, @Nullable String permission) { - this(name, children, null, permission); - } - - public LiteralCommandNode(@NotNull String name, @Nullable String permission) { - this(name, List.of(), null, permission); - } - - public LiteralCommandNode(@NotNull String name, @NotNull List> children, @Nullable CommandNodeExecutor executor) { - this(name, children, executor, null); - } - - public LiteralCommandNode(@NotNull String name, @Nullable CommandNodeExecutor executor) { - this(name, List.of(), executor, null); - } - - public LiteralCommandNode(@NotNull String name, @NotNull List> children) { - this(name, children, null, null); - } - - public LiteralCommandNode(@NotNull String name) { - this(name, List.of(), null, null); - } - @Override public @NotNull AllowedStringInputs.Value getAllowedInputs() { return (AllowedStringInputs.Value) super.getAllowedInputs(); diff --git a/commands/src/main/java/com/wizardlybump17/wlib/command/node/object/UUIDCommandNode.java b/commands/src/main/java/com/wizardlybump17/wlib/command/node/object/UUIDCommandNode.java index 71906849..717e208d 100644 --- a/commands/src/main/java/com/wizardlybump17/wlib/command/node/object/UUIDCommandNode.java +++ b/commands/src/main/java/com/wizardlybump17/wlib/command/node/object/UUIDCommandNode.java @@ -18,39 +18,16 @@ public UUIDCommandNode(@NotNull String name, @NotNull @Unmodifiable List> children, @NotNull AllowedUUIDInputs allowedInputs, @Nullable CommandNodeExecutor executor, @Nullable String permission) { - super(name, children, allowedInputs, executor, permission); - } - - public UUIDCommandNode(@NotNull String name, @NotNull AllowedUUIDInputs allowedInputs, @Nullable CommandNodeExecutor executor, @Nullable String permission) { - super(name, allowedInputs, executor, permission); - } - - public UUIDCommandNode(@NotNull String name, @NotNull List> children, @NotNull AllowedUUIDInputs allowedInputs, @Nullable String permission) { - super(name, children, allowedInputs, permission); - } - - public UUIDCommandNode(@NotNull String name, @NotNull AllowedUUIDInputs allowedInputs, @Nullable String permission) { - super(name, allowedInputs, permission); - } - - public UUIDCommandNode(@NotNull String name, @NotNull AllowedUUIDInputs allowedInputs, @Nullable CommandNodeExecutor executor) { - super(name, allowedInputs, executor); - } - - public UUIDCommandNode(@NotNull String name, @NotNull List> children, @NotNull AllowedUUIDInputs allowedInputs) { - super(name, children, allowedInputs); - } - - public UUIDCommandNode(@NotNull String name, @NotNull AllowedUUIDInputs allowedInputs) { - super(name, allowedInputs); - } - @Override public @NotNull AllowedUUIDInputs getAllowedInputs() { return (AllowedUUIDInputs) super.getAllowedInputs(); } + @Override + public @Nullable UUIDSuggester getSuggester() { + return (UUIDSuggester) super.getSuggester(); + } + @Override public @Nullable UUID parse(@NotNull String input) throws InputParsingException { try { @@ -62,16 +39,16 @@ public UUIDCommandNode(@NotNull String name, @NotNull AllowedUUIDInputs allowedI @Override public @NotNull UUIDCommandNode withChildren(@NotNull List> children) { - return new UUIDCommandNode(getName(), children, getAllowedInputs(), getExecutor(), getPermission()); + return new UUIDCommandNode(getName(), children, getAllowedInputs(), getSuggester(), getExecutor(), getPermission()); } @Override public @NotNull UUIDCommandNode withExecutor(@Nullable CommandNodeExecutor executor) { - return new UUIDCommandNode(getName(), getChildren(), getAllowedInputs(), executor, getPermission()); + return new UUIDCommandNode(getName(), getChildren(), getAllowedInputs(), getSuggester(), executor, getPermission()); } @Override public @NotNull UUIDCommandNode withPermission(@Nullable String permission) { - return new UUIDCommandNode(getName(), getChildren(), getAllowedInputs(), getExecutor(), permission); + return new UUIDCommandNode(getName(), getChildren(), getAllowedInputs(), getSuggester(), getExecutor(), permission); } } diff --git a/commands/src/main/java/com/wizardlybump17/wlib/command/node/primitive/AbstractPrimitiveCommandNode.java b/commands/src/main/java/com/wizardlybump17/wlib/command/node/primitive/AbstractPrimitiveCommandNode.java index 02271272..8578fe08 100644 --- a/commands/src/main/java/com/wizardlybump17/wlib/command/node/primitive/AbstractPrimitiveCommandNode.java +++ b/commands/src/main/java/com/wizardlybump17/wlib/command/node/primitive/AbstractPrimitiveCommandNode.java @@ -2,7 +2,6 @@ import com.wizardlybump17.wlib.command.executor.CommandNodeExecutor; import com.wizardlybump17.wlib.command.input.AllowedInputs; -import com.wizardlybump17.wlib.command.input.primitive.PrimitiveAllowedInputs; import com.wizardlybump17.wlib.command.node.CommandNode; import com.wizardlybump17.wlib.command.suggestion.Suggester; import org.jetbrains.annotations.NotNull; @@ -16,32 +15,4 @@ public abstract class AbstractPrimitiveCommandNode

extends CommandNode

imp public AbstractPrimitiveCommandNode(@NotNull String name, @NotNull @Unmodifiable List> children, @NotNull AllowedInputs

allowedInputs, @Nullable Suggester

suggester, @Nullable CommandNodeExecutor executor, @Nullable String permission) { super(name, children, allowedInputs, suggester, executor, permission); } - - public AbstractPrimitiveCommandNode(@NotNull String name, @NotNull List> children, @NotNull PrimitiveAllowedInputs

allowedInputs, @Nullable CommandNodeExecutor executor, @Nullable String permission) { - super(name, children, allowedInputs, executor, permission); - } - - public AbstractPrimitiveCommandNode(@NotNull String name, @NotNull PrimitiveAllowedInputs

allowedInputs, @Nullable CommandNodeExecutor executor, @Nullable String permission) { - super(name, allowedInputs, executor, permission); - } - - public AbstractPrimitiveCommandNode(@NotNull String name, @NotNull List> children, @NotNull PrimitiveAllowedInputs

allowedInputs, @Nullable String permission) { - super(name, children, allowedInputs, permission); - } - - public AbstractPrimitiveCommandNode(@NotNull String name, @NotNull PrimitiveAllowedInputs

allowedInputs, @Nullable String permission) { - super(name, allowedInputs, permission); - } - - public AbstractPrimitiveCommandNode(@NotNull String name, @NotNull PrimitiveAllowedInputs

allowedInputs, @Nullable CommandNodeExecutor executor) { - super(name, allowedInputs, executor); - } - - public AbstractPrimitiveCommandNode(@NotNull String name, @NotNull List> children, @NotNull PrimitiveAllowedInputs

allowedInputs) { - super(name, children, allowedInputs); - } - - public AbstractPrimitiveCommandNode(@NotNull String name, @NotNull PrimitiveAllowedInputs

allowedInputs) { - super(name, allowedInputs); - } } diff --git a/commands/src/main/java/com/wizardlybump17/wlib/command/node/primitive/BooleanCommandNode.java b/commands/src/main/java/com/wizardlybump17/wlib/command/node/primitive/BooleanCommandNode.java index 8bd5e763..e8ad719d 100644 --- a/commands/src/main/java/com/wizardlybump17/wlib/command/node/primitive/BooleanCommandNode.java +++ b/commands/src/main/java/com/wizardlybump17/wlib/command/node/primitive/BooleanCommandNode.java @@ -17,39 +17,16 @@ public BooleanCommandNode(@NotNull String name, @NotNull @Unmodifiable List> children, @NotNull AllowedBooleanInputs allowedInputs, @Nullable CommandNodeExecutor executor, @Nullable String permission) { - super(name, children, allowedInputs, executor, permission); - } - - public BooleanCommandNode(@NotNull String name, @NotNull AllowedBooleanInputs allowedInputs, @Nullable CommandNodeExecutor executor, @Nullable String permission) { - super(name, allowedInputs, executor, permission); - } - - public BooleanCommandNode(@NotNull String name, @NotNull List> children, @NotNull AllowedBooleanInputs allowedInputs, @Nullable String permission) { - super(name, children, allowedInputs, permission); - } - - public BooleanCommandNode(@NotNull String name, @NotNull AllowedBooleanInputs allowedInputs, @Nullable String permission) { - super(name, allowedInputs, permission); - } - - public BooleanCommandNode(@NotNull String name, @NotNull AllowedBooleanInputs allowedInputs, @Nullable CommandNodeExecutor executor) { - super(name, allowedInputs, executor); - } - - public BooleanCommandNode(@NotNull String name, @NotNull List> children, @NotNull AllowedBooleanInputs allowedInputs) { - super(name, children, allowedInputs); - } - - public BooleanCommandNode(@NotNull String name, @NotNull AllowedBooleanInputs allowedInputs) { - super(name, allowedInputs); - } - @Override public @NotNull AllowedBooleanInputs getAllowedInputs() { return (AllowedBooleanInputs) super.getAllowedInputs(); } + @Override + public @Nullable BooleanSuggester getSuggester() { + return (BooleanSuggester) super.getSuggester(); + } + @Override public @Nullable Boolean parse(@NotNull String input) throws InputParsingException { if (input.equalsIgnoreCase("true")) @@ -61,16 +38,16 @@ public BooleanCommandNode(@NotNull String name, @NotNull AllowedBooleanInputs al @Override public @NotNull BooleanCommandNode withChildren(@NotNull List> children) { - return new BooleanCommandNode(getName(), children, getAllowedInputs(), getExecutor(), getPermission()); + return new BooleanCommandNode(getName(), children, getAllowedInputs(), getSuggester(), getExecutor(), getPermission()); } @Override public @NotNull BooleanCommandNode withExecutor(@Nullable CommandNodeExecutor executor) { - return new BooleanCommandNode(getName(), getChildren(), getAllowedInputs(), executor, getPermission()); + return new BooleanCommandNode(getName(), getChildren(), getAllowedInputs(), getSuggester(), executor, getPermission()); } @Override public @NotNull BooleanCommandNode withPermission(@Nullable String permission) { - return new BooleanCommandNode(getName(), getChildren(), getAllowedInputs(), getExecutor(), permission); + return new BooleanCommandNode(getName(), getChildren(), getAllowedInputs(), getSuggester(), getExecutor(), permission); } } diff --git a/commands/src/main/java/com/wizardlybump17/wlib/command/node/primitive/CharacterCommandNode.java b/commands/src/main/java/com/wizardlybump17/wlib/command/node/primitive/CharacterCommandNode.java index 3d2a86ea..284a562e 100644 --- a/commands/src/main/java/com/wizardlybump17/wlib/command/node/primitive/CharacterCommandNode.java +++ b/commands/src/main/java/com/wizardlybump17/wlib/command/node/primitive/CharacterCommandNode.java @@ -17,39 +17,16 @@ public CharacterCommandNode(@NotNull String name, @NotNull @Unmodifiable List> children, @NotNull AllowedCharacterInputs allowedInputs, @Nullable CommandNodeExecutor executor, @Nullable String permission) { - super(name, children, allowedInputs, executor, permission); - } - - public CharacterCommandNode(@NotNull String name, @NotNull AllowedCharacterInputs allowedInputs, @Nullable CommandNodeExecutor executor, @Nullable String permission) { - super(name, allowedInputs, executor, permission); - } - - public CharacterCommandNode(@NotNull String name, @NotNull List> children, @NotNull AllowedCharacterInputs allowedInputs, @Nullable String permission) { - super(name, children, allowedInputs, permission); - } - - public CharacterCommandNode(@NotNull String name, @NotNull AllowedCharacterInputs allowedInputs, @Nullable String permission) { - super(name, allowedInputs, permission); - } - - public CharacterCommandNode(@NotNull String name, @NotNull AllowedCharacterInputs allowedInputs, @Nullable CommandNodeExecutor executor) { - super(name, allowedInputs, executor); - } - - public CharacterCommandNode(@NotNull String name, @NotNull List> children, @NotNull AllowedCharacterInputs allowedInputs) { - super(name, children, allowedInputs); - } - - public CharacterCommandNode(@NotNull String name, @NotNull AllowedCharacterInputs allowedInputs) { - super(name, allowedInputs); - } - @Override public @NotNull AllowedCharacterInputs getAllowedInputs() { return (AllowedCharacterInputs) super.getAllowedInputs(); } + @Override + public @Nullable CharacterSuggester getSuggester() { + return (CharacterSuggester) super.getSuggester(); + } + @Override public @Nullable Character parse(@NotNull String input) throws InputParsingException { if (input.length() != 1) @@ -59,16 +36,16 @@ public CharacterCommandNode(@NotNull String name, @NotNull AllowedCharacterInput @Override public @NotNull CharacterCommandNode withChildren(@NotNull List> children) { - return new CharacterCommandNode(getName(), children, getAllowedInputs(), getExecutor(), getPermission()); + return new CharacterCommandNode(getName(), children, getAllowedInputs(), getSuggester(), getExecutor(), getPermission()); } @Override public @NotNull CharacterCommandNode withExecutor(@Nullable CommandNodeExecutor executor) { - return new CharacterCommandNode(getName(), getChildren(), getAllowedInputs(), executor, getPermission()); + return new CharacterCommandNode(getName(), getChildren(), getAllowedInputs(), getSuggester(), executor, getPermission()); } @Override public @NotNull CharacterCommandNode withPermission(@Nullable String permission) { - return new CharacterCommandNode(getName(), getChildren(), getAllowedInputs(), getExecutor(), permission); + return new CharacterCommandNode(getName(), getChildren(), getAllowedInputs(), getSuggester(), getExecutor(), permission); } } diff --git a/commands/src/main/java/com/wizardlybump17/wlib/command/node/primitive/number/ByteCommandNode.java b/commands/src/main/java/com/wizardlybump17/wlib/command/node/primitive/number/ByteCommandNode.java index 3c0999eb..b5c8b6b2 100644 --- a/commands/src/main/java/com/wizardlybump17/wlib/command/node/primitive/number/ByteCommandNode.java +++ b/commands/src/main/java/com/wizardlybump17/wlib/command/node/primitive/number/ByteCommandNode.java @@ -17,38 +17,6 @@ public ByteCommandNode(@NotNull String name, @NotNull List> child super(name, children, allowedInputs, suggester, executor, permission); } - public ByteCommandNode(@NotNull String name, @NotNull List> children, @NotNull AllowedByteInputs allowedInputs, @Nullable CommandNodeExecutor executor, @Nullable String permission) { - this(name, children, allowedInputs, null, executor, permission); - } - - public ByteCommandNode(@NotNull String name, @NotNull AllowedByteInputs allowedInputs, @Nullable CommandNodeExecutor executor, @Nullable String permission) { - this(name, List.of(), allowedInputs, null, executor, permission); - } - - public ByteCommandNode(@NotNull String name, @NotNull List> children, @NotNull AllowedByteInputs allowedInputs, @Nullable String permission) { - this(name, children, allowedInputs, null, null, permission); - } - - public ByteCommandNode(@NotNull String name, @NotNull AllowedByteInputs allowedInputs, @Nullable String permission) { - this(name, List.of(), allowedInputs, null, null, permission); - } - - public ByteCommandNode(@NotNull String name, @NotNull List> children, @NotNull AllowedByteInputs allowedInputs, @Nullable CommandNodeExecutor executor) { - this(name, children, allowedInputs, null, executor, null); - } - - public ByteCommandNode(@NotNull String name, @NotNull AllowedByteInputs allowedInputs, @Nullable CommandNodeExecutor executor) { - this(name, List.of(), allowedInputs, null, executor, null); - } - - public ByteCommandNode(@NotNull String name, @NotNull List> children, @NotNull AllowedByteInputs allowedInputs) { - this(name, children, allowedInputs, null, null, null); - } - - public ByteCommandNode(@NotNull String name, @NotNull AllowedByteInputs allowedInputs) { - this(name, List.of(), allowedInputs, null, null, null); - } - @Override public @NotNull AllowedByteInputs getAllowedInputs() { return (AllowedByteInputs) super.getAllowedInputs(); diff --git a/commands/src/main/java/com/wizardlybump17/wlib/command/node/primitive/number/DoubleCommandNode.java b/commands/src/main/java/com/wizardlybump17/wlib/command/node/primitive/number/DoubleCommandNode.java index e2dc9c6b..2c40547b 100644 --- a/commands/src/main/java/com/wizardlybump17/wlib/command/node/primitive/number/DoubleCommandNode.java +++ b/commands/src/main/java/com/wizardlybump17/wlib/command/node/primitive/number/DoubleCommandNode.java @@ -17,43 +17,16 @@ public DoubleCommandNode(@NotNull String name, @NotNull List> chi super(name, children, allowedInputs, suggester, executor, permission); } - public DoubleCommandNode(@NotNull String name, @NotNull List> children, @NotNull AllowedDoubleInputs allowedInputs, @Nullable CommandNodeExecutor executor, @Nullable String permission) { - super(name, children, allowedInputs, executor, permission); - } - - public DoubleCommandNode(@NotNull String name, @NotNull AllowedDoubleInputs allowedInputs, @Nullable CommandNodeExecutor executor, @Nullable String permission) { - this(name, List.of(), allowedInputs, executor, permission); - } - - public DoubleCommandNode(@NotNull String name, @NotNull List> children, @NotNull AllowedDoubleInputs allowedInputs, @Nullable String permission) { - this(name, children, allowedInputs, null, permission); - } - - public DoubleCommandNode(@NotNull String name, @NotNull AllowedDoubleInputs allowedInputs, @Nullable String permission) { - this(name, List.of(), allowedInputs, null, permission); - } - - public DoubleCommandNode(@NotNull String name, @NotNull List> children, @NotNull AllowedDoubleInputs allowedInputs, @Nullable CommandNodeExecutor executor) { - super(name, children, allowedInputs, executor, null); - } - - public DoubleCommandNode(@NotNull String name, @NotNull AllowedDoubleInputs allowedInputs, @Nullable CommandNodeExecutor executor) { - this(name, List.of(), allowedInputs, executor, null); - } - - public DoubleCommandNode(@NotNull String name, @NotNull List> children, @NotNull AllowedDoubleInputs allowedInputs) { - this(name, children, allowedInputs, null, null); - } - - public DoubleCommandNode(@NotNull String name, @NotNull AllowedDoubleInputs allowedInputs) { - this(name, List.of(), allowedInputs, null, null); - } - @Override public @NotNull AllowedDoubleInputs getAllowedInputs() { return (AllowedDoubleInputs) super.getAllowedInputs(); } + @Override + public @Nullable DoubleSuggester getSuggester() { + return (DoubleSuggester) super.getSuggester(); + } + @Override public @NotNull Double parse(@NotNull String input) throws InputParsingException { try { @@ -65,16 +38,16 @@ public DoubleCommandNode(@NotNull String name, @NotNull AllowedDoubleInputs allo @Override public @NotNull DoubleCommandNode withChildren(@NotNull List> children) { - return new DoubleCommandNode(getName(), children, getAllowedInputs(), getExecutor(), getPermission()); + return new DoubleCommandNode(getName(), children, getAllowedInputs(), getSuggester(), getExecutor(), getPermission()); } @Override public @NotNull DoubleCommandNode withExecutor(@Nullable CommandNodeExecutor executor) { - return new DoubleCommandNode(getName(), getChildren(), getAllowedInputs(), executor, getPermission()); + return new DoubleCommandNode(getName(), getChildren(), getAllowedInputs(), getSuggester(), executor, getPermission()); } @Override public @NotNull DoubleCommandNode withPermission(@Nullable String permission) { - return new DoubleCommandNode(getName(), getChildren(), getAllowedInputs(), getExecutor(), permission); + return new DoubleCommandNode(getName(), getChildren(), getAllowedInputs(), getSuggester(), getExecutor(), permission); } } diff --git a/commands/src/main/java/com/wizardlybump17/wlib/command/node/primitive/number/FloatCommandNode.java b/commands/src/main/java/com/wizardlybump17/wlib/command/node/primitive/number/FloatCommandNode.java index a58910e0..19fbe868 100644 --- a/commands/src/main/java/com/wizardlybump17/wlib/command/node/primitive/number/FloatCommandNode.java +++ b/commands/src/main/java/com/wizardlybump17/wlib/command/node/primitive/number/FloatCommandNode.java @@ -17,43 +17,16 @@ public FloatCommandNode(@NotNull String name, @NotNull List> chil super(name, children, allowedInputs, suggester, executor, permission); } - public FloatCommandNode(@NotNull String name, @NotNull List> children, @NotNull AllowedFloatInputs allowedInputs, @Nullable CommandNodeExecutor executor, @Nullable String permission) { - super(name, children, allowedInputs, executor, permission); - } - - public FloatCommandNode(@NotNull String name, @NotNull AllowedFloatInputs allowedInputs, @Nullable CommandNodeExecutor executor, @Nullable String permission) { - this(name, List.of(), allowedInputs, executor, permission); - } - - public FloatCommandNode(@NotNull String name, @NotNull List> children, @NotNull AllowedFloatInputs allowedInputs, @Nullable String permission) { - this(name, children, allowedInputs, null, permission); - } - - public FloatCommandNode(@NotNull String name, @NotNull AllowedFloatInputs allowedInputs, @Nullable String permission) { - this(name, List.of(), allowedInputs, null, permission); - } - - public FloatCommandNode(@NotNull String name, @NotNull List> children, @NotNull AllowedFloatInputs allowedInputs, @Nullable CommandNodeExecutor executor) { - super(name, children, allowedInputs, executor, null); - } - - public FloatCommandNode(@NotNull String name, @NotNull AllowedFloatInputs allowedInputs, @Nullable CommandNodeExecutor executor) { - this(name, List.of(), allowedInputs, executor, null); - } - - public FloatCommandNode(@NotNull String name, @NotNull List> children, @NotNull AllowedFloatInputs allowedInputs) { - this(name, children, allowedInputs, null, null); - } - - public FloatCommandNode(@NotNull String name, @NotNull AllowedFloatInputs allowedInputs) { - this(name, List.of(), allowedInputs, null, null); - } - @Override public @NotNull AllowedFloatInputs getAllowedInputs() { return (AllowedFloatInputs) super.getAllowedInputs(); } + @Override + public @Nullable FloatSuggester getSuggester() { + return (FloatSuggester) super.getSuggester(); + } + @Override public @NotNull Float parse(@NotNull String input) throws InputParsingException { try { @@ -65,16 +38,16 @@ public FloatCommandNode(@NotNull String name, @NotNull AllowedFloatInputs allowe @Override public @NotNull FloatCommandNode withChildren(@NotNull List> children) { - return new FloatCommandNode(getName(), children, getAllowedInputs(), getExecutor(), getPermission()); + return new FloatCommandNode(getName(), children, getAllowedInputs(), getSuggester(), getExecutor(), getPermission()); } @Override public @NotNull FloatCommandNode withExecutor(@Nullable CommandNodeExecutor executor) { - return new FloatCommandNode(getName(), getChildren(), getAllowedInputs(), executor, getPermission()); + return new FloatCommandNode(getName(), getChildren(), getAllowedInputs(), getSuggester(), executor, getPermission()); } @Override public @NotNull FloatCommandNode withPermission(@Nullable String permission) { - return new FloatCommandNode(getName(), getChildren(), getAllowedInputs(), getExecutor(), permission); + return new FloatCommandNode(getName(), getChildren(), getAllowedInputs(), getSuggester(), getExecutor(), permission); } } diff --git a/commands/src/main/java/com/wizardlybump17/wlib/command/node/primitive/number/IntegerCommandNode.java b/commands/src/main/java/com/wizardlybump17/wlib/command/node/primitive/number/IntegerCommandNode.java index eb7cd3cb..211b9400 100644 --- a/commands/src/main/java/com/wizardlybump17/wlib/command/node/primitive/number/IntegerCommandNode.java +++ b/commands/src/main/java/com/wizardlybump17/wlib/command/node/primitive/number/IntegerCommandNode.java @@ -19,38 +19,6 @@ public IntegerCommandNode(@NotNull String name, @NotNull List> ch super(name, children, allowedInputs, suggester, executor, permission); } - public IntegerCommandNode(@NotNull String name, @NotNull List> children, @NotNull AllowedIntegerInputs allowedInputs, @Nullable CommandNodeExecutor executor, @Nullable String permission) { - this(name, children, allowedInputs, null, executor, permission); - } - - public IntegerCommandNode(@NotNull String name, @NotNull AllowedIntegerInputs allowedInputs, @Nullable CommandNodeExecutor executor, @Nullable String permission) { - this(name, List.of(), allowedInputs, null, executor, permission); - } - - public IntegerCommandNode(@NotNull String name, @NotNull List> children, @NotNull AllowedIntegerInputs allowedInputs, @Nullable String permission) { - this(name, children, allowedInputs, null, null, permission); - } - - public IntegerCommandNode(@NotNull String name, @NotNull AllowedIntegerInputs allowedInputs, @Nullable String permission) { - this(name, List.of(), allowedInputs, null, null, permission); - } - - public IntegerCommandNode(@NotNull String name, @NotNull List> children, @NotNull AllowedIntegerInputs allowedInputs, @Nullable CommandNodeExecutor executor) { - this(name, children, allowedInputs, null, executor, null); - } - - public IntegerCommandNode(@NotNull String name, @NotNull AllowedIntegerInputs allowedInputs, @Nullable CommandNodeExecutor executor) { - this(name, List.of(), allowedInputs, null, executor, null); - } - - public IntegerCommandNode(@NotNull String name, @NotNull List> children, @NotNull AllowedIntegerInputs allowedInputs) { - this(name, children, allowedInputs, null, null, null); - } - - public IntegerCommandNode(@NotNull String name, @NotNull AllowedIntegerInputs allowedInputs) { - this(name, List.of(), allowedInputs, null, null, null); - } - @Override public @NotNull AllowedIntegerInputs getAllowedInputs() { return (AllowedIntegerInputs) super.getAllowedInputs(); diff --git a/commands/src/main/java/com/wizardlybump17/wlib/command/node/primitive/number/LongCommandNode.java b/commands/src/main/java/com/wizardlybump17/wlib/command/node/primitive/number/LongCommandNode.java index b2bf0446..8b35d2b9 100644 --- a/commands/src/main/java/com/wizardlybump17/wlib/command/node/primitive/number/LongCommandNode.java +++ b/commands/src/main/java/com/wizardlybump17/wlib/command/node/primitive/number/LongCommandNode.java @@ -17,38 +17,6 @@ public LongCommandNode(@NotNull String name, @NotNull List> child super(name, children, allowedInputs, suggester, executor, permission); } - public LongCommandNode(@NotNull String name, @NotNull List> children, @NotNull AllowedLongInputs allowedInputs, @Nullable CommandNodeExecutor executor, @Nullable String permission) { - this(name, children, allowedInputs, null, executor, permission); - } - - public LongCommandNode(@NotNull String name, @NotNull AllowedLongInputs allowedInputs, @Nullable CommandNodeExecutor executor, @Nullable String permission) { - this(name, List.of(), allowedInputs, null, executor, permission); - } - - public LongCommandNode(@NotNull String name, @NotNull List> children, @NotNull AllowedLongInputs allowedInputs, @Nullable String permission) { - this(name, children, allowedInputs, null, null, permission); - } - - public LongCommandNode(@NotNull String name, @NotNull AllowedLongInputs allowedInputs, @Nullable String permission) { - this(name, List.of(), allowedInputs, null, null, permission); - } - - public LongCommandNode(@NotNull String name, @NotNull List> children, @NotNull AllowedLongInputs allowedInputs, @Nullable CommandNodeExecutor executor) { - this(name, children, allowedInputs, null, executor, null); - } - - public LongCommandNode(@NotNull String name, @NotNull AllowedLongInputs allowedInputs, @Nullable CommandNodeExecutor executor) { - this(name, List.of(), allowedInputs, null, executor, null); - } - - public LongCommandNode(@NotNull String name, @NotNull List> children, @NotNull AllowedLongInputs allowedInputs) { - this(name, children, allowedInputs, null, null, null); - } - - public LongCommandNode(@NotNull String name, @NotNull AllowedLongInputs allowedInputs) { - this(name, List.of(), allowedInputs, null, null, null); - } - @Override public @NotNull AllowedLongInputs getAllowedInputs() { return (AllowedLongInputs) super.getAllowedInputs(); diff --git a/commands/src/main/java/com/wizardlybump17/wlib/command/node/primitive/number/NumberCommandNode.java b/commands/src/main/java/com/wizardlybump17/wlib/command/node/primitive/number/NumberCommandNode.java index a101e916..8827ec30 100644 --- a/commands/src/main/java/com/wizardlybump17/wlib/command/node/primitive/number/NumberCommandNode.java +++ b/commands/src/main/java/com/wizardlybump17/wlib/command/node/primitive/number/NumberCommandNode.java @@ -4,6 +4,7 @@ import com.wizardlybump17.wlib.command.input.AllowedInputs; import com.wizardlybump17.wlib.command.node.CommandNode; import com.wizardlybump17.wlib.command.suggestion.Suggester; +import com.wizardlybump17.wlib.command.suggestion.primitive.number.NumberSuggester; import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.Nullable; @@ -15,32 +16,9 @@ public NumberCommandNode(@NotNull String name, @NotNull List> chi super(name, children, allowedInputs, suggester, executor, permission); } - public NumberCommandNode(@NotNull String name, @NotNull List> children, @NotNull AllowedInputs allowedInputs, @Nullable CommandNodeExecutor executor, @Nullable String permission) { - super(name, children, allowedInputs, executor, permission); - } - - public NumberCommandNode(@NotNull String name, @NotNull AllowedInputs allowedInputs, @Nullable CommandNodeExecutor executor, @Nullable String permission) { - super(name, allowedInputs, executor, permission); - } - - public NumberCommandNode(@NotNull String name, @NotNull List> children, @NotNull AllowedInputs allowedInputs, @Nullable String permission) { - super(name, children, allowedInputs, permission); - } - - public NumberCommandNode(@NotNull String name, @NotNull AllowedInputs allowedInputs, @Nullable String permission) { - super(name, allowedInputs, permission); - } - - public NumberCommandNode(@NotNull String name, @NotNull AllowedInputs allowedInputs, @Nullable CommandNodeExecutor executor) { - super(name, allowedInputs, executor); - } - - public NumberCommandNode(@NotNull String name, @NotNull List> children, @NotNull AllowedInputs allowedInputs) { - super(name, children, allowedInputs); - } - - public NumberCommandNode(@NotNull String name, @NotNull AllowedInputs allowedInputs) { - super(name, allowedInputs); + @Override + public @Nullable NumberSuggester getSuggester() { + return (NumberSuggester) super.getSuggester(); } @Override diff --git a/commands/src/main/java/com/wizardlybump17/wlib/command/node/primitive/number/ShortCommandNode.java b/commands/src/main/java/com/wizardlybump17/wlib/command/node/primitive/number/ShortCommandNode.java index b6efa6e5..c5ff2b92 100644 --- a/commands/src/main/java/com/wizardlybump17/wlib/command/node/primitive/number/ShortCommandNode.java +++ b/commands/src/main/java/com/wizardlybump17/wlib/command/node/primitive/number/ShortCommandNode.java @@ -19,38 +19,6 @@ public ShortCommandNode(@NotNull String name, @NotNull List> chil super(name, children, allowedInputs, suggester, executor, permission); } - public ShortCommandNode(@NotNull String name, @NotNull List> children, @NotNull AllowedShortInputs allowedInputs, @Nullable CommandNodeExecutor executor, @Nullable String permission) { - this(name, children, allowedInputs, null, executor, permission); - } - - public ShortCommandNode(@NotNull String name, @NotNull AllowedShortInputs allowedInputs, @Nullable CommandNodeExecutor executor, @Nullable String permission) { - this(name, List.of(), allowedInputs, null, executor, permission); - } - - public ShortCommandNode(@NotNull String name, @NotNull List> children, @NotNull AllowedShortInputs allowedInputs, @Nullable String permission) { - this(name, children, allowedInputs, null, null, permission); - } - - public ShortCommandNode(@NotNull String name, @NotNull AllowedShortInputs allowedInputs, @Nullable String permission) { - this(name, List.of(), allowedInputs, null, null, permission); - } - - public ShortCommandNode(@NotNull String name, @NotNull List> children, @NotNull AllowedShortInputs allowedInputs, @Nullable CommandNodeExecutor executor) { - this(name, children, allowedInputs, null, executor, null); - } - - public ShortCommandNode(@NotNull String name, @NotNull AllowedShortInputs allowedInputs, @Nullable CommandNodeExecutor executor) { - this(name, List.of(), allowedInputs, null, executor, null); - } - - public ShortCommandNode(@NotNull String name, @NotNull List> children, @NotNull AllowedShortInputs allowedInputs) { - this(name, children, allowedInputs, null, null, null); - } - - public ShortCommandNode(@NotNull String name, @NotNull AllowedShortInputs allowedInputs) { - this(name, List.of(), allowedInputs, null, null, null); - } - @Override public @NotNull AllowedShortInputs getAllowedInputs() { return (AllowedShortInputs) super.getAllowedInputs(); diff --git a/commands/src/main/java/com/wizardlybump17/wlib/command/node/string/StringCommandNode.java b/commands/src/main/java/com/wizardlybump17/wlib/command/node/string/StringCommandNode.java index 4f4f4fb8..b4cfa4e2 100644 --- a/commands/src/main/java/com/wizardlybump17/wlib/command/node/string/StringCommandNode.java +++ b/commands/src/main/java/com/wizardlybump17/wlib/command/node/string/StringCommandNode.java @@ -17,39 +17,16 @@ public StringCommandNode(@NotNull String name, @NotNull @Unmodifiable List> children, @NotNull AllowedStringInputs allowedInputs, @Nullable CommandNodeExecutor executor, @Nullable String permission) { - super(name, children, allowedInputs, executor, permission); - } - - public StringCommandNode(@NotNull String name, @NotNull AllowedStringInputs allowedInputs, @Nullable CommandNodeExecutor executor, @Nullable String permission) { - super(name, allowedInputs, executor, permission); - } - - public StringCommandNode(@NotNull String name, @NotNull List> children, @NotNull AllowedStringInputs allowedInputs, @Nullable String permission) { - super(name, children, allowedInputs, permission); - } - - public StringCommandNode(@NotNull String name, @NotNull AllowedStringInputs allowedInputs, @Nullable String permission) { - super(name, allowedInputs, permission); - } - - public StringCommandNode(@NotNull String name, @NotNull AllowedStringInputs allowedInputs, @Nullable CommandNodeExecutor executor) { - super(name, allowedInputs, executor); - } - - public StringCommandNode(@NotNull String name, @NotNull List> children, @NotNull AllowedStringInputs allowedInputs) { - super(name, children, allowedInputs); - } - - public StringCommandNode(@NotNull String name, @NotNull AllowedStringInputs allowedInputs) { - super(name, allowedInputs); - } - @Override public @NotNull AllowedStringInputs getAllowedInputs() { return (AllowedStringInputs) super.getAllowedInputs(); } + @Override + public @Nullable StringSuggester getSuggester() { + return (StringSuggester) super.getSuggester(); + } + @Override public @Nullable String parse(@NotNull String input) throws InputParsingException { return input; @@ -57,16 +34,16 @@ public StringCommandNode(@NotNull String name, @NotNull AllowedStringInputs allo @Override public @NotNull StringCommandNode withChildren(@NotNull List> children) { - return new StringCommandNode(getName(), children, getAllowedInputs(), getExecutor(), getPermission()); + return new StringCommandNode(getName(), children, getAllowedInputs(), getSuggester(), getExecutor(), getPermission()); } @Override public @NotNull StringCommandNode withExecutor(@Nullable CommandNodeExecutor executor) { - return new StringCommandNode(getName(), getChildren(), getAllowedInputs(), executor, getPermission()); + return new StringCommandNode(getName(), getChildren(), getAllowedInputs(), getSuggester(), executor, getPermission()); } @Override public @NotNull StringCommandNode withPermission(@Nullable String permission) { - return new StringCommandNode(getName(), getChildren(), getAllowedInputs(), getExecutor(), permission); + return new StringCommandNode(getName(), getChildren(), getAllowedInputs(), getSuggester(), getExecutor(), permission); } } From bb629ac8c99c6b74a20fc7d7ee994507adc31b12 Mon Sep 17 00:00:00 2001 From: WizardlyBump17 Date: Fri, 12 Dec 2025 23:22:00 -0300 Subject: [PATCH 233/363] x more to go --- .../method/MethodCommandExtractor.java | 4 +- .../result/error/CommandNotFoundResult.java | 2 +- .../wlib/test/command/CommandTests.java | 214 +++++++++++++++--- 3 files changed, 184 insertions(+), 36 deletions(-) diff --git a/commands/src/main/java/com/wizardlybump17/wlib/command/extractor/method/MethodCommandExtractor.java b/commands/src/main/java/com/wizardlybump17/wlib/command/extractor/method/MethodCommandExtractor.java index afd1c784..0b599fae 100644 --- a/commands/src/main/java/com/wizardlybump17/wlib/command/extractor/method/MethodCommandExtractor.java +++ b/commands/src/main/java/com/wizardlybump17/wlib/command/extractor/method/MethodCommandExtractor.java @@ -85,7 +85,7 @@ public boolean isAccepted(@NotNull Object object) { part = part.substring(1, part.length() - 1); if (parameterIndex < 0) { - newNode = new LiteralCommandNode(part, root == null ? List.of() : List.of(root)); + newNode = new LiteralCommandNode(part, root == null ? List.of() : List.of(root), null, null); } else { if (argument) { Parameter parameter = parameters[parameterIndex]; @@ -97,7 +97,7 @@ public boolean isAccepted(@NotNull Object object) { newNode = factory.create(object, method, annotation, parameter, part, root); } else { - newNode = new LiteralCommandNode(part, root == null ? List.of() : List.of(root)); + newNode = new LiteralCommandNode(part, root == null ? List.of() : List.of(root), null, null); } } diff --git a/commands/src/main/java/com/wizardlybump17/wlib/command/result/error/CommandNotFoundResult.java b/commands/src/main/java/com/wizardlybump17/wlib/command/result/error/CommandNotFoundResult.java index 0e610b72..27bbe154 100644 --- a/commands/src/main/java/com/wizardlybump17/wlib/command/result/error/CommandNotFoundResult.java +++ b/commands/src/main/java/com/wizardlybump17/wlib/command/result/error/CommandNotFoundResult.java @@ -24,7 +24,7 @@ private static final class DummyNode extends CommandNode { public static final @NotNull DummyNode INSTANCE = new DummyNode(); private DummyNode() { - super("DummyNode", $ -> true); + super("DummyNode", List.of(), $ -> true, null, null, null); } @Override diff --git a/commands/src/test/java/com/wizardlybump17/wlib/test/command/CommandTests.java b/commands/src/test/java/com/wizardlybump17/wlib/test/command/CommandTests.java index 49118175..74c0c1c5 100644 --- a/commands/src/test/java/com/wizardlybump17/wlib/test/command/CommandTests.java +++ b/commands/src/test/java/com/wizardlybump17/wlib/test/command/CommandTests.java @@ -31,7 +31,12 @@ public class CommandTests { @Test void testSuccessHello() { - LiteralCommandNode helloNode = new LiteralCommandNode("hello", context -> CommandResult.successful(context, "hello")); + LiteralCommandNode helloNode = new LiteralCommandNode( + "hello", + List.of(), + context -> CommandResult.successful(context, "hello"), + null + ); Command command = new Command(helloNode); CommandResult expected = CommandResult.successful(0, helloNode, "hello"); @@ -42,8 +47,20 @@ void testSuccessHello() { @Test void testSuccessHelloWorld() { - LiteralCommandNode worldNode = new LiteralCommandNode("world", context -> CommandResult.successful(context, "hello world")); - Command command = new Command(new LiteralCommandNode("hello", List.of(worldNode))); + LiteralCommandNode worldNode = new LiteralCommandNode( + "world", + List.of(), + context -> CommandResult.successful(context, "hello world"), + null + ); + Command command = new Command( + new LiteralCommandNode( + "hello", + List.of(worldNode), + null, + null + ) + ); CommandResult expected = CommandResult.successful(1, worldNode, "hello world"); CommandResult actual = command.execute(CHAD_SENDER, List.of("hello", "world")); @@ -53,8 +70,27 @@ void testSuccessHelloWorld() { @Test void testSuccessHelloWorldHi() { - LiteralCommandNode hiNode = new LiteralCommandNode("hi", context -> CommandResult.successful(context, "hello world hi")); - Command command = new Command(new LiteralCommandNode("hello", List.of(new LiteralCommandNode("world", List.of(hiNode))))); + LiteralCommandNode hiNode = new LiteralCommandNode( + "hi", + List.of(), + context -> CommandResult.successful(context, "hello world hi"), + null + ); + Command command = new Command( + new LiteralCommandNode( + "hello", + List.of( + new LiteralCommandNode( + "world", + List.of(hiNode), + null, + null + ) + ), + null, + null + ) + ); CommandResult expected = CommandResult.successful(2, hiNode, "hello world hi"); CommandResult actual = command.execute(CHAD_SENDER, List.of("hello", "world", "hi")); @@ -65,13 +101,25 @@ void testSuccessHelloWorldHi() { @Test @DisplayName("Multiple children 0 (hello, hi): success") void test0() { - LiteralCommandNode hiNode = new LiteralCommandNode("hi", context -> CommandResult.successful(context, "hello hi")); + LiteralCommandNode hiNode = new LiteralCommandNode( + "hi", + List.of(), + context -> CommandResult.successful(context, "hello hi"), + null + ); Command command = new Command(new LiteralCommandNode( "hello", List.of( - new LiteralCommandNode("world", context -> CommandResult.successful(context, "hello world")), + new LiteralCommandNode( + "world", + List.of(), + context -> CommandResult.successful(context, "hello world"), + null + ), hiNode - ) + ), + null, + null )); CommandResult expected = CommandResult.successful(1, hiNode, "hello hi"); @@ -83,13 +131,30 @@ void test0() { @Test @DisplayName("Multiple children 1 (hello, hi, world): success") void test1() { - LiteralCommandNode hiWorldNode = new LiteralCommandNode("world0", context -> CommandResult.successful(context, "hello hi world")); + LiteralCommandNode hiWorldNode = new LiteralCommandNode( + "world0", + List.of(), + context -> CommandResult.successful(context, "hello hi world"), + null + ); Command command = new Command(new LiteralCommandNode( "hello", List.of( - new LiteralCommandNode("world", context -> CommandResult.successful(context, "hello world")), - new LiteralCommandNode("hi", List.of(hiWorldNode)) - ) + new LiteralCommandNode( + "world", + List.of(), + context -> CommandResult.successful(context, "hello world"), + null + ), + new LiteralCommandNode( + "hi", + List.of(hiWorldNode), + null, + null + ) + ), + null, + null )); CommandResult expected = CommandResult.successful(2, hiWorldNode, "hello hi world"); @@ -100,7 +165,12 @@ void test1() { @Test void testExtraArguments0() { - LiteralCommandNode helloNode = new LiteralCommandNode("hello", context -> CommandResult.successful(context, "hello")); + LiteralCommandNode helloNode = new LiteralCommandNode( + "hello", + List.of(), + context -> CommandResult.successful(context, "hello"), + null + ); Command command = new Command(helloNode); ExtraArgumentsResult expected = CommandResult.extraArguments(1, helloNode); @@ -111,11 +181,18 @@ void testExtraArguments0() { @Test void testExtraArguments1() { - LiteralCommandNode worldNode = new LiteralCommandNode("world", context -> CommandResult.successful(context, "hello world")); + LiteralCommandNode worldNode = new LiteralCommandNode( + "world", + List.of(), + context -> CommandResult.successful(context, "hello world"), + null + ); Command command = new Command( new LiteralCommandNode( "hello", - List.of(worldNode) + List.of(worldNode), + null, + null ) ); @@ -127,13 +204,30 @@ void testExtraArguments1() { @Test void testExtraArguments2() { - LiteralCommandNode hiWorldNode = new LiteralCommandNode("world0", context -> CommandResult.successful(context, "hello hi world")); + LiteralCommandNode hiWorldNode = new LiteralCommandNode( + "world0", + List.of(), + context -> CommandResult.successful(context, "hello hi world"), + null + ); Command command = new Command(new LiteralCommandNode( "hello", List.of( - new LiteralCommandNode("world", context -> CommandResult.successful(context, "hello world")), - new LiteralCommandNode("hi", List.of(hiWorldNode)) - ) + new LiteralCommandNode( + "world", + List.of(), + context -> CommandResult.successful(context, "hello world"), + null + ), + new LiteralCommandNode( + "hi", + List.of(hiWorldNode), + null, + null + ) + ), + null, + null )); ExtraArgumentsResult expected = CommandResult.extraArguments(3, hiWorldNode); @@ -145,9 +239,14 @@ void testExtraArguments2() { @Test void testException() { RuntimeException helloException = new RuntimeException("hello"); - LiteralCommandNode helloNode = new LiteralCommandNode("hello", context -> { - throw helloException; - }); + LiteralCommandNode helloNode = new LiteralCommandNode( + "hello", + List.of(), + context -> { + throw helloException; + }, + null + ); Command command = new Command(helloNode); ExceptionResult expected = CommandResult.exceptionally(0, helloNode, helloException); @@ -158,7 +257,14 @@ void testException() { @Test void testInsufficientArguments() { - Command command = new Command(new LiteralCommandNode("hello", context -> CommandResult.successful(context, "hello"))); + Command command = new Command( + new LiteralCommandNode( + "hello", + List.of(), + context -> CommandResult.successful(context, "hello"), + null + ) + ); InsufficientArgumentsResult expected = CommandResult.insufficientArguments(command); CommandResult actual = command.execute(CHAD_SENDER, List.of()); @@ -168,7 +274,12 @@ void testInsufficientArguments() { @Test void testNoPermission() { - LiteralCommandNode helloNode = new LiteralCommandNode("hello", context -> CommandResult.successful(context, "hello"), "permission"); + LiteralCommandNode helloNode = new LiteralCommandNode( + "hello", + List.of(), + context -> CommandResult.successful(context, "hello"), + "permission" + ); Command command = new Command(helloNode); NoPermissionResult expected = CommandResult.noPermission(0, helloNode); @@ -179,7 +290,12 @@ void testNoPermission() { @Test void testOutOfRange() { - LiteralCommandNode helloNode = new LiteralCommandNode("hello", context -> CommandResult.successful(context, "hello")); + LiteralCommandNode helloNode = new LiteralCommandNode( + "hello", + List.of(), + context -> CommandResult.successful(context, "hello"), + null + ); Command command = new Command(helloNode); OutOfRangeInputResult expected = CommandResult.outOfRangeInput(0, helloNode); @@ -190,8 +306,22 @@ void testOutOfRange() { @Test void testParseInputException() { - IntegerCommandNode worldNode = new IntegerCommandNode("world", AllowedIntegerInputs.value(10), context -> CommandResult.successful(context, 10)); - Command command = new Command(new LiteralCommandNode("hello", List.of(worldNode))); + IntegerCommandNode worldNode = new IntegerCommandNode( + "world", + List.of(), + AllowedIntegerInputs.value(10), + null, + context -> CommandResult.successful(context, 10), + null + ); + Command command = new Command( + new LiteralCommandNode( + "hello", + List.of(worldNode), + null, + null + ) + ); ParseInputExceptionResult expected = CommandResult.parseInputException(1, worldNode, new InputParsingException("Could not parse as int: world", new NumberFormatException("For input string: \"world\""))); CommandResult actual = command.execute(CHAD_SENDER, List.of("hello", "world")); @@ -207,7 +337,12 @@ void testParseInputException() { @Test void testCommandNodeExecutorNotFound() { - LiteralCommandNode helloNode = new LiteralCommandNode("hello"); + LiteralCommandNode helloNode = new LiteralCommandNode( + "hello", + List.of(), + null, + null + ); Command command = new Command(helloNode); CommandNodeExecutorNotFoundResult expected = CommandResult.noCommandNodeExecutor(0, helloNode); @@ -267,15 +402,19 @@ void testCommandArguments() { { LiteralCommandNode world = new LiteralCommandNode( "world", + List.of(), context -> { Assertions.assertEquals(Map.of(), context.arguments().getArguments()); return CommandResult.successful(context, "Hello World"); - } + }, + null ); CommandResult result = new Command( new LiteralCommandNode( "hello", - List.of(world) + List.of(world), + null, + null ) ).execute(CHAD_SENDER, List.of("hello", "world")); @@ -286,7 +425,9 @@ void testCommandArguments() { AtomicReference worldReference = new AtomicReference<>(); IntegerCommandNode world = new IntegerCommandNode( "world", + List.of(), AllowedIntegerInputs.unlimited(), + null, context -> { Assertions.assertEquals(Map.of("world", new CommandContext.CommandNodeArgument<>(worldReference.get(), "10", 10)), context.arguments().getArguments()); return CommandResult.successful(context, context.arguments().getArgumentData("world").orElseThrow()); @@ -298,7 +439,9 @@ void testCommandArguments() { CommandResult result = new Command( new LiteralCommandNode( "hello", - List.of(world) + List.of(world), + null, + null ) ).execute(CHAD_SENDER, List.of("hello", "10")); @@ -309,16 +452,19 @@ void testCommandArguments() { AtomicReference worldReference = new AtomicReference<>(); LiteralCommandNode test = new LiteralCommandNode( "test", + List.of(), context -> { Assertions.assertEquals(Map.of("world", new CommandContext.CommandNodeArgument<>(worldReference.get(), "10", 10)), context.arguments().getArguments()); return CommandResult.successful(context, "Hello " + context.arguments().getArgumentData("world").orElseThrow() + " world"); - } + }, + null ); IntegerCommandNode world = new IntegerCommandNode( "world", List.of(test), AllowedIntegerInputs.unlimited(), null, + null, null ); worldReference.set(world); @@ -326,7 +472,9 @@ void testCommandArguments() { CommandResult result = new Command( new LiteralCommandNode( "hello", - List.of(world) + List.of(world), + null, + null ) ).execute(CHAD_SENDER, List.of("hello", "10", "test")); From 0f0c8235d0cbb4754c6e0184ed9ca51e5de653af Mon Sep 17 00:00:00 2001 From: WizardlyBump17 Date: Fri, 12 Dec 2025 23:40:15 -0300 Subject: [PATCH 234/363] x more to go --- .../wlib/test/command/SuggestionTests.java | 143 +++++++++++++----- 1 file changed, 109 insertions(+), 34 deletions(-) diff --git a/commands/src/test/java/com/wizardlybump17/wlib/test/command/SuggestionTests.java b/commands/src/test/java/com/wizardlybump17/wlib/test/command/SuggestionTests.java index 438c6ba6..00550d19 100644 --- a/commands/src/test/java/com/wizardlybump17/wlib/test/command/SuggestionTests.java +++ b/commands/src/test/java/com/wizardlybump17/wlib/test/command/SuggestionTests.java @@ -41,9 +41,13 @@ void testSuccess0() { List.of( new LiteralCommandNode( "world", - context -> CommandResult.successful(context, "hello world") + List.of(), + context -> CommandResult.successful(context, "hello world"), + null ) - ) + ), + null, + null ) ); @@ -62,9 +66,13 @@ void testSuccess1() { List.of( new LiteralCommandNode( "world", - context -> CommandResult.successful(context, "hello world") + List.of(), + context -> CommandResult.successful(context, "hello world"), + null ) - ) + ), + null, + null ) ); @@ -83,17 +91,25 @@ void testSuccess2() { List.of( new LiteralCommandNode( "world", - context -> CommandResult.successful(context, "hello world") + List.of(), + context -> CommandResult.successful(context, "hello world"), + null ), new LiteralCommandNode( "hi", - context -> CommandResult.successful(context, "hello hi") + List.of(), + context -> CommandResult.successful(context, "hello hi"), + null ), new LiteralCommandNode( "there", - context -> CommandResult.successful(context, "hello there") + List.of(), + context -> CommandResult.successful(context, "hello there"), + null ) - ) + ), + null, + null ) ); @@ -112,11 +128,15 @@ void testSuccess3() { List.of( new LiteralCommandNode( "world", - context -> CommandResult.successful(context, "hello world") + List.of(), + context -> CommandResult.successful(context, "hello world"), + null ), new LiteralCommandNode( "hi", - context -> CommandResult.successful(context, "hello hi") + List.of(), + context -> CommandResult.successful(context, "hello hi"), + null ), new IntegerCommandNode( "there", @@ -126,7 +146,9 @@ void testSuccess3() { context -> CommandResult.successful(context, "hello there"), null ) - ) + ), + null, + null ) ); @@ -145,22 +167,33 @@ void testSuccess4() { List.of( new LiteralCommandNode( "world", - context -> CommandResult.successful(context, "hello world") + List.of(), + context -> CommandResult.successful(context, "hello world"), + null ), new LiteralCommandNode( "hi", - context -> CommandResult.successful(context, "hello hi") + List.of(), + context -> CommandResult.successful(context, "hello hi"), + null ), new IntegerCommandNode( "there", + List.of(), AllowedIntegerInputs.range(1, 10), - context -> CommandResult.successful(context, "hello there") + IntegerSuggester.range(1, 10), + context -> CommandResult.successful(context, "hello there"), + null ), new LiteralCommandNode( "happy", - context -> CommandResult.successful(context, "hello happy") + List.of(), + context -> CommandResult.successful(context, "hello happy"), + null ) - ) + ), + null, + null ) ); @@ -175,18 +208,36 @@ void testDefaultSuggestions() { //literal Assertions.assertEquals( List.of("hello"), - new Command(new LiteralCommandNode("hello")) - .getSuggestions(CHAD_SENDER, List.of()) + new Command( + new LiteralCommandNode( + "hello", + List.of(), + null, + null + ) + ).getSuggestions(CHAD_SENDER, List.of()) ); Assertions.assertEquals( List.of("hello"), - new Command(new LiteralCommandNode("hello")) - .getSuggestions(CHAD_SENDER, List.of("")) + new Command( + new LiteralCommandNode( + "hello", + List.of(), + null, + null + ) + ).getSuggestions(CHAD_SENDER, List.of("")) ); Assertions.assertEquals( List.of("hello"), - new Command(new LiteralCommandNode("hello")) - .getSuggestions(CHAD_SENDER, List.of("hel")) + new Command( + new LiteralCommandNode( + "hello", + List.of(), + null, + null + ) + ).getSuggestions(CHAD_SENDER, List.of("hel")) ); //byte @@ -204,7 +255,9 @@ void testDefaultSuggestions() { null, null ) - ) + ), + null, + null ) ).getSuggestions(CHAD_SENDER, List.of("hello", "")) ); @@ -222,7 +275,9 @@ void testDefaultSuggestions() { null, null ) - ) + ), + null, + null ) ).getSuggestions(CHAD_SENDER, List.of("hello", "0")) ); @@ -240,7 +295,9 @@ void testDefaultSuggestions() { null, null ) - ) + ), + null, + null ) ).getSuggestions(CHAD_SENDER, List.of("hello", "10")) ); @@ -260,7 +317,9 @@ void testDefaultSuggestions() { null, null ) - ) + ), + null, + null ) ).getSuggestions(CHAD_SENDER, List.of("hello", "")) ); @@ -278,7 +337,9 @@ void testDefaultSuggestions() { null, null ) - ) + ), + null, + null ) ).getSuggestions(CHAD_SENDER, List.of("hello", "0")) ); @@ -296,7 +357,9 @@ void testDefaultSuggestions() { null, null ) - ) + ), + null, + null ) ).getSuggestions(CHAD_SENDER, List.of("hello", "10")) ); @@ -316,7 +379,9 @@ void testDefaultSuggestions() { null, null ) - ) + ), + null, + null ) ).getSuggestions(CHAD_SENDER, List.of("hello", "")) ); @@ -334,7 +399,9 @@ void testDefaultSuggestions() { null, null ) - ) + ), + null, + null ) ).getSuggestions(CHAD_SENDER, List.of("hello", "0")) ); @@ -352,7 +419,9 @@ void testDefaultSuggestions() { null, null ) - ) + ), + null, + null ) ).getSuggestions(CHAD_SENDER, List.of("hello", "10")) ); @@ -372,7 +441,9 @@ void testDefaultSuggestions() { null, null ) - ) + ), + null, + null ) ).getSuggestions(CHAD_SENDER, List.of("hello", "")) ); @@ -390,7 +461,9 @@ void testDefaultSuggestions() { null, null ) - ) + ), + null, + null ) ).getSuggestions(CHAD_SENDER, List.of("hello", "0")) ); @@ -408,7 +481,9 @@ void testDefaultSuggestions() { null, null ) - ) + ), + null, + null ) ).getSuggestions(CHAD_SENDER, List.of("hello", "10")) ); From d39c78c7fd1260465bf3bca3de5fb16ed5228015 Mon Sep 17 00:00:00 2001 From: WizardlyBump17 Date: Fri, 12 Dec 2025 23:47:18 -0300 Subject: [PATCH 235/363] x more to go --- .../command/manager/CommandManagerTests.java | 125 +++++++++++++++--- 1 file changed, 109 insertions(+), 16 deletions(-) diff --git a/commands/src/test/java/com/wizardlybump17/wlib/test/command/manager/CommandManagerTests.java b/commands/src/test/java/com/wizardlybump17/wlib/test/command/manager/CommandManagerTests.java index 5acc0776..c3734118 100644 --- a/commands/src/test/java/com/wizardlybump17/wlib/test/command/manager/CommandManagerTests.java +++ b/commands/src/test/java/com/wizardlybump17/wlib/test/command/manager/CommandManagerTests.java @@ -25,10 +25,37 @@ class CommandManagerTests { @Test void testRegisterDifferent() { - Command command0 = new Command(new LiteralCommandNode("hello0", context -> CommandResult.successful(context, "hello0"), "permission")); - Command command1 = new Command(new LiteralCommandNode("hello1", context -> CommandResult.successful(context, "hello1"), "permission")); - Command command2 = new Command(new LiteralCommandNode("hello2", context -> CommandResult.successful(context, "hello2"), "permission")); - Command command3 = new Command(new LiteralCommandNode("hello3", context -> CommandResult.successful(context, "hello3"), "permission")); + Command command0 = new Command( + new LiteralCommandNode( + "hello0", + List.of(), + context -> CommandResult.successful(context, "hello0"), + "permission" + ) + ); + Command command1 = new Command( + new LiteralCommandNode( + "hello1", + List.of(), + context -> CommandResult.successful(context, "hello1"), + "permission" + ) + ); + Command command2 = new Command( + new LiteralCommandNode( + "hello2", + List.of(), + context -> CommandResult.successful(context, "hello2"), + "permission") + ); + Command command3 = new Command( + new LiteralCommandNode( + "hello3", + List.of(), + context -> CommandResult.successful(context, "hello3"), + "permission" + ) + ); CommandManager manager = new CommandManager(); @@ -52,6 +79,7 @@ void testRegisterMerging0() { Command command0 = new Command( new LiteralCommandNode( "hello", + List.of(), helloExecutor, "permission" ) @@ -62,10 +90,12 @@ void testRegisterMerging0() { List.of( new LiteralCommandNode( "world", + List.of(), helloWorldExecutor, "permission" ) ), + null, "permission" ) ); @@ -78,13 +108,16 @@ void testRegisterMerging0() { List.of( new LiteralCommandNode( "hi", + List.of(), helloWorldHiExecutor, "permission" ) ), + null, "permission" ) ), + null, "permission" ) ); @@ -98,6 +131,7 @@ void testRegisterMerging0() { Command expectedCommand0 = new Command( new LiteralCommandNode( "hello", + List.of(), helloExecutor, "permission" ) @@ -108,6 +142,7 @@ void testRegisterMerging0() { List.of( new LiteralCommandNode( "world", + List.of(), helloWorldExecutor, "permission" ) @@ -125,6 +160,7 @@ void testRegisterMerging0() { List.of( new LiteralCommandNode( "hi", + List.of(), helloWorldHiExecutor, "permission" ) @@ -153,6 +189,7 @@ void testRegisterMerging1() { Command command0 = new Command( new LiteralCommandNode( "hello", + List.of(), helloExecutor, "permission" ) @@ -163,15 +200,18 @@ void testRegisterMerging1() { List.of( new LiteralCommandNode( "world", + List.of(), helloWorldExecutor, "permission" ), new LiteralCommandNode( "there", + List.of(), helloThereExecutor, "permission" ) ), + null, "permission" ) ); @@ -184,13 +224,16 @@ void testRegisterMerging1() { List.of( new LiteralCommandNode( "hi", + List.of(), helloWorldHiExecutor, "permission" ) ), + null, "permission" ) ), + null, "permission" ) ); @@ -204,6 +247,7 @@ void testRegisterMerging1() { Command expectedCommand0 = new Command( new LiteralCommandNode( "hello", + List.of(), helloExecutor, "permission" ) @@ -214,11 +258,13 @@ void testRegisterMerging1() { List.of( new LiteralCommandNode( "world", + List.of(), helloWorldExecutor, "permission" ), new LiteralCommandNode( "there", + List.of(), helloThereExecutor, "permission" ) @@ -236,6 +282,7 @@ void testRegisterMerging1() { List.of( new LiteralCommandNode( "hi", + List.of(), helloWorldHiExecutor, "permission" ) @@ -245,6 +292,7 @@ void testRegisterMerging1() { ), new LiteralCommandNode( "there", + List.of(), helloThereExecutor, "permission" ) @@ -264,6 +312,7 @@ void testCommandNotFound0() { Command command = new Command( new LiteralCommandNode( "hello", + List.of(), context -> CommandResult.successful(context, "hello"), "permission" ) @@ -283,6 +332,7 @@ void testCommandNotFound1() { Command command = new Command( new LiteralCommandNode( "hello", + List.of(), context -> CommandResult.successful(context, "hello"), "permission" ) @@ -301,6 +351,7 @@ void testCommandNotFound1() { void testSuccess0() { LiteralCommandNode helloNode = new LiteralCommandNode( "hello", + List.of(), context -> CommandResult.successful(context, "hello"), "permission" ); @@ -309,6 +360,7 @@ void testSuccess0() { Command command1 = new Command( new LiteralCommandNode( "hi", + List.of(), context -> CommandResult.successful(context, "hi"), "permission" ) @@ -316,6 +368,7 @@ void testSuccess0() { Command command2 = new Command( new LiteralCommandNode( "welcome", + List.of(), context -> CommandResult.successful(context, "welcome"), "permission" ) @@ -334,23 +387,26 @@ void testSuccess0() { @Test void testSuccess1() { - Command command0 = new Command(new LiteralCommandNode( - "hello", - context -> CommandResult.successful(context, "hello"), - "permission" - )); + Command command0 = new Command( + new LiteralCommandNode( + "hello", + List.of(), + context -> CommandResult.successful(context, "hello"), + "permission" + ) + ); LiteralCommandNode thereNode = new LiteralCommandNode( "there", + List.of(), context -> CommandResult.successful(context, "hi there"), "permission" ); Command command1 = new Command( new LiteralCommandNode( "hi", - List.of( - thereNode - ), + List.of(thereNode), + null, "permission" ) ); @@ -358,6 +414,7 @@ void testSuccess1() { Command command2 = new Command( new LiteralCommandNode( "welcome", + List.of(), context -> CommandResult.successful(context, "welcome"), "permission" ) @@ -376,10 +433,37 @@ void testSuccess1() { @Test void testRegisterMultipleDifferent0() { - Command command0 = new Command(new LiteralCommandNode("hello0", context -> CommandResult.successful(context, "hello0"), "permission")); - Command command1 = new Command(new LiteralCommandNode("hello1", context -> CommandResult.successful(context, "hello1"), "permission")); - Command command2 = new Command(new LiteralCommandNode("hello2", context -> CommandResult.successful(context, "hello2"), "permission")); - Command command3 = new Command(new LiteralCommandNode("hello3", context -> CommandResult.successful(context, "hello3"), "permission")); + Command command0 = new Command( + new LiteralCommandNode( + "hello0", + List.of(), + context -> CommandResult.successful(context, "hello0"), + "permission" + ) + ); + Command command1 = new Command( + new LiteralCommandNode( + "hello1", + List.of(), + context -> CommandResult.successful(context, "hello1"), + "permission" + ) + ); + Command command2 = new Command( + new LiteralCommandNode( + "hello2", + List.of(), + context -> CommandResult.successful(context, "hello2"), + "permission") + ); + Command command3 = new Command( + new LiteralCommandNode( + "hello3", + List.of(), + context -> CommandResult.successful(context, "hello3"), + "permission" + ) + ); CommandManager manager = new CommandManager(); @@ -398,6 +482,7 @@ void testRegisterMultipleMerging0() { Command command0 = new Command( new LiteralCommandNode( "hello", + List.of(), helloExecutor, "permission" ) @@ -408,10 +493,12 @@ void testRegisterMultipleMerging0() { List.of( new LiteralCommandNode( "world", + List.of(), helloWorldExecutor, "permission" ) ), + null, "permission" ) ); @@ -424,13 +511,16 @@ void testRegisterMultipleMerging0() { List.of( new LiteralCommandNode( "hi", + List.of(), helloWorldHiExecutor, "permission" ) ), + null, "permission" ) ), + null, "permission" ) ); @@ -440,6 +530,7 @@ void testRegisterMultipleMerging0() { Command expectedCommand0 = new Command( new LiteralCommandNode( "hello", + List.of(), helloExecutor, "permission" ) @@ -450,6 +541,7 @@ void testRegisterMultipleMerging0() { List.of( new LiteralCommandNode( "world", + List.of(), helloWorldExecutor, "permission" ) @@ -467,6 +559,7 @@ void testRegisterMultipleMerging0() { List.of( new LiteralCommandNode( "hi", + List.of(), helloWorldHiExecutor, "permission" ) From 89d072b691e5bdac0bcc9170a5c5424831ec85b8 Mon Sep 17 00:00:00 2001 From: WizardlyBump17 Date: Fri, 12 Dec 2025 23:50:40 -0300 Subject: [PATCH 236/363] x more to go --- .../CommandManagerSuggestionTests.java | 290 +++++++++++++----- 1 file changed, 205 insertions(+), 85 deletions(-) diff --git a/commands/src/test/java/com/wizardlybump17/wlib/test/command/manager/CommandManagerSuggestionTests.java b/commands/src/test/java/com/wizardlybump17/wlib/test/command/manager/CommandManagerSuggestionTests.java index a84d35d2..a7443b13 100644 --- a/commands/src/test/java/com/wizardlybump17/wlib/test/command/manager/CommandManagerSuggestionTests.java +++ b/commands/src/test/java/com/wizardlybump17/wlib/test/command/manager/CommandManagerSuggestionTests.java @@ -26,27 +26,33 @@ class CommandManagerSuggestionTests { @Test void testSuggestionsSuccessListChad0() { - Command command0 = new Command(new LiteralCommandNode( - "hello", - context -> CommandResult.successful(context, "hello"), - "permission" - )); + Command command0 = new Command( + new LiteralCommandNode( + "hello", + List.of(), + context -> CommandResult.successful(context, "hello"), + "permission" + ) + ); Command command1 = new Command( new LiteralCommandNode( "hi", List.of( new LiteralCommandNode( "there", + List.of(), context -> CommandResult.successful(context, "hi there"), "permission" ) ), + null, "permission" ) ); Command command2 = new Command( new LiteralCommandNode( "welcome", + List.of(), context -> CommandResult.successful(context, "welcome"), "permission" ) @@ -65,27 +71,33 @@ void testSuggestionsSuccessListChad0() { @Test void testSuggestionsSuccessListChad1() { - Command command0 = new Command(new LiteralCommandNode( - "hello", - context -> CommandResult.successful(context, "hello"), - "permission" - )); + Command command0 = new Command( + new LiteralCommandNode( + "hello", + List.of(), + context -> CommandResult.successful(context, "hello"), + "permission" + ) + ); Command command1 = new Command( new LiteralCommandNode( "hi", List.of( new LiteralCommandNode( "there", + List.of(), context -> CommandResult.successful(context, "hi there"), "permission" ) ), + null, "permission" ) ); Command command2 = new Command( new LiteralCommandNode( "welcome", + List.of(), context -> CommandResult.successful(context, "welcome"), "permission" ) @@ -104,27 +116,33 @@ void testSuggestionsSuccessListChad1() { @Test void testSuggestionsSuccessListChad2() { - Command command0 = new Command(new LiteralCommandNode( - "hello", - context -> CommandResult.successful(context, "hello"), - "permission" - )); + Command command0 = new Command( + new LiteralCommandNode( + "hello", + List.of(), + context -> CommandResult.successful(context, "hello"), + "permission" + ) + ); Command command1 = new Command( new LiteralCommandNode( "hi", List.of( new LiteralCommandNode( "there", + List.of(), context -> CommandResult.successful(context, "hi there"), "permission" ) ), + null, "permission" ) ); Command command2 = new Command( new LiteralCommandNode( "welcome", + List.of(), context -> CommandResult.successful(context, "welcome"), "permission" ) @@ -143,27 +161,33 @@ void testSuggestionsSuccessListChad2() { @Test void testSuggestionsSuccessListChad3() { - Command command0 = new Command(new LiteralCommandNode( - "hello", - context -> CommandResult.successful(context, "hello"), - "permission" - )); + Command command0 = new Command( + new LiteralCommandNode( + "hello", + List.of(), + context -> CommandResult.successful(context, "hello"), + "permission" + ) + ); Command command1 = new Command( new LiteralCommandNode( "hi", List.of( new LiteralCommandNode( "there", + List.of(), context -> CommandResult.successful(context, "hi there"), "permission" ) ), + null, "permission" ) ); Command command2 = new Command( new LiteralCommandNode( "welcome", + List.of(), context -> CommandResult.successful(context, "welcome"), "permission" ) @@ -182,21 +206,26 @@ void testSuggestionsSuccessListChad3() { @Test void testSuggestionsSuccessListChad4() { - Command command0 = new Command(new LiteralCommandNode( - "hello", - context -> CommandResult.successful(context, "hello"), - "permission" - )); + Command command0 = new Command( + new LiteralCommandNode( + "hello", + List.of(), + context -> CommandResult.successful(context, "hello"), + "permission" + ) + ); Command command1 = new Command( new LiteralCommandNode( "hi", List.of( new LiteralCommandNode( "there", + List.of(), context -> CommandResult.successful(context, "hi there"), "permission" ) ), + null, "permission" ) ); @@ -231,21 +260,26 @@ void testSuggestionsSuccessListChad4() { @Test void testSuggestionsSuccessListChad6() { - Command command0 = new Command(new LiteralCommandNode( - "hello", - context -> CommandResult.successful(context, "hello"), - "permission" - )); + Command command0 = new Command( + new LiteralCommandNode( + "hello", + List.of(), + context -> CommandResult.successful(context, "hello"), + "permission" + ) + ); Command command1 = new Command( new LiteralCommandNode( "hi", List.of( new LiteralCommandNode( "there", + List.of(), context -> CommandResult.successful(context, "hi there"), "permission" ) ), + null, "permission" ) ); @@ -280,27 +314,33 @@ void testSuggestionsSuccessListChad6() { @Test void testSuggestionsFailListBeta0() { - Command command0 = new Command(new LiteralCommandNode( - "hello", - context -> CommandResult.successful(context, "hello"), - "permission" - )); + Command command0 = new Command( + new LiteralCommandNode( + "hello", + List.of(), + context -> CommandResult.successful(context, "hello"), + "permission" + ) + ); Command command1 = new Command( new LiteralCommandNode( "hi", List.of( new LiteralCommandNode( "there", + List.of(), context -> CommandResult.successful(context, "hi there"), "permission" ) ), + null, "permission" ) ); Command command2 = new Command( new LiteralCommandNode( "welcome", + List.of(), context -> CommandResult.successful(context, "welcome"), "permission" ) @@ -319,21 +359,26 @@ void testSuggestionsFailListBeta0() { @Test void testSuggestionsSuccessStringChad0() { - Command command0 = new Command(new LiteralCommandNode( - "hello", - context -> CommandResult.successful(context, "hello"), - "permission" - )); + Command command0 = new Command( + new LiteralCommandNode( + "hello", + List.of(), + context -> CommandResult.successful(context, "hello"), + "permission" + ) + ); Command command1 = new Command( new LiteralCommandNode( "hi", List.of( new LiteralCommandNode( "there", + List.of(), context -> CommandResult.successful(context, "hi there"), "permission" ) ), + null, "permission" ) ); @@ -343,7 +388,9 @@ void testSuggestionsSuccessStringChad0() { List.of( new IntegerCommandNode( "repeat", + List.of(), AllowedIntegerInputs.positive(), + IntegerSuggester.positive(), context -> CommandResult.successful(context, "welcome".repeat(context.arguments().getArgument("repeat").orElseThrow().data())), "permission" ) @@ -366,21 +413,26 @@ void testSuggestionsSuccessStringChad0() { @Test void testSuggestionsSuccessStringChad1() { - Command command0 = new Command(new LiteralCommandNode( - "hello", - context -> CommandResult.successful(context, "hello"), - "permission" - )); + Command command0 = new Command( + new LiteralCommandNode( + "hello", + List.of(), + context -> CommandResult.successful(context, "hello"), + "permission" + ) + ); Command command1 = new Command( new LiteralCommandNode( "hi", List.of( new LiteralCommandNode( "there", + List.of(), context -> CommandResult.successful(context, "hi there"), "permission" ) ), + null, "permission" ) ); @@ -390,7 +442,9 @@ void testSuggestionsSuccessStringChad1() { List.of( new IntegerCommandNode( "repeat", + List.of(), AllowedIntegerInputs.positive(), + IntegerSuggester.positive(), context -> CommandResult.successful(context, "welcome".repeat(context.arguments().getArgument("repeat").orElseThrow().data())), "permission" ) @@ -413,21 +467,26 @@ void testSuggestionsSuccessStringChad1() { @Test void testSuggestionsSuccessStringChad2() { - Command command0 = new Command(new LiteralCommandNode( - "hello", - context -> CommandResult.successful(context, "hello"), - "permission" - )); + Command command0 = new Command( + new LiteralCommandNode( + "hello", + List.of(), + context -> CommandResult.successful(context, "hello"), + "permission" + ) + ); Command command1 = new Command( new LiteralCommandNode( "hi", List.of( new LiteralCommandNode( "there", + List.of(), context -> CommandResult.successful(context, "hi there"), "permission" ) ), + null, "permission" ) ); @@ -462,21 +521,26 @@ void testSuggestionsSuccessStringChad2() { @Test void testSuggestionsSuccessStringChad3() { - Command command0 = new Command(new LiteralCommandNode( - "hello", - context -> CommandResult.successful(context, "hello"), - "permission" - )); + Command command0 = new Command( + new LiteralCommandNode( + "hello", + List.of(), + context -> CommandResult.successful(context, "hello"), + "permission" + ) + ); Command command1 = new Command( new LiteralCommandNode( "hi", List.of( new LiteralCommandNode( "there", + List.of(), context -> CommandResult.successful(context, "hi there"), "permission" ) ), + null, "permission" ) ); @@ -486,7 +550,9 @@ void testSuggestionsSuccessStringChad3() { List.of( new IntegerCommandNode( "repeat", + List.of(), AllowedIntegerInputs.positive(), + IntegerSuggester.positive(), context -> CommandResult.successful(context, "welcome".repeat(context.arguments().getArgument("repeat").orElseThrow().data())), "permission" ) @@ -501,10 +567,12 @@ void testSuggestionsSuccessStringChad3() { List.of( new LiteralCommandNode( "spaced string", + List.of(), context -> CommandResult.successful(context, "spaced string"), "permission" ) ), + null, "permission" ) ); @@ -523,21 +591,26 @@ void testSuggestionsSuccessStringChad3() { @Test void testSuggestionsSuccessStringArrayChad0() { - Command command0 = new Command(new LiteralCommandNode( - "hello", - context -> CommandResult.successful(context, "hello"), - "permission" - )); + Command command0 = new Command( + new LiteralCommandNode( + "hello", + List.of(), + context -> CommandResult.successful(context, "hello"), + "permission" + ) + ); Command command1 = new Command( new LiteralCommandNode( "hi", List.of( new LiteralCommandNode( "there", + List.of(), context -> CommandResult.successful(context, "hi there"), "permission" ) ), + null, "permission" ) ); @@ -547,7 +620,9 @@ void testSuggestionsSuccessStringArrayChad0() { List.of( new IntegerCommandNode( "repeat", + List.of(), AllowedIntegerInputs.positive(), + IntegerSuggester.positive(), context -> CommandResult.successful(context, "welcome".repeat(context.arguments().getArgument("repeat").orElseThrow().data())), "permission" ) @@ -562,10 +637,12 @@ void testSuggestionsSuccessStringArrayChad0() { List.of( new LiteralCommandNode( "spaced string", + List.of(), context -> CommandResult.successful(context, "spaced string"), "permission" ) ), + null, "permission" ) ); @@ -584,21 +661,26 @@ void testSuggestionsSuccessStringArrayChad0() { @Test void testSuggestionsSuccessStringArrayChad1() { - Command command0 = new Command(new LiteralCommandNode( - "hello", - context -> CommandResult.successful(context, "hello"), - "permission" - )); + Command command0 = new Command( + new LiteralCommandNode( + "hello", + List.of(), + context -> CommandResult.successful(context, "hello"), + "permission" + ) + ); Command command1 = new Command( new LiteralCommandNode( "hi", List.of( new LiteralCommandNode( "there", + List.of(), context -> CommandResult.successful(context, "hi there"), "permission" ) ), + null, "permission" ) ); @@ -608,7 +690,9 @@ void testSuggestionsSuccessStringArrayChad1() { List.of( new IntegerCommandNode( "repeat", + List.of(), AllowedIntegerInputs.positive(), + IntegerSuggester.positive(), context -> CommandResult.successful(context, "welcome".repeat(context.arguments().getArgument("repeat").orElseThrow().data())), "permission" ) @@ -623,10 +707,12 @@ void testSuggestionsSuccessStringArrayChad1() { List.of( new LiteralCommandNode( "spaced string", + List.of(), context -> CommandResult.successful(context, "spaced string"), "permission" ) ), + null, "permission" ) ); @@ -645,21 +731,26 @@ void testSuggestionsSuccessStringArrayChad1() { @Test void testSuggestionsSuccessStringArrayChad2() { - Command command0 = new Command(new LiteralCommandNode( - "hello", - context -> CommandResult.successful(context, "hello"), - "permission" - )); + Command command0 = new Command( + new LiteralCommandNode( + "hello", + List.of(), + context -> CommandResult.successful(context, "hello"), + "permission" + ) + ); Command command1 = new Command( new LiteralCommandNode( "hi", List.of( new LiteralCommandNode( "there", + List.of(), context -> CommandResult.successful(context, "hi there"), "permission" ) ), + null, "permission" ) ); @@ -686,10 +777,12 @@ void testSuggestionsSuccessStringArrayChad2() { List.of( new LiteralCommandNode( "spaced string", + List.of(), context -> CommandResult.successful(context, "spaced string"), "permission" ) ), + null, "permission" ) ); @@ -708,21 +801,26 @@ void testSuggestionsSuccessStringArrayChad2() { @Test void testSuggestionsSuccessStringArrayChad3() { - Command command0 = new Command(new LiteralCommandNode( - "hello", - context -> CommandResult.successful(context, "hello"), - "permission" - )); + Command command0 = new Command( + new LiteralCommandNode( + "hello", + List.of(), + context -> CommandResult.successful(context, "hello"), + "permission" + ) + ); Command command1 = new Command( new LiteralCommandNode( "hi", List.of( new LiteralCommandNode( "there", + List.of(), context -> CommandResult.successful(context, "hi there"), "permission" ) ), + null, "permission" ) ); @@ -732,7 +830,9 @@ void testSuggestionsSuccessStringArrayChad3() { List.of( new IntegerCommandNode( "repeat", + List.of(), AllowedIntegerInputs.positive(), + IntegerSuggester.positive(), context -> CommandResult.successful(context, "welcome".repeat(context.arguments().getArgument("repeat").orElseThrow().data())), "permission" ) @@ -747,10 +847,12 @@ void testSuggestionsSuccessStringArrayChad3() { List.of( new LiteralCommandNode( "spaced string", + List.of(), context -> CommandResult.successful(context, "spaced string"), "permission" ) ), + null, "permission" ) ); @@ -769,21 +871,26 @@ void testSuggestionsSuccessStringArrayChad3() { @Test void testSuggestionsSuccessStringArrayChad4() { - Command command0 = new Command(new LiteralCommandNode( - "hello", - context -> CommandResult.successful(context, "hello"), - "permission" - )); + Command command0 = new Command( + new LiteralCommandNode( + "hello", + List.of(), + context -> CommandResult.successful(context, "hello"), + "permission" + ) + ); Command command1 = new Command( new LiteralCommandNode( "hi", List.of( new LiteralCommandNode( "there", + List.of(), context -> CommandResult.successful(context, "hi there"), "permission" ) ), + null, "permission" ) ); @@ -793,7 +900,9 @@ void testSuggestionsSuccessStringArrayChad4() { List.of( new IntegerCommandNode( "repeat", + List.of(), AllowedIntegerInputs.positive(), + IntegerSuggester.positive(), context -> CommandResult.successful(context, "welcome".repeat(context.arguments().getArgument("repeat").orElseThrow().data())), "permission" ) @@ -808,10 +917,12 @@ void testSuggestionsSuccessStringArrayChad4() { List.of( new LiteralCommandNode( "spaced string", + List.of(), context -> CommandResult.successful(context, "spaced string"), "permission" ) ), + null, "permission" ) ); @@ -830,21 +941,26 @@ void testSuggestionsSuccessStringArrayChad4() { @Test void testSuggestionsSuccessStringArrayChad5() { - Command command0 = new Command(new LiteralCommandNode( - "hello", - context -> CommandResult.successful(context, "hello"), - "permission" - )); + Command command0 = new Command( + new LiteralCommandNode( + "hello", + List.of(), + context -> CommandResult.successful(context, "hello"), + "permission" + ) + ); Command command1 = new Command( new LiteralCommandNode( "hi", List.of( new LiteralCommandNode( "there", + List.of(), context -> CommandResult.successful(context, "hi there"), "permission" ) ), + null, "permission" ) ); @@ -854,7 +970,9 @@ void testSuggestionsSuccessStringArrayChad5() { List.of( new IntegerCommandNode( "repeat", + List.of(), AllowedIntegerInputs.positive(), + IntegerSuggester.positive(), context -> CommandResult.successful(context, "welcome".repeat(context.arguments().getArgument("repeat").orElseThrow().data())), "permission" ) @@ -869,10 +987,12 @@ void testSuggestionsSuccessStringArrayChad5() { List.of( new LiteralCommandNode( "spaced string", + List.of(), context -> CommandResult.successful(context, "spaced string"), "permission" ) ), + null, "permission" ) ); From f9f4f0948eae50d88a99e051a8fba162560b7605 Mon Sep 17 00:00:00 2001 From: WizardlyBump17 Date: Sat, 13 Dec 2025 17:21:58 -0300 Subject: [PATCH 237/363] x more to go --- .../listener/CommandManagerListenerTests.java | 375 ++++++++++++++++-- 1 file changed, 345 insertions(+), 30 deletions(-) diff --git a/commands/src/test/java/com/wizardlybump17/wlib/test/command/manager/listener/CommandManagerListenerTests.java b/commands/src/test/java/com/wizardlybump17/wlib/test/command/manager/listener/CommandManagerListenerTests.java index 6c37129c..f64a94a5 100644 --- a/commands/src/test/java/com/wizardlybump17/wlib/test/command/manager/listener/CommandManagerListenerTests.java +++ b/commands/src/test/java/com/wizardlybump17/wlib/test/command/manager/listener/CommandManagerListenerTests.java @@ -37,9 +37,39 @@ public void onUnregister(@NotNull String identifier, @NotNull Command command, @ } }); - manager.registerCommand("test", new Command(new LiteralCommandNode("test"))); - manager.registerCommand("test", new Command(new LiteralCommandNode("test"))); - manager.registerCommand("test", new Command(new LiteralCommandNode("test"))); + manager.registerCommand( + "test", + new Command( + new LiteralCommandNode( + "test", + List.of(), + null, + null + ) + ) + ); + manager.registerCommand( + "test", + new Command( + new LiteralCommandNode( + "test", + List.of(), + null, + null + ) + ) + ); + manager.registerCommand( + "test", + new Command( + new LiteralCommandNode( + "test", + List.of(), + null, + null + ) + ) + ); Assertions.assertEquals(3, counter.get()); } @@ -64,9 +94,39 @@ public void onUnregister(@NotNull String identifier, @NotNull Command command, @ } }); - manager.registerCommand("test", new Command(new LiteralCommandNode("test0"))); - manager.registerCommand("test", new Command(new LiteralCommandNode("test1"))); - manager.registerCommand("test", new Command(new LiteralCommandNode("test2"))); + manager.registerCommand( + "test", + new Command( + new LiteralCommandNode( + "test0", + List.of(), + null, + null + ) + ) + ); + manager.registerCommand( + "test", + new Command( + new LiteralCommandNode( + "test1", + List.of(), + null, + null + ) + ) + ); + manager.registerCommand( + "test", + new Command( + new LiteralCommandNode( + "test2", + List.of(), + null, + null + ) + ) + ); Assertions.assertEquals( List.of( @@ -100,9 +160,39 @@ public void onUnregister(@NotNull String identifier, @NotNull Command command, @ } }); - manager.registerCommand("test", new Command(new LiteralCommandNode("test0"))); - manager.registerCommand("test", new Command(new LiteralCommandNode("test1"))); - manager.registerCommand("test", new Command(new LiteralCommandNode("test2"))); + manager.registerCommand( + "test", + new Command( + new LiteralCommandNode( + "test0", + List.of(), + null, + null + ) + ) + ); + manager.registerCommand( + "test", + new Command( + new LiteralCommandNode( + "test1", + List.of(), + null, + null + ) + ) + ); + manager.registerCommand( + "test", + new Command( + new LiteralCommandNode( + "test2", + List.of(), + null, + null + ) + ) + ); manager.clear(); @@ -129,9 +219,36 @@ public void onUnregister(@NotNull String identifier, @NotNull Command command, @ } }); - manager.registerCommand("test", new Command(new LiteralCommandNode("test0"))); - manager.registerCommand("test", new Command(new LiteralCommandNode("test1"))); - manager.registerCommand("test", new Command(new LiteralCommandNode("test2"))); + manager.registerCommand( + "test", + new Command( + new LiteralCommandNode( + "test0", + List.of(), + null, + null + ) + )); + manager.registerCommand( + "test", + new Command( + new LiteralCommandNode( + "test1", + List.of(), + null, + null + ) + )); + manager.registerCommand( + "test", + new Command( + new LiteralCommandNode( + "test2", + List.of(), + null, + null + ) + )); manager.unregister("test", "test0"); manager.unregister("test", "test1"); @@ -167,12 +284,78 @@ public void onUnregister(@NotNull String identifier, @NotNull Command command, @ } }); - manager.registerCommand("test", new Command(new LiteralCommandNode("test0")), "test"); - manager.registerCommand("test", new Command(new LiteralCommandNode("test1")), "test"); - manager.registerCommand("test", new Command(new LiteralCommandNode("test2")), "test"); - manager.registerCommand("test1", new Command(new LiteralCommandNode("test10")), "test1"); - manager.registerCommand("test1", new Command(new LiteralCommandNode("test11")), "test1"); - manager.registerCommand("test1", new Command(new LiteralCommandNode("test12")), "test1"); + manager.registerCommand( + "test", + new Command( + new LiteralCommandNode( + "test0", + List.of(), + null, + null + ) + ), + "test" + ); + manager.registerCommand( + "test", + new Command( + new LiteralCommandNode( + "test1", + List.of(), + null, + null + ) + ), + "test" + ); + manager.registerCommand( + "test", + new Command( + new LiteralCommandNode( + "test2", + List.of(), + null, + null + ) + ), + "test" + ); + manager.registerCommand( + "test1", + new Command( + new LiteralCommandNode( + "test10", + List.of(), + null, + null + ) + ), + "test1" + ); + manager.registerCommand( + "test1", + new Command( + new LiteralCommandNode( + "test11", + List.of(), + null, + null + ) + ), + "test1" + ); + manager.registerCommand( + "test1", + new Command( + new LiteralCommandNode( + "test12", + List.of(), + null, + null + ) + ), + "test1" + ); manager.unregisterByHolder("test", "test"); @@ -206,12 +389,78 @@ public void onUnregister(@NotNull String identifier, @NotNull Command command, @ } }); - manager.registerCommand("test", new Command(new LiteralCommandNode("test0")), "test"); - manager.registerCommand("test", new Command(new LiteralCommandNode("test1")), "test"); - manager.registerCommand("test", new Command(new LiteralCommandNode("test2")), "test"); - manager.registerCommand("test1", new Command(new LiteralCommandNode("test10")), "test1"); - manager.registerCommand("test1", new Command(new LiteralCommandNode("test11")), "test1"); - manager.registerCommand("test1", new Command(new LiteralCommandNode("test12")), "test1"); + manager.registerCommand( + "test", + new Command( + new LiteralCommandNode( + "test0", + List.of(), + null, + null + ) + ), + "test" + ); + manager.registerCommand( + "test", + new Command( + new LiteralCommandNode( + "test1", + List.of(), + null, + null + ) + ), + "test" + ); + manager.registerCommand( + "test", + new Command( + new LiteralCommandNode( + "test2", + List.of(), + null, + null + ) + ), + "test" + ); + manager.registerCommand( + "test1", + new Command( + new LiteralCommandNode( + "test10", + List.of(), + null, + null + ) + ), + "test1" + ); + manager.registerCommand( + "test1", + new Command( + new LiteralCommandNode( + "test11", + List.of(), + null, + null + ) + ), + "test1" + ); + manager.registerCommand( + "test1", + new Command( + new LiteralCommandNode( + "test12", + List.of(), + null, + null + ) + ), + "test1" + ); manager.unregisterByHolder("test1", "test1"); @@ -245,12 +494,78 @@ public void onUnregister(@NotNull String identifier, @NotNull Command command, @ } }); - manager.registerCommand("test", new Command(new LiteralCommandNode("test0")), "test"); - manager.registerCommand("test", new Command(new LiteralCommandNode("test1")), "test"); - manager.registerCommand("test", new Command(new LiteralCommandNode("test2")), "test"); - manager.registerCommand("test1", new Command(new LiteralCommandNode("test10")), "test1"); - manager.registerCommand("test1", new Command(new LiteralCommandNode("test11")), "test1"); - manager.registerCommand("test1", new Command(new LiteralCommandNode("test12")), "test1"); + manager.registerCommand( + "test", + new Command( + new LiteralCommandNode( + "test0", + List.of(), + null, + null + ) + ), + "test" + ); + manager.registerCommand( + "test", + new Command( + new LiteralCommandNode( + "test1", + List.of(), + null, + null + ) + ), + "test" + ); + manager.registerCommand( + "test", + new Command( + new LiteralCommandNode( + "test2", + List.of(), + null, + null + ) + ), + "test" + ); + manager.registerCommand( + "test1", + new Command( + new LiteralCommandNode( + "test10", + List.of(), + null, + null + ) + ), + "test1" + ); + manager.registerCommand( + "test1", + new Command( + new LiteralCommandNode( + "test11", + List.of(), + null, + null + ) + ), + "test1" + ); + manager.registerCommand( + "test1", + new Command( + new LiteralCommandNode( + "test12", + List.of(), + null, + null + ) + ), + "test1" + ); manager.unregisterByHolder("test", "test"); manager.unregisterByHolder("test1", "test1"); From b595426c0efad1c69f63fc5454ec142e677aa773 Mon Sep 17 00:00:00 2001 From: WizardlyBump17 Date: Sun, 14 Dec 2025 15:57:08 -0300 Subject: [PATCH 238/363] x more to go --- .../method/MethodCommandNodeFactoryTests.java | 290 ++++++++++++++---- 1 file changed, 234 insertions(+), 56 deletions(-) diff --git a/commands/src/test/java/com/wizardlybump17/wlib/test/command/extractor/method/MethodCommandNodeFactoryTests.java b/commands/src/test/java/com/wizardlybump17/wlib/test/command/extractor/method/MethodCommandNodeFactoryTests.java index 7dc1c325..8fc74708 100644 --- a/commands/src/test/java/com/wizardlybump17/wlib/test/command/extractor/method/MethodCommandNodeFactoryTests.java +++ b/commands/src/test/java/com/wizardlybump17/wlib/test/command/extractor/method/MethodCommandNodeFactoryTests.java @@ -12,6 +12,8 @@ import com.wizardlybump17.wlib.command.node.primitive.number.*; import com.wizardlybump17.wlib.command.node.string.StringCommandNode; import com.wizardlybump17.wlib.command.registry.MethodCommandNodeFactoryRegistry; +import com.wizardlybump17.wlib.command.suggestion.primitive.number.*; +import com.wizardlybump17.wlib.command.suggestion.string.StringSuggester; import com.wizardlybump17.wlib.test.util.AssertionUtil; import org.junit.jupiter.api.AfterAll; import org.junit.jupiter.api.Assertions; @@ -51,9 +53,15 @@ void testByte() { List.of( new ByteCommandNode( "arg0", - AllowedByteInputs.unlimited() + List.of(), + AllowedByteInputs.unlimited(), + ByteSuggester.unlimited(), + null, + null ) - ) + ), + null, + null ) ); Command test1 = new Command( @@ -68,16 +76,25 @@ void testByte() { List.of( new ByteCommandNode( "arg1", - AllowedByteInputs.unlimited() + List.of(), + AllowedByteInputs.unlimited(), + ByteSuggester.unlimited(), + null, + null ) - ) + ), + null, + null ) ), AllowedByteInputs.unlimited(), + ByteSuggester.unlimited(), null, null ) - ) + ), + null, + null ) ); @@ -111,9 +128,15 @@ void testShort() { List.of( new ShortCommandNode( "arg0", - AllowedShortInputs.unlimited() + List.of(), + AllowedShortInputs.unlimited(), + ShortSuggester.unlimited(), + null, + null ) - ) + ), + null, + null ) ); Command test1 = new Command( @@ -128,16 +151,25 @@ void testShort() { List.of( new ShortCommandNode( "arg1", - AllowedShortInputs.unlimited() + List.of(), + AllowedShortInputs.unlimited(), + ShortSuggester.unlimited(), + null, + null ) - ) + ), + null, + null ) ), AllowedShortInputs.unlimited(), + ShortSuggester.unlimited(), null, null ) - ) + ), + null, + null ) ); @@ -171,9 +203,15 @@ void testInt() { List.of( new IntegerCommandNode( "arg0", - AllowedIntegerInputs.unlimited() + List.of(), + AllowedIntegerInputs.unlimited(), + IntegerSuggester.unlimited(), + null, + null ) - ) + ), + null, + null ) ); Command test1 = new Command( @@ -188,16 +226,25 @@ void testInt() { List.of( new IntegerCommandNode( "arg1", - AllowedIntegerInputs.unlimited() + List.of(), + AllowedIntegerInputs.unlimited(), + IntegerSuggester.unlimited(), + null, + null ) - ) + ), + null, + null ) ), AllowedIntegerInputs.unlimited(), + IntegerSuggester.unlimited(), null, null ) - ) + ), + null, + null ) ); @@ -231,9 +278,15 @@ void testLong() { List.of( new LongCommandNode( "arg0", - AllowedLongInputs.unlimited() + List.of(), + AllowedLongInputs.unlimited(), + LongSuggester.unlimited(), + null, + null ) - ) + ), + null, + null ) ); Command test1 = new Command( @@ -248,16 +301,25 @@ void testLong() { List.of( new LongCommandNode( "arg1", - AllowedLongInputs.unlimited() + List.of(), + AllowedLongInputs.unlimited(), + LongSuggester.unlimited(), + null, + null ) - ) + ), + null, + null ) ), AllowedLongInputs.unlimited(), + LongSuggester.unlimited(), null, null ) - ) + ), + null, + null ) ); @@ -291,9 +353,15 @@ void testFloat() { List.of( new FloatCommandNode( "arg0", - AllowedFloatInputs.unlimited() + List.of(), + AllowedFloatInputs.unlimited(), + FloatSuggester.unlimited(), + null, + null ) - ) + ), + null, + null ) ); Command test1 = new Command( @@ -308,16 +376,25 @@ void testFloat() { List.of( new FloatCommandNode( "arg1", - AllowedFloatInputs.unlimited() + List.of(), + AllowedFloatInputs.unlimited(), + FloatSuggester.unlimited(), + null, + null ) - ) + ), + null, + null ) ), AllowedFloatInputs.unlimited(), + FloatSuggester.unlimited(), null, null ) - ) + ), + null, + null ) ); @@ -351,9 +428,15 @@ void testDouble() { List.of( new DoubleCommandNode( "arg0", - AllowedDoubleInputs.unlimited() + List.of(), + AllowedDoubleInputs.unlimited(), + DoubleSuggester.unlimited(), + null, + null ) - ) + ), + null, + null ) ); Command test1 = new Command( @@ -368,16 +451,25 @@ void testDouble() { List.of( new DoubleCommandNode( "arg1", - AllowedDoubleInputs.unlimited() + List.of(), + AllowedDoubleInputs.unlimited(), + DoubleSuggester.unlimited(), + null, + null ) - ) + ), + null, + null ) ), AllowedDoubleInputs.unlimited(), + DoubleSuggester.unlimited(), null, null ) - ) + ), + null, + null ) ); @@ -411,9 +503,15 @@ void testChar() { List.of( new CharacterCommandNode( "arg0", - AllowedCharacterInputs.anyNotNull() + List.of(), + AllowedCharacterInputs.anyNotNull(), + null, + null, + null ) - ) + ), + null, + null ) ); Command test1 = new Command( @@ -428,16 +526,25 @@ void testChar() { List.of( new CharacterCommandNode( "arg1", - AllowedCharacterInputs.anyNotNull() + List.of(), + AllowedCharacterInputs.anyNotNull(), + null, + null, + null ) - ) + ), + null, + null ) ), AllowedCharacterInputs.anyNotNull(), null, + null, null ) - ) + ), + null, + null ) ); @@ -471,9 +578,15 @@ void testString() { List.of( new StringCommandNode( "arg0", - AllowedStringInputs.anyNullable() + List.of(), + AllowedStringInputs.anyNullable(), + StringSuggester.any(), + null, + null ) - ) + ), + null, + null ) ); Command test1 = new Command( @@ -488,16 +601,25 @@ void testString() { List.of( new StringCommandNode( "arg1", - AllowedStringInputs.anyNullable() + List.of(), + AllowedStringInputs.anyNullable(), + StringSuggester.any(), + null, + null ) - ) + ), + null, + null ) ), AllowedStringInputs.anyNullable(), + StringSuggester.any(), null, null ) - ) + ), + null, + null ) ); @@ -531,9 +653,15 @@ void testUUID() { List.of( new UUIDCommandNode( "arg0", - AllowedUUIDInputs.anyNullable() + List.of(), + AllowedUUIDInputs.anyNullable(), + null, + null, + null ) - ) + ), + null, + null ) ); Command test1 = new Command( @@ -548,16 +676,25 @@ void testUUID() { List.of( new UUIDCommandNode( "arg1", - AllowedUUIDInputs.anyNullable() + List.of(), + AllowedUUIDInputs.anyNullable(), + null, + null, + null ) - ) + ), + null, + null ) ), AllowedUUIDInputs.anyNullable(), null, + null, null ) - ) + ), + null, + null ) ); @@ -668,112 +805,153 @@ void testMix() { List.of( new UUIDCommandNode( "uuid1", - AllowedUUIDInputs.anyNullable() + List.of(), + AllowedUUIDInputs.anyNullable(), + null, + null, + null ) - ) + ), + null, + null ) ), AllowedUUIDInputs.anyNullable(), null, + null, null ) ), AllowedStringInputs.anyNullable(), + StringSuggester.any(), null, null ) - ) + ), + null, + null ) ), AllowedStringInputs.anyNullable(), + StringSuggester.any(), null, null ) - ) + ), + null, + null ) ), AllowedCharacterInputs.anyNotNull(), null, + null, null ) ), AllowedCharacterInputs.anyNotNull(), null, + null, null ) - ) + ), + null, + null ) ), AllowedDoubleInputs.unlimited(), + DoubleSuggester.unlimited(), null, null ) ), AllowedDoubleInputs.unlimited(), + DoubleSuggester.unlimited(), null, null ) - ) + ), + null, + null ) ), AllowedShortInputs.unlimited(), + ShortSuggester.unlimited(), null, null ) ), AllowedShortInputs.unlimited(), + ShortSuggester.unlimited(), null, null ) - ) + ), + null, + null ) ), AllowedLongInputs.unlimited(), + LongSuggester.unlimited(), null, null ) ), AllowedLongInputs.unlimited(), + LongSuggester.unlimited(), null, null ) ), AllowedFloatInputs.unlimited(), + FloatSuggester.unlimited(), null, null ) - ) + ), + null, + null ) ), AllowedFloatInputs.unlimited(), + FloatSuggester.unlimited(), null, null ) - ) + ), + null, + null ) ), AllowedByteInputs.unlimited(), + ByteSuggester.unlimited(), null, null ) ), AllowedByteInputs.unlimited(), + ByteSuggester.unlimited(), null, null ) - ) + ), + null, + null ) ), AllowedIntegerInputs.unlimited(), + IntegerSuggester.unlimited(), null, null ) ), AllowedIntegerInputs.unlimited(), + IntegerSuggester.unlimited(), null, null ) - ) + ), + null, + null )); TestMix object = new TestMix(); From 21e63ba2601c806d8759e48cdf2e40213cb2f5fc Mon Sep 17 00:00:00 2001 From: WizardlyBump17 Date: Sun, 14 Dec 2025 16:09:22 -0300 Subject: [PATCH 239/363] x more to go --- .../method/MethodCommandExtractorTests.java | 428 +++++++++++++----- 1 file changed, 326 insertions(+), 102 deletions(-) diff --git a/commands/src/test/java/com/wizardlybump17/wlib/test/command/extractor/method/MethodCommandExtractorTests.java b/commands/src/test/java/com/wizardlybump17/wlib/test/command/extractor/method/MethodCommandExtractorTests.java index 17eaa65b..75e9cdb6 100644 --- a/commands/src/test/java/com/wizardlybump17/wlib/test/command/extractor/method/MethodCommandExtractorTests.java +++ b/commands/src/test/java/com/wizardlybump17/wlib/test/command/extractor/method/MethodCommandExtractorTests.java @@ -14,6 +14,8 @@ import com.wizardlybump17.wlib.command.result.CommandResult; import com.wizardlybump17.wlib.command.sender.BasicCommandSender; import com.wizardlybump17.wlib.command.sender.CommandSender; +import com.wizardlybump17.wlib.command.suggestion.primitive.number.IntegerSuggester; +import com.wizardlybump17.wlib.command.suggestion.string.StringSuggester; import org.jetbrains.annotations.NotNull; import org.junit.jupiter.api.AfterAll; import org.junit.jupiter.api.Assertions; @@ -57,7 +59,9 @@ void testNoParameters() { new Command( new LiteralCommandNode( "hello", - Assertions.assertDoesNotThrow(() -> MethodCommandExtractor.createExecutor(object, "hello")) + List.of(), + Assertions.assertDoesNotThrow(() -> MethodCommandExtractor.createExecutor(object, "hello")), + null ) ), new Command( @@ -66,9 +70,13 @@ void testNoParameters() { List.of( new LiteralCommandNode( "world", - Assertions.assertDoesNotThrow(() -> MethodCommandExtractor.createExecutor(object, "helloWorld")) + List.of(), + Assertions.assertDoesNotThrow(() -> MethodCommandExtractor.createExecutor(object, "helloWorld")), + null ) - ) + ), + null, + null ) ), new Command( @@ -80,11 +88,17 @@ void testNoParameters() { List.of( new LiteralCommandNode( "hi", - Assertions.assertDoesNotThrow(() -> MethodCommandExtractor.createExecutor(object, "helloThereHi")) + List.of(), + Assertions.assertDoesNotThrow(() -> MethodCommandExtractor.createExecutor(object, "helloThereHi")), + null ) - ) + ), + null, + null ) - ) + ), + null, + null ) ) )); @@ -122,7 +136,9 @@ void testNoParametersCommandResult() { new Command( new LiteralCommandNode( "hello", - Assertions.assertDoesNotThrow(() -> MethodCommandExtractor.createExecutor(object, "hello")) + List.of(), + Assertions.assertDoesNotThrow(() -> MethodCommandExtractor.createExecutor(object, "hello")), + null ) ), new Command( @@ -131,9 +147,13 @@ void testNoParametersCommandResult() { List.of( new LiteralCommandNode( "world", - Assertions.assertDoesNotThrow(() -> MethodCommandExtractor.createExecutor(object, "helloWorld")) + List.of(), + Assertions.assertDoesNotThrow(() -> MethodCommandExtractor.createExecutor(object, "helloWorld")), + null ) - ) + ), + null, + null ) ), new Command( @@ -145,11 +165,17 @@ void testNoParametersCommandResult() { List.of( new LiteralCommandNode( "hi", - Assertions.assertDoesNotThrow(() -> MethodCommandExtractor.createExecutor(object, "helloThereHi")) + List.of(), + Assertions.assertDoesNotThrow(() -> MethodCommandExtractor.createExecutor(object, "helloThereHi")), + null ) - ) + ), + null, + null ) - ) + ), + null, + null ) ) )); @@ -191,7 +217,9 @@ void testCommandSender() { new Command( new LiteralCommandNode( "hello", - Assertions.assertDoesNotThrow(() -> MethodCommandExtractor.createExecutor(object, "hello", CommandSender.class)) + List.of(), + Assertions.assertDoesNotThrow(() -> MethodCommandExtractor.createExecutor(object, "hello", CommandSender.class)), + null ) ), new Command( @@ -200,9 +228,13 @@ void testCommandSender() { List.of( new LiteralCommandNode( "world", - Assertions.assertDoesNotThrow(() -> MethodCommandExtractor.createExecutor(object, "helloWorld", CommandSender.class)) + List.of(), + Assertions.assertDoesNotThrow(() -> MethodCommandExtractor.createExecutor(object, "helloWorld", CommandSender.class)), + null ) - ) + ), + null, + null ) ), new Command( @@ -214,11 +246,17 @@ void testCommandSender() { List.of( new LiteralCommandNode( "hi", - Assertions.assertDoesNotThrow(() -> MethodCommandExtractor.createExecutor(object, "helloThereHi", CommandSender.class)) + List.of(), + Assertions.assertDoesNotThrow(() -> MethodCommandExtractor.createExecutor(object, "helloThereHi", CommandSender.class)), + null ) - ) + ), + null, + null ) - ) + ), + null, + null ) ) )); @@ -253,7 +291,9 @@ void testCommandContext() { new Command( new LiteralCommandNode( "hello", - Assertions.assertDoesNotThrow(() -> MethodCommandExtractor.createExecutor(object, "hello", CommandContext.class)) + List.of(), + Assertions.assertDoesNotThrow(() -> MethodCommandExtractor.createExecutor(object, "hello", CommandContext.class)), + null ) ), new Command( @@ -262,9 +302,13 @@ void testCommandContext() { List.of( new LiteralCommandNode( "world", - Assertions.assertDoesNotThrow(() -> MethodCommandExtractor.createExecutor(object, "helloWorld", CommandContext.class)) + List.of(), + Assertions.assertDoesNotThrow(() -> MethodCommandExtractor.createExecutor(object, "helloWorld", CommandContext.class)), + null ) - ) + ), + null, + null ) ), new Command( @@ -276,11 +320,17 @@ void testCommandContext() { List.of( new LiteralCommandNode( "hi", - Assertions.assertDoesNotThrow(() -> MethodCommandExtractor.createExecutor(object, "helloThereHi", CommandContext.class)) + List.of(), + Assertions.assertDoesNotThrow(() -> MethodCommandExtractor.createExecutor(object, "helloThereHi", CommandContext.class)), + null ) - ) + ), + null, + null ) - ) + ), + null, + null ) ) )); @@ -319,7 +369,9 @@ void testCommandContextCommandResult() { new Command( new LiteralCommandNode( "hello", - Assertions.assertDoesNotThrow(() -> MethodCommandExtractor.createExecutor(object, "hello", CommandContext.class)) + List.of(), + Assertions.assertDoesNotThrow(() -> MethodCommandExtractor.createExecutor(object, "hello", CommandContext.class)), + null ) ), new Command( @@ -328,9 +380,13 @@ void testCommandContextCommandResult() { List.of( new LiteralCommandNode( "world", - Assertions.assertDoesNotThrow(() -> MethodCommandExtractor.createExecutor(object, "helloWorld", CommandContext.class)) + List.of(), + Assertions.assertDoesNotThrow(() -> MethodCommandExtractor.createExecutor(object, "helloWorld", CommandContext.class)), + null ) - ) + ), + null, + null ) ), new Command( @@ -342,11 +398,17 @@ void testCommandContextCommandResult() { List.of( new LiteralCommandNode( "hi", - Assertions.assertDoesNotThrow(() -> MethodCommandExtractor.createExecutor(object, "helloThereHi", CommandContext.class)) + List.of(), + Assertions.assertDoesNotThrow(() -> MethodCommandExtractor.createExecutor(object, "helloThereHi", CommandContext.class)), + null ) - ) + ), + null, + null ) - ) + ), + null, + null ) ) )); @@ -384,7 +446,9 @@ void testCommandSenderCommandResult() { new Command( new LiteralCommandNode( "hello", - Assertions.assertDoesNotThrow(() -> MethodCommandExtractor.createExecutor(object, "hello", CommandSender.class)) + List.of(), + Assertions.assertDoesNotThrow(() -> MethodCommandExtractor.createExecutor(object, "hello", CommandSender.class)), + null ) ), new Command( @@ -393,9 +457,13 @@ void testCommandSenderCommandResult() { List.of( new LiteralCommandNode( "world", - Assertions.assertDoesNotThrow(() -> MethodCommandExtractor.createExecutor(object, "helloWorld", CommandSender.class)) + List.of(), + Assertions.assertDoesNotThrow(() -> MethodCommandExtractor.createExecutor(object, "helloWorld", CommandSender.class)), + null ) - ) + ), + null, + null ) ), new Command( @@ -407,11 +475,17 @@ void testCommandSenderCommandResult() { List.of( new LiteralCommandNode( "hi", - Assertions.assertDoesNotThrow(() -> MethodCommandExtractor.createExecutor(object, "helloThereHi", CommandSender.class)) + List.of(), + Assertions.assertDoesNotThrow(() -> MethodCommandExtractor.createExecutor(object, "helloThereHi", CommandSender.class)), + null ) - ) + ), + null, + null ) - ) + ), + null, + null ) ) )); @@ -456,10 +530,15 @@ void testCommandSenderParameters() { List.of( new IntegerCommandNode( "int", + List.of(), AllowedIntegerInputs.unlimited(), - Assertions.assertDoesNotThrow(() -> MethodCommandExtractor.createExecutor(object, "hello", CommandSender.class, int.class)) + IntegerSuggester.unlimited(), + Assertions.assertDoesNotThrow(() -> MethodCommandExtractor.createExecutor(object, "hello", CommandSender.class, int.class)), + null ) - ) + ), + null, + null ) ), new Command( @@ -471,12 +550,19 @@ void testCommandSenderParameters() { List.of( new IntegerCommandNode( "int", + List.of(), AllowedIntegerInputs.unlimited(), - Assertions.assertDoesNotThrow(() -> MethodCommandExtractor.createExecutor(object, "helloWorld", CommandSender.class, int.class)) + IntegerSuggester.unlimited(), + Assertions.assertDoesNotThrow(() -> MethodCommandExtractor.createExecutor(object, "helloWorld", CommandSender.class, int.class)), + null ) - ) + ), + null, + null ) - ) + ), + null, + null ) ), new Command( @@ -491,14 +577,23 @@ void testCommandSenderParameters() { List.of( new IntegerCommandNode( "int", + List.of(), AllowedIntegerInputs.unlimited(), - Assertions.assertDoesNotThrow(() -> MethodCommandExtractor.createExecutor(object, "helloThereHi", CommandSender.class, int.class)) + IntegerSuggester.unlimited(), + Assertions.assertDoesNotThrow(() -> MethodCommandExtractor.createExecutor(object, "helloThereHi", CommandSender.class, int.class)), + null ) - ) + ), + null, + null ) - ) + ), + null, + null ) - ) + ), + null, + null ) ) )); @@ -536,10 +631,15 @@ void testCommandContextParameters() { List.of( new IntegerCommandNode( "int", + List.of(), AllowedIntegerInputs.unlimited(), - Assertions.assertDoesNotThrow(() -> MethodCommandExtractor.createExecutor(object, "hello", CommandContext.class, int.class)) + IntegerSuggester.unlimited(), + Assertions.assertDoesNotThrow(() -> MethodCommandExtractor.createExecutor(object, "hello", CommandContext.class, int.class)), + null ) - ) + ), + null, + null ) ), new Command( @@ -551,12 +651,19 @@ void testCommandContextParameters() { List.of( new IntegerCommandNode( "int", + List.of(), AllowedIntegerInputs.unlimited(), - Assertions.assertDoesNotThrow(() -> MethodCommandExtractor.createExecutor(object, "helloWorld", CommandContext.class, int.class)) + IntegerSuggester.unlimited(), + Assertions.assertDoesNotThrow(() -> MethodCommandExtractor.createExecutor(object, "helloWorld", CommandContext.class, int.class)), + null ) - ) + ), + null, + null ) - ) + ), + null, + null ) ), new Command( @@ -571,14 +678,23 @@ void testCommandContextParameters() { List.of( new IntegerCommandNode( "int", + List.of(), AllowedIntegerInputs.unlimited(), - Assertions.assertDoesNotThrow(() -> MethodCommandExtractor.createExecutor(object, "helloThereHi", CommandContext.class, int.class)) + IntegerSuggester.unlimited(), + Assertions.assertDoesNotThrow(() -> MethodCommandExtractor.createExecutor(object, "helloThereHi", CommandContext.class, int.class)), + null ) - ) + ), + null, + null ) - ) + ), + null, + null ) - ) + ), + null, + null ) ) )); @@ -620,10 +736,15 @@ void testCommandSenderParametersCommandResult() { List.of( new IntegerCommandNode( "int", + List.of(), AllowedIntegerInputs.unlimited(), - Assertions.assertDoesNotThrow(() -> MethodCommandExtractor.createExecutor(object, "hello", CommandSender.class, int.class)) + IntegerSuggester.unlimited(), + Assertions.assertDoesNotThrow(() -> MethodCommandExtractor.createExecutor(object, "hello", CommandSender.class, int.class)), + null ) - ) + ), + null, + null ) ), new Command( @@ -635,12 +756,19 @@ void testCommandSenderParametersCommandResult() { List.of( new IntegerCommandNode( "int", + List.of(), AllowedIntegerInputs.unlimited(), - Assertions.assertDoesNotThrow(() -> MethodCommandExtractor.createExecutor(object, "helloWorld", CommandSender.class, int.class)) + IntegerSuggester.unlimited(), + Assertions.assertDoesNotThrow(() -> MethodCommandExtractor.createExecutor(object, "helloWorld", CommandSender.class, int.class)), + null ) - ) + ), + null, + null ) - ) + ), + null, + null ) ), new Command( @@ -655,14 +783,23 @@ void testCommandSenderParametersCommandResult() { List.of( new IntegerCommandNode( "int", + List.of(), AllowedIntegerInputs.unlimited(), - Assertions.assertDoesNotThrow(() -> MethodCommandExtractor.createExecutor(object, "helloThereHi", CommandSender.class, int.class)) + IntegerSuggester.unlimited(), + Assertions.assertDoesNotThrow(() -> MethodCommandExtractor.createExecutor(object, "helloThereHi", CommandSender.class, int.class)), + null ) - ) + ), + null, + null ) - ) + ), + null, + null ) - ) + ), + null, + null ) ) )); @@ -703,10 +840,15 @@ void testCommandContextParametersCommandResult() { List.of( new IntegerCommandNode( "int", + List.of(), AllowedIntegerInputs.unlimited(), - Assertions.assertDoesNotThrow(() -> MethodCommandExtractor.createExecutor(object, "hello", CommandContext.class, int.class)) + IntegerSuggester.unlimited(), + Assertions.assertDoesNotThrow(() -> MethodCommandExtractor.createExecutor(object, "hello", CommandContext.class, int.class)), + null ) - ) + ), + null, + null ) ), new Command( @@ -718,12 +860,19 @@ void testCommandContextParametersCommandResult() { List.of( new IntegerCommandNode( "int", + List.of(), AllowedIntegerInputs.unlimited(), - Assertions.assertDoesNotThrow(() -> MethodCommandExtractor.createExecutor(object, "helloWorld", CommandContext.class, int.class)) + IntegerSuggester.unlimited(), + Assertions.assertDoesNotThrow(() -> MethodCommandExtractor.createExecutor(object, "helloWorld", CommandContext.class, int.class)), + null ) - ) + ), + null, + null ) - ) + ), + null, + null ) ), new Command( @@ -738,14 +887,23 @@ void testCommandContextParametersCommandResult() { List.of( new IntegerCommandNode( "int", + List.of(), AllowedIntegerInputs.unlimited(), - Assertions.assertDoesNotThrow(() -> MethodCommandExtractor.createExecutor(object, "helloThereHi", CommandContext.class, int.class)) + IntegerSuggester.unlimited(), + Assertions.assertDoesNotThrow(() -> MethodCommandExtractor.createExecutor(object, "helloThereHi", CommandContext.class, int.class)), + null ) - ) + ), + null, + null ) - ) + ), + null, + null ) - ) + ), + null, + null ) ) )); @@ -790,10 +948,15 @@ void testParametersPure() { List.of( new IntegerCommandNode( "int", + List.of(), AllowedIntegerInputs.unlimited(), - Assertions.assertDoesNotThrow(() -> MethodCommandExtractor.createExecutor(object, "hello", int.class)) + IntegerSuggester.unlimited(), + Assertions.assertDoesNotThrow(() -> MethodCommandExtractor.createExecutor(object, "hello", int.class)), + null ) - ) + ), + null, + null ) ), new Command( @@ -805,12 +968,19 @@ void testParametersPure() { List.of( new IntegerCommandNode( "int", + List.of(), AllowedIntegerInputs.unlimited(), - Assertions.assertDoesNotThrow(() -> MethodCommandExtractor.createExecutor(object, "helloWorld", int.class)) + IntegerSuggester.unlimited(), + Assertions.assertDoesNotThrow(() -> MethodCommandExtractor.createExecutor(object, "helloWorld", int.class)), + null ) - ) + ), + null, + null ) - ) + ), + null, + null ) ), new Command( @@ -825,14 +995,23 @@ void testParametersPure() { List.of( new IntegerCommandNode( "int", + List.of(), AllowedIntegerInputs.unlimited(), - Assertions.assertDoesNotThrow(() -> MethodCommandExtractor.createExecutor(object, "helloThereHi", int.class)) + IntegerSuggester.unlimited(), + Assertions.assertDoesNotThrow(() -> MethodCommandExtractor.createExecutor(object, "helloThereHi", int.class)), + null ) - ) + ), + null, + null ) - ) + ), + null, + null ) - ) + ), + null, + null ) ) )); @@ -874,10 +1053,15 @@ void testParametersPureCommandResult() { List.of( new IntegerCommandNode( "int", + List.of(), AllowedIntegerInputs.unlimited(), - Assertions.assertDoesNotThrow(() -> MethodCommandExtractor.createExecutor(object, "hello", int.class)) + IntegerSuggester.unlimited(), + Assertions.assertDoesNotThrow(() -> MethodCommandExtractor.createExecutor(object, "hello", int.class)), + null ) - ) + ), + null, + null ) ), new Command( @@ -889,12 +1073,19 @@ void testParametersPureCommandResult() { List.of( new IntegerCommandNode( "int", + List.of(), AllowedIntegerInputs.unlimited(), - Assertions.assertDoesNotThrow(() -> MethodCommandExtractor.createExecutor(object, "helloWorld", int.class)) + IntegerSuggester.unlimited(), + Assertions.assertDoesNotThrow(() -> MethodCommandExtractor.createExecutor(object, "helloWorld", int.class)), + null ) - ) + ), + null, + null ) - ) + ), + null, + null ) ), new Command( @@ -909,14 +1100,23 @@ void testParametersPureCommandResult() { List.of( new IntegerCommandNode( "int", + List.of(), AllowedIntegerInputs.unlimited(), - Assertions.assertDoesNotThrow(() -> MethodCommandExtractor.createExecutor(object, "helloThereHi", int.class)) + IntegerSuggester.unlimited(), + Assertions.assertDoesNotThrow(() -> MethodCommandExtractor.createExecutor(object, "helloThereHi", int.class)), + null ) - ) + ), + null, + null ) - ) + ), + null, + null ) - ) + ), + null, + null ) ) )); @@ -964,10 +1164,13 @@ void testExecute() { List.of( new LiteralCommandNode( "world", - Assertions.assertDoesNotThrow(() -> MethodCommandExtractor.createExecutor(object, "helloWorld")) + List.of(), + Assertions.assertDoesNotThrow(() -> MethodCommandExtractor.createExecutor(object, "helloWorld")), + null ) ), - Assertions.assertDoesNotThrow(() -> MethodCommandExtractor.createExecutor(object, "hello")) + Assertions.assertDoesNotThrow(() -> MethodCommandExtractor.createExecutor(object, "hello")), + null ) ); Command hi = new Command( @@ -976,10 +1179,13 @@ void testExecute() { List.of( new LiteralCommandNode( "world", - Assertions.assertDoesNotThrow(() -> MethodCommandExtractor.createExecutor(object, "hiWorld", CommandSender.class)) + List.of(), + Assertions.assertDoesNotThrow(() -> MethodCommandExtractor.createExecutor(object, "hiWorld", CommandSender.class)), + null ) ), - Assertions.assertDoesNotThrow(() -> MethodCommandExtractor.createExecutor(object, "hi", CommandSender.class)) + Assertions.assertDoesNotThrow(() -> MethodCommandExtractor.createExecutor(object, "hi", CommandSender.class)), + null ) ); Command greetings = new Command( @@ -988,10 +1194,13 @@ void testExecute() { List.of( new LiteralCommandNode( "world", - Assertions.assertDoesNotThrow(() -> MethodCommandExtractor.createExecutor(object, "greetingsWorld", CommandContext.class)) + List.of(), + Assertions.assertDoesNotThrow(() -> MethodCommandExtractor.createExecutor(object, "greetingsWorld", CommandContext.class)), + null ) ), - Assertions.assertDoesNotThrow(() -> MethodCommandExtractor.createExecutor(object, "greetings", CommandContext.class)) + Assertions.assertDoesNotThrow(() -> MethodCommandExtractor.createExecutor(object, "greetings", CommandContext.class)), + null ) ); Command welcome = new Command( @@ -1003,14 +1212,19 @@ void testExecute() { List.of( new LiteralCommandNode( "world", - Assertions.assertDoesNotThrow(() -> MethodCommandExtractor.createExecutor(object, "welcomeWorld", CommandSender.class, String.class)) + List.of(), + Assertions.assertDoesNotThrow(() -> MethodCommandExtractor.createExecutor(object, "welcomeWorld", CommandSender.class, String.class)), + null ) ), AllowedStringInputs.anyNullable(), + StringSuggester.any(), Assertions.assertDoesNotThrow(() -> MethodCommandExtractor.createExecutor(object, "welcome", CommandSender.class, String.class)), null ) - ) + ), + null, + null ) ); Command wassup = new Command( @@ -1022,14 +1236,19 @@ void testExecute() { List.of( new LiteralCommandNode( "nice", - Assertions.assertDoesNotThrow(() -> MethodCommandExtractor.createExecutor(object, "wassupNice", CommandContext.class, String.class)) + List.of(), + Assertions.assertDoesNotThrow(() -> MethodCommandExtractor.createExecutor(object, "wassupNice", CommandContext.class, String.class)), + null ) ), AllowedStringInputs.anyNullable(), + StringSuggester.any(), Assertions.assertDoesNotThrow(() -> MethodCommandExtractor.createExecutor(object, "wassup", CommandContext.class, String.class)), null ) - ) + ), + null, + null ) ); Command aye = new Command( @@ -1041,14 +1260,19 @@ void testExecute() { List.of( new LiteralCommandNode( "nice", - Assertions.assertDoesNotThrow(() -> MethodCommandExtractor.createExecutor(object, "ayeNice", String.class)) + List.of(), + Assertions.assertDoesNotThrow(() -> MethodCommandExtractor.createExecutor(object, "ayeNice", String.class)), + null ) ), AllowedStringInputs.anyNullable(), + StringSuggester.any(), Assertions.assertDoesNotThrow(() -> MethodCommandExtractor.createExecutor(object, "aye", String.class)), null ) - ) + ), + null, + null ) ); From 8a654c553d3245ddcead370cc84b62bc1842e7eb Mon Sep 17 00:00:00 2001 From: WizardlyBump17 Date: Sun, 14 Dec 2025 16:12:06 -0300 Subject: [PATCH 240/363] x more to go --- .../MethodCommandExtractorStructureTests.java | 60 +++++++++++++++---- 1 file changed, 47 insertions(+), 13 deletions(-) diff --git a/commands/src/test/java/com/wizardlybump17/wlib/test/command/extractor/method/MethodCommandExtractorStructureTests.java b/commands/src/test/java/com/wizardlybump17/wlib/test/command/extractor/method/MethodCommandExtractorStructureTests.java index 3593652a..66381a97 100644 --- a/commands/src/test/java/com/wizardlybump17/wlib/test/command/extractor/method/MethodCommandExtractorStructureTests.java +++ b/commands/src/test/java/com/wizardlybump17/wlib/test/command/extractor/method/MethodCommandExtractorStructureTests.java @@ -7,6 +7,7 @@ import com.wizardlybump17.wlib.command.node.LiteralCommandNode; import com.wizardlybump17.wlib.command.node.primitive.number.IntegerCommandNode; import com.wizardlybump17.wlib.command.registry.MethodCommandNodeFactoryRegistry; +import com.wizardlybump17.wlib.command.suggestion.primitive.number.IntegerSuggester; import com.wizardlybump17.wlib.test.util.AssertionUtil; import org.junit.jupiter.api.AfterAll; import org.junit.jupiter.api.Assertions; @@ -44,9 +45,14 @@ void test0() { "test0", List.of( new LiteralCommandNode( - "123" + "123", + List.of(), + null, + null ) - ) + ), + null, + null ) ); Command test1 = new Command( @@ -57,11 +63,18 @@ void test0() { "123", List.of( new LiteralCommandNode( - "456" + "456", + List.of(), + null, + null ) - ) + ), + null, + null ) - ) + ), + null, + null ) ); @@ -97,12 +110,20 @@ void test1() { "int", List.of( new LiteralCommandNode( - "123" + "123", + List.of(), + null, + null ) ), - AllowedIntegerInputs.unlimited() + AllowedIntegerInputs.unlimited(), + IntegerSuggester.unlimited(), + null, + null ) - ) + ), + null, + null ) ); Command test1 = new Command( @@ -119,17 +140,30 @@ void test1() { "123", List.of( new LiteralCommandNode( - "abc" + "abc", + List.of(), + null, + null ) - ) + ), + null, + null ) ), - AllowedIntegerInputs.unlimited() + AllowedIntegerInputs.unlimited(), + IntegerSuggester.unlimited(), + null, + null ) ), - AllowedIntegerInputs.unlimited() + AllowedIntegerInputs.unlimited(), + IntegerSuggester.unlimited(), + null, + null ) - ) + ), + null, + null ) ); From a003ba8a0f31f6d880c0203d8452f4b3168ddc12 Mon Sep 17 00:00:00 2001 From: WizardlyBump17 Date: Sun, 14 Dec 2025 16:23:32 -0300 Subject: [PATCH 241/363] sync with the recent changes --- ...OfflinePlayerMethodCommandNodeFactory.java | 2 + .../node/OfflinePlayerCommandNode.java | 42 +++++----------- .../suggestion/OfflinePlayerSuggester.java | 49 +++++++++++++++++++ 3 files changed, 64 insertions(+), 29 deletions(-) create mode 100644 core/src/main/java/com/wizardlybump17/wlib/command/suggestion/OfflinePlayerSuggester.java diff --git a/core/src/main/java/com/wizardlybump17/wlib/command/extractor/method/factory/OfflinePlayerMethodCommandNodeFactory.java b/core/src/main/java/com/wizardlybump17/wlib/command/extractor/method/factory/OfflinePlayerMethodCommandNodeFactory.java index f7ea63fe..dd61a6cc 100644 --- a/core/src/main/java/com/wizardlybump17/wlib/command/extractor/method/factory/OfflinePlayerMethodCommandNodeFactory.java +++ b/core/src/main/java/com/wizardlybump17/wlib/command/extractor/method/factory/OfflinePlayerMethodCommandNodeFactory.java @@ -4,6 +4,7 @@ import com.wizardlybump17.wlib.command.input.AllowedOfflinePlayerInputs; import com.wizardlybump17.wlib.command.node.CommandNode; import com.wizardlybump17.wlib.command.node.OfflinePlayerCommandNode; +import com.wizardlybump17.wlib.command.suggestion.OfflinePlayerSuggester; import org.bukkit.OfflinePlayer; import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.Nullable; @@ -20,6 +21,7 @@ public class OfflinePlayerMethodCommandNodeFactory extends MethodCommandNodeFact name, root == null ? List.of() : List.of(root), parameter.isAnnotationPresent(NotNull.class) ? AllowedOfflinePlayerInputs.anyNotNull() : AllowedOfflinePlayerInputs.anyNullable(), + OfflinePlayerSuggester.online(), null, null ); diff --git a/core/src/main/java/com/wizardlybump17/wlib/command/node/OfflinePlayerCommandNode.java b/core/src/main/java/com/wizardlybump17/wlib/command/node/OfflinePlayerCommandNode.java index a8f0e533..5a2a4a4f 100644 --- a/core/src/main/java/com/wizardlybump17/wlib/command/node/OfflinePlayerCommandNode.java +++ b/core/src/main/java/com/wizardlybump17/wlib/command/node/OfflinePlayerCommandNode.java @@ -2,43 +2,22 @@ import com.wizardlybump17.wlib.command.exception.InputParsingException; import com.wizardlybump17.wlib.command.executor.CommandNodeExecutor; +import com.wizardlybump17.wlib.command.input.AllowedInputs; import com.wizardlybump17.wlib.command.input.AllowedOfflinePlayerInputs; +import com.wizardlybump17.wlib.command.suggestion.OfflinePlayerSuggester; import org.bukkit.Bukkit; import org.bukkit.OfflinePlayer; import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.Nullable; +import org.jetbrains.annotations.Unmodifiable; import java.util.List; import java.util.UUID; public class OfflinePlayerCommandNode extends CommandNode { - public OfflinePlayerCommandNode(@NotNull String name, @NotNull List> children, @NotNull AllowedOfflinePlayerInputs allowedInputs, @Nullable CommandNodeExecutor executor, @Nullable String permission) { - super(name, children, allowedInputs, executor, permission); - } - - public OfflinePlayerCommandNode(@NotNull String name, @NotNull AllowedOfflinePlayerInputs allowedInputs, @Nullable CommandNodeExecutor executor, @Nullable String permission) { - super(name, allowedInputs, executor, permission); - } - - public OfflinePlayerCommandNode(@NotNull String name, @NotNull List> children, @NotNull AllowedOfflinePlayerInputs allowedInputs, @Nullable String permission) { - super(name, children, allowedInputs, permission); - } - - public OfflinePlayerCommandNode(@NotNull String name, @NotNull AllowedOfflinePlayerInputs allowedInputs, @Nullable String permission) { - super(name, allowedInputs, permission); - } - - public OfflinePlayerCommandNode(@NotNull String name, @NotNull AllowedOfflinePlayerInputs allowedInputs, @Nullable CommandNodeExecutor executor) { - super(name, allowedInputs, executor); - } - - public OfflinePlayerCommandNode(@NotNull String name, @NotNull List> children, @NotNull AllowedOfflinePlayerInputs allowedInputs) { - super(name, children, allowedInputs); - } - - public OfflinePlayerCommandNode(@NotNull String name, @NotNull AllowedOfflinePlayerInputs allowedInputs) { - super(name, allowedInputs); + public OfflinePlayerCommandNode(@NotNull String name, @NotNull @Unmodifiable List> children, @NotNull AllowedInputs allowedInputs, @Nullable OfflinePlayerSuggester suggester, @Nullable CommandNodeExecutor executor, @Nullable String permission) { + super(name, children, allowedInputs, suggester, executor, permission); } @Override @@ -66,18 +45,23 @@ public OfflinePlayerCommandNode(@NotNull String name, @NotNull AllowedOfflinePla return (AllowedOfflinePlayerInputs) super.getAllowedInputs(); } + @Override + public @Nullable OfflinePlayerSuggester getSuggester() { + return (OfflinePlayerSuggester) super.getSuggester(); + } + @Override public @NotNull OfflinePlayerCommandNode withChildren(@NotNull List> children) { - return new OfflinePlayerCommandNode(getName(), children, getAllowedInputs(), getExecutor(), getPermission()); + return new OfflinePlayerCommandNode(getName(), children, getAllowedInputs(), getSuggester(), getExecutor(), getPermission()); } @Override public @NotNull OfflinePlayerCommandNode withExecutor(@Nullable CommandNodeExecutor executor) { - return new OfflinePlayerCommandNode(getName(), getChildren(), getAllowedInputs(), executor, getPermission()); + return new OfflinePlayerCommandNode(getName(), getChildren(), getAllowedInputs(), getSuggester(), executor, getPermission()); } @Override public @NotNull OfflinePlayerCommandNode withPermission(@Nullable String permission) { - return new OfflinePlayerCommandNode(getName(), getChildren(), getAllowedInputs(), getExecutor(), permission); + return new OfflinePlayerCommandNode(getName(), getChildren(), getAllowedInputs(), getSuggester(), getExecutor(), permission); } } diff --git a/core/src/main/java/com/wizardlybump17/wlib/command/suggestion/OfflinePlayerSuggester.java b/core/src/main/java/com/wizardlybump17/wlib/command/suggestion/OfflinePlayerSuggester.java new file mode 100644 index 00000000..d12199fc --- /dev/null +++ b/core/src/main/java/com/wizardlybump17/wlib/command/suggestion/OfflinePlayerSuggester.java @@ -0,0 +1,49 @@ +package com.wizardlybump17.wlib.command.suggestion; + +import com.wizardlybump17.wlib.command.node.CommandNode; +import com.wizardlybump17.wlib.command.sender.CommandSender; +import org.bukkit.Bukkit; +import org.bukkit.OfflinePlayer; +import org.jetbrains.annotations.NotNull; + +import java.util.List; + +public interface OfflinePlayerSuggester extends Suggester { + + @Override + default @NotNull String getStringRepresentation(@NotNull OfflinePlayer value) { + String name = value.getName(); + return name == null ? value.getUniqueId().toString() : name; + } + + static @NotNull Online online() { + return Online.INSTANCE; + } + + static @NotNull Cached cached() { + return Cached.INSTANCE; + } + + final class Online implements OfflinePlayerSuggester { + + private static final @NotNull Online INSTANCE = new Online(); + + @Override + public @NotNull List getSuggestions(@NotNull CommandSender sender, @NotNull List input, @NotNull String current, @NotNull CommandNode currentNode) { + return Bukkit.getOnlinePlayers() + .stream() + .map(OfflinePlayer.class::cast) + .toList(); + } + } + + final class Cached implements OfflinePlayerSuggester { + + private static final @NotNull Cached INSTANCE = new Cached(); + + @Override + public @NotNull List getSuggestions(@NotNull CommandSender sender, @NotNull List input, @NotNull String current, @NotNull CommandNode currentNode) { + return List.of(Bukkit.getOfflinePlayers()); + } + } +} From 9e3671d915c6e5b76b8aacf48bb2c9df8a927b6a Mon Sep 17 00:00:00 2001 From: WizardlyBump17 Date: Sun, 14 Dec 2025 21:02:04 -0300 Subject: [PATCH 242/363] the suggestions are now Strings --- .../wizardlybump17/wlib/command/Command.java | 28 ++++++-- .../wlib/command/manager/CommandManager.java | 7 +- .../wlib/test/command/SuggestionTests.java | 44 ++++++------ .../CommandManagerSuggestionTests.java | 68 +++++++++---------- 4 files changed, 83 insertions(+), 64 deletions(-) diff --git a/commands/src/main/java/com/wizardlybump17/wlib/command/Command.java b/commands/src/main/java/com/wizardlybump17/wlib/command/Command.java index 9df93f7e..55b5036b 100644 --- a/commands/src/main/java/com/wizardlybump17/wlib/command/Command.java +++ b/commands/src/main/java/com/wizardlybump17/wlib/command/Command.java @@ -8,6 +8,7 @@ import com.wizardlybump17.wlib.command.node.LiteralCommandNode; import com.wizardlybump17.wlib.command.result.CommandResult; import com.wizardlybump17.wlib.command.sender.CommandSender; +import com.wizardlybump17.wlib.command.suggestion.Suggester; import com.wizardlybump17.wlib.util.StringUtil; import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.Nullable; @@ -116,13 +117,14 @@ public Command(@NotNull LiteralCommandNode root) { return StringUtil.parseQuotedStrings(original); } - public @NotNull List getSuggestions(@NotNull CommandSender sender, @NotNull List input) { + @SuppressWarnings("unchecked") + public @NotNull List getSuggestions(@NotNull CommandSender sender, @NotNull List input) { if (input.isEmpty()) return List.of(root.getName()); String currentInput = input.getLast(); - List suggestions = new ArrayList<>(); + List suggestions = new ArrayList<>(); List> children = List.of(root); CommandNode lastNode = null; @@ -136,7 +138,7 @@ public Command(@NotNull LiteralCommandNode root) { for (CommandNode child : children) { String permission = child.getPermission(); if (permission == null || sender.hasPermission(permission)) - suggestions.addAll(child.getSuggestions(sender, input, "")); + suggestions.addAll(getSuggestions0(child, sender, input, "")); } if (!children.isEmpty()) lastNode = children.getLast(); @@ -154,7 +156,7 @@ public Command(@NotNull LiteralCommandNode root) { String permission = child.getPermission(); if (isLastInput && (permission == null || sender.hasPermission(permission))) - suggestions.addAll(child.getSuggestions(sender, input, currentInput)); + suggestions.addAll(getSuggestions0(child, sender, input, currentInput)); lastParsingError = null; @@ -182,6 +184,24 @@ public Command(@NotNull LiteralCommandNode root) { return suggestions; } + @SuppressWarnings("unchecked") + private static @NotNull List getSuggestions0(@NotNull CommandNode node, @NotNull CommandSender sender, @NotNull List input, @NotNull String currentInput) { + List childSuggestions = node.getSuggestions(sender, input, currentInput); + Suggester suggester = (Suggester) node.getSuggester(); + + if (suggester == null) { + return childSuggestions + .stream() + .map(Object::toString) + .toList(); + } else { + return childSuggestions + .stream() + .map(suggester::getStringRepresentation) + .toList(); + } + } + public @NotNull Command merge(@NotNull Command other) { return new Command((LiteralCommandNode) root.merge(other.getRoot())); } diff --git a/commands/src/main/java/com/wizardlybump17/wlib/command/manager/CommandManager.java b/commands/src/main/java/com/wizardlybump17/wlib/command/manager/CommandManager.java index 31a86997..fda360e6 100644 --- a/commands/src/main/java/com/wizardlybump17/wlib/command/manager/CommandManager.java +++ b/commands/src/main/java/com/wizardlybump17/wlib/command/manager/CommandManager.java @@ -98,13 +98,12 @@ protected void addCommand(@NotNull String identifier, @NotNull String name, @Not return execute(sender, String.join(" ", input)); } - public @NotNull List getSuggestions(@NotNull CommandSender sender, @NotNull List input) { + public @NotNull List getSuggestions(@NotNull CommandSender sender, @NotNull List input) { if (input.isEmpty() || input.size() == 1) { return commandsByName.values().stream() .map(Command::getRoot) .filter(node -> node.canExecute(sender)) .map(CommandNode::getName) - .map(string -> (Object) string) .toList(); } @@ -120,7 +119,7 @@ protected void addCommand(@NotNull String identifier, @NotNull String name, @Not return command.getSuggestions(sender, input); } - public @NotNull List getSuggestions(@NotNull CommandSender sender, @NotNull String input) { + public @NotNull List getSuggestions(@NotNull CommandSender sender, @NotNull String input) { try { if (!input.isEmpty() && !StringUtil.isProperlyQuoted(input)) input = input + "\""; @@ -130,7 +129,7 @@ protected void addCommand(@NotNull String identifier, @NotNull String name, @Not } } - public @NotNull List getSuggestions(@NotNull CommandSender sender, @NotNull String @NotNull [] input) { + public @NotNull List getSuggestions(@NotNull CommandSender sender, @NotNull String @NotNull [] input) { return getSuggestions(sender, String.join(" ", input)); } diff --git a/commands/src/test/java/com/wizardlybump17/wlib/test/command/SuggestionTests.java b/commands/src/test/java/com/wizardlybump17/wlib/test/command/SuggestionTests.java index 00550d19..87b843e1 100644 --- a/commands/src/test/java/com/wizardlybump17/wlib/test/command/SuggestionTests.java +++ b/commands/src/test/java/com/wizardlybump17/wlib/test/command/SuggestionTests.java @@ -51,8 +51,8 @@ void testSuccess0() { ) ); - List expected = List.of("hello"); - List actual = command.getSuggestions(CHAD_SENDER, List.of()); + List expected = List.of("hello"); + List actual = command.getSuggestions(CHAD_SENDER, List.of()); Assertions.assertEquals(expected, actual); } @@ -76,8 +76,8 @@ void testSuccess1() { ) ); - List expected = List.of("hello"); - List actual = command.getSuggestions(CHAD_SENDER, List.of("he")); + List expected = List.of("hello"); + List actual = command.getSuggestions(CHAD_SENDER, List.of("he")); Assertions.assertEquals(expected, actual); } @@ -113,8 +113,8 @@ void testSuccess2() { ) ); - List expected = List.of("world", "hi", "there"); - List actual = command.getSuggestions(CHAD_SENDER, List.of("hello", "")); + List expected = List.of("world", "hi", "there"); + List actual = command.getSuggestions(CHAD_SENDER, List.of("hello", "")); Assertions.assertEquals(expected, actual); } @@ -152,8 +152,8 @@ void testSuccess3() { ) ); - List expected = List.of("world", "hi", 1, 3, 5, 7, 10); - List actual = command.getSuggestions(CHAD_SENDER, List.of("hello", "")); + List expected = List.of("world", "hi", "1", "3", "5", "7", "10"); + List actual = command.getSuggestions(CHAD_SENDER, List.of("hello", "")); Assertions.assertEquals(expected, actual); } @@ -197,8 +197,8 @@ void testSuccess4() { ) ); - List expected = List.of("world", "hi", "happy"); - List actual = command.getSuggestions(CHAD_SENDER, List.of("hello", "h")); + List expected = List.of("world", "hi", "happy"); + List actual = command.getSuggestions(CHAD_SENDER, List.of("hello", "h")); Assertions.assertEquals(expected, actual); } @@ -242,7 +242,7 @@ void testDefaultSuggestions() { //byte Assertions.assertEquals( - List.of((byte) -128, (byte) -100, (byte) -50, (byte) 0, (byte) 50, (byte) 100, (byte) 127), + List.of("-128", "-100", "-50", "0", "50", "100", "127"), new Command( new LiteralCommandNode( "hello", @@ -262,7 +262,7 @@ void testDefaultSuggestions() { ).getSuggestions(CHAD_SENDER, List.of("hello", "")) ); Assertions.assertEquals( - List.of((byte) -128, (byte) -100, (byte) -50, (byte) 0, (byte) 50, (byte) 100, (byte) 127), + List.of("-128", "-100", "-50", "0", "50", "100", "127"), new Command( new LiteralCommandNode( "hello", @@ -282,7 +282,7 @@ void testDefaultSuggestions() { ).getSuggestions(CHAD_SENDER, List.of("hello", "0")) ); Assertions.assertEquals( - List.of((byte) -128, (byte) -100, (byte) -50, (byte) 0, (byte) 50, (byte) 100, (byte) 127), + List.of("-128", "-100", "-50", "0", "50", "100", "127"), new Command( new LiteralCommandNode( "hello", @@ -304,7 +304,7 @@ void testDefaultSuggestions() { //short Assertions.assertEquals( - List.of((short) -32768, (short) -3000, (short) -100, (short) -50, (short) 0, (short) 50, (short) 100, (short) 3000, (short) 32767), + List.of("-32768", "-3000", "-100", "-50", "0", "50", "100", "3000", "32767"), new Command( new LiteralCommandNode( "hello", @@ -324,7 +324,7 @@ void testDefaultSuggestions() { ).getSuggestions(CHAD_SENDER, List.of("hello", "")) ); Assertions.assertEquals( - List.of((short) -32768, (short) -3000, (short) -100, (short) -50, (short) 0, (short) 50, (short) 100, (short) 3000, (short) 32767), + List.of("-32768", "-3000", "-100", "-50", "0", "50", "100", "3000", "32767"), new Command( new LiteralCommandNode( "hello", @@ -344,7 +344,7 @@ void testDefaultSuggestions() { ).getSuggestions(CHAD_SENDER, List.of("hello", "0")) ); Assertions.assertEquals( - List.of((short) -32768, (short) -3000, (short) -100, (short) -50, (short) 0, (short) 50, (short) 100, (short) 3000, (short) 32767), + List.of("-32768", "-3000", "-100", "-50", "0", "50", "100", "3000", "32767"), new Command( new LiteralCommandNode( "hello", @@ -366,7 +366,7 @@ void testDefaultSuggestions() { //int Assertions.assertEquals( - List.of(-100000, -50000, -3000, -200, -50, 0, 50, 200, 3000, 50000, 100000), + List.of("-100000", "-50000", "-3000", "-200", "-50", "0", "50", "200", "3000", "50000", "100000"), new Command( new LiteralCommandNode( "hello", @@ -386,7 +386,7 @@ void testDefaultSuggestions() { ).getSuggestions(CHAD_SENDER, List.of("hello", "")) ); Assertions.assertEquals( - List.of(-100000, -50000, -3000, -200, -50, 0, 50, 200, 3000, 50000, 100000), + List.of("-100000", "-50000", "-3000", "-200", "-50", "0", "50", "200", "3000", "50000", "100000"), new Command( new LiteralCommandNode( "hello", @@ -406,7 +406,7 @@ void testDefaultSuggestions() { ).getSuggestions(CHAD_SENDER, List.of("hello", "0")) ); Assertions.assertEquals( - List.of(-100000, -50000, -3000, -200, -50, 0, 50, 200, 3000, 50000, 100000), + List.of("-100000", "-50000", "-3000", "-200", "-50", "0", "50", "200", "3000", "50000", "100000"), new Command( new LiteralCommandNode( "hello", @@ -428,7 +428,7 @@ void testDefaultSuggestions() { //long Assertions.assertEquals( - List.of(-100000L, -50000L, -3000L, -200L, -50L, 0L, 50L, 200L, 3000L, 50000L, 100000L), + List.of("-100000", "-50000", "-3000", "-200", "-50", "0", "50", "200", "3000", "50000", "100000"), new Command( new LiteralCommandNode( "hello", @@ -448,7 +448,7 @@ void testDefaultSuggestions() { ).getSuggestions(CHAD_SENDER, List.of("hello", "")) ); Assertions.assertEquals( - List.of(-100000L, -50000L, -3000L, -200L, -50L, 0L, 50L, 200L, 3000L, 50000L, 100000L), + List.of("-100000", "-50000", "-3000", "-200", "-50", "0", "50", "200", "3000", "50000", "100000"), new Command( new LiteralCommandNode( "hello", @@ -468,7 +468,7 @@ void testDefaultSuggestions() { ).getSuggestions(CHAD_SENDER, List.of("hello", "0")) ); Assertions.assertEquals( - List.of(-100000L, -50000L, -3000L, -200L, -50L, 0L, 50L, 200L, 3000L, 50000L, 100000L), + List.of("-100000", "-50000", "-3000", "-200", "-50", "0", "50", "200", "3000", "50000", "100000"), new Command( new LiteralCommandNode( "hello", diff --git a/commands/src/test/java/com/wizardlybump17/wlib/test/command/manager/CommandManagerSuggestionTests.java b/commands/src/test/java/com/wizardlybump17/wlib/test/command/manager/CommandManagerSuggestionTests.java index a7443b13..de8f32dc 100644 --- a/commands/src/test/java/com/wizardlybump17/wlib/test/command/manager/CommandManagerSuggestionTests.java +++ b/commands/src/test/java/com/wizardlybump17/wlib/test/command/manager/CommandManagerSuggestionTests.java @@ -63,8 +63,8 @@ void testSuggestionsSuccessListChad0() { manager.registerCommand("test", command1); manager.registerCommand("test", command2); - List expected = List.of("hello", "hi", "welcome"); - List actual = manager.getSuggestions(CHAD_SENDER, List.of()); + List expected = List.of("hello", "hi", "welcome"); + List actual = manager.getSuggestions(CHAD_SENDER, List.of()); Assertions.assertTrue(CollectionUtil.contentEquals(expected, actual)); } @@ -108,8 +108,8 @@ void testSuggestionsSuccessListChad1() { manager.registerCommand("test", command1); manager.registerCommand("test", command2); - List expected = List.of("hello", "hi", "welcome"); - List actual = manager.getSuggestions(CHAD_SENDER, List.of("he")); + List expected = List.of("hello", "hi", "welcome"); + List actual = manager.getSuggestions(CHAD_SENDER, List.of("he")); Assertions.assertTrue(CollectionUtil.contentEquals(expected, actual)); } @@ -153,8 +153,8 @@ void testSuggestionsSuccessListChad2() { manager.registerCommand("test", command1); manager.registerCommand("test", command2); - List expected = List.of("there"); - List actual = manager.getSuggestions(CHAD_SENDER, List.of("hi", "")); + List expected = List.of("there"); + List actual = manager.getSuggestions(CHAD_SENDER, List.of("hi", "")); Assertions.assertTrue(CollectionUtil.contentEquals(expected, actual)); } @@ -198,8 +198,8 @@ void testSuggestionsSuccessListChad3() { manager.registerCommand("test", command1); manager.registerCommand("test", command2); - List expected = List.of("there"); - List actual = manager.getSuggestions(CHAD_SENDER, List.of("hi", "ther")); + List expected = List.of("there"); + List actual = manager.getSuggestions(CHAD_SENDER, List.of("hi", "ther")); Assertions.assertTrue(CollectionUtil.contentEquals(expected, actual)); } @@ -252,8 +252,8 @@ void testSuggestionsSuccessListChad4() { manager.registerCommand("test", command1); manager.registerCommand("test", command2); - List expected = List.of(0, 50, 200, 3000, 50000, 100000); - List actual = manager.getSuggestions(CHAD_SENDER, List.of("welcome", "")); + List expected = List.of("0", "50", "200", "3000", "50000", "100000"); + List actual = manager.getSuggestions(CHAD_SENDER, List.of("welcome", "")); Assertions.assertEquals(expected, actual); } @@ -306,8 +306,8 @@ void testSuggestionsSuccessListChad6() { manager.registerCommand("test", command1); manager.registerCommand("test", command2); - List expected = List.of(0, 50, 200, 3000, 50000, 100000); - List actual = manager.getSuggestions(CHAD_SENDER, List.of("welcome", "10")); + List expected = List.of("0", "50", "200", "3000", "50000", "100000"); + List actual = manager.getSuggestions(CHAD_SENDER, List.of("welcome", "10")); Assertions.assertTrue(CollectionUtil.contentEquals(expected, actual)); } @@ -351,8 +351,8 @@ void testSuggestionsFailListBeta0() { manager.registerCommand("test", command1); manager.registerCommand("test", command2); - List expected = List.of(); - List actual = manager.getSuggestions(BETA_SENDER, List.of()); + List expected = List.of(); + List actual = manager.getSuggestions(BETA_SENDER, List.of()); Assertions.assertTrue(CollectionUtil.contentEquals(expected, actual)); } @@ -405,8 +405,8 @@ void testSuggestionsSuccessStringChad0() { manager.registerCommand("test", command1); manager.registerCommand("test", command2); - List expected = List.of("hi", "hello", "welcome"); - List actual = manager.getSuggestions(CHAD_SENDER, ""); + List expected = List.of("hi", "hello", "welcome"); + List actual = manager.getSuggestions(CHAD_SENDER, ""); Assertions.assertEquals(expected, actual); } @@ -459,8 +459,8 @@ void testSuggestionsSuccessStringChad1() { manager.registerCommand("test", command1); manager.registerCommand("test", command2); - List expected = List.of("there"); - List actual = manager.getSuggestions(CHAD_SENDER, "hi t"); + List expected = List.of("there"); + List actual = manager.getSuggestions(CHAD_SENDER, "hi t"); Assertions.assertEquals(expected, actual); } @@ -513,8 +513,8 @@ void testSuggestionsSuccessStringChad2() { manager.registerCommand("test", command1); manager.registerCommand("test", command2); - List expected = List.of(0, 50, 200, 3000, 50000, 100000); - List actual = manager.getSuggestions(CHAD_SENDER, "welcome 1"); + List expected = List.of("0", "50", "200", "3000", "50000", "100000"); + List actual = manager.getSuggestions(CHAD_SENDER, "welcome 1"); Assertions.assertEquals(expected, actual); } @@ -583,8 +583,8 @@ void testSuggestionsSuccessStringChad3() { manager.registerCommand("test", command2); manager.registerCommand("test", command3); - List expected = List.of("spaced string"); - List actual = manager.getSuggestions(CHAD_SENDER, "test \"spaced "); + List expected = List.of("spaced string"); + List actual = manager.getSuggestions(CHAD_SENDER, "test \"spaced "); Assertions.assertEquals(expected, actual); } @@ -653,8 +653,8 @@ void testSuggestionsSuccessStringArrayChad0() { manager.registerCommand("test", command2); manager.registerCommand("test", command3); - List expected = List.of("hi", "test", "hello", "welcome"); - List actual = manager.getSuggestions(CHAD_SENDER, new String[]{}); + List expected = List.of("hi", "test", "hello", "welcome"); + List actual = manager.getSuggestions(CHAD_SENDER, new String[]{}); Assertions.assertEquals(expected, actual); } @@ -723,8 +723,8 @@ void testSuggestionsSuccessStringArrayChad1() { manager.registerCommand("test", command2); manager.registerCommand("test", command3); - List expected = List.of("hi", "test", "hello", "welcome"); - List actual = manager.getSuggestions(CHAD_SENDER, new String[]{"he"}); + List expected = List.of("hi", "test", "hello", "welcome"); + List actual = manager.getSuggestions(CHAD_SENDER, new String[]{"he"}); Assertions.assertEquals(expected, actual); } @@ -793,8 +793,8 @@ void testSuggestionsSuccessStringArrayChad2() { manager.registerCommand("test", command2); manager.registerCommand("test", command3); - List expected = List.of(0, 50, 200, 3000, 50000, 100000); - List actual = manager.getSuggestions(CHAD_SENDER, new String[]{"welcome", ""}); + List expected = List.of("0", "50", "200", "3000", "50000", "100000"); + List actual = manager.getSuggestions(CHAD_SENDER, new String[]{"welcome", ""}); Assertions.assertEquals(expected, actual); } @@ -863,8 +863,8 @@ void testSuggestionsSuccessStringArrayChad3() { manager.registerCommand("test", command2); manager.registerCommand("test", command3); - List expected = List.of("spaced string"); - List actual = manager.getSuggestions(CHAD_SENDER, new String[]{"test", ""}); + List expected = List.of("spaced string"); + List actual = manager.getSuggestions(CHAD_SENDER, new String[]{"test", ""}); Assertions.assertEquals(expected, actual); } @@ -933,8 +933,8 @@ void testSuggestionsSuccessStringArrayChad4() { manager.registerCommand("test", command2); manager.registerCommand("test", command3); - List expected = List.of("spaced string"); - List actual = manager.getSuggestions(CHAD_SENDER, new String[]{"test", "spaced"}); + List expected = List.of("spaced string"); + List actual = manager.getSuggestions(CHAD_SENDER, new String[]{"test", "spaced"}); Assertions.assertEquals(expected, actual); } @@ -1003,8 +1003,8 @@ void testSuggestionsSuccessStringArrayChad5() { manager.registerCommand("test", command2); manager.registerCommand("test", command3); - List expected = List.of("spaced string"); - List actual = manager.getSuggestions(CHAD_SENDER, new String[]{"test", "\"space"}); + List expected = List.of("spaced string"); + List actual = manager.getSuggestions(CHAD_SENDER, new String[]{"test", "\"space"}); Assertions.assertEquals(expected, actual); } From c0a5cb633beb89e982a24ef259c2bc39f6ebd6c5 Mon Sep 17 00:00:00 2001 From: WizardlyBump17 Date: Sun, 14 Dec 2025 21:07:05 -0300 Subject: [PATCH 243/363] finished the number suggestion tests --- .../wlib/test/command/SuggestionTests.java | 139 ++++++++++++++++-- 1 file changed, 127 insertions(+), 12 deletions(-) diff --git a/commands/src/test/java/com/wizardlybump17/wlib/test/command/SuggestionTests.java b/commands/src/test/java/com/wizardlybump17/wlib/test/command/SuggestionTests.java index 87b843e1..f8230516 100644 --- a/commands/src/test/java/com/wizardlybump17/wlib/test/command/SuggestionTests.java +++ b/commands/src/test/java/com/wizardlybump17/wlib/test/command/SuggestionTests.java @@ -1,22 +1,13 @@ package com.wizardlybump17.wlib.test.command; import com.wizardlybump17.wlib.command.Command; -import com.wizardlybump17.wlib.command.input.primitive.number.AllowedByteInputs; -import com.wizardlybump17.wlib.command.input.primitive.number.AllowedIntegerInputs; -import com.wizardlybump17.wlib.command.input.primitive.number.AllowedLongInputs; -import com.wizardlybump17.wlib.command.input.primitive.number.AllowedShortInputs; +import com.wizardlybump17.wlib.command.input.primitive.number.*; import com.wizardlybump17.wlib.command.node.LiteralCommandNode; -import com.wizardlybump17.wlib.command.node.primitive.number.ByteCommandNode; -import com.wizardlybump17.wlib.command.node.primitive.number.IntegerCommandNode; -import com.wizardlybump17.wlib.command.node.primitive.number.LongCommandNode; -import com.wizardlybump17.wlib.command.node.primitive.number.ShortCommandNode; +import com.wizardlybump17.wlib.command.node.primitive.number.*; import com.wizardlybump17.wlib.command.result.CommandResult; import com.wizardlybump17.wlib.command.sender.BasicCommandSender; import com.wizardlybump17.wlib.command.sender.CommandSender; -import com.wizardlybump17.wlib.command.suggestion.primitive.number.ByteSuggester; -import com.wizardlybump17.wlib.command.suggestion.primitive.number.IntegerSuggester; -import com.wizardlybump17.wlib.command.suggestion.primitive.number.LongSuggester; -import com.wizardlybump17.wlib.command.suggestion.primitive.number.ShortSuggester; +import com.wizardlybump17.wlib.command.suggestion.primitive.number.*; import org.jetbrains.annotations.NotNull; import org.junit.jupiter.api.Assertions; import org.junit.jupiter.api.DisplayName; @@ -487,5 +478,129 @@ void testDefaultSuggestions() { ) ).getSuggestions(CHAD_SENDER, List.of("hello", "10")) ); + + //float + Assertions.assertEquals( + List.of("-100000.5", "-50000.5", "-3000.5", "-200.5", "-50.5", "0.0", "50.5", "200.5", "3000.5", "50000.5", "100000.5"), + new Command( + new LiteralCommandNode( + "hello", + List.of( + new FloatCommandNode( + "world", + List.of(), + AllowedFloatInputs.unlimited(), + FloatSuggester.unlimited(), + null, + null + ) + ), + null, + null + ) + ).getSuggestions(CHAD_SENDER, List.of("hello", "")) + ); + Assertions.assertEquals( + List.of("-100000.5", "-50000.5", "-3000.5", "-200.5", "-50.5", "0.0", "50.5", "200.5", "3000.5", "50000.5", "100000.5"), + new Command( + new LiteralCommandNode( + "hello", + List.of( + new FloatCommandNode( + "world", + List.of(), + AllowedFloatInputs.unlimited(), + FloatSuggester.unlimited(), + null, + null + ) + ), + null, + null + ) + ).getSuggestions(CHAD_SENDER, List.of("hello", "0")) + ); + Assertions.assertEquals( + List.of("-100000.5", "-50000.5", "-3000.5", "-200.5", "-50.5", "0.0", "50.5", "200.5", "3000.5", "50000.5", "100000.5"), + new Command( + new LiteralCommandNode( + "hello", + List.of( + new FloatCommandNode( + "world", + List.of(), + AllowedFloatInputs.unlimited(), + FloatSuggester.unlimited(), + null, + null + ) + ), + null, + null + ) + ).getSuggestions(CHAD_SENDER, List.of("hello", "10")) + ); + + //double + Assertions.assertEquals( + List.of("-100000.5", "-50000.5", "-3000.5", "-200.5", "-50.5", "0.0", "50.5", "200.5", "3000.5", "50000.5", "100000.5"), + new Command( + new LiteralCommandNode( + "hello", + List.of( + new DoubleCommandNode( + "world", + List.of(), + AllowedDoubleInputs.unlimited(), + DoubleSuggester.unlimited(), + null, + null + ) + ), + null, + null + ) + ).getSuggestions(CHAD_SENDER, List.of("hello", "")) + ); + Assertions.assertEquals( + List.of("-100000.5", "-50000.5", "-3000.5", "-200.5", "-50.5", "0.0", "50.5", "200.5", "3000.5", "50000.5", "100000.5"), + new Command( + new LiteralCommandNode( + "hello", + List.of( + new DoubleCommandNode( + "world", + List.of(), + AllowedDoubleInputs.unlimited(), + DoubleSuggester.unlimited(), + null, + null + ) + ), + null, + null + ) + ).getSuggestions(CHAD_SENDER, List.of("hello", "0")) + ); + Assertions.assertEquals( + List.of("-100000.5", "-50000.5", "-3000.5", "-200.5", "-50.5", "0.0", "50.5", "200.5", "3000.5", "50000.5", "100000.5"), + new Command( + new LiteralCommandNode( + "hello", + List.of( + new DoubleCommandNode( + "world", + List.of(), + AllowedDoubleInputs.unlimited(), + DoubleSuggester.unlimited(), + null, + null + ) + ), + null, + null + ) + ).getSuggestions(CHAD_SENDER, List.of("hello", "10")) + ); } } From f08a9836c2bc2fc1e183844fc03d0a32fb437664 Mon Sep 17 00:00:00 2001 From: WizardlyBump17 Date: Sun, 14 Dec 2025 21:09:41 -0300 Subject: [PATCH 244/363] testing strings --- .../wlib/test/command/SuggestionTests.java | 85 +++++++++++++++++++ 1 file changed, 85 insertions(+) diff --git a/commands/src/test/java/com/wizardlybump17/wlib/test/command/SuggestionTests.java b/commands/src/test/java/com/wizardlybump17/wlib/test/command/SuggestionTests.java index f8230516..397affbf 100644 --- a/commands/src/test/java/com/wizardlybump17/wlib/test/command/SuggestionTests.java +++ b/commands/src/test/java/com/wizardlybump17/wlib/test/command/SuggestionTests.java @@ -2,12 +2,15 @@ import com.wizardlybump17.wlib.command.Command; import com.wizardlybump17.wlib.command.input.primitive.number.*; +import com.wizardlybump17.wlib.command.input.string.AllowedStringInputs; import com.wizardlybump17.wlib.command.node.LiteralCommandNode; import com.wizardlybump17.wlib.command.node.primitive.number.*; +import com.wizardlybump17.wlib.command.node.string.StringCommandNode; import com.wizardlybump17.wlib.command.result.CommandResult; import com.wizardlybump17.wlib.command.sender.BasicCommandSender; import com.wizardlybump17.wlib.command.sender.CommandSender; import com.wizardlybump17.wlib.command.suggestion.primitive.number.*; +import com.wizardlybump17.wlib.command.suggestion.string.StringSuggester; import org.jetbrains.annotations.NotNull; import org.junit.jupiter.api.Assertions; import org.junit.jupiter.api.DisplayName; @@ -602,5 +605,87 @@ void testDefaultSuggestions() { ) ).getSuggestions(CHAD_SENDER, List.of("hello", "10")) ); + + //String + Assertions.assertEquals( + List.of(""), + new Command( + new LiteralCommandNode( + "hello", + List.of( + new StringCommandNode( + "world", + List.of(), + AllowedStringInputs.anyNullable(), + StringSuggester.any(), + null, + null + ) + ), + null, + null + ) + ).getSuggestions(CHAD_SENDER, List.of("hello", "")) + ); + Assertions.assertEquals( + List.of("wo"), + new Command( + new LiteralCommandNode( + "hello", + List.of( + new StringCommandNode( + "world", + List.of(), + AllowedStringInputs.anyNullable(), + StringSuggester.any(), + null, + null + ) + ), + null, + null + ) + ).getSuggestions(CHAD_SENDER, List.of("hello", "wo")) + ); + Assertions.assertEquals( + List.of("spaced "), + new Command( + new LiteralCommandNode( + "hello", + List.of( + new StringCommandNode( + "world", + List.of(), + AllowedStringInputs.anyNullable(), + StringSuggester.any(), + null, + null + ) + ), + null, + null + ) + ).getSuggestions(CHAD_SENDER, List.of("hello", "spaced ")) + ); + Assertions.assertEquals( + List.of("spaced string"), + new Command( + new LiteralCommandNode( + "hello", + List.of( + new StringCommandNode( + "world", + List.of(), + AllowedStringInputs.anyNullable(), + StringSuggester.any(), + null, + null + ) + ), + null, + null + ) + ).getSuggestions(CHAD_SENDER, List.of("hello", "spaced string")) + ); } } From 85fe9bab09ce5eb149d6066517373dd11e9b70ac Mon Sep 17 00:00:00 2001 From: WizardlyBump17 Date: Sun, 14 Dec 2025 21:19:12 -0300 Subject: [PATCH 245/363] it is not needed to try parsing the input, just return all suggestions --- .../wizardlybump17/wlib/command/Command.java | 33 ++++++------------- .../wlib/test/command/SuggestionTests.java | 2 +- 2 files changed, 11 insertions(+), 24 deletions(-) diff --git a/commands/src/main/java/com/wizardlybump17/wlib/command/Command.java b/commands/src/main/java/com/wizardlybump17/wlib/command/Command.java index 55b5036b..6faa4b64 100644 --- a/commands/src/main/java/com/wizardlybump17/wlib/command/Command.java +++ b/commands/src/main/java/com/wizardlybump17/wlib/command/Command.java @@ -128,7 +128,6 @@ public Command(@NotNull LiteralCommandNode root) { List> children = List.of(root); CommandNode lastNode = null; - InputParsingException lastParsingError = null; inputLoop: for (int i = 0; i < input.size(); i++) { String inputString = input.get(i); @@ -145,35 +144,23 @@ public Command(@NotNull LiteralCommandNode root) { break; } - boolean foundNode = false; + boolean foundNode = !children.isEmpty(); for (CommandNode child : children) { lastNode = child; - try { - foundNode = true; - - child.parse(inputString); - - String permission = child.getPermission(); - if (isLastInput && (permission == null || sender.hasPermission(permission))) - suggestions.addAll(getSuggestions0(child, sender, input, currentInput)); - - lastParsingError = null; + String permission = child.getPermission(); + if (isLastInput && (permission == null || sender.hasPermission(permission))) + suggestions.addAll(getSuggestions0(child, sender, input, currentInput)); - if (isLastInput) { - continue; - } else { - children = child.getChildren(); - continue inputLoop; - } - } catch (InputParsingException e) { - lastParsingError = e; + if (isLastInput) { + continue; + } else { + children = child.getChildren(); + foundNode = !children.isEmpty(); + continue inputLoop; } } - if (lastParsingError != null) - return List.of(); - if (!foundNode) return List.of(); } diff --git a/commands/src/test/java/com/wizardlybump17/wlib/test/command/SuggestionTests.java b/commands/src/test/java/com/wizardlybump17/wlib/test/command/SuggestionTests.java index 397affbf..0a264d08 100644 --- a/commands/src/test/java/com/wizardlybump17/wlib/test/command/SuggestionTests.java +++ b/commands/src/test/java/com/wizardlybump17/wlib/test/command/SuggestionTests.java @@ -191,7 +191,7 @@ void testSuccess4() { ) ); - List expected = List.of("world", "hi", "happy"); + List expected = List.of("world", "hi", "1", "3", "5", "7", "10", "happy"); List actual = command.getSuggestions(CHAD_SENDER, List.of("hello", "h")); Assertions.assertEquals(expected, actual); From fcf438d541d00717b5b8346e5643909ca5f52898 Mon Sep 17 00:00:00 2001 From: WizardlyBump17 Date: Sun, 14 Dec 2025 21:19:34 -0300 Subject: [PATCH 246/363] testing UUIDs --- .../wlib/test/command/SuggestionTests.java | 53 +++++++++++++++++++ 1 file changed, 53 insertions(+) diff --git a/commands/src/test/java/com/wizardlybump17/wlib/test/command/SuggestionTests.java b/commands/src/test/java/com/wizardlybump17/wlib/test/command/SuggestionTests.java index 0a264d08..c522ae9d 100644 --- a/commands/src/test/java/com/wizardlybump17/wlib/test/command/SuggestionTests.java +++ b/commands/src/test/java/com/wizardlybump17/wlib/test/command/SuggestionTests.java @@ -1,14 +1,17 @@ package com.wizardlybump17.wlib.test.command; import com.wizardlybump17.wlib.command.Command; +import com.wizardlybump17.wlib.command.input.object.AllowedUUIDInputs; import com.wizardlybump17.wlib.command.input.primitive.number.*; import com.wizardlybump17.wlib.command.input.string.AllowedStringInputs; import com.wizardlybump17.wlib.command.node.LiteralCommandNode; +import com.wizardlybump17.wlib.command.node.object.UUIDCommandNode; import com.wizardlybump17.wlib.command.node.primitive.number.*; import com.wizardlybump17.wlib.command.node.string.StringCommandNode; import com.wizardlybump17.wlib.command.result.CommandResult; import com.wizardlybump17.wlib.command.sender.BasicCommandSender; import com.wizardlybump17.wlib.command.sender.CommandSender; +import com.wizardlybump17.wlib.command.suggestion.object.UUIDSuggester; import com.wizardlybump17.wlib.command.suggestion.primitive.number.*; import com.wizardlybump17.wlib.command.suggestion.string.StringSuggester; import org.jetbrains.annotations.NotNull; @@ -687,5 +690,55 @@ void testDefaultSuggestions() { ) ).getSuggestions(CHAD_SENDER, List.of("hello", "spaced string")) ); + + //UUID + Assertions.assertEquals( + List.of("9b07bd8a-a4c0-3681-997f-6b6df78c0abe", "2931e955-084c-3d9e-aea4-8e5c2c1089c1", "2931e955-084c-3d9e-aea4-8e5c2c1089c1"), + new Command( + new LiteralCommandNode( + "hello", + List.of( + new UUIDCommandNode( + "world", + List.of(), + AllowedUUIDInputs.anyNullable(), + UUIDSuggester.values( + UUID.nameUUIDFromBytes("WizardlyBump17".getBytes()), + UUID.nameUUIDFromBytes("WizardlyBump18".getBytes()), + UUID.nameUUIDFromBytes("WizardlyBump18".getBytes()) + ), + null, + null + ) + ), + null, + null + ) + ).getSuggestions(CHAD_SENDER, List.of("hello", "")) + ); + Assertions.assertEquals( + List.of("9b07bd8a-a4c0-3681-997f-6b6df78c0abe", "2931e955-084c-3d9e-aea4-8e5c2c1089c1", "2931e955-084c-3d9e-aea4-8e5c2c1089c1"), + new Command( + new LiteralCommandNode( + "hello", + List.of( + new UUIDCommandNode( + "world", + List.of(), + AllowedUUIDInputs.anyNullable(), + UUIDSuggester.values( + UUID.nameUUIDFromBytes("WizardlyBump17".getBytes()), + UUID.nameUUIDFromBytes("WizardlyBump18".getBytes()), + UUID.nameUUIDFromBytes("WizardlyBump18".getBytes()) + ), + null, + null + ) + ), + null, + null + ) + ).getSuggestions(CHAD_SENDER, List.of("hello", "9b07bd8a-a4c0")) + ); } } From 661dd1e5d0eafd6d490be907079aa4964780cdeb Mon Sep 17 00:00:00 2001 From: WizardlyBump17 Date: Sun, 14 Dec 2025 22:25:29 -0300 Subject: [PATCH 247/363] suggesting only stuff that starts with the current input --- .../com/wizardlybump17/wlib/command/WLibCommandExecutor.java | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/core/src/main/java/com/wizardlybump17/wlib/command/WLibCommandExecutor.java b/core/src/main/java/com/wizardlybump17/wlib/command/WLibCommandExecutor.java index 55b6bd8f..7ab79b08 100644 --- a/core/src/main/java/com/wizardlybump17/wlib/command/WLibCommandExecutor.java +++ b/core/src/main/java/com/wizardlybump17/wlib/command/WLibCommandExecutor.java @@ -74,9 +74,12 @@ public boolean onCommand(@NotNull CommandSender sender, @NotNull Command command wlibArgs.add(command.getName()); Collections.addAll(wlibArgs, args); + String current = args.length == 1 ? args[0] : args[args.length - 1]; + String currentLowerCase = current.toLowerCase(); + return commandManager.getSuggestions(wlibSender, wlibArgs) .stream() - .map(Object::toString) + .filter(suggestion -> suggestion.toLowerCase().startsWith(currentLowerCase)) .toList(); } } From f8dd2dd6bab30ca5d1204b569776b0aa99c3e158 Mon Sep 17 00:00:00 2001 From: WizardlyBump17 Date: Sun, 14 Dec 2025 23:33:56 -0300 Subject: [PATCH 248/363] improved the suggestions --- .../wizardlybump17/wlib/command/Command.java | 17 ++++++++++++++--- 1 file changed, 14 insertions(+), 3 deletions(-) diff --git a/commands/src/main/java/com/wizardlybump17/wlib/command/Command.java b/commands/src/main/java/com/wizardlybump17/wlib/command/Command.java index 6faa4b64..8a82e3b9 100644 --- a/commands/src/main/java/com/wizardlybump17/wlib/command/Command.java +++ b/commands/src/main/java/com/wizardlybump17/wlib/command/Command.java @@ -117,7 +117,6 @@ public Command(@NotNull LiteralCommandNode root) { return StringUtil.parseQuotedStrings(original); } - @SuppressWarnings("unchecked") public @NotNull List getSuggestions(@NotNull CommandSender sender, @NotNull List input) { if (input.isEmpty()) return List.of(root.getName()); @@ -128,6 +127,7 @@ public Command(@NotNull LiteralCommandNode root) { List> children = List.of(root); CommandNode lastNode = null; + Throwable lastError = null; inputLoop: for (int i = 0; i < input.size(); i++) { String inputString = input.get(i); @@ -148,6 +148,18 @@ public Command(@NotNull LiteralCommandNode root) { for (CommandNode child : children) { lastNode = child; + if (!isLastInput) { + try { + child.parseOrInvalid(inputString); + } catch (InputParsingException | InvalidInputException e) { + lastError = e; + foundNode = false; + continue; + } + } + + foundNode = true; + String permission = child.getPermission(); if (isLastInput && (permission == null || sender.hasPermission(permission))) suggestions.addAll(getSuggestions0(child, sender, input, currentInput)); @@ -156,12 +168,11 @@ public Command(@NotNull LiteralCommandNode root) { continue; } else { children = child.getChildren(); - foundNode = !children.isEmpty(); continue inputLoop; } } - if (!foundNode) + if (lastError != null || !foundNode) return List.of(); } From 25bf362e090cf9677d6f8cb3a8943eb36396a6e1 Mon Sep 17 00:00:00 2001 From: WizardlyBump17 Date: Sun, 14 Dec 2025 23:34:08 -0300 Subject: [PATCH 249/363] using a LinkedHashMap --- .../com/wizardlybump17/wlib/command/context/CommandContext.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/commands/src/main/java/com/wizardlybump17/wlib/command/context/CommandContext.java b/commands/src/main/java/com/wizardlybump17/wlib/command/context/CommandContext.java index ec88f63e..a834b3aa 100644 --- a/commands/src/main/java/com/wizardlybump17/wlib/command/context/CommandContext.java +++ b/commands/src/main/java/com/wizardlybump17/wlib/command/context/CommandContext.java @@ -19,7 +19,7 @@ public static final class CommandNodeArguments { private final @NotNull @Unmodifiable Map> arguments; public CommandNodeArguments(@NotNull List> arguments) { - Map> argumentsMap = new HashMap<>(); + Map> argumentsMap = new LinkedHashMap<>(); for (CommandNodeArgument argument : arguments) argumentsMap.put(argument.node().getName(), argument); this.arguments = Map.copyOf(argumentsMap); From 667005874e109fb65cd8963762a013b08550cfa3 Mon Sep 17 00:00:00 2001 From: WizardlyBump17 Date: Sun, 14 Dec 2025 23:40:36 -0300 Subject: [PATCH 250/363] clearing the last error --- .../src/main/java/com/wizardlybump17/wlib/command/Command.java | 1 + 1 file changed, 1 insertion(+) diff --git a/commands/src/main/java/com/wizardlybump17/wlib/command/Command.java b/commands/src/main/java/com/wizardlybump17/wlib/command/Command.java index 8a82e3b9..d64da2f3 100644 --- a/commands/src/main/java/com/wizardlybump17/wlib/command/Command.java +++ b/commands/src/main/java/com/wizardlybump17/wlib/command/Command.java @@ -158,6 +158,7 @@ public Command(@NotNull LiteralCommandNode root) { } } + lastError = null; foundNode = true; String permission = child.getPermission(); From d0e787f785b78798a9b3f0ae440cc024eb22c16e Mon Sep 17 00:00:00 2001 From: WizardlyBump17 Date: Mon, 15 Dec 2025 00:01:46 -0300 Subject: [PATCH 251/363] added support to create commands using the Command from Bukkit --- .../wlib/command/WLibCommandExecutor.java | 3 +- .../wlib/command/bukkit/BukkitCommand.java | 19 +++++++ .../command/bukkit/InternalBukkitCommand.java | 51 +++++++++++++++++++ .../BukkitCommandManagerListener.java | 38 ++++++++++---- 4 files changed, 99 insertions(+), 12 deletions(-) create mode 100644 core/src/main/java/com/wizardlybump17/wlib/command/bukkit/BukkitCommand.java create mode 100644 core/src/main/java/com/wizardlybump17/wlib/command/bukkit/InternalBukkitCommand.java diff --git a/core/src/main/java/com/wizardlybump17/wlib/command/WLibCommandExecutor.java b/core/src/main/java/com/wizardlybump17/wlib/command/WLibCommandExecutor.java index 7ab79b08..c3e91f3d 100644 --- a/core/src/main/java/com/wizardlybump17/wlib/command/WLibCommandExecutor.java +++ b/core/src/main/java/com/wizardlybump17/wlib/command/WLibCommandExecutor.java @@ -10,7 +10,6 @@ import org.bukkit.command.CommandSender; import org.bukkit.command.TabCompleter; import org.jetbrains.annotations.NotNull; -import org.jetbrains.annotations.Nullable; import java.util.ArrayList; import java.util.Collections; @@ -67,7 +66,7 @@ public boolean onCommand(@NotNull CommandSender sender, @NotNull Command command } @Override - public @Nullable List onTabComplete(@NotNull CommandSender sender, @NotNull Command command, @NotNull String label, @NotNull String[] args) { + public @NotNull List onTabComplete(@NotNull CommandSender sender, @NotNull Command command, @NotNull String label, @NotNull String[] args) { com.wizardlybump17.wlib.command.sender.CommandSender wlibSender = new BukkitCommandSender(sender); List wlibArgs = new ArrayList<>(); diff --git a/core/src/main/java/com/wizardlybump17/wlib/command/bukkit/BukkitCommand.java b/core/src/main/java/com/wizardlybump17/wlib/command/bukkit/BukkitCommand.java new file mode 100644 index 00000000..029e9aba --- /dev/null +++ b/core/src/main/java/com/wizardlybump17/wlib/command/bukkit/BukkitCommand.java @@ -0,0 +1,19 @@ +package com.wizardlybump17.wlib.command.bukkit; + +import com.wizardlybump17.wlib.command.Command; +import com.wizardlybump17.wlib.command.node.LiteralCommandNode; +import org.jetbrains.annotations.NotNull; + +public class BukkitCommand extends Command { + + private final @NotNull InternalBukkitCommand internalCommand; + + public BukkitCommand(@NotNull LiteralCommandNode root) { + super(root); + internalCommand = new InternalBukkitCommand(this); + } + + public @NotNull InternalBukkitCommand getInternalCommand() { + return internalCommand; + } +} diff --git a/core/src/main/java/com/wizardlybump17/wlib/command/bukkit/InternalBukkitCommand.java b/core/src/main/java/com/wizardlybump17/wlib/command/bukkit/InternalBukkitCommand.java new file mode 100644 index 00000000..c11ba911 --- /dev/null +++ b/core/src/main/java/com/wizardlybump17/wlib/command/bukkit/InternalBukkitCommand.java @@ -0,0 +1,51 @@ +package com.wizardlybump17.wlib.command.bukkit; + +import com.wizardlybump17.wlib.command.WLibCommandExecutor; +import org.bukkit.Location; +import org.bukkit.command.Command; +import org.bukkit.command.CommandSender; +import org.jetbrains.annotations.ApiStatus; +import org.jetbrains.annotations.NotNull; +import org.jetbrains.annotations.Nullable; + +import java.util.List; + +@ApiStatus.Internal +public class InternalBukkitCommand extends Command { + + private final @NotNull BukkitCommand command; + private WLibCommandExecutor executor; + + public InternalBukkitCommand(@NotNull BukkitCommand command) { + super(command.getName()); + this.command = command; + } + + @Override + public boolean execute(@NotNull CommandSender sender, @NotNull String commandLabel, @NotNull String[] args) { + if (executor == null) + return false; + + executor.onCommand(sender, this, commandLabel, args); + return false; + } + + @Override + public @NotNull List tabComplete(@NotNull CommandSender sender, @NotNull String alias, @NotNull String[] args, @Nullable Location location) throws IllegalArgumentException { + if (executor == null) + return List.of(); + return executor.onTabComplete(sender, this, alias, args); + } + + public @NotNull BukkitCommand getCommand() { + return command; + } + + public WLibCommandExecutor getExecutor() { + return executor; + } + + public void setExecutor(WLibCommandExecutor executor) { + this.executor = executor; + } +} diff --git a/core/src/main/java/com/wizardlybump17/wlib/command/listener/BukkitCommandManagerListener.java b/core/src/main/java/com/wizardlybump17/wlib/command/listener/BukkitCommandManagerListener.java index 3d67865e..7dd661aa 100644 --- a/core/src/main/java/com/wizardlybump17/wlib/command/listener/BukkitCommandManagerListener.java +++ b/core/src/main/java/com/wizardlybump17/wlib/command/listener/BukkitCommandManagerListener.java @@ -2,13 +2,17 @@ import com.wizardlybump17.wlib.command.Command; import com.wizardlybump17.wlib.command.WLibCommandExecutor; +import com.wizardlybump17.wlib.command.bukkit.BukkitCommand; +import com.wizardlybump17.wlib.command.bukkit.InternalBukkitCommand; import com.wizardlybump17.wlib.command.manager.CommandManager; import com.wizardlybump17.wlib.command.manager.listener.CommandManagerListener; +import org.bukkit.Bukkit; import org.bukkit.command.PluginCommand; import org.bukkit.plugin.java.JavaPlugin; import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.Nullable; +import java.util.Map; import java.util.logging.Level; public class BukkitCommandManagerListener implements CommandManagerListener { @@ -24,13 +28,20 @@ public void onRegister(@NotNull String identifier, @NotNull Command command, @Nu if (!(holder instanceof JavaPlugin plugin)) return; - PluginCommand pluginCommand = plugin.getCommand(command.getName()); - if (pluginCommand == null) { - plugin.getLogger().log(Level.WARNING, "Command not found on plugin.yml while trying to register it to WLib: " + command.getName()); - return; - } + if (command instanceof BukkitCommand bukkitCommand) { + InternalBukkitCommand internalCommand = bukkitCommand.getInternalCommand(); + internalCommand.setExecutor(commandExecutor); - pluginCommand.setExecutor(commandExecutor); + Bukkit.getCommandMap().register(command.getName(), identifier, internalCommand); + } else { + PluginCommand pluginCommand = plugin.getCommand(command.getName()); + if (pluginCommand == null) { + plugin.getLogger().log(Level.WARNING, "Command not found on plugin.yml while trying to register it to WLib: " + command.getName()); + return; + } + + pluginCommand.setExecutor(commandExecutor); + } } @Override @@ -42,11 +53,18 @@ public void onUnregister(@NotNull String identifier, @NotNull Command command, @ if (!(holder instanceof JavaPlugin plugin)) return; - PluginCommand pluginCommand = plugin.getCommand(command.getName()); - if (pluginCommand == null) - return; + if (command instanceof BukkitCommand bukkitCommand) { + bukkitCommand.getInternalCommand().setExecutor(null); + + Map knownCommands = Bukkit.getCommandMap().getKnownCommands(); + knownCommands.remove(identifier + CommandManager.SEPARATOR + command.getName()); + } else { + PluginCommand pluginCommand = plugin.getCommand(command.getName()); + if (pluginCommand == null) + return; - pluginCommand.setExecutor(null); + pluginCommand.setExecutor(null); + } } public @NotNull WLibCommandExecutor getCommandExecutor() { From f9c677e40954a5f2314a74769845100f95c562ae Mon Sep 17 00:00:00 2001 From: WizardlyBump17 Date: Mon, 15 Dec 2025 00:15:37 -0300 Subject: [PATCH 252/363] removing the command by name too --- .../wlib/command/listener/BukkitCommandManagerListener.java | 1 + 1 file changed, 1 insertion(+) diff --git a/core/src/main/java/com/wizardlybump17/wlib/command/listener/BukkitCommandManagerListener.java b/core/src/main/java/com/wizardlybump17/wlib/command/listener/BukkitCommandManagerListener.java index 7dd661aa..1b34adb2 100644 --- a/core/src/main/java/com/wizardlybump17/wlib/command/listener/BukkitCommandManagerListener.java +++ b/core/src/main/java/com/wizardlybump17/wlib/command/listener/BukkitCommandManagerListener.java @@ -58,6 +58,7 @@ public void onUnregister(@NotNull String identifier, @NotNull Command command, @ Map knownCommands = Bukkit.getCommandMap().getKnownCommands(); knownCommands.remove(identifier + CommandManager.SEPARATOR + command.getName()); + knownCommands.remove(command.getName()); } else { PluginCommand pluginCommand = plugin.getCommand(command.getName()); if (pluginCommand == null) From 12f1a7a0778a333c0ab10f13219dd68e01acc6ca Mon Sep 17 00:00:00 2001 From: WizardlyBump17 Date: Mon, 15 Dec 2025 11:10:51 -0300 Subject: [PATCH 253/363] private constructors --- .../command/suggestion/primitive/BooleanSuggester.java | 9 +++++++++ .../wlib/command/suggestion/OfflinePlayerSuggester.java | 6 ++++++ 2 files changed, 15 insertions(+) diff --git a/commands/src/main/java/com/wizardlybump17/wlib/command/suggestion/primitive/BooleanSuggester.java b/commands/src/main/java/com/wizardlybump17/wlib/command/suggestion/primitive/BooleanSuggester.java index 1bbbdac2..e79cd8d6 100644 --- a/commands/src/main/java/com/wizardlybump17/wlib/command/suggestion/primitive/BooleanSuggester.java +++ b/commands/src/main/java/com/wizardlybump17/wlib/command/suggestion/primitive/BooleanSuggester.java @@ -25,6 +25,9 @@ final class True implements BooleanSuggester { private static final @NotNull List LIST = List.of(true); private static final @NotNull True INSTANCE = new True(); + private True() { + } + @Override public @NotNull List getSuggestions(@NotNull CommandSender sender, @NotNull List input, @NotNull String current, @NotNull CommandNode currentNode) { return LIST; @@ -41,6 +44,9 @@ final class False implements BooleanSuggester { private static final @NotNull List LIST = List.of(false); private static final @NotNull False INSTANCE = new False(); + private False() { + } + @Override public @NotNull List getSuggestions(@NotNull CommandSender sender, @NotNull List input, @NotNull String current, @NotNull CommandNode currentNode) { return LIST; @@ -57,6 +63,9 @@ final class Any implements BooleanSuggester { private static final @NotNull List LIST = List.of(true, false); private static final @NotNull Any INSTANCE = new Any(); + private Any() { + } + @Override public @NotNull List getSuggestions(@NotNull CommandSender sender, @NotNull List input, @NotNull String current, @NotNull CommandNode currentNode) { return LIST; diff --git a/core/src/main/java/com/wizardlybump17/wlib/command/suggestion/OfflinePlayerSuggester.java b/core/src/main/java/com/wizardlybump17/wlib/command/suggestion/OfflinePlayerSuggester.java index d12199fc..5fe61e6a 100644 --- a/core/src/main/java/com/wizardlybump17/wlib/command/suggestion/OfflinePlayerSuggester.java +++ b/core/src/main/java/com/wizardlybump17/wlib/command/suggestion/OfflinePlayerSuggester.java @@ -28,6 +28,9 @@ final class Online implements OfflinePlayerSuggester { private static final @NotNull Online INSTANCE = new Online(); + private Online() { + } + @Override public @NotNull List getSuggestions(@NotNull CommandSender sender, @NotNull List input, @NotNull String current, @NotNull CommandNode currentNode) { return Bukkit.getOnlinePlayers() @@ -41,6 +44,9 @@ final class Cached implements OfflinePlayerSuggester { private static final @NotNull Cached INSTANCE = new Cached(); + private Cached() { + } + @Override public @NotNull List getSuggestions(@NotNull CommandSender sender, @NotNull List input, @NotNull String current, @NotNull CommandNode currentNode) { return List.of(Bukkit.getOfflinePlayers()); From 0753e28570ef7e2653b3d71d2d503ef0c68ebd03 Mon Sep 17 00:00:00 2001 From: WizardlyBump17 Date: Mon, 15 Dec 2025 11:31:26 -0300 Subject: [PATCH 254/363] requiring an AllowedOfflinePlayerInputs --- .../wlib/command/node/OfflinePlayerCommandNode.java | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/core/src/main/java/com/wizardlybump17/wlib/command/node/OfflinePlayerCommandNode.java b/core/src/main/java/com/wizardlybump17/wlib/command/node/OfflinePlayerCommandNode.java index 5a2a4a4f..eeea12f5 100644 --- a/core/src/main/java/com/wizardlybump17/wlib/command/node/OfflinePlayerCommandNode.java +++ b/core/src/main/java/com/wizardlybump17/wlib/command/node/OfflinePlayerCommandNode.java @@ -2,7 +2,6 @@ import com.wizardlybump17.wlib.command.exception.InputParsingException; import com.wizardlybump17.wlib.command.executor.CommandNodeExecutor; -import com.wizardlybump17.wlib.command.input.AllowedInputs; import com.wizardlybump17.wlib.command.input.AllowedOfflinePlayerInputs; import com.wizardlybump17.wlib.command.suggestion.OfflinePlayerSuggester; import org.bukkit.Bukkit; @@ -16,7 +15,7 @@ public class OfflinePlayerCommandNode extends CommandNode { - public OfflinePlayerCommandNode(@NotNull String name, @NotNull @Unmodifiable List> children, @NotNull AllowedInputs allowedInputs, @Nullable OfflinePlayerSuggester suggester, @Nullable CommandNodeExecutor executor, @Nullable String permission) { + public OfflinePlayerCommandNode(@NotNull String name, @NotNull @Unmodifiable List> children, @NotNull AllowedOfflinePlayerInputs allowedInputs, @Nullable OfflinePlayerSuggester suggester, @Nullable CommandNodeExecutor executor, @Nullable String permission) { super(name, children, allowedInputs, suggester, executor, permission); } From 7d7e741b6a50e471860fba8eeae47616bf309475 Mon Sep 17 00:00:00 2001 From: WizardlyBump17 Date: Mon, 15 Dec 2025 11:36:15 -0300 Subject: [PATCH 255/363] accepting Players too --- .../method/factory/OfflinePlayerMethodCommandNodeFactory.java | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/core/src/main/java/com/wizardlybump17/wlib/command/extractor/method/factory/OfflinePlayerMethodCommandNodeFactory.java b/core/src/main/java/com/wizardlybump17/wlib/command/extractor/method/factory/OfflinePlayerMethodCommandNodeFactory.java index dd61a6cc..54d604ec 100644 --- a/core/src/main/java/com/wizardlybump17/wlib/command/extractor/method/factory/OfflinePlayerMethodCommandNodeFactory.java +++ b/core/src/main/java/com/wizardlybump17/wlib/command/extractor/method/factory/OfflinePlayerMethodCommandNodeFactory.java @@ -6,6 +6,7 @@ import com.wizardlybump17.wlib.command.node.OfflinePlayerCommandNode; import com.wizardlybump17.wlib.command.suggestion.OfflinePlayerSuggester; import org.bukkit.OfflinePlayer; +import org.bukkit.entity.Player; import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.Nullable; @@ -29,7 +30,7 @@ public class OfflinePlayerMethodCommandNodeFactory extends MethodCommandNodeFact @Override public @NotNull Class @NotNull [] getSupportedTypes() { - return new Class[] {OfflinePlayer.class}; + return new Class[] {OfflinePlayer.class, Player.class}; } @Override From 51a359ac5a5a8f4ed09bc36a6bdf2ea817546fe4 Mon Sep 17 00:00:00 2001 From: WizardlyBump17 Date: Mon, 15 Dec 2025 11:38:21 -0300 Subject: [PATCH 256/363] added support for Players --- .../java/com/wizardlybump17/wlib/WLib.java | 2 + .../PlayerMethodCommandNodeFactory.java | 39 +++++ .../command/input/AllowedPlayerInputs.java | 136 ++++++++++++++++++ .../wlib/command/node/PlayerCommandNode.java | 67 +++++++++ .../command/suggestion/PlayerSuggester.java | 40 ++++++ 5 files changed, 284 insertions(+) create mode 100644 core/src/main/java/com/wizardlybump17/wlib/command/extractor/method/factory/PlayerMethodCommandNodeFactory.java create mode 100644 core/src/main/java/com/wizardlybump17/wlib/command/input/AllowedPlayerInputs.java create mode 100644 core/src/main/java/com/wizardlybump17/wlib/command/node/PlayerCommandNode.java create mode 100644 core/src/main/java/com/wizardlybump17/wlib/command/suggestion/PlayerSuggester.java diff --git a/core/src/main/java/com/wizardlybump17/wlib/WLib.java b/core/src/main/java/com/wizardlybump17/wlib/WLib.java index fbb3fda1..8324aeba 100644 --- a/core/src/main/java/com/wizardlybump17/wlib/WLib.java +++ b/core/src/main/java/com/wizardlybump17/wlib/WLib.java @@ -7,6 +7,7 @@ import com.wizardlybump17.wlib.command.WLibCommandExecutor; import com.wizardlybump17.wlib.command.extractor.method.MethodCommandExtractor; import com.wizardlybump17.wlib.command.extractor.method.factory.OfflinePlayerMethodCommandNodeFactory; +import com.wizardlybump17.wlib.command.extractor.method.factory.PlayerMethodCommandNodeFactory; import com.wizardlybump17.wlib.command.listener.BukkitCommandManagerListener; import com.wizardlybump17.wlib.command.manager.CommandManager; import com.wizardlybump17.wlib.command.registry.MethodCommandNodeFactoryRegistry; @@ -68,6 +69,7 @@ private void initCommandSystem() { methodCommandNodeFactoryRegistry.registerDefaults(); methodCommandNodeFactoryRegistry.addFactory(new OfflinePlayerMethodCommandNodeFactory()); + methodCommandNodeFactoryRegistry.addFactory(new PlayerMethodCommandNodeFactory()); commandManager = new CommandManager(); diff --git a/core/src/main/java/com/wizardlybump17/wlib/command/extractor/method/factory/PlayerMethodCommandNodeFactory.java b/core/src/main/java/com/wizardlybump17/wlib/command/extractor/method/factory/PlayerMethodCommandNodeFactory.java new file mode 100644 index 00000000..c3c4cc2b --- /dev/null +++ b/core/src/main/java/com/wizardlybump17/wlib/command/extractor/method/factory/PlayerMethodCommandNodeFactory.java @@ -0,0 +1,39 @@ +package com.wizardlybump17.wlib.command.extractor.method.factory; + +import com.wizardlybump17.wlib.command.annotation.Command; +import com.wizardlybump17.wlib.command.input.AllowedPlayerInputs; +import com.wizardlybump17.wlib.command.node.CommandNode; +import com.wizardlybump17.wlib.command.node.PlayerCommandNode; +import com.wizardlybump17.wlib.command.suggestion.PlayerSuggester; +import org.bukkit.entity.Player; +import org.jetbrains.annotations.NotNull; +import org.jetbrains.annotations.Nullable; + +import java.lang.reflect.Method; +import java.lang.reflect.Parameter; +import java.util.List; + +public class PlayerMethodCommandNodeFactory extends MethodCommandNodeFactory { + + @Override + public @NotNull CommandNode create(@NotNull Object object, @NotNull Method method, @NotNull Command commandAnnotation, @NotNull Parameter parameter, @NotNull String name, @Nullable CommandNode root) { + return new PlayerCommandNode( + name, + root == null ? List.of() : List.of(root), + parameter.isAnnotationPresent(NotNull.class) ? AllowedPlayerInputs.anyNotNull() : AllowedPlayerInputs.anyNullable(), + PlayerSuggester.online(), + null, + null + ); + } + + @Override + public @NotNull Class @NotNull [] getSupportedTypes() { + return new Class[] {Player.class}; + } + + @Override + public boolean isStrict() { + return false; + } +} diff --git a/core/src/main/java/com/wizardlybump17/wlib/command/input/AllowedPlayerInputs.java b/core/src/main/java/com/wizardlybump17/wlib/command/input/AllowedPlayerInputs.java new file mode 100644 index 00000000..1f1a281a --- /dev/null +++ b/core/src/main/java/com/wizardlybump17/wlib/command/input/AllowedPlayerInputs.java @@ -0,0 +1,136 @@ +package com.wizardlybump17.wlib.command.input; + +import org.bukkit.entity.Player; +import org.jetbrains.annotations.NotNull; +import org.jetbrains.annotations.Nullable; + +import java.util.List; +import java.util.Objects; + +public interface AllowedPlayerInputs extends AllowedInputs { + + static @NotNull AllowedPlayerInputs.Value value(@NotNull Player value) { + return new AllowedPlayerInputs.Value(value); + } + + static @NotNull AllowedPlayerInputs.Values values(@NotNull List values) { + return new AllowedPlayerInputs.Values(List.copyOf(values)); + } + + static @NotNull AllowedPlayerInputs.Values values(@NotNull Player @NotNull ... values) { + return new AllowedPlayerInputs.Values(List.of(values)); + } + + static @NotNull AllowedPlayerInputs.Any anyNullable() { + return AllowedPlayerInputs.Any.NULLABLE; + } + + static @NotNull AllowedPlayerInputs.Any anyNotNull() { + return AllowedPlayerInputs.Any.NOT_NULL; + } + + final class Value implements AllowedPlayerInputs, SingleValueInput { + + private final @NotNull Player value; + + Value(@NotNull Player value) { + this.value = value; + } + + @Override + public @NotNull Player value() { + return value; + } + + @Override + public boolean equals(Object object) { + if (object == null || getClass() != object.getClass()) + return false; + Value value1 = (Value) object; + return Objects.equals(value, value1.value); + } + + @Override + public int hashCode() { + return Objects.hashCode(value); + } + + @Override + public String toString() { + return "AllowedPlayerInputs$Value{" + + "value=" + value + + '}'; + } + } + + final class Values implements AllowedPlayerInputs, AllowedListInputs { + + private final @NotNull List values; + + private Values(@NotNull List values) { + this.values = values; + } + + @Override + public @NotNull List allowedValues() { + return values; + } + + @Override + public boolean equals(Object object) { + if (object == null || getClass() != object.getClass()) + return false; + Values values1 = (Values) object; + return Objects.equals(values, values1.values); + } + + @Override + public int hashCode() { + return Objects.hashCode(values); + } + + @Override + public String toString() { + return "AllowedPlayerInputs$Values{" + + "values=" + values + + '}'; + } + } + + final class Any implements AllowedPlayerInputs { + + private static final @NotNull Any NULLABLE = new Any(true); + private static final @NotNull Any NOT_NULL = new Any(false); + + private final boolean nullable; + + private Any(boolean nullable) { + this.nullable = nullable; + } + + @Override + public boolean isAllowed(@Nullable Player input) { + return nullable || input != null; + } + + @Override + public boolean equals(Object object) { + if (object == null || getClass() != object.getClass()) + return false; + Any any = (Any) object; + return nullable == any.nullable; + } + + @Override + public int hashCode() { + return Objects.hashCode(nullable); + } + + @Override + public String toString() { + return "AllowedPlayerInputs$Any{" + + "nullable=" + nullable + + '}'; + } + } +} diff --git a/core/src/main/java/com/wizardlybump17/wlib/command/node/PlayerCommandNode.java b/core/src/main/java/com/wizardlybump17/wlib/command/node/PlayerCommandNode.java new file mode 100644 index 00000000..b92014b0 --- /dev/null +++ b/core/src/main/java/com/wizardlybump17/wlib/command/node/PlayerCommandNode.java @@ -0,0 +1,67 @@ +package com.wizardlybump17.wlib.command.node; + +import com.wizardlybump17.wlib.command.exception.InputParsingException; +import com.wizardlybump17.wlib.command.executor.CommandNodeExecutor; +import com.wizardlybump17.wlib.command.input.AllowedInputs; +import com.wizardlybump17.wlib.command.input.AllowedPlayerInputs; +import com.wizardlybump17.wlib.command.suggestion.PlayerSuggester; +import org.bukkit.Bukkit; +import org.bukkit.entity.Player; +import org.jetbrains.annotations.NotNull; +import org.jetbrains.annotations.Nullable; +import org.jetbrains.annotations.Unmodifiable; + +import java.util.List; +import java.util.UUID; + +public class PlayerCommandNode extends CommandNode { + + public PlayerCommandNode(@NotNull String name, @NotNull @Unmodifiable List> children, @NotNull AllowedInputs allowedInputs, @Nullable PlayerSuggester suggester, @Nullable CommandNodeExecutor executor, @Nullable String permission) { + super(name, children, allowedInputs, suggester, executor, permission); + } + + @Override + public @Nullable Player parse(@Nullable String input) throws InputParsingException { + if (input == null) + throw new InputParsingException("The input cannot be null"); + + Player player = Bukkit.getPlayerExact(input); + if (player != null) + return player; + + if (input.length() == 36) { + try { + return Bukkit.getPlayer(UUID.fromString(input)); + } catch (IllegalArgumentException e) { + throw new InputParsingException("Could not parse as UUID to get an Player: " + input, e); + } + } + + return null; + } + + @Override + public @NotNull AllowedPlayerInputs getAllowedInputs() { + return (AllowedPlayerInputs) super.getAllowedInputs(); + } + + @Override + public @Nullable PlayerSuggester getSuggester() { + return (PlayerSuggester) super.getSuggester(); + } + + @Override + public @NotNull PlayerCommandNode withChildren(@NotNull List> children) { + return new PlayerCommandNode(getName(), children, getAllowedInputs(), getSuggester(), getExecutor(), getPermission()); + } + + @Override + public @NotNull PlayerCommandNode withExecutor(@Nullable CommandNodeExecutor executor) { + return new PlayerCommandNode(getName(), getChildren(), getAllowedInputs(), getSuggester(), executor, getPermission()); + } + + @Override + public @NotNull PlayerCommandNode withPermission(@Nullable String permission) { + return new PlayerCommandNode(getName(), getChildren(), getAllowedInputs(), getSuggester(), getExecutor(), permission); + } +} diff --git a/core/src/main/java/com/wizardlybump17/wlib/command/suggestion/PlayerSuggester.java b/core/src/main/java/com/wizardlybump17/wlib/command/suggestion/PlayerSuggester.java new file mode 100644 index 00000000..db9c608c --- /dev/null +++ b/core/src/main/java/com/wizardlybump17/wlib/command/suggestion/PlayerSuggester.java @@ -0,0 +1,40 @@ +package com.wizardlybump17.wlib.command.suggestion; + +import com.wizardlybump17.wlib.command.node.CommandNode; +import com.wizardlybump17.wlib.command.sender.CommandSender; +import org.bukkit.Bukkit; +import org.bukkit.entity.Player; +import org.jetbrains.annotations.NotNull; + +import java.util.ArrayList; +import java.util.List; + +public interface PlayerSuggester extends Suggester { + + @Override + default @NotNull String getStringRepresentation(@NotNull Player value) { + return value.getName(); + } + + static @NotNull Online online() { + return Online.INSTANCE; + } + + final class Online implements PlayerSuggester { + + private static final @NotNull Online INSTANCE = new Online(); + + private Online() { + } + + @Override + public @NotNull List getSuggestions(@NotNull CommandSender sender, @NotNull List input, @NotNull String current, @NotNull CommandNode currentNode) { + return new ArrayList<>(Bukkit.getOnlinePlayers()); + } + + @Override + public String toString() { + return "PlayerSuggester$Online{}"; + } + } +} From d3195db884cad4e1d184d5f4ca174e849ccc1500 Mon Sep 17 00:00:00 2001 From: WizardlyBump17 Date: Mon, 15 Dec 2025 12:22:18 -0300 Subject: [PATCH 257/363] requiring an AllowedPlayerInputs --- .../wizardlybump17/wlib/command/node/PlayerCommandNode.java | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/core/src/main/java/com/wizardlybump17/wlib/command/node/PlayerCommandNode.java b/core/src/main/java/com/wizardlybump17/wlib/command/node/PlayerCommandNode.java index b92014b0..417905e5 100644 --- a/core/src/main/java/com/wizardlybump17/wlib/command/node/PlayerCommandNode.java +++ b/core/src/main/java/com/wizardlybump17/wlib/command/node/PlayerCommandNode.java @@ -2,7 +2,6 @@ import com.wizardlybump17.wlib.command.exception.InputParsingException; import com.wizardlybump17.wlib.command.executor.CommandNodeExecutor; -import com.wizardlybump17.wlib.command.input.AllowedInputs; import com.wizardlybump17.wlib.command.input.AllowedPlayerInputs; import com.wizardlybump17.wlib.command.suggestion.PlayerSuggester; import org.bukkit.Bukkit; @@ -16,7 +15,7 @@ public class PlayerCommandNode extends CommandNode { - public PlayerCommandNode(@NotNull String name, @NotNull @Unmodifiable List> children, @NotNull AllowedInputs allowedInputs, @Nullable PlayerSuggester suggester, @Nullable CommandNodeExecutor executor, @Nullable String permission) { + public PlayerCommandNode(@NotNull String name, @NotNull @Unmodifiable List> children, @NotNull AllowedPlayerInputs allowedInputs, @Nullable PlayerSuggester suggester, @Nullable CommandNodeExecutor executor, @Nullable String permission) { super(name, children, allowedInputs, suggester, executor, permission); } From 92f5bfc50dfed08936f85620761661a946927417 Mon Sep 17 00:00:00 2001 From: WizardlyBump17 Date: Mon, 15 Dec 2025 12:54:02 -0300 Subject: [PATCH 258/363] Collections.unmodifiableMap(Map) --- .../com/wizardlybump17/wlib/command/context/CommandContext.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/commands/src/main/java/com/wizardlybump17/wlib/command/context/CommandContext.java b/commands/src/main/java/com/wizardlybump17/wlib/command/context/CommandContext.java index a834b3aa..0a74caec 100644 --- a/commands/src/main/java/com/wizardlybump17/wlib/command/context/CommandContext.java +++ b/commands/src/main/java/com/wizardlybump17/wlib/command/context/CommandContext.java @@ -22,7 +22,7 @@ public CommandNodeArguments(@NotNull List> arguments) { Map> argumentsMap = new LinkedHashMap<>(); for (CommandNodeArgument argument : arguments) argumentsMap.put(argument.node().getName(), argument); - this.arguments = Map.copyOf(argumentsMap); + this.arguments = Collections.unmodifiableMap(argumentsMap); } public boolean hasArgument(@NotNull String key) { From f68a53bf84e5b145b87090dc0265f61e0b166d58 Mon Sep 17 00:00:00 2001 From: WizardlyBump17 Date: Mon, 15 Dec 2025 12:57:13 -0300 Subject: [PATCH 259/363] added the CommandManager#getHoldersByFullName() method --- .../wizardlybump17/wlib/command/manager/CommandManager.java | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/commands/src/main/java/com/wizardlybump17/wlib/command/manager/CommandManager.java b/commands/src/main/java/com/wizardlybump17/wlib/command/manager/CommandManager.java index fda360e6..38d04513 100644 --- a/commands/src/main/java/com/wizardlybump17/wlib/command/manager/CommandManager.java +++ b/commands/src/main/java/com/wizardlybump17/wlib/command/manager/CommandManager.java @@ -166,6 +166,10 @@ public void clear() { return Collections.unmodifiableSet(commandsByHolder.getOrDefault(holder, Set.of())); } + public @NotNull @UnmodifiableView Map getHoldersByFullName() { + return Collections.unmodifiableMap(holdersByFullName); + } + public void addListener(@NotNull CommandManagerListener listener) { listeners.add(listener); } From b5a42390c55a319a26e5daaa3196ea395d1a6d68 Mon Sep 17 00:00:00 2001 From: WizardlyBump17 Date: Mon, 15 Dec 2025 12:57:27 -0300 Subject: [PATCH 260/363] clearing the holdersByFullName too --- .../com/wizardlybump17/wlib/command/manager/CommandManager.java | 2 ++ 1 file changed, 2 insertions(+) diff --git a/commands/src/main/java/com/wizardlybump17/wlib/command/manager/CommandManager.java b/commands/src/main/java/com/wizardlybump17/wlib/command/manager/CommandManager.java index 38d04513..0a77eb86 100644 --- a/commands/src/main/java/com/wizardlybump17/wlib/command/manager/CommandManager.java +++ b/commands/src/main/java/com/wizardlybump17/wlib/command/manager/CommandManager.java @@ -146,6 +146,8 @@ public void clear() { commandsByHolder.forEach((holder, commands) -> commands.clear()); commandsByHolder.clear(); + holdersByFullName.clear(); + for (CommandManagerListener listener : listeners) listener.onClear(this); } From 2c971c28e9f7d43a14f13cb50533cf1154b1b67b Mon Sep 17 00:00:00 2001 From: WizardlyBump17 Date: Mon, 15 Dec 2025 12:57:51 -0300 Subject: [PATCH 261/363] listening the pre and post clear --- .../wlib/command/manager/CommandManager.java | 5 ++- .../listener/CommandManagerListener.java | 4 +- .../listener/CommandManagerListenerTests.java | 42 +++++++++++++++---- .../BukkitCommandManagerListener.java | 6 +++ 4 files changed, 48 insertions(+), 9 deletions(-) diff --git a/commands/src/main/java/com/wizardlybump17/wlib/command/manager/CommandManager.java b/commands/src/main/java/com/wizardlybump17/wlib/command/manager/CommandManager.java index 0a77eb86..74a719f5 100644 --- a/commands/src/main/java/com/wizardlybump17/wlib/command/manager/CommandManager.java +++ b/commands/src/main/java/com/wizardlybump17/wlib/command/manager/CommandManager.java @@ -140,6 +140,9 @@ protected void addCommand(@NotNull String identifier, @NotNull String name, @Not } public void clear() { + for (CommandManagerListener listener : listeners) + listener.onPreClear(this); + commandsByName.clear(); commandsByFullName.clear(); @@ -149,7 +152,7 @@ public void clear() { holdersByFullName.clear(); for (CommandManagerListener listener : listeners) - listener.onClear(this); + listener.onPostClear(this); } public @NotNull @UnmodifiableView Map getCommandsByFullName() { diff --git a/commands/src/main/java/com/wizardlybump17/wlib/command/manager/listener/CommandManagerListener.java b/commands/src/main/java/com/wizardlybump17/wlib/command/manager/listener/CommandManagerListener.java index 82de9cb0..a0d3974e 100644 --- a/commands/src/main/java/com/wizardlybump17/wlib/command/manager/listener/CommandManagerListener.java +++ b/commands/src/main/java/com/wizardlybump17/wlib/command/manager/listener/CommandManagerListener.java @@ -9,7 +9,9 @@ public interface CommandManagerListener { void onRegister(@NotNull String identifier, @NotNull Command command, @Nullable Object holder, @NotNull CommandManager manager); - void onClear(@NotNull CommandManager manager); + void onPreClear(@NotNull CommandManager manager); + + void onPostClear(@NotNull CommandManager manager); void onUnregister(@NotNull String identifier, @NotNull Command command, @Nullable Object holder, @NotNull CommandManager manager); } diff --git a/commands/src/test/java/com/wizardlybump17/wlib/test/command/manager/listener/CommandManagerListenerTests.java b/commands/src/test/java/com/wizardlybump17/wlib/test/command/manager/listener/CommandManagerListenerTests.java index f64a94a5..e04c7055 100644 --- a/commands/src/test/java/com/wizardlybump17/wlib/test/command/manager/listener/CommandManagerListenerTests.java +++ b/commands/src/test/java/com/wizardlybump17/wlib/test/command/manager/listener/CommandManagerListenerTests.java @@ -29,7 +29,11 @@ public void onRegister(@NotNull String identifier, @NotNull Command command, @Nu } @Override - public void onClear(@NotNull CommandManager manager) { + public void onPreClear(@NotNull CommandManager manager) { + } + + @Override + public void onPostClear(@NotNull CommandManager manager) { } @Override @@ -86,7 +90,11 @@ public void onRegister(@NotNull String identifier, @NotNull Command command, @Nu } @Override - public void onClear(@NotNull CommandManager manager) { + public void onPreClear(@NotNull CommandManager manager) { + } + + @Override + public void onPostClear(@NotNull CommandManager manager) { } @Override @@ -150,7 +158,11 @@ public void onRegister(@NotNull String identifier, @NotNull Command command, @Nu } @Override - public void onClear(@NotNull CommandManager manager) { + public void onPreClear(@NotNull CommandManager manager) { + } + + @Override + public void onPostClear(@NotNull CommandManager manager) { Assertions.assertTrue(manager.isEmpty()); called.set(true); } @@ -210,7 +222,11 @@ public void onRegister(@NotNull String identifier, @NotNull Command command, @Nu } @Override - public void onClear(@NotNull CommandManager manager) { + public void onPreClear(@NotNull CommandManager manager) { + } + + @Override + public void onPostClear(@NotNull CommandManager manager) { } @Override @@ -275,7 +291,11 @@ public void onRegister(@NotNull String identifier, @NotNull Command command, @Nu } @Override - public void onClear(@NotNull CommandManager manager) { + public void onPreClear(@NotNull CommandManager manager) { + } + + @Override + public void onPostClear(@NotNull CommandManager manager) { } @Override @@ -380,7 +400,11 @@ public void onRegister(@NotNull String identifier, @NotNull Command command, @Nu } @Override - public void onClear(@NotNull CommandManager manager) { + public void onPreClear(@NotNull CommandManager manager) { + } + + @Override + public void onPostClear(@NotNull CommandManager manager) { } @Override @@ -485,7 +509,11 @@ public void onRegister(@NotNull String identifier, @NotNull Command command, @Nu } @Override - public void onClear(@NotNull CommandManager manager) { + public void onPreClear(@NotNull CommandManager manager) { + } + + @Override + public void onPostClear(@NotNull CommandManager manager) { } @Override diff --git a/core/src/main/java/com/wizardlybump17/wlib/command/listener/BukkitCommandManagerListener.java b/core/src/main/java/com/wizardlybump17/wlib/command/listener/BukkitCommandManagerListener.java index 1b34adb2..e7752565 100644 --- a/core/src/main/java/com/wizardlybump17/wlib/command/listener/BukkitCommandManagerListener.java +++ b/core/src/main/java/com/wizardlybump17/wlib/command/listener/BukkitCommandManagerListener.java @@ -46,6 +46,12 @@ public void onRegister(@NotNull String identifier, @NotNull Command command, @Nu @Override public void onClear(@NotNull CommandManager manager) { + public void onPreClear(@NotNull CommandManager manager) { + }); + } + + @Override + public void onPostClear(@NotNull CommandManager manager) { } @Override From fd5fe4004562fe2fb4efd72a95151934f43f2877 Mon Sep 17 00:00:00 2001 From: WizardlyBump17 Date: Mon, 15 Dec 2025 13:01:25 -0300 Subject: [PATCH 262/363] properly unregistering the Bukkit commands --- .../wlib/command/listener/BukkitCommandManagerListener.java | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/core/src/main/java/com/wizardlybump17/wlib/command/listener/BukkitCommandManagerListener.java b/core/src/main/java/com/wizardlybump17/wlib/command/listener/BukkitCommandManagerListener.java index e7752565..0383696a 100644 --- a/core/src/main/java/com/wizardlybump17/wlib/command/listener/BukkitCommandManagerListener.java +++ b/core/src/main/java/com/wizardlybump17/wlib/command/listener/BukkitCommandManagerListener.java @@ -45,8 +45,11 @@ public void onRegister(@NotNull String identifier, @NotNull Command command, @Nu } @Override - public void onClear(@NotNull CommandManager manager) { public void onPreClear(@NotNull CommandManager manager) { + Map holdersByFullName = manager.getHoldersByFullName(); + manager.getCommandsByFullName().forEach((name, command) -> { + Object holder = holdersByFullName.get(name); + onUnregister(name.substring(0, name.indexOf(CommandManager.SEPARATOR)), command, holder, manager); }); } From bcba0a61bf4eef43d509bdc82dbd51cb5e924d64 Mon Sep 17 00:00:00 2001 From: WizardlyBump17 Date: Mon, 15 Dec 2025 16:47:42 -0300 Subject: [PATCH 263/363] using the class name --- .../wlib/command/suggestion/AbstractValuesSuggester.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/commands/src/main/java/com/wizardlybump17/wlib/command/suggestion/AbstractValuesSuggester.java b/commands/src/main/java/com/wizardlybump17/wlib/command/suggestion/AbstractValuesSuggester.java index 8e081a11..a1c895a6 100644 --- a/commands/src/main/java/com/wizardlybump17/wlib/command/suggestion/AbstractValuesSuggester.java +++ b/commands/src/main/java/com/wizardlybump17/wlib/command/suggestion/AbstractValuesSuggester.java @@ -40,7 +40,7 @@ public int hashCode() { @Override public String toString() { - return "AbstractValuesSuggester{" + + return getClass().getSimpleName() + "{" + "suggestions=" + suggestions + '}'; } From e78c3619661bcaced8fa4cd5645387e4d37bc8db Mon Sep 17 00:00:00 2001 From: WizardlyBump17 Date: Mon, 15 Dec 2025 19:25:53 -0300 Subject: [PATCH 264/363] not letting some stuff to happen --- .../wizardlybump17/wlib/command/Command.java | 8 +-- .../method/MethodCommandExtractorTests.java | 52 ++++++++++++++++--- 2 files changed, 49 insertions(+), 11 deletions(-) diff --git a/commands/src/main/java/com/wizardlybump17/wlib/command/Command.java b/commands/src/main/java/com/wizardlybump17/wlib/command/Command.java index d64da2f3..619045fc 100644 --- a/commands/src/main/java/com/wizardlybump17/wlib/command/Command.java +++ b/commands/src/main/java/com/wizardlybump17/wlib/command/Command.java @@ -104,9 +104,11 @@ public Command(@NotNull LiteralCommandNode root) { try { CommandResult result = executor.execute(context); if (result == null) - return CommandResult.successful(context, null); - if (result.lastNode() == null || result.lastInputIndex() < 0) - return CommandResult.genericError(context); + return CommandResult.exceptionally(lastInputIndex, lastNode, new NullPointerException("The CommandResult can not be null")); + if (result.lastNode() == null) + return CommandResult.genericError(lastInputIndex, lastNode, "The last node can not be null"); + if (result.lastInputIndex() < 0) + return CommandResult.genericError(lastInputIndex, lastNode, "The last input index can not be less than 0"); return result; } catch (Throwable throwable) { return CommandResult.exceptionally(lastInputIndex, lastNode, throwable); diff --git a/commands/src/test/java/com/wizardlybump17/wlib/test/command/extractor/method/MethodCommandExtractorTests.java b/commands/src/test/java/com/wizardlybump17/wlib/test/command/extractor/method/MethodCommandExtractorTests.java index 75e9cdb6..6fdf91fc 100644 --- a/commands/src/test/java/com/wizardlybump17/wlib/test/command/extractor/method/MethodCommandExtractorTests.java +++ b/commands/src/test/java/com/wizardlybump17/wlib/test/command/extractor/method/MethodCommandExtractorTests.java @@ -1301,7 +1301,7 @@ void testExecute() { manager.execute(CHAD_SENDER, "hello") ); Assertions.assertEquals( - CommandResult.successful(1, hello.findNode("world"), null), + CommandResult.successful(1, hello.findNode("world"), "Hello World"), manager.execute(CHAD_SENDER, "hello world") ); @@ -1310,7 +1310,7 @@ void testExecute() { manager.execute(CHAD_SENDER, "hi") ); Assertions.assertEquals( - CommandResult.successful(1, hi.findNode("world"), null), + CommandResult.successful(1, hi.findNode("world"), "Hi World"), manager.execute(CHAD_SENDER, "hi world") ); @@ -1328,7 +1328,7 @@ void testExecute() { manager.execute(CHAD_SENDER, "welcome test") ); Assertions.assertEquals( - CommandResult.successful(2, welcome.findNode("world"), null), + CommandResult.successful(2, welcome.findNode("world"), "Welcome test"), manager.execute(CHAD_SENDER, "welcome test world") ); @@ -1346,7 +1346,7 @@ void testExecute() { manager.execute(CHAD_SENDER, "aye test") ); Assertions.assertEquals( - CommandResult.successful(2, aye.findNode("nice"), null), + CommandResult.successful(2, aye.findNode("nice"), "Aye test"), manager.execute(CHAD_SENDER, "aye test nice") ); } @@ -1359,7 +1359,16 @@ public void hello() { @com.wizardlybump17.wlib.command.annotation.Command("hello world") public CommandResult helloWorld() { - return null; + return CommandResult.successful( + 1, + new LiteralCommandNode( + "world", + List.of(), + Assertions.assertDoesNotThrow(() -> MethodCommandExtractor.createExecutor(this, "helloWorld")), + null + ), + "Hello World" + ); } @com.wizardlybump17.wlib.command.annotation.Command("hi") @@ -1368,7 +1377,16 @@ public void hi(@NotNull CommandSender sender) { @com.wizardlybump17.wlib.command.annotation.Command("hi world") public CommandResult hiWorld(@NotNull CommandSender sender) { - return null; + return CommandResult.successful( + 1, + new LiteralCommandNode( + "world", + List.of(), + Assertions.assertDoesNotThrow(() -> MethodCommandExtractor.createExecutor(this, "hiWorld", CommandSender.class)), + null + ), + "Hi World" + ); } @com.wizardlybump17.wlib.command.annotation.Command("greetings") @@ -1386,7 +1404,16 @@ public void welcome(@NotNull CommandSender sender, @NotNull String name) { @com.wizardlybump17.wlib.command.annotation.Command("welcome world") public CommandResult welcomeWorld(@NotNull CommandSender sender, @NotNull String name) { - return null; + return CommandResult.successful( + 2, + new LiteralCommandNode( + "world", + List.of(), + Assertions.assertDoesNotThrow(() -> MethodCommandExtractor.createExecutor(this, "welcomeWorld", CommandSender.class, String.class)), + null + ), + "Welcome " + name + ); } @com.wizardlybump17.wlib.command.annotation.Command("wassup ") @@ -1404,7 +1431,16 @@ public void aye(@NotNull String name) { @com.wizardlybump17.wlib.command.annotation.Command("aye nice") public CommandResult ayeNice(@NotNull String name) { - return null; + return CommandResult.successful( + 2, + new LiteralCommandNode( + "nice", + List.of(), + Assertions.assertDoesNotThrow(() -> MethodCommandExtractor.createExecutor(this, "ayeNice", String.class)), + null + ), + "Aye " + name + ); } } } From c1f1f9fb7b068a0c90521dd6e437172ce76b3d44 Mon Sep 17 00:00:00 2001 From: WizardlyBump17 Date: Mon, 15 Dec 2025 19:34:52 -0300 Subject: [PATCH 265/363] properly merging commands --- .../main/java/com/wizardlybump17/wlib/command/Command.java | 4 +++- .../wizardlybump17/wlib/command/node/LiteralCommandNode.java | 5 +++++ .../wizardlybump17/wlib/command/bukkit/BukkitCommand.java | 5 +++++ 3 files changed, 13 insertions(+), 1 deletion(-) diff --git a/commands/src/main/java/com/wizardlybump17/wlib/command/Command.java b/commands/src/main/java/com/wizardlybump17/wlib/command/Command.java index 619045fc..076a96e8 100644 --- a/commands/src/main/java/com/wizardlybump17/wlib/command/Command.java +++ b/commands/src/main/java/com/wizardlybump17/wlib/command/Command.java @@ -204,7 +204,9 @@ public Command(@NotNull LiteralCommandNode root) { } public @NotNull Command merge(@NotNull Command other) { - return new Command((LiteralCommandNode) root.merge(other.getRoot())); + if (other.getClass() != getClass()) + throw new IllegalArgumentException("Can not merge different kinds of Commands"); + return new Command(root.merge(other.getRoot())); } @Override diff --git a/commands/src/main/java/com/wizardlybump17/wlib/command/node/LiteralCommandNode.java b/commands/src/main/java/com/wizardlybump17/wlib/command/node/LiteralCommandNode.java index 180774ac..92a1366d 100644 --- a/commands/src/main/java/com/wizardlybump17/wlib/command/node/LiteralCommandNode.java +++ b/commands/src/main/java/com/wizardlybump17/wlib/command/node/LiteralCommandNode.java @@ -49,4 +49,9 @@ public LiteralCommandNode(@NotNull String name, @NotNull List> ch public @NotNull CommandNode withPermission(@Nullable String permission) { return new LiteralCommandNode(getName(), getChildren(), getExecutor(), permission); } + + @Override + public @NotNull LiteralCommandNode merge(@NotNull CommandNode right) { + return (LiteralCommandNode) super.merge(right); + } } diff --git a/core/src/main/java/com/wizardlybump17/wlib/command/bukkit/BukkitCommand.java b/core/src/main/java/com/wizardlybump17/wlib/command/bukkit/BukkitCommand.java index 029e9aba..5bfa6c5d 100644 --- a/core/src/main/java/com/wizardlybump17/wlib/command/bukkit/BukkitCommand.java +++ b/core/src/main/java/com/wizardlybump17/wlib/command/bukkit/BukkitCommand.java @@ -16,4 +16,9 @@ public BukkitCommand(@NotNull LiteralCommandNode root) { public @NotNull InternalBukkitCommand getInternalCommand() { return internalCommand; } + + @Override + public @NotNull BukkitCommand merge(@NotNull Command other) { + return new BukkitCommand(getRoot().merge(other.getRoot())); + } } From f35aa1134ac09b43255e09b7ef70c703036d9acb Mon Sep 17 00:00:00 2001 From: WizardlyBump17 Date: Mon, 15 Dec 2025 21:43:22 -0300 Subject: [PATCH 266/363] preparing the ground for the FullCommandResult --- .../wizardlybump17/wlib/command/Command.java | 27 ++++++++++--------- .../wlib/command/manager/CommandManager.java | 12 +++++---- .../result/error/CommandNotFoundResult.java | 4 +++ .../result/full/FullCommandResult.java | 11 ++++++++ 4 files changed, 36 insertions(+), 18 deletions(-) create mode 100644 commands/src/main/java/com/wizardlybump17/wlib/command/result/full/FullCommandResult.java diff --git a/commands/src/main/java/com/wizardlybump17/wlib/command/Command.java b/commands/src/main/java/com/wizardlybump17/wlib/command/Command.java index 076a96e8..f5ed145e 100644 --- a/commands/src/main/java/com/wizardlybump17/wlib/command/Command.java +++ b/commands/src/main/java/com/wizardlybump17/wlib/command/Command.java @@ -7,6 +7,7 @@ import com.wizardlybump17.wlib.command.node.CommandNode; import com.wizardlybump17.wlib.command.node.LiteralCommandNode; import com.wizardlybump17.wlib.command.result.CommandResult; +import com.wizardlybump17.wlib.command.result.full.FullCommandResult; import com.wizardlybump17.wlib.command.sender.CommandSender; import com.wizardlybump17.wlib.command.suggestion.Suggester; import com.wizardlybump17.wlib.util.StringUtil; @@ -33,15 +34,15 @@ public Command(@NotNull LiteralCommandNode root) { return root; } - public @NotNull CommandResult execute(@NotNull CommandSender sender, @NotNull String input) { + public @NotNull FullCommandResult execute(@NotNull CommandSender sender, @NotNull String input) { List inputList = getInputList(input); return execute(sender, inputList); } @SuppressWarnings("unchecked") - public @NotNull CommandResult execute(@NotNull CommandSender sender, @NotNull List input) { + public @NotNull FullCommandResult execute(@NotNull CommandSender sender, @NotNull List input) { if (input.isEmpty()) - return CommandResult.insufficientArguments(this); + return new FullCommandResult(sender, List.of(), root, CommandResult.insufficientArguments(this)); List> arguments = new ArrayList<>(); List> children = List.of(root); @@ -78,20 +79,20 @@ public Command(@NotNull LiteralCommandNode root) { } if (lastParsingError != null) - return CommandResult.parseInputException(lastInputIndex, lastNode, lastParsingError); + return new FullCommandResult(sender, input, lastNode, CommandResult.parseInputException(lastInputIndex, lastNode, lastParsingError)); if (lastInputError != null) - return CommandResult.outOfRangeInput(lastInputIndex, lastNode); + return new FullCommandResult(sender, input, lastNode, CommandResult.outOfRangeInput(lastInputIndex, lastNode)); - return CommandResult.extraArguments(lastInputIndex, lastNode); + return new FullCommandResult(sender, input, lastNode, CommandResult.extraArguments(lastInputIndex, lastNode)); } CommandNodeExecutor executor = lastNode.getExecutor(); if (executor == null) - return CommandResult.noCommandNodeExecutor(lastInputIndex, lastNode); + return new FullCommandResult(sender, input, lastNode, CommandResult.noCommandNodeExecutor(lastInputIndex, lastNode)); String nodePermission = lastNode.getPermission(); if (nodePermission != null && !sender.hasPermission(nodePermission)) - return CommandResult.noPermission(lastInputIndex, lastNode); + return new FullCommandResult(sender, input, lastNode, CommandResult.noPermission(lastInputIndex, lastNode)); CommandContext context = new CommandContext( this, @@ -104,14 +105,14 @@ public Command(@NotNull LiteralCommandNode root) { try { CommandResult result = executor.execute(context); if (result == null) - return CommandResult.exceptionally(lastInputIndex, lastNode, new NullPointerException("The CommandResult can not be null")); + return new FullCommandResult(sender, input, lastNode, CommandResult.exceptionally(lastInputIndex, lastNode, new NullPointerException("The CommandResult can not be null"))); if (result.lastNode() == null) - return CommandResult.genericError(lastInputIndex, lastNode, "The last node can not be null"); + return new FullCommandResult(sender, input, lastNode, CommandResult.genericError(lastInputIndex, lastNode, "The last node can not be null")); if (result.lastInputIndex() < 0) - return CommandResult.genericError(lastInputIndex, lastNode, "The last input index can not be less than 0"); - return result; + return new FullCommandResult(sender, input, lastNode, CommandResult.genericError(lastInputIndex, lastNode, "The last input index can not be less than 0")); + return new FullCommandResult(sender, input, lastNode, result); } catch (Throwable throwable) { - return CommandResult.exceptionally(lastInputIndex, lastNode, throwable); + return new FullCommandResult(sender, input, lastNode, CommandResult.exceptionally(lastInputIndex, lastNode, throwable)); } } diff --git a/commands/src/main/java/com/wizardlybump17/wlib/command/manager/CommandManager.java b/commands/src/main/java/com/wizardlybump17/wlib/command/manager/CommandManager.java index 74a719f5..b7909b56 100644 --- a/commands/src/main/java/com/wizardlybump17/wlib/command/manager/CommandManager.java +++ b/commands/src/main/java/com/wizardlybump17/wlib/command/manager/CommandManager.java @@ -4,6 +4,8 @@ import com.wizardlybump17.wlib.command.manager.listener.CommandManagerListener; import com.wizardlybump17.wlib.command.node.CommandNode; import com.wizardlybump17.wlib.command.result.CommandResult; +import com.wizardlybump17.wlib.command.result.error.CommandNotFoundResult; +import com.wizardlybump17.wlib.command.result.full.FullCommandResult; import com.wizardlybump17.wlib.command.sender.CommandSender; import com.wizardlybump17.wlib.util.StringUtil; import com.wizardlybump17.wlib.util.exception.QuotedStringException; @@ -74,9 +76,9 @@ protected void addCommand(@NotNull String identifier, @NotNull String name, @Not return left.merge(right); } - public @NotNull CommandResult execute(@NotNull CommandSender sender, @NotNull List input) { + public @NotNull FullCommandResult execute(@NotNull CommandSender sender, @NotNull List input) { if (input.isEmpty()) - return CommandResult.commandNotFound(""); + return new FullCommandResult(sender, List.of(), CommandNotFoundResult.dummyNode(), CommandResult.commandNotFound("")); String commandName = input.getFirst(); @@ -85,16 +87,16 @@ protected void addCommand(@NotNull String identifier, @NotNull String name, @Not if (command == null) command = commandsByName.get(commandName); if (command == null) - return CommandResult.commandNotFound(commandName); + return new FullCommandResult(sender, input, CommandNotFoundResult.dummyNode(), CommandResult.commandNotFound(commandName)); return command.execute(sender, input); } - public @NotNull CommandResult execute(@NotNull CommandSender sender, @NotNull String input) { + public @NotNull FullCommandResult execute(@NotNull CommandSender sender, @NotNull String input) { return execute(sender, StringUtil.parseQuotedStrings(input)); } - public @NotNull CommandResult execute(@NotNull CommandSender sender, @NotNull String @NotNull [] input) { + public @NotNull FullCommandResult execute(@NotNull CommandSender sender, @NotNull String @NotNull [] input) { return execute(sender, String.join(" ", input)); } diff --git a/commands/src/main/java/com/wizardlybump17/wlib/command/result/error/CommandNotFoundResult.java b/commands/src/main/java/com/wizardlybump17/wlib/command/result/error/CommandNotFoundResult.java index 27bbe154..ea3843b9 100644 --- a/commands/src/main/java/com/wizardlybump17/wlib/command/result/error/CommandNotFoundResult.java +++ b/commands/src/main/java/com/wizardlybump17/wlib/command/result/error/CommandNotFoundResult.java @@ -19,6 +19,10 @@ public int lastInputIndex() { return DummyNode.INSTANCE; } + public static @NotNull CommandNode dummyNode() { + return DummyNode.INSTANCE; + } + private static final class DummyNode extends CommandNode { public static final @NotNull DummyNode INSTANCE = new DummyNode(); diff --git a/commands/src/main/java/com/wizardlybump17/wlib/command/result/full/FullCommandResult.java b/commands/src/main/java/com/wizardlybump17/wlib/command/result/full/FullCommandResult.java new file mode 100644 index 00000000..c53afb12 --- /dev/null +++ b/commands/src/main/java/com/wizardlybump17/wlib/command/result/full/FullCommandResult.java @@ -0,0 +1,11 @@ +package com.wizardlybump17.wlib.command.result.full; + +import com.wizardlybump17.wlib.command.node.CommandNode; +import com.wizardlybump17.wlib.command.result.CommandResult; +import com.wizardlybump17.wlib.command.sender.CommandSender; +import org.jetbrains.annotations.NotNull; + +import java.util.List; + +public record FullCommandResult(@NotNull CommandSender sender, @NotNull List input, @NotNull CommandNode lastNode, @NotNull CommandResult result) { +} From 0b7d1d099265e35564dca0f1fbdfa286931b95da Mon Sep 17 00:00:00 2001 From: WizardlyBump17 Date: Mon, 15 Dec 2025 21:59:14 -0300 Subject: [PATCH 267/363] preparing the ground for the FullCommandResult --- .../wizardlybump17/wlib/command/Command.java | 84 ++++++++++++------- .../wlib/command/manager/CommandManager.java | 4 +- .../result/full/FullCommandResult.java | 2 +- .../wlib/test/command/CommandTests.java | 53 ++++++------ .../command/manager/CommandManagerTests.java | 13 +-- 5 files changed, 89 insertions(+), 67 deletions(-) diff --git a/commands/src/main/java/com/wizardlybump17/wlib/command/Command.java b/commands/src/main/java/com/wizardlybump17/wlib/command/Command.java index f5ed145e..ad0e3865 100644 --- a/commands/src/main/java/com/wizardlybump17/wlib/command/Command.java +++ b/commands/src/main/java/com/wizardlybump17/wlib/command/Command.java @@ -42,7 +42,7 @@ public Command(@NotNull LiteralCommandNode root) { @SuppressWarnings("unchecked") public @NotNull FullCommandResult execute(@NotNull CommandSender sender, @NotNull List input) { if (input.isEmpty()) - return new FullCommandResult(sender, List.of(), root, CommandResult.insufficientArguments(this)); + return new FullCommandResult(sender, List.of(), 0, root, CommandResult.insufficientArguments(this)); List> arguments = new ArrayList<>(); List> children = List.of(root); @@ -52,6 +52,7 @@ public Command(@NotNull LiteralCommandNode root) { InputParsingException lastParsingError = null; InvalidInputException lastInputError = null; + CommandResult finalResult = null; inputLoop: for (int i = 0; i < input.size(); i++) { String inputString = input.get(i); lastInputIndex = i; @@ -78,42 +79,61 @@ public Command(@NotNull LiteralCommandNode root) { } } - if (lastParsingError != null) - return new FullCommandResult(sender, input, lastNode, CommandResult.parseInputException(lastInputIndex, lastNode, lastParsingError)); - if (lastInputError != null) - return new FullCommandResult(sender, input, lastNode, CommandResult.outOfRangeInput(lastInputIndex, lastNode)); + if (lastParsingError != null) { + finalResult = CommandResult.parseInputException(lastInputIndex, lastNode, lastParsingError); + break; + } + if (lastInputError != null) { + finalResult = CommandResult.outOfRangeInput(lastInputIndex, lastNode); + break; + } - return new FullCommandResult(sender, input, lastNode, CommandResult.extraArguments(lastInputIndex, lastNode)); + finalResult = CommandResult.extraArguments(lastInputIndex, lastNode); + break; } CommandNodeExecutor executor = lastNode.getExecutor(); - if (executor == null) - return new FullCommandResult(sender, input, lastNode, CommandResult.noCommandNodeExecutor(lastInputIndex, lastNode)); - - String nodePermission = lastNode.getPermission(); - if (nodePermission != null && !sender.hasPermission(nodePermission)) - return new FullCommandResult(sender, input, lastNode, CommandResult.noPermission(lastInputIndex, lastNode)); - - CommandContext context = new CommandContext( - this, - sender, - new CommandContext.CommandNodeArguments(arguments), - lastInputIndex, - lastNode - ); - - try { - CommandResult result = executor.execute(context); - if (result == null) - return new FullCommandResult(sender, input, lastNode, CommandResult.exceptionally(lastInputIndex, lastNode, new NullPointerException("The CommandResult can not be null"))); - if (result.lastNode() == null) - return new FullCommandResult(sender, input, lastNode, CommandResult.genericError(lastInputIndex, lastNode, "The last node can not be null")); - if (result.lastInputIndex() < 0) - return new FullCommandResult(sender, input, lastNode, CommandResult.genericError(lastInputIndex, lastNode, "The last input index can not be less than 0")); - return new FullCommandResult(sender, input, lastNode, result); - } catch (Throwable throwable) { - return new FullCommandResult(sender, input, lastNode, CommandResult.exceptionally(lastInputIndex, lastNode, throwable)); + + if (finalResult == null) { + if (executor == null) + finalResult = CommandResult.noCommandNodeExecutor(lastInputIndex, lastNode); } + + if (finalResult == null) { + String nodePermission = lastNode.getPermission(); + if (nodePermission != null && !sender.hasPermission(nodePermission)) + finalResult = CommandResult.noPermission(lastInputIndex, lastNode); + } + + if (finalResult == null) { + CommandContext context = new CommandContext( + this, + sender, + new CommandContext.CommandNodeArguments(arguments), + lastInputIndex, + lastNode + ); + + try { + CommandResult result = executor.execute(context); + + if (result == null) + finalResult = CommandResult.exceptionally(lastInputIndex, lastNode, new NullPointerException("The CommandResult can not be null")); + if (finalResult == null && result.lastNode() == null) + finalResult = CommandResult.genericError(lastInputIndex, lastNode, "The last node can not be null"); + if (finalResult == null && result.lastInputIndex() < 0) + finalResult = CommandResult.genericError(lastInputIndex, lastNode, "The last input index can not be less than 0"); + + if (finalResult == null) + finalResult = result; + + return new FullCommandResult(sender, input, lastInputIndex, lastNode, finalResult); + } catch (Throwable throwable) { + finalResult = CommandResult.exceptionally(lastInputIndex, lastNode, throwable); + } + } + + return new FullCommandResult(sender, input, lastInputIndex, lastNode, finalResult); } public @NotNull List getInputList(@NotNull String original) { diff --git a/commands/src/main/java/com/wizardlybump17/wlib/command/manager/CommandManager.java b/commands/src/main/java/com/wizardlybump17/wlib/command/manager/CommandManager.java index b7909b56..50ec2635 100644 --- a/commands/src/main/java/com/wizardlybump17/wlib/command/manager/CommandManager.java +++ b/commands/src/main/java/com/wizardlybump17/wlib/command/manager/CommandManager.java @@ -78,7 +78,7 @@ protected void addCommand(@NotNull String identifier, @NotNull String name, @Not public @NotNull FullCommandResult execute(@NotNull CommandSender sender, @NotNull List input) { if (input.isEmpty()) - return new FullCommandResult(sender, List.of(), CommandNotFoundResult.dummyNode(), CommandResult.commandNotFound("")); + return new FullCommandResult(sender, List.of(), 0, CommandNotFoundResult.dummyNode(), CommandResult.commandNotFound("")); String commandName = input.getFirst(); @@ -87,7 +87,7 @@ protected void addCommand(@NotNull String identifier, @NotNull String name, @Not if (command == null) command = commandsByName.get(commandName); if (command == null) - return new FullCommandResult(sender, input, CommandNotFoundResult.dummyNode(), CommandResult.commandNotFound(commandName)); + return new FullCommandResult(sender, input, 0, CommandNotFoundResult.dummyNode(), CommandResult.commandNotFound(commandName)); return command.execute(sender, input); } diff --git a/commands/src/main/java/com/wizardlybump17/wlib/command/result/full/FullCommandResult.java b/commands/src/main/java/com/wizardlybump17/wlib/command/result/full/FullCommandResult.java index c53afb12..38c74787 100644 --- a/commands/src/main/java/com/wizardlybump17/wlib/command/result/full/FullCommandResult.java +++ b/commands/src/main/java/com/wizardlybump17/wlib/command/result/full/FullCommandResult.java @@ -7,5 +7,5 @@ import java.util.List; -public record FullCommandResult(@NotNull CommandSender sender, @NotNull List input, @NotNull CommandNode lastNode, @NotNull CommandResult result) { +public record FullCommandResult(@NotNull CommandSender sender, @NotNull List input, int lastInputIndex, @NotNull CommandNode lastNode, @NotNull CommandResult result) { } diff --git a/commands/src/test/java/com/wizardlybump17/wlib/test/command/CommandTests.java b/commands/src/test/java/com/wizardlybump17/wlib/test/command/CommandTests.java index 74c0c1c5..771b48dd 100644 --- a/commands/src/test/java/com/wizardlybump17/wlib/test/command/CommandTests.java +++ b/commands/src/test/java/com/wizardlybump17/wlib/test/command/CommandTests.java @@ -10,6 +10,7 @@ import com.wizardlybump17.wlib.command.node.primitive.number.IntegerCommandNode; import com.wizardlybump17.wlib.command.result.CommandResult; import com.wizardlybump17.wlib.command.result.error.*; +import com.wizardlybump17.wlib.command.result.full.FullCommandResult; import com.wizardlybump17.wlib.command.sender.BasicCommandSender; import com.wizardlybump17.wlib.command.sender.CommandSender; import org.jetbrains.annotations.NotNull; @@ -39,8 +40,8 @@ void testSuccessHello() { ); Command command = new Command(helloNode); - CommandResult expected = CommandResult.successful(0, helloNode, "hello"); - CommandResult actual = command.execute(CHAD_SENDER, List.of("hello")); + FullCommandResult expected = new FullCommandResult(CHAD_SENDER, List.of("hello"), 0, helloNode, CommandResult.successful(0, helloNode, "hello")); + FullCommandResult actual = command.execute(CHAD_SENDER, List.of("hello")); Assertions.assertEquals(expected, actual); } @@ -62,8 +63,8 @@ void testSuccessHelloWorld() { ) ); - CommandResult expected = CommandResult.successful(1, worldNode, "hello world"); - CommandResult actual = command.execute(CHAD_SENDER, List.of("hello", "world")); + FullCommandResult expected = new FullCommandResult(CHAD_SENDER, List.of("hello", "world"), 1, worldNode, CommandResult.successful(1, worldNode, "hello world")); + FullCommandResult actual = command.execute(CHAD_SENDER, List.of("hello", "world")); Assertions.assertEquals(expected, actual); } @@ -92,8 +93,8 @@ void testSuccessHelloWorldHi() { ) ); - CommandResult expected = CommandResult.successful(2, hiNode, "hello world hi"); - CommandResult actual = command.execute(CHAD_SENDER, List.of("hello", "world", "hi")); + FullCommandResult expected = new FullCommandResult(CHAD_SENDER, List.of("hello", "world", "hi"), 2, hiNode, CommandResult.successful(2, hiNode, "hello world hi")); + FullCommandResult actual = command.execute(CHAD_SENDER, List.of("hello", "world", "hi")); Assertions.assertEquals(expected, actual); } @@ -122,8 +123,8 @@ void test0() { null )); - CommandResult expected = CommandResult.successful(1, hiNode, "hello hi"); - CommandResult actual = command.execute(CHAD_SENDER, List.of("hello", "hi")); + FullCommandResult expected = new FullCommandResult(CHAD_SENDER, List.of("hello", "hi"), 1, hiNode, CommandResult.successful(1, hiNode, "hello hi")); + FullCommandResult actual = command.execute(CHAD_SENDER, List.of("hello", "hi")); Assertions.assertEquals(expected, actual); } @@ -157,8 +158,8 @@ void test1() { null )); - CommandResult expected = CommandResult.successful(2, hiWorldNode, "hello hi world"); - CommandResult actual = command.execute(CHAD_SENDER, List.of("hello", "hi", "world0")); + FullCommandResult expected = new FullCommandResult(CHAD_SENDER, List.of("hello", "hi", "world0"), 2, hiWorldNode, CommandResult.successful(2, hiWorldNode, "hello hi world")); + FullCommandResult actual = command.execute(CHAD_SENDER, List.of("hello", "hi", "world0")); Assertions.assertEquals(expected, actual); } @@ -173,8 +174,8 @@ void testExtraArguments0() { ); Command command = new Command(helloNode); - ExtraArgumentsResult expected = CommandResult.extraArguments(1, helloNode); - CommandResult actual = command.execute(CHAD_SENDER, List.of("hello", "world")); + FullCommandResult expected = new FullCommandResult(CHAD_SENDER, List.of("hello", "world"), 2, helloNode, CommandResult.extraArguments(1, helloNode)); + FullCommandResult actual = command.execute(CHAD_SENDER, List.of("hello", "world")); Assertions.assertEquals(expected, actual); } @@ -196,8 +197,8 @@ void testExtraArguments1() { ) ); - ExtraArgumentsResult expected = CommandResult.extraArguments(2, worldNode); - CommandResult actual = command.execute(CHAD_SENDER, List.of("hello", "world", "hi")); + FullCommandResult expected = new FullCommandResult(CHAD_SENDER, List.of("hello", "world", "hi"), 2, worldNode, CommandResult.extraArguments(2, worldNode)); + FullCommandResult actual = command.execute(CHAD_SENDER, List.of("hello", "world", "hi")); Assertions.assertEquals(expected, actual); } @@ -230,8 +231,8 @@ void testExtraArguments2() { null )); - ExtraArgumentsResult expected = CommandResult.extraArguments(3, hiWorldNode); - CommandResult actual = command.execute(CHAD_SENDER, List.of("hello", "hi", "world0", "extra")); + FullCommandResult expected = new FullCommandResult(CHAD_SENDER, List.of("hello", "hi", "world0", "extra"), 2, hiWorldNode, CommandResult.extraArguments(3, hiWorldNode)); + FullCommandResult actual = command.execute(CHAD_SENDER, List.of("hello", "hi", "world0", "extra")); Assertions.assertEquals(expected, actual); } @@ -250,7 +251,7 @@ void testException() { Command command = new Command(helloNode); ExceptionResult expected = CommandResult.exceptionally(0, helloNode, helloException); - CommandResult actual = command.execute(CHAD_SENDER, List.of("hello")); + FullCommandResult actual = command.execute(CHAD_SENDER, List.of("hello")); Assertions.assertEquals(expected, actual); } @@ -267,7 +268,7 @@ void testInsufficientArguments() { ); InsufficientArgumentsResult expected = CommandResult.insufficientArguments(command); - CommandResult actual = command.execute(CHAD_SENDER, List.of()); + FullCommandResult actual = command.execute(CHAD_SENDER, List.of()); Assertions.assertEquals(expected, actual); } @@ -283,7 +284,7 @@ void testNoPermission() { Command command = new Command(helloNode); NoPermissionResult expected = CommandResult.noPermission(0, helloNode); - CommandResult actual = command.execute(BETA_SENDER, List.of("hello")); + FullCommandResult actual = command.execute(BETA_SENDER, List.of("hello")); Assertions.assertEquals(expected, actual); } @@ -299,7 +300,7 @@ void testOutOfRange() { Command command = new Command(helloNode); OutOfRangeInputResult expected = CommandResult.outOfRangeInput(0, helloNode); - CommandResult actual = command.execute(CHAD_SENDER, List.of("hello0")); + FullCommandResult actual = command.execute(CHAD_SENDER, List.of("hello0")); Assertions.assertEquals(expected, actual); } @@ -324,11 +325,11 @@ void testParseInputException() { ); ParseInputExceptionResult expected = CommandResult.parseInputException(1, worldNode, new InputParsingException("Could not parse as int: world", new NumberFormatException("For input string: \"world\""))); - CommandResult actual = command.execute(CHAD_SENDER, List.of("hello", "world")); + FullCommandResult actual = command.execute(CHAD_SENDER, List.of("hello", "world")); Assertions.assertInstanceOf(ParseInputExceptionResult.class, actual); - ParseInputExceptionResult actualException = (ParseInputExceptionResult) actual; + ParseInputExceptionResult actualException = (ParseInputExceptionResult) actual.result(); Assertions.assertEquals(expected.lastInputIndex(), actual.lastInputIndex()); Assertions.assertEquals(expected.lastNode(), actual.lastNode()); Assertions.assertEquals(expected.exception().getMessage(), actualException.exception().getMessage()); @@ -346,7 +347,7 @@ void testCommandNodeExecutorNotFound() { Command command = new Command(helloNode); CommandNodeExecutorNotFoundResult expected = CommandResult.noCommandNodeExecutor(0, helloNode); - CommandResult actual = command.execute(CHAD_SENDER, List.of("hello")); + FullCommandResult actual = command.execute(CHAD_SENDER, List.of("hello")); Assertions.assertEquals(expected, actual); } @@ -409,7 +410,7 @@ void testCommandArguments() { }, null ); - CommandResult result = new Command( + FullCommandResult result = new Command( new LiteralCommandNode( "hello", List.of(world), @@ -436,7 +437,7 @@ void testCommandArguments() { ); worldReference.set(world); - CommandResult result = new Command( + FullCommandResult result = new Command( new LiteralCommandNode( "hello", List.of(world), @@ -469,7 +470,7 @@ void testCommandArguments() { ); worldReference.set(world); - CommandResult result = new Command( + FullCommandResult result = new Command( new LiteralCommandNode( "hello", List.of(world), diff --git a/commands/src/test/java/com/wizardlybump17/wlib/test/command/manager/CommandManagerTests.java b/commands/src/test/java/com/wizardlybump17/wlib/test/command/manager/CommandManagerTests.java index c3734118..05ad4aee 100644 --- a/commands/src/test/java/com/wizardlybump17/wlib/test/command/manager/CommandManagerTests.java +++ b/commands/src/test/java/com/wizardlybump17/wlib/test/command/manager/CommandManagerTests.java @@ -7,6 +7,7 @@ import com.wizardlybump17.wlib.command.result.CommandResult; import com.wizardlybump17.wlib.command.result.SuccessResult; import com.wizardlybump17.wlib.command.result.error.CommandNotFoundResult; +import com.wizardlybump17.wlib.command.result.full.FullCommandResult; import com.wizardlybump17.wlib.command.sender.BasicCommandSender; import com.wizardlybump17.wlib.command.sender.CommandSender; import org.jetbrains.annotations.NotNull; @@ -321,8 +322,8 @@ void testCommandNotFound0() { CommandManager manager = new CommandManager(); manager.registerCommand("test", command); - CommandNotFoundResult expected = CommandResult.commandNotFound("hello0"); - CommandResult actual = manager.execute(CHAD_SENDER, List.of("hello0")); + FullCommandResult expected = new FullCommandResult(CHAD_SENDER, List.of("hello0"), 0, command.getRoot(), CommandResult.commandNotFound("hello0")); + FullCommandResult actual = manager.execute(CHAD_SENDER, List.of("hello0")); Assertions.assertEquals(expected, actual); } @@ -341,8 +342,8 @@ void testCommandNotFound1() { CommandManager manager = new CommandManager(); manager.registerCommand("test", command); - CommandNotFoundResult expected = CommandResult.commandNotFound(""); - CommandResult actual = manager.execute(CHAD_SENDER, List.of()); + FullCommandResult expected = new FullCommandResult(CHAD_SENDER, List.of(), 0, CommandNotFoundResult.dummyNode(), CommandResult.commandNotFound("")); + FullCommandResult actual = manager.execute(CHAD_SENDER, List.of()); Assertions.assertEquals(expected, actual); } @@ -380,7 +381,7 @@ void testSuccess0() { manager.registerCommand("test", command2); SuccessResult expected = CommandResult.successful(0, helloNode, "hello"); - CommandResult actual = manager.execute(CHAD_SENDER, List.of("hello")); + FullCommandResult actual = manager.execute(CHAD_SENDER, List.of("hello")); Assertions.assertEquals(expected, actual); } @@ -426,7 +427,7 @@ void testSuccess1() { manager.registerCommand("test", command2); SuccessResult expected = CommandResult.successful(1, thereNode, "hi there"); - CommandResult actual = manager.execute(CHAD_SENDER, List.of("hi", "there")); + FullCommandResult actual = manager.execute(CHAD_SENDER, List.of("hi", "there")); Assertions.assertEquals(expected, actual); } From 7467c883c723fda99de9f8250ffdee63cc56dcd1 Mon Sep 17 00:00:00 2001 From: WizardlyBump17 Date: Mon, 15 Dec 2025 22:14:25 -0300 Subject: [PATCH 268/363] Revert "preparing the ground for the FullCommandResult" This reverts commit 0b7d1d099265e35564dca0f1fbdfa286931b95da. --- .../wizardlybump17/wlib/command/Command.java | 84 +++++++------------ .../wlib/command/manager/CommandManager.java | 4 +- .../result/full/FullCommandResult.java | 2 +- .../wlib/test/command/CommandTests.java | 53 ++++++------ .../command/manager/CommandManagerTests.java | 13 ++- 5 files changed, 67 insertions(+), 89 deletions(-) diff --git a/commands/src/main/java/com/wizardlybump17/wlib/command/Command.java b/commands/src/main/java/com/wizardlybump17/wlib/command/Command.java index ad0e3865..f5ed145e 100644 --- a/commands/src/main/java/com/wizardlybump17/wlib/command/Command.java +++ b/commands/src/main/java/com/wizardlybump17/wlib/command/Command.java @@ -42,7 +42,7 @@ public Command(@NotNull LiteralCommandNode root) { @SuppressWarnings("unchecked") public @NotNull FullCommandResult execute(@NotNull CommandSender sender, @NotNull List input) { if (input.isEmpty()) - return new FullCommandResult(sender, List.of(), 0, root, CommandResult.insufficientArguments(this)); + return new FullCommandResult(sender, List.of(), root, CommandResult.insufficientArguments(this)); List> arguments = new ArrayList<>(); List> children = List.of(root); @@ -52,7 +52,6 @@ public Command(@NotNull LiteralCommandNode root) { InputParsingException lastParsingError = null; InvalidInputException lastInputError = null; - CommandResult finalResult = null; inputLoop: for (int i = 0; i < input.size(); i++) { String inputString = input.get(i); lastInputIndex = i; @@ -79,61 +78,42 @@ public Command(@NotNull LiteralCommandNode root) { } } - if (lastParsingError != null) { - finalResult = CommandResult.parseInputException(lastInputIndex, lastNode, lastParsingError); - break; - } - if (lastInputError != null) { - finalResult = CommandResult.outOfRangeInput(lastInputIndex, lastNode); - break; - } + if (lastParsingError != null) + return new FullCommandResult(sender, input, lastNode, CommandResult.parseInputException(lastInputIndex, lastNode, lastParsingError)); + if (lastInputError != null) + return new FullCommandResult(sender, input, lastNode, CommandResult.outOfRangeInput(lastInputIndex, lastNode)); - finalResult = CommandResult.extraArguments(lastInputIndex, lastNode); - break; + return new FullCommandResult(sender, input, lastNode, CommandResult.extraArguments(lastInputIndex, lastNode)); } CommandNodeExecutor executor = lastNode.getExecutor(); - - if (finalResult == null) { - if (executor == null) - finalResult = CommandResult.noCommandNodeExecutor(lastInputIndex, lastNode); + if (executor == null) + return new FullCommandResult(sender, input, lastNode, CommandResult.noCommandNodeExecutor(lastInputIndex, lastNode)); + + String nodePermission = lastNode.getPermission(); + if (nodePermission != null && !sender.hasPermission(nodePermission)) + return new FullCommandResult(sender, input, lastNode, CommandResult.noPermission(lastInputIndex, lastNode)); + + CommandContext context = new CommandContext( + this, + sender, + new CommandContext.CommandNodeArguments(arguments), + lastInputIndex, + lastNode + ); + + try { + CommandResult result = executor.execute(context); + if (result == null) + return new FullCommandResult(sender, input, lastNode, CommandResult.exceptionally(lastInputIndex, lastNode, new NullPointerException("The CommandResult can not be null"))); + if (result.lastNode() == null) + return new FullCommandResult(sender, input, lastNode, CommandResult.genericError(lastInputIndex, lastNode, "The last node can not be null")); + if (result.lastInputIndex() < 0) + return new FullCommandResult(sender, input, lastNode, CommandResult.genericError(lastInputIndex, lastNode, "The last input index can not be less than 0")); + return new FullCommandResult(sender, input, lastNode, result); + } catch (Throwable throwable) { + return new FullCommandResult(sender, input, lastNode, CommandResult.exceptionally(lastInputIndex, lastNode, throwable)); } - - if (finalResult == null) { - String nodePermission = lastNode.getPermission(); - if (nodePermission != null && !sender.hasPermission(nodePermission)) - finalResult = CommandResult.noPermission(lastInputIndex, lastNode); - } - - if (finalResult == null) { - CommandContext context = new CommandContext( - this, - sender, - new CommandContext.CommandNodeArguments(arguments), - lastInputIndex, - lastNode - ); - - try { - CommandResult result = executor.execute(context); - - if (result == null) - finalResult = CommandResult.exceptionally(lastInputIndex, lastNode, new NullPointerException("The CommandResult can not be null")); - if (finalResult == null && result.lastNode() == null) - finalResult = CommandResult.genericError(lastInputIndex, lastNode, "The last node can not be null"); - if (finalResult == null && result.lastInputIndex() < 0) - finalResult = CommandResult.genericError(lastInputIndex, lastNode, "The last input index can not be less than 0"); - - if (finalResult == null) - finalResult = result; - - return new FullCommandResult(sender, input, lastInputIndex, lastNode, finalResult); - } catch (Throwable throwable) { - finalResult = CommandResult.exceptionally(lastInputIndex, lastNode, throwable); - } - } - - return new FullCommandResult(sender, input, lastInputIndex, lastNode, finalResult); } public @NotNull List getInputList(@NotNull String original) { diff --git a/commands/src/main/java/com/wizardlybump17/wlib/command/manager/CommandManager.java b/commands/src/main/java/com/wizardlybump17/wlib/command/manager/CommandManager.java index 50ec2635..b7909b56 100644 --- a/commands/src/main/java/com/wizardlybump17/wlib/command/manager/CommandManager.java +++ b/commands/src/main/java/com/wizardlybump17/wlib/command/manager/CommandManager.java @@ -78,7 +78,7 @@ protected void addCommand(@NotNull String identifier, @NotNull String name, @Not public @NotNull FullCommandResult execute(@NotNull CommandSender sender, @NotNull List input) { if (input.isEmpty()) - return new FullCommandResult(sender, List.of(), 0, CommandNotFoundResult.dummyNode(), CommandResult.commandNotFound("")); + return new FullCommandResult(sender, List.of(), CommandNotFoundResult.dummyNode(), CommandResult.commandNotFound("")); String commandName = input.getFirst(); @@ -87,7 +87,7 @@ protected void addCommand(@NotNull String identifier, @NotNull String name, @Not if (command == null) command = commandsByName.get(commandName); if (command == null) - return new FullCommandResult(sender, input, 0, CommandNotFoundResult.dummyNode(), CommandResult.commandNotFound(commandName)); + return new FullCommandResult(sender, input, CommandNotFoundResult.dummyNode(), CommandResult.commandNotFound(commandName)); return command.execute(sender, input); } diff --git a/commands/src/main/java/com/wizardlybump17/wlib/command/result/full/FullCommandResult.java b/commands/src/main/java/com/wizardlybump17/wlib/command/result/full/FullCommandResult.java index 38c74787..c53afb12 100644 --- a/commands/src/main/java/com/wizardlybump17/wlib/command/result/full/FullCommandResult.java +++ b/commands/src/main/java/com/wizardlybump17/wlib/command/result/full/FullCommandResult.java @@ -7,5 +7,5 @@ import java.util.List; -public record FullCommandResult(@NotNull CommandSender sender, @NotNull List input, int lastInputIndex, @NotNull CommandNode lastNode, @NotNull CommandResult result) { +public record FullCommandResult(@NotNull CommandSender sender, @NotNull List input, @NotNull CommandNode lastNode, @NotNull CommandResult result) { } diff --git a/commands/src/test/java/com/wizardlybump17/wlib/test/command/CommandTests.java b/commands/src/test/java/com/wizardlybump17/wlib/test/command/CommandTests.java index 771b48dd..74c0c1c5 100644 --- a/commands/src/test/java/com/wizardlybump17/wlib/test/command/CommandTests.java +++ b/commands/src/test/java/com/wizardlybump17/wlib/test/command/CommandTests.java @@ -10,7 +10,6 @@ import com.wizardlybump17.wlib.command.node.primitive.number.IntegerCommandNode; import com.wizardlybump17.wlib.command.result.CommandResult; import com.wizardlybump17.wlib.command.result.error.*; -import com.wizardlybump17.wlib.command.result.full.FullCommandResult; import com.wizardlybump17.wlib.command.sender.BasicCommandSender; import com.wizardlybump17.wlib.command.sender.CommandSender; import org.jetbrains.annotations.NotNull; @@ -40,8 +39,8 @@ void testSuccessHello() { ); Command command = new Command(helloNode); - FullCommandResult expected = new FullCommandResult(CHAD_SENDER, List.of("hello"), 0, helloNode, CommandResult.successful(0, helloNode, "hello")); - FullCommandResult actual = command.execute(CHAD_SENDER, List.of("hello")); + CommandResult expected = CommandResult.successful(0, helloNode, "hello"); + CommandResult actual = command.execute(CHAD_SENDER, List.of("hello")); Assertions.assertEquals(expected, actual); } @@ -63,8 +62,8 @@ void testSuccessHelloWorld() { ) ); - FullCommandResult expected = new FullCommandResult(CHAD_SENDER, List.of("hello", "world"), 1, worldNode, CommandResult.successful(1, worldNode, "hello world")); - FullCommandResult actual = command.execute(CHAD_SENDER, List.of("hello", "world")); + CommandResult expected = CommandResult.successful(1, worldNode, "hello world"); + CommandResult actual = command.execute(CHAD_SENDER, List.of("hello", "world")); Assertions.assertEquals(expected, actual); } @@ -93,8 +92,8 @@ void testSuccessHelloWorldHi() { ) ); - FullCommandResult expected = new FullCommandResult(CHAD_SENDER, List.of("hello", "world", "hi"), 2, hiNode, CommandResult.successful(2, hiNode, "hello world hi")); - FullCommandResult actual = command.execute(CHAD_SENDER, List.of("hello", "world", "hi")); + CommandResult expected = CommandResult.successful(2, hiNode, "hello world hi"); + CommandResult actual = command.execute(CHAD_SENDER, List.of("hello", "world", "hi")); Assertions.assertEquals(expected, actual); } @@ -123,8 +122,8 @@ void test0() { null )); - FullCommandResult expected = new FullCommandResult(CHAD_SENDER, List.of("hello", "hi"), 1, hiNode, CommandResult.successful(1, hiNode, "hello hi")); - FullCommandResult actual = command.execute(CHAD_SENDER, List.of("hello", "hi")); + CommandResult expected = CommandResult.successful(1, hiNode, "hello hi"); + CommandResult actual = command.execute(CHAD_SENDER, List.of("hello", "hi")); Assertions.assertEquals(expected, actual); } @@ -158,8 +157,8 @@ void test1() { null )); - FullCommandResult expected = new FullCommandResult(CHAD_SENDER, List.of("hello", "hi", "world0"), 2, hiWorldNode, CommandResult.successful(2, hiWorldNode, "hello hi world")); - FullCommandResult actual = command.execute(CHAD_SENDER, List.of("hello", "hi", "world0")); + CommandResult expected = CommandResult.successful(2, hiWorldNode, "hello hi world"); + CommandResult actual = command.execute(CHAD_SENDER, List.of("hello", "hi", "world0")); Assertions.assertEquals(expected, actual); } @@ -174,8 +173,8 @@ void testExtraArguments0() { ); Command command = new Command(helloNode); - FullCommandResult expected = new FullCommandResult(CHAD_SENDER, List.of("hello", "world"), 2, helloNode, CommandResult.extraArguments(1, helloNode)); - FullCommandResult actual = command.execute(CHAD_SENDER, List.of("hello", "world")); + ExtraArgumentsResult expected = CommandResult.extraArguments(1, helloNode); + CommandResult actual = command.execute(CHAD_SENDER, List.of("hello", "world")); Assertions.assertEquals(expected, actual); } @@ -197,8 +196,8 @@ void testExtraArguments1() { ) ); - FullCommandResult expected = new FullCommandResult(CHAD_SENDER, List.of("hello", "world", "hi"), 2, worldNode, CommandResult.extraArguments(2, worldNode)); - FullCommandResult actual = command.execute(CHAD_SENDER, List.of("hello", "world", "hi")); + ExtraArgumentsResult expected = CommandResult.extraArguments(2, worldNode); + CommandResult actual = command.execute(CHAD_SENDER, List.of("hello", "world", "hi")); Assertions.assertEquals(expected, actual); } @@ -231,8 +230,8 @@ void testExtraArguments2() { null )); - FullCommandResult expected = new FullCommandResult(CHAD_SENDER, List.of("hello", "hi", "world0", "extra"), 2, hiWorldNode, CommandResult.extraArguments(3, hiWorldNode)); - FullCommandResult actual = command.execute(CHAD_SENDER, List.of("hello", "hi", "world0", "extra")); + ExtraArgumentsResult expected = CommandResult.extraArguments(3, hiWorldNode); + CommandResult actual = command.execute(CHAD_SENDER, List.of("hello", "hi", "world0", "extra")); Assertions.assertEquals(expected, actual); } @@ -251,7 +250,7 @@ void testException() { Command command = new Command(helloNode); ExceptionResult expected = CommandResult.exceptionally(0, helloNode, helloException); - FullCommandResult actual = command.execute(CHAD_SENDER, List.of("hello")); + CommandResult actual = command.execute(CHAD_SENDER, List.of("hello")); Assertions.assertEquals(expected, actual); } @@ -268,7 +267,7 @@ void testInsufficientArguments() { ); InsufficientArgumentsResult expected = CommandResult.insufficientArguments(command); - FullCommandResult actual = command.execute(CHAD_SENDER, List.of()); + CommandResult actual = command.execute(CHAD_SENDER, List.of()); Assertions.assertEquals(expected, actual); } @@ -284,7 +283,7 @@ void testNoPermission() { Command command = new Command(helloNode); NoPermissionResult expected = CommandResult.noPermission(0, helloNode); - FullCommandResult actual = command.execute(BETA_SENDER, List.of("hello")); + CommandResult actual = command.execute(BETA_SENDER, List.of("hello")); Assertions.assertEquals(expected, actual); } @@ -300,7 +299,7 @@ void testOutOfRange() { Command command = new Command(helloNode); OutOfRangeInputResult expected = CommandResult.outOfRangeInput(0, helloNode); - FullCommandResult actual = command.execute(CHAD_SENDER, List.of("hello0")); + CommandResult actual = command.execute(CHAD_SENDER, List.of("hello0")); Assertions.assertEquals(expected, actual); } @@ -325,11 +324,11 @@ void testParseInputException() { ); ParseInputExceptionResult expected = CommandResult.parseInputException(1, worldNode, new InputParsingException("Could not parse as int: world", new NumberFormatException("For input string: \"world\""))); - FullCommandResult actual = command.execute(CHAD_SENDER, List.of("hello", "world")); + CommandResult actual = command.execute(CHAD_SENDER, List.of("hello", "world")); Assertions.assertInstanceOf(ParseInputExceptionResult.class, actual); - ParseInputExceptionResult actualException = (ParseInputExceptionResult) actual.result(); + ParseInputExceptionResult actualException = (ParseInputExceptionResult) actual; Assertions.assertEquals(expected.lastInputIndex(), actual.lastInputIndex()); Assertions.assertEquals(expected.lastNode(), actual.lastNode()); Assertions.assertEquals(expected.exception().getMessage(), actualException.exception().getMessage()); @@ -347,7 +346,7 @@ void testCommandNodeExecutorNotFound() { Command command = new Command(helloNode); CommandNodeExecutorNotFoundResult expected = CommandResult.noCommandNodeExecutor(0, helloNode); - FullCommandResult actual = command.execute(CHAD_SENDER, List.of("hello")); + CommandResult actual = command.execute(CHAD_SENDER, List.of("hello")); Assertions.assertEquals(expected, actual); } @@ -410,7 +409,7 @@ void testCommandArguments() { }, null ); - FullCommandResult result = new Command( + CommandResult result = new Command( new LiteralCommandNode( "hello", List.of(world), @@ -437,7 +436,7 @@ void testCommandArguments() { ); worldReference.set(world); - FullCommandResult result = new Command( + CommandResult result = new Command( new LiteralCommandNode( "hello", List.of(world), @@ -470,7 +469,7 @@ void testCommandArguments() { ); worldReference.set(world); - FullCommandResult result = new Command( + CommandResult result = new Command( new LiteralCommandNode( "hello", List.of(world), diff --git a/commands/src/test/java/com/wizardlybump17/wlib/test/command/manager/CommandManagerTests.java b/commands/src/test/java/com/wizardlybump17/wlib/test/command/manager/CommandManagerTests.java index 05ad4aee..c3734118 100644 --- a/commands/src/test/java/com/wizardlybump17/wlib/test/command/manager/CommandManagerTests.java +++ b/commands/src/test/java/com/wizardlybump17/wlib/test/command/manager/CommandManagerTests.java @@ -7,7 +7,6 @@ import com.wizardlybump17.wlib.command.result.CommandResult; import com.wizardlybump17.wlib.command.result.SuccessResult; import com.wizardlybump17.wlib.command.result.error.CommandNotFoundResult; -import com.wizardlybump17.wlib.command.result.full.FullCommandResult; import com.wizardlybump17.wlib.command.sender.BasicCommandSender; import com.wizardlybump17.wlib.command.sender.CommandSender; import org.jetbrains.annotations.NotNull; @@ -322,8 +321,8 @@ void testCommandNotFound0() { CommandManager manager = new CommandManager(); manager.registerCommand("test", command); - FullCommandResult expected = new FullCommandResult(CHAD_SENDER, List.of("hello0"), 0, command.getRoot(), CommandResult.commandNotFound("hello0")); - FullCommandResult actual = manager.execute(CHAD_SENDER, List.of("hello0")); + CommandNotFoundResult expected = CommandResult.commandNotFound("hello0"); + CommandResult actual = manager.execute(CHAD_SENDER, List.of("hello0")); Assertions.assertEquals(expected, actual); } @@ -342,8 +341,8 @@ void testCommandNotFound1() { CommandManager manager = new CommandManager(); manager.registerCommand("test", command); - FullCommandResult expected = new FullCommandResult(CHAD_SENDER, List.of(), 0, CommandNotFoundResult.dummyNode(), CommandResult.commandNotFound("")); - FullCommandResult actual = manager.execute(CHAD_SENDER, List.of()); + CommandNotFoundResult expected = CommandResult.commandNotFound(""); + CommandResult actual = manager.execute(CHAD_SENDER, List.of()); Assertions.assertEquals(expected, actual); } @@ -381,7 +380,7 @@ void testSuccess0() { manager.registerCommand("test", command2); SuccessResult expected = CommandResult.successful(0, helloNode, "hello"); - FullCommandResult actual = manager.execute(CHAD_SENDER, List.of("hello")); + CommandResult actual = manager.execute(CHAD_SENDER, List.of("hello")); Assertions.assertEquals(expected, actual); } @@ -427,7 +426,7 @@ void testSuccess1() { manager.registerCommand("test", command2); SuccessResult expected = CommandResult.successful(1, thereNode, "hi there"); - FullCommandResult actual = manager.execute(CHAD_SENDER, List.of("hi", "there")); + CommandResult actual = manager.execute(CHAD_SENDER, List.of("hi", "there")); Assertions.assertEquals(expected, actual); } From 1f8bb8e0a15f0fab81c7f287506495021ba8ddb7 Mon Sep 17 00:00:00 2001 From: WizardlyBump17 Date: Mon, 15 Dec 2025 22:14:26 -0300 Subject: [PATCH 269/363] Revert "preparing the ground for the FullCommandResult" This reverts commit f35aa1134ac09b43255e09b7ef70c703036d9acb. --- .../wizardlybump17/wlib/command/Command.java | 27 +++++++++---------- .../wlib/command/manager/CommandManager.java | 12 ++++----- .../result/error/CommandNotFoundResult.java | 4 --- .../result/full/FullCommandResult.java | 11 -------- 4 files changed, 18 insertions(+), 36 deletions(-) delete mode 100644 commands/src/main/java/com/wizardlybump17/wlib/command/result/full/FullCommandResult.java diff --git a/commands/src/main/java/com/wizardlybump17/wlib/command/Command.java b/commands/src/main/java/com/wizardlybump17/wlib/command/Command.java index f5ed145e..076a96e8 100644 --- a/commands/src/main/java/com/wizardlybump17/wlib/command/Command.java +++ b/commands/src/main/java/com/wizardlybump17/wlib/command/Command.java @@ -7,7 +7,6 @@ import com.wizardlybump17.wlib.command.node.CommandNode; import com.wizardlybump17.wlib.command.node.LiteralCommandNode; import com.wizardlybump17.wlib.command.result.CommandResult; -import com.wizardlybump17.wlib.command.result.full.FullCommandResult; import com.wizardlybump17.wlib.command.sender.CommandSender; import com.wizardlybump17.wlib.command.suggestion.Suggester; import com.wizardlybump17.wlib.util.StringUtil; @@ -34,15 +33,15 @@ public Command(@NotNull LiteralCommandNode root) { return root; } - public @NotNull FullCommandResult execute(@NotNull CommandSender sender, @NotNull String input) { + public @NotNull CommandResult execute(@NotNull CommandSender sender, @NotNull String input) { List inputList = getInputList(input); return execute(sender, inputList); } @SuppressWarnings("unchecked") - public @NotNull FullCommandResult execute(@NotNull CommandSender sender, @NotNull List input) { + public @NotNull CommandResult execute(@NotNull CommandSender sender, @NotNull List input) { if (input.isEmpty()) - return new FullCommandResult(sender, List.of(), root, CommandResult.insufficientArguments(this)); + return CommandResult.insufficientArguments(this); List> arguments = new ArrayList<>(); List> children = List.of(root); @@ -79,20 +78,20 @@ public Command(@NotNull LiteralCommandNode root) { } if (lastParsingError != null) - return new FullCommandResult(sender, input, lastNode, CommandResult.parseInputException(lastInputIndex, lastNode, lastParsingError)); + return CommandResult.parseInputException(lastInputIndex, lastNode, lastParsingError); if (lastInputError != null) - return new FullCommandResult(sender, input, lastNode, CommandResult.outOfRangeInput(lastInputIndex, lastNode)); + return CommandResult.outOfRangeInput(lastInputIndex, lastNode); - return new FullCommandResult(sender, input, lastNode, CommandResult.extraArguments(lastInputIndex, lastNode)); + return CommandResult.extraArguments(lastInputIndex, lastNode); } CommandNodeExecutor executor = lastNode.getExecutor(); if (executor == null) - return new FullCommandResult(sender, input, lastNode, CommandResult.noCommandNodeExecutor(lastInputIndex, lastNode)); + return CommandResult.noCommandNodeExecutor(lastInputIndex, lastNode); String nodePermission = lastNode.getPermission(); if (nodePermission != null && !sender.hasPermission(nodePermission)) - return new FullCommandResult(sender, input, lastNode, CommandResult.noPermission(lastInputIndex, lastNode)); + return CommandResult.noPermission(lastInputIndex, lastNode); CommandContext context = new CommandContext( this, @@ -105,14 +104,14 @@ public Command(@NotNull LiteralCommandNode root) { try { CommandResult result = executor.execute(context); if (result == null) - return new FullCommandResult(sender, input, lastNode, CommandResult.exceptionally(lastInputIndex, lastNode, new NullPointerException("The CommandResult can not be null"))); + return CommandResult.exceptionally(lastInputIndex, lastNode, new NullPointerException("The CommandResult can not be null")); if (result.lastNode() == null) - return new FullCommandResult(sender, input, lastNode, CommandResult.genericError(lastInputIndex, lastNode, "The last node can not be null")); + return CommandResult.genericError(lastInputIndex, lastNode, "The last node can not be null"); if (result.lastInputIndex() < 0) - return new FullCommandResult(sender, input, lastNode, CommandResult.genericError(lastInputIndex, lastNode, "The last input index can not be less than 0")); - return new FullCommandResult(sender, input, lastNode, result); + return CommandResult.genericError(lastInputIndex, lastNode, "The last input index can not be less than 0"); + return result; } catch (Throwable throwable) { - return new FullCommandResult(sender, input, lastNode, CommandResult.exceptionally(lastInputIndex, lastNode, throwable)); + return CommandResult.exceptionally(lastInputIndex, lastNode, throwable); } } diff --git a/commands/src/main/java/com/wizardlybump17/wlib/command/manager/CommandManager.java b/commands/src/main/java/com/wizardlybump17/wlib/command/manager/CommandManager.java index b7909b56..74a719f5 100644 --- a/commands/src/main/java/com/wizardlybump17/wlib/command/manager/CommandManager.java +++ b/commands/src/main/java/com/wizardlybump17/wlib/command/manager/CommandManager.java @@ -4,8 +4,6 @@ import com.wizardlybump17.wlib.command.manager.listener.CommandManagerListener; import com.wizardlybump17.wlib.command.node.CommandNode; import com.wizardlybump17.wlib.command.result.CommandResult; -import com.wizardlybump17.wlib.command.result.error.CommandNotFoundResult; -import com.wizardlybump17.wlib.command.result.full.FullCommandResult; import com.wizardlybump17.wlib.command.sender.CommandSender; import com.wizardlybump17.wlib.util.StringUtil; import com.wizardlybump17.wlib.util.exception.QuotedStringException; @@ -76,9 +74,9 @@ protected void addCommand(@NotNull String identifier, @NotNull String name, @Not return left.merge(right); } - public @NotNull FullCommandResult execute(@NotNull CommandSender sender, @NotNull List input) { + public @NotNull CommandResult execute(@NotNull CommandSender sender, @NotNull List input) { if (input.isEmpty()) - return new FullCommandResult(sender, List.of(), CommandNotFoundResult.dummyNode(), CommandResult.commandNotFound("")); + return CommandResult.commandNotFound(""); String commandName = input.getFirst(); @@ -87,16 +85,16 @@ protected void addCommand(@NotNull String identifier, @NotNull String name, @Not if (command == null) command = commandsByName.get(commandName); if (command == null) - return new FullCommandResult(sender, input, CommandNotFoundResult.dummyNode(), CommandResult.commandNotFound(commandName)); + return CommandResult.commandNotFound(commandName); return command.execute(sender, input); } - public @NotNull FullCommandResult execute(@NotNull CommandSender sender, @NotNull String input) { + public @NotNull CommandResult execute(@NotNull CommandSender sender, @NotNull String input) { return execute(sender, StringUtil.parseQuotedStrings(input)); } - public @NotNull FullCommandResult execute(@NotNull CommandSender sender, @NotNull String @NotNull [] input) { + public @NotNull CommandResult execute(@NotNull CommandSender sender, @NotNull String @NotNull [] input) { return execute(sender, String.join(" ", input)); } diff --git a/commands/src/main/java/com/wizardlybump17/wlib/command/result/error/CommandNotFoundResult.java b/commands/src/main/java/com/wizardlybump17/wlib/command/result/error/CommandNotFoundResult.java index ea3843b9..27bbe154 100644 --- a/commands/src/main/java/com/wizardlybump17/wlib/command/result/error/CommandNotFoundResult.java +++ b/commands/src/main/java/com/wizardlybump17/wlib/command/result/error/CommandNotFoundResult.java @@ -19,10 +19,6 @@ public int lastInputIndex() { return DummyNode.INSTANCE; } - public static @NotNull CommandNode dummyNode() { - return DummyNode.INSTANCE; - } - private static final class DummyNode extends CommandNode { public static final @NotNull DummyNode INSTANCE = new DummyNode(); diff --git a/commands/src/main/java/com/wizardlybump17/wlib/command/result/full/FullCommandResult.java b/commands/src/main/java/com/wizardlybump17/wlib/command/result/full/FullCommandResult.java deleted file mode 100644 index c53afb12..00000000 --- a/commands/src/main/java/com/wizardlybump17/wlib/command/result/full/FullCommandResult.java +++ /dev/null @@ -1,11 +0,0 @@ -package com.wizardlybump17.wlib.command.result.full; - -import com.wizardlybump17.wlib.command.node.CommandNode; -import com.wizardlybump17.wlib.command.result.CommandResult; -import com.wizardlybump17.wlib.command.sender.CommandSender; -import org.jetbrains.annotations.NotNull; - -import java.util.List; - -public record FullCommandResult(@NotNull CommandSender sender, @NotNull List input, @NotNull CommandNode lastNode, @NotNull CommandResult result) { -} From 8bfcc3f4ba2e1eb0b8ed98f688b7857db52e9361 Mon Sep 17 00:00:00 2001 From: WizardlyBump17 Date: Mon, 15 Dec 2025 23:27:47 -0300 Subject: [PATCH 270/363] added the SuggesterException --- .../wizardlybump17/wlib/command/Command.java | 5 +++-- .../command/exception/SuggesterException.java | 21 +++++++++++++++++++ .../wlib/command/manager/CommandManager.java | 7 ++++--- .../wlib/command/node/CommandNode.java | 3 ++- .../wlib/command/suggestion/Suggester.java | 3 ++- 5 files changed, 32 insertions(+), 7 deletions(-) create mode 100644 commands/src/main/java/com/wizardlybump17/wlib/command/exception/SuggesterException.java diff --git a/commands/src/main/java/com/wizardlybump17/wlib/command/Command.java b/commands/src/main/java/com/wizardlybump17/wlib/command/Command.java index 076a96e8..b444ff84 100644 --- a/commands/src/main/java/com/wizardlybump17/wlib/command/Command.java +++ b/commands/src/main/java/com/wizardlybump17/wlib/command/Command.java @@ -3,6 +3,7 @@ import com.wizardlybump17.wlib.command.context.CommandContext; import com.wizardlybump17.wlib.command.exception.InputParsingException; import com.wizardlybump17.wlib.command.exception.InvalidInputException; +import com.wizardlybump17.wlib.command.exception.SuggesterException; import com.wizardlybump17.wlib.command.executor.CommandNodeExecutor; import com.wizardlybump17.wlib.command.node.CommandNode; import com.wizardlybump17.wlib.command.node.LiteralCommandNode; @@ -119,7 +120,7 @@ public Command(@NotNull LiteralCommandNode root) { return StringUtil.parseQuotedStrings(original); } - public @NotNull List getSuggestions(@NotNull CommandSender sender, @NotNull List input) { + public @NotNull List getSuggestions(@NotNull CommandSender sender, @NotNull List input) throws SuggesterException { if (input.isEmpty()) return List.of(root.getName()); @@ -186,7 +187,7 @@ public Command(@NotNull LiteralCommandNode root) { } @SuppressWarnings("unchecked") - private static @NotNull List getSuggestions0(@NotNull CommandNode node, @NotNull CommandSender sender, @NotNull List input, @NotNull String currentInput) { + private static @NotNull List getSuggestions0(@NotNull CommandNode node, @NotNull CommandSender sender, @NotNull List input, @NotNull String currentInput) throws SuggesterException { List childSuggestions = node.getSuggestions(sender, input, currentInput); Suggester suggester = (Suggester) node.getSuggester(); diff --git a/commands/src/main/java/com/wizardlybump17/wlib/command/exception/SuggesterException.java b/commands/src/main/java/com/wizardlybump17/wlib/command/exception/SuggesterException.java new file mode 100644 index 00000000..92c90364 --- /dev/null +++ b/commands/src/main/java/com/wizardlybump17/wlib/command/exception/SuggesterException.java @@ -0,0 +1,21 @@ +package com.wizardlybump17.wlib.command.exception; + +import org.jetbrains.annotations.NotNull; + +public class SuggesterException extends Exception { + + public SuggesterException() { + } + + public SuggesterException(@NotNull String message) { + super(message); + } + + public SuggesterException(@NotNull String message, @NotNull Throwable cause) { + super(message, cause); + } + + public SuggesterException(@NotNull Throwable cause) { + super(cause); + } +} diff --git a/commands/src/main/java/com/wizardlybump17/wlib/command/manager/CommandManager.java b/commands/src/main/java/com/wizardlybump17/wlib/command/manager/CommandManager.java index 74a719f5..e211f049 100644 --- a/commands/src/main/java/com/wizardlybump17/wlib/command/manager/CommandManager.java +++ b/commands/src/main/java/com/wizardlybump17/wlib/command/manager/CommandManager.java @@ -1,6 +1,7 @@ package com.wizardlybump17.wlib.command.manager; import com.wizardlybump17.wlib.command.Command; +import com.wizardlybump17.wlib.command.exception.SuggesterException; import com.wizardlybump17.wlib.command.manager.listener.CommandManagerListener; import com.wizardlybump17.wlib.command.node.CommandNode; import com.wizardlybump17.wlib.command.result.CommandResult; @@ -98,7 +99,7 @@ protected void addCommand(@NotNull String identifier, @NotNull String name, @Not return execute(sender, String.join(" ", input)); } - public @NotNull List getSuggestions(@NotNull CommandSender sender, @NotNull List input) { + public @NotNull List getSuggestions(@NotNull CommandSender sender, @NotNull List input) throws SuggesterException { if (input.isEmpty() || input.size() == 1) { return commandsByName.values().stream() .map(Command::getRoot) @@ -119,7 +120,7 @@ protected void addCommand(@NotNull String identifier, @NotNull String name, @Not return command.getSuggestions(sender, input); } - public @NotNull List getSuggestions(@NotNull CommandSender sender, @NotNull String input) { + public @NotNull List getSuggestions(@NotNull CommandSender sender, @NotNull String input) throws SuggesterException { try { if (!input.isEmpty() && !StringUtil.isProperlyQuoted(input)) input = input + "\""; @@ -129,7 +130,7 @@ protected void addCommand(@NotNull String identifier, @NotNull String name, @Not } } - public @NotNull List getSuggestions(@NotNull CommandSender sender, @NotNull String @NotNull [] input) { + public @NotNull List getSuggestions(@NotNull CommandSender sender, @NotNull String @NotNull [] input) throws SuggesterException { return getSuggestions(sender, String.join(" ", input)); } diff --git a/commands/src/main/java/com/wizardlybump17/wlib/command/node/CommandNode.java b/commands/src/main/java/com/wizardlybump17/wlib/command/node/CommandNode.java index aba682f0..8cf9cf3d 100644 --- a/commands/src/main/java/com/wizardlybump17/wlib/command/node/CommandNode.java +++ b/commands/src/main/java/com/wizardlybump17/wlib/command/node/CommandNode.java @@ -2,6 +2,7 @@ import com.wizardlybump17.wlib.command.exception.InputParsingException; import com.wizardlybump17.wlib.command.exception.InvalidInputException; +import com.wizardlybump17.wlib.command.exception.SuggesterException; import com.wizardlybump17.wlib.command.executor.CommandNodeExecutor; import com.wizardlybump17.wlib.command.input.AllowedInputs; import com.wizardlybump17.wlib.command.sender.CommandSender; @@ -60,7 +61,7 @@ public final boolean isValidInput(@Nullable T input) { return parse; } - public @NotNull List getSuggestions(@NotNull CommandSender sender, @NotNull List args, @NotNull String currentInput) { + public @NotNull List getSuggestions(@NotNull CommandSender sender, @NotNull List args, @NotNull String currentInput) throws SuggesterException { return suggester == null ? List.of() : suggester.getSuggestions(sender, args, currentInput, this); } diff --git a/commands/src/main/java/com/wizardlybump17/wlib/command/suggestion/Suggester.java b/commands/src/main/java/com/wizardlybump17/wlib/command/suggestion/Suggester.java index dcb79b27..8d64f81c 100644 --- a/commands/src/main/java/com/wizardlybump17/wlib/command/suggestion/Suggester.java +++ b/commands/src/main/java/com/wizardlybump17/wlib/command/suggestion/Suggester.java @@ -1,5 +1,6 @@ package com.wizardlybump17.wlib.command.suggestion; +import com.wizardlybump17.wlib.command.exception.SuggesterException; import com.wizardlybump17.wlib.command.node.CommandNode; import com.wizardlybump17.wlib.command.sender.CommandSender; import org.jetbrains.annotations.NotNull; @@ -8,7 +9,7 @@ public interface Suggester { - @NotNull List getSuggestions(@NotNull CommandSender sender, @NotNull List input, @NotNull String current, @NotNull CommandNode currentNode); + @NotNull List getSuggestions(@NotNull CommandSender sender, @NotNull List input, @NotNull String current, @NotNull CommandNode currentNode) throws SuggesterException; default @NotNull String getStringRepresentation(@NotNull T value) { return value.toString(); From c97d9995269596d71b8efaecc5d97c307b6d19b1 Mon Sep 17 00:00:00 2001 From: WizardlyBump17 Date: Mon, 15 Dec 2025 23:34:13 -0300 Subject: [PATCH 271/363] handling the SuggesterException --- .../wlib/test/command/SuggestionTests.java | 118 +++++++++--------- .../CommandManagerSuggestionTests.java | 34 ++--- .../wlib/command/WLibCommandExecutor.java | 14 ++- 3 files changed, 86 insertions(+), 80 deletions(-) diff --git a/commands/src/test/java/com/wizardlybump17/wlib/test/command/SuggestionTests.java b/commands/src/test/java/com/wizardlybump17/wlib/test/command/SuggestionTests.java index c522ae9d..88a872b5 100644 --- a/commands/src/test/java/com/wizardlybump17/wlib/test/command/SuggestionTests.java +++ b/commands/src/test/java/com/wizardlybump17/wlib/test/command/SuggestionTests.java @@ -49,7 +49,7 @@ void testSuccess0() { ); List expected = List.of("hello"); - List actual = command.getSuggestions(CHAD_SENDER, List.of()); + List actual = Assertions.assertDoesNotThrow(() -> command.getSuggestions(CHAD_SENDER, List.of())); Assertions.assertEquals(expected, actual); } @@ -74,7 +74,7 @@ void testSuccess1() { ); List expected = List.of("hello"); - List actual = command.getSuggestions(CHAD_SENDER, List.of("he")); + List actual = Assertions.assertDoesNotThrow(() -> command.getSuggestions(CHAD_SENDER, List.of("he"))); Assertions.assertEquals(expected, actual); } @@ -111,7 +111,7 @@ void testSuccess2() { ); List expected = List.of("world", "hi", "there"); - List actual = command.getSuggestions(CHAD_SENDER, List.of("hello", "")); + List actual = Assertions.assertDoesNotThrow(() -> command.getSuggestions(CHAD_SENDER, List.of("hello", ""))); Assertions.assertEquals(expected, actual); } @@ -150,7 +150,7 @@ void testSuccess3() { ); List expected = List.of("world", "hi", "1", "3", "5", "7", "10"); - List actual = command.getSuggestions(CHAD_SENDER, List.of("hello", "")); + List actual = Assertions.assertDoesNotThrow(() -> command.getSuggestions(CHAD_SENDER, List.of("hello", ""))); Assertions.assertEquals(expected, actual); } @@ -195,7 +195,7 @@ void testSuccess4() { ); List expected = List.of("world", "hi", "1", "3", "5", "7", "10", "happy"); - List actual = command.getSuggestions(CHAD_SENDER, List.of("hello", "h")); + List actual = Assertions.assertDoesNotThrow(() -> command.getSuggestions(CHAD_SENDER, List.of("hello", "h"))); Assertions.assertEquals(expected, actual); } @@ -205,42 +205,42 @@ void testDefaultSuggestions() { //literal Assertions.assertEquals( List.of("hello"), - new Command( + Assertions.assertDoesNotThrow(() -> new Command( new LiteralCommandNode( "hello", List.of(), null, null ) - ).getSuggestions(CHAD_SENDER, List.of()) + ).getSuggestions(CHAD_SENDER, List.of())) ); Assertions.assertEquals( List.of("hello"), - new Command( + Assertions.assertDoesNotThrow(() -> new Command( new LiteralCommandNode( "hello", List.of(), null, null ) - ).getSuggestions(CHAD_SENDER, List.of("")) + ).getSuggestions(CHAD_SENDER, List.of(""))) ); Assertions.assertEquals( List.of("hello"), - new Command( + Assertions.assertDoesNotThrow(() -> new Command( new LiteralCommandNode( "hello", List.of(), null, null ) - ).getSuggestions(CHAD_SENDER, List.of("hel")) + ).getSuggestions(CHAD_SENDER, List.of("hel"))) ); //byte Assertions.assertEquals( List.of("-128", "-100", "-50", "0", "50", "100", "127"), - new Command( + Assertions.assertDoesNotThrow(() -> new Command( new LiteralCommandNode( "hello", List.of( @@ -256,11 +256,11 @@ void testDefaultSuggestions() { null, null ) - ).getSuggestions(CHAD_SENDER, List.of("hello", "")) + ).getSuggestions(CHAD_SENDER, List.of("hello", ""))) ); Assertions.assertEquals( List.of("-128", "-100", "-50", "0", "50", "100", "127"), - new Command( + Assertions.assertDoesNotThrow(() -> new Command( new LiteralCommandNode( "hello", List.of( @@ -276,11 +276,11 @@ void testDefaultSuggestions() { null, null ) - ).getSuggestions(CHAD_SENDER, List.of("hello", "0")) + ).getSuggestions(CHAD_SENDER, List.of("hello", "0"))) ); Assertions.assertEquals( List.of("-128", "-100", "-50", "0", "50", "100", "127"), - new Command( + Assertions.assertDoesNotThrow(() -> new Command( new LiteralCommandNode( "hello", List.of( @@ -296,13 +296,13 @@ void testDefaultSuggestions() { null, null ) - ).getSuggestions(CHAD_SENDER, List.of("hello", "10")) + ).getSuggestions(CHAD_SENDER, List.of("hello", "10"))) ); //short Assertions.assertEquals( List.of("-32768", "-3000", "-100", "-50", "0", "50", "100", "3000", "32767"), - new Command( + Assertions.assertDoesNotThrow(() -> new Command( new LiteralCommandNode( "hello", List.of( @@ -318,11 +318,11 @@ void testDefaultSuggestions() { null, null ) - ).getSuggestions(CHAD_SENDER, List.of("hello", "")) + ).getSuggestions(CHAD_SENDER, List.of("hello", ""))) ); Assertions.assertEquals( List.of("-32768", "-3000", "-100", "-50", "0", "50", "100", "3000", "32767"), - new Command( + Assertions.assertDoesNotThrow(() -> new Command( new LiteralCommandNode( "hello", List.of( @@ -338,11 +338,11 @@ void testDefaultSuggestions() { null, null ) - ).getSuggestions(CHAD_SENDER, List.of("hello", "0")) + ).getSuggestions(CHAD_SENDER, List.of("hello", "0"))) ); Assertions.assertEquals( List.of("-32768", "-3000", "-100", "-50", "0", "50", "100", "3000", "32767"), - new Command( + Assertions.assertDoesNotThrow(() -> new Command( new LiteralCommandNode( "hello", List.of( @@ -358,13 +358,13 @@ void testDefaultSuggestions() { null, null ) - ).getSuggestions(CHAD_SENDER, List.of("hello", "10")) + ).getSuggestions(CHAD_SENDER, List.of("hello", "10"))) ); //int Assertions.assertEquals( List.of("-100000", "-50000", "-3000", "-200", "-50", "0", "50", "200", "3000", "50000", "100000"), - new Command( + Assertions.assertDoesNotThrow(() -> new Command( new LiteralCommandNode( "hello", List.of( @@ -380,11 +380,11 @@ void testDefaultSuggestions() { null, null ) - ).getSuggestions(CHAD_SENDER, List.of("hello", "")) + ).getSuggestions(CHAD_SENDER, List.of("hello", ""))) ); Assertions.assertEquals( List.of("-100000", "-50000", "-3000", "-200", "-50", "0", "50", "200", "3000", "50000", "100000"), - new Command( + Assertions.assertDoesNotThrow(() -> new Command( new LiteralCommandNode( "hello", List.of( @@ -400,11 +400,11 @@ void testDefaultSuggestions() { null, null ) - ).getSuggestions(CHAD_SENDER, List.of("hello", "0")) + ).getSuggestions(CHAD_SENDER, List.of("hello", "0"))) ); Assertions.assertEquals( List.of("-100000", "-50000", "-3000", "-200", "-50", "0", "50", "200", "3000", "50000", "100000"), - new Command( + Assertions.assertDoesNotThrow(() -> new Command( new LiteralCommandNode( "hello", List.of( @@ -420,13 +420,13 @@ void testDefaultSuggestions() { null, null ) - ).getSuggestions(CHAD_SENDER, List.of("hello", "10")) + ).getSuggestions(CHAD_SENDER, List.of("hello", "10"))) ); //long Assertions.assertEquals( List.of("-100000", "-50000", "-3000", "-200", "-50", "0", "50", "200", "3000", "50000", "100000"), - new Command( + Assertions.assertDoesNotThrow(() -> new Command( new LiteralCommandNode( "hello", List.of( @@ -442,11 +442,11 @@ void testDefaultSuggestions() { null, null ) - ).getSuggestions(CHAD_SENDER, List.of("hello", "")) + ).getSuggestions(CHAD_SENDER, List.of("hello", ""))) ); Assertions.assertEquals( List.of("-100000", "-50000", "-3000", "-200", "-50", "0", "50", "200", "3000", "50000", "100000"), - new Command( + Assertions.assertDoesNotThrow(() -> new Command( new LiteralCommandNode( "hello", List.of( @@ -462,11 +462,11 @@ void testDefaultSuggestions() { null, null ) - ).getSuggestions(CHAD_SENDER, List.of("hello", "0")) + ).getSuggestions(CHAD_SENDER, List.of("hello", "0"))) ); Assertions.assertEquals( List.of("-100000", "-50000", "-3000", "-200", "-50", "0", "50", "200", "3000", "50000", "100000"), - new Command( + Assertions.assertDoesNotThrow(() -> new Command( new LiteralCommandNode( "hello", List.of( @@ -482,13 +482,13 @@ void testDefaultSuggestions() { null, null ) - ).getSuggestions(CHAD_SENDER, List.of("hello", "10")) + ).getSuggestions(CHAD_SENDER, List.of("hello", "10"))) ); //float Assertions.assertEquals( List.of("-100000.5", "-50000.5", "-3000.5", "-200.5", "-50.5", "0.0", "50.5", "200.5", "3000.5", "50000.5", "100000.5"), - new Command( + Assertions.assertDoesNotThrow(() -> new Command( new LiteralCommandNode( "hello", List.of( @@ -504,11 +504,11 @@ void testDefaultSuggestions() { null, null ) - ).getSuggestions(CHAD_SENDER, List.of("hello", "")) + ).getSuggestions(CHAD_SENDER, List.of("hello", ""))) ); Assertions.assertEquals( List.of("-100000.5", "-50000.5", "-3000.5", "-200.5", "-50.5", "0.0", "50.5", "200.5", "3000.5", "50000.5", "100000.5"), - new Command( + Assertions.assertDoesNotThrow(() -> new Command( new LiteralCommandNode( "hello", List.of( @@ -524,11 +524,11 @@ void testDefaultSuggestions() { null, null ) - ).getSuggestions(CHAD_SENDER, List.of("hello", "0")) + ).getSuggestions(CHAD_SENDER, List.of("hello", "0"))) ); Assertions.assertEquals( List.of("-100000.5", "-50000.5", "-3000.5", "-200.5", "-50.5", "0.0", "50.5", "200.5", "3000.5", "50000.5", "100000.5"), - new Command( + Assertions.assertDoesNotThrow(() -> new Command( new LiteralCommandNode( "hello", List.of( @@ -544,13 +544,13 @@ void testDefaultSuggestions() { null, null ) - ).getSuggestions(CHAD_SENDER, List.of("hello", "10")) + ).getSuggestions(CHAD_SENDER, List.of("hello", "10"))) ); //double Assertions.assertEquals( List.of("-100000.5", "-50000.5", "-3000.5", "-200.5", "-50.5", "0.0", "50.5", "200.5", "3000.5", "50000.5", "100000.5"), - new Command( + Assertions.assertDoesNotThrow(() -> new Command( new LiteralCommandNode( "hello", List.of( @@ -566,11 +566,11 @@ void testDefaultSuggestions() { null, null ) - ).getSuggestions(CHAD_SENDER, List.of("hello", "")) + ).getSuggestions(CHAD_SENDER, List.of("hello", ""))) ); Assertions.assertEquals( List.of("-100000.5", "-50000.5", "-3000.5", "-200.5", "-50.5", "0.0", "50.5", "200.5", "3000.5", "50000.5", "100000.5"), - new Command( + Assertions.assertDoesNotThrow(() -> new Command( new LiteralCommandNode( "hello", List.of( @@ -586,11 +586,11 @@ void testDefaultSuggestions() { null, null ) - ).getSuggestions(CHAD_SENDER, List.of("hello", "0")) + ).getSuggestions(CHAD_SENDER, List.of("hello", "0"))) ); Assertions.assertEquals( List.of("-100000.5", "-50000.5", "-3000.5", "-200.5", "-50.5", "0.0", "50.5", "200.5", "3000.5", "50000.5", "100000.5"), - new Command( + Assertions.assertDoesNotThrow(() -> new Command( new LiteralCommandNode( "hello", List.of( @@ -606,13 +606,13 @@ void testDefaultSuggestions() { null, null ) - ).getSuggestions(CHAD_SENDER, List.of("hello", "10")) + ).getSuggestions(CHAD_SENDER, List.of("hello", "10"))) ); //String Assertions.assertEquals( List.of(""), - new Command( + Assertions.assertDoesNotThrow(() -> new Command( new LiteralCommandNode( "hello", List.of( @@ -628,11 +628,11 @@ void testDefaultSuggestions() { null, null ) - ).getSuggestions(CHAD_SENDER, List.of("hello", "")) + ).getSuggestions(CHAD_SENDER, List.of("hello", ""))) ); Assertions.assertEquals( List.of("wo"), - new Command( + Assertions.assertDoesNotThrow(() -> new Command( new LiteralCommandNode( "hello", List.of( @@ -648,11 +648,11 @@ void testDefaultSuggestions() { null, null ) - ).getSuggestions(CHAD_SENDER, List.of("hello", "wo")) + ).getSuggestions(CHAD_SENDER, List.of("hello", "wo"))) ); Assertions.assertEquals( List.of("spaced "), - new Command( + Assertions.assertDoesNotThrow(() -> new Command( new LiteralCommandNode( "hello", List.of( @@ -668,11 +668,11 @@ void testDefaultSuggestions() { null, null ) - ).getSuggestions(CHAD_SENDER, List.of("hello", "spaced ")) + ).getSuggestions(CHAD_SENDER, List.of("hello", "spaced "))) ); Assertions.assertEquals( List.of("spaced string"), - new Command( + Assertions.assertDoesNotThrow(() -> new Command( new LiteralCommandNode( "hello", List.of( @@ -688,13 +688,13 @@ void testDefaultSuggestions() { null, null ) - ).getSuggestions(CHAD_SENDER, List.of("hello", "spaced string")) + ).getSuggestions(CHAD_SENDER, List.of("hello", "spaced string"))) ); //UUID Assertions.assertEquals( List.of("9b07bd8a-a4c0-3681-997f-6b6df78c0abe", "2931e955-084c-3d9e-aea4-8e5c2c1089c1", "2931e955-084c-3d9e-aea4-8e5c2c1089c1"), - new Command( + Assertions.assertDoesNotThrow(() -> new Command( new LiteralCommandNode( "hello", List.of( @@ -714,11 +714,11 @@ void testDefaultSuggestions() { null, null ) - ).getSuggestions(CHAD_SENDER, List.of("hello", "")) + ).getSuggestions(CHAD_SENDER, List.of("hello", ""))) ); Assertions.assertEquals( List.of("9b07bd8a-a4c0-3681-997f-6b6df78c0abe", "2931e955-084c-3d9e-aea4-8e5c2c1089c1", "2931e955-084c-3d9e-aea4-8e5c2c1089c1"), - new Command( + Assertions.assertDoesNotThrow(() -> new Command( new LiteralCommandNode( "hello", List.of( @@ -738,7 +738,7 @@ void testDefaultSuggestions() { null, null ) - ).getSuggestions(CHAD_SENDER, List.of("hello", "9b07bd8a-a4c0")) + ).getSuggestions(CHAD_SENDER, List.of("hello", "9b07bd8a-a4c0"))) ); } } diff --git a/commands/src/test/java/com/wizardlybump17/wlib/test/command/manager/CommandManagerSuggestionTests.java b/commands/src/test/java/com/wizardlybump17/wlib/test/command/manager/CommandManagerSuggestionTests.java index de8f32dc..81963a7e 100644 --- a/commands/src/test/java/com/wizardlybump17/wlib/test/command/manager/CommandManagerSuggestionTests.java +++ b/commands/src/test/java/com/wizardlybump17/wlib/test/command/manager/CommandManagerSuggestionTests.java @@ -64,7 +64,7 @@ void testSuggestionsSuccessListChad0() { manager.registerCommand("test", command2); List expected = List.of("hello", "hi", "welcome"); - List actual = manager.getSuggestions(CHAD_SENDER, List.of()); + List actual = Assertions.assertDoesNotThrow(() -> manager.getSuggestions(CHAD_SENDER, List.of())); Assertions.assertTrue(CollectionUtil.contentEquals(expected, actual)); } @@ -109,7 +109,7 @@ void testSuggestionsSuccessListChad1() { manager.registerCommand("test", command2); List expected = List.of("hello", "hi", "welcome"); - List actual = manager.getSuggestions(CHAD_SENDER, List.of("he")); + List actual = Assertions.assertDoesNotThrow(() -> manager.getSuggestions(CHAD_SENDER, List.of("he"))); Assertions.assertTrue(CollectionUtil.contentEquals(expected, actual)); } @@ -154,7 +154,7 @@ void testSuggestionsSuccessListChad2() { manager.registerCommand("test", command2); List expected = List.of("there"); - List actual = manager.getSuggestions(CHAD_SENDER, List.of("hi", "")); + List actual = Assertions.assertDoesNotThrow(() -> manager.getSuggestions(CHAD_SENDER, List.of("hi", ""))); Assertions.assertTrue(CollectionUtil.contentEquals(expected, actual)); } @@ -199,7 +199,7 @@ void testSuggestionsSuccessListChad3() { manager.registerCommand("test", command2); List expected = List.of("there"); - List actual = manager.getSuggestions(CHAD_SENDER, List.of("hi", "ther")); + List actual = Assertions.assertDoesNotThrow(() -> manager.getSuggestions(CHAD_SENDER, List.of("hi", "ther"))); Assertions.assertTrue(CollectionUtil.contentEquals(expected, actual)); } @@ -253,7 +253,7 @@ void testSuggestionsSuccessListChad4() { manager.registerCommand("test", command2); List expected = List.of("0", "50", "200", "3000", "50000", "100000"); - List actual = manager.getSuggestions(CHAD_SENDER, List.of("welcome", "")); + List actual = Assertions.assertDoesNotThrow(() -> manager.getSuggestions(CHAD_SENDER, List.of("welcome", ""))); Assertions.assertEquals(expected, actual); } @@ -307,7 +307,7 @@ void testSuggestionsSuccessListChad6() { manager.registerCommand("test", command2); List expected = List.of("0", "50", "200", "3000", "50000", "100000"); - List actual = manager.getSuggestions(CHAD_SENDER, List.of("welcome", "10")); + List actual = Assertions.assertDoesNotThrow(() -> manager.getSuggestions(CHAD_SENDER, List.of("welcome", "10"))); Assertions.assertTrue(CollectionUtil.contentEquals(expected, actual)); } @@ -352,7 +352,7 @@ void testSuggestionsFailListBeta0() { manager.registerCommand("test", command2); List expected = List.of(); - List actual = manager.getSuggestions(BETA_SENDER, List.of()); + List actual = Assertions.assertDoesNotThrow(() -> manager.getSuggestions(BETA_SENDER, List.of())); Assertions.assertTrue(CollectionUtil.contentEquals(expected, actual)); } @@ -406,7 +406,7 @@ void testSuggestionsSuccessStringChad0() { manager.registerCommand("test", command2); List expected = List.of("hi", "hello", "welcome"); - List actual = manager.getSuggestions(CHAD_SENDER, ""); + List actual = Assertions.assertDoesNotThrow(() -> manager.getSuggestions(CHAD_SENDER, "")); Assertions.assertEquals(expected, actual); } @@ -460,7 +460,7 @@ void testSuggestionsSuccessStringChad1() { manager.registerCommand("test", command2); List expected = List.of("there"); - List actual = manager.getSuggestions(CHAD_SENDER, "hi t"); + List actual = Assertions.assertDoesNotThrow(() -> manager.getSuggestions(CHAD_SENDER, "hi t")); Assertions.assertEquals(expected, actual); } @@ -514,7 +514,7 @@ void testSuggestionsSuccessStringChad2() { manager.registerCommand("test", command2); List expected = List.of("0", "50", "200", "3000", "50000", "100000"); - List actual = manager.getSuggestions(CHAD_SENDER, "welcome 1"); + List actual = Assertions.assertDoesNotThrow(() -> manager.getSuggestions(CHAD_SENDER, "welcome 1")); Assertions.assertEquals(expected, actual); } @@ -584,7 +584,7 @@ void testSuggestionsSuccessStringChad3() { manager.registerCommand("test", command3); List expected = List.of("spaced string"); - List actual = manager.getSuggestions(CHAD_SENDER, "test \"spaced "); + List actual = Assertions.assertDoesNotThrow(() -> manager.getSuggestions(CHAD_SENDER, "test \"spaced ")); Assertions.assertEquals(expected, actual); } @@ -654,7 +654,7 @@ void testSuggestionsSuccessStringArrayChad0() { manager.registerCommand("test", command3); List expected = List.of("hi", "test", "hello", "welcome"); - List actual = manager.getSuggestions(CHAD_SENDER, new String[]{}); + List actual = Assertions.assertDoesNotThrow(() -> manager.getSuggestions(CHAD_SENDER, new String[]{})); Assertions.assertEquals(expected, actual); } @@ -724,7 +724,7 @@ void testSuggestionsSuccessStringArrayChad1() { manager.registerCommand("test", command3); List expected = List.of("hi", "test", "hello", "welcome"); - List actual = manager.getSuggestions(CHAD_SENDER, new String[]{"he"}); + List actual = Assertions.assertDoesNotThrow(() -> manager.getSuggestions(CHAD_SENDER, new String[]{"he"})); Assertions.assertEquals(expected, actual); } @@ -794,7 +794,7 @@ void testSuggestionsSuccessStringArrayChad2() { manager.registerCommand("test", command3); List expected = List.of("0", "50", "200", "3000", "50000", "100000"); - List actual = manager.getSuggestions(CHAD_SENDER, new String[]{"welcome", ""}); + List actual = Assertions.assertDoesNotThrow(() -> manager.getSuggestions(CHAD_SENDER, new String[]{"welcome", ""})); Assertions.assertEquals(expected, actual); } @@ -864,7 +864,7 @@ void testSuggestionsSuccessStringArrayChad3() { manager.registerCommand("test", command3); List expected = List.of("spaced string"); - List actual = manager.getSuggestions(CHAD_SENDER, new String[]{"test", ""}); + List actual = Assertions.assertDoesNotThrow(() -> manager.getSuggestions(CHAD_SENDER, new String[]{"test", ""})); Assertions.assertEquals(expected, actual); } @@ -934,7 +934,7 @@ void testSuggestionsSuccessStringArrayChad4() { manager.registerCommand("test", command3); List expected = List.of("spaced string"); - List actual = manager.getSuggestions(CHAD_SENDER, new String[]{"test", "spaced"}); + List actual = Assertions.assertDoesNotThrow(() -> manager.getSuggestions(CHAD_SENDER, new String[]{"test", "spaced"})); Assertions.assertEquals(expected, actual); } @@ -1004,7 +1004,7 @@ void testSuggestionsSuccessStringArrayChad5() { manager.registerCommand("test", command3); List expected = List.of("spaced string"); - List actual = manager.getSuggestions(CHAD_SENDER, new String[]{"test", "\"space"}); + List actual = Assertions.assertDoesNotThrow(() -> manager.getSuggestions(CHAD_SENDER, new String[]{"test", "\"space"})); Assertions.assertEquals(expected, actual); } diff --git a/core/src/main/java/com/wizardlybump17/wlib/command/WLibCommandExecutor.java b/core/src/main/java/com/wizardlybump17/wlib/command/WLibCommandExecutor.java index c3e91f3d..e75c7522 100644 --- a/core/src/main/java/com/wizardlybump17/wlib/command/WLibCommandExecutor.java +++ b/core/src/main/java/com/wizardlybump17/wlib/command/WLibCommandExecutor.java @@ -1,5 +1,6 @@ package com.wizardlybump17.wlib.command; +import com.wizardlybump17.wlib.command.exception.SuggesterException; import com.wizardlybump17.wlib.command.manager.CommandManager; import com.wizardlybump17.wlib.command.result.CommandResult; import com.wizardlybump17.wlib.command.result.SuccessResult; @@ -76,9 +77,14 @@ public boolean onCommand(@NotNull CommandSender sender, @NotNull Command command String current = args.length == 1 ? args[0] : args[args.length - 1]; String currentLowerCase = current.toLowerCase(); - return commandManager.getSuggestions(wlibSender, wlibArgs) - .stream() - .filter(suggestion -> suggestion.toLowerCase().startsWith(currentLowerCase)) - .toList(); + try { + return commandManager.getSuggestions(wlibSender, wlibArgs) + .stream() + .filter(suggestion -> suggestion.toLowerCase().startsWith(currentLowerCase)) + .toList(); + } catch (SuggesterException e) { + logger.log(Level.SEVERE, "Error while getting suggestions for " + sender + ": " + wlibArgs, e); + return List.of(); + } } } From 9567ef612a28b35b2c0beb626ad203841094354c Mon Sep 17 00:00:00 2001 From: WizardlyBump17 Date: Mon, 15 Dec 2025 23:41:21 -0300 Subject: [PATCH 272/363] added the CachingSuggester --- .../command/suggestion/CachingSuggester.java | 62 +++++++++++++++++++ 1 file changed, 62 insertions(+) create mode 100644 commands/src/main/java/com/wizardlybump17/wlib/command/suggestion/CachingSuggester.java diff --git a/commands/src/main/java/com/wizardlybump17/wlib/command/suggestion/CachingSuggester.java b/commands/src/main/java/com/wizardlybump17/wlib/command/suggestion/CachingSuggester.java new file mode 100644 index 00000000..055041ed --- /dev/null +++ b/commands/src/main/java/com/wizardlybump17/wlib/command/suggestion/CachingSuggester.java @@ -0,0 +1,62 @@ +package com.wizardlybump17.wlib.command.suggestion; + +import com.wizardlybump17.wlib.command.exception.SuggesterException; +import com.wizardlybump17.wlib.command.node.CommandNode; +import com.wizardlybump17.wlib.command.sender.CommandSender; +import org.jetbrains.annotations.NotNull; +import org.jetbrains.annotations.UnmodifiableView; + +import java.util.Collections; +import java.util.List; + +public class CachingSuggester implements Suggester { + + public static final long DEFAULT_EXPIRATION_MILLIS = 30 * 1000; + + private final @NotNull Suggester delegate; + private final long expirationMillis; + private @NotNull @UnmodifiableView List cache = List.of(); + private long lastUpdateMillis; + + private CachingSuggester(@NotNull Suggester delegate, long expirationMillis) { + this.delegate = delegate; + this.expirationMillis = expirationMillis; + } + + @Override + public @NotNull List getSuggestions(@NotNull CommandSender sender, @NotNull List input, @NotNull String current, @NotNull CommandNode currentNode) throws SuggesterException { + if (lastUpdateMillis + expirationMillis >= System.currentTimeMillis()) { + List suggestions = delegate.getSuggestions(sender, input, current, currentNode); + cache = Collections.unmodifiableList(suggestions); + lastUpdateMillis = System.currentTimeMillis(); + return suggestions; + } + + return cache; + } + + @Override + public @NotNull String getStringRepresentation(@NotNull T value) { + return delegate.getStringRepresentation(value); + } + + public long expirationMillis() { + return expirationMillis; + } + + public @NotNull @UnmodifiableView List cache() { + return cache; + } + + private long lastUpdateMillis() { + return lastUpdateMillis; + } + + public static @NotNull CachingSuggester of(@NotNull Suggester suggester, long expirationMillis) { + return new CachingSuggester<>(suggester, expirationMillis); + } + + public static @NotNull CachingSuggester of(@NotNull Suggester suggester) { + return new CachingSuggester<>(suggester, DEFAULT_EXPIRATION_MILLIS); + } +} From e73d2688211c90bcb2eccf6b05fa2fcbd4881991 Mon Sep 17 00:00:00 2001 From: WizardlyBump17 Date: Tue, 16 Dec 2025 16:32:14 -0300 Subject: [PATCH 273/363] fixed the cache expiration check --- .../wlib/command/suggestion/CachingSuggester.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/commands/src/main/java/com/wizardlybump17/wlib/command/suggestion/CachingSuggester.java b/commands/src/main/java/com/wizardlybump17/wlib/command/suggestion/CachingSuggester.java index 055041ed..a64681ea 100644 --- a/commands/src/main/java/com/wizardlybump17/wlib/command/suggestion/CachingSuggester.java +++ b/commands/src/main/java/com/wizardlybump17/wlib/command/suggestion/CachingSuggester.java @@ -25,7 +25,7 @@ private CachingSuggester(@NotNull Suggester delegate, long expirationMillis) @Override public @NotNull List getSuggestions(@NotNull CommandSender sender, @NotNull List input, @NotNull String current, @NotNull CommandNode currentNode) throws SuggesterException { - if (lastUpdateMillis + expirationMillis >= System.currentTimeMillis()) { + if (lastUpdateMillis + expirationMillis <= System.currentTimeMillis()) { List suggestions = delegate.getSuggestions(sender, input, current, currentNode); cache = Collections.unmodifiableList(suggestions); lastUpdateMillis = System.currentTimeMillis(); From a026484e82bcb4d48e731391a32e82b45d40c697 Mon Sep 17 00:00:00 2001 From: WizardlyBump17 Date: Tue, 16 Dec 2025 22:27:17 -0300 Subject: [PATCH 274/363] added support for JsonElements --- core/build.gradle | 5 + .../java/com/wizardlybump17/wlib/WLib.java | 13 ++ .../JsonElementMethodCommandNodeFactory.java | 50 +++++++ .../input/AllowedJsonElementInputs.java | 132 ++++++++++++++++++ .../command/node/JsonElementCommandNode.java | 47 +++++++ .../suggestion/JsonElementSuggester.java | 116 +++++++++++++++ core/src/main/resources/plugin.yml | 1 + 7 files changed, 364 insertions(+) create mode 100644 core/src/main/java/com/wizardlybump17/wlib/command/extractor/method/factory/JsonElementMethodCommandNodeFactory.java create mode 100644 core/src/main/java/com/wizardlybump17/wlib/command/input/AllowedJsonElementInputs.java create mode 100644 core/src/main/java/com/wizardlybump17/wlib/command/node/JsonElementCommandNode.java create mode 100644 core/src/main/java/com/wizardlybump17/wlib/command/suggestion/JsonElementSuggester.java diff --git a/core/build.gradle b/core/build.gradle index b1570761..24f60d6c 100644 --- a/core/build.gradle +++ b/core/build.gradle @@ -1,3 +1,5 @@ +var gson = "2.13.2" + dependencies { compileOnly( 'org.projectlombok:lombok:1.18.32', @@ -24,11 +26,14 @@ dependencies { project(':config'), project(':bukkit-utils'), ) + + compileOnly("com.google.code.gson:gson:${gson}") } processResources { filesMatching('**/plugin.yml') { expand 'version': project.version + expand "gson": gson } } diff --git a/core/src/main/java/com/wizardlybump17/wlib/WLib.java b/core/src/main/java/com/wizardlybump17/wlib/WLib.java index 8324aeba..0ec0b6c0 100644 --- a/core/src/main/java/com/wizardlybump17/wlib/WLib.java +++ b/core/src/main/java/com/wizardlybump17/wlib/WLib.java @@ -1,11 +1,14 @@ package com.wizardlybump17.wlib; +import com.google.gson.Gson; +import com.google.gson.GsonBuilder; import com.wizardlybump17.wlib.adapter.AttributeAdapter; import com.wizardlybump17.wlib.adapter.ItemAdapter; import com.wizardlybump17.wlib.adapter.command.CommandMapAdapter; import com.wizardlybump17.wlib.adapter.player.PlayerAdapter; import com.wizardlybump17.wlib.command.WLibCommandExecutor; import com.wizardlybump17.wlib.command.extractor.method.MethodCommandExtractor; +import com.wizardlybump17.wlib.command.extractor.method.factory.JsonElementMethodCommandNodeFactory; import com.wizardlybump17.wlib.command.extractor.method.factory.OfflinePlayerMethodCommandNodeFactory; import com.wizardlybump17.wlib.command.extractor.method.factory.PlayerMethodCommandNodeFactory; import com.wizardlybump17.wlib.command.listener.BukkitCommandManagerListener; @@ -48,9 +51,12 @@ public class WLib extends JavaPlugin { private CommandManager commandManager; private WLibCommandExecutor commandExecutor; private BukkitCommandManagerListener commandManagerListener; + private Gson gson; @Override public void onLoad() { + gson = new GsonBuilder().create(); + initCommandSystem(); ItemMetaHandlerModel.initModels(); initAdapters(); @@ -70,6 +76,7 @@ private void initCommandSystem() { methodCommandNodeFactoryRegistry.registerDefaults(); methodCommandNodeFactoryRegistry.addFactory(new OfflinePlayerMethodCommandNodeFactory()); methodCommandNodeFactoryRegistry.addFactory(new PlayerMethodCommandNodeFactory()); + methodCommandNodeFactoryRegistry.addFactory(new JsonElementMethodCommandNodeFactory(gson)); commandManager = new CommandManager(); @@ -100,6 +107,8 @@ public void onEnable() { @Override public void onDisable() { + gson = null; + clearCommandSystem(); HandlerList.unregisterAll(this); saveControllersTask.cancel(); @@ -198,4 +207,8 @@ public MethodCommandNodeFactoryRegistry getMethodCommandNodeFactoryRegistry() { public CommandManager getCommandManager() { return commandManager; } + + public Gson getGson() { + return gson; + } } diff --git a/core/src/main/java/com/wizardlybump17/wlib/command/extractor/method/factory/JsonElementMethodCommandNodeFactory.java b/core/src/main/java/com/wizardlybump17/wlib/command/extractor/method/factory/JsonElementMethodCommandNodeFactory.java new file mode 100644 index 00000000..d03f7197 --- /dev/null +++ b/core/src/main/java/com/wizardlybump17/wlib/command/extractor/method/factory/JsonElementMethodCommandNodeFactory.java @@ -0,0 +1,50 @@ +package com.wizardlybump17.wlib.command.extractor.method.factory; + +import com.google.gson.Gson; +import com.google.gson.JsonElement; +import com.wizardlybump17.wlib.command.annotation.Command; +import com.wizardlybump17.wlib.command.input.AllowedJsonElementInputs; +import com.wizardlybump17.wlib.command.node.CommandNode; +import com.wizardlybump17.wlib.command.node.JsonElementCommandNode; +import org.jetbrains.annotations.NotNull; +import org.jetbrains.annotations.Nullable; + +import java.lang.reflect.Method; +import java.lang.reflect.Parameter; +import java.util.List; + +public class JsonElementMethodCommandNodeFactory extends MethodCommandNodeFactory { + + private final @NotNull Gson gson; + + public JsonElementMethodCommandNodeFactory(@NotNull Gson gson) { + this.gson = gson; + } + + @Override + public @NotNull JsonElementCommandNode create(@NotNull Object object, @NotNull Method method, @NotNull Command commandAnnotation, @NotNull Parameter parameter, @NotNull String name, @Nullable CommandNode root) { + return new JsonElementCommandNode( + name, + root == null ? List.of() : List.of(root), + parameter.isAnnotationPresent(NotNull.class) ? AllowedJsonElementInputs.anyNotNull() : AllowedJsonElementInputs.anyNullable(), + null, + null, + null, + gson + ); + } + + @Override + public @NotNull Class @NotNull [] getSupportedTypes() { + return new Class[] {JsonElement.class}; + } + + @Override + public boolean isStrict() { + return false; + } + + public @NotNull Gson getGson() { + return gson; + } +} diff --git a/core/src/main/java/com/wizardlybump17/wlib/command/input/AllowedJsonElementInputs.java b/core/src/main/java/com/wizardlybump17/wlib/command/input/AllowedJsonElementInputs.java new file mode 100644 index 00000000..465c63dd --- /dev/null +++ b/core/src/main/java/com/wizardlybump17/wlib/command/input/AllowedJsonElementInputs.java @@ -0,0 +1,132 @@ +package com.wizardlybump17.wlib.command.input; + +import com.google.gson.JsonElement; +import org.jetbrains.annotations.NotNull; +import org.jetbrains.annotations.Nullable; + +import java.util.List; +import java.util.Objects; + +public interface AllowedJsonElementInputs extends AllowedInputs { + + static @NotNull Value value(@NotNull JsonElement value) { + return new Value(value); + } + + static @NotNull Values values(@NotNull List values) { + return new Values(values); + } + + static @NotNull Any anyNotNull() { + return Any.NOT_NULL; + } + + static @NotNull Any anyNullable() { + return Any.NULLABLE; + } + + final class Value implements AllowedJsonElementInputs, SingleValueInput { + + private final @NotNull JsonElement value; + + Value(@NotNull JsonElement value) { + this.value = value; + } + + @Override + public @NotNull JsonElement value() { + return value; + } + + @Override + public boolean equals(Object object) { + if (object == null || getClass() != object.getClass()) + return false; + Value value1 = (Value) object; + return Objects.equals(value, value1.value); + } + + @Override + public int hashCode() { + return Objects.hashCode(value); + } + + @Override + public String toString() { + return "AllowedJsonElementInputs$Value{" + + "value=" + value + + '}'; + } + } + + final class Values implements AllowedJsonElementInputs, AllowedListInputs { + + private final @NotNull List values; + + private Values(@NotNull List values) { + this.values = values; + } + + @Override + public @NotNull List allowedValues() { + return values; + } + + @Override + public boolean equals(Object object) { + if (object == null || getClass() != object.getClass()) + return false; + Values values1 = (Values) object; + return Objects.equals(values, values1.values); + } + + @Override + public int hashCode() { + return Objects.hashCode(values); + } + + @Override + public String toString() { + return "AllowedJsonElementInputs$Values{" + + "values=" + values + + '}'; + } + } + + final class Any implements AllowedJsonElementInputs { + + private static final @NotNull Any NOT_NULL = new Any(false); + private static final @NotNull Any NULLABLE = new Any(true); + + private final boolean nullable; + + private Any(boolean nullable) { + this.nullable = nullable; + } + + @Override + public boolean isAllowed(@Nullable JsonElement input) { + return nullable || input != null; + } + + @Override + public boolean equals(Object o) { + if (o == null || getClass() != o.getClass()) + return false; + Any any = (Any) o; + return nullable == any.nullable; + } + + @Override + public int hashCode() { + return Objects.hashCode(nullable); + } + + @Override + public String toString() { + return "AllowedJsonElementInputs$Any{" + + "nullable=" + nullable + + '}'; + } + } +} diff --git a/core/src/main/java/com/wizardlybump17/wlib/command/node/JsonElementCommandNode.java b/core/src/main/java/com/wizardlybump17/wlib/command/node/JsonElementCommandNode.java new file mode 100644 index 00000000..4db754a0 --- /dev/null +++ b/core/src/main/java/com/wizardlybump17/wlib/command/node/JsonElementCommandNode.java @@ -0,0 +1,47 @@ +package com.wizardlybump17.wlib.command.node; + +import com.google.gson.Gson; +import com.google.gson.JsonElement; +import com.google.gson.JsonSyntaxException; +import com.wizardlybump17.wlib.command.exception.InputParsingException; +import com.wizardlybump17.wlib.command.executor.CommandNodeExecutor; +import com.wizardlybump17.wlib.command.input.AllowedInputs; +import com.wizardlybump17.wlib.command.suggestion.Suggester; +import org.jetbrains.annotations.NotNull; +import org.jetbrains.annotations.Nullable; + +import java.util.List; + +public class JsonElementCommandNode extends CommandNode { + + private final @NotNull Gson gson; + + public JsonElementCommandNode(@NotNull String name, @NotNull List> children, @NotNull AllowedInputs allowedInputs, @Nullable Suggester suggester, @Nullable CommandNodeExecutor executor, @Nullable String permission, @NotNull Gson gson) { + super(name, children, allowedInputs, suggester, executor, permission); + this.gson = gson; + } + + @Override + public @Nullable JsonElement parse(@NotNull String input) throws InputParsingException { + try { + return gson.fromJson(input, JsonElement.class); + } catch (JsonSyntaxException e) { + throw new InputParsingException("Could not parse as JsonElement: " + input, e); + } + } + + @Override + public @NotNull CommandNode withChildren(@NotNull List> children) { + return new JsonElementCommandNode(getName(), children, getAllowedInputs(), getSuggester(), getExecutor(), getPermission(), gson); + } + + @Override + public @NotNull CommandNode withExecutor(@Nullable CommandNodeExecutor executor) { + return new JsonElementCommandNode(getName(), getChildren(), getAllowedInputs(), getSuggester(), executor, getPermission(), gson); + } + + @Override + public @NotNull CommandNode withPermission(@Nullable String permission) { + return new JsonElementCommandNode(getName(), getChildren(), getAllowedInputs(), getSuggester(), getExecutor(), permission, gson); + } +} diff --git a/core/src/main/java/com/wizardlybump17/wlib/command/suggestion/JsonElementSuggester.java b/core/src/main/java/com/wizardlybump17/wlib/command/suggestion/JsonElementSuggester.java new file mode 100644 index 00000000..f3d45e10 --- /dev/null +++ b/core/src/main/java/com/wizardlybump17/wlib/command/suggestion/JsonElementSuggester.java @@ -0,0 +1,116 @@ +package com.wizardlybump17.wlib.command.suggestion; + +import com.google.gson.Gson; +import com.google.gson.JsonElement; +import com.wizardlybump17.wlib.command.node.CommandNode; +import com.wizardlybump17.wlib.command.sender.CommandSender; +import org.jetbrains.annotations.NotNull; +import org.jetbrains.annotations.Unmodifiable; + +import java.util.List; +import java.util.Objects; + +public interface JsonElementSuggester extends Suggester { + + @NotNull Gson gson(); + + static @NotNull Values values(@NotNull Gson gson, @NotNull List elements) { + return new Values(gson, elements); + } + + static @NotNull Values values(@NotNull List elements) { + return new Values(Values.GSON, elements); + } + + static @NotNull Value value(@NotNull Gson gson, @NotNull JsonElement value) { + return new Value(gson, value); + } + + static @NotNull Value value(@NotNull JsonElement value) { + return new Value(Values.GSON, value); + } + + final class Values extends AbstractValuesSuggester implements JsonElementSuggester { + + private static final @NotNull Gson GSON = new Gson(); + + private final @NotNull Gson gson; + + private Values(@NotNull Gson gson, @NotNull List suggestions) { + super(suggestions); + this.gson = gson; + } + + @Override + public @NotNull Gson gson() { + return gson; + } + + @Override + public boolean equals(Object o) { + if (o == null || getClass() != o.getClass()) + return false; + if (!super.equals(o)) return false; + Values values = (Values) o; + return Objects.equals(gson, values.gson); + } + + @Override + public int hashCode() { + return Objects.hash(super.hashCode(), gson); + } + + @Override + public String toString() { + return "JsonElementSuggester$Values{" + + "gson=" + gson + + "} " + super.toString(); + } + } + + final class Value implements JsonElementSuggester { + + private final @NotNull Gson gson; + private final @NotNull @Unmodifiable List list; + + private Value(@NotNull Gson gson, @NotNull JsonElement value) { + this.gson = gson; + this.list = List.of(value); + } + + @Override + public @NotNull List getSuggestions(@NotNull CommandSender sender, @NotNull List input, @NotNull String current, @NotNull CommandNode currentNode) { + return list; + } + + @Override + public @NotNull Gson gson() { + return gson; + } + + public @NotNull JsonElement value() { + return list.getFirst(); + } + + @Override + public boolean equals(Object o) { + if (o == null || getClass() != o.getClass()) + return false; + Value value = (Value) o; + return Objects.equals(gson, value.gson) && Objects.equals(list, value.list); + } + + @Override + public int hashCode() { + return Objects.hash(gson, list); + } + + @Override + public String toString() { + return "Value{" + + "gson=" + gson + + ", value=" + value() + + '}'; + } + } +} diff --git a/core/src/main/resources/plugin.yml b/core/src/main/resources/plugin.yml index 35676d43..f4a373e2 100644 --- a/core/src/main/resources/plugin.yml +++ b/core/src/main/resources/plugin.yml @@ -8,3 +8,4 @@ libraries: - net.kyori:adventure-api:4.18.0 - net.kyori:adventure-text-minimessage:4.18.0 - net.kyori:adventure-platform-bukkit:4.3.4 + - com.google.code.gson:gson:${gson} From 3e83701261185b526245376aa7a3d16505529f03 Mon Sep 17 00:00:00 2001 From: WizardlyBump17 Date: Tue, 16 Dec 2025 22:28:28 -0300 Subject: [PATCH 275/363] removed lombok from the WLib class --- .../java/com/wizardlybump17/wlib/WLib.java | 19 ++++++++++++------- 1 file changed, 12 insertions(+), 7 deletions(-) diff --git a/core/src/main/java/com/wizardlybump17/wlib/WLib.java b/core/src/main/java/com/wizardlybump17/wlib/WLib.java index 0ec0b6c0..7a4383de 100644 --- a/core/src/main/java/com/wizardlybump17/wlib/WLib.java +++ b/core/src/main/java/com/wizardlybump17/wlib/WLib.java @@ -34,14 +34,11 @@ import com.wizardlybump17.wlib.util.bukkit.config.wrapper.potion.PotionDataWrapper; import com.wizardlybump17.wlib.util.bukkit.config.wrapper.potion.PotionEffectWrapper; import com.wizardlybump17.wlib.util.bukkit.particle.*; -import lombok.Getter; -import lombok.NonNull; import org.bukkit.Bukkit; import org.bukkit.configuration.serialization.ConfigurationSerialization; import org.bukkit.event.HandlerList; import org.bukkit.plugin.java.JavaPlugin; -@Getter public class WLib extends JavaPlugin { private final SaveControllersTask saveControllersTask = new SaveControllersTask(getLogger()); @@ -192,10 +189,6 @@ public static WLib getInstance() { return getPlugin(WLib.class); } - public static @NonNull String getServerVersion() { - return Bukkit.getServer().getClass().getName().split("\\.")[3]; - } - public MethodCommandExtractor getMethodCommandExtractor() { return methodCommandExtractor; } @@ -204,6 +197,14 @@ public MethodCommandNodeFactoryRegistry getMethodCommandNodeFactoryRegistry() { return methodCommandNodeFactoryRegistry; } + public WLibCommandExecutor getCommandExecutor() { + return commandExecutor; + } + + public BukkitCommandManagerListener getCommandManagerListener() { + return commandManagerListener; + } + public CommandManager getCommandManager() { return commandManager; } @@ -211,4 +212,8 @@ public CommandManager getCommandManager() { public Gson getGson() { return gson; } + + public SaveControllersTask getSaveControllersTask() { + return saveControllersTask; + } } From c9d5b4b2eacf772e94a22a42fc747388b30d327a Mon Sep 17 00:00:00 2001 From: WizardlyBump17 Date: Tue, 16 Dec 2025 22:29:54 -0300 Subject: [PATCH 276/363] fixed build.gradle --- core/build.gradle | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/core/build.gradle b/core/build.gradle index 24f60d6c..3312cb24 100644 --- a/core/build.gradle +++ b/core/build.gradle @@ -32,8 +32,10 @@ dependencies { processResources { filesMatching('**/plugin.yml') { - expand 'version': project.version - expand "gson": gson + expand(Map.of( + "version", project.version, + "gson", gson + )) } } From 2fbaff84ac988d9c99107a55b8b28dca037970f3 Mon Sep 17 00:00:00 2001 From: WizardlyBump17 Date: Tue, 16 Dec 2025 23:12:47 -0300 Subject: [PATCH 277/363] passing a string instead --- .../wlib/command/WLibCommandExecutor.java | 10 ++-------- 1 file changed, 2 insertions(+), 8 deletions(-) diff --git a/core/src/main/java/com/wizardlybump17/wlib/command/WLibCommandExecutor.java b/core/src/main/java/com/wizardlybump17/wlib/command/WLibCommandExecutor.java index e75c7522..94c7def4 100644 --- a/core/src/main/java/com/wizardlybump17/wlib/command/WLibCommandExecutor.java +++ b/core/src/main/java/com/wizardlybump17/wlib/command/WLibCommandExecutor.java @@ -12,8 +12,6 @@ import org.bukkit.command.TabCompleter; import org.jetbrains.annotations.NotNull; -import java.util.ArrayList; -import java.util.Collections; import java.util.List; import java.util.logging.Level; import java.util.logging.Logger; @@ -40,9 +38,7 @@ public WLibCommandExecutor(@NotNull CommandManager commandManager, @NotNull Logg public boolean onCommand(@NotNull CommandSender sender, @NotNull Command command, @NotNull String label, @NotNull String[] args) { com.wizardlybump17.wlib.command.sender.CommandSender wlibSender = new BukkitCommandSender(sender); - List wlibArgs = new ArrayList<>(); - wlibArgs.add(command.getName()); - Collections.addAll(wlibArgs, args); + String wlibArgs = command.getName() + " " + String.join(" ", args); CommandResult result = commandManager.execute(wlibSender, wlibArgs); switch (result) { @@ -70,9 +66,7 @@ public boolean onCommand(@NotNull CommandSender sender, @NotNull Command command public @NotNull List onTabComplete(@NotNull CommandSender sender, @NotNull Command command, @NotNull String label, @NotNull String[] args) { com.wizardlybump17.wlib.command.sender.CommandSender wlibSender = new BukkitCommandSender(sender); - List wlibArgs = new ArrayList<>(); - wlibArgs.add(command.getName()); - Collections.addAll(wlibArgs, args); + String wlibArgs = command.getName() + " " + String.join(" ", args); String current = args.length == 1 ? args[0] : args[args.length - 1]; String currentLowerCase = current.toLowerCase(); From a58d536f38f4e16bfd585443ddb1f551b54c10cd Mon Sep 17 00:00:00 2001 From: WizardlyBump17 Date: Tue, 16 Dec 2025 23:13:20 -0300 Subject: [PATCH 278/363] improved the messages --- .../com/wizardlybump17/wlib/command/WLibCommandExecutor.java | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/core/src/main/java/com/wizardlybump17/wlib/command/WLibCommandExecutor.java b/core/src/main/java/com/wizardlybump17/wlib/command/WLibCommandExecutor.java index 94c7def4..59b0954d 100644 --- a/core/src/main/java/com/wizardlybump17/wlib/command/WLibCommandExecutor.java +++ b/core/src/main/java/com/wizardlybump17/wlib/command/WLibCommandExecutor.java @@ -44,7 +44,7 @@ public boolean onCommand(@NotNull CommandSender sender, @NotNull Command command switch (result) { case SuccessResult successResult -> {} case ExceptionResult exceptionResult -> { - sender.sendMessage("§cAn internal error occurred while executing this command."); + sender.sendMessage("§cAn internal error occurred while executing this command: " + exceptionResult.exception() + "."); logger.log(Level.SEVERE, "Error while " + sender + " tried to execute " + wlibArgs, exceptionResult.exception()); } case OutOfRangeInputResult outOfRangeInputResult -> sender.sendMessage("§cInvalid input at index " + outOfRangeInputResult.lastInputIndex() + "."); @@ -52,7 +52,7 @@ public boolean onCommand(@NotNull CommandSender sender, @NotNull Command command case InsufficientArgumentsResult insufficientArgumentsResult -> sender.sendMessage("§cInsufficient arguments provided."); case ParseInputExceptionResult parseInputExceptionResult -> sender.sendMessage("§cInvalid input at index " + parseInputExceptionResult.lastInputIndex() + ": " + parseInputExceptionResult.exception().getMessage()); case CommandNodeExecutorNotFoundResult notFoundResult -> sender.sendMessage("§cNo executor found for this command."); - case GenericErrorResult genericErrorResult -> sender.sendMessage("§cAn error occurred while executing the command."); + case GenericErrorResult genericErrorResult -> sender.sendMessage("§cAn error occurred while executing the command: " + genericErrorResult.message() + "."); case NoPermissionResult noPermissionResult -> sender.sendMessage("§cYou do not have permission to execute this command."); case CommandNotFoundResult notFoundResult -> sender.sendMessage("§cCommand not found."); case InvalidSenderResult invalidSenderResult -> sender.sendMessage("§cYou can not execute this command."); From bc22f9a35ea3d484155157023520fada1105a606 Mon Sep 17 00:00:00 2001 From: WizardlyBump17 Date: Tue, 16 Dec 2025 23:42:55 -0300 Subject: [PATCH 279/363] some changes to the quoted string system --- .../wlib/command/manager/CommandManager.java | 17 ++- .../wizardlybump17/wlib/util/StringUtil.java | 108 +++++------------- .../util/exception/QuotedStringException.java | 2 - .../wlib/util/test/QuotedStringsTests.java | 53 +++++++-- 4 files changed, 85 insertions(+), 95 deletions(-) diff --git a/commands/src/main/java/com/wizardlybump17/wlib/command/manager/CommandManager.java b/commands/src/main/java/com/wizardlybump17/wlib/command/manager/CommandManager.java index e211f049..990c6fd7 100644 --- a/commands/src/main/java/com/wizardlybump17/wlib/command/manager/CommandManager.java +++ b/commands/src/main/java/com/wizardlybump17/wlib/command/manager/CommandManager.java @@ -131,7 +131,22 @@ protected void addCommand(@NotNull String identifier, @NotNull String name, @Not } public @NotNull List getSuggestions(@NotNull CommandSender sender, @NotNull String @NotNull [] input) throws SuggesterException { - return getSuggestions(sender, String.join(" ", input)); + if (input.length == 0) + return getSuggestions(sender, List.of()); + + String inputString = String.join(" ", input); + try { + if (!inputString.isEmpty() && !StringUtil.isProperlyQuoted(inputString)) + inputString = inputString + "\""; + + List inputList = StringUtil.parseQuotedStrings(inputString); + if (input[input.length - 1].isEmpty()) + inputList.add(""); + + return getSuggestions(sender, inputList); + } catch (QuotedStringException e) { + return List.of(); + } } public @NotNull Optional getCommand(@NotNull String name) { diff --git a/utils/src/main/java/com/wizardlybump17/wlib/util/StringUtil.java b/utils/src/main/java/com/wizardlybump17/wlib/util/StringUtil.java index 30551861..7b92076b 100644 --- a/utils/src/main/java/com/wizardlybump17/wlib/util/StringUtil.java +++ b/utils/src/main/java/com/wizardlybump17/wlib/util/StringUtil.java @@ -321,8 +321,6 @@ public static String fixName(String name) { * @return the {@link List} of {@link String}s * @throws QuotedStringException if any of the following situations happen: *
    - *
  • A quoted string is started right after a normal (or escaped) {@code char};
  • - *
  • A quoted string is ended right before a normal (or escaped) {@code char};
  • *
  • A escape {@code char} is found at the end of the input;
  • *
  • A quoted string is not closed.
  • *
@@ -337,128 +335,78 @@ public static String fixName(String name) { char[] chars = input.toCharArray(); StringBuilder builder = new StringBuilder(); - StringBuilder quoted = new StringBuilder(); boolean escaped = false; - boolean delimited = true; - boolean hadQuote = false; + boolean onQuotes = false; - for (char current : chars) { - if (current == escape && !escaped) { // start of an escaped char + for (char currentChar : chars) { + if (currentChar == escape) { + builder.append(currentChar); escaped = true; continue; } - if (escaped) { // end of the escaped char - (quoted.isEmpty() ? builder : quoted).append(current); - escaped = false; + escaped = false; + + if (currentChar == quote) { + if (onQuotes) { + strings.add(builder.toString()); + builder.setLength(0); + onQuotes = false; + } else { + onQuotes = true; + } continue; } - if (current == quote) { - if (!delimited) // the previous char was not the delimiter. Example case: string"quoted" - throw new QuotedStringException(QuotedStringException.QUOTED_WITHOUT_DELIMITER); - - if (quoted.isEmpty()) { // begin of quoted string - quoted.append(quote); + if (currentChar == delimiter) { + if (onQuotes) { + builder.append(currentChar); continue; } - // end of quoted string - strings.add(quoted.substring(1)); - delimited = false; - hadQuote = true; - quoted.setLength(0); - continue; - } - - if (current == delimiter && quoted.isEmpty()) { // delimiter (space) if (!builder.isEmpty()) { strings.add(builder.toString()); builder.setLength(0); } - delimited = true; - hadQuote = false; continue; } - if (hadQuote) // the previous char was a quote. Example case: "quoted"string - throw new QuotedStringException(QuotedStringException.NON_QUOTED_AFTER_QUOTED); - - (quoted.isEmpty() ? builder : quoted).append(current); // any char - if (quoted.isEmpty()) - delimited = false; + builder.append(currentChar); } if (escaped) throw new QuotedStringException(QuotedStringException.INVALID_ESCAPE); - if (!quoted.isEmpty()) + if (onQuotes) throw new QuotedStringException(QuotedStringException.UNCLOSED_QUOTE); if (!builder.isEmpty()) strings.add(builder.toString()); - if (input.charAt(input.length() - 1) == delimiter) - strings.add(""); - return strings; } - public static boolean isProperlyQuoted(@NotNull String input, char quote, char escape, char delimiter) throws QuotedStringException { + public static boolean isProperlyQuoted(@NotNull String input, char quote, char escape) throws QuotedStringException { char[] chars = input.toCharArray(); - boolean escaped = false; - boolean delimited = true; - boolean hadQuote = false; - boolean insideQuotes = false; + boolean onQuotes = false; - for (char current : chars) { - if (current == escape && !escaped) { // start of an escaped char + for (char currentChar : chars) { + if (currentChar == escape) { escaped = true; continue; } - if (escaped) { // end of the escaped char - escaped = false; - continue; - } - - if (current == quote) { - if (!delimited) // the previous char was not the delimiter. Example case: string"quoted" - throw new QuotedStringException(QuotedStringException.QUOTED_WITHOUT_DELIMITER); - - if (!insideQuotes) { // begin of quoted string - insideQuotes = true; - continue; - } - - // end of quoted string - delimited = false; - hadQuote = true; - insideQuotes = false; - continue; - } - - if (current == delimiter && !insideQuotes) { // delimiter (space) - delimited = true; - hadQuote = false; - continue; - } - - if (hadQuote) // the previous char was a quote. Example case: "quoted"string - throw new QuotedStringException(QuotedStringException.NON_QUOTED_AFTER_QUOTED); + escaped = false; - if (insideQuotes) - delimited = false; + if (currentChar == quote) + onQuotes = !onQuotes; } - if (escaped) - throw new QuotedStringException(QuotedStringException.INVALID_ESCAPE); - - return !insideQuotes; + return !escaped && !onQuotes; } public static boolean isProperlyQuoted(@NotNull String input) throws QuotedStringException { - return isProperlyQuoted(input, QUOTE, QUOTE_ESCAPE, QUOTE_DELIMITER); + return isProperlyQuoted(input, QUOTE, QUOTE_ESCAPE); } /** diff --git a/utils/src/main/java/com/wizardlybump17/wlib/util/exception/QuotedStringException.java b/utils/src/main/java/com/wizardlybump17/wlib/util/exception/QuotedStringException.java index ed8713b5..4701ac19 100644 --- a/utils/src/main/java/com/wizardlybump17/wlib/util/exception/QuotedStringException.java +++ b/utils/src/main/java/com/wizardlybump17/wlib/util/exception/QuotedStringException.java @@ -4,8 +4,6 @@ public class QuotedStringException extends RuntimeException { - public static final @NonNull String QUOTED_WITHOUT_DELIMITER = "Can not have quoted strings without the delimiter"; - public static final @NonNull String NON_QUOTED_AFTER_QUOTED = "Can not have non-quoted strings after quoted strings"; public static final @NonNull String INVALID_ESCAPE = "Invalid escape sequence"; public static final @NonNull String UNCLOSED_QUOTE = "Unclosed quote"; diff --git a/utils/src/test/java/com/wizardlybump17/wlib/util/test/QuotedStringsTests.java b/utils/src/test/java/com/wizardlybump17/wlib/util/test/QuotedStringsTests.java index 1585d10a..2ccb73fd 100644 --- a/utils/src/test/java/com/wizardlybump17/wlib/util/test/QuotedStringsTests.java +++ b/utils/src/test/java/com/wizardlybump17/wlib/util/test/QuotedStringsTests.java @@ -105,20 +105,18 @@ void testEscapeInTheEndException() { } @Test - void testQuotedStringAfterNonQuotedStringException() { - assertThrows( - QuotedStringException.class, - () -> StringUtil.parseQuotedStrings("Hello World\"Hi\"", QUOTE, ESCAPE, DELIMITER), - QuotedStringException.QUOTED_WITHOUT_DELIMITER + void testQuotedStringAfterNonQuotedStringSuccess() { + Assertions.assertEquals( + List.of("Hello", "WorldHi"), + StringUtil.parseQuotedStrings("Hello World\"Hi\"", QUOTE, ESCAPE, DELIMITER) ); } @Test - void testNonQuotedStringAfterQuotedStringException() { - assertThrows( - QuotedStringException.class, - () -> StringUtil.parseQuotedStrings("\"Hello\"World", QUOTE, ESCAPE, DELIMITER), - QuotedStringException.NON_QUOTED_AFTER_QUOTED + void testNonQuotedStringAfterQuotedStringSuccess() { + Assertions.assertEquals( + List.of("Hello", "World"), + StringUtil.parseQuotedStrings("\"Hello\"World", QUOTE, ESCAPE, DELIMITER) ); } @@ -133,7 +131,7 @@ void testEmpty() { @Test void testEndingWithSpace0() { Assertions.assertEquals( - List.of(""), + List.of(), StringUtil.parseQuotedStrings(" ", QUOTE, ESCAPE, DELIMITER) ); } @@ -141,8 +139,39 @@ void testEndingWithSpace0() { @Test void testEndingWithSpace1() { Assertions.assertEquals( - List.of("Hello", "World", ""), + List.of("Hello", "World"), StringUtil.parseQuotedStrings("Hello World ", QUOTE, ESCAPE, DELIMITER) ); } + + @Test + void testProperlyQuotedTrue() { + Assertions.assertTrue(StringUtil.isProperlyQuoted("Hello World", QUOTE, ESCAPE)); + + Assertions.assertTrue(StringUtil.isProperlyQuoted("Hello \"World\"", QUOTE, ESCAPE)); + Assertions.assertTrue(StringUtil.isProperlyQuoted("\"Hello World\"", QUOTE, ESCAPE)); + + Assertions.assertTrue(StringUtil.isProperlyQuoted("Hello \"World \"", QUOTE, ESCAPE)); + + Assertions.assertTrue(StringUtil.isProperlyQuoted("Hello \"World\" Hi There", QUOTE, ESCAPE)); + + Assertions.assertTrue(StringUtil.isProperlyQuoted("Hello \"World\"Hi There", QUOTE, ESCAPE)); + Assertions.assertTrue(StringUtil.isProperlyQuoted("Hello\"World\" Hi There", QUOTE, ESCAPE)); + Assertions.assertTrue(StringUtil.isProperlyQuoted("Hello\"World\"Hi There", QUOTE, ESCAPE)); + + Assertions.assertTrue(StringUtil.isProperlyQuoted("", QUOTE, ESCAPE)); + Assertions.assertTrue(StringUtil.isProperlyQuoted("\"\"", QUOTE, ESCAPE)); + + Assertions.assertTrue(StringUtil.isProperlyQuoted("Hello\\ World", QUOTE, ESCAPE)); + } + + @Test + void testProperlyQuotedFalse() { + Assertions.assertFalse(StringUtil.isProperlyQuoted("Hello \"World", QUOTE, ESCAPE)); + Assertions.assertFalse(StringUtil.isProperlyQuoted("Hello \"World\" Hi \"There", QUOTE, ESCAPE)); + + Assertions.assertFalse(StringUtil.isProperlyQuoted("\"", QUOTE, ESCAPE)); + + Assertions.assertFalse(StringUtil.isProperlyQuoted("Hello \"World\" \\", QUOTE, ESCAPE)); + } } From 962b5e1a2edf6f5452ab89a0f926a86bfeaf49d1 Mon Sep 17 00:00:00 2001 From: WizardlyBump17 Date: Wed, 17 Dec 2025 00:00:31 -0300 Subject: [PATCH 280/363] properly handling escapes --- .../java/com/wizardlybump17/wlib/util/StringUtil.java | 7 +++++-- .../wlib/util/test/QuotedStringsTests.java | 10 ++++++++++ 2 files changed, 15 insertions(+), 2 deletions(-) diff --git a/utils/src/main/java/com/wizardlybump17/wlib/util/StringUtil.java b/utils/src/main/java/com/wizardlybump17/wlib/util/StringUtil.java index 7b92076b..81c82360 100644 --- a/utils/src/main/java/com/wizardlybump17/wlib/util/StringUtil.java +++ b/utils/src/main/java/com/wizardlybump17/wlib/util/StringUtil.java @@ -340,12 +340,15 @@ public static String fixName(String name) { for (char currentChar : chars) { if (currentChar == escape) { - builder.append(currentChar); escaped = true; continue; } - escaped = false; + if (escaped) { + builder.append(currentChar); + escaped = false; + continue; + } if (currentChar == quote) { if (onQuotes) { diff --git a/utils/src/test/java/com/wizardlybump17/wlib/util/test/QuotedStringsTests.java b/utils/src/test/java/com/wizardlybump17/wlib/util/test/QuotedStringsTests.java index 2ccb73fd..57bccf68 100644 --- a/utils/src/test/java/com/wizardlybump17/wlib/util/test/QuotedStringsTests.java +++ b/utils/src/test/java/com/wizardlybump17/wlib/util/test/QuotedStringsTests.java @@ -144,6 +144,14 @@ void testEndingWithSpace1() { ); } + @Test + void testStringInsideString() { + Assertions.assertEquals( + List.of("Hello There \"Hi There\" Cool"), + StringUtil.parseQuotedStrings("\"Hello There \\\"Hi There\\\" Cool\"") + ); + } + @Test void testProperlyQuotedTrue() { Assertions.assertTrue(StringUtil.isProperlyQuoted("Hello World", QUOTE, ESCAPE)); @@ -163,6 +171,8 @@ void testProperlyQuotedTrue() { Assertions.assertTrue(StringUtil.isProperlyQuoted("\"\"", QUOTE, ESCAPE)); Assertions.assertTrue(StringUtil.isProperlyQuoted("Hello\\ World", QUOTE, ESCAPE)); + + Assertions.assertTrue(StringUtil.isProperlyQuoted("\"Hello There \\\"Hi There\\\" Cool\"")); } @Test From 45e632ec682e4b56ff4ac263856f25639730d309 Mon Sep 17 00:00:00 2001 From: WizardlyBump17 Date: Wed, 17 Dec 2025 15:18:49 -0300 Subject: [PATCH 281/363] added the CommandResult#id() method --- .../wizardlybump17/wlib/command/result/CommandResult.java | 2 ++ .../wizardlybump17/wlib/command/result/SuccessResult.java | 7 +++++++ .../result/error/CommandNodeExecutorNotFoundResult.java | 7 +++++++ .../wlib/command/result/error/CommandNotFoundResult.java | 7 +++++++ .../wlib/command/result/error/ExceptionResult.java | 7 +++++++ .../wlib/command/result/error/ExtraArgumentsResult.java | 7 +++++++ .../wlib/command/result/error/GenericErrorResult.java | 6 ++++++ .../command/result/error/InsufficientArgumentsResult.java | 7 +++++++ .../wlib/command/result/error/InvalidSenderResult.java | 7 +++++++ .../wlib/command/result/error/NoPermissionResult.java | 7 +++++++ .../wlib/command/result/error/OutOfRangeInputResult.java | 7 +++++++ .../command/result/error/ParseInputExceptionResult.java | 7 +++++++ 12 files changed, 78 insertions(+) diff --git a/commands/src/main/java/com/wizardlybump17/wlib/command/result/CommandResult.java b/commands/src/main/java/com/wizardlybump17/wlib/command/result/CommandResult.java index e6c4330b..5cdddcf8 100644 --- a/commands/src/main/java/com/wizardlybump17/wlib/command/result/CommandResult.java +++ b/commands/src/main/java/com/wizardlybump17/wlib/command/result/CommandResult.java @@ -21,6 +21,8 @@ public interface CommandResult { @NotNull CommandNode lastNode(); + @NotNull String id(); + //without context static @NotNull SuccessResult successful(int lastInputIndex, @NotNull CommandNode lastNode, @Nullable T data) { diff --git a/commands/src/main/java/com/wizardlybump17/wlib/command/result/SuccessResult.java b/commands/src/main/java/com/wizardlybump17/wlib/command/result/SuccessResult.java index 49fe0585..eed1e9a7 100644 --- a/commands/src/main/java/com/wizardlybump17/wlib/command/result/SuccessResult.java +++ b/commands/src/main/java/com/wizardlybump17/wlib/command/result/SuccessResult.java @@ -6,8 +6,15 @@ public record SuccessResult(int lastInputIndex, @NotNull CommandNode lastNode, @Nullable T data) implements CommandResult { + public static final @NotNull String ID = "WLib:Success"; + @Override public boolean success() { return true; } + + @Override + public @NotNull String id() { + return ID; + } } diff --git a/commands/src/main/java/com/wizardlybump17/wlib/command/result/error/CommandNodeExecutorNotFoundResult.java b/commands/src/main/java/com/wizardlybump17/wlib/command/result/error/CommandNodeExecutorNotFoundResult.java index d2cbde76..0d37d793 100644 --- a/commands/src/main/java/com/wizardlybump17/wlib/command/result/error/CommandNodeExecutorNotFoundResult.java +++ b/commands/src/main/java/com/wizardlybump17/wlib/command/result/error/CommandNodeExecutorNotFoundResult.java @@ -4,4 +4,11 @@ import org.jetbrains.annotations.NotNull; public record CommandNodeExecutorNotFoundResult(int lastInputIndex, @NotNull CommandNode lastNode) implements UnsuccessResult { + + public static final @NotNull String ID = "WLib:Unsuccess/NoCommandExecutor"; + + @Override + public @NotNull String id() { + return ID; + } } diff --git a/commands/src/main/java/com/wizardlybump17/wlib/command/result/error/CommandNotFoundResult.java b/commands/src/main/java/com/wizardlybump17/wlib/command/result/error/CommandNotFoundResult.java index 27bbe154..8d48b768 100644 --- a/commands/src/main/java/com/wizardlybump17/wlib/command/result/error/CommandNotFoundResult.java +++ b/commands/src/main/java/com/wizardlybump17/wlib/command/result/error/CommandNotFoundResult.java @@ -9,6 +9,8 @@ public record CommandNotFoundResult(@NotNull String input) implements UnsuccessResult { + public static final @NotNull String ID = "WLib:Unsuccess/CommandNotFound"; + @Override public int lastInputIndex() { return 0; @@ -19,6 +21,11 @@ public int lastInputIndex() { return DummyNode.INSTANCE; } + @Override + public @NotNull String id() { + return ID; + } + private static final class DummyNode extends CommandNode { public static final @NotNull DummyNode INSTANCE = new DummyNode(); diff --git a/commands/src/main/java/com/wizardlybump17/wlib/command/result/error/ExceptionResult.java b/commands/src/main/java/com/wizardlybump17/wlib/command/result/error/ExceptionResult.java index 4137420b..40de6e8c 100644 --- a/commands/src/main/java/com/wizardlybump17/wlib/command/result/error/ExceptionResult.java +++ b/commands/src/main/java/com/wizardlybump17/wlib/command/result/error/ExceptionResult.java @@ -4,4 +4,11 @@ import org.jetbrains.annotations.NotNull; public record ExceptionResult(int lastInputIndex, @NotNull CommandNode lastNode, @NotNull Throwable exception) implements UnsuccessResult { + + public static final @NotNull String ID = "WLib:Unsuccess/Exception"; + + @Override + public @NotNull String id() { + return ID; + } } diff --git a/commands/src/main/java/com/wizardlybump17/wlib/command/result/error/ExtraArgumentsResult.java b/commands/src/main/java/com/wizardlybump17/wlib/command/result/error/ExtraArgumentsResult.java index 76f1dcca..bb1ed267 100644 --- a/commands/src/main/java/com/wizardlybump17/wlib/command/result/error/ExtraArgumentsResult.java +++ b/commands/src/main/java/com/wizardlybump17/wlib/command/result/error/ExtraArgumentsResult.java @@ -4,4 +4,11 @@ import org.jetbrains.annotations.NotNull; public record ExtraArgumentsResult(int lastInputIndex, @NotNull CommandNode lastNode) implements UnsuccessResult { + + public static final @NotNull String ID = "WLib:Unsuccess/ExtraArguments"; + + @Override + public @NotNull String id() { + return ID; + } } diff --git a/commands/src/main/java/com/wizardlybump17/wlib/command/result/error/GenericErrorResult.java b/commands/src/main/java/com/wizardlybump17/wlib/command/result/error/GenericErrorResult.java index 6605d032..8bc97952 100644 --- a/commands/src/main/java/com/wizardlybump17/wlib/command/result/error/GenericErrorResult.java +++ b/commands/src/main/java/com/wizardlybump17/wlib/command/result/error/GenericErrorResult.java @@ -6,8 +6,14 @@ public record GenericErrorResult(int lastInputIndex, @NotNull CommandNode lastNode, @NotNull String message) implements UnsuccessResult { public static final @NotNull String DEFAULT_MESSAGE = "An error occurred while executing the command."; + public static final @NotNull String ID = "WLib:Unsuccess/Generic"; public GenericErrorResult(int lastInputIndex, @NotNull CommandNode lastNode) { this(lastInputIndex, lastNode, DEFAULT_MESSAGE); } + + @Override + public @NotNull String id() { + return ID; + } } diff --git a/commands/src/main/java/com/wizardlybump17/wlib/command/result/error/InsufficientArgumentsResult.java b/commands/src/main/java/com/wizardlybump17/wlib/command/result/error/InsufficientArgumentsResult.java index 313b6e6c..168c3e28 100644 --- a/commands/src/main/java/com/wizardlybump17/wlib/command/result/error/InsufficientArgumentsResult.java +++ b/commands/src/main/java/com/wizardlybump17/wlib/command/result/error/InsufficientArgumentsResult.java @@ -6,6 +6,8 @@ public record InsufficientArgumentsResult(@NotNull Command command) implements UnsuccessResult { + public static final @NotNull String ID = "WLib:Unsuccess/InsufficientArguments"; + @Override public int lastInputIndex() { return -1; @@ -15,4 +17,9 @@ public int lastInputIndex() { public @NotNull CommandNode lastNode() { return command.getRoot(); } + + @Override + public @NotNull String id() { + return ID; + } } diff --git a/commands/src/main/java/com/wizardlybump17/wlib/command/result/error/InvalidSenderResult.java b/commands/src/main/java/com/wizardlybump17/wlib/command/result/error/InvalidSenderResult.java index 04ebcf53..9e95f4ac 100644 --- a/commands/src/main/java/com/wizardlybump17/wlib/command/result/error/InvalidSenderResult.java +++ b/commands/src/main/java/com/wizardlybump17/wlib/command/result/error/InvalidSenderResult.java @@ -5,4 +5,11 @@ import org.jetbrains.annotations.NotNull; public record InvalidSenderResult(int lastInputIndex, @NotNull CommandNode lastNode, @NotNull CommandSender sender, @NotNull Class> expectedSender) implements UnsuccessResult { + + public static final @NotNull String ID = "WLib:Unsuccess/InvalidSender"; + + @Override + public @NotNull String id() { + return ID; + } } diff --git a/commands/src/main/java/com/wizardlybump17/wlib/command/result/error/NoPermissionResult.java b/commands/src/main/java/com/wizardlybump17/wlib/command/result/error/NoPermissionResult.java index a82751f1..c9b4cf76 100644 --- a/commands/src/main/java/com/wizardlybump17/wlib/command/result/error/NoPermissionResult.java +++ b/commands/src/main/java/com/wizardlybump17/wlib/command/result/error/NoPermissionResult.java @@ -5,7 +5,14 @@ public record NoPermissionResult(int lastInputIndex, @NotNull CommandNode lastNode) implements UnsuccessResult { + public static final @NotNull String ID = "WLib:Unsuccess/NoPermission"; + public @NotNull String permission() { return lastNode.getPermission(); } + + @Override + public @NotNull String id() { + return ID; + } } diff --git a/commands/src/main/java/com/wizardlybump17/wlib/command/result/error/OutOfRangeInputResult.java b/commands/src/main/java/com/wizardlybump17/wlib/command/result/error/OutOfRangeInputResult.java index bd6c4a1a..91c15c24 100644 --- a/commands/src/main/java/com/wizardlybump17/wlib/command/result/error/OutOfRangeInputResult.java +++ b/commands/src/main/java/com/wizardlybump17/wlib/command/result/error/OutOfRangeInputResult.java @@ -4,4 +4,11 @@ import org.jetbrains.annotations.NotNull; public record OutOfRangeInputResult(int lastInputIndex, @NotNull CommandNode lastNode) implements UnsuccessResult { + + public static final @NotNull String ID = "WLib:Unsuccess/OutOfRange"; + + @Override + public @NotNull String id() { + return ID; + } } diff --git a/commands/src/main/java/com/wizardlybump17/wlib/command/result/error/ParseInputExceptionResult.java b/commands/src/main/java/com/wizardlybump17/wlib/command/result/error/ParseInputExceptionResult.java index ece9e883..0feca4da 100644 --- a/commands/src/main/java/com/wizardlybump17/wlib/command/result/error/ParseInputExceptionResult.java +++ b/commands/src/main/java/com/wizardlybump17/wlib/command/result/error/ParseInputExceptionResult.java @@ -5,4 +5,11 @@ import org.jetbrains.annotations.NotNull; public record ParseInputExceptionResult(int lastInputIndex, @NotNull CommandNode lastNode, @NotNull InputParsingException exception) implements UnsuccessResult { + + public static final @NotNull String ID = "WLib:Unsuccess/ParseError"; + + @Override + public @NotNull String id() { + return ID; + } } From 9d3745c6ddb278ff137e4a0c5913dabeca01f4f0 Mon Sep 17 00:00:00 2001 From: WizardlyBump17 Date: Wed, 17 Dec 2025 17:02:00 -0300 Subject: [PATCH 282/363] some changes --- .../main/java/com/wizardlybump17/wlib/util/StringUtil.java | 6 +++++- .../wizardlybump17/wlib/util/test/QuotedStringsTests.java | 4 ++-- 2 files changed, 7 insertions(+), 3 deletions(-) diff --git a/utils/src/main/java/com/wizardlybump17/wlib/util/StringUtil.java b/utils/src/main/java/com/wizardlybump17/wlib/util/StringUtil.java index 81c82360..ec921fde 100644 --- a/utils/src/main/java/com/wizardlybump17/wlib/util/StringUtil.java +++ b/utils/src/main/java/com/wizardlybump17/wlib/util/StringUtil.java @@ -337,6 +337,7 @@ public static String fixName(String name) { StringBuilder builder = new StringBuilder(); boolean escaped = false; boolean onQuotes = false; + boolean leftQuotes = false; for (char currentChar : chars) { if (currentChar == escape) { @@ -355,6 +356,7 @@ public static String fixName(String name) { strings.add(builder.toString()); builder.setLength(0); onQuotes = false; + leftQuotes = true; } else { onQuotes = true; } @@ -367,9 +369,11 @@ public static String fixName(String name) { continue; } - if (!builder.isEmpty()) { + if (!leftQuotes) { strings.add(builder.toString()); builder.setLength(0); + } else { + leftQuotes = false; } continue; } diff --git a/utils/src/test/java/com/wizardlybump17/wlib/util/test/QuotedStringsTests.java b/utils/src/test/java/com/wizardlybump17/wlib/util/test/QuotedStringsTests.java index 57bccf68..79393859 100644 --- a/utils/src/test/java/com/wizardlybump17/wlib/util/test/QuotedStringsTests.java +++ b/utils/src/test/java/com/wizardlybump17/wlib/util/test/QuotedStringsTests.java @@ -27,7 +27,7 @@ void testNoQuotes() { StringUtil.parseQuotedStrings("Hello Beautiful World", QUOTE, ESCAPE, DELIMITER) ); assertEquals( - List.of("Hello", "World", "Hi"), + List.of("Hello", "World", "", "", "Hi"), StringUtil.parseQuotedStrings("Hello World Hi", QUOTE, ESCAPE, DELIMITER) ); } @@ -131,7 +131,7 @@ void testEmpty() { @Test void testEndingWithSpace0() { Assertions.assertEquals( - List.of(), + List.of(""), StringUtil.parseQuotedStrings(" ", QUOTE, ESCAPE, DELIMITER) ); } From e7bda3e9272e30a93891e1bc1c49c7beb81e0aba Mon Sep 17 00:00:00 2001 From: WizardlyBump17 Date: Wed, 17 Dec 2025 17:09:45 -0300 Subject: [PATCH 283/363] fixed the Bukkit suggestions --- .../wizardlybump17/wlib/command/WLibCommandExecutor.java | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/core/src/main/java/com/wizardlybump17/wlib/command/WLibCommandExecutor.java b/core/src/main/java/com/wizardlybump17/wlib/command/WLibCommandExecutor.java index 59b0954d..1e5c592a 100644 --- a/core/src/main/java/com/wizardlybump17/wlib/command/WLibCommandExecutor.java +++ b/core/src/main/java/com/wizardlybump17/wlib/command/WLibCommandExecutor.java @@ -12,6 +12,7 @@ import org.bukkit.command.TabCompleter; import org.jetbrains.annotations.NotNull; +import java.util.Arrays; import java.util.List; import java.util.logging.Level; import java.util.logging.Logger; @@ -66,7 +67,9 @@ public boolean onCommand(@NotNull CommandSender sender, @NotNull Command command public @NotNull List onTabComplete(@NotNull CommandSender sender, @NotNull Command command, @NotNull String label, @NotNull String[] args) { com.wizardlybump17.wlib.command.sender.CommandSender wlibSender = new BukkitCommandSender(sender); - String wlibArgs = command.getName() + " " + String.join(" ", args); + String[] wlibArgs = new String[args.length + 1]; + wlibArgs[0] = command.getName(); + System.arraycopy(args, 0, wlibArgs, 1, args.length); String current = args.length == 1 ? args[0] : args[args.length - 1]; String currentLowerCase = current.toLowerCase(); @@ -77,7 +80,7 @@ public boolean onCommand(@NotNull CommandSender sender, @NotNull Command command .filter(suggestion -> suggestion.toLowerCase().startsWith(currentLowerCase)) .toList(); } catch (SuggesterException e) { - logger.log(Level.SEVERE, "Error while getting suggestions for " + sender + ": " + wlibArgs, e); + logger.log(Level.SEVERE, "Error while getting suggestions for " + sender + ": " + Arrays.toString(wlibArgs), e); return List.of(); } } From 4c73f730edbf90eebce4d4e6cd75eb6fc492ac85 Mon Sep 17 00:00:00 2001 From: WizardlyBump17 Date: Wed, 17 Dec 2025 22:03:36 -0300 Subject: [PATCH 284/363] more changes --- .../wizardlybump17/wlib/util/StringUtil.java | 36 ++++++++----------- .../wlib/util/test/QuotedStringsTests.java | 2 +- 2 files changed, 16 insertions(+), 22 deletions(-) diff --git a/utils/src/main/java/com/wizardlybump17/wlib/util/StringUtil.java b/utils/src/main/java/com/wizardlybump17/wlib/util/StringUtil.java index ec921fde..ba9e5564 100644 --- a/utils/src/main/java/com/wizardlybump17/wlib/util/StringUtil.java +++ b/utils/src/main/java/com/wizardlybump17/wlib/util/StringUtil.java @@ -335,9 +335,8 @@ public static String fixName(String name) { char[] chars = input.toCharArray(); StringBuilder builder = new StringBuilder(); + StringBuilder quotes = new StringBuilder(); boolean escaped = false; - boolean onQuotes = false; - boolean leftQuotes = false; for (char currentChar : chars) { if (currentChar == escape) { @@ -346,35 +345,30 @@ public static String fixName(String name) { } if (escaped) { - builder.append(currentChar); + (quotes.isEmpty() ? builder : quotes).append(currentChar); escaped = false; continue; } if (currentChar == quote) { - if (onQuotes) { - strings.add(builder.toString()); - builder.setLength(0); - onQuotes = false; - leftQuotes = true; + if (!quotes.isEmpty()) { + quotes.deleteCharAt(0); + builder.append(quotes); + quotes.setLength(0); } else { - onQuotes = true; + quotes.append(quote); } continue; } - if (currentChar == delimiter) { - if (onQuotes) { - builder.append(currentChar); - continue; - } + if (!quotes.isEmpty()) { + quotes.append(currentChar); + continue; + } - if (!leftQuotes) { - strings.add(builder.toString()); - builder.setLength(0); - } else { - leftQuotes = false; - } + if (currentChar == delimiter) { + strings.add(builder.toString()); + builder.setLength(0); continue; } @@ -383,7 +377,7 @@ public static String fixName(String name) { if (escaped) throw new QuotedStringException(QuotedStringException.INVALID_ESCAPE); - if (onQuotes) + if (!quotes.isEmpty()) throw new QuotedStringException(QuotedStringException.UNCLOSED_QUOTE); if (!builder.isEmpty()) diff --git a/utils/src/test/java/com/wizardlybump17/wlib/util/test/QuotedStringsTests.java b/utils/src/test/java/com/wizardlybump17/wlib/util/test/QuotedStringsTests.java index 79393859..e0b21b2d 100644 --- a/utils/src/test/java/com/wizardlybump17/wlib/util/test/QuotedStringsTests.java +++ b/utils/src/test/java/com/wizardlybump17/wlib/util/test/QuotedStringsTests.java @@ -115,7 +115,7 @@ void testQuotedStringAfterNonQuotedStringSuccess() { @Test void testNonQuotedStringAfterQuotedStringSuccess() { Assertions.assertEquals( - List.of("Hello", "World"), + List.of("HelloWorld"), StringUtil.parseQuotedStrings("\"Hello\"World", QUOTE, ESCAPE, DELIMITER) ); } From 2b81c94e1a58096671189d6cca90853ddc5a8d5f Mon Sep 17 00:00:00 2001 From: WizardlyBump17 Date: Wed, 17 Dec 2025 22:11:34 -0300 Subject: [PATCH 285/363] fixed the escape --- .../wizardlybump17/wlib/util/StringUtil.java | 2 +- .../wlib/util/test/QuotedStringsTests.java | 26 +++++++++++++++++++ 2 files changed, 27 insertions(+), 1 deletion(-) diff --git a/utils/src/main/java/com/wizardlybump17/wlib/util/StringUtil.java b/utils/src/main/java/com/wizardlybump17/wlib/util/StringUtil.java index ba9e5564..fddeeb90 100644 --- a/utils/src/main/java/com/wizardlybump17/wlib/util/StringUtil.java +++ b/utils/src/main/java/com/wizardlybump17/wlib/util/StringUtil.java @@ -339,7 +339,7 @@ public static String fixName(String name) { boolean escaped = false; for (char currentChar : chars) { - if (currentChar == escape) { + if (!escaped && currentChar == escape) { escaped = true; continue; } diff --git a/utils/src/test/java/com/wizardlybump17/wlib/util/test/QuotedStringsTests.java b/utils/src/test/java/com/wizardlybump17/wlib/util/test/QuotedStringsTests.java index e0b21b2d..e11ed926 100644 --- a/utils/src/test/java/com/wizardlybump17/wlib/util/test/QuotedStringsTests.java +++ b/utils/src/test/java/com/wizardlybump17/wlib/util/test/QuotedStringsTests.java @@ -184,4 +184,30 @@ void testProperlyQuotedFalse() { Assertions.assertFalse(StringUtil.isProperlyQuoted("Hello \"World\" \\", QUOTE, ESCAPE)); } + + @Test + void testEscape() { + Assertions.assertEquals( + List.of("Hello World"), + StringUtil.parseQuotedStrings("\"Hello World\"", QUOTE, ESCAPE, DELIMITER) + ); + Assertions.assertEquals( + List.of("Hello World"), + StringUtil.parseQuotedStrings("Hello\\ World", QUOTE, ESCAPE, DELIMITER) + ); + + Assertions.assertEquals( + List.of("\\Hello", "World"), + StringUtil.parseQuotedStrings("\\\\Hello World", QUOTE, ESCAPE, DELIMITER) + ); + + Assertions.assertEquals( + List.of("\\"), + StringUtil.parseQuotedStrings("\\\\", QUOTE, ESCAPE, DELIMITER) + ); + Assertions.assertEquals( + List.of("\\\\"), + StringUtil.parseQuotedStrings("\\\\\\\\", QUOTE, ESCAPE, DELIMITER) + ); + } } From d2e69323c59239c19462746b0861067c4a1d8bd8 Mon Sep 17 00:00:00 2001 From: WizardlyBump17 Date: Wed, 17 Dec 2025 23:53:26 -0300 Subject: [PATCH 286/363] escaping some suggestions --- .../wizardlybump17/wlib/command/Command.java | 11 +++-- .../wlib/command/node/LiteralCommandNode.java | 8 ++-- .../command/suggestion/LiteralSuggester.java | 47 ++++++++++++++++++ .../wlib/command/suggestion/Suggester.java | 4 ++ .../suggestion/string/StringSuggester.java | 5 ++ .../wlib/test/command/SuggestionTests.java | 8 ++-- .../suggestion/JsonElementSuggester.java | 5 ++ .../wizardlybump17/wlib/util/StringUtil.java | 48 +++++++++++++++++++ .../wlib/util/test/QuotedStringsTests.java | 33 +++++++++++++ 9 files changed, 157 insertions(+), 12 deletions(-) create mode 100644 commands/src/main/java/com/wizardlybump17/wlib/command/suggestion/LiteralSuggester.java diff --git a/commands/src/main/java/com/wizardlybump17/wlib/command/Command.java b/commands/src/main/java/com/wizardlybump17/wlib/command/Command.java index b444ff84..e3791055 100644 --- a/commands/src/main/java/com/wizardlybump17/wlib/command/Command.java +++ b/commands/src/main/java/com/wizardlybump17/wlib/command/Command.java @@ -18,6 +18,7 @@ import java.util.Comparator; import java.util.List; import java.util.Objects; +import java.util.stream.Stream; public class Command implements Comparable { @@ -197,10 +198,12 @@ public Command(@NotNull LiteralCommandNode root) { .map(Object::toString) .toList(); } else { - return childSuggestions - .stream() - .map(suggester::getStringRepresentation) - .toList(); + Stream stream = childSuggestions + .stream() + .map(suggester::getStringRepresentation); + if (suggester.needsEscape()) + stream = stream.map(StringUtil::escapeString); + return stream.toList(); } } diff --git a/commands/src/main/java/com/wizardlybump17/wlib/command/node/LiteralCommandNode.java b/commands/src/main/java/com/wizardlybump17/wlib/command/node/LiteralCommandNode.java index 92a1366d..666ede29 100644 --- a/commands/src/main/java/com/wizardlybump17/wlib/command/node/LiteralCommandNode.java +++ b/commands/src/main/java/com/wizardlybump17/wlib/command/node/LiteralCommandNode.java @@ -3,7 +3,7 @@ import com.wizardlybump17.wlib.command.executor.CommandNodeExecutor; import com.wizardlybump17.wlib.command.input.string.AllowedStringInputs; import com.wizardlybump17.wlib.command.sender.CommandSender; -import com.wizardlybump17.wlib.command.suggestion.string.StringSuggester; +import com.wizardlybump17.wlib.command.suggestion.LiteralSuggester; import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.Nullable; @@ -12,7 +12,7 @@ public class LiteralCommandNode extends CommandNode { public LiteralCommandNode(@NotNull String name, @NotNull List> children, @Nullable CommandNodeExecutor executor, @Nullable String permission) { - super(name, children, AllowedStringInputs.valueIgnoreCase(name), StringSuggester.value(name), executor, permission); + super(name, children, AllowedStringInputs.valueIgnoreCase(name), LiteralSuggester.of(name), executor, permission); } @Override @@ -21,8 +21,8 @@ public LiteralCommandNode(@NotNull String name, @NotNull List> ch } @Override - public @NotNull StringSuggester.Values getSuggester() { - return (StringSuggester.Values) super.getSuggester(); + public @NotNull LiteralSuggester getSuggester() { + return (LiteralSuggester) super.getSuggester(); } @Override diff --git a/commands/src/main/java/com/wizardlybump17/wlib/command/suggestion/LiteralSuggester.java b/commands/src/main/java/com/wizardlybump17/wlib/command/suggestion/LiteralSuggester.java new file mode 100644 index 00000000..6df01e63 --- /dev/null +++ b/commands/src/main/java/com/wizardlybump17/wlib/command/suggestion/LiteralSuggester.java @@ -0,0 +1,47 @@ +package com.wizardlybump17.wlib.command.suggestion; + +import com.wizardlybump17.wlib.command.exception.SuggesterException; +import com.wizardlybump17.wlib.command.node.CommandNode; +import com.wizardlybump17.wlib.command.sender.CommandSender; +import org.jetbrains.annotations.NotNull; + +import java.util.List; +import java.util.Objects; + +public final class LiteralSuggester implements Suggester { + + private final @NotNull List suggestions; + + private LiteralSuggester(@NotNull String value) { + this.suggestions = List.of(value); + } + + @Override + public @NotNull List getSuggestions(@NotNull CommandSender sender, @NotNull List input, @NotNull String current, @NotNull CommandNode currentNode) throws SuggesterException { + return suggestions; + } + + public static @NotNull LiteralSuggester of(@NotNull String value) { + return new LiteralSuggester(value); + } + + @Override + public boolean equals(Object o) { + if (o == null || getClass() != o.getClass()) + return false; + LiteralSuggester that = (LiteralSuggester) o; + return Objects.equals(suggestions, that.suggestions); + } + + @Override + public int hashCode() { + return Objects.hashCode(suggestions); + } + + @Override + public String toString() { + return "LiteralSuggester{" + + "value=" + suggestions.getFirst() + + '}'; + } +} diff --git a/commands/src/main/java/com/wizardlybump17/wlib/command/suggestion/Suggester.java b/commands/src/main/java/com/wizardlybump17/wlib/command/suggestion/Suggester.java index 8d64f81c..7505469e 100644 --- a/commands/src/main/java/com/wizardlybump17/wlib/command/suggestion/Suggester.java +++ b/commands/src/main/java/com/wizardlybump17/wlib/command/suggestion/Suggester.java @@ -14,4 +14,8 @@ public interface Suggester { default @NotNull String getStringRepresentation(@NotNull T value) { return value.toString(); } + + default boolean needsEscape() { + return false; + } } diff --git a/commands/src/main/java/com/wizardlybump17/wlib/command/suggestion/string/StringSuggester.java b/commands/src/main/java/com/wizardlybump17/wlib/command/suggestion/string/StringSuggester.java index 22166696..7f004cf5 100644 --- a/commands/src/main/java/com/wizardlybump17/wlib/command/suggestion/string/StringSuggester.java +++ b/commands/src/main/java/com/wizardlybump17/wlib/command/suggestion/string/StringSuggester.java @@ -26,6 +26,11 @@ public interface StringSuggester extends PrimitiveSuggester { return Any.INSTANCE; } + @Override + default boolean needsEscape() { + return true; + } + final class Values extends AbstractValuesSuggester implements StringSuggester { Values(@NotNull List values) { diff --git a/commands/src/test/java/com/wizardlybump17/wlib/test/command/SuggestionTests.java b/commands/src/test/java/com/wizardlybump17/wlib/test/command/SuggestionTests.java index 88a872b5..afb688b2 100644 --- a/commands/src/test/java/com/wizardlybump17/wlib/test/command/SuggestionTests.java +++ b/commands/src/test/java/com/wizardlybump17/wlib/test/command/SuggestionTests.java @@ -611,7 +611,7 @@ void testDefaultSuggestions() { //String Assertions.assertEquals( - List.of(""), + List.of("\"\""), Assertions.assertDoesNotThrow(() -> new Command( new LiteralCommandNode( "hello", @@ -631,7 +631,7 @@ void testDefaultSuggestions() { ).getSuggestions(CHAD_SENDER, List.of("hello", ""))) ); Assertions.assertEquals( - List.of("wo"), + List.of("\"wo\""), Assertions.assertDoesNotThrow(() -> new Command( new LiteralCommandNode( "hello", @@ -651,7 +651,7 @@ void testDefaultSuggestions() { ).getSuggestions(CHAD_SENDER, List.of("hello", "wo"))) ); Assertions.assertEquals( - List.of("spaced "), + List.of("\"spaced \""), Assertions.assertDoesNotThrow(() -> new Command( new LiteralCommandNode( "hello", @@ -671,7 +671,7 @@ void testDefaultSuggestions() { ).getSuggestions(CHAD_SENDER, List.of("hello", "spaced "))) ); Assertions.assertEquals( - List.of("spaced string"), + List.of("\"spaced string\""), Assertions.assertDoesNotThrow(() -> new Command( new LiteralCommandNode( "hello", diff --git a/core/src/main/java/com/wizardlybump17/wlib/command/suggestion/JsonElementSuggester.java b/core/src/main/java/com/wizardlybump17/wlib/command/suggestion/JsonElementSuggester.java index f3d45e10..2dee37f3 100644 --- a/core/src/main/java/com/wizardlybump17/wlib/command/suggestion/JsonElementSuggester.java +++ b/core/src/main/java/com/wizardlybump17/wlib/command/suggestion/JsonElementSuggester.java @@ -14,6 +14,11 @@ public interface JsonElementSuggester extends Suggester { @NotNull Gson gson(); + @Override + default boolean needsEscape() { + return true; + } + static @NotNull Values values(@NotNull Gson gson, @NotNull List elements) { return new Values(gson, elements); } diff --git a/utils/src/main/java/com/wizardlybump17/wlib/util/StringUtil.java b/utils/src/main/java/com/wizardlybump17/wlib/util/StringUtil.java index fddeeb90..f43f1dc6 100644 --- a/utils/src/main/java/com/wizardlybump17/wlib/util/StringUtil.java +++ b/utils/src/main/java/com/wizardlybump17/wlib/util/StringUtil.java @@ -468,4 +468,52 @@ public static boolean isProperlyQuoted(@NotNull String input) throws QuotedStrin return builder.toString(); } + + /** + * + * + * + * + * + * + * + * + * + * + * + * + * + * + * + * + * + * + * + * + * + * + * + * + * + *
InputOutput
Hello"Hello"
Hello World"Hello\ World"
"Hello World""\"Hello\ World\""
\"\\"
\Hello World"\\Hello\ World"
+ */ + public static @NotNull String escapeString(@NotNull String input, char quote, char escape) { + StringBuilder result = new StringBuilder(input.length()); + result.append(quote); + + for (char currentChar : input.toCharArray()) { + if (currentChar == quote || currentChar == escape) { + result.append(escape).append(currentChar); + } else { + result.append(currentChar); + } + } + + result.append(quote); + return result.toString(); + } + + public static @NotNull String escapeString(@NotNull String input) { + return escapeString(input, QUOTE, ESCAPE); + } } diff --git a/utils/src/test/java/com/wizardlybump17/wlib/util/test/QuotedStringsTests.java b/utils/src/test/java/com/wizardlybump17/wlib/util/test/QuotedStringsTests.java index e11ed926..121c2403 100644 --- a/utils/src/test/java/com/wizardlybump17/wlib/util/test/QuotedStringsTests.java +++ b/utils/src/test/java/com/wizardlybump17/wlib/util/test/QuotedStringsTests.java @@ -210,4 +210,37 @@ void testEscape() { StringUtil.parseQuotedStrings("\\\\\\\\", QUOTE, ESCAPE, DELIMITER) ); } + + @Test + void testAddEscape() { + Assertions.assertEquals( + "\"Hello World\"", //"Hello World" + StringUtil.escapeString("Hello World", QUOTE, ESCAPE) + ); + + Assertions.assertEquals( + "\"Hello World \\\\\"", //"Hello World \\" + StringUtil.escapeString("Hello World \\", QUOTE, ESCAPE) + ); + + Assertions.assertEquals( + "\" \"", //" " + StringUtil.escapeString(" ", QUOTE, ESCAPE) + ); + + Assertions.assertEquals( + "\"\\\"\\\"\\\"\"", //"\"\"\"" + StringUtil.escapeString("\"\"\"", QUOTE, ESCAPE) + ); + + Assertions.assertEquals( + "\"\"", + StringUtil.escapeString("", QUOTE, ESCAPE) + ); + + Assertions.assertEquals( + "\"\\\"\"", // "\"" + StringUtil.escapeString("\"", QUOTE, ESCAPE) + ); + } } From 37336b03ba8e0a4aad22d4217d8f9a2576f10143 Mon Sep 17 00:00:00 2001 From: WizardlyBump17 Date: Fri, 19 Dec 2025 18:38:41 -0300 Subject: [PATCH 287/363] just realized the NotNull annotation is not retained at runtime --- .../wlib/command/annotation/NonNullInput.java | 11 +++++++++++ .../factory/object/UUIDMethodCommandNodeFactory.java | 3 ++- .../string/StringMethodCommandNodeFactory.java | 3 ++- .../factory/JsonElementMethodCommandNodeFactory.java | 3 ++- .../OfflinePlayerMethodCommandNodeFactory.java | 3 ++- .../factory/PlayerMethodCommandNodeFactory.java | 3 ++- 6 files changed, 21 insertions(+), 5 deletions(-) create mode 100644 commands/src/main/java/com/wizardlybump17/wlib/command/annotation/NonNullInput.java diff --git a/commands/src/main/java/com/wizardlybump17/wlib/command/annotation/NonNullInput.java b/commands/src/main/java/com/wizardlybump17/wlib/command/annotation/NonNullInput.java new file mode 100644 index 00000000..1060aab8 --- /dev/null +++ b/commands/src/main/java/com/wizardlybump17/wlib/command/annotation/NonNullInput.java @@ -0,0 +1,11 @@ +package com.wizardlybump17.wlib.command.annotation; + +import java.lang.annotation.ElementType; +import java.lang.annotation.Retention; +import java.lang.annotation.RetentionPolicy; +import java.lang.annotation.Target; + +@Retention(RetentionPolicy.RUNTIME) +@Target(ElementType.PARAMETER) +public @interface NonNullInput { +} diff --git a/commands/src/main/java/com/wizardlybump17/wlib/command/extractor/method/factory/object/UUIDMethodCommandNodeFactory.java b/commands/src/main/java/com/wizardlybump17/wlib/command/extractor/method/factory/object/UUIDMethodCommandNodeFactory.java index 23203dff..cb3817c4 100644 --- a/commands/src/main/java/com/wizardlybump17/wlib/command/extractor/method/factory/object/UUIDMethodCommandNodeFactory.java +++ b/commands/src/main/java/com/wizardlybump17/wlib/command/extractor/method/factory/object/UUIDMethodCommandNodeFactory.java @@ -1,6 +1,7 @@ package com.wizardlybump17.wlib.command.extractor.method.factory.object; import com.wizardlybump17.wlib.command.annotation.Command; +import com.wizardlybump17.wlib.command.annotation.NonNullInput; import com.wizardlybump17.wlib.command.extractor.method.factory.MethodCommandNodeFactory; import com.wizardlybump17.wlib.command.input.object.AllowedUUIDInputs; import com.wizardlybump17.wlib.command.node.CommandNode; @@ -23,7 +24,7 @@ public class UUIDMethodCommandNodeFactory extends MethodCommandNodeFactory { return new UUIDCommandNode( name, root == null ? List.of() : List.of(root), - parameter.isAnnotationPresent(NotNull.class) ? AllowedUUIDInputs.anyNotNull() : AllowedUUIDInputs.anyNullable(), + parameter.isAnnotationPresent(NonNullInput.class) ? AllowedUUIDInputs.anyNotNull() : AllowedUUIDInputs.anyNullable(), null, null, null diff --git a/commands/src/main/java/com/wizardlybump17/wlib/command/extractor/method/factory/string/StringMethodCommandNodeFactory.java b/commands/src/main/java/com/wizardlybump17/wlib/command/extractor/method/factory/string/StringMethodCommandNodeFactory.java index fd80c142..eb29fc96 100644 --- a/commands/src/main/java/com/wizardlybump17/wlib/command/extractor/method/factory/string/StringMethodCommandNodeFactory.java +++ b/commands/src/main/java/com/wizardlybump17/wlib/command/extractor/method/factory/string/StringMethodCommandNodeFactory.java @@ -1,6 +1,7 @@ package com.wizardlybump17.wlib.command.extractor.method.factory.string; import com.wizardlybump17.wlib.command.annotation.Command; +import com.wizardlybump17.wlib.command.annotation.NonNullInput; import com.wizardlybump17.wlib.command.extractor.method.factory.MethodCommandNodeFactory; import com.wizardlybump17.wlib.command.input.string.AllowedStringInputs; import com.wizardlybump17.wlib.command.node.CommandNode; @@ -24,7 +25,7 @@ public class StringMethodCommandNodeFactory extends MethodCommandNodeFactory { return new StringCommandNode( name, root == null ? List.of() : List.of(root), - parameter.isAnnotationPresent(NotNull.class) ? AllowedStringInputs.anyNotNull() : AllowedStringInputs.anyNullable(), + parameter.isAnnotationPresent(NonNullInput.class) ? AllowedStringInputs.anyNotNull() : AllowedStringInputs.anyNullable(), StringSuggester.any(), null, null diff --git a/core/src/main/java/com/wizardlybump17/wlib/command/extractor/method/factory/JsonElementMethodCommandNodeFactory.java b/core/src/main/java/com/wizardlybump17/wlib/command/extractor/method/factory/JsonElementMethodCommandNodeFactory.java index d03f7197..041c31f4 100644 --- a/core/src/main/java/com/wizardlybump17/wlib/command/extractor/method/factory/JsonElementMethodCommandNodeFactory.java +++ b/core/src/main/java/com/wizardlybump17/wlib/command/extractor/method/factory/JsonElementMethodCommandNodeFactory.java @@ -3,6 +3,7 @@ import com.google.gson.Gson; import com.google.gson.JsonElement; import com.wizardlybump17.wlib.command.annotation.Command; +import com.wizardlybump17.wlib.command.annotation.NonNullInput; import com.wizardlybump17.wlib.command.input.AllowedJsonElementInputs; import com.wizardlybump17.wlib.command.node.CommandNode; import com.wizardlybump17.wlib.command.node.JsonElementCommandNode; @@ -26,7 +27,7 @@ public JsonElementMethodCommandNodeFactory(@NotNull Gson gson) { return new JsonElementCommandNode( name, root == null ? List.of() : List.of(root), - parameter.isAnnotationPresent(NotNull.class) ? AllowedJsonElementInputs.anyNotNull() : AllowedJsonElementInputs.anyNullable(), + parameter.isAnnotationPresent(NonNullInput.class) ? AllowedJsonElementInputs.anyNotNull() : AllowedJsonElementInputs.anyNullable(), null, null, null, diff --git a/core/src/main/java/com/wizardlybump17/wlib/command/extractor/method/factory/OfflinePlayerMethodCommandNodeFactory.java b/core/src/main/java/com/wizardlybump17/wlib/command/extractor/method/factory/OfflinePlayerMethodCommandNodeFactory.java index 54d604ec..90a0df9b 100644 --- a/core/src/main/java/com/wizardlybump17/wlib/command/extractor/method/factory/OfflinePlayerMethodCommandNodeFactory.java +++ b/core/src/main/java/com/wizardlybump17/wlib/command/extractor/method/factory/OfflinePlayerMethodCommandNodeFactory.java @@ -1,6 +1,7 @@ package com.wizardlybump17.wlib.command.extractor.method.factory; import com.wizardlybump17.wlib.command.annotation.Command; +import com.wizardlybump17.wlib.command.annotation.NonNullInput; import com.wizardlybump17.wlib.command.input.AllowedOfflinePlayerInputs; import com.wizardlybump17.wlib.command.node.CommandNode; import com.wizardlybump17.wlib.command.node.OfflinePlayerCommandNode; @@ -21,7 +22,7 @@ public class OfflinePlayerMethodCommandNodeFactory extends MethodCommandNodeFact return new OfflinePlayerCommandNode( name, root == null ? List.of() : List.of(root), - parameter.isAnnotationPresent(NotNull.class) ? AllowedOfflinePlayerInputs.anyNotNull() : AllowedOfflinePlayerInputs.anyNullable(), + parameter.isAnnotationPresent(NonNullInput.class) ? AllowedOfflinePlayerInputs.anyNotNull() : AllowedOfflinePlayerInputs.anyNullable(), OfflinePlayerSuggester.online(), null, null diff --git a/core/src/main/java/com/wizardlybump17/wlib/command/extractor/method/factory/PlayerMethodCommandNodeFactory.java b/core/src/main/java/com/wizardlybump17/wlib/command/extractor/method/factory/PlayerMethodCommandNodeFactory.java index c3c4cc2b..7c9b3893 100644 --- a/core/src/main/java/com/wizardlybump17/wlib/command/extractor/method/factory/PlayerMethodCommandNodeFactory.java +++ b/core/src/main/java/com/wizardlybump17/wlib/command/extractor/method/factory/PlayerMethodCommandNodeFactory.java @@ -1,6 +1,7 @@ package com.wizardlybump17.wlib.command.extractor.method.factory; import com.wizardlybump17.wlib.command.annotation.Command; +import com.wizardlybump17.wlib.command.annotation.NonNullInput; import com.wizardlybump17.wlib.command.input.AllowedPlayerInputs; import com.wizardlybump17.wlib.command.node.CommandNode; import com.wizardlybump17.wlib.command.node.PlayerCommandNode; @@ -20,7 +21,7 @@ public class PlayerMethodCommandNodeFactory extends MethodCommandNodeFactory { return new PlayerCommandNode( name, root == null ? List.of() : List.of(root), - parameter.isAnnotationPresent(NotNull.class) ? AllowedPlayerInputs.anyNotNull() : AllowedPlayerInputs.anyNullable(), + parameter.isAnnotationPresent(NonNullInput.class) ? AllowedPlayerInputs.anyNotNull() : AllowedPlayerInputs.anyNullable(), PlayerSuggester.online(), null, null From e434915a43f13addffced9964162fee0616176f3 Mon Sep 17 00:00:00 2001 From: WizardlyBump17 Date: Fri, 19 Dec 2025 19:25:13 -0300 Subject: [PATCH 288/363] added the BukkitCommandSender.CONSOLE field --- .../wlib/command/sender/BukkitCommandSender.java | 3 +++ 1 file changed, 3 insertions(+) diff --git a/core/src/main/java/com/wizardlybump17/wlib/command/sender/BukkitCommandSender.java b/core/src/main/java/com/wizardlybump17/wlib/command/sender/BukkitCommandSender.java index b5aac8ca..7886f363 100644 --- a/core/src/main/java/com/wizardlybump17/wlib/command/sender/BukkitCommandSender.java +++ b/core/src/main/java/com/wizardlybump17/wlib/command/sender/BukkitCommandSender.java @@ -3,6 +3,7 @@ import com.wizardlybump17.wlib.util.bukkit.collector.ComponentCollector; import net.kyori.adventure.text.Component; import net.kyori.adventure.text.ComponentLike; +import org.bukkit.Bukkit; import org.bukkit.command.BlockCommandSender; import org.bukkit.command.ConsoleCommandSender; import org.bukkit.entity.Entity; @@ -16,6 +17,8 @@ public class BukkitCommandSender implements CommandSender { + public static final @NotNull BukkitCommandSender CONSOLE = new BukkitCommandSender(Bukkit.getConsoleSender()); + private final @NotNull org.bukkit.command.CommandSender handle; public BukkitCommandSender(@NotNull org.bukkit.command.CommandSender handle) { From 97ac25cc3870bfcf1b6f04cc5d5a0384b8b7f407 Mon Sep 17 00:00:00 2001 From: WizardlyBump17 Date: Fri, 19 Dec 2025 22:32:42 -0300 Subject: [PATCH 289/363] caching the CommandSender --- .../java/com/wizardlybump17/wlib/WLib.java | 3 +++ .../wlib/command/WLibCommandExecutor.java | 4 ++-- .../command/sender/BukkitCommandSender.java | 22 +++++++++++++++++++ .../wlib/listener/EntityListener.java | 8 +++++++ 4 files changed, 35 insertions(+), 2 deletions(-) diff --git a/core/src/main/java/com/wizardlybump17/wlib/WLib.java b/core/src/main/java/com/wizardlybump17/wlib/WLib.java index 7a4383de..fbe7ab2d 100644 --- a/core/src/main/java/com/wizardlybump17/wlib/WLib.java +++ b/core/src/main/java/com/wizardlybump17/wlib/WLib.java @@ -14,6 +14,7 @@ import com.wizardlybump17.wlib.command.listener.BukkitCommandManagerListener; import com.wizardlybump17.wlib.command.manager.CommandManager; import com.wizardlybump17.wlib.command.registry.MethodCommandNodeFactoryRegistry; +import com.wizardlybump17.wlib.command.sender.BukkitCommandSender; import com.wizardlybump17.wlib.config.holder.BukkitConfigHolderFactory; import com.wizardlybump17.wlib.config.registry.ConfigHandlerRegistry; import com.wizardlybump17.wlib.config.registry.ConfigHolderFactoryRegistry; @@ -127,6 +128,8 @@ private void clearCommandSystem() { commandExecutor = null; commandManagerListener = null; + + BukkitCommandSender.clearCache(); } private void initSerializables() { diff --git a/core/src/main/java/com/wizardlybump17/wlib/command/WLibCommandExecutor.java b/core/src/main/java/com/wizardlybump17/wlib/command/WLibCommandExecutor.java index 1e5c592a..43cd0530 100644 --- a/core/src/main/java/com/wizardlybump17/wlib/command/WLibCommandExecutor.java +++ b/core/src/main/java/com/wizardlybump17/wlib/command/WLibCommandExecutor.java @@ -37,7 +37,7 @@ public WLibCommandExecutor(@NotNull CommandManager commandManager, @NotNull Logg @Override public boolean onCommand(@NotNull CommandSender sender, @NotNull Command command, @NotNull String label, @NotNull String[] args) { - com.wizardlybump17.wlib.command.sender.CommandSender wlibSender = new BukkitCommandSender(sender); + com.wizardlybump17.wlib.command.sender.CommandSender wlibSender = BukkitCommandSender.from(sender); String wlibArgs = command.getName() + " " + String.join(" ", args); @@ -65,7 +65,7 @@ public boolean onCommand(@NotNull CommandSender sender, @NotNull Command command @Override public @NotNull List onTabComplete(@NotNull CommandSender sender, @NotNull Command command, @NotNull String label, @NotNull String[] args) { - com.wizardlybump17.wlib.command.sender.CommandSender wlibSender = new BukkitCommandSender(sender); + com.wizardlybump17.wlib.command.sender.CommandSender wlibSender = BukkitCommandSender.from(sender); String[] wlibArgs = new String[args.length + 1]; wlibArgs[0] = command.getName(); diff --git a/core/src/main/java/com/wizardlybump17/wlib/command/sender/BukkitCommandSender.java b/core/src/main/java/com/wizardlybump17/wlib/command/sender/BukkitCommandSender.java index 7886f363..c4382172 100644 --- a/core/src/main/java/com/wizardlybump17/wlib/command/sender/BukkitCommandSender.java +++ b/core/src/main/java/com/wizardlybump17/wlib/command/sender/BukkitCommandSender.java @@ -8,16 +8,20 @@ import org.bukkit.command.ConsoleCommandSender; import org.bukkit.entity.Entity; import org.bukkit.entity.Player; +import org.jetbrains.annotations.ApiStatus; import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.Nullable; import java.util.ArrayList; import java.util.List; +import java.util.Map; import java.util.UUID; +import java.util.concurrent.ConcurrentHashMap; public class BukkitCommandSender implements CommandSender { public static final @NotNull BukkitCommandSender CONSOLE = new BukkitCommandSender(Bukkit.getConsoleSender()); + private static final @NotNull Map SENDERS_BY_ID = new ConcurrentHashMap<>(); private final @NotNull org.bukkit.command.CommandSender handle; @@ -96,4 +100,22 @@ public boolean hasPermission(String permission) { public boolean hasId(@NotNull UUID id) { return handle instanceof Entity entity && entity.getUniqueId().equals(id); } + + @ApiStatus.Internal + public static void clearCache() { + SENDERS_BY_ID.clear(); + } + + public static @NotNull BukkitCommandSender from(@NotNull org.bukkit.command.CommandSender sender) { + return switch (sender) { + case ConsoleCommandSender ignored -> BukkitCommandSender.CONSOLE; + case Entity entity -> SENDERS_BY_ID.computeIfAbsent(entity.getUniqueId(), $ -> new BukkitCommandSender(sender)); + default -> new BukkitCommandSender(sender); + }; + } + + @ApiStatus.Internal + public static void removeFromCache(@NotNull UUID id) { + SENDERS_BY_ID.remove(id); + } } diff --git a/core/src/main/java/com/wizardlybump17/wlib/listener/EntityListener.java b/core/src/main/java/com/wizardlybump17/wlib/listener/EntityListener.java index 28382af8..62545845 100644 --- a/core/src/main/java/com/wizardlybump17/wlib/listener/EntityListener.java +++ b/core/src/main/java/com/wizardlybump17/wlib/listener/EntityListener.java @@ -1,5 +1,7 @@ package com.wizardlybump17.wlib.listener; +import com.destroystokyo.paper.event.entity.EntityRemoveFromWorldEvent; +import com.wizardlybump17.wlib.command.sender.BukkitCommandSender; import com.wizardlybump17.wlib.inventory.CustomInventory; import com.wizardlybump17.wlib.inventory.CustomInventoryHolder; import com.wizardlybump17.wlib.inventory.item.ClickAction; @@ -15,6 +17,7 @@ import org.bukkit.event.inventory.InventoryDragEvent; import org.bukkit.inventory.Inventory; import org.bukkit.inventory.InventoryHolder; +import org.jetbrains.annotations.NotNull; @RequiredArgsConstructor public class EntityListener implements Listener { @@ -63,4 +66,9 @@ public void onClose(InventoryCloseEvent event) { paginatedInventory.stopListeners(); } + + @EventHandler + public void onRemove(@NotNull EntityRemoveFromWorldEvent event) { + BukkitCommandSender.removeFromCache(event.getEntity().getUniqueId()); + } } From 867fc5d337fe84f25e4dd63874bada9ac27ab2ab Mon Sep 17 00:00:00 2001 From: WizardlyBump17 Date: Fri, 19 Dec 2025 23:01:02 -0300 Subject: [PATCH 290/363] added the NoContentResult --- .../wlib/command/result/CommandResult.java | 9 +++++++ .../result/success/NoContentResult.java | 26 +++++++++++++++++++ 2 files changed, 35 insertions(+) create mode 100644 commands/src/main/java/com/wizardlybump17/wlib/command/result/success/NoContentResult.java diff --git a/commands/src/main/java/com/wizardlybump17/wlib/command/result/CommandResult.java b/commands/src/main/java/com/wizardlybump17/wlib/command/result/CommandResult.java index 5cdddcf8..e5d73ccb 100644 --- a/commands/src/main/java/com/wizardlybump17/wlib/command/result/CommandResult.java +++ b/commands/src/main/java/com/wizardlybump17/wlib/command/result/CommandResult.java @@ -5,6 +5,7 @@ import com.wizardlybump17.wlib.command.exception.InputParsingException; import com.wizardlybump17.wlib.command.node.CommandNode; import com.wizardlybump17.wlib.command.result.error.*; +import com.wizardlybump17.wlib.command.result.success.NoContentResult; import com.wizardlybump17.wlib.command.sender.CommandSender; import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.Nullable; @@ -73,6 +74,10 @@ public interface CommandResult { return new InvalidSenderResult<>(lastInputIndex, lastNode, sender, expectedSender); } + static @NotNull NoContentResult noContent(int lastInputIndex, @NotNull CommandNode lastNode) { + return new NoContentResult<>(lastInputIndex, lastNode); + } + //with context static @NotNull SuccessResult successful(@NotNull CommandContext context, @Nullable T data) { @@ -98,4 +103,8 @@ public interface CommandResult { static @NotNull InvalidSenderResult invalidSender(@NotNull CommandContext context, @NotNull Class> expectedSender) { return invalidSender(context.lastInputIndex(), context.lastNode(), context.sender(), expectedSender); } + + static @NotNull NoContentResult noContent(@NotNull CommandContext context) { + return noContent(context.lastInputIndex(), context.lastNode()); + } } diff --git a/commands/src/main/java/com/wizardlybump17/wlib/command/result/success/NoContentResult.java b/commands/src/main/java/com/wizardlybump17/wlib/command/result/success/NoContentResult.java new file mode 100644 index 00000000..69a530e3 --- /dev/null +++ b/commands/src/main/java/com/wizardlybump17/wlib/command/result/success/NoContentResult.java @@ -0,0 +1,26 @@ +package com.wizardlybump17.wlib.command.result.success; + +import com.wizardlybump17.wlib.command.node.CommandNode; +import com.wizardlybump17.wlib.command.result.CommandResult; +import org.jetbrains.annotations.NotNull; +import org.jetbrains.annotations.Nullable; + +public record NoContentResult(int lastInputIndex, @NotNull CommandNode lastNode) implements CommandResult { + + private static final @NotNull String ID = "WLib:Success/NoContent"; + + @Override + public @NotNull String id() { + return ID; + } + + @Override + public boolean success() { + return true; + } + + @Override + public @Nullable T data() { + return null; + } +} From 2f1017c3887cbda8eee47ef7cafefc4ae39ea93b Mon Sep 17 00:00:00 2001 From: WizardlyBump17 Date: Fri, 19 Dec 2025 23:09:14 -0300 Subject: [PATCH 291/363] added the NotFoundResult --- .../wlib/command/result/CommandResult.java | 8 ++++++++ .../wlib/command/result/error/NotFoundResult.java | 14 ++++++++++++++ 2 files changed, 22 insertions(+) create mode 100644 commands/src/main/java/com/wizardlybump17/wlib/command/result/error/NotFoundResult.java diff --git a/commands/src/main/java/com/wizardlybump17/wlib/command/result/CommandResult.java b/commands/src/main/java/com/wizardlybump17/wlib/command/result/CommandResult.java index e5d73ccb..04de928c 100644 --- a/commands/src/main/java/com/wizardlybump17/wlib/command/result/CommandResult.java +++ b/commands/src/main/java/com/wizardlybump17/wlib/command/result/CommandResult.java @@ -78,6 +78,10 @@ public interface CommandResult { return new NoContentResult<>(lastInputIndex, lastNode); } + static @NotNull NotFoundResult notFound(int lastInputIndex, @NotNull CommandNode lastNode) { + return new NotFoundResult<>(lastInputIndex, lastNode); + } + //with context static @NotNull SuccessResult successful(@NotNull CommandContext context, @Nullable T data) { @@ -107,4 +111,8 @@ public interface CommandResult { static @NotNull NoContentResult noContent(@NotNull CommandContext context) { return noContent(context.lastInputIndex(), context.lastNode()); } + + static @NotNull NotFoundResult notFound(@NotNull CommandContext context) { + return notFound(context.lastInputIndex(), context.lastNode()); + } } diff --git a/commands/src/main/java/com/wizardlybump17/wlib/command/result/error/NotFoundResult.java b/commands/src/main/java/com/wizardlybump17/wlib/command/result/error/NotFoundResult.java new file mode 100644 index 00000000..97f600e4 --- /dev/null +++ b/commands/src/main/java/com/wizardlybump17/wlib/command/result/error/NotFoundResult.java @@ -0,0 +1,14 @@ +package com.wizardlybump17.wlib.command.result.error; + +import com.wizardlybump17.wlib.command.node.CommandNode; +import org.jetbrains.annotations.NotNull; + +public record NotFoundResult(int lastInputIndex, @NotNull CommandNode lastNode) implements UnsuccessResult { + + public static final @NotNull String ID = "WLib:Error/NotFound"; + + @Override + public @NotNull String id() { + return ID; + } +} From da897a641b4ea3c0d16f7aca6bda18cac987801b Mon Sep 17 00:00:00 2001 From: WizardlyBump17 Date: Mon, 22 Dec 2025 18:48:52 -0300 Subject: [PATCH 292/363] added the ConflictResult --- .../wlib/command/result/CommandResult.java | 8 ++++++++ .../wlib/command/result/error/ConflictResult.java | 14 ++++++++++++++ 2 files changed, 22 insertions(+) create mode 100644 commands/src/main/java/com/wizardlybump17/wlib/command/result/error/ConflictResult.java diff --git a/commands/src/main/java/com/wizardlybump17/wlib/command/result/CommandResult.java b/commands/src/main/java/com/wizardlybump17/wlib/command/result/CommandResult.java index 04de928c..995406d5 100644 --- a/commands/src/main/java/com/wizardlybump17/wlib/command/result/CommandResult.java +++ b/commands/src/main/java/com/wizardlybump17/wlib/command/result/CommandResult.java @@ -82,6 +82,10 @@ public interface CommandResult { return new NotFoundResult<>(lastInputIndex, lastNode); } + static @NotNull ConflictResult conflict(int lastInputIndex, @NotNull CommandNode lastNode) { + return new ConflictResult<>(lastInputIndex, lastNode); + } + //with context static @NotNull SuccessResult successful(@NotNull CommandContext context, @Nullable T data) { @@ -115,4 +119,8 @@ public interface CommandResult { static @NotNull NotFoundResult notFound(@NotNull CommandContext context) { return notFound(context.lastInputIndex(), context.lastNode()); } + + static @NotNull ConflictResult conflict(@NotNull CommandContext context) { + return conflict(context.lastInputIndex(), context.lastNode()); + } } diff --git a/commands/src/main/java/com/wizardlybump17/wlib/command/result/error/ConflictResult.java b/commands/src/main/java/com/wizardlybump17/wlib/command/result/error/ConflictResult.java new file mode 100644 index 00000000..c97aa295 --- /dev/null +++ b/commands/src/main/java/com/wizardlybump17/wlib/command/result/error/ConflictResult.java @@ -0,0 +1,14 @@ +package com.wizardlybump17.wlib.command.result.error; + +import com.wizardlybump17.wlib.command.node.CommandNode; +import org.jetbrains.annotations.NotNull; + +public record ConflictResult(int lastInputIndex, @NotNull CommandNode lastNode) implements UnsuccessResult { + + public static final @NotNull String ID = "WLib:Error/Conflict"; + + @Override + public @NotNull String id() { + return ID; + } +} From 602b20569948067223089637710b7a8b1759746e Mon Sep 17 00:00:00 2001 From: WizardlyBump17 Date: Wed, 24 Dec 2025 01:18:14 -0300 Subject: [PATCH 293/363] skipping NMS on publish --- .github/workflows/publish.yml | 3 +++ build.gradle | 1 + core/build.gradle | 23 +++++++++++++++---- .../java/com/wizardlybump17/wlib/WLib.java | 6 ++--- 4 files changed, 24 insertions(+), 9 deletions(-) diff --git a/.github/workflows/publish.yml b/.github/workflows/publish.yml index a3653164..cc129cb0 100644 --- a/.github/workflows/publish.yml +++ b/.github/workflows/publish.yml @@ -24,6 +24,9 @@ jobs: run: echo "WLIB_BUILD_DATE=$(date +'%Y-%m-%d_%H-%M-%S')" >> "$GITHUB_ENV" - name: Get snapshot number run: echo "WLIB_SNAPSHOT_NUMBER=$((${{ github.run_number }}+${{ github.run_attempt }}))" >> $GITHUB_ENV + - name: "Skip NMS if needed" + if: ${{ github.event_name != 'release' }} + run: echo "WLIB_SKIP_NMS=true" >> "$GITHUB_ENV" - uses: actions/checkout@v4 - name: Set up JDK 21 uses: actions/setup-java@v4 diff --git a/build.gradle b/build.gradle index 5445af38..16409863 100644 --- a/build.gradle +++ b/build.gradle @@ -1,6 +1,7 @@ plugins { id("com.gradleup.shadow") version "9.2.2" id 'maven-publish' + id("systems.manifold.manifold-gradle-plugin") version "0.0.2-alpha" apply false } subprojects { diff --git a/core/build.gradle b/core/build.gradle index 3312cb24..a060e539 100644 --- a/core/build.gradle +++ b/core/build.gradle @@ -1,4 +1,7 @@ var gson = "2.13.2" +var manifold = "2025.1.27" + +apply plugin: "systems.manifold.manifold-gradle-plugin" dependencies { compileOnly( @@ -12,11 +15,6 @@ dependencies { project(':utils'), project(':versions:adapter'), - project(':versions:v1_20_R4'), - project(':versions:v1_21_R1'), - project(':versions:v1_21_R3'), - project(':versions:v1_21_R5'), - project(':database'), project(':objects'), @@ -27,7 +25,17 @@ dependencies { project(':bukkit-utils'), ) + if (System.getenv("WLIB_SKIP_NMS") == null) { + implementation(project(":versions:v1_20_R4")) + implementation(project(":versions:v1_21_R1")) + implementation(project(":versions:v1_21_R3")) + implementation(project(":versions:v1_21_R5")) + } + compileOnly("com.google.code.gson:gson:${gson}") + + annotationProcessor("systems.manifold:manifold-preprocessor:${manifold}") + testAnnotationProcessor("systems.manifold:manifold-preprocessor:${manifold}") } processResources { @@ -44,5 +52,10 @@ tasks { archiveFileName = 'WLib-' + project.version + '.jar' relocate("com.github.sisyphsu", "com.wizardlybump17.wlib.libs.com.github.sisyphsu") } + + tasks.withType(JavaCompile) { + if (System.getenv("WLIB_SKIP_NMS") == null) + options.compilerArgs += ["-Awlib_include_nms"] + } } diff --git a/core/src/main/java/com/wizardlybump17/wlib/WLib.java b/core/src/main/java/com/wizardlybump17/wlib/WLib.java index fbe7ab2d..0e381cba 100644 --- a/core/src/main/java/com/wizardlybump17/wlib/WLib.java +++ b/core/src/main/java/com/wizardlybump17/wlib/WLib.java @@ -2,10 +2,6 @@ import com.google.gson.Gson; import com.google.gson.GsonBuilder; -import com.wizardlybump17.wlib.adapter.AttributeAdapter; -import com.wizardlybump17.wlib.adapter.ItemAdapter; -import com.wizardlybump17.wlib.adapter.command.CommandMapAdapter; -import com.wizardlybump17.wlib.adapter.player.PlayerAdapter; import com.wizardlybump17.wlib.command.WLibCommandExecutor; import com.wizardlybump17.wlib.command.extractor.method.MethodCommandExtractor; import com.wizardlybump17.wlib.command.extractor.method.factory.JsonElementMethodCommandNodeFactory; @@ -158,6 +154,7 @@ private void initAdapters() { } private void setupAdapters() { + #if WLIB_INCLUDE_NMS String version = Bukkit.getMinecraftVersion(); switch (version) { case "1.20.5", "1.20.6" -> { @@ -186,6 +183,7 @@ private void setupAdapters() { } default -> getLogger().severe("The server version (" + version + ") is not supported by WLib yet."); } + #endif } public static WLib getInstance() { From 089208eb3b5da01216ee3d9372207c5c4b8f867c Mon Sep 17 00:00:00 2001 From: WizardlyBump17 Date: Thu, 25 Dec 2025 21:26:42 -0300 Subject: [PATCH 294/363] added the AllowedInputs.Any class --- .../wlib/command/input/AllowedInputs.java | 54 +++++++++++++++++++ 1 file changed, 54 insertions(+) diff --git a/commands/src/main/java/com/wizardlybump17/wlib/command/input/AllowedInputs.java b/commands/src/main/java/com/wizardlybump17/wlib/command/input/AllowedInputs.java index 3aef4108..892e83bf 100644 --- a/commands/src/main/java/com/wizardlybump17/wlib/command/input/AllowedInputs.java +++ b/commands/src/main/java/com/wizardlybump17/wlib/command/input/AllowedInputs.java @@ -1,8 +1,62 @@ package com.wizardlybump17.wlib.command.input; +import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.Nullable; +import java.util.Objects; + public interface AllowedInputs { boolean isAllowed(@Nullable T input); + + @SuppressWarnings("unchecked") + static @NotNull Any anyNullable() { + return (Any) Any.NULLABLE; + } + + @SuppressWarnings("unchecked") + static @NotNull Any anyNotNull() { + return (Any) Any.NOT_NULL; + } + + final class Any implements AllowedInputs { + + private static final @NotNull Any NULLABLE = new Any<>(true); + private static final @NotNull Any NOT_NULL = new Any<>(false); + + private final boolean nullable; + + Any(boolean nullable) { + this.nullable = nullable; + } + + @Override + public boolean isAllowed(@Nullable T input) { + return nullable || input != null; + } + + public boolean nullable() { + return nullable; + } + + @Override + public boolean equals(Object o) { + if (o == null || getClass() != o.getClass()) + return false; + Any any = (Any) o; + return nullable == any.nullable; + } + + @Override + public int hashCode() { + return Objects.hashCode(nullable); + } + + @Override + public String toString() { + return "AllowedInputs$Any{" + + "nullable=" + nullable + + '}'; + } + } } From 4621d456e13180014a053dcf5b33346ecf12d1d6 Mon Sep 17 00:00:00 2001 From: WizardlyBump17 Date: Thu, 25 Dec 2025 21:26:48 -0300 Subject: [PATCH 295/363] added the InstantCommandNode --- .../factory/object/InstantCommandNode.java | 44 +++++++++++++++++++ 1 file changed, 44 insertions(+) create mode 100644 commands/src/main/java/com/wizardlybump17/wlib/command/extractor/method/factory/object/InstantCommandNode.java diff --git a/commands/src/main/java/com/wizardlybump17/wlib/command/extractor/method/factory/object/InstantCommandNode.java b/commands/src/main/java/com/wizardlybump17/wlib/command/extractor/method/factory/object/InstantCommandNode.java new file mode 100644 index 00000000..e1899eaa --- /dev/null +++ b/commands/src/main/java/com/wizardlybump17/wlib/command/extractor/method/factory/object/InstantCommandNode.java @@ -0,0 +1,44 @@ +package com.wizardlybump17.wlib.command.extractor.method.factory.object; + +import com.wizardlybump17.wlib.command.exception.InputParsingException; +import com.wizardlybump17.wlib.command.executor.CommandNodeExecutor; +import com.wizardlybump17.wlib.command.input.AllowedInputs; +import com.wizardlybump17.wlib.command.node.CommandNode; +import com.wizardlybump17.wlib.command.suggestion.Suggester; +import org.jetbrains.annotations.NotNull; +import org.jetbrains.annotations.Nullable; + +import java.time.Instant; +import java.time.format.DateTimeParseException; +import java.util.List; + +public class InstantCommandNode extends CommandNode { + + public InstantCommandNode(@NotNull String name, @NotNull List> children, @NotNull AllowedInputs allowedInputs, @Nullable Suggester suggester, @Nullable CommandNodeExecutor executor, @Nullable String permission) { + super(name, children, allowedInputs, suggester, executor, permission); + } + + @Override + public @Nullable Instant parse(@NotNull String input) throws InputParsingException { + try { + return Instant.parse(input); + } catch (DateTimeParseException e) { + throw new InputParsingException("Could not parse as Instant: " + input, e); + } + } + + @Override + public @NotNull InstantCommandNode withChildren(@NotNull List> children) { + return new InstantCommandNode(getName(), children, getAllowedInputs(), getSuggester(), getExecutor(), getPermission()); + } + + @Override + public @NotNull InstantCommandNode withExecutor(@Nullable CommandNodeExecutor executor) { + return new InstantCommandNode(getName(), getChildren(), getAllowedInputs(), getSuggester(), executor, getPermission()); + } + + @Override + public @NotNull InstantCommandNode withPermission(@Nullable String permission) { + return new InstantCommandNode(getName(), getChildren(), getAllowedInputs(), getSuggester(), getExecutor(), permission); + } +} From 2014006d43eb5f04c9b03ca101810e4df67b58ce Mon Sep 17 00:00:00 2001 From: WizardlyBump17 Date: Thu, 25 Dec 2025 22:32:04 -0300 Subject: [PATCH 296/363] returning null if needed --- .../extractor/method/factory/object/InstantCommandNode.java | 2 ++ 1 file changed, 2 insertions(+) diff --git a/commands/src/main/java/com/wizardlybump17/wlib/command/extractor/method/factory/object/InstantCommandNode.java b/commands/src/main/java/com/wizardlybump17/wlib/command/extractor/method/factory/object/InstantCommandNode.java index e1899eaa..36030ef2 100644 --- a/commands/src/main/java/com/wizardlybump17/wlib/command/extractor/method/factory/object/InstantCommandNode.java +++ b/commands/src/main/java/com/wizardlybump17/wlib/command/extractor/method/factory/object/InstantCommandNode.java @@ -20,6 +20,8 @@ public InstantCommandNode(@NotNull String name, @NotNull List> ch @Override public @Nullable Instant parse(@NotNull String input) throws InputParsingException { + if (input.equalsIgnoreCase("null")) + return null; try { return Instant.parse(input); } catch (DateTimeParseException e) { From 7f53a8df5d82182e8b89c145d9ccd17029827aa0 Mon Sep 17 00:00:00 2001 From: WizardlyBump17 Date: Fri, 26 Dec 2025 21:37:39 -0300 Subject: [PATCH 297/363] added the MiniMessageUtil.getMessage(String, String, Object, Map) method --- .../wlib/util/bukkit/MiniMessageUtil.java | 26 +++++++++++++++++++ 1 file changed, 26 insertions(+) diff --git a/bukkit-utils/src/main/java/com/wizardlybump17/wlib/util/bukkit/MiniMessageUtil.java b/bukkit-utils/src/main/java/com/wizardlybump17/wlib/util/bukkit/MiniMessageUtil.java index 6cbc701a..6ad72e33 100644 --- a/bukkit-utils/src/main/java/com/wizardlybump17/wlib/util/bukkit/MiniMessageUtil.java +++ b/bukkit-utils/src/main/java/com/wizardlybump17/wlib/util/bukkit/MiniMessageUtil.java @@ -33,6 +33,32 @@ private MiniMessageUtil() { return miniMessage.deserialize(message, resolvers); } + public static @NotNull Component getMessage(@NotNull String message, @NotNull String placeholderKey, @NotNull Object placeholderValue, @NotNull Map additionalPlaceholders) { + MiniMessage miniMessage = MiniMessage.miniMessage(); + if (additionalPlaceholders.isEmpty()) + return getMessage(message, Map.of(placeholderKey, placeholderValue)); + + TagResolver[] resolvers = new TagResolver[additionalPlaceholders.size() + 1]; + int resolverIndex = 0; + for (Map.Entry entry : additionalPlaceholders.entrySet()) { + String key = entry.getKey(); + Object value = entry.getValue(); + resolvers[resolverIndex++] = TagResolver.builder() + .tag( + key, + Tag.inserting(value instanceof Component component ? component : Component.text(String.valueOf(value))) + ) + .build(); + } + resolvers[resolverIndex] = TagResolver.builder() + .tag( + placeholderKey, + Tag.inserting(placeholderValue instanceof Component component ? component : Component.text(String.valueOf(placeholderValue))) + ) + .build(); + return miniMessage.deserialize(message, resolvers); + } + public static @NotNull Component getMessage(@NotNull String message) { return getMessage(message, Map.of()); } From 12a1db44431dd81c1d9ebeec86935873aa9f8650 Mon Sep 17 00:00:00 2001 From: WizardlyBump17 Date: Fri, 26 Dec 2025 22:08:47 -0300 Subject: [PATCH 298/363] added the MiniMessageUtil.getMessage(String, String, Object, String, Map) method --- .../wlib/util/bukkit/MiniMessageUtil.java | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/bukkit-utils/src/main/java/com/wizardlybump17/wlib/util/bukkit/MiniMessageUtil.java b/bukkit-utils/src/main/java/com/wizardlybump17/wlib/util/bukkit/MiniMessageUtil.java index 6ad72e33..89b5c3d8 100644 --- a/bukkit-utils/src/main/java/com/wizardlybump17/wlib/util/bukkit/MiniMessageUtil.java +++ b/bukkit-utils/src/main/java/com/wizardlybump17/wlib/util/bukkit/MiniMessageUtil.java @@ -33,7 +33,7 @@ private MiniMessageUtil() { return miniMessage.deserialize(message, resolvers); } - public static @NotNull Component getMessage(@NotNull String message, @NotNull String placeholderKey, @NotNull Object placeholderValue, @NotNull Map additionalPlaceholders) { + public static @NotNull Component getMessage(@NotNull String message, @NotNull String placeholderKey, @NotNull Object placeholderValue, @NotNull String prefix, @NotNull Map additionalPlaceholders) { MiniMessage miniMessage = MiniMessage.miniMessage(); if (additionalPlaceholders.isEmpty()) return getMessage(message, Map.of(placeholderKey, placeholderValue)); @@ -45,20 +45,24 @@ private MiniMessageUtil() { Object value = entry.getValue(); resolvers[resolverIndex++] = TagResolver.builder() .tag( - key, + prefix + key, Tag.inserting(value instanceof Component component ? component : Component.text(String.valueOf(value))) ) .build(); } resolvers[resolverIndex] = TagResolver.builder() .tag( - placeholderKey, + prefix + placeholderKey, Tag.inserting(placeholderValue instanceof Component component ? component : Component.text(String.valueOf(placeholderValue))) ) .build(); return miniMessage.deserialize(message, resolvers); } + public static @NotNull Component getMessage(@NotNull String message, @NotNull String placeholderKey, @NotNull Object placeholderValue, @NotNull Map additionalPlaceholders) { + return getMessage(message, placeholderKey, placeholderValue, "", additionalPlaceholders); + } + public static @NotNull Component getMessage(@NotNull String message) { return getMessage(message, Map.of()); } From a5e2d65c8b03919a089834d379df5d6c25f076d8 Mon Sep 17 00:00:00 2001 From: WizardlyBump17 Date: Fri, 26 Dec 2025 22:48:36 -0300 Subject: [PATCH 299/363] added the EnumSuggester --- .../suggestion/object/EnumSuggester.java | 66 +++++++++++++++++++ 1 file changed, 66 insertions(+) create mode 100644 commands/src/main/java/com/wizardlybump17/wlib/command/suggestion/object/EnumSuggester.java diff --git a/commands/src/main/java/com/wizardlybump17/wlib/command/suggestion/object/EnumSuggester.java b/commands/src/main/java/com/wizardlybump17/wlib/command/suggestion/object/EnumSuggester.java new file mode 100644 index 00000000..66cd5e27 --- /dev/null +++ b/commands/src/main/java/com/wizardlybump17/wlib/command/suggestion/object/EnumSuggester.java @@ -0,0 +1,66 @@ +package com.wizardlybump17.wlib.command.suggestion.object; + +import com.wizardlybump17.wlib.command.exception.SuggesterException; +import com.wizardlybump17.wlib.command.node.CommandNode; +import com.wizardlybump17.wlib.command.sender.CommandSender; +import com.wizardlybump17.wlib.command.suggestion.Suggester; +import org.jetbrains.annotations.NotNull; + +import java.util.List; +import java.util.Objects; + +public interface EnumSuggester> extends Suggester { + + @Override + default @NotNull String getStringRepresentation(@NotNull E value) { + return value.name(); + } + + @NotNull Class enumType(); + + static > @NotNull Any any(@NotNull Class enumType) { + return new Any<>(enumType); + } + + final class Any> implements EnumSuggester { + + private final @NotNull List cache; + private final @NotNull Class enumType; + + private Any(@NotNull Class enumType) { + this.enumType = enumType; + this.cache = List.of(enumType.getEnumConstants()); + } + + @Override + public @NotNull List getSuggestions(@NotNull CommandSender sender, @NotNull List input, @NotNull String current, @NotNull CommandNode currentNode) throws SuggesterException { + return cache; + } + + @Override + public @NotNull Class enumType() { + return enumType; + } + + @Override + public boolean equals(Object o) { + if (o == null || getClass() != o.getClass()) + return false; + Any any = (Any) o; + return Objects.equals(cache, any.cache) && Objects.equals(enumType, any.enumType); + } + + @Override + public int hashCode() { + return Objects.hash(cache, enumType); + } + + @Override + public String toString() { + return "EnumSuggester$Any{" + + "cache=" + cache + + ", enumType=" + enumType + + '}'; + } + } +} From a1c0b88b9d449c86abe8b7e2cec60617f0c0948d Mon Sep 17 00:00:00 2001 From: WizardlyBump17 Date: Fri, 26 Dec 2025 22:52:19 -0300 Subject: [PATCH 300/363] added the EnumCommandNode --- .../command/node/object/EnumCommandNode.java | 49 +++++++++++++++++++ 1 file changed, 49 insertions(+) create mode 100644 commands/src/main/java/com/wizardlybump17/wlib/command/node/object/EnumCommandNode.java diff --git a/commands/src/main/java/com/wizardlybump17/wlib/command/node/object/EnumCommandNode.java b/commands/src/main/java/com/wizardlybump17/wlib/command/node/object/EnumCommandNode.java new file mode 100644 index 00000000..b9cdf5f0 --- /dev/null +++ b/commands/src/main/java/com/wizardlybump17/wlib/command/node/object/EnumCommandNode.java @@ -0,0 +1,49 @@ +package com.wizardlybump17.wlib.command.node.object; + +import com.wizardlybump17.wlib.command.exception.InputParsingException; +import com.wizardlybump17.wlib.command.executor.CommandNodeExecutor; +import com.wizardlybump17.wlib.command.input.AllowedInputs; +import com.wizardlybump17.wlib.command.node.CommandNode; +import com.wizardlybump17.wlib.command.suggestion.Suggester; +import org.jetbrains.annotations.NotNull; +import org.jetbrains.annotations.Nullable; + +import java.util.List; + +public class EnumCommandNode> extends CommandNode { + + private final @NotNull Class enumType; + + public EnumCommandNode(@NotNull String name, @NotNull List> children, @NotNull AllowedInputs allowedInputs, @Nullable Suggester suggester, @Nullable CommandNodeExecutor executor, @Nullable String permission, @NotNull Class enumType) { + super(name, children, allowedInputs, suggester, executor, permission); + this.enumType = enumType; + } + + @Override + public @Nullable E parse(@NotNull String input) throws InputParsingException { + try { + return Enum.valueOf(enumType, input.toUpperCase()); + } catch (IllegalArgumentException e) { + throw new InputParsingException("Could not parse as " + enumType.getSimpleName() + ": " + input, e); + } + } + + @Override + public @NotNull CommandNode withChildren(@NotNull List> children) { + return new EnumCommandNode<>(getName(), children, getAllowedInputs(), getSuggester(), getExecutor(), getPermission(), enumType); + } + + @Override + public @NotNull CommandNode withExecutor(@Nullable CommandNodeExecutor executor) { + return new EnumCommandNode<>(getName(), getChildren(), getAllowedInputs(), getSuggester(), executor, getPermission(), enumType); + } + + @Override + public @NotNull CommandNode withPermission(@Nullable String permission) { + return new EnumCommandNode<>(getName(), getChildren(), getAllowedInputs(), getSuggester(), getExecutor(), permission, enumType); + } + + public @NotNull Class getEnumType() { + return enumType; + } +} From 427be218bc9822cc8586bfdd8cde78c8f2b532e9 Mon Sep 17 00:00:00 2001 From: WizardlyBump17 Date: Mon, 29 Dec 2025 00:10:57 -0300 Subject: [PATCH 301/363] moved the JsonElementCommandNode system to the commands module --- commands/build.gradle.kts | 3 + .../JsonElementMethodCommandNodeFactory.java | 9 +- .../node/object}/JsonElementCommandNode.java | 4 +- .../object}/JsonElementSuggester.java | 4 +- .../java/com/wizardlybump17/wlib/WLib.java | 2 +- .../input/AllowedJsonElementInputs.java | 132 ------------------ 6 files changed, 15 insertions(+), 139 deletions(-) rename {core/src/main/java/com/wizardlybump17/wlib/command/extractor/method/factory => commands/src/main/java/com/wizardlybump17/wlib/command/extractor/method/factory/object}/JsonElementMethodCommandNodeFactory.java (83%) rename {core/src/main/java/com/wizardlybump17/wlib/command/node => commands/src/main/java/com/wizardlybump17/wlib/command/node/object}/JsonElementCommandNode.java (94%) rename {core/src/main/java/com/wizardlybump17/wlib/command/suggestion => commands/src/main/java/com/wizardlybump17/wlib/command/suggestion/object}/JsonElementSuggester.java (94%) delete mode 100644 core/src/main/java/com/wizardlybump17/wlib/command/input/AllowedJsonElementInputs.java diff --git a/commands/build.gradle.kts b/commands/build.gradle.kts index a133d837..10b877a5 100644 --- a/commands/build.gradle.kts +++ b/commands/build.gradle.kts @@ -1,9 +1,12 @@ val annotations = "26.0.1" +val gson = "2.13.2" dependencies { implementation("org.jetbrains:annotations:${annotations}") implementation(project(":objects")) implementation(project(":utils")) + implementation("com.google.code.gson:gson:${gson}") + testImplementation("org.jetbrains:annotations:${annotations}") } diff --git a/core/src/main/java/com/wizardlybump17/wlib/command/extractor/method/factory/JsonElementMethodCommandNodeFactory.java b/commands/src/main/java/com/wizardlybump17/wlib/command/extractor/method/factory/object/JsonElementMethodCommandNodeFactory.java similarity index 83% rename from core/src/main/java/com/wizardlybump17/wlib/command/extractor/method/factory/JsonElementMethodCommandNodeFactory.java rename to commands/src/main/java/com/wizardlybump17/wlib/command/extractor/method/factory/object/JsonElementMethodCommandNodeFactory.java index 041c31f4..8c9072a3 100644 --- a/core/src/main/java/com/wizardlybump17/wlib/command/extractor/method/factory/JsonElementMethodCommandNodeFactory.java +++ b/commands/src/main/java/com/wizardlybump17/wlib/command/extractor/method/factory/object/JsonElementMethodCommandNodeFactory.java @@ -1,12 +1,13 @@ -package com.wizardlybump17.wlib.command.extractor.method.factory; +package com.wizardlybump17.wlib.command.extractor.method.factory.object; import com.google.gson.Gson; import com.google.gson.JsonElement; import com.wizardlybump17.wlib.command.annotation.Command; import com.wizardlybump17.wlib.command.annotation.NonNullInput; -import com.wizardlybump17.wlib.command.input.AllowedJsonElementInputs; +import com.wizardlybump17.wlib.command.extractor.method.factory.MethodCommandNodeFactory; +import com.wizardlybump17.wlib.command.input.AllowedInputs; import com.wizardlybump17.wlib.command.node.CommandNode; -import com.wizardlybump17.wlib.command.node.JsonElementCommandNode; +import com.wizardlybump17.wlib.command.node.object.JsonElementCommandNode; import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.Nullable; @@ -27,7 +28,7 @@ public JsonElementMethodCommandNodeFactory(@NotNull Gson gson) { return new JsonElementCommandNode( name, root == null ? List.of() : List.of(root), - parameter.isAnnotationPresent(NonNullInput.class) ? AllowedJsonElementInputs.anyNotNull() : AllowedJsonElementInputs.anyNullable(), + parameter.isAnnotationPresent(NonNullInput.class) ? AllowedInputs.anyNotNull() : AllowedInputs.anyNullable(), null, null, null, diff --git a/core/src/main/java/com/wizardlybump17/wlib/command/node/JsonElementCommandNode.java b/commands/src/main/java/com/wizardlybump17/wlib/command/node/object/JsonElementCommandNode.java similarity index 94% rename from core/src/main/java/com/wizardlybump17/wlib/command/node/JsonElementCommandNode.java rename to commands/src/main/java/com/wizardlybump17/wlib/command/node/object/JsonElementCommandNode.java index 4db754a0..4667f8af 100644 --- a/core/src/main/java/com/wizardlybump17/wlib/command/node/JsonElementCommandNode.java +++ b/commands/src/main/java/com/wizardlybump17/wlib/command/node/object/JsonElementCommandNode.java @@ -1,4 +1,4 @@ -package com.wizardlybump17.wlib.command.node; +package com.wizardlybump17.wlib.command.node.object; import com.google.gson.Gson; import com.google.gson.JsonElement; @@ -6,12 +6,14 @@ import com.wizardlybump17.wlib.command.exception.InputParsingException; import com.wizardlybump17.wlib.command.executor.CommandNodeExecutor; import com.wizardlybump17.wlib.command.input.AllowedInputs; +import com.wizardlybump17.wlib.command.node.CommandNode; import com.wizardlybump17.wlib.command.suggestion.Suggester; import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.Nullable; import java.util.List; +//TODO: test public class JsonElementCommandNode extends CommandNode { private final @NotNull Gson gson; diff --git a/core/src/main/java/com/wizardlybump17/wlib/command/suggestion/JsonElementSuggester.java b/commands/src/main/java/com/wizardlybump17/wlib/command/suggestion/object/JsonElementSuggester.java similarity index 94% rename from core/src/main/java/com/wizardlybump17/wlib/command/suggestion/JsonElementSuggester.java rename to commands/src/main/java/com/wizardlybump17/wlib/command/suggestion/object/JsonElementSuggester.java index 2dee37f3..67f26f18 100644 --- a/core/src/main/java/com/wizardlybump17/wlib/command/suggestion/JsonElementSuggester.java +++ b/commands/src/main/java/com/wizardlybump17/wlib/command/suggestion/object/JsonElementSuggester.java @@ -1,9 +1,11 @@ -package com.wizardlybump17.wlib.command.suggestion; +package com.wizardlybump17.wlib.command.suggestion.object; import com.google.gson.Gson; import com.google.gson.JsonElement; import com.wizardlybump17.wlib.command.node.CommandNode; import com.wizardlybump17.wlib.command.sender.CommandSender; +import com.wizardlybump17.wlib.command.suggestion.AbstractValuesSuggester; +import com.wizardlybump17.wlib.command.suggestion.Suggester; import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.Unmodifiable; diff --git a/core/src/main/java/com/wizardlybump17/wlib/WLib.java b/core/src/main/java/com/wizardlybump17/wlib/WLib.java index 0e381cba..ebd86592 100644 --- a/core/src/main/java/com/wizardlybump17/wlib/WLib.java +++ b/core/src/main/java/com/wizardlybump17/wlib/WLib.java @@ -4,9 +4,9 @@ import com.google.gson.GsonBuilder; import com.wizardlybump17.wlib.command.WLibCommandExecutor; import com.wizardlybump17.wlib.command.extractor.method.MethodCommandExtractor; -import com.wizardlybump17.wlib.command.extractor.method.factory.JsonElementMethodCommandNodeFactory; import com.wizardlybump17.wlib.command.extractor.method.factory.OfflinePlayerMethodCommandNodeFactory; import com.wizardlybump17.wlib.command.extractor.method.factory.PlayerMethodCommandNodeFactory; +import com.wizardlybump17.wlib.command.extractor.method.factory.object.JsonElementMethodCommandNodeFactory; import com.wizardlybump17.wlib.command.listener.BukkitCommandManagerListener; import com.wizardlybump17.wlib.command.manager.CommandManager; import com.wizardlybump17.wlib.command.registry.MethodCommandNodeFactoryRegistry; diff --git a/core/src/main/java/com/wizardlybump17/wlib/command/input/AllowedJsonElementInputs.java b/core/src/main/java/com/wizardlybump17/wlib/command/input/AllowedJsonElementInputs.java deleted file mode 100644 index 465c63dd..00000000 --- a/core/src/main/java/com/wizardlybump17/wlib/command/input/AllowedJsonElementInputs.java +++ /dev/null @@ -1,132 +0,0 @@ -package com.wizardlybump17.wlib.command.input; - -import com.google.gson.JsonElement; -import org.jetbrains.annotations.NotNull; -import org.jetbrains.annotations.Nullable; - -import java.util.List; -import java.util.Objects; - -public interface AllowedJsonElementInputs extends AllowedInputs { - - static @NotNull Value value(@NotNull JsonElement value) { - return new Value(value); - } - - static @NotNull Values values(@NotNull List values) { - return new Values(values); - } - - static @NotNull Any anyNotNull() { - return Any.NOT_NULL; - } - - static @NotNull Any anyNullable() { - return Any.NULLABLE; - } - - final class Value implements AllowedJsonElementInputs, SingleValueInput { - - private final @NotNull JsonElement value; - - Value(@NotNull JsonElement value) { - this.value = value; - } - - @Override - public @NotNull JsonElement value() { - return value; - } - - @Override - public boolean equals(Object object) { - if (object == null || getClass() != object.getClass()) - return false; - Value value1 = (Value) object; - return Objects.equals(value, value1.value); - } - - @Override - public int hashCode() { - return Objects.hashCode(value); - } - - @Override - public String toString() { - return "AllowedJsonElementInputs$Value{" + - "value=" + value + - '}'; - } - } - - final class Values implements AllowedJsonElementInputs, AllowedListInputs { - - private final @NotNull List values; - - private Values(@NotNull List values) { - this.values = values; - } - - @Override - public @NotNull List allowedValues() { - return values; - } - - @Override - public boolean equals(Object object) { - if (object == null || getClass() != object.getClass()) - return false; - Values values1 = (Values) object; - return Objects.equals(values, values1.values); - } - - @Override - public int hashCode() { - return Objects.hashCode(values); - } - - @Override - public String toString() { - return "AllowedJsonElementInputs$Values{" + - "values=" + values + - '}'; - } - } - - final class Any implements AllowedJsonElementInputs { - - private static final @NotNull Any NOT_NULL = new Any(false); - private static final @NotNull Any NULLABLE = new Any(true); - - private final boolean nullable; - - private Any(boolean nullable) { - this.nullable = nullable; - } - - @Override - public boolean isAllowed(@Nullable JsonElement input) { - return nullable || input != null; - } - - @Override - public boolean equals(Object o) { - if (o == null || getClass() != o.getClass()) - return false; - Any any = (Any) o; - return nullable == any.nullable; - } - - @Override - public int hashCode() { - return Objects.hashCode(nullable); - } - - @Override - public String toString() { - return "AllowedJsonElementInputs$Any{" + - "nullable=" + nullable + - '}'; - } - } -} From 9fce7f3300c9477c779ca323878ed91001c81ae9 Mon Sep 17 00:00:00 2001 From: WizardlyBump17 Date: Mon, 29 Dec 2025 15:20:45 -0300 Subject: [PATCH 302/363] added a default ValuesSuggester implementation --- .../wlib/command/suggestion/Suggester.java | 9 ++++ .../command/suggestion/ValuesSuggester.java | 41 +++++++++++++++++++ 2 files changed, 50 insertions(+) diff --git a/commands/src/main/java/com/wizardlybump17/wlib/command/suggestion/Suggester.java b/commands/src/main/java/com/wizardlybump17/wlib/command/suggestion/Suggester.java index 7505469e..de4ffd75 100644 --- a/commands/src/main/java/com/wizardlybump17/wlib/command/suggestion/Suggester.java +++ b/commands/src/main/java/com/wizardlybump17/wlib/command/suggestion/Suggester.java @@ -6,6 +6,7 @@ import org.jetbrains.annotations.NotNull; import java.util.List; +import java.util.function.Function; public interface Suggester { @@ -18,4 +19,12 @@ public interface Suggester { default boolean needsEscape() { return false; } + + static ValuesSuggester.@NotNull Values values(@NotNull List values, @NotNull Function stringRepresentation) { + return new ValuesSuggester.Values<>(values, stringRepresentation); + } + + static ValuesSuggester.@NotNull Values values(@NotNull List values) { + return new ValuesSuggester.Values<>(values); + } } diff --git a/commands/src/main/java/com/wizardlybump17/wlib/command/suggestion/ValuesSuggester.java b/commands/src/main/java/com/wizardlybump17/wlib/command/suggestion/ValuesSuggester.java index 18b41826..7e248b89 100644 --- a/commands/src/main/java/com/wizardlybump17/wlib/command/suggestion/ValuesSuggester.java +++ b/commands/src/main/java/com/wizardlybump17/wlib/command/suggestion/ValuesSuggester.java @@ -1,10 +1,51 @@ package com.wizardlybump17.wlib.command.suggestion; +import com.wizardlybump17.wlib.command.exception.SuggesterException; +import com.wizardlybump17.wlib.command.node.CommandNode; +import com.wizardlybump17.wlib.command.sender.CommandSender; import org.jetbrains.annotations.NotNull; +import org.jetbrains.annotations.Nullable; +import org.jetbrains.annotations.Unmodifiable; import java.util.List; +import java.util.function.Function; public interface ValuesSuggester extends Suggester { @NotNull List values(); + + final class Values implements ValuesSuggester { + + private final @NotNull List values; + private final @Nullable Function stringRepresentationFunction; + + Values(@NotNull List values, @NotNull Function stringRepresentationFunction) { + this.values = List.copyOf(values); + this.stringRepresentationFunction = stringRepresentationFunction; + } + + Values(@NotNull List values) { + this.values = List.copyOf(values); + stringRepresentationFunction = null; + } + + @Override + public @NotNull @Unmodifiable List values() { + return values; + } + + public @Nullable Function stringRepresentation() { + return stringRepresentationFunction; + } + + @Override + public @NotNull List getSuggestions(@NotNull CommandSender sender, @NotNull List input, @NotNull String current, @NotNull CommandNode currentNode) throws SuggesterException { + return values; + } + + @Override + public @NotNull String getStringRepresentation(@NotNull T value) { + return stringRepresentationFunction == null ? ValuesSuggester.super.getStringRepresentation(value) : stringRepresentationFunction.apply(value); + } + } } From 91b98acdd75f0737cd6fa6f7f8538cb6935a3b66 Mon Sep 17 00:00:00 2001 From: WizardlyBump17 Date: Mon, 29 Dec 2025 15:22:02 -0300 Subject: [PATCH 303/363] implementing equals, hashCode and toString --- .../command/suggestion/ValuesSuggester.java | 22 +++++++++++++++++++ 1 file changed, 22 insertions(+) diff --git a/commands/src/main/java/com/wizardlybump17/wlib/command/suggestion/ValuesSuggester.java b/commands/src/main/java/com/wizardlybump17/wlib/command/suggestion/ValuesSuggester.java index 7e248b89..cb283d2e 100644 --- a/commands/src/main/java/com/wizardlybump17/wlib/command/suggestion/ValuesSuggester.java +++ b/commands/src/main/java/com/wizardlybump17/wlib/command/suggestion/ValuesSuggester.java @@ -8,6 +8,7 @@ import org.jetbrains.annotations.Unmodifiable; import java.util.List; +import java.util.Objects; import java.util.function.Function; public interface ValuesSuggester extends Suggester { @@ -47,5 +48,26 @@ final class Values implements ValuesSuggester { public @NotNull String getStringRepresentation(@NotNull T value) { return stringRepresentationFunction == null ? ValuesSuggester.super.getStringRepresentation(value) : stringRepresentationFunction.apply(value); } + + @Override + public boolean equals(Object o) { + if (o == null || getClass() != o.getClass()) + return false; + Values values1 = (Values) o; + return Objects.equals(values, values1.values) && Objects.equals(stringRepresentationFunction, values1.stringRepresentationFunction); + } + + @Override + public int hashCode() { + return Objects.hash(values, stringRepresentationFunction); + } + + @Override + public String toString() { + return "ValuesSuggester$Values{" + + "values=" + values + + ", stringRepresentationFunction=" + stringRepresentationFunction + + '}'; + } } } From bf27eda72c19b6d7cb616a0ed3d72bc91186d1ff Mon Sep 17 00:00:00 2001 From: WizardlyBump17 Date: Mon, 29 Dec 2025 15:29:01 -0300 Subject: [PATCH 304/363] added a simple implementation of the AllowedListInputs --- .../wlib/command/input/AllowedInputs.java | 5 +++ .../wlib/command/input/AllowedListInputs.java | 35 +++++++++++++++++++ 2 files changed, 40 insertions(+) diff --git a/commands/src/main/java/com/wizardlybump17/wlib/command/input/AllowedInputs.java b/commands/src/main/java/com/wizardlybump17/wlib/command/input/AllowedInputs.java index 892e83bf..afa40388 100644 --- a/commands/src/main/java/com/wizardlybump17/wlib/command/input/AllowedInputs.java +++ b/commands/src/main/java/com/wizardlybump17/wlib/command/input/AllowedInputs.java @@ -3,6 +3,7 @@ import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.Nullable; +import java.util.List; import java.util.Objects; public interface AllowedInputs { @@ -19,6 +20,10 @@ public interface AllowedInputs { return (Any) Any.NOT_NULL; } + static AllowedListInputs.@NotNull Values values(@NotNull List values) { + return new AllowedListInputs.Values<>(values); + } + final class Any implements AllowedInputs { private static final @NotNull Any NULLABLE = new Any<>(true); diff --git a/commands/src/main/java/com/wizardlybump17/wlib/command/input/AllowedListInputs.java b/commands/src/main/java/com/wizardlybump17/wlib/command/input/AllowedListInputs.java index 2eeb37ff..5a6a4fbb 100644 --- a/commands/src/main/java/com/wizardlybump17/wlib/command/input/AllowedListInputs.java +++ b/commands/src/main/java/com/wizardlybump17/wlib/command/input/AllowedListInputs.java @@ -4,6 +4,7 @@ import org.jetbrains.annotations.Nullable; import java.util.List; +import java.util.Objects; public interface AllowedListInputs extends AllowedInputs { @@ -15,4 +16,38 @@ default boolean isAllowed(@Nullable T input) { return false; return allowedValues().contains(input); } + + final class Values implements AllowedListInputs { + + private final @NotNull List values; + + Values(@NotNull List values) { + this.values = List.copyOf(values); + } + + @Override + public @NotNull List allowedValues() { + return values; + } + + @Override + public boolean equals(Object o) { + if (o == null || getClass() != o.getClass()) + return false; + Values values1 = (Values) o; + return Objects.equals(values, values1.values); + } + + @Override + public int hashCode() { + return Objects.hashCode(values); + } + + @Override + public String toString() { + return "AllowedListInputs$Values{" + + "values=" + values + + '}'; + } + } } From 480d628886f316d93e018179474b00e20a81a6bf Mon Sep 17 00:00:00 2001 From: WizardlyBump17 Date: Mon, 29 Dec 2025 15:33:53 -0300 Subject: [PATCH 305/363] fixed --- .../wlib/command/input/object/AllowedUUIDInputs.java | 8 ++++---- .../command/input/primitive/AllowedCharacterInputs.java | 2 +- .../input/primitive/number/AllowedNumberInputs.java | 2 +- .../wlib/command/input/string/AllowedStringInputs.java | 8 ++++---- .../command/suggestion/object/JsonElementSuggester.java | 2 +- .../suggestion/primitive/number/ByteSuggester.java | 6 +++--- .../suggestion/primitive/number/IntegerSuggester.java | 6 +++--- .../suggestion/primitive/number/LongSuggester.java | 6 +++--- .../suggestion/primitive/number/ShortSuggester.java | 6 +++--- .../wlib/command/input/AllowedOfflinePlayerInputs.java | 8 ++++---- .../wlib/command/input/AllowedPlayerInputs.java | 8 ++++---- 11 files changed, 31 insertions(+), 31 deletions(-) diff --git a/commands/src/main/java/com/wizardlybump17/wlib/command/input/object/AllowedUUIDInputs.java b/commands/src/main/java/com/wizardlybump17/wlib/command/input/object/AllowedUUIDInputs.java index bd246aff..3dc4e768 100644 --- a/commands/src/main/java/com/wizardlybump17/wlib/command/input/object/AllowedUUIDInputs.java +++ b/commands/src/main/java/com/wizardlybump17/wlib/command/input/object/AllowedUUIDInputs.java @@ -83,7 +83,7 @@ private Values(@NotNull List values) { public boolean equals(Object object) { if (object == null || getClass() != object.getClass()) return false; - Values values1 = (Values) object; + AllowedUUIDInputs.Values values1 = (AllowedUUIDInputs.Values) object; return Objects.equals(values, values1.values); } @@ -102,8 +102,8 @@ public String toString() { final class Any implements AllowedUUIDInputs { - private static final @NotNull Any NULLABLE = new Any(true); - private static final @NotNull Any NOT_NULL = new Any(false); + private static final @NotNull AllowedUUIDInputs.Any NULLABLE = new AllowedUUIDInputs.Any(true); + private static final @NotNull AllowedUUIDInputs.Any NOT_NULL = new AllowedUUIDInputs.Any(false); private final boolean nullable; @@ -120,7 +120,7 @@ public boolean isAllowed(@Nullable UUID input) { public boolean equals(Object object) { if (object == null || getClass() != object.getClass()) return false; - Any any = (Any) object; + AllowedUUIDInputs.Any any = (AllowedUUIDInputs.Any) object; return nullable == any.nullable; } diff --git a/commands/src/main/java/com/wizardlybump17/wlib/command/input/primitive/AllowedCharacterInputs.java b/commands/src/main/java/com/wizardlybump17/wlib/command/input/primitive/AllowedCharacterInputs.java index 5bdecdc3..79046455 100644 --- a/commands/src/main/java/com/wizardlybump17/wlib/command/input/primitive/AllowedCharacterInputs.java +++ b/commands/src/main/java/com/wizardlybump17/wlib/command/input/primitive/AllowedCharacterInputs.java @@ -129,7 +129,7 @@ public boolean isAllowed(@Nullable Character input) { public boolean equals(Object object) { if (object == null || getClass() != object.getClass()) return false; - Values values1 = (Values) object; + AllowedCharacterInputs.Values values1 = (AllowedCharacterInputs.Values) object; return ignoreCase == values1.ignoreCase && Objects.equals(values, values1.values) && Objects.equals(toCheck, values1.toCheck); } diff --git a/commands/src/main/java/com/wizardlybump17/wlib/command/input/primitive/number/AllowedNumberInputs.java b/commands/src/main/java/com/wizardlybump17/wlib/command/input/primitive/number/AllowedNumberInputs.java index 1f54d839..916bdfc8 100644 --- a/commands/src/main/java/com/wizardlybump17/wlib/command/input/primitive/number/AllowedNumberInputs.java +++ b/commands/src/main/java/com/wizardlybump17/wlib/command/input/primitive/number/AllowedNumberInputs.java @@ -133,7 +133,7 @@ class Values implements AllowedNumberInputs, AllowedListInp public boolean equals(Object object) { if (object == null || getClass() != object.getClass()) return false; - Values values1 = (Values) object; + AllowedNumberInputs.Values values1 = (AllowedNumberInputs.Values) object; return Objects.equals(values, values1.values); } diff --git a/commands/src/main/java/com/wizardlybump17/wlib/command/input/string/AllowedStringInputs.java b/commands/src/main/java/com/wizardlybump17/wlib/command/input/string/AllowedStringInputs.java index a5be18b2..1e5cf8d1 100644 --- a/commands/src/main/java/com/wizardlybump17/wlib/command/input/string/AllowedStringInputs.java +++ b/commands/src/main/java/com/wizardlybump17/wlib/command/input/string/AllowedStringInputs.java @@ -68,7 +68,7 @@ public boolean isAllowed(@Nullable String input) { public boolean equals(Object object) { if (object == null || getClass() != object.getClass()) return false; - Values values1 = (Values) object; + AllowedStringInputs.Values values1 = (AllowedStringInputs.Values) object; return ignoreCase == values1.ignoreCase && Objects.equals(values, values1.values) && Objects.equals(toCheck, values1.toCheck); } @@ -137,8 +137,8 @@ public String toString() { final class Any implements AllowedStringInputs { - private static final @NotNull Any NULLABLE = new Any(true); - private static final @NotNull Any NOT_NULL = new Any(false); + private static final @NotNull AllowedStringInputs.Any NULLABLE = new AllowedStringInputs.Any(true); + private static final @NotNull AllowedStringInputs.Any NOT_NULL = new AllowedStringInputs.Any(false); private final boolean nullable; @@ -159,7 +159,7 @@ public boolean nullable() { public boolean equals(Object object) { if (object == null || getClass() != object.getClass()) return false; - Any any = (Any) object; + AllowedStringInputs.Any any = (AllowedStringInputs.Any) object; return nullable == any.nullable; } diff --git a/commands/src/main/java/com/wizardlybump17/wlib/command/suggestion/object/JsonElementSuggester.java b/commands/src/main/java/com/wizardlybump17/wlib/command/suggestion/object/JsonElementSuggester.java index 67f26f18..6c6d514a 100644 --- a/commands/src/main/java/com/wizardlybump17/wlib/command/suggestion/object/JsonElementSuggester.java +++ b/commands/src/main/java/com/wizardlybump17/wlib/command/suggestion/object/JsonElementSuggester.java @@ -58,7 +58,7 @@ public boolean equals(Object o) { if (o == null || getClass() != o.getClass()) return false; if (!super.equals(o)) return false; - Values values = (Values) o; + JsonElementSuggester.Values values = (JsonElementSuggester.Values) o; return Objects.equals(gson, values.gson); } diff --git a/commands/src/main/java/com/wizardlybump17/wlib/command/suggestion/primitive/number/ByteSuggester.java b/commands/src/main/java/com/wizardlybump17/wlib/command/suggestion/primitive/number/ByteSuggester.java index 5b6d9d25..c2f2ccde 100644 --- a/commands/src/main/java/com/wizardlybump17/wlib/command/suggestion/primitive/number/ByteSuggester.java +++ b/commands/src/main/java/com/wizardlybump17/wlib/command/suggestion/primitive/number/ByteSuggester.java @@ -57,19 +57,19 @@ public interface ByteSuggester extends PrimitiveSuggester, NumberSuggester final class Values extends AbstractValuesSuggester implements ByteSuggester { - private static final @NotNull Values POSITIVE = new Values(List.of( + private static final @NotNull ByteSuggester.Values POSITIVE = new ByteSuggester.Values(List.of( (byte) 0, (byte) 50, (byte) 100, (byte) 127 )); - private static final @NotNull Values NEGATIVE = new Values(List.of( + private static final @NotNull ByteSuggester.Values NEGATIVE = new ByteSuggester.Values(List.of( (byte) -128, (byte) -100, (byte) -50, (byte) -1 )); - private static final @NotNull Values UNLIMITED = new Values(List.of( + private static final @NotNull ByteSuggester.Values UNLIMITED = new ByteSuggester.Values(List.of( (byte) -128, (byte) -100, (byte) -50, diff --git a/commands/src/main/java/com/wizardlybump17/wlib/command/suggestion/primitive/number/IntegerSuggester.java b/commands/src/main/java/com/wizardlybump17/wlib/command/suggestion/primitive/number/IntegerSuggester.java index a05f951c..64beda11 100644 --- a/commands/src/main/java/com/wizardlybump17/wlib/command/suggestion/primitive/number/IntegerSuggester.java +++ b/commands/src/main/java/com/wizardlybump17/wlib/command/suggestion/primitive/number/IntegerSuggester.java @@ -55,7 +55,7 @@ public interface IntegerSuggester extends PrimitiveSuggester, NumberSug final class Values extends AbstractValuesSuggester implements IntegerSuggester { - private static final @NotNull Values POSITIVE = new Values(List.of( + private static final @NotNull IntegerSuggester.Values POSITIVE = new IntegerSuggester.Values(List.of( 0, 50, 200, @@ -63,7 +63,7 @@ final class Values extends AbstractValuesSuggester implements IntegerSu 50000, 100000 )); - private static final @NotNull Values NEGATIVE = new Values(List.of( + private static final @NotNull IntegerSuggester.Values NEGATIVE = new IntegerSuggester.Values(List.of( -100000, -50000, -3000, @@ -71,7 +71,7 @@ final class Values extends AbstractValuesSuggester implements IntegerSu -50, -1 )); - private static final @NotNull Values UNLIMITED = new Values(List.of( + private static final @NotNull IntegerSuggester.Values UNLIMITED = new IntegerSuggester.Values(List.of( -100000, -50000, -3000, diff --git a/commands/src/main/java/com/wizardlybump17/wlib/command/suggestion/primitive/number/LongSuggester.java b/commands/src/main/java/com/wizardlybump17/wlib/command/suggestion/primitive/number/LongSuggester.java index e0ae05ad..5913f0f7 100644 --- a/commands/src/main/java/com/wizardlybump17/wlib/command/suggestion/primitive/number/LongSuggester.java +++ b/commands/src/main/java/com/wizardlybump17/wlib/command/suggestion/primitive/number/LongSuggester.java @@ -57,7 +57,7 @@ public interface LongSuggester extends PrimitiveSuggester, NumberSuggester final class Values extends AbstractValuesSuggester implements LongSuggester { - private static final @NotNull Values POSITIVE = new Values(List.of( + private static final @NotNull LongSuggester.Values POSITIVE = new LongSuggester.Values(List.of( 0L, 50L, 200L, @@ -65,7 +65,7 @@ final class Values extends AbstractValuesSuggester implements LongSuggeste 50000L, 100000L )); - private static final @NotNull Values NEGATIVE = new Values(List.of( + private static final @NotNull LongSuggester.Values NEGATIVE = new LongSuggester.Values(List.of( -100000L, -50000L, -3000L, @@ -73,7 +73,7 @@ final class Values extends AbstractValuesSuggester implements LongSuggeste -50L, -1L )); - private static final @NotNull Values UNLIMITED = new Values(List.of( + private static final @NotNull LongSuggester.Values UNLIMITED = new LongSuggester.Values(List.of( -100000L, -50000L, -3000L, diff --git a/commands/src/main/java/com/wizardlybump17/wlib/command/suggestion/primitive/number/ShortSuggester.java b/commands/src/main/java/com/wizardlybump17/wlib/command/suggestion/primitive/number/ShortSuggester.java index bde37d1d..0f6fd57a 100644 --- a/commands/src/main/java/com/wizardlybump17/wlib/command/suggestion/primitive/number/ShortSuggester.java +++ b/commands/src/main/java/com/wizardlybump17/wlib/command/suggestion/primitive/number/ShortSuggester.java @@ -57,21 +57,21 @@ public interface ShortSuggester extends PrimitiveSuggester, NumberSuggest final class Values extends AbstractValuesSuggester implements ShortSuggester { - private static final @NotNull Values POSITIVE = new Values(List.of( + private static final @NotNull ShortSuggester.Values POSITIVE = new ShortSuggester.Values(List.of( (short) 0, (short) 50, (short) 100, (short) 3000, (short) 32767 )); - private static final @NotNull Values NEGATIVE = new Values(List.of( + private static final @NotNull ShortSuggester.Values NEGATIVE = new ShortSuggester.Values(List.of( (short) -32768, (short) -3000, (short) -100, (short) -50, (short) -1 )); - private static final @NotNull Values UNLIMITED = new Values(List.of( + private static final @NotNull ShortSuggester.Values UNLIMITED = new ShortSuggester.Values(List.of( (short) -32768, (short) -3000, (short) -100, diff --git a/core/src/main/java/com/wizardlybump17/wlib/command/input/AllowedOfflinePlayerInputs.java b/core/src/main/java/com/wizardlybump17/wlib/command/input/AllowedOfflinePlayerInputs.java index 51a5c4d9..f5c3a01d 100644 --- a/core/src/main/java/com/wizardlybump17/wlib/command/input/AllowedOfflinePlayerInputs.java +++ b/core/src/main/java/com/wizardlybump17/wlib/command/input/AllowedOfflinePlayerInputs.java @@ -80,7 +80,7 @@ private Values(@NotNull List values) { public boolean equals(Object object) { if (object == null || getClass() != object.getClass()) return false; - Values values1 = (Values) object; + AllowedOfflinePlayerInputs.Values values1 = (AllowedOfflinePlayerInputs.Values) object; return Objects.equals(values, values1.values); } @@ -99,8 +99,8 @@ public String toString() { final class Any implements AllowedOfflinePlayerInputs { - private static final @NotNull Any NULLABLE = new Any(true); - private static final @NotNull Any NOT_NULL = new Any(false); + private static final @NotNull AllowedOfflinePlayerInputs.Any NULLABLE = new AllowedOfflinePlayerInputs.Any(true); + private static final @NotNull AllowedOfflinePlayerInputs.Any NOT_NULL = new AllowedOfflinePlayerInputs.Any(false); private final boolean nullable; @@ -117,7 +117,7 @@ public boolean isAllowed(@Nullable OfflinePlayer input) { public boolean equals(Object object) { if (object == null || getClass() != object.getClass()) return false; - Any any = (Any) object; + AllowedOfflinePlayerInputs.Any any = (AllowedOfflinePlayerInputs.Any) object; return nullable == any.nullable; } diff --git a/core/src/main/java/com/wizardlybump17/wlib/command/input/AllowedPlayerInputs.java b/core/src/main/java/com/wizardlybump17/wlib/command/input/AllowedPlayerInputs.java index 1f1a281a..14430ccb 100644 --- a/core/src/main/java/com/wizardlybump17/wlib/command/input/AllowedPlayerInputs.java +++ b/core/src/main/java/com/wizardlybump17/wlib/command/input/AllowedPlayerInputs.java @@ -80,7 +80,7 @@ private Values(@NotNull List values) { public boolean equals(Object object) { if (object == null || getClass() != object.getClass()) return false; - Values values1 = (Values) object; + AllowedPlayerInputs.Values values1 = (AllowedPlayerInputs.Values) object; return Objects.equals(values, values1.values); } @@ -99,8 +99,8 @@ public String toString() { final class Any implements AllowedPlayerInputs { - private static final @NotNull Any NULLABLE = new Any(true); - private static final @NotNull Any NOT_NULL = new Any(false); + private static final @NotNull AllowedPlayerInputs.Any NULLABLE = new AllowedPlayerInputs.Any(true); + private static final @NotNull AllowedPlayerInputs.Any NOT_NULL = new AllowedPlayerInputs.Any(false); private final boolean nullable; @@ -117,7 +117,7 @@ public boolean isAllowed(@Nullable Player input) { public boolean equals(Object object) { if (object == null || getClass() != object.getClass()) return false; - Any any = (Any) object; + AllowedPlayerInputs.Any any = (AllowedPlayerInputs.Any) object; return nullable == any.nullable; } From f7bf71507910ee3c6ae792b67a592ef88a3ba5aa Mon Sep 17 00:00:00 2001 From: WizardlyBump17 Date: Sat, 10 Jan 2026 18:39:53 -0300 Subject: [PATCH 306/363] improved the ComponentCollector --- .../bukkit/collector/ComponentCollector.java | 17 ++++------------- 1 file changed, 4 insertions(+), 13 deletions(-) diff --git a/bukkit-utils/src/main/java/com/wizardlybump17/wlib/util/bukkit/collector/ComponentCollector.java b/bukkit-utils/src/main/java/com/wizardlybump17/wlib/util/bukkit/collector/ComponentCollector.java index efd535a2..d0e554b3 100644 --- a/bukkit-utils/src/main/java/com/wizardlybump17/wlib/util/bukkit/collector/ComponentCollector.java +++ b/bukkit-utils/src/main/java/com/wizardlybump17/wlib/util/bukkit/collector/ComponentCollector.java @@ -3,7 +3,6 @@ import net.kyori.adventure.text.Component; import org.jetbrains.annotations.NotNull; -import java.util.Objects; import java.util.Set; import java.util.function.BiConsumer; import java.util.function.BinaryOperator; @@ -25,33 +24,25 @@ public ComponentCollector(@NotNull Component separator) { @Override public @NotNull Supplier supplier() { - return () -> new Component[1]; + return () -> new Component[] {Component.empty()}; } @Override public @NotNull BiConsumer accumulator() { - return (array, component) -> { - if (array[0] == null) - array[0] = component; - else - array[0] = array[0].append(separator).append(component); - }; + return (array, component) -> array[0] = array[0].append(separator).append(component); } @Override public @NotNull BinaryOperator combiner() { return (left, right) -> { - if (left[0] == null) - left[0] = right[0]; - else - left[0] = left[0].append(separator).append(right[0]); + left[0] = left[0].append(separator).append(right[0]); return left; }; } @Override public @NotNull Function finisher() { - return array -> Objects.requireNonNullElseGet(array[0], Component::empty); + return array -> array[0]; } @Override From 7d0f42a8c934a7d332053600b0ba6233b2c080a9 Mon Sep 17 00:00:00 2001 From: WizardlyBump17 Date: Sat, 24 Jan 2026 16:26:17 -0300 Subject: [PATCH 307/363] properly using the preprocessor system --- .github/workflows/publish.yml | 10 ++++++---- .gitignore | 1 + core/build.gradle | 16 ++++++++++++---- .../main/java/com/wizardlybump17/wlib/WLib.java | 14 +++++++++++++- 4 files changed, 32 insertions(+), 9 deletions(-) diff --git a/.github/workflows/publish.yml b/.github/workflows/publish.yml index cc129cb0..4e19e35c 100644 --- a/.github/workflows/publish.yml +++ b/.github/workflows/publish.yml @@ -24,9 +24,6 @@ jobs: run: echo "WLIB_BUILD_DATE=$(date +'%Y-%m-%d_%H-%M-%S')" >> "$GITHUB_ENV" - name: Get snapshot number run: echo "WLIB_SNAPSHOT_NUMBER=$((${{ github.run_number }}+${{ github.run_attempt }}))" >> $GITHUB_ENV - - name: "Skip NMS if needed" - if: ${{ github.event_name != 'release' }} - run: echo "WLIB_SKIP_NMS=true" >> "$GITHUB_ENV" - uses: actions/checkout@v4 - name: Set up JDK 21 uses: actions/setup-java@v4 @@ -36,7 +33,12 @@ jobs: - name: Setup Gradle uses: gradle/actions/setup-gradle@v4 - name: Build - run: ./gradlew build + run: | + if [ "${{ github.event_name }}" != "release" ]; then + ./gradlew build -Pskip_nms=true + else + ./gradlew build + fi - name: Upload results uses: actions/upload-artifact@v4 with: diff --git a/.gitignore b/.gitignore index 0e100001..9137fbef 100644 --- a/.gitignore +++ b/.gitignore @@ -1,3 +1,4 @@ **/build/ .idea/ .gradle/ +/build.properties diff --git a/core/build.gradle b/core/build.gradle index a060e539..ccaed075 100644 --- a/core/build.gradle +++ b/core/build.gradle @@ -25,7 +25,7 @@ dependencies { project(':bukkit-utils'), ) - if (System.getenv("WLIB_SKIP_NMS") == null) { + if (!"true".equals(properties.get("skip_nms"))) { implementation(project(":versions:v1_20_R4")) implementation(project(":versions:v1_21_R1")) implementation(project(":versions:v1_21_R3")) @@ -52,10 +52,18 @@ tasks { archiveFileName = 'WLib-' + project.version + '.jar' relocate("com.github.sisyphsu", "com.wizardlybump17.wlib.libs.com.github.sisyphsu") } +} + +def preprocessors() { + StringBuilder preprocessors = new StringBuilder() - tasks.withType(JavaCompile) { - if (System.getenv("WLIB_SKIP_NMS") == null) - options.compilerArgs += ["-Awlib_include_nms"] + if ("true".equals(properties.get("skip_nms"))) { + preprocessors.append("WLIB_INCLUDE_NMS=0") + } else { + preprocessors.append("WLIB_INCLUDE_NMS=1") } + + new File(rootProject.projectDir, "build.properties").text = preprocessors.toString() } +preprocessors() diff --git a/core/src/main/java/com/wizardlybump17/wlib/WLib.java b/core/src/main/java/com/wizardlybump17/wlib/WLib.java index ebd86592..78032e39 100644 --- a/core/src/main/java/com/wizardlybump17/wlib/WLib.java +++ b/core/src/main/java/com/wizardlybump17/wlib/WLib.java @@ -2,6 +2,10 @@ import com.google.gson.Gson; import com.google.gson.GsonBuilder; +import com.wizardlybump17.wlib.adapter.AttributeAdapter; +import com.wizardlybump17.wlib.adapter.ItemAdapter; +import com.wizardlybump17.wlib.adapter.command.CommandMapAdapter; +import com.wizardlybump17.wlib.adapter.player.PlayerAdapter; import com.wizardlybump17.wlib.command.WLibCommandExecutor; import com.wizardlybump17.wlib.command.extractor.method.MethodCommandExtractor; import com.wizardlybump17.wlib.command.extractor.method.factory.OfflinePlayerMethodCommandNodeFactory; @@ -154,7 +158,13 @@ private void initAdapters() { } private void setupAdapters() { - #if WLIB_INCLUDE_NMS + //keep IntelliJ from removing the import + ItemAdapter.class.toString(); + PlayerAdapter.class.toString(); + AttributeAdapter.class.toString(); + CommandMapAdapter.class.toString(); + + #if WLIB_INCLUDE_NMS == 1 String version = Bukkit.getMinecraftVersion(); switch (version) { case "1.20.5", "1.20.6" -> { @@ -183,6 +193,8 @@ private void setupAdapters() { } default -> getLogger().severe("The server version (" + version + ") is not supported by WLib yet."); } + #else + getLogger().severe("The NMS integration was disabled during compile, probably because of the presence of the \"skip_nms\" property and it was set to \"true\". The following systems are expected to not work: ItemAdapter, PlayerAdapter, AttributeAdapter, CommandMapAdapter."); #endif } From 45be564e407e5536d989663cae08d14f1bfa32e9 Mon Sep 17 00:00:00 2001 From: WizardlyBump17 Date: Mon, 26 Jan 2026 17:21:35 -0300 Subject: [PATCH 308/363] excluding gson to get a smaller jar --- core/build.gradle | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/core/build.gradle b/core/build.gradle index ccaed075..c733e3c2 100644 --- a/core/build.gradle +++ b/core/build.gradle @@ -19,12 +19,15 @@ dependencies { project(':objects'), - project(':commands'), project(':config'), - project(':bukkit-utils'), + project(':bukkit-utils') ) + implementation(project(':commands')) { + exclude group: "com.google.code.gson", module: "gson" + } + if (!"true".equals(properties.get("skip_nms"))) { implementation(project(":versions:v1_20_R4")) implementation(project(":versions:v1_21_R1")) From 38a6bc39295ddbccc3198229dc96ee77fd5d7d1f Mon Sep 17 00:00:00 2001 From: WizardlyBump17 Date: Mon, 26 Jan 2026 19:30:28 -0300 Subject: [PATCH 309/363] accepting null from the argument list --- .../java/com/wizardlybump17/wlib/command/Command.java | 10 +++++++++- .../wlib/command/context/CommandContext.java | 2 +- 2 files changed, 10 insertions(+), 2 deletions(-) diff --git a/commands/src/main/java/com/wizardlybump17/wlib/command/Command.java b/commands/src/main/java/com/wizardlybump17/wlib/command/Command.java index e3791055..d2ec5c3f 100644 --- a/commands/src/main/java/com/wizardlybump17/wlib/command/Command.java +++ b/commands/src/main/java/com/wizardlybump17/wlib/command/Command.java @@ -61,7 +61,15 @@ public Command(@NotNull LiteralCommandNode root) { lastNode = child; try { - Object result = child.parseOrInvalid(inputString); + Object result; + if (inputString == null) { + if (child.isValidInput(null)) + result = null; + else + throw new InvalidInputException("Null inputs not accepted by " + child); + } else { + result = child.parseOrInvalid(inputString); + } if (!(child instanceof LiteralCommandNode)) arguments.add(new CommandContext.CommandNodeArgument<>((CommandNode) child, inputString, result)); diff --git a/commands/src/main/java/com/wizardlybump17/wlib/command/context/CommandContext.java b/commands/src/main/java/com/wizardlybump17/wlib/command/context/CommandContext.java index 0a74caec..82a63e15 100644 --- a/commands/src/main/java/com/wizardlybump17/wlib/command/context/CommandContext.java +++ b/commands/src/main/java/com/wizardlybump17/wlib/command/context/CommandContext.java @@ -11,7 +11,7 @@ public record CommandContext(@NotNull Command command, @NotNull CommandSender sender, @NotNull CommandNodeArguments arguments, int lastInputIndex, @NotNull CommandNode lastNode) { - public record CommandNodeArgument(@NotNull CommandNode node, @NotNull String input, @Nullable T data) { + public record CommandNodeArgument(@NotNull CommandNode node, @Nullable String input, @Nullable T data) { } public static final class CommandNodeArguments { From 750dde5d60f2eb5459f7ad999daf646eef158ce9 Mon Sep 17 00:00:00 2001 From: WizardlyBump17 Date: Mon, 26 Jan 2026 19:32:30 -0300 Subject: [PATCH 310/363] accepting null from the argument list --- .../java/com/wizardlybump17/wlib/command/Command.java | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/commands/src/main/java/com/wizardlybump17/wlib/command/Command.java b/commands/src/main/java/com/wizardlybump17/wlib/command/Command.java index d2ec5c3f..e735b270 100644 --- a/commands/src/main/java/com/wizardlybump17/wlib/command/Command.java +++ b/commands/src/main/java/com/wizardlybump17/wlib/command/Command.java @@ -145,7 +145,7 @@ public Command(@NotNull LiteralCommandNode root) { String inputString = input.get(i); boolean isLastInput = i == input.size() - 1; - if (inputString.isEmpty()) { + if (inputString != null && inputString.isEmpty()) { for (CommandNode child : children) { String permission = child.getPermission(); if (permission == null || sender.hasPermission(permission)) @@ -162,6 +162,12 @@ public Command(@NotNull LiteralCommandNode root) { if (!isLastInput) { try { + if (inputString == null) { + if (!child.isValidInput(null)) + throw new InvalidInputException("Null inputs not accepted by " + child); + continue; + } + child.parseOrInvalid(inputString); } catch (InputParsingException | InvalidInputException e) { lastError = e; From 6c49e8c48ee05cc3f79ef42ed698c543ce2a245f Mon Sep 17 00:00:00 2001 From: WizardlyBump17 Date: Mon, 26 Jan 2026 19:45:11 -0300 Subject: [PATCH 311/363] testing "accepting null from the arguments list" --- .../wlib/test/command/CommandTests.java | 63 +++++++++++++++++++ 1 file changed, 63 insertions(+) diff --git a/commands/src/test/java/com/wizardlybump17/wlib/test/command/CommandTests.java b/commands/src/test/java/com/wizardlybump17/wlib/test/command/CommandTests.java index 74c0c1c5..eb9c6299 100644 --- a/commands/src/test/java/com/wizardlybump17/wlib/test/command/CommandTests.java +++ b/commands/src/test/java/com/wizardlybump17/wlib/test/command/CommandTests.java @@ -5,13 +5,16 @@ import com.wizardlybump17.wlib.command.exception.InputParsingException; import com.wizardlybump17.wlib.command.executor.CommandNodeExecutor; import com.wizardlybump17.wlib.command.input.primitive.number.AllowedIntegerInputs; +import com.wizardlybump17.wlib.command.input.string.AllowedStringInputs; import com.wizardlybump17.wlib.command.node.CommandNode; import com.wizardlybump17.wlib.command.node.LiteralCommandNode; import com.wizardlybump17.wlib.command.node.primitive.number.IntegerCommandNode; +import com.wizardlybump17.wlib.command.node.string.StringCommandNode; import com.wizardlybump17.wlib.command.result.CommandResult; import com.wizardlybump17.wlib.command.result.error.*; import com.wizardlybump17.wlib.command.sender.BasicCommandSender; import com.wizardlybump17.wlib.command.sender.CommandSender; +import com.wizardlybump17.wlib.util.CollectionUtil; import org.jetbrains.annotations.NotNull; import org.junit.jupiter.api.Assertions; import org.junit.jupiter.api.DisplayName; @@ -481,4 +484,64 @@ void testCommandArguments() { Assertions.assertEquals(CommandResult.successful(2, test, "Hello 10 world"), result); } } + + @Test + void testNullArgumentsSuccess() { + Command command = new Command( + new LiteralCommandNode( + "test", + List.of( + new StringCommandNode( + "nullable0", + List.of(), + AllowedStringInputs.anyNullable(), + null, + context -> CommandResult.successful(context, context.arguments().getArgumentData("nullable0").orElse(null)), + null + ) + ), + null, + null + ) + ); + + Assertions.assertEquals( + CommandResult.successful(1, command.findNode("nullable0"), "Hello World"), + command.execute(CHAD_SENDER, List.of("test", "Hello World")) + ); + Assertions.assertEquals( + CommandResult.successful(1, command.findNode("nullable0"), null), + command.execute(CHAD_SENDER, CollectionUtil.listOf("test", null)) + ); + } + + @Test + void testNullArgumentsError() { + Command command = new Command( + new LiteralCommandNode( + "test", + List.of( + new StringCommandNode( + "nullable0", + List.of(), + AllowedStringInputs.anyNotNull(), + null, + context -> CommandResult.successful(context, context.arguments().getArgumentData("nullable0").orElse(null)), + null + ) + ), + null, + null + ) + ); + + Assertions.assertEquals( + CommandResult.successful(1, command.findNode("nullable0"), "Hello World"), + command.execute(CHAD_SENDER, List.of("test", "Hello World")) + ); + Assertions.assertEquals( + CommandResult.outOfRangeInput(1, command.findNode("nullable0")), + command.execute(CHAD_SENDER, CollectionUtil.listOf("test", null)) + ); + } } From a872eae14173559eb37dc2b21eafef5e6cdb8c6a Mon Sep 17 00:00:00 2001 From: WizardlyBump17 Date: Mon, 26 Jan 2026 21:27:33 -0300 Subject: [PATCH 312/363] improved the NMS ignoring --- .github/workflows/publish.yml | 15 ++++++++------- core/build.gradle | 2 ++ 2 files changed, 10 insertions(+), 7 deletions(-) diff --git a/.github/workflows/publish.yml b/.github/workflows/publish.yml index 4e19e35c..fe5f3730 100644 --- a/.github/workflows/publish.yml +++ b/.github/workflows/publish.yml @@ -32,13 +32,14 @@ jobs: distribution: temurin - name: Setup Gradle uses: gradle/actions/setup-gradle@v4 - - name: Build - run: | - if [ "${{ github.event_name }}" != "release" ]; then - ./gradlew build -Pskip_nms=true - else - ./gradlew build - fi + + - name: Build without NMS + if: ${{ github.event_name != 'release' }} + run: ./gradlew build -Pskip_nms=true + - name: Build with NMS + if: ${{ github.event_name == 'release' }} + run: ./gradlew build -Pskip_nms=false + - name: Upload results uses: actions/upload-artifact@v4 with: diff --git a/core/build.gradle b/core/build.gradle index c733e3c2..1bdbb1d3 100644 --- a/core/build.gradle +++ b/core/build.gradle @@ -66,6 +66,8 @@ def preprocessors() { preprocessors.append("WLIB_INCLUDE_NMS=1") } + println("Preprocessors: ${preprocessors}") + new File(rootProject.projectDir, "build.properties").text = preprocessors.toString() } From 8e25d9f0f608cb9b2648928706d7183a0cd3f5a7 Mon Sep 17 00:00:00 2001 From: WizardlyBump17 Date: Mon, 26 Jan 2026 21:46:34 -0300 Subject: [PATCH 313/363] rootProject there --- core/build.gradle | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/core/build.gradle b/core/build.gradle index 1bdbb1d3..d104af0d 100644 --- a/core/build.gradle +++ b/core/build.gradle @@ -28,7 +28,7 @@ dependencies { exclude group: "com.google.code.gson", module: "gson" } - if (!"true".equals(properties.get("skip_nms"))) { + if (!"true".equals(rootProject.properties.get("skip_nms"))) { implementation(project(":versions:v1_20_R4")) implementation(project(":versions:v1_21_R1")) implementation(project(":versions:v1_21_R3")) @@ -60,7 +60,7 @@ tasks { def preprocessors() { StringBuilder preprocessors = new StringBuilder() - if ("true".equals(properties.get("skip_nms"))) { + if ("true".equals(rootProject.properties.get("skip_nms"))) { preprocessors.append("WLIB_INCLUDE_NMS=0") } else { preprocessors.append("WLIB_INCLUDE_NMS=1") From a8e70aecc1ad9a30ae37481858a9a5b9ebe76ae9 Mon Sep 17 00:00:00 2001 From: WizardlyBump17 Date: Mon, 26 Jan 2026 22:01:50 -0300 Subject: [PATCH 314/363] just fucking work please --- core/build.gradle | 3 +++ settings.gradle | 19 +++++++++++-------- 2 files changed, 14 insertions(+), 8 deletions(-) diff --git a/core/build.gradle b/core/build.gradle index d104af0d..dd148f3b 100644 --- a/core/build.gradle +++ b/core/build.gradle @@ -29,10 +29,13 @@ dependencies { } if (!"true".equals(rootProject.properties.get("skip_nms"))) { + println("Including the NMS stuff") implementation(project(":versions:v1_20_R4")) implementation(project(":versions:v1_21_R1")) implementation(project(":versions:v1_21_R3")) implementation(project(":versions:v1_21_R5")) + } else { + println("Excluding the NMS stuff") } compileOnly("com.google.code.gson:gson:${gson}") diff --git a/settings.gradle b/settings.gradle index 37c4d078..65fa2255 100644 --- a/settings.gradle +++ b/settings.gradle @@ -20,11 +20,14 @@ include 'bukkit-utils' include 'versions:adapter' findProject(':versions:adapter')?.name = 'adapter' -include 'versions:v1_20_R4' -findProject(':versions:v1_20_R4')?.name = 'v1_20_R4' -include 'versions:v1_21_R1' -findProject(':versions:v1_21_R1')?.name = 'v1_21_R1' -include 'versions:v1_21_R3' -findProject(':versions:v1_21_R3')?.name = 'v1_21_R3' -include 'versions:v1_21_R5' -findProject(':versions:v1_21_R5')?.name = 'v1_21_R5' \ No newline at end of file + +if (!"true".equals(properties.get("skip_nms"))) { + include 'versions:v1_20_R4' + findProject(':versions:v1_20_R4')?.name = 'v1_20_R4' + include 'versions:v1_21_R1' + findProject(':versions:v1_21_R1')?.name = 'v1_21_R1' + include 'versions:v1_21_R3' + findProject(':versions:v1_21_R3')?.name = 'v1_21_R3' + include 'versions:v1_21_R5' + findProject(':versions:v1_21_R5')?.name = 'v1_21_R5' +} \ No newline at end of file From 409551ae35c08111536a2531f87878f846f01e90 Mon Sep 17 00:00:00 2001 From: WizardlyBump17 Date: Mon, 26 Jan 2026 22:31:53 -0300 Subject: [PATCH 315/363] PLEASE --- build.gradle | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/build.gradle b/build.gradle index 16409863..aa272ada 100644 --- a/build.gradle +++ b/build.gradle @@ -79,6 +79,14 @@ subprojects { dep.parent().remove(dep) } } + pom.withXml { + def deps = asNode().dependencies?.dependency + deps?.findAll { + it.groupId.text() == "com.wizardlybump17.wlib" && it.artifactId.text().matches("v\\d_\\d+_R\\d+") + }?.each { + it.parent().remove(it) + } + } } } } From b97ae64e61ac1ff432b40e314175c442fa1b4aac Mon Sep 17 00:00:00 2001 From: WizardlyBump17 Date: Mon, 26 Jan 2026 22:37:27 -0300 Subject: [PATCH 316/363] guess you cant duplicate --- build.gradle | 6 ------ 1 file changed, 6 deletions(-) diff --git a/build.gradle b/build.gradle index aa272ada..8ec11a2a 100644 --- a/build.gradle +++ b/build.gradle @@ -73,12 +73,6 @@ subprojects { publications { gpr(MavenPublication) { from(components.java) - pom.withXml { - asNode().dependencies.dependency.each { dep -> - if (dep.artifactId.last().value().last().matches('v\\d_\\d+_R\\d+')) - dep.parent().remove(dep) - } - } pom.withXml { def deps = asNode().dependencies?.dependency deps?.findAll { From 78826a57304f2de0776971f8c3e5b2227ec37bf5 Mon Sep 17 00:00:00 2001 From: WizardlyBump17 Date: Mon, 26 Jan 2026 23:03:28 -0300 Subject: [PATCH 317/363] we will get this done eventually --- core/build.gradle | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/core/build.gradle b/core/build.gradle index dd148f3b..422c65ed 100644 --- a/core/build.gradle +++ b/core/build.gradle @@ -29,13 +29,15 @@ dependencies { } if (!"true".equals(rootProject.properties.get("skip_nms"))) { - println("Including the NMS stuff") implementation(project(":versions:v1_20_R4")) implementation(project(":versions:v1_21_R1")) implementation(project(":versions:v1_21_R3")) implementation(project(":versions:v1_21_R5")) } else { - println("Excluding the NMS stuff") + compileOnly(project(":versions:v1_20_R4")) + compileOnly(project(":versions:v1_21_R1")) + compileOnly(project(":versions:v1_21_R3")) + compileOnly(project(":versions:v1_21_R5")) } compileOnly("com.google.code.gson:gson:${gson}") From 222d5289a31b61748e0dbac86ea3a7f0f3eee575 Mon Sep 17 00:00:00 2001 From: WizardlyBump17 Date: Mon, 26 Jan 2026 23:08:08 -0300 Subject: [PATCH 318/363] playing around --- .github/workflows/publish.yml | 4 ++-- build.gradle | 16 ++++++++-------- core/build.gradle | 5 ----- 3 files changed, 10 insertions(+), 15 deletions(-) diff --git a/.github/workflows/publish.yml b/.github/workflows/publish.yml index fe5f3730..047b6624 100644 --- a/.github/workflows/publish.yml +++ b/.github/workflows/publish.yml @@ -30,8 +30,8 @@ jobs: with: java-version: 21 distribution: temurin - - name: Setup Gradle - uses: gradle/actions/setup-gradle@v4 +# - name: Setup Gradle +# uses: gradle/actions/setup-gradle@v4 - name: Build without NMS if: ${{ github.event_name != 'release' }} diff --git a/build.gradle b/build.gradle index 8ec11a2a..8801857c 100644 --- a/build.gradle +++ b/build.gradle @@ -73,14 +73,14 @@ subprojects { publications { gpr(MavenPublication) { from(components.java) - pom.withXml { - def deps = asNode().dependencies?.dependency - deps?.findAll { - it.groupId.text() == "com.wizardlybump17.wlib" && it.artifactId.text().matches("v\\d_\\d+_R\\d+") - }?.each { - it.parent().remove(it) - } - } +// pom.withXml { +// def deps = asNode().dependencies?.dependency +// deps?.findAll { +// it.groupId.text() == "com.wizardlybump17.wlib" && it.artifactId.text().matches("v\\d_\\d+_R\\d+") +// }?.each { +// it.parent().remove(it) +// } +// } } } } diff --git a/core/build.gradle b/core/build.gradle index 422c65ed..d104af0d 100644 --- a/core/build.gradle +++ b/core/build.gradle @@ -33,11 +33,6 @@ dependencies { implementation(project(":versions:v1_21_R1")) implementation(project(":versions:v1_21_R3")) implementation(project(":versions:v1_21_R5")) - } else { - compileOnly(project(":versions:v1_20_R4")) - compileOnly(project(":versions:v1_21_R1")) - compileOnly(project(":versions:v1_21_R3")) - compileOnly(project(":versions:v1_21_R5")) } compileOnly("com.google.code.gson:gson:${gson}") From 14de4b86e92c00c7c0cbc03a10b56e0d980b4be0 Mon Sep 17 00:00:00 2001 From: WizardlyBump17 Date: Mon, 26 Jan 2026 23:18:34 -0300 Subject: [PATCH 319/363] playing around --- core/build.gradle | 3 +++ settings.gradle | 1 + 2 files changed, 4 insertions(+) diff --git a/core/build.gradle b/core/build.gradle index d104af0d..269f1453 100644 --- a/core/build.gradle +++ b/core/build.gradle @@ -33,6 +33,9 @@ dependencies { implementation(project(":versions:v1_21_R1")) implementation(project(":versions:v1_21_R3")) implementation(project(":versions:v1_21_R5")) + println("Including NMS") + } else { + println("Ignoring NMS") } compileOnly("com.google.code.gson:gson:${gson}") diff --git a/settings.gradle b/settings.gradle index 65fa2255..1ac21287 100644 --- a/settings.gradle +++ b/settings.gradle @@ -22,6 +22,7 @@ include 'versions:adapter' findProject(':versions:adapter')?.name = 'adapter' if (!"true".equals(properties.get("skip_nms"))) { + println("Ignoring NMS at settings.gradle") include 'versions:v1_20_R4' findProject(':versions:v1_20_R4')?.name = 'v1_20_R4' include 'versions:v1_21_R1' From c00f1afc50b64c07d30b85d5a254bf386badc8bb Mon Sep 17 00:00:00 2001 From: WizardlyBump17 Date: Mon, 26 Jan 2026 23:30:56 -0300 Subject: [PATCH 320/363] Revert "playing around" This reverts commit 14de4b86e92c00c7c0cbc03a10b56e0d980b4be0. --- core/build.gradle | 3 --- settings.gradle | 1 - 2 files changed, 4 deletions(-) diff --git a/core/build.gradle b/core/build.gradle index 269f1453..d104af0d 100644 --- a/core/build.gradle +++ b/core/build.gradle @@ -33,9 +33,6 @@ dependencies { implementation(project(":versions:v1_21_R1")) implementation(project(":versions:v1_21_R3")) implementation(project(":versions:v1_21_R5")) - println("Including NMS") - } else { - println("Ignoring NMS") } compileOnly("com.google.code.gson:gson:${gson}") diff --git a/settings.gradle b/settings.gradle index 1ac21287..65fa2255 100644 --- a/settings.gradle +++ b/settings.gradle @@ -22,7 +22,6 @@ include 'versions:adapter' findProject(':versions:adapter')?.name = 'adapter' if (!"true".equals(properties.get("skip_nms"))) { - println("Ignoring NMS at settings.gradle") include 'versions:v1_20_R4' findProject(':versions:v1_20_R4')?.name = 'v1_20_R4' include 'versions:v1_21_R1' From 356afcd158bbf03bcab8a6aff57df4e0d89ce164 Mon Sep 17 00:00:00 2001 From: WizardlyBump17 Date: Mon, 26 Jan 2026 23:30:57 -0300 Subject: [PATCH 321/363] Revert "playing around" This reverts commit 222d5289a31b61748e0dbac86ea3a7f0f3eee575. --- .github/workflows/publish.yml | 4 ++-- build.gradle | 16 ++++++++-------- core/build.gradle | 5 +++++ 3 files changed, 15 insertions(+), 10 deletions(-) diff --git a/.github/workflows/publish.yml b/.github/workflows/publish.yml index 047b6624..fe5f3730 100644 --- a/.github/workflows/publish.yml +++ b/.github/workflows/publish.yml @@ -30,8 +30,8 @@ jobs: with: java-version: 21 distribution: temurin -# - name: Setup Gradle -# uses: gradle/actions/setup-gradle@v4 + - name: Setup Gradle + uses: gradle/actions/setup-gradle@v4 - name: Build without NMS if: ${{ github.event_name != 'release' }} diff --git a/build.gradle b/build.gradle index 8801857c..8ec11a2a 100644 --- a/build.gradle +++ b/build.gradle @@ -73,14 +73,14 @@ subprojects { publications { gpr(MavenPublication) { from(components.java) -// pom.withXml { -// def deps = asNode().dependencies?.dependency -// deps?.findAll { -// it.groupId.text() == "com.wizardlybump17.wlib" && it.artifactId.text().matches("v\\d_\\d+_R\\d+") -// }?.each { -// it.parent().remove(it) -// } -// } + pom.withXml { + def deps = asNode().dependencies?.dependency + deps?.findAll { + it.groupId.text() == "com.wizardlybump17.wlib" && it.artifactId.text().matches("v\\d_\\d+_R\\d+") + }?.each { + it.parent().remove(it) + } + } } } } diff --git a/core/build.gradle b/core/build.gradle index d104af0d..422c65ed 100644 --- a/core/build.gradle +++ b/core/build.gradle @@ -33,6 +33,11 @@ dependencies { implementation(project(":versions:v1_21_R1")) implementation(project(":versions:v1_21_R3")) implementation(project(":versions:v1_21_R5")) + } else { + compileOnly(project(":versions:v1_20_R4")) + compileOnly(project(":versions:v1_21_R1")) + compileOnly(project(":versions:v1_21_R3")) + compileOnly(project(":versions:v1_21_R5")) } compileOnly("com.google.code.gson:gson:${gson}") From 82c58b8577cb55978ea1ceeeadaa967e04ef1166 Mon Sep 17 00:00:00 2001 From: WizardlyBump17 Date: Mon, 26 Jan 2026 23:30:57 -0300 Subject: [PATCH 322/363] Revert "we will get this done eventually" This reverts commit 78826a57304f2de0776971f8c3e5b2227ec37bf5. --- core/build.gradle | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) diff --git a/core/build.gradle b/core/build.gradle index 422c65ed..dd148f3b 100644 --- a/core/build.gradle +++ b/core/build.gradle @@ -29,15 +29,13 @@ dependencies { } if (!"true".equals(rootProject.properties.get("skip_nms"))) { + println("Including the NMS stuff") implementation(project(":versions:v1_20_R4")) implementation(project(":versions:v1_21_R1")) implementation(project(":versions:v1_21_R3")) implementation(project(":versions:v1_21_R5")) } else { - compileOnly(project(":versions:v1_20_R4")) - compileOnly(project(":versions:v1_21_R1")) - compileOnly(project(":versions:v1_21_R3")) - compileOnly(project(":versions:v1_21_R5")) + println("Excluding the NMS stuff") } compileOnly("com.google.code.gson:gson:${gson}") From eecd62d5cdf98cfb1934732ad6e43d03680b2b41 Mon Sep 17 00:00:00 2001 From: WizardlyBump17 Date: Mon, 26 Jan 2026 23:30:58 -0300 Subject: [PATCH 323/363] Revert "guess you cant duplicate" This reverts commit b97ae64e61ac1ff432b40e314175c442fa1b4aac. --- build.gradle | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/build.gradle b/build.gradle index 8ec11a2a..aa272ada 100644 --- a/build.gradle +++ b/build.gradle @@ -73,6 +73,12 @@ subprojects { publications { gpr(MavenPublication) { from(components.java) + pom.withXml { + asNode().dependencies.dependency.each { dep -> + if (dep.artifactId.last().value().last().matches('v\\d_\\d+_R\\d+')) + dep.parent().remove(dep) + } + } pom.withXml { def deps = asNode().dependencies?.dependency deps?.findAll { From 492ced670c43f0f5258e90280c5c5a9259bb203b Mon Sep 17 00:00:00 2001 From: WizardlyBump17 Date: Mon, 26 Jan 2026 23:30:58 -0300 Subject: [PATCH 324/363] Revert "PLEASE" This reverts commit 409551ae35c08111536a2531f87878f846f01e90. --- build.gradle | 8 -------- 1 file changed, 8 deletions(-) diff --git a/build.gradle b/build.gradle index aa272ada..16409863 100644 --- a/build.gradle +++ b/build.gradle @@ -79,14 +79,6 @@ subprojects { dep.parent().remove(dep) } } - pom.withXml { - def deps = asNode().dependencies?.dependency - deps?.findAll { - it.groupId.text() == "com.wizardlybump17.wlib" && it.artifactId.text().matches("v\\d_\\d+_R\\d+") - }?.each { - it.parent().remove(it) - } - } } } } From dcf6f2fdc5242af245168a1f9a5fb04576e0bec6 Mon Sep 17 00:00:00 2001 From: WizardlyBump17 Date: Mon, 26 Jan 2026 23:30:59 -0300 Subject: [PATCH 325/363] Revert "just fucking work please" This reverts commit a8e70aecc1ad9a30ae37481858a9a5b9ebe76ae9. --- core/build.gradle | 3 --- settings.gradle | 19 ++++++++----------- 2 files changed, 8 insertions(+), 14 deletions(-) diff --git a/core/build.gradle b/core/build.gradle index dd148f3b..d104af0d 100644 --- a/core/build.gradle +++ b/core/build.gradle @@ -29,13 +29,10 @@ dependencies { } if (!"true".equals(rootProject.properties.get("skip_nms"))) { - println("Including the NMS stuff") implementation(project(":versions:v1_20_R4")) implementation(project(":versions:v1_21_R1")) implementation(project(":versions:v1_21_R3")) implementation(project(":versions:v1_21_R5")) - } else { - println("Excluding the NMS stuff") } compileOnly("com.google.code.gson:gson:${gson}") diff --git a/settings.gradle b/settings.gradle index 65fa2255..37c4d078 100644 --- a/settings.gradle +++ b/settings.gradle @@ -20,14 +20,11 @@ include 'bukkit-utils' include 'versions:adapter' findProject(':versions:adapter')?.name = 'adapter' - -if (!"true".equals(properties.get("skip_nms"))) { - include 'versions:v1_20_R4' - findProject(':versions:v1_20_R4')?.name = 'v1_20_R4' - include 'versions:v1_21_R1' - findProject(':versions:v1_21_R1')?.name = 'v1_21_R1' - include 'versions:v1_21_R3' - findProject(':versions:v1_21_R3')?.name = 'v1_21_R3' - include 'versions:v1_21_R5' - findProject(':versions:v1_21_R5')?.name = 'v1_21_R5' -} \ No newline at end of file +include 'versions:v1_20_R4' +findProject(':versions:v1_20_R4')?.name = 'v1_20_R4' +include 'versions:v1_21_R1' +findProject(':versions:v1_21_R1')?.name = 'v1_21_R1' +include 'versions:v1_21_R3' +findProject(':versions:v1_21_R3')?.name = 'v1_21_R3' +include 'versions:v1_21_R5' +findProject(':versions:v1_21_R5')?.name = 'v1_21_R5' \ No newline at end of file From 9da8748ee782e599328f0c42d32bb734217358fb Mon Sep 17 00:00:00 2001 From: WizardlyBump17 Date: Mon, 26 Jan 2026 23:34:11 -0300 Subject: [PATCH 326/363] ignoring NMS at settings.gradle --- core/build.gradle | 2 ++ settings.gradle | 21 +++++++++++++-------- 2 files changed, 15 insertions(+), 8 deletions(-) diff --git a/core/build.gradle b/core/build.gradle index d104af0d..dadb3fea 100644 --- a/core/build.gradle +++ b/core/build.gradle @@ -33,6 +33,8 @@ dependencies { implementation(project(":versions:v1_21_R1")) implementation(project(":versions:v1_21_R3")) implementation(project(":versions:v1_21_R5")) + } else { + println("Ignoring NMS") } compileOnly("com.google.code.gson:gson:${gson}") diff --git a/settings.gradle b/settings.gradle index 37c4d078..bbe72c8a 100644 --- a/settings.gradle +++ b/settings.gradle @@ -20,11 +20,16 @@ include 'bukkit-utils' include 'versions:adapter' findProject(':versions:adapter')?.name = 'adapter' -include 'versions:v1_20_R4' -findProject(':versions:v1_20_R4')?.name = 'v1_20_R4' -include 'versions:v1_21_R1' -findProject(':versions:v1_21_R1')?.name = 'v1_21_R1' -include 'versions:v1_21_R3' -findProject(':versions:v1_21_R3')?.name = 'v1_21_R3' -include 'versions:v1_21_R5' -findProject(':versions:v1_21_R5')?.name = 'v1_21_R5' \ No newline at end of file + +if (!"true".equals(properties.get("skip_nms"))) { + include 'versions:v1_20_R4' + findProject(':versions:v1_20_R4')?.name = 'v1_20_R4' + include 'versions:v1_21_R1' + findProject(':versions:v1_21_R1')?.name = 'v1_21_R1' + include 'versions:v1_21_R3' + findProject(':versions:v1_21_R3')?.name = 'v1_21_R3' + include 'versions:v1_21_R5' + findProject(':versions:v1_21_R5')?.name = 'v1_21_R5' +} else { + println("Ignoring NMS at settings.gradle") +} From 651235a41d6826d465568c673ecc20d45f4f56fa Mon Sep 17 00:00:00 2001 From: WizardlyBump17 Date: Mon, 26 Jan 2026 23:40:33 -0300 Subject: [PATCH 327/363] improved NMS ignoring --- .github/workflows/publish.yml | 12 +++--------- 1 file changed, 3 insertions(+), 9 deletions(-) diff --git a/.github/workflows/publish.yml b/.github/workflows/publish.yml index fe5f3730..8cd36d45 100644 --- a/.github/workflows/publish.yml +++ b/.github/workflows/publish.yml @@ -32,14 +32,8 @@ jobs: distribution: temurin - name: Setup Gradle uses: gradle/actions/setup-gradle@v4 - - - name: Build without NMS - if: ${{ github.event_name != 'release' }} - run: ./gradlew build -Pskip_nms=true - - name: Build with NMS - if: ${{ github.event_name == 'release' }} - run: ./gradlew build -Pskip_nms=false - + - name: Build + run: ./gradlew build - name: Upload results uses: actions/upload-artifact@v4 with: @@ -55,4 +49,4 @@ jobs: gh release upload ${{ github.event.release.tag_name }} $file done - name: Publish - run: ./gradlew publish + run: ./gradlew -Pskip_nms=true clean build publish From 01120ceaf59e9dba7acbf86c48a553a194d4f825 Mon Sep 17 00:00:00 2001 From: WizardlyBump17 Date: Mon, 26 Jan 2026 23:43:08 -0300 Subject: [PATCH 328/363] merged the workflows --- .../{publish.yml => build-and-publish.yml} | 38 +++++++++++++---- .github/workflows/build.yml | 41 ------------------- 2 files changed, 29 insertions(+), 50 deletions(-) rename .github/workflows/{publish.yml => build-and-publish.yml} (61%) delete mode 100644 .github/workflows/build.yml diff --git a/.github/workflows/publish.yml b/.github/workflows/build-and-publish.yml similarity index 61% rename from .github/workflows/publish.yml rename to .github/workflows/build-and-publish.yml index 8cd36d45..3fe0fbff 100644 --- a/.github/workflows/publish.yml +++ b/.github/workflows/build-and-publish.yml @@ -1,12 +1,15 @@ -name: Publish to GitHub Packages +name: Build and upload on: + push: + pull_request: + types: + - opened + - reopened + workflow_dispatch: release: types: - - published - push: - branches: - - new-command-system-1.20.6-2 + - created env: USERNAME: ${{ github.actor }} @@ -17,8 +20,7 @@ jobs: build: runs-on: ubuntu-latest permissions: - contents: write - packages: write + contents: read steps: - name: Get current date run: echo "WLIB_BUILD_DATE=$(date +'%Y-%m-%d_%H-%M-%S')" >> "$GITHUB_ENV" @@ -40,8 +42,26 @@ jobs: path: "**/build/libs/*.jar" name: WLib-${{ env.WLIB_BUILD_DATE }} if-no-files-found: error + publish: + runs-on: ubuntu-latest + permissions: + contents: write + packages: write + if: ${{ github.event_name != 'pull_request' }} + steps: + - name: Get current date + run: echo "WLIB_BUILD_DATE=$(date +'%Y-%m-%d_%H-%M-%S')" >> "$GITHUB_ENV" + - name: Get snapshot number + run: echo "WLIB_SNAPSHOT_NUMBER=$((${{ github.run_number }}+${{ github.run_attempt }}))" >> $GITHUB_ENV + - uses: actions/checkout@v4 + - name: Set up JDK 21 + uses: actions/setup-java@v4 + with: + java-version: 21 + distribution: temurin + - name: Setup Gradle + uses: gradle/actions/setup-gradle@v4 - name: Upload to the release - if: ${{ github.event_name == 'release' }} env: GH_TOKEN: ${{ github.token }} run: | @@ -49,4 +69,4 @@ jobs: gh release upload ${{ github.event.release.tag_name }} $file done - name: Publish - run: ./gradlew -Pskip_nms=true clean build publish + run: ./gradlew -Pskip_nms=true clean build publish \ No newline at end of file diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml deleted file mode 100644 index aae6a066..00000000 --- a/.github/workflows/build.yml +++ /dev/null @@ -1,41 +0,0 @@ -name: Build and upload - -on: - push: - pull_request: - types: - - opened - - reopened - workflow_dispatch: - -env: - USERNAME: ${{ github.actor }} - TOKEN: ${{ secrets.GITHUB_TOKEN }} - WLIB_SNAPSHOT: ${{ github.event_name != 'release' }} - -jobs: - build: - runs-on: ubuntu-latest - permissions: - contents: read - steps: - - name: Get current date - run: echo "WLIB_BUILD_DATE=$(date +'%Y-%m-%d_%H-%M-%S')" >> "$GITHUB_ENV" - - name: Get snapshot number - run: echo "WLIB_SNAPSHOT_NUMBER=$((${{ github.run_number }}+${{ github.run_attempt }}))" >> $GITHUB_ENV - - uses: actions/checkout@v4 - - name: Set up JDK 21 - uses: actions/setup-java@v4 - with: - java-version: 21 - distribution: temurin - - name: Setup Gradle - uses: gradle/actions/setup-gradle@v4 - - name: Build - run: ./gradlew build - - name: Upload results - uses: actions/upload-artifact@v4 - with: - path: "**/build/libs/*.jar" - name: WLib-${{ env.WLIB_BUILD_DATE }} - if-no-files-found: error \ No newline at end of file From 567e46e2760a771249e1c8ebf0c2f04705a53f19 Mon Sep 17 00:00:00 2001 From: WizardlyBump17 Date: Mon, 26 Jan 2026 23:44:09 -0300 Subject: [PATCH 329/363] wait for it to build --- .github/workflows/build-and-publish.yml | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/.github/workflows/build-and-publish.yml b/.github/workflows/build-and-publish.yml index 3fe0fbff..45e7367e 100644 --- a/.github/workflows/build-and-publish.yml +++ b/.github/workflows/build-and-publish.yml @@ -48,6 +48,8 @@ jobs: contents: write packages: write if: ${{ github.event_name != 'pull_request' }} + needs: + - build steps: - name: Get current date run: echo "WLIB_BUILD_DATE=$(date +'%Y-%m-%d_%H-%M-%S')" >> "$GITHUB_ENV" @@ -69,4 +71,4 @@ jobs: gh release upload ${{ github.event.release.tag_name }} $file done - name: Publish - run: ./gradlew -Pskip_nms=true clean build publish \ No newline at end of file + run: ./gradlew -Pskip_nms=true publish \ No newline at end of file From 7027b81e068b07150faecfa02e23d51daa9cc857 Mon Sep 17 00:00:00 2001 From: WizardlyBump17 Date: Mon, 26 Jan 2026 23:48:56 -0300 Subject: [PATCH 330/363] mb --- .github/workflows/build-and-publish.yml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/.github/workflows/build-and-publish.yml b/.github/workflows/build-and-publish.yml index 45e7367e..30774f21 100644 --- a/.github/workflows/build-and-publish.yml +++ b/.github/workflows/build-and-publish.yml @@ -63,6 +63,8 @@ jobs: distribution: temurin - name: Setup Gradle uses: gradle/actions/setup-gradle@v4 + - name: Build and publish + run: ./gradlew clean build -Pskip_nms=true publish - name: Upload to the release env: GH_TOKEN: ${{ github.token }} @@ -70,5 +72,3 @@ jobs: for file in */build/libs/*.jar; do gh release upload ${{ github.event.release.tag_name }} $file done - - name: Publish - run: ./gradlew -Pskip_nms=true publish \ No newline at end of file From 9f798227e6f1d82a12d322285560d1d95b3a3cd6 Mon Sep 17 00:00:00 2001 From: WizardlyBump17 Date: Mon, 26 Jan 2026 23:50:59 -0300 Subject: [PATCH 331/363] mb --- .github/workflows/build-and-publish.yml | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/.github/workflows/build-and-publish.yml b/.github/workflows/build-and-publish.yml index 30774f21..1233eee3 100644 --- a/.github/workflows/build-and-publish.yml +++ b/.github/workflows/build-and-publish.yml @@ -63,8 +63,8 @@ jobs: distribution: temurin - name: Setup Gradle uses: gradle/actions/setup-gradle@v4 - - name: Build and publish - run: ./gradlew clean build -Pskip_nms=true publish + - name: Build this shit again + run: ./gradlew clean build - name: Upload to the release env: GH_TOKEN: ${{ github.token }} @@ -72,3 +72,5 @@ jobs: for file in */build/libs/*.jar; do gh release upload ${{ github.event.release.tag_name }} $file done + - name: Clean, Build and Publish + run: ./gradle -Pskip_nms=true publish clean build publish From ab4cf3db14f0753da66dc070d779fbf8ca4cf29e Mon Sep 17 00:00:00 2001 From: WizardlyBump17 Date: Mon, 26 Jan 2026 23:58:50 -0300 Subject: [PATCH 332/363] mb --- .github/workflows/build-and-publish.yml | 1 + 1 file changed, 1 insertion(+) diff --git a/.github/workflows/build-and-publish.yml b/.github/workflows/build-and-publish.yml index 1233eee3..15e9bbbc 100644 --- a/.github/workflows/build-and-publish.yml +++ b/.github/workflows/build-and-publish.yml @@ -66,6 +66,7 @@ jobs: - name: Build this shit again run: ./gradlew clean build - name: Upload to the release + if: ${{ github.event_name == 'release' }} env: GH_TOKEN: ${{ github.token }} run: | From 5367b2b38f23fdf93c6c3958d96cb82c2789c459 Mon Sep 17 00:00:00 2001 From: WizardlyBump17 Date: Mon, 26 Jan 2026 23:59:31 -0300 Subject: [PATCH 333/363] mb --- .github/workflows/build-and-publish.yml | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/.github/workflows/build-and-publish.yml b/.github/workflows/build-and-publish.yml index 15e9bbbc..eceface1 100644 --- a/.github/workflows/build-and-publish.yml +++ b/.github/workflows/build-and-publish.yml @@ -65,6 +65,8 @@ jobs: uses: gradle/actions/setup-gradle@v4 - name: Build this shit again run: ./gradlew clean build + - name: Clean, Build and Publish + run: ./gradle -Pskip_nms=true clean build publish - name: Upload to the release if: ${{ github.event_name == 'release' }} env: @@ -73,5 +75,4 @@ jobs: for file in */build/libs/*.jar; do gh release upload ${{ github.event.release.tag_name }} $file done - - name: Clean, Build and Publish - run: ./gradle -Pskip_nms=true publish clean build publish + From c6536ee97a07bcd36a1a5bdef8ddd28201d4a35a Mon Sep 17 00:00:00 2001 From: WizardlyBump17 Date: Tue, 27 Jan 2026 00:05:03 -0300 Subject: [PATCH 334/363] uploading to the release --- .github/workflows/build-and-publish.yml | 20 +++++++++----------- 1 file changed, 9 insertions(+), 11 deletions(-) diff --git a/.github/workflows/build-and-publish.yml b/.github/workflows/build-and-publish.yml index eceface1..753bd63b 100644 --- a/.github/workflows/build-and-publish.yml +++ b/.github/workflows/build-and-publish.yml @@ -42,6 +42,14 @@ jobs: path: "**/build/libs/*.jar" name: WLib-${{ env.WLIB_BUILD_DATE }} if-no-files-found: error + - name: Upload to the release + if: ${{ github.event_name == 'release' }} + env: + GH_TOKEN: ${{ github.token }} + run: | + for file in */build/libs/*.jar; do + gh release upload ${{ github.event.release.tag_name }} $file + done publish: runs-on: ubuntu-latest permissions: @@ -63,16 +71,6 @@ jobs: distribution: temurin - name: Setup Gradle uses: gradle/actions/setup-gradle@v4 - - name: Build this shit again - run: ./gradlew clean build - name: Clean, Build and Publish run: ./gradle -Pskip_nms=true clean build publish - - name: Upload to the release - if: ${{ github.event_name == 'release' }} - env: - GH_TOKEN: ${{ github.token }} - run: | - for file in */build/libs/*.jar; do - gh release upload ${{ github.event.release.tag_name }} $file - done - + From a7b3f92484bb512fbc43bb056121389244ebb04d Mon Sep 17 00:00:00 2001 From: WizardlyBump17 Date: Tue, 27 Jan 2026 00:07:15 -0300 Subject: [PATCH 335/363] generational fumble --- .github/workflows/build-and-publish.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/build-and-publish.yml b/.github/workflows/build-and-publish.yml index 753bd63b..e69fad1b 100644 --- a/.github/workflows/build-and-publish.yml +++ b/.github/workflows/build-and-publish.yml @@ -72,5 +72,5 @@ jobs: - name: Setup Gradle uses: gradle/actions/setup-gradle@v4 - name: Clean, Build and Publish - run: ./gradle -Pskip_nms=true clean build publish + run: ./gradlew -Pskip_nms=true clean build publish From 91ad68e0c76254d821d4c667af341b62e95bdc57 Mon Sep 17 00:00:00 2001 From: WizardlyBump17 Date: Tue, 27 Jan 2026 15:59:24 -0300 Subject: [PATCH 336/363] on second thought... --- .github/workflows/build-and-publish.yml | 2 +- build.gradle | 13 -------- core/build.gradle | 33 +++---------------- .../java/com/wizardlybump17/wlib/WLib.java | 10 ------ 4 files changed, 5 insertions(+), 53 deletions(-) diff --git a/.github/workflows/build-and-publish.yml b/.github/workflows/build-and-publish.yml index e69fad1b..02d8f2e8 100644 --- a/.github/workflows/build-and-publish.yml +++ b/.github/workflows/build-and-publish.yml @@ -72,5 +72,5 @@ jobs: - name: Setup Gradle uses: gradle/actions/setup-gradle@v4 - name: Clean, Build and Publish - run: ./gradlew -Pskip_nms=true clean build publish + run: ./gradlew publish diff --git a/build.gradle b/build.gradle index 16409863..14cae67c 100644 --- a/build.gradle +++ b/build.gradle @@ -52,13 +52,6 @@ subprojects { useJUnitPlatform() } - if (project.name == 'versions' || project.name.matches('v\\d_\\d+_R\\d+')) { - tasks.withType(PublishToMavenRepository).configureEach { - it.enabled = false - } - return - } - publishing { repositories { maven { @@ -73,12 +66,6 @@ subprojects { publications { gpr(MavenPublication) { from(components.java) - pom.withXml { - asNode().dependencies.dependency.each { dep -> - if (dep.artifactId.last().value().last().matches('v\\d_\\d+_R\\d+')) - dep.parent().remove(dep) - } - } } } } diff --git a/core/build.gradle b/core/build.gradle index dadb3fea..805ffe94 100644 --- a/core/build.gradle +++ b/core/build.gradle @@ -1,7 +1,4 @@ var gson = "2.13.2" -var manifold = "2025.1.27" - -apply plugin: "systems.manifold.manifold-gradle-plugin" dependencies { compileOnly( @@ -28,19 +25,12 @@ dependencies { exclude group: "com.google.code.gson", module: "gson" } - if (!"true".equals(rootProject.properties.get("skip_nms"))) { - implementation(project(":versions:v1_20_R4")) - implementation(project(":versions:v1_21_R1")) - implementation(project(":versions:v1_21_R3")) - implementation(project(":versions:v1_21_R5")) - } else { - println("Ignoring NMS") - } + implementation(project(":versions:v1_20_R4")) + implementation(project(":versions:v1_21_R1")) + implementation(project(":versions:v1_21_R3")) + implementation(project(":versions:v1_21_R5")) compileOnly("com.google.code.gson:gson:${gson}") - - annotationProcessor("systems.manifold:manifold-preprocessor:${manifold}") - testAnnotationProcessor("systems.manifold:manifold-preprocessor:${manifold}") } processResources { @@ -59,18 +49,3 @@ tasks { } } -def preprocessors() { - StringBuilder preprocessors = new StringBuilder() - - if ("true".equals(rootProject.properties.get("skip_nms"))) { - preprocessors.append("WLIB_INCLUDE_NMS=0") - } else { - preprocessors.append("WLIB_INCLUDE_NMS=1") - } - - println("Preprocessors: ${preprocessors}") - - new File(rootProject.projectDir, "build.properties").text = preprocessors.toString() -} - -preprocessors() diff --git a/core/src/main/java/com/wizardlybump17/wlib/WLib.java b/core/src/main/java/com/wizardlybump17/wlib/WLib.java index 78032e39..9bd1bb26 100644 --- a/core/src/main/java/com/wizardlybump17/wlib/WLib.java +++ b/core/src/main/java/com/wizardlybump17/wlib/WLib.java @@ -158,13 +158,6 @@ private void initAdapters() { } private void setupAdapters() { - //keep IntelliJ from removing the import - ItemAdapter.class.toString(); - PlayerAdapter.class.toString(); - AttributeAdapter.class.toString(); - CommandMapAdapter.class.toString(); - - #if WLIB_INCLUDE_NMS == 1 String version = Bukkit.getMinecraftVersion(); switch (version) { case "1.20.5", "1.20.6" -> { @@ -193,9 +186,6 @@ private void setupAdapters() { } default -> getLogger().severe("The server version (" + version + ") is not supported by WLib yet."); } - #else - getLogger().severe("The NMS integration was disabled during compile, probably because of the presence of the \"skip_nms\" property and it was set to \"true\". The following systems are expected to not work: ItemAdapter, PlayerAdapter, AttributeAdapter, CommandMapAdapter."); - #endif } public static WLib getInstance() { From 8393df747c5b3d08a9e628c5cf6ad07fc9dd4bda Mon Sep 17 00:00:00 2001 From: WizardlyBump17 Date: Tue, 27 Jan 2026 18:44:46 -0300 Subject: [PATCH 337/363] those arbitrary restrictions... --- core/build.gradle | 8 ++++---- settings.gradle | 20 ++++++++------------ 2 files changed, 12 insertions(+), 16 deletions(-) diff --git a/core/build.gradle b/core/build.gradle index 805ffe94..bdf67d9e 100644 --- a/core/build.gradle +++ b/core/build.gradle @@ -25,10 +25,10 @@ dependencies { exclude group: "com.google.code.gson", module: "gson" } - implementation(project(":versions:v1_20_R4")) - implementation(project(":versions:v1_21_R1")) - implementation(project(":versions:v1_21_R3")) - implementation(project(":versions:v1_21_R5")) + implementation(project(":versions:v1_20_r4")) + implementation(project(":versions:v1_21_r1")) + implementation(project(":versions:v1_21_r3")) + implementation(project(":versions:v1_21_r5")) compileOnly("com.google.code.gson:gson:${gson}") } diff --git a/settings.gradle b/settings.gradle index bbe72c8a..0adbac28 100644 --- a/settings.gradle +++ b/settings.gradle @@ -21,15 +21,11 @@ include 'bukkit-utils' include 'versions:adapter' findProject(':versions:adapter')?.name = 'adapter' -if (!"true".equals(properties.get("skip_nms"))) { - include 'versions:v1_20_R4' - findProject(':versions:v1_20_R4')?.name = 'v1_20_R4' - include 'versions:v1_21_R1' - findProject(':versions:v1_21_R1')?.name = 'v1_21_R1' - include 'versions:v1_21_R3' - findProject(':versions:v1_21_R3')?.name = 'v1_21_R3' - include 'versions:v1_21_R5' - findProject(':versions:v1_21_R5')?.name = 'v1_21_R5' -} else { - println("Ignoring NMS at settings.gradle") -} +include 'versions:v1_20_R4' +findProject(':versions:v1_20_R4')?.name = 'v1_20_r4' +include 'versions:v1_21_R1' +findProject(':versions:v1_21_R1')?.name = 'v1_21_r1' +include 'versions:v1_21_R3' +findProject(':versions:v1_21_R3')?.name = 'v1_21_r3' +include 'versions:v1_21_R5' +findProject(':versions:v1_21_R5')?.name = 'v1_21_r5' From 120b0a49f0229d80e160a67c3dedd56280f6448f Mon Sep 17 00:00:00 2001 From: WizardlyBump17 Date: Wed, 28 Jan 2026 00:19:02 -0300 Subject: [PATCH 338/363] there will be a whole between the versions, but who cares? --- .github/workflows/build-and-publish.yml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/.github/workflows/build-and-publish.yml b/.github/workflows/build-and-publish.yml index 02d8f2e8..088ac21c 100644 --- a/.github/workflows/build-and-publish.yml +++ b/.github/workflows/build-and-publish.yml @@ -25,7 +25,7 @@ jobs: - name: Get current date run: echo "WLIB_BUILD_DATE=$(date +'%Y-%m-%d_%H-%M-%S')" >> "$GITHUB_ENV" - name: Get snapshot number - run: echo "WLIB_SNAPSHOT_NUMBER=$((${{ github.run_number }}+${{ github.run_attempt }}))" >> $GITHUB_ENV + run: echo "WLIB_SNAPSHOT_NUMBER=$((${{ github.run_number }}+${{ github.run_attempt }}+68))" >> $GITHUB_ENV - uses: actions/checkout@v4 - name: Set up JDK 21 uses: actions/setup-java@v4 @@ -62,7 +62,7 @@ jobs: - name: Get current date run: echo "WLIB_BUILD_DATE=$(date +'%Y-%m-%d_%H-%M-%S')" >> "$GITHUB_ENV" - name: Get snapshot number - run: echo "WLIB_SNAPSHOT_NUMBER=$((${{ github.run_number }}+${{ github.run_attempt }}))" >> $GITHUB_ENV + run: echo "WLIB_SNAPSHOT_NUMBER=$((${{ github.run_number }}+${{ github.run_attempt }}+68))" >> $GITHUB_ENV - uses: actions/checkout@v4 - name: Set up JDK 21 uses: actions/setup-java@v4 From 93407693ed0acb1633d8af5860887ce5f9df950a Mon Sep 17 00:00:00 2001 From: WizardlyBump17 Date: Wed, 28 Jan 2026 17:34:45 -0300 Subject: [PATCH 339/363] do we need some escaping? --- .../wlib/command/suggestion/Suggester.java | 15 ++++++++++--- .../command/suggestion/ValuesSuggester.java | 21 ++++++++++++------- 2 files changed, 25 insertions(+), 11 deletions(-) diff --git a/commands/src/main/java/com/wizardlybump17/wlib/command/suggestion/Suggester.java b/commands/src/main/java/com/wizardlybump17/wlib/command/suggestion/Suggester.java index de4ffd75..f7ca1ed3 100644 --- a/commands/src/main/java/com/wizardlybump17/wlib/command/suggestion/Suggester.java +++ b/commands/src/main/java/com/wizardlybump17/wlib/command/suggestion/Suggester.java @@ -4,6 +4,7 @@ import com.wizardlybump17.wlib.command.node.CommandNode; import com.wizardlybump17.wlib.command.sender.CommandSender; import org.jetbrains.annotations.NotNull; +import org.jetbrains.annotations.Nullable; import java.util.List; import java.util.function.Function; @@ -20,11 +21,19 @@ default boolean needsEscape() { return false; } - static ValuesSuggester.@NotNull Values values(@NotNull List values, @NotNull Function stringRepresentation) { - return new ValuesSuggester.Values<>(values, stringRepresentation); + static ValuesSuggester.@NotNull Values values(@NotNull List values, @Nullable Function stringRepresentation, boolean needsEscape) { + return new ValuesSuggester.Values<>(values, stringRepresentation, needsEscape); + } + + static ValuesSuggester.@NotNull Values values(@NotNull List values, @Nullable Function stringRepresentation) { + return Suggester.values(values, stringRepresentation, false); } + static ValuesSuggester.@NotNull Values values(@NotNull List values, boolean needsEscape) { + return Suggester.values(values, null, needsEscape); + } + static ValuesSuggester.@NotNull Values values(@NotNull List values) { - return new ValuesSuggester.Values<>(values); + return Suggester.values(values, null, false); } } diff --git a/commands/src/main/java/com/wizardlybump17/wlib/command/suggestion/ValuesSuggester.java b/commands/src/main/java/com/wizardlybump17/wlib/command/suggestion/ValuesSuggester.java index cb283d2e..5ac20908 100644 --- a/commands/src/main/java/com/wizardlybump17/wlib/command/suggestion/ValuesSuggester.java +++ b/commands/src/main/java/com/wizardlybump17/wlib/command/suggestion/ValuesSuggester.java @@ -19,15 +19,12 @@ final class Values implements ValuesSuggester { private final @NotNull List values; private final @Nullable Function stringRepresentationFunction; + private final boolean needsEscape; - Values(@NotNull List values, @NotNull Function stringRepresentationFunction) { + Values(@NotNull List values, @Nullable Function stringRepresentationFunction, boolean needsEscape) { this.values = List.copyOf(values); this.stringRepresentationFunction = stringRepresentationFunction; - } - - Values(@NotNull List values) { - this.values = List.copyOf(values); - stringRepresentationFunction = null; + this.needsEscape = needsEscape; } @Override @@ -39,6 +36,11 @@ final class Values implements ValuesSuggester { return stringRepresentationFunction; } + @Override + public boolean needsEscape() { + return needsEscape; + } + @Override public @NotNull List getSuggestions(@NotNull CommandSender sender, @NotNull List input, @NotNull String current, @NotNull CommandNode currentNode) throws SuggesterException { return values; @@ -54,12 +56,14 @@ public boolean equals(Object o) { if (o == null || getClass() != o.getClass()) return false; Values values1 = (Values) o; - return Objects.equals(values, values1.values) && Objects.equals(stringRepresentationFunction, values1.stringRepresentationFunction); + return Objects.equals(values, values1.values) + && Objects.equals(stringRepresentationFunction, values1.stringRepresentationFunction) + && needsEscape == values1.needsEscape; } @Override public int hashCode() { - return Objects.hash(values, stringRepresentationFunction); + return Objects.hash(values, stringRepresentationFunction, needsEscape); } @Override @@ -67,6 +71,7 @@ public String toString() { return "ValuesSuggester$Values{" + "values=" + values + ", stringRepresentationFunction=" + stringRepresentationFunction + + ", needsEscape=" + needsEscape + '}'; } } From 91a0eafce74c761eb28f66edf9c59d194121bdf2 Mon Sep 17 00:00:00 2001 From: WizardlyBump17 Date: Wed, 28 Jan 2026 17:46:30 -0300 Subject: [PATCH 340/363] added the StringUtil.pascalToCamel(String) method --- .../com/wizardlybump17/wlib/util/StringUtil.java | 14 ++++++++++++++ 1 file changed, 14 insertions(+) diff --git a/utils/src/main/java/com/wizardlybump17/wlib/util/StringUtil.java b/utils/src/main/java/com/wizardlybump17/wlib/util/StringUtil.java index f43f1dc6..d7b88239 100644 --- a/utils/src/main/java/com/wizardlybump17/wlib/util/StringUtil.java +++ b/utils/src/main/java/com/wizardlybump17/wlib/util/StringUtil.java @@ -516,4 +516,18 @@ public static boolean isProperlyQuoted(@NotNull String input) throws QuotedStrin public static @NotNull String escapeString(@NotNull String input) { return escapeString(input, QUOTE, ESCAPE); } + + public static @NotNull String pascalToCamel(@NotNull String input) { + StringBuilder builder = new StringBuilder(input.length()); + for (char currentChar : input.toCharArray()) { + if (currentChar >= 'A' && currentChar <= 'Z') { + if (!builder.isEmpty()) + builder.append('_'); + builder.append(Character.toLowerCase(currentChar)); + continue; + } + builder.append(currentChar); + } + return builder.toString(); + } } From 8cefd8b50fbbf0fbc81e62caf6716c25784d6f91 Mon Sep 17 00:00:00 2001 From: WizardlyBump17 Date: Wed, 28 Jan 2026 17:47:08 -0300 Subject: [PATCH 341/363] camel --- .../com/wizardlybump17/wlib/util/bukkit/MiniMessageUtil.java | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/bukkit-utils/src/main/java/com/wizardlybump17/wlib/util/bukkit/MiniMessageUtil.java b/bukkit-utils/src/main/java/com/wizardlybump17/wlib/util/bukkit/MiniMessageUtil.java index 89b5c3d8..6ece5a15 100644 --- a/bukkit-utils/src/main/java/com/wizardlybump17/wlib/util/bukkit/MiniMessageUtil.java +++ b/bukkit-utils/src/main/java/com/wizardlybump17/wlib/util/bukkit/MiniMessageUtil.java @@ -1,5 +1,6 @@ package com.wizardlybump17.wlib.util.bukkit; +import com.wizardlybump17.wlib.util.StringUtil; import net.kyori.adventure.text.Component; import net.kyori.adventure.text.minimessage.MiniMessage; import net.kyori.adventure.text.minimessage.tag.Tag; @@ -21,7 +22,7 @@ private MiniMessageUtil() { TagResolver[] resolvers = new TagResolver[placeholders.size()]; int resolverIndex = 0; for (Map.Entry entry : placeholders.entrySet()) { - String key = entry.getKey(); + String key = StringUtil.pascalToCamel(entry.getKey()); Object value = entry.getValue(); resolvers[resolverIndex++] = TagResolver.builder() .tag( @@ -41,7 +42,7 @@ private MiniMessageUtil() { TagResolver[] resolvers = new TagResolver[additionalPlaceholders.size() + 1]; int resolverIndex = 0; for (Map.Entry entry : additionalPlaceholders.entrySet()) { - String key = entry.getKey(); + String key = StringUtil.pascalToCamel(entry.getKey()); Object value = entry.getValue(); resolvers[resolverIndex++] = TagResolver.builder() .tag( From c87a2ec665ef0960fe1a3b2d6a9f5c1638a67a52 Mon Sep 17 00:00:00 2001 From: WizardlyBump17 Date: Wed, 28 Jan 2026 17:49:10 -0300 Subject: [PATCH 342/363] a better way to get the insertion --- .../wlib/util/bukkit/MiniMessageUtil.java | 20 ++++++++++++++++--- 1 file changed, 17 insertions(+), 3 deletions(-) diff --git a/bukkit-utils/src/main/java/com/wizardlybump17/wlib/util/bukkit/MiniMessageUtil.java b/bukkit-utils/src/main/java/com/wizardlybump17/wlib/util/bukkit/MiniMessageUtil.java index 6ece5a15..461cc676 100644 --- a/bukkit-utils/src/main/java/com/wizardlybump17/wlib/util/bukkit/MiniMessageUtil.java +++ b/bukkit-utils/src/main/java/com/wizardlybump17/wlib/util/bukkit/MiniMessageUtil.java @@ -2,15 +2,19 @@ import com.wizardlybump17.wlib.util.StringUtil; import net.kyori.adventure.text.Component; +import net.kyori.adventure.text.TextComponent; import net.kyori.adventure.text.minimessage.MiniMessage; import net.kyori.adventure.text.minimessage.tag.Tag; import net.kyori.adventure.text.minimessage.tag.resolver.TagResolver; import org.jetbrains.annotations.NotNull; +import org.jetbrains.annotations.Nullable; import java.util.Map; public final class MiniMessageUtil { + private static final @NotNull TextComponent NULL = Component.text("null"); + private MiniMessageUtil() { } @@ -27,7 +31,7 @@ private MiniMessageUtil() { resolvers[resolverIndex++] = TagResolver.builder() .tag( key, - Tag.inserting(value instanceof Component component ? component : Component.text(String.valueOf(value))) + Tag.inserting(getInsertion(value)) ) .build(); } @@ -47,19 +51,29 @@ private MiniMessageUtil() { resolvers[resolverIndex++] = TagResolver.builder() .tag( prefix + key, - Tag.inserting(value instanceof Component component ? component : Component.text(String.valueOf(value))) + Tag.inserting(getInsertion(value)) ) .build(); } resolvers[resolverIndex] = TagResolver.builder() .tag( prefix + placeholderKey, - Tag.inserting(placeholderValue instanceof Component component ? component : Component.text(String.valueOf(placeholderValue))) + Tag.inserting(getInsertion(placeholderValue)) ) .build(); return miniMessage.deserialize(message, resolvers); } + private static @NotNull Component getInsertion(@Nullable Object object) { + if (object == null) + return NULL; + + return switch (object) { + case Component component -> component; + default -> Component.text(String.valueOf(object)); + }; + } + public static @NotNull Component getMessage(@NotNull String message, @NotNull String placeholderKey, @NotNull Object placeholderValue, @NotNull Map additionalPlaceholders) { return getMessage(message, placeholderKey, placeholderValue, "", additionalPlaceholders); } From 9a25d99c51a852fd656a4de62ba59b52f7c3f1a6 Mon Sep 17 00:00:00 2001 From: WizardlyBump17 Date: Wed, 28 Jan 2026 17:50:02 -0300 Subject: [PATCH 343/363] handling JSON --- .../com/wizardlybump17/wlib/util/bukkit/MiniMessageUtil.java | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/bukkit-utils/src/main/java/com/wizardlybump17/wlib/util/bukkit/MiniMessageUtil.java b/bukkit-utils/src/main/java/com/wizardlybump17/wlib/util/bukkit/MiniMessageUtil.java index 461cc676..c0157604 100644 --- a/bukkit-utils/src/main/java/com/wizardlybump17/wlib/util/bukkit/MiniMessageUtil.java +++ b/bukkit-utils/src/main/java/com/wizardlybump17/wlib/util/bukkit/MiniMessageUtil.java @@ -1,5 +1,7 @@ package com.wizardlybump17.wlib.util.bukkit; +import com.google.gson.JsonNull; +import com.google.gson.JsonPrimitive; import com.wizardlybump17.wlib.util.StringUtil; import net.kyori.adventure.text.Component; import net.kyori.adventure.text.TextComponent; @@ -70,6 +72,8 @@ private MiniMessageUtil() { return switch (object) { case Component component -> component; + case JsonPrimitive jsonPrimitive -> Component.text(jsonPrimitive.getAsString()); + case JsonNull ignored -> NULL; default -> Component.text(String.valueOf(object)); }; } From 082cb8fb18c89ad142e0b211a5205384330ad755 Mon Sep 17 00:00:00 2001 From: WizardlyBump17 Date: Thu, 29 Jan 2026 22:06:53 -0300 Subject: [PATCH 344/363] Revert "improved the ComponentCollector" This reverts commit f7bf71507910ee3c6ae792b67a592ef88a3ba5aa. --- .../bukkit/collector/ComponentCollector.java | 17 +++++++++++++---- 1 file changed, 13 insertions(+), 4 deletions(-) diff --git a/bukkit-utils/src/main/java/com/wizardlybump17/wlib/util/bukkit/collector/ComponentCollector.java b/bukkit-utils/src/main/java/com/wizardlybump17/wlib/util/bukkit/collector/ComponentCollector.java index d0e554b3..efd535a2 100644 --- a/bukkit-utils/src/main/java/com/wizardlybump17/wlib/util/bukkit/collector/ComponentCollector.java +++ b/bukkit-utils/src/main/java/com/wizardlybump17/wlib/util/bukkit/collector/ComponentCollector.java @@ -3,6 +3,7 @@ import net.kyori.adventure.text.Component; import org.jetbrains.annotations.NotNull; +import java.util.Objects; import java.util.Set; import java.util.function.BiConsumer; import java.util.function.BinaryOperator; @@ -24,25 +25,33 @@ public ComponentCollector(@NotNull Component separator) { @Override public @NotNull Supplier supplier() { - return () -> new Component[] {Component.empty()}; + return () -> new Component[1]; } @Override public @NotNull BiConsumer accumulator() { - return (array, component) -> array[0] = array[0].append(separator).append(component); + return (array, component) -> { + if (array[0] == null) + array[0] = component; + else + array[0] = array[0].append(separator).append(component); + }; } @Override public @NotNull BinaryOperator combiner() { return (left, right) -> { - left[0] = left[0].append(separator).append(right[0]); + if (left[0] == null) + left[0] = right[0]; + else + left[0] = left[0].append(separator).append(right[0]); return left; }; } @Override public @NotNull Function finisher() { - return array -> array[0]; + return array -> Objects.requireNonNullElseGet(array[0], Component::empty); } @Override From fcfc862a18707db2c500f30cffd9d3fc62280d74 Mon Sep 17 00:00:00 2001 From: WizardlyBump17 Date: Fri, 30 Jan 2026 19:49:00 -0300 Subject: [PATCH 345/363] only handle that if it is the last input --- .../wizardlybump17/wlib/command/Command.java | 2 +- .../wlib/test/command/SuggestionTests.java | 53 +++++++++++++++++++ 2 files changed, 54 insertions(+), 1 deletion(-) diff --git a/commands/src/main/java/com/wizardlybump17/wlib/command/Command.java b/commands/src/main/java/com/wizardlybump17/wlib/command/Command.java index e735b270..60be8cb3 100644 --- a/commands/src/main/java/com/wizardlybump17/wlib/command/Command.java +++ b/commands/src/main/java/com/wizardlybump17/wlib/command/Command.java @@ -145,7 +145,7 @@ public Command(@NotNull LiteralCommandNode root) { String inputString = input.get(i); boolean isLastInput = i == input.size() - 1; - if (inputString != null && inputString.isEmpty()) { + if (isLastInput && inputString != null && inputString.isEmpty()) { for (CommandNode child : children) { String permission = child.getPermission(); if (permission == null || sender.hasPermission(permission)) diff --git a/commands/src/test/java/com/wizardlybump17/wlib/test/command/SuggestionTests.java b/commands/src/test/java/com/wizardlybump17/wlib/test/command/SuggestionTests.java index afb688b2..216b076a 100644 --- a/commands/src/test/java/com/wizardlybump17/wlib/test/command/SuggestionTests.java +++ b/commands/src/test/java/com/wizardlybump17/wlib/test/command/SuggestionTests.java @@ -741,4 +741,57 @@ void testDefaultSuggestions() { ).getSuggestions(CHAD_SENDER, List.of("hello", "9b07bd8a-a4c0"))) ); } + + @Test + void testEmptyStrings0() { + Command command = new Command( + new LiteralCommandNode( + "hello", + List.of( + new LiteralCommandNode( + "world", + List.of(), + null, + null + ) + ), + null, + null + ) + ); + + Assertions.assertEquals(List.of("world"), Assertions.assertDoesNotThrow(() -> command.getSuggestions(CHAD_SENDER, List.of("hello", "")))); + Assertions.assertEquals(List.of(), Assertions.assertDoesNotThrow(() -> command.getSuggestions(CHAD_SENDER, List.of("hello", "", "")))); + } + + @Test + void testEmptyStrings1() { + Command command = new Command( + new LiteralCommandNode( + "hello", + List.of( + new LiteralCommandNode( + "world", + List.of( + new LiteralCommandNode( + "test0", + List.of(), + null, + null + ) + ), + null, + null + ) + ), + null, + null + ) + ); + + Assertions.assertEquals(List.of("world"), Assertions.assertDoesNotThrow(() -> command.getSuggestions(CHAD_SENDER, List.of("hello", "")))); + Assertions.assertEquals(List.of(), Assertions.assertDoesNotThrow(() -> command.getSuggestions(CHAD_SENDER, List.of("hello", "", "")))); + Assertions.assertEquals(List.of("test0"), Assertions.assertDoesNotThrow(() -> command.getSuggestions(CHAD_SENDER, List.of("hello", "world", "")))); + Assertions.assertEquals(List.of(), Assertions.assertDoesNotThrow(() -> command.getSuggestions(CHAD_SENDER, List.of("hello", "world", "test0", "")))); + } } From 226392c2b75362f7dc32872de172e6af01baeed1 Mon Sep 17 00:00:00 2001 From: WizardlyBump17 Date: Fri, 30 Jan 2026 20:13:47 -0300 Subject: [PATCH 346/363] added the PaginatedInventoryBuilder#setReplacementActionByCustomData(String, Object, ClickAction) method --- .../inventory/paginated/PaginatedInventoryBuilder.java | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/core/src/main/java/com/wizardlybump17/wlib/inventory/paginated/PaginatedInventoryBuilder.java b/core/src/main/java/com/wizardlybump17/wlib/inventory/paginated/PaginatedInventoryBuilder.java index 60586060..709a9c7d 100644 --- a/core/src/main/java/com/wizardlybump17/wlib/inventory/paginated/PaginatedInventoryBuilder.java +++ b/core/src/main/java/com/wizardlybump17/wlib/inventory/paginated/PaginatedInventoryBuilder.java @@ -2,6 +2,7 @@ import com.wizardlybump17.wlib.inventory.CustomInventory; import com.wizardlybump17.wlib.inventory.CustomInventoryHolder; +import com.wizardlybump17.wlib.inventory.item.ClickAction; import com.wizardlybump17.wlib.inventory.item.InventoryNavigator; import com.wizardlybump17.wlib.inventory.item.ItemButton; import com.wizardlybump17.wlib.inventory.listener.InventoryListener; @@ -104,6 +105,14 @@ public PaginatedInventoryBuilder shapeReplacements(@NonNull Map content) { this.content = content == null ? new ArrayList<>() : content; checkNullContent(); From 2666619402818c229f3503ee97dac36192b9e16d Mon Sep 17 00:00:00 2001 From: WizardlyBump17 Date: Fri, 30 Jan 2026 20:13:47 -0300 Subject: [PATCH 347/363] added the PaginatedInventoryBuilder#setReplacementActionByCustomData(String, Object, ClickAction) method --- .../inventory/paginated/PaginatedInventoryBuilder.java | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/core/src/main/java/com/wizardlybump17/wlib/inventory/paginated/PaginatedInventoryBuilder.java b/core/src/main/java/com/wizardlybump17/wlib/inventory/paginated/PaginatedInventoryBuilder.java index 60586060..709a9c7d 100644 --- a/core/src/main/java/com/wizardlybump17/wlib/inventory/paginated/PaginatedInventoryBuilder.java +++ b/core/src/main/java/com/wizardlybump17/wlib/inventory/paginated/PaginatedInventoryBuilder.java @@ -2,6 +2,7 @@ import com.wizardlybump17.wlib.inventory.CustomInventory; import com.wizardlybump17.wlib.inventory.CustomInventoryHolder; +import com.wizardlybump17.wlib.inventory.item.ClickAction; import com.wizardlybump17.wlib.inventory.item.InventoryNavigator; import com.wizardlybump17.wlib.inventory.item.ItemButton; import com.wizardlybump17.wlib.inventory.listener.InventoryListener; @@ -104,6 +105,14 @@ public PaginatedInventoryBuilder shapeReplacements(@NonNull Map content) { this.content = content == null ? new ArrayList<>() : content; checkNullContent(); From 6d0a3970eaba7f1f14db11fbcef90e87fe03aeb7 Mon Sep 17 00:00:00 2001 From: WizardlyBump17 Date: Mon, 2 Feb 2026 20:44:55 -0300 Subject: [PATCH 348/363] added the BadRequestResult --- .../wlib/command/result/CommandResult.java | 8 ++++++++ .../command/result/error/BadRequestResult.java | 14 ++++++++++++++ 2 files changed, 22 insertions(+) create mode 100644 commands/src/main/java/com/wizardlybump17/wlib/command/result/error/BadRequestResult.java diff --git a/commands/src/main/java/com/wizardlybump17/wlib/command/result/CommandResult.java b/commands/src/main/java/com/wizardlybump17/wlib/command/result/CommandResult.java index 995406d5..1d76fe05 100644 --- a/commands/src/main/java/com/wizardlybump17/wlib/command/result/CommandResult.java +++ b/commands/src/main/java/com/wizardlybump17/wlib/command/result/CommandResult.java @@ -86,6 +86,10 @@ public interface CommandResult { return new ConflictResult<>(lastInputIndex, lastNode); } + static @NotNull BadRequestResult badRequest(int lastInputIndex, @NotNull CommandNode lastNode) { + return new BadRequestResult<>(lastInputIndex, lastNode); + } + //with context static @NotNull SuccessResult successful(@NotNull CommandContext context, @Nullable T data) { @@ -123,4 +127,8 @@ public interface CommandResult { static @NotNull ConflictResult conflict(@NotNull CommandContext context) { return conflict(context.lastInputIndex(), context.lastNode()); } + + static @NotNull BadRequestResult badRequest(@NotNull CommandContext context) { + return badRequest(context.lastInputIndex(), context.lastNode()); + } } diff --git a/commands/src/main/java/com/wizardlybump17/wlib/command/result/error/BadRequestResult.java b/commands/src/main/java/com/wizardlybump17/wlib/command/result/error/BadRequestResult.java new file mode 100644 index 00000000..fcdd6d69 --- /dev/null +++ b/commands/src/main/java/com/wizardlybump17/wlib/command/result/error/BadRequestResult.java @@ -0,0 +1,14 @@ +package com.wizardlybump17.wlib.command.result.error; + +import com.wizardlybump17.wlib.command.node.CommandNode; +import org.jetbrains.annotations.NotNull; + +public record BadRequestResult(int lastInputIndex, @NotNull CommandNode lastNode) implements UnsuccessResult { + + public static final @NotNull String ID = "WLib:Error/BadRequest"; + + @Override + public @NotNull String id() { + return ID; + } +} From 70ce8e5c0aea1181336e89984eecd9607f93311d Mon Sep 17 00:00:00 2001 From: WizardlyBump17 Date: Mon, 2 Feb 2026 21:14:34 -0300 Subject: [PATCH 349/363] added the UnprocessableContentResult --- .../wlib/command/result/CommandResult.java | 8 ++++++++ .../result/error/UnprocessableContentResult.java | 14 ++++++++++++++ 2 files changed, 22 insertions(+) create mode 100644 commands/src/main/java/com/wizardlybump17/wlib/command/result/error/UnprocessableContentResult.java diff --git a/commands/src/main/java/com/wizardlybump17/wlib/command/result/CommandResult.java b/commands/src/main/java/com/wizardlybump17/wlib/command/result/CommandResult.java index 1d76fe05..56377cba 100644 --- a/commands/src/main/java/com/wizardlybump17/wlib/command/result/CommandResult.java +++ b/commands/src/main/java/com/wizardlybump17/wlib/command/result/CommandResult.java @@ -90,6 +90,10 @@ public interface CommandResult { return new BadRequestResult<>(lastInputIndex, lastNode); } + static @NotNull UnprocessableContentResult unprocessableContent(int lastInputIndex, @NotNull CommandNode lastNode) { + return new UnprocessableContentResult<>(lastInputIndex, lastNode); + } + //with context static @NotNull SuccessResult successful(@NotNull CommandContext context, @Nullable T data) { @@ -131,4 +135,8 @@ public interface CommandResult { static @NotNull BadRequestResult badRequest(@NotNull CommandContext context) { return badRequest(context.lastInputIndex(), context.lastNode()); } + + static @NotNull UnprocessableContentResult unprocessableContent(@NotNull CommandContext context) { + return unprocessableContent(context.lastInputIndex(), context.lastNode()); + } } diff --git a/commands/src/main/java/com/wizardlybump17/wlib/command/result/error/UnprocessableContentResult.java b/commands/src/main/java/com/wizardlybump17/wlib/command/result/error/UnprocessableContentResult.java new file mode 100644 index 00000000..5a1e8a62 --- /dev/null +++ b/commands/src/main/java/com/wizardlybump17/wlib/command/result/error/UnprocessableContentResult.java @@ -0,0 +1,14 @@ +package com.wizardlybump17.wlib.command.result.error; + +import com.wizardlybump17.wlib.command.node.CommandNode; +import org.jetbrains.annotations.NotNull; + +public record UnprocessableContentResult(int lastInputIndex, @NotNull CommandNode lastNode) implements UnsuccessResult { + + public static final @NotNull String ID = "WLib:Error/UnprocessableContent"; + + @Override + public @NotNull String id() { + return ID; + } +} From a7145effe6c239cd57ee4efc25ec8081acc629f0 Mon Sep 17 00:00:00 2001 From: WizardlyBump17 Date: Wed, 11 Feb 2026 23:11:23 -0300 Subject: [PATCH 350/363] let the other command do the merge --- .../wizardlybump17/wlib/command/Command.java | 2 +- .../wlib/test/command/CommandTests.java | 150 ++++++++++++++++++ 2 files changed, 151 insertions(+), 1 deletion(-) diff --git a/commands/src/main/java/com/wizardlybump17/wlib/command/Command.java b/commands/src/main/java/com/wizardlybump17/wlib/command/Command.java index 60be8cb3..1980bd62 100644 --- a/commands/src/main/java/com/wizardlybump17/wlib/command/Command.java +++ b/commands/src/main/java/com/wizardlybump17/wlib/command/Command.java @@ -223,7 +223,7 @@ public Command(@NotNull LiteralCommandNode root) { public @NotNull Command merge(@NotNull Command other) { if (other.getClass() != getClass()) - throw new IllegalArgumentException("Can not merge different kinds of Commands"); + return other.merge(this); return new Command(root.merge(other.getRoot())); } diff --git a/commands/src/test/java/com/wizardlybump17/wlib/test/command/CommandTests.java b/commands/src/test/java/com/wizardlybump17/wlib/test/command/CommandTests.java index eb9c6299..c25744d5 100644 --- a/commands/src/test/java/com/wizardlybump17/wlib/test/command/CommandTests.java +++ b/commands/src/test/java/com/wizardlybump17/wlib/test/command/CommandTests.java @@ -398,6 +398,156 @@ void testMerge() { )); Assertions.assertEquals(expected, actual); + + Assertions.assertEquals( + new TestMerge0( + new LiteralCommandNode( + "hello", + List.of( + new LiteralCommandNode( + "world", + List.of(), + null, + null + ) + ), + null, + null + ) + ), + new Command( + new LiteralCommandNode( + "hello", + List.of(), + null, + null + ) + ).merge( + new TestMerge0( + new LiteralCommandNode( + "hello", + List.of( + new LiteralCommandNode( + "world", + List.of(), + null, + null + ) + ), + null, + null + ) + ) + ) + ); + + Assertions.assertEquals( + new TestMerge1( + new LiteralCommandNode( + "hi", + List.of( + new LiteralCommandNode( + "there", + List.of(), + null, + null + ) + ), + null, + null + ) + ), + new Command( + new LiteralCommandNode( + "hi", + List.of(), + null, + null + ) + ).merge( + new TestMerge1( + new LiteralCommandNode( + "hi", + List.of( + new LiteralCommandNode( + "there", + List.of(), + null, + null + ) + ), + null, + null + ) + ) + ) + ); + + Assertions.assertEquals( + new TestMerge0( + new LiteralCommandNode( + "test", + List.of( + new LiteralCommandNode( + "test0", + List.of(), + null, + null + ) + ), + null, + null + ) + ), + new TestMerge0( + new LiteralCommandNode( + "test", + List.of(), + null, + null + ) + ).merge( + new TestMerge1( + new LiteralCommandNode( + "test", + List.of( + new LiteralCommandNode( + "test0", + List.of(), + null, + null + ) + ), + null, + null + ) + ) + ) + ); + } + + static class TestMerge0 extends Command { + + public TestMerge0(@NotNull LiteralCommandNode root) { + super(root); + } + + @Override + public @NotNull Command merge(@NotNull Command other) { + return new TestMerge0(getRoot().merge(other.getRoot())); + } + } + + static class TestMerge1 extends Command { + + public TestMerge1(@NotNull LiteralCommandNode root) { + super(root); + } + + @Override + public @NotNull Command merge(@NotNull Command other) { + return new TestMerge1(getRoot().merge(other.getRoot())); + } } @Test From e49c5dfa86df39b56a601dba7abb7f3c439b883c Mon Sep 17 00:00:00 2001 From: WizardlyBump17 Date: Thu, 19 Feb 2026 17:32:58 -0300 Subject: [PATCH 351/363] you can be anything --- .../command/node/object/UUIDCommandNode.java | 16 +++------------- .../node/primitive/BooleanCommandNode.java | 16 +++------------- .../node/primitive/CharacterCommandNode.java | 16 +++------------- .../node/primitive/number/ByteCommandNode.java | 16 +++------------- .../node/primitive/number/DoubleCommandNode.java | 16 +++------------- .../node/primitive/number/FloatCommandNode.java | 16 +++------------- .../primitive/number/IntegerCommandNode.java | 12 ------------ .../node/primitive/number/LongCommandNode.java | 16 +++------------- .../node/primitive/number/NumberCommandNode.java | 6 ------ .../node/primitive/number/ShortCommandNode.java | 12 ------------ .../command/node/string/StringCommandNode.java | 16 +++------------- .../command/node/OfflinePlayerCommandNode.java | 16 +++------------- .../wlib/command/node/PlayerCommandNode.java | 16 +++------------- 13 files changed, 30 insertions(+), 160 deletions(-) diff --git a/commands/src/main/java/com/wizardlybump17/wlib/command/node/object/UUIDCommandNode.java b/commands/src/main/java/com/wizardlybump17/wlib/command/node/object/UUIDCommandNode.java index 717e208d..97040cbb 100644 --- a/commands/src/main/java/com/wizardlybump17/wlib/command/node/object/UUIDCommandNode.java +++ b/commands/src/main/java/com/wizardlybump17/wlib/command/node/object/UUIDCommandNode.java @@ -2,9 +2,9 @@ import com.wizardlybump17.wlib.command.exception.InputParsingException; import com.wizardlybump17.wlib.command.executor.CommandNodeExecutor; -import com.wizardlybump17.wlib.command.input.object.AllowedUUIDInputs; +import com.wizardlybump17.wlib.command.input.AllowedInputs; import com.wizardlybump17.wlib.command.node.CommandNode; -import com.wizardlybump17.wlib.command.suggestion.object.UUIDSuggester; +import com.wizardlybump17.wlib.command.suggestion.Suggester; import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.Nullable; import org.jetbrains.annotations.Unmodifiable; @@ -14,20 +14,10 @@ public class UUIDCommandNode extends CommandNode { - public UUIDCommandNode(@NotNull String name, @NotNull @Unmodifiable List> children, @NotNull AllowedUUIDInputs allowedInputs, @Nullable UUIDSuggester suggester, @Nullable CommandNodeExecutor executor, @Nullable String permission) { + public UUIDCommandNode(@NotNull String name, @NotNull @Unmodifiable List> children, @NotNull AllowedInputs allowedInputs, @Nullable Suggester suggester, @Nullable CommandNodeExecutor executor, @Nullable String permission) { super(name, children, allowedInputs, suggester, executor, permission); } - @Override - public @NotNull AllowedUUIDInputs getAllowedInputs() { - return (AllowedUUIDInputs) super.getAllowedInputs(); - } - - @Override - public @Nullable UUIDSuggester getSuggester() { - return (UUIDSuggester) super.getSuggester(); - } - @Override public @Nullable UUID parse(@NotNull String input) throws InputParsingException { try { diff --git a/commands/src/main/java/com/wizardlybump17/wlib/command/node/primitive/BooleanCommandNode.java b/commands/src/main/java/com/wizardlybump17/wlib/command/node/primitive/BooleanCommandNode.java index e8ad719d..17a84308 100644 --- a/commands/src/main/java/com/wizardlybump17/wlib/command/node/primitive/BooleanCommandNode.java +++ b/commands/src/main/java/com/wizardlybump17/wlib/command/node/primitive/BooleanCommandNode.java @@ -2,9 +2,9 @@ import com.wizardlybump17.wlib.command.exception.InputParsingException; import com.wizardlybump17.wlib.command.executor.CommandNodeExecutor; -import com.wizardlybump17.wlib.command.input.primitive.AllowedBooleanInputs; +import com.wizardlybump17.wlib.command.input.AllowedInputs; import com.wizardlybump17.wlib.command.node.CommandNode; -import com.wizardlybump17.wlib.command.suggestion.primitive.BooleanSuggester; +import com.wizardlybump17.wlib.command.suggestion.Suggester; import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.Nullable; import org.jetbrains.annotations.Unmodifiable; @@ -13,20 +13,10 @@ public class BooleanCommandNode extends AbstractPrimitiveCommandNode { - public BooleanCommandNode(@NotNull String name, @NotNull @Unmodifiable List> children, @NotNull AllowedBooleanInputs allowedInputs, @Nullable BooleanSuggester suggester, @Nullable CommandNodeExecutor executor, @Nullable String permission) { + public BooleanCommandNode(@NotNull String name, @NotNull @Unmodifiable List> children, @NotNull AllowedInputs allowedInputs, @Nullable Suggester suggester, @Nullable CommandNodeExecutor executor, @Nullable String permission) { super(name, children, allowedInputs, suggester, executor, permission); } - @Override - public @NotNull AllowedBooleanInputs getAllowedInputs() { - return (AllowedBooleanInputs) super.getAllowedInputs(); - } - - @Override - public @Nullable BooleanSuggester getSuggester() { - return (BooleanSuggester) super.getSuggester(); - } - @Override public @Nullable Boolean parse(@NotNull String input) throws InputParsingException { if (input.equalsIgnoreCase("true")) diff --git a/commands/src/main/java/com/wizardlybump17/wlib/command/node/primitive/CharacterCommandNode.java b/commands/src/main/java/com/wizardlybump17/wlib/command/node/primitive/CharacterCommandNode.java index 284a562e..e3f356fd 100644 --- a/commands/src/main/java/com/wizardlybump17/wlib/command/node/primitive/CharacterCommandNode.java +++ b/commands/src/main/java/com/wizardlybump17/wlib/command/node/primitive/CharacterCommandNode.java @@ -2,9 +2,9 @@ import com.wizardlybump17.wlib.command.exception.InputParsingException; import com.wizardlybump17.wlib.command.executor.CommandNodeExecutor; -import com.wizardlybump17.wlib.command.input.primitive.AllowedCharacterInputs; +import com.wizardlybump17.wlib.command.input.AllowedInputs; import com.wizardlybump17.wlib.command.node.CommandNode; -import com.wizardlybump17.wlib.command.suggestion.primitive.CharacterSuggester; +import com.wizardlybump17.wlib.command.suggestion.Suggester; import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.Nullable; import org.jetbrains.annotations.Unmodifiable; @@ -13,20 +13,10 @@ public class CharacterCommandNode extends AbstractPrimitiveCommandNode { - public CharacterCommandNode(@NotNull String name, @NotNull @Unmodifiable List> children, @NotNull AllowedCharacterInputs allowedInputs, @Nullable CharacterSuggester suggester, @Nullable CommandNodeExecutor executor, @Nullable String permission) { + public CharacterCommandNode(@NotNull String name, @NotNull @Unmodifiable List> children, @NotNull AllowedInputs allowedInputs, @Nullable Suggester suggester, @Nullable CommandNodeExecutor executor, @Nullable String permission) { super(name, children, allowedInputs, suggester, executor, permission); } - @Override - public @NotNull AllowedCharacterInputs getAllowedInputs() { - return (AllowedCharacterInputs) super.getAllowedInputs(); - } - - @Override - public @Nullable CharacterSuggester getSuggester() { - return (CharacterSuggester) super.getSuggester(); - } - @Override public @Nullable Character parse(@NotNull String input) throws InputParsingException { if (input.length() != 1) diff --git a/commands/src/main/java/com/wizardlybump17/wlib/command/node/primitive/number/ByteCommandNode.java b/commands/src/main/java/com/wizardlybump17/wlib/command/node/primitive/number/ByteCommandNode.java index b5c8b6b2..a8072033 100644 --- a/commands/src/main/java/com/wizardlybump17/wlib/command/node/primitive/number/ByteCommandNode.java +++ b/commands/src/main/java/com/wizardlybump17/wlib/command/node/primitive/number/ByteCommandNode.java @@ -2,10 +2,10 @@ import com.wizardlybump17.wlib.command.exception.InputParsingException; import com.wizardlybump17.wlib.command.executor.CommandNodeExecutor; -import com.wizardlybump17.wlib.command.input.primitive.number.AllowedByteInputs; +import com.wizardlybump17.wlib.command.input.AllowedInputs; import com.wizardlybump17.wlib.command.node.CommandNode; import com.wizardlybump17.wlib.command.node.primitive.PrimitiveCommandNode; -import com.wizardlybump17.wlib.command.suggestion.primitive.number.ByteSuggester; +import com.wizardlybump17.wlib.command.suggestion.Suggester; import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.Nullable; @@ -13,20 +13,10 @@ public class ByteCommandNode extends NumberCommandNode implements PrimitiveCommandNode { - public ByteCommandNode(@NotNull String name, @NotNull List> children, @NotNull AllowedByteInputs allowedInputs, @Nullable ByteSuggester suggester, @Nullable CommandNodeExecutor executor, @Nullable String permission) { + public ByteCommandNode(@NotNull String name, @NotNull List> children, @NotNull AllowedInputs allowedInputs, @Nullable Suggester suggester, @Nullable CommandNodeExecutor executor, @Nullable String permission) { super(name, children, allowedInputs, suggester, executor, permission); } - @Override - public @NotNull AllowedByteInputs getAllowedInputs() { - return (AllowedByteInputs) super.getAllowedInputs(); - } - - @Override - public @Nullable ByteSuggester getSuggester() { - return (ByteSuggester) super.getSuggester(); - } - @Override public @NotNull Byte parse(@NotNull String input) throws InputParsingException { try { diff --git a/commands/src/main/java/com/wizardlybump17/wlib/command/node/primitive/number/DoubleCommandNode.java b/commands/src/main/java/com/wizardlybump17/wlib/command/node/primitive/number/DoubleCommandNode.java index 2c40547b..d27e8c53 100644 --- a/commands/src/main/java/com/wizardlybump17/wlib/command/node/primitive/number/DoubleCommandNode.java +++ b/commands/src/main/java/com/wizardlybump17/wlib/command/node/primitive/number/DoubleCommandNode.java @@ -2,10 +2,10 @@ import com.wizardlybump17.wlib.command.exception.InputParsingException; import com.wizardlybump17.wlib.command.executor.CommandNodeExecutor; -import com.wizardlybump17.wlib.command.input.primitive.number.AllowedDoubleInputs; +import com.wizardlybump17.wlib.command.input.AllowedInputs; import com.wizardlybump17.wlib.command.node.CommandNode; import com.wizardlybump17.wlib.command.node.primitive.PrimitiveCommandNode; -import com.wizardlybump17.wlib.command.suggestion.primitive.number.DoubleSuggester; +import com.wizardlybump17.wlib.command.suggestion.Suggester; import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.Nullable; @@ -13,20 +13,10 @@ public class DoubleCommandNode extends NumberCommandNode implements PrimitiveCommandNode { - public DoubleCommandNode(@NotNull String name, @NotNull List> children, @NotNull AllowedDoubleInputs allowedInputs, @Nullable DoubleSuggester suggester, @Nullable CommandNodeExecutor executor, @Nullable String permission) { + public DoubleCommandNode(@NotNull String name, @NotNull List> children, @NotNull AllowedInputs allowedInputs, @Nullable Suggester suggester, @Nullable CommandNodeExecutor executor, @Nullable String permission) { super(name, children, allowedInputs, suggester, executor, permission); } - @Override - public @NotNull AllowedDoubleInputs getAllowedInputs() { - return (AllowedDoubleInputs) super.getAllowedInputs(); - } - - @Override - public @Nullable DoubleSuggester getSuggester() { - return (DoubleSuggester) super.getSuggester(); - } - @Override public @NotNull Double parse(@NotNull String input) throws InputParsingException { try { diff --git a/commands/src/main/java/com/wizardlybump17/wlib/command/node/primitive/number/FloatCommandNode.java b/commands/src/main/java/com/wizardlybump17/wlib/command/node/primitive/number/FloatCommandNode.java index 19fbe868..e0f3baa0 100644 --- a/commands/src/main/java/com/wizardlybump17/wlib/command/node/primitive/number/FloatCommandNode.java +++ b/commands/src/main/java/com/wizardlybump17/wlib/command/node/primitive/number/FloatCommandNode.java @@ -2,10 +2,10 @@ import com.wizardlybump17.wlib.command.exception.InputParsingException; import com.wizardlybump17.wlib.command.executor.CommandNodeExecutor; -import com.wizardlybump17.wlib.command.input.primitive.number.AllowedFloatInputs; +import com.wizardlybump17.wlib.command.input.AllowedInputs; import com.wizardlybump17.wlib.command.node.CommandNode; import com.wizardlybump17.wlib.command.node.primitive.PrimitiveCommandNode; -import com.wizardlybump17.wlib.command.suggestion.primitive.number.FloatSuggester; +import com.wizardlybump17.wlib.command.suggestion.Suggester; import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.Nullable; @@ -13,20 +13,10 @@ public class FloatCommandNode extends NumberCommandNode implements PrimitiveCommandNode { - public FloatCommandNode(@NotNull String name, @NotNull List> children, @NotNull AllowedFloatInputs allowedInputs, @Nullable FloatSuggester suggester, @Nullable CommandNodeExecutor executor, @Nullable String permission) { + public FloatCommandNode(@NotNull String name, @NotNull List> children, @NotNull AllowedInputs allowedInputs, @Nullable Suggester suggester, @Nullable CommandNodeExecutor executor, @Nullable String permission) { super(name, children, allowedInputs, suggester, executor, permission); } - @Override - public @NotNull AllowedFloatInputs getAllowedInputs() { - return (AllowedFloatInputs) super.getAllowedInputs(); - } - - @Override - public @Nullable FloatSuggester getSuggester() { - return (FloatSuggester) super.getSuggester(); - } - @Override public @NotNull Float parse(@NotNull String input) throws InputParsingException { try { diff --git a/commands/src/main/java/com/wizardlybump17/wlib/command/node/primitive/number/IntegerCommandNode.java b/commands/src/main/java/com/wizardlybump17/wlib/command/node/primitive/number/IntegerCommandNode.java index 211b9400..89c26e53 100644 --- a/commands/src/main/java/com/wizardlybump17/wlib/command/node/primitive/number/IntegerCommandNode.java +++ b/commands/src/main/java/com/wizardlybump17/wlib/command/node/primitive/number/IntegerCommandNode.java @@ -3,11 +3,9 @@ import com.wizardlybump17.wlib.command.exception.InputParsingException; import com.wizardlybump17.wlib.command.executor.CommandNodeExecutor; import com.wizardlybump17.wlib.command.input.AllowedInputs; -import com.wizardlybump17.wlib.command.input.primitive.number.AllowedIntegerInputs; import com.wizardlybump17.wlib.command.node.CommandNode; import com.wizardlybump17.wlib.command.node.primitive.PrimitiveCommandNode; import com.wizardlybump17.wlib.command.suggestion.Suggester; -import com.wizardlybump17.wlib.command.suggestion.primitive.number.IntegerSuggester; import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.Nullable; @@ -19,16 +17,6 @@ public IntegerCommandNode(@NotNull String name, @NotNull List> ch super(name, children, allowedInputs, suggester, executor, permission); } - @Override - public @NotNull AllowedIntegerInputs getAllowedInputs() { - return (AllowedIntegerInputs) super.getAllowedInputs(); - } - - @Override - public @Nullable IntegerSuggester getSuggester() { - return (IntegerSuggester) super.getSuggester(); - } - @Override public @NotNull Integer parse(@NotNull String input) throws InputParsingException { try { diff --git a/commands/src/main/java/com/wizardlybump17/wlib/command/node/primitive/number/LongCommandNode.java b/commands/src/main/java/com/wizardlybump17/wlib/command/node/primitive/number/LongCommandNode.java index 8b35d2b9..8bad6eda 100644 --- a/commands/src/main/java/com/wizardlybump17/wlib/command/node/primitive/number/LongCommandNode.java +++ b/commands/src/main/java/com/wizardlybump17/wlib/command/node/primitive/number/LongCommandNode.java @@ -2,10 +2,10 @@ import com.wizardlybump17.wlib.command.exception.InputParsingException; import com.wizardlybump17.wlib.command.executor.CommandNodeExecutor; -import com.wizardlybump17.wlib.command.input.primitive.number.AllowedLongInputs; +import com.wizardlybump17.wlib.command.input.AllowedInputs; import com.wizardlybump17.wlib.command.node.CommandNode; import com.wizardlybump17.wlib.command.node.primitive.PrimitiveCommandNode; -import com.wizardlybump17.wlib.command.suggestion.primitive.number.LongSuggester; +import com.wizardlybump17.wlib.command.suggestion.Suggester; import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.Nullable; @@ -13,20 +13,10 @@ public class LongCommandNode extends NumberCommandNode implements PrimitiveCommandNode { - public LongCommandNode(@NotNull String name, @NotNull List> children, @NotNull AllowedLongInputs allowedInputs, @Nullable LongSuggester suggester, @Nullable CommandNodeExecutor executor, @Nullable String permission) { + public LongCommandNode(@NotNull String name, @NotNull List> children, @NotNull AllowedInputs allowedInputs, @Nullable Suggester suggester, @Nullable CommandNodeExecutor executor, @Nullable String permission) { super(name, children, allowedInputs, suggester, executor, permission); } - @Override - public @NotNull AllowedLongInputs getAllowedInputs() { - return (AllowedLongInputs) super.getAllowedInputs(); - } - - @Override - public @Nullable LongSuggester getSuggester() { - return (LongSuggester) super.getSuggester(); - } - @Override public @NotNull Long parse(@NotNull String input) throws InputParsingException { try { diff --git a/commands/src/main/java/com/wizardlybump17/wlib/command/node/primitive/number/NumberCommandNode.java b/commands/src/main/java/com/wizardlybump17/wlib/command/node/primitive/number/NumberCommandNode.java index 8827ec30..4b807681 100644 --- a/commands/src/main/java/com/wizardlybump17/wlib/command/node/primitive/number/NumberCommandNode.java +++ b/commands/src/main/java/com/wizardlybump17/wlib/command/node/primitive/number/NumberCommandNode.java @@ -4,7 +4,6 @@ import com.wizardlybump17.wlib.command.input.AllowedInputs; import com.wizardlybump17.wlib.command.node.CommandNode; import com.wizardlybump17.wlib.command.suggestion.Suggester; -import com.wizardlybump17.wlib.command.suggestion.primitive.number.NumberSuggester; import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.Nullable; @@ -16,11 +15,6 @@ public NumberCommandNode(@NotNull String name, @NotNull List> chi super(name, children, allowedInputs, suggester, executor, permission); } - @Override - public @Nullable NumberSuggester getSuggester() { - return (NumberSuggester) super.getSuggester(); - } - @Override public abstract @NotNull NumberCommandNode withChildren(@NotNull List> children); diff --git a/commands/src/main/java/com/wizardlybump17/wlib/command/node/primitive/number/ShortCommandNode.java b/commands/src/main/java/com/wizardlybump17/wlib/command/node/primitive/number/ShortCommandNode.java index c5ff2b92..c45cdd7d 100644 --- a/commands/src/main/java/com/wizardlybump17/wlib/command/node/primitive/number/ShortCommandNode.java +++ b/commands/src/main/java/com/wizardlybump17/wlib/command/node/primitive/number/ShortCommandNode.java @@ -3,11 +3,9 @@ import com.wizardlybump17.wlib.command.exception.InputParsingException; import com.wizardlybump17.wlib.command.executor.CommandNodeExecutor; import com.wizardlybump17.wlib.command.input.AllowedInputs; -import com.wizardlybump17.wlib.command.input.primitive.number.AllowedShortInputs; import com.wizardlybump17.wlib.command.node.CommandNode; import com.wizardlybump17.wlib.command.node.primitive.PrimitiveCommandNode; import com.wizardlybump17.wlib.command.suggestion.Suggester; -import com.wizardlybump17.wlib.command.suggestion.primitive.number.ShortSuggester; import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.Nullable; @@ -19,16 +17,6 @@ public ShortCommandNode(@NotNull String name, @NotNull List> chil super(name, children, allowedInputs, suggester, executor, permission); } - @Override - public @NotNull AllowedShortInputs getAllowedInputs() { - return (AllowedShortInputs) super.getAllowedInputs(); - } - - @Override - public @Nullable ShortSuggester getSuggester() { - return (ShortSuggester) super.getSuggester(); - } - @Override public @NotNull Short parse(@NotNull String input) throws InputParsingException { try { diff --git a/commands/src/main/java/com/wizardlybump17/wlib/command/node/string/StringCommandNode.java b/commands/src/main/java/com/wizardlybump17/wlib/command/node/string/StringCommandNode.java index b4cfa4e2..eedeb82a 100644 --- a/commands/src/main/java/com/wizardlybump17/wlib/command/node/string/StringCommandNode.java +++ b/commands/src/main/java/com/wizardlybump17/wlib/command/node/string/StringCommandNode.java @@ -2,9 +2,9 @@ import com.wizardlybump17.wlib.command.exception.InputParsingException; import com.wizardlybump17.wlib.command.executor.CommandNodeExecutor; -import com.wizardlybump17.wlib.command.input.string.AllowedStringInputs; +import com.wizardlybump17.wlib.command.input.AllowedInputs; import com.wizardlybump17.wlib.command.node.CommandNode; -import com.wizardlybump17.wlib.command.suggestion.string.StringSuggester; +import com.wizardlybump17.wlib.command.suggestion.Suggester; import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.Nullable; import org.jetbrains.annotations.Unmodifiable; @@ -13,20 +13,10 @@ public class StringCommandNode extends CommandNode { - public StringCommandNode(@NotNull String name, @NotNull @Unmodifiable List> children, @NotNull AllowedStringInputs allowedInputs, @Nullable StringSuggester suggester, @Nullable CommandNodeExecutor executor, @Nullable String permission) { + public StringCommandNode(@NotNull String name, @NotNull @Unmodifiable List> children, @NotNull AllowedInputs allowedInputs, @Nullable Suggester suggester, @Nullable CommandNodeExecutor executor, @Nullable String permission) { super(name, children, allowedInputs, suggester, executor, permission); } - @Override - public @NotNull AllowedStringInputs getAllowedInputs() { - return (AllowedStringInputs) super.getAllowedInputs(); - } - - @Override - public @Nullable StringSuggester getSuggester() { - return (StringSuggester) super.getSuggester(); - } - @Override public @Nullable String parse(@NotNull String input) throws InputParsingException { return input; diff --git a/core/src/main/java/com/wizardlybump17/wlib/command/node/OfflinePlayerCommandNode.java b/core/src/main/java/com/wizardlybump17/wlib/command/node/OfflinePlayerCommandNode.java index eeea12f5..cd6e91bd 100644 --- a/core/src/main/java/com/wizardlybump17/wlib/command/node/OfflinePlayerCommandNode.java +++ b/core/src/main/java/com/wizardlybump17/wlib/command/node/OfflinePlayerCommandNode.java @@ -2,8 +2,8 @@ import com.wizardlybump17.wlib.command.exception.InputParsingException; import com.wizardlybump17.wlib.command.executor.CommandNodeExecutor; -import com.wizardlybump17.wlib.command.input.AllowedOfflinePlayerInputs; -import com.wizardlybump17.wlib.command.suggestion.OfflinePlayerSuggester; +import com.wizardlybump17.wlib.command.input.AllowedInputs; +import com.wizardlybump17.wlib.command.suggestion.Suggester; import org.bukkit.Bukkit; import org.bukkit.OfflinePlayer; import org.jetbrains.annotations.NotNull; @@ -15,7 +15,7 @@ public class OfflinePlayerCommandNode extends CommandNode { - public OfflinePlayerCommandNode(@NotNull String name, @NotNull @Unmodifiable List> children, @NotNull AllowedOfflinePlayerInputs allowedInputs, @Nullable OfflinePlayerSuggester suggester, @Nullable CommandNodeExecutor executor, @Nullable String permission) { + public OfflinePlayerCommandNode(@NotNull String name, @NotNull @Unmodifiable List> children, @NotNull AllowedInputs allowedInputs, @Nullable Suggester suggester, @Nullable CommandNodeExecutor executor, @Nullable String permission) { super(name, children, allowedInputs, suggester, executor, permission); } @@ -39,16 +39,6 @@ public OfflinePlayerCommandNode(@NotNull String name, @NotNull @Unmodifiable Lis return null; } - @Override - public @NotNull AllowedOfflinePlayerInputs getAllowedInputs() { - return (AllowedOfflinePlayerInputs) super.getAllowedInputs(); - } - - @Override - public @Nullable OfflinePlayerSuggester getSuggester() { - return (OfflinePlayerSuggester) super.getSuggester(); - } - @Override public @NotNull OfflinePlayerCommandNode withChildren(@NotNull List> children) { return new OfflinePlayerCommandNode(getName(), children, getAllowedInputs(), getSuggester(), getExecutor(), getPermission()); diff --git a/core/src/main/java/com/wizardlybump17/wlib/command/node/PlayerCommandNode.java b/core/src/main/java/com/wizardlybump17/wlib/command/node/PlayerCommandNode.java index 417905e5..45d56cad 100644 --- a/core/src/main/java/com/wizardlybump17/wlib/command/node/PlayerCommandNode.java +++ b/core/src/main/java/com/wizardlybump17/wlib/command/node/PlayerCommandNode.java @@ -2,8 +2,8 @@ import com.wizardlybump17.wlib.command.exception.InputParsingException; import com.wizardlybump17.wlib.command.executor.CommandNodeExecutor; -import com.wizardlybump17.wlib.command.input.AllowedPlayerInputs; -import com.wizardlybump17.wlib.command.suggestion.PlayerSuggester; +import com.wizardlybump17.wlib.command.input.AllowedInputs; +import com.wizardlybump17.wlib.command.suggestion.Suggester; import org.bukkit.Bukkit; import org.bukkit.entity.Player; import org.jetbrains.annotations.NotNull; @@ -15,7 +15,7 @@ public class PlayerCommandNode extends CommandNode { - public PlayerCommandNode(@NotNull String name, @NotNull @Unmodifiable List> children, @NotNull AllowedPlayerInputs allowedInputs, @Nullable PlayerSuggester suggester, @Nullable CommandNodeExecutor executor, @Nullable String permission) { + public PlayerCommandNode(@NotNull String name, @NotNull @Unmodifiable List> children, @NotNull AllowedInputs allowedInputs, @Nullable Suggester suggester, @Nullable CommandNodeExecutor executor, @Nullable String permission) { super(name, children, allowedInputs, suggester, executor, permission); } @@ -39,16 +39,6 @@ public PlayerCommandNode(@NotNull String name, @NotNull @Unmodifiable List> children) { return new PlayerCommandNode(getName(), children, getAllowedInputs(), getSuggester(), getExecutor(), getPermission()); From 79dfefe95263e1ee2473021f1b4549d70a79f101 Mon Sep 17 00:00:00 2001 From: WizardlyBump17 Date: Thu, 26 Feb 2026 19:25:48 -0300 Subject: [PATCH 352/363] using an ItemMeta instead --- .../wlib/item/handler/ItemMetaHandler.java | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/core/src/main/java/com/wizardlybump17/wlib/item/handler/ItemMetaHandler.java b/core/src/main/java/com/wizardlybump17/wlib/item/handler/ItemMetaHandler.java index 6c137fa5..8a9bc9e4 100644 --- a/core/src/main/java/com/wizardlybump17/wlib/item/handler/ItemMetaHandler.java +++ b/core/src/main/java/com/wizardlybump17/wlib/item/handler/ItemMetaHandler.java @@ -1,8 +1,9 @@ package com.wizardlybump17.wlib.item.handler; -import com.wizardlybump17.wlib.item.ItemBuilder; import com.wizardlybump17.wlib.item.handler.model.ItemMetaHandlerModel; import lombok.Data; +import org.bukkit.inventory.meta.ItemMeta; +import org.jetbrains.annotations.NotNull; import java.util.Map; @@ -10,9 +11,13 @@ public abstract class ItemMetaHandler> { private final M model; - private final ItemBuilder builder; + private final @NotNull ItemMeta itemMeta; public abstract void serialize(Map map); public abstract void deserialize(Map map); + + public @NotNull ItemMeta getItemMeta() { + return itemMeta; + } } From 81840511f3fc63003e87dd0a9982102796d5b251 Mon Sep 17 00:00:00 2001 From: WizardlyBump17 Date: Thu, 26 Feb 2026 20:13:18 -0300 Subject: [PATCH 353/363] added the ItemMetaHandlerModel.getApplicableModelOptional(Material) method --- .../wlib/item/handler/model/ItemMetaHandlerModel.java | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/core/src/main/java/com/wizardlybump17/wlib/item/handler/model/ItemMetaHandlerModel.java b/core/src/main/java/com/wizardlybump17/wlib/item/handler/model/ItemMetaHandlerModel.java index 74b3a487..3aaee54f 100644 --- a/core/src/main/java/com/wizardlybump17/wlib/item/handler/model/ItemMetaHandlerModel.java +++ b/core/src/main/java/com/wizardlybump17/wlib/item/handler/model/ItemMetaHandlerModel.java @@ -8,6 +8,7 @@ import java.util.EnumMap; import java.util.Map; +import java.util.Optional; import java.util.Set; @Data @@ -34,6 +35,10 @@ public static ItemMetaHandlerModel getApplicableModel(Material material) { return MODELS.get(material); } + public static @NotNull Optional> getApplicableModelOptional(@NotNull Material material) { + return Optional.ofNullable(getApplicableModel(material)); + } + public static void registerModel(ItemMetaHandlerModel model) { for (Material material : model.getApplicableMaterials()) MODELS.put(material, model); From 05b0c26a3878c5365bb92bc29f5e4ecd237ff49a Mon Sep 17 00:00:00 2001 From: WizardlyBump17 Date: Thu, 26 Feb 2026 20:13:48 -0300 Subject: [PATCH 354/363] using the ItemMeta --- .../wlib/item/handler/model/ItemMetaHandlerModel.java | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/core/src/main/java/com/wizardlybump17/wlib/item/handler/model/ItemMetaHandlerModel.java b/core/src/main/java/com/wizardlybump17/wlib/item/handler/model/ItemMetaHandlerModel.java index 3aaee54f..3e6e3cda 100644 --- a/core/src/main/java/com/wizardlybump17/wlib/item/handler/model/ItemMetaHandlerModel.java +++ b/core/src/main/java/com/wizardlybump17/wlib/item/handler/model/ItemMetaHandlerModel.java @@ -4,6 +4,8 @@ import com.wizardlybump17.wlib.item.handler.ItemMetaHandler; import lombok.Data; import org.bukkit.Material; +import org.bukkit.inventory.meta.ItemMeta; +import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.Nullable; import java.util.EnumMap; @@ -26,6 +28,8 @@ public ItemMetaHandlerModel(Set applicableMaterials) { public abstract H createHandler(ItemBuilder builder); + public abstract @NotNull H createHandler(@NotNull ItemMeta itemMeta); + public boolean isApplicable(Material material) { return applicableMaterials.contains(material); } From 423ff8b40b330946ccaede6393b7cc9c6c98a421 Mon Sep 17 00:00:00 2001 From: WizardlyBump17 Date: Thu, 26 Feb 2026 20:16:01 -0300 Subject: [PATCH 355/363] deprecation notice --- .../wlib/item/handler/model/ItemMetaHandlerModel.java | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/core/src/main/java/com/wizardlybump17/wlib/item/handler/model/ItemMetaHandlerModel.java b/core/src/main/java/com/wizardlybump17/wlib/item/handler/model/ItemMetaHandlerModel.java index 3e6e3cda..2b6ad166 100644 --- a/core/src/main/java/com/wizardlybump17/wlib/item/handler/model/ItemMetaHandlerModel.java +++ b/core/src/main/java/com/wizardlybump17/wlib/item/handler/model/ItemMetaHandlerModel.java @@ -26,6 +26,10 @@ public ItemMetaHandlerModel(Set applicableMaterials) { registerModel(this); } + /** + * @deprecated use {@link #createHandler(ItemMeta)} instead + */ + @Deprecated(forRemoval = true) public abstract H createHandler(ItemBuilder builder); public abstract @NotNull H createHandler(@NotNull ItemMeta itemMeta); From 24d3ec61c4dcc40a7a1bf17fdb3c9252921edc55 Mon Sep 17 00:00:00 2001 From: WizardlyBump17 Date: Thu, 26 Feb 2026 20:27:30 -0300 Subject: [PATCH 356/363] using the ItemMeta instead --- .../item/handler/FireworkMetaHandler.java | 45 ++++++---- .../item/handler/LeatherArmorMetaHandler.java | 31 ++++--- .../wlib/item/handler/PotionMetaHandler.java | 33 ++++--- .../wlib/item/handler/SkullMetaHandler.java | 85 ++++++++++++------- .../model/FireworkMetaHandlerModel.java | 10 ++- .../model/LeatherArmorMetaHandlerModel.java | 10 ++- .../handler/model/PotionMetaHandlerModel.java | 10 ++- .../handler/model/SkullMetaHandlerModel.java | 10 ++- 8 files changed, 155 insertions(+), 79 deletions(-) diff --git a/core/src/main/java/com/wizardlybump17/wlib/item/handler/FireworkMetaHandler.java b/core/src/main/java/com/wizardlybump17/wlib/item/handler/FireworkMetaHandler.java index 724bd80f..278d4717 100644 --- a/core/src/main/java/com/wizardlybump17/wlib/item/handler/FireworkMetaHandler.java +++ b/core/src/main/java/com/wizardlybump17/wlib/item/handler/FireworkMetaHandler.java @@ -1,57 +1,66 @@ package com.wizardlybump17.wlib.item.handler; -import com.wizardlybump17.wlib.item.ItemBuilder; import com.wizardlybump17.wlib.item.handler.model.FireworkMetaHandlerModel; import org.bukkit.FireworkEffect; import org.bukkit.inventory.meta.FireworkMeta; +import org.jetbrains.annotations.NotNull; -import java.util.Collections; import java.util.List; import java.util.Map; public class FireworkMetaHandler extends ItemMetaHandler { - public FireworkMetaHandler(FireworkMetaHandlerModel model, ItemBuilder builder) { - super(model, builder); + public FireworkMetaHandler(FireworkMetaHandlerModel model, @NotNull FireworkMeta itemMeta) { + super(model, itemMeta); + } + + @Override + public @NotNull FireworkMeta getItemMeta() { + return (FireworkMeta) super.getItemMeta(); } @Override public void serialize(Map map) { - List effects = getBuilder().getFromMeta(FireworkMeta::getEffects, Collections.emptyList()); - map.put("effects", effects.isEmpty() ? null : effects); - int power = getBuilder().getFromMeta(FireworkMeta::getPower, 0); - map.put("power", power == 0 ? null : power); + FireworkMeta itemMeta = getItemMeta(); + + List effects = itemMeta.getEffects(); + if (!effects.isEmpty()) + map.put("effects", effects); + + int power = itemMeta.getPower(); + map.put("power", power); } - @SuppressWarnings("unchecked") @Override public void deserialize(Map map) { - getBuilder().consumeMeta(meta -> { - meta.addEffects((List) map.getOrDefault("effects", Collections.emptyList())); - meta.setPower((Integer) map.getOrDefault("power", 0)); - }); + FireworkMeta itemMeta = getItemMeta(); + + itemMeta.addEffects((FireworkEffect) map.getOrDefault("effects", List.of())); + itemMeta.setPower((int) map.getOrDefault("power", 0)); } public FireworkMetaHandler effects(FireworkEffect... effects) { - getBuilder().consumeMeta(meta -> meta.addEffects(effects)); + FireworkMeta itemMeta = getItemMeta(); + itemMeta.clearEffects(); + itemMeta.addEffects(effects); return this; } public FireworkMetaHandler power(int power) { - getBuilder().consumeMeta(meta -> meta.setPower(power)); + getItemMeta().setPower(power); return this; } public FireworkMetaHandler clearEffects() { - getBuilder().consumeMeta(FireworkMeta::clearEffects); + getItemMeta().clearEffects(); return this; } public List effects() { - return getBuilder().getFromMeta(FireworkMeta::getEffects, Collections.emptyList()); + return getItemMeta().getEffects(); } public int power() { - return getBuilder().getFromMeta(FireworkMeta::getPower, 0); + return getItemMeta().getPower(); } } diff --git a/core/src/main/java/com/wizardlybump17/wlib/item/handler/LeatherArmorMetaHandler.java b/core/src/main/java/com/wizardlybump17/wlib/item/handler/LeatherArmorMetaHandler.java index 981091fc..4781c604 100644 --- a/core/src/main/java/com/wizardlybump17/wlib/item/handler/LeatherArmorMetaHandler.java +++ b/core/src/main/java/com/wizardlybump17/wlib/item/handler/LeatherArmorMetaHandler.java @@ -1,35 +1,44 @@ package com.wizardlybump17.wlib.item.handler; -import com.wizardlybump17.wlib.item.ItemBuilder; import com.wizardlybump17.wlib.item.handler.model.LeatherArmorMetaHandlerModel; import org.bukkit.Color; import org.bukkit.inventory.meta.LeatherArmorMeta; +import org.jetbrains.annotations.NotNull; import java.util.Map; public class LeatherArmorMetaHandler extends ItemMetaHandler { - public LeatherArmorMetaHandler(LeatherArmorMetaHandlerModel model, ItemBuilder builder) { - super(model, builder); + public LeatherArmorMetaHandler(LeatherArmorMetaHandlerModel model, LeatherArmorMeta itemMeta) { + super(model, itemMeta); } @Override - public void serialize(Map map) { - map.put("color", getBuilder().getFromMeta(LeatherArmorMeta::getColor, (Color) null)); + public @NotNull LeatherArmorMeta getItemMeta() { + return (LeatherArmorMeta) super.getItemMeta(); } @Override - public void deserialize(Map map) { - getBuilder().consumeMeta(meta -> meta.setColor(getColor(map.get("color")))); + public void serialize(@NotNull Map map) { + LeatherArmorMeta itemMeta = getItemMeta(); + + map.put("color", itemMeta.getColor()); + } + + @Override + public void deserialize(@NotNull Map map) { + LeatherArmorMeta itemMeta = getItemMeta(); + + itemMeta.setColor(getColor(map.get("color"))); } - public LeatherArmorMetaHandler color(Color color) { - getBuilder().consumeMeta(meta -> meta.setColor(color)); + public @NotNull LeatherArmorMetaHandler color(@NotNull Color color) { + getItemMeta().setColor(color); return this; } - public Color color() { - return getBuilder().getFromMeta(LeatherArmorMeta::getColor, (Color) null); + public @NotNull Color color() { + return getItemMeta().getColor(); } private static Color getColor(Object object) { diff --git a/core/src/main/java/com/wizardlybump17/wlib/item/handler/PotionMetaHandler.java b/core/src/main/java/com/wizardlybump17/wlib/item/handler/PotionMetaHandler.java index 3d752ea9..837a6e0e 100644 --- a/core/src/main/java/com/wizardlybump17/wlib/item/handler/PotionMetaHandler.java +++ b/core/src/main/java/com/wizardlybump17/wlib/item/handler/PotionMetaHandler.java @@ -1,6 +1,5 @@ package com.wizardlybump17.wlib.item.handler; -import com.wizardlybump17.wlib.item.ItemBuilder; import com.wizardlybump17.wlib.item.handler.model.PotionMetaHandlerModel; import com.wizardlybump17.wlib.util.bukkit.config.wrapper.potion.PotionDataWrapper; import lombok.NonNull; @@ -9,6 +8,7 @@ import org.bukkit.potion.PotionData; import org.bukkit.potion.PotionEffect; import org.bukkit.potion.PotionEffectType; +import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.Nullable; import java.util.Collections; @@ -17,8 +17,13 @@ public class PotionMetaHandler extends ItemMetaHandler { - public PotionMetaHandler(PotionMetaHandlerModel model, ItemBuilder builder) { - super(model, builder); + public PotionMetaHandler(@NotNull PotionMetaHandlerModel model, @NotNull PotionMeta itemMeta) { + super(model, itemMeta); + } + + @Override + public @NotNull PotionMeta getItemMeta() { + return (PotionMeta) super.getItemMeta(); } @Override @@ -40,48 +45,48 @@ public void deserialize(Map map) { } public PotionMetaHandler basePotionData(@NonNull PotionData data) { - getBuilder().consumeMeta(meta -> meta.setBasePotionData(data)); + getItemMeta().setBasePotionData(data); return this; } public PotionData basePotionData() { - return getBuilder().getFromMeta(PotionMeta::getBasePotionData, (PotionData) null); + return getItemMeta().getBasePotionData(); } public boolean hasCustomEffects() { - return getBuilder().getFromMeta(PotionMeta::hasCustomEffects, false); + return getItemMeta().hasCustomEffects(); } public @NonNull List customEffects() { - return getBuilder().getFromMeta(PotionMeta::getCustomEffects, Collections.emptyList()); + return getItemMeta().getCustomEffects(); } public boolean customEffect(@NonNull PotionEffect effect, boolean overwrite) { - return getBuilder().consumeMetaAndReturn(meta -> meta.addCustomEffect(effect, overwrite), false); + return getItemMeta().addCustomEffect(effect, overwrite); } public boolean removeCustomEffect(@NonNull PotionEffectType type) { - return getBuilder().consumeMetaAndReturn(meta -> meta.removeCustomEffect(type), false); + return getItemMeta().removeCustomEffect(type); } public boolean hasCustomEffect(@NonNull PotionEffectType type) { - return getBuilder().getFromMeta(meta -> meta.hasCustomEffect(type), false); + return getItemMeta().hasCustomEffect(type); } public boolean clearCustomEffects() { - return getBuilder().consumeMetaAndReturn(PotionMeta::clearCustomEffects, false); + return getItemMeta().clearCustomEffects(); } public boolean hasColor() { - return getBuilder().getFromMeta(PotionMeta::hasColor, false); + return getItemMeta().hasColor(); } public @Nullable Color color() { - return getBuilder().getFromMeta(PotionMeta::getColor, (Color) null); + return getItemMeta().getColor(); } public PotionMetaHandler color(@Nullable Color color) { - getBuilder().consumeMeta(meta -> meta.setColor(color)); + getItemMeta().setColor(color); return this; } } diff --git a/core/src/main/java/com/wizardlybump17/wlib/item/handler/SkullMetaHandler.java b/core/src/main/java/com/wizardlybump17/wlib/item/handler/SkullMetaHandler.java index a66017c4..523d601e 100644 --- a/core/src/main/java/com/wizardlybump17/wlib/item/handler/SkullMetaHandler.java +++ b/core/src/main/java/com/wizardlybump17/wlib/item/handler/SkullMetaHandler.java @@ -1,12 +1,13 @@ package com.wizardlybump17.wlib.item.handler; import com.destroystokyo.paper.profile.PlayerProfile; -import com.wizardlybump17.wlib.item.ItemBuilder; import com.wizardlybump17.wlib.item.handler.model.SkullMetaHandlerModel; import org.bukkit.Bukkit; import org.bukkit.OfflinePlayer; import org.bukkit.inventory.meta.SkullMeta; import org.bukkit.profile.PlayerTextures; +import org.jetbrains.annotations.NotNull; +import org.jetbrains.annotations.Nullable; import java.net.MalformedURLException; import java.net.URI; @@ -16,16 +17,24 @@ public class SkullMetaHandler extends ItemMetaHandler { - public SkullMetaHandler(SkullMetaHandlerModel model, ItemBuilder builder) { - super(model, builder); + public SkullMetaHandler(@NotNull SkullMetaHandlerModel model, @NotNull SkullMeta itemMeta) { + super(model, itemMeta); + } + + @Override + public @NotNull SkullMeta getItemMeta() { + return (SkullMeta) super.getItemMeta(); } @Override public void serialize(Map map) { - if (skullUrl() != null) - map.put("skull", skullUrl()); - if (skullOwner() != null) - map.put("owner", skullOwner().getUniqueId().toString()); + String skullUrl = skullUrl(); + if (skullUrl != null) + map.put("skull", skullUrl); + + OfflinePlayer skullOwner = skullOwner(); + if (skullOwner != null) + map.put("owner", skullOwner.getUniqueId().toString()); } @Override @@ -41,41 +50,53 @@ public void deserialize(Map map) { skull(Bukkit.getOfflinePlayer(UUID.fromString(owner))); } - public String skullUrl() { - return getBuilder().getFromMeta(meta -> { - PlayerProfile profile = meta.getPlayerProfile(); - if (profile == null) - return null; + public @Nullable String skullUrl() { + PlayerProfile profile = getItemMeta().getPlayerProfile(); + if (profile == null) + return null; - URL skin = profile.getTextures().getSkin(); - return skin == null ? null : skin.toString(); - }, () -> null); + URL skin = profile.getTextures().getSkin(); + return skin == null ? null : skin.toString(); } - public SkullMetaHandler skull(String url) { - getBuilder().consumeMeta(meta -> { - try { - PlayerProfile profile = Bukkit.createProfile(UUID.nameUUIDFromBytes(url.getBytes())); + public @NotNull SkullMetaHandler skull(@Nullable String url) { + SkullMeta itemMeta = getItemMeta(); + + if (url == null) { + PlayerProfile profile = itemMeta.getPlayerProfile(); + if (profile == null) + return this; - PlayerTextures textures = profile.getTextures(); - textures.setSkin(URI.create(url).toURL()); + PlayerTextures textures = profile.getTextures(); - profile.setTextures(textures); + textures.setSkin(null); + profile.setTextures(textures); - meta.setPlayerProfile(profile); - } catch (MalformedURLException e) { - throw new IllegalArgumentException("Invalid URL " + url, e); - } - }); - return this; + itemMeta.setPlayerProfile(profile); + return this; + } + + try { + PlayerProfile profile = Bukkit.createProfile(UUID.nameUUIDFromBytes(url.getBytes())); + + PlayerTextures textures = profile.getTextures(); + textures.setSkin(URI.create(url).toURL()); + + profile.setTextures(textures); + + itemMeta.setPlayerProfile(profile); + return this; + } catch (MalformedURLException e) { + throw new IllegalArgumentException("Invalid URL " + url, e); + } } - public OfflinePlayer skullOwner() { - return getBuilder().getFromMeta(SkullMeta::getOwningPlayer, (OfflinePlayer) null); + public @Nullable OfflinePlayer skullOwner() { + return getItemMeta().getOwningPlayer(); } - public SkullMetaHandler skull(OfflinePlayer owner) { - getBuilder().consumeMeta(meta -> meta.setOwningPlayer(owner)); + public @NotNull SkullMetaHandler skull(@Nullable OfflinePlayer owner) { + getItemMeta().setOwningPlayer(owner); return this; } } diff --git a/core/src/main/java/com/wizardlybump17/wlib/item/handler/model/FireworkMetaHandlerModel.java b/core/src/main/java/com/wizardlybump17/wlib/item/handler/model/FireworkMetaHandlerModel.java index f732074c..2eeebf66 100644 --- a/core/src/main/java/com/wizardlybump17/wlib/item/handler/model/FireworkMetaHandlerModel.java +++ b/core/src/main/java/com/wizardlybump17/wlib/item/handler/model/FireworkMetaHandlerModel.java @@ -3,6 +3,9 @@ import com.wizardlybump17.wlib.item.ItemBuilder; import com.wizardlybump17.wlib.item.handler.FireworkMetaHandler; import org.bukkit.Material; +import org.bukkit.inventory.meta.FireworkMeta; +import org.bukkit.inventory.meta.ItemMeta; +import org.jetbrains.annotations.NotNull; import java.util.Set; @@ -14,6 +17,11 @@ public FireworkMetaHandlerModel() { @Override public FireworkMetaHandler createHandler(ItemBuilder builder) { - return new FireworkMetaHandler(this, builder); + return new FireworkMetaHandler(this, builder.getItemMeta()); + } + + @Override + public @NotNull FireworkMetaHandler createHandler(@NotNull ItemMeta itemMeta) { + return new FireworkMetaHandler(this, (FireworkMeta) itemMeta); } } diff --git a/core/src/main/java/com/wizardlybump17/wlib/item/handler/model/LeatherArmorMetaHandlerModel.java b/core/src/main/java/com/wizardlybump17/wlib/item/handler/model/LeatherArmorMetaHandlerModel.java index a4cff9dc..078702ef 100644 --- a/core/src/main/java/com/wizardlybump17/wlib/item/handler/model/LeatherArmorMetaHandlerModel.java +++ b/core/src/main/java/com/wizardlybump17/wlib/item/handler/model/LeatherArmorMetaHandlerModel.java @@ -3,6 +3,9 @@ import com.wizardlybump17.wlib.item.ItemBuilder; import com.wizardlybump17.wlib.item.handler.LeatherArmorMetaHandler; import org.bukkit.Material; +import org.bukkit.inventory.meta.ItemMeta; +import org.bukkit.inventory.meta.LeatherArmorMeta; +import org.jetbrains.annotations.NotNull; import java.util.Set; @@ -14,6 +17,11 @@ public LeatherArmorMetaHandlerModel() { @Override public LeatherArmorMetaHandler createHandler(ItemBuilder builder) { - return new LeatherArmorMetaHandler(this, builder); + return new LeatherArmorMetaHandler(this, builder.getItemMeta()); + } + + @Override + public @NotNull LeatherArmorMetaHandler createHandler(@NotNull ItemMeta itemMeta) { + return new LeatherArmorMetaHandler(this, (LeatherArmorMeta) itemMeta); } } diff --git a/core/src/main/java/com/wizardlybump17/wlib/item/handler/model/PotionMetaHandlerModel.java b/core/src/main/java/com/wizardlybump17/wlib/item/handler/model/PotionMetaHandlerModel.java index b119af08..652bbcfe 100644 --- a/core/src/main/java/com/wizardlybump17/wlib/item/handler/model/PotionMetaHandlerModel.java +++ b/core/src/main/java/com/wizardlybump17/wlib/item/handler/model/PotionMetaHandlerModel.java @@ -3,6 +3,9 @@ import com.wizardlybump17.wlib.item.ItemBuilder; import com.wizardlybump17.wlib.item.handler.PotionMetaHandler; import org.bukkit.Material; +import org.bukkit.inventory.meta.ItemMeta; +import org.bukkit.inventory.meta.PotionMeta; +import org.jetbrains.annotations.NotNull; import java.util.Set; @@ -14,6 +17,11 @@ public PotionMetaHandlerModel() { @Override public PotionMetaHandler createHandler(ItemBuilder builder) { - return new PotionMetaHandler(this, builder); + return new PotionMetaHandler(this, builder.getItemMeta()); + } + + @Override + public @NotNull PotionMetaHandler createHandler(@NotNull ItemMeta itemMeta) { + return new PotionMetaHandler(this, (PotionMeta) itemMeta); } } diff --git a/core/src/main/java/com/wizardlybump17/wlib/item/handler/model/SkullMetaHandlerModel.java b/core/src/main/java/com/wizardlybump17/wlib/item/handler/model/SkullMetaHandlerModel.java index 2445e3de..8bdf022b 100644 --- a/core/src/main/java/com/wizardlybump17/wlib/item/handler/model/SkullMetaHandlerModel.java +++ b/core/src/main/java/com/wizardlybump17/wlib/item/handler/model/SkullMetaHandlerModel.java @@ -3,6 +3,9 @@ import com.wizardlybump17.wlib.item.ItemBuilder; import com.wizardlybump17.wlib.item.handler.SkullMetaHandler; import org.bukkit.Material; +import org.bukkit.inventory.meta.ItemMeta; +import org.bukkit.inventory.meta.SkullMeta; +import org.jetbrains.annotations.NotNull; import java.util.Set; @@ -14,6 +17,11 @@ public SkullMetaHandlerModel() { @Override public SkullMetaHandler createHandler(ItemBuilder builder) { - return new SkullMetaHandler(this, builder); + return new SkullMetaHandler(this, builder.getItemMeta()); + } + + @Override + public @NotNull SkullMetaHandler createHandler(@NotNull ItemMeta itemMeta) { + return new SkullMetaHandler(this, (SkullMeta) itemMeta); } } From 21491be7fadd7e2ae49df879d2a119e8064b3412 Mon Sep 17 00:00:00 2001 From: WizardlyBump17 Date: Thu, 26 Feb 2026 20:42:23 -0300 Subject: [PATCH 357/363] small rework on the constructors --- .../wizardlybump17/wlib/item/ItemBuilder.java | 110 +++++++++++------- 1 file changed, 67 insertions(+), 43 deletions(-) diff --git a/core/src/main/java/com/wizardlybump17/wlib/item/ItemBuilder.java b/core/src/main/java/com/wizardlybump17/wlib/item/ItemBuilder.java index e55b5657..3e519624 100644 --- a/core/src/main/java/com/wizardlybump17/wlib/item/ItemBuilder.java +++ b/core/src/main/java/com/wizardlybump17/wlib/item/ItemBuilder.java @@ -41,61 +41,79 @@ @SerializableAs("item-builder") public class ItemBuilder implements ConfigurationSerializable, Cloneable { - private @NotNull Material type; - private int amount; - private final @NotNull Map customData; + private @NotNull Material type = Material.AIR; + private int amount = 1; + private final @NotNull Map customData = new TreeMap<>(); private @Nullable ItemMetaHandler metaHandler; private @Nullable ItemMeta itemMeta; - public ItemBuilder(@NotNull Material type, int amount, @NotNull Map customData, @Nullable ItemMeta itemMeta) { - this.type = type; - this.amount = amount; - this.customData = customData; - - ItemMetaHandlerModel metaHandlerModel = ItemMetaHandlerModel.getApplicableModel(type); - if (metaHandlerModel != null) - this.metaHandler = metaHandlerModel.createHandler(this); - - this.itemMeta = itemMeta; + public ItemBuilder() { } - public ItemBuilder(@NotNull Material type, int amount, @NotNull Map customData) { - this(type, amount, customData, null); + public ItemBuilder(@NotNull Material type) { + this.type = type; + itemMeta = Bukkit.getItemFactory().getItemMeta(type); + metaHandler = ItemMetaHandlerModel.getApplicableModelOptional(type) + .map(model -> model.createHandler(itemMeta)) + .orElse(null); } public ItemBuilder(@NotNull Material type, int amount) { - this(type, amount, new HashMap<>()); + this.type = type; + this.amount = amount; + itemMeta = Bukkit.getItemFactory().getItemMeta(type); + metaHandler = ItemMetaHandlerModel.getApplicableModelOptional(type) + .map(model -> model.createHandler(itemMeta)) + .orElse(null); } - public ItemBuilder(@NotNull Material type) { - this(type, 1); + public ItemBuilder(@NotNull Material type, int amount, @NotNull Map customData) { + this.type = type; + this.amount = amount; + itemMeta = Bukkit.getItemFactory().getItemMeta(type); + metaHandler = ItemMetaHandlerModel.getApplicableModelOptional(type) + .map(model -> model.createHandler(itemMeta)) + .orElse(null); + this.customData.putAll(customData); } - public ItemBuilder(@Nullable ItemStack item, @NotNull Map customData) { - this( - item == null ? Material.AIR : item.getType(), - item == null ? 1 : item.getAmount(), - customData, - item == null ? null : item.getItemMeta() - ); + public ItemBuilder(@NotNull Material type, int amount, @NotNull Map customData, @Nullable ItemMeta itemMeta) { + this.type = type; + this.amount = amount; + this.itemMeta = itemMeta; + if (itemMeta != null) { + metaHandler = ItemMetaHandlerModel.getApplicableModelOptional(type) + .map(model -> model.createHandler(itemMeta)) + .orElse(null); + } + this.customData.putAll(customData); } - public ItemBuilder(@Nullable ItemStack item) { - this( - item == null ? Material.AIR : item.getType(), - item == null ? 1 : item.getAmount(), - new HashMap<>(), - item == null ? null : item.getItemMeta() - ); + /** + * @deprecated use {@link #fromItemStack(ItemStack)} instead + */ + @Deprecated(forRemoval = true) + public ItemBuilder(@NotNull ItemStack item) { + type = item.getType(); + amount = item.getAmount(); + itemMeta = item.getItemMeta(); + if (itemMeta != null) { + metaHandler = ItemMetaHandlerModel.getApplicableModelOptional(type) + .map(model -> model.createHandler(itemMeta)) + .orElse(null); + } } - public ItemBuilder() { - this( - Material.AIR, - 1, - new HashMap<>(), - null - ); + public ItemBuilder(@NotNull ItemStack item, @NotNull Map customData) { + type = item.getType(); + amount = item.getAmount(); + itemMeta = item.getItemMeta(); + if (itemMeta != null) { + metaHandler = ItemMetaHandlerModel.getApplicableModelOptional(type) + .map(model -> model.createHandler(itemMeta)) + .orElse(null); + } + this.customData.putAll(customData); } @SuppressWarnings("unchecked") @@ -145,7 +163,7 @@ public ItemBuilder type(@NonNull Material material) { itemMeta = itemMeta == null ? itemFactory.getItemMeta(type) : itemFactory.asMetaFor(itemMeta, type); ItemMetaHandlerModel model = ItemMetaHandlerModel.getApplicableModel(type); - metaHandler = model == null ? null : model.createHandler(this); + metaHandler = model == null || itemMeta == null ? null : model.createHandler(itemMeta); return this; } @@ -495,7 +513,7 @@ public ItemBuilder clone() { return new ItemBuilder( type, amount, - new HashMap<>(customData), + customData, itemMeta == null ? null : itemMeta.clone() ); } @@ -521,7 +539,13 @@ public ItemBuilder clone() { * @return a new builder with the data from the given item */ public static ItemBuilder fromItemStack(@Nullable ItemStack item) { - return new ItemBuilder(item, new HashMap<>()); + if (item == null) + return empty(); + return new ItemBuilder(item.getType(), item.getAmount(), Map.of(), item.getItemMeta()); + } + + public static @NotNull ItemBuilder empty() { + return new ItemBuilder(); } public static ItemBuilder deserialize(Map map) { @@ -559,7 +583,7 @@ public static ItemBuilder deserialize(Map map) { .ifPresent(result::itemCustomData); ItemMetaHandlerModel metaHandlerModel = ItemMetaHandlerModel.getApplicableModel(result.type()); - result.metaHandler(metaHandlerModel == null ? null : metaHandlerModel.createHandler(result)); + result.metaHandler(metaHandlerModel == null || result.itemMeta == null ? null : metaHandlerModel.createHandler(result.itemMeta)); if (result.metaHandler != null) result.metaHandler.deserialize(map); From 6fe3840a30efe6b56ffa8981b8c0d6ade221d03a Mon Sep 17 00:00:00 2001 From: WizardlyBump17 Date: Sat, 28 Feb 2026 18:33:22 -0300 Subject: [PATCH 358/363] using an Object for the key instead --- .../wlib/inventory/paginated/PaginatedInventoryBuilder.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/core/src/main/java/com/wizardlybump17/wlib/inventory/paginated/PaginatedInventoryBuilder.java b/core/src/main/java/com/wizardlybump17/wlib/inventory/paginated/PaginatedInventoryBuilder.java index 709a9c7d..1a98f359 100644 --- a/core/src/main/java/com/wizardlybump17/wlib/inventory/paginated/PaginatedInventoryBuilder.java +++ b/core/src/main/java/com/wizardlybump17/wlib/inventory/paginated/PaginatedInventoryBuilder.java @@ -105,7 +105,7 @@ public PaginatedInventoryBuilder shapeReplacements(@NonNull Map Date: Sat, 28 Feb 2026 18:38:33 -0300 Subject: [PATCH 359/363] added methods to replace the ItemStack of an ItemButton --- .../paginated/PaginatedInventoryBuilder.java | 32 +++++++++++++++++++ 1 file changed, 32 insertions(+) diff --git a/core/src/main/java/com/wizardlybump17/wlib/inventory/paginated/PaginatedInventoryBuilder.java b/core/src/main/java/com/wizardlybump17/wlib/inventory/paginated/PaginatedInventoryBuilder.java index 1a98f359..f364db25 100644 --- a/core/src/main/java/com/wizardlybump17/wlib/inventory/paginated/PaginatedInventoryBuilder.java +++ b/core/src/main/java/com/wizardlybump17/wlib/inventory/paginated/PaginatedInventoryBuilder.java @@ -6,6 +6,7 @@ import com.wizardlybump17.wlib.inventory.item.InventoryNavigator; import com.wizardlybump17.wlib.inventory.item.ItemButton; import com.wizardlybump17.wlib.inventory.listener.InventoryListener; +import com.wizardlybump17.wlib.item.ItemBuilder; import com.wizardlybump17.wlib.util.MapUtils; import com.wizardlybump17.wlib.util.ObjectUtil; import lombok.AccessLevel; @@ -113,6 +114,37 @@ public PaginatedInventoryBuilder shapeReplacements(@NonNull Map itemSupplier) { + for (ItemButton button : shapeReplacements.values()) + if (Objects.equals(button.getCustomData().get(key), value)) + button.setItem(itemSupplier); + return this; + } + + public @NotNull PaginatedInventoryBuilder setReplacementItemStackByCustomData(@NotNull Object key, @Nullable Object value, @NotNull ItemStack item) { + Supplier itemSupplier = () -> item; + for (ItemButton button : shapeReplacements.values()) + if (Objects.equals(button.getCustomData().get(key), value)) + button.setItem(itemSupplier); + return this; + } + + public @NotNull PaginatedInventoryBuilder setReplacementItemByCustomData(@NotNull Object key, @Nullable Object value, @NotNull Supplier itemSupplier) { + Supplier itemStackSupplier = () -> itemSupplier.get().build(); + for (ItemButton button : shapeReplacements.values()) + if (Objects.equals(button.getCustomData().get(key), value)) + button.setItem(itemStackSupplier); + return this; + } + + public @NotNull PaginatedInventoryBuilder setReplacementItemByCustomData(@NotNull Object key, @Nullable Object value, @NotNull ItemBuilder item) { + Supplier itemSupplier = item::build; + for (ItemButton button : shapeReplacements.values()) + if (Objects.equals(button.getCustomData().get(key), value)) + button.setItem(itemSupplier); + return this; + } + public PaginatedInventoryBuilder content(@Nullable List content) { this.content = content == null ? new ArrayList<>() : content; checkNullContent(); From a725985331cd8c02e428aebbbc2679ef7a9eed49 Mon Sep 17 00:00:00 2001 From: WizardlyBump17 Date: Sat, 28 Feb 2026 18:56:27 -0300 Subject: [PATCH 360/363] replacing items based on the original ones --- .../paginated/PaginatedInventoryBuilder.java | 21 +++++++++++++++++++ 1 file changed, 21 insertions(+) diff --git a/core/src/main/java/com/wizardlybump17/wlib/inventory/paginated/PaginatedInventoryBuilder.java b/core/src/main/java/com/wizardlybump17/wlib/inventory/paginated/PaginatedInventoryBuilder.java index f364db25..9407485f 100644 --- a/core/src/main/java/com/wizardlybump17/wlib/inventory/paginated/PaginatedInventoryBuilder.java +++ b/core/src/main/java/com/wizardlybump17/wlib/inventory/paginated/PaginatedInventoryBuilder.java @@ -23,6 +23,7 @@ import org.jetbrains.annotations.Nullable; import java.util.*; +import java.util.function.Function; import java.util.function.Supplier; import java.util.function.UnaryOperator; @@ -114,6 +115,8 @@ public PaginatedInventoryBuilder shapeReplacements(@NonNull Map itemSupplier) { for (ItemButton button : shapeReplacements.values()) if (Objects.equals(button.getCustomData().get(key), value)) @@ -129,6 +132,15 @@ public PaginatedInventoryBuilder shapeReplacements(@NonNull Map replacer) { + for (ItemButton button : shapeReplacements.values()) + if (Objects.equals(button.getCustomData().get(key), value)) + button.setItem(() -> replacer.apply(button.getItem().get())); + return this; + } + + //ItemBuilder + public @NotNull PaginatedInventoryBuilder setReplacementItemByCustomData(@NotNull Object key, @Nullable Object value, @NotNull Supplier itemSupplier) { Supplier itemStackSupplier = () -> itemSupplier.get().build(); for (ItemButton button : shapeReplacements.values()) @@ -145,6 +157,15 @@ public PaginatedInventoryBuilder shapeReplacements(@NonNull Map replacer) { + for (ItemButton button : shapeReplacements.values()) + if (Objects.equals(button.getCustomData().get(key), value)) + button.setItem(() -> replacer.apply(ItemBuilder.fromItemStack(button.getItem().get())).build()); + return this; + } + + //rest of the code + public PaginatedInventoryBuilder content(@Nullable List content) { this.content = content == null ? new ArrayList<>() : content; checkNullContent(); From f6ff05ddf57dc1e28364334a63efdd0e267b8d86 Mon Sep 17 00:00:00 2001 From: WizardlyBump17 Date: Sat, 28 Feb 2026 22:47:40 -0300 Subject: [PATCH 361/363] fixed a stack overflow --- .../paginated/PaginatedInventoryBuilder.java | 18 ++++++++++++------ 1 file changed, 12 insertions(+), 6 deletions(-) diff --git a/core/src/main/java/com/wizardlybump17/wlib/inventory/paginated/PaginatedInventoryBuilder.java b/core/src/main/java/com/wizardlybump17/wlib/inventory/paginated/PaginatedInventoryBuilder.java index 9407485f..dbea234c 100644 --- a/core/src/main/java/com/wizardlybump17/wlib/inventory/paginated/PaginatedInventoryBuilder.java +++ b/core/src/main/java/com/wizardlybump17/wlib/inventory/paginated/PaginatedInventoryBuilder.java @@ -133,9 +133,12 @@ public PaginatedInventoryBuilder shapeReplacements(@NonNull Map replacer) { - for (ItemButton button : shapeReplacements.values()) - if (Objects.equals(button.getCustomData().get(key), value)) - button.setItem(() -> replacer.apply(button.getItem().get())); + for (ItemButton button : shapeReplacements.values()) { + ItemStack originalItem = button.getItem().get(); + if (Objects.equals(button.getCustomData().get(key), value)) { + button.setItem(() -> replacer.apply(originalItem)); + } + } return this; } @@ -158,9 +161,12 @@ public PaginatedInventoryBuilder shapeReplacements(@NonNull Map replacer) { - for (ItemButton button : shapeReplacements.values()) - if (Objects.equals(button.getCustomData().get(key), value)) - button.setItem(() -> replacer.apply(ItemBuilder.fromItemStack(button.getItem().get())).build()); + for (ItemButton button : shapeReplacements.values()) { + ItemStack originalItem = button.getItem().get(); + if (Objects.equals(button.getCustomData().get(key), value)) { + button.setItem(() -> replacer.apply(ItemBuilder.fromItemStack(originalItem)).build()); + } + } return this; } From 027476f98bdaaad05b2c3f20c44dff385394ce55 Mon Sep 17 00:00:00 2001 From: WizardlyBump17 Date: Sat, 28 Feb 2026 22:47:40 -0300 Subject: [PATCH 362/363] fixed a stack overflow --- .../paginated/PaginatedInventoryBuilder.java | 18 ++++++++++++------ 1 file changed, 12 insertions(+), 6 deletions(-) diff --git a/core/src/main/java/com/wizardlybump17/wlib/inventory/paginated/PaginatedInventoryBuilder.java b/core/src/main/java/com/wizardlybump17/wlib/inventory/paginated/PaginatedInventoryBuilder.java index 9407485f..dbea234c 100644 --- a/core/src/main/java/com/wizardlybump17/wlib/inventory/paginated/PaginatedInventoryBuilder.java +++ b/core/src/main/java/com/wizardlybump17/wlib/inventory/paginated/PaginatedInventoryBuilder.java @@ -133,9 +133,12 @@ public PaginatedInventoryBuilder shapeReplacements(@NonNull Map replacer) { - for (ItemButton button : shapeReplacements.values()) - if (Objects.equals(button.getCustomData().get(key), value)) - button.setItem(() -> replacer.apply(button.getItem().get())); + for (ItemButton button : shapeReplacements.values()) { + ItemStack originalItem = button.getItem().get(); + if (Objects.equals(button.getCustomData().get(key), value)) { + button.setItem(() -> replacer.apply(originalItem)); + } + } return this; } @@ -158,9 +161,12 @@ public PaginatedInventoryBuilder shapeReplacements(@NonNull Map replacer) { - for (ItemButton button : shapeReplacements.values()) - if (Objects.equals(button.getCustomData().get(key), value)) - button.setItem(() -> replacer.apply(ItemBuilder.fromItemStack(button.getItem().get())).build()); + for (ItemButton button : shapeReplacements.values()) { + ItemStack originalItem = button.getItem().get(); + if (Objects.equals(button.getCustomData().get(key), value)) { + button.setItem(() -> replacer.apply(ItemBuilder.fromItemStack(originalItem)).build()); + } + } return this; } From 56c9c65a2e8329c0b4e656cc875a88fd21ec86dc Mon Sep 17 00:00:00 2001 From: WizardlyBump17 Date: Sat, 28 Feb 2026 22:56:37 -0300 Subject: [PATCH 363/363] replacing items based on ItemButtons --- .../paginated/PaginatedInventoryBuilder.java | 30 +++++++++++++++++++ 1 file changed, 30 insertions(+) diff --git a/core/src/main/java/com/wizardlybump17/wlib/inventory/paginated/PaginatedInventoryBuilder.java b/core/src/main/java/com/wizardlybump17/wlib/inventory/paginated/PaginatedInventoryBuilder.java index dbea234c..e199dfe0 100644 --- a/core/src/main/java/com/wizardlybump17/wlib/inventory/paginated/PaginatedInventoryBuilder.java +++ b/core/src/main/java/com/wizardlybump17/wlib/inventory/paginated/PaginatedInventoryBuilder.java @@ -170,6 +170,36 @@ public PaginatedInventoryBuilder shapeReplacements(@NonNull Map itemSupplier) { + ItemButton newButton = itemSupplier.get(); + for (Map.Entry entry : shapeReplacements.entrySet()) { + ItemButton button = entry.getValue(); + if (Objects.equals(button.getCustomData().get(key), value)) + entry.setValue(newButton); + } + return this; + } + + public @NotNull PaginatedInventoryBuilder setReplacementItemButtonByCustomData(@NotNull Object key, @Nullable Object value, @NotNull ItemButton item) { + for (Map.Entry entry : shapeReplacements.entrySet()) { + ItemButton button = entry.getValue(); + if (Objects.equals(button.getCustomData().get(key), value)) + entry.setValue(item); + } + return this; + } + + public @NotNull PaginatedInventoryBuilder setReplacementItemButtonByCustomData(@NotNull Object key, @Nullable Object value, @NotNull Function replacer) { + for (Map.Entry entry : shapeReplacements.entrySet()) { + ItemButton button = entry.getValue(); + if (Objects.equals(button.getCustomData().get(key), value)) + entry.setValue(replacer.apply(button)); + } + return this; + } + //rest of the code public PaginatedInventoryBuilder content(@Nullable List content) {