mirror of
https://github.com/aikar/commands.git
synced 2026-06-08 09:42:17 +00:00
Refactor the MessageFormatter to support any number of colors
This commit is contained in:
@@ -4,39 +4,13 @@ import org.spongepowered.api.text.Text;
|
||||
import org.spongepowered.api.text.format.TextColor;
|
||||
import org.spongepowered.api.text.serializer.TextSerializers;
|
||||
|
||||
public class SpongeMessageFormatter implements MessageFormatter {
|
||||
private final TextColor color1;
|
||||
private final TextColor color2;
|
||||
private final TextColor color3;
|
||||
public class SpongeMessageFormatter extends MessageFormatter<TextColor> {
|
||||
|
||||
public SpongeMessageFormatter(TextColor color1) {
|
||||
this(color1, color1);
|
||||
}
|
||||
public SpongeMessageFormatter(TextColor color1, TextColor color2) {
|
||||
this(color1, color2, color2);
|
||||
}
|
||||
public SpongeMessageFormatter(TextColor color1, TextColor color2, TextColor color3) {
|
||||
this.color1 = color1;
|
||||
this.color2 = color2;
|
||||
this.color3 = color3;
|
||||
public SpongeMessageFormatter(TextColor... colors) {
|
||||
super(colors);
|
||||
}
|
||||
|
||||
@Override
|
||||
public String c1(String message) {
|
||||
return convert(color1, message);
|
||||
}
|
||||
|
||||
@Override
|
||||
public String c2(String message) {
|
||||
return convert(color2, message);
|
||||
}
|
||||
|
||||
@Override
|
||||
public String c3(String message) {
|
||||
return convert(color3, message);
|
||||
}
|
||||
|
||||
private String convert(TextColor color, String message) {
|
||||
public String format(TextColor color, String message) {
|
||||
return TextSerializers.LEGACY_FORMATTING_CODE.serialize(Text.of(color, message));
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user