fix Vanilla commands
This commit is contained in:
@@ -7,9 +7,11 @@ package mc.commands;
|
|||||||
import lombok.extern.slf4j.Slf4j;
|
import lombok.extern.slf4j.Slf4j;
|
||||||
import mc.core.chat.CommandExecutor;
|
import mc.core.chat.CommandExecutor;
|
||||||
import mc.core.chat.CommanderChatProcessor;
|
import mc.core.chat.CommanderChatProcessor;
|
||||||
|
import mc.core.chat.MessageType;
|
||||||
import mc.core.player.Player;
|
import mc.core.player.Player;
|
||||||
import mc.core.text.Text;
|
import mc.core.text.Text;
|
||||||
import mc.core.text.TextColor;
|
import mc.core.text.TextColor;
|
||||||
|
import mc.core.text.TextTemplate;
|
||||||
import org.springframework.beans.factory.annotation.Autowired;
|
import org.springframework.beans.factory.annotation.Autowired;
|
||||||
import org.springframework.context.ApplicationContext;
|
import org.springframework.context.ApplicationContext;
|
||||||
|
|
||||||
@@ -17,6 +19,12 @@ import java.util.Optional;
|
|||||||
|
|
||||||
@Slf4j
|
@Slf4j
|
||||||
public class HelpCommand implements CommandExecutor {
|
public class HelpCommand implements CommandExecutor {
|
||||||
|
private static final TextTemplate messageFormat = TextTemplate.builder()
|
||||||
|
.arg("command", TextColor.RED)
|
||||||
|
.append(Text.of(TextColor.GRAY, " - "))
|
||||||
|
.arg("description", TextColor.WHITE)
|
||||||
|
.build();
|
||||||
|
|
||||||
@Autowired
|
@Autowired
|
||||||
private ApplicationContext applicationContext;
|
private ApplicationContext applicationContext;
|
||||||
private CommanderChatProcessor commanderChatProcessor;
|
private CommanderChatProcessor commanderChatProcessor;
|
||||||
@@ -52,18 +60,11 @@ public class HelpCommand implements CommandExecutor {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
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 -> {
|
commanderChatProcessor.getAllCommands().forEach(commandExecutor -> {
|
||||||
commandNameText.setString(commandExecutor.getUsage().orElse(commandExecutor.getName()));
|
Text message = messageFormat.apply(
|
||||||
descriptionText.setString(commandExecutor.getDescription());
|
"command", commandExecutor.getUsage().orElse(commandExecutor.getName()),
|
||||||
sender.getChannel().sendChatMessage(messageText);
|
"description", commandExecutor.getDescription());
|
||||||
|
sender.getChannel().sendChatMessage(message, MessageType.SYSTEM_MESSAGE);
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -5,16 +5,25 @@
|
|||||||
package mc.commands;
|
package mc.commands;
|
||||||
|
|
||||||
import mc.core.chat.CommandExecutor;
|
import mc.core.chat.CommandExecutor;
|
||||||
|
import mc.core.chat.MessageType;
|
||||||
import mc.core.player.Player;
|
import mc.core.player.Player;
|
||||||
import mc.core.player.PlayerManager;
|
import mc.core.player.PlayerManager;
|
||||||
import mc.core.text.Text;
|
import mc.core.text.Text;
|
||||||
import mc.core.text.TextColor;
|
import mc.core.text.TextColor;
|
||||||
|
import mc.core.text.TextTemplate;
|
||||||
import org.springframework.beans.factory.annotation.Autowired;
|
import org.springframework.beans.factory.annotation.Autowired;
|
||||||
|
|
||||||
import java.util.Optional;
|
import java.util.Optional;
|
||||||
import java.util.StringJoiner;
|
import java.util.StringJoiner;
|
||||||
|
|
||||||
public class ListCommand implements CommandExecutor {
|
public class ListCommand implements CommandExecutor {
|
||||||
|
private static final TextTemplate messageFormat = TextTemplate.builder()
|
||||||
|
.append(Text.of(TextColor.GREEN, "Online("))
|
||||||
|
.arg("count")
|
||||||
|
.append(Text.of(TextColor.GREEN, "): "))
|
||||||
|
.arg("players", TextColor.DARK_GREEN)
|
||||||
|
.build();
|
||||||
|
|
||||||
@Autowired
|
@Autowired
|
||||||
private PlayerManager playerManager;
|
private PlayerManager playerManager;
|
||||||
|
|
||||||
@@ -43,9 +52,9 @@ public class ListCommand implements CommandExecutor {
|
|||||||
StringJoiner sj = new StringJoiner(", ");
|
StringJoiner sj = new StringJoiner(", ");
|
||||||
playerManager.getPlayers().forEach(pl -> sj.add(pl.getName()));
|
playerManager.getPlayers().forEach(pl -> sj.add(pl.getName()));
|
||||||
|
|
||||||
Text message = Text.builder(TextColor.GREEN, "Online(" + playerManager.getCountOnlinePlayers() + "): ")
|
Text message = messageFormat.apply(
|
||||||
.append(Text.of(TextColor.DARK_GREEN, sj.toString()))
|
"count", playerManager.getCountOnlinePlayers(),
|
||||||
.build();
|
"players", sj.toString());
|
||||||
sender.getChannel().sendChatMessage(message);
|
sender.getChannel().sendChatMessage(message, MessageType.SYSTEM_MESSAGE);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user