[fix] implement Command Interface for Example command
This commit is contained in:
parent
7cb1ed6f75
commit
59420948d3
3 changed files with 20 additions and 2 deletions
|
@ -57,7 +57,7 @@ public class CommandHandler implements HandlerInterface {
|
||||||
LOGGER.debug("Valid Prefix received");
|
LOGGER.debug("Valid Prefix received");
|
||||||
|
|
||||||
for (Command command : commands){
|
for (Command command : commands){
|
||||||
if (command.acceptInput()) { // Try execute command
|
if (command.acceptInput(args[0])) { // Try execute command
|
||||||
command.run(commandSource, args);
|
command.run(commandSource, args);
|
||||||
LOGGER.debug("Executed following command: " + message);
|
LOGGER.debug("Executed following command: " + message);
|
||||||
return command.intercept(); // if executed return interception flag
|
return command.intercept(); // if executed return interception flag
|
||||||
|
|
|
@ -12,7 +12,7 @@ public interface Command {
|
||||||
|
|
||||||
Set<String> getAlias();
|
Set<String> getAlias();
|
||||||
|
|
||||||
boolean acceptInput();
|
boolean acceptInput(String command);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* should message get intercepted and not send to Server?
|
* should message get intercepted and not send to Server?
|
||||||
|
|
|
@ -6,10 +6,13 @@ import org.apache.logging.log4j.LogManager;
|
||||||
import org.apache.logging.log4j.Logger;
|
import org.apache.logging.log4j.Logger;
|
||||||
|
|
||||||
import java.util.Arrays;
|
import java.util.Arrays;
|
||||||
|
import java.util.HashSet;
|
||||||
|
import java.util.Set;
|
||||||
|
|
||||||
public class EaaCommand implements Command {
|
public class EaaCommand implements Command {
|
||||||
|
|
||||||
private static final String COMMAND = "echo";
|
private static final String COMMAND = "echo";
|
||||||
|
private static final Set<String> ALIAS = new HashSet<>(Arrays.asList("e"));
|
||||||
private static final boolean INTERCEPT = true;
|
private static final boolean INTERCEPT = true;
|
||||||
private static final Logger LOGGER = LogManager.getLogger();
|
private static final Logger LOGGER = LogManager.getLogger();
|
||||||
|
|
||||||
|
@ -35,6 +38,21 @@ public class EaaCommand implements Command {
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public String getCommand() {
|
||||||
|
return COMMAND;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public Set<String> getAlias() {
|
||||||
|
return ALIAS;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean acceptInput(String command) {
|
||||||
|
return (command.equalsIgnoreCase(getCommand()) || getAlias().contains(command.toLowerCase()));
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean intercept() {
|
public boolean intercept() {
|
||||||
return INTERCEPT;
|
return INTERCEPT;
|
||||||
|
|
Loading…
Reference in a new issue