Archived
0

Применяем TextTemplate

This commit is contained in:
2018-06-13 17:26:30 +03:00
parent fefd9e6266
commit d0db6c7ec4

View File

@@ -8,6 +8,7 @@ import lombok.extern.slf4j.Slf4j;
import mc.core.player.Player;
import mc.core.text.Text;
import mc.core.text.TextColor;
import mc.core.text.TextTemplate;
import org.slf4j.Marker;
import org.slf4j.helpers.BasicMarkerFactory;
import org.springframework.beans.factory.annotation.Autowired;
@@ -22,6 +23,11 @@ import java.util.Map;
@Slf4j
public class CommanderChatProcessor extends SimpleChatProcessor {
private static final Marker COMMAND_MARKER = new BasicMarkerFactory().getMarker("Command");
private static final TextTemplate UNKNOW_COMMAND_MSG = TextTemplate.builder()
.append(Text.of("Unknown command \"", TextColor.RED))
.arg("command", TextColor.WHITE)
.append(Text.of("\"", TextColor.RED))
.build();
@Autowired
private ApplicationContext applicationContext;
private Map<String, CommandExecutor> commands = new HashMap<>();
@@ -73,11 +79,7 @@ public class CommanderChatProcessor extends SimpleChatProcessor {
String[] args = message.substring(idx).split(" ");
commands.get(command).execute(player, args);
} else {
Text msg = Text.builder(TextColor.RED, "Unknown command \"")
.append(Text.of(TextColor.WHITE, command))
.append(Text.of("\""))
.build();
player.getChannel().sendChatMessage(msg);
player.getChannel().sendChatMessage(UNKNOW_COMMAND_MSG.apply("command", command));
}
} else {
super.process(player, message);