From 7867f8a2ee6bba6b296e865949f5f2c1f17b0952 Mon Sep 17 00:00:00 2001 From: Zffu <103074097+Radi0o@users.noreply.github.com> Date: Sat, 10 Aug 2024 01:04:03 +0200 Subject: [PATCH 01/11] Added sender directly into Invoker --- .../net/zffu/hardened/api/invoker/CommandInvoker.java | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/api/src/main/java/net/zffu/hardened/api/invoker/CommandInvoker.java b/api/src/main/java/net/zffu/hardened/api/invoker/CommandInvoker.java index 435858f..5fab51a 100644 --- a/api/src/main/java/net/zffu/hardened/api/invoker/CommandInvoker.java +++ b/api/src/main/java/net/zffu/hardened/api/invoker/CommandInvoker.java @@ -8,7 +8,7 @@ *
The {@link CommandInvoker} will be provided by the {@link CommandContext} when a command gets executed.
* @since 1.0.0 */ -public interface CommandInvoker { +public interface CommandInvokerGets the type of the {@link CommandInvoker}
@@ -23,4 +23,10 @@ public interface CommandInvoker { */ boolean hasPermission(@NotNull String permission); + /** + *Gets the "command sender" version of the invoker.
+ * @return the "command sender" as S. + */ + S getSender(); + } From 127537e545e460f69fd9c0c2fcc209f349d21640 Mon Sep 17 00:00:00 2001 From: Zffu <103074097+Radi0o@users.noreply.github.com> Date: Sat, 10 Aug 2024 01:05:53 +0200 Subject: [PATCH 02/11] Added sendMessage function --- .../java/net/zffu/hardened/api/invoker/CommandInvoker.java | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/api/src/main/java/net/zffu/hardened/api/invoker/CommandInvoker.java b/api/src/main/java/net/zffu/hardened/api/invoker/CommandInvoker.java index 5fab51a..cf9aefd 100644 --- a/api/src/main/java/net/zffu/hardened/api/invoker/CommandInvoker.java +++ b/api/src/main/java/net/zffu/hardened/api/invoker/CommandInvoker.java @@ -29,4 +29,10 @@ public interface CommandInvokerSends a message to the invoker.
+ * @param message the message as a {@link String} + */ + void sendMessage(String message); + } From 1454a8dd248a91a11ece14ae3c0ed5cc6a3458a4 Mon Sep 17 00:00:00 2001 From: Zffu <103074097+Radi0o@users.noreply.github.com> Date: Sat, 10 Aug 2024 01:12:59 +0200 Subject: [PATCH 03/11] Added InvokerFactory --- .../hardened/api/invoker/InvokerFactory.java | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) create mode 100644 api/src/main/java/net/zffu/hardened/api/invoker/InvokerFactory.java diff --git a/api/src/main/java/net/zffu/hardened/api/invoker/InvokerFactory.java b/api/src/main/java/net/zffu/hardened/api/invoker/InvokerFactory.java new file mode 100644 index 0000000..1a626ee --- /dev/null +++ b/api/src/main/java/net/zffu/hardened/api/invoker/InvokerFactory.java @@ -0,0 +1,18 @@ +package net.zffu.hardened.api.invoker; + +/** + *A factory to create command invokers.
+ * @paramCreates an {@link CommandInvoker} of type S for the provided sender with the provided type.
+ * @param sender the sender. + * @param type the type. + * @return the {@link CommandInvoker} as S. + */ + S createInvoker(T sender, InvokerType type); + +} From da3a18371d5a613b650df101c7c76bf50e2bb964 Mon Sep 17 00:00:00 2001 From: Zffu <103074097+Radi0o@users.noreply.github.com> Date: Sat, 10 Aug 2024 01:16:07 +0200 Subject: [PATCH 04/11] Deleted old invokers --- .../shared/invokers/ConsoleInvoker.java | 31 ----------------- .../shared/invokers/OtherInvoker.java | 34 ------------------- .../shared/invokers/PlayerInvoker.java | 30 ---------------- 3 files changed, 95 deletions(-) delete mode 100644 shared/src/main/java/net/zffu/hardened/shared/invokers/ConsoleInvoker.java delete mode 100644 shared/src/main/java/net/zffu/hardened/shared/invokers/OtherInvoker.java delete mode 100644 shared/src/main/java/net/zffu/hardened/shared/invokers/PlayerInvoker.java diff --git a/shared/src/main/java/net/zffu/hardened/shared/invokers/ConsoleInvoker.java b/shared/src/main/java/net/zffu/hardened/shared/invokers/ConsoleInvoker.java deleted file mode 100644 index 8b00153..0000000 --- a/shared/src/main/java/net/zffu/hardened/shared/invokers/ConsoleInvoker.java +++ /dev/null @@ -1,31 +0,0 @@ -package net.zffu.hardened.shared.invokers; - -import net.zffu.hardened.api.invoker.CommandInvoker; -import net.zffu.hardened.api.invoker.InvokerType; -import org.bukkit.command.CommandSender; - -/** - * A {@link CommandInvoker} that is also a {@link org.bukkit.command.ConsoleCommandSender}. - * @since 1.0.0 - */ -public class ConsoleInvoker implements CommandInvoker { - - private CommandSender sender; - - public ConsoleInvoker(CommandSender sender) { - this.sender = sender; - } - - public InvokerType getType() { - return InvokerType.CONSOLE; - } - - public boolean hasPermission(String permission) { - return this.sender.hasPermission(permission); - } - - public CommandSender getSender() { - return this.sender; - } - -} diff --git a/shared/src/main/java/net/zffu/hardened/shared/invokers/OtherInvoker.java b/shared/src/main/java/net/zffu/hardened/shared/invokers/OtherInvoker.java deleted file mode 100644 index dc68aa6..0000000 --- a/shared/src/main/java/net/zffu/hardened/shared/invokers/OtherInvoker.java +++ /dev/null @@ -1,34 +0,0 @@ -package net.zffu.hardened.shared.invokers; - -import net.zffu.hardened.api.invoker.CommandInvoker; -import net.zffu.hardened.api.invoker.InvokerType; -import org.bukkit.command.CommandSender; - -/** - * An {@link CommandInvoker} on which the type couldn't be determined. - */ -public class OtherInvoker implements CommandInvoker { - - private CommandSender sender; - - /** - * Constructs an new {@link OtherInvoker}. - * @param sender - */ - public OtherInvoker(CommandSender sender) { - this.sender = sender; - } - - public InvokerType getType() { - return InvokerType.OTHER; - } - - public boolean hasPermission(String permission) { - return this.sender.hasPermission(permission); - } - - public CommandSender getCommandSender() { - return this.sender; - } - -} diff --git a/shared/src/main/java/net/zffu/hardened/shared/invokers/PlayerInvoker.java b/shared/src/main/java/net/zffu/hardened/shared/invokers/PlayerInvoker.java deleted file mode 100644 index 888224f..0000000 --- a/shared/src/main/java/net/zffu/hardened/shared/invokers/PlayerInvoker.java +++ /dev/null @@ -1,30 +0,0 @@ -package net.zffu.hardened.shared.invokers; - -import net.zffu.hardened.api.invoker.CommandInvoker; -import net.zffu.hardened.api.invoker.InvokerType; -import org.bukkit.entity.Player; - -/** - * An {@link CommandInvoker} that is a {@link org.bukkit.entity.Player}. - * @since 1.0.0 - */ -public class PlayerInvoker implements CommandInvoker { - - private Player player; - - public PlayerInvoker(Player player) { - this.player = player; - } - - public InvokerType getType() { - return InvokerType.PLAYER; - } - - public boolean hasPermission(String permission) { - return player.hasPermission(permission); - } - - public Player getPlayer() { - return this.player; - } -} From 6c07b852ee6a1ef9071d055b19f33d3dc85f7fae Mon Sep 17 00:00:00 2001 From: Zffu <103074097+Radi0o@users.noreply.github.com> Date: Sat, 10 Aug 2024 01:17:24 +0200 Subject: [PATCH 05/11] Added SharedInvokerFactory --- .../hardened/shared/SharedInvokerFactory.java | 41 +++++++++++++++++++ 1 file changed, 41 insertions(+) create mode 100644 shared/src/main/java/net/zffu/hardened/shared/SharedInvokerFactory.java diff --git a/shared/src/main/java/net/zffu/hardened/shared/SharedInvokerFactory.java b/shared/src/main/java/net/zffu/hardened/shared/SharedInvokerFactory.java new file mode 100644 index 0000000..34e1fb9 --- /dev/null +++ b/shared/src/main/java/net/zffu/hardened/shared/SharedInvokerFactory.java @@ -0,0 +1,41 @@ +package net.zffu.hardened.shared; + +import net.zffu.hardened.api.invoker.CommandInvoker; +import net.zffu.hardened.api.invoker.InvokerFactory; +import net.zffu.hardened.api.invoker.InvokerType; +import org.bukkit.command.CommandSender; +import org.jetbrains.annotations.NotNull; + +/** + *Invoker factory for Spigot, Paper
+ * @since 1.0.0 + */ +public class SharedInvokerFactory implements InvokerFactorySince spigot api is bad, aliases aren't supported by the reflection-less version.
From 342b75858b61356b2576c84ba80cfd3ae8585ad1 Mon Sep 17 00:00:00 2001 From: Zffu <103074097+Radi0o@users.noreply.github.com> Date: Sat, 10 Aug 2024 01:18:40 +0200 Subject: [PATCH 07/11] Added factory in registrar --- .../zffu/hardened/spigot/registrar/SpigotCommandRegistrar.java | 3 +++ 1 file changed, 3 insertions(+) diff --git a/spigot/src/main/java/net/zffu/hardened/spigot/registrar/SpigotCommandRegistrar.java b/spigot/src/main/java/net/zffu/hardened/spigot/registrar/SpigotCommandRegistrar.java index 2e232cf..297ac46 100644 --- a/spigot/src/main/java/net/zffu/hardened/spigot/registrar/SpigotCommandRegistrar.java +++ b/spigot/src/main/java/net/zffu/hardened/spigot/registrar/SpigotCommandRegistrar.java @@ -2,6 +2,7 @@ import net.zffu.hardened.api.commands.Command; import net.zffu.hardened.api.registrar.CommandRegistrar; +import net.zffu.hardened.shared.SharedInvokerFactory; import net.zffu.hardened.spigot.handler.SpigotCommandHandler; import org.bukkit.plugin.java.JavaPlugin; @@ -12,6 +13,7 @@ */ public class SpigotCommandRegistrar implements CommandRegistrar { + protected SharedInvokerFactory factory; protected JavaPlugin plugin; /** @@ -20,6 +22,7 @@ public class SpigotCommandRegistrar implements CommandRegistrar { */ public SpigotCommandRegistrar(JavaPlugin plugin) { this.plugin = plugin; + this.factory = new SharedInvokerFactory(); } public void register(Command> command) { From b1bbc75c03828276f28f26d309977a54e42ab612 Mon Sep 17 00:00:00 2001 From: Zffu <103074097+Radi0o@users.noreply.github.com> Date: Sat, 10 Aug 2024 01:20:53 +0200 Subject: [PATCH 08/11] Swapped to public final --- .../zffu/hardened/spigot/registrar/SpigotCommandRegistrar.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/spigot/src/main/java/net/zffu/hardened/spigot/registrar/SpigotCommandRegistrar.java b/spigot/src/main/java/net/zffu/hardened/spigot/registrar/SpigotCommandRegistrar.java index 297ac46..8b29e09 100644 --- a/spigot/src/main/java/net/zffu/hardened/spigot/registrar/SpigotCommandRegistrar.java +++ b/spigot/src/main/java/net/zffu/hardened/spigot/registrar/SpigotCommandRegistrar.java @@ -13,7 +13,7 @@ */ public class SpigotCommandRegistrar implements CommandRegistrar { - protected SharedInvokerFactory factory; + public final SharedInvokerFactory factory; protected JavaPlugin plugin; /** From 369e59f017dfcc05e2ce7ff6578f771c82b59089 Mon Sep 17 00:00:00 2001 From: Zffu <103074097+Radi0o@users.noreply.github.com> Date: Sat, 10 Aug 2024 01:21:52 +0200 Subject: [PATCH 09/11] Migrated spigot command handler --- .../spigot/handler/SpigotCommandHandler.java | 15 +++++++-------- 1 file changed, 7 insertions(+), 8 deletions(-) diff --git a/spigot/src/main/java/net/zffu/hardened/spigot/handler/SpigotCommandHandler.java b/spigot/src/main/java/net/zffu/hardened/spigot/handler/SpigotCommandHandler.java index 6f286fe..59acdfe 100644 --- a/spigot/src/main/java/net/zffu/hardened/spigot/handler/SpigotCommandHandler.java +++ b/spigot/src/main/java/net/zffu/hardened/spigot/handler/SpigotCommandHandler.java @@ -2,9 +2,8 @@ import net.zffu.hardened.api.context.CommandContext; import net.zffu.hardened.api.invoker.CommandInvoker; -import net.zffu.hardened.spigot.invokers.ConsoleInvoker; -import net.zffu.hardened.spigot.invokers.OtherInvoker; -import net.zffu.hardened.spigot.invokers.PlayerInvoker; +import net.zffu.hardened.api.invoker.InvokerType; +import net.zffu.hardened.spigot.registrar.SpigotCommandRegistrar; import org.bukkit.command.Command; import org.bukkit.command.CommandExecutor; import org.bukkit.command.CommandSender; @@ -17,10 +16,11 @@ */ public class SpigotCommandHandler implements CommandExecutor { + private SpigotCommandRegistrar registrar; private net.zffu.hardened.api.commands.Command> command; private boolean parseArgs; - public SpigotCommandHandler(net.zffu.hardened.api.commands.Command> command) { + public SpigotCommandHandler(net.zffu.hardened.api.commands.Command> command, SpigotCommandRegistrar registrar) { this.command = command; this.parseArgs = !this.command.getArguments().getArguments().isEmpty(); } @@ -36,10 +36,9 @@ public boolean onCommand(CommandSender sender, Command command, String label, St * @param sender the {@link CommandSender} * @return the {@link CommandInvoker} */ - public static CommandInvoker fromCommandSender(CommandSender sender) { - if(sender instanceof Player) return new PlayerInvoker((Player) sender); - if(sender instanceof ConsoleCommandSender) return new ConsoleInvoker(sender); - return new OtherInvoker(sender); + public CommandInvokerA factory to create command invokers.
* @param