Initial commit
This commit is contained in:
@@ -0,0 +1,76 @@
|
||||
package eu.mhsl.minenet.minigames.message;
|
||||
|
||||
import eu.mhsl.minenet.minigames.message.component.Translatable;
|
||||
import eu.mhsl.minenet.minigames.message.component.TranslatedComponent;
|
||||
import net.kyori.adventure.text.Component;
|
||||
import net.kyori.adventure.text.ComponentBuilder;
|
||||
import net.kyori.adventure.text.ComponentLike;
|
||||
import net.kyori.adventure.text.format.NamedTextColor;
|
||||
import net.minestom.server.entity.Player;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
public abstract class TranslatableMessage implements Sendable {
|
||||
int indention = 0;
|
||||
List<ComponentLike> chain = new ArrayList<>();
|
||||
|
||||
public TranslatableMessage() {
|
||||
|
||||
}
|
||||
|
||||
public TranslatableMessage appendStatic(Component component) {
|
||||
chain.add(component);
|
||||
return this;
|
||||
}
|
||||
|
||||
public TranslatableMessage appendStatic(String text) {
|
||||
chain.add(Component.text(text));
|
||||
return this;
|
||||
}
|
||||
|
||||
public TranslatableMessage appendTranslated(String mapId) {
|
||||
chain.add(new TranslatedComponent(mapId));
|
||||
return this;
|
||||
}
|
||||
|
||||
public TranslatableMessage list(List<String> list) {
|
||||
list.forEach(s -> {
|
||||
chain.add(Component.text(s));
|
||||
newLine();
|
||||
});
|
||||
return this;
|
||||
}
|
||||
|
||||
public TranslatableMessage pipe() {
|
||||
chain.add(Component.text(" | ", NamedTextColor.DARK_GRAY));
|
||||
return this;
|
||||
}
|
||||
|
||||
public TranslatableMessage quote(String text) {
|
||||
chain.add(Component.text("'" + text + "'"));
|
||||
return this;
|
||||
}
|
||||
|
||||
public TranslatableMessage indent(int amount) {
|
||||
this.indention += amount;
|
||||
this.newLine();
|
||||
return this;
|
||||
}
|
||||
|
||||
public TranslatableMessage newLine() {
|
||||
chain.add(Component.text(" ".repeat(indention) + "\n"));
|
||||
return this;
|
||||
}
|
||||
|
||||
|
||||
public Component build(Player p) {
|
||||
ComponentBuilder out = Component.text();
|
||||
chain.forEach(componentLike -> {
|
||||
if(componentLike instanceof Translatable t) t.compute(p);
|
||||
|
||||
out.append(componentLike);
|
||||
});
|
||||
return out.build();
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user