From 16588ad747bac9ea2e9443e008957ac1e14687d5 Mon Sep 17 00:00:00 2001 From: R2D2Warrior Date: Fri, 7 Mar 2014 15:21:28 -0500 Subject: [PATCH] Change "alt" to "aliases" and added the option for multiple aliases --- src/com/chcmatt/katelyn/commands/Command.java | 2 +- src/com/chcmatt/katelyn/commands/Ping.java | 2 +- src/com/chcmatt/katelyn/handling/CommandInfo.java | 13 +++---------- .../chcmatt/katelyn/handling/CommandRegistry.java | 5 +++-- 4 files changed, 8 insertions(+), 14 deletions(-) diff --git a/src/com/chcmatt/katelyn/commands/Command.java b/src/com/chcmatt/katelyn/commands/Command.java index a837366..3eed8d4 100644 --- a/src/com/chcmatt/katelyn/commands/Command.java +++ b/src/com/chcmatt/katelyn/commands/Command.java @@ -10,7 +10,7 @@ public @interface Command { String name(); - String alt() default ""; + String[] alias() default {}; String desc() default ""; /** Required: {@code}, Optional: [arg]*/ String syntax() default ""; diff --git a/src/com/chcmatt/katelyn/commands/Ping.java b/src/com/chcmatt/katelyn/commands/Ping.java index 37dc0df..02684e7 100644 --- a/src/com/chcmatt/katelyn/commands/Ping.java +++ b/src/com/chcmatt/katelyn/commands/Ping.java @@ -5,7 +5,7 @@ import com.chcmatt.katelyn.handling.CommandEvent; //Added as example -@Command(name="ping", alt="p", desc="Sends a ping reply message back to you.") +@Command(name="ping", alias="p", desc="Sends a ping reply message back to you.") public class Ping extends GenericCommand { diff --git a/src/com/chcmatt/katelyn/handling/CommandInfo.java b/src/com/chcmatt/katelyn/handling/CommandInfo.java index c82b99c..9a0066b 100644 --- a/src/com/chcmatt/katelyn/handling/CommandInfo.java +++ b/src/com/chcmatt/katelyn/handling/CommandInfo.java @@ -1,7 +1,5 @@ package com.chcmatt.katelyn.handling; -import org.apache.commons.lang3.StringUtils; - import com.chcmatt.katelyn.commands.GenericCommand; import lombok.AccessLevel; @@ -11,7 +9,7 @@ public class CommandInfo { private String name; - private String alt; + private String[] aliases; private String desc; private String syntax; private boolean isAdminOnly; @@ -20,10 +18,10 @@ public class CommandInfo private Class commandClass; @SuppressWarnings("unchecked") - public CommandInfo(String name, String alt, String desc, String syntax, boolean adminOnly, boolean requiresArgs, Class commandClass) + public CommandInfo(String name, String[] aliases, String desc, String syntax, boolean adminOnly, boolean requiresArgs, Class commandClass) { this.name = name; - this.alt = alt; + this.aliases = aliases; this.desc = desc; this.syntax = syntax; this.isAdminOnly = adminOnly; @@ -35,9 +33,4 @@ public boolean requiresArgs() { return requiresArgs; } - - public boolean hasAlt() - { - return StringUtils.isNotBlank(alt); - } } diff --git a/src/com/chcmatt/katelyn/handling/CommandRegistry.java b/src/com/chcmatt/katelyn/handling/CommandRegistry.java index 73423e1..ee4f0b7 100644 --- a/src/com/chcmatt/katelyn/handling/CommandRegistry.java +++ b/src/com/chcmatt/katelyn/handling/CommandRegistry.java @@ -7,6 +7,7 @@ import lombok.Getter; +import org.apache.commons.lang3.ArrayUtils; import org.pircbotx.PircBotX; import org.reflections.Reflections; @@ -29,7 +30,7 @@ public CommandRegistry(PircBotX bot) for (Class cls : reflections.getTypesAnnotatedWith(Command.class)) { cmd = cls.getAnnotation(Command.class); - commands.add(new CommandInfo(cmd.name(), cmd.alt(), cmd.desc(), + commands.add(new CommandInfo(cmd.name(), cmd.alias(), cmd.desc(), cmd.syntax(), cmd.adminOnly(), cmd.requiresArgs(), cls)); } } @@ -72,7 +73,7 @@ public String executeCommand(CommandEvent event) public Class getCommandClass(String name) { for (CommandInfo info : commands) - if (info.getName().equals(name) || (info.hasAlt() && info.getAlt().equals(name))) + if (info.getName().equals(name) || ArrayUtils.contains(info.getAliases(), name)) return info.getCommandClass(); return null;