Skip to content

Instantly share code, notes, and snippets.

@Deamon5550
Last active August 29, 2015 14:06
Show Gist options
  • Save Deamon5550/fef0c5bf5af8c5c24edf to your computer and use it in GitHub Desktop.
Save Deamon5550/fef0c5bf5af8c5c24edf to your computer and use it in GitHub Desktop.
Commands
package com.voxelplugineering.voxelsniper.common.command;
import java.lang.annotation.Retention;
import java.lang.annotation.RetentionPolicy;
@Retention(RetentionPolicy.RUNTIME)
public @interface Command
{
String command();
String[] aliases() default {};
String info() default "No help is provided for this command";
}
package com.voxelplugineering.voxelsniper.common.command;
import java.lang.reflect.Method;
import java.util.Arrays;
import java.util.HashMap;
import java.util.Map;
import com.voxelplugineering.voxelsniper.api.ISniper;
public class CommandHandler
{
public static CommandHandler COMMAND_HANDLER = null;
private CommandHandler()
{
}
public static void create()
{
if(COMMAND_HANDLER != null) return;
COMMAND_HANDLER = new CommandHandler();
}
private Map<String, Method> commands = new HashMap<String, Method>();
public void registerCommands(Class<?> cls)
{
for(Method m: cls.getMethods())
{
if(m.isAnnotationPresent(Command.class))
{
Command cmd = m.getAnnotation(Command.class);
registerCommand(cmd, m);
}
}
}
public void registerCommand(Command cmd, Method handler)
{
}
public void onCommand(ISniper player, String command, String[] args)
{
}
public void onCommand(ISniper player, String fullCommand)
{
String[] s = fullCommand.split(" ");
onCommand(player, s[0], Arrays.copyOfRange(s, 1, s.length));
}
}
package com.voxelplugineering.voxelsniper.api;
import java.lang.reflect.Method;
import com.voxelplugineering.voxelsniper.common.command.Command;
public interface ICommandRegistrar
{
public void registerCommand(Command cmd, Method handler);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment