Archived
0
This repository has been archived on 2022-03-24. You can view files and clone it, but cannot push or open issues or pull requests.
Files
mc-server/vanilla_commands/src/main/java/mc/commands/HelpCommand.java

70 lines
2.1 KiB
Java

/*
* DmitriyMX <dimon550@gmail.com>
* 2018-05-23
*/
package mc.commands;
import lombok.extern.slf4j.Slf4j;
import mc.core.chat.CommandExecutor;
import mc.core.chat.CommanderChatProcessor;
import mc.core.player.Player;
import mc.core.text.Text;
import mc.core.text.TextColor;
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(Text.of(TextColor.RED, "!!-Server error-!!"));
return;
}
}
Text commandNameText = Text.of(TextColor.RED);
Text descriptionText = Text.of(TextColor.WHITE);
Text messageText = Text.builder()
.append(commandNameText)
.append(Text.of(TextColor.GRAY, " - "))
.append(descriptionText)
.build();
commanderChatProcessor.getAllCommands().forEach(commandExecutor -> {
commandNameText.setString(commandExecutor.getUsage().orElse(commandExecutor.getName()));
descriptionText.setString(commandExecutor.getDescription());
sender.getChannel().sendChatMessage(messageText);
});
}
}