Refactored chat messaging api
This commit is contained in:
@ -13,7 +13,7 @@ import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
public abstract class TranslatableMessage implements Sendable {
|
||||
int indention = 0;
|
||||
protected int indention = 0;
|
||||
final List<ComponentLike> chain = new ArrayList<>();
|
||||
|
||||
public TranslatableMessage() {
|
||||
@ -36,6 +36,7 @@ public abstract class TranslatableMessage implements Sendable {
|
||||
}
|
||||
|
||||
public TranslatableMessage list(List<String> list) {
|
||||
newLine();
|
||||
list.forEach(s -> {
|
||||
chain.add(Component.text(s));
|
||||
newLine();
|
||||
@ -43,6 +44,16 @@ public abstract class TranslatableMessage implements Sendable {
|
||||
return this;
|
||||
}
|
||||
|
||||
public TranslatableMessage numberedList(List<String> list) {
|
||||
newLine();
|
||||
for (int i = 0; i < list.size(); i++) {
|
||||
appendStatic(i+1 + ". ");
|
||||
appendStatic(list.get(i));
|
||||
newLine();
|
||||
}
|
||||
return this;
|
||||
}
|
||||
|
||||
public TranslatableMessage pipe() {
|
||||
chain.add(Component.text(" | ", NamedTextColor.DARK_GRAY));
|
||||
return this;
|
||||
@ -53,14 +64,29 @@ public abstract class TranslatableMessage implements Sendable {
|
||||
return this;
|
||||
}
|
||||
|
||||
public TranslatableMessage indent(int amount) {
|
||||
this.indention += amount;
|
||||
this.newLine();
|
||||
public TranslatableMessage newLine() {
|
||||
chain.add(Component.text("\n"));
|
||||
this.appendStatic(" ".repeat(indention));
|
||||
return this;
|
||||
}
|
||||
|
||||
public TranslatableMessage newLine() {
|
||||
chain.add(Component.text(" ".repeat(indention) + "\n"));
|
||||
public TranslatableMessage indent(int indention) {
|
||||
this.indention += indention;
|
||||
return this;
|
||||
}
|
||||
|
||||
public TranslatableMessage indent() {
|
||||
this.indent(1);
|
||||
return this;
|
||||
}
|
||||
|
||||
public TranslatableMessage undent() {
|
||||
this.indent(-1);
|
||||
return this;
|
||||
}
|
||||
|
||||
public TranslatableMessage resetIndention() {
|
||||
indention = 0;
|
||||
return this;
|
||||
}
|
||||
|
||||
|
@ -6,10 +6,25 @@ import net.minestom.server.entity.Player;
|
||||
|
||||
public class ChatMessage extends TranslatableMessage {
|
||||
public ChatMessage(Icon icon) {
|
||||
super.appendStatic("\n");
|
||||
appendStatic(icon.getComponent());
|
||||
pipe();
|
||||
}
|
||||
|
||||
public ChatMessage() {
|
||||
appendStatic(Icon.CHAT.getComponent());
|
||||
pipe();
|
||||
}
|
||||
|
||||
@Override
|
||||
public TranslatableMessage newLine() {
|
||||
super.appendStatic("\n");
|
||||
super.appendStatic(" ");
|
||||
super.pipe();
|
||||
super.appendStatic(" ".repeat(super.indention));
|
||||
return this;
|
||||
}
|
||||
|
||||
public void send(Player p) {
|
||||
p.sendMessage(build(p));
|
||||
}
|
||||
|
Reference in New Issue
Block a user