Skip to content

Commit 870ba42

Browse files
authored
GH-910 Fix delay, improve messages in alert (queue) (#910)
* Update ChatSection interface and translations for alert queue removal messages - Split `alertQueueRemoved` into `alertQueueRemovedSingle` and `alertQueueRemovedAll` to differentiate between removing a single message and removing all messages. - Updated translations (EN and PL) to include new fields and ensure consistency. - Adjusted command logic to use the new fields for better clarity and user feedback. * Check for AlertService#hasBroadcast in send command. * Fix checking AlertService#hasBroadcast. * Follow dmk feedback. * Follow Dr. hab Rolczi's Feedback. * Fix.
1 parent 4e2e3d2 commit 870ba42

File tree

5 files changed

+56
-27
lines changed

5 files changed

+56
-27
lines changed

eternalcore-core/src/main/java/com/eternalcode/core/feature/alert/AlertManager.java

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3,12 +3,11 @@
33
import com.eternalcode.commons.scheduler.Scheduler;
44
import com.eternalcode.core.injector.annotations.Inject;
55
import com.eternalcode.core.injector.annotations.component.Service;
6-
import com.eternalcode.core.notice.EternalCoreBroadcast;
76
import com.eternalcode.core.notice.NoticeTextType;
87
import com.eternalcode.core.translation.Translation;
98
import com.eternalcode.core.viewer.Viewer;
10-
119
import com.eternalcode.multification.notice.NoticeBroadcast;
10+
1211
import java.time.Duration;
1312
import java.util.ArrayList;
1413
import java.util.HashMap;
@@ -58,6 +57,8 @@ void clearBroadcasts(UUID uuid) {
5857
}
5958

6059
void send(UUID uuid, Duration delay) {
60+
Duration actualDelay = delay.isNegative() ? Duration.ofSeconds(2) : delay;
61+
6162
this.broadcasts.forEach((alertKey, broadcasts) -> {
6263
if (!alertKey.uuid().equals(uuid)) {
6364
return;
@@ -67,9 +68,8 @@ void send(UUID uuid, Duration delay) {
6768
if (DELAYED_TYPES.contains(type)) {
6869
for (int i = 0; i < broadcasts.size(); i++) {
6970
NoticeBroadcast<Viewer, Translation, ?> broadcast = broadcasts.get(i);
70-
scheduler.runLater(broadcast::send, delay.multipliedBy(i));
71+
scheduler.runLater(broadcast::send, actualDelay.multipliedBy(i + 1));
7172
}
72-
7373
return;
7474
}
7575

@@ -81,5 +81,9 @@ void send(UUID uuid, Duration delay) {
8181
clearBroadcasts(uuid);
8282
}
8383

84+
boolean hasNoBroadcasts(UUID uuid) {
85+
return this.broadcasts.keySet().stream().noneMatch(key -> key.uuid().equals(uuid));
86+
}
87+
8488
private record AlertKey(UUID uuid, NoticeTextType type) {}
8589
}

eternalcore-core/src/main/java/com/eternalcode/core/feature/alert/AlertQueueCommand.java

Lines changed: 35 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -5,18 +5,18 @@
55
import com.eternalcode.core.notice.NoticeService;
66
import com.eternalcode.core.notice.NoticeTextType;
77
import dev.rollczi.litecommands.annotations.argument.Arg;
8+
import dev.rollczi.litecommands.annotations.command.Command;
89
import dev.rollczi.litecommands.annotations.context.Sender;
9-
import dev.rollczi.litecommands.annotations.join.Join;
1010
import dev.rollczi.litecommands.annotations.execute.Execute;
11+
import dev.rollczi.litecommands.annotations.join.Join;
1112
import dev.rollczi.litecommands.annotations.literal.Literal;
1213
import dev.rollczi.litecommands.annotations.permission.Permission;
13-
import dev.rollczi.litecommands.annotations.command.Command;
14-
import org.bukkit.entity.Player;
15-
1614
import java.time.Duration;
1715
import java.util.Optional;
16+
import java.util.UUID;
17+
import org.bukkit.entity.Player;
1818

19-
@Command(name = "alert-queue", aliases = { "alert-q" })
19+
@Command(name = "alert-queue", aliases = {"alert-q"})
2020
@Permission("eternalcore.alert.queue")
2121
class AlertQueueCommand {
2222

@@ -35,11 +35,11 @@ class AlertQueueCommand {
3535
@Execute(name = "add")
3636
@DescriptionDocs(description = "Adds alert to the queue with specified notice type and messages", arguments = "<type> <message>")
3737
void executeAdd(@Sender Player sender, @Arg NoticeTextType type, @Join String text) {
38-
39-
this.alertService.addBroadcast(sender.getUniqueId(), type, this.noticeService.create()
40-
.notice(type, translation -> translation.chat().alertMessageFormat())
41-
.placeholder("{BROADCAST}", text)
42-
.onlinePlayers());
38+
this.alertService.addBroadcast(
39+
sender.getUniqueId(), type, this.noticeService.create()
40+
.notice(type, translation -> translation.chat().alertMessageFormat())
41+
.placeholder("{BROADCAST}", text)
42+
.onlinePlayers());
4343

4444
this.noticeService.create()
4545
.player(sender.getUniqueId())
@@ -54,7 +54,9 @@ void executeRemoveAll(@Sender Player sender, @Arg NoticeTextType type, @Literal(
5454

5555
this.noticeService.create()
5656
.player(sender.getUniqueId())
57-
.notice(translation -> success ? translation.chat().alertQueueRemoved() : translation.chat().alertQueueEmpty())
57+
.notice(translation -> success
58+
? translation.chat().alertQueueRemovedAll()
59+
: translation.chat().alertQueueEmpty())
5860
.send();
5961
}
6062

@@ -65,13 +67,23 @@ void executeRemove(@Sender Player sender, @Arg NoticeTextType type, @Literal("la
6567

6668
this.noticeService.create()
6769
.player(sender.getUniqueId())
68-
.notice(translation -> success ? translation.chat().alertQueueRemoved() : translation.chat().alertQueueEmpty())
70+
.notice(translation -> success
71+
? translation.chat().alertQueueRemovedSingle()
72+
: translation.chat().alertQueueEmpty())
6973
.send();
7074
}
7175

7276
@Execute(name = "clear")
7377
@DescriptionDocs(description = "Clears all alerts from the queue")
7478
void executeClear(@Sender Player sender) {
79+
if (this.alertService.hasNoBroadcasts(sender.getUniqueId())) {
80+
this.noticeService.create()
81+
.player(sender.getUniqueId())
82+
.notice(translation -> translation.chat().alertQueueEmpty())
83+
.send();
84+
return;
85+
}
86+
7587
this.alertService.clearBroadcasts(sender.getUniqueId());
7688
this.noticeService.create()
7789
.player(sender.getUniqueId())
@@ -82,7 +94,17 @@ void executeClear(@Sender Player sender) {
8294
@Execute(name = "send")
8395
@DescriptionDocs(description = "Sends all alerts from the queue")
8496
void executeSend(@Sender Player sender, @Arg Optional<Duration> duration) {
85-
this.alertService.send(sender.getUniqueId(), duration.orElse(Duration.ofSeconds(2)));
97+
UUID uniqueId = sender.getUniqueId();
98+
99+
if (this.alertService.hasNoBroadcasts(sender.getUniqueId())) {
100+
this.noticeService.create()
101+
.player(uniqueId)
102+
.notice(translation -> translation.chat().alertQueueEmpty())
103+
.send();
104+
return;
105+
}
106+
107+
this.alertService.send(uniqueId, duration.orElse(Duration.ofSeconds(2)));
86108
this.noticeService.create()
87109
.player(sender.getUniqueId())
88110
.notice(translation -> translation.chat().alertQueueSent())

eternalcore-core/src/main/java/com/eternalcode/core/translation/Translation.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -76,7 +76,8 @@ interface ChatSection {
7676
Notice tellrawMultipleSent();
7777
Notice tellrawCleared();
7878
Notice alertQueueAdded();
79-
Notice alertQueueRemoved();
79+
Notice alertQueueRemovedSingle();
80+
Notice alertQueueRemovedAll();
8081
Notice alertQueueCleared();
8182
Notice alertQueueEmpty();
8283
Notice alertQueueSent();

eternalcore-core/src/main/java/com/eternalcode/core/translation/implementation/ENTranslation.java

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -223,9 +223,6 @@ public static class ENChatSection implements ChatSection {
223223
@Description(" ")
224224
public Notice disabledChatInfo = Notice.chat("<red>✘ <dark_red>Chat is currently disabled!");
225225

226-
@Description({" ", "# {BROADCAST} - Broadcast"})
227-
public String alertMessageFormat = "<red><bold>BROADCAST: <gray>{BROADCAST}";
228-
229226
@Description(" ")
230227
public Notice commandNotFound = Notice.chat("<red>✘ <dark_red>Command <red>{COMMAND} <dark_red>doesn't exists!");
231228

@@ -237,10 +234,14 @@ public static class ENChatSection implements ChatSection {
237234
public Notice tellrawNoSaved = Notice.chat("<red>✘ <dark_red>No messages saved in queue!");
238235
public Notice tellrawMultipleSent = Notice.chat("<green>► <white>Messages sent! Message que has been cleared!");
239236
public Notice tellrawCleared = Notice.chat("<green>► <white>Message queue cleared!");
237+
238+
@Description({" ", "# {BROADCAST} - Broadcast"})
239+
public String alertMessageFormat = "<red><bold>BROADCAST:</bold> <gray>{BROADCAST}";
240240
public Notice alertQueueAdded = Notice.chat("<green>► <white>Message added to the queue!");
241-
public Notice alertQueueRemoved = Notice.chat("<green>► <white>Message removed from the queue!");
241+
public Notice alertQueueRemovedSingle = Notice.chat("<green>► <white>Removed latest message!");
242+
public Notice alertQueueRemovedAll = Notice.chat("<green>► <white>Removed all messages!");
242243
public Notice alertQueueCleared = Notice.chat("<green>► <white>Message queue cleared!");
243-
public Notice alertQueueEmpty = Notice.chat("<red>✘ <dark_red>Error: <red>The message queue is empty!");
244+
public Notice alertQueueEmpty = Notice.chat("<red>✘ <dark_red>The message queue is empty!");
244245
public Notice alertQueueSent = Notice.chat("<green>► <white>All messages sent from the queue!");
245246

246247
}

eternalcore-core/src/main/java/com/eternalcode/core/translation/implementation/PLTranslation.java

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -229,9 +229,6 @@ public static class PLChatSection implements ChatSection {
229229
public Notice disabledChatInfo = Notice.chat("<red>✘ <dark_red>Czat jest obecnie wyłączony!");
230230

231231

232-
@Description({" ", "# {BROADCAST} - Ogłoszenie"})
233-
public String alertMessageFormat = "<red><bold>OGŁOSZENIE: <gray>{BROADCAST}";
234-
235232
@Description(" ")
236233
public Notice commandNotFound = Notice.chat("<red>✘ <dark_red>Komenda <red>{COMMAND} <dark_red>nie istnieje!");
237234

@@ -243,8 +240,12 @@ public static class PLChatSection implements ChatSection {
243240
public Notice tellrawNoSaved = Notice.chat("<red>✘ <dark_red>Nie ma zapisanych wiadomości!");
244241
public Notice tellrawMultipleSent = Notice.chat("<green>► <white>Wysłano wszystkie zapisane wiadomości!");
245242
public Notice tellrawCleared = Notice.chat("<green>► <white>Wyczyszczono zapisane wiadomości!");
243+
244+
@Description({" ", "# {BROADCAST} - Ogłoszenie"})
245+
public String alertMessageFormat = "<red><bold>OGŁOSZENIE:</bold> <gray>{BROADCAST}";
246246
public Notice alertQueueAdded = Notice.chat("<green>► <white>Dodano wiadomość do kolejki!");
247-
public Notice alertQueueRemoved = Notice.chat("<green>► <white>Usunięto wiadomość z kolejki!");
247+
public Notice alertQueueRemovedSingle = Notice.chat("<green>► <white>Usunięto ostatnią wiadomość z kolejki!");
248+
public Notice alertQueueRemovedAll = Notice.chat("<green>► <white>Usunięto wszystkie wiadomości z kolejki!");
248249
public Notice alertQueueCleared = Notice.chat("<green>► <white>Wyczyszczono kolejkę wiadomości!");
249250
public Notice alertQueueEmpty = Notice.chat("<red>✘ <dark_red>Kolejka wiadomości jest pusta!");
250251
public Notice alertQueueSent = Notice.chat("<green>► <white>Wysłano wszystkie wiadomości z kolejki!");

0 commit comments

Comments
 (0)