From 2721ddfdd3c4639163b1188dc032281f6a435604 Mon Sep 17 00:00:00 2001 From: Zffu <103074097+Radi0o@users.noreply.github.com> Date: Sat, 20 Jul 2024 19:27:52 +0200 Subject: [PATCH 1/4] Swaped from array to Collection to allow for lists --- .../zffu/hardened/api/commands/types/TypeGatedCommand.java | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/api/src/main/java/net/zffu/hardened/api/commands/types/TypeGatedCommand.java b/api/src/main/java/net/zffu/hardened/api/commands/types/TypeGatedCommand.java index c21c851..6ffb722 100644 --- a/api/src/main/java/net/zffu/hardened/api/commands/types/TypeGatedCommand.java +++ b/api/src/main/java/net/zffu/hardened/api/commands/types/TypeGatedCommand.java @@ -2,6 +2,8 @@ import net.zffu.hardened.api.invoker.InvokerType; +import java.util.Collection; + /** * A {@link net.zffu.hardened.api.commands.Command} that can onlu run with specific {@link net.zffu.hardened.api.invoker.InvokerType}. * @since 1.0.0 @@ -12,6 +14,6 @@ public interface TypeGatedCommand { * Gets the list of the {@link InvokerType} that are allowed to run the command. * @return {@link InvokerType}. */ - InvokerType[] getAllowedInvokers(); + Collection getAllowedInvokers(); } From 6f5b1abc2232f352f9b1614493b0b8583bf26bc6 Mon Sep 17 00:00:00 2001 From: Zffu <103074097+Radi0o@users.noreply.github.com> Date: Sat, 20 Jul 2024 19:29:30 +0200 Subject: [PATCH 2/4] Swapped to list --- .../zffu/hardened/examples/api/CustomCommandExample.java | 7 +++++-- .../zffu/hardened/examples/api/CustomCommandValidator.java | 2 +- .../zffu/hardened/api/commands/types/TypeGatedCommand.java | 4 ++-- 3 files changed, 8 insertions(+), 5 deletions(-) diff --git a/api-examples/src/main/java/net/zffu/hardened/examples/api/CustomCommandExample.java b/api-examples/src/main/java/net/zffu/hardened/examples/api/CustomCommandExample.java index 955648d..e085997 100644 --- a/api-examples/src/main/java/net/zffu/hardened/examples/api/CustomCommandExample.java +++ b/api-examples/src/main/java/net/zffu/hardened/examples/api/CustomCommandExample.java @@ -6,6 +6,9 @@ import net.zffu.hardened.api.context.CommandContext; import net.zffu.hardened.api.invoker.InvokerType; +import java.util.Arrays; +import java.util.List; + /** * An example on how to create your own {@link net.zffu.hardened.api.commands.Command} implementation with the custom features you want. */ @@ -14,7 +17,7 @@ public class CustomCommandExample implements Command, TypeGatedCommand { private String[] names = new String[]{"test"}; - private InvokerType[] allowedInvokers = new InvokerType[] {InvokerType.PLAYER}; // Only allows players to use our command, this will not matter at all if the custom validator doesn't include a check for it + private List allowedInvokers = Arrays.asList(new InvokerType[]{InvokerType.PLAYER}); // Only allows players to use our command, this will not matter at all if the custom validator doesn't include a check for it @Override public String[] getNames() { @@ -32,7 +35,7 @@ public void execute(CommandContext commandContext) { } @Override - public InvokerType[] getAllowedInvokers() { + public List getAllowedInvokers() { return this.allowedInvokers; } } diff --git a/api-examples/src/main/java/net/zffu/hardened/examples/api/CustomCommandValidator.java b/api-examples/src/main/java/net/zffu/hardened/examples/api/CustomCommandValidator.java index d2f4e40..d8e5edc 100644 --- a/api-examples/src/main/java/net/zffu/hardened/examples/api/CustomCommandValidator.java +++ b/api-examples/src/main/java/net/zffu/hardened/examples/api/CustomCommandValidator.java @@ -15,7 +15,7 @@ public class CustomCommandValidator implements CommandValidator getAllowedInvokers(); + List getAllowedInvokers(); } From 80713c6f53f24b053a3ca53096490819b82be3ca Mon Sep 17 00:00:00 2001 From: Zffu <103074097+Radi0o@users.noreply.github.com> Date: Sat, 20 Jul 2024 19:31:24 +0200 Subject: [PATCH 3/4] Fixed command builder --- .../zffu/hardened/api/commands/builder/BuilderCommand.java | 7 +++++-- .../zffu/hardened/api/commands/builder/CommandBuilder.java | 4 +++- 2 files changed, 8 insertions(+), 3 deletions(-) diff --git a/api/src/main/java/net/zffu/hardened/api/commands/builder/BuilderCommand.java b/api/src/main/java/net/zffu/hardened/api/commands/builder/BuilderCommand.java index 43c8902..de949ac 100644 --- a/api/src/main/java/net/zffu/hardened/api/commands/builder/BuilderCommand.java +++ b/api/src/main/java/net/zffu/hardened/api/commands/builder/BuilderCommand.java @@ -8,6 +8,9 @@ import net.zffu.hardened.api.commands.types.TypeGatedCommand; import net.zffu.hardened.api.invoker.InvokerType; +import java.util.ArrayList; +import java.util.List; + /** *

Variant of the {@link net.zffu.hardened.api.commands.Command} interface.

*

This variant isn't the default one as it implements every single feature that commands can have in the Hardened for the builder.

@@ -21,7 +24,7 @@ public abstract class BuilderCommand implements Command protected String primaryName; - protected InvokerType[] allowedTypes; + protected List allowedTypes; protected String[] aliases; @@ -47,7 +50,7 @@ public BuilderCommandValidator getValidator() { } @Override - public InvokerType[] getAllowedInvokers() { + public List getAllowedInvokers() { return this.allowedTypes; } diff --git a/api/src/main/java/net/zffu/hardened/api/commands/builder/CommandBuilder.java b/api/src/main/java/net/zffu/hardened/api/commands/builder/CommandBuilder.java index 1d2e17b..b0e1b6b 100644 --- a/api/src/main/java/net/zffu/hardened/api/commands/builder/CommandBuilder.java +++ b/api/src/main/java/net/zffu/hardened/api/commands/builder/CommandBuilder.java @@ -5,6 +5,8 @@ import net.zffu.hardened.api.context.CommandContext; import net.zffu.hardened.api.invoker.InvokerType; +import java.util.ArrayList; +import java.util.Arrays; import java.util.function.Consumer; import java.util.function.Function; import java.util.function.Supplier; @@ -44,7 +46,7 @@ public CommandBuilder(String primaryName, String... aliases) { * @return */ public CommandBuilder allowed(InvokerType... types) { - this.allowedTypes = types; + this.allowedTypes = Arrays.asList(types); return this; } From 52c52db9c1a2686497a6a97ba8289f4aed35fc6e Mon Sep 17 00:00:00 2001 From: Zffu <103074097+Radi0o@users.noreply.github.com> Date: Sat, 20 Jul 2024 19:32:11 +0200 Subject: [PATCH 4/4] Fixed example command having errors --- .../hardened/examples/api/CustomCommandExample.java | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/api-examples/src/main/java/net/zffu/hardened/examples/api/CustomCommandExample.java b/api-examples/src/main/java/net/zffu/hardened/examples/api/CustomCommandExample.java index e085997..8d44797 100644 --- a/api-examples/src/main/java/net/zffu/hardened/examples/api/CustomCommandExample.java +++ b/api-examples/src/main/java/net/zffu/hardened/examples/api/CustomCommandExample.java @@ -16,12 +16,16 @@ // In this example we create a invoker gated command. public class CustomCommandExample implements Command, TypeGatedCommand { - private String[] names = new String[]{"test"}; private List allowedInvokers = Arrays.asList(new InvokerType[]{InvokerType.PLAYER}); // Only allows players to use our command, this will not matter at all if the custom validator doesn't include a check for it @Override - public String[] getNames() { - return this.names; + public String getPrimaryName() { + return "test"; + } + + @Override + public String[] getAliases() { + return new String[0]; } @Override