reformatted project
This commit is contained in:
@@ -9,8 +9,6 @@ import java.util.concurrent.atomic.AtomicInteger;
|
||||
import java.util.function.Consumer;
|
||||
|
||||
public class Countdown {
|
||||
public Countdown(Class<? extends TranslatableMessage> messageType) {
|
||||
}
|
||||
public CompletableFuture<Void> countdown(Audience targets, int from, Consumer<CountdownModifier> modifier) {
|
||||
CompletableFuture<Void> future = new CompletableFuture<>();
|
||||
AtomicInteger count = new AtomicInteger(from);
|
||||
@@ -23,7 +21,7 @@ public class Countdown {
|
||||
CountdownModifier countdownModifier = new CountdownModifier(count.getAndDecrement());
|
||||
modifier.accept(countdownModifier);
|
||||
countdownModifier.message.send(targets);
|
||||
} catch (Exception e) {
|
||||
} catch(Exception e) {
|
||||
throw new RuntimeException(e);
|
||||
}
|
||||
return TaskSchedule.seconds(1);
|
||||
@@ -33,8 +31,9 @@ public class Countdown {
|
||||
|
||||
|
||||
public static class CountdownModifier {
|
||||
public TranslatableMessage message;
|
||||
public final int timeLeft;
|
||||
public TranslatableMessage message;
|
||||
|
||||
public CountdownModifier(int timeLeft) {
|
||||
this.timeLeft = timeLeft;
|
||||
}
|
||||
|
||||
@@ -3,6 +3,7 @@ package eu.mhsl.minenet.minigames.message;
|
||||
import net.kyori.adventure.text.Component;
|
||||
import net.kyori.adventure.text.format.NamedTextColor;
|
||||
|
||||
@SuppressWarnings("UnnecessaryUnicodeEscape")
|
||||
public enum Icon {
|
||||
SCIENCE("\uD83E\uDDEA", NamedTextColor.LIGHT_PURPLE),
|
||||
STAR("\u2606", NamedTextColor.GOLD),
|
||||
@@ -15,20 +16,21 @@ public enum Icon {
|
||||
|
||||
private final String symbol;
|
||||
private final NamedTextColor color;
|
||||
|
||||
Icon(String symbol, NamedTextColor color) {
|
||||
this.symbol = symbol;
|
||||
this.color = color;
|
||||
}
|
||||
|
||||
public String getSymbol() {
|
||||
return symbol;
|
||||
return this.symbol;
|
||||
}
|
||||
|
||||
public NamedTextColor getColor() {
|
||||
return color;
|
||||
return this.color;
|
||||
}
|
||||
|
||||
public Component getComponent() {
|
||||
return Component.text(getSymbol(), getColor());
|
||||
return Component.text(this.getSymbol(), this.getColor());
|
||||
}
|
||||
}
|
||||
|
||||
@@ -14,75 +14,75 @@ import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
public abstract class TranslatableMessage implements Sendable {
|
||||
protected int indention = 0;
|
||||
final List<ComponentLike> chain = new ArrayList<>();
|
||||
protected int indention = 0;
|
||||
|
||||
public TranslatableMessage() {
|
||||
|
||||
}
|
||||
|
||||
public TranslatableMessage appendStatic(Component component) {
|
||||
chain.add(component);
|
||||
this.chain.add(component);
|
||||
return this;
|
||||
}
|
||||
|
||||
public TranslatableMessage appendStatic(String text) {
|
||||
chain.add(Component.text(text));
|
||||
this.chain.add(Component.text(text));
|
||||
return this;
|
||||
}
|
||||
|
||||
public TranslatableMessage appendSpace() {
|
||||
chain.add(Component.text(" "));
|
||||
this.chain.add(Component.text(" "));
|
||||
return this;
|
||||
}
|
||||
|
||||
public TranslatableMessage appendTranslated(String mapId) {
|
||||
chain.add(TranslatedComponent.byId(mapId).setColor(NamedTextColor.WHITE));
|
||||
this.chain.add(TranslatedComponent.byId(mapId).setColor(NamedTextColor.WHITE));
|
||||
return this;
|
||||
}
|
||||
|
||||
public TranslatableMessage appendTranslated(String mapId, NamedTextColor color) {
|
||||
chain.add(TranslatedComponent.byId(mapId).setColor(color));
|
||||
this.chain.add(TranslatedComponent.byId(mapId).setColor(color));
|
||||
return this;
|
||||
}
|
||||
|
||||
public TranslatableMessage appendTranslated(TranslatedComponent component) {
|
||||
chain.add(component);
|
||||
this.chain.add(component);
|
||||
return this;
|
||||
}
|
||||
|
||||
public TranslatableMessage list(List<String> list) {
|
||||
newLine();
|
||||
this.newLine();
|
||||
list.forEach(s -> {
|
||||
chain.add(Component.text(s));
|
||||
newLine();
|
||||
this.chain.add(Component.text(s));
|
||||
this.newLine();
|
||||
});
|
||||
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();
|
||||
this.newLine();
|
||||
for(int i = 0; i < list.size(); i++) {
|
||||
this.appendStatic(i + 1 + ". ");
|
||||
this.appendStatic(list.get(i));
|
||||
this.newLine();
|
||||
}
|
||||
return this;
|
||||
}
|
||||
|
||||
public TranslatableMessage pipe() {
|
||||
chain.add(Component.text(" | ", NamedTextColor.DARK_GRAY));
|
||||
this.chain.add(Component.text(" | ", NamedTextColor.DARK_GRAY));
|
||||
return this;
|
||||
}
|
||||
|
||||
public TranslatableMessage quote(String text) {
|
||||
chain.add(Component.text("'" + text + "'"));
|
||||
this.chain.add(Component.text("'" + text + "'"));
|
||||
return this;
|
||||
}
|
||||
|
||||
public TranslatableMessage newLine() {
|
||||
chain.add(Component.text("\n"));
|
||||
this.appendStatic(" ".repeat(indention));
|
||||
this.chain.add(Component.text("\n"));
|
||||
this.appendStatic(" ".repeat(this.indention));
|
||||
return this;
|
||||
}
|
||||
|
||||
@@ -102,15 +102,15 @@ public abstract class TranslatableMessage implements Sendable {
|
||||
}
|
||||
|
||||
public TranslatableMessage resetIndention() {
|
||||
indention = 0;
|
||||
this.indention = 0;
|
||||
return this;
|
||||
}
|
||||
|
||||
|
||||
public Component build(Player p) {
|
||||
ComponentBuilder<TextComponent, TextComponent.Builder> out = Component.text();
|
||||
chain.forEach(componentLike -> {
|
||||
if(componentLike == null) componentLike = Component.text("NULL", NamedTextColor.RED, TextDecoration.ITALIC);
|
||||
this.chain.forEach(componentLike -> {
|
||||
if(componentLike == null)
|
||||
componentLike = Component.text("NULL", NamedTextColor.RED, TextDecoration.ITALIC);
|
||||
if(componentLike instanceof Translatable t) t.assemble(p);
|
||||
out.append(componentLike);
|
||||
});
|
||||
|
||||
@@ -1,14 +0,0 @@
|
||||
package eu.mhsl.minenet.minigames.message.component;
|
||||
|
||||
|
||||
public class NamespacedTranslatable {
|
||||
private final String namespace;
|
||||
|
||||
public NamespacedTranslatable(String namespace) {
|
||||
this.namespace = namespace;
|
||||
}
|
||||
|
||||
public TranslatedComponent get(String mapId) {
|
||||
return TranslatedComponent.byId(namespace + mapId);
|
||||
}
|
||||
}
|
||||
@@ -18,6 +18,10 @@ public class TranslatedComponent implements ComponentLike, Translatable {
|
||||
private NamedTextColor color;
|
||||
private int wrap = 0;
|
||||
|
||||
private TranslatedComponent(String mapId) {
|
||||
this.mapId = mapId;
|
||||
}
|
||||
|
||||
public static TranslatedComponent byId(String mapId) {
|
||||
return new TranslatedComponent(mapId);
|
||||
}
|
||||
@@ -26,20 +30,17 @@ public class TranslatedComponent implements ComponentLike, Translatable {
|
||||
return new TranslatedComponent(mapid).getAssembled(p);
|
||||
}
|
||||
|
||||
private TranslatedComponent(String mapId) {
|
||||
this.mapId = mapId;
|
||||
}
|
||||
|
||||
public void assemble(Player p) {
|
||||
result = Languages.getInstance().getLanguage(p).getEntry(mapId);
|
||||
if(wrap > 0) {
|
||||
result = WordUtils.wrap(result, wrap, "\n", false);
|
||||
this.result = Languages.getInstance().getLanguage(p).getEntry(this.mapId);
|
||||
if(this.wrap > 0) {
|
||||
this.result = WordUtils.wrap(this.result, this.wrap, "\n", false);
|
||||
}
|
||||
}
|
||||
|
||||
public TranslatedComponent addWrap() {
|
||||
return this.addWrap(30);
|
||||
}
|
||||
|
||||
public TranslatedComponent addWrap(int wrap) {
|
||||
this.wrap = wrap;
|
||||
return this;
|
||||
@@ -47,12 +48,12 @@ public class TranslatedComponent implements ComponentLike, Translatable {
|
||||
|
||||
public Component getAssembled(Player p) {
|
||||
this.assemble(p);
|
||||
return asComponent();
|
||||
return this.asComponent();
|
||||
}
|
||||
|
||||
public List<Component> getWrappedAssembled(Player p) {
|
||||
this.assemble(p);
|
||||
return asWrappedComponent();
|
||||
return this.asWrappedComponent();
|
||||
}
|
||||
|
||||
public TranslatedComponent setColor(NamedTextColor color) {
|
||||
@@ -62,16 +63,16 @@ public class TranslatedComponent implements ComponentLike, Translatable {
|
||||
|
||||
@Override
|
||||
public @NotNull Component asComponent() {
|
||||
return this.componentFromString(result);
|
||||
return this.componentFromString(this.result);
|
||||
}
|
||||
|
||||
public List<Component> asWrappedComponent() {
|
||||
return Arrays.stream(result.split("\n")).map(this::componentFromString).toList();
|
||||
return Arrays.stream(this.result.split("\n")).map(this::componentFromString).toList();
|
||||
}
|
||||
|
||||
private Component componentFromString(String data) {
|
||||
if(color != null)
|
||||
return Component.text(data, color);
|
||||
if(this.color != null)
|
||||
return Component.text(data, this.color);
|
||||
else
|
||||
return Component.text(data);
|
||||
}
|
||||
|
||||
@@ -6,6 +6,6 @@ import net.minestom.server.entity.Player;
|
||||
public class ActionBarMessage extends TranslatableMessage {
|
||||
@Override
|
||||
public void send(Player p) {
|
||||
p.sendActionBar(build(p));
|
||||
p.sendActionBar(this.build(p));
|
||||
}
|
||||
}
|
||||
|
||||
@@ -6,25 +6,25 @@ import net.minestom.server.entity.Player;
|
||||
|
||||
public class ChatMessage extends TranslatableMessage {
|
||||
public ChatMessage() {
|
||||
construct(Icon.CHAT, false);
|
||||
this.construct(Icon.CHAT, false);
|
||||
}
|
||||
|
||||
public ChatMessage(Icon icon) {
|
||||
construct(icon, false);
|
||||
this.construct(icon, false);
|
||||
}
|
||||
|
||||
public ChatMessage(Icon icon, boolean preSpace) {
|
||||
construct(icon, preSpace);
|
||||
this.construct(icon, preSpace);
|
||||
}
|
||||
|
||||
private void construct(Icon icon, boolean preSpace) {
|
||||
if(preSpace) {
|
||||
super.appendStatic(" ");
|
||||
pipe();
|
||||
this.pipe();
|
||||
super.appendStatic("\n");
|
||||
}
|
||||
appendStatic(icon.getComponent());
|
||||
pipe();
|
||||
this.appendStatic(icon.getComponent());
|
||||
this.pipe();
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -37,6 +37,6 @@ public class ChatMessage extends TranslatableMessage {
|
||||
}
|
||||
|
||||
public void send(Player p) {
|
||||
p.sendMessage(build(p));
|
||||
p.sendMessage(this.build(p));
|
||||
}
|
||||
}
|
||||
|
||||
@@ -18,13 +18,15 @@ public class TitleMessage extends TranslatableMessage {
|
||||
private SubtitleMessage subtitle = new SubtitleMessage();
|
||||
|
||||
public TitleMessage() {
|
||||
times = Title.Times.times(Duration.ZERO, Duration.ofSeconds(1), Duration.ZERO);
|
||||
this.times = Title.Times.times(Duration.ZERO, Duration.ofSeconds(1), Duration.ZERO);
|
||||
}
|
||||
|
||||
public TitleMessage(Duration stay) {
|
||||
times = Title.Times.times(Duration.ZERO, stay, Duration.ZERO);
|
||||
this.times = Title.Times.times(Duration.ZERO, stay, Duration.ZERO);
|
||||
}
|
||||
|
||||
public TitleMessage(Duration stay, Duration fade) {
|
||||
times = Title.Times.times(fade, stay, fade);
|
||||
this.times = Title.Times.times(fade, stay, fade);
|
||||
}
|
||||
|
||||
public void setTimes(Title.Times times) {
|
||||
@@ -33,7 +35,7 @@ public class TitleMessage extends TranslatableMessage {
|
||||
|
||||
public TranslatableMessage subtitle(Consumer<SubtitleMessage> callback) {
|
||||
this.subtitle = new SubtitleMessage();
|
||||
callback.accept(subtitle);
|
||||
callback.accept(this.subtitle);
|
||||
return this;
|
||||
}
|
||||
|
||||
@@ -42,17 +44,17 @@ public class TitleMessage extends TranslatableMessage {
|
||||
Audience.audience(p).showTitle(new Title() {
|
||||
@Override
|
||||
public @NotNull Component title() {
|
||||
return build(p);
|
||||
return TitleMessage.this.build(p);
|
||||
}
|
||||
|
||||
@Override
|
||||
public @NotNull Component subtitle() {
|
||||
return subtitle.build(p);
|
||||
return TitleMessage.this.subtitle.build(p);
|
||||
}
|
||||
|
||||
@Override
|
||||
public @Nullable Times times() {
|
||||
return times;
|
||||
return TitleMessage.this.times;
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
Reference in New Issue
Block a user