Применяем TextTemplate
This commit is contained in:
@@ -8,6 +8,7 @@ import lombok.extern.slf4j.Slf4j;
|
|||||||
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.slf4j.Marker;
|
import org.slf4j.Marker;
|
||||||
import org.slf4j.helpers.BasicMarkerFactory;
|
import org.slf4j.helpers.BasicMarkerFactory;
|
||||||
import org.springframework.beans.factory.annotation.Autowired;
|
import org.springframework.beans.factory.annotation.Autowired;
|
||||||
@@ -22,6 +23,11 @@ import java.util.Map;
|
|||||||
@Slf4j
|
@Slf4j
|
||||||
public class CommanderChatProcessor extends SimpleChatProcessor {
|
public class CommanderChatProcessor extends SimpleChatProcessor {
|
||||||
private static final Marker COMMAND_MARKER = new BasicMarkerFactory().getMarker("Command");
|
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
|
@Autowired
|
||||||
private ApplicationContext applicationContext;
|
private ApplicationContext applicationContext;
|
||||||
private Map<String, CommandExecutor> commands = new HashMap<>();
|
private Map<String, CommandExecutor> commands = new HashMap<>();
|
||||||
@@ -73,11 +79,7 @@ public class CommanderChatProcessor extends SimpleChatProcessor {
|
|||||||
String[] args = message.substring(idx).split(" ");
|
String[] args = message.substring(idx).split(" ");
|
||||||
commands.get(command).execute(player, args);
|
commands.get(command).execute(player, args);
|
||||||
} else {
|
} else {
|
||||||
Text msg = Text.builder(TextColor.RED, "Unknown command \"")
|
player.getChannel().sendChatMessage(UNKNOW_COMMAND_MSG.apply("command", command));
|
||||||
.append(Text.of(TextColor.WHITE, command))
|
|
||||||
.append(Text.of("\""))
|
|
||||||
.build();
|
|
||||||
player.getChannel().sendChatMessage(msg);
|
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
super.process(player, message);
|
super.process(player, message);
|
||||||
|
|||||||
Reference in New Issue
Block a user