From 59420948d352c2f7b34fb5e2a6193c93ff5df659 Mon Sep 17 00:00:00 2001 From: "Ansgar [Hiajen]" Date: Sun, 23 May 2021 14:55:44 +0200 Subject: [PATCH] [fix] implement Command Interface for Example command --- .../saltymc/eaa/handler/CommandHandler.java | 2 +- .../saltymc/eaa/handler/commands/Command.java | 2 +- .../eaa/handler/commands/EaaCommand.java | 18 ++++++++++++++++++ 3 files changed, 20 insertions(+), 2 deletions(-) diff --git a/src/main/java/net/saltymc/eaa/handler/CommandHandler.java b/src/main/java/net/saltymc/eaa/handler/CommandHandler.java index de41017..30a2e3d 100644 --- a/src/main/java/net/saltymc/eaa/handler/CommandHandler.java +++ b/src/main/java/net/saltymc/eaa/handler/CommandHandler.java @@ -57,7 +57,7 @@ public class CommandHandler implements HandlerInterface { LOGGER.debug("Valid Prefix received"); for (Command command : commands){ - if (command.acceptInput()) { // Try execute command + if (command.acceptInput(args[0])) { // Try execute command command.run(commandSource, args); LOGGER.debug("Executed following command: " + message); return command.intercept(); // if executed return interception flag diff --git a/src/main/java/net/saltymc/eaa/handler/commands/Command.java b/src/main/java/net/saltymc/eaa/handler/commands/Command.java index f4aa26d..30c324b 100644 --- a/src/main/java/net/saltymc/eaa/handler/commands/Command.java +++ b/src/main/java/net/saltymc/eaa/handler/commands/Command.java @@ -12,7 +12,7 @@ public interface Command { Set getAlias(); - boolean acceptInput(); + boolean acceptInput(String command); /** * should message get intercepted and not send to Server? diff --git a/src/main/java/net/saltymc/eaa/handler/commands/EaaCommand.java b/src/main/java/net/saltymc/eaa/handler/commands/EaaCommand.java index 54b7db7..f903755 100644 --- a/src/main/java/net/saltymc/eaa/handler/commands/EaaCommand.java +++ b/src/main/java/net/saltymc/eaa/handler/commands/EaaCommand.java @@ -6,10 +6,13 @@ import org.apache.logging.log4j.LogManager; import org.apache.logging.log4j.Logger; import java.util.Arrays; +import java.util.HashSet; +import java.util.Set; public class EaaCommand implements Command { private static final String COMMAND = "echo"; + private static final Set ALIAS = new HashSet<>(Arrays.asList("e")); private static final boolean INTERCEPT = true; private static final Logger LOGGER = LogManager.getLogger(); @@ -35,6 +38,21 @@ public class EaaCommand implements Command { return true; } + @Override + public String getCommand() { + return COMMAND; + } + + @Override + public Set getAlias() { + return ALIAS; + } + + @Override + public boolean acceptInput(String command) { + return (command.equalsIgnoreCase(getCommand()) || getAlias().contains(command.toLowerCase())); + } + @Override public boolean intercept() { return INTERCEPT;