Archived
0

Vanilla commands: help, list

This commit is contained in:
2018-05-23 02:17:33 +03:00
parent ca1d3914c8
commit 429681c32e
6 changed files with 165 additions and 5 deletions

View 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()
));
});
}
}