Vanilla commands: help, list
This commit is contained in:
62
vanilla_commands/src/main/java/mc/commands/HelpCommand.java
Normal file
62
vanilla_commands/src/main/java/mc/commands/HelpCommand.java
Normal file
@@ -0,0 +1,62 @@
|
||||
/*
|
||||
* DmitriyMX <dimon550@gmail.com>
|
||||
* 2018-05-23
|
||||
*/
|
||||
package mc.commands;
|
||||
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import mc.core.chat.ChatStyle;
|
||||
import mc.core.chat.CommandExecutor;
|
||||
import mc.core.chat.CommanderChatProcessor;
|
||||
import mc.core.player.Player;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.context.ApplicationContext;
|
||||
|
||||
import java.util.Optional;
|
||||
|
||||
@Slf4j
|
||||
public class HelpCommand implements CommandExecutor {
|
||||
@Autowired
|
||||
private ApplicationContext applicationContext;
|
||||
private CommanderChatProcessor commanderChatProcessor;
|
||||
|
||||
@Override
|
||||
public String getName() {
|
||||
return "help";
|
||||
}
|
||||
|
||||
@Override
|
||||
public Optional<String[]> getAliases() {
|
||||
return Optional.of(new String[]{"?"});
|
||||
}
|
||||
|
||||
@Override
|
||||
public Optional<String> getUsage() {
|
||||
return Optional.empty();
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getDescription() {
|
||||
return "shows this message";
|
||||
}
|
||||
|
||||
@Override
|
||||
public void execute(Player sender, String... args) {
|
||||
if (commanderChatProcessor == null) {
|
||||
commanderChatProcessor = applicationContext.getBean(CommanderChatProcessor.class);
|
||||
if (commanderChatProcessor == null) {
|
||||
log.error("Error get bean of type \"CommanderChatProcessor\". WTF?!");
|
||||
sender.getChannel().sendChatMessage(ChatStyle.RED + "!!-Server error-!!");
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
final String messageFormat = ChatStyle.RED + "%s " + ChatStyle.GRAY + "- " + ChatStyle.WHITE + "%s";
|
||||
commanderChatProcessor.getAllCommands().forEach(commandExecutor -> {
|
||||
sender.getChannel().sendChatMessage(String.format(messageFormat,
|
||||
commandExecutor.getUsage().orElse(commandExecutor.getName()),
|
||||
commandExecutor.getDescription()
|
||||
));
|
||||
});
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user