Created
February 26, 2015 02:20
-
-
Save Romain-P/32f21b2bdcbec300ddab to your computer and use it in GitHub Desktop.
example
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| package org.heat.world.commands.implementations.created; | |
| import org.heat.world.commands.Command; | |
| import org.heat.world.commands.CommandAction; | |
| import org.heat.world.commands.CommandManager; | |
| import org.heat.world.commands.CommandSender; | |
| import org.heat.world.commands.implementations.DefaultCommand; | |
| import javax.inject.Inject; | |
| import java.util.List; | |
| /** | |
| * Managed by romain on 25/02/2015. | |
| */ | |
| public class HelpCommand extends DefaultCommand { | |
| @Inject | |
| public HelpCommand(CommandManager manager) { | |
| super('!', "help", new CommandAction() { | |
| @Override | |
| public void execute(CommandSender sender, String[] args) { | |
| String commandName = args[0]; | |
| if(!commandName.isEmpty()) { | |
| Command command = manager.getCommandByNameOrAlias(commandName); | |
| if(command == null) | |
| sender.reply("La commande est introuvable: !help pour la liste"); | |
| else { | |
| StringBuilder text = new StringBuilder("\nSyntax:"); | |
| String main = command.getPrefix() + command.getName() + " "; | |
| command.getSubCommands().keySet().forEach((sub) -> text.append("\n").append(main).append(sub)); | |
| sender.reply(text.toString()); | |
| } | |
| return; | |
| } | |
| StringBuilder list = new StringBuilder("\nCommandes disponibles:"); | |
| List<Command> commands = manager.getCommandsByRankAsList(sender.getRank()); | |
| commands.stream().forEach((command) -> list.append("\n- ").append(command.getPrefix()).append(command.getName())); | |
| sender.reply(list.toString()); | |
| } | |
| }); | |
| addAlias("!commands"); | |
| addArgument("command", false); | |
| } | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment