aboutsummaryrefslogtreecommitdiff
path: root/juick-commands/src/main/java/com/juick/command/Processor.java
diff options
context:
space:
mode:
authorGravatar Anatoliy Sablin2017-11-05 10:33:34 +0300
committerGravatar Anatoliy Sablin2017-11-06 15:00:22 +0300
commitce0ed9ac9e82b19763b7dfd4814d327e0b49ddb7 (patch)
tree4e63b5a35e162956b548d9415fa8f2c6d38b8e3b /juick-commands/src/main/java/com/juick/command/Processor.java
parent83815d291a7945c26a675c8543e8766ad2d1beda (diff)
juick-commands
Diffstat (limited to 'juick-commands/src/main/java/com/juick/command/Processor.java')
-rw-r--r--juick-commands/src/main/java/com/juick/command/Processor.java48
1 files changed, 48 insertions, 0 deletions
diff --git a/juick-commands/src/main/java/com/juick/command/Processor.java b/juick-commands/src/main/java/com/juick/command/Processor.java
new file mode 100644
index 00000000..bf38a1b3
--- /dev/null
+++ b/juick-commands/src/main/java/com/juick/command/Processor.java
@@ -0,0 +1,48 @@
+package com.juick.command;
+
+import com.juick.User;
+import com.juick.server.protocol.ProtocolListener;
+import lombok.Getter;
+import lombok.Setter;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.stereotype.Component;
+
+import java.util.Set;
+
+/**
+ * @author ma1uta
+ */
+@Component
+@Getter
+public class Processor {
+
+ private static final Logger LOGGER = LoggerFactory.getLogger(Processor.class);
+
+ private final Set<Command> commands;
+ @Setter
+ private ProtocolListener protocolListener;
+
+ @Autowired
+ public Processor(Set<Command> commands) {
+ this.commands = commands;
+ }
+
+ public String execute(User sender, String command) {
+ if (LOGGER.isDebugEnabled()) {
+ LOGGER.debug("Execute command: {}", command);
+ }
+ for (Command commandItem : getCommands()) {
+ if (commandItem.pattern().matcher(command).matches()) {
+ if (LOGGER.isDebugEnabled()) {
+ LOGGER.debug("Found command processor: {}", commandItem.getClass().getName());
+ }
+ return commandItem.execute(sender, command);
+ }
+ }
+
+ LOGGER.debug("Command processor not found, return help");
+ return "";
+ }
+}