Skip to content
This repository has been archived by the owner on Jul 10, 2021. It is now read-only.

Commit

Permalink
Change "alt" to "aliases" and added the option for multiple aliases
Browse files Browse the repository at this point in the history
  • Loading branch information
R2D2Warrior committed Mar 7, 2014
1 parent edd0188 commit 16588ad
Show file tree
Hide file tree
Showing 4 changed files with 8 additions and 14 deletions.
2 changes: 1 addition & 1 deletion src/com/chcmatt/katelyn/commands/Command.java
Expand Up @@ -10,7 +10,7 @@
public @interface Command
{
String name();
String alt() default "";
String[] alias() default {};
String desc() default "";
/** Required: {@code<arg>}, Optional: [arg]*/
String syntax() default "";
Expand Down
2 changes: 1 addition & 1 deletion src/com/chcmatt/katelyn/commands/Ping.java
Expand Up @@ -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
{

Expand Down
13 changes: 3 additions & 10 deletions 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;
Expand All @@ -11,7 +9,7 @@
public class CommandInfo<T extends GenericCommand>
{
private String name;
private String alt;
private String[] aliases;
private String desc;
private String syntax;
private boolean isAdminOnly;
Expand All @@ -20,10 +18,10 @@ public class CommandInfo<T extends GenericCommand>
private Class<T> 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;
Expand All @@ -35,9 +33,4 @@ public boolean requiresArgs()
{
return requiresArgs;
}

public boolean hasAlt()
{
return StringUtils.isNotBlank(alt);
}
}
5 changes: 3 additions & 2 deletions src/com/chcmatt/katelyn/handling/CommandRegistry.java
Expand Up @@ -7,6 +7,7 @@

import lombok.Getter;

import org.apache.commons.lang3.ArrayUtils;
import org.pircbotx.PircBotX;
import org.reflections.Reflections;

Expand All @@ -29,7 +30,7 @@ public CommandRegistry(PircBotX bot)
for (Class<?> cls : reflections.getTypesAnnotatedWith(Command.class))
{
cmd = cls.getAnnotation(Command.class);
commands.add(new CommandInfo<T>(cmd.name(), cmd.alt(), cmd.desc(),
commands.add(new CommandInfo<T>(cmd.name(), cmd.alias(), cmd.desc(),
cmd.syntax(), cmd.adminOnly(), cmd.requiresArgs(), cls));
}
}
Expand Down Expand Up @@ -72,7 +73,7 @@ public String executeCommand(CommandEvent<PircBotX> event)
public Class<T> getCommandClass(String name)
{
for (CommandInfo<T> 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;
Expand Down

0 comments on commit 16588ad

Please sign in to comment.