Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 7 additions & 5 deletions src/main/java/de/rettichlp/ucutils/common/Storage.java
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
import lombok.Getter;
import lombok.Setter;
import net.minecraft.entity.vehicle.MinecartEntity;
import net.minecraft.text.Text;
import org.jetbrains.annotations.Nullable;

import java.util.ArrayList;
Expand All @@ -32,6 +33,7 @@
import static de.rettichlp.ucutils.common.models.Faction.NULL;
import static java.util.Arrays.stream;
import static java.util.Optional.ofNullable;
import static net.minecraft.text.Text.translatable;

public class Storage {

Expand Down Expand Up @@ -189,12 +191,12 @@ public void trackReinforcement(Reinforcement reinforcement) {
@AllArgsConstructor
public enum ToggledChat {

NONE("", "Dauerhafter Chat deaktiviert"),
D_CHAT("d", "Dauerhafter D-Chat aktiviert"),
F_CHAT("f", "Dauerhafter F-Chat aktiviert"),
W_CHAT("w", "Dauerhafter Flüster-Chat aktiviert");
NONE("", translatable("ucutils.notification.toggled_chat.none")),
D_CHAT("d", translatable("ucutils.notification.toggled_chat.d")),
F_CHAT("f", translatable("ucutils.notification.toggled_chat.f")),
W_CHAT("w", translatable("ucutils.notification.toggled_chat.w"));

private final String command;
private final String toggleMessage;
private final Text toggleMessage;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@

import static de.rettichlp.ucutils.UCUtils.LOGGER;
import static de.rettichlp.ucutils.UCUtils.notificationService;
import static net.minecraft.text.Text.translatable;

@Getter
public class ApiException extends RuntimeException {
Expand All @@ -24,7 +25,7 @@ public ApiException(@NotNull HttpResponse<String> response, String message) {
}

public void sendNotification() {
notificationService.sendErrorNotification("Fehler bei der Abfrage (" + this.response.statusCode() + ")");
notificationService.sendErrorNotification(translatable("ucutils.notification.error.api", this.response.statusCode()));
}

public void log() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
import static de.rettichlp.ucutils.common.gui.widgets.base.AbstractUCUtilsWidget.Alignment.RIGHT;
import static java.util.Objects.isNull;
import static java.util.Optional.ofNullable;
import static net.minecraft.text.Text.translatable;

@Getter
public abstract class AbstractUCUtilsWidget<C extends UCUtilsWidgetConfiguration> {
Expand Down Expand Up @@ -94,7 +95,7 @@ public void loadConfiguration() {
this.widgetConfiguration.setX(getDefaultX());
this.widgetConfiguration.setY(getDefaultY());
} catch (Exception e) {
notificationService.sendErrorNotification("Konfiguration konnte nicht geladen werden");
notificationService.sendErrorNotification(translatable("ucutils.notification.error.configuration"));
LOGGER.error("Could not load configuration for widget {}", registryName, e);
}

Expand Down
3 changes: 1 addition & 2 deletions src/main/java/de/rettichlp/ucutils/common/models/Job.java
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@
import java.time.Duration;
import java.util.regex.Pattern;

import static de.rettichlp.ucutils.UCUtils.notificationService;
import static de.rettichlp.ucutils.UCUtils.storage;
import static java.time.Duration.ofMinutes;
import static java.util.regex.Pattern.compile;
Expand Down Expand Up @@ -47,6 +46,6 @@ public enum Job {
}

public void startCountdown() {
storage.getCountdowns().add(new Countdown(this.displayName, this.cooldown, () -> notificationService.sendInfoNotification("Cooldown für '" + this.displayName + "' abgelaufen")));
storage.getCountdowns().add(new Countdown(this.displayName, this.cooldown, () -> {}));
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@
import de.rettichlp.ucutils.common.gui.widgets.NotificationWidget;
import lombok.Data;
import net.minecraft.text.Text;
import org.jetbrains.annotations.NotNull;

import java.awt.Color;
import java.time.LocalDateTime;
Expand All @@ -13,9 +12,7 @@
import java.util.List;
import java.util.Objects;
import java.util.UUID;
import java.util.function.Supplier;

import static de.rettichlp.ucutils.UCUtils.renderService;
import static java.awt.Color.CYAN;
import static java.awt.Color.GREEN;
import static java.awt.Color.ORANGE;
Expand All @@ -31,30 +28,25 @@ public class NotificationService {

private final Collection<Notification> notifications = new ArrayList<>();

public void sendSuccessNotification(String message) {
sendNotification(message, GREEN, 5000);
public void sendSuccessNotification(Text text) {
sendNotification(text, GREEN, 5000);
}

public void sendInfoNotification(String message) {
sendNotification(message, CYAN, 5000);
public void sendInfoNotification(Text text) {
sendNotification(text, CYAN, 5000);
}

public void sendWarningNotification(String message) {
sendNotification(message, ORANGE, 5000);
public void sendWarningNotification(Text text) {
sendNotification(text, ORANGE, 5000);
}

public void sendErrorNotification(String message) {
sendNotification(message, RED, 5000);
public void sendErrorNotification(Text text) {
sendNotification(text, RED, 5000);
}

public void sendNotification(String message, Color color, long durationInMillis) {
sendNotification(() -> Text.of(message), color, durationInMillis);
}

public void sendNotification(@NotNull Supplier<Text> messageSupplier, Color color, long durationInMillis) {
Notification notification = new Notification(messageSupplier, durationInMillis);
notification.setBorderColor(color);
notification.setBackgroundColor(renderService.getSecondaryColor(color));
public void sendNotification(Text text, Color color, long durationInMillis) {
Notification notification = new Notification(text, durationInMillis);
notification.setColor(color);
this.notifications.add(notification);
}

Expand All @@ -70,15 +62,14 @@ public List<Notification> getActiveNotifications() {
public static class Notification {

private final UUID id = randomUUID();
private final Supplier<Text> textSupplier;
private final Text text;
private final long durationInMillis;
private final LocalDateTime timestamp = now();
private Color borderColor = WHITE;
private Color backgroundColor = renderService.getSecondaryColor(WHITE);
private Color color = WHITE;

@Override
public int hashCode() {
return hash(this.id, this.textSupplier, this.durationInMillis, this.timestamp, this.borderColor, this.backgroundColor);
return hash(this.id, this.text, this.durationInMillis, this.timestamp, this.color);
}

@Override
Expand All @@ -87,7 +78,7 @@ public boolean equals(Object o) {
}

public NotificationWidget toWidget() {
return new NotificationWidget(this.getTextSupplier().get(), this.borderColor, this.timestamp, this.durationInMillis);
return new NotificationWidget(this.text, this.color, this.timestamp, this.durationInMillis);
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,8 @@
import static java.util.Objects.nonNull;
import static java.util.concurrent.TimeUnit.MINUTES;
import static net.minecraft.text.Text.empty;
import static net.minecraft.text.Text.of;
import static net.minecraft.text.Text.literal;
import static net.minecraft.text.Text.translatable;
import static net.minecraft.util.Formatting.DARK_GRAY;
import static net.minecraft.util.Formatting.GRAY;
import static net.minecraft.util.Formatting.GREEN;
Expand Down Expand Up @@ -68,7 +69,7 @@ public void syncFactionSpecificData() {

utilService.delayedAction(() -> {
this.gameSyncProcessActive = false;
notificationService.sendSuccessNotification("Fraktionsdaten synchronisiert");
notificationService.sendSuccessNotification(translatable("ucutils.notification.info.faction_data_synchronized"));
}, COMMAND_COOLDOWN_MILLIS * 2);
}

Expand All @@ -83,12 +84,12 @@ public void checkForUpdates() {

String currentVersion = utilService.getVersion();
if (nonNull(latestVersion) && !currentVersion.equals(latestVersion)) {
notificationService.sendNotification(() -> empty()
.append(of("Neue UCUtils Version verfügbar").copy().formatted(GRAY))
.append(of(":").copy().formatted(DARK_GRAY)).append(" ")
.append(of(currentVersion).copy().formatted(RED)).append(" ")
.append(of("→").copy().formatted(GRAY)).append(" ")
.append(of(latestVersion).copy().formatted(GREEN)), MAGENTA, MINUTES.toMillis(5));
notificationService.sendNotification(empty()
.append(translatable("ucutils.notification.info.new_version").copy().formatted(GRAY))
.append(literal(":").copy().formatted(DARK_GRAY)).append(" ")
.append(literal(currentVersion).copy().formatted(RED)).append(" ")
.append(literal("→").copy().formatted(GRAY)).append(" ")
.append(literal(latestVersion).copy().formatted(GREEN)), MAGENTA, MINUTES.toMillis(5));
}
});
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
import static de.rettichlp.ucutils.common.models.ScreenshotType.OTHER;
import static de.rettichlp.ucutils.common.models.ScreenshotType.fromDisplayName;
import static java.lang.Thread.sleep;
import static net.minecraft.text.Text.translatable;

@Mixin(ChatScreen.class)
public abstract class ChatScreenMixin {
Expand All @@ -23,7 +24,7 @@ public abstract class ChatScreenMixin {
if (messageParts.length >= 2 && message.startsWith("/screenshot ")) {
String screenshotTypeString = messageParts[1].toLowerCase();
ScreenshotType screenshotType = fromDisplayName(screenshotTypeString).orElse(OTHER);
screenshotType.take(file -> notificationService.sendInfoNotification("Screenshot gespeichert: '" + file.getName() + "'"));
screenshotType.take(file -> notificationService.sendInfoNotification(translatable("ucutils.notification.info.screenshot_saved", file.getName())));

try {
sleep(5);
Expand Down
10 changes: 10 additions & 0 deletions src/main/resources/assets/ucutils/lang/de_de.json
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,16 @@
"ucutils.inventory.crystals": "Kristalle",
"ucutils.inventory.grab_bag": "Wundertüte",

"ucutils.notification.error.api": "Fehler bei der API Abfrage (%s)",
"ucutils.notification.error.configuration": "Konfiguration konnte nicht geladen werden",
"ucutils.notification.info.faction_data_synchronized": "Fraktionsdaten synchronisiert",
"ucutils.notification.info.new_version": "Neue UCUtils Version verfügbar",
"ucutils.notification.info.screenshot_saved": "Screenshot gespeichert: '%s'",
"ucutils.notification.toggled_chat.none": "Dauerhafter Chat deaktiviert",
"ucutils.notification.toggled_chat.f": "Dauerhafter F-Chat aktiviert",
"ucutils.notification.toggled_chat.d": "Dauerhafter D-Chat aktiviert",
"ucutils.notification.toggled_chat.w": "Dauerhaftes Flüstern aktiviert",

"ucutils.options.text.additional": "Erweitert",
"ucutils.options.text.amount": "Menge",
"ucutils.options.text.automation": "Automatisierung",
Expand Down
10 changes: 10 additions & 0 deletions src/main/resources/assets/ucutils/lang/en_gb.json
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,16 @@
"ucutils.inventory.crystals": "Crystals",
"ucutils.inventory.grab_bag": "Grab bag",

"ucutils.notification.error.api": "API request error (%s)",
"ucutils.notification.error.configuration": "Configuration could not be loaded",
"ucutils.notification.info.faction_data_synchronized": "Faction data synchronized",
"ucutils.notification.info.new_version": "New UCUtils version available",
"ucutils.notification.info.screenshot_saved": "Screenshot saved: '%s'",
"ucutils.notification.toggled_chat.none": "Persistent chat disabled",
"ucutils.notification.toggled_chat.f": "Persistent F-Chat enabled",
"ucutils.notification.toggled_chat.d": "Persistent D-Chat enabled",
"ucutils.notification.toggled_chat.w": "Persistent whispering enabled",

"ucutils.options.text.additional": "Additional",
"ucutils.options.text.amount": "Amount",
"ucutils.options.text.automation": "Automation",
Expand Down
10 changes: 10 additions & 0 deletions src/main/resources/assets/ucutils/lang/en_us.json
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,16 @@
"ucutils.inventory.crystals": "Crystals",
"ucutils.inventory.grab_bag": "Grab bag",

"ucutils.notification.error.api": "API request error (%s)",
"ucutils.notification.error.configuration": "Configuration could not be loaded",
"ucutils.notification.info.faction_data_synchronized": "Faction data synchronized",
"ucutils.notification.info.new_version": "New UCUtils version available",
"ucutils.notification.info.screenshot_saved": "Screenshot saved: '%s'",
"ucutils.notification.toggled_chat.none": "Persistent chat disabled",
"ucutils.notification.toggled_chat.f": "Persistent F-Chat enabled",
"ucutils.notification.toggled_chat.d": "Persistent D-Chat enabled",
"ucutils.notification.toggled_chat.w": "Persistent whispering enabled",

"ucutils.options.text.additional": "Additional",
"ucutils.options.text.amount": "Amount",
"ucutils.options.text.automation": "Automation",
Expand Down