Creating Custom SubCommand

Learn how to create custom subcommand!

Command handler needs to extend CommandHandler interface

public class APIExample implements CommandHandler {
	
	
	@Override
	public boolean readAndExecute(CommandSender s, String[] args) {
		
		/*
		* 
		* Your command handler
		* @ false - helpMessage() will be sent to command sender
		* @ true - helpMessage() won't be sent to command sender
		* 
		* */
		
		return false;
	}
	
	@Override
	public List<String> readAndReturn(CommandSender s, String[] args) {
		
		/*
		* 
		* Your tab completer
		* 
		* */
		
		return null;
	}
	
	@Override
	public String permission() {
		return "some.permission.to.use";
	}
	
	@Override
	public HandlerType handlerType() {
		return new ExtensionHandlerType();
	}
	
	@Override
	public BaseComponent[] helpMessage() {
		
		/*
		* For this you can use built in TextComponentBuilder!
		* */
		TextComponentBuilder builder = new TextComponentBuilder();
		
		// Appending legacy text (Will be colorized automatically)
		builder.appendLegacy("&aSome text");
		
		// Appending legacy text with hover (Will be colorized automatically)
		builder.appendLegacy("&aSome text", "&bSome Hover");
		
		// Appending legacy text with click (Will be colorized automatically)
		builder.appendLegacy("&aSome text", ClickEvent.Action.OPEN_URL, "some.url");
		
		// Appending legacy text with hover & click (Will be colorized automatically)
		builder.appendLegacy("&aSome text", "&bSome Hover", ClickEvent.Action.OPEN_URL, "some.url");
		 
		// Returning component
		return builder.createMessage();
	}
	
}

Registering your CommandHandler

/*
* Let's register your handler with API!
* @ String - SubArgument (For example now usage is /at clearchat)
* @ CommandHandler - Your handler object
* */
AmazingTitles.registerCommandHandler("clearChat", new ClearChatCommandHandler());

Last updated